Thread Tools Display Modes
02-12-16, 05:38 PM   #21
tyroneexe
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Feb 2016
Posts: 13
The quest to make the addon/frame hidden when not in ashran continues.

Tried
Lua Code:
  1. if pvpMapID = 3 then
  2.     frame:Show()
  3. else
  4.     frame:Hide()
  5. end

also
Lua Code:
  1. frame:SetShown(pvpMapID(3))
and
Lua Code:
  1. if (not Api:IsInAshran()) then
  2.         self.Component:Hide()
  3.     end

and while some parts might be part of the solution, I'm also sure I'm missing some parts.
maybe
Lua Code:
  1. local pvpID, localizedName  = GetWorldPVPAreaInfo(3);
is part of the solution.

I think I'll leave it for today, spend enough time on that today. Thanks for the help thus far.
  Reply With Quote
02-12-16, 05:55 PM   #22
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
This is where we get into listening for events. Right under where you set up your container frame, put this in.
Lua Code:
  1. frame:RegisterEvent("PLAYER_ENTERING_WORLD")--  Load screen disapears
  2. frame:RegisterEvent("ZONE_CHANGED_NEW_AREA")--  Moved into new area
  3. frame:SetScript("OnEvent",function(self,event) self:SetShown(GetZoneText()==GetMapNameByID(978)) end)

This compares the name of the zone you enter with the localized name of Ashran.
__________________
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, 06:20 PM   #23
tyroneexe
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Feb 2016
Posts: 13
Originally Posted by SDPhantom View Post
This is where we get into listening for events. Right under where you set up your container frame, put this in.
Lua Code:
  1. frame:RegisterEvent("PLAYER_ENTERING_WORLD")--  Load screen disapears
  2. frame:RegisterEvent("ZONE_CHANGED_NEW_AREA")--  Moved into new area
  3. frame:SetScript("OnEvent",function(self,event) self:SetShown(GetZoneText()==GetMapNameByID(978)) end)

This compares the name of the zone you enter with the localized name of Ashran.
Thanks a bunch. Tested and it works, pops up as soon as I step over the border between Warspear and Ashran. Now I'm ready to steal all the glory and say I did it all on my own


I was wondering something - how does it remember where I placed the frame? I can't see in the code where it is told to do that. Is that something BlizzardsUI does?
  Reply With Quote
02-12-16, 07:26 PM   #24
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
http://wowprogramming.com/docs/widge.../SetUserPlaced
__________________
"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, 09:29 PM   #25
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
As soon as you stop dragging, it saves the position automatically. You can use Frame:SetUserPlaced(false) to cancel this or Frame:SetDontSavePosition(true) to turn it off completely. This happens for every frame that has Frame:SetMovable() set.
__________________
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 09:31 PM.
  Reply With Quote
02-13-16, 01:42 AM   #26
Yukyuk
A Chromatic Dragonspawn
 
Yukyuk's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2015
Posts: 179
Personally I do not like SetUserPlaced
I save the placement of my frame in the SavedVariables.

See the answer by Phanx in this post why http://forums.wowace.com/showthread.php?t=18521

Its a post from 2010 but as far as I can tell, it's still valid.
__________________
Better to fail then never have tried at all.
  Reply With Quote
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
02-13-16, 09:02 AM   #28
tyroneexe
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Feb 2016
Posts: 13
Still messing around with the addon.
After a test in Ashran last night, I found some functions could be added.

So I've added a second frame and found some code SDPhantom helped another user with

Lua Code:
  1. button:SetAttribute("type","macro");--  "type" without a number will handle all clicks unless a more specific attribute is found
  2. button:SetAttribute("macrotext1",SLASH_WORLD_MARKER1.." 1");--      Adds world marker 1 on left-click
  3. button:SetAttribute("macrotext2",SLASH_CLEAR_WORLD_MARKER1.." 1");--    Clears world marker 1 on right-click

I already use wMarker in Ashran to set gathering spots or direct the focus of the raid to certain enemies or if AA carrier is killed, to mark the AA location quickly.
Having just one marker is enough and placing/removing(well removing isn't really needed in Ashran, but it's nice either way) works.

My issue is getting the button to also send out msg to the raid in RAID_WARNING and INSTANCE_CHAT - sending different msg to each chat, Shorter ones in /rw longer ones in /i

Tried placing SDPhantoms code in different places within the function, and tried adding SetRaidTarget("mouseover",6); as well - although mouseover would be a bad choice since the mouse is clicking the button But just to see if I was on the right track.

This is the current mashup
Lua Code:
  1. local button=CreateButton(frame,"AshranCommanderButton22","Interface\\Icons\\ability_blackhand_marked4death",nil,"Place World Marker");
  2. button:SetPoint("TOP",AshranCommanderButton21,"BOTTOM",0,0);-- Anchors always default to an object's parent
  3. button:SetAttribute("type","macro");--  "type" without a number will handle all clicks unless a more specific attribute is found
  4. button:SetAttribute("macrotext1",SLASH_WORLD_MARKER1.." 1");--      Adds world marker 1 on left-click
  5. button:SetAttribute("macrotext2",SLASH_CLEAR_WORLD_MARKER1.." 1");--    Clears world marker 1 on right-click
  6. --button:SetScript("OnClick", function()
  7. --       SendChatMessage("{square} is used by a commander to mark the battlefront, gathering spot, defensive lines and on AA if it is dropped.","INSTANCE_CHAT")
  8. --       SendChatMessage("{square} Get to {square}", "RAID_WARNING")
  9.          --SetRaidTarget("mouseover",6);
  10. --  end )

Last edited by tyroneexe : 02-13-16 at 10:18 AM.
  Reply With Quote
02-13-16, 02:51 PM   #29
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
Since MunkDev wants to address the button layout code and this is moving into the realm of protected frames, I'll offer a rewrite of the entire code and explain the changes along the way.

