Thread Tools Display Modes
11-22-14, 10:21 PM   #1
Zireko
An Aku'mai Servant
Join Date: Nov 2014
Posts: 38
I Need some Help On an Addon I'm working On

Currently I'm just practicing and trying to build a very simple addon called ZBar. I will later anchor it to the bottom center of the screen. this addon is just supposed to add an image that can be moved around on the screen currently. It's a custom image and I've converted it to tga using power of 2 like I've read, (tga img size is 512x512). I'm not sure why the addon isn't currently showing up. I'm still very new to coding and I'm learning wows API I came from building a few addons for Elder Scrolls Online. Any way here is the current code I have and I've attached the addon I've built so far below.

Toc File
Lua Code:
  1. ## Interface: 60000
  2. ## Title: ZBar
  3. ## Notes: A simple skin addon that allows you to place your ui into it.
  4. ## Author: Zireko
  5. ## Version: 1.0
  6.  
  7. ZBar.xml

Xml File
Lua Code:
  1. <Ui xmlns="http://www.blizzard.com/wow/ui/"
  2.                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3.                    xsi:schemaLocation="http://www.blizzard.com/wow/ui/
  4.                   ..\..\FrameXML\UI.xsd">
  5.     <frame name="barAWindow" parent="UIParent" moveable="true">
  6.         <Size x="800" y="300"/>
  7.             <Anchors>
  8.                 <Anchor point="CENTER">
  9.             </Anchors>
  10.             <Layers>
  11.                 <Layer level="BACKGROUND">
  12.                     <Texture file="ZBar\ZBarImgs\barA.tga" setAllPoints="true"/>
  13.                 </Layer>
  14.             </Layers>
  15.     <Scripts>
  16.         <OnMouseDown>
  17.             self:StartMoving()
  18.         </OnMouseDown>
  19.         <OnMouseUp>
  20.             self:StopMoving()
  21.         </OnMouseUp>
  22.     </Scripts>
  23.     </frame>
  24. </Ui>

My question for my code is simply "What am I missing and why do I need it?" please explain in full detail so I may learn more thoroughly.
Attached Files
File Type: zip ZBar.zip (176.6 KB, 193 views)
  Reply With Quote
11-22-14, 11:26 PM   #2
Zireko
An Aku'mai Servant
Join Date: Nov 2014
Posts: 38
Never Mind I figured out Most of it on my own. I'm still going to keep working on this if you would like to see my code now this is what I have and it made everything work correctly. I switched to using blp instead of a tga image.

XML
Lua Code:
  1. <Ui xmlns="http://www.blizzard.com/wow/ui/"
  2.                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3.                    xsi:schemaLocation="http://www.blizzard.com/wow/ui/
  4.                   ..\..\FrameXML\UI.xsd">
  5.     <Frame name="barAWindow" parent="UIParent" movable="true" alpha="0.8">
  6.         <Size x="1800" y="300"/>
  7.             <Anchors>
  8.                 <Anchor point="CENTER"/>
  9.             </Anchors>
  10.             <Layers>
  11.                 <Layer level="BACKGROUND">
  12.                     <Texture file="Interface\AddOns\ZBar\ZBarImgs\barA.blp" setAllPoints="true"/>
  13.                 </Layer>
  14.             </Layers>
  15.     <Scripts>
  16.         <OnMouseDown>
  17.             self:StartMoving()
  18.         </OnMouseDown>
  19.         <OnMouseUp>
  20.             self:StopMovingOrSizing()
  21.         </OnMouseUp>
  22.     </Scripts>
  23.     </Frame>
  24. </Ui>

I'll be adding more to this as I go a long and making the main anchor at the bottom of the screen and get rid of the self:StartMoving() function / scripts , I'm just using this to get a general idea of where my addon is before I anchor it down.
  Reply With Quote
11-23-14, 01:20 AM   #3
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Unless you're really in love with XML from some prior programming experience, I'd suggest writing your addon in Lua only. It's much less verbose, and reduces the need for you to learn two separate syntaxes:

Code:
local frame = CreateFrame("Frame", "barAWindow", UIParent)
frame:SetSize(1800, 300)
frame:SetPoint("CENTER")
frame:SetAlpha(0.8)

local bg = frame:CreateTexture(nil, "BACKGROUND")
bg:SetAllPoints(true)
bg:SetTexture("Interface\\AddOns\\ZBar\\ZBarImgs\\barA")

