ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   Trouble with Starting a function from xml (https://www.esoui.com/forums/showthread.php?t=7872)

Tarlac 06/18/18 10:10 PM

Trouble with Starting a function from xml
 
Hi guys,

I am trying to add the LibAddonMenu-2.0 to this addon. I am able to get the settings window to work, but now that I have added that I am no longer able to access a function from within the xml. If I comment out the
Lua Code:
  1. LAM2:RegisterAddonPanel("ReloadButton", panelData)
  2. LAM2:RegisterOptionControls("ReloadButton", optionsTable)
Then I again am able to access my functions from within the xml. I am hoping someone sees what am doing wrong?


Lua Code:
  1. ReloadButton = {}
  2.  
  3. ReloadButton.Default = { OffsetX = 300, OffsetY = 300, Show = true, version = 2}
  4.  
  5. ReloadButton.name = "ReloadButton"
  6. ReloadButton.version = 2
  7. ReloadButton.show = true
  8.  
  9. ZO_CreateStringId("SI_BINDING_NAME_TARLAC_RELOADBUTTON", "Show/Hide ReloadButton") -- This is not showing up
  10.  
  11.  
  12.  
  13. function ReloadButton.OnAddOnLoaded(event, addonName)
  14.    if addonName == ReloadButton.name then  
  15.     ReloadButton:Initialize()
  16.   end
  17. end
  18.  
  19. function ReloadButton:Initialize()
  20.  
  21.   ReloadButton.savedVariables = ZO_SavedVars:NewCharacterIdSettings("ReloadButtonSavedVariables", ReloadButton.version, nil, ReloadButton.Default)  
  22.   --Load Defaults
  23.  
  24.  
  25.   ReloadButtonWindow:ClearAnchors()
  26.   ReloadButtonWindow:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, ReloadButton.savedVariables.OffsetX, ReloadButton.savedVariables.OffsetY)
  27.   ReloadButton.ControlSettings()  
  28.   EVENT_MANAGER:UnregisterForEvent(ReloadButton.name, EVENT_ADD_ON_LOADED)
  29. end
  30.  
  31. function ReloadButton.SaveSettings()
  32.  
  33.   ReloadButton.version = ReloadButton.version + 1
  34.   ReloadButton.savedVariables.version = ReloadButton.version
  35.     ReloadButton.savedVariables.OffsetX = ReloadButtonWindow:GetLeft()
  36.     ReloadButton.savedVariables.OffsetY = ReloadButtonWindow:GetTop()
  37.   d("Saved = " .. tostring(ReloadButton.savedVariables.OffsetX))
  38. end
  39.  
  40. function ReloadButton.Close()
  41.   ReloadButtonWindow:SetHidden(true)
  42.   ReloadButton.show = false
  43.   ReloadButton.savedVariables.Show = false
  44. end
  45.  
  46. function ReloadButton.Open()
  47.   ReloadButtonWindow:SetHidden(false)
  48.   ReloadButton.show = true
  49.   ReloadButton.savedVariables.Show = true
  50.   end
  51.  
  52. function ReloadButton.Reload()
  53.   ReloadUI("ingame")
  54.   end
  55.  
  56. function ReloadButton.Check()
  57.   if ReloadButton.show == true then
  58.       ReloadButton.Open()
  59.     else
  60.       ReloadButton.Close()
  61.     end
  62.   end
  63.  
  64.   function ReloadButton.ControlSettings()
  65.     d("Control Settings Started")
  66.     local tempVersion = ReloadButton.version
  67.    
  68.     local panelData = {
  69.     type = "panel",
  70.     name = "ReloadButton",
  71.     displayName = "ReloadButton",
  72.     author = "Tarlac",
  73.     version = tempVersion,
  74.     slashCommand = "/reloadbuttonsettings", --(optional) will register a keybind to open to this panel
  75.     registerForRefresh = true--boolean (optional) (will refresh all options controls when a setting is changed and when the panel is shown)
  76.     registerForDefaults = true, --boolean (optional) (will set all options controls back to default values)
  77. }
  78.    
  79.     local optionsTable = {
  80.     [1] = {
  81.         type = "header",
  82.         name = "ReloadButton",
  83.         width = "full", --or "half" (optional)
  84.     },
  85.  
  86.     [2] = {
  87.         type = "checkbox",
  88.         name = "Show/Hide ReloadButton",
  89.         tooltip = "Checkbox's tooltip text.",
  90.         getFunc = function() return true end,
  91.         setFunc = function(value) ReloadButton.show = value ReloadButtonWindow:SetHidden (not value) end,
  92.         width = "half", --or "half" (optional)
  93.     },
  94.        
  95. }
  96.    
  97.     local LAM2 = LibStub("LibAddonMenu-2.0")
  98.     ---------------------------------If I comments these out then my addon works.--------------------
  99.     LAM2:RegisterAddonPanel("ReloadButton", panelData)
  100.     LAM2:RegisterOptionControls("ReloadButton", optionsTable)
  101.     -------------------------------------------------------------------------------------------------
  102.     d("Control Settings Ended")
  103.     end
  104.  
  105. d("Loaded ReloadButton...")
  106. EVENT_MANAGER:RegisterForEvent(ReloadButton.name, EVENT_ADD_ON_LOADED, ReloadButton.OnAddOnLoaded)
  107. SLASH_COMMANDS["/reloadbutton"] = function()  ReloadButton.Open() end

