vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | -- Addon information variables. |
2 | TITAN_TITANBT_ID = "TitanBT"; |
||
3 | TITANBT_MENU_TEXT = "BattleTracker"; |
||
4 | TITAN_TITANBT_FREQUENCY = 0.5; |
||
5 | TITANBT_ARTWORK_PATH = "Interface\\AddOns\\Titan\\TitanBattleTracker\\Artwork\\TitanBT"; |
||
6 | TITANBT_BLUETEXT = "|cff0070dd" |
||
7 | TITANBT_NOTICK = 0; |
||
8 | |||
9 | -- Game win/loss ratio stats |
||
10 | |||
11 | BTStats = {}; |
||
12 | |||
13 | BTStats["AV"] = {}; |
||
14 | BTStats["WSG"] = {}; |
||
15 | BTStats["AB"] = {}; |
||
16 | |||
17 | BTStats.AV.Games = 0; |
||
18 | BTStats.AB.Games = 0; |
||
19 | BTStats.WSG.Games = 0; |
||
20 | |||
21 | BTStats.AV.Wins = 0; |
||
22 | BTStats.AB.Wins = 0; |
||
23 | BTStats.WSG.Wins = 0; |
||
24 | |||
25 | BTStats.AV.Losses = 0; |
||
26 | BTStats.AB.Losses = 0; |
||
27 | BTStats.WSG.Losses = 0; |
||
28 | |||
29 | TitanBT_Vars = {}; |
||
30 | |||
31 | TitanBT_Vars.ShowAVText = false; |
||
32 | TitanBT_Vars.ShowWSGText = false; |
||
33 | TitanBT_Vars.ShowABText = false; |
||
34 | |||
35 | TitanBT_Vars.Debug = false; |
||
36 | |||
37 | -- Indicates the addon was successfully loaded. |
||
38 | local _addon_loaded = false; |
||
39 | |||
40 | |||
41 | -- ##################### |
||
42 | -- ## EVENT FUNCTIONS ## |
||
43 | -- ##################### |
||
44 | |||
45 | -- ## Events occuring when caught in game by the system. |
||
46 | function TitanPanelTitanBTButton_OnEvent(event, arg1) |
||
47 | if (event == "ADDON_LOADED") then |
||
48 | |||
49 | -- Indicate the addon has finished loading. |
||
50 | _addon_loaded = true; |
||
51 | |||
52 | elseif ( event == "CHAT_MSG_BG_SYSTEM_NEUTRAL" or event == "CHAT_MSG_BG_SYSTEM_ALLIANCE" or event == "CHAT_MSG_BG_SYSTEM_HORDE" or event == "CHAT_MSG_MONSTER_YELL" ) then |
||
53 | if ( arg1 ~= nil) then |
||
54 | TitanBT_DebugPrint("Battleground Event {"..event.."} arg1 {"..arg1.."}"); |
||
55 | if ( event == "CHAT_MSG_MONSTER_YELL" ) then |
||
56 | if ( arg2 ~= "Horde" and arg2 ~= "Alliance" and arg2 ~= "Herald" ) then |
||
57 | TitanBT_DebugPrint("Event "..event.." arg2 {"..arg2.."} did not match"); |
||
58 | return; |
||
59 | end |
||
60 | end |
||
61 | |||
62 | if ( string.find(arg1, TITANBT_NOTICE_GAMEOVER) ) then |
||
63 | |||
64 | TitanBT_DebugPrint("arg1 {"..arg1.."} indicates this is a GAME OVER message"); |
||
65 | |||
66 | -- Only add to the correct one |
||
67 | if ( GetRealZoneText() == TITANBT_BG_AV ) then |
||
68 | BTStats.AV.Games = BTStats.AV.Games + 1; |
||
69 | elseif ( GetRealZoneText() == TITANBT_BG_AB ) then |
||
70 | BTStats.AB.Games = BTStats.AB.Games + 1; |
||
71 | elseif ( GetRealZoneText() == TITANBT_BG_WSG ) then |
||
72 | BTStats.WSG.Games = BTStats.WSG.Games + 1; |
||
73 | end |
||
74 | |||
75 | if ( string.find( arg1, (UnitFactionGroup("player")) ) ) then |
||
76 | TitanPanelTitanBT_Print(string.format(TITANBT_GAMEWON, GetRealZoneText())); |
||
77 | if ( GetRealZoneText() == TITANBT_BG_AV ) then |
||
78 | BTStats.AV.Wins = BTStats.AV.Wins + 1; |
||
79 | elseif ( GetRealZoneText() == TITANBT_BG_AB ) then |
||
80 | BTStats.AB.Wins = BTStats.AB.Wins + 1; |
||
81 | elseif ( GetRealZoneText() == TITANBT_BG_WSG ) then |
||
82 | BTStats.WSG.Wins = BTStats.WSG.Wins + 1; |
||
83 | end |
||
84 | elseif ( string.find( arg1, (GetOpposingFaction()) ) ) then |
||
85 | TitanPanelTitanBT_Print(string.format(TITANBT_GAMELOST, GetRealZoneText())); |
||
86 | if ( GetRealZoneText() == TITANBT_BG_AV ) then |
||
87 | BTStats.AV.Losses = BTStats.AV.Losses + 1; |
||
88 | elseif ( GetRealZoneText() == TITANBT_BG_AB ) then |
||
89 | BTStats.AB.Losses = BTStats.AB.Losses + 1; |
||
90 | elseif ( GetRealZoneText() == TITANBT_BG_WSG ) then |
||
91 | BTStats.WSG.Losses = BTStats.WSG.Losses + 1; |
||
92 | end |
||
93 | end |
||
94 | end |
||
95 | end |
||
96 | end |
||
97 | end |
||
98 | |||
99 | |||
100 | function GetOpposingFaction() |
||
101 | if ( (UnitFactionGroup("player")) == TITANBT_ALLIANCE ) then |
||
102 | return TITANBT_HORDE; |
||
103 | else |
||
104 | return TITANBT_ALLIANCE; |
||
105 | end |
||
106 | end |
||
107 | |||
108 | -- ##################### |
||
109 | -- ## TITAN FUNCTIONS ## |
||
110 | -- ##################### |
||
111 | |||
112 | -- ## Creates the text located on the titan bar. |
||
113 | function TitanPanelTitanBTButton_GetButtonText(id) |
||
114 | local text = ""; |
||
115 | |||
116 | if ( not TitanBT_Vars.ShowABText and not TitanBT_Vars.ShowABText and not TitanBT_Vars.ShowWSGText ) then |
||
117 | text = text..TITANBT_S_NULL; |
||
118 | else |
||
119 | text = text..TITANBT_S_SHORT; |
||
120 | end |
||
121 | |||
122 | if ( TitanBT_Vars.ShowAVText ) then |
||
123 | text = text..TITANBT_S_AV..BTStats.AV.Games.."/"..TitanUtils_GetGreenText(BTStats.AV.Wins).."/"..TitanUtils_GetRedText(BTStats.AV.Losses) |
||
124 | end |
||
125 | if ( TitanBT_Vars.ShowABText ) then |
||
126 | text = text..TITANBT_S_AB..BTStats.AB.Games.."/"..TitanUtils_GetGreenText(BTStats.AB.Wins).."/"..TitanUtils_GetRedText(BTStats.AB.Losses) |
||
127 | end |
||
128 | if ( TitanBT_Vars.ShowWSGText ) then |
||
129 | text = text..TITANBT_S_WSG..BTStats.WSG.Games.."/"..TitanUtils_GetGreenText(BTStats.WSG.Wins).."/"..TitanUtils_GetRedText(BTStats.WSG.Losses) |
||
130 | end |
||
131 | |||
132 | return text; |
||
133 | end |
||
134 | |||
135 | |||
136 | -- ## Creates the tooltip text for the addon. |
||
137 | function TitanPanelTitanBTButton_GetTooltipText() |
||
138 | local tt; |
||
139 | tt = TITANBT_BLUETEXT .. TITANBT_TT_HeaderLeft .. "\t" .. TITANBT_TT_HeaderRight; |
||
140 | |||
141 | -- ## Alterac Valley |
||
142 | tt = tt .. "\n" .. TITANBT_TT_AV .. "\t" .. BTStats.AV.Games .. "/" .. TitanUtils_GetGreenText(BTStats.AV.Wins) .. "/" .. TitanUtils_GetRedText(BTStats.AV.Losses); |
||
143 | |||
144 | -- ## Arathi Basin |
||
145 | tt = tt .. "\n" .. TITANBT_TT_AB .. "\t" .. BTStats.AB.Games .. "/" .. TitanUtils_GetGreenText(BTStats.AB.Wins) .. "/" .. TitanUtils_GetRedText(BTStats.AB.Losses); |
||
146 | |||
147 | -- ## Warsong Gulch |
||
148 | tt = tt .. "\n" .. TITANBT_TT_WSG .. "\t" .. BTStats.WSG.Games .. "/" .. TitanUtils_GetGreenText(BTStats.WSG.Wins) .. "/" .. TitanUtils_GetRedText(BTStats.WSG.Losses); |
||
149 | |||
150 | return "\n" .. tt; |
||
151 | end |
||
152 | |||
153 | |||
154 | -- ####################### |
||
155 | -- ## DISPLAY FUNCTIONS ## |
||
156 | -- ####################### |
||
157 | |||
158 | |||
159 | -- ## Prints a message to the user's console. |
||
160 | function TitanPanelTitanBT_Print(string) |
||
161 | DEFAULT_CHAT_FRAME:AddMessage("[TitanBT]: " .. string); |
||
162 | end |
||
163 | |||
164 | -- ## Prints a message to the user's console. |
||
165 | function TitanBT_DebugPrint(string) |
||
166 | if ( TitanBT_Vars.Debug ) then |
||
167 | DEFAULT_CHAT_FRAME:AddMessage("[TitanBT Debug]: " .. string); |
||
168 | end |
||
169 | end |
||
170 | |||
171 | -- ############################# |
||
172 | -- ## INITALISATION FUNCTIONS ## |
||
173 | -- ############################# |
||
174 | |||
175 | |||
176 | -- ## Performed when the addon is loaded. |
||
177 | function TitanPanelTitanBTButton_OnLoad() |
||
178 | this.registry = { |
||
179 | id = TITAN_TITANBT_ID, |
||
180 | menuText = TITANBT_MENU_TEXT, |
||
181 | buttonTextFunction = "TitanPanelTitanBTButton_GetButtonText", |
||
182 | tooltipTitle = TITANBT_TOOLTIP, |
||
183 | tooltipTextFunction = "TitanPanelTitanBTButton_GetTooltipText", |
||
184 | icon = TITANBT_ARTWORK_PATH, |
||
185 | iconWidth = 16, |
||
186 | frequency = TITAN_TITANBT_FREQUENCY, |
||
187 | savedVariables = { |
||
188 | ShowIcon = 1, |
||
189 | } |
||
190 | }; |
||
191 | |||
192 | this:RegisterEvent("ADDON_LOADED"); |
||
193 | this:RegisterEvent("CHAT_MSG_BG_SYSTEM_NEUTRAL"); |
||
194 | this:RegisterEvent("CHAT_MSG_BG_SYSTEM_ALLIANCE"); |
||
195 | this:RegisterEvent("CHAT_MSG_BG_SYSTEM_HORDE"); |
||
196 | this:RegisterEvent("CHAT_MSG_MONSTER_YELL"); |
||
197 | end |
||
198 | |||
199 | -- #################### |
||
200 | -- ## MENU FUNCTIONS ## |
||
201 | -- #################### |
||
202 | |||
203 | -- ## Creates the titan drop down menu for the addon. |
||
204 | function TitanPanelRightClickMenu_PrepareTitanBTMenu() |
||
205 | |||
206 | local info = {}; |
||
207 | |||
208 | -- First Level Menu |
||
209 | |||
210 | TitanPanelTitanBT_MenuAddHeader(TitanPlugins[TITAN_TITANBT_ID].menuText); |
||
211 | |||
212 | -- Show Icon |
||
213 | TitanPanelRightClickMenu_AddToggleIcon(TITAN_TITANBT_ID); |
||
214 | |||
215 | -- Show AV Label |
||
216 | info = {}; |
||
217 | info.text = TITANBT_MENU_DISP_AV; |
||
218 | info.value = "ShowAVText"; |
||
219 | info.func = TitanPanelTitanBT_MenuClicked; |
||
220 | TitanPanelTitanBT_MenuAddOption(info, nil); |
||
221 | |||
222 | -- Show AB Label |
||
223 | info = {}; |
||
224 | info.text = TITANBT_MENU_DISP_AB; |
||
225 | info.value = "ShowABText"; |
||
226 | info.func = TitanPanelTitanBT_MenuClicked; |
||
227 | TitanPanelTitanBT_MenuAddOption(info, nil); |
||
228 | |||
229 | -- Show WSG Label |
||
230 | info = {}; |
||
231 | info.text = TITANBT_MENU_DISP_WSG; |
||
232 | info.value = "ShowWSGText"; |
||
233 | info.func = TitanPanelTitanBT_MenuClicked; |
||
234 | TitanPanelTitanBT_MenuAddOption(info, nil); |
||
235 | |||
236 | TitanPanelRightClickMenu_AddSpacer(); |
||
237 | |||
238 | -- Debug Mode |
||
239 | info = {}; |
||
240 | info.text = TITANBT_MENU_OPTS_DEBUG; |
||
241 | info.value = "Debug"; |
||
242 | info.func = TitanPanelTitanBT_MenuClicked; |
||
243 | TitanPanelTitanBT_MenuAddOption(info, nil); |
||
244 | |||
245 | TitanPanelRightClickMenu_AddSpacer(); |
||
246 | |||
247 | -- Reset Stats |
||
248 | info = {}; |
||
249 | info.text = TITANBT_MENU_FUNCS_RESET; |
||
250 | info.value = "ResetStats"; |
||
251 | info.func = TitanPanelTitanBT_ResetClicked; |
||
252 | TitanPanelTitanBT_MenuAddOption(info, nil); |
||
253 | |||
254 | -- Hide |
||
255 | TitanPanelRightClickMenu_AddSpacer(); |
||
256 | TitanPanelRightClickMenu_AddCommand(TITAN_PANEL_MENU_HIDE, TITAN_TITANBT_ID, TITAN_PANEL_MENU_FUNC_HIDE); |
||
257 | |||
258 | end |
||
259 | |||
260 | |||
261 | -- ## Adds a new header to the menu. |
||
262 | function TitanPanelTitanBT_MenuAddHeader(title, level) |
||
263 | info = {}; |
||
264 | info.text = title; |
||
265 | info.notClickable = 1; |
||
266 | info.isTitle = 1; |
||
267 | UIDropDownMenu_AddButton(info, level); |
||
268 | end |
||
269 | |||
270 | |||
271 | -- ## Adds a new option to the menu. |
||
272 | function TitanPanelTitanBT_MenuAddOption(info, level) |
||
273 | info.keepShownOnClick = 1; |
||
274 | if (TitanBT_Vars[info.value]) then info.checked = 1; end |
||
275 | UIDropDownMenu_AddButton(info, level); |
||
276 | end |
||
277 | |||
278 | |||
279 | -- ## Called when a menu item is clicked and requires action. |
||
280 | function TitanPanelTitanBT_MenuClicked() |
||
281 | TitanPanelTitanBT_MenuToggleVar(this.value); |
||
282 | end |
||
283 | |||
284 | -- ## Called when the button is clicked. |
||
285 | function TitanPanelTitanBTButton_OnClick(button) |
||
286 | if ( button ~= "LeftButton" ) then |
||
287 | return; |
||
288 | end |
||
289 | |||
290 | local message = GetDataForChat(); |
||
291 | local numMembers = GetNumRaidMembers(); |
||
292 | if ( numMembers > 0 ) then |
||
293 | SendChatMessage(message, "BATTLEGROUND"); |
||
294 | else |
||
295 | TitanPanelTitanBT_Print(message); |
||
296 | end |
||
297 | end |
||
298 | |||
299 | function GetDataForChat() |
||
300 | local AV = "T:"..BTStats.AV.Games.."/W:"..BTStats.AV.Wins.."/L:"..BTStats.AV.Losses; |
||
301 | local AB = "T:"..BTStats.AB.Games.."/W:"..BTStats.AB.Wins.."/L:"..BTStats.AB.Losses; |
||
302 | local WSG = "T:"..BTStats.WSG.Games.."/W:"..BTStats.WSG.Wins.."/L:"..BTStats.WSG.Losses; |
||
303 | local message = string.format(TITANBT_SEND_DATA, AV, AB, WSG); |
||
304 | AV = nil; |
||
305 | AB = nil; |
||
306 | WSG = nil; |
||
307 | return message; |
||
308 | end |
||
309 | |||
310 | -- ## Called when a menu item is clicked and requires action. |
||
311 | function TitanPanelTitanBT_ResetClicked() |
||
312 | BTStats.AV.Games = 0; |
||
313 | BTStats.AB.Games = 0; |
||
314 | BTStats.WSG.Games = 0; |
||
315 | BTStats.AV.Wins = 0; |
||
316 | BTStats.AB.Wins = 0; |
||
317 | BTStats.WSG.Wins = 0; |
||
318 | BTStats.AV.Losses = 0; |
||
319 | BTStats.AB.Losses = 0; |
||
320 | BTStats.WSG.Losses = 0; |
||
321 | end |
||
322 | |||
323 | |||
324 | -- ## Toggles a specified variable in the menu, changing it from true to false and vice versa. |
||
325 | -- ## |
||
326 | -- ## Variables |
||
327 | -- ## value: The value that UIDROPDOWNMENU_MENU_VALUE is set to when the button is clicked. |
||
328 | function TitanPanelTitanBT_MenuToggleVar(value) |
||
329 | if (TitanBT_Vars[value]) then |
||
330 | TitanBT_Vars[value] = false; |
||
331 | else |
||
332 | TitanBT_Vars[value] = true; |
||
333 | end |
||
334 | end |