vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 -- Plug-in for Titan Panel to show the raid members that are soulstoned
2 -- Author: Lilcure
3 -- Website: http://www.shadowedsoul.com
4 --
5 --
6 -- Version History
7 -- before 2.0:
8 -- o in guild only testing, it's nice having guinea pigs
9 -- 2.0:
10 -- o initial public release on wowinterface, recode from version 1.0
11 -- increased efficiency and a lot lower eval cost for each check of
12 -- it on update
13 -- 2.1:
14 -- o added icon to the titan panel, and made it so you can choose what shows
15 -- in the panel instead of just saying Soulstones: you can pick the icon, the label,
16 -- both or none, credit to TitanBag for learning how to do this
17 --
18 -- o small tweak in one of the raid detection functions.
19 -- 2.2:
20 -- o Added in the ability to show both the high and low times left
21 -- on the titan panel. they are selectable from the right click menu
22 -- o tweaked where build_tooltip() is called.
23 -- 3.0:
24 -- o total record to coincide with porting to FuBar
25  
26 -- Version information
27 local TitanCHKSTONEName = "TitanCHKSTONE";
28 local TitanCHKSTONEVersion = 3.1;
29  
30 -- Titan Specific Constants, these are needed to make the plugin appear on the titan bars
31 TITAN_CHKSTONE_MENU_TEXT = "Soulstones";
32 TITAN_CHKSTONE_TOOLTIP = "Raid members with\nsoulstones\n------------------------";
33 TITAN_CHKSTONE_BUTTON_LABEL = "Soulstones";
34 TITAN_CHKSTONE_FREQUENCY=1;
35  
36 -- Colors not included in the titan sours that were needed
37 MAGENTA_FONT_COLOR_CODE_LIL = "|cffdc143c";
38 YELLOW_FONT_COLOR_CODE_LIL = "|cffdaa520";
39 GREEN_FONT_COLOR_CODE_LIL = "|cff00FF00";
40 WHITE_FONT_COLOR_CODE_LIL = "|cffFFFFFF";
41  
42 -- Array and constants for the index of that array holding data for the members
43 -- of the current raid data is stored in this with the UnitName as the key and
44 -- the first element is the time and the second element reflects whether the
45 -- data is good or bad
46 raid_members = {};
47 PLAYER_DATA_TIME = 1;
48 PLAYER_DATA_GOOD = 2;
49  
50 -- Status Variables
51 current_high = 0;
52 current_low = 999999999999;
53  
54 -- Saved Variables
55 TITAN_CHKSTONE_HIGH = false;
56 TITAN_CHKSTONE_LOW = false;
57  
58 -- Filename of the soulstone buff, this is how we detect if it's up or nto
59 BUFF_SEARCH_STRING = "Spell_Shadow_SoulGem";
60 -- BUFF_SEARCH_STRING = "Fortitude";
61  
62 -- Variables to hold the info shown either on the titan bar or on the mouseover tooltip
63 CHKSTONE_TOTAL_STONED = 0;
64 CHKSTONE_TOOLTIP = "";
65 CHKSTONE_BUTTON = "";
66  
67 -- OnLoad handler set the registry variable that titan needs to manage this plugin
68 function TitanPanelCHKSTONEButton_OnLoad()
69 this.registry={
70 id="CHKSTONE",
71 version = tostring(TitanCHKSTONEVersion),
72 menuText=TITAN_CHKSTONE_MENU_TEXT,
73 buttonTextFunction="TitanPanelCHKSTONEButton_GetButtonText",
74 tooltipTitle = TITAN_CHKSTONE_TOOLTIP,
75 tooltipTextFunction = "TitanPanelCHKSTONEButton_GetTooltipText",
76 frequency=TITAN_CHKSTONE_FREQUENCY,
77 icon = "Interface\\AddOns\\TitanCheckStone\\soulstone",
78 iconWidth = 16,
79 savedVariables = {
80 ShowIcon = 1,
81 ShowLabelText = 1,
82 }
83 };
84 members = {}
85 current_high = 0
86 current_low = 999999999999
87 CHKSTONE_TOTAL_STONED = 0
88 update_data()
89 end
90  
91 -- Called by the Titan Panel base addon to setup a right click
92 -- options menu, at present it just lets the user choose the appearance
93 -- in the main menu.
94 function TitanPanelRightClickMenu_PrepareCHKSTONEMenu()
95 TitanPanelRightClickMenu_AddTitle(TitanPlugins["CHKSTONE"].menuText);
96  
97 TitanPanelRightClickMenu_AddSpacer();
98  
99 local info = {};
100 info.text = "Show High Time"
101 info.func = ToggleHigh
102 if(TITAN_CHKSTONE_HIGH == true) then
103 info.checked = 1;
104 else
105 info.checked = nil;
106 end
107 info.keepShownOnClick = 1;
108 UIDropDownMenu_AddButton(info);
109  
110 info = {};
111 info.text = "Show Low Time"
112 info.func = ToggleLow
113 if(TITAN_CHKSTONE_LOW == true) then
114 info.checked = 1;
115 else
116 info.checked = nil;
117 end
118 info.keepShownOnClick = 1;
119 UIDropDownMenu_AddButton(info);
120  
121 TitanPanelRightClickMenu_AddSpacer();
122  
123 TitanPanelRightClickMenu_AddToggleIcon("CHKSTONE");
124 TitanPanelRightClickMenu_AddToggleLabelText("CHKSTONE");
125 end
126  
127 -- Toggle functions to decide whether or not to show the high and low
128 -- times in the button bar
129 function ToggleHigh()
130 if(TITAN_CHKSTONE_HIGH == true) then
131 TITAN_CHKSTONE_HIGH = false;
132 else
133 TITAN_CHKSTONE_HIGH = true;
134 end
135 end
136 function ToggleLow()
137 if(TITAN_CHKSTONE_LOW == true) then
138 TITAN_CHKSTONE_LOW = false;
139 else
140 TITAN_CHKSTONE_LOW = true;
141 end
142 end
143  
144 -- Called each second to build the tool tip and store it to the global variable
145 -- CHKSTONE_TOOLTIP
146 function build_tooltip()
147 CHKSTONE_TOOLTIP = "";
148 size = getn(members)
149 for k=1, size do
150 if(members[k][2] ~= 0) then
151 if(members[k][3] == 1) then
152 local time_left = calculate_time_left(members[k][2])
153 CHKSTONE_TOOLTIP = CHKSTONE_TOOLTIP..WHITE_FONT_COLOR_CODE_LIL..members[k][1]..": "..GREEN_FONT_COLOR_CODE_LIL..time_left..FONT_COLOR_CODE_CLOSE.."\n";
154 else
155 CHKSTONE_TOOLTIP = CHKSTONE_TOOLTIP..WHITE_FONT_COLOR_CODE_LIL..members[k][1]..": "..YELLOW_FONT_COLOR_CODE_LIL.."UNKNOWN"..FONT_COLOR_CODE_CLOSE.."\n";
156 end
157 end
158 end
159 end
160  
161 function update_data()
162 local numraid = GetNumRaidMembers()
163 local numparty = GetNumPartyMembers()
164 local member_number = 0
165 local button_output = ""
166 local stone_colored_output
167 current_high = 0
168 current_low = 999999999999
169 CHKSTONE_TOTAL_STONED = 0
170 if(numraid > 1) then
171 for i=1, numraid do
172 local current_raid_member = "raid"..i
173 member_number = check_member_number(current_raid_member)
174 check_stone_status(current_raid_member,member_number)
175 check_highs_lows(member_number)
176 end
177 else
178 for i=1, numparty do
179 local current_raid_member = "party"..i
180 member_number = check_member_number(current_raid_member)
181 check_stone_status(current_raid_member,member_number)
182 check_highs_lows(member_number)
183 end
184 member_number = check_member_number("player")
185 check_stone_status("player",member_number)
186 check_highs_lows(member_number)
187 end
188 if(CHKSTONE_TOTAL_STONED == 0) then
189 stone_colored_output = MAGENTA_FONT_COLOR_CODE_LIL..CHKSTONE_TOTAL_STONED
190 elseif(CHKSTONE_TOTAL_STONED < 2) then
191 stone_colored_output = YELLOW_FONT_COLOR_CODE_LIL..CHKSTONE_TOTAL_STONED
192 else
193 stone_colored_output = GREEN_FONT_COLOR_CODE_LIL..CHKSTONE_TOTAL_STONED
194 end
195 button_output = stone_colored_output
196 if(TITAN_CHKSTONE_HIGH == true) then
197 if(current_high ~= 0) then
198 button_output = button_output..WHITE_FONT_COLOR_CODE_LIL.." High: "..calculate_time_left(current_high)
199 else
200 button_output = button_output..WHITE_FONT_COLOR_CODE_LIL.." High: ".."UNKNOWN"
201 end
202 end
203 if(TITAN_CHKSTONE_LOW == true) then
204 if(current_low ~= 999999999999) then
205 button_output = button_output..WHITE_FONT_COLOR_CODE_LIL.." Low: "..calculate_time_left(current_low)
206 else
207 button_output = button_output..WHITE_FONT_COLOR_CODE_LIL.." Low: ".."UNKNOWN"
208 end
209 end
210 CHKSTONE_BUTTON = button_output
211 end
212  
213 function check_member_number(unit)
214 local size = getn(members)
215 local found = -1
216 if(members == nil or size == 0) then
217 found = -99
218 else
219 for i=1,size do
220 if(members[i][1] == UnitName(unit)) then
221 found = i
222 end
223 end
224 end
225 if(found == -99) then
226 members = {}
227 found = -1
228 end
229 if(found == -1) then
230 if(check_buff_present(unit) == 1) then
231 members[getn(members)+1] = { UnitName(unit), time(), 0 }
232 else
233 members[getn(members)+1] = { UnitName(unit), 0, 0 }
234 end
235 found = getn(members)
236 end
237 return found
238 end
239  
240 function check_buff_present(current_raid_member)
241 local buff_found = 0
242 local buff_ittr = 1
243 while (UnitBuff(current_raid_member, buff_ittr)) do
244 if (string.find(UnitBuff(current_raid_member,buff_ittr), BUFF_SEARCH_STRING)) then
245 buff_found = 1
246 end
247 buff_ittr = buff_ittr + 1
248 end
249 return buff_found
250 end
251  
252 function calculate_time_left(recorded_time)
253 local elapsed_seconds = time() - recorded_time
254 local total_seconds = 1800 - elapsed_seconds
255 local leftover_seconds = mod(total_seconds,60)
256 local total_minutes = (total_seconds - leftover_seconds) / 60
257 local seconds_string = ""
258 local minutes_string = ""
259 if(leftover_seconds < 10) then
260 seconds_string = "0"..leftover_seconds
261 else
262 seconds_string = leftover_seconds
263 end
264 if(total_minutes == 0) then
265 minutes_string = "00"
266 else
267 minutes_string = total_minutes
268 end
269 return minutes_string..":"..seconds_string
270 end
271  
272 function check_stone_status(unit, number)
273 if(check_buff_present(unit) == 1) then
274 CHKSTONE_TOTAL_STONED = CHKSTONE_TOTAL_STONED + 1
275 if(members[number][2] == 0) then
276 members[number] = { UnitName(unit) , time(), 1 }
277 end
278 else
279 if(members[number][2] ~= 0) then
280 announce_lost_stone(number)
281 members[number] = { UnitName(unit), 0, 1 }
282 end
283 end
284 end
285  
286 function check_highs_lows(number)
287 if(members[number][2] ~= 0) then
288 if(members[number][3] ~= 0) then
289 if(members[number][2] > current_high) then
290 current_high = members[number][2]
291 end
292 if(members[number][2] < current_low) then
293 current_low = members[number][2]
294 end
295 end
296 end
297 end
298  
299 function announce_lost_stone(number)
300 if(DEFAULT_CHAT_FRAME) then
301 DEFAULT_CHAT_FRAME:AddMessage("*** "..members[number][1].." has lost their SOULSTONE! ***", 1, 1, 1, 1, 5)
302 end
303 if(CT_RAMessageFrame) then
304 CT_RAMessageFrame:AddMessage("*** "..members[number][1].." has lost their SOULSTONE! ***", 1, 1, 1, 1, 5)
305 end
306 end
307  
308  
309 -- Called each second by the titan panel plugin to update the raid member array and
310 -- to update both the button and the tooltip text. It returns number of soulstones
311 -- colored based on how many there are.
312 function TitanPanelCHKSTONEButton_GetButtonText(id)
313 local total_stones_text = "";
314 update_data();
315 build_tooltip();
316 return TITAN_CHKSTONE_BUTTON_LABEL, ": "..CHKSTONE_BUTTON;
317 end
318  
319 -- Calls for the tooltip to be built and returns it to the titan panel addon
320 function TitanPanelCHKSTONEButton_GetTooltipText()
321 return TitanUtils_GetHighlightText(CHKSTONE_TOOLTIP);
322 end