vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 TITAN_DURABILITY_ID = "Durability";
2 TITAN_DURABILITY_FREQUENCY = 1;
3  
4 TITAN_DURABILITY_FORMAT = "%d%%";
5  
6 -- Local variables
7 TitanDurability_totalRepairCost = 0;
8 TitanDurability_duraPercent = 0;
9 TitanDurability_duraCurr = 0;
10 TitanDurability_duraTotal = 0;
11 TitanDurability_itemstats = {};
12  
13 function TitanPanelDurabilityButton_OnLoad()
14 _, _, TITAN_DURABILITY_TEXT = string.find(DURABILITY_TEMPLATE, "(.+) %%[^%s]+ / %%[^%s]+")
15 TITAN_DURABILITY_TOOLTIP_REPAIR = REPAIR_COST.. "\t";
16 TITAN_DURABILITY_TOOLTIP_DURA = TITAN_DURABILITY_TEXT.. ":\t"
17 TITAN_DURABILITY_LABEL = TITAN_DURABILITY_TEXT.. ": ";
18  
19 this.registry = {
20 id = TITAN_DURABILITY_ID,
21 menuText = TITAN_DURABILITY_TEXT,
22 buttonTextFunction = "TitanPanelDurabilityButton_GetButtonText",
23 tooltipTitle = TITAN_DURABILITY_TEXT,
24 tooltipTextFunction = "TitanPanelDurabilityButton_GetTooltipText",
25 frequency = TITAN_DURABILITY_FREQUENCY,
26 icon = "Interface\\Icons\\Trade_BlackSmithing.blp";
27 iconWidth = 16,
28 savedVariables = {
29 ShowLabelText = 1,
30 ShowColoredText = 1,
31 ShowIcon = 1,
32 iteminfo = 0,
33 hideguy = 0,
34 }
35 };
36  
37 this:RegisterEvent("PLAYER_ENTERING_WORLD");
38 this:RegisterEvent("UPDATE_INVENTORY_ALERTS");
39 end
40  
41 function TitanPanelDurabilityButton_GetButtonText(id)
42 if (not TitanDurability_duraPercent) then
43 return TITAN_DURABILITY_NUDE;
44 end
45 if ( TitanGetVar(TITAN_DURABILITY_ID, "ShowColoredText") ) then
46 duraRichText = TitanPanelDurability_GetColoredText(TitanDurability_duraPercent);
47 else
48 local duraText = format(TITAN_DURABILITY_FORMAT,TitanDurability_duraPercent);
49 duraRichText = TitanUtils_GetHighlightText(duraText);
50 end
51  
52 return TITAN_DURABILITY_LABEL,duraRichText;
53 end
54  
55 function TitanPanelDurabilityButton_GetTooltipText()
56 local retstr = "\n";
57 if (not TitanDurability_duraPercent) then
58 retstr = retstr.. TITAN_DURABILITY_TOOLTIP_DURA.. GSC_NONE.. "\n";
59 else
60 retstr = retstr.. TITAN_DURABILITY_TOOLTIP_DURA.. TitanPanelDurability_GetColoredText(TitanDurability_duraPercent).. "\n";
61 end
62 retstr = retstr.. TITAN_DURABILITY_TOOLTIP_REPAIR.. TitanPanelDurability_GetTextGSC(TitanDurability_totalRepairCost);
63  
64 if (TitanGetVar(TITAN_DURABILITY_ID, "iteminfo")) then
65 local slots = {
66 {"Head", HEADSLOT},
67 {"Shoulder", SHOULDERSLOT},
68 {"Chest", CHESTSLOT},
69 {"Wrist", WRISTSLOT},
70 {"Hands", HANDSSLOT},
71 {"Waist", WAISTSLOT},
72 {"Legs", LEGSSLOT},
73 {"Feet", FEETSLOT},
74 {"MainHand", MAINHANDSLOT},
75 {"SecondaryHand", SECONDARYHANDSLOT},
76 {"Ranged", RANGEDSLOT},
77 };
78  
79 retstr = retstr.. "\n";
80 for i,arr in slots do
81 local stats = TitanDurability_itemstats[arr[1]]
82 if (stats) then
83 if (stats[1] == GSC_NONE) then
84 retstr = retstr.. "\n".. arr[2]..":\t".. stats[1];
85 else
86 if ( TitanGetVar(TITAN_DURABILITY_ID, "ShowColoredText") ) then
87 retstr = retstr.. "\n".. arr[2]..":\t".. TitanPanelDurability_GetColoredText(stats[1]);
88 else
89 local duraText = TitanUtils_GetHighlightText(format(TITAN_DURABILITY_FORMAT,stats[1]));
90 retstr = retstr.. "\n".. arr[2]..":\t".. duraText;
91 end
92 end
93 end
94 end
95 retstr = retstr.. "\n";
96 for i,arr in slots do
97 cost = TitanDurability_itemstats[arr[1]][2];
98 if (cost ~= GSC_NONE) then
99 retstr = retstr.. "\n".. arr[2]..":\t".. cost;
100 end
101 end
102 end
103  
104 return retstr;
105 end
106  
107 function TitanPanelDurabilityButton_OnEvent()
108 if (event == "PLAYER_ENTERING_WORLD")
109 or (event == "UPDATE_INVENTORY_ALERTS")
110 then
111 TitanPanelDurability_CalcValues();
112 end
113 end
114  
115 function TitanPanelRightClickMenu_PrepareDurabilityMenu()
116 local id = "Durability";
117 local info = {};
118  
119 TitanPanelRightClickMenu_AddTitle(TitanPlugins[TITAN_DURABILITY_ID].menuText);
120 TitanPanelRightClickMenu_AddSpacer();
121  
122 info = {};
123 info.text = TITAN_DURABILITY_MENU_ITEMS;
124 info.value = "iteminfo";
125 info.func = TitanPanelDurability_Toggle;
126 info.checked = TitanGetVar(TITAN_DURABILITY_ID, "iteminfo");
127 UIDropDownMenu_AddButton(info);
128  
129 info = {};
130 info.text = TITAN_DURABILITY_MENU_GUY;
131 info.value = "hideguy";
132 info.func = TitanPanelDurability_Toggle;
133 info.checked = TitanGetVar(TITAN_DURABILITY_ID, "hideguy");
134 UIDropDownMenu_AddButton(info);
135  
136 TitanPanelRightClickMenu_AddToggleIcon(TITAN_DURABILITY_ID);
137 TitanPanelRightClickMenu_AddToggleLabelText(TITAN_DURABILITY_ID);
138 TitanPanelRightClickMenu_AddToggleColoredText(TITAN_DURABILITY_ID);
139 TitanPanelRightClickMenu_AddCommand(TITAN_PANEL_MENU_HIDE, id, TITAN_PANEL_MENU_FUNC_HIDE);
140 end
141  
142 function TitanPanelDurability_Toggle()
143 TitanToggleVar(TITAN_DURABILITY_ID, this.value);
144 TitanPanelButton_UpdateButton(TITAN_DURABILITY_ID);
145  
146 if (this.value == "hideguy") then TitanPanelDurability_CalcValues(); end
147 end
148  
149 function TitanPanelDurability_CalcValues()
150 -- hide Durability "guy"
151 if (TitanGetVar(TITAN_DURABILITY_ID, "hideguy")) then
152 if (DurabilityFrame:IsVisible()) then
153 DurabilityFrame:Hide();
154 end
155 end
156  
157 local slotnames = {
158 "Head",
159 "Shoulder",
160 "Chest",
161 "Wrist",
162 "Hands",
163 "Waist",
164 "Legs",
165 "Feet",
166 "MainHand",
167 "SecondaryHand",
168 "Ranged",
169 };
170  
171 local id, hasItem, repairCost;
172 local itemName, durability, tmpText, midpt, lval, rval;
173  
174 TitanDurability_totalRepairCost = 0;
175 TitanDurability_duraPercent = 0;
176 TitanDurability_duraCurr = 0;
177 TitanDurability_duraTotal = 0;
178  
179 for i,slotName in slotnames do
180 id, _ = GetInventorySlotInfo(slotName.. "Slot");
181 TPDurTooltip:Hide()
182 TPDurTooltip:SetOwner(this, "ANCHOR_LEFT");
183 hasItem, _, repairCost = TPDurTooltip:SetInventoryItem("player", id);
184  
185 if ( not hasItem ) then
186 TPDurTooltip:ClearLines()
187 else
188 itemName = TPDurTooltipTextLeft1:GetText();
189  
190 --Search for durability line
191 for i=2, 15, 1 do
192 tmpText = getglobal("TPDurTooltipTextLeft"..i);
193 lval = nil;
194 rval = nil;
195 if (tmpText:GetText()) then
196  
197 local searchstr = string.gsub(DURABILITY_TEMPLATE, "%%d", "(.+)")
198 _, _, lval, rval = string.find(tmpText:GetText(), searchstr);
199 end
200 if (lval and rval) then break; end
201 end
202 end
203 if (lval and rval) then
204 local currpercent;
205 if (rval == 0) then
206 currpercent = GSC_NONE;
207 else
208 currpercent = math.floor(lval / rval * 100);
209 end
210 TitanDurability_itemstats[slotName] = {currpercent, TitanPanelDurability_GetTextGSC(repairCost)};
211 TitanDurability_duraCurr = TitanDurability_duraCurr + lval;
212 TitanDurability_duraTotal = TitanDurability_duraTotal + rval;
213 TitanDurability_totalRepairCost = TitanDurability_totalRepairCost + repairCost
214 lval = 0;
215 rval = 0;
216 else
217 TitanDurability_itemstats[slotName] = {GSC_NONE, GSC_NONE};
218 end
219 end
220 TPDurTooltip:Hide()
221 if (TitanDurability_duraTotal == 0) then
222 TitanDurability_duraPercent = nil
223 else
224 TitanDurability_duraPercent = math.floor(TitanDurability_duraCurr / TitanDurability_duraTotal * 100);
225 end
226 end
227  
228 -------------------------------------------------------------------------------
229 -- Gold formatting code, shamelessly "borrowed" from Auctioneer
230 -------------------------------------------------------------------------------
231  
232 function TitanPanelDurability_GetGSC(money)
233 local neg = false;
234 if (money == nil) then money = 0; end
235 if (money < 0) then
236 neg = true;
237 money = money * -1;
238 end
239 local g = math.floor(money / 10000);
240 local s = math.floor((money - (g*10000)) / 100);
241 local c = math.floor(money - (g*10000) - (s*100));
242 return g,s,c,neg;
243 end
244  
245 GSC_GOLD="ffd100";
246 GSC_SILVER="e6e6e6";
247 GSC_COPPER="c8602c";
248 GSC_START="|cff%s%d|r";
249 GSC_PART=".|cff%s%02d|r";
250 GSC_NONE="|cffa0a0a0"..NONE.."|r";
251  
252 function TitanPanelDurability_GetTextGSC(money)
253 local g, s, c, neg = TitanPanelDurability_GetGSC(money);
254 local gsc = "";
255 if (g > 0) then
256 gsc = format(GSC_START, GSC_GOLD, g);
257 gsc = gsc..format(GSC_PART, GSC_SILVER, s);
258 gsc = gsc..format(GSC_PART, GSC_COPPER, c);
259 elseif (s > 0) then
260 gsc = format(GSC_START, GSC_SILVER, s);
261 if (c > 0) then
262 gsc = gsc..format(GSC_PART, GSC_COPPER, c);
263 end
264 elseif (c > 0) then
265 gsc = gsc..format(GSC_START, GSC_COPPER, c);
266 else
267 gsc = GSC_NONE;
268 end
269  
270 if (neg) then gsc = "(".. gsc.. ")"; end
271  
272 return gsc;
273 end
274  
275 function TitanPanelDurability_GetColoredText(percent)
276 local green = GREEN_FONT_COLOR; -- 0.1, 1.00, 0.1
277 local yellow = NORMAL_FONT_COLOR; -- 1.0, 0.82, 0.0
278 local red = RED_FONT_COLOR; -- 1.0, 0.10, 0.1
279  
280 percent = percent / 100;
281 local color = {};
282  
283 if (percent == 1.0) then
284 color = green;
285 elseif (percent == 0.5) then
286 color = yellow;
287 elseif (percent == 0.0) then
288 color = red;
289 elseif (percent > 0.5) then
290 local pct = (1.0 - percent) * 2;
291 color.r =(yellow.r - green.r)*pct + green.r;
292 color.g = (yellow.g - green.g)*pct + green.g;
293 color.b = (yellow.b - green.b)*pct + green.b;
294 elseif (percent < 0.5) then
295 local pct = (0.5 - percent) * 2;
296 color.r = (red.r - yellow.r)*pct + yellow.r;
297 color.g = (red.g - yellow.g)*pct + yellow.g;
298 color.b = (red.b - yellow.b)*pct + yellow.b;
299 end
300  
301 local txt = format(TITAN_DURABILITY_FORMAT,percent*100);
302 local colortxt = TitanUtils_GetColoredText(txt, color);
303  
304 return colortxt;
305 end