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