Originally Posted by myrroddin
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:
------------------------------------------
-- Variable
------------------------------------------
local anchorList = {
TOPLEFT = "TOPLEFT",
TOPRIGHT = "TOPRIGHT",
BOTTOMRIGHT = "BOTTOMRIGHT",
BOTTOMLEFT = "BOTTOMLEFT",
LEFT = "LEFT",
TOP = "TOP",
RIGHT = "RIGHT",
BOTTOM = "BOTTOM",
CENTER = "CENTER",
};
local selectedUnit = "Player";
local unitList = {
Player = "Player",
Pet = "Pet",
Target = "Target",
TargetTarget = "TargetTarget",
Focus = "Focus",
};
local option;
local CreateOption;
local CreateUnitOption;
local CreateGeneralOption;
local CreateBarOption;
local CreateClassPowerOption;
------------------------------------------
-- Function
------------------------------------------
function CreateOption()
if not option then
option = {
order = A:GetModuleOrder(),
type = "group",
childGroups = "tab",
name = "Unitframe",
args = {
unit = {
order = 1,
type = "group",
childGroups = "tab",
name = "Unit",
args = CreateUnitOption(),
},
},
};
end
return option;
end
function CreateUnitOption()
local option = {
selected = {
order = 1,
type = "select",
name = "Selected Unit",
values = unitList,
get = function(info)
return selectedUnit;
end,
set = function(info, ...)
selectedUnit = ...;
end,
},
general = CreateGeneralOption(),
};
for _, bar in pairs({"Health", "Power"}) do
option[string.lower(bar)] = CreateBarOption(bar);
end
return option;
end
Originally Posted by myrroddin
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