frame:SetMovable(true)
frame:SetScript("OnMouseDown", frame.StartMoving)
frame:SetScript("OnMouseUp", frame.StopMovingOrSizing)
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
11-23-14, 01:48 AM   #4
Zireko
An Aku'mai Servant
Join Date: Nov 2014
Posts: 38
Originally Posted by Phanx View Post
Unless you're really in love with XML from some prior programming experience, I'd suggest writing your addon in Lua only. It's much less verbose, and reduces the need for you to learn two separate syntaxes:
It's not that I'm more interested in xml. It's simply the fact most tutorials and information I find is in xml and not lua. I would really like it much more to do it in lua code strictly but most of the learning information focuses deeply on xml instead of lua. But I've got the code working pretty good right now however the mini map and chat window sometime fall behind my image that I'm using. I'm using <Layer level="BACKGROUND"> which I thought was the furthest background you can get but for some reasone when I move the mini map or chat system around my addon is layred infront of it and not in the deepst background. It would be helpfull if you could show me how to fix this in xml and how to code it in lua instead of xml. Here is my current xml code.

XML
Lua Code:
  1. <Ui xmlns="http://www.blizzard.com/wow/ui/"
  2.                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3.                    xsi:schemaLocation="http://www.blizzard.com/wow/ui/
  4.                   ..\..\FrameXML\UI.xsd">
  5.     <Frame name="barAWindow" parent="UIParent" movable="true" alpha="0.8">
  6.         <Size x="1800" y="300"/>
  7.             <Anchors>
  8.                 <Anchor point="CENTER"/>
  9.             </Anchors>
  10.             <Layers>
  11.                 <Layer level="BACKGROUND">
  12.                     <Texture file="Interface\AddOns\ZBar\ZBarImgs\barA.blp" setAllPoints="true"/>
  13.                 </Layer>
  14.             </Layers>
  15.     <Scripts>
  16.         <OnMouseDown>
  17.             self:StartMoving()
  18.         </OnMouseDown>
  19.         <OnMouseUp>
  20.             self:StopMovingOrSizing()
  21.         </OnMouseUp>
  22.     </Scripts>
  23.     </Frame>
  24. </Ui>
  Reply With Quote
11-23-14, 04:14 AM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
The Lua code I posted is a direct conversion of the XML code in your previous post.

Originally Posted by Zireko View Post
the mini map and chat window sometime fall behind my image that I'm using. I'm using <Layer level="BACKGROUND"> which I thought was the furthest background you can get but for some reasone when I move the mini map or chat system around my addon is layred infront of it and not in the deepst background.
You may want to read the Wowpedia page about layers. Draw layers only affect the relative layering of the regions attached to the same parent frame -- they don't affect whether one frame is drawn in front of or behind other frames. To change that, you need to change the strata of the frame itself.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
11-23-14, 12:37 PM   #6
Zireko
An Aku'mai Servant
Join Date: Nov 2014
Posts: 38
How do I lock a frame with right mouse click. I am trying to look it up but not finding anything yet. I want the user to be able to move the frame where they want it then they can right click or middle click to lock they frame in place so they don't accidently move it again afterwards. If they want to move it again the can right click or middle click the frame to unlock it. Here is the code I have currently and Phanx ty I forgot all about the frameStrata to push the frame to the furthest background.

XML
Lua Code:
  1. <Ui xmlns="http://www.blizzard.com/wow/ui/"
  2.                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3.                    xsi:schemaLocation="http://www.blizzard.com/wow/ui/
  4.                   ..\..\FrameXML\UI.xsd">
  5.     <Frame name="barAWindow" frameStrata="BACKGROUND" parent="UIParent" movable="true" alpha="0.8">
  6.         <Size x="600" y="300"/>
  7.             <Anchors>
  8.                 <Anchor point="BOTTOM"/>
  9.             </Anchors>
  10.             <Layers>
  11.                 <Layer level="BACKGROUND">
  12.                     <Texture file="Interface\AddOns\ZBar\ZBarImgs\barA.blp" setAllPoints="true"/>
  13.                 </Layer>
  14.             </Layers>
  15.     <Scripts>
  16.         <OnMouseDown>
  17.             self:StartMoving()
  18.         </OnMouseDown>
  19.         <OnMouseUp>
  20.             self:StopMovingOrSizing()
  21.         </OnMouseUp>
  22.     </Scripts>
  23.     </Frame>
  24. </Ui>
  Reply With Quote
11-23-14, 12:44 PM   #7
Clamsoda
A Frostmaul Preserver
Join Date: Nov 2011
Posts: 269
You're going to have a very hard time finding help with XML. Relying heavily on XML is discouraged for various reasons, and there is only one thing XML can do that pure LUA cannot: creating secure templates.

You could give your frame an OnClick script, that checks for the button, and toggle frame locking that way.


