WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   [AceConfig-3.0] Unit specific option tab (https://www.wowinterface.com/forums/showthread.php?t=56809)

Lyak 10-27-18 03:08 PM

[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 :p)

What would be the best way to achieve such thing?

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

myrroddin 10-27-18 11:13 PM

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.

myrroddin 10-27-18 11:18 PM

To disable if the unit is not the player, add this where appropriate:
Code:

disabled = function() return unit ~= "player" end,

Lyak 10-27-18 11:33 PM

Quote:

Originally Posted by myrroddin (Post 330656)
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 :rolleyes:

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

Quote:

Originally Posted by myrroddin (Post 330657)
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


Seerah 10-28-18 02:12 PM

Use the disabled key for that tab's group.
https://www.wowace.com/projects/ace3...options-tables

Lyak 10-28-18 03:02 PM

Quote:

Originally Posted by Seerah (Post 330667)
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 ;)

Seerah 10-28-18 06:28 PM

As far as I know, AceConfig is not capable of removing the tab.

Vrul 10-28-18 06:43 PM

You want "hidden" not "disabled"

Seerah 10-28-18 07:50 PM

Quote:

Originally Posted by Vrul (Post 330673)
You want "hidden" not "disabled"

Oh - I completely forgot about that one. And look, it's right under disabled in the docs. :o

Lyak 10-28-18 09:36 PM

Quote:

Originally Posted by Vrul (Post 330673)
You want "hidden" not "disabled"

Quote:

Originally Posted by Seerah (Post 330674)
Oh - I completely forgot about that one. And look, it's right under disabled in the docs. :o

(-‸ლ)

I am the dumbest creature of the entire universe.

God...................................... How could I have not seen that.............................?


All times are GMT -6. The time now is 03:30 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI