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