View Single Post
10-27-18, 11:33 PM   #4
Lyak
A Cyclonian
Join Date: Jul 2018
Posts: 46
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