Mercurial > wow > buffalo2
diff ObjectiveWidgets.lua @ 14:ed642234f017
ObjectiveFrame
- implement proper tracker name text
- expanded tracker prototypes to cover "objective lines" formatting and accommodation of widget variables
- implement the progress bars for bonus objectives
ObjectiveStyle
- moved `UpdateWrapperStyle` over and renamed it to fit semantics
- change the formula for block.`height` to measure non-widget content only
- allows widgets to position relative to text
- size FontString `status` to match block.`height`
- full block height is acquired by adding block.`height` and block.`attachmentHeight` which is calculated during objective parsing
ObjectiveWidgets
- use string keys for generated widgets to deal with multiple objectives under the same questID, and maybe dungeon objectives
- wrapper buttons use a common code path
- specialized handlers for wheel scrolling moved over to fit semantics
author | Nenue |
---|---|
date | Mon, 04 Apr 2016 03:16:22 -0400 |
parents | 9455693fc290 |
children | f660f1c1e0aa |
line wrap: on
line diff
--- a/ObjectiveWidgets.lua Sat Apr 02 17:46:52 2016 -0400 +++ b/ObjectiveWidgets.lua Mon Apr 04 03:16:22 2016 -0400 @@ -5,6 +5,122 @@ local GetQuestLogSpecialItemInfo, IsQuestLogSpecialItemInRange, GetQuestLogSpecialItemCooldown = GetQuestLogSpecialItemInfo, IsQuestLogSpecialItemInRange, GetQuestLogSpecialItemCooldown local CooldownFrame_SetTimer, SetItemButtonTextureVertexColor, CreateFrame, VeneerObjectiveScroll = CooldownFrame_SetTimer, SetItemButtonTextureVertexColor, CreateFrame, VeneerObjectiveScroll local tremove, tinsert, tContains, pairs, setmetatable = tremove, tinsert, tContains, pairs, setmetatable + +--- frame refs +local Wrapper = _G.VeneerObjectiveWrapper +local Scroller = Wrapper.scrollArea +local CloseButton = Wrapper.CloseButton +local QuestMapButton = Wrapper.QuestMapButton +local Scroll = _G.VeneerObjectiveScroll + +local panelButtons = { + CloseButton = { + closedSwatch = { + [[Interface\Buttons\UI-Panel-QuestHideButton]], + [[Interface\Buttons\UI-Panel-QuestHideButton]], + 0, 0.5, 0.5, 1, + 0.5, 1, 0.5, 1, + }, + openSwatch = { + [[Interface\Buttons\UI-Panel-QuestHideButton]], + [[Interface\Buttons\UI-Panel-QuestHideButton]], + 0.5, 1, 0.5, 1, + 0, 0.5, 0.5, 1, + }, + parent = 'VeneerObjectiveWrapper' + }, + QuestMapButton = { + closedSwatch = { + [[Interface\QUESTFRAME\UI-QUESTMAP_BUTTON]], + [[Interface\QUESTFRAME\UI-QUESTMAP_BUTTON]], + 0, 1, 0.5, 1, + 0, 1, 0, 0.5, + }, + openSwatch = { + [[Interface\QUESTFRAME\UI-QUESTMAP_BUTTON]], + [[Interface\QUESTFRAME\UI-QUESTMAP_BUTTON]], + 0, 1, 0, 0.5, + 0, 1, 0.5, 1, + } + } +} + +local Scroller_OnShow = function() + Wrapper.watchMoneyReasons = 0; + mod.UpdateWrapper() + mod.SetEvents() + for i, region in ipairs(Wrapper.headerComplex) do + region:Show() + end +end + +local Scroller_OnHide = function() + local self = Wrapper + Wrapper:UnregisterAllEvents() + Wrapper:SetScript('OnEvent', nil) + for i, region in ipairs(Wrapper.headerComplex) do + region:Hide() + end +end + +local Scroller_OnMouseWheel = function(self, delta) + local r = Scroll:GetHeight() - Scroller:GetHeight() + local s = B.Conf.ObjectiveScroll - delta * floor(r/5+.5) + local from = self:GetVerticalScroll() + if s >= r then + s = r + elseif s < 1 then + s = 0 + end + self:SetVerticalScroll(s) + B.Conf.ObjectiveScroll = s + print('|cFF00FF00OnMouseWheel', 'from = ', from, 'scroll =', s, ' range =', r, 'current =', self:GetVerticalScroll()) + + mod.UpdateActionButtons('SCROLLING') +end + +local UpdatePanelButton = function (self, state) + state = state and B.Conf.FrameState[state] or 1 + local swatch = (state == 1) and self.openSwatch or self.closedSwatch + self:SetNormalTexture(swatch[1]) + self:SetPushedTexture(swatch[2]) + if #swatch >= 6 then + self:GetNormalTexture():SetTexCoord(swatch[3], swatch[4], swatch[5], swatch[6]) + end + if #swatch == 10 then + self:GetPushedTexture():SetTexCoord(swatch[7], swatch[8], swatch[9], swatch[10]) + end + +end + +local OnClick = {} +OnClick.CloseButton = function(self) + Wrapper:Minimize() + UpdatePanelButton(self, self.parent) +end + +OnClick.QuestMapButton = function() + ToggleWorldMap() +end + +mod.InitializeWrapperWidgets = function() + --- tracker scroll + Scroller:SetScript('OnMouseWheel', Scroller_OnMouseWheel) + Scroller:SetScript('OnShow', Scroller_OnShow) + Scroller:SetScript('OnHide', Scroller_OnHide) + for name, swatch in pairs(panelButtons) do + local source = swatch and swatch or panelButtons.CloseButton + local button = Wrapper[name] + button.parent = swatch.parent + button.openSwatch = source.openSwatch + button.closedSwatch = source.closedSwatch + if OnClick[name] then + button:SetScript('OnClick', OnClick[name]) + end + UpdatePanelButton(button, button.parent) + end +end + ---------------------------------------------------------------------------------------- --- XML and script code lifted from "QuestKing 2" by Barjack, --- found at http://mods.curse.com/addons/wow/questking @@ -152,13 +268,13 @@ --- Get a usable widget for the given achievement criteria set. -- Returns a frame object with dimensioning parameters needed to size the receiving tracker block -mod.SetWidget = function(obj, info) +mod.SetWidget = function(line, info, objectiveType, objectiveKey) local print = B.print('ObjectiveWidgets') - local widgetType = obj.type + local widgetType = objectiveType local widget - if wr[widgetType] and wr[widgetType].used[obj.criteriaID] then - widget = wr[widgetType].used[obj.criteriaID] - print('|cFF00FF00Updating ('..obj.criteriaID..')', widget) + if wr[widgetType] and wr[widgetType].used[objectiveKey] then + widget = wr[widgetType].used[objectiveKey] + print('|cFF00FF00Updating ('..objectiveKey..')', widget) elseif not wr[widgetType] or #wr[widgetType].free == 0 then widget = CreateFrame('Frame', 'VeneerObjective' .. widgetType .. (wr[widgetType] and (wr[widgetType].lastn+1) or (1)), VeneerObjectiveScroll, 'VeneerObjectiveCriteria' .. widgetType) @@ -168,9 +284,11 @@ print('|cFFFFFF00Acquiring released widget', widget:GetName()) end - wr[widgetType].used[obj.criteriaID] = widget - widget.info = obj - widget.parentInfo = info + + wr[widgetType].used[objectiveKey] = widget + widget.line = line + widget.info = info + widget.key = objectiveKey mod.InitializeWidget(widget) return widget end @@ -195,7 +313,6 @@ local maxWidth = 250 frame:SetWidth(maxWidth) - mod.UpdateWidget[frame.widgetType](frame) frame:SetScript('OnEvent', mod.UpdateWidget[frame.widgetType]) if frame.info.isCurrency then frame:RegisterEvent('CHAT_MSG_CURRENCY') @@ -206,8 +323,8 @@ frame:RegisterEvent('CRITERIA_UPDATE') frame:RegisterEvent('CRITERIA_COMPLETE') frame:RegisterEvent('CRITERIA_EARNED') - - return t[frame.widgetType](frame) + t[frame.widgetType](frame) + mod.UpdateWidget[frame.widgetType](frame) end, }) @@ -227,10 +344,10 @@ mod.ReleaseWidget = function(frame) local print = B.print('ObjectiveWidgets') local reg = wr[frame.widgetType] - if reg and reg.used[frame.info.criteriaID] then - reg.used[frame.info.criteriaID] = nil + if reg and reg.used[frame.key] then + reg.used[frame.key] = nil + frame.line = nil frame.info = nil - frame.parentInfo = nil frame:UnregisterAllEvents() tinsert(reg.free, frame) print('|cFFBBBBBBreleased from service', frame:GetName()) @@ -241,23 +358,30 @@ mod.CleanWidgets = function() local print = B.print('ObjectiveWidgets') local tracked = {GetTrackedAchievements() } + local tasks = GetTasksTable() for type, reg in pairs(mod.WidgetRegistry) do print('collecting', type) - for criteriaID, frame in pairs(reg.used) do - local id = frame.info.cheevID + for key, frame in pairs(reg.used) do + if frame.info.cheevID then + local id = frame.info.cheevID - if id and not tContains(tracked, id) then + if id and not tContains(tracked, id) then - print(' untracked achievement', id, 'associated with', criteriaID, frame:GetName()) - frame:Hide() + print(' untracked achievement', id, 'associated with', key, frame:GetName()) + frame:Hide() + end + elseif frame.info.questID then + -- do something for quest task end end end end -mod.defaults.WidgetVars = { + +mod.defaults.WidgetStyle = { ProgressBar = { + Spacing = 4, bg = { Height = 20, }, @@ -265,33 +389,42 @@ Height = 16, }, status = { - FontObject = _G.VeneerFontNormal + FontObject = _G.VeneerCriteriaFontNormal } } } mod.InitializeWidget.ProgressBar = function(self) - local c = mod.defaults.WidgetVars.ProgressBar - local params = mod.WidgetParams[self.widgetType] - self.height = params.height + local c = mod.defaults.WidgetStyle.ProgressBar + self.height = c.bg.Height + c.Spacing self:SetHeight(c.bg.Height) self.bg:SetHeight(c.bg.Height) self.fg:ClearAllPoints() - self.fg:SetPoint('BOTTOMLEFT', self, 'BOTTOMLEFT', 2, 2) + self.indent = (c.bg.Height - c.fg.Height) / 2 + self.fg:SetPoint('BOTTOMLEFT', self, 'BOTTOMLEFT', self.indent, self.indent) self.fg:SetHeight(c.fg.Height) self.status:SetFontObject(c.status.FontObject) self.status:SetText(self.info.quantityString) end mod.UpdateWidget.ProgressBar = function (self) - local quantity, requiredQuantity = self.info.quantity, self.info.requiredQuantity + local quantity, requiredQuantity = self.line.value, self.line.maxValue + print('update vals:') + for k,v in pairs(self.line) do + print(k, v) + end - if self.info.finished then - self.fg:SetWidth(self.bg:GetWidth() - 4) + if self.line.format then + self.status:SetFormattedText(self.line.format, self.line.value, self.line.maxValue) + end + + + if self.line.finished then + self.fg:SetWidth(self.bg:GetWidth() - self.indent) elseif quantity == 0 then self.fg:Hide() else self.fg:Show() - self.fg:SetWidth((self.bg:GetWidth()-4) * (quantity / requiredQuantity)) + self.fg:SetWidth((self.bg:GetWidth() -self.indent) * (quantity / requiredQuantity)) end end