comparison ClassPlan.lua @ 23:e49efad51698 v1.0-rc7

* Run data scooping operations from the main Refresh block
author Nenue
date Mon, 24 Oct 2016 23:17:42 -0400
parents 6016ec3c8adf
children 4a7e89bffbcb
comparison
equal deleted inserted replaced
22:b3835b6b61f7 23:e49efad51698
52 else 52 else
53 return ((hours > 0) and (hours .. 'h') or '') .. ((minutes > 0) and (' ' ..minutes .. ' min') or '') 53 return ((hours > 0) and (hours .. 'h') or '') .. ((minutes > 0) and (' ' ..minutes .. ' min') or '')
54 end 54 end
55 end 55 end
56 56
57
58
57 MissionsHandler.GetPlayerData = function(self) 59 MissionsHandler.GetPlayerData = function(self)
58 if not self.profile then 60 if not self.profile then
59 return 61 return
60 end 62 end
61 local items = C_Garrison.GetLandingPageItems(LE_GARRISON_TYPE_7_0) 63 local items = C_Garrison.GetLandingPageItems(LE_GARRISON_TYPE_7_0)
62 print(#items)
63
64 wipe(self.profile.missions) 64 wipe(self.profile.missions)
65 for index, data in ipairs(items) do 65 for index, data in ipairs(items) do
66 print(' ',data.name, '|cFF00FF00'.. data.timeLeft .. '|r', date("%A %I:%m %p", data.missionEndTime)) 66 print(' -',data.name, '|cFF00FF00'.. data.timeLeft .. '|r', date("%A %I:%m %p", data.missionEndTime))
67 tinsert(self.profile.missions, data) 67 tinsert(self.profile.missions, data)
68 end 68 end
69 print('items update pending') 69 ClassOrderPlan.isStale = true
70 self.isStale = true
71 end 70 end
72 71
73 MissionsHandler.OnGetItem = function(data) 72 MissionsHandler.OnGetItem = function(data)
74 if data.missionEndTime < GI_currentTime then 73 if data.missionEndTime < GI_currentTime then
75 data.isComplete = true 74 data.isComplete = true
196 wipe(self.profile.shipments) 195 wipe(self.profile.shipments)
197 for index, data in ipairs(ShipmentsInfo) do 196 for index, data in ipairs(ShipmentsInfo) do
198 --DEFAULT_CHAT_FRAME:AddMessage(data.shipmentType ..' '.. tostring(data.name) ..' '.. tostring(data.creationTime) ..' '.. tostring(data.duration)) 197 --DEFAULT_CHAT_FRAME:AddMessage(data.shipmentType ..' '.. tostring(data.name) ..' '.. tostring(data.creationTime) ..' '.. tostring(data.duration))
199 tinsert(self.profile.shipments, data) 198 tinsert(self.profile.shipments, data)
200 end 199 end
201 self.isStale = true 200 ClassOrderPlan.isStale = true
202 end 201 end
203 202
204 function core:OnLoad () 203 function core:OnLoad ()
205 self:RegisterEvent('PLAYER_LOGIN') 204 self:RegisterEvent('PLAYER_LOGIN')
206 self:RegisterEvent('ADDON_LOADED') 205 self:RegisterEvent('ADDON_LOADED')
208 self:RegisterEvent('PLAYER_REGEN_DISABLED') 207 self:RegisterEvent('PLAYER_REGEN_DISABLED')
209 -- Blizzard_GarrisonUI already fires a shipment data request for GARRISON_SHIPMENT_RECEIVED; this is unlikely to 208 -- Blizzard_GarrisonUI already fires a shipment data request for GARRISON_SHIPMENT_RECEIVED; this is unlikely to
210 self:AddHandler('missions', MissionsHandler) 209 self:AddHandler('missions', MissionsHandler)
211 self:AddHandler('shipments', ShipmentsHandler) 210 self:AddHandler('shipments', ShipmentsHandler)
212 self:Reanchor() 211 self:Reanchor()
212 C_Garrison.RequestLandingPageShipmentInfo();
213 end 213 end
214 214
215 local parentFrames = {'VeneerWorldState', 'OrderHallCommandBar'} 215 local parentFrames = {'VeneerWorldState', 'OrderHallCommandBar'}
216 function core:Reanchor() 216 function core:Reanchor()
217 self:ClearAllPoints() 217 self:ClearAllPoints()
300 300
301 if self.data.IsShown then 301 if self.data.IsShown then
302 self:Show() 302 self:Show()
303 end 303 end
304 self.initialized = true 304 self.initialized = true
305 self.isStale = true
305 end 306 end
306 end 307 end
307 308
308 local last_invoc = {} 309 local last_invoc = {}
309 function core:OnEvent (event, ...) 310 function core:OnEvent (event, ...)
403 end 404 end
404 end 405 end
405 406
406 return totalHeight 407 return totalHeight
407 end 408 end
408 local max = math.max 409
409 function core:Refresh()
410 if self.isStale then
411 self:SortItems()
412 end
413 self.isStale = nil
414
415 self.currentHeight = 0
416 for name, info in pairs(self.prototypes) do
417 local itemsHeight = self:RefreshItems(name, info)
418 self.currentHeight = max(itemsHeight, self.currentHeight)
419 end
420
421 self:Reanchor()
422 self:SetHeight(self.currentHeight)
423 end
424
425 function core:Toggle()
426 if self:IsShown() then
427 self:Hide()
428 else
429 self:Show()
430 end
431
432 if self.data then
433 self.data.IsShown = self:IsShown()
434 end
435 end
436
437 function core:OnUpdate()
438 if self.fadeTimer and self.fadeTimer < GetTime() then
439 self:Hide()
440 end
441
442 if self.isStale then
443 print('updating items on show')
444 self:Refresh()
445 end
446 end
447
448 function core:OnShow()
449 if self.isStale then
450 print('updating items on show')
451 self:Refresh()
452 end
453 -- grab this at least once
454 C_Garrison.RequestLandingPageShipmentInfo();
455 ClassPlanButton.Background:Show()
456 ClassPlanButton.Grip:SetShown(true)
457 end
458 function core:OnHide()
459 ClassPlanButton.Background:Hide()
460 ClassPlanButton.Grip:SetShown(false)
461 end
462 410
463 local GI_profileKey, GI_profile, GI_isMine 411 local GI_profileKey, GI_profile, GI_isMine
464 local defaultClassColor = {r = 0.7, g = 0.7, b =0.7, colorStr = "ffffffff"} 412 local defaultClassColor = {r = 0.7, g = 0.7, b =0.7, colorStr = "ffffffff"}
465 local DoItemList = function (source, dest, onGetItem) 413 local DoItemList = function (source, dest, onGetItem)
466 if not source then
467 return
468 end
469 local numItems = 0 414 local numItems = 0
470 for index, data in ipairs(source) do 415 for index, data in ipairs(source) do
471 data.classColor = GI_profile.classColor or defaultClassColor 416 data.classColor = GI_profile.classColor or defaultClassColor
472 data.profileKey = GI_profileKey 417 data.profileKey = GI_profileKey
473 data.isMine = GI_isMine 418 data.isMine = GI_isMine
478 tinsert(dest, data) 423 tinsert(dest, data)
479 end 424 end
480 return numItems 425 return numItems
481 end 426 end
482 427
483 function core:SortItems() 428 local max = math.max
484 print('|cFF0088FFSortItems()|r') 429 function core:Refresh()
430 print('|cFF00FFFFRefresh()|r')
431 self.currentHeight = 0
432 for name, ptype in pairs(self.prototypes) do
433 print(' |cFF00FF00'..name..'|r')
434 if self.isStale then
435 ptype.GetPlayerData(self)
436 self.sortedItems[name] = self.sortedItems[name] or {}
437
438 wipe(self.sortedItems[name])
439 --print( 'object:', ptype)
440 for key, profile in pairs(self.data.characters) do
441 if profile[name] and #profile[name] >= 1 then
442 print(' ', #profile[name], key)
443 GI_profileKey = key
444 GI_profile = profile
445 GI_isMine = (profile == self.profile)
446 local results = DoItemList(profile[name], self.sortedItems[name], ptype.OnGetItem)
447 end
448
449 end
450
451 if ptype.SortHandler then
452 sort(self.sortedItems[name], ptype.SortHandler)
453 end
454 end
455
456 local itemsHeight = self:RefreshItems(name, ptype)
457 self.currentHeight = max(itemsHeight, self.currentHeight)
458 end
459
460 self:Reanchor()
461 self:SetHeight(self.currentHeight)
462 self.isStale = nil
463 end
464
465 function core:Toggle()
466 if self:IsShown() then
467 self:Hide()
468 else
469 self:Show()
470 end
471
472 if self.data then
473 self.data.IsShown = self:IsShown()
474 end
475 end
476
477 function core:OnUpdate()
478 if self.isStale then
479 print('update requested internally')
480 self:Refresh()
481 end
482 end
483
484 function core:OnShow()
485 print('|cFF00FFFFShow()')
486 if self.isStale then
487 print('on-show update')
488 self:Refresh()
489 end
490 ClassPlanButton.Background:Show()
491 ClassPlanButton.Grip:SetShown(true)
492 end
493 function core:OnHide()
494 print('|cFF00FFFFHide()')
495 ClassPlanButton.Background:Hide()
496 ClassPlanButton.Grip:SetShown(false)
497 end
498
499
500 function core:SortItems(ptype)
501 print('|cFF0088FFSortItems('..tostring(ptype)..')|r')
485 GI_currentTime = time() 502 GI_currentTime = time()
486 503
487 for key, sortedItems in pairs(self.sortedItems) do
488 wipe(sortedItems)
489 local ptype = self.prototypes[key]
490 --print( 'object:', ptype)
491 for name, profile in pairs(self.data.characters) do
492 GI_profileKey = name
493 GI_profile = profile
494 GI_isMine = (profile == self.profile)
495 local results = DoItemList(profile[key], sortedItems, ptype.OnGetItem)
496 --print(' - ', name, results, 'items')
497 end
498
499 if ptype.SortHandler then
500 sort(sortedItems, ptype.SortHandler)
501 end
502 end
503 end 504 end
504 505
505 function MissionsHandler:OnComplete() 506 function MissionsHandler:OnComplete()
506 print('flagging complete', self.name) 507 print('flagging complete', self.name)
507 self:Refresh() 508 self:Refresh()