Nenue@30: -- WorldPlan Nenue@30: -- FilterBar.lua Nenue@30: -- Created: 10/27/2016 8:55 PM Nenue@30: -- %file-revision% Nenue@30: -- Nenue@40: local _, db = ... Nenue@30: local print = DEVIAN_WORKSPACE and function(...) _G.print('FilterBar', ...) end or nop Nenue@33: local wprint = DEVIAN_WORKSPACE and function(...) _G.print('WP', ...) end or function() end Nenue@31: local wipe, ipairs, pairs = table.wipe, ipairs, pairs Nenue@30: Nenue@30: local REWARD_CASH = WORLD_QUEST_REWARD_TYPE_FLAG_GOLD Nenue@30: local REWARD_ARTIFACT_POWER = WORLD_QUEST_REWARD_TYPE_FLAG_ARTIFACT_POWER Nenue@30: local REWARD_GEAR = WORLD_QUEST_REWARD_TYPE_FLAG_EQUIPMENT Nenue@30: local REWARD_CURRENCY = WORLD_QUEST_REWARD_TYPE_FLAG_ORDER_RESOURCES Nenue@30: local REWARD_REAGENT = WORLD_QUEST_REWARD_TYPE_FLAG_MATERIALS Nenue@30: Nenue@30: Nenue@93: local filtersUsed Nenue@93: local filterFill = "Interface\\BUTTONS\\YELLOWORANGE64" Nenue@93: local filterMask = "Interface\\Minimap\\UI-Minimap-Background" Nenue@93: Nenue@93: local HEADERS_SPACING = 3 Nenue@93: local BUTTONS_SPACING = 1 Nenue@93: local BUTTONS_HEIGHT = 20 Nenue@93: local TOGGLE_SIZE = 20 Nenue@95: local HEADERS_HEIGHT = 24 Nenue@93: Nenue@30: local LE_QUEST_TAG_TYPE_PVP = LE_QUEST_TAG_TYPE_PVP Nenue@30: local LE_QUEST_TAG_TYPE_PET_BATTLE = LE_QUEST_TAG_TYPE_PET_BATTLE Nenue@30: local LE_QUEST_TAG_TYPE_DUNGEON = LE_QUEST_TAG_TYPE_DUNGEON Nenue@30: local LE_QUEST_TAG_TYPE_PROFESSION = LE_QUEST_TAG_TYPE_PROFESSION Nenue@33: Nenue@93: local barMouseOver Nenue@93: local filtersDirty = true Nenue@93: local layoutDirty = true Nenue@93: local matchesDirty -- don't flag until first filter loadout Nenue@93: Nenue@33: local familiars = { Nenue@33: [42159] = {npc = 106552, name = 'Nightwatcher Merayl'}, Nenue@33: [40277] = {npc = 97804, name = 'Tiffany Nelson'}, Nenue@33: [40298] = {npc = 99182, name = 'Sir Galveston'}, Nenue@33: [40282] = {npc= 99150, name = 'Grixis Tinypop'}, Nenue@33: [40278] = {npc = 98270, name = 'Robert Craig'}, Nenue@33: [48195] = {npc = 105250, name = 'Aulier'}, Nenue@33: [41990] = {npc = 105674, name = 'Varenne'}, Nenue@33: [41860] = {npc = 104970, name = 'Xorvasc'}, Nenue@33: [40299] = {npc = 99210, name = 'Bodhi Sunwayver'}, Nenue@33: [42442] = {npc = 107489, name = 'Amalia'}, Nenue@33: [40280] = {npc = 99077, name = 'Bredda Tenderhide'}, Nenue@33: [41687] = {npc = 104553, name = 'Odrogg'}, Nenue@33: [41944] = {npc = 105455, name = 'Trapper Jarrun'}, Nenue@33: [40337] = {npc = 97709, name = 'Master Tamer Flummox'}, Nenue@33: [40279] = {npc = 99035, name = 'Durian Strongfruit'} Nenue@33: } Nenue@33: local familiars_id = 9696 Nenue@33: Nenue@40: db.DefaultFilterType = { Nenue@36: iconWidth = 24, Nenue@40: iconHeight = 18, Nenue@36: borderWidth = 3, Nenue@36: highlightWidth = 2, Nenue@30: TagSize = 12, Nenue@30: TimeleftStage = 3, Nenue@30: showNumber = true, Nenue@30: numberFontObject = 'WorldPlanNumberFontThin' Nenue@30: } Nenue@93: Nenue@93: local headerNames = { Nenue@93: ['rewardType'] = 'Reward Type', Nenue@93: ['worldQuestType'] = 'Quest Type', Nenue@93: ['isElite'] = 'Elite', Nenue@93: ['factionID'] = 'Bounties' Nenue@93: } Nenue@93: Nenue@40: db.DefaultFilters = { Nenue@30: { filterKey= 'rewardType', cVar = 'worldQuestFilterArtifactPower', filterValue = REWARD_ARTIFACT_POWER, label = 'Artifact Power', texture = "Interface\\ICONS\\inv_7xp_inscription_talenttome01" }, Nenue@31: { filterKey= 'rewardType', cVar = 'worldQuestFilterOrderResources', filterValue = REWARD_CURRENCY,label = 'Order Resources', texture = "Interface\\Icons\\inv_orderhall_orderresources" }, Nenue@30: { filterKey= 'rewardType', cVar = 'worldQuestFilterEquipment', filterValue = REWARD_GEAR, label = 'Equipment', texture = "Interface\\ICONS\\garrison_bluearmorupgrade" }, Nenue@30: { filterKey= 'rewardType', cVar = 'worldQuestFilterProfessionMaterials', filterValue = REWARD_REAGENT, label = 'Materials', texture = 1417744 }, Nenue@30: { filterKey= 'rewardType', cVar = 'worldQuestFilterGold', filterValue = REWARD_CASH, label = 'Gold', texture = "Interface\\Buttons\\UI-GroupLoot-Coin-Up" }, Nenue@30: { filterKey= 'worldQuestType', filterValue = LE_QUEST_TAG_TYPE_PVP, label = 'PvP', texture = "Interface\\Icons\\Ability_PVP_GladiatorMedallion", spacing = 10 }, Nenue@30: { filterKey= 'worldQuestType', filterValue = LE_QUEST_TAG_TYPE_PET_BATTLE, label = 'Pet Battle', texture = "Interface\\Icons\\PetJournalPortrait", }, Nenue@93: { filterKey= 'worldQuestType', filterValue = LE_QUEST_TAG_TYPE_DUNGEON, label = 'Dungeon', texture = "Interface\\LFGFRAME\\BattlenetWorking0", }, Nenue@30: { filterKey= 'worldQuestType', filterValue = LE_QUEST_TAG_TYPE_PROFESSION, label = 'Profession', texture = "Interface\\ICONS\\70_professions_scroll_02", }, Nenue@93: --{ filterKey = 'isElite', filterValue = true, label = 'Elite', texture = "", desaturated = false}, Nenue@93: --{ filterKey = 'isElite', filterValue = false, label = 'Not-Elite', texture = "", desaturated = false}, Nenue@30: } Nenue@30: local defaults = {} Nenue@30: Nenue@108: WorldPlanSummaryMixin = { Nenue@108: fadeOpacity = 1, Nenue@108: } Nenue@41: local Module = WorldPlanSummaryMixin Nenue@41: Module.selectedBountyIndex = {} Nenue@41: Module.bounties = {} Nenue@41: Module.filterList = {} Nenue@93: Module.Buttons = {} Nenue@93: Module.Headers = {} Nenue@41: Module.cvarFiltersDirty = false Nenue@93: WorldPlanFilterButtonMixin = {} Nenue@93: local Pin = WorldPlanFilterButtonMixin Nenue@30: Nenue@41: function Module:OnLoad() Nenue@93: --self:SetParent(WorldMapFrame.UIElementsFrame) Nenue@40: WorldPlan:AddHandler(self) Nenue@69: --[[for index, info in ipairs(db.DefaultFilters) do Nenue@40: info.zone = db.DefaultFilterType Nenue@40: info.continent = db.DefaultFilterType Nenue@30: info.pinMask = "Interface\\Minimap\\UI-Minimap-Background" Nenue@30: WorldPlan:AddTypeInfo(self,index, info) Nenue@30: end Nenue@69: --]] Nenue@93: Nenue@93: Nenue@30: end Nenue@30: Nenue@30: Nenue@57: function Module:OnEvent(event, arg) Nenue@33: print('|cFF00FF88'..self:GetName()..':OnEvent()', event) Nenue@57: if (event == 'QUEST_LOG_UPDATE') and arg then Nenue@93: filtersDirty = true Nenue@93: self:Refresh() Nenue@57: end Nenue@30: end Nenue@30: Nenue@30: local bountyIndex Nenue@30: local debug_headers = {} Nenue@93: local ToggleButton = {} Nenue@41: function Module:Setup() Nenue@33: print('|cFF00FF88'..self:GetName()..':Setup()') Nenue@45: self.isStale = true Nenue@93: self:SetParent(WorldMapFrame.UIElementsFrame) Nenue@93: --self:SetPoint('BOTTOMLEFT') Nenue@93: for k,v in pairs( ToggleButton) do Nenue@93: self.Toggle:SetScript(k,v) Nenue@93: end Nenue@93: self.Toggle:SetSize(TOGGLE_SIZE, TOGGLE_SIZE) Nenue@93: Nenue@30: end Nenue@30: Nenue@30: Nenue@93: function Module:OnUpdate(sinceLast) Nenue@33: if self.isStale then Nenue@93: print('|cFF00FF00pushing update') Nenue@33: self:Refresh() Nenue@33: end Nenue@93: Nenue@93: barMouseOver = self:IsMouseOver() Nenue@108: self:UpdateAlpha(sinceLast, barMouseOver) Nenue@30: end Nenue@33: Nenue@84: function Module:OnMapInfo(isBrokenIsle, isZoomedOut, mapAreaID, isNewMap, isMapOpen) Nenue@84: print('|cFFFFFF00OnMapInfo()', isBrokenIsle, isZoomedOut, mapAreaID, isNewMap, isMapOpen) Nenue@41: if not isBrokenIsle then Nenue@41: self:SetShown(false) Nenue@41: else Nenue@93: self:SetShown(true) Nenue@93: if isMapOpen then Nenue@84: self:Refresh() Nenue@93: else Nenue@93: matchesDirty = true Nenue@93: layoutDirty = true Nenue@84: end Nenue@41: end Nenue@41: end Nenue@41: Nenue@41: function Module:OnShow() Nenue@33: print('|cFF00FF88'..self:GetName()..':OnShow()') Nenue@93: self:Refresh() Nenue@93: end Nenue@93: Nenue@93: local IsBountyCriteria = function(poiFrame, questID) Nenue@93: return IsQuestCriteriaForBounty(poiFrame.questID, questID) Nenue@93: end Nenue@93: Nenue@93: local tinsert, GetQuestBountyInfoForMapID, GetQuestLogTitle, GetQuestLogIndexByID = tinsert, GetQuestBountyInfoForMapID, GetQuestLogTitle, GetQuestLogIndexByID Nenue@93: Nenue@93: function Module:OnConfigUpdate() Nenue@93: Nenue@93: ToggleButton.OnShow(self.Toggle) Nenue@93: end Nenue@93: Nenue@93: function Module:Reset() Nenue@95: Nenue@95: Nenue@95: Nenue@93: self:UpdateFilters('SUMMARY_RESET') Nenue@93: self:UpdateMatches('SUMMARY_RESET') Nenue@93: self:UpdateLayout('SUMMARY_RESET') Nenue@93: end Nenue@93: Nenue@93: function Module:Refresh() Nenue@93: self:UpdateFilters('SUMMARY_REFRESH') Nenue@93: self:UpdateMatches('SUMMARY_REFRESH') Nenue@93: self:UpdateLayout('SUMMARY_REFRESH') Nenue@93: end Nenue@93: Nenue@93: local questResults = {{} } Nenue@93: db.FilterList = {} Nenue@93: Nenue@93: function Module:UpdateFilters(event) Nenue@93: Nenue@93: print('|cFF00FFFF'..self:GetName()..':GetFilters()', event) Nenue@93: Nenue@93: wipe(db.FilterList) Nenue@93: Nenue@93: for index, info in ipairs(db.DefaultFilters) do Nenue@95: info.used = true Nenue@93: tinsert(db.FilterList, info) Nenue@93: end Nenue@93: self.bounties = db.Bounties Nenue@93: self.BountyFilters = {} Nenue@95: local numBounties = 0 Nenue@93: for index, data in ipairs(self.bounties) do Nenue@93: if not IsQuestComplete(data.questID) then Nenue@95: numBounties = numBounties + 1 Nenue@93: local info = self.BountyFilters[index] Nenue@93: if not info then Nenue@93: info = {} Nenue@93: self.BountyFilters[index] = info Nenue@93: layoutDirty = true Nenue@93: else Nenue@93: if info.questID ~= data.questID then Nenue@93: layoutDirty = true Nenue@93: end Nenue@93: end Nenue@93: Nenue@93: local questTitle = GetQuestLogTitle(GetQuestLogIndexByID(data.questID)) Nenue@95: info.used = true Nenue@93: info.filterKey = 'factionID' Nenue@93: info.filterFunc = IsBountyCriteria Nenue@93: info.filterValue = data.questID Nenue@93: info.label = questTitle Nenue@93: info.texture = data.icon Nenue@93: print('loading emissary', questTitle) Nenue@93: Nenue@93: tinsert(db.FilterList, info) Nenue@93: --{ filterKey= 'worldQuestType', filterValue = LE_QUEST_TAG_TYPE_PROFESSION, label = 'Profession', texture = "Interface\\LFGFRAME\\UI-LFR-PORTRAIT", }, Nenue@93: end Nenue@95: end Nenue@93: Nenue@95: for i = numBounties + 1, #self.BountyFilters do Nenue@95: self.BountyFilters[i].used = nil Nenue@32: end Nenue@95: Nenue@32: end Nenue@30: Nenue@93: function Module:UpdateMatches(event) Nenue@93: print('|cFF00FF00UpdateMatches()', event) Nenue@93: local quests = db.QuestsByID Nenue@93: local questsForMap = db.QuestsByZone[db.currentMapID] or quests Nenue@30: Nenue@93: for index, info in ipairs(db.FilterList) do Nenue@93: info.GlobalMatches = info.GlobalMatches or {} Nenue@93: info.LocalMatches = info.LocalMatches or {} Nenue@93: wipe(info.GlobalMatches) Nenue@93: wipe(info.LocalMatches) Nenue@93: print(info.filterKey, info.filterValue, info.filterFunc and 'func test' or 'compare') Nenue@93: for questID, pin in pairs(quests) do Nenue@93: print('', questID, pin.dataLoaded, (not IsQuestComplete(questID))) Nenue@95: if pin.dataLoaded and (not IsQuestComplete(questID)) then Nenue@93: local keyName, keyValue = info.filterKey, info.filterValue Nenue@93: local isMatch Nenue@93: if info.filterFunc then Nenue@93: isMatch = info.filterFunc(pin, keyValue) Nenue@93: print(' running special function, result =', isMatch) Nenue@93: elseif pin[keyName] and (pin[keyName] == keyValue) then Nenue@93: isMatch = true Nenue@93: print(' rote match') Nenue@93: end Nenue@93: if isMatch then Nenue@93: tinsert(info.GlobalMatches, pin) Nenue@93: if questsForMap[questID] then Nenue@93: print(' local map') Nenue@93: tinsert(info.LocalMatches, pin) Nenue@93: end Nenue@93: end Nenue@93: end Nenue@30: end Nenue@93: print('global', #info.GlobalMatches, 'local', #info.LocalMatches) Nenue@30: end Nenue@30: end Nenue@30: Nenue@93: function Module:UpdateLayout(event) Nenue@93: print('|cFF00FF88UpdateLayout()|r', event, 'currentMap=',db.currentMapID) Nenue@30: Nenue@93: self.filtersSelected = nil Nenue@30: Nenue@93: local currentHeader Nenue@93: local relativeFrame = self Nenue@93: local lastKey Nenue@31: Nenue@93: local numHeaders = 0 Nenue@93: local numButtons = 0 Nenue@40: Nenue@93: local layoutWidth = TOGGLE_SIZE + HEADERS_SPACING * 2 Nenue@93: local headerWidth = HEADERS_SPACING Nenue@30: Nenue@40: Nenue@40: local layout = db.DefaultFilterType Nenue@36: local borderWidth = layout.iconWidth + (layout.borderWidth * 2) Nenue@36: local highlightWidth = borderWidth + (layout.highlightWidth * 2) Nenue@40: local mapQuests = db.QuestsByZone[db.currentMapID] or db.QuestsByID Nenue@84: local n = 0 Nenue@84: for _ in pairs(mapQuests) do Nenue@84: n = n + 1 Nenue@84: end Nenue@84: print(n, 'pins to work with') Nenue@84: Nenue@93: Nenue@93: filtersUsed = nil Nenue@57: local firstCvar, lastCvar Nenue@93: local isFirst = true Nenue@93: for index, info in ipairs(db.FilterList) do Nenue@93: --print('num here', numQuestsHere, numQuestsTotal) Nenue@40: Nenue@30: Nenue@40: --print(tostring(index).. ' ("'..tostring(info.label)..'" f('.. tostring(info.filterKey).. '='..tostring(info.filterValue) .. '), '..tostring(numQuests)..')') Nenue@40: Nenue@93: if #info.GlobalMatches >= 1 then Nenue@93: if info.filterKey ~= lastKey then Nenue@93: Nenue@93: numHeaders = numHeaders + 1 Nenue@93: local nextHeader = self.Headers[numHeaders] or CreateFrame('Frame', 'FilterHeader' .. numHeaders, self, 'WorldPlanFilterHeader') Nenue@93: if currentHeader then Nenue@93: nextHeader:SetPoint('TOPLEFT', currentHeader, 'TOPRIGHT', 0, 0) Nenue@93: Nenue@93: currentHeader:SetSize(headerWidth - BUTTONS_SPACING + HEADERS_SPACING, HEADERS_HEIGHT) Nenue@93: layoutWidth = layoutWidth + headerWidth Nenue@93: headerWidth = HEADERS_SPACING Nenue@93: else Nenue@93: nextHeader:SetPoint('TOPLEFT', TOGGLE_SIZE + HEADERS_SPACING * 2, 0) Nenue@93: Nenue@93: end Nenue@93: Nenue@93: print(' begin header '..numHeaders, 'layout width =', floor(layoutWidth+.5)) Nenue@93: isFirst = true Nenue@93: currentHeader = nextHeader Nenue@93: currentHeader.Backdrop:SetHeight(BUTTONS_HEIGHT *2) Nenue@93: currentHeader.Label:SetText(headerNames[info.filterKey]) Nenue@93: relativeFrame = currentHeader Nenue@93: end Nenue@93: Nenue@93: numButtons = numButtons + 1 Nenue@93: local button = self.Buttons[numButtons] Nenue@93: if not button then Nenue@93: button = CreateFrame('Button', 'FilterButton'..numButtons, self, 'WorldPlanFilterButton') Nenue@93: button:SetSize(32,BUTTONS_HEIGHT) Nenue@93: button.icon:SetTexCoord(0.1,.9,.1,(1 * (BUTTONS_HEIGHT/32))) Nenue@30: Nenue@40: button.RewardBorder:ClearAllPoints() Nenue@40: button.RewardBorder:SetPoint('TOPLEFT', button, 'TOPLEFT') Nenue@40: button.RewardBorder:SetPoint('BOTTOMRIGHT', button, 'BOTTOMRIGHT') Nenue@30: end Nenue@30: Nenue@30: button.info = info Nenue@93: button.numQuestsTotal = #info.GlobalMatches Nenue@93: button.numQuestsHere = #info.LocalMatches Nenue@93: button.GlobalMatches = info.GlobalMatches Nenue@93: button.LocalMatches = info.LocalMatches Nenue@93: button.isFirst = isFirst Nenue@30: button:SetID(index) Nenue@93: button:SetParent(currentHeader) Nenue@30: button.relativeFrame = relativeFrame Nenue@40: button:Refresh() Nenue@30: button:Show() Nenue@30: relativeFrame = button Nenue@93: headerWidth = headerWidth + button:GetWidth() + BUTTONS_SPACING Nenue@40: Nenue@93: isFirst = false Nenue@40: if info.cVar then Nenue@40: firstCvar = firstCvar or button Nenue@40: lastCvar = button Nenue@40: end Nenue@93: lastKey = info.filterKey Nenue@30: end Nenue@30: end Nenue@30: Nenue@30: self.numHeaders = numHeaders Nenue@93: for i = numButtons + 1, #self.Buttons do Nenue@93: if self.Buttons[i] then Nenue@93: self.Buttons[i]:Hide() Nenue@93: wipe(self.Buttons[i].LocalMatches) Nenue@93: wipe(self.Buttons[i].GlobalMatches) Nenue@93: end Nenue@93: end Nenue@93: for i = numHeaders + 1, #self.Headers do Nenue@93: if self.Headers[i] then Nenue@93: self.Headers[i]:Hide() Nenue@31: end Nenue@30: end Nenue@40: Nenue@40: Nenue@93: if currentHeader then Nenue@93: currentHeader:SetSize(headerWidth - BUTTONS_SPACING + HEADERS_SPACING, HEADERS_HEIGHT) Nenue@93: layoutWidth = layoutWidth + headerWidth + HEADERS_SPACING Nenue@93: end Nenue@40: Nenue@95: self:SetSize(layoutWidth, BUTTONS_HEIGHT + (BUTTONS_SPACING * 2)) Nenue@93: self:ClearAllPoints() Nenue@108: self:SetPoint('TOPLEFT', WorldMapFrameNavBar, 'BOTTOMLEFT', 0, -3) Nenue@32: self.isStale = nil Nenue@93: layoutDirty = nil Nenue@30: end Nenue@30: Nenue@41: function Module:Cleanup() Nenue@30: -- hide trailing buttons Nenue@30: end Nenue@30: Nenue@93: local rgbWhite = {r = 1, g= 1, b= 1, hex = '|cFFFFFFFF' } Nenue@93: local found = {} Nenue@41: function Pin:OnEnter() Nenue@93: if #self.GlobalMatches >= 1 then Nenue@93: GameTooltip:SetOwner(self, 'ANCHOR_BOTTOMRIGHT') Nenue@108: GameTooltip:AddLine(headerNames[self.info.filterKey]) Nenue@31: GameTooltip:AddLine(self.info.label) Nenue@93: wipe(found) Nenue@93: Nenue@93: if self.numQuestsHere >= 1 then Nenue@93: if self.numQuestsHere < self.numQuestsTotal then Nenue@93: GameTooltip:AddLine('This Zone', 1, 1, 0) Nenue@93: end Nenue@93: for index, pin in ipairs(self.LocalMatches) do Nenue@117: if not IsQuestFlaggedCompleted(pin.questID) then Nenue@117: local colorInfo = (pin.quality and ITEM_QUALITY_COLORS[pin.quality]) or rgbWhite Nenue@117: found[pin] = pin Nenue@117: GameTooltip:AddLine('|T'.. tostring(pin.itemTexture)..':16:16|t ' .. tostring(pin.title) ..(pin.cheevos and " |cFFFFFF00!|R" or ''), 0, 1, 0) Nenue@117: end Nenue@93: end Nenue@31: end Nenue@93: Nenue@93: if self.numQuestsHere < self.numQuestsTotal then Nenue@93: if self.numQuestsHere >= 1 then Nenue@93: GameTooltip:AddLine(' ') Nenue@93: end Nenue@117: GameTooltip:AddLine('Other Zones', 1, 1, 0) Nenue@93: for index, pin in ipairs(self.GlobalMatches) do Nenue@117: if not IsQuestFlaggedCompleted(pin.questID) then Nenue@117: if not found[pin] then Nenue@117: local colorInfo = (pin.quality and ITEM_QUALITY_COLORS[pin.quality]) or rgbWhite Nenue@117: found[pin] = pin Nenue@117: GameTooltip:AddLine('|T'.. tostring(pin.itemTexture)..':16:16|t ' .. tostring(pin.title) ..(pin.cheevos and " |cFFFFFF00!|R" or ''), 1, 1, 1) Nenue@117: end Nenue@93: end Nenue@93: end Nenue@93: end Nenue@93: Nenue@40: GameTooltip:AddLine(self.numQuestsTotal .. ' total') Nenue@36: GameTooltip:Show() Nenue@31: end Nenue@30: end Nenue@30: Nenue@41: function Pin:OnLeave() Nenue@31: if GameTooltip:IsOwned(self) then Nenue@31: GameTooltip:Hide() Nenue@31: end Nenue@31: end Nenue@30: Nenue@41: function Pin:Refresh() Nenue@30: local info = self.info Nenue@30: self.filterKey = info.filterKey Nenue@30: self.filterValue = info.filterValue Nenue@30: self.tagID = info.tagID Nenue@30: Nenue@30: self.icon:SetTexture(info.texture) Nenue@93: Nenue@93: if (self.numQuestsHere == 0) and (self.numQuestsTotal >= 1) then Nenue@93: self.count:SetText('*'..self.numQuestsTotal) Nenue@93: self.count:SetTextColor(0,1,1) Nenue@93: elseif self.numQuestsHere < self.numQuestsTotal then Nenue@93: self.count:SetText(self.numQuestsHere..'+') Nenue@93: self.count:SetTextColor(1,1,0) Nenue@93: else Nenue@93: self.count:SetText(self.numQuestsHere) Nenue@93: self.count:SetTextColor(1,1,1) Nenue@93: end Nenue@93: Nenue@30: self.cVar = info.cVar Nenue@30: self.itemTexture = self.texture Nenue@30: Nenue@45: self:ClearAllPoints() Nenue@40: if self.isFirst then Nenue@93: self:SetPoint('TOPLEFT', self.relativeFrame, 'TOPLEFT', HEADERS_SPACING, -HEADERS_SPACING) Nenue@30: else Nenue@93: self:SetPoint('LEFT', self.relativeFrame, 'RIGHT', BUTTONS_SPACING, 0) Nenue@30: end Nenue@93: --print('anchor', self.relativeFrame:IsShown(), self:GetPoint(1)) Nenue@30: Nenue@40: self.icon:SetDesaturated(self.numQuestsHere == 0) Nenue@40: Nenue@40: local r, g, b, a = 0,0,0,1 Nenue@31: local desaturated = false Nenue@93: if (self.numQuestsHere > 0) or db.UsedFilters[self.filterKey] then Nenue@93: Nenue@40: if self.cVar then Nenue@40: if GetCVarBool(self.cVar) then Nenue@93: --self.count:SetTextColor(1,1,1) Nenue@41: r,g,b,a = 0, 0, 0, 1 Nenue@31: else Nenue@93: filtersUsed = true Nenue@93: --self.count:SetTextColor(1,0,0) Nenue@40: self.icon:SetDesaturated(true) Nenue@41: r,g,b,a = 1, 0, 0, 0.5 Nenue@31: end Nenue@31: else Nenue@40: if db.UsedFilters[self.filterKey] then Nenue@93: filtersUsed = true Nenue@40: if db.UsedFilters[self.filterKey] == self.filterValue then Nenue@93: --self.count:SetTextColor(0,1,0) Nenue@41: r, g, b = 0, 1, 0 Nenue@40: else Nenue@93: --self.count:SetTextColor(1,0,0) Nenue@40: r, g, b = 1, 0, 0 Nenue@40: end Nenue@36: else Nenue@36: Nenue@93: --self.count:SetTextColor(1,1,1) Nenue@40: if self.filterKey == 'worldQuestType' then Nenue@40: r, g, b = 0, 0, 1 Nenue@40: elseif self.filterKey == 'factionID' then Nenue@40: r, g, b = 1, 1, 0 Nenue@40: end Nenue@36: end Nenue@30: end Nenue@30: end Nenue@41: self.RewardBorder:SetColorTexture(r, g, b) Nenue@41: self:SetAlpha(a) Nenue@31: Nenue@30: --self:UpdateSize() Nenue@30: end Nenue@30: Nenue@41: function Pin:OnLoad() Nenue@30: self:RegisterForClicks('AnyUp') Nenue@30: self:SetFrameStrata('HIGH') Nenue@30: self:SetFrameLevel(151) Nenue@40: self.questList = {} Nenue@41: -- WORLD_MAP_UPDATE and PLAYER_ENTERING_WORLD are passed down from a higher level Nenue@30: end Nenue@30: Nenue@41: function Pin:OnUpdate () Nenue@93: local group = self:GetParent() Nenue@93: if group:IsMouseOver() and barMouseOver then Nenue@93: group.Backdrop:Show() Nenue@93: group.Label:Show() Nenue@93: else Nenue@93: group.Backdrop:Hide() Nenue@93: group.Label:Hide() Nenue@93: end Nenue@30: end Nenue@30: Nenue@30: -- shift-click: reset filter Nenue@30: -- click: rotate through include(1), exclude(-1), ignore(nil) Nenue@36: local filtered_report = {} Nenue@40: local RESET_FILTER = "|cFFFFFFFF+%s|r" Nenue@40: local FILTER_EXCLUDE_TYPE = '|cFFFF0000-%s|r' Nenue@40: local FILTER_INCLUDE_TYPE = '|cFF00FF00+%s|r' Nenue@41: function Pin:OnClick (button) Nenue@30: Nenue@30: local filterKey = self.filterKey Nenue@30: local filterValue = self.filterValue Nenue@36: local cVar = self.cVar Nenue@36: local parent = self:GetParent() Nenue@40: local setDirty Nenue@40: Nenue@40: print('|cFF00FF88'..self:GetName()..':OnClick()|r', filterKey, filterValue, cVar, parent) Nenue@30: Nenue@36: local resetMode = (button == 'RightButton') Nenue@36: wipe(filtered_report) Nenue@36: if not (filterKey or cVar) then Nenue@40: for i, info in ipairs(db.DefaultFilters) do Nenue@33: if info.cVar then Nenue@40: SetCVar(info.cVar, 1) Nenue@40: elseif info.filterKey then Nenue@40: if db.UsedFilters[info.filterKey] then Nenue@40: db.UsedFilters[info.filterKey] = nil Nenue@36: end Nenue@33: end Nenue@33: end Nenue@40: parent.cvarFiltersDirty = false Nenue@33: Nenue@40: --WorldPlan:print('All filters reset.') Nenue@36: elseif cVar then Nenue@40: if resetMode then Nenue@40: print('|cFFFF4400cleaning dirty') Nenue@40: for i, info in ipairs(db.DefaultFilters) do Nenue@33: if info.cVar then Nenue@40: parent.cvarFiltersDirty = false Nenue@40: SetCVar(info.cVar, 1) Nenue@33: end Nenue@33: end Nenue@40: --WorldPlan:print('Reward filters reset.') Nenue@40: elseif parent.cvarFiltersDirty == true then Nenue@40: if GetCVarBool(cVar) then Nenue@40: tinsert(filtered_report, FILTER_EXCLUDE_TYPE:format(tostring(self.info.label))) Nenue@40: SetCVar(cVar, 0) Nenue@40: else Nenue@40: Nenue@40: tinsert(filtered_report, FILTER_INCLUDE_TYPE:format(tostring(self.info.label))) Nenue@40: SetCVar(cVar, 1) Nenue@40: end Nenue@40: Nenue@40: -- check the visible filters and consider it clean if they're all lit Nenue@40: parent.cvarFiltersDirty = false Nenue@93: for i, info in ipairs(db.FilterList) do Nenue@93: if info.cVar and (#info.GlobalMatches >= 1) then Nenue@40: print(info.cVar, GetCVarBool(info.cVar)) Nenue@40: if GetCVarBool(info.cVar) == false then Nenue@40: parent.cvarFiltersDirty = true Nenue@40: print('|cFFFF4400still dirty') Nenue@40: break Nenue@40: end Nenue@40: end Nenue@36: end Nenue@36: else Nenue@40: print('|cFFFF4400making dirty') Nenue@40: for i, info in ipairs(db.DefaultFilters) do Nenue@40: if info.cVar then Nenue@40: local msgType = (cVar == info.cVar) and FILTER_INCLUDE_TYPE or FILTER_EXCLUDE_TYPE Nenue@40: SetCVar(info.cVar, ((cVar == info.cVar) and 1) or 0) Nenue@40: tinsert(filtered_report, msgType:format(info.label)) Nenue@40: end Nenue@40: end Nenue@40: parent.cvarFiltersDirty = true Nenue@36: end Nenue@30: else Nenue@40: if resetMode then Nenue@40: wipe(db.UsedFilters) Nenue@40: --WorldPlan:print('Type filters reset.') Nenue@31: else Nenue@40: if (db.UsedFilters[filterKey] == filterValue) or resetMode then Nenue@40: db.UsedFilters[filterKey] = nil Nenue@40: tinsert(filtered_report, FILTER_INCLUDE_TYPE:format(tostring(filterKey))) Nenue@40: else Nenue@40: db.UsedFilters[filterKey] = filterValue Nenue@40: tinsert(filtered_report, FILTER_EXCLUDE_TYPE:format(tostring(filterKey))) Nenue@40: end Nenue@30: end Nenue@30: end Nenue@40: if #filtered_report >= 1 then Nenue@40: --WorldPlan:print('Setting filter(s):', table.concat(filtered_report, ', ')) Nenue@40: end Nenue@33: WorldPlan:Refresh(true) Nenue@93: end Nenue@93: function ToggleButton:OnEnter() Nenue@93: Nenue@93: GameTooltip:SetOwner(self, 'ANCHOR_BOTTOMRIGHT') Nenue@93: GameTooltip:AddLine('Toggle Pins') Nenue@93: GameTooltip:Show() Nenue@93: end Nenue@93: function ToggleButton:OnLeave() Nenue@93: Nenue@93: if GameTooltip:IsOwned(self) then Nenue@93: GameTooltip:Hide() Nenue@93: end Nenue@93: end Nenue@93: function ToggleButton:OnShow() Nenue@93: self:SetChecked(db.Config.EnablePins and true or false) Nenue@93: end Nenue@93: function ToggleButton:OnHide() Nenue@93: if GameTooltip:IsOwned(self) then Nenue@93: GameTooltip:Hide() Nenue@93: end Nenue@93: Nenue@93: end Nenue@93: function ToggleButton:OnClick() Nenue@93: --print(self:GetChecked()) Nenue@93: db.Config.EnablePins = self:GetChecked() Nenue@93: _G.WorldPlan:OnConfigUpdate() Nenue@30: end