comparison ClassPlan.lua @ 1:232617b8bcd5

New Order Hall mission tracker: - record active missions and shipments across characters
author Nenue
date Thu, 13 Oct 2016 05:32:43 -0400
parents
children b8a19781f79b
comparison
equal deleted inserted replaced
0:3830a592cb0f 1:232617b8bcd5
1 SLASH_CLASSPLAN1 = "/classplan"
2 SLASH_CLASSPLAN2 = "/cp"
3 SlashCmdList.CLASSPLAN = function(args)
4 if ClassOrderPlan:IsVisible() then
5 ClassOrderPlan:Hide()
6 else
7 ClassOrderPlan:Show()
8 DEFAULT_CHAT_FRAME:AddMessage('|cFF88FF00WorldPlan|r: Order Hall Panel')
9 end
10 end
11
12 ClassOrderPlanCore = {
13 blocks = {},
14 playerFirst = true,
15 timers = {}
16 }
17 ClassPlanBlockMixin = {
18 followers = {},
19 blocks = {},
20 }
21 local core, block = ClassOrderPlanCore, ClassPlanBlockMixin
22 local print = DEVIAN_WORKSPACE and function(...) print('ClassPlan', ...) end or nop
23
24 function core:OnLoad ()
25 self:RegisterUnitEvent('UNIT_PORTRAIT_UPDATE', 'player')
26 self:RegisterEvent('GARRISON_MISSION_STARTED')
27 self:RegisterEvent('GARRISON_MISSION_FINISHED')
28 self:RegisterEvent('PLAYER_LOGIN')
29 self:RegisterEvent('PLAYER_ENTERING_WORLD')
30 end
31
32
33 function core:OnEvent (event, ...)
34 if event == 'UNIT_PORTRAIT_UPDATE' then
35 SetPortraitTexture(self.portrait, 'player')
36 elseif event == 'PLAYER_LOGIN' then
37 if not self.initialized then
38 if IsLoggedIn() then
39 WorldPlanData.OrderHall = WorldPlanData.OrderHall or {}
40 self.data = WorldPlanData.OrderHall
41
42
43 local name, realm = UnitName('player')
44 realm = realm or GetRealmName()
45 self.profileKey = name .. '-' .. realm
46 if not self.data[self.profileKey] then
47 self.data[self.profileKey] = {}
48 end
49 self.profile = self.data[self.profileKey]
50
51 self.initialized = true
52 print('initialized')
53 end
54 end
55 else
56 self:Refresh ()
57 end
58 end
59
60 function core:UpdateList()
61 self.sortedMissions = self.sortedMissions or {}
62 table.wipe(self.sortedMissions)
63
64 for name, profile in pairs(self.data) do
65 local isMine = (profile == self.profile)
66 for index, data in pairs(profile.missions) do
67
68 data.classColor = profile.classColor or {r = 0.7, g = 0.7, b =0.7}
69
70 data.profileKey = name
71 data.isMine = (profile == self.profile)
72 tinsert(self.sortedMissions, data)
73 end
74 end
75
76 for i, v in ipairs(self.sortedMissions) do
77 print(i, v.missionEndTime, v.name)
78 end
79
80
81 table.sort(self.sortedMissions, function(a,b)
82 local result = false
83 if not a or not b then
84 result = true
85 else
86
87 if (a.isMine ~= b.isMine) and self.playerFirst then
88 result = a.isMine
89 else
90 if (not b.missionEndTime) or (not a.missionEndTime) then
91 print('missing article', b.missionEndTime, a.missionEndTime)
92 end
93
94 result = ( b.missionEndTime > a.missionEndTime)
95 end
96 end
97
98 print('cmp', (b and (b.missionEndTime .. ' ' .. tostring(b.isMine)) or '-'), '>', (a and (a.missionEndTime .. ' ' .. tostring(a.isMine)) or '-'), result, n)
99 return result
100 end)
101 self.isStale = nil
102
103 local lastProfile
104 local numItems = #self.sortedMissions
105 for i, data in ipairs(self.sortedMissions) do
106 local block = self.blocks[i]
107 if not block then
108 block = CreateFrame('Frame', nil, self, 'ClassPlanBlock')
109 block:SetID(i)
110 self.numBlocks = (self.numBlocks or 0) + 1
111
112 if self.lastBlock then
113 block:SetPoint('TOPLEFT', self.lastBlock, 'BOTTOMLEFT', 0, 0)
114 else
115 block:SetPoint('TOPLEFT', self.portrait, 'TOPRIGHT', 0, 0)
116 end
117 self.lastBlock = block
118 self.blocks[i] = block
119 end
120
121 local r,g,b = 1, 1, 1
122 if data.isRare then
123 r,g,b = 0.1, 0.4, 1
124 end
125 if data.isMine then
126 block.Icon:SetVertexColor(0,1,0,1)
127 else
128 block.Icon:SetVertexColor(1,1,1)
129 end
130
131
132 --block.missionData = data
133 block.missionID = data.missionID
134 block.missionEndTime = data.missionEndTime
135 block.Icon:SetAtlas(data.typeAtlas, false)
136 block.Label:SetText(data.name)
137 block.Label:SetTextColor(r, g, b)
138
139 if lastProfile ~= data.profileKey then
140 block.Owner:SetText(data.profileKey)
141 block.Owner:SetTextColor(data.classColor.r, data.classColor.g, data.classColor.b)
142 else
143 block.Owner:SetText(nil)
144 end
145 block.Background:SetColorTexture(data.classColor.r, data.classColor.g, data.classColor.b, 0.5)
146
147 block:Show()
148 lastProfile = data.profileKey
149 end
150 for i = numItems + 1, self.numBlocks do
151 if self.blocks[i] then
152 self.blocks[i]:Hide()
153 end
154 end
155 end
156
157 function core:OnShow()
158 if self.isStale then
159 print('updating items on show')
160 self:UpdateList()
161 end
162 end
163
164 function core:Refresh ()
165 if not self.profile then
166 return
167 end
168
169 self.items = C_Garrison.GetLandingPageItems(LE_GARRISON_TYPE_7_0)
170
171 self.profile.missions = self.profile.missions or {}
172
173 self.profile.classColor = RAID_CLASS_COLORS[select(2, UnitClass('player'))]
174
175
176 print('|cFF0088FFLocal Scoop|r:', self.profileKey)
177 if #self.items >= 1 then
178 table.wipe(self.profile.missions)
179 for index, data in ipairs(self.items) do
180 print('', data.name)
181 print(' |cFF00FF00', data.timeLeft .. '|r', date("%A %I:%m %p", data.missionEndTime))
182 tinsert(self.profile.missions, data)
183 end
184 end
185
186 if self:IsVisible() then
187 self:UpdateList()
188 else
189 print('items update pending')
190 self.isStale = true
191 end
192 end
193
194 function block:OnUpdate()
195 if self.missionEndTime then
196 local timeLeft = self.missionEndTime - time()
197 if timeLeft < 0 then
198 self.TimeLeft:SetText('Complete!')
199 else
200 local days = floor(timeLeft/(24*3600))
201 local hours = floor(mod(timeLeft, (24*3600)) / 3600)
202 local minutes = floor(mod(timeLeft, 3600) / 60)
203 local seconds = mod(timeLeft, 60)
204 self.TimeLeft:SetText(
205 ((days > 0) and (days .. ' d') or '') ..
206 ((hours > 0) and (' '.. hours .. ' hr') or '')..
207 ((minutes > 0) and (' ' .. minutes .. ' min' or ''))
208 , 1,1,1)
209 end
210 else
211 self.TimeLeft:SetText(self.missionEndTime)
212 end
213 end