Lua Code:
  1. local frame = CreateFrame("Button", MyReallyNeatFrameName, UIParent)
  2.  
  3. frame:RegisterForClicks("AnyUp")
  4. frame:SetScript("OnClick", function(self, button, ...)
  5.     if (button == "RightButton" or "MiddleButton") then
  6.         -- Execute whatever method you'd choose for locking your frame.
  7.     end
  8. end)

Last edited by Clamsoda : 11-23-14 at 11:22 PM.
  Reply With Quote
11-23-14, 08:01 PM   #8
Zireko
An Aku'mai Servant
Join Date: Nov 2014
Posts: 38
I need some help figuring some of this out. I've got my button and a few things in place. I'm trying to teach myself how to more so create a frame in the lua now and trying to understand it a little more. But what I need help on is a few different things.

*I need the button to show and hide my Options frame when it's clicked.
*I need to figure out how to move text up to the top of the frame in the center.
*I need to add some check boxes for each window frame for when there checked they will show my other windows.
*I need to add another check boxes that when it's checked it locks each windows.

The windows I'm trying to hide/show and lock are in my xml.

Here is my code and I'll leave the attachment of the updated addon so far that I'm working on.

LUA Code

Lua Code:
  1. --Want to add Show Hide function for each window. ( barQWindow, barAWindow, barMWindow, barCWindow )
  2. --With the Show Hide I want to add this in an addon options window.
  3. --Want to add a lock frame for each window.
  4. --With lock frame I want to add this in an addon options window.
  5.  
  6. --Create a button using lua that pulls up a window for ZBar Options.
  7.  
  8. -- creates a generic button in the middle of the screen --
  9. ZBarButton = CreateFrame("Button","ZBarButton",UIParent,"UIPanelButtonTemplate")
  10. ZBarButton:SetPoint("CENTER",0,0)
  11. ZBarButton:SetWidth(30)
  12. ZBarButton:SetHeight(30)
  13. ZBarButton:SetText("ZB")
  14. ZBarButton:SetMovable(true)
  15. ZBarButton:RegisterForDrag("LeftButton")
  16. ZBarButton:SetScript("OnDragStart",ZBarButton.StartMoving)
  17. ZBarButton:SetScript("OnDragStop",ZBarButton.StopMovingOrSizing)
  18.  
  19. ZBarOptionFrame = CreateFrame("Frame")
  20. ZBarOptionFrame:ClearAllPoints()
  21. ZBarOptionFrame:SetBackdrop(StaticPopup1:GetBackdrop())
  22. ZBarOptionFrame:SetHeight(300)
  23. ZBarOptionFrame:SetWidth(300)
  24.  
  25. ZBarOptionFrame.text = ZBarOptionFrame:CreateFontString(nil, "BACKGROUND", "GameFontNormal")
  26. ZBarOptionFrame.text:SetAllPoints()
  27. ZBarOptionFrame.text:SetText("ZBar Options Verison 1.0")
  28. ZBarOptionFrame:SetPoint("CENTER", 0, 0)

XML

