annotate ClassPlan.lua @ 8:802abb8a10ea

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