Thread Tools Display Modes
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:	307
Size:	1.53 MB
ID:	8693  
Attached Files
File Type: lua AshranCommander.lua (7.5 KB, 110 views)
  Reply With Quote
02-12-16, 01:20 PM   #2
Yukyuk
A Chromatic Dragonspawn
 
Yukyuk's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2015
Posts: 179
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:
  1. local button=CreateButton(AshranCommander,"AshranCommanderButton2","Interface\\Icons\\achievement_garrison_tier02_horde",nil,"Emberfall Tower");

Use

Lua Code:
  1. local button=CreateButton("ACFrame","AshranCommanderButton2","Interface\\Icons\\achievement_garrison_tier02_horde",nil,"Emberfall Tower");

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.
  Reply With Quote
02-12-16, 01:21 PM   #3
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,857
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.
  Reply With Quote
02-12-16, 01:21 PM   #4
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
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.
__________________
"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
02-12-16, 01:44 PM   #5
Yukyuk
A Chromatic Dragonspawn
 
Yukyuk's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2015
Posts: 179
/edit2: except Yukyuk accidentally told you to put ACFrame in quotes when calling your CreateButton function.
Seerah is right of course

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

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:
  1. local frame = CreateFrame("Frame","ACFrame",UIParent)
  2. frame:SetPoint("CENTER",UIParent)
  3. frame:SetSize(30+30+20,(7*30)+20)
  4. frame:SetBackdrop(StaticPopup1:GetBackdrop())
  5.  
  6. frame:SetMovable(true)
  7. frame:EnableMouse(true)--   Receive mouse events (Buttons automatically have this set)
  8. frame:RegisterForDrag("LeftButton")--   Register left button for dragging
  9. frame:SetScript("OnDragStart",frame.StartMoving)--  Set script for drag start
  10. frame:SetScript("OnDragStop",frame.StopMovingOrSizing)--    Set script for drag stop

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:
  1. local button=CreateButton(frame,"AshranCommanderButton1","Interface\\Icons\\achievement_pvp_a_h",nil,"Warspear Keep");
  2. button:SetPoint("TOPRIGHT",-10,-10);-- Anchors always default to an object's parent
  3. button:SetScript("OnClick", function()
  4.     SendChatMessage("Warspear Keep ","SAY")
  5.     DoEmote("follow")
  6. end )
  7. local button=CreateButton(frame,"AshranCommanderButton2","Interface\\Icons\\achievement_garrison_tier02_horde",nil,"Emberfall Tower");
  8. button:SetPoint("TOP",AshranCommanderButton1,"BOTTOM");-- Anchors always default to an object's parent
  9. button:SetScript("OnClick", function()
  10.     SendChatMessage("Emberfall Tower ","SAY")
  11.     DoEmote("follow" , UnitName("target"))
  12. end )
  13. local button=CreateButton(frame,"AshranCommanderButton3","Interface\\Icons\\achievement_garrison_tier01_horde",nil,"Volrath's Advance");
  14. button:SetPoint("TOP",AshranCommanderButton2,"BOTTOM");-- Anchors always default to an object's parent
  15. button:SetScript("OnClick", function()
  16.     SendChatMessage("Volrath's Advance ","SAY")
  17.     DoEmote("follow" , UnitName("target"))
  18. end )
  19. local button=CreateButton(frame,"AshranCommanderButton4","Interface\\Icons\\achievement_doublejeopardy",nil,"The Crossroads");
  20. button:SetPoint("TOP",AshranCommanderButton3,"BOTTOM");-- Anchors always default to an object's parent
  21. button:SetScript("OnClick", function()
  22.     SendChatMessage("The Crossroads ","SAY")
  23.     DoEmote("follow" , UnitName("target"))
  24. end )
  25. local button=CreateButton(frame,"AshranCommanderButton5","Interface\\Icons\\achievement_garrison_tier01_alliance",nil,"Tremblade's Vanguard");
  26. button:SetPoint("TOP",AshranCommanderButton4,"BOTTOM");-- Anchors always default to an object's parent
  27. button:SetScript("OnClick", function()
  28.     SendChatMessage("Tremblade's Vanguard ","SAY")
  29.     DoEmote("follow" , UnitName("target"))
  30. end )
  31. local button=CreateButton(frame,"AshranCommanderButton6","Interface\\Icons\\achievement_garrison_tier02_alliance",nil,"Archmage Overwatch");
  32. button:SetPoint("TOP",AshranCommanderButton5,"BOTTOM");-- Anchors always default to an object's parent
  33. button:SetScript("OnClick", function()
  34.     SendChatMessage("Archmage Overwatch ","SAY")
  35.     DoEmote("follow" , UnitName("target"))
  36. end )
  37. local button=CreateButton(frame,"AshranCommanderButton7","Interface\\Icons\\achievement_pvp_h_a",nil,"Stormshield Stronghold");
  38. button:SetPoint("TOP",AshranCommanderButton6,"BOTTOM");-- Anchors always default to an object's parent
  39. button:SetScript("OnClick", function()
  40.     SendChatMessage("Stormshield Stronghold ","SAY")
  41.     DoEmote("follow" , UnitName("target"))
  42. end )
  43. local button=CreateButton(frame,"AshranCommanderButton8","Interface\\Icons\\Ability_rogue_sprint",nil,"Amphitheater of Annihilation(AoA)");
  44. button:SetPoint("RIGHT",AshranCommanderButton1,"LEFT");-- Anchors always default to an object's parent
  45. button:SetScript("OnClick", function()
  46.     SendChatMessage("AoA - EVENT:STADIUM RACING - Block the entrance!","SAY")
  47.     DoEmote("follow" , UnitName("target"))
  48. end )
  49. local button=CreateButton(frame,"AshranCommanderButton9","Interface\\Icons\\spell_fire_fire",nil,"Brute's Rise(BR)");
  50. button:SetPoint("RIGHT",AshranCommanderButton2,"LEFT");-- Anchors always default to an object's parent
  51. button:SetScript("OnClick", function()
  52.     SendChatMessage("BR - EVENT:OGRE FIRES - Block the stairs! ","SAY")
  53.     DoEmote("follow" , UnitName("target"))
  54. end )
  55. local button=CreateButton(frame,"AshranCommanderButton10","Interface\\Icons\\achievement_boss_furyfurnace",nil,"Ring of Conquest(RoC)");
  56. button:SetPoint("RIGHT",AshranCommanderButton3,"LEFT");-- Anchors always default to an object's parent
  57. button:SetScript("OnClick", function()
  58.     SendChatMessage("Ring of Conquest GO RoC ","SAY")
  59.     DoEmote("follow" , UnitName("target"))
  60. end )
  61. local button=CreateButton(frame,"AshranCommanderButton11","Interface\\Icons\\Trade_archaeology_apexisstatue",nil,"Ashran Excavation(Mines)");
  62. button:SetPoint("RIGHT",AshranCommanderButton4,"LEFT");-- Anchors always default to an object's parent
  63. button:SetScript("OnClick", function()
  64.     SendChatMessage("Ashran Excavation - EVENT:APEXIS MARKS - Secure the center!  ","SAY")
  65.     DoEmote("follow" , UnitName("target"))
  66. end )
  67. local button=CreateButton(frame,"AshranCommanderButton12","Interface\\Icons\\achievement_reputation_ogre",nil,"Seat of Kor'lok");
  68. button:SetPoint("RIGHT",AshranCommanderButton5,"LEFT");-- Anchors always default to an object's parent
  69. button:SetScript("OnClick", function()
  70.     SendChatMessage("Seat of Kor'lok - Kor'lok - Kill the ogre!  ","SAY")
  71.     DoEmote("follow" , UnitName("target"))
  72. end )
  73. local button=CreateButton(frame,"AshranCommanderButton13","Interface\\Icons\\Spell_lifegivingspeed",nil,"Molten Quarry(MQ)");
  74. button:SetPoint("RIGHT",AshranCommanderButton6,"LEFT");-- Anchors always default to an object's parent
  75. button:SetScript("OnClick", function()
  76.     SendChatMessage("Molten Quarry - EVENT:Empowered Ore - Block the entrance!  ","SAY")
  77.     DoEmote("follow" , UnitName("target"))
  78. end )
  79. local button=CreateButton(frame,"AshranCommanderButton14","Interface\\Icons\\Achievement_halloween_ghost_01",nil,"Ashmaul Burial Grounds(ABG)");
  80. button:SetPoint("RIGHT",AshranCommanderButton7,"LEFT");-- Anchors always default to an object's parent
  81. button:SetScript("OnClick", function()
  82.     SendChatMessage("Ashmaul Burial Grounds - EVENT:RISEN SPIRITS - Clear the center and block the entrance!  ","SAY")
  83.     DoEmote("follow" , UnitName("target"))
  84. end )



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
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 02-12-16 at 02:49 PM.
  Reply With Quote
