annotate FilterBar.lua @ 107:b2be2de2b133

live branch cleanup
author Nenue
date Sun, 28 May 2017 20:16:05 -0400
parents b29b35cb8539
children b67ba1078824
rev   line source
Nenue@30 1 -- WorldPlan
Nenue@30 2 -- FilterBar.lua
Nenue@30 3 -- Created: 10/27/2016 8:55 PM
Nenue@30 4 -- %file-revision%
Nenue@30 5 --
Nenue@40 6 local _, db = ...
Nenue@30 7 local print = DEVIAN_WORKSPACE and function(...) _G.print('FilterBar', ...) end or nop
Nenue@33 8 local wprint = DEVIAN_WORKSPACE and function(...) _G.print('WP', ...) end or function() end
Nenue@31 9 local wipe, ipairs, pairs = table.wipe, ipairs, pairs
Nenue@30 10
Nenue@30 11 local REWARD_CASH = WORLD_QUEST_REWARD_TYPE_FLAG_GOLD
Nenue@30 12 local REWARD_ARTIFACT_POWER = WORLD_QUEST_REWARD_TYPE_FLAG_ARTIFACT_POWER
Nenue@30 13 local REWARD_GEAR = WORLD_QUEST_REWARD_TYPE_FLAG_EQUIPMENT
Nenue@30 14 local REWARD_CURRENCY = WORLD_QUEST_REWARD_TYPE_FLAG_ORDER_RESOURCES
Nenue@30 15 local REWARD_REAGENT = WORLD_QUEST_REWARD_TYPE_FLAG_MATERIALS
Nenue@30 16
Nenue@30 17
Nenue@93 18 local filtersUsed
Nenue@93 19 local filterFill = "Interface\\BUTTONS\\YELLOWORANGE64"
Nenue@93 20 local filterMask = "Interface\\Minimap\\UI-Minimap-Background"
Nenue@93 21
Nenue@93 22 local HEADERS_SPACING = 3
Nenue@93 23 local BUTTONS_SPACING = 1
Nenue@93 24 local BUTTONS_HEIGHT = 20
Nenue@93 25 local TOGGLE_SIZE = 20
Nenue@95 26 local HEADERS_HEIGHT = 24
Nenue@93 27
Nenue@30 28 local LE_QUEST_TAG_TYPE_PVP = LE_QUEST_TAG_TYPE_PVP
Nenue@30 29 local LE_QUEST_TAG_TYPE_PET_BATTLE = LE_QUEST_TAG_TYPE_PET_BATTLE
Nenue@30 30 local LE_QUEST_TAG_TYPE_DUNGEON = LE_QUEST_TAG_TYPE_DUNGEON
Nenue@30 31 local LE_QUEST_TAG_TYPE_PROFESSION = LE_QUEST_TAG_TYPE_PROFESSION
Nenue@33 32
Nenue@93 33 local barMouseOver
Nenue@93 34 local filtersDirty = true
Nenue@93 35 local layoutDirty = true
Nenue@93 36 local matchesDirty -- don't flag until first filter loadout
Nenue@93 37
Nenue@33 38 local familiars = {
Nenue@33 39 [42159] = {npc = 106552, name = 'Nightwatcher Merayl'},
Nenue@33 40 [40277] = {npc = 97804, name = 'Tiffany Nelson'},
Nenue@33 41 [40298] = {npc = 99182, name = 'Sir Galveston'},
Nenue@33 42 [40282] = {npc= 99150, name = 'Grixis Tinypop'},
Nenue@33 43 [40278] = {npc = 98270, name = 'Robert Craig'},
Nenue@33 44 [48195] = {npc = 105250, name = 'Aulier'},
Nenue@33 45 [41990] = {npc = 105674, name = 'Varenne'},
Nenue@33 46 [41860] = {npc = 104970, name = 'Xorvasc'},
Nenue@33 47 [40299] = {npc = 99210, name = 'Bodhi Sunwayver'},
Nenue@33 48 [42442] = {npc = 107489, name = 'Amalia'},
Nenue@33 49 [40280] = {npc = 99077, name = 'Bredda Tenderhide'},
Nenue@33 50 [41687] = {npc = 104553, name = 'Odrogg'},
Nenue@33 51 [41944] = {npc = 105455, name = 'Trapper Jarrun'},
Nenue@33 52 [40337] = {npc = 97709, name = 'Master Tamer Flummox'},
Nenue@33 53 [40279] = {npc = 99035, name = 'Durian Strongfruit'}
Nenue@33 54 }
Nenue@33 55 local familiars_id = 9696
Nenue@33 56
Nenue@40 57 db.DefaultFilterType = {
Nenue@36 58 iconWidth = 24,
Nenue@40 59 iconHeight = 18,
Nenue@36 60 borderWidth = 3,
Nenue@36 61 highlightWidth = 2,
Nenue@30 62 TagSize = 12,
Nenue@30 63 TimeleftStage = 3,
Nenue@30 64 showNumber = true,
Nenue@30 65 numberFontObject = 'WorldPlanNumberFontThin'
Nenue@30 66 }
Nenue@93 67
Nenue@93 68 local headerNames = {
Nenue@93 69 ['rewardType'] = 'Reward Type',
Nenue@93 70 ['worldQuestType'] = 'Quest Type',
Nenue@93 71 ['isElite'] = 'Elite',
Nenue@93 72 ['factionID'] = 'Bounties'
Nenue@93 73 }
Nenue@93 74
Nenue@40 75 db.DefaultFilters = {
Nenue@30 76 { filterKey= 'rewardType', cVar = 'worldQuestFilterArtifactPower', filterValue = REWARD_ARTIFACT_POWER, label = 'Artifact Power', texture = "Interface\\ICONS\\inv_7xp_inscription_talenttome01" },
Nenue@31 77 { filterKey= 'rewardType', cVar = 'worldQuestFilterOrderResources', filterValue = REWARD_CURRENCY,label = 'Order Resources', texture = "Interface\\Icons\\inv_orderhall_orderresources" },
Nenue@30 78 { filterKey= 'rewardType', cVar = 'worldQuestFilterEquipment', filterValue = REWARD_GEAR, label = 'Equipment', texture = "Interface\\ICONS\\garrison_bluearmorupgrade" },
Nenue@30 79 { filterKey= 'rewardType', cVar = 'worldQuestFilterProfessionMaterials', filterValue = REWARD_REAGENT, label = 'Materials', texture = 1417744 },
Nenue@30 80 { filterKey= 'rewardType', cVar = 'worldQuestFilterGold', filterValue = REWARD_CASH, label = 'Gold', texture = "Interface\\Buttons\\UI-GroupLoot-Coin-Up" },
Nenue@30 81 { filterKey= 'worldQuestType', filterValue = LE_QUEST_TAG_TYPE_PVP, label = 'PvP', texture = "Interface\\Icons\\Ability_PVP_GladiatorMedallion", spacing = 10 },
Nenue@30 82 { filterKey= 'worldQuestType', filterValue = LE_QUEST_TAG_TYPE_PET_BATTLE, label = 'Pet Battle', texture = "Interface\\Icons\\PetJournalPortrait", },
Nenue@93 83 { filterKey= 'worldQuestType', filterValue = LE_QUEST_TAG_TYPE_DUNGEON, label = 'Dungeon', texture = "Interface\\LFGFRAME\\BattlenetWorking0", },
Nenue@30 84 { filterKey= 'worldQuestType', filterValue = LE_QUEST_TAG_TYPE_PROFESSION, label = 'Profession', texture = "Interface\\ICONS\\70_professions_scroll_02", },
Nenue@93 85 --{ filterKey = 'isElite', filterValue = true, label = 'Elite', texture = "", desaturated = false},
Nenue@93 86 --{ filterKey = 'isElite', filterValue = false, label = 'Not-Elite', texture = "", desaturated = false},
Nenue@30 87 }
Nenue@30 88 local defaults = {}
Nenue@30 89
Nenue@40 90 WorldPlanSummaryMixin = WorldPlanSummaryMixin or {}
Nenue@41 91 local Module = WorldPlanSummaryMixin
Nenue@41 92 Module.selectedBountyIndex = {}
Nenue@41 93 Module.bounties = {}
Nenue@41 94 Module.filterList = {}
Nenue@93 95 Module.Buttons = {}
Nenue@93 96 Module.Headers = {}
Nenue@41 97 Module.cvarFiltersDirty = false
Nenue@93 98 WorldPlanFilterButtonMixin = {}
Nenue@93 99 local Pin = WorldPlanFilterButtonMixin
Nenue@30 100
Nenue@41 101 function Module:OnLoad()
Nenue@93 102 --self:SetParent(WorldMapFrame.UIElementsFrame)
Nenue@40 103 WorldPlan:AddHandler(self)
Nenue@69 104 --[[for index, info in ipairs(db.DefaultFilters) do
Nenue@40 105 info.zone = db.DefaultFilterType
Nenue@40 106 info.continent = db.DefaultFilterType
Nenue@30 107 info.pinMask = "Interface\\Minimap\\UI-Minimap-Background"
Nenue@30 108 WorldPlan:AddTypeInfo(self,index, info)
Nenue@30 109 end
Nenue@69 110 --]]
Nenue@93 111
Nenue@93 112
Nenue@30 113 end
Nenue@30 114
Nenue@30 115
Nenue@57 116 function Module:OnEvent(event, arg)
Nenue@33 117 print('|cFF00FF88'..self:GetName()..':OnEvent()', event)
Nenue@57 118 if (event == 'QUEST_LOG_UPDATE') and arg then
Nenue@93 119 filtersDirty = true
Nenue@93 120 self:Refresh()
Nenue@57 121 end
Nenue@30 122 end
Nenue@30 123
Nenue@30 124 local bountyIndex
Nenue@30 125 local debug_headers = {}
Nenue@93 126 local ToggleButton = {}
Nenue@41 127 function Module:Setup()
Nenue@33 128 print('|cFF00FF88'..self:GetName()..':Setup()')
Nenue@45 129 self.isStale = true
Nenue@93 130 self:SetParent(WorldMapFrame.UIElementsFrame)
Nenue@93 131 --self:SetPoint('BOTTOMLEFT')
Nenue@93 132 for k,v in pairs( ToggleButton) do
Nenue@93 133 self.Toggle:SetScript(k,v)
Nenue@93 134 end
Nenue@93 135 self.Toggle:SetSize(TOGGLE_SIZE, TOGGLE_SIZE)
Nenue@93 136
Nenue@30 137 end
Nenue@30 138
Nenue@30 139
Nenue@93 140 function Module:OnUpdate(sinceLast)
Nenue@33 141 if self.isStale then
Nenue@93 142 print('|cFF00FF00pushing update')
Nenue@33 143 self:Refresh()
Nenue@33 144 end
Nenue@93 145
Nenue@93 146 barMouseOver = self:IsMouseOver()
Nenue@93 147 if barMouseOver or filtersUsed then
Nenue@93 148
Nenue@93 149 self.toAlpha = 1
Nenue@93 150 self.Backdrop:Show()
Nenue@93 151 else
Nenue@93 152 self.toAlpha = 0.25
Nenue@93 153 self.Backdrop:Hide()
Nenue@93 154 end
Nenue@93 155 local cAlpha = self:GetAlpha()
Nenue@93 156 if cAlpha ~= self.toAlpha then
Nenue@93 157 if cAlpha > self.toAlpha then
Nenue@93 158 cAlpha = cAlpha - sinceLast*4
Nenue@93 159 if cAlpha <= self.toAlpha then
Nenue@93 160 cAlpha = self.toAlpha
Nenue@93 161 end
Nenue@93 162 else
Nenue@93 163 cAlpha = cAlpha + sinceLast*4
Nenue@93 164 if cAlpha >= self.toAlpha then
Nenue@93 165 cAlpha = self.toAlpha
Nenue@93 166 end
Nenue@93 167 end
Nenue@93 168 end
Nenue@93 169 self:SetAlpha(cAlpha)
Nenue@30 170 end
Nenue@33 171
Nenue@84 172 function Module:OnMapInfo(isBrokenIsle, isZoomedOut, mapAreaID, isNewMap, isMapOpen)
Nenue@84 173 print('|cFFFFFF00OnMapInfo()', isBrokenIsle, isZoomedOut, mapAreaID, isNewMap, isMapOpen)
Nenue@41 174 if not isBrokenIsle then
Nenue@41 175 self:SetShown(false)
Nenue@41 176 else
Nenue@93 177 self:SetShown(true)
Nenue@93 178 if isMapOpen then
Nenue@84 179 self:Refresh()
Nenue@93 180 else
Nenue@93 181 matchesDirty = true
Nenue@93 182 layoutDirty = true
Nenue@84 183 end
Nenue@41 184 end
Nenue@41 185 end
Nenue@41 186
Nenue@41 187 function Module:OnShow()
Nenue@33 188 print('|cFF00FF88'..self:GetName()..':OnShow()')
Nenue@93 189 self:Refresh()
Nenue@93 190 end
Nenue@93 191
Nenue@93 192 local IsBountyCriteria = function(poiFrame, questID)
Nenue@93 193 return IsQuestCriteriaForBounty(poiFrame.questID, questID)
Nenue@93 194 end
Nenue@93 195
Nenue@93 196 local tinsert, GetQuestBountyInfoForMapID, GetQuestLogTitle, GetQuestLogIndexByID = tinsert, GetQuestBountyInfoForMapID, GetQuestLogTitle, GetQuestLogIndexByID
Nenue@93 197
Nenue@93 198 function Module:OnConfigUpdate()
Nenue@93 199
Nenue@93 200 ToggleButton.OnShow(self.Toggle)
Nenue@93 201 end
Nenue@93 202
Nenue@93 203 function Module:Reset()
Nenue@95 204
Nenue@95 205
Nenue@95 206
Nenue@93 207 self:UpdateFilters('SUMMARY_RESET')
Nenue@93 208 self:UpdateMatches('SUMMARY_RESET')
Nenue@93 209 self:UpdateLayout('SUMMARY_RESET')
Nenue@93 210 end
Nenue@93 211
Nenue@93 212 function Module:Refresh()
Nenue@93 213 self:UpdateFilters('SUMMARY_REFRESH')
Nenue@93 214 self:UpdateMatches('SUMMARY_REFRESH')
Nenue@93 215 self:UpdateLayout('SUMMARY_REFRESH')
Nenue@93 216 end
Nenue@93 217
Nenue@93 218 local questResults = {{} }
Nenue@93 219 db.FilterList = {}
Nenue@93 220
Nenue@93 221 function Module:UpdateFilters(event)
Nenue@93 222
Nenue@93 223 print('|cFF00FFFF'..self:GetName()..':GetFilters()', event)
Nenue@93 224
Nenue@93 225 wipe(db.FilterList)
Nenue@93 226
Nenue@93 227 for index, info in ipairs(db.DefaultFilters) do
Nenue@95 228 info.used = true
Nenue@93 229 tinsert(db.FilterList, info)
Nenue@93 230 end
Nenue@93 231 self.bounties = db.Bounties
Nenue@93 232 self.BountyFilters = {}
Nenue@95 233 local numBounties = 0
Nenue@93 234 for index, data in ipairs(self.bounties) do
Nenue@93 235 if not IsQuestComplete(data.questID) then
Nenue@95 236 numBounties = numBounties + 1
Nenue@93 237 local info = self.BountyFilters[index]
Nenue@93 238 if not info then
Nenue@93 239 info = {}
Nenue@93 240 self.BountyFilters[index] = info
Nenue@93 241 layoutDirty = true
Nenue@93 242 else
Nenue@93 243 if info.questID ~= data.questID then
Nenue@93 244 layoutDirty = true
Nenue@93 245 end
Nenue@93 246 end
Nenue@93 247
Nenue@93 248 local questTitle = GetQuestLogTitle(GetQuestLogIndexByID(data.questID))
Nenue@95 249 info.used = true
Nenue@93 250 info.filterKey = 'factionID'
Nenue@93 251 info.filterFunc = IsBountyCriteria
Nenue@93 252 info.filterValue = data.questID
Nenue@93 253 info.label = questTitle
Nenue@93 254 info.texture = data.icon
Nenue@93 255 print('loading emissary', questTitle)
Nenue@93 256
Nenue@93 257 tinsert(db.FilterList, info)
Nenue@93 258 --{ filterKey= 'worldQuestType', filterValue = LE_QUEST_TAG_TYPE_PROFESSION, label = 'Profession', texture = "Interface\\LFGFRAME\\UI-LFR-PORTRAIT", },
Nenue@93 259 end
Nenue@95 260 end
Nenue@93 261
Nenue@95 262 for i = numBounties + 1, #self.BountyFilters do
Nenue@95 263 self.BountyFilters[i].used = nil
Nenue@32 264 end
Nenue@95 265
Nenue@32 266 end
Nenue@30 267
Nenue@93 268 function Module:UpdateMatches(event)
Nenue@93 269 print('|cFF00FF00UpdateMatches()', event)
Nenue@93 270 local quests = db.QuestsByID
Nenue@93 271 local questsForMap = db.QuestsByZone[db.currentMapID] or quests
Nenue@30 272
Nenue@93 273 for index, info in ipairs(db.FilterList) do
Nenue@93 274 info.GlobalMatches = info.GlobalMatches or {}
Nenue@93 275 info.LocalMatches = info.LocalMatches or {}
Nenue@93 276 wipe(info.GlobalMatches)
Nenue@93 277 wipe(info.LocalMatches)
Nenue@93 278 print(info.filterKey, info.filterValue, info.filterFunc and 'func test' or 'compare')
Nenue@93 279 for questID, pin in pairs(quests) do
Nenue@93 280 print('', questID, pin.dataLoaded, (not IsQuestComplete(questID)))
Nenue@95 281 if pin.dataLoaded and (not IsQuestComplete(questID)) then
Nenue@93 282 local keyName, keyValue = info.filterKey, info.filterValue
Nenue@93 283 local isMatch
Nenue@93 284 if info.filterFunc then
Nenue@93 285 isMatch = info.filterFunc(pin, keyValue)
Nenue@93 286 print(' running special function, result =', isMatch)
Nenue@93 287 elseif pin[keyName] and (pin[keyName] == keyValue) then
Nenue@93 288 isMatch = true
Nenue@93 289 print(' rote match')
Nenue@93 290 end
Nenue@93 291 if isMatch then
Nenue@93 292 tinsert(info.GlobalMatches, pin)
Nenue@93 293 if questsForMap[questID] then
Nenue@93 294 print(' local map')
Nenue@93 295 tinsert(info.LocalMatches, pin)
Nenue@93 296 end
Nenue@93 297 end
Nenue@93 298 end
Nenue@30 299 end
Nenue@93 300 print('global', #info.GlobalMatches, 'local', #info.LocalMatches)
Nenue@30 301 end
Nenue@30 302 end
Nenue@30 303
Nenue@93 304 function Module:UpdateLayout(event)
Nenue@93 305 print('|cFF00FF88UpdateLayout()|r', event, 'currentMap=',db.currentMapID)
Nenue@30 306
Nenue@93 307 self.filtersSelected = nil
Nenue@30 308
Nenue@93 309 local currentHeader
Nenue@93 310 local relativeFrame = self
Nenue@93 311 local lastKey
Nenue@31 312
Nenue@93 313 local numHeaders = 0
Nenue@93 314 local numButtons = 0
Nenue@40 315
Nenue@93 316 local layoutWidth = TOGGLE_SIZE + HEADERS_SPACING * 2
Nenue@93 317 local headerWidth = HEADERS_SPACING
Nenue@30 318
Nenue@40 319
Nenue@40 320 local layout = db.DefaultFilterType
Nenue@36 321 local borderWidth = layout.iconWidth + (layout.borderWidth * 2)
Nenue@36 322 local highlightWidth = borderWidth + (layout.highlightWidth * 2)
Nenue@40 323 local mapQuests = db.QuestsByZone[db.currentMapID] or db.QuestsByID
Nenue@84 324 local n = 0
Nenue@84 325 for _ in pairs(mapQuests) do
Nenue@84 326 n = n + 1
Nenue@84 327 end
Nenue@84 328 print(n, 'pins to work with')
Nenue@84 329
Nenue@93 330
Nenue@93 331 filtersUsed = nil
Nenue@57 332 local firstCvar, lastCvar
Nenue@93 333 local isFirst = true
Nenue@93 334 for index, info in ipairs(db.FilterList) do
Nenue@93 335 --print('num here', numQuestsHere, numQuestsTotal)
Nenue@40 336
Nenue@30 337
Nenue@40 338 --print(tostring(index).. ' ("'..tostring(info.label)..'" f('.. tostring(info.filterKey).. '='..tostring(info.filterValue) .. '), '..tostring(numQuests)..')')
Nenue@40 339
Nenue@93 340 if #info.GlobalMatches >= 1 then
Nenue@93 341 if info.filterKey ~= lastKey then
Nenue@93 342
Nenue@93 343 numHeaders = numHeaders + 1
Nenue@93 344 local nextHeader = self.Headers[numHeaders] or CreateFrame('Frame', 'FilterHeader' .. numHeaders, self, 'WorldPlanFilterHeader')
Nenue@93 345 if currentHeader then
Nenue@93 346 nextHeader:SetPoint('TOPLEFT', currentHeader, 'TOPRIGHT', 0, 0)
Nenue@93 347
Nenue@93 348 currentHeader:SetSize(headerWidth - BUTTONS_SPACING + HEADERS_SPACING, HEADERS_HEIGHT)
Nenue@93 349 layoutWidth = layoutWidth + headerWidth
Nenue@93 350 headerWidth = HEADERS_SPACING
Nenue@93 351 else
Nenue@93 352 nextHeader:SetPoint('TOPLEFT', TOGGLE_SIZE + HEADERS_SPACING * 2, 0)
Nenue@93 353
Nenue@93 354 end
Nenue@93 355
Nenue@93 356 print(' begin header '..numHeaders, 'layout width =', floor(layoutWidth+.5))
Nenue@93 357 isFirst = true
Nenue@93 358 currentHeader = nextHeader
Nenue@93 359 currentHeader.Backdrop:SetHeight(BUTTONS_HEIGHT *2)
Nenue@93 360 currentHeader.Label:SetText(headerNames[info.filterKey])
Nenue@93 361 relativeFrame = currentHeader
Nenue@93 362 end
Nenue@93 363
Nenue@93 364 numButtons = numButtons + 1
Nenue@93 365 local button = self.Buttons[numButtons]
Nenue@93 366 if not button then
Nenue@93 367 button = CreateFrame('Button', 'FilterButton'..numButtons, self, 'WorldPlanFilterButton')
Nenue@93 368 button:SetSize(32,BUTTONS_HEIGHT)
Nenue@93 369 button.icon:SetTexCoord(0.1,.9,.1,(1 * (BUTTONS_HEIGHT/32)))
Nenue@30 370
Nenue@40 371 button.RewardBorder:ClearAllPoints()
Nenue@40 372 button.RewardBorder:SetPoint('TOPLEFT', button, 'TOPLEFT')
Nenue@40 373 button.RewardBorder:SetPoint('BOTTOMRIGHT', button, 'BOTTOMRIGHT')
Nenue@30 374 end
Nenue@30 375
Nenue@30 376 button.info = info
Nenue@93 377 button.numQuestsTotal = #info.GlobalMatches
Nenue@93 378 button.numQuestsHere = #info.LocalMatches
Nenue@93 379 button.GlobalMatches = info.GlobalMatches
Nenue@93 380 button.LocalMatches = info.LocalMatches
Nenue@93 381 button.isFirst = isFirst
Nenue@30 382 button:SetID(index)
Nenue@93 383 button:SetParent(currentHeader)
Nenue@30 384 button.relativeFrame = relativeFrame
Nenue@40 385 button:Refresh()
Nenue@30 386 button:Show()
Nenue@30 387 relativeFrame = button
Nenue@93 388 headerWidth = headerWidth + button:GetWidth() + BUTTONS_SPACING
Nenue@40 389
Nenue@93 390 isFirst = false
Nenue@40 391 if info.cVar then
Nenue@40 392 firstCvar = firstCvar or button
Nenue@40 393 lastCvar = button
Nenue@40 394 end
Nenue@93 395 lastKey = info.filterKey
Nenue@30 396 end
Nenue@30 397 end
Nenue@30 398
Nenue@30 399 self.numHeaders = numHeaders
Nenue@93 400 for i = numButtons + 1, #self.Buttons do
Nenue@93 401 if self.Buttons[i] then
Nenue@93 402 self.Buttons[i]:Hide()
Nenue@93 403 wipe(self.Buttons[i].LocalMatches)
Nenue@93 404 wipe(self.Buttons[i].GlobalMatches)
Nenue@93 405 end
Nenue@93 406 end
Nenue@93 407 for i = numHeaders + 1, #self.Headers do
Nenue@93 408 if self.Headers[i] then
Nenue@93 409 self.Headers[i]:Hide()
Nenue@31 410 end
Nenue@30 411 end
Nenue@40 412
Nenue@40 413
Nenue@93 414 if currentHeader then
Nenue@93 415 currentHeader:SetSize(headerWidth - BUTTONS_SPACING + HEADERS_SPACING, HEADERS_HEIGHT)
Nenue@93 416 layoutWidth = layoutWidth + headerWidth + HEADERS_SPACING
Nenue@93 417 end
Nenue@40 418
Nenue@95 419 self:SetSize(layoutWidth, BUTTONS_HEIGHT + (BUTTONS_SPACING * 2))
Nenue@93 420 self:ClearAllPoints()
Nenue@95 421 self:SetPoint('BOTTOM')
Nenue@32 422 self.isStale = nil
Nenue@93 423 layoutDirty = nil
Nenue@30 424 end
Nenue@30 425
Nenue@41 426 function Module:Cleanup()
Nenue@30 427 -- hide trailing buttons
Nenue@30 428 end
Nenue@30 429
Nenue@93 430 local rgbWhite = {r = 1, g= 1, b= 1, hex = '|cFFFFFFFF' }
Nenue@93 431 local found = {}
Nenue@41 432 function Pin:OnEnter()
Nenue@93 433 if #self.GlobalMatches >= 1 then
Nenue@93 434 GameTooltip:SetOwner(self, 'ANCHOR_BOTTOMRIGHT')
Nenue@31 435 GameTooltip:AddLine(self.info.label)
Nenue@93 436 wipe(found)
Nenue@93 437
Nenue@93 438 if self.numQuestsHere >= 1 then
Nenue@93 439 if self.numQuestsHere < self.numQuestsTotal then
Nenue@93 440 GameTooltip:AddLine('This Zone', 1, 1, 0)
Nenue@93 441 end
Nenue@93 442 for index, pin in ipairs(self.LocalMatches) do
Nenue@93 443 local colorInfo = (pin.quality and ITEM_QUALITY_COLORS[pin.quality]) or rgbWhite
Nenue@93 444 found[pin] = pin
Nenue@93 445 GameTooltip:AddLine('|T'.. tostring(pin.itemTexture)..':16:16|t ' .. tostring(pin.title) ..(pin.cheevos and " |cFFFFFF00!|R" or ''), 0, 1, 0)
Nenue@93 446 end
Nenue@31 447 end
Nenue@93 448
Nenue@93 449 if self.numQuestsHere < self.numQuestsTotal then
Nenue@93 450 if self.numQuestsHere >= 1 then
Nenue@93 451 GameTooltip:AddLine(' ')
Nenue@93 452 end
Nenue@93 453 GameTooltip:AddLine('Other Maps', 1, 1, 0)
Nenue@93 454 for index, pin in ipairs(self.GlobalMatches) do
Nenue@93 455 if not found[pin] then
Nenue@93 456 local colorInfo = (pin.quality and ITEM_QUALITY_COLORS[pin.quality]) or rgbWhite
Nenue@93 457 found[pin] = pin
Nenue@93 458 GameTooltip:AddLine('|T'.. tostring(pin.itemTexture)..':16:16|t ' .. tostring(pin.title) ..(pin.cheevos and " |cFFFFFF00!|R" or ''), 1, 1, 1)
Nenue@93 459 end
Nenue@93 460 end
Nenue@93 461 end
Nenue@93 462
Nenue@93 463
Nenue@40 464 GameTooltip:AddLine(self.numQuestsTotal .. ' total')
Nenue@36 465 GameTooltip:Show()
Nenue@31 466 end
Nenue@30 467 end
Nenue@30 468
Nenue@41 469 function Pin:OnLeave()
Nenue@31 470 if GameTooltip:IsOwned(self) then
Nenue@31 471 GameTooltip:Hide()
Nenue@31 472 end
Nenue@31 473 end
Nenue@30 474
Nenue@41 475 function Pin:Refresh()
Nenue@30 476 local info = self.info
Nenue@30 477 self.filterKey = info.filterKey
Nenue@30 478 self.filterValue = info.filterValue
Nenue@30 479 self.tagID = info.tagID
Nenue@30 480
Nenue@30 481 self.icon:SetTexture(info.texture)
Nenue@93 482
Nenue@93 483 if (self.numQuestsHere == 0) and (self.numQuestsTotal >= 1) then
Nenue@93 484 self.count:SetText('*'..self.numQuestsTotal)
Nenue@93 485 self.count:SetTextColor(0,1,1)
Nenue@93 486 elseif self.numQuestsHere < self.numQuestsTotal then
Nenue@93 487 self.count:SetText(self.numQuestsHere..'+')
Nenue@93 488 self.count:SetTextColor(1,1,0)
Nenue@93 489 else
Nenue@93 490 self.count:SetText(self.numQuestsHere)
Nenue@93 491 self.count:SetTextColor(1,1,1)
Nenue@93 492 end
Nenue@93 493
Nenue@30 494 self.cVar = info.cVar
Nenue@30 495 self.itemTexture = self.texture
Nenue@30 496
Nenue@45 497 self:ClearAllPoints()
Nenue@40 498 if self.isFirst then
Nenue@93 499 self:SetPoint('TOPLEFT', self.relativeFrame, 'TOPLEFT', HEADERS_SPACING, -HEADERS_SPACING)
Nenue@30 500 else
Nenue@93 501 self:SetPoint('LEFT', self.relativeFrame, 'RIGHT', BUTTONS_SPACING, 0)
Nenue@30 502 end
Nenue@93 503 --print('anchor', self.relativeFrame:IsShown(), self:GetPoint(1))
Nenue@30 504
Nenue@40 505 self.icon:SetDesaturated(self.numQuestsHere == 0)
Nenue@40 506
Nenue@40 507 local r, g, b, a = 0,0,0,1
Nenue@31 508 local desaturated = false
Nenue@93 509 if (self.numQuestsHere > 0) or db.UsedFilters[self.filterKey] then
Nenue@93 510
Nenue@40 511 if self.cVar then
Nenue@40 512 if GetCVarBool(self.cVar) then
Nenue@93 513 --self.count:SetTextColor(1,1,1)
Nenue@41 514 r,g,b,a = 0, 0, 0, 1
Nenue@31 515 else
Nenue@93 516 filtersUsed = true
Nenue@93 517 --self.count:SetTextColor(1,0,0)
Nenue@40 518 self.icon:SetDesaturated(true)
Nenue@41 519 r,g,b,a = 1, 0, 0, 0.5
Nenue@31 520 end
Nenue@31 521 else
Nenue@40 522 if db.UsedFilters[self.filterKey] then
Nenue@93 523 filtersUsed = true
Nenue@40 524 if db.UsedFilters[self.filterKey] == self.filterValue then
Nenue@93 525 --self.count:SetTextColor(0,1,0)
Nenue@41 526 r, g, b = 0, 1, 0
Nenue@40 527 else
Nenue@93 528 --self.count:SetTextColor(1,0,0)
Nenue@40 529 r, g, b = 1, 0, 0
Nenue@40 530 end
Nenue@36 531 else
Nenue@36 532
Nenue@93 533 --self.count:SetTextColor(1,1,1)
Nenue@40 534 if self.filterKey == 'worldQuestType' then
Nenue@40 535 r, g, b = 0, 0, 1
Nenue@40 536 elseif self.filterKey == 'factionID' then
Nenue@40 537 r, g, b = 1, 1, 0
Nenue@40 538 end
Nenue@36 539 end
Nenue@30 540 end
Nenue@30 541 end
Nenue@41 542 self.RewardBorder:SetColorTexture(r, g, b)
Nenue@41 543 self:SetAlpha(a)
Nenue@31 544
Nenue@30 545 --self:UpdateSize()
Nenue@30 546 end
Nenue@30 547
Nenue@41 548 function Pin:OnLoad()
Nenue@30 549 self:RegisterForClicks('AnyUp')
Nenue@30 550 self:SetFrameStrata('HIGH')
Nenue@30 551 self:SetFrameLevel(151)
Nenue@40 552 self.questList = {}
Nenue@41 553 -- WORLD_MAP_UPDATE and PLAYER_ENTERING_WORLD are passed down from a higher level
Nenue@30 554 end
Nenue@30 555
Nenue@41 556 function Pin:OnUpdate ()
Nenue@93 557 local group = self:GetParent()
Nenue@93 558 if group:IsMouseOver() and barMouseOver then
Nenue@93 559 group.Backdrop:Show()
Nenue@93 560 group.Label:Show()
Nenue@93 561 else
Nenue@93 562 group.Backdrop:Hide()
Nenue@93 563 group.Label:Hide()
Nenue@93 564 end
Nenue@30 565 end
Nenue@30 566
Nenue@30 567 -- shift-click: reset filter
Nenue@30 568 -- click: rotate through include(1), exclude(-1), ignore(nil)
Nenue@36 569 local filtered_report = {}
Nenue@40 570 local RESET_FILTER = "|cFFFFFFFF+%s|r"
Nenue@40 571 local FILTER_EXCLUDE_TYPE = '|cFFFF0000-%s|r'
Nenue@40 572 local FILTER_INCLUDE_TYPE = '|cFF00FF00+%s|r'
Nenue@41 573 function Pin:OnClick (button)
Nenue@30 574
Nenue@30 575 local filterKey = self.filterKey
Nenue@30 576 local filterValue = self.filterValue
Nenue@36 577 local cVar = self.cVar
Nenue@36 578 local parent = self:GetParent()
Nenue@40 579 local setDirty
Nenue@40 580
Nenue@40 581 print('|cFF00FF88'..self:GetName()..':OnClick()|r', filterKey, filterValue, cVar, parent)
Nenue@30 582
Nenue@36 583 local resetMode = (button == 'RightButton')
Nenue@36 584 wipe(filtered_report)
Nenue@36 585 if not (filterKey or cVar) then
Nenue@40 586 for i, info in ipairs(db.DefaultFilters) do
Nenue@33 587 if info.cVar then
Nenue@40 588 SetCVar(info.cVar, 1)
Nenue@40 589 elseif info.filterKey then
Nenue@40 590 if db.UsedFilters[info.filterKey] then
Nenue@40 591 db.UsedFilters[info.filterKey] = nil
Nenue@36 592 end
Nenue@33 593 end
Nenue@33 594 end
Nenue@40 595 parent.cvarFiltersDirty = false
Nenue@33 596
Nenue@40 597 --WorldPlan:print('All filters reset.')
Nenue@36 598 elseif cVar then
Nenue@40 599 if resetMode then
Nenue@40 600 print('|cFFFF4400cleaning dirty')
Nenue@40 601 for i, info in ipairs(db.DefaultFilters) do
Nenue@33 602 if info.cVar then
Nenue@40 603 parent.cvarFiltersDirty = false
Nenue@40 604 SetCVar(info.cVar, 1)
Nenue@33 605 end
Nenue@33 606 end
Nenue@40 607 --WorldPlan:print('Reward filters reset.')
Nenue@40 608 elseif parent.cvarFiltersDirty == true then
Nenue@40 609 if GetCVarBool(cVar) then
Nenue@40 610 tinsert(filtered_report, FILTER_EXCLUDE_TYPE:format(tostring(self.info.label)))
Nenue@40 611 SetCVar(cVar, 0)
Nenue@40 612 else
Nenue@40 613
Nenue@40 614 tinsert(filtered_report, FILTER_INCLUDE_TYPE:format(tostring(self.info.label)))
Nenue@40 615 SetCVar(cVar, 1)
Nenue@40 616 end
Nenue@40 617
Nenue@40 618 -- check the visible filters and consider it clean if they're all lit
Nenue@40 619 parent.cvarFiltersDirty = false
Nenue@93 620 for i, info in ipairs(db.FilterList) do
Nenue@93 621 if info.cVar and (#info.GlobalMatches >= 1) then
Nenue@40 622 print(info.cVar, GetCVarBool(info.cVar))
Nenue@40 623 if GetCVarBool(info.cVar) == false then
Nenue@40 624 parent.cvarFiltersDirty = true
Nenue@40 625 print('|cFFFF4400still dirty')
Nenue@40 626 break
Nenue@40 627 end
Nenue@40 628 end
Nenue@36 629 end
Nenue@36 630 else
Nenue@40 631 print('|cFFFF4400making dirty')
Nenue@40 632 for i, info in ipairs(db.DefaultFilters) do
Nenue@40 633 if info.cVar then
Nenue@40 634 local msgType = (cVar == info.cVar) and FILTER_INCLUDE_TYPE or FILTER_EXCLUDE_TYPE
Nenue@40 635 SetCVar(info.cVar, ((cVar == info.cVar) and 1) or 0)
Nenue@40 636 tinsert(filtered_report, msgType:format(info.label))
Nenue@40 637 end
Nenue@40 638 end
Nenue@40 639 parent.cvarFiltersDirty = true
Nenue@36 640 end
Nenue@30 641 else
Nenue@40 642 if resetMode then
Nenue@40 643 wipe(db.UsedFilters)
Nenue@40 644 --WorldPlan:print('Type filters reset.')
Nenue@31 645 else
Nenue@40 646 if (db.UsedFilters[filterKey] == filterValue) or resetMode then
Nenue@40 647 db.UsedFilters[filterKey] = nil
Nenue@40 648 tinsert(filtered_report, FILTER_INCLUDE_TYPE:format(tostring(filterKey)))
Nenue@40 649 else
Nenue@40 650 db.UsedFilters[filterKey] = filterValue
Nenue@40 651 tinsert(filtered_report, FILTER_EXCLUDE_TYPE:format(tostring(filterKey)))
Nenue@40 652 end
Nenue@30 653 end
Nenue@30 654 end
Nenue@40 655 if #filtered_report >= 1 then
Nenue@40 656 --WorldPlan:print('Setting filter(s):', table.concat(filtered_report, ', '))
Nenue@40 657 end
Nenue@33 658 WorldPlan:Refresh(true)
Nenue@93 659 end
Nenue@93 660 function ToggleButton:OnEnter()
Nenue@93 661
Nenue@93 662 GameTooltip:SetOwner(self, 'ANCHOR_BOTTOMRIGHT')
Nenue@93 663 GameTooltip:AddLine('Toggle Pins')
Nenue@93 664 GameTooltip:Show()
Nenue@93 665 end
Nenue@93 666 function ToggleButton:OnLeave()
Nenue@93 667
Nenue@93 668 if GameTooltip:IsOwned(self) then
Nenue@93 669 GameTooltip:Hide()
Nenue@93 670 end
Nenue@93 671 end
Nenue@93 672 function ToggleButton:OnShow()
Nenue@93 673 self:SetChecked(db.Config.EnablePins and true or false)
Nenue@93 674 end
Nenue@93 675 function ToggleButton:OnHide()
Nenue@93 676 if GameTooltip:IsOwned(self) then
Nenue@93 677 GameTooltip:Hide()
Nenue@93 678 end
Nenue@93 679
Nenue@93 680 end
Nenue@93 681 function ToggleButton:OnClick()
Nenue@93 682 --print(self:GetChecked())
Nenue@93 683 db.Config.EnablePins = self:GetChecked()
Nenue@93 684 _G.WorldPlan:OnConfigUpdate()
Nenue@30 685 end