Lua Code:
  1. <Ui xmlns="http://www.blizzard.com/wow/ui/"
  2.                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3.                    xsi:schemaLocation="http://www.blizzard.com/wow/ui/
  4.                   ..\..\FrameXML\UI.xsd">
  5.     <Frame name="barQWindow" frameStrata="BACKGROUND" parent="UIParent" movable="true" alpha="0.8">
  6.         <Size x="300" y="900"/>
  7.             <Anchors>
  8.                 <Anchor point="BOTTOM"/>
  9.             </Anchors>
  10.             <Layers>
  11.                 <Layer level="BACKGROUND">
  12.                     <Texture file="Interface\AddOns\ZBar\ZBarImgs\barA.blp" setAllPoints="true"/>
  13.                 </Layer>
  14.             </Layers>
  15.     <Scripts>
  16.         <OnMouseDown>
  17.             self:StartMoving()
  18.         </OnMouseDown>
  19.         <OnMouseUp>
  20.             self:StopMovingOrSizing()
  21.         </OnMouseUp>
  22.     </Scripts>
  23.     </Frame>
  24.     <Frame name="barCWindow" frameStrata="BACKGROUND" parent="UIParent" movable="true" alpha="0.8">
  25.         <Size x="600" y="300"/>
  26.             <Anchors>
  27.                 <Anchor point="BOTTOM"/>
  28.             </Anchors>
  29.             <Layers>
  30.                 <Layer level="BACKGROUND">
  31.                     <Texture file="Interface\AddOns\ZBar\ZBarImgs\barA.blp" setAllPoints="true"/>
  32.                 </Layer>
  33.             </Layers>
  34.     <Scripts>
  35.         <OnMouseDown>
  36.             self:StartMoving()
  37.         </OnMouseDown>
  38.         <OnMouseUp>
  39.             self:StopMovingOrSizing()
  40.         </OnMouseUp>
  41.     </Scripts>
  42.     </Frame>
  43.     <Frame name="barMWindow" frameStrata="BACKGROUND" parent="UIParent" movable="true" alpha="0.8">
  44.         <Size x="600" y="300"/>
  45.             <Anchors>
  46.                 <Anchor point="BOTTOM"/>
  47.             </Anchors>
  48.             <Layers>
  49.                 <Layer level="BACKGROUND">
  50.                     <Texture file="Interface\AddOns\ZBar\ZBarImgs\barA.blp" setAllPoints="true"/>
  51.                 </Layer>
  52.             </Layers>
  53.     <Scripts>
  54.         <OnMouseDown>
  55.             self:StartMoving()
  56.         </OnMouseDown>
  57.         <OnMouseUp>
  58.             self:StopMovingOrSizing()
  59.         </OnMouseUp>
  60.     </Scripts>
  61.     </Frame>
  62.     <Frame name="barAWindow" frameStrata="BACKGROUND" parent="UIParent" movable="true" alpha="0.8">
  63.         <Size x="2000" y="300"/>
  64.             <Anchors>
  65.                 <Anchor point="BOTTOM"/>
  66.             </Anchors>
  67.             <Layers>
  68.                 <Layer level="BACKGROUND">
  69.                     <Texture file="Interface\AddOns\ZBar\ZBarImgs\barA.blp" setAllPoints="true"/>
  70.                 </Layer>
  71.             </Layers>
  72.     <Scripts>
  73.         <OnMouseDown>
  74.             self:StartMoving()
  75.         </OnMouseDown>
  76.         <OnMouseUp>
  77.             self:StopMovingOrSizing()
  78.         </OnMouseUp>
  79.     </Scripts>
  80.     </Frame>
  81. </Ui>

TOC

Lua Code:
  1. ## Interface: 60000
  2. ## Title: ZBar
  3. ## Notes: A simple skin addon that allows you to place your ui into it.
  4. ## Author: Zireko
  5. ## Version: 1.0
  6.  
  7. ZBar.xml
  8. ZBar.lua
Attached Files
File Type: zip ZBar.zip (38.6 KB, 157 views)
  Reply With Quote
11-24-14, 06:40 PM   #9
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
XML is just too unpleasant. I'll answer general questions but I'm just not going to read through or write any specific XML for you, sorry.

Originally Posted by Zireko View Post
I need the button to show and hide my Options frame when it's clicked.
Set an OnScript script on the button that checks if the options frame IsShown and then calls Hide or Show on it as needed.

Originally Posted by Zireko View Post
I need to figure out how to move text up to the top of the frame in the center.
Anchor your font string by its TOP point to the TOP point of the frame, with a negative Y offset if you need to move it down a little for spacing.

Originally Posted by Zireko View Post
I need to add some check boxes for each window frame for when there checked they will show my other windows.
Create a check button inheriting from the relevant Blizzard template, and give it an OnClick script that checks (lol) if it's GetChecked or not, and then Show or Hide the other window accordingly.

