vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1  
2 -- Title: TitanRepair v2.17 (improved Performances by Archarodim - 2006-04-21 04:35 CEST)
3 -- Notes: Adds Durability Info to Titan Panel, also reminds you to repair
4 -- Author: lua@lumpn.de/Adsertor
5  
6 TITAN_REPAIR_ID = "Repair";
7  
8 REPAIR_INDEX = 0;
9 REPAIR_MONEY = 0;
10 REPAIR_ITEM_STATUS = {};
11 REPAIR_ITEM_BAG = {};
12 -- this index (0) will be never set, just accessed to this state, it simplifies code for TitanRepair_GetMostDamagedItem() when Tit_R_EquipedMinIndex == 0
13 REPAIR_ITEM_STATUS[0] = { val = 0, max = 0, cost = 0, name = INVTYPE_HEAD, slot = "VIRTUAL" };
14 --
15 REPAIR_ITEM_STATUS[1] = { val = 0, max = 0, cost = 0, name = INVTYPE_HEAD, slot = "Head" };
16 REPAIR_ITEM_STATUS[2] = { val = 0, max = 0, cost = 0, name = INVTYPE_SHOULDER, slot = "Shoulder" };
17 REPAIR_ITEM_STATUS[3] = { val = 0, max = 0, cost = 0, name = INVTYPE_CHEST, slot = "Chest" };
18 REPAIR_ITEM_STATUS[4] = { val = 0, max = 0, cost = 0, name = INVTYPE_WAIST, slot = "Waist" };
19 REPAIR_ITEM_STATUS[5] = { val = 0, max = 0, cost = 0, name = INVTYPE_LEGS, slot = "Legs" };
20 REPAIR_ITEM_STATUS[6] = { val = 0, max = 0, cost = 0, name = INVTYPE_FEET, slot = "Feet" };
21 REPAIR_ITEM_STATUS[7] = { val = 0, max = 0, cost = 0, name = INVTYPE_WRIST, slot = "Wrist" };
22 REPAIR_ITEM_STATUS[8] = { val = 0, max = 0, cost = 0, name = INVTYPE_HAND, slot = "Hands" };
23 REPAIR_ITEM_STATUS[9] = { val = 0, max = 0, cost = 0, name = INVTYPE_WEAPONMAINHAND, slot = "MainHand" };
24 REPAIR_ITEM_STATUS[10] = { val = 0, max = 0, cost = 0, name = INVTYPE_WEAPONOFFHAND, slot = "SecondaryHand" };
25 REPAIR_ITEM_STATUS[11] = { val = 0, max = 0, cost = 0, name = INVTYPE_RANGED, slot = "Ranged" };
26 REPAIR_ITEM_STATUS[12] = { val = 0, max = 0, cost = 0, name = INVENTORY_TOOLTIP };
27  
28 INVENTORY_REPAIR_STATUS = {}
29 INVENTORY_REPAIR_STATUS[0] = { val = 0, max = 0, cost = 0, name = INVENTORY_TOOLTIP };
30 INVENTORY_REPAIR_STATUS[1] = { val = 0, max = 0, cost = 0, name = INVENTORY_TOOLTIP };
31 INVENTORY_REPAIR_STATUS[2] = { val = 0, max = 0, cost = 0, name = INVENTORY_TOOLTIP };
32 INVENTORY_REPAIR_STATUS[3] = { val = 0, max = 0, cost = 0, name = INVENTORY_TOOLTIP };
33 INVENTORY_REPAIR_STATUS[4] = { val = 0, max = 0, cost = 0, name = INVENTORY_TOOLTIP };
34  
35  
36 local TitRep_show_debug = false; -- will tell you a lot about what's happening
37  
38 local Tit_R_WholeScanInProgress = false;
39 local Tit_R_UpdateCheckDelay = 2; -- 2 seconds must elaps between scans
40 local Tit_R_DelayTimer = 0; -- init the timer
41 local Tit_R_EquipedMinIndex = 0; -- keep a record of the most damaged equiped item (used when removing the most damaged item placed in the inventory to switch on an equiped index)
42 local Tit_R_PleaseCheckBag = { };
43 local Tit_R_CouldRepair = false;
44 local Tit_R_CheckForUpdate = false; -- tells the TitanPanelRepairButton_OnUpdate() function that it has something to do
45  
46 Tit_R_PleaseCheckBag[0] = 0;
47 Tit_R_PleaseCheckBag[1] = 0;
48 Tit_R_PleaseCheckBag[2] = 0;
49 Tit_R_PleaseCheckBag[3] = 0;
50 Tit_R_PleaseCheckBag[4] = 0;
51 Tit_R_PleaseCheckBag[5] = 0; -- this will be used for equiped items, not very good but simplify the code...
52 -- Tit_R_PleaseCheckBag element values meaning:
53 -- 0 means "This bag did not changed, no need to scan it"
54 -- 1 means "Please Check This Bag"
55 -- 2 means "Yes I'm checking, don't disturb me"
56 --
57  
58 local InitialLoad = 0; -- Found no use of this
59  
60 StaticPopupDialogs["REPAIR_CONFIRMATION"] = {
61 text = TEXT(REPAIR_LOCALE["confirmation"]),
62 button1 = TEXT(YES),
63 button2 = TEXT(NO),
64 OnAccept = function()
65 TitanRepair_RepairItems();
66 end,
67 OnShow = function()
68 MoneyFrame_Update(this:GetName().."MoneyFrame", REPAIR_MONEY);
69 end,
70 hasMoneyFrame = 1,
71 timeout = 0,
72 };
73  
74  
75 function TitanPanelRepairButton_OnLoad()
76 -- register plugin
77 this.registry = {
78 id = TITAN_REPAIR_ID,
79 builtIn = 1,
80 version = "2.17.11000",
81 menuText = REPAIR_LOCALE["menu"],
82 buttonTextFunction = "TitanPanelRepairButton_GetButtonText",
83 tooltipTitle = REPAIR_LOCALE["tooltip"],
84 tooltipTextFunction = "TitanPanelRepairButton_GetTooltipText",
85 icon = "Interface\\AddOns\\Titan\\Artwork\\TitanRepair",
86 iconWidth = 16,
87 savedVariables = {
88 ShowIcon = 1,
89 ShowLabelText = 1,
90 ShowItemName = TITAN_NIL,
91 ShowUndamaged = TITAN_NIL,
92 ShowPopup = TITAN_NIL,
93 ShowPercentage = TITAN_NIL,
94 ShowColoredText = TITAN_NIL,
95 RepairInventory = TITAN_NIL,
96 ShowInventory = 1 -- this is no longer a problem :-D
97 }
98 };
99  
100 this:RegisterEvent("PLAYER_LEAVING_WORLD");
101 this:RegisterEvent("PLAYER_ENTERING_WORLD");
102 end
103  
104 function TitanPanelRepairButton_ScanAllItems()
105 if (TitanGetVar(TITAN_REPAIR_ID,"ShowInventory") == 1) then
106 Tit_R_PleaseCheckBag[0] = 1;
107 Tit_R_PleaseCheckBag[1] = 1;
108 Tit_R_PleaseCheckBag[2] = 1;
109 Tit_R_PleaseCheckBag[3] = 1;
110 Tit_R_PleaseCheckBag[4] = 1;
111 end
112 Tit_R_PleaseCheckBag[5] = 1;
113  
114 Tit_R_WholeScanInProgress = true;
115 TitanPanelButton_UpdateButton(TITAN_REPAIR_ID);
116  
117 end
118  
119 function TitanPanelRepairButton_OnEvent()
120  
121 -- NOTE that events test are done in probability order:
122 -- The events that fires the most are tested first
123  
124 if (event == "UPDATE_INVENTORY_ALERTS") then
125  
126 -- register to check the equiped items on next appropriate OnUpdate call
127 if (TitRep_show_debug) then -- this if is not necessary but is here to optimize this part the most possible
128 tit_debug_bis("Event " .. event .. " TREATED!");
129 end
130 Tit_R_PleaseCheckBag[5] = 1;
131 Tit_R_CheckForUpdate = true;
132 return;
133  
134 end
135  
136 -- when arg1 is > 4 it means that a bank's bag has been updated
137 if ( (event == "BAG_UPDATE") and (arg1 < 5) and (TitanGetVar(TITAN_REPAIR_ID,"ShowInventory") == 1)) then
138  
139 -- register to check this bag's items on next appropriate OnUpdate call
140 if (TitRep_show_debug) then -- this if is not necessary but is here to optimize this part the most possible
141 tit_debug_bis("Event " .. event .. " TREATED!");
142 end
143  
144 Tit_R_PleaseCheckBag[arg1] = 1;
145 Tit_R_CheckForUpdate = true;
146 return;
147 end
148  
149  
150  
151  
152 if (event == "MERCHANT_SHOW") then
153 if TitanGetVar(TITAN_REPAIR_ID,"ShowPopup") == 1 then
154 local repairCost, canRepair = GetRepairAllCost();
155 if (canRepair) then
156 Tit_R_CouldRepair = true;
157 if (TitanGetVar(TITAN_REPAIR_ID, "RepairInventory")) then
158 repairCost = repairCost + TitanRepair_GetRepairInvCost();
159 end
160 if (repairCost > 0) then
161 REPAIR_MONEY = repairCost;
162 StaticPopup_Show("REPAIR_CONFIRMATION");
163 end
164 end
165 end
166 return;
167 end
168  
169 if ( event == "MERCHANT_CLOSED" ) then
170 StaticPopup_Hide("REPAIR_CONFIRMATION");
171 -- When an object is repaired in a bag, the BAG_UPDATE event is not sent... :'(
172 -- so we rescan all
173 if (Tit_R_CouldRepair) then
174 TitanPanelRepairButton_ScanAllItems();
175 Tit_R_CheckForUpdate = true;
176 Tit_R_CouldRepair = false;
177 end;
178 return;
179 end
180  
181  
182  
183 if (event == "PLAYER_ENTERING_WORLD") then
184 this:RegisterEvent("BAG_UPDATE");
185 this:RegisterEvent("UPDATE_INVENTORY_ALERTS");
186 this:RegisterEvent("MERCHANT_SHOW");
187 this:RegisterEvent("MERCHANT_CLOSED");
188  
189 -- Check everything on world enter (at init and after zoning)
190 -- (NOTE: this will take 6 * Tit_R_UpdateCheckDelay seconds to update)
191 TitanPanelRepairButton_ScanAllItems();
192 Tit_R_CheckForUpdate = true;
193 return;
194 end
195  
196 if (event == "PLAYER_LEAVING_WORLD") then
197 this:UnregisterEvent("BAG_UPDATE");
198 this:UnregisterEvent("UPDATE_INVENTORY_ALERTS");
199 this:UnregisterEvent("MERCHANT_SHOW");
200 this:UnregisterEvent("MERCHANT_CLOSED");
201 return;
202 end
203  
204 end
205  
206 -- A little debug function
207 function tit_debug_bis( Message)
208 if (TitRep_show_debug) then
209 DEFAULT_CHAT_FRAME:AddMessage("TiT_Rep: " .. Message, 0.5, 0.3, 1);
210 end
211 end
212  
213  
214 function TitanPanelRepairButton_OnUpdate (Elapsed)
215  
216 -- Note that Tit_R_CheckForUpdate is a boolean value, boolean values are easier to test for the cpu
217 if (not Tit_R_CheckForUpdate) then
218 return;
219 end
220 Tit_R_CheckForUpdate = false; -- this is the first thing we do so another event that fires while we are here can set it to true
221  
222 -- test if a "bag" needs to be scanned
223 for tocheck = 0, 5 do
224  
225 -- if there is one
226 if (Tit_R_PleaseCheckBag[tocheck] == 1) then
227 Tit_R_CheckForUpdate = true; -- so Tit_R_CheckForUpdate will remain false only if there WAS nothing to do :-) (The WAS is important)
228 -- and ONLY if no event fires while we were in this loop... We can't miss anything :-D
229  
230 -- increase the delay timer
231 Tit_R_DelayTimer = Tit_R_DelayTimer + Elapsed;
232  
233 -- if enough time has elapsed
234 if (Tit_R_DelayTimer > Tit_R_UpdateCheckDelay) then
235  
236 -- we are checking...
237 Tit_R_PleaseCheckBag[tocheck] = 2;
238 -- reset the timer, next update will be made once Tit_R_UpdateCheckDelay seconds have elapsed from now
239 Tit_R_DelayTimer = 0;
240  
241 if (tocheck ~= 5) then -- call update inventory function (I've put this test first because there is 5 chances on 6 that it returns true)
242 tit_debug_bis("Upadate: Checking bag " .. tocheck .. " as requested");
243 TitanRepair_GetInventoryInformation(tocheck);
244 else -- call update equiped items function
245 tit_debug_bis("Upadate: Checking equiped items as requested");
246 TitanRepair_GetEquipedInformation();
247 end
248  
249 -- test if another check was not asked during this update (avoid to miss something... rare but still)
250 if (Tit_R_PleaseCheckBag[tocheck] ~= 1) then
251 -- Check completed
252 Tit_R_PleaseCheckBag[tocheck] = 0;
253 end
254  
255 -- we break here since we don't have time to scan anything else.
256 break;
257  
258 else
259 break;
260 end
261  
262  
263 end
264 end
265  
266 -- These lines are commented because they're here just for debugging...
267 -- if (not Tit_R_CheckForUpdate) then
268 -- if we get here it means there was nothing to update (we've gone through 0 to 5 without hitting a bag to check that would have set Tit_R_CheckForUpdatep to true)
269 -- tit_debug_bis("***No more \"Please\" to handle, easy mode on");
270 -- end
271  
272 end;
273  
274  
275 function TitanRepair_GetStatusPercent(val, max)
276  
277 if (max > 0) then
278 return (val / max);
279 end
280  
281 return 1.0;
282  
283 end;
284  
285 function TitanRepair_GetMostDamagedItem ()
286 -- Get repair status for Equiped items and inventory
287 -- NOTE: TitanRepair_GetStatusPercent() will return 1.0 if max value <= 0
288 local EquipedItemsStatus = TitanRepair_GetStatusPercent( REPAIR_ITEM_STATUS[Tit_R_EquipedMinIndex].val, REPAIR_ITEM_STATUS[Tit_R_EquipedMinIndex].max );
289 local InventoryItemsStatus = TitanRepair_GetStatusPercent( REPAIR_ITEM_STATUS[12].val, REPAIR_ITEM_STATUS[12].max );
290  
291 -- if everything is repaired
292 if (EquipedItemsStatus == 1.0 and InventoryItemsStatus == 1.0) then
293 tit_debug_bis("Everything is repaired");
294 return 0;
295 end
296  
297 -- If something is more or equaly damaged than the current most damaged equiped item
298 --
299 -- NOTE: The <= is important because InventoryItemsStatus is updated BEFORE EquipedItemsStatus
300 -- The typicale case is when you move the most damaged equiped item to your iventory,
301 -- when this function will be called by TitanRepair_GetInventoryInformation(), Tit_R_EquipedMinIndex will point to an empty slot:
302 -- since TitanRepair_GetEquipedInformation() won't have been called yet (bag update events are treated before equiped item event),
303 -- EquipedItemsStatus will be egual to InventoryItemsStatus...
304 -- So the <= is to avoid that Tit_R_EquipedMinIndex points to nothing (even if it has no concequence right now, it may save hours of debugging some day...)
305  
306 if ( (InventoryItemsStatus <= EquipedItemsStatus) and (TitanGetVar(TITAN_REPAIR_ID,"ShowInventory") == 1) ) then
307 tit_debug_bis("Inventory is more damaged than equiped items");
308 return 12;
309 else -- if EquipedItemsStatus < InventoryItemsStatus
310 tit_debug_bis("Equiped items are more damaged than inventory");
311 return Tit_R_EquipedMinIndex;
312 end
313  
314 -- Typical 6 possibilities:
315 -- - InventoryItemsStatus == 1 and EquipedItemsStatus == 1 ==> returns 0
316 -- - InventoryItemsStatus < 1 and EquipedItemsStatus == 1 ==> returns 12
317 -- - InventoryItemsStatus == 1 and EquipedItemsStatus < 1 ==> ! (InventoryItemsStatus <= EquipedItemsStatus) ==> returns Tit_R_EquipedMinIndex
318 -- - InventoryItemsStatus < 1 and EquipedItemsStatus < 1 :
319 -- - InventoryItemsStatus <= EquipedItemsStatus ==> returns 12
320 -- - InventoryItemsStatus > EquipedItemsStatus ==> ! (InventoryItemsStatus <= EquipedItemsStatus) ==> returns Tit_R_EquipedMinIndex
321  
322 end;
323  
324 function TitanRepair_GetInventoryInformation(bag)
325 local min_status = 1.0;
326 local min_val = 0;
327 local min_max = 0;
328  
329 TitanRepairTooltip:SetOwner(WorldFrame, "ANCHOR_NONE");
330  
331 if (bag > 4) then -- should never get true though, bag > 4 are for the bank's bags
332 return;
333 end
334  
335 -- we re-scan the whole bag so we reset its status
336 INVENTORY_REPAIR_STATUS[bag].cost = 0; -- reset this bag globl repair cost
337 INVENTORY_REPAIR_STATUS[bag].val = 0; --
338 INVENTORY_REPAIR_STATUS[bag].max = 0; --
339  
340 for slot = 1, GetContainerNumSlots(bag) do -- find the most damaged item of this bag
341  
342 local act_status, act_val, act_max, act_cost = TitanRepair_GetStatus(slot, bag); -- retrieve slot's item repair status
343  
344 if (act_status < min_status) then -- if this item is more damaged than the others
345 min_status = act_status;
346 min_val = act_val;
347 min_max = act_max;
348  
349 -- set the global bag repair state to this item state
350 INVENTORY_REPAIR_STATUS[bag].val = act_val;
351 INVENTORY_REPAIR_STATUS[bag].max = act_max;
352 end
353 -- add this item cost to this bag global repair cost
354 INVENTORY_REPAIR_STATUS[bag].cost = INVENTORY_REPAIR_STATUS[bag].cost + act_cost;
355 end
356  
357 -- We check all the bags so we reset the global inventory status
358 REPAIR_ITEM_STATUS[12].cost = 0; -- reset global repair cost for inventory
359 REPAIR_ITEM_STATUS[12].val = 0; --
360 REPAIR_ITEM_STATUS[12].max = 0; --
361 min_status = 1.0; -- reset min status to maximum
362  
363 -- let's find the bag that contains the most damaged item of the inventory
364 for bag = 0, 4 do
365  
366 local act_val = INVENTORY_REPAIR_STATUS[bag].val ;
367 local act_max = INVENTORY_REPAIR_STATUS[bag].max ;
368 local act_cost = INVENTORY_REPAIR_STATUS[bag].cost ;
369 local act_status= TitanRepair_GetStatusPercent(act_val, act_max);
370  
371 -- if the bag contains a damaged item (else act_status == 1, and min_status <= 1 and so this if never get true)
372 if (act_status < min_status) then
373 min_status = act_status;
374 min_val = act_val;
375 min_max = act_max;
376  
377 REPAIR_ITEM_STATUS[12].val = act_val;
378 REPAIR_ITEM_STATUS[12].max = act_max;
379 end
380 -- add each bag global repair cost to inventory global repair cost
381 REPAIR_ITEM_STATUS[12].cost = REPAIR_ITEM_STATUS[12].cost + act_cost;
382 end
383  
384 REPAIR_INDEX = TitanRepair_GetMostDamagedItem();
385  
386 tit_debug_bis("(inv) REPAIR_INDEX=" ..REPAIR_INDEX );
387  
388 -- Update the button text only if we are not waiting for TitanRepair_GetEquipedInformation()
389 -- else an incorrect value may be displayed till TitanRepair_GetEquipedInformation() is called
390 -- if a whole scan is in progress we update the button ("Updating..." is displayed in that case, so incorrect values are acceptable)
391 if ( (Tit_R_PleaseCheckBag[5] == 0) or Tit_R_WholeScanInProgress ) then
392 TitanPanelButton_UpdateButton(TITAN_REPAIR_ID);
393 else
394 tit_debug_bis("Waiting for updating button text");
395 end
396 TitanPanelButton_UpdateTooltip();
397 TitanRepairTooltip:Hide();
398 end
399  
400 function TitanRepair_GetEquipedInformation()
401 local min_status = 1.0;
402 local min_val = 0;
403 local min_max = 0;
404 local min_index = 0;
405 Tit_R_EquipedMinIndex = 0;
406  
407 TitanRepairTooltip:SetOwner(WorldFrame, "ANCHOR_NONE");
408  
409 for index, value in INVENTORY_ALERT_STATUS_SLOTS do -- index begins from 1
410  
411 local act_status, act_val, act_max, act_cost = TitanRepair_GetStatus(index);
412 if ( act_status < min_status ) then
413 min_status = act_status;
414 min_val = act_val;
415 min_max = act_max;
416 min_index = index;
417 end
418  
419 REPAIR_ITEM_STATUS[index].val = act_val;
420 REPAIR_ITEM_STATUS[index].max = act_max;
421 REPAIR_ITEM_STATUS[index].cost = act_cost;
422 end
423 Tit_R_EquipedMinIndex = min_index;
424  
425  
426 REPAIR_INDEX = TitanRepair_GetMostDamagedItem();
427  
428 -- if a whole update is in progress, and we are here, then we have finished this wole update :)
429 -- it has to be here because it changes the text of the button.
430 if (Tit_R_WholeScanInProgress) then
431 Tit_R_WholeScanInProgress = false;
432 end
433  
434 tit_debug_bis("(equip) REPAIR_INDEX=" ..REPAIR_INDEX .. " min_index=" .. min_index);
435  
436 TitanPanelButton_UpdateButton(TITAN_REPAIR_ID);
437 TitanPanelButton_UpdateTooltip();
438 TitanRepairTooltip:Hide();
439 end
440  
441 function TitanRepair_GetStatus(index, bag)
442 local val = 0;
443 local max = 0;
444 local cost = 0;
445 local hasItem, repairCost
446  
447 if (bag) then
448 local _, lRepairCost = TitanRepairTooltip:SetBagItem(bag, index);
449 repairCost = lRepairCost;
450 hasItem = 1;
451 else
452 local slotName = REPAIR_ITEM_STATUS[index].slot .. "Slot";
453  
454 local id = GetInventorySlotInfo(slotName);
455 local lHasItem, _, lRepairCost = TitanRepairTooltip:SetInventoryItem("player", id);
456 hasItem = lHasItem;
457 repairCost = lRepairCost;
458 end
459  
460 if (hasItem) then
461 if (repairCost) then
462 cost = repairCost;
463 end
464  
465 for i = 1, 30 do
466 local field = getglobal("TitanRepairTooltipTextLeft" .. i);
467 if (field ~= nil) then
468 local text = field:GetText();
469 if (text) then
470 -- find durability
471 local _, _, f_val, f_max = string.find(text, REPAIR_LOCALE["pattern"]);
472 if (f_val) then
473 val = tonumber(f_val);
474 max = tonumber(f_max);
475 end
476 end
477 end
478  
479 end
480  
481 end
482  
483 return TitanRepair_GetStatusPercent(val, max), val, max, cost;
484  
485 end
486  
487 local Tit_R_LastKnownText = "";
488 local Tit_R_LastKnownItemFrac = 1.0;
489 function TitanRepair_GetStatusStr(index, short)
490 -- skip if fully repaired
491 if (index == 0) then
492 return TitanRepair_AutoHighlight(1.0, "100%");
493 end
494  
495 local valueText = "";
496  
497 -- if used for button text
498 if (short) then
499 valueText = Tit_R_LastKnownText;
500 end
501  
502 local item_status = REPAIR_ITEM_STATUS[index];
503 local item_frac = TitanRepair_GetStatusPercent(item_status.val, item_status.max);
504  
505 -- skip if empty slot
506 if (item_status.max == 0) then
507 if (short) then
508  
509 if (not Tit_R_WholeScanInProgress) then
510 valueText = TitanRepair_AutoHighlight(Tit_R_LastKnownItemFrac, valueText .. " (" .. REPAIR_LOCALE["WholeScanInProgress"] .. ")");
511 else
512 valueText = TitanRepair_AutoHighlight(Tit_R_LastKnownItemFrac, valueText);
513 end
514  
515 return valueText;
516 else
517 return nil;
518 end
519 end
520  
521 -- percent or value
522 if (TitanGetVar(TITAN_REPAIR_ID,"ShowPercentage") or short) then
523 valueText = string.format("%d%%", item_frac * 100);
524 else
525 valueText = string.format("%d / %d", item_status.val, item_status.max);
526 end
527  
528  
529 -- color
530 valueText = TitanRepair_AutoHighlight(item_frac, valueText);
531 -- name
532  
533 if (not short or TitanGetVar(TITAN_REPAIR_ID, "ShowItemName")) then
534 valueText = valueText .. " " .. item_status.name;
535 end
536  
537 -- add repair cost
538 local item_cost = TitanRepair_GetCostStr(item_status.cost);
539 if (not short and item_cost) then
540 valueText = valueText .. "\t" .. item_cost;
541 end
542  
543 if (short) then
544 Tit_R_LastKnownText = valueText;
545 Tit_R_LastKnownItemFrac = item_frac;
546 end
547 return valueText;
548  
549 end
550  
551 function TitanRepair_AutoHighlight (item_frac, valueText)
552 -- I've changed this so when the ratio is 1, the text is green (green means OK for FPS, Latency, etc...)
553 -- beneath 0.91 (so it can be true for 0.90) the text is white
554 -- and red if the ratio reach 0.20
555 -- I didn't check for <= 0.90 or <= 0.20 because fractional eguality test is not acurate...
556 if (TitanGetVar(TITAN_REPAIR_ID, "ShowColoredText")) then
557 if (item_frac == 0.0) then
558 valueText = TitanUtils_GetRedText(valueText);
559 elseif (item_frac < 0.21) then
560 valueText = TitanUtils_GetNormalText(valueText);
561 elseif (item_frac < 0.91) then
562 valueText = TitanUtils_GetHighlightText(valueText);
563 else
564 valueText = TitanUtils_GetGreenText(valueText);
565 end
566 else
567 valueText = TitanUtils_GetHighlightText(valueText);
568 end
569  
570 return valueText;
571 end
572  
573 function TitanRepair_GetCostStr(cost)
574 if (cost > 0) then
575 return TitanUtils_GetHighlightText(string.format("%.2fg" , cost / 10000));
576 end
577  
578 return nil;
579 end
580  
581 -- to move in the localisation files
582 REPAIR_LOCALE["WholeScanInProgress"] = "Updating...";
583  
584 function TitanPanelRepairButton_GetButtonText(id)
585 -- supports turning off labels
586 if (not Tit_R_WholeScanInProgress) then
587 return REPAIR_LOCALE["button"], TitanRepair_GetStatusStr(REPAIR_INDEX, 1);
588 else
589 return REPAIR_LOCALE["button"], TitanRepair_GetStatusStr(REPAIR_INDEX, 1) .. " (" .. REPAIR_LOCALE["WholeScanInProgress"] .. ")";
590 end
591 end
592  
593  
594 function TitanPanelRepairButton_GetTooltipText()
595 local out = "";
596 local cost = 0;
597 local sum = 0;
598  
599 for i = 1, table.getn(REPAIR_ITEM_STATUS) do
600 local str = TitanRepair_GetStatusStr(i);
601  
602 cost = REPAIR_ITEM_STATUS[i].cost;
603 sum = sum + cost;
604  
605 if ((str) and (TitanGetVar(TITAN_REPAIR_ID,"ShowUndamaged") or (cost > 0))) then
606 out = out .. str .. "\n";
607 end
608 end
609  
610 if (sum > 0) then
611 local costStr = TitanRepair_GetCostStr(sum);
612 if (costStr) then
613 out = out .. "\n" .. REPAIR_COST .. " " .. costStr;
614 end
615 else
616 out = out .. "\n" .. REPAIR_LOCALE["nothing"];
617 end
618  
619 return out;
620  
621 end
622  
623  
624 function TitanPanelRightClickMenu_PrepareRepairMenu()
625 TitanPanelRightClickMenu_AddTitle(TitanPlugins[TITAN_REPAIR_ID].menuText);
626  
627 local info = {};
628 info.text = REPAIR_LOCALE["percentage"];
629 info.func = TitanRepair_ShowPercentage;
630 info.checked = TitanGetVar(TITAN_REPAIR_ID,"ShowPercentage");
631 UIDropDownMenu_AddButton(info);
632  
633 local info = {};
634 info.text = REPAIR_LOCALE["itemname"];
635 info.func = TitanRepair_ShowItemName;
636 info.checked = TitanGetVar(TITAN_REPAIR_ID,"ShowItemName");
637 UIDropDownMenu_AddButton(info);
638  
639 local info = {};
640 info.text = REPAIR_LOCALE["undamaged"];
641 info.func = TitanRepair_ShowUndamaged;
642 info.checked = TitanGetVar(TITAN_REPAIR_ID,"ShowUndamaged");
643 UIDropDownMenu_AddButton(info);
644  
645 local info = {};
646 info.text = REPAIR_LOCALE["popup"];
647 info.func = TitanRepair_ShowPop;
648 info.checked = TitanGetVar(TITAN_REPAIR_ID,"ShowPopup");
649 UIDropDownMenu_AddButton(info);
650  
651 local info = {};
652 info.text = REPAIR_LOCALE["repinventory"];
653 info.func = TitanRepair_RepairInventory;
654 info.checked = TitanGetVar(TITAN_REPAIR_ID,"RepairInventory");
655 UIDropDownMenu_AddButton(info);
656  
657 local info = {};
658 info.text = REPAIR_LOCALE["showinventory"];
659 info.func = TitanRepair_ShowInventory;
660 info.checked = TitanGetVar(TITAN_REPAIR_ID,"ShowInventory");
661 UIDropDownMenu_AddButton(info);
662  
663 TitanPanelRightClickMenu_AddSpacer();
664 TitanPanelRightClickMenu_AddToggleIcon(TITAN_REPAIR_ID);
665 TitanPanelRightClickMenu_AddToggleLabelText(TITAN_REPAIR_ID);
666 TitanPanelRightClickMenu_AddToggleColoredText(TITAN_REPAIR_ID);
667  
668 TitanPanelRightClickMenu_AddSpacer();
669 TitanPanelRightClickMenu_AddCommand(TITAN_PANEL_MENU_HIDE, TITAN_REPAIR_ID, TITAN_PANEL_MENU_FUNC_HIDE);
670 end
671  
672  
673 function TitanRepair_ShowPercentage()
674 TitanToggleVar(TITAN_REPAIR_ID, "ShowPercentage");
675 TitanPanelButton_UpdateButton(TITAN_REPAIR_ID);
676 end
677  
678  
679 function TitanRepair_ShowItemName()
680 TitanToggleVar(TITAN_REPAIR_ID, "ShowItemName");
681 TitanPanelButton_UpdateButton(TITAN_REPAIR_ID);
682 end
683  
684  
685 function TitanRepair_ShowUndamaged()
686 TitanToggleVar(TITAN_REPAIR_ID, "ShowUndamaged");
687 end
688  
689 function TitanRepair_ShowPop()
690 TitanToggleVar(TITAN_REPAIR_ID, "ShowPopup");
691 end
692  
693 function TitanRepair_RepairInventory()
694 TitanToggleVar(TITAN_REPAIR_ID, "RepairInventory");
695 end
696  
697 function TitanRepair_ShowInventory()
698  
699 if (Tit_R_WholeScanInProgress) then
700 return;
701 end
702  
703 tit_debug_bis("TitanRepair_ShowInventory has been called !!");
704 TitanToggleVar(TITAN_REPAIR_ID, "ShowInventory");
705  
706 if TitanGetVar(TITAN_REPAIR_ID,"ShowInventory") ~= 1 then
707 REPAIR_ITEM_STATUS[12].cost = 0;
708 REPAIR_ITEM_STATUS[12].val = 0;
709 REPAIR_ITEM_STATUS[12].max = 0;
710  
711 end
712 TitanPanelRepairButton_ScanAllItems();
713 Tit_R_CheckForUpdate = true;
714 end
715  
716 function TitanRepair_RepairItems()
717 RepairAllItems();
718  
719 if (not TitanGetVar(TITAN_REPAIR_ID, "RepairInventory")) then
720 return;
721 end
722  
723 ShowRepairCursor();
724 local bag, slot
725 for bag = 0, 4 do
726 for slot = 1, GetContainerNumSlots(bag) do
727 local _, repairCost = TitanRepairTooltip:SetBagItem(bag, slot);
728 if (repairCost and (repairCost > 0)) then
729 UseContainerItem(bag,slot);
730 Tit_R_PleaseCheckBag[bag] = 1; -- this bag will be updated
731 Tit_R_CheckForUpdate = true;
732 end
733 end
734 end
735 HideRepairCursor();
736 end
737  
738  
739 function TitanRepair_GetRepairInvCost()
740 local result = 0;
741 local bag;
742 TitanRepairTooltip:SetOwner(WorldFrame, "ANCHOR_NONE");
743  
744 for bag = 0, 4 do
745 for slot = 1, GetContainerNumSlots(bag) do
746 local _, repairCost = TitanRepairTooltip:SetBagItem(bag, slot);
747 if (repairCost and (repairCost > 0)) then
748 result = result + repairCost;
749 end
750 end
751 end
752 TitanRepairTooltip:Hide();
753  
754 return result;
755 end
756  
757  
758