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