Originally Posted by Zireko View Post
I need to add another check boxes that when it's checked it locks each windows.
Same as above, but either toggle SetMouseEnabled on the desired frame or, if you need it to still catch the mouse but not be draggable, just modify its OnDragStart or OnMouseDown script (whichever you're using) to check whether it's locked (based on the value in your saved variables, or the state of the checkbox, or whatever you're using to keep track of that) and don't StartMoving it if it's locked.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
11-25-14, 03:06 PM   #10
Zireko
An Aku'mai Servant
Join Date: Nov 2014
Posts: 38
I've got this part working slightly but running into a problem. I have a checkbox and I'm trying to lock the frame. Problem is when you click the checkbox it locks the frame but when you un check the box it will not unlock my frame. I know it's in my function I'm just not sure what I'm doing wrong here.

LUA

Lua Code:
  1. barQWindowLockCheckButton = CreateFrame("CheckButton", "barQWindowLockCheckButton_GlobalName", ZBarOptionFrame, "ChatConfigCheckButtonTemplate");
  2. barQWindowLockCheckButton:SetPoint("TOPLEFT", 25, -145);
  3. barQWindowLockCheckButton_GlobalNameText:SetText("Frame 1 Lock");
  4. barQWindowLockCheckButton.tooltip = "This is will lock the frame in place.";
  5. barQWindowLockCheckButton:SetScript("OnClick",
  6.   function()
  7.     if barQWindow:SetMovable(true) then
  8.         barQWindow:SetMovable(true)
  9.     else
  10.         barQWindow:SetMovable(false)
  11.     end
  12.   end
  13. );

So can anyone tell me what I'm doing wrong here?
  Reply With Quote
11-25-14, 03:24 PM   #11
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
http://wowpedia.org/API_Frame_IsMovable
In line 7 you dont query the moveable state ... you set it which will always work.
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
11-25-14, 03:33 PM   #12
Zireko
An Aku'mai Servant
Join Date: Nov 2014
Posts: 38
Thank you I got it working correctly now. I just didn't know the IsMovable() that was all I was missing.
  Reply With Quote
11-25-14, 04:05 PM   #13
Zireko
An Aku'mai Servant
Join Date: Nov 2014
Posts: 38
Ok, I have my code working pretty good now. I just need to add in one last thing. I want it to save if someone selects to lock the frame from my checkboxes and if they select to hide it with the checkboxes.

So can someone explain to me the way I'll need to save variables like this with the wow api? The elder scrolls online saving is very different in a way I think.

Here is my full code currently.

LUA

Lua Code:
  1. --Want to add Show Hide function for each window. ( barQWindow, barAWindow, barMWindow, barCWindow )
  2. --With the Show Hide I want to add this in an addon options window.
  3. --Want to add a lock frame for each window.
  4. --With lock frame I want to add this in an addon options window.
  5.  
  6. --Create a button using lua that pulls up a window for ZBar Options.
  7.  
  8. -- creates a generic button in the middle of the screen --
  9. ZBarButton = CreateFrame("Button","ZBarButton",UIParent,"UIPanelButtonTemplate")
  10. ZBarButton:SetPoint("CENTER",0,0)
  11. ZBarButton:SetWidth(30)
  12. ZBarButton:SetHeight(30)
  13. ZBarButton:SetText("ZB")
  14. ZBarButton:SetMovable(true)
  15. ZBarButton:RegisterForDrag("LeftButton")
  16. ZBarButton:SetScript("OnDragStart",ZBarButton.StartMoving)
  17. ZBarButton:SetScript("OnDragStop",ZBarButton.StopMovingOrSizing)
  18.  
  19. ZBarOptionFrame = CreateFrame("Frame")
  20. ZBarOptionFrame:ClearAllPoints()
  21. ZBarOptionFrame:SetBackdrop(StaticPopup1:GetBackdrop())
  22. ZBarOptionFrame:SetHeight(300)
  23. ZBarOptionFrame:SetWidth(300)
  24. ZBarOptionFrame:Hide(true)
  25.  
  26. ZBarOptionFrame.text = ZBarOptionFrame:CreateFontString(nil, "BACKGROUND", "GameFontNormal")
  27. ZBarOptionFrame.text:SetPoint("CENTER", 0, 125)
  28. ZBarOptionFrame.text:SetText("ZBar Options Verison 1.0")
  29. ZBarOptionFrame:SetPoint("CENTER", 0, 0)
  30.  
  31. ZBarButton:RegisterForClicks("AnyUp")
  32. ZBarButton:SetScript("OnClick", function(self, button, ...)
  33.     if (button == "RightButton") then
  34.         if ZBarOptionFrame:IsShown() then
  35.             ZBarOptionFrame:Hide()
  36.         else
  37.             ZBarOptionFrame:Show()
  38.         end
  39.     end
  40. end)
  41.  
  42. -- My window Names are barQWindow (name frame 1), barCWindow (name frame 2), barMWindow (name frame 3), barAWindow (name frame 4)
  43.  
  44. --Frame 1 (barQWindow)
  45. barQWindowCheckButton = CreateFrame("CheckButton", "barQWindowCheckButton_GlobalName", ZBarOptionFrame, "ChatConfigCheckButtonTemplate");
  46. barQWindowCheckButton:SetPoint("TOPLEFT", 25, -65);
  47. barQWindowCheckButton_GlobalNameText:SetText("Frame 1 Hide");
  48. barQWindowCheckButton.tooltip = "This is will hide the frame.";
  49. barQWindowCheckButton:SetScript("OnClick",
  50.   function()
  51.     if barQWindow:IsShown() then
  52.         barQWindow:Hide()
  53.     else
  54.         barQWindow:Show()
  55.     end
  56.   end
  57. );
  58.  
  59. --Frame 2(barCWindow)
  60. barCWindowCheckButton = CreateFrame("CheckButton", "barCWindowCheckButton_GlobalName", ZBarOptionFrame, "ChatConfigCheckButtonTemplate");
  61. barCWindowCheckButton:SetPoint("TOPLEFT", 25, -85);
  62. barCWindowCheckButton_GlobalNameText:SetText("Frame 2 Hide");
  63. barCWindowCheckButton.tooltip = "This is will hide the frame.";
  64. barCWindowCheckButton:SetScript("OnClick",
  65.   function()
  66.     if barCWindow:IsShown() then
  67.         barCWindow:Hide()
  68.     else
  69.         barCWindow:Show()
  70.     end
  71.   end
  72. );
  73.  
  74. --Frame 3 (barMWindow)
  75. barMWindowCheckButton = CreateFrame("CheckButton", "barMWindowCheckButton_GlobalName", ZBarOptionFrame, "ChatConfigCheckButtonTemplate");
  76. barMWindowCheckButton:SetPoint("TOPLEFT", 25, -105);
  77. barMWindowCheckButton_GlobalNameText:SetText("Frame 3 Hide");
  78. barMWindowCheckButton.tooltip = "This is will hide the frame.";
  79. barMWindowCheckButton:SetScript("OnClick",
  80.   function()
  81.     if barMWindow:IsShown() then
  82.         barMWindow:Hide()
  83.     else
  84.         barMWindow:Show()
  85.     end
  86.   end
  87. );
  88.  
  89. --Frame 4 (barAWindow)
  90. barAWindowCheckButton = CreateFrame("CheckButton", "barAWindowCheckButton_GlobalName", ZBarOptionFrame, "ChatConfigCheckButtonTemplate");
  91. barAWindowCheckButton:SetPoint("TOPLEFT", 25, -125);
  92. barAWindowCheckButton_GlobalNameText:SetText("Frame 4 Hide");
  93. barAWindowCheckButton.tooltip = "This is will hide the frame.";
  94. barAWindowCheckButton:SetScript("OnClick",
  95.   function()
  96.     if barAWindow:IsShown() then
  97.         barAWindow:Hide()
  98.     else
  99.         barAWindow:Show()
  100.     end
  101.   end
  102. );
  103.  
  104. --This will be to lock the frame into place
  105.  
  106. --Frame 1 (barQWindow)
  107. barQWindowLockCheckButton = CreateFrame("CheckButton", "barQWindowLockCheckButton_GlobalName", ZBarOptionFrame, "ChatConfigCheckButtonTemplate");
  108. barQWindowLockCheckButton:SetPoint("TOPLEFT", 150, -65);
  109. barQWindowLockCheckButton_GlobalNameText:SetText("Frame 1 Lock");
  110. barQWindowLockCheckButton.tooltip = "This is will lock the frame in place.";
  111. barQWindowLockCheckButton:SetScript("OnClick",
  112.   function()
  113.     if barQWindow:IsMovable() then
  114.         barQWindow:SetMovable(false)
  115.     else
  116.         barQWindow:SetMovable(true)
  117.     end
  118.   end
  119. );
  120.  
  121. --Frame 2 (barCWindow)
  122. barCWindowLockCheckButton = CreateFrame("CheckButton", "barCWindowLockCheckButton_GlobalName", ZBarOptionFrame, "ChatConfigCheckButtonTemplate");
  123. barCWindowLockCheckButton:SetPoint("TOPLEFT", 150, -85);
  124. barCWindowLockCheckButton_GlobalNameText:SetText("Frame 2 Lock");
  125. barCWindowLockCheckButton.tooltip = "This is will lock the frame in place.";
  126. barCWindowLockCheckButton:SetScript("OnClick",
  127.   function()
  128.     if barCWindow:IsMovable() then
  129.         barCWindow:SetMovable(false)
  130.     else
  131.         barCWindow:SetMovable(true)
  132.     end
  133.   end
  134. );
  135.  
  136. --Frame 3 (barMWindow)
  137. barMWindowLockCheckButton = CreateFrame("CheckButton", "barMWindowLockCheckButton_GlobalName", ZBarOptionFrame, "ChatConfigCheckButtonTemplate");
  138. barMWindowLockCheckButton:SetPoint("TOPLEFT", 150, -105);
  139. barMWindowLockCheckButton_GlobalNameText:SetText("Frame 3 Lock");
  140. barMWindowLockCheckButton.tooltip = "This is will lock the frame in place.";
  141. barMWindowLockCheckButton:SetScript("OnClick",
  142.   function()
  143.     if barMWindow:IsMovable() then
  144.         barMWindow:SetMovable(false)
  145.     else
  146.         barMWindow:SetMovable(true)
  147.     end
  148.   end
  149. );
  150.  
  151. --Frame 4 (barMWindow)
  152. barAWindowLockCheckButton = CreateFrame("CheckButton", "barAWindowLockCheckButton_GlobalName", ZBarOptionFrame, "ChatConfigCheckButtonTemplate");
  153. barAWindowLockCheckButton:SetPoint("TOPLEFT", 150, -125);
  154. barAWindowLockCheckButton_GlobalNameText:SetText("Frame 4 Lock");
  155. barAWindowLockCheckButton.tooltip = "This is will lock the frame in place.";
  156. barAWindowLockCheckButton:SetScript("OnClick",
  157.   function()
  158.     if barAWindow:IsMovable() then
  159.         barAWindow:SetMovable(false)
  160.     else
  161.         barAWindow:SetMovable(true)
  162.     end
  163.   end
  164. );

XML

Lua Code:
  1. <Ui xmlns="http://www.blizzard.com/wow/ui/"
  2.                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3.                    xsi:schemaLocation="http://www.blizzard.com/wow/ui/
  4.                   ..\..\FrameXML\UI.xsd">
  5.     <Frame name="barQWindow" frameStrata="BACKGROUND" parent="UIParent" movable="true" alpha="0.8">
  6.         <Size x="300" y="900"/>
  7.             <Anchors>
  8.                 <Anchor point="BOTTOM"/>
  9.             </Anchors>
  10.             <Layers>
  11.                 <Layer level="BACKGROUND">
  12.                     <Texture file="Interface\AddOns\ZBar\ZBarImgs\barA.blp" setAllPoints="true"/>
  13.                 </Layer>
  14.             </Layers>
  15.     <Scripts>
  16.         <OnMouseDown>
  17.             self:StartMoving()
  18.         </OnMouseDown>
  19.         <OnMouseUp>
  20.             self:StopMovingOrSizing()
  21.         </OnMouseUp>
  22.     </Scripts>
  23.     </Frame>
  24.     <Frame name="barCWindow" frameStrata="BACKGROUND" parent="UIParent" movable="true" alpha="0.8">
  25.         <Size x="600" y="300"/>
  26.             <Anchors>
  27.                 <Anchor point="BOTTOM"/>
  28.             </Anchors>
  29.             <Layers>
  30.                 <Layer level="BACKGROUND">
  31.                     <Texture file="Interface\AddOns\ZBar\ZBarImgs\barA.blp" setAllPoints="true"/>
  32.                 </Layer>
  33.             </Layers>
  34.     <Scripts>
  35.         <OnMouseDown>
  36.             self:StartMoving()
  37.         </OnMouseDown>
  38.         <OnMouseUp>
  39.             self:StopMovingOrSizing()
  40.         </OnMouseUp>
  41.     </Scripts>
  42.     </Frame>
  43.     <Frame name="barMWindow" frameStrata="BACKGROUND" parent="UIParent" movable="true" alpha="0.8">
  44.         <Size x="600" y="300"/>
  45.             <Anchors>
  46.                 <Anchor point="BOTTOM"/>
  47.             </Anchors>
  48.             <Layers>
  49.                 <Layer level="BACKGROUND">
  50.                     <Texture file="Interface\AddOns\ZBar\ZBarImgs\barA.blp" setAllPoints="true"/>
  51.                 </Layer>
  52.             </Layers>
  53.     <Scripts>
  54.         <OnMouseDown>
  55.             self:StartMoving()
  56.         </OnMouseDown>
  57.         <OnMouseUp>
  58.             self:StopMovingOrSizing()
  59.         </OnMouseUp>
  60.     </Scripts>
  61.     </Frame>
  62.     <Frame name="barAWindow" frameStrata="BACKGROUND" parent="UIParent" movable="true" alpha="0.8">
  63.         <Size x="2000" y="300"/>
  64.             <Anchors>
  65.                 <Anchor point="BOTTOM"/>
  66.             </Anchors>
  67.             <Layers>
  68.                 <Layer level="BACKGROUND">
  69.                     <Texture file="Interface\AddOns\ZBar\ZBarImgs\barA.blp" setAllPoints="true"/>
  70.                 </Layer>
  71.             </Layers>
  72.     <Scripts>
  73.         <OnMouseDown>
  74.             self:StartMoving()
  75.         </OnMouseDown>
  76.         <OnMouseUp>
  77.             self:StopMovingOrSizing()
  78.         </OnMouseUp>
  79.     </Scripts>
  80.     </Frame>
  81. </Ui>

Toc

Lua Code:
  1. ## Interface: 60000
  2. ## Title: ZBar
  3. ## Notes: A simple skin addon that allows you to place your ui into it.
  4. ## Author: Zireko
  5. ## Version: 1.0
  6.  
  7. ZBar.xml
  8. ZBar.lua
  Reply With Quote
11-25-14, 06:22 PM   #14
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,322
Forum search works.
http://www.wowinterface.com/forums/s...aved+variables
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
11-25-14, 07:02 PM   #15
Zireko
An Aku'mai Servant
Join Date: Nov 2014
Posts: 38
I just read over the saved variables information you gave me. However could someone give me an example with just my first frame?

I've added this to my toc
## SavedVariables: QWindowHide, QWindowLock

I've added this to the top of my lua

Lua Code:
  1. local MasterZframe = CreateFrame("FRAME"); -- Need a frame to respond to events
  2. MasterZframe:RegisterEvent("ADDON_LOADED"); -- Fired when saved variables are loaded
  3. MasterZframe:RegisterEvent("PLAYER_LOGOUT"); -- Fired when about to log out

I've added this to the bottom of my lua

Lua Code:
  1. local function MasterZframe:OnEvent(event, arg1)
  2.     if event == "ADDON_LOADED" and arg1 == "ZBar" then
  3.        
  4.    
  5. end

I'm trying to understand what needs to go below (if event == "ADDON_LOADED")

I know it needs to save the hide and lock checkboxes. This is as far as I've gotten I'm just not sure how to save if they've clicked the checkbox or not.
  Reply With Quote
11-25-14, 08:23 PM   #16
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
If you're just using one variable per setting (which is a bad plan if you're going to have more than 2-3 settings, but fine for now) you don't need to do any initialization whatsoever. Just read and set the variables and don't worry about whether they exist or not; nil evaluates to false in Lua, so it doesn't matter if they exist or not.

Code:
frame:RegisterEvent("ADDON_LOADED")
frame:SetScript("OnEvent", function(self, event, arg1)
   if event == "ADDON_LOADED" and arg1 == "MyAddonName" then
   window:SetShown(not QWindowHide)
end)
Code:
checkbox:SetScript("OnClick", function(self)
   QWindowHide = self:IsChecked()
   window:SetShown(not QWindowHide)
end)
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
11-25-14, 08:47 PM   #17
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,322
It's actually suggested that you have a table of values saved instead of a saved variable for each one. This will reduce the exposure of your addon to the global namespace. The reason keeping the variable scope of your addon tight is important is not only because using locals is faster than globals, but without careful naming of your globals can cause a lot of problems and even break your addon (and others) due to what is known as global leaks.

With that out of the way, here's an example of using a saved configuration table.
Note: This melds the ability of saved variables with the performance of a local.

ToC:
Code:
##Interface: 60000
##Title: MyAddon
##Notes: Description
##SavedVariables: MyAddonConfig
Lua Code:
  1. local Name=...;--   This will retrieve our Addon ID
  2.  
  3. --  Default configuration
  4. local Config={--    This will be our upvalue where we're going to access our configuration table
  5.     QWindowVisible=true;
  6.     QWindowEnabled=true;
  7. }
  8. MyAddonConfig=Config;-- We'll load our default into the global pointed to by our ToC
  9.  
  10. local MyFrame=CreateFrame("Frame");
  11. MyFrame:RegisterEvent("ADDON_LOADED");
  12. MyFrame:SetScript("OnEvent",function(self,event,...)
  13.     if event=="ADDON_LOADED" and (...)==Name then-- Check if our addon is the one that loaded
  14. --      If there is any saved data, it'll overwrite whatever is in the global
  15.         Config=MyAddonConfig;-- Resync upvalue to saved data (defaults will remain if no data loaded)
  16.  
  17. --      Now we can use our Config upvalue as if it were our saved variable
  18.         MyAddonQWindow:SetShown(Config.QWindowVisible);
  19.         MyAddonQWindow:EnableMouse(Config.QWindowEnabled);
  20.  
  21.         self:UnregisterEvent("ADDON_LOADED");-- We no longer need this event, unregister it
  22.     end
  23. end);
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
11-25-14, 09:00 PM   #18
Zireko
An Aku'mai Servant
Join Date: Nov 2014
Posts: 38
By any chance is there a good youtube video that teaches how to do saved variables? This seems to be a weak point for me because I'm just really seeming to not understand how to do them. I've tried to put the code together using what you all have said so far yet it's still not saving yet.

I'm attaching my addon so if anyone can help me understand what I'm doing wrong you can freely see all the code I have currently.
Attached Files
File Type: zip ZBar.zip (39.4 KB, 165 views)
  Reply With Quote
11-25-14, 09:08 PM   #19
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Did you read this?
http://wowpedia.org/Saving_variables..._game_sessions

/edit: saved variables work this exact same way in ESO, too - no need to use their wrapper API for it.
__________________
"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
11-25-14, 10:06 PM   #20
Zireko
An Aku'mai Servant
Join Date: Nov 2014
Posts: 38
I've read the wowpedia over and over and over again lol. Still trying to understand how to do the saved variables. If I remember correctly I also had a very hard time with them when I was working on my addons I did in ESO. I'm still working at it though.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » I Need some Help On an Addon I'm working On

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