comparison KBF.lua @ 42:d792f986400f

Add in support for custom display of weapon enchants.
author Chris Mellon <arkanes@gmail.com>
date Tue, 18 Jan 2011 22:34:29 -0600
parents 15a0ceebbd83
children 81cade22f2f9
comparison
equal deleted inserted replaced
41:15a0ceebbd83 42:d792f986400f
107 end 107 end
108 buffCount = buffCount+1 108 buffCount = buffCount+1
109 end 109 end
110 110
111 -- temporary enchants 111 -- temporary enchants
112 -- TODO: So much copy/paste here. I really need to clean this up.
112 local tempEnchant = self.secureHeader:GetAttribute("tempEnchant1") 113 local tempEnchant = self.secureHeader:GetAttribute("tempEnchant1")
113 if tempEnchant and tempEnchant:IsShown() then 114 if tempEnchant and tempEnchant:IsShown() then
114 self:BindBarToWeaponEnchant(tempEnchant, 16) 115 self:BindBarToWeaponEnchant(tempEnchant, 16)
115 self:UpdateBarExpirationTime(tempEnchant) 116 self:UpdateBarExpirationTime(tempEnchant)
116 buffCount = buffCount + 1 117 buffCount = buffCount + 1
117 end 118 end
119 if ( tempEnchant and GameTooltip:IsOwned(tempEnchant) ) then
120 self:OnEnter(tempEnchant)
121 end
118 tempEnchant = self.secureHeader:GetAttribute("tempEnchant2") 122 tempEnchant = self.secureHeader:GetAttribute("tempEnchant2")
119 if tempEnchant and tempEnchant:IsShown() then 123 if tempEnchant and tempEnchant:IsShown() then
120 self:BindBarToWeaponEnchant(tempEnchant, 17) 124 self:BindBarToWeaponEnchant(tempEnchant, 17)
121 self:UpdateBarExpirationTime(tempEnchant) 125 self:UpdateBarExpirationTime(tempEnchant)
122 buffCount = buffCount + 1 126 buffCount = buffCount + 1
125 -- TODO: maybe this should only happen if we're dirty 129 -- TODO: maybe this should only happen if we're dirty
126 if not InCombatLockdown() then 130 if not InCombatLockdown() then
127 tempEnchant:SetAttribute('target-slot', 17) 131 tempEnchant:SetAttribute('target-slot', 17)
128 end 132 end
129 end 133 end
134 if ( tempEnchant and GameTooltip:IsOwned(tempEnchant) ) then
135 self:OnEnter(tempEnchant)
136 end
130 -- make a fake third buff bar. It can't be used to cancel the buff, but 137 -- make a fake third buff bar. It can't be used to cancel the buff, but
131 -- at least you can see it. 138 -- at least you can see it.
132 139
133 local thirdWeaponInfo = select(7, GetWeaponEnchantInfo()) 140 local thirdWeaponInfo = select(7, GetWeaponEnchantInfo())
134 if thirdWeaponInfo then 141 if thirdWeaponInfo then
150 self.tempEnchant3:SetPoint("TOP", self.secureHeader, "TOP", 0, (buffCount * -16)) 157 self.tempEnchant3:SetPoint("TOP", self.secureHeader, "TOP", 0, (buffCount * -16))
151 self:BindBarToWeaponEnchant(tempEnchant, 18) 158 self:BindBarToWeaponEnchant(tempEnchant, 18)
152 self:UpdateBarExpirationTime(tempEnchant) 159 self:UpdateBarExpirationTime(tempEnchant)
153 buffCount = buffCount + 1 160 buffCount = buffCount + 1
154 end 161 end
155 162 if ( tempEnchant and GameTooltip:IsOwned(tempEnchant) ) then
163 self:OnEnter(tempEnchant)
164 end
156 -- debuffs 165 -- debuffs
157 -- Since debuffs aren't cancellable, don't need to use the secure header 166 -- Since debuffs aren't cancellable, don't need to use the secure header
158 -- for them. This could be rewritten to support useful features like 167 -- for them. This could be rewritten to support useful features like
159 -- sorting & scaling and stuff. Honestly, should at least be alphabetical. 168 -- sorting & scaling and stuff. Honestly, should at least be alphabetical.
160 for idx=1,99 do 169 for idx=1,99 do
210 frame.timertext:SetText(self:FormatTimeText(remaining)) 219 frame.timertext:SetText(self:FormatTimeText(remaining))
211 frame.statusbar:SetValue(remaining) 220 frame.statusbar:SetValue(remaining)
212 end 221 end
213 end 222 end
214 223
224 local gratt = LibStub:GetLibrary("LibGratuity-3.0")
225
215 function kbf:BindBarToWeaponEnchant(parentFrame, slotOverride) 226 function kbf:BindBarToWeaponEnchant(parentFrame, slotOverride)
216 -- allow passing of explicit slot in order to work around aura header bug 227 -- allow passing of explicit slot in order to work around aura header bug
217 local slot = slotOverride or parentFrame:GetAttribute("target-slot") 228 local slot = slotOverride or parentFrame:GetAttribute("target-slot")
218 local itemIndex = slot - 15 -- 1MH, 2OF 229 local itemIndex = slot - 15 -- 1MH, 2OF
219 local RETURNS_PER_ITEM = 3 230 local RETURNS_PER_ITEM = 3
220 local hasEnchant, remaining, enchantCharges = select(RETURNS_PER_ITEM * (itemIndex - 1) + 1, GetWeaponEnchantInfo()) 231 local hasEnchant, remaining, enchantCharges = select(RETURNS_PER_ITEM * (itemIndex - 1) + 1, GetWeaponEnchantInfo())
221 -- remaining time is in milliseconds 232 -- remaining time is in milliseconds
222 if not hasEnchant then return end -- this should never happen 233 if not hasEnchant then return end -- this should never happen
223 local remaining = remaining / 1000 234 local remaining = remaining / 1000
235
224 local icon = GetInventoryItemTexture("player", slot) 236 local icon = GetInventoryItemTexture("player", slot)
225 -- this is terrible, but I hate myself and everyone else. 237 local maxDuration
226 -- We're going to assume that the duration of the temp enchant 238 if select(2, UnitClass("player")) == "ROGUE" then
227 -- is either 60 minutes, or however long is left, because poisons are 1 hour 239 -- Rogues are probably using poisons, which are an hour
228 local duration = max((60 * 60), remaining) 240 maxDuration = 60 * 60
241 else
242 -- everyone else is probably using something thats a half hour
243 maxDuration = 30 * 60
244 end
245 local duration = max(maxDuration, remaining)
229 local expirationTime = GetTime() + remaining 246 local expirationTime = GetTime() + remaining
230 -- TODO
231 local name = GetItemInfo(GetInventoryItemID("player", slot)) 247 local name = GetItemInfo(GetInventoryItemID("player", slot))
248 -- try to figure out what the weapon enchant is
249 -- tooltip string -> {spellid, duration}
250 local knownEnchants = {
251 ["Flametongue"] = {8024, 30*60},
252 ["Frostbrand"] = {8033, 30*60},
253
254 }
255 local spellId = nil
256 if gratt then
257 gratt:SetInventoryItem("player", slot)
258 for tag, info in pairs(knownEnchants) do
259 if gratt:Find(tag) then
260 spellId, duration = unpack(info)
261 -- TODO: Maybe want to leave it as the weapon icon?
262 -- I don't think theres enough room to add both the name of the weapon & the buff in there
263 -- maybe use the tag?
264 -- Or maybe use the slot name, ie Flametongue / Main Hand
265 name, _, _ = GetSpellInfo(spellId)
266 break
267 end
268 end
269 end
270 parentFrame.spellId = spellId
232 if not parentFrame.icon then 271 if not parentFrame.icon then
233 self:ConstructBar(parentFrame, 1, 0, 1) 272 self:ConstructBar(parentFrame, 1, 0, 1)
234 end 273 end
235 self:SetBarAppearance(parentFrame, name, icon, enchantCharges, duration, expirationTime) 274 self:SetBarAppearance(parentFrame, name, icon, enchantCharges, duration, expirationTime)
236 end 275 end
299 GameTooltip:SetFrameLevel(button:GetFrameLevel() + 2); 338 GameTooltip:SetFrameLevel(button:GetFrameLevel() + 2);
300 GameTooltip:SetUnitAura(unit, index, filter); 339 GameTooltip:SetUnitAura(unit, index, filter);
301 return 340 return
302 end 341 end
303 local slot = button:GetAttribute("target-slot") -- temp enchant 342 local slot = button:GetAttribute("target-slot") -- temp enchant
304 GameTooltip:SetOwner(button, "ANCHOR_BOTTOMLEFT"); 343 if slot then
305 GameTooltip:SetFrameLevel(button:GetFrameLevel() + 2); 344 GameTooltip:SetOwner(button, "ANCHOR_BOTTOMLEFT");
306 GameTooltip:SetInventoryItem(unit, slot) 345 GameTooltip:SetFrameLevel(button:GetFrameLevel() + 2);
346 if button.spellId then
347 -- TODO: This might be too big of a tooltip to care about that much.
348 -- Maybe I should just have a single line with the weapon name
349 --GameTooltip:SetInventoryItem(unit, slot)
350 local name = GetItemInfo(GetInventoryItemID("player", slot))
351 local r, g, b = GetItemQualityColor(GetInventoryItemQuality("player", slot))
352 GameTooltip:SetText(name, r, g, b)
353 GameTooltip:AddLine(" ")
354 GameTooltip:AddSpellByID(button.spellId)
355 else
356 GameTooltip:SetInventoryItem(unit, slot)
357 end
358 end
307 end 359 end
308 360
309 -- creates a icon + statusbar bar 361 -- creates a icon + statusbar bar
310 function kbf:ConstructBar(frame, r, g, b) 362 function kbf:ConstructBar(frame, r, g, b)
311 local texture = "Interface\\TargetingFrame\\UI-StatusBar" 363 local texture = "Interface\\TargetingFrame\\UI-StatusBar"