Thread Tools Display Modes
Prev Previous Post   Next Post Next
02-12-16, 12:57 PM   #1
tyroneexe
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Feb 2016
Posts: 13
Question Movable frame with buttons inside (lua)

I'm trying to make a small addon (my first time) and I'm very new to coding - did some html when the internet was young, but that's kinda it.

The addon: The addon is meant to help people lead in Ashran. Sending simple commands to the raid via the click of a button (for testing purposes it's set to "SAY" for now. The addon is not meant to provide any information about the flow of battle, AshranBuddy does that just fine.

What is working? After a crashcourse in lua and scavaging code from this site and others, I've managed to make the buttons. They function as they should and are arranged in relation to eachother the way I want them to. The mouseover tooltip also works.

What the current issue? The wall I've hit now is getting the buttons to be inside a frame and make the frame (with buttons ofc) movable. I've tried moving the frame part of the code around, but that results in nothing showing or only the frame. I've tried getting the buttons to have the frame as parent and hope they would align, but nothing has worked.
I've also tried to only have the frame to see if I could move it, but again my skills feel short. The books I've found use XML in their example addons for the frame and movable frame parts, but I don't think it should be nessesary for such a simple addon.

What next? Once the frame is movable and the buttons aligned inside the frame, I want to make sure it remembers where the user has placed the addon after relog/reload.

Next is making the frame hide when not in Ashran

Afterwards try to allow the user to resize the addon and ofcourse have the addon remember the size the user has set.

Lua Code:
  1. local CreateButton; do-- Prototype for function
  2. --  Tooltip Handlers
  3.     local function OnEnter(self)
  4.         if self.Tooltip then
  5.             GameTooltip:SetOwner(self,"ANCHOR_TOP");
  6.             GameTooltip:AddLine(self.Tooltip,0,1,0.5,1,1,1);
  7.             GameTooltip:Show();
  8.         end
  9.     end
  10.     local function OnLeave(self) if GameTooltip:IsOwned(self) then GameTooltip:Hide(); end end
  11.  
  12. --  Button Generator (this will be assigned to the upvalue noted as a function prototype)
  13.     function CreateButton(parent,name,texture,text,tooltip)
  14.         tooltip=tooltip or text;--  If no tooltip, use button text
  15.  
  16. --      Create our button
  17.         local btn=CreateFrame("Button",name,parent,"SecureActionButtonTemplate");
  18.         btn:RegisterForClicks("AnyUp");--   Register all buttons
  19.         btn:SetSize(30,30);
  20.  
  21. --      Setup button text
  22.         btn:SetNormalFontObject("GameFontNormalSmall");
  23.         btn:SetHighlightFontObject("GameFontHighlightSmall");
  24.         btn:SetDisabledFontObject("GameFontDisableSmall");
  25.         btn:SetText(text);
  26.  
  27. --      Setup button's backgorund, you can use :SetNormalTexture() and other functions to set state-based textures
  28.         local tex=btn:CreateTexture(nil,"BACKGROUND");
  29.         tex:SetAllPoints(btn);
  30.         tex:SetTexture(texture);
  31.         btn.Texture=tex;
  32.  
  33. --      Register handlers
  34.         btn:SetScript("OnEnter",OnEnter);
  35.         btn:SetScript("OnLeave",OnLeave);
  36.         btn.Tooltip=tooltip;
  37.  
  38. --      Return our button
  39.         return btn;
  40.     end
  41. end
  42.  
  43. local button=CreateButton(AshranCommander,"AshranCommanderButton1","Interface\\Icons\\achievement_pvp_a_h",nil,"Warspear Keep");
  44. button:SetPoint("TOPRIGHT",ACFrame,"CENTER",13,-13);-- Anchors always default to an object's parent
  45. button:SetScript("OnClick", function()
  46.          SendChatMessage("Warspear Keep ","SAY")
  47.          DoEmote("follow")
  48.     end )
  49. local button=CreateButton(AshranCommander,"AshranCommanderButton2","Interface\\Icons\\achievement_garrison_tier02_horde",nil,"Emberfall Tower");
  50. button:SetPoint("TOP",AshranCommanderButton1,"BOTTOM",0,-1);-- Anchors always default to an object's parent
  51. button:SetScript("OnClick", function()
  52.          SendChatMessage("Emberfall Tower ","SAY")
  53.          DoEmote("follow" , UnitName("target"))
  54.     end )
  55. local button=CreateButton(AshranCommander,"AshranCommanderButton3","Interface\\Icons\\achievement_garrison_tier01_horde",nil,"Volrath's Advance");
  56. button:SetPoint("TOP",AshranCommanderButton2,"BOTTOM",0,-1);-- Anchors always default to an object's parent
  57. button:SetScript("OnClick", function()
  58.          SendChatMessage("Volrath's Advance ","SAY")
  59.          DoEmote("follow" , UnitName("target"))
  60.     end )
  61. local button=CreateButton(AshranCommander,"AshranCommanderButton4","Interface\\Icons\\achievement_doublejeopardy",nil,"The Crossroads");
  62. button:SetPoint("TOP",AshranCommanderButton3,"BOTTOM",0,-1);-- Anchors always default to an object's parent
  63. button:SetScript("OnClick", function()
  64.          SendChatMessage("The Crossroads ","SAY")
  65.          DoEmote("follow" , UnitName("target"))
  66.     end )
  67. local button=CreateButton(AshranCommander,"AshranCommanderButton5","Interface\\Icons\\achievement_garrison_tier01_alliance",nil,"Tremblade's Vanguard");
  68. button:SetPoint("TOP",AshranCommanderButton4,"BOTTOM",0,-1);-- Anchors always default to an object's parent
  69. button:SetScript("OnClick", function()
  70.          SendChatMessage("Tremblade's Vanguard ","SAY")
  71.          DoEmote("follow" , UnitName("target"))
  72.     end )
  73. local button=CreateButton(AshranCommander,"AshranCommanderButton6","Interface\\Icons\\achievement_garrison_tier02_alliance",nil,"Archmage Overwatch");
  74. button:SetPoint("TOP",AshranCommanderButton5,"BOTTOM",0,-1);-- Anchors always default to an object's parent
  75. button:SetScript("OnClick", function()
  76.          SendChatMessage("Archmage Overwatch ","SAY")
  77.          DoEmote("follow" , UnitName("target"))
  78.     end )
  79. local button=CreateButton(AshranCommander,"AshranCommanderButton7","Interface\\Icons\\achievement_pvp_h_a",nil,"Stormshield Stronghold");
  80. button:SetPoint("TOP",AshranCommanderButton6,"BOTTOM",0,-1);-- Anchors always default to an object's parent
  81. button:SetScript("OnClick", function()
  82.          SendChatMessage("Stormshield Stronghold ","SAY")
  83.          DoEmote("follow" , UnitName("target"))
  84.     end )
  85. local button=CreateButton(AshranCommander,"AshranCommanderButton8","Interface\\Icons\\Ability_rogue_sprint",nil,"Amphitheater of Annihilation(AoA)");
  86. button:SetPoint("RIGHT",AshranCommanderButton1,"LEFT",0,0);-- Anchors always default to an object's parent
  87. button:SetScript("OnClick", function()
  88.          SendChatMessage("AoA - EVENT:STADIUM RACING - Block the entrance!","SAY")
  89.          DoEmote("follow" , UnitName("target"))
  90.     end )
  91. local button=CreateButton(AshranCommander,"AshranCommanderButton9","Interface\\Icons\\spell_fire_fire",nil,"Brute's Rise(BR)");
  92. button:SetPoint("RIGHT",AshranCommanderButton2,"LEFT",0,0);-- Anchors always default to an object's parent
  93. button:SetScript("OnClick", function()
  94.          SendChatMessage("BR - EVENT:OGRE FIRES - Block the stairs! ","SAY")
  95.          DoEmote("follow" , UnitName("target"))
  96.     end )
  97. local button=CreateButton(AshranCommander,"AshranCommanderButton10","Interface\\Icons\\achievement_boss_furyfurnace",nil,"Ring of Conquest(RoC)");
  98. button:SetPoint("RIGHT",AshranCommanderButton3,"LEFT",0,0);-- Anchors always default to an object's parent
  99. button:SetScript("OnClick", function()
  100.          SendChatMessage("Ring of Conquest GO RoC ","SAY")
  101.          DoEmote("follow" , UnitName("target"))
  102.     end )
  103. local button=CreateButton(AshranCommander,"AshranCommanderButton11","Interface\\Icons\\Trade_archaeology_apexisstatue",nil,"Ashran Excavation(Mines)");
  104. button:SetPoint("RIGHT",AshranCommanderButton4,"LEFT",0,0);-- Anchors always default to an object's parent
  105. button:SetScript("OnClick", function()
  106.          SendChatMessage("Ashran Excavation - EVENT:APEXIS MARKS - Secure the center!  ","SAY")
  107.          DoEmote("follow" , UnitName("target"))
  108.     end )
  109. local button=CreateButton(AshranCommander,"AshranCommanderButton12","Interface\\Icons\\achievement_reputation_ogre",nil,"Seat of Kor'lok");
  110. button:SetPoint("RIGHT",AshranCommanderButton5,"LEFT",0,0);-- Anchors always default to an object's parent
  111. button:SetScript("OnClick", function()
  112.          SendChatMessage("Seat of Kor'lok - Kor'lok - Kill the ogre!  ","SAY")
  113.          DoEmote("follow" , UnitName("target"))
  114.     end )
  115. local button=CreateButton(AshranCommander,"AshranCommanderButton13","Interface\\Icons\\Spell_lifegivingspeed",nil,"Molten Quarry(MQ)");
  116. button:SetPoint("RIGHT",AshranCommanderButton6,"LEFT",0,0);-- Anchors always default to an object's parent
  117. button:SetScript("OnClick", function()
  118.          SendChatMessage("Molten Quarry - EVENT:Empowered Ore - Block the entrance!  ","SAY")
  119.          DoEmote("follow" , UnitName("target"))
  120.     end )
  121. local button=CreateButton(AshranCommander,"AshranCommanderButton14","Interface\\Icons\\Achievement_halloween_ghost_01",nil,"Ashmaul Burial Grounds(ABG)");
  122. button:SetPoint("RIGHT",AshranCommanderButton7,"LEFT",0,0);-- Anchors always default to an object's parent
  123. button:SetScript("OnClick", function()
  124.          SendChatMessage("Ashmaul Burial Grounds - EVENT:RISEN SPIRITS - Clear the center and block the entrance!  ","SAY")
  125.          DoEmote("follow" , UnitName("target"))
  126.     end )
  127.  
  128. local frame = CreateFrame("Frame","ACFrame",UIParent)
  129. frame:SetWidth(40+40+20)
  130. frame:SetHeight((7*40)+20)
  131. frame:ClearAllPoints()
  132. frame:SetBackdrop(StaticPopup1:GetBackdrop())
  133. frame:SetPoint("CENTER",UIParent)
  134. frame:SetScale(scale)
  135. frame:Show()
  136. frame:SetMovable(movable)
  137. frame:StartMoving()
  138. frame:StopMovingOrSizing()

toc Code:
  1. ## Interface: 60200
  2. ## Title: AshranCommander
  3. ## Version: <VERSION>
  4. ## Author: Tyroneexe
  5. ## Dependencies:
  6. ## Notes: First test
  7. ## DefaultState: enabled
  8. ## SavedVariables: AshranCommander_Text
  9.  
  10. AshranCommander.lua
Attached Thumbnails
Click image for larger version

Name:	WoWScrnShot_021216_194549.jpg
Views:	315
Size:	1.53 MB
ID:	8693  
Attached Files
File Type: lua AshranCommander.lua (7.5 KB, 113 views)
  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » Movable frame with buttons inside (lua)


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