Here's what I have so far:
Lua Code:
  1. --------------------------
  2. --[[    Layout Settings ]]
  3. --------------------------
  4. local ButtonSize=32;--  Size to make buttons
  5.  
  6. local Padding=12;-- Buttons are placed this far from the edge of the container frame
  7. local Backdrop={
  8.     bgFile="Interface\\DialogFrame\\UI-DialogBox-Background",
  9.     edgeFile="Interface\\DialogFrame\\UI-DialogBox-Border",
  10.     tile=true,tileSize=32,edgeSize=32,
  11.     insets={left=11,right=12,top=12,bottom=12}
  12. };
  13.  
  14. local ButtonData={--    Note: Buttons will be created top-down, then left-right
  15. --[[    Data Format (All arguments are optional)
  16.         Icon:       Icon file
  17.         Text:       Button text
  18.         Tooltip:    Tooltip text
  19.         Message:    Message to send     Format: {<Message>, <Channel>, ...} Can contain multiple messages as pairs of message and channel strings
  20.         Emote:      Perform emote       Format: {<EmoteToken>, <TargetUnit>}    -or-    <EmoteToken>
  21.         Attributes: List of attributes to apply (keys are attributes, values are values)
  22. --]]
  23.     {-- Container 1
  24.         {-- Column 1
  25.             {
  26.                 Icon="Interface\\Icons\\Ability_rogue_sprint";
  27.                 Tooltip="Amphitheater of Annihilation(AoA)";
  28.                 Message={
  29.                     "Amphitheater of Annihilation(AoA) - EVENT:STADIUM RACING - Block the entrance!","INSTANCE_CHAT";
  30.                     "AoA AoA GO NOW! - Block the entrance!","RAID_WARNING";
  31.                 };
  32.                 Emote="FOLLOW";
  33.             };
  34.             {
  35.                 Icon="Interface\\Icons\\spell_fire_fire";
  36.                 Tooltip="Brute's Rise(BR)";
  37.                 Message={
  38.                     "Brute's Rise(BR) - EVENT:OGRE FIRES - Block the stairs!","INSTANCE_CHAT";
  39.                     "BR BR GO NOW! MOVE IT! Block the stairs!","RAID_WARNING";
  40.                 };
  41.                 Emote="FOLLOW";
  42.             };
  43.             {
  44.                 Icon="Interface\\Icons\\achievement_boss_furyfurnace";
  45.                 Tooltip="Ring of Conquest(RoC)";
  46.                 Message={
  47.                     "Ring of Conquest GO RoC - Let's get some fragments, scrolls, wands and class books","INSTANCE_CHAT";
  48.                     "Ring of Conquest GO RoC","RAID_WARNING";
  49.                 };
  50.                 Emote="FOLLOW";
  51.             };
  52.             {
  53.                 Icon="Interface\\Icons\\Trade_archaeology_apexisstatue";
  54.                 Tooltip="Ashran Excavation(Mines)";
  55.                 Message={
  56.                     "Ashran Excavation(Mines) - EVENT:APEXIS MARKS - Secure the center!","INSTANCE_CHAT";
  57.                     "MINES! GO NOW! MOVE IT! - Secure the center!","RAID_WARNING";
  58.                 };
  59.                 Emote="FOLLOW";
  60.             };
  61.             {
  62.                 Icon="Interface\\Icons\\achievement_reputation_ogre";
  63.                 Tooltip="Seat of Kor'lok";
  64.                 Message={
  65.                     "Seat of Kor'lok - Kor'lok - Kill the ogre!","INSTANCE_CHAT";
  66.                     "Kor'lok! - Kill the ogre!","RAID_WARNING";
  67.                 };
  68.                 Emote="FOLLOW";
  69.             };
  70.             {
  71.                 Icon="Interface\\Icons\\Spell_lifegivingspeed";
  72.                 Tooltip="Molten Quarry(MQ)";
  73.                 Message={
  74.                     "Molten Quarry(MQ) - EVENT:Empowered Ore - Block the entrance!","INSTANCE_CHAT";
  75.                     "MQ MQ GO NOW! MOVE IT! - Block the entrance!","RAID_WARNING";
  76.                 };
  77.                 Emote="FOLLOW";
  78.             };
  79.             {
  80.                 Icon="Interface\\Icons\\Achievement_halloween_ghost_01";
  81.                 Tooltip="Ashmaul Burial Grounds(ABG)";
  82.                 Message={
  83.                     "Ashmaul Burial Grounds(ABG) - EVENT:RISEN SPIRITS - Clear the center and block the entrance!","INSTANCE_CHAT";
  84.                     "ABG ABG GO NOW! MOVE IT! - Clear the center and block the entrance!","RAID_WARNING";
  85.                 };
  86.                 Emote="FOLLOW";
  87.             };
  88.         };
  89.         {-- Column 2
  90.             {
  91.                 Icon="Interface\\Icons\\achievement_pvp_a_h";
  92.                 Tooltip="Warspear Keep";
  93.                 Message={
  94.                     "Warspear Keep!","INSTANCE_CHAT";
  95.                     "Warspear Keep!","RAID_WARNING";
  96.                 };
  97.                 Emote="FOLLOW";
  98.             };
  99.             {
  100.                 Icon="Interface\\Icons\\achievement_garrison_tier02_horde";
  101.                 Tooltip="Emberfall Tower";
  102.                 Message={
  103.                     "Emberfall Tower! Go Go Go! Stack at the flag","INSTANCE_CHAT";
  104.                     "Emberfall Tower!","RAID_WARNING";
  105.                 };
  106.                 Emote="FOLLOW";
  107.             };
  108.             {
  109.                 Icon="Interface\\Icons\\achievement_garrison_tier01_horde";
  110.                 Tooltip="Volrath's Advance";
  111.                 Message={
  112.                     "Volrath's Advance! Go Go Go! Stack at the flag","INSTANCE_CHAT";
  113.                     "Volrath's Advance! VA VA VA","RAID_WARNING";
  114.                 };
  115.                 Emote="FOLLOW";
  116.             };
  117.             {
  118.                 Icon="Interface\\Icons\\achievement_doublejeopardy";
  119.                 Tooltip="The Crossroads";
  120.                     "The Crossroads - Get to Crossroads! Stack at the flag","INSTANCE_CHAT";
  121.                     "The Crossroads - XR XR XR","RAID_WARNING";
  122.                 Message={
  123.                 };
  124.                 Emote="FOLLOW";
  125.             };
  126.             {
  127.                 Icon="Interface\\Icons\\achievement_garrison_tier01_alliance";
  128.                 Tooltip="Tremblade's Vanguard";
  129.                 Message={
  130.                     "Tremblade's Vanguard! Go Go Go! Stack at the flag","INSTANCE_CHAT";
  131.                     "Tremblade's Vanguard! TV TV TV","RAID_WARNING";
  132.                 };
  133.                 Emote="FOLLOW";
  134.             };
  135.             {
  136.                 Icon="Interface\\Icons\\achievement_garrison_tier02_alliance";
  137.                 Tooltip="Archmage Overwatch";
  138.                 Message={
  139.                     "Archmage Overwatch! Go Go Go! Stack at the flag","INSTANCE_CHAT";
  140.                     "Archmage Overwatch! AO AO AO","RAID_WARNING";
  141.                 };
  142.                 Emote="FOLLOW";
  143.             };
  144.             {
  145.                 Icon="Interface\\Icons\\achievement_pvp_h_a";
  146.                 Tooltip="Stormshield Stronghold";
  147.                 Message={
  148.                     "Stormshield Stronghold!","INSTANCE_CHAT";
  149.                     "Stormshield Stronghold!","RAID_WARNING";
  150.                 };
  151.                 Emote="FOLLOW";
  152.             };
  153.         };
  154.     };
  155.  
  156.     {-- Container 2
  157.         {-- Column 1
  158.             {
  159.                 Icon="Interface\\Icons\\Spell_holy_mindvision";
  160.                 Tooltip="Song flower";
  161.                 Message={
  162.                     "Song Flower - Increases all stats by 15%. This effect persists through death. Pick them up in The Dark Woods (the arakkoa area)","INSTANCE_CHAT";
  163.                     "Use Song Flower! 15% to all stats","RAID_WARNING";
  164.                     "You should also pick up Star Root Tuber in Root Den (the saberon area). It gives you are small heal and 40% damage reduction for 10 sec. when used. The Tuber is not as visible as the Song Flowers, but once you know what to look for, it's easy to find them.","INSTANCE_CHAT";
  165.                 };
  166.                 Emote="DRINK";
  167.             };
  168.             {
  169.                 Icon="Interface\\Icons\\Misc_arrowleft";
  170.                 Tooltip="Get out of the road";
  171.                 Message={
  172.                     "Get out of the main road - Stampede or Frost wyrm incoming - Move it!","INSTANCE_CHAT";
  173.                     "GET OUT OF THE ROAD! STAMPEDE OR FROST WYRM INCOMING!","RAID_WARNING";
  174.                 };
  175.                 Emote="DUCK";
  176.             };
  177.             {
  178.                 Icon="Interface\\Icons\\Spell_nature_bloodlust";
  179.                 Tooltip="Bloodlust";
  180.                 Message={
  181.                     "Time to fight! Pop Bloodlust/Time Warp/Heroism","INSTANCE_CHAT";
  182.                     "Pop Bloodlust - Time Warp - Heroism!!","RAID_WARNING";
  183.                 };
  184.                 Emote="FLEX";
  185.             };
  186.         };
  187.  
  188.         {-- Column 2
  189.             {
  190.                 Icon="Interface\\Icons\\misc_arrowlup";
  191.                 Tooltip="Push";
  192.                 Message={
  193.                     "PUSH PUSH! Give them nothing! But take from them EVERYTHING!","INSTANCE_CHAT";
  194.                     "PUSH PUSH PUSH!","RAID_WARNING";
  195.                 };
  196.                 Emote="CHARGE";
  197.             };
  198.             {
  199.                 Icon="Interface\\Icons\\ability_defend";
  200.                 Tooltip="Hold Position";
  201.                 Message={
  202.                     "Hold this position. Stay grouped. Form a wall and let any attackers break upon it. Protect the healers.","INSTANCE_CHAT";
  203.                     "HOLD THE POSITION - STAY GROUPED","RAID_WARNING";
  204.                 };
  205.                 Emote="ENCOURAGE";
  206.             };
  207.             {
  208.                 Icon="Interface\\Icons\\misc_arrowdown";
  209.                 Tooltip="Retreat";
  210.                 Message={
  211.                     "Time for a tactical retreat. Stay grouped. Disengage from combat quickly. Like Top Gear, we will leave stragglers behind","INSTANCE_CHAT";
  212.                     "MOVE BACK! STAY GROUPED!","RAID_WARNING";
  213.                 };
  214.                 Emote="FLEE";
  215.             };
  216.         };
  217.  
  218.         {-- Column 3
  219.             {
  220.                 Icon="Interface\\Icons\\Inv_enchant_formulasuperior_01";
  221.                 Tooltip="Scroll of Protection";
  222.                 Message={
  223.                     "One player use Scroll of Protection(SoP) now. If you see another player use one, don't use yours for 10-15 sec. SoP reduces damage taken by 60% for 15 seconds.","INSTANCE_CHAT";
  224.                     "Use Scroll of Protection!","RAID_WARNING";
  225.                 };
  226.                 Emote="INCOMING";
  227.             };
  228.             {
  229.                 Icon="Interface\\Icons\\achievement_bg_xkills_avgraveyard";
  230.                 Tooltip="Market Graveyard";
  231.                 Message={
  232.                     "Capture Market Graveyard. No more than 5 should disengage from combat to capture the graveyard, unless the raid is moving past it anyway or not engaged in combat.","INSTANCE_CHAT";
  233.                     "CAP THE GY!","RAID_WARNING";
  234.                 };
  235.                 Emote="GO";
  236.             };
  237.             {
  238.                 Icon="Interface\\TargetingFrame\\UI-RaidTargetingIcon_8";
  239.                 Tooltip="Place World Marker/Right-click to remove";
  240.                 Message={
  241.                     "{rt8} is used by a commander to mark the battlefront, gathering spots, defensive lines and on AA if it is dropped.","INSTANCE_CHAT";
  242.                     "{rt8} Get to {rt8}","RAID_WARNING";--  {rt8} is locale-independant form of {skull}
  243.                 };
  244.                 Attributes={
  245.                     type="macro";
  246.                     macrotext1=SLASH_WORLD_MARKER1.." 8";
  247.                     macrotext2=SLASH_CLEAR_WORLD_MARKER1.." 8";
  248.                 };
  249.             };
  250.         };
  251.     };
  252. };
  253.  
  254. ------------------------------------------------------------------
  255. --[[    Addon Code (Don't change anything below this line)  ]]
  256. ------------------------------------------------------------------
  257. --  Button Handlers
  258. local function Container_OnEvent(self)
  259.     if not (self.HasProtectedFrame and InCombatLockdown()) then--   Check if we have a protected button and can show/hide ourselves (Protected frames are protected in combat)
  260.         self:SetShown(GetZoneText()==GetMapNameByID(978))
  261.     end
  262. end
  263.  
  264. local function Button_OnEnter(self)
  265.     GameTooltip:SetOwner(self,"ANCHOR_TOP");
  266.     GameTooltip:AddLine(self.Tooltip,0,1,0.5);
  267.     GameTooltip:Show();
  268. end
  269. local function Button_OnLeave(self) if GameTooltip:IsOwned(self) then GameTooltip:Hide(); end end
  270. local function Button_OnDragStart(self) self:GetParent():StartMoving(); end
  271. local function Button_OnDragStop(self) self:GetParent():StopMovingOrSizing(); end
  272. local function Button_OnClick(self)
  273.     if self.Message then
  274.         for i=1,#self.Message,2 do
  275.             SendChatMessage(self.Message[i],self.Message[i+1]);
  276.         end
  277.     end
  278.     if self.Emote then
  279.         if type(self.Emote)=="table" then
  280.             local target; do--  Prototype variable
  281.                 local unit=self.Emote[2];
  282.                 if unit and UnitExists(unit) and UnitIsPlayer(unit) then
  283.                     local name,server=UnitName(unit);-- Unit name and server
  284.                     target=name..(server and "-"..server:gsub("%s","") or "");--    Format name to <name-server> if necessary
  285.                 end
  286.             end
  287.             DoEmote(self.Emote[1],target);
  288.         else
  289.             DoEmote(self.Emote);
  290.         end
  291.     end
  292. end
  293.  
  294. local OffsetX=0;
  295. for containerid,buttonlist in ipairs(ButtonData) do
  296. --  Container Frame
  297.     local container=CreateFrame("Frame","AshranCommander"..containerid,UIParent);
  298.     container:SetBackdrop(Backdrop);
  299.     container:Hide();-- Start hidden
  300.  
  301. --  Enable Dragging
  302.     container:EnableMouse(true);
  303.     container:SetMovable(true);
  304.     container:SetClampedToScreen(true);
  305.     container:RegisterForDrag("LeftButton");
  306.     container:SetScript("OnDragStart",container.StartMoving);
  307.     container:SetScript("OnDragStop",container.StopMovingOrSizing);
  308.  
  309. --  Event Handlers
  310.     container:RegisterEvent("PLAYER_ENTERING_WORLD");-- Load screen disapears
  311.     container:RegisterEvent("ZONE_CHANGED_NEW_AREA");-- Moved into new area
  312.     container:RegisterEvent("PLAYER_REGEN_ENABLED");--  Retry when exiting combat
  313.     container:SetScript("OnEvent",Container_OnEvent);
  314.  
  315. --  Button Factory
  316.     local numrows,buttonid=0,1;
  317.     for column,rowlist in ipairs(buttonlist) do
  318.         numrows=math.max(numrows,#rowlist);
  319.         for row,data in ipairs(rowlist) do
  320.             local btn=CreateFrame("Button","$parentButton"..buttonid,container,data.Attributes and "SecureActionButtonTemplate");
  321.             btn:SetPoint("TOPLEFT",(column-1)*ButtonSize+Padding,-(row-1)*ButtonSize-Padding);--    Yay, math!
  322.             btn:SetSize(ButtonSize,ButtonSize);
  323.  
  324. --          Extra flair
  325.             btn:SetPushedTexture("Interface\\Buttons\\UI-Quickslot-Depress");
  326.             btn:SetHighlightTexture("Interface\\Buttons\\ButtonHilight-Square","ADD");
  327.  
  328. --          Pushed texture replaces normal texture
  329.             local icon=btn:CreateTexture(nil,"BACKGROUND");
  330.             icon:SetTexture(data.Icon or "Interface\\Icons\\INV_Misc_QuestionMark");
  331.             icon:SetAllPoints(btn);
  332.  
  333. --          Button Text
  334.             if data.Text then
  335.                 btn:SetNormalFontObject("GameFontNormalSmall");
  336.                 btn:SetHighlightFontObject("GameFontHighlightSmall");
  337.                 btn:SetDisabledFontObject("GameFontDisableSmall");
  338.                 btn:SetText(data.Text);
  339.             end
  340.  
  341. --          Register clicks and drag
  342.             btn:RegisterForClicks("AnyUp");--   By default, buttons only respond to LeftUp
  343.             btn:RegisterForDrag("LeftButton");
  344.             btn:HookScript("OnDragStart",Button_OnDragStart);
  345.             btn:HookScript("OnDragStop",Button_OnDragStop);
  346.  
  347. --          Attribute Setup
  348.             if data.Attributes then
  349.                 container.HasProtectedFrame=true;-- Lets the container frame know we have protected buttons now
  350.                 for key,val in pairs(data.Attributes) do btn:SetAttribute(key,val); end
  351.             end
  352.  
  353. --          Tooltip Setup
  354.             if data.Tooltip then
  355.                 btn.Tooltip=data.Tooltip;
  356.                 btn:HookScript("OnEnter",Button_OnEnter);
  357.                 btn:HookScript("OnLeave",Button_OnLeave);
  358.             end
  359.  
  360. --          Chat Handling
  361.             if data.Message or data.Emote then
  362.                 btn.Message=data.Message;
  363.                 btn.Emote=data.Emote;
  364.                 btn:HookScript("OnClick",Button_OnClick);
  365.             end
  366.         end
  367.     end
  368.  
  369. --  We get to apply the position and size now
  370.     local width=#buttonlist*ButtonSize+Padding*2;
  371.     container:SetPoint("TOPLEFT",256+OffsetX,-256);
  372.     container:SetSize(width,numrows*ButtonSize+Padding*2);--    More math, yay!
  373.     OffsetX=OffsetX+width;
  374. end

You'll notice a settings section at the top where you can tweak the UI. The button factory was moved from its dedicated function into a loop at the bottom. Container frame size is calculated using the data in the settings section. The container frame is also created as initially hidden. Since we're starting to deal with protected frames, the show/hide event code checks InCombatLockdown() and also listens to PLAYER_REGEN_ENABLED in order to retry once out of combat. Buttons are now directly anchored to the container frame with some mathematical magic instead of anchored to each other. Script handlers on the buttons are now using Frame:HookScript() in order to avoid taint and preserve scripts set by inherited templates.
__________________
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-23-16 at 03:11 PM.
  Reply With Quote
02-13-16, 03:59 PM   #30
tyroneexe
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Feb 2016
Posts: 13
This looks very interesting. I starting to understand the code, but like languages it's easier to understand sentences than construct sentences.

My current code, not altered yet, provides these two frames with the functions I think are needed.



Current code.
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. frame:EnableMouse(true)
  6. frame:SetScale(0.8)
  7. frame:SetMovable(true)
  8. frame:SetClampedToScreen(true)
  9. frame:RegisterForDrag("LeftButton")--   Register left button for dragging
  10. frame:SetScript("OnDragStart",frame.StartMoving)--  Set script for drag start
  11. frame:SetScript("OnDragStop",frame.StopMovingOrSizing)--    Set script for drag stop
  12. frame:SetUserPlaced(true)
  13. -- disabled for testing purposes frame:RegisterEvent("PLAYER_ENTERING_WORLD")--  Load screen disapears
  14. -- disabled for testing purposes frame:RegisterEvent("ZONE_CHANGED_NEW_AREA")--  Moved into new area
  15. -- disabled for testing purposes frame:SetScript("OnEvent",function(self,event) self:SetShown(GetZoneText()==GetMapNameByID(978)) end)
  16.    
  17.  
  18. local CreateButton; do-- Prototype for function
  19.     --  Drag Handlers
  20.     local function OnDragStart(self) self:GetParent():StartMoving(); end
  21.     local function OnDragStop(self) self:GetParent():StopMovingOrSizing(); end
  22.  
  23.     --  Tooltip Handlers
  24.     local function OnEnter(self)
  25.         if self.Tooltip then
  26.             GameTooltip:SetOwner(self,"ANCHOR_TOP");
  27.             GameTooltip:AddLine(self.Tooltip,0,1,0.5,1,1,1);
  28.             GameTooltip:Show();
  29.         end
  30.     end
  31.     local function OnLeave(self) if GameTooltip:IsOwned(self) then GameTooltip:Hide(); end end
  32.  
  33.     --  Button Generator (this will be assigned to the upvalue noted as a function prototype)
  34.     function CreateButton(parent,name,texture,text,tooltip)
  35.         tooltip=tooltip or text;--  If no tooltip, use button text
  36.  
  37.         --      Create our button
  38.         local btn=CreateFrame("Button",name,parent,"SecureActionButtonTemplate");
  39.         btn:SetSize(40,40);
  40.  
  41.         --      Setup button text
  42.         btn:SetNormalFontObject("GameFontNormalSmall");
  43.         btn:SetHighlightFontObject("GameFontHighlightSmall");
  44.         btn:SetDisabledFontObject("GameFontDisableSmall");
  45.         btn:SetText(text);
  46.  
  47.         --      Setup button's backgorund, you can use :SetNormalTexture() and other functions to set state-based textures
  48.         local tex=btn:CreateTexture(nil,"BACKGROUND");
  49.         tex:SetAllPoints(btn);
  50.         tex:SetTexture(texture);
  51.         btn.Texture=tex;
  52.  
  53.         --      Register handlers
  54.         btn:RegisterForClicks("AnyUp");--   Register all buttons
  55.         btn:RegisterForDrag("LeftButton");--    Register for left drag
  56.         btn:SetScript("OnDragStart",function(self)
  57.                 local f = frame:GetScript("OnDragStart") -- get the frame OnDragStart script
  58.                 f(frame) -- run it
  59.         end);
  60.         btn:SetScript("OnDragStop",function(self)
  61.                 local f = frame:GetScript("OnDragStop") -- get the frame OnDragStop script
  62.                 f(frame) -- run it
  63.         end);
  64.         btn:SetScript("OnDragStop",OnDragStop);
  65.         btn:SetScript("OnEnter",OnEnter);
  66.         btn:SetScript("OnLeave",OnLeave);
  67.         btn.Tooltip=tooltip;
  68.        
  69.  
  70.         --      Return our button
  71.         return btn;
  72.     end
  73. end
  74.  
  75.  
  76.  
  77.  
  78. local button=CreateButton(frame,"AshranCommanderButton1","Interface\\Icons\\achievement_pvp_a_h",nil,"Warspear Keep");
  79. button:SetPoint("TOPRIGHT",frame,"TOPRIGHT",-10,-10);-- Anchors always default to an object's parent
  80. button:SetScript("OnClick", function()
  81.          SendChatMessage("Warspear Keep! ","INSTANCE_CHAT")
  82.          SendChatMessage("Warspear Keep! ","RAID_WARNING")
  83.          DoEmote("follow")
  84.     end )
  85. local button=CreateButton(frame,"AshranCommanderButton2","Interface\\Icons\\achievement_garrison_tier02_horde",nil,"Emberfall Tower");
  86. button:SetPoint("TOP",AshranCommanderButton1,"BOTTOM",0,0);-- Anchors always default to an object's parent
  87. button:SetScript("OnClick", function()
  88.          SendChatMessage("Emberfall Tower! Go Go Go! Stack at the flag","INSTANCE_CHAT")
  89.          SendChatMessage("Emberfall Tower! ","RAID_WARNING")
  90.          DoEmote("follow" , UnitName("target"))
  91.     end )
  92. local button=CreateButton(frame,"AshranCommanderButton3","Interface\\Icons\\achievement_garrison_tier01_horde",nil,"Volrath's Advance");
  93. button:SetPoint("TOP",AshranCommanderButton2,"BOTTOM",0,0);-- Anchors always default to an object's parent
  94. button:SetScript("OnClick", function()
  95.          SendChatMessage("Volrath's Advance! Go Go Go! Stack at the flag","INSTANCE_CHAT")
  96.          SendChatMessage("Volrath's Advance! VA VA VA","RAID_WARNING")
  97.          DoEmote("follow" , UnitName("target"))
  98.     end )
  99. local button=CreateButton(frame,"AshranCommanderButton4","Interface\\Icons\\achievement_doublejeopardy",nil,"The Crossroads");
  100. button:SetPoint("TOP",AshranCommanderButton3,"BOTTOM",0,0);-- Anchors always default to an object's parent
  101. button:SetScript("OnClick", function()
  102.          SendChatMessage("The Crossroads - Get to Crossroads! Stack at the flag","INSTANCE_CHAT")
  103.          SendChatMessage("The Crossroads - XR XR XR ","RAID_WARNING")
  104.          DoEmote("follow" , UnitName("target"))
  105.     end )
  106. local button=CreateButton(frame,"AshranCommanderButton5","Interface\\Icons\\achievement_garrison_tier01_alliance",nil,"Tremblade's Vanguard");
  107. button:SetPoint("TOP",AshranCommanderButton4,"BOTTOM",0,0);-- Anchors always default to an object's parent
  108. button:SetScript("OnClick", function()
  109.          SendChatMessage("Tremblade's Vanguard! Go Go Go! Stack at the flag","INSTANCE_CHAT")
  110.          SendChatMessage("Tremblade's Vanguard! TV TV TV ","RAID_WARNING")
  111.          DoEmote("follow" , UnitName("target"))
  112.     end )
  113. local button=CreateButton(frame,"AshranCommanderButton6","Interface\\Icons\\achievement_garrison_tier02_alliance",nil,"Archmage Overwatch");
  114. button:SetPoint("TOP",AshranCommanderButton5,"BOTTOM",0,0);-- Anchors always default to an object's parent
  115. button:SetScript("OnClick", function()
  116.          SendChatMessage("Archmage Overwatch! Go Go Go! Stack at the flag","INSTANCE_CHAT")
  117.          SendChatMessage("Archmage Overwatch! AO AO AO ","RAID_WARNING")
  118.          DoEmote("follow" , UnitName("target"))
  119.     end )
  120. local button=CreateButton(frame,"AshranCommanderButton7","Interface\\Icons\\achievement_pvp_h_a",nil,"Stormshield Stronghold");
  121. button:SetPoint("TOP",AshranCommanderButton6,"BOTTOM",0,0);-- Anchors always default to an object's parent
  122. button:SetScript("OnClick", function()
  123.          SendChatMessage("Stormshield Stronghold! ","INSTANCE_CHAT")
  124.          SendChatMessage("Stormshield Stronghold! ","RAID_WARNING")
  125.          DoEmote("follow" , UnitName("target"))
  126.     end )
  127. local button=CreateButton(frame,"AshranCommanderButton8","Interface\\Icons\\Ability_rogue_sprint",nil,"Amphitheater of Annihilation(AoA)");
  128. button:SetPoint("RIGHT",AshranCommanderButton1,"LEFT",0,0);-- Anchors always default to an object's parent
  129. button:SetScript("OnClick", function()
  130.          SendChatMessage("Amphitheater of Annihilation(AoA) - EVENT:STADIUM RACING - Block the entrance!","INSTANCE_CHAT")
  131.          SendChatMessage("AoA AoA GO NOW! - Block the entrance!","RAID_WARNING")
  132.          DoEmote("follow" , UnitName("target"))
  133.     end )
  134. local button=CreateButton(frame,"AshranCommanderButton9","Interface\\Icons\\spell_fire_fire",nil,"Brute's Rise(BR)");
  135. button:SetPoint("RIGHT",AshranCommanderButton2,"LEFT",0,0);-- Anchors always default to an object's parent
  136. button:SetScript("OnClick", function()
  137.          SendChatMessage("Brute's Rise(BR) - EVENT:OGRE FIRES - Block the stairs! ","INSTANCE_CHAT")
  138.          SendChatMessage("BR BR GO NOW! MOVE IT! Block the stairs! ","RAID_WARNING")
  139.          DoEmote("follow" , UnitName("target"))
  140.     end )
  141. local button=CreateButton(frame,"AshranCommanderButton10","Interface\\Icons\\achievement_boss_furyfurnace",nil,"Ring of Conquest(RoC)");
  142. button:SetPoint("RIGHT",AshranCommanderButton3,"LEFT",0,0);-- Anchors always default to an object's parent
  143. button:SetScript("OnClick", function()
  144.          SendChatMessage("Ring of Conquest GO RoC - Let's get some fragments, scrolls, wands and class books","INSTANCE_CHAT")
  145.          SendChatMessage("Ring of Conquest GO RoC ","RAID_WARNING")
  146.          DoEmote("follow" , UnitName("target"))
  147.     end )
  148. local button=CreateButton(frame,"AshranCommanderButton11","Interface\\Icons\\Trade_archaeology_apexisstatue",nil,"Ashran Excavation(Mines)");
  149. button:SetPoint("RIGHT",AshranCommanderButton4,"LEFT",0,0);-- Anchors always default to an object's parent
  150. button:SetScript("OnClick", function()
  151.          SendChatMessage("Ashran Excavation(Mines) - EVENT:APEXIS MARKS - Secure the center!  ","INSTANCE_CHAT")
  152.          SendChatMessage("MINES! GO NOW! MOVE IT! - Secure the center!  ","RAID_WARNING")
  153.          DoEmote("follow" , UnitName("target"))
  154.     end )
  155. local button=CreateButton(frame,"AshranCommanderButton12","Interface\\Icons\\achievement_reputation_ogre",nil,"Seat of Kor'lok");
  156. button:SetPoint("RIGHT",AshranCommanderButton5,"LEFT",0,0);-- Anchors always default to an object's parent
  157. button:SetScript("OnClick", function()
  158.          SendChatMessage("Seat of Kor'lok - Kor'lok - Kill the ogre!  ","INSTANCE_CHAT")
  159.          SendChatMessage("Kor'lok! - Kill the ogre!  ","RAID_WARNING")
  160.          DoEmote("follow" , UnitName("target"))
  161.     end )
  162. local button=CreateButton(frame,"AshranCommanderButton13","Interface\\Icons\\Inv_ore_blackrock_nugget",nil,"Molten Quarry(MQ)");
  163. button:SetPoint("RIGHT",AshranCommanderButton6,"LEFT",0,0);-- Anchors always default to an object's parent
  164. button:SetScript("OnClick", function()
  165.          SendChatMessage("Molten Quarry(MQ) - EVENT:Empowered Ore - Block the entrance!  ","INSTANCE_CHAT")
  166.          SendChatMessage("MQ MQ GO NOW! MOVE IT! - Block the entrance!  ","RAID_WARNING")
  167.          DoEmote("follow" , UnitName("target"))
  168.     end )
  169. local button=CreateButton(frame,"AshranCommanderButton14","Interface\\Icons\\Achievement_halloween_ghost_01",nil,"Ashmaul Burial Grounds(ABG)");
  170. button:SetPoint("RIGHT",AshranCommanderButton7,"LEFT",0,0);-- Anchors always default to an object's parent
  171. button:SetScript("OnClick", function()
  172.          SendChatMessage("Ashmaul Burial Grounds(ABG) - EVENT:RISEN SPIRITS - Clear the center and block the entrance! ","INSTANCE_CHAT")
  173.          SendChatMessage("ABG ABG GO NOW! MOVE IT! - Clear the center and block the entrance!  ","RAID_WARNING")
  174.          DoEmote("follow" , UnitName("target"))
  175.     end )
  176.  
  177. local frame = CreateFrame("Frame","ACFrame2",UIParent)
  178. frame:SetPoint("CENTER",UIParent)
  179. frame:SetSize(40+40+40+20,(3*40)+20)
  180. frame:SetBackdrop(StaticPopup1:GetBackdrop())
  181. frame:EnableMouse(true)
  182. frame:SetScale(0.8)
  183. frame:SetMovable(true)
  184. frame:SetClampedToScreen(true)
  185. frame:RegisterForDrag("LeftButton")--   Register left button for dragging
  186. frame:SetScript("OnDragStart",frame.StartMoving)--  Set script for drag start
  187. frame:SetScript("OnDragStop",frame.StopMovingOrSizing)--    Set script for drag stop
  188. frame:SetUserPlaced(true)
  189. -- disabled for testing purposes frame:RegisterEvent("PLAYER_ENTERING_WORLD")--  Load screen disapears
  190. -- disabled for testing purposesframe:RegisterEvent("ZONE_CHANGED_NEW_AREA")--  Moved into new area
  191. -- disabled for testing purposesframe:SetScript("OnEvent",function(self,event) self:SetShown(GetZoneText()==GetMapNameByID(978)) end)
  192.    
  193.  
  194. local CreateButton; do-- Prototype for function
  195.     --  Drag Handlers
  196.     local function OnDragStart(self) self:GetParent():StartMoving(); end
  197.     local function OnDragStop(self) self:GetParent():StopMovingOrSizing(); end
  198.  
  199.     --  Tooltip Handlers
  200.     local function OnEnter(self)
  201.         if self.Tooltip then
  202.             GameTooltip:SetOwner(self,"ANCHOR_TOP");
  203.             GameTooltip:AddLine(self.Tooltip,0,1,0.5,1,1,1);
  204.             GameTooltip:Show();
  205.         end
  206.     end
  207.     local function OnLeave(self) if GameTooltip:IsOwned(self) then GameTooltip:Hide(); end end
  208.  
  209.     --  Button Generator (this will be assigned to the upvalue noted as a function prototype)
  210.     function CreateButton(parent,name,texture,text,tooltip)
  211.         tooltip=tooltip or text;--  If no tooltip, use button text
  212.  
  213.         --      Create our button
  214.         local btn=CreateFrame("Button",name,parent,"SecureActionButtonTemplate");
  215.         btn:SetSize(40,40);
  216.  
  217.         --      Setup button text
  218.         btn:SetNormalFontObject("GameFontNormalSmall");
  219.         btn:SetHighlightFontObject("GameFontHighlightSmall");
  220.         btn:SetDisabledFontObject("GameFontDisableSmall");
  221.         btn:SetText(text);
  222.  
  223.         --      Setup button's backgorund, you can use :SetNormalTexture() and other functions to set state-based textures
  224.         local tex=btn:CreateTexture(nil,"BACKGROUND");
  225.         tex:SetAllPoints(btn);
  226.         tex:SetTexture(texture);
  227.         btn.Texture=tex;
  228.  
  229.         --      Register handlers
  230.         btn:RegisterForClicks("AnyUp");--   Register all buttons
  231.         btn:RegisterForDrag("LeftButton");--    Register for left drag
  232.         btn:SetScript("OnDragStart",function(self)
  233.                 local f = frame:GetScript("OnDragStart") -- get the frame OnDragStart script
  234.                 f(frame) -- run it
  235.         end);
  236.         btn:SetScript("OnDragStop",function(self)
  237.                 local f = frame:GetScript("OnDragStop") -- get the frame OnDragStop script
  238.                 f(frame) -- run it
  239.         end);
  240.         btn:SetScript("OnDragStop",OnDragStop);
  241.         btn:SetScript("OnEnter",OnEnter);
  242.         btn:SetScript("OnLeave",OnLeave);
  243.         btn.Tooltip=tooltip;
  244.        
  245.  
  246.         --      Return our button
  247.         return btn;
  248.     end
  249. end
  250.  
  251.  
  252.  
  253.  
  254. local button=CreateButton(frame,"AshranCommanderButton20","Interface\\Icons\\Inv_enchant_formulasuperior_01",nil,"Scroll of Protection");
  255. button:SetPoint("TOPRIGHT",frame,"TOPRIGHT",-10,-10);-- Anchors always default to an object's parent
  256. button:SetScript("OnClick", function()
  257.          SendChatMessage("One player use Scroll of Protection(SoP) now. If you see another player use one, don't use yours for 10-15 sec. SoP reduces damage taken by 60% for 15 seconds.","INSTANCE_CHAT")
  258.          SendChatMessage("Use Scroll of Protection! ","RAID_WARNING")
  259.          DoEmote("incoming")
  260.     end )
  261. local button=CreateButton(frame,"AshranCommanderButton21","Interface\\Icons\\achievement_bg_xkills_avgraveyard",nil,"Market Graveyard");
  262. button:SetPoint("TOP",AshranCommanderButton20,"BOTTOM",0,0);-- Anchors always default to an object's parent
  263. button:SetScript("OnClick", function()
  264.          SendChatMessage("Capture Market Graveyard. No more than 5 should disengage from combat to capture the graveyard, unless the raid is moving past it anyway or not engaged in combat. ","INSTANCE_CHAT")
  265.          SendChatMessage("CAP THE GY! ","RAID_WARNING")
  266.          DoEmote("go" , UnitName("target"))
  267.     end )
  268. local button=CreateButton(frame,"AshranCommanderButton22","Interface\\TargetingFrame\\UI-RaidTargetingIcon_8",nil,"Place World Marker/Right-click to remove");
  269. button:SetPoint("TOP",AshranCommanderButton21,"BOTTOM",0,0);-- Anchors always default to an object's parent
  270. button:SetAttribute("type","macro");--  "type" without a number will handle all clicks unless a more specific attribute is found
  271. button:SetAttribute("macrotext1",SLASH_WORLD_MARKER1.." 8");--      Adds world marker 1 on left-click
  272. button:SetAttribute("macrotext2",SLASH_CLEAR_WORLD_MARKER1.." 8");--    Clears world marker 1 on right-click
  273. --button:SetScript("OnClick", function()
  274. --       SendChatMessage("{skull} is used by a commander to mark the battlefront, gathering spots, defensive lines and on AA if it is dropped.","INSTANCE_CHAT")
  275. --       SendChatMessage("{skull} Get to {skull}", "RAID_WARNING")
  276.          --SetRaidTarget("mouseover",6);
  277. --  end )
  278. local button=CreateButton(frame,"AshranCommanderButton23","Interface\\Icons\\misc_arrowlup",nil,"Push");
  279. button:SetPoint("RIGHT",AshranCommanderButton20,"LEFT",0,0);-- Anchors always default to an object's parent
  280. button:SetScript("OnClick", function()
  281.          SendChatMessage("PUSH PUSH! Give them nothing! But take from them EVERYTHING!","INSTANCE_CHAT")
  282.          SendChatMessage("PUSH PUSH PUSH! ","RAID_WARNING")
  283.          DoEmote("charge" , UnitName("target"))
  284.     end )
  285. local button=CreateButton(frame,"AshranCommanderButton24","Interface\\Icons\\ability_defend",nil,"Hold Position");
  286. button:SetPoint("TOP",AshranCommanderButton23,"BOTTOM",0,0);-- Anchors always default to an object's parent
  287. button:SetScript("OnClick", function()
  288.          SendChatMessage("Hold this position. Stay grouped. Form a wall and let any attackers break upon it. Protect the healers. ","INSTANCE_CHAT")
  289.          SendChatMessage("HOLD THE POSITION - STAY GROUPED ","RAID_WARNING")
  290.          DoEmote("encourage")
  291.     end )
  292. local button=CreateButton(frame,"AshranCommanderButton25","Interface\\Icons\\misc_arrowdown",nil,"Retreat");
  293. button:SetPoint("TOP",AshranCommanderButton24,"BOTTOM",0,0);-- Anchors always default to an object's parent
  294. button:SetScript("OnClick", function()
  295.          SendChatMessage("Time for a tactical retreat. Stay grouped. Disengage from combat quickly. Like Top Gear, we will leave stragglers behind","INSTANCE_CHAT")
  296.          SendChatMessage("MOVE BACK! STAY GROUPED! ","RAID_WARNING")
  297.          DoEmote("flee" , UnitName("target"))
  298.     end )
  299. local button=CreateButton(frame,"AshranCommanderButton26","Interface\\Icons\\Spell_holy_mindvision",nil,"Song flower");
  300. button:SetPoint("RIGHT",AshranCommanderButton23,"LEFT",0,0);-- Anchors always default to an object's parent
  301. button:SetScript("OnClick", function()
  302.          SendChatMessage("Song Flower -  Increases all stats by 15%. This effect persists through death. Pick them up in The Dark Woods (the arakkoa area) ","INSTANCE_CHAT")
  303.          SendChatMessage("Use Song Flower!  15% to all stats ","RAID_WARNING")
  304.          SendChatMessage("You should also pick up Star Root Tuber in Root Den (the saberon area). It gives you are small heal and 40% damage reduction for 10 sec. when used. The Tuber is not as visible as the Song Flowers, but once you know what to look for, it's easy to find them.","INSTANCE_CHAT")
  305.          DoEmote("drink")
  306.     end )
  307. local button=CreateButton(frame,"AshranCommanderButton27","Interface\\Icons\\Misc_arrowleft",nil,"Get out of the road");
  308. button:SetPoint("TOP",AshranCommanderButton26,"BOTTOM",0,0);-- Anchors always default to an object's parent
  309. button:SetScript("OnClick", function()
  310.          SendChatMessage("Get out of the main road - Stampede or Frost wyrm incoming - Move it!","INSTANCE_CHAT")
  311.          SendChatMessage("GET OUT OF THE ROAD! STAMPEDE OR FROST WYRM INCOMING!","RAID_WARNING")
  312.          DoEmote("duck" , UnitName("target"))
  313.     end )
  314. local button=CreateButton(frame,"AshranCommanderButton28","Interface\\Icons\\Spell_nature_bloodlust",nil,"Bloodlust");
  315. button:SetPoint("TOP",AshranCommanderButton27,"BOTTOM",0,0);-- Anchors always default to an object's parent
  316. button:SetScript("OnClick", function()
  317.          SendChatMessage("Time to fight! Pop Bloodlust/Time Warp/Heroism","INSTANCE_CHAT")
  318.          SendChatMessage("Pop Bloodlust - Time Warp - Heroism!! ","RAID_WARNING")
  319.          DoEmote("flex" , UnitName("target"))
  320.     end )

So the question is if I should copy and edit the code provided by SDPhantom and add the second frame using his code?

I'm assuming in order to change the icon / marker to skull all I have to do is change the number to 8 or another number if another marker is wanted?

In addition, would this macro code also function as the basis for using an item in the game?

Lua Code:
  1. {
  2.         Icon="ability_blackhand_marked4death";
  3.         Tooltip="Place World Marker";
  4.         Message={
  5.             "{rt6} is used by a commander to mark the battlefront, gathering spot, defensive lines and on AA if it is dropped.","INSTANCE_CHAT";
  6.             "{rt6} Get to {rt6}","RAID_WARNING";--  {rt6} is locale-independant form of {square}
  7.         };
  8.         Emote="FOLLOW";
  9.         Attributes={
  10.             type="macro";
  11.             macrotext1=SLASH_WORLD_MARKER1.." 1";
  12.             macrotext2=SLASH_CLEAR_WORLD_MARKER1.." 1";
  13.         };
  Reply With Quote
02-13-16, 09:12 PM   #31
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
I updated the code I posted earlier to handle creating 2 container frames. And yes, you can use macro code to use items.
__________________
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-14-16, 06:54 AM   #32
tyroneexe
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Feb 2016
Posts: 13
Originally Posted by SDPhantom View Post
I updated the code I posted earlier to handle creating 2 container frames. And yes, you can use macro code to use items.
Thank you, I will check it out and play around with it when I have time later.
  Reply With Quote
02-23-16, 10:05 AM   #33
tyroneexe
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Feb 2016
Posts: 13
Originally Posted by SDPhantom View Post
I updated the code I posted earlier to handle creating 2 container frames. And yes, you can use macro code to use items.
Well, well, I must say I didn't think you'd actually changed all the messages and emotes to the ones I'd set up. You're code was ready to go, after activating the part to only show in Ashran. Very nice, thank you.
The addon is up on wowinterface and curse now. I also let the people over at r/wow know about the addon and some have asked about the process for creating the addon, so I told them that you guys/girls helped this novice out a bunch. If you start getting more new people here, that might be why.

Getting quite a few requests for changes/additions, but primarily the ability to either allow the user to set up their own messages or have the addon send out a message based on the clients language. I know I've seen the later, sending one message to enUS/GB and another to the DE clients. I'll look around, but for now I'm in over my head again

and again, special thanks SDPhantom, you're a true gentleman.
  Reply With Quote
02-23-16, 10:36 AM   #34
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
If you set up default text strings with your messages, either stand-alone or in a table, then when the game loads you can then detect the localisation and overwrite the variables with the locale specific messages.
Code:
local MyMessages = {
    Winning = "WINNING!!!",
    Losing = "LOSING!!!!",
}

if GetLocale() == "deDE" then
    MyMessages = {
        Winning = "GEREINNT!!!",
        Losing = "VERLIENREN!!!!",
    }
end
-- Pardon my german, it is coutesy of google tranlate.

Everywhere xx:SetText(MyMessages.Winning)
You will get the current locale message.

There may well be other, better ways.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 02-23-16 at 10:38 AM.
  Reply With Quote
02-23-16, 11:14 AM   #35
tyroneexe
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Feb 2016
Posts: 13
are we talking
Lua Code:
  1. {
  2.                 Icon="Interface\\Icons\\Ability_rogue_sprint";
  3.                 Tooltip="Amphitheater of Annihilation(AoA)";
  4.                 Message={
  5.                     "Amphitheater of Annihilation(AoA) - EVENT:STADIUM RACING - Block the entrance!","INSTANCE_CHAT";
  6.                     "AoA AoA GO NOW! - Block the entrance!","RAID_WARNING";}
  7.                
  8. if GetLocale() == "deDE" then
  9.                 Message={
  10.                        "CHATMESSAGE_DE ","INSTANCE_CHAT";
  11.                     "RAIDMESSAGE_DE ","RAID_WARNING";};
  12.                 Emote="FOLLOW";
  13.             };

and how do you test without a deDE client. Well at least I know some Germans
  Reply With Quote
02-23-16, 12:00 PM   #36
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
You create a set of default string variables
Code:
local Message1 = "Message 1"
local Message2 = "Message 2"

if GetLocale() == "deDE" then 
  Message1 = "Germane for Message 1"
  Message2 = "Germane for Message 2"
end
This is essentially the same as:
Code:
local Message1
local Message2

if GetLocale() == "deDE" then 
  Message1 = "German for Message 1"
  Message2 = "German for Message 2"
else
  Message1 = "Message 1"
  Message2 - "Message 2"
end
-- you know it's German because GetLocale returns "deDE" if the game is running on a german client so you take it on good faith and feedback that it will work . That or have VMs with the various language OSs installed .

So now:
xx:SetText(Message1) will display "German for Message 1" on a german client otherwise "Message 1".

These variables can be created simply like I did here or in a table like I did in my original and if your addon spans multiple .lua files would most likely be created in the addons private table
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 02-23-16 at 12:05 PM.
  Reply With Quote
02-23-16, 03:09 PM   #37
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
Originally Posted by tyroneexe View Post
are we talking
Lua Code:
  1. {
  2.                 Icon="Interface\\Icons\\Ability_rogue_sprint";
  3.                 Tooltip="Amphitheater of Annihilation(AoA)";
  4.                 Message={
  5.                     "Amphitheater of Annihilation(AoA) - EVENT:STADIUM RACING - Block the entrance!","INSTANCE_CHAT";
  6.                     "AoA AoA GO NOW! - Block the entrance!","RAID_WARNING";}
  7.                
  8. if GetLocale() == "deDE" then
  9.                 Message={
  10.                        "CHATMESSAGE_DE ","INSTANCE_CHAT";
  11.                     "RAIDMESSAGE_DE ","RAID_WARNING";};
  12.                 Emote="FOLLOW";
  13.             };

and how do you test without a deDE client. Well at least I know some Germans
Close, but not quite. You can't put an IF block in the middle of a table constructor. What most people do to handle localization is make a completely separate table that stores localized strings. Since localization can take up a lot of code, it's common to place it in a separate Lua file.

For this specifically, I'd put the entire layout table in an IF block and make copies of localized versions for each locale check.
Lua Code:
  1. local ButtonData;-- Data prototype
  2. if GetLocale()=="deDE" then
  3.     ButtonData={
  4. --      deDE Layout
  5.     };
  6. elseif GetLocale()=="frFR" then
  7.     ButtonData={
  8. --      frFR Layout
  9.     };
  10. else--  Default enUS
  11.     ButtonData={
  12. --      enUS Layout
  13.     };
  14. end

To force it to load a specific locale, you could temporarily modify the condition statement you want to load to evaluate to true. Adding or true to it should do the trick.



PS: I forgot I had the "Show only in Ashran" code disabled for testing. This has been fixed in my previous post.
__________________
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-23-16 at 03:12 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