vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 CT_ItemBuff_MinBuffMessageTime = 16;
2 CT_ItemBuff_MinBuffDuration = 15;
3 CT_ItemBuff_HasMainBuff = -1;
4 CT_ItemBuff_HasOffBuff = -1;
5  
6 -- Credits to Telo for the following 2 functions
7 local CT_GameTooltip_ClearMoney;
8  
9 local function CT_ItemBuff_MoneyToggle()
10 if( CT_GameTooltip_ClearMoney ) then
11 GameTooltip_ClearMoney = CT_GameTooltip_ClearMoney;
12 CT_GameTooltip_ClearMoney = nil;
13 else
14 CT_GameTooltip_ClearMoney = GameTooltip_ClearMoney;
15 GameTooltip_ClearMoney = CT_GameTooltipFunc_ClearMoney;
16 end
17 end
18  
19 function CT_GameTooltipFunc_ClearMoney()
20  
21 end
22  
23 function CT_ItemBuffFrame_OnUpdate(elapsed)
24 local hasMainHandEnchant, mainHandExpiration, mainHandCharges, hasOffHandEnchant, offHandExpiration, offHandCharges = GetWeaponEnchantInfo();
25  
26 -- No enchants, kick out early
27 if ( ( not hasMainHandEnchant and not hasOffHandEnchant ) or not CT_BuffFrame:IsVisible() ) then
28 CT_ItemBuffButton1:Hide();
29 CT_ItemBuffButton2:Hide();
30 return;
31 end
32  
33 -- Has enchants
34 local enchantButton;
35 local textureName;
36 local buffAlphaValue;
37 local enchantIndex = 0;
38 local name;
39 local duration;
40  
41 if ( hasOffHandEnchant ) then
42 local showIcon = 1;
43 local timeLeft = floor(offHandExpiration/1000);
44 if ( CT_ItemBuff_HasOffBuff == -1 ) then
45 CT_ItemBuff_HasOffBuff = timeLeft;
46 end
47 if ( CT_ItemBuff_HasOffBuff >= CT_ItemBuff_MinBuffDuration ) then
48 name = CT_ItemBuff_GetEnchantInfo(17);
49 local type = 2;
50 local typeLeft = timeLeft;
51 if ( timeLeft >= 60 ) then
52 type = 1;
53 typeLeft = ceil(timeLeft/60);
54 end
55 duration = CT_ItemBuff_FixString(typeLeft, type, offHandCharges);
56 enchantIndex = enchantIndex + 1;
57 textureName = GetInventoryItemTexture("player", 17);
58 CT_ItemBuffButton1:SetID(17);
59 CT_ItemBuffButton1Icon:SetTexture(textureName);
60 CT_ItemBuffButton1:Show();
61 CT_ItemBuffButton1DurationText:SetText(duration);
62 CT_ItemBuffButton1DescribeText:SetText(name);
63 hasEnchant = 1;
64  
65 if ( floor(timeLeft) == CT_ItemBuff_MinBuffMessageTime ) then
66 CT_ExpireBuffs[name] = 1;
67 end
68  
69 if ( ceil(timeLeft) == ExpireMessageTime and CT_ExpireBuffs[name] and CT_ExpireBuffs[name] == 1 ) then
70 CT_ExpireBuffs[name] = nil;
71 if ( CT_ShowExpire == 1 and name ) then
72 local message = format( ExpireMessageString, name );
73 CT_Print( message, ExpireMessageColors["r"], ExpireMessageColors["g"], ExpireMessageColors["b"] );
74 end
75 end
76 if ( timeLeft < BuffStartFlashTime ) then
77 if ( BuffFlashState == 1 ) then
78 buffAlphaValue = (BuffFlashOn - BuffFlashTime) / BuffFlashOn;
79 buffAlphaValue = buffAlphaValue * (1 - BuffMinOpacity) + BuffMinOpacity;
80 else
81 buffAlphaValue = BuffFlashTime / BuffFlashOn;
82 buffAlphaValue = (buffAlphaValue * (1 - BuffMinOpacity)) + BuffMinOpacity;
83 CT_ItemBuffButton1:SetAlpha(BuffFlashTime / BuffFlashOn);
84 end
85 CT_ItemBuffButton1:SetAlpha(buffAlphaValue);
86 else
87 CT_ItemBuffButton1:SetAlpha(1.0);
88 end
89 else
90 CT_ItemBuff_HasOffBuff = -1;
91 end
92  
93 end
94 if ( hasMainHandEnchant ) then
95 local showIcon = 1;
96 local timeLeft = floor(mainHandExpiration/1000);
97 if ( CT_ItemBuff_HasMainBuff == -1 ) then
98 CT_ItemBuff_HasMainBuff = timeLeft;
99 end
100 if ( CT_ItemBuff_HasMainBuff >= CT_ItemBuff_MinBuffDuration ) then
101  
102 name = CT_ItemBuff_GetEnchantInfo(16);
103 local type = 2;
104 local typeLeft = timeLeft;
105 if ( timeLeft >= 60 ) then
106 type = 1;
107 typeLeft = ceil(timeLeft/60);
108 end
109 duration = CT_ItemBuff_FixString(typeLeft, type, mainHandCharges);
110 enchantIndex = enchantIndex + 1;
111 enchantButton = getglobal("CT_ItemBuffButton"..enchantIndex);
112 textureName = GetInventoryItemTexture("player", 16);
113 enchantButton:SetID(16);
114 getglobal(enchantButton:GetName().."Icon"):SetTexture(textureName);
115 enchantButton:Show();
116 getglobal("CT_ItemBuffButton"..enchantIndex .. "DurationText"):SetText(duration);
117 getglobal("CT_ItemBuffButton"..enchantIndex .. "DescribeText"):SetText(name);
118 hasEnchant = 1;
119  
120 if ( timeLeft == CT_ItemBuff_MinBuffMessageTime ) then
121 CT_ExpireBuffs[name] = 1;
122 end
123  
124 if ( timeLeft == ExpireMessageTime and CT_ExpireBuffs[name] and CT_ExpireBuffs[name] == 1 ) then
125 CT_ExpireBuffs[name] = nil;
126 if ( CT_ShowExpire == 1 and name ) then
127 local message = format( ExpireMessageString, name );
128 CT_Print( message, ExpireMessageColors["r"], ExpireMessageColors["g"], ExpireMessageColors["b"] );
129 end
130 end
131 if ( timeLeft < BuffStartFlashTime ) then
132 if ( BuffFlashState == 1 ) then
133 buffAlphaValue = (BuffFlashOn - BuffFlashTime) / BuffFlashOn;
134 buffAlphaValue = buffAlphaValue * (1 - BuffMinOpacity) + BuffMinOpacity;
135 else
136 buffAlphaValue = BuffFlashTime / BuffFlashOn;
137 buffAlphaValue = (buffAlphaValue * (1 - BuffMinOpacity)) + BuffMinOpacity;
138 enchantButton:SetAlpha(BuffFlashTime / BuffFlashOn);
139 end
140 enchantButton:SetAlpha(buffAlphaValue);
141 else
142 enchantButton:SetAlpha(1.0);
143 end
144 else
145 CT_ItemBuff_HasMainBuff = -1;
146 end
147 end
148  
149 --Hide unused enchants
150 for i=enchantIndex+1, 2 do
151 getglobal("CT_ItemBuffButton"..i):Hide();
152 end
153  
154 if ( not CT_BuffButton0:IsVisible() ) then
155 CT_ItemBuffButton1:ClearAllPoints();
156 CT_ItemBuffButton1:SetPoint("TOPLEFT", "CT_BuffButton0", "TOPLEFT", 0, 0);
157 else
158 for i = 1, 23, 1 do
159 if ( not getglobal("CT_BuffButton" .. i):IsVisible() ) then
160 CT_ItemBuffButton1:ClearAllPoints();
161 CT_ItemBuffButton1:SetPoint("TOPLEFT", "CT_BuffButton" .. (i-1), "BOTTOMLEFT", 0, -5);
162 break;
163 end
164 end
165 end
166 end
167  
168 function CT_ItemBuff_FixString(num, type, charges)
169 local chargestring = "";
170 if ( charges == 1 ) then
171 chargestring = " 1 charge";
172 charges = 2;
173 elseif ( charges > 1 ) then
174 chargestring = " " .. charges .. " charges";
175 charges = 2;
176 end
177  
178 local types = {
179 { "minute", "second", "min", "sec" },
180 { "minutes", "seconds", "min", "sec" }
181 };
182  
183 if ( num == 1 ) then
184 return num .. " " .. types[1][(type+charges)] .. chargestring;
185 else
186 return num .. " " .. types[2][(type+charges)] .. chargestring;
187 end
188 end
189  
190 function CT_ItemBuff_GetEnchantInfo(id)
191 CT_IB_TempTooltip:ClearLines();
192 CT_ItemBuff_MoneyToggle();
193 local val = CT_IB_TempTooltip:SetInventoryItem("player", id)
194 CT_ItemBuff_MoneyToggle();
195  
196 if ( val ) then
197 for i = 1, 15, 1 do
198 text = getglobal("CT_IB_TempTooltipTextLeft"..i);
199 local text = text:GetText();
200 if ( strlen(text or "") > 0 )then
201 iStart, iEnd, temp = string.find(text, "([^%(]+) %(%d+.+%)$");
202 if ( temp ) then
203 return temp;
204 end
205 end
206 end
207 end
208 return nil;
209 end
210  
211 function CT_ItemBuffs_InitFunc(modId)
212 local val = CT_Mods[modId]["modStatus"];
213 if ( val == "on" ) then
214 CT_ItemBuff_MinBuffDuration = 0;
215 else
216 CT_ItemBuff_MinBuffDuration = 16;
217 end
218 end
219  
220 function CT_ItemBuffs_Func(modId)
221 local val = CT_Mods[modId]["modStatus"];
222 if ( val == "on" ) then
223 CT_Print("<CTMod> " .. CT_ITEMBUFFS_SHORTDURATION_SHOWN, 1, 1, 0);
224 CT_ItemBuff_MinBuffDuration = 0;
225 else
226 CT_Print("<CTMod> " .. CT_ITEMBUFFS_SHORTDURATION_HIDDEN, 1, 1, 0);
227 CT_ItemBuff_MinBuffDuration = 16;
228 end
229 end
230  
231 CT_RegisterMod(CT_ITEMBUFFS_MODNAME, CT_ITEMBUFFS_SUBNAME, 3, "Interface\\Icons\\INV_Misc_PocketWatch_01", CT_ITEMBUFFS_TOOLTIP, "off", nil, CT_ItemBuffs_Func, CT_ItemBuffs_InitFunc);
232  
233 -- Hook our own function ;)
234  
235 CT_Old_SwapSides = CT_Buffs_SwapSides;
236  
237 function CT_ItemBuffs_SwapSides(onLoad)
238 CT_Old_SwapSides(onLoad);
239 local i;
240 for i = 1, 2, 1 do
241 getglobal("CT_ItemBuffButton" .. i .. "DescribeText"):ClearAllPoints();
242 getglobal("CT_ItemBuffButton" .. i .. "DurationText"):ClearAllPoints();
243 if ( CT_BuffMod_BuffSides == "LEFT" or onLoad ) then
244 getglobal("CT_ItemBuffButton" .. i .. "DescribeText"):SetPoint("RIGHT", "CT_ItemBuffButton" .. i, "LEFT", -8, 7);
245 getglobal("CT_ItemBuffButton" .. i .. "DurationText"):SetPoint("RIGHT", "CT_ItemBuffButton" .. i, "LEFT", -8, -7);
246 elseif ( CT_BuffMod_BuffSides == "RIGHT" ) then
247 getglobal("CT_ItemBuffButton" .. i .. "DescribeText"):SetPoint("LEFT", "CT_ItemBuffButton" .. i, "LEFT", 40, 7);
248 getglobal("CT_ItemBuffButton" .. i .. "DurationText"):SetPoint("LEFT", "CT_ItemBuffButton" .. i, "LEFT", 40, -7);
249 end
250 end
251 end
252  
253 CT_Buffs_SwapSides = CT_ItemBuffs_SwapSides;
254  
255 function CT_ItemBuffs_GetStrTime(time)
256 local min, sec;
257 if ( time >= 60 ) then
258 min = floor(time/60);
259 sec = time - min*60;
260 else
261 sec = time;
262 min = 0;
263 end
264 if ( sec <= 9 ) then sec = "0" .. sec; end
265 if ( min <= 9 ) then min = "0" .. min; end
266 return min .. ":" .. sec;
267 end
268  
269 CT_oldBuffFrame_UpdateDuration = BuffFrame_UpdateDuration;
270  
271 function CT_newBuffFrame_UpdateDuration(buffButton, timeLeft)
272 CT_oldBuffFrame_UpdateDuration(buffButton, timeLeft);
273 local duration = getglobal(buffButton:GetName().."Duration");
274 if ( SHOW_BUFF_DURATIONS == "1" and timeLeft ) then
275 duration:SetText(CT_ItemBuffs_GetStrTime(floor(timeLeft)));
276 end
277 end
278  
279 BuffFrame_UpdateDuration = CT_newBuffFrame_UpdateDuration;