annotate ObjectiveTracker/Widgets.lua @ 41:7a65ed86e4dd r42-release

- prevent animation Play from firing more than once before block:Hide is called
author Nenue
date Sun, 24 Apr 2016 14:28:49 -0400
parents 92534dc793f2
children 9480bd904f4c
rev   line source
Nenue@28 1 local B = select(2,...).frame
Nenue@28 2 local T = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame')
Nenue@28 3 local print = B.print('WidgetFactory')
Nenue@28 4 local _G, UIParent = _G, UIParent
Nenue@28 5 local GetQuestLogSpecialItemInfo, IsQuestLogSpecialItemInRange, GetQuestLogSpecialItemCooldown = GetQuestLogSpecialItemInfo, IsQuestLogSpecialItemInRange, GetQuestLogSpecialItemCooldown
Nenue@28 6 local CooldownFrame_SetTimer, SetItemButtonTextureVertexColor, CreateFrame, VeneerObjectiveScroll = CooldownFrame_SetTimer, SetItemButtonTextureVertexColor, CreateFrame, VeneerObjectiveScroll
Nenue@28 7 local tremove, tContains, pairs, ipairs, setmetatable, floor = tremove, tContains, pairs, ipairs, setmetatable, floor
Nenue@28 8 local SetItemButtonTexture, SetItemButtonCount = SetItemButtonTexture, SetItemButtonCount
Nenue@28 9 local ToggleWorldMap, GetTrackedAchievements, GetTasksTable = ToggleWorldMap, GetTrackedAchievements, GetTasksTable
Nenue@28 10 -- GLOBALS: Veneer_QuestObjectiveItem_UpdateCooldown, Veneer_QuestObjectiveItem_OnUpdate
Nenue@28 11 --- frame refs
Nenue@28 12 local Wrapper = _G.VeneerObjectiveWrapper
Nenue@28 13 local Scroller = Wrapper.scrollArea
Nenue@28 14 local CloseButton = Wrapper.CloseButton
Nenue@28 15 local QuestMapButton = Wrapper.QuestMapButton
Nenue@28 16 local Scroll = _G.VeneerObjectiveScroll
Nenue@28 17 local usedButtons = T.Quest.itemButtons
Nenue@28 18 local freeButtons = T.Quest.freeButtons
Nenue@28 19
Nenue@28 20 T.buttons = {
Nenue@28 21 CloseButton = {
Nenue@28 22 closedSwatch = {
Nenue@28 23 [[Interface\Buttons\UI-Panel-QuestHideButton]],
Nenue@28 24 [[Interface\Buttons\UI-Panel-QuestHideButton]],
Nenue@28 25 0, 0.5, 0.5, 1,
Nenue@28 26 0.5, 1, 0.5, 1,
Nenue@28 27 },
Nenue@28 28 openSwatch = {
Nenue@28 29 [[Interface\Buttons\UI-Panel-QuestHideButton]],
Nenue@28 30 [[Interface\Buttons\UI-Panel-QuestHideButton]],
Nenue@28 31 0.5, 1, 0.5, 1,
Nenue@28 32 0, 0.5, 0.5, 1,
Nenue@28 33 },
Nenue@28 34 parent = 'VeneerObjectiveWrapper'
Nenue@28 35 },
Nenue@28 36 QuestMapButton = {
Nenue@28 37 closedSwatch = {
Nenue@28 38 [[Interface\QUESTFRAME\UI-QUESTMAP_BUTTON]],
Nenue@28 39 [[Interface\QUESTFRAME\UI-QUESTMAP_BUTTON]],
Nenue@28 40 0, 1, 0.5, 1,
Nenue@28 41 0, 1, 0, 0.5,
Nenue@28 42 },
Nenue@28 43 openSwatch = {
Nenue@28 44 [[Interface\QUESTFRAME\UI-QUESTMAP_BUTTON]],
Nenue@28 45 [[Interface\QUESTFRAME\UI-QUESTMAP_BUTTON]],
Nenue@28 46 0, 1, 0, 0.5,
Nenue@28 47 0, 1, 0.5, 1,
Nenue@28 48 }
Nenue@28 49 }
Nenue@28 50 }
Nenue@28 51
Nenue@28 52 local Scroller_OnShow = function()
Nenue@28 53 Wrapper.watchMoneyReasons = 0;
Nenue@28 54 --T:Update()
Nenue@28 55 --T:OnInitialize()
Nenue@28 56 for i, region in ipairs(Wrapper.headerComplex) do
Nenue@28 57 region:Show()
Nenue@28 58 end
Nenue@28 59 end
Nenue@28 60
Nenue@28 61 local Scroller_OnHide = function()
Nenue@28 62 local self = Wrapper
Nenue@28 63 Wrapper:UnregisterAllEvents()
Nenue@28 64 Wrapper:SetScript('OnEvent', nil)
Nenue@28 65 for i, region in ipairs(Wrapper.headerComplex) do
Nenue@28 66 region:Hide()
Nenue@28 67 end
Nenue@28 68 end
Nenue@28 69
Nenue@28 70 local Scroller_OnMouseWheel = function(self, delta)
Nenue@28 71 local r = Scroll:GetHeight() - Scroller:GetHeight()
Nenue@28 72 local s = B.Conf.ObjectiveScroll - delta * floor(r/5+.5)
Nenue@28 73 local from = self:GetVerticalScroll()
Nenue@28 74 print('|cFF00FF00OnMouseWheel', 'scroll =', s)
Nenue@28 75 if s >= r then
Nenue@28 76 s = r
Nenue@28 77 elseif s < 1 then
Nenue@28 78 s = 0
Nenue@28 79 end
Nenue@28 80 self:SetVerticalScroll(s)
Nenue@28 81 B.Conf.ObjectiveScroll = s
Nenue@28 82 print('|cFF00FF00OnMouseWheel', 'from = ', from, 'scroll =', s, ' range =', r, 'current =', self:GetVerticalScroll())
Nenue@28 83
Nenue@28 84 T.UpdateActionButtons('SCROLLING')
Nenue@28 85 end
Nenue@28 86
Nenue@28 87 local UpdatePanelButton = function (self, state)
Nenue@28 88 state = state or true
Nenue@28 89 local swatch = (state == true) and self.openSwatch or self.closedSwatch
Nenue@28 90 print((state ~= true) and 'closedSwatch' or 'openSwatch')
Nenue@28 91 self:SetNormalTexture(swatch[1])
Nenue@28 92 self:SetPushedTexture(swatch[2])
Nenue@28 93 if #swatch >= 6 then
Nenue@28 94 self:GetNormalTexture():SetTexCoord(swatch[3], swatch[4], swatch[5], swatch[6])
Nenue@28 95 end
Nenue@28 96 if #swatch == 10 then
Nenue@28 97 self:GetPushedTexture():SetTexCoord(swatch[7], swatch[8], swatch[9], swatch[10])
Nenue@28 98 end
Nenue@28 99
Nenue@28 100 end
Nenue@28 101
Nenue@28 102 local OnClick = {}
Nenue@28 103 OnClick.CloseButton = function(self)
Nenue@38 104 T:Enable()
Nenue@34 105 if T.Conf.enabled then
Nenue@34 106 T:Update()
Nenue@34 107 end
Nenue@34 108
Nenue@28 109 UpdatePanelButton(self, T.Conf.enabled)
Nenue@28 110 end
Nenue@28 111
Nenue@28 112 OnClick.QuestMapButton = function()
Nenue@28 113 ToggleWorldMap()
Nenue@28 114 end
Nenue@28 115
Nenue@28 116
Nenue@28 117 T.InitializeWidgets = function()
Nenue@28 118 local panelButtons = T.buttons
Nenue@28 119 --- tracker scroll
Nenue@28 120 Scroller:SetScript('OnMouseWheel', Scroller_OnMouseWheel)
Nenue@28 121 Scroller:SetScript('OnShow', Scroller_OnShow)
Nenue@28 122 Scroller:SetScript('OnHide', Scroller_OnHide)
Nenue@28 123 for name, swatch in pairs(panelButtons) do
Nenue@28 124 local source = swatch and swatch or panelButtons.CloseButton
Nenue@28 125 local button = Wrapper[name]
Nenue@28 126 button.parent = swatch.parent
Nenue@28 127 button.openSwatch = source.openSwatch
Nenue@28 128 button.closedSwatch = source.closedSwatch
Nenue@28 129 if OnClick[name] then
Nenue@28 130 button:SetScript('OnClick', OnClick[name])
Nenue@28 131 end
Nenue@28 132 UpdatePanelButton(button, T.Conf.enabled)
Nenue@28 133 end
Nenue@28 134 end
Nenue@28 135
Nenue@28 136 ----------------------------------------------------------------------------------------
Nenue@28 137 --- modified version of the itemButton initializer used by Barjack's 'QuestKing 2' addon,
Nenue@28 138 --- url: http://mods.curse.com/addons/wow/questking
Nenue@28 139 ----------------------------------------------------------------------------------------
Nenue@28 140 T.SetItemButton = function(block, info)
Nenue@28 141 local itemInfo = info.specialItem
Nenue@28 142 if not itemInfo then
Nenue@28 143 return
Nenue@28 144 end
Nenue@28 145
Nenue@28 146 local itemButton
Nenue@28 147 if not info.itemButton then
Nenue@28 148 if #freeButtons >= 1 then
Nenue@28 149 print(' |cFF00FFFFfound a free button')
Nenue@28 150 itemButton = freeButtons[#freeButtons]
Nenue@28 151 freeButtons[#freeButtons] = nil
Nenue@28 152 if itemButton.block then
Nenue@28 153 itemButton.block.itemButton = nil
Nenue@28 154 itemButton.block = nil
Nenue@28 155 end
Nenue@28 156 else
Nenue@28 157 local buttonIndex = T.Quest.numButtons + #freeButtons + 1
Nenue@28 158 itemButton = CreateFrame('Button', 'VeneerQuestItemButton' .. buttonIndex, UIParent, 'VeneerItemButtonTemplate')
Nenue@28 159 itemButton.buttonIndex = buttonIndex
Nenue@28 160 itemButton:SetSize(36, 36)
Nenue@28 161 itemButton:GetNormalTexture():SetSize(36 * (5/3), 36 * (5/3))
Nenue@28 162 print(' |cFFFF4400starting new button', itemButton:GetName())
Nenue@28 163 end
Nenue@28 164 T.Quest.numButtons = T.Quest.numButtons + 1
Nenue@28 165 else
Nenue@28 166 itemButton = info.itemButton
Nenue@28 167 print(' |cFF00FF00found assigned button', itemButton:GetName())
Nenue@28 168
Nenue@28 169 end
Nenue@28 170 -- set values
Nenue@28 171
Nenue@28 172 info.itemButton = itemButton
Nenue@28 173 usedButtons[info.questID] = itemButton
Nenue@28 174 print(' |cFF8800FFassigning|r', itemButton:GetName(), 'to quest|cFF00FF00', info.questID, '|rat|cFFFFFF00', block:GetName(),'|r')
Nenue@28 175
Nenue@28 176 for k,v in pairs(usedButtons) do
Nenue@28 177 print('|cFFFF44DD'..k..'|r', v:GetName())
Nenue@28 178 end
Nenue@28 179
Nenue@28 180 itemButton:SetAttribute("type", "item")
Nenue@28 181 itemButton:SetAttribute("item", itemInfo.link)
Nenue@28 182
Nenue@28 183 itemButton.questID = info.questID
Nenue@34 184 itemButton.logIndex = info.logIndex
Nenue@28 185 itemButton.charges = itemInfo.charges
Nenue@28 186 itemButton.rangeTimer = -1
Nenue@28 187 itemButton.block = block
Nenue@28 188
Nenue@28 189 SetItemButtonTexture(itemButton, itemInfo.icon)
Nenue@28 190 SetItemButtonCount(itemButton, itemInfo.charges)
Nenue@28 191 Veneer_QuestObjectiveItem_UpdateCooldown(itemButton);
Nenue@28 192
Nenue@28 193 return itemButton
Nenue@28 194 end
Nenue@28 195 --- Clear an itemButton from the given block
Nenue@28 196 T.FreeItemButtons = function(block)
Nenue@28 197
Nenue@28 198 if block.itemButton then
Nenue@28 199 local itemButton = block.itemButton
Nenue@28 200 if itemButton.questID ~= block.info.questID then
Nenue@28 201 block.itemButton = nil
Nenue@28 202 itemButton.block = T.Quest.InfoBlock[itemButton.questID]
Nenue@28 203 else
Nenue@28 204 itemButton.block = nil
Nenue@28 205 itemButton:Hide()
Nenue@28 206
Nenue@28 207 usedButtons[itemButton.questID] = nil
Nenue@28 208 freeButtons[#freeButtons + 1] = itemButton
Nenue@28 209 T.Quest.numButtons = T.Quest.numButtons - 1
Nenue@28 210 print('|cFFFF0088released', itemButton:GetName(),'and', block:GetName())
Nenue@28 211 end
Nenue@28 212 end
Nenue@28 213 end
Nenue@28 214
Nenue@28 215 function Veneer_QuestObjectiveItem_OnUpdate (self, elapsed)
Nenue@28 216 -- Handle range indicator
Nenue@28 217 local rangeTimer = self.rangeTimer
Nenue@28 218 if (rangeTimer) then
Nenue@28 219 rangeTimer = rangeTimer - elapsed
Nenue@28 220 if (rangeTimer <= 0) then
Nenue@34 221 local link, item, charges, showItemWhenComplete = GetQuestLogSpecialItemInfo(self.logIndex)
Nenue@28 222 if ((not charges) or (charges ~= self.charges)) then
Nenue@28 223 T:Update()
Nenue@28 224 return
Nenue@28 225 end
Nenue@28 226
Nenue@28 227 local count = self.HotKey
Nenue@34 228 local valid = IsQuestLogSpecialItemInRange(self.logIndex)
Nenue@28 229 if (valid == 0) then
Nenue@28 230 count:Show()
Nenue@28 231 count:SetVertexColor(1.0, 0.1, 0.1)
Nenue@28 232 elseif (valid == 1) then
Nenue@28 233 count:Show()
Nenue@28 234 count:SetVertexColor(0.6, 0.6, 0.6)
Nenue@28 235 else
Nenue@28 236 count:Hide()
Nenue@28 237 end
Nenue@28 238 rangeTimer = TOOLTIP_UPDATE_TIME
Nenue@28 239 end
Nenue@28 240
Nenue@28 241 self.rangeTimer = rangeTimer
Nenue@28 242 end
Nenue@28 243 end
Nenue@28 244
Nenue@28 245 function Veneer_QuestObjectiveItem_UpdateCooldown (itemButton)
Nenue@34 246 local start, duration, enable = GetQuestLogSpecialItemCooldown(itemButton.logIndex)
Nenue@28 247 if (start) then
Nenue@28 248 CooldownFrame_SetTimer(itemButton.Cooldown, start, duration, enable)
Nenue@28 249 if (duration > 0 and enable == 0) then
Nenue@28 250 SetItemButtonTextureVertexColor(itemButton, 0.4, 0.4, 0.4)
Nenue@28 251 else
Nenue@28 252 SetItemButtonTextureVertexColor(itemButton, 1, 1, 1)
Nenue@28 253 end
Nenue@28 254 end
Nenue@28 255 end
Nenue@28 256