annotate ClassPlan.lua @ 2:b8a19781f79b

shipment logging
author Nenue
date Thu, 13 Oct 2016 09:08:38 -0400
parents 232617b8bcd5
children c006ce87a147
rev   line source
Nenue@2 1 local wipe = table.wipe
Nenue@2 2 local pairs, ipairs = pairs, ipairs
Nenue@2 3 local GetTime = GetTime
Nenue@2 4 local blockTemplate = {
Nenue@2 5 point = 'TOPLEFT',
Nenue@2 6 relativePoint ='TOPLEFT',
Nenue@2 7 }
Nenue@2 8
Nenue@1 9 SLASH_CLASSPLAN1 = "/classplan"
Nenue@1 10 SLASH_CLASSPLAN2 = "/cp"
Nenue@1 11 SlashCmdList.CLASSPLAN = function(args)
Nenue@1 12 if ClassOrderPlan:IsVisible() then
Nenue@1 13 ClassOrderPlan:Hide()
Nenue@1 14 else
Nenue@1 15 ClassOrderPlan:Show()
Nenue@1 16 DEFAULT_CHAT_FRAME:AddMessage('|cFF88FF00WorldPlan|r: Order Hall Panel')
Nenue@1 17 end
Nenue@1 18 end
Nenue@1 19
Nenue@1 20 ClassOrderPlanCore = {
Nenue@2 21 freeBlocks = {},
Nenue@1 22 blocks = {},
Nenue@2 23 shipmentBlocks = {},
Nenue@2 24 freeShipmentBlocks = {},
Nenue@2 25 sortedShipments = {},
Nenue@2 26 sortedMissions = {},
Nenue@2 27 timers = {},
Nenue@2 28 shipments = {},
Nenue@2 29 playerFirst = false,
Nenue@2 30 templates = setmetatable({}, {
Nenue@2 31 __newindex = function(t,k ,v)
Nenue@2 32 if type(v) == 'table' then
Nenue@2 33 setmetatable(v, {__index = blockTemplate})
Nenue@2 34 rawset(t,k,v)
Nenue@2 35 end
Nenue@2 36 end
Nenue@2 37 })
Nenue@1 38 }
Nenue@2 39 ClassPlanBlockMixin = {}
Nenue@2 40 ClassPlanShipmentMixin = setmetatable({}, {__index = ClassPlanBlockMixin})
Nenue@2 41 local core, block, shipment = ClassOrderPlanCore, ClassPlanBlockMixin, ClassPlanShipmentMixin
Nenue@1 42 local print = DEVIAN_WORKSPACE and function(...) print('ClassPlan', ...) end or nop
Nenue@1 43
Nenue@2 44
Nenue@2 45
Nenue@1 46 function core:OnLoad ()
Nenue@1 47 self:RegisterUnitEvent('UNIT_PORTRAIT_UPDATE', 'player')
Nenue@1 48 self:RegisterEvent('PLAYER_LOGIN')
Nenue@1 49 self:RegisterEvent('PLAYER_ENTERING_WORLD')
Nenue@2 50 self:RegisterEvent('PLAYER_REGEN_ENABLED')
Nenue@2 51
Nenue@2 52 self:RegisterEvent('GARRISON_MISSION_LIST_UPDATE')
Nenue@2 53 self:RegisterEvent('GARRISON_MISSION_FINISHED')
Nenue@2 54 self:RegisterEvent("GARRISON_LANDINGPAGE_SHIPMENTS");
Nenue@2 55 self:RegisterEvent("GARRISON_SHIPMENT_RECEIVED");
Nenue@2 56 self:RegisterEvent("GARRISON_TALENT_UPDATE");
Nenue@2 57 self:RegisterEvent("GARRISON_TALENT_COMPLETE");
Nenue@1 58 end
Nenue@1 59
Nenue@2 60 core.templates.ClassPlanBlock = {
Nenue@2 61 SetItemData = function(block, data)
Nenue@2 62 block.isComplete = data.isComplete
Nenue@2 63 block.missionEndTime = data.missionEndTime
Nenue@2 64 end
Nenue@2 65 }
Nenue@2 66
Nenue@2 67 core.templates.ClassPlanShipment = {
Nenue@2 68
Nenue@2 69 parent = false,
Nenue@2 70 point = 'TOPRIGHT',
Nenue@2 71 relativePoint ='TOPRIGHT',
Nenue@2 72 SetItemData = function(block, data)
Nenue@2 73 block.icon = data.icon
Nenue@2 74 block.shipmentCapacity = data.shipmentCapacity
Nenue@2 75 block.shipmentsReady = data.shipmentsReady
Nenue@2 76 block.shipmentsTotal = data.shipmentsTotal
Nenue@2 77 block.creationTime = data.creationTime
Nenue@2 78 block.duration = data.duration
Nenue@2 79 block.itemID = data.itemID
Nenue@2 80 block.itemQuality = data.itemQuality
Nenue@2 81 --[[
Nenue@2 82 icon = texture,
Nenue@2 83 shipmentCapacity = shipmentCapacity,
Nenue@2 84 shipmentsReady = shipmentsReady,
Nenue@2 85 shipmentsTotal = shipmentsTotal,
Nenue@2 86 creationTime = creationTime,
Nenue@2 87 duration = duration,
Nenue@2 88 timeleftString = timeleftString,
Nenue@2 89 itemName = itemName,
Nenue@2 90 itemIcon = itemIcon,
Nenue@2 91 itemQuality = itemQuality,
Nenue@2 92 itemID = itemID
Nenue@2 93
Nenue@2 94 --]]
Nenue@2 95 end
Nenue@2 96 }
Nenue@1 97
Nenue@1 98 function core:OnEvent (event, ...)
Nenue@2 99 print(event)
Nenue@1 100 if event == 'UNIT_PORTRAIT_UPDATE' then
Nenue@1 101 SetPortraitTexture(self.portrait, 'player')
Nenue@1 102 elseif event == 'PLAYER_LOGIN' then
Nenue@1 103 if not self.initialized then
Nenue@1 104 if IsLoggedIn() then
Nenue@1 105 WorldPlanData.OrderHall = WorldPlanData.OrderHall or {}
Nenue@1 106 self.data = WorldPlanData.OrderHall
Nenue@1 107
Nenue@1 108
Nenue@1 109 local name, realm = UnitName('player')
Nenue@1 110 realm = realm or GetRealmName()
Nenue@1 111 self.profileKey = name .. '-' .. realm
Nenue@1 112 if not self.data[self.profileKey] then
Nenue@1 113 self.data[self.profileKey] = {}
Nenue@1 114 end
Nenue@1 115 self.profile = self.data[self.profileKey]
Nenue@1 116
Nenue@2 117 self.profile.shipments = self.profile.shipments or {}
Nenue@2 118 self.profile.missions = self.profile.missions or {}
Nenue@2 119 self.profile.classColor = RAID_CLASS_COLORS[select(2, UnitClass('player'))]
Nenue@2 120
Nenue@2 121 C_Garrison.RequestLandingPageShipmentInfo();
Nenue@1 122 self.initialized = true
Nenue@1 123 end
Nenue@1 124 end
Nenue@2 125 elseif event == 'GARRISON_LANDINGPAGE_SHIPMENTS' or event == 'GARRISON_TALENT_UPDATE' then
Nenue@2 126 self:UpdateShipments()
Nenue@2 127 elseif event == 'PLAYER_REGEN_ENABLED' or event == 'GARRISON_MISSION_FINISHED' or event == 'GARRISON_TALENT_COMPLETE' or event == 'GARRISON_SHIPMENT_RECEIVED' then
Nenue@2 128 self:UpdateNotifications()
Nenue@1 129 else
Nenue@2 130 self:UpdateItems ()
Nenue@1 131 end
Nenue@1 132 end
Nenue@1 133
Nenue@2 134 function core:UpdateNotifications()
Nenue@2 135 end
Nenue@1 136
Nenue@2 137 function core:RefreshItems(sortedItems, templateName)
Nenue@2 138 self.blocks[templateName] = self.blocks[templateName] or {}
Nenue@2 139 local blocks = self.blocks[templateName]
Nenue@2 140 local template = self.templates[templateName] or {
Nenue@2 141 parent = self.portrait,
Nenue@2 142 point = 'TOPLEFT',
Nenue@2 143 relativePoint ='TOPRIGHT',
Nenue@2 144 }
Nenue@2 145
Nenue@2 146 local lastProfile
Nenue@2 147 local numItems = #sortedItems
Nenue@2 148 for i, data in ipairs(sortedItems) do
Nenue@2 149 local block = blocks[i]
Nenue@2 150
Nenue@2 151 if not block then
Nenue@2 152 block = CreateFrame('Frame', nil, self, templateName)
Nenue@2 153 block:SetID(i)
Nenue@2 154 template.numBlocks = (template.numBlocks or 0) + 1
Nenue@2 155
Nenue@2 156 if template.lastBlock then
Nenue@2 157 block:SetPoint('TOPLEFT', template.lastBlock, 'BOTTOMLEFT', 0, 0)
Nenue@2 158 else
Nenue@2 159 block:SetPoint(template.point, self[template.parent] or self, template.relativePoint, 0, 0)
Nenue@2 160 end
Nenue@2 161 template.lastBlock = block
Nenue@2 162 blocks[i] = block
Nenue@2 163 end
Nenue@2 164
Nenue@2 165 if template.SetItemData then
Nenue@2 166 template.SetItemData(block, data)
Nenue@2 167 end
Nenue@2 168
Nenue@2 169
Nenue@2 170 block.lastProfile = lastProfile
Nenue@2 171 block:Refresh(data)
Nenue@2 172 block:Show()
Nenue@2 173 lastProfile = data.profileKey
Nenue@2 174 end
Nenue@2 175
Nenue@2 176 for i = numItems + 1, template.numBlocks do
Nenue@2 177 if blocks[i] then
Nenue@2 178 blocks[i]:Hide()
Nenue@2 179 end
Nenue@2 180 end
Nenue@2 181 end
Nenue@2 182
Nenue@2 183 function core:Refresh()
Nenue@2 184 if self.isStale then
Nenue@2 185 self:SortLists()
Nenue@2 186 end
Nenue@2 187 self.isStale = nil
Nenue@2 188
Nenue@2 189 self:RefreshItems(self.sortedMissions, 'ClassPlanBlock')
Nenue@2 190 self:RefreshItems(self.sortedShipments, 'ClassPlanShipment')
Nenue@2 191
Nenue@2 192
Nenue@2 193 local posX = self.data.posX or 0
Nenue@2 194 local posY = self.data.posY or -24
Nenue@2 195 local point = self.point or 'TOP'
Nenue@2 196 local relativePoint = self.point or 'TOP'
Nenue@2 197 self:SetPoint(point, UIParent, relativePoint, posX, posY)
Nenue@2 198
Nenue@2 199
Nenue@2 200 end
Nenue@2 201
Nenue@2 202 function core:OnUpdate()
Nenue@2 203 if self.fadeTimer and self.fadeTimer < GetTime() then
Nenue@2 204 self:Hide()
Nenue@2 205 end
Nenue@2 206 end
Nenue@2 207
Nenue@2 208 function core:OnShow()
Nenue@2 209 if self.isStale then
Nenue@2 210 print('updating items on show')
Nenue@2 211 self:Refresh()
Nenue@2 212 end
Nenue@2 213
Nenue@2 214 end
Nenue@2 215
Nenue@2 216 function core:SortLists()
Nenue@2 217
Nenue@2 218 wipe(self.sortedShipments)
Nenue@2 219 wipe(self.sortedMissions)
Nenue@1 220 for name, profile in pairs(self.data) do
Nenue@1 221 local isMine = (profile == self.profile)
Nenue@1 222 for index, data in pairs(profile.missions) do
Nenue@1 223
Nenue@1 224 data.classColor = profile.classColor or {r = 0.7, g = 0.7, b =0.7}
Nenue@1 225 data.profileKey = name
Nenue@1 226 data.isMine = (profile == self.profile)
Nenue@1 227 tinsert(self.sortedMissions, data)
Nenue@1 228 end
Nenue@2 229
Nenue@2 230 if not profile.shipments then
Nenue@2 231 profile.shipments = {}
Nenue@2 232 profile.shipment = nil
Nenue@2 233 end
Nenue@2 234
Nenue@2 235 for index, data in pairs(profile.shipments) do
Nenue@2 236 data.classColor = profile.classColor or {r = 0.7, g = 0.7, b =0.7}
Nenue@2 237 data.profileKey = name
Nenue@2 238 data.isMine = (profile == self.profile)
Nenue@2 239 tinsert(self.sortedShipments, data)
Nenue@2 240 end
Nenue@1 241 end
Nenue@1 242
Nenue@2 243 table.sort(self.sortedMissions, function (a,b)
Nenue@1 244 local result = false
Nenue@1 245 if not a or not b then
Nenue@1 246 result = true
Nenue@1 247 else
Nenue@1 248 if (a.isMine ~= b.isMine) and self.playerFirst then
Nenue@1 249 result = a.isMine
Nenue@1 250 else
Nenue@1 251 if (not b.missionEndTime) or (not a.missionEndTime) then
Nenue@1 252 print('missing article', b.missionEndTime, a.missionEndTime)
Nenue@1 253 end
Nenue@1 254 result = ( b.missionEndTime > a.missionEndTime)
Nenue@1 255 end
Nenue@1 256 end
Nenue@1 257
Nenue@2 258 --print('cmp', (b and (b.missionEndTime .. ' ' .. tostring(b.isMine)) or '-'), '>', (a and (a.missionEndTime .. ' ' .. tostring(a.isMine)) or '-'), result, n)
Nenue@1 259 return result
Nenue@1 260 end)
Nenue@1 261
Nenue@2 262 end
Nenue@1 263
Nenue@2 264 function core:UpdateShipments()
Nenue@2 265 print('|cFF0088FFShipments|r:', self.profileKey)
Nenue@2 266 if not self.profile then
Nenue@2 267 return
Nenue@2 268 end
Nenue@2 269 wipe(self.shipments)
Nenue@2 270
Nenue@2 271
Nenue@2 272 local garrisonType = LE_GARRISON_TYPE_7_0
Nenue@2 273 local buildings = C_Garrison.GetBuildings(garrisonType);
Nenue@2 274 local shipmentIndex = 0
Nenue@2 275 print('Buildings:')
Nenue@2 276 for i = 1, #buildings do
Nenue@2 277 local name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, itemName, itemIcon, itemQuality, itemID = C_Garrison.GetLandingPageShipmentInfo(buildingID);
Nenue@2 278 print(buildings[i], name, creationTime, duration)
Nenue@2 279 tinsert(self.shipments,
Nenue@2 280 {
Nenue@2 281 shipmentType = 'Work Order',
Nenue@2 282 name = name,
Nenue@2 283 icon = texture,
Nenue@2 284 shipmentCapacity = shipmentCapacity,
Nenue@2 285 shipmentsReady = shipmentsReady,
Nenue@2 286 shipmentsTotal = shipmentsTotal,
Nenue@2 287 creationTime = creationTime,
Nenue@2 288 duration = duration,
Nenue@2 289 timeleftString = timeleftString,
Nenue@2 290 itemName = itemName,
Nenue@2 291 itemIcon = itemIcon,
Nenue@2 292 itemQuality = itemQuality,
Nenue@2 293 itemID = itemID
Nenue@2 294 })
Nenue@2 295 end
Nenue@2 296
Nenue@2 297 print('Follower:')
Nenue@2 298 local followerShipments = C_Garrison.GetFollowerShipments(garrisonType);
Nenue@2 299 for i = 1, #followerShipments do
Nenue@2 300 local name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, _, _, _, _, followerID = C_Garrison.GetLandingPageShipmentInfoByContainerID(followerShipments[i]);
Nenue@2 301 print(followerShipments[i], name, creationTime, duration)
Nenue@2 302 tinsert(self.shipments,
Nenue@2 303 {
Nenue@2 304 shipmentType = '',
Nenue@2 305 name = name,
Nenue@2 306 icon = texture,
Nenue@2 307 shipmentCapacity = shipmentCapacity,
Nenue@2 308 shipmentsReady = shipmentsReady,
Nenue@2 309 shipmentsTotal = shipmentsTotal,
Nenue@2 310 creationTime = creationTime,
Nenue@2 311 duration = duration,
Nenue@2 312 timeleftString = timeleftString,
Nenue@2 313 followerID = followerID,
Nenue@2 314 })
Nenue@2 315 end
Nenue@2 316
Nenue@2 317 print('Loose:')
Nenue@2 318 local looseShipments = C_Garrison.GetLooseShipments(garrisonType)
Nenue@2 319 for i = 1, #looseShipments do
Nenue@2 320 local name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString = C_Garrison.GetLandingPageShipmentInfoByContainerID(looseShipments[i]);
Nenue@2 321 print(looseShipments[i], name, creationTime, duration)
Nenue@2 322 tinsert(self.shipments,
Nenue@2 323 {
Nenue@2 324 shipmentType = '',
Nenue@2 325 name = name,
Nenue@2 326 icon = texture,
Nenue@2 327 shipmentCapacity = shipmentCapacity,
Nenue@2 328 shipmentsReady = shipmentsReady,
Nenue@2 329 shipmentsTotal = shipmentsTotal,
Nenue@2 330 creationTime = creationTime,
Nenue@2 331 duration = duration,
Nenue@2 332 timeleftString = timeleftString,
Nenue@2 333 })
Nenue@2 334 end
Nenue@2 335
Nenue@2 336 local talentTrees = C_Garrison.GetTalentTrees(garrisonType, select(3, UnitClass("player")));
Nenue@2 337 -- this is a talent that has completed, but has not been seen in the talent UI yet.
Nenue@2 338 local completeTalentID = C_Garrison.GetCompleteTalent(garrisonType);
Nenue@2 339 print('Talents:')
Nenue@2 340 if (talentTrees) then
Nenue@2 341 for treeIndex, tree in ipairs(talentTrees) do
Nenue@2 342 for talentIndex, talent in ipairs(tree) do
Nenue@2 343 local showTalent = false;
Nenue@2 344 if (talent.isBeingResearched) then
Nenue@2 345 showTalent = true;
Nenue@2 346 end
Nenue@2 347 if (talent.id == completeTalentID) then
Nenue@2 348 showTalent = true;
Nenue@2 349 end
Nenue@2 350 if (showTalent) then
Nenue@2 351 print(talent.name)
Nenue@2 352 talent.creationTime = talent.researchStartTime
Nenue@2 353 talent.duration = talent.researchDuration
Nenue@2 354 talent.shipmentType = 'Talent: '
Nenue@2 355 tinsert(self.shipments, talent)
Nenue@2 356 end
Nenue@1 357 end
Nenue@1 358 end
Nenue@2 359 end
Nenue@1 360
Nenue@2 361 self.profile.shipments = self.profile.shipments or {}
Nenue@2 362 if #self.shipments >= 1 then
Nenue@2 363
Nenue@2 364 wipe(self.profile.shipments)
Nenue@2 365 for index, shipment in ipairs(self.shipments) do
Nenue@2 366 tinsert(self.profile.shipments, shipment)
Nenue@1 367 end
Nenue@2 368 self.isStale = true
Nenue@2 369 end
Nenue@1 370
Nenue@2 371 if self:IsVisible() then
Nenue@2 372 self:Refresh()
Nenue@1 373 end
Nenue@1 374 end
Nenue@1 375
Nenue@2 376 function core:UpdateItems ()
Nenue@1 377 if not self.profile then
Nenue@1 378 return
Nenue@1 379 end
Nenue@1 380 self.items = C_Garrison.GetLandingPageItems(LE_GARRISON_TYPE_7_0)
Nenue@1 381
Nenue@1 382
Nenue@1 383
Nenue@1 384
Nenue@2 385 print('|cFF0088FFLandingPageItems|r:', self.profileKey)
Nenue@1 386 if #self.items >= 1 then
Nenue@2 387 wipe(self.profile.missions)
Nenue@1 388 for index, data in ipairs(self.items) do
Nenue@1 389 print('', data.name)
Nenue@1 390 print(' |cFF00FF00', data.timeLeft .. '|r', date("%A %I:%m %p", data.missionEndTime))
Nenue@1 391 tinsert(self.profile.missions, data)
Nenue@1 392 end
Nenue@2 393 print('items update pending')
Nenue@2 394 self.isStale = true
Nenue@1 395 end
Nenue@1 396
Nenue@1 397 if self:IsVisible() then
Nenue@2 398 self:Refresh()
Nenue@2 399 end
Nenue@2 400 end
Nenue@2 401
Nenue@2 402 function block:OnComplete()
Nenue@2 403 self.isComplete = true
Nenue@2 404 self:Refresh()
Nenue@2 405 end
Nenue@2 406
Nenue@2 407 local GetTimeLeftString = function(timeLeft)
Nenue@2 408
Nenue@2 409 local days = floor(timeLeft/(24*3600))
Nenue@2 410 local hours = floor(mod(timeLeft, (24*3600)) / 3600)
Nenue@2 411 local minutes = floor(mod(timeLeft, 3600) / 60)
Nenue@2 412 local seconds = mod(timeLeft, 60)
Nenue@2 413 if days >= 1 then
Nenue@2 414 return (days .. 'd' .. ' ') .. ((hours > 0) and (hours .. 'h ') or '')
Nenue@1 415 else
Nenue@2 416 return ((hours > 0) and (hours .. 'h ') or '') .. ((minutes > 0) and (minutes .. ' min') or '')
Nenue@1 417 end
Nenue@1 418 end
Nenue@1 419
Nenue@1 420 function block:OnUpdate()
Nenue@2 421 if self.isComplete then
Nenue@2 422 return
Nenue@2 423 end
Nenue@2 424
Nenue@1 425 if self.missionEndTime then
Nenue@1 426 local timeLeft = self.missionEndTime - time()
Nenue@1 427 if timeLeft < 0 then
Nenue@2 428 self:OnComplete()
Nenue@1 429 else
Nenue@2 430 self.TimeLeft:SetText(GetTimeLeftString(timeLeft))
Nenue@2 431
Nenue@2 432 if timeLeft > 3600 then
Nenue@2 433 self.TimeLeft:SetTextColor(1,1,1)
Nenue@2 434 else
Nenue@2 435 self.TimeLeft:SetTextColor(1,1,0)
Nenue@2 436 end
Nenue@2 437
Nenue@1 438 end
Nenue@1 439 else
Nenue@1 440 self.TimeLeft:SetText(self.missionEndTime)
Nenue@1 441 end
Nenue@2 442 end
Nenue@2 443
Nenue@2 444 local SetClassColors = function(self, data)
Nenue@2 445
Nenue@2 446 if self.lastProfile ~= data.profileKey then
Nenue@2 447 self.Owner:SetText(data.profileKey)
Nenue@2 448 self.Owner:SetTextColor(data.classColor.r, data.classColor.g, data.classColor.b)
Nenue@2 449 else
Nenue@2 450 self.Owner:SetText(nil)
Nenue@2 451 end
Nenue@2 452 self.Background:SetColorTexture(data.classColor.r, data.classColor.g, data.classColor.b,
Nenue@2 453 (data.isComplete and 0.5 or 0.1))
Nenue@2 454 end
Nenue@2 455
Nenue@2 456 function block:Refresh(data)
Nenue@2 457 data = data or self.data
Nenue@2 458 self.data = data
Nenue@2 459
Nenue@2 460 local r,g,b = 1, 1, 1
Nenue@2 461 if data.isRare then
Nenue@2 462 r,g,b = 0.1, 0.4, 1
Nenue@2 463 end
Nenue@2 464
Nenue@2 465
Nenue@2 466 --self.missionData = data
Nenue@2 467 self.Label:SetText(data.name)
Nenue@2 468 self.Label:SetTextColor(r, g, b)
Nenue@2 469
Nenue@2 470 if #data.rewards >= 1 then
Nenue@2 471 self.Icon:SetTexture(data.rewards[1].icon or GetItemIcon(data.rewards[1].itemID))
Nenue@2 472 self.rewardInfo = data.rewards[1]
Nenue@2 473 else
Nenue@2 474 self.Icon:SetAtlas(data.typeAtlas, false)
Nenue@2 475 end
Nenue@2 476
Nenue@2 477 SetClassColors(self, data)
Nenue@2 478
Nenue@2 479 if self.isComplete then
Nenue@2 480 self.TimeLeft:SetText('Complete!')
Nenue@2 481 end
Nenue@2 482 end
Nenue@2 483
Nenue@2 484
Nenue@2 485 function block:OnEnter()
Nenue@2 486 if self.rewardInfo and self.rewardInfo.itemID then
Nenue@2 487 GameTooltip:SetOwner(self, 'ANCHOR_LEFT')
Nenue@2 488 GameTooltip:SetItemByID(self.rewardInfo.itemID)
Nenue@2 489 GameTooltip:Show()
Nenue@2 490 end
Nenue@2 491 end
Nenue@2 492 function block:OnLeave()
Nenue@2 493 if GameTooltip:IsOwned(self) then
Nenue@2 494 GameTooltip:Hide()
Nenue@2 495 end
Nenue@2 496 end
Nenue@2 497
Nenue@2 498
Nenue@2 499
Nenue@2 500 function shipment:Refresh(data)
Nenue@2 501 data = data or self.data
Nenue@2 502 self.Icon:SetTexture(data.icon)
Nenue@2 503 self.data = data
Nenue@2 504
Nenue@2 505 self.Name:SetText(data.shipmentType .. data.name)
Nenue@2 506 self.Count:SetText(data.shipmentsReady)
Nenue@2 507
Nenue@2 508 self.Done:SetShown(data.shipmentsReady and (data.shipmentsReady >= 1))
Nenue@2 509
Nenue@2 510 if ( data.shipmentsReady == data.shipmentsTotal ) then
Nenue@2 511 self.Swipe:SetCooldownUNIX(0, 0);
Nenue@2 512 self.Done:Show();
Nenue@2 513 if not data.isBeingResearched then
Nenue@2 514 data.isComplete = true
Nenue@2 515 end
Nenue@2 516 else
Nenue@2 517 self.Swipe:SetCooldownUNIX(data.creationTime or 0 , data.duration or 0);
Nenue@2 518 end
Nenue@2 519
Nenue@2 520
Nenue@2 521
Nenue@2 522 SetClassColors(self, data)
Nenue@2 523 end
Nenue@2 524 function shipment:UpdateShipment()
Nenue@2 525
Nenue@2 526 local data = self.data
Nenue@2 527 if data.shipmentsTotal then
Nenue@2 528 local timeLeft = data.creationTime + data.duration - time()
Nenue@2 529 if timeLeft < 0 then
Nenue@2 530 local numReady = floor((1*timeLeft) / data.duration)
Nenue@2 531 data.shipmentsReady = data.shipmentsReady + numReady
Nenue@2 532 data.creationTime = data.creationTime + (numReady * data.duration)
Nenue@2 533 self:Refresh()
Nenue@2 534 end
Nenue@2 535 end
Nenue@2 536 end
Nenue@2 537 function shipment:OnUpdate()
Nenue@2 538 local data = self.data
Nenue@2 539 if (data.shipmentsReady and data.shipmentsTotal) and (data.shipmentsReady ~= data.shipmentsTotal) then
Nenue@2 540 local timeLeft = data.creationTime + data.duration - time()
Nenue@2 541 if timeLeft < 0 then
Nenue@2 542 self:UpdateShipment()
Nenue@2 543 return
Nenue@2 544 end
Nenue@2 545
Nenue@2 546 self.TimeLeft:SetText('Next: '.. GetTimeLeftString(timeLeft) .. ' |cFFFFFF00'..data.shipmentsTotal..' orders|r')
Nenue@2 547
Nenue@2 548
Nenue@2 549 elseif data.isBeingResearched then
Nenue@2 550 self.TimeLeft:SetText(GetTimeLeftString(data.researchStartTime + data.researchDuration - time()))
Nenue@2 551 else
Nenue@2 552 self.TimeLeft:SetText('Complete!')
Nenue@2 553 end
Nenue@2 554
Nenue@2 555 end
Nenue@2 556
Nenue@2 557 function shipment:OnEnter()
Nenue@2 558 local data = self.data
Nenue@2 559 if ( data.shipmentsReady and data.shipmentsTotal ) then
Nenue@2 560 GameTooltip:SetOwner(self, 'ANCHOR_LEFT')
Nenue@2 561 GameTooltip:AddLine(data.shipmentsReady .. ' of '.. data.shipmentsTotal)
Nenue@2 562 GameTooltip:Show()
Nenue@2 563 end
Nenue@2 564 end
Nenue@2 565
Nenue@2 566 function shipment:OnLeave()
Nenue@2 567 if GameTooltip:IsOwned(self) then
Nenue@2 568 GameTooltip:Hide()
Nenue@2 569 end
Nenue@2 570 end
Nenue@2 571
Nenue@2 572 function shipment:OnClick(button)
Nenue@2 573 --todo: trigger cleanup script for dead shipment data
Nenue@1 574 end