Mercurial > wow > worldplan
comparison FilterBar.lua @ 30:8cb750e79952
WorldPlan:
- Reworking filters to utilize newly added CVars
author | Nenue |
---|---|
date | Fri, 28 Oct 2016 14:06:07 -0400 |
parents | |
children | d0114b51cdea |
comparison
equal
deleted
inserted
replaced
29:c1612c2c1840 | 30:8cb750e79952 |
---|---|
1 -- WorldPlan | |
2 -- FilterBar.lua | |
3 -- Created: 10/27/2016 8:55 PM | |
4 -- %file-revision% | |
5 -- | |
6 | |
7 local print = DEVIAN_WORKSPACE and function(...) _G.print('FilterBar', ...) end or nop | |
8 | |
9 local REWARD_CASH = WORLD_QUEST_REWARD_TYPE_FLAG_GOLD | |
10 local REWARD_ARTIFACT_POWER = WORLD_QUEST_REWARD_TYPE_FLAG_ARTIFACT_POWER | |
11 local REWARD_GEAR = WORLD_QUEST_REWARD_TYPE_FLAG_EQUIPMENT | |
12 local REWARD_CURRENCY = WORLD_QUEST_REWARD_TYPE_FLAG_ORDER_RESOURCES | |
13 local REWARD_REAGENT = WORLD_QUEST_REWARD_TYPE_FLAG_MATERIALS | |
14 | |
15 | |
16 local LE_QUEST_TAG_TYPE_PVP = LE_QUEST_TAG_TYPE_PVP | |
17 local LE_QUEST_TAG_TYPE_PET_BATTLE = LE_QUEST_TAG_TYPE_PET_BATTLE | |
18 local LE_QUEST_TAG_TYPE_DUNGEON = LE_QUEST_TAG_TYPE_DUNGEON | |
19 local LE_QUEST_TAG_TYPE_PROFESSION = LE_QUEST_TAG_TYPE_PROFESSION | |
20 local LE_QUEST_TAG_TYPE_NORMAL = LE_QUEST_TAG_TYPE_NORMAL | |
21 local DEFAULT_FILTER_LAYOUT = { | |
22 PinSize = 22, | |
23 Border = 3, | |
24 TrackingBorder = 2, | |
25 TagSize = 12, | |
26 TimeleftStage = 3, | |
27 showNumber = true, | |
28 numberFontObject = 'WorldPlanNumberFontThin' | |
29 } | |
30 local DEFAULT_FILTER_LIST = { | |
31 { label = 'Filters', texture = "Interface\\WorldMap\\WorldMap-Icon" }, | |
32 { filterKey= 'rewardType', cVar = 'worldQuestFilterArtifactPower', filterValue = REWARD_ARTIFACT_POWER, label = 'Artifact Power', texture = "Interface\\ICONS\\inv_7xp_inscription_talenttome01" }, | |
33 { filterKey= 'rewardType', cVar = 'worldQuestFilterOrderResources', filterValue = REWARD_CURRENCY,label = 'Order Resources', texture = "Interface\\ICONS\\inv_misc_elvencoins" }, | |
34 { filterKey= 'rewardType', cVar = 'worldQuestFilterEquipment', filterValue = REWARD_GEAR, label = 'Equipment', texture = "Interface\\ICONS\\garrison_bluearmorupgrade" }, | |
35 { filterKey= 'rewardType', cVar = 'worldQuestFilterProfessionMaterials', filterValue = REWARD_REAGENT, label = 'Materials', texture = 1417744 }, | |
36 { filterKey= 'rewardType', cVar = 'worldQuestFilterGold', filterValue = REWARD_CASH, label = 'Gold', texture = "Interface\\Buttons\\UI-GroupLoot-Coin-Up" }, | |
37 { filterKey= 'worldQuestType', filterValue = LE_QUEST_TAG_TYPE_PVP, label = 'PvP', texture = "Interface\\Icons\\Ability_PVP_GladiatorMedallion", spacing = 10 }, | |
38 { filterKey= 'worldQuestType', filterValue = LE_QUEST_TAG_TYPE_PET_BATTLE, label = 'Pet Battle', texture = "Interface\\Icons\\PetJournalPortrait", }, | |
39 { filterKey= 'worldQuestType', filterValue = LE_QUEST_TAG_TYPE_DUNGEON, label = 'Dungeon', texture = "Interface\\LFGFRAME\\UI-LFR-PORTRAIT", }, | |
40 { filterKey= 'worldQuestType', filterValue = LE_QUEST_TAG_TYPE_PROFESSION, label = 'Profession', texture = "Interface\\ICONS\\70_professions_scroll_02", }, | |
41 } | |
42 local defaults = {} | |
43 | |
44 WorldPlanSummaryMixin = { | |
45 selectedBountyIndex = {}, | |
46 bounties = {}, | |
47 filterList = {}, | |
48 buttons = {}, | |
49 } | |
50 WorldPlanFilterPinMixin = {} | |
51 | |
52 function WorldPlanSummaryMixin:OnLoad() | |
53 self:RegisterEvent('QUEST_LOG_UPDATE') | |
54 self:RegisterEvent('WORLD_MAP_UPDATE') | |
55 | |
56 WorldPlan:AddHandler(self, defaults) | |
57 | |
58 for index, info in ipairs(DEFAULT_FILTER_LIST) do | |
59 info.zone = DEFAULT_FILTER_LAYOUT | |
60 info.continent = DEFAULT_FILTER_LAYOUT | |
61 info.pinMask = "Interface\\Minimap\\UI-Minimap-Background" | |
62 | |
63 WorldPlan:AddTypeInfo(self,index, info) | |
64 end | |
65 | |
66 end | |
67 | |
68 | |
69 function WorldPlanSummaryMixin:OnEvent(event) | |
70 end | |
71 | |
72 local bountyIndex | |
73 local debug_headers = {} | |
74 | |
75 function WorldPlanSummaryMixin:Setup() | |
76 self:GetFilters() | |
77 end | |
78 | |
79 | |
80 function WorldPlanSummaryMixin:OnEvent(event,...) | |
81 self.isStale = true | |
82 end | |
83 | |
84 function WorldPlanSummaryMixin:OnShow() | |
85 self:Refresh() | |
86 end | |
87 | |
88 function WorldPlanSummaryMixin:GetFilters() | |
89 | |
90 | |
91 wipe(self.filterList) | |
92 | |
93 for index, info in ipairs(DEFAULT_FILTER_LIST) do | |
94 tinsert(self.filterList, info) | |
95 end | |
96 self.bounties, self.numBounties = GetQuestBountyInfoForMapID(WorldPlan.currentMapID) | |
97 self.BountyFilters = {} | |
98 for index, data in ipairs(self.bounties) do | |
99 local info = self.BountyFilters[index] | |
100 if not info then | |
101 info = {} | |
102 self.BountyFilters[index] = info | |
103 end | |
104 | |
105 local questTitle = GetQuestLogTitle(GetQuestLogIndexByID(data.questID)) | |
106 | |
107 info.filterKey = 'factionID' | |
108 info.filterValue = data.factionID | |
109 info.label = questTitle | |
110 info.texture = data.icon | |
111 print('loading emissary', questTitle) | |
112 | |
113 tinsert(self.filterList, info) | |
114 --{ filterKey= 'worldQuestType', filterValue = LE_QUEST_TAG_TYPE_PROFESSION, label = 'Profession', texture = "Interface\\LFGFRAME\\UI-LFR-PORTRAIT", }, | |
115 end | |
116 end | |
117 | |
118 function WorldPlanSummaryMixin:Reset() | |
119 self.pinLayout = self:GetTypeInfo(255) | |
120 self:GetFilters() | |
121 end | |
122 | |
123 function WorldPlanSummaryMixin:Refresh(forced) | |
124 self:Update(forced) | |
125 end | |
126 | |
127 local filterFill = "Interface\\BUTTONS\\YELLOWORANGE64" | |
128 local filterMask = "Interface\\Minimap\\UI-Minimap-Background" | |
129 function WorldPlanSummaryMixin:Update(forced) | |
130 local blocks = self.buttons | |
131 local relativeFrame = WorldMapFrame.UIElementsFrame.TrackingOptionsButton | |
132 local numHeaders = 0 | |
133 print('|cFF00FF88'..tostring(self)..':Refresh()|r', 'currentMap=',self.currentMapID) | |
134 | |
135 | |
136 local quests = WorldPlanQuests.QuestsByZone[self.currentMapID] or WorldPlanQuests.QuestsByID | |
137 | |
138 | |
139 for index, info in ipairs(self.filterList) do | |
140 local numQuests = 0 | |
141 | |
142 for questID, pin in pairs(quests) do | |
143 if pin.used then | |
144 if not info.filterKey then | |
145 numQuests = numQuests + 1 | |
146 elseif pin[info.filterKey] == info.filterValue then | |
147 numQuests = numQuests + 1 | |
148 end | |
149 end | |
150 end | |
151 print(tostring(index).. ' ("'..tostring(info.label)..'" f('.. tostring(info.filterKey).. '='..tostring(info.filterValue) .. '), '..tostring(numQuests)..')') | |
152 | |
153 if numQuests >= 1 then | |
154 numHeaders = numHeaders + 1 | |
155 local button = blocks[numHeaders] | |
156 if not blocks[numHeaders] then | |
157 button = CreateFrame('Button', 'WorldPlanFilterButton'..numHeaders, WorldMapScrollFrame, 'WorldPlanFilterPin') | |
158 | |
159 button:SetSize(24,24) | |
160 button.icon:ClearAllPoints() | |
161 button.icon:SetAllPoints(button) | |
162 | |
163 button.iconBorder:SetPoint('TOPLEFT', button, 'TOPLEFT', -2, 2) | |
164 button.iconBorder:SetPoint('BOTTOMRIGHT', button, 'BOTTOMRIGHT', 2, -2) | |
165 button.iconBorder:SetMask(filterMask) | |
166 button.iconBorder:SetTexture(filterFill) | |
167 button.iconBorder:SetDesaturated(true) | |
168 | |
169 button.supertrackBorder:Hide() | |
170 blocks[numHeaders] = button | |
171 end | |
172 | |
173 button.info = info | |
174 button:SetID(index) | |
175 button.spacing = ((info.filterKey ~= relativeFrame.filterKey) and 10) or 0 | |
176 button.relativeFrame = relativeFrame | |
177 button:Refresh((numHeaders == 1), numQuests) | |
178 button:Show() | |
179 relativeFrame = button | |
180 end | |
181 | |
182 end | |
183 | |
184 self.numHeaders = numHeaders | |
185 for i = numHeaders + 1, #blocks do | |
186 if blocks[i] then | |
187 blocks[i]:Hide() | |
188 end | |
189 end | |
190 end | |
191 | |
192 function WorldPlanSummaryMixin:Cleanup() | |
193 | |
194 -- hide trailing buttons | |
195 end | |
196 | |
197 function WorldPlanFilterPinMixin:OnEnter() | |
198 | |
199 end | |
200 function WorldPlanFilterPinMixin:OnLeave() | |
201 | |
202 end | |
203 | |
204 | |
205 function WorldPlanFilterPinMixin:Refresh(isFirst, numQuests) | |
206 isFirst = isFirst or self.isFirst | |
207 numQuests = numQuests or self.numQuests | |
208 | |
209 local info = self.info | |
210 | |
211 self.isFirst = isFirst | |
212 self.numQuests = numQuests | |
213 self.filterKey = info.filterKey | |
214 self.filterValue = info.filterValue | |
215 self.tagID = info.tagID | |
216 | |
217 self.icon:SetMask(filterMask) | |
218 self.icon:SetTexture(info.texture) | |
219 self.count:SetText(numQuests) | |
220 self.cVar = info.cVar | |
221 | |
222 | |
223 self.itemTexture = self.texture | |
224 | |
225 if isFirst then | |
226 self:SetPoint('TOP', self.relativeFrame, 'BOTTOM', 0, -5) | |
227 else | |
228 self:SetPoint('TOPRIGHT', self.relativeFrame, 'BOTTOMRIGHT', 0, -(3 + (self.spacing or 0))) | |
229 | |
230 end | |
231 print('anchor to', self.relativeFrame:GetName(), info.mask) | |
232 | |
233 local r, g, b, a = 1,1,1,1 | |
234 local used = WorldPlan.UsedFilters[self.filterKey] | |
235 if used and self.filterKey then | |
236 if used[self.filterValue] == true then | |
237 r, g, b = 0, 1, 0 | |
238 elseif used[self.filterValue] == false then | |
239 r, g, b = 1, 0, 0 | |
240 end | |
241 else | |
242 if self.cVar and GetCVarBool(self.cVar) then | |
243 r, g, b = 0, 1, 0 | |
244 end | |
245 end | |
246 self.iconBorder:SetVertexColor(r, g, b, a) | |
247 --self:UpdateSize() | |
248 end | |
249 | |
250 function WorldPlanFilterPinMixin:OnLoad() | |
251 self:RegisterForClicks('AnyUp') | |
252 self:SetFrameStrata('HIGH') | |
253 self:SetFrameLevel(151) | |
254 self:SetScript('OnUpdate', nil) | |
255 end | |
256 | |
257 function WorldPlanFilterPinMixin:OnUpdate () | |
258 end | |
259 | |
260 function WorldPlanFilterPinMixin:OnLeave () | |
261 if GameTooltip:IsOwned(self) then | |
262 GameTooltip:Hide() | |
263 end | |
264 end | |
265 | |
266 -- shift-click: reset filter | |
267 -- click: rotate through include(1), exclude(-1), ignore(nil) | |
268 function WorldPlanFilterPinMixin:OnClick (button) | |
269 | |
270 local filterKey = self.filterKey | |
271 local filterValue = self.filterValue | |
272 | |
273 | |
274 local operation = opPrefix | |
275 local setInclude = (button == 'LeftButton') | |
276 | |
277 | |
278 if not filterKey then | |
279 -- resetting | |
280 wipe(WorldPlan.UsedFilters) | |
281 | |
282 elseif IsShiftKeyDown() then | |
283 WorldPlan.UsedFilters[filterKey] = nil | |
284 else | |
285 WorldPlan.UsedFilters[filterKey] = WorldPlan.UsedFilters[filterKey] or {} | |
286 WorldPlan.UsedFilters[filterKey][filterValue] = setInclude | |
287 print(filterKey, filterValue, '=', setInclude) | |
288 | |
289 for index, info in ipairs(WorldPlan.FilterOptions) do | |
290 if info.filterKey == filterKey then | |
291 if (not IsControlKeyDown()) and (filterValue ~= info.filterValue) then | |
292 WorldPlan.UsedFilters[filterKey][info.filterValue] = (not setInclude) | |
293 print(filterKey, info.filterValue, '=', WorldPlan.UsedFilters[filterKey][info.filterValue]) | |
294 end | |
295 end | |
296 end | |
297 | |
298 end | |
299 print('|cFF00FF88Filter Update:', filterKey, filterValue, operation) | |
300 WorldPlan:Refresh() | |
301 end |