Quantcast [AceConfig-3.0] Unit specific option tab - WoWInterface
Thread Tools Display Modes
10-27-18, 03:08 PM   #1
Lyak
A Cyclonian
Join Date: Jul 2018
Posts: 44
[AceConfig-3.0] Unit specific option tab

Hi all,

I am trying to tweak my options table and create a tab only for a specific unit and here's what I've got so far.

Lua Code:
  1. function CreateOption()
  2.     if not option then
  3.         option = {
  4.             order = A:GetModuleOrder(),
  5.             type = "group",
  6.             childGroups = "tab",
  7.             name = "Unitframe",
  8.             args = {
  9.                 unit = {
  10.                     order = 1,
  11.                     type = "group",
  12.                     childGroups = "tab",
  13.                     name = "Unit",
  14.                     args = CreateUnitOption(),
  15.                 },
  16.             },
  17.         };
  18.     end
  19.  
  20.     return option;
  21. end
  22.  
  23. function CreateUnitOption()
  24.     local option = {
  25.         selected = {
  26.             order = 1,
  27.             type = "select",
  28.             name = "Selected Unit",
  29.             values = unitList,
  30.             get = function(info)
  31.                 return selectedUnit;
  32.             end,
  33.             set = function(info, ...)
  34.                 selectedUnit = ...;
  35.             end,
  36.         },
  37.         general = CreateGeneralOption(),
  38.     };
  39.  
  40.     for _, bar in pairs({"Health", "Power"}) do
  41.         option[string.lower(bar)] = CreateBarOption(bar);
  42.     end
  43.  
  44.     return option;
  45. end



On red colored section, as shown on the image above, I would like to create a "ClassPower" tab only when the selected unit is player.
(Which will obviously be hidden when the other units are selected )

What would be the best way to achieve such thing?

Thank you in advance and I wish you all the best!!

Last edited by Lyak : 10-27-18 at 05:53 PM.
  Reply With Quote
10-27-18, 11:13 PM   #2
myrroddin
A Molten Giant
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 950
Before I think about your requested issue, your functions need to be local functions. Having names like CreateOption and CreateUnitOption in the global namespace is a very bad idea.

Also, you do not need to specify that childGroups = "tab" twice. You only need that in the parent group.

Last edited by myrroddin : 10-27-18 at 11:16 PM. Reason: childgroups
  Reply With Quote
10-27-18, 11:18 PM   #3
myrroddin
A Molten Giant
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 950
To disable if the unit is not the player, add this where appropriate:
Code:
disabled = function() return unit ~= "player" end,
  Reply With Quote
10-27-18, 11:33 PM   #4
Lyak
A Cyclonian
Join Date: Jul 2018
Posts: 44
Originally Posted by myrroddin View Post
Before I think about your requested issue, your functions need to be local functions. Having names like CreateOption and CreateUnitOption in the global namespace is a very bad idea.
Sorry for causing a confusion.

I did not upload the upper part of the lua file, but it actually has those functions declared in local variable first

