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@3
|
29 ClassPlanBlockMixin = {
|
Nenue@3
|
30 templateName = 'ClassPlanBlock',
|
Nenue@4
|
31 events = {'GARRISON_MISSION_LIST_UPDATE', 'GARRISON_MISSION_STARTED', 'GARRISON_MISSION_FINISHED'},}
|
Nenue@3
|
32 ClassPlanShipmentMixin = {
|
Nenue@3
|
33 templateName = 'ClassPlanShipment',
|
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@3
|
39 setmetatable(ClassPlanShipmentMixin, {__index = ClassPlanBlockMixin})
|
Nenue@3
|
40 local core, MissionsHandler, ShipmentsHandler = ClassOrderPlanCore, ClassPlanBlockMixin, 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@4
|
49 return (days .. 'd' .. ' ') .. ((hours > 0) and (hours .. 'h ') or '')
|
Nenue@4
|
50 else
|
Nenue@4
|
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@3
|
104 local numOrders = -1*floor(timeLeft/data.duration)
|
Nenue@2
|
105
|
Nenue@3
|
106 data.originalCreationTime = data.creationTime
|
Nenue@3
|
107 data.originalShipmentsReady = data.shipmentsReady
|
Nenue@2
|
108
|
Nenue@3
|
109 data.creationTime = data.creationTime + numOrders*data.duration
|
Nenue@3
|
110 data.shipmentsReady = data.shipmentsReady + numOrders
|
Nenue@3
|
111 print(data.profileKey, 'shipment "'.. data.name..'" reconciling', numOrders, 'lapsed orders. -->', data.creationTime, data.shipmentsReady)
|
Nenue@2
|
112 end
|
Nenue@2
|
113 end
|
Nenue@2
|
114 end
|
Nenue@2
|
115
|
Nenue@3
|
116 ShipmentsHandler.SortHandler = function(a, b)
|
Nenue@3
|
117 if b.isComplete ~= a.isComplete then
|
Nenue@3
|
118 return a.isComplete and true or false
|
Nenue@4
|
119 elseif a.shipmentsReady or b.shipmentsReady then
|
Nenue@4
|
120 return (a.shipmentsReady or 0) > (b.shipmentsReady or 0)
|
Nenue@4
|
121 else
|
Nenue@4
|
122 return (a.creationTime) < (b.creationTime)
|
Nenue@2
|
123 end
|
Nenue@2
|
124 end
|
Nenue@2
|
125
|
Nenue@4
|
126 local AddShipmentInfo = function(self, 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@4
|
131 print(shipmentType, name, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString)
|
Nenue@4
|
132 tinsert(self.shipments,
|
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@2
|
154 wipe(self.shipments)
|
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@4
|
163 AddShipmentInfo(self, '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@4
|
170 AddShipmentInfo(self, '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@4
|
177 AddShipmentInfo(self, 'Follower', 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@4
|
189 AddShipmentInfo(self, '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@2
|
196 if #self.shipments >= 1 then
|
Nenue@2
|
197 wipe(self.profile.shipments)
|
Nenue@3
|
198 for index, data in ipairs(self.shipments) do
|
Nenue@4
|
199
|
Nenue@4
|
200 --DEFAULT_CHAT_FRAME:AddMessage(data.shipmentType ..' '.. tostring(data.name) ..' '.. tostring(data.creationTime) ..' '.. tostring(data.duration))
|
Nenue@3
|
201 tinsert(self.profile.shipments, data)
|
Nenue@1
|
202 end
|
Nenue@2
|
203 self.isStale = true
|
Nenue@2
|
204 end
|
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@5
|
325 self:SetShown(false)
|
Nenue@5
|
326 elseif event == 'PLAYER_REGEN_ENABLED' then
|
Nenue@5
|
327 self:SetShown(true)
|
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@2
|
339 end
|
Nenue@2
|
340 end
|
Nenue@2
|
341
|
Nenue@3
|
342 function core:UpdateNotifications()
|
Nenue@3
|
343 end
|
Nenue@3
|
344
|
Nenue@4
|
345
|
Nenue@4
|
346 local SetOwnerData = function(self, data)
|
Nenue@4
|
347 local name, realm = string.match(data.profileKey, "(.+)%-(.+)")
|
Nenue@4
|
348 local ownerText = '|c'.. data.classColor.colorStr .. name .. '|r'
|
Nenue@5
|
349 --if realm ~= GI_currentRealm then
|
Nenue@5
|
350 --ownerText = ownerText .. ' (' .. realm .. ')'
|
Nenue@5
|
351 --end
|
Nenue@5
|
352 self.Owner:SetText(ownerText)
|
Nenue@5
|
353 self.Name:SetTextColor(data.classColor.r, data.classColor.g, data.classColor.b)
|
Nenue@5
|
354
|
Nenue@5
|
355 if self.isComplete then
|
Nenue@5
|
356 self.TimeLeft:SetText('Complete!')
|
Nenue@5
|
357 self.Background:SetColorTexture(.25,.25,.25,1)
|
Nenue@5
|
358 else
|
Nenue@5
|
359 self.Background:SetColorTexture(0,0,0,0.5)
|
Nenue@4
|
360 end
|
Nenue@5
|
361
|
Nenue@4
|
362 end
|
Nenue@4
|
363
|
Nenue@3
|
364 function core:RefreshItems(configKey, prototype)
|
Nenue@3
|
365 local sortedItems = self.sortedItems[configKey]
|
Nenue@3
|
366
|
Nenue@3
|
367 self.blocks[configKey] = self.blocks[configKey] or {}
|
Nenue@3
|
368 local blocks = self.blocks[configKey]
|
Nenue@3
|
369
|
Nenue@3
|
370 local lastProfile
|
Nenue@3
|
371 local numItems = #sortedItems
|
Nenue@3
|
372 local totalHeight = 0
|
Nenue@3
|
373 for i, data in ipairs(sortedItems) do
|
Nenue@3
|
374 local block = blocks[i]
|
Nenue@3
|
375
|
Nenue@3
|
376 if not block then
|
Nenue@3
|
377 block = CreateFrame('Button', nil, self, prototype.templateName)
|
Nenue@3
|
378 block:SetID(i)
|
Nenue@4
|
379 block.handler = prototype
|
Nenue@3
|
380 prototype.numBlocks = prototype.numBlocks + 1
|
Nenue@3
|
381
|
Nenue@3
|
382 if prototype.lastBlock then
|
Nenue@3
|
383 block:SetPoint('TOPLEFT', prototype.lastBlock, 'BOTTOMLEFT', 0, 0)
|
Nenue@3
|
384 else
|
Nenue@3
|
385 block:SetPoint(prototype.point, self[prototype.parent] or self, prototype.relativePoint, 0, 0)
|
Nenue@3
|
386 end
|
Nenue@3
|
387 prototype.lastBlock = block
|
Nenue@3
|
388 blocks[i] = block
|
Nenue@3
|
389 end
|
Nenue@3
|
390
|
Nenue@3
|
391 totalHeight = totalHeight + block:GetHeight()
|
Nenue@3
|
392 block.lastProfile = lastProfile
|
Nenue@4
|
393 for k,v in pairs(data) do
|
Nenue@4
|
394 if type(block[k]) ~= 'function' then
|
Nenue@4
|
395 block[k] = v
|
Nenue@4
|
396 end
|
Nenue@4
|
397 end
|
Nenue@3
|
398 block:Refresh(data)
|
Nenue@5
|
399 print(block.isComplete, block.missionEndTime, block.name)
|
Nenue@4
|
400 SetOwnerData(block, data)
|
Nenue@4
|
401
|
Nenue@3
|
402 block:Show()
|
Nenue@3
|
403 lastProfile = data.profileKey
|
Nenue@3
|
404 end
|
Nenue@3
|
405
|
Nenue@3
|
406 for i = numItems + 1, prototype.numBlocks do
|
Nenue@3
|
407 if blocks[i] then
|
Nenue@3
|
408 blocks[i]:Hide()
|
Nenue@3
|
409 end
|
Nenue@3
|
410 end
|
Nenue@3
|
411
|
Nenue@3
|
412 return totalHeight
|
Nenue@3
|
413 end
|
Nenue@3
|
414 local max = math.max
|
Nenue@3
|
415 function core:Refresh()
|
Nenue@3
|
416 if self.isStale then
|
Nenue@3
|
417 self:SortItems()
|
Nenue@3
|
418 end
|
Nenue@3
|
419 self.isStale = nil
|
Nenue@3
|
420
|
Nenue@3
|
421 self.currentHeight = 0
|
Nenue@3
|
422 for name, info in pairs(self.prototypes) do
|
Nenue@3
|
423 local itemsHeight = self:RefreshItems(name, info)
|
Nenue@3
|
424 self.currentHeight = max(itemsHeight, self.currentHeight)
|
Nenue@3
|
425 end
|
Nenue@3
|
426
|
Nenue@4
|
427 self:Reanchor()
|
Nenue@3
|
428 self:SetHeight(self.currentHeight)
|
Nenue@3
|
429 end
|
Nenue@3
|
430
|
Nenue@3
|
431 function core:Toggle()
|
Nenue@5
|
432 if self:IsShown() then
|
Nenue@3
|
433 self:Hide()
|
Nenue@3
|
434 else
|
Nenue@3
|
435 self:Show()
|
Nenue@3
|
436 end
|
Nenue@3
|
437
|
Nenue@3
|
438 if self.data then
|
Nenue@5
|
439 self.data.IsShown = self:IsShown()
|
Nenue@3
|
440 end
|
Nenue@3
|
441 end
|
Nenue@3
|
442
|
Nenue@3
|
443 function core:OnUpdate()
|
Nenue@3
|
444 if self.fadeTimer and self.fadeTimer < GetTime() then
|
Nenue@3
|
445 self:Hide()
|
Nenue@3
|
446 end
|
Nenue@3
|
447 end
|
Nenue@3
|
448
|
Nenue@3
|
449 function core:OnShow()
|
Nenue@3
|
450 if self.isStale then
|
Nenue@3
|
451 print('updating items on show')
|
Nenue@3
|
452 self:Refresh()
|
Nenue@3
|
453 end
|
Nenue@4
|
454 -- grab this at least once
|
Nenue@4
|
455 C_Garrison.RequestLandingPageShipmentInfo();
|
Nenue@4
|
456 ClassPlanButton.Background:Show()
|
Nenue@4
|
457 ClassPlanButton.Grip:SetShown(true)
|
Nenue@3
|
458 end
|
Nenue@3
|
459 function core:OnHide()
|
Nenue@4
|
460 ClassPlanButton.Background:Hide()
|
Nenue@4
|
461 ClassPlanButton.Grip:SetShown(false)
|
Nenue@3
|
462 end
|
Nenue@3
|
463
|
Nenue@3
|
464 local GI_profileKey, GI_profile, GI_isMine
|
Nenue@4
|
465 local defaultClassColor = {r = 0.7, g = 0.7, b =0.7, colorStr = "ffffffff"}
|
Nenue@4
|
466 local DoItemList = function (source, dest, onGetItem)
|
Nenue@3
|
467 if not source then
|
Nenue@3
|
468 return
|
Nenue@3
|
469 end
|
Nenue@3
|
470 local numItems = 0
|
Nenue@3
|
471 for index, data in ipairs(source) do
|
Nenue@4
|
472 data.classColor = GI_profile.classColor or defaultClassColor
|
Nenue@3
|
473 data.profileKey = GI_profileKey
|
Nenue@3
|
474 data.isMine = GI_isMine
|
Nenue@3
|
475 if onGetItem then
|
Nenue@3
|
476 onGetItem(data)
|
Nenue@3
|
477 end
|
Nenue@3
|
478 numItems = numItems + 1
|
Nenue@3
|
479 tinsert(dest, data)
|
Nenue@3
|
480 end
|
Nenue@3
|
481 return numItems
|
Nenue@3
|
482 end
|
Nenue@3
|
483
|
Nenue@3
|
484 function core:SortItems()
|
Nenue@3
|
485 print('|cFF0088FFSortItems()|r')
|
Nenue@3
|
486 GI_currentTime = time()
|
Nenue@3
|
487
|
Nenue@3
|
488 for key, sortedItems in pairs(self.sortedItems) do
|
Nenue@3
|
489 wipe(sortedItems)
|
Nenue@3
|
490 local ptype = self.prototypes[key]
|
Nenue@4
|
491 --print( 'object:', ptype)
|
Nenue@3
|
492 for name, profile in pairs(self.data.characters) do
|
Nenue@3
|
493 GI_profileKey = name
|
Nenue@3
|
494 GI_profile = profile
|
Nenue@3
|
495 GI_isMine = (profile == self.profile)
|
Nenue@4
|
496 local results = DoItemList(profile[key], sortedItems, ptype.OnGetItem)
|
Nenue@4
|
497 --print(' - ', name, results, 'items')
|
Nenue@3
|
498 end
|
Nenue@3
|
499
|
Nenue@3
|
500 if ptype.SortHandler then
|
Nenue@4
|
501 sort(sortedItems, ptype.SortHandler)
|
Nenue@3
|
502 end
|
Nenue@3
|
503 end
|
Nenue@3
|
504 end
|
Nenue@3
|
505
|
Nenue@3
|
506 function MissionsHandler:OnComplete()
|
Nenue@5
|
507 print('flagging complete', self.name)
|
Nenue@2
|
508 self:Refresh()
|
Nenue@2
|
509 end
|
Nenue@2
|
510
|
Nenue@3
|
511 function MissionsHandler:OnUpdate()
|
Nenue@4
|
512 if self.isComplete then
|
Nenue@2
|
513 return
|
Nenue@2
|
514 end
|
Nenue@2
|
515
|
Nenue@1
|
516 if self.missionEndTime then
|
Nenue@1
|
517 local timeLeft = self.missionEndTime - time()
|
Nenue@1
|
518 if timeLeft < 0 then
|
Nenue@2
|
519 self:OnComplete()
|
Nenue@1
|
520 else
|
Nenue@2
|
521 self.TimeLeft:SetText(GetTimeLeftString(timeLeft))
|
Nenue@2
|
522
|
Nenue@2
|
523 if timeLeft > 3600 then
|
Nenue@2
|
524 self.TimeLeft:SetTextColor(1,1,1)
|
Nenue@2
|
525 else
|
Nenue@2
|
526 self.TimeLeft:SetTextColor(1,1,0)
|
Nenue@2
|
527 end
|
Nenue@2
|
528
|
Nenue@1
|
529 end
|
Nenue@1
|
530 else
|
Nenue@1
|
531 self.TimeLeft:SetText(self.missionEndTime)
|
Nenue@1
|
532 end
|
Nenue@2
|
533 end
|
Nenue@2
|
534
|
Nenue@4
|
535 function MissionsHandler:Refresh()
|
Nenue@2
|
536
|
Nenue@3
|
537
|
Nenue@2
|
538 local r,g,b = 1, 1, 1
|
Nenue@4
|
539 if self.isRare then
|
Nenue@2
|
540 r,g,b = 0.1, 0.4, 1
|
Nenue@5
|
541 self.IconBorder:SetVertexColor(r, g, b, 1)
|
Nenue@2
|
542 end
|
Nenue@2
|
543
|
Nenue@2
|
544
|
Nenue@2
|
545 --self.missionData = data
|
Nenue@5
|
546 self.Name:SetText(self.name)
|
Nenue@2
|
547
|
Nenue@4
|
548 if #self.rewards >= 1 then
|
Nenue@4
|
549 self.Icon:SetTexture(self.rewards[1].icon or GetItemIcon(self.rewards[1].itemID))
|
Nenue@4
|
550 self.rewardInfo = self.rewards[1]
|
Nenue@2
|
551 else
|
Nenue@4
|
552 self.Icon:SetAtlas(self.typeAtlas, false)
|
Nenue@2
|
553 end
|
Nenue@2
|
554 end
|
Nenue@2
|
555
|
Nenue@2
|
556
|
Nenue@3
|
557 function MissionsHandler:OnEnter()
|
Nenue@2
|
558 if self.rewardInfo and self.rewardInfo.itemID then
|
Nenue@2
|
559 GameTooltip:SetOwner(self, 'ANCHOR_LEFT')
|
Nenue@2
|
560 GameTooltip:SetItemByID(self.rewardInfo.itemID)
|
Nenue@2
|
561 GameTooltip:Show()
|
Nenue@2
|
562 end
|
Nenue@2
|
563 end
|
Nenue@3
|
564 function MissionsHandler:OnLeave()
|
Nenue@2
|
565 if GameTooltip:IsOwned(self) then
|
Nenue@2
|
566 GameTooltip:Hide()
|
Nenue@2
|
567 end
|
Nenue@2
|
568 end
|
Nenue@2
|
569
|
Nenue@2
|
570
|
Nenue@2
|
571
|
Nenue@4
|
572 function ShipmentsHandler:Refresh()
|
Nenue@3
|
573
|
Nenue@3
|
574 --[[
|
Nenue@3
|
575 self.icon = data.icon
|
Nenue@3
|
576 self.shipmentCapacity = data.shipmentCapacity
|
Nenue@3
|
577 self.shipmentsReady = data.shipmentsReady
|
Nenue@3
|
578 self.shipmentsTotal = data.shipmentsTotal
|
Nenue@3
|
579 self.creationTime = data.creationTime
|
Nenue@3
|
580 self.duration = data.duration
|
Nenue@3
|
581 self.itemID = data.itemID
|
Nenue@3
|
582 self.itemQuality = data.itemQuality
|
Nenue@3
|
583 icon = texture,
|
Nenue@3
|
584 shipmentCapacity = shipmentCapacity,
|
Nenue@3
|
585 shipmentsReady = shipmentsReady,
|
Nenue@3
|
586 shipmentsTotal = shipmentsTotal,
|
Nenue@3
|
587 creationTime = creationTime,
|
Nenue@3
|
588 duration = duration,
|
Nenue@3
|
589 timeleftString = timeleftString,
|
Nenue@3
|
590 itemName = itemName,
|
Nenue@3
|
591 itemIcon = itemIcon,
|
Nenue@3
|
592 itemQuality = itemQuality,
|
Nenue@3
|
593 itemID = itemID
|
Nenue@3
|
594
|
Nenue@3
|
595 --]]
|
Nenue@3
|
596
|
Nenue@4
|
597 self.Icon:SetTexture(self.icon)
|
Nenue@2
|
598
|
Nenue@4
|
599 self.Name:SetText(self.name)
|
Nenue@4
|
600 self.Count:SetText(self.shipmentsReady)
|
Nenue@4
|
601 self.Done:SetShown(self.shipmentsReady and (self.shipmentsReady >= 1))
|
Nenue@2
|
602
|
Nenue@3
|
603
|
Nenue@3
|
604 -- flag as complete
|
Nenue@4
|
605 if ( self.shipmentsReady == self.shipmentsTotal ) and (not self.isBeingResearched) then
|
Nenue@2
|
606 self.Swipe:SetCooldownUNIX(0, 0);
|
Nenue@2
|
607 self.Done:Show();
|
Nenue@4
|
608 self.isComplete = true
|
Nenue@2
|
609 else
|
Nenue@4
|
610 self.Swipe:SetCooldownUNIX(self.creationTime or 0 , self.duration or 0);
|
Nenue@2
|
611 end
|
Nenue@2
|
612
|
Nenue@4
|
613 local hasPickups = (self.isComplete or (self.shipmentsTotal and (self.shipmentsReady > 0)))
|
Nenue@4
|
614 self.Background:SetAlpha(hasPickups and 1 or 0.1)
|
Nenue@4
|
615 end
|
Nenue@4
|
616 local time = time
|
Nenue@4
|
617 function ShipmentsHandler:OnUpdate()
|
Nenue@2
|
618
|
Nenue@4
|
619 if (self.shipmentsReady and self.shipmentsTotal) and (self.shipmentsReady ~= self.shipmentsTotal) then
|
Nenue@4
|
620 local timeLeft = self.creationTime + self.duration - time()
|
Nenue@4
|
621 self.TimeLeft:SetText('Next: '.. GetTimeLeftString(timeLeft) .. ' |cFFFFFF00'..self.shipmentsTotal..' orders|r')
|
Nenue@4
|
622 elseif self.isStale then
|
Nenue@3
|
623 self.TimeLeft:SetText('|cFFFF0000Needs refresh|r')
|
Nenue@4
|
624 elseif self.isBeingResearched then
|
Nenue@4
|
625 self.TimeLeft:SetText(GetTimeLeftString(self.researchStartTime + self.researchDuration - time()))
|
Nenue@2
|
626 else
|
Nenue@2
|
627 self.TimeLeft:SetText('Complete!')
|
Nenue@2
|
628 end
|
Nenue@2
|
629
|
Nenue@2
|
630 end
|
Nenue@2
|
631
|
Nenue@3
|
632 function ShipmentsHandler:OnEnter()
|
Nenue@4
|
633
|
Nenue@4
|
634 if ( self.shipmentsReady and self.shipmentsTotal ) then
|
Nenue@2
|
635 GameTooltip:SetOwner(self, 'ANCHOR_LEFT')
|
Nenue@4
|
636
|
Nenue@4
|
637 GameTooltip:AddLine(self.Owner:GetText(), self.Owner:GetTextColor())
|
Nenue@4
|
638 GameTooltip:AddLine(self.shipmentType)
|
Nenue@4
|
639 GameTooltip:AddLine(self.shipmentsReady .. ' of '.. self.shipmentsTotal)
|
Nenue@2
|
640 GameTooltip:Show()
|
Nenue@2
|
641 end
|
Nenue@2
|
642 end
|
Nenue@2
|
643
|
Nenue@3
|
644 function ShipmentsHandler:OnLeave()
|
Nenue@2
|
645 if GameTooltip:IsOwned(self) then
|
Nenue@2
|
646 GameTooltip:Hide()
|
Nenue@2
|
647 end
|
Nenue@2
|
648 end
|
Nenue@2
|
649
|
Nenue@3
|
650 function ShipmentsHandler:OnClick(button)
|
Nenue@3
|
651 if button == 'RightButton' then
|
Nenue@4
|
652 self.handler:FreeBlock(self)
|
Nenue@3
|
653 end
|
Nenue@1
|
654 end |