Mercurial > wow > worldplan
diff FilterBar.lua @ 40:589c444d4837
WowAce/Curseforge migration push
author | Nenue |
---|---|
date | Sun, 25 Dec 2016 13:04:57 -0500 |
parents | 21bcff08b0f4 |
children | 79e5e96e5f18 |
line wrap: on
line diff
--- a/FilterBar.lua Fri Nov 04 02:54:32 2016 -0400 +++ b/FilterBar.lua Sun Dec 25 13:04:57 2016 -0500 @@ -3,7 +3,7 @@ -- Created: 10/27/2016 8:55 PM -- %file-revision% -- - +local _, db = ... local print = DEVIAN_WORKSPACE and function(...) _G.print('FilterBar', ...) end or nop local wprint = DEVIAN_WORKSPACE and function(...) _G.print('WP', ...) end or function() end local wipe, ipairs, pairs = table.wipe, ipairs, pairs @@ -39,8 +39,9 @@ } local familiars_id = 9696 -local DEFAULT_FILTER_LAYOUT = { +db.DefaultFilterType = { iconWidth = 24, + iconHeight = 18, borderWidth = 3, highlightWidth = 2, TagSize = 12, @@ -48,7 +49,7 @@ showNumber = true, numberFontObject = 'WorldPlanNumberFontThin' } -local DEFAULT_FILTER_LIST = { +db.DefaultFilters = { { label = 'Filters', texture = "Interface\\WorldMap\\WorldMap-Icon" }, { filterKey= 'rewardType', cVar = 'worldQuestFilterArtifactPower', filterValue = REWARD_ARTIFACT_POWER, label = 'Artifact Power', texture = "Interface\\ICONS\\inv_7xp_inscription_talenttome01" }, { filterKey= 'rewardType', cVar = 'worldQuestFilterOrderResources', filterValue = REWARD_CURRENCY,label = 'Order Resources', texture = "Interface\\Icons\\inv_orderhall_orderresources" }, @@ -62,21 +63,21 @@ } local defaults = {} -WorldPlanSummaryMixin = { - selectedBountyIndex = {}, - bounties = {}, - filterList = {}, - buttons = {}, -} +WorldPlanSummaryMixin = WorldPlanSummaryMixin or {} +WorldPlanSummaryMixin.selectedBountyIndex = {} +WorldPlanSummaryMixin.bounties = {} +WorldPlanSummaryMixin.filterList = {} +WorldPlanSummaryMixin.buttons = {} +WorldPlanSummaryMixin.cvarFiltersDirty = false WorldPlanFilterPinMixin = {} function WorldPlanSummaryMixin:OnLoad() - WorldPlan:AddHandler(self, defaults) - for index, info in ipairs(DEFAULT_FILTER_LIST) do - info.zone = DEFAULT_FILTER_LAYOUT - info.continent = DEFAULT_FILTER_LAYOUT + self:SetParent(WorldMapFrame) + WorldPlan:AddHandler(self) + for index, info in ipairs(db.DefaultFilters) do + info.zone = db.DefaultFilterType + info.continent = db.DefaultFilterType info.pinMask = "Interface\\Minimap\\UI-Minimap-Background" - WorldPlan:AddTypeInfo(self,index, info) end @@ -93,7 +94,6 @@ function WorldPlanSummaryMixin:Setup() print('|cFF00FF88'..self:GetName()..':Setup()') - self:GetFilters() end @@ -117,10 +117,10 @@ wipe(self.filterList) - for index, info in ipairs(DEFAULT_FILTER_LIST) do + for index, info in ipairs(db.DefaultFilters) do tinsert(self.filterList, info) end - self.bounties, self.numBounties = GetQuestBountyInfoForMapID(WorldPlan.currentMapID) + self.bounties, self.numBounties = GetQuestBountyInfoForMapID(db.currentMapID) self.BountyFilters = {} for index, data in ipairs(self.bounties) do local info = self.BountyFilters[index] @@ -148,6 +148,7 @@ end function WorldPlanSummaryMixin:Refresh() + self:GetFilters() self:Update() end @@ -157,59 +158,85 @@ local questResults = {{}} function WorldPlanSummaryMixin:Update() local blocks = self.buttons + local relativeFrame = WorldMapFrame.UIElementsFrame.TrackingOptionsButton - local numHeaders = 0 + if FlightMapFrame and FlightMapFrame:IsVisible() then + relativeFrame = FlightMapFrame + end + self:SetParent(relativeFrame) + + local numHeaders = 0 print('|cFF00FF88'..self:GetName()..':Update()|r', 'currentMap=',WorldPlan.currentMapID) - local layout = DEFAULT_FILTER_LAYOUT + + local layout = db.DefaultFilterType local borderWidth = layout.iconWidth + (layout.borderWidth * 2) local highlightWidth = borderWidth + (layout.highlightWidth * 2) - local quests = WorldPlanQuests.QuestsByZone[WorldPlan.currentMapID] or WorldPlanQuests.QuestsByID - local foundQuests = questResults[1] + local mapQuests = db.QuestsByZone[db.currentMapID] or db.QuestsByID + local firstCvar, lastCvar for index, info in ipairs(self.filterList) do - local numQuests = 0 - local resultIndex = numHeaders + 1 - questResults[resultIndex] = questResults[resultIndex] or {} - wipe(questResults[resultIndex]) - for questID, pin in pairs(quests) do - if pin.used then + local numQuestsHere = 0 + local numQuestsTotal = 0 + info.questList = info.questList or {} + wipe(info.questList) + + for questID, pin in pairs(db.QuestsByID) do + print(pin.worldQuestType ~= LE_QUEST_TAG_TYPE_PROFESSION, (db.Config.ShowAllProfessionQuests or pin.isKnownProfession)) + if (pin.worldQuestType ~= LE_QUEST_TAG_TYPE_PROFESSION) or (db.Config.ShowAllProfessionQuests or pin.isKnownProfession) then + print(pin.title) if not info.filterKey then - numQuests = numQuests + 1 + if mapQuests[questID] then + numQuestsHere = numQuestsHere + 1 + end + numQuestsTotal = numQuestsTotal + 1 elseif pin[info.filterKey] == info.filterValue then - numQuests = numQuests + 1 - tinsert(questResults[resultIndex], pin) + if mapQuests[questID] then + numQuestsHere = numQuestsHere + 1 + tinsert(info.questList, pin) + end + numQuestsTotal = numQuestsTotal + 1 end end end - print(tostring(index).. ' ("'..tostring(info.label)..'" f('.. tostring(info.filterKey).. '='..tostring(info.filterValue) .. '), '..tostring(numQuests)..')') + --print('num here', numQuestsHere, numQuestsTotal) + info.totalQuests = maxQuests - if numQuests >= 1 then + --print(tostring(index).. ' ("'..tostring(info.label)..'" f('.. tostring(info.filterKey).. '='..tostring(info.filterValue) .. '), '..tostring(numQuests)..')') + + if numQuestsTotal >= 1 then numHeaders = numHeaders + 1 local button = blocks[numHeaders] if not blocks[numHeaders] then - button = CreateFrame('Button', 'WorldPlanFilterButton'..numHeaders, WorldMapScrollFrame, 'WorldPlanFilterPin') - button:SetSize(borderWidth, borderWidth) + button = CreateFrame('Button', 'WorldPlanFilterButton'..numHeaders, self, 'WorldPlanFilterPin') + button:SetSize(32,20) + button.icon:SetTexCoord(0.1,.9,.1,(1 * (20/32))) - button.icon:SetSize(layout.iconWidth, layout.iconWidth) - button.RewardBorder:SetSize(borderWidth, borderWidth) - button.HighlightBorder:SetSize(highlightWidth, highlightWidth) - button.RewardBorder:SetMask(filterMask) - button.RewardBorder:SetDesaturated(true) + button.RewardBorder:ClearAllPoints() + button.RewardBorder:SetPoint('TOPLEFT', button, 'TOPLEFT') + button.RewardBorder:SetPoint('BOTTOMRIGHT', button, 'BOTTOMRIGHT') - button.HighlightBorder:Hide() + blocks[numHeaders] = button end button.info = info - button.questList = questResults[resultIndex] + button.numQuestsTotal = numQuestsTotal + button.numQuestsHere = numQuestsHere + button.questList = info.questList + button.isFirst = (numHeaders == 1) button:SetID(index) - button.spacing = ((relativeFrame.cVar and (not info.cVar)) or (relativeFrame.filterKey ~= info.filterKey)) and 5 or 0 + button.spacing = ((relativeFrame.cVar and (not info.cVar)) or (relativeFrame.filterKey ~= info.filterKey)) and 5 or 1 button.relativeFrame = relativeFrame - button:Refresh((numHeaders == 1), numQuests) + button:Refresh() button:Show() relativeFrame = button + + if info.cVar then + firstCvar = firstCvar or button + lastCvar = button + end + end - end self.numHeaders = numHeaders @@ -221,6 +248,16 @@ wipe(questResults[i]) end end + + + if firstCvar and lastCvar then + self.CVarsHighlight:ClearAllPoints() + self.CVarsHighlight:SetPoint('TOPLEFT', firstCvar, 'TOPLEFT', -1, 1) + self.CVarsHighlight:SetPoint('BOTTOMRIGHT', lastCvar, 'BOTTOMRIGHT', 1, -1) + end + self.CVarsHighlight:SetShown(self.cvarFiltersDirty or false) + + self.isStale = nil end @@ -230,13 +267,14 @@ local rgbWhite = {r = 1, g= 1, b= 1, hex = '|cFFFFFFFF'} function WorldPlanFilterPinMixin:OnEnter() - if self.questList and #self.questList >= 1 then + if #self.questList >= 1 then GameTooltip:SetOwner(self, 'ANCHOR_LEFT') GameTooltip:AddLine(self.info.label) for index, pin in ipairs(self.questList) do local colorInfo = (pin.quality and ITEM_QUALITY_COLORS[pin.quality]) or rgbWhite - GameTooltip:AddLine('|T'.. tostring(pin.itemTexture)..':16:16|t ' .. pin.title ..(pin.cheevos and " |cFFFFFF00!|R" or ''), colorInfo.r, colorInfo.g, colorInfo.b) + GameTooltip:AddLine('|T'.. tostring(pin.itemTexture)..':16:16|t ' .. tostring(pin.title) ..(pin.cheevos and " |cFFFFFF00!|R" or ''), colorInfo.r, colorInfo.g, colorInfo.b) end + GameTooltip:AddLine(self.numQuestsTotal .. ' total') GameTooltip:Show() end end @@ -247,63 +285,66 @@ end end -function WorldPlanFilterPinMixin:Refresh(isFirst, numQuests) - isFirst = isFirst or self.isFirst - numQuests = numQuests or self.numQuests - +function WorldPlanFilterPinMixin:Refresh() local info = self.info - - self.isFirst = isFirst - self.numQuests = numQuests self.filterKey = info.filterKey self.filterValue = info.filterValue self.tagID = info.tagID - self.icon:SetMask(filterMask) self.icon:SetTexture(info.texture) - self.count:SetText(numQuests) + self.count:SetText(self.numQuestsHere) self.cVar = info.cVar self.itemTexture = self.texture - if isFirst then - self:SetPoint('TOP', self.relativeFrame, 'BOTTOM', 0, -5) + if self.isFirst then + if FlightMapFrame and FlightMapFrame:IsVisible() then + self:SetPoint('TOPRIGHT', FlightMapFrame, 'TOPRIGHT', -4, -25) + else + self:SetPoint('TOP', self.relativeFrame, 'BOTTOM', 0, -5) + end + else self:SetPoint('TOPRIGHT', self.relativeFrame, 'BOTTOMRIGHT', 0, -(self.spacing or 0)) end print('anchor to', self.relativeFrame:GetName(), info.mask) - local r, g, b, a = 1,1,1,1 + self.icon:SetDesaturated(self.numQuestsHere == 0) + + local r, g, b, a = 0,0,0,1 local desaturated = false - if self.cVar then - self.RewardBorder:SetVertexColor(1, 1, 1, 1) - if GetCVarBool(self.cVar) then - self.icon:SetVertexColor(1,1,1,1) - self:SetAlpha(1) - else - self.icon:SetVertexColor(.5, .5, .5, 1) - self:SetAlpha(0.5) - end - else - self:SetAlpha(1) - if WorldPlan.UsedFilters[self.filterKey] then - if WorldPlan.UsedFilters[self.filterKey] == self.filterValue then - self.RewardBorder:SetVertexColor(0, 1, 0) + if (self.numQuestsHere > 0) then + if self.cVar then + if GetCVarBool(self.cVar) then + self.count:SetTextColor(1,1,1) + r,g,b = 0, 1, 0 else - self.RewardBorder:SetVertexColor(1, 0, 0) + self:GetParent().cvarFiltersDirty = true + self.count:SetTextColor(1,0,0) + self.icon:SetDesaturated(true) + r,g,b = 1, 0, 0 end else - if self.filterKey == 'worldQuestType' then - self.RewardBorder:SetVertexColor(0, 1, 1) - elseif self.filterKey == 'factionID' then - self.RewardBorder:SetVertexColor(1, 1, 0) + if db.UsedFilters[self.filterKey] then + if db.UsedFilters[self.filterKey] == self.filterValue then + self.count:SetTextColor(0,1,0) + r,g,b = 0, 1, 0 + else + self.count:SetTextColor(1,0,0) + r, g, b = 1, 0, 0 + end else - self.RewardBorder:SetVertexColor(0.5, 0.5, 0.5) + self.count:SetTextColor(1,1,1) + if self.filterKey == 'worldQuestType' then + r, g, b = 0, 0, 1 + elseif self.filterKey == 'factionID' then + r, g, b = 1, 1, 0 + end end - end end + self.RewardBorder:SetColorTexture(r, g, b, a) --self:UpdateSize() end @@ -313,84 +354,102 @@ self:SetFrameStrata('HIGH') self:SetFrameLevel(151) self:SetScript('OnUpdate', nil) - WorldPlanPOIMixin.OnLoad(self) + self.questList = {} end function WorldPlanFilterPinMixin:OnUpdate () end - -function WorldPlanFilterPinMixin:OnLeave () - if GameTooltip:IsOwned(self) then - GameTooltip:Hide() - end -end - -- shift-click: reset filter -- click: rotate through include(1), exclude(-1), ignore(nil) local filtered_report = {} +local RESET_FILTER = "|cFFFFFFFF+%s|r" +local FILTER_EXCLUDE_TYPE = '|cFFFF0000-%s|r' +local FILTER_INCLUDE_TYPE = '|cFF00FF00+%s|r' function WorldPlanFilterPinMixin:OnClick (button) - print('|cFF00FF88'..self:GetName()..':OnClick()|r', filterKey, filterValue, operation) local filterKey = self.filterKey local filterValue = self.filterValue local cVar = self.cVar local parent = self:GetParent() - local operation = opPrefix - local setDirty = false + local setDirty + + print('|cFF00FF88'..self:GetName()..':OnClick()|r', filterKey, filterValue, cVar, parent) local resetMode = (button == 'RightButton') wipe(filtered_report) if not (filterKey or cVar) then - wipe(WorldPlan.UsedFilters) - for i, info in ipairs(DEFAULT_FILTER_LIST) do + for i, info in ipairs(db.DefaultFilters) do if info.cVar then - if GetCVar(info.cVar) ~= 1 then - tinsert(filtered_report, '|cFF888888'.. tostring(info.label) ..'|r') + SetCVar(info.cVar, 1) + elseif info.filterKey then + if db.UsedFilters[info.filterKey] then + db.UsedFilters[info.filterKey] = nil end - SetCVar(info.cVar, 1) end end + parent.cvarFiltersDirty = false + --WorldPlan:print('All filters reset.') elseif cVar then - WorldPlan:print('Toggling cvar filter:', cVar) - if (not parent.isDirty) or resetMode then - for i, info in ipairs(DEFAULT_FILTER_LIST) do + if resetMode then + print('|cFFFF4400cleaning dirty') + for i, info in ipairs(db.DefaultFilters) do if info.cVar then - local value = GetCVar(info.cVar) - if resetMode then - value = 1 - parent.isDirty = nil - else - - if (cVar ~= info.cVar) then - value = 0 - else - value = 1 - end - setDirty = true - - end - SetCVar(info.cVar, value) + parent.cvarFiltersDirty = false + SetCVar(info.cVar, 1) end end - if setDirty then - parent.isDirty = true + --WorldPlan:print('Reward filters reset.') + elseif parent.cvarFiltersDirty == true then + if GetCVarBool(cVar) then + tinsert(filtered_report, FILTER_EXCLUDE_TYPE:format(tostring(self.info.label))) + SetCVar(cVar, 0) + else + + tinsert(filtered_report, FILTER_INCLUDE_TYPE:format(tostring(self.info.label))) + SetCVar(cVar, 1) + end + + -- check the visible filters and consider it clean if they're all lit + parent.cvarFiltersDirty = false + for i, info in ipairs(parent.filterList) do + if info.cVar and (#info.questList >= 1) then + print(info.cVar, GetCVarBool(info.cVar)) + if GetCVarBool(info.cVar) == false then + parent.cvarFiltersDirty = true + print('|cFFFF4400still dirty') + break + end + end end else - SetCVar(cVar, (GetCVarBool(cVar) and 0) or 1) + print('|cFFFF4400making dirty') + for i, info in ipairs(db.DefaultFilters) do + if info.cVar then + local msgType = (cVar == info.cVar) and FILTER_INCLUDE_TYPE or FILTER_EXCLUDE_TYPE + SetCVar(info.cVar, ((cVar == info.cVar) and 1) or 0) + tinsert(filtered_report, msgType:format(info.label)) + end + end + parent.cvarFiltersDirty = true end else - local flushValue - print('') - if WorldPlan.UsedFilters[filterKey] == filterValue then - WorldPlan.UsedFilters[filterKey] = nil - tinsert(filtered_report, '|cFFFF0000'.. tostring(filterKey) ..'|r') + if resetMode then + wipe(db.UsedFilters) + --WorldPlan:print('Type filters reset.') else - WorldPlan.UsedFilters[filterKey] = filterValue - tinsert(filtered_report, '|cFF00FF00'.. tostring(filterKey) ..'|r') + if (db.UsedFilters[filterKey] == filterValue) or resetMode then + db.UsedFilters[filterKey] = nil + tinsert(filtered_report, FILTER_INCLUDE_TYPE:format(tostring(filterKey))) + else + db.UsedFilters[filterKey] = filterValue + tinsert(filtered_report, FILTER_EXCLUDE_TYPE:format(tostring(filterKey))) + end end end - WorldPlan:print('Changed:', table.concat(filtered_report, ', ')) + if #filtered_report >= 1 then + --WorldPlan:print('Setting filter(s):', table.concat(filtered_report, ', ')) + end WorldPlan:Refresh(true) end \ No newline at end of file