02-12-16, 02:13 PM   #8
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,857
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.
  Reply With Quote
02-12-16, 02:42 PM   #9
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,857
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.
  Reply With Quote
02-12-16, 02:53 PM   #10
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,308
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
"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
02-12-16, 02:59 PM   #11
tyroneexe
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Feb 2016
Posts: 13
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:
  1. local button=CreateButton(frame,"AshranCommanderButton1","Interface\\Icons\\achievement_pvp_a_h",nil,"Warspear Keep");
  2. button:SetPoint("TOPRIGHT",frame,"TOPRIGHT",-10,-8);-- Anchors always default to an object's parent
  3. button:SetScript("OnClick", function()
  4.          SendChatMessage("Warspear Keep ","SAY")
  5.          DoEmote("follow")
  6.     end )

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:
  1. frame:SetSize(40+40+20,(7*40)+20)
Or
Lua Code:
  1. btn:SetSize(38,38);


Tried changing "40+40" to SecureActionButtonTemplate, hoping it would act similar to

Lua Code:
  1. frame:SetHeight((#CLASS_SORT_ORDER*40)+20) --NOT FROM THIS LUA

but no, that was not the way

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

Last edited by tyroneexe : 02-12-16 at 03:10 PM. Reason: specify what's working
  Reply With Quote
02-12-16, 03:09 PM   #12
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,308
You could use Frame:SetScale() to scale everything. For example, Frame:SetScale(0.5) will shrink the frame and its children to 50% of their size. Likewise, Frame:SetScale(1.25) will enlarge the frame and its children by 25%. At any rate, I honestly don't think resizing is going to be an in-demand feature.

PS: Don't forget to add the Frame:EnableMouse(true) that I forgot earlier, otherwise the container frame won't run the OnDrag* scripts.
__________________
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)

Last edited by SDPhantom : 02-12-16 at 04:00 PM.
  Reply With Quote
02-12-16, 03:45 PM   #13
tyroneexe
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Feb 2016
Posts: 13
Originally Posted by SDPhantom View Post
PS: Don't forget to add the Frame:SetMovable(true) that I forgot earlier, otherwise the container frame won't run the OnDrag* scripts.
It is in there as far as I can see.

I tried adding Frame:SetClampedToScreen(enable), but it just returned an error.

Lua Code:
  1. Frame:SetClampedToScreen(enable) --True to limit the frame's boundaries to those of the screen; false to allow the frame to be moved/resized without such limits

I instead added
Lua Code:
  1. btn:SetClampedToScreen(enable);
to
Lua Code:
  1. --      Register handlers
  2.         btn:RegisterForClicks("AnyUp");--   Register all buttons
  3.         btn:RegisterForDrag("LeftButton");--    Register for left drag
  4.         btn:SetScript("OnDragStart",OnDragStart);
  5.         btn:SetScript("OnDragStop",OnDragStop);
  6.         btn:SetScript("OnEnter",OnEnter);
  7.         btn:SetScript("OnLeave",OnLeave);
  8.         btn.Tooltip=tooltip;
  9.         btn:SetClampedToScreen(enable);

which does the job. As far as I can tell it works on the button which the mouse is interacting with, meaning that button cannot be moved out of the screen, but the others can. Since you can then still drag the entire frame back, I suppose that it good enough.

You might have a point about the ability to resize. Set scale to 0.8 for now
Lua Code:
  1. frame:SetScale(0.8)
  Reply With Quote
02-12-16, 03:59 PM   #14
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,857
You don't want to actually drag the buttons themselves, you want to activate the container frame onDragxxx

Code:
            
btn:RegisterForDrag("LeftButton");--    Register for left drag
btn:SetScript("OnDragStart", function(self) 
	local f = frame:GetScript("OnDragStart") -- Get the frame OnDragStart script
	f(frame) -- run it
end);
btn:SetScript("OnDragStop", function(self) 
	local f = frame:GetScript("OnDragStop") -- Get the frame OnDragStop script
	f(frame) -- run it
end);
This requires that the frame creation be above the CeateButton function ie. at the top of the file.
__________________
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 04:03 PM.
  Reply With Quote
02-12-16, 03:59 PM   #15
Yukyuk
A Chromatic Dragonspawn
 
Yukyuk's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2015
Posts: 179
As far as I now SetClampedToScreen(boolean), meaning it has either to be true or false.
__________________
Better to fail then never have tried at all.
  Reply With Quote
02-12-16, 04:08 PM   #16
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,308
Originally Posted by tyroneexe View Post
Originally Posted by SDPhantom View Post
PS: Don't forget to add the Frame:SetMovable(true) that I forgot earlier, otherwise the container frame won't run the OnDrag* scripts.
It is in there as far as I can see.
I accidentally put the wrong function name in the post, it's supposed to be Frame:EnableMouse(true).



Originally Posted by tyroneexe View Post
I tried adding Frame:SetClampedToScreen(enable), but it just returned an error.
enable is a label for the argument, it's supposed to be a boolean true or false. Like Frame:SetClampedToScreen(true). You need to apply this to the container frame since that's what we're actually moving, not the buttons.
__________________
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
02-12-16, 04:14 PM   #17
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,857
I think I will de-cook this by one. Best of luck tyroneexe.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
02-12-16, 04:28 PM   #18
tyroneexe
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Feb 2016
Posts: 13
Originally Posted by Fizzlemizz View Post
You don't want to actually drag the buttons themselves, you want to activate the container frame onDragxxx

Code:
            
btn:RegisterForDrag("LeftButton");--    Register for left drag
btn:SetScript("OnDragStart", function(self) 
	local f = frame:GetScript("OnDragStart") -- Get the frame OnDragStart script
	f(frame) -- run it
end);
btn:SetScript("OnDragStop", function(self) 
	local f = frame:GetScript("OnDragStop") -- Get the frame OnDragStop script
	f(frame) -- run it
end);
This requires that the frame creation be above the CeateButton function ie. at the top of the file.
I not sure what I'm to change (which parts and where in the code). I think here:
Lua Code:
  1. --      Register handlers
  2.         btn:RegisterForClicks("AnyUp");--   Register all buttons
  3.         btn:RegisterForDrag("LeftButton");--    Register for left drag
  4.         btn:SetScript("OnDragStart",OnDragStart);
  5.         btn:SetScript("OnDragStop",OnDragStop);
  6.         btn:SetScript("OnEnter",OnEnter);
  7.         btn:SetScript("OnLeave",OnLeave);
  8.         btn.Tooltip=tooltip;
  9.         btn:SetClampedToScreen(enable);
While also moving
Lua Code:
  1. local frame = CreateFrame("Frame","ACFrame",UIParent)
  2. frame:SetPoint("CENTER",UIParent)
  3. frame:SetSize(40+40+20,(7*40)+20)
  4. frame:SetBackdrop(StaticPopup1:GetBackdrop())
  5.  
  6. frame:SetScale(0.8)
  7. frame:SetMovable(true)
  8. frame:RegisterForDrag("LeftButton")--   Register left button for dragging
  9. frame:SetScript("OnDragStart",frame.StartMoving)--  Set script for drag start
  10. frame:SetScript("OnDragStop",frame.StopMovingOrSizing)--    Set script for drag stop
to the Top. Sorry for asking, I should just do it and see what happens really.

With the current code the frame and buttons all move together when dragging on one of the buttons. Feels nice and easy. I suppose if the player, in the heat of battle, could move the frame by accident. On the other hand it's easier to move without having the click the small area which is the frame.


On another matter.
I'm looking into having the frame only show in Ashran, similar to AshranBuddy.
I'm guessing I'm looking for something like
Fragment Lua from AshranBuddy Code:
  1. if (not Api:IsInAshran()) then
  2.         self.Component:Hide()
  3.     end
although I'm also looking around http://wowprogramming.com/ for something useful.

note to self, should remember to load a char which is actually in Ashran for testing this.
  Reply With Quote
02-12-16, 04:36 PM   #19
tyroneexe
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Feb 2016
Posts: 13
Originally Posted by SDPhantom View Post
I accidentally put the wrong function name in the post, it's supposed to be Frame:EnableMouse(true).




enable is a label for the argument, it's supposed to be a boolean true or false. Like Frame:SetClampedToScreen(true). You need to apply this to the container frame since that's what we're actually moving, not the buttons.
Yeah, I did set it to true, but nothing - tried again and it worked - might have been a typo or not changing Frame to frame (heard case matters)

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

EDIT: did the changes suggested by FizzleMizz and while I could move the entire thing before, I can now "grap" it at the outer edge (frame) as well.

Last edited by tyroneexe : 02-12-16 at 04:44 PM.
  Reply With Quote
02-12-16, 05:36 PM   #20
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,308
Originally Posted by Fizzlemizz View Post
You don't want to actually drag the buttons themselves, you want to activate the container frame onDragxxx

Code:
            
btn:RegisterForDrag("LeftButton");--    Register for left drag
btn:SetScript("OnDragStart", function(self) 
	local f = frame:GetScript("OnDragStart") -- Get the frame OnDragStart script
	f(frame) -- run it
end);
btn:SetScript("OnDragStop", function(self) 
	local f = frame:GetScript("OnDragStop") -- Get the frame OnDragStop script
	f(frame) -- run it
end);
This requires that the frame creation be above the CreateButton function ie. at the top of the file.
The code I proposed actually is dragging the container frame by calling self:GetParent():StartMoving(). This doesn't require the container frame to be pre-defined since it's accessing it through the button's set parent.
__________________
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)

Last edited by SDPhantom : 02-12-16 at 05:55 PM.
  Reply With Quote

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

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