annotate ClassPlan.lua @ 6:48001b6a9496

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