View Single Post
02-13-16, 06:11 AM   #27
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
Just posting this for the sake of readability, since you might want to consider some other practices when it comes to doing repeated bits of code. You already have a function that creates the buttons, which is great, but using a data table and a single click function with changing arguments instead of hardcoding every button will look a lot cleaner and it will be much easier to add more buttons to it.

This code is untested, but you should get the general idea.

Lua Code:
  1. local buttons = {
  2.     {
  3.         icon = "achievement_pvp_a_h",
  4.         pos = "Warspear Keep"
  5.     },
  6.     {
  7.         icon = "achievement_garrison_tier02_horde",
  8.         pos = "Emberfall Tower",
  9.         target = true
  10.     },
  11.     {
  12.         icon = "achievement_garrison_tier01_horde",
  13.         pos = "Volrath's Advance",
  14.         target = true
  15.     },
  16.     {
  17.         icon = "achievement_doublejeopardy",
  18.         pos = "The Crossroads",
  19.         target = true
  20.     },
  21.     {
  22.         icon = "achievement_garrison_tier01_alliance",
  23.         pos = "Tremblade's Vanguard",
  24.         target = true
  25.     },
  26.     {
  27.         icon = "achievement_garrison_tier02_alliance",
  28.         pos = "Archmage Overwatch",
  29.         target = true
  30.     },
  31.     {
  32.         icon = "achievement_pvp_h_a",
  33.         pos = "Stormshield Stronghold",
  34.         target = true
  35.     },
  36.     {
  37.         msg = "AoA - EVENT:STADIUM RACING - Block the entrance!",
  38.         icon = "Ability_rogue_sprint",
  39.         pos = "Amphitheater of Annihilation(AoA)",
  40.         target = true
  41.     },
  42.     {
  43.         msg = "BR - EVENT:OGRE FIRES - Block the stairs!",
  44.         icon = "spell_fire_fire",
  45.         pos = "Brute's Rise(BR)",
  46.         target = true
  47.     },
  48.     {
  49.         msg = "Ring of Conquest GO RoC",
  50.         icon = "achievement_boss_furyfurnace",
  51.         pos = "Ring of Conquest(RoC)",
  52.         target = true
  53.     },
  54.     {
  55.         msg = "Ashran Excavation - EVENT:APEXIS MARKS - Secure the center!",
  56.         icon = "Trade_archaeology_apexisstatue",
  57.         pos = "Ashran Excavation(Mines)",
  58.         target = true
  59.     },
  60.     {
  61.         msg = "Seat of Kor'lok - Kor'lok - Kill the ogre!",
  62.         icon = "achievement_reputation_ogre",
  63.         pos = "Seat of Kor'lok",
  64.         target = true
  65.     },
  66.     {
  67.         msg = "Molten Quarry - EVENT:Empowered Ore - Block the entrance!",
  68.         icon = "Spell_lifegivingspeed",
  69.         pos = "Molten Quarry(MQ)",
  70.         target = true
  71.     },
  72.     {
  73.         msg = "Ashmaul Burial Grounds - EVENT:RISEN SPIRITS - Clear the center and block the entrance!",
  74.         icon = "Achievement_halloween_ghost_01",
  75.         pos = "Ashmaul Burial Grounds(ABG)",
  76.         target = true
  77.     },
  78. }
  79.  
  80. local mid = #buttons / 2
  81.  
  82. local function OnClick(self)
  83.     SendChatMessage(self.msg.." ", "SAY")
  84.     DoEmote("follow", self.target and UnitName("target"))
  85. end
  86.  
  87. ACFrame.Buttons = {}
  88.  
  89. for i, info in pairs(buttons) do
  90.     local button = CreateButton(AshranCommander, "$parentButton"..i, "Interface\\Icons\\"..info.icon, nil, info.pos)
  91.     button:SetScript("OnClick", OnClick)
  92.     button.msg = info.msg or info.pos
  93.     button.target = info.target
  94.  
  95.     if i == 1 then
  96.         button:SetPoint("TOPRIGHT", ACFrame, "CENTER", 13, -13)
  97.     elseif i > mid then
  98.         button:SetPoint("RIGHT", ACFrame.Buttons[i-mid], "LEFT", 0, 0)
  99.     else
  100.         button:SetPoint("TOP", ACFrame.Buttons[i-1], "BOTTOM", 0, -1)
  101.     end
  102.     tinsert(ACFrame.Buttons, button)
  103. end
__________________

Last edited by MunkDev : 02-13-16 at 06:16 AM.
  Reply With Quote