Code:

GuiXml>
  <Controls>
  <TopLevelControl name="ReloadButtonWindow" clampedToScreen="true" mouseEnabled="true" movable="true" hidden="false">       
      <Dimensions x="50" y="20" />
      <Anchor point="TOPLEFT" relativeTo="GuiRoot" relativePoint="CENTER" offsetX="0" offsetY="-30"/>
      <OnMoveStop>
        ReloadButton.SaveSettings()
      </OnMoveStop>
      <Controls>
        <Backdrop name="$(parent)Backdrop" edgeColor="FF0000" centerColor="6495ED" alpha="0.6" >
            <Dimensions x="50" y="50" />
            <Anchor point="TOPRIGHT" relativeTo="$(parent)" relativePoint="TOPLEFT" offsetX="50" offsetY="20"/>
            <Edge edgeSize="6" />
        </Backdrop>
 
        <Button name="$(parent)Button" >
            <Dimensions x="50" y="50" />
            <Anchor point="TOPRIGHT" relativeTo="$(parent)" relativePoint="TOPLEFT" offsetX="50" offsetY="20"/>
            <Textures
                    normal                ="/esoui/art/help/help_tabicon_feedback_up.dds"
                   
                    mouseOver        ="/esoui/art/help/help_tabicon_feedback_over.dds"/>
            <OnClicked>
              ReloadButton.Reload()
                                        </OnClicked>
        </Button>       
       
        <Button name="$(parent)ButtonCloseAddon" inherits="ZO_ButtonBehaviorClickSound">
                                        <Dimensions x="40" y="40" />
                                        <Anchor point="TOPRIGHT" relativeTo="$(parent)" relativePoint="TOPRIGHT" offsetX="40" />
                                        <Textures normal="EsoUI/Art/Buttons/closebutton_up.dds"
                                                pressed="EsoUI/Art/Buttons/closebutton_down.dds"
                                                mouseOver="EsoUI/Art/Buttons/closebutton_mouseover.dds"
                                                disabled="EsoUI/Art/Buttons/closebutton_disabled.dds"/>
                                        <OnClicked>
            ReloadButton.Close()
                                        </OnClicked>
                                </Button>
 
        <Label name="$(parent)Label" font="ZoFontWinH3" color="ffffff" text="Reload" verticalAlignment="CENTER" horizontalAlignment="LEFT"  alpha="0.85">                       
            <Dimensions x="60" y="20" />
            <Anchor point="TOPLEFT"  relativeTo="$(parent)" relativePoint="TOPLEFT" offsetX="-5" offsetY="0"/>
        </Label>
      </Controls>
  </TopLevelControl>
  </Controls>
</GuiXml>


votan 06/19/18 01:26 AM

The file order matters.

sirinsidiator 06/19/18 05:18 AM

Calling LAM2:RegisterAddonPanel("ReloadButton", panelData) creates a global variable for the settings panel, which will overwrite any variables that existed prior. Since you pass "ReloadButton", it will replace your global table. Use something like ReloadButtonSettings instead and it should work.

Tarlac 06/19/18 01:15 PM

Quote:

Originally Posted by sirinsidiator (Post 35090)
Calling LAM2:RegisterAddonPanel("ReloadButton", panelData) creates a global variable for the settings panel, which will overwrite any variables that existed prior. Since you pass "ReloadButton", it will replace your global table. Use something like ReloadButtonSettings instead and it should work.

Thank you so much!!! I knew my variables were being wiped, but did not know why. Thank you!! I changed name and works like a champ. FYI, incase you were wondering if your tutorials were being used, they are by me for sure. Thank you for doing those. I have been following what you say and using it in my own addon. Thank you very much for your help.

Tarlac.


All times are GMT -6. The time now is 06:35 PM.

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