Mercurial > wow > kbf
comparison KBF.lua @ 17:233745d4774b
basic, buggy, temp weapon enchant support. Secure headers are totally screwed with these
| author | Chris Mellon <arkanes@gmai.com> |
|---|---|
| date | Fri, 15 Oct 2010 21:41:55 -0500 |
| parents | 87131aeedc3f |
| children | 27aa0d9ffe43 |
comparison
equal
deleted
inserted
replaced
| 16:87131aeedc3f | 17:233745d4774b |
|---|---|
| 17 self.anchor:SetScript("OnUpdate", function() self:OnUpdate() end) | 17 self.anchor:SetScript("OnUpdate", function() self:OnUpdate() end) |
| 18 self.dirty = true -- force an immediate scan on login | 18 self.dirty = true -- force an immediate scan on login |
| 19 self:HideBlizzardBuffFrames() | 19 self:HideBlizzardBuffFrames() |
| 20 end | 20 end |
| 21 -- naming convention | 21 -- naming convention |
| 22 -- "frame" is the secure aura button created by the group handler | 22 -- a "frame" is the top-level button (secure button from the header, or one I make myself) |
| 23 -- "bar" is the set of icon + status bars that we create to show the buff time | 23 -- that will contain the UI information about the buff |
| 24 | |
| 25 -- a "bar" is a frame that has the icon, status bar, ect associated with it | |
| 24 | 26 |
| 25 function kbf:HideBlizzardBuffFrames() | 27 function kbf:HideBlizzardBuffFrames() |
| 26 local function HideBlizFrame(frame) | 28 local function HideBlizFrame(frame) |
| 27 if not frame then return end | 29 if not frame then return end |
| 28 frame:UnregisterAllEvents() | 30 frame:UnregisterAllEvents() |
| 54 end | 56 end |
| 55 -- temporary enchants | 57 -- temporary enchants |
| 56 -- TODO: The blizz secure aura header binds both temp enchants | 58 -- TODO: The blizz secure aura header binds both temp enchants |
| 57 -- to the main hand. No support for cancelling weapon enchants | 59 -- to the main hand. No support for cancelling weapon enchants |
| 58 -- until this gets fixed up | 60 -- until this gets fixed up |
| 61 local tempEnchant = self.secureFrame:GetAttribute("tempEnchant1") | |
| 62 if tempEnchant and tempEnchant:IsShown() then | |
| 63 if self.dirty or true then | |
| 64 self:BindBarToWeaponEnchant(tempEnchant, 16) | |
| 65 end | |
| 66 self:UpdateBarExpirationTime(tempEnchant) | |
| 67 end | |
| 68 tempEnchant = self.secureFrame:GetAttribute("tempEnchant2") | |
| 69 if tempEnchant and tempEnchant:IsShown() then | |
| 70 if self.dirty or true then | |
| 71 self:BindBarToWeaponEnchant(tempEnchant, 17) | |
| 72 end | |
| 73 self:UpdateBarExpirationTime(tempEnchant) | |
| 74 end | |
| 59 | 75 |
| 60 -- debuffs | 76 -- debuffs |
| 61 -- Since debuffs aren't cancellable, don't need to use the secure header | 77 -- Since debuffs aren't cancellable, don't need to use the secure header |
| 62 -- for them. This could be rewritten to support useful features like | 78 -- for them. This could be rewritten to support useful features like |
| 63 -- sorting & scaling and stuff. Honestly, should at least be alphabetical. | 79 -- sorting & scaling and stuff. Honestly, should at least be alphabetical. |
| 113 frame.timertext:SetText(self:FormatTimeText(remaining)) | 129 frame.timertext:SetText(self:FormatTimeText(remaining)) |
| 114 frame.statusbar:SetValue(remaining) | 130 frame.statusbar:SetValue(remaining) |
| 115 end | 131 end |
| 116 end | 132 end |
| 117 | 133 |
| 134 function kbf:BindBarToWeaponEnchant(parentFrame, slotOverride) | |
| 135 local index = parentFrame:GetAttribute("index") | |
| 136 -- allow passing of explicit slot in order to work around aura header bug | |
| 137 local slot = slotOverride or parentFrame:GetAttribute("target-slot") | |
| 138 local itemIndex = slot - 15 -- 1MH, 2OF | |
| 139 local RETURNS_PER_ITEM = 3 | |
| 140 local hasEnchant, remaining, enchantCharges = select(RETURNS_PER_ITEM * (itemIndex - 1) + 1, GetWeaponEnchantInfo()) | |
| 141 -- remaining time is in milliseconds | |
| 142 if not hasEnchant then return end | |
| 143 local remaining = remaining / 1000 | |
| 144 if not hasEnchant then return end -- this should never happen | |
| 145 local icon = GetInventoryItemTexture("player", slot) | |
| 146 -- this is terrible, but I hate myself and everyone else. | |
| 147 -- We're going to assume that the duration of the temp enchant | |
| 148 -- is either 60 minutes, or however long is left, because poisons are 1 hour | |
| 149 local duration = max((60 * 60), remaining) | |
| 150 local expirationTime = GetTime() + remaining | |
| 151 -- TODO | |
| 152 local name = GetItemInfo(GetInventoryItemID("player", slot)) | |
| 153 if not parentFrame.icon then | |
| 154 self:ConstructBar(parentFrame, 1, 0, 1) | |
| 155 end | |
| 156 self:SetBarAppearance(parentFrame, name, icon, enchantCharges, duration, expirationTime) | |
| 157 end | |
| 158 | |
| 118 function kbf:BindBarToBuff(parentFrame, unit) | 159 function kbf:BindBarToBuff(parentFrame, unit) |
| 119 local index = parentFrame:GetAttribute("index") | 160 local index = parentFrame:GetAttribute("index") |
| 120 local filter = parentFrame:GetAttribute("filter") | 161 local filter = parentFrame:GetAttribute("filter") |
| 121 local name, rank, icon, stacks, debuffType, duration, expirationTime, | 162 local name, rank, icon, stacks, debuffType, duration, expirationTime, |
| 122 unitCaster, isStealable, shouldConsolidate, spellId = UnitAura(unit, index, filter) | 163 unitCaster, isStealable, shouldConsolidate, spellId = UnitAura(unit, index, filter) |
| 146 parentFrame.statusbar:SetMinMaxValues(0,1) | 187 parentFrame.statusbar:SetMinMaxValues(0,1) |
| 147 parentFrame.statusbar:SetValue(1) | 188 parentFrame.statusbar:SetValue(1) |
| 148 end | 189 end |
| 149 end | 190 end |
| 150 | 191 |
| 192 -- expects time seconds | |
| 151 function kbf:FormatTimeText(time) | 193 function kbf:FormatTimeText(time) |
| 152 if not time or time == 0 then return "" end | 194 if not time or time == 0 then return "" end |
| 153 local timetext | 195 local timetext |
| 154 local h = floor(time/3600) | 196 local h = floor(time/3600) |
| 155 local m = time - (h*3600) | 197 local m = time - (h*3600) |
| 171 -- this is for the secure buttons, so use the attributes | 213 -- this is for the secure buttons, so use the attributes |
| 172 -- I'd like a better place to position this but it's funky for right now, handle it later | 214 -- I'd like a better place to position this but it's funky for right now, handle it later |
| 173 local unit = button.unit or button:GetAttribute("unit") | 215 local unit = button.unit or button:GetAttribute("unit") |
| 174 local filter = button.filter or button:GetAttribute("filter") | 216 local filter = button.filter or button:GetAttribute("filter") |
| 175 local index = button:GetAttribute("index") or button.index | 217 local index = button:GetAttribute("index") or button.index |
| 218 if unit and filter and index then | |
| 219 GameTooltip:SetOwner(button, "ANCHOR_BOTTOMLEFT"); | |
| 220 GameTooltip:SetFrameLevel(button:GetFrameLevel() + 2); | |
| 221 GameTooltip:SetUnitAura(unit, index, filter); | |
| 222 return | |
| 223 end | |
| 224 local slot = button:GetAttribute("target-slot") -- temp enchant | |
| 176 GameTooltip:SetOwner(button, "ANCHOR_BOTTOMLEFT"); | 225 GameTooltip:SetOwner(button, "ANCHOR_BOTTOMLEFT"); |
| 177 GameTooltip:SetFrameLevel(button:GetFrameLevel() + 2); | 226 GameTooltip:SetFrameLevel(button:GetFrameLevel() + 2); |
| 178 GameTooltip:SetUnitAura(unit, index, filter); | 227 GameTooltip:SetInventoryItem("player", slot) |
| 179 end | 228 end |
| 180 | 229 |
| 181 -- creates a icon + statusbar bar | 230 -- creates a icon + statusbar bar |
| 182 function kbf:ConstructBar(frame, r, g, b) | 231 function kbf:ConstructBar(frame, r, g, b) |
| 183 local texture = "Interface\\TargetingFrame\\UI-StatusBar" | 232 local texture = "Interface\\TargetingFrame\\UI-StatusBar" |
| 295 frame:SetAttribute("minHeight", 16) | 344 frame:SetAttribute("minHeight", 16) |
| 296 frame:SetAttribute("unit", "player") -- TODO: figure out the vehicle swapping stuff | 345 frame:SetAttribute("unit", "player") -- TODO: figure out the vehicle swapping stuff |
| 297 frame:SetAttribute("sortMethod", "NAME") | 346 frame:SetAttribute("sortMethod", "NAME") |
| 298 frame:SetAttribute("sortOrder", "-") | 347 frame:SetAttribute("sortOrder", "-") |
| 299 -- TODO: SecureAuraHeader doesn't correcltly implement the temp enchants | 348 -- TODO: SecureAuraHeader doesn't correcltly implement the temp enchants |
| 300 --frame:SetAttribute("weaponTemplate", "KBFSecureUnitAuraTemplate") | 349 frame:SetAttribute("weaponTemplate", "KBFSecureUnitAuraTemplate") |
| 301 --frame:SetAttribute("includeWeapons", 1) | 350 frame:SetAttribute("includeWeapons", 1) |
| 302 frame:SetPoint("TOP", anchor, "BOTTOM", 0, 0) | 351 frame:SetPoint("TOP", anchor, "BOTTOM", 0, 0) |
| 303 frame:Show() -- has to be shown, otherwise the child frames don't show | 352 frame:Show() -- has to be shown, otherwise the child frames don't show |
| 304 self.secureFrame = frame | 353 self.secureFrame = frame |
| 305 return anchor | 354 return anchor |
| 306 end | 355 end |
