|
02-12-16, 12:57 PM | #1 |
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:
toc Code:
|
|
02-12-16, 01:20 PM | #2 |
Ok, am not an expert but will try to help (a bit).
First of all, if you want to have the buttons inside the frame (as achild) you have to create them using the frames name as the parent. Since the frame is called "ACFrame", you have to use that name So instead of using Lua Code:
Use Lua Code:
But as I said, I am no expert. There are people with vastly more knowlegde of lua, its quite possible they have better way.
__________________
Better to fail then never have tried at all. |
|
02-12-16, 01:21 PM | #3 |
As far as I can see, AshranCommander hasn't been defined anywhere (it's not automatically create with the addon) so all the buttons are being parented to nil.
You should create your frame first and name it AshranCommander and then all the buttons will be parented to the frame. Edit: If you leave the frame creation at the end where it currently is, the buttons will still be parented to nil as the frame won't exist.
__________________
Fizzlemizz Maintainer of Discord Unit Frames and Discord Art. Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus. Last edited by Fizzlemizz : 02-12-16 at 01:28 PM. |
|
02-12-16, 01:21 PM | #4 |
You're setting the button's parent as AshranCommander, but the name you gave your frame is ACFrame.
/edit: Yukyuk beat me. /edit2: except Yukyuk accidentally told you to put ACFrame in quotes when calling your CreateButton function. |
|
02-12-16, 01:44 PM | #5 | |
Start with these answers first and we will help you wtih the other problems later.
__________________
Better to fail then never have tried at all. |
||
02-12-16, 01:56 PM | #6 |
I moved the frame to the top and renamed it (i hope it's the right spot) - This now shows the frame, unmovable, but not the buttons.
Am I missing something after frame:StopMovingOrSizing() ? func? Lua Code:
|
|
02-12-16, 02:02 PM | #7 | |
Here's some points I need to address before moving on:
The "parent" of a frame refers to another frame that it shares its visibility, scale, and other attributes with. For example, you have one frame representing a dialog box, and another representing a button. Normally, the button would have its parent set to the dialog box so when you show and hide the box, the button would respond accordingly and show or hide itself as well. ACFrame is defined at the bottom, which isn't useful at all. Lua and other programming languages execute code in top-down order. When you reference ACFrame, Lua doesn't know what it is yet and attempts to find a global with that name. At this time, it's simply nil. When Frame:SetPoint() gets this, it positions relative to the screen itself instead of the frame you're creating later. To start, let's rearrange the code so we can get things to work: This can stay where it is. The function only reacts to what's passed to it. Drag handlers registered to move parent. Button:SetNormalTexture() was used to show each icon. Lua Code:
The frame definition is moved here so the code below can use it. Proper registration for dragging has been implemented. New frames are always shown and have no anchors, so Frame:Show() and Frame:ClearAllPoints() respectively are unnecessary. Frame:SetSize() replaces both Frame:SetWidth() and Frame:SetHeight(). Frame:SetScale() was removed as you were sending nil to it and Frame:SetMovable() was properly set. Lua Code:
The following is slightly modified to use the frame pointer stored in frame immediately above. Layout was corrected to fit nicely within frame. Lua Code:
There is more that can be done to optimize the code like creating a layout table and using that in a loop to create your buttons, but for now, this'll do.
__________________
WoWInterface AddOns
Last edited by SDPhantom : 02-12-16 at 02:49 PM. |
||
02-12-16, 02:13 PM | #8 |
A debugger would also help. If you install BugGrabber and either Bugger or BugSack you will find your coding life greatly enhanced.
__________________
Fizzlemizz Maintainer of Discord Unit Frames and Discord Art. Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus. |
|
02-12-16, 02:42 PM | #9 |
There were a couple of other problems so this is the full code.
Code:
local CreateButton; do-- Prototype for function -- Tooltip Handlers local function OnEnter(self) if self.Tooltip then GameTooltip:SetOwner(self,"ANCHOR_TOP"); GameTooltip:AddLine(self.Tooltip,0,1,0.5,1,1,1); GameTooltip:Show(); end end local function OnLeave(self) if GameTooltip:IsOwned(self) then GameTooltip:Hide(); end end -- Button Generator (this will be assigned to the upvalue noted as a function prototype) function CreateButton(parent,name,texture,text,tooltip) tooltip=tooltip or text;-- If no tooltip, use button text -- Create our button local btn=CreateFrame("Button",name,parent,"SecureActionButtonTemplate"); btn:RegisterForClicks("AnyUp");-- Register all buttons btn:SetSize(30,30); -- Setup button text btn:SetNormalFontObject("GameFontNormalSmall"); btn:SetHighlightFontObject("GameFontHighlightSmall"); btn:SetDisabledFontObject("GameFontDisableSmall"); btn:SetText(text); -- Setup button's backgorund, you can use :SetNormalTexture() and other functions to set state-based textures local tex=btn:CreateTexture(nil,"BACKGROUND"); tex:SetAllPoints(btn); tex:SetTexture(texture); btn.Texture=tex; -- Register handlers btn:SetScript("OnEnter",OnEnter); btn:SetScript("OnLeave",OnLeave); btn.Tooltip=tooltip; -- Return our button return btn; end end local frame = CreateFrame("Button","ACFrame",UIParent) frame:SetPoint("CENTER",UIParent) frame:SetSize(40+40+20,(7*40)+20) frame:SetBackdrop(StaticPopup1:GetBackdrop()) frame:SetMovable(true) frame:RegisterForDrag("LeftButton")-- Register left button for dragging frame:SetScript("OnDragStart", function(self) self:StartMoving() end)-- Set script for drag start frame:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)-- Set script for drag stop local button=CreateButton(frame,"AshranCommanderButton1","Interface\\Icons\\achievement_pvp_a_h",nil,"Warspear Keep"); button:SetPoint("TOPRIGHT",frame,"TOPRIGHT",-13,-13);-- Anchors always default to an object's parent button:SetScript("OnClick", function() SendChatMessage("Warspear Keep ","SAY") DoEmote("follow") end ) local button=CreateButton(frame,"AshranCommanderButton2","Interface\\Icons\\achievement_garrison_tier02_horde",nil,"Emberfall Tower"); button:SetPoint("TOP",AshranCommanderButton1,"BOTTOM",0,-1);-- Anchors always default to an object's parent button:SetScript("OnClick", function() SendChatMessage("Emberfall Tower ","SAY") DoEmote("follow" , UnitName("target")) end ) local button=CreateButton(frame,"AshranCommanderButton3","Interface\\Icons\\achievement_garrison_tier01_horde",nil,"Volrath's Advance"); button:SetPoint("TOP",AshranCommanderButton2,"BOTTOM",0,-1);-- Anchors always default to an object's parent button:SetScript("OnClick", function() SendChatMessage("Volrath's Advance ","SAY") DoEmote("follow" , UnitName("target")) end ) local button=CreateButton(frame,"AshranCommanderButton4","Interface\\Icons\\achievement_doublejeopardy",nil,"The Crossroads"); button:SetPoint("TOP",AshranCommanderButton3,"BOTTOM",0,-1);-- Anchors always default to an object's parent button:SetScript("OnClick", function() SendChatMessage("The Crossroads ","SAY") DoEmote("follow" , UnitName("target")) end ) local button=CreateButton(frame,"AshranCommanderButton5","Interface\\Icons\\achievement_garrison_tier01_alliance",nil,"Tremblade's Vanguard"); button:SetPoint("TOP",AshranCommanderButton4,"BOTTOM",0,-1);-- Anchors always default to an object's parent button:SetScript("OnClick", function() SendChatMessage("Tremblade's Vanguard ","SAY") DoEmote("follow" , UnitName("target")) end ) local button=CreateButton(frame,"AshranCommanderButton6","Interface\\Icons\\achievement_garrison_tier02_alliance",nil,"Archmage Overwatch"); button:SetPoint("TOP",AshranCommanderButton5,"BOTTOM",0,-1);-- Anchors always default to an object's parent button:SetScript("OnClick", function() SendChatMessage("Archmage Overwatch ","SAY") DoEmote("follow" , UnitName("target")) end ) local button=CreateButton(frame,"AshranCommanderButton7","Interface\\Icons\\achievement_pvp_h_a",nil,"Stormshield Stronghold"); button:SetPoint("TOP",AshranCommanderButton6,"BOTTOM",0,-1);-- Anchors always default to an object's parent button:SetScript("OnClick", function() SendChatMessage("Stormshield Stronghold ","SAY") DoEmote("follow" , UnitName("target")) end ) local button=CreateButton(frame,"AshranCommanderButton8","Interface\\Icons\\Ability_rogue_sprint",nil,"Amphitheater of Annihilation(AoA)"); button:SetPoint("RIGHT",AshranCommanderButton1,"LEFT",0,0);-- Anchors always default to an object's parent button:SetScript("OnClick", function() SendChatMessage("AoA - EVENT:STADIUM RACING - Block the entrance!","SAY") DoEmote("follow" , UnitName("target")) end ) local button=CreateButton(frame,"AshranCommanderButton9","Interface\\Icons\\spell_fire_fire",nil,"Brute's Rise(BR)"); button:SetPoint("RIGHT",AshranCommanderButton2,"LEFT",0,0);-- Anchors always default to an object's parent button:SetScript("OnClick", function() SendChatMessage("BR - EVENT:OGRE FIRES - Block the stairs! ","SAY") DoEmote("follow" , UnitName("target")) end ) local button=CreateButton(frame,"AshranCommanderButton10","Interface\\Icons\\achievement_boss_furyfurnace",nil,"Ring of Conquest(RoC)"); button:SetPoint("RIGHT",AshranCommanderButton3,"LEFT",0,0);-- Anchors always default to an object's parent button:SetScript("OnClick", function() SendChatMessage("Ring of Conquest GO RoC ","SAY") DoEmote("follow" , UnitName("target")) end ) local button=CreateButton(frame,"AshranCommanderButton11","Interface\\Icons\\Trade_archaeology_apexisstatue",nil,"Ashran Excavation(Mines)"); button:SetPoint("RIGHT",AshranCommanderButton4,"LEFT",0,0);-- Anchors always default to an object's parent button:SetScript("OnClick", function() SendChatMessage("Ashran Excavation - EVENT:APEXIS MARKS - Secure the center! ","SAY") DoEmote("follow" , UnitName("target")) end ) local button=CreateButton(frame,"AshranCommanderButton12","Interface\\Icons\\achievement_reputation_ogre",nil,"Seat of Kor'lok"); button:SetPoint("RIGHT",AshranCommanderButton5,"LEFT",0,0);-- Anchors always default to an object's parent button:SetScript("OnClick", function() SendChatMessage("Seat of Kor'lok - Kor'lok - Kill the ogre! ","SAY") DoEmote("follow" , UnitName("target")) end ) local button=CreateButton(frame,"AshranCommanderButton13","Interface\\Icons\\Spell_lifegivingspeed",nil,"Molten Quarry(MQ)"); button:SetPoint("RIGHT",AshranCommanderButton6,"LEFT",0,0);-- Anchors always default to an object's parent button:SetScript("OnClick", function() SendChatMessage("Molten Quarry - EVENT:Empowered Ore - Block the entrance! ","SAY") DoEmote("follow" , UnitName("target")) end ) local button=CreateButton(frame,"AshranCommanderButton14","Interface\\Icons\\Achievement_halloween_ghost_01",nil,"Ashmaul Burial Grounds(ABG)"); button:SetPoint("RIGHT",AshranCommanderButton7,"LEFT",0,0);-- Anchors always default to an object's parent button:SetScript("OnClick", function() SendChatMessage("Ashmaul Burial Grounds - EVENT:RISEN SPIRITS - Clear the center and block the entrance! ","SAY") DoEmote("follow" , UnitName("target")) end )
__________________
Fizzlemizz Maintainer of Discord Unit Frames and Discord Art. Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus. |
|
02-12-16, 02:53 PM | #10 | |
I've been doing micro-edits on mine. Finished enabling dragging on the main frame, set buttons to drag parent, corrected layout issues, etc. I think I'm done now minus the horrendous button layout code.
__________________
WoWInterface AddOns
|
||
02-12-16, 02:59 PM | #11 |
Thank you guys/girls so much. It's working now and with the cleanup SDPhantom gave it, !buggrabber (ty FizzleMizz) stopped complaining.
EDIT: I should specify what is working. The buttons are now movable and with them the frame. I also changed the first button to align to the frames TOPRIGHT instead Lua Code:
Looking at it, I'm thinking if there's a better way to size the frame based on the button size or vice-versa. Mess with Lua Code:
Lua Code:
Tried changing "40+40" to SecureActionButtonTemplate, hoping it would act similar to Lua Code:
but no, that was not the way Current complete Lua Lua Code:
Last edited by tyroneexe : 02-12-16 at 03:10 PM. Reason: specify what's working |
|
WoWInterface » Developer Discussions » Lua/XML Help » Movable frame with buttons inside (lua) |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Switch to Linear Mode |
Hybrid Mode |
Switch to Threaded Mode |
|
|