annotate ClassPlan.lua @ 9:a2b623043970 v1.0-rc

WorldQuests: - Filter interface controls reworked: Left-Click toggles inclusive filtering, right-click toggle exclusion, and holding ctrl or shift will flip or reset the other filters of that type respectively. - Fix QuestPOI texture masks disappearing when toggling filter options * new masks aren't applied until SetTexture() is called, making a seemingly redundant call necessary for the change to manifest - Implemented configuration data storage and retrieval; tracking menu options should actually do something now. - Ignore remaining time for Profession quests that aren't part of the player's profession loadout - Alternate tooltip data appears for Pet Battle quests involved in the Family Familar achievement. A list of outstanding criteria is provided in the POI tooltip, and the quest name is highlighted in the filter tooltip. ClassPlan: - actually handle the mission complete icon
author Nenue
date Sun, 23 Oct 2016 17:18:31 -0400
parents 802abb8a10ea
children 08b03bcdfeac
rev   line source
Nenue@4 1 local wipe, tinsert, sort = table.wipe, tinsert, table.sort
Nenue@2 2 local pairs, ipairs = pairs, ipairs
Nenue@4 3 local floor, mod, time = floor, mod, time
Nenue@2 4 local GetTime = GetTime
Nenue@3 5 local GI_currentTime = time()
Nenue@3 6
Nenue@4 7 local BOUND_FRAMES = {}
Nenue@2 8 local blockTemplate = {
Nenue@2 9 point = 'TOPLEFT',
Nenue@2 10 relativePoint ='TOPLEFT',
Nenue@2 11 }
Nenue@2 12
Nenue@1 13 SLASH_CLASSPLAN1 = "/classplan"
Nenue@1 14 SLASH_CLASSPLAN2 = "/cp"
Nenue@1 15 SlashCmdList.CLASSPLAN = function(args)
Nenue@3 16 ClassOrderPlan:Toggle()
Nenue@3 17 end
Nenue@3 18
Nenue@3 19 ClassOrderPlanCore = {
Nenue@3 20 events = {},
Nenue@3 21 freeBlocks = {},
Nenue@3 22 blocks = {},
Nenue@3 23 sortedItems = {},
Nenue@3 24 timers = {},
Nenue@3 25 shipments = {},
Nenue@3 26 playerFirst = false,
Nenue@3 27 prototypes = {}
Nenue@3 28 }
Nenue@9 29
Nenue@6 30 ClassPlanMissionMixin = {
Nenue@6 31 templateName = 'ClassPlanMissionEntry',
Nenue@8 32 events = {'GARRISON_MISSION_LIST_UPDATE', 'GARRISON_MISSION_STARTED', 'GARRISON_MISSION_FINISHED', 'GARRISON_LANDINGPAGE_SHIPMENTS'},}
Nenue@3 33 ClassPlanShipmentMixin = {
Nenue@6 34 templateName = 'ClassPlanShipmentEntry',
Nenue@3 35 parent = false,
Nenue@3 36 point = 'TOPRIGHT',
Nenue@3 37 relativePoint ='TOPRIGHT',
Nenue@4 38 events = {'GARRISON_LANDINGPAGE_SHIPMENTS', 'GARRISON_TALENT_UPDATE', "GARRISON_TALENT_COMPLETE", "GARRISON_SHIPMENT_RECEIVED"},
Nenue@3 39 }
Nenue@6 40 setmetatable(ClassPlanShipmentMixin, {__index = ClassPlanMissionMixin})
Nenue@6 41 local core, MissionsHandler, ShipmentsHandler = ClassOrderPlanCore, ClassPlanMissionMixin, ClassPlanShipmentMixin
Nenue@3 42 local print = DEVIAN_WORKSPACE and function(...) print('ClassPlan', ...) end or nop
Nenue@3 43
Nenue@4 44 local GetTimeLeftString = function(timeLeft)
Nenue@4 45 local days = floor(timeLeft/(24*3600))
Nenue@4 46 local hours = floor(mod(timeLeft, (24*3600)) / 3600)
Nenue@4 47 local minutes = floor(mod(timeLeft, 3600) / 60)
Nenue@4 48 local seconds = mod(timeLeft, 60)
Nenue@4 49 if days >= 1 then
Nenue@6 50 return (days .. 'd' .. ' ') .. ((hours > 0) and (hours .. 'h') or '')
Nenue@4 51 else
Nenue@6 52 return ((hours > 0) and (hours .. 'h') or '') .. ((minutes > 0) and (' ' ..minutes .. ' min') or '')
Nenue@4 53 end
Nenue@4 54 end
Nenue@3 55
Nenue@3 56 MissionsHandler.GetPlayerData = function(self)
Nenue@3 57 if not self.profile then
Nenue@3 58 return
Nenue@3 59 end
Nenue@8 60 local items = C_Garrison.GetLandingPageItems(LE_GARRISON_TYPE_7_0)
Nenue@8 61 print(#items)
Nenue@3 62
Nenue@4 63 wipe(self.profile.missions)
Nenue@8 64 for index, data in ipairs(items) do
Nenue@4 65 print(' ',data.name, '|cFF00FF00'.. data.timeLeft .. '|r', date("%A %I:%m %p", data.missionEndTime))
Nenue@4 66 tinsert(self.profile.missions, data)
Nenue@3 67 end
Nenue@4 68 print('items update pending')
Nenue@4 69 self.isStale = true
Nenue@1 70 end
Nenue@1 71
Nenue@5 72 MissionsHandler.OnGetItem = function(data)
Nenue@5 73 if data.missionEndTime < GI_currentTime then
Nenue@5 74 data.isComplete = true
Nenue@5 75 end
Nenue@5 76 end
Nenue@5 77
Nenue@4 78 MissionsHandler.FreeBlock = function(self, block)
Nenue@4 79 end
Nenue@4 80
Nenue@3 81 MissionsHandler.SortHandler = function (a,b)
Nenue@3 82 local result = false
Nenue@4 83 --if not a or not b then
Nenue@4 84 -- return true
Nenue@4 85 --else
Nenue@4 86 --if (a.isMine ~= b.isMine) then
Nenue@4 87 -- result = a.isMine
Nenue@4 88 --else
Nenue@4 89 --if (not b.missionEndTime) or (not a.missionEndTime) then
Nenue@4 90 -- print('missing article', b.missionEndTime, a.missionEndTime)
Nenue@4 91 --end
Nenue@4 92 return ( b.missionEndTime > a.missionEndTime)
Nenue@4 93 --end
Nenue@4 94 --end
Nenue@1 95 end
Nenue@1 96
Nenue@2 97
Nenue@3 98 ShipmentsHandler.OnGetItem = function(data)
Nenue@3 99 if data.shipmentsTotal then
Nenue@3 100 local timeLeft = data.creationTime + data.duration - GI_currentTime
Nenue@3 101 if (timeLeft <= 0) and (data.shipmentsReady < data.shipmentsTotal) then
Nenue@6 102 local numOrders = min(-1*floor(timeLeft/data.duration), (data.shipmentsTotal - data.shipmentsReady))
Nenue@2 103
Nenue@6 104 if not data.originalCreationTime then
Nenue@6 105 data.originalCreationTime = data.creationTime
Nenue@6 106 data.originalShipmentsReady = data.shipmentsReady
Nenue@6 107 end
Nenue@2 108
Nenue@3 109 data.creationTime = data.creationTime + numOrders*data.duration
Nenue@3 110 data.shipmentsReady = data.shipmentsReady + numOrders
Nenue@3 111 print(data.profileKey, 'shipment "'.. data.name..'" reconciling', numOrders, 'lapsed orders. -->', data.creationTime, data.shipmentsReady)
Nenue@2 112 end
Nenue@2 113 end
Nenue@2 114 end
Nenue@2 115
Nenue@3 116 ShipmentsHandler.SortHandler = function(a, b)
Nenue@3 117 if b.isComplete ~= a.isComplete then
Nenue@3 118 return a.isComplete and true or false
Nenue@4 119 elseif a.shipmentsReady or b.shipmentsReady then
Nenue@4 120 return (a.shipmentsReady or 0) > (b.shipmentsReady or 0)
Nenue@4 121 else
Nenue@4 122 return (a.creationTime) < (b.creationTime)
Nenue@2 123 end
Nenue@2 124 end
Nenue@2 125
Nenue@6 126 local ShipmentsInfo = {}
Nenue@6 127 local AddShipmentInfo = function(shipmentType, name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, itemName, itemIcon, itemQuality, itemID, followerID)
Nenue@4 128 -- early login queries may return empty tables, causing the sorter to compare nil
Nenue@4 129 if not creationTime then
Nenue@4 130 return
Nenue@4 131 end
Nenue@8 132 --print(shipmentType, name, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString)
Nenue@6 133 tinsert(ShipmentsInfo,
Nenue@4 134 {
Nenue@4 135 shipmentType = shipmentType,
Nenue@4 136 name = name,
Nenue@4 137 icon = texture,
Nenue@4 138 shipmentCapacity = shipmentCapacity,
Nenue@4 139 shipmentsReady = shipmentsReady,
Nenue@4 140 shipmentsTotal = shipmentsTotal,
Nenue@4 141 creationTime = creationTime,
Nenue@4 142 duration = duration,
Nenue@4 143 timeleftString = timeleftString,
Nenue@4 144 itemName = itemName,
Nenue@4 145 itemIcon = itemIcon,
Nenue@4 146 itemQuality = itemQuality,
Nenue@4 147 itemID = itemID,
Nenue@4 148 followerID = followerID,
Nenue@4 149 })
Nenue@4 150 end
Nenue@3 151 ShipmentsHandler.GetPlayerData = function (self)
Nenue@2 152 if not self.profile then
Nenue@2 153 return
Nenue@2 154 end
Nenue@6 155 wipe(ShipmentsInfo)
Nenue@2 156
Nenue@2 157
Nenue@2 158 local garrisonType = LE_GARRISON_TYPE_7_0
Nenue@2 159 local buildings = C_Garrison.GetBuildings(garrisonType);
Nenue@2 160 local shipmentIndex = 0
Nenue@3 161 --print('Buildings:')
Nenue@2 162 for i = 1, #buildings do
Nenue@2 163 local name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, itemName, itemIcon, itemQuality, itemID = C_Garrison.GetLandingPageShipmentInfo(buildingID);
Nenue@6 164 AddShipmentInfo('Building', name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, itemName, itemIcon, itemQuality, itemID)
Nenue@2 165 end
Nenue@2 166
Nenue@3 167 --print('Follower:')
Nenue@2 168 local followerShipments = C_Garrison.GetFollowerShipments(garrisonType);
Nenue@2 169 for i = 1, #followerShipments do
Nenue@2 170 local name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, _, _, _, _, followerID = C_Garrison.GetLandingPageShipmentInfoByContainerID(followerShipments[i]);
Nenue@6 171 AddShipmentInfo('Follower', name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, nil, nil, nil, nil, followerID)
Nenue@2 172 end
Nenue@2 173
Nenue@3 174 --print('Loose:')
Nenue@2 175 local looseShipments = C_Garrison.GetLooseShipments(garrisonType)
Nenue@2 176 for i = 1, #looseShipments do
Nenue@2 177 local name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString = C_Garrison.GetLandingPageShipmentInfoByContainerID(looseShipments[i]);
Nenue@6 178 AddShipmentInfo('Misc', name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString)
Nenue@2 179 end
Nenue@2 180
Nenue@2 181 local talentTrees = C_Garrison.GetTalentTrees(garrisonType, select(3, UnitClass("player")));
Nenue@2 182 -- this is a talent that has completed, but has not been seen in the talent UI yet.
Nenue@2 183 local completeTalentID = C_Garrison.GetCompleteTalent(garrisonType);
Nenue@3 184 --print('Talents:')
Nenue@2 185 if (talentTrees) then
Nenue@2 186 for treeIndex, tree in ipairs(talentTrees) do
Nenue@2 187 for talentIndex, talent in ipairs(tree) do
Nenue@2 188 local showTalent = false;
Nenue@4 189 if (talent.isBeingResearched) or (talent.id == completeTalentID) then
Nenue@6 190 AddShipmentInfo('Talent', talent.name, talent.icon, 1, (talent.isBeingResearched and 0 or 1), 1, talent.researchStartTime, talent.researchDuration, talent.timeleftString)
Nenue@2 191 end
Nenue@1 192 end
Nenue@1 193 end
Nenue@2 194 end
Nenue@1 195
Nenue@2 196 self.profile.shipments = self.profile.shipments or {}
Nenue@6 197 wipe(self.profile.shipments)
Nenue@6 198 for index, data in ipairs(ShipmentsInfo) do
Nenue@6 199 --DEFAULT_CHAT_FRAME:AddMessage(data.shipmentType ..' '.. tostring(data.name) ..' '.. tostring(data.creationTime) ..' '.. tostring(data.duration))
Nenue@6 200 tinsert(self.profile.shipments, data)
Nenue@2 201 end
Nenue@6 202 self.isStale = true
Nenue@1 203
Nenue@1 204 end
Nenue@1 205
Nenue@3 206 function core:OnLoad ()
Nenue@3 207 self:RegisterEvent('PLAYER_LOGIN')
Nenue@3 208 self:RegisterEvent('ADDON_LOADED')
Nenue@3 209 self:RegisterEvent('PLAYER_REGEN_ENABLED')
Nenue@5 210 self:RegisterEvent('PLAYER_REGEN_DISABLED')
Nenue@4 211 -- Blizzard_GarrisonUI already fires a shipment data request for GARRISON_SHIPMENT_RECEIVED; this is unlikely to
Nenue@4 212
Nenue@3 213
Nenue@3 214 self:AddHandler('missions', MissionsHandler)
Nenue@3 215 self:AddHandler('shipments', ShipmentsHandler)
Nenue@4 216
Nenue@4 217
Nenue@4 218 self:Reanchor()
Nenue@4 219 end
Nenue@4 220 local parentFrames = {'VeneerWorldState', 'OrderHallCommandBar'}
Nenue@4 221 function core:Reanchor()
Nenue@4 222
Nenue@4 223
Nenue@4 224 self:ClearAllPoints()
Nenue@4 225
Nenue@5 226 local anchorTo = 'TOP'
Nenue@4 227 self.anchorParent = UIParent
Nenue@4 228 for i, name in ipairs(parentFrames) do
Nenue@4 229 local frame = _G[name]
Nenue@4 230 if frame then
Nenue@4 231 if not BOUND_FRAMES[frame] then
Nenue@5 232 BOUND_FRAMES[frame] = {visible = (frame:IsVisible() and frame:IsShown())}
Nenue@4 233 hooksecurefunc(frame, 'Show', function()
Nenue@4 234 BOUND_FRAMES[frame].visible = true
Nenue@4 235 print(frame:GetName(), 'Show', 'reanchor trigger')
Nenue@4 236 self:Reanchor()
Nenue@4 237 end)
Nenue@4 238 hooksecurefunc(frame, 'Hide', function()
Nenue@5 239 BOUND_FRAMES[frame].visible = nil
Nenue@4 240 print(frame:GetName(), 'Hide', 'reanchor trigger')
Nenue@4 241 self:Reanchor()
Nenue@4 242 end)
Nenue@4 243 end
Nenue@5 244 print('f:', frame:GetName(), BOUND_FRAMES[frame].visible)
Nenue@4 245 if BOUND_FRAMES[frame].visible then
Nenue@4 246 self.anchorParent = frame
Nenue@5 247 anchorTo = 'BOTTOM'
Nenue@4 248 break
Nenue@4 249 end
Nenue@4 250 end
Nenue@4 251 end
Nenue@5 252 print('|cFFFF8800Using ' .. tostring(self.anchorParent:GetName()) .. '-'..anchorTo..' as anchor point')
Nenue@4 253
Nenue@5 254 if self:IsShown() then
Nenue@4 255 ClassPlanButton.Background:Show()
Nenue@4 256 ClassPlanButton:SetWidth(600)
Nenue@4 257 else
Nenue@4 258 ClassPlanButton.Background:Hide()
Nenue@4 259 ClassPlanButton:SetWidth(200)
Nenue@4 260 end
Nenue@4 261
Nenue@5 262 self:SetPoint('TOP', ClassPlanButton, 'BOTTOM', 0, 0)
Nenue@5 263 ClassPlanButton:ClearAllPoints()
Nenue@5 264 ClassPlanButton:SetPoint('TOP', self.anchorParent, anchorTo, 0, 0)
Nenue@4 265
Nenue@5 266 print(ClassPlanButton:GetPoint(1))
Nenue@3 267 end
Nenue@3 268
Nenue@3 269 function core:AddHandler(name, prototype)
Nenue@3 270 self.prototypes[name] = setmetatable(prototype, {
Nenue@3 271 __index = blockTemplate,
Nenue@3 272 __tostring = function() return name end
Nenue@3 273 })
Nenue@3 274
Nenue@3 275 for i, event in ipairs(prototype.events) do
Nenue@3 276 if not self.events[event] then
Nenue@3 277 self:RegisterEvent(event)
Nenue@3 278 self.events[event] = {}
Nenue@3 279 print('|cFF00FF00registering', event)
Nenue@3 280 end
Nenue@3 281
Nenue@3 282 prototype.numBlocks = 0
Nenue@3 283 if not self.events[event][name] then
Nenue@3 284 print('adding', name, 'to', event)
Nenue@3 285 self.events[event][name] = prototype.GetPlayerData
Nenue@3 286 end
Nenue@1 287 end
Nenue@3 288 self.sortedItems[name] = {}
Nenue@3 289 end
Nenue@1 290
Nenue@4 291 function core:Setup()
Nenue@4 292 if IsLoggedIn() then
Nenue@4 293 WorldPlanData.OrderHall = WorldPlanData.OrderHall or {}
Nenue@4 294 self.data = WorldPlanData.OrderHall
Nenue@4 295 self.data.characters = self.data.characters or {}
Nenue@4 296
Nenue@4 297 local name, realm = UnitName('player')
Nenue@4 298 realm = realm or GetRealmName()
Nenue@4 299 self.profileKey = name .. '-' .. realm
Nenue@4 300 if not self.data.characters[self.profileKey] then
Nenue@4 301 self.data.characters[self.profileKey] = {}
Nenue@4 302 end
Nenue@4 303 self.profile = self.data.characters[self.profileKey]
Nenue@4 304
Nenue@4 305 self.profile.shipments = self.profile.shipments or {}
Nenue@4 306 self.profile.missions = self.profile.missions or {}
Nenue@4 307 self.profile.classColor = RAID_CLASS_COLORS[select(2, UnitClass('player'))]
Nenue@4 308
Nenue@4 309 if self.data.IsShown then
Nenue@4 310 self:Show()
Nenue@4 311 end
Nenue@4 312 self.initialized = true
Nenue@4 313 end
Nenue@4 314 end
Nenue@4 315
Nenue@3 316 function core:OnEvent (event, ...)
Nenue@3 317 print(event)
Nenue@5 318 if event == 'PLAYER_REGEN_DISABLED' then
Nenue@6 319 if self:IsVisible() then
Nenue@6 320 self.combatHide = true
Nenue@6 321 self:SetShown(false)
Nenue@6 322 end
Nenue@6 323
Nenue@5 324 elseif event == 'PLAYER_REGEN_ENABLED' then
Nenue@6 325 if self.combatHide == true then
Nenue@6 326 self.combatHide = nil
Nenue@6 327 self:SetShown(true)
Nenue@6 328 end
Nenue@3 329 elseif event == 'PLAYER_LOGIN' then
Nenue@3 330 if not self.initialized then
Nenue@4 331 self:Setup()
Nenue@1 332 end
Nenue@4 333 elseif self.initialized and self.events[event] then
Nenue@4 334 local numCalls = 0
Nenue@3 335 for ptype, eventFunc in pairs(self.events[event]) do
Nenue@4 336 numCalls = numCalls + 1
Nenue@4 337 print('|cFF88FF00' .. tostring(ptype) .. '|r:GetPlayerData() --', numCalls)
Nenue@3 338 eventFunc(self, event)
Nenue@3 339 end
Nenue@8 340
Nenue@8 341
Nenue@8 342 if self:IsVisible() then
Nenue@8 343 self:Refresh()
Nenue@8 344 end
Nenue@2 345 end
Nenue@2 346 end
Nenue@2 347
Nenue@3 348 function core:UpdateNotifications()
Nenue@3 349 end
Nenue@3 350
Nenue@4 351
Nenue@4 352 local SetOwnerData = function(self, data)
Nenue@4 353 local name, realm = string.match(data.profileKey, "(.+)%-(.+)")
Nenue@4 354 local ownerText = '|c'.. data.classColor.colorStr .. name .. '|r'
Nenue@5 355 --if realm ~= GI_currentRealm then
Nenue@5 356 --ownerText = ownerText .. ' (' .. realm .. ')'
Nenue@5 357 --end
Nenue@5 358 self.Owner:SetText(ownerText)
Nenue@5 359 self.Name:SetTextColor(data.classColor.r, data.classColor.g, data.classColor.b)
Nenue@5 360
Nenue@5 361 if self.isComplete then
Nenue@5 362 self.TimeLeft:SetText('Complete!')
Nenue@5 363 self.Background:SetColorTexture(.25,.25,.25,1)
Nenue@5 364 else
Nenue@5 365 self.Background:SetColorTexture(0,0,0,0.5)
Nenue@4 366 end
Nenue@5 367
Nenue@4 368 end
Nenue@4 369
Nenue@3 370 function core:RefreshItems(configKey, prototype)
Nenue@3 371 local sortedItems = self.sortedItems[configKey]
Nenue@3 372
Nenue@3 373 self.blocks[configKey] = self.blocks[configKey] or {}
Nenue@3 374 local blocks = self.blocks[configKey]
Nenue@3 375
Nenue@3 376 local lastProfile
Nenue@3 377 local numItems = #sortedItems
Nenue@3 378 local totalHeight = 0
Nenue@3 379 for i, data in ipairs(sortedItems) do
Nenue@3 380 local block = blocks[i]
Nenue@3 381
Nenue@3 382 if not block then
Nenue@3 383 block = CreateFrame('Button', nil, self, prototype.templateName)
Nenue@3 384 block:SetID(i)
Nenue@4 385 block.handler = prototype
Nenue@3 386 prototype.numBlocks = prototype.numBlocks + 1
Nenue@3 387
Nenue@3 388 if prototype.lastBlock then
Nenue@3 389 block:SetPoint('TOPLEFT', prototype.lastBlock, 'BOTTOMLEFT', 0, 0)
Nenue@3 390 else
Nenue@3 391 block:SetPoint(prototype.point, self[prototype.parent] or self, prototype.relativePoint, 0, 0)
Nenue@3 392 end
Nenue@3 393 prototype.lastBlock = block
Nenue@3 394 blocks[i] = block
Nenue@3 395 end
Nenue@3 396
Nenue@3 397 totalHeight = totalHeight + block:GetHeight()
Nenue@3 398 block.lastProfile = lastProfile
Nenue@4 399 for k,v in pairs(data) do
Nenue@4 400 if type(block[k]) ~= 'function' then
Nenue@4 401 block[k] = v
Nenue@4 402 end
Nenue@4 403 end
Nenue@3 404 block:Refresh(data)
Nenue@5 405 print(block.isComplete, block.missionEndTime, block.name)
Nenue@4 406 SetOwnerData(block, data)
Nenue@4 407
Nenue@3 408 block:Show()
Nenue@3 409 lastProfile = data.profileKey
Nenue@3 410 end
Nenue@3 411
Nenue@3 412 for i = numItems + 1, prototype.numBlocks do
Nenue@3 413 if blocks[i] then
Nenue@3 414 blocks[i]:Hide()
Nenue@3 415 end
Nenue@3 416 end
Nenue@3 417
Nenue@3 418 return totalHeight
Nenue@3 419 end
Nenue@3 420 local max = math.max
Nenue@3 421 function core:Refresh()
Nenue@3 422 if self.isStale then
Nenue@3 423 self:SortItems()
Nenue@3 424 end
Nenue@3 425 self.isStale = nil
Nenue@3 426
Nenue@3 427 self.currentHeight = 0
Nenue@3 428 for name, info in pairs(self.prototypes) do
Nenue@3 429 local itemsHeight = self:RefreshItems(name, info)
Nenue@3 430 self.currentHeight = max(itemsHeight, self.currentHeight)
Nenue@3 431 end
Nenue@3 432
Nenue@4 433 self:Reanchor()
Nenue@3 434 self:SetHeight(self.currentHeight)
Nenue@3 435 end
Nenue@3 436
Nenue@3 437 function core:Toggle()
Nenue@5 438 if self:IsShown() then
Nenue@3 439 self:Hide()
Nenue@3 440 else
Nenue@3 441 self:Show()
Nenue@3 442 end
Nenue@3 443
Nenue@3 444 if self.data then
Nenue@5 445 self.data.IsShown = self:IsShown()
Nenue@3 446 end
Nenue@3 447 end
Nenue@3 448
Nenue@3 449 function core:OnUpdate()
Nenue@3 450 if self.fadeTimer and self.fadeTimer < GetTime() then
Nenue@3 451 self:Hide()
Nenue@3 452 end
Nenue@3 453 end
Nenue@3 454
Nenue@3 455 function core:OnShow()
Nenue@3 456 if self.isStale then
Nenue@3 457 print('updating items on show')
Nenue@3 458 self:Refresh()
Nenue@3 459 end
Nenue@4 460 -- grab this at least once
Nenue@4 461 C_Garrison.RequestLandingPageShipmentInfo();
Nenue@4 462 ClassPlanButton.Background:Show()
Nenue@4 463 ClassPlanButton.Grip:SetShown(true)
Nenue@3 464 end
Nenue@3 465 function core:OnHide()
Nenue@4 466 ClassPlanButton.Background:Hide()
Nenue@4 467 ClassPlanButton.Grip:SetShown(false)
Nenue@3 468 end
Nenue@3 469
Nenue@3 470 local GI_profileKey, GI_profile, GI_isMine
Nenue@4 471 local defaultClassColor = {r = 0.7, g = 0.7, b =0.7, colorStr = "ffffffff"}
Nenue@4 472 local DoItemList = function (source, dest, onGetItem)
Nenue@3 473 if not source then
Nenue@3 474 return
Nenue@3 475 end
Nenue@3 476 local numItems = 0
Nenue@3 477 for index, data in ipairs(source) do
Nenue@4 478 data.classColor = GI_profile.classColor or defaultClassColor
Nenue@3 479 data.profileKey = GI_profileKey
Nenue@3 480 data.isMine = GI_isMine
Nenue@3 481 if onGetItem then
Nenue@3 482 onGetItem(data)
Nenue@3 483 end
Nenue@3 484 numItems = numItems + 1
Nenue@3 485 tinsert(dest, data)
Nenue@3 486 end
Nenue@3 487 return numItems
Nenue@3 488 end
Nenue@3 489
Nenue@3 490 function core:SortItems()
Nenue@3 491 print('|cFF0088FFSortItems()|r')
Nenue@3 492 GI_currentTime = time()
Nenue@3 493
Nenue@3 494 for key, sortedItems in pairs(self.sortedItems) do
Nenue@3 495 wipe(sortedItems)
Nenue@3 496 local ptype = self.prototypes[key]
Nenue@4 497 --print( 'object:', ptype)
Nenue@3 498 for name, profile in pairs(self.data.characters) do
Nenue@3 499 GI_profileKey = name
Nenue@3 500 GI_profile = profile
Nenue@3 501 GI_isMine = (profile == self.profile)
Nenue@4 502 local results = DoItemList(profile[key], sortedItems, ptype.OnGetItem)
Nenue@4 503 --print(' - ', name, results, 'items')
Nenue@3 504 end
Nenue@3 505
Nenue@3 506 if ptype.SortHandler then
Nenue@4 507 sort(sortedItems, ptype.SortHandler)
Nenue@3 508 end
Nenue@3 509 end
Nenue@3 510 end
Nenue@3 511
Nenue@3 512 function MissionsHandler:OnComplete()
Nenue@5 513 print('flagging complete', self.name)
Nenue@2 514 self:Refresh()
Nenue@2 515 end
Nenue@2 516
Nenue@6 517 function MissionsHandler:OnUpdate(sinceLast)
Nenue@4 518 if self.isComplete then
Nenue@2 519 return
Nenue@2 520 end
Nenue@6 521 self.throttle = (self.throttle or .5) + sinceLast
Nenue@6 522 if self.throttle >= .5 then
Nenue@6 523 self.throttle = self.throttle - .5
Nenue@6 524 else
Nenue@6 525 return
Nenue@6 526 end
Nenue@6 527
Nenue@2 528
Nenue@1 529 if self.missionEndTime then
Nenue@1 530 local timeLeft = self.missionEndTime - time()
Nenue@1 531 if timeLeft < 0 then
Nenue@2 532 self:OnComplete()
Nenue@1 533 else
Nenue@2 534 self.TimeLeft:SetText(GetTimeLeftString(timeLeft))
Nenue@2 535
Nenue@2 536 if timeLeft > 3600 then
Nenue@2 537 self.TimeLeft:SetTextColor(1,1,1)
Nenue@2 538 else
Nenue@2 539 self.TimeLeft:SetTextColor(1,1,0)
Nenue@2 540 end
Nenue@6 541 end
Nenue@2 542
Nenue@6 543 if not self.isComplete then
Nenue@6 544 local progress = (self.missionEndTime - time()) / self.durationSeconds
Nenue@6 545 local w = self.ProgressBG:GetWidth()
Nenue@6 546 if progress >= 1 then
Nenue@6 547 self.ProgressBar:SetWidth(w)
Nenue@6 548 else
Nenue@6 549 self.ProgressBar:SetWidth(w - (progress * w))
Nenue@6 550 end
Nenue@6 551
Nenue@6 552 self.ProgressBG:Show()
Nenue@6 553 self.ProgressBar:Show()
Nenue@6 554 else
Nenue@6 555 self.ProgressBG:Hide()
Nenue@6 556 self.ProgressBar:Hide()
Nenue@1 557 end
Nenue@6 558
Nenue@1 559 else
Nenue@1 560 self.TimeLeft:SetText(self.missionEndTime)
Nenue@1 561 end
Nenue@2 562 end
Nenue@2 563
Nenue@4 564 function MissionsHandler:Refresh()
Nenue@2 565
Nenue@3 566
Nenue@2 567 local r,g,b = 1, 1, 1
Nenue@4 568 if self.isRare then
Nenue@2 569 r,g,b = 0.1, 0.4, 1
Nenue@5 570 self.IconBorder:SetVertexColor(r, g, b, 1)
Nenue@2 571 end
Nenue@2 572
Nenue@2 573
Nenue@2 574 --self.missionData = data
Nenue@5 575 self.Name:SetText(self.name)
Nenue@2 576
Nenue@4 577 if #self.rewards >= 1 then
Nenue@4 578 self.Icon:SetTexture(self.rewards[1].icon or GetItemIcon(self.rewards[1].itemID))
Nenue@4 579 self.rewardInfo = self.rewards[1]
Nenue@2 580 else
Nenue@4 581 self.Icon:SetAtlas(self.typeAtlas, false)
Nenue@2 582 end
Nenue@6 583
Nenue@9 584 if self.isComplete then
Nenue@9 585 self.Done:Show()
Nenue@9 586 else
Nenue@9 587 self.Done:Hide()
Nenue@9 588 end
Nenue@6 589
Nenue@2 590 end
Nenue@2 591
Nenue@2 592
Nenue@3 593 function MissionsHandler:OnEnter()
Nenue@2 594 if self.rewardInfo and self.rewardInfo.itemID then
Nenue@2 595 GameTooltip:SetOwner(self, 'ANCHOR_LEFT')
Nenue@2 596 GameTooltip:SetItemByID(self.rewardInfo.itemID)
Nenue@2 597 GameTooltip:Show()
Nenue@2 598 end
Nenue@2 599 end
Nenue@3 600 function MissionsHandler:OnLeave()
Nenue@2 601 if GameTooltip:IsOwned(self) then
Nenue@2 602 GameTooltip:Hide()
Nenue@2 603 end
Nenue@2 604 end
Nenue@2 605
Nenue@2 606
Nenue@2 607
Nenue@4 608 function ShipmentsHandler:Refresh()
Nenue@3 609
Nenue@3 610 --[[
Nenue@3 611 self.icon = data.icon
Nenue@3 612 self.shipmentCapacity = data.shipmentCapacity
Nenue@3 613 self.shipmentsReady = data.shipmentsReady
Nenue@3 614 self.shipmentsTotal = data.shipmentsTotal
Nenue@3 615 self.creationTime = data.creationTime
Nenue@3 616 self.duration = data.duration
Nenue@3 617 self.itemID = data.itemID
Nenue@3 618 self.itemQuality = data.itemQuality
Nenue@3 619 icon = texture,
Nenue@3 620 shipmentCapacity = shipmentCapacity,
Nenue@3 621 shipmentsReady = shipmentsReady,
Nenue@3 622 shipmentsTotal = shipmentsTotal,
Nenue@3 623 creationTime = creationTime,
Nenue@3 624 duration = duration,
Nenue@3 625 timeleftString = timeleftString,
Nenue@3 626 itemName = itemName,
Nenue@3 627 itemIcon = itemIcon,
Nenue@3 628 itemQuality = itemQuality,
Nenue@3 629 itemID = itemID
Nenue@3 630
Nenue@3 631 --]]
Nenue@3 632
Nenue@4 633 self.Icon:SetTexture(self.icon)
Nenue@2 634
Nenue@4 635 self.Name:SetText(self.name)
Nenue@4 636 self.Count:SetText(self.shipmentsReady)
Nenue@4 637 self.Done:SetShown(self.shipmentsReady and (self.shipmentsReady >= 1))
Nenue@2 638
Nenue@3 639
Nenue@3 640 -- flag as complete
Nenue@6 641 if ( self.shipmentsReady >= self.shipmentsTotal ) and (not self.isBeingResearched) then
Nenue@2 642 self.Swipe:SetCooldownUNIX(0, 0);
Nenue@2 643 self.Done:Show();
Nenue@4 644 self.isComplete = true
Nenue@2 645 else
Nenue@4 646 self.Swipe:SetCooldownUNIX(self.creationTime or 0 , self.duration or 0);
Nenue@2 647 end
Nenue@2 648
Nenue@4 649 local hasPickups = (self.isComplete or (self.shipmentsTotal and (self.shipmentsReady > 0)))
Nenue@4 650 self.Background:SetAlpha(hasPickups and 1 or 0.1)
Nenue@4 651 end
Nenue@4 652 local time = time
Nenue@4 653 function ShipmentsHandler:OnUpdate()
Nenue@2 654
Nenue@6 655 if (self.shipmentsReady and self.shipmentsTotal) and (self.shipmentsReady < self.shipmentsTotal) then
Nenue@4 656 local timeLeft = self.creationTime + self.duration - time()
Nenue@6 657 if self.shipmentsReady >= 1 then
Nenue@6 658 self.TimeLeft:SetText(GetTimeLeftString(timeLeft))
Nenue@6 659 self.TimeLeft:SetTextColor(0,1,0)
Nenue@6 660 else
Nenue@6 661 self.TimeLeft:SetText(GetTimeLeftString(timeLeft))
Nenue@6 662 self.TimeLeft:SetTextColor(1,1,1)
Nenue@6 663 end
Nenue@6 664 if (timeLeft < 0) then
Nenue@6 665 if self.shipmentsReady < self.shipmentsTotal then
Nenue@6 666 self.shipmentsReady = self.shipmentsReady + 1
Nenue@6 667 self.creationTime = self.creationTime + self.duration
Nenue@6 668 -- text will be set on next update
Nenue@6 669 end
Nenue@6 670 end
Nenue@6 671
Nenue@4 672 elseif self.isBeingResearched then
Nenue@4 673 self.TimeLeft:SetText(GetTimeLeftString(self.researchStartTime + self.researchDuration - time()))
Nenue@6 674 self.TimeLeft:SetTextColor(1,1,0)
Nenue@2 675 else
Nenue@2 676 self.TimeLeft:SetText('Complete!')
Nenue@6 677 self.TimeLeft:SetTextColor(0,1,0)
Nenue@2 678 end
Nenue@2 679
Nenue@2 680 end
Nenue@2 681
Nenue@3 682 function ShipmentsHandler:OnEnter()
Nenue@4 683
Nenue@4 684 if ( self.shipmentsReady and self.shipmentsTotal ) then
Nenue@2 685 GameTooltip:SetOwner(self, 'ANCHOR_LEFT')
Nenue@4 686
Nenue@4 687 GameTooltip:AddLine(self.Owner:GetText(), self.Owner:GetTextColor())
Nenue@4 688 GameTooltip:AddLine(self.shipmentType)
Nenue@4 689 GameTooltip:AddLine(self.shipmentsReady .. ' of '.. self.shipmentsTotal)
Nenue@2 690 GameTooltip:Show()
Nenue@2 691 end
Nenue@2 692 end
Nenue@2 693
Nenue@3 694 function ShipmentsHandler:OnLeave()
Nenue@2 695 if GameTooltip:IsOwned(self) then
Nenue@2 696 GameTooltip:Hide()
Nenue@2 697 end
Nenue@2 698 end
Nenue@2 699
Nenue@3 700 function ShipmentsHandler:OnClick(button)
Nenue@3 701 if button == 'RightButton' then
Nenue@4 702 self.handler:FreeBlock(self)
Nenue@3 703 end
Nenue@1 704 end