Lua Code:
  1. ------------------------------------------
  2. -- Variable
  3. ------------------------------------------
  4.  
  5. local anchorList = {
  6.     TOPLEFT = "TOPLEFT",
  7.     TOPRIGHT = "TOPRIGHT",
  8.     BOTTOMRIGHT = "BOTTOMRIGHT",
  9.     BOTTOMLEFT = "BOTTOMLEFT",
  10.     LEFT = "LEFT",
  11.     TOP = "TOP",
  12.     RIGHT = "RIGHT",
  13.     BOTTOM = "BOTTOM",
  14.     CENTER = "CENTER",
  15. };
  16.  
  17. local selectedUnit = "Player";
  18. local unitList = {
  19.     Player = "Player",
  20.     Pet = "Pet",
  21.     Target = "Target",
  22.     TargetTarget = "TargetTarget",
  23.     Focus = "Focus",
  24. };
  25.  
  26. local option;
  27.  
  28. local CreateOption;
  29. local CreateUnitOption;
  30. local CreateGeneralOption;
  31. local CreateBarOption;
  32. local CreateClassPowerOption;
  33.  
  34. ------------------------------------------
  35. -- Function
  36. ------------------------------------------
  37.  
  38. function CreateOption()
  39.     if not option then
  40.         option = {
  41.             order = A:GetModuleOrder(),
  42.             type = "group",
  43.             childGroups = "tab",
  44.             name = "Unitframe",
  45.             args = {
  46.                 unit = {
  47.                     order = 1,
  48.                     type = "group",
  49.                     childGroups = "tab",
  50.                     name = "Unit",
  51.                     args = CreateUnitOption(),
  52.                 },
  53.             },
  54.         };
  55.     end
  56.  
  57.     return option;
  58. end
  59.  
  60. function CreateUnitOption()
  61.     local option = {
  62.         selected = {
  63.             order = 1,
  64.             type = "select",
  65.             name = "Selected Unit",
  66.             values = unitList,
  67.             get = function(info)
  68.                 return selectedUnit;
  69.             end,
  70.             set = function(info, ...)
  71.                 selectedUnit = ...;
  72.             end,
  73.         },
  74.         general = CreateGeneralOption(),
  75.     };
  76.  
  77.     for _, bar in pairs({"Health", "Power"}) do
  78.         option[string.lower(bar)] = CreateBarOption(bar);
  79.     end
  80.  
  81.     return option;
  82. end

Originally Posted by myrroddin View Post
To disable if the unit is not the player, add this where appropriate:
Code:
disabled = function() return unit ~= "player" end,
Thanks for the idea!

But, instead of disabling the tab, would there be any possible way to register (show)/unregister (hide) from the options tab which is actually being recycled depending on a selected unit?

Here's what I am currently thinking as my solution (which actually works, but I don't think this is optimized)

Code:
function CreateUnitOption()
	local option = {
		selected = {
			order = 1,
			type = "select",
			name = "Selected Unit",
			values = unitList,
			get = function(info)
				return selectedUnit;
			end,
			set = function(info, ...)
				selectedUnit = ...;

				option.args.unit.args.classPower = selectedUnit == "Player" and CreateClassPowerOption() or nil;
			end,
		},
		general = CreateGeneralOption(),
	};

	for _, bar in pairs({"Health", "Power"}) do
		option[string.lower(bar)] = CreateBarOption(bar);
	end

	option.classPower = selectedUnit == "Player" and CreateClassPowerOption() or nil;

	ResetOrder();

	return option;
end

Last edited by Lyak : 10-27-18 at 11:40 PM.
  Reply With Quote
10-28-18, 02:12 PM   #5
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,557
Use the disabled key for that tab's group.
https://www.wowace.com/projects/ace3...options-tables
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
10-28-18, 03:02 PM   #6
Lyak
A Cyclonian
Join Date: Jul 2018
Posts: 44
Originally Posted by Seerah View Post
Use the disabled key for that tab's group.
https://www.wowace.com/projects/ace3...options-tables
Hi Seerah,

Yeah, I thought of using disabled key which will disable that particular tab when the other unit is selected. However, the tab will still be "visible", only grey it out :/

What I want is the tab being fully hidden if the selected unit is not a player
  Reply With Quote
10-28-18, 06:28 PM   #7
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,557
As far as I know, AceConfig is not capable of removing the tab.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
10-28-18, 06:43 PM   #8
Vrul
A Frostmaul Preserver
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 292
You want "hidden" not "disabled"
  Reply With Quote
10-28-18, 07:50 PM   #9
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,557
Originally Posted by Vrul View Post
You want "hidden" not "disabled"
Oh - I completely forgot about that one. And look, it's right under disabled in the docs.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
10-28-18, 09:36 PM   #10
Lyak
A Cyclonian
Join Date: Jul 2018
Posts: 44
Originally Posted by Vrul View Post
You want "hidden" not "disabled"
Originally Posted by Seerah View Post
Oh - I completely forgot about that one. And look, it's right under disabled in the docs.
(-‸ლ)

I am the dumbest creature of the entire universe.

God...................................... How could I have not seen that.............................?
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » [AceConfig-3.0] Unit specific option tab

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off