vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | -------------------------------------------------------------------------- |
2 | -- TitanFactions.lua |
||
3 | -------------------------------------------------------------------------- |
||
4 | --[[ |
||
5 | |||
6 | Titan Panel [Factions] |
||
7 | When hovered over it displays the reputation standing for each faction |
||
8 | and the percentage completed. Can monitor an individual faction in the |
||
9 | Titan Panel. |
||
10 | |||
11 | Author: Corgi - corgiwow@gmail.com |
||
12 | |||
13 | v0.13 (April 10, 2006 14:21 PST) |
||
14 | - updated toc# for 1.10 patch |
||
15 | - added ability to show both percent and raw values |
||
16 | |||
17 | v0.12 (January 6, 2006 10:00 PST) |
||
18 | - updated toc# for 1.9 patch |
||
19 | |||
20 | v0.11 (October 19, 2005 11:15 PST) |
||
21 | - localization update |
||
22 | |||
23 | v0.10 (October 14, 2005 13:45 PST) |
||
24 | - added ability to monitor a faction |
||
25 | - color-coded faction text (thanks Fyredrake) |
||
26 | |||
27 | v0.09 (October 11, 2005 16:20 PST) |
||
28 | - updated for changes to GetFactionInfo() |
||
29 | - updated toc# for 1.80 patch |
||
30 | |||
31 | v0.08 (September 15, 2005 21:23 PST) |
||
32 | - added toggle between raw and percentage |
||
33 | - updated toc# for 1.70 patch |
||
34 | |||
35 | v0.07 (June 13, 2005 15:00 PST) |
||
36 | - updated for Titan Panel 1.24 |
||
37 | |||
38 | v0.06 (June 7, 2005 20:30 PST) |
||
39 | - toc updated for 1.50 patch |
||
40 | |||
41 | v0.05 (June 6, 2005 23:45 PST) |
||
42 | - added transparent icon |
||
43 | |||
44 | v0.04 (May 31, 2005 02:22 PST) |
||
45 | - updated for Titan Panel version 1.22 |
||
46 | - added Icon |
||
47 | - removed the displaying number of factions |
||
48 | |||
49 | v0.03 (May 26, 2005 15:20 PST) |
||
50 | - added a tab between faction name and standing |
||
51 | |||
52 | v0.02 (May 25, 2005 11:05 PST) |
||
53 | - removed faction headers from total number of factions |
||
54 | |||
55 | v0.01 (May 25, 2005 02:00 PST) |
||
56 | - Initial Release |
||
57 | |||
58 | TODO: Complete translation for German, French and Korean. |
||
59 | |||
60 | NOTE: Requires Titan Panel version 1.22+ |
||
61 | |||
62 | ]]-- |
||
63 | |||
64 | TITAN_FACTIONS_ID = "Factions"; |
||
65 | |||
66 | TITAN_FACTIONS_ICON = "Interface\\AddOns\\TitanFactions\\Artwork\\TitanFactions"; |
||
67 | |||
68 | -- Maximum units for each standing |
||
69 | Units = { }; |
||
70 | Units[1] = 36000; -- Hated |
||
71 | Units[2] = 3000; -- Hostile |
||
72 | Units[3] = 3000; -- Unfriendly |
||
73 | Units[4] = 3000; -- Neutral |
||
74 | Units[5] = 6000; -- Friendly |
||
75 | Units[6] = 12000; -- Honored |
||
76 | Units[7] = 21000; -- Revered |
||
77 | Units[8] = 1000; -- Exalted |
||
78 | |||
79 | -- |
||
80 | -- OnFunctions |
||
81 | -- |
||
82 | function TitanPanelFactionsButton_OnLoad() |
||
83 | this.registry = { |
||
84 | id = TITAN_FACTIONS_ID, |
||
85 | menuText = TITAN_FACTIONS_MENU_TEXT, |
||
86 | buttonTextFunction = "TitanPanelFactionsButton_GetButtonText", |
||
87 | tooltipTitle = TITAN_FACTIONS_TOOLTIP, |
||
88 | tooltipTextFunction = "TitanPanelFactionsButton_GetTooltipText", |
||
89 | icon = TITAN_FACTIONS_ICON, |
||
90 | iconWidth = 16, |
||
91 | savedVariables = { |
||
92 | ShowIcon = 1, |
||
93 | ShowLabelText = 1, |
||
94 | ShowRaw = TITAN_NIL, |
||
95 | ShowBoth = TITAN_NIL, |
||
96 | ShowMonitor = TITAN_NIL, |
||
97 | MonitorFaction = TITAN_NIL, |
||
98 | } |
||
99 | }; |
||
100 | |||
101 | this:RegisterEvent("UPDATE_FACTION"); |
||
102 | end |
||
103 | |||
104 | |||
105 | function TitanPanelFactionsButton_OnEvent(event) |
||
106 | if ( event == "UPDATE_FACTION" ) then |
||
107 | if ( TitanGetVar(TITAN_FACTIONS_ID, "ShowMonitor") == 1 ) then |
||
108 | TitanPanelFactions_UpdateMonitor(); |
||
109 | TitanPanelButton_UpdateButton(TITAN_FACTIONS_ID); |
||
110 | end |
||
111 | TitanPanelButton_UpdateTooltip(); |
||
112 | end |
||
113 | end |
||
114 | |||
115 | -- |
||
116 | -- Titan functions |
||
117 | -- |
||
118 | function TitanPanelFactionsButton_GetButtonText(id) |
||
119 | local buttonRichText = ""; |
||
120 | if ( TitanGetVar(TITAN_FACTIONS_ID, "ShowMonitor") == 1 and (TitanGetVar(TITAN_FACTIONS_ID, "MonitorFaction") ~= nil) ) then |
||
121 | buttonRichText = format(TITAN_FACTIONS_BUTTON_TEXT, TitanGetVar(TITAN_FACTIONS_ID, "MonitorFaction")); |
||
122 | end |
||
123 | |||
124 | return TITAN_FACTIONS_BUTTON_LABEL, buttonRichText; |
||
125 | end |
||
126 | |||
127 | |||
128 | function TitanPanelFactionsButton_GetTooltipText() |
||
129 | |||
130 | local tooltipRichText = ""; |
||
131 | |||
132 | local NumFactions = GetNumFactions(); |
||
133 | |||
134 | local faction_name, faction_description, faction_standingID, faction_barMin, faction_barMax, faction_barValue, faction_atWarWith; |
||
135 | local faction_canToggleAtWar, faction_isHeader, faction_isCollapsed; |
||
136 | |||
137 | local factionIndex; |
||
138 | |||
139 | for factionIndex=1, NumFactions do |
||
140 | |||
141 | faction_name, faction_description, faction_standingID, faction_barMin, faction_barMax, faction_barValue, faction_atWarWith, faction_canToggleAtWar, faction_isHeader, faction_isCollapsed = GetFactionInfo(factionIndex); |
||
142 | |||
143 | if ( not faction_isHeader ) then |
||
144 | |||
145 | tooltipRichText = tooltipRichText..TitanUtils_GetGreenText(faction_name)..":".."\t"..TitanPanelFactions_FindRep(faction_standingID).."("; |
||
146 | |||
147 | if ( TitanGetVar(TITAN_FACTIONS_ID, "ShowRaw") ) then |
||
148 | tooltipRichText = tooltipRichText..faction_barValue - faction_barMin.."/"..faction_barMax - faction_barMin..")\n"; |
||
149 | elseif (TitanGetVar(TITAN_FACTIONS_ID, "ShowBoth") ) then |
||
150 | local bval = math.floor( ((faction_barValue - faction_barMin) / (faction_barMax - faction_barMin)) * 100); |
||
151 | tooltipRichText = tooltipRichText..faction_barValue - faction_barMin.."/"..faction_barMax - faction_barMin..") ("..bval.."%)\n"; |
||
152 | else |
||
153 | local bval = math.floor( ((faction_barValue - faction_barMin) / (faction_barMax - faction_barMin)) * 100); |
||
154 | tooltipRichText = tooltipRichText..bval.."%)\n"; |
||
155 | end |
||
156 | else |
||
157 | tooltipRichText = tooltipRichText..TitanUtils_GetNormalText(faction_name).."\n"; |
||
158 | end |
||
159 | end |
||
160 | |||
161 | -- remove the last \n |
||
162 | tooltipRichText = string.sub(tooltipRichText, 1, string.len(tooltipRichText)-1); |
||
163 | |||
164 | return tooltipRichText; |
||
165 | end |
||
166 | |||
167 | -- |
||
168 | -- create 2nd level right-click menu |
||
169 | -- |
||
170 | function TitanPanelRightClickMenu_PrepareFactionsMenu() |
||
171 | |||
172 | local info = {}; |
||
173 | |||
174 | if ( UIDROPDOWNMENU_MENU_LEVEL == 2 ) then |
||
175 | if ( UIDROPDOWNMENU_MENU_VALUE == "DisplayAbout" ) then |
||
176 | info = {}; |
||
177 | info.text = TITAN_FACTIONS_ABOUT_POPUP_TEXT; |
||
178 | info.value = "AboutTextPopUP"; |
||
179 | info.notClickable = 1; |
||
180 | info.isTitle = 0; |
||
181 | UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL); |
||
182 | end |
||
183 | |||
184 | if ( UIDROPDOWNMENU_MENU_VALUE == "Monitor" ) then |
||
185 | |||
186 | info = {}; |
||
187 | info.text = TITAN_FACTIONS_MONITOR_TOGGLE_TEXT; |
||
188 | info.func = TitanPanelFactions_MonitorToggle; |
||
189 | info.checked = TitanGetVar(TITAN_FACTIONS_ID, "ShowMonitor"); |
||
190 | UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL); |
||
191 | |||
192 | info = {}; |
||
193 | UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL); |
||
194 | |||
195 | local NumFactions = GetNumFactions(); |
||
196 | |||
197 | local faction_name, faction_description, faction_standingID, faction_barMin, faction_barMax, faction_barValue, faction_atWarWith; |
||
198 | local faction_canToggleAtWar, faction_isHeader, faction_isCollapsed; |
||
199 | |||
200 | local factionIndex; |
||
201 | |||
202 | for factionIndex=1, NumFactions do |
||
203 | |||
204 | info = {}; |
||
205 | info.text = ""; |
||
206 | |||
207 | faction_name, faction_description, faction_standingID, faction_barMin, faction_barMax, faction_barValue, faction_atWarWith, faction_canToggleAtWar, faction_isHeader, faction_isCollapsed = GetFactionInfo(factionIndex); |
||
208 | |||
209 | if ( not faction_isHeader ) then |
||
210 | |||
211 | info.text = info.text..TitanUtils_GetGreenText(faction_name)..":".."\t"..TitanPanelFactions_FindRep(faction_standingID).."("; |
||
212 | |||
213 | if ( TitanGetVar(TITAN_FACTIONS_ID, "ShowRaw") ) then |
||
214 | info.text = info.text..faction_barValue - faction_barMin.."/"..faction_barMax - faction_barMin..")\n"; |
||
215 | elseif (TitanGetVar(TITAN_FACTIONS_ID, "ShowBoth") ) then |
||
216 | local bval = math.floor( ((faction_barValue - faction_barMin) / (faction_barMax - faction_barMin)) * 100); |
||
217 | info.text = info.text..faction_barValue - faction_barMin.."/"..faction_barMax - faction_barMin..") ("..bval.."%)\n"; |
||
218 | else |
||
219 | local bval = math.floor( ((faction_barValue - faction_barMin) / (faction_barMax - faction_barMin)) * 100); |
||
220 | info.text = info.text..bval.."%)\n"; |
||
221 | end |
||
222 | |||
223 | info.value = info.text; |
||
224 | |||
225 | info.func = TitanPanelFactions_SetMonitorFaction; |
||
226 | |||
227 | info.checked = nil; |
||
228 | if ( info.text == TitanGetVar(TITAN_FACTIONS_ID, "MonitorFaction") ) then |
||
229 | info.checked = 1; |
||
230 | end |
||
231 | UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL); |
||
232 | |||
233 | end |
||
234 | |||
235 | end |
||
236 | end |
||
237 | |||
238 | return; |
||
239 | end |
||
240 | |||
241 | TitanPanelRightClickMenu_AddTitle(TitanPlugins[TITAN_FACTIONS_ID].menuText); |
||
242 | |||
243 | --TitanPanelRightClickMenu_AddToggleIcon(TITAN_FACTIONS_ID); |
||
244 | |||
245 | -- monitor |
||
246 | info = {}; |
||
247 | info.text = TITAN_FACTIONS_MONITOR; |
||
248 | info.value = "Monitor"; |
||
249 | info.hasArrow = 1; |
||
250 | UIDropDownMenu_AddButton(info); |
||
251 | |||
252 | info = {}; |
||
253 | UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL); |
||
254 | |||
255 | info = {}; |
||
256 | info.text = TITAN_FACTIONS_SHOW_RAW; |
||
257 | info.func = TitanPanelFactions_ShowRawToggle; |
||
258 | info.checked = TitanGetVar(TITAN_FACTIONS_ID, "ShowRaw"); |
||
259 | UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL); |
||
260 | |||
261 | info = {}; |
||
262 | info.text = TITAN_FACTIONS_SHOW_BOTH; |
||
263 | info.func = TitanPanelFactions_ShowBothToggle; |
||
264 | info.checked = TitanGetVar(TITAN_FACTIONS_ID, "ShowBoth"); |
||
265 | UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL); |
||
266 | |||
267 | info = {}; |
||
268 | UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL); |
||
269 | |||
270 | TitanPanelRightClickMenu_AddToggleLabelText(TITAN_FACTIONS_ID); |
||
271 | TitanPanelRightClickMenu_AddCommand(TITAN_PANEL_MENU_HIDE, TITAN_FACTIONS_ID, TITAN_PANEL_MENU_FUNC_HIDE); |
||
272 | |||
273 | -- info about plugin |
||
274 | info = {}; |
||
275 | info.text = TITAN_FACTIONS_ABOUT_TEXT; |
||
276 | info.value = "DisplayAbout"; |
||
277 | info.hasArrow = 1; |
||
278 | UIDropDownMenu_AddButton(info); |
||
279 | |||
280 | end |
||
281 | |||
282 | -- |
||
283 | -- Factions functions |
||
284 | -- |
||
285 | -- Round function |
||
286 | function round(x) |
||
287 | return floor(x+0.5); |
||
288 | end |
||
289 | |||
290 | function TitanPanelFactions_UpdateMonitor() |
||
291 | |||
292 | local tmp_faction = ""; |
||
293 | |||
294 | local NumFactions = GetNumFactions(); |
||
295 | |||
296 | local faction_name, faction_description, faction_standingID, faction_barMin, faction_barMax, faction_barValue, faction_atWarWith; |
||
297 | local faction_canToggleAtWar, faction_isHeader, faction_isCollapsed; |
||
298 | |||
299 | local factionIndex; |
||
300 | |||
301 | for factionIndex=1, NumFactions do |
||
302 | |||
303 | faction_name, faction_description, faction_standingID, faction_barMin, faction_barMax, faction_barValue, faction_atWarWith, faction_canToggleAtWar, faction_isHeader, faction_isCollapsed = GetFactionInfo(factionIndex); |
||
304 | |||
305 | if ( (TitanGetVar(TITAN_FACTIONS_ID, "MonitorFaction") ~= nil) and string.find(TitanGetVar(TITAN_FACTIONS_ID, "MonitorFaction"), faction_name) ) then |
||
306 | |||
307 | tmp_faction = TitanUtils_GetGreenText(faction_name)..":".."\t"..TitanPanelFactions_FindRep(faction_standingID).."("; |
||
308 | |||
309 | if ( TitanGetVar(TITAN_FACTIONS_ID, "ShowRaw") ) then |
||
310 | tmp_faction = tmp_faction..faction_barValue - faction_barMin.."/"..faction_barMax - faction_barMin..")\n"; |
||
311 | elseif (TitanGetVar(TITAN_FACTIONS_ID, "ShowBoth") ) then |
||
312 | local bval = math.floor( ((faction_barValue - faction_barMin) / (faction_barMax - faction_barMin)) * 100); |
||
313 | tmp_faction = tmp_faction..faction_barValue - faction_barMin.."/"..faction_barMax - faction_barMin..") ("..bval.."%)\n"; |
||
314 | else |
||
315 | local bval = math.floor( ((faction_barValue - faction_barMin) / (faction_barMax - faction_barMin)) * 100); |
||
316 | tmp_faction = tmp_faction..bval.."%)\n"; |
||
317 | end |
||
318 | TitanSetVar(TITAN_FACTIONS_ID, "MonitorFaction", tmp_faction); |
||
319 | end |
||
320 | end |
||
321 | end |
||
322 | |||
323 | function TitanPanelFactions_MonitorToggle() |
||
324 | if ( TitanGetVar(TITAN_FACTIONS_ID, "ShowMonitor") ) then |
||
325 | TitanSetVar(TITAN_FACTIONS_ID, "ShowMonitor", nil); |
||
326 | else |
||
327 | TitanSetVar(TITAN_FACTIONS_ID, "ShowMonitor", 1); |
||
328 | end |
||
329 | TitanPanelButton_UpdateButton(TITAN_FACTIONS_ID); |
||
330 | end |
||
331 | |||
332 | function TitanPanelFactions_SetMonitorFaction() |
||
333 | TitanSetVar(TITAN_FACTIONS_ID, "MonitorFaction", this.value); |
||
334 | TitanPanelButton_UpdateButton(TITAN_FACTIONS_ID); |
||
335 | end |
||
336 | |||
337 | function TitanPanelFactions_ShowRawToggle() |
||
338 | if ( TitanGetVar(TITAN_FACTIONS_ID, "ShowRaw") ) then |
||
339 | TitanSetVar(TITAN_FACTIONS_ID, "ShowRaw", nil); |
||
340 | else |
||
341 | TitanSetVar(TITAN_FACTIONS_ID, "ShowRaw", 1); |
||
342 | if ( TitanGetVar(TITAN_FACTIONS_ID, "ShowBoth") ) then |
||
343 | TitanSetVar(TITAN_FACTIONS_ID, "ShowBoth", nil); |
||
344 | end |
||
345 | end |
||
346 | if ( TitanGetVar(TITAN_FACTIONS_ID, "ShowMonitor") == 1 ) then |
||
347 | TitanPanelFactions_UpdateMonitor(); |
||
348 | end |
||
349 | TitanPanelButton_UpdateButton(TITAN_FACTIONS_ID); |
||
350 | end |
||
351 | |||
352 | function TitanPanelFactions_ShowBothToggle() |
||
353 | if ( TitanGetVar(TITAN_FACTIONS_ID, "ShowBoth") ) then |
||
354 | TitanSetVar(TITAN_FACTIONS_ID, "ShowBoth", nil); |
||
355 | else |
||
356 | TitanSetVar(TITAN_FACTIONS_ID, "ShowBoth", 1); |
||
357 | if ( TitanGetVar(TITAN_FACTIONS_ID, "ShowRaw") ) then |
||
358 | TitanSetVar(TITAN_FACTIONS_ID, "ShowRaw", nil); |
||
359 | end |
||
360 | end |
||
361 | if ( TitanGetVar(TITAN_FACTIONS_ID, "ShowMonitor") == 1 ) then |
||
362 | TitanPanelFactions_UpdateMonitor(); |
||
363 | end |
||
364 | TitanPanelButton_UpdateButton(TITAN_FACTIONS_ID); |
||
365 | end |
||
366 | |||
367 | function TitanPanelFactions_FindRep(standingID) |
||
368 | if ( standingID == 0 ) then |
||
369 | return UNKNOWN; -- unknown |
||
370 | elseif ( standingID == 1 ) then |
||
371 | return FactionTextHated; -- hated |
||
372 | elseif ( standingID == 2) then |
||
373 | return FactionTextHostile; -- hostile |
||
374 | elseif ( standingID == 3) then |
||
375 | return FactionTextUnfriendly; -- unfriendly |
||
376 | elseif ( standingID == 4) then |
||
377 | return FactionTextNeutral; -- neutral |
||
378 | elseif ( standingID == 5) then |
||
379 | return FactionTextFriendly; -- friendly |
||
380 | elseif ( standingID == 6) then |
||
381 | return FactionTextHonored; -- honored |
||
382 | elseif ( standingID == 7) then |
||
383 | return FactionTextRevered; -- revered |
||
384 | elseif ( standingID == 8) then |
||
385 | return FactionTextExalted; -- exalted |
||
386 | end |
||
387 | end |
||
388 | |||
389 | -- |
||
390 | -- debug |
||
391 | -- |
||
392 | function TitanPanelFactions_ChatPrint(msg) |
||
393 | DEFAULT_CHAT_FRAME:AddMessage(msg); |
||
394 | end |