comparison ClassPlan.lua @ 5:4e1883842abf

- use of SetShown() for combat visibility toggle
author Nenue
date Tue, 18 Oct 2016 01:50:06 -0400
parents 4c7e9efec4b5
children 48001b6a9496
comparison
equal deleted inserted replaced
4:4c7e9efec4b5 5:4e1883842abf
69 if self:IsVisible() then 69 if self:IsVisible() then
70 self:Refresh() 70 self:Refresh()
71 end 71 end
72 end 72 end
73 73
74 MissionsHandler.OnGetItem = function(data)
75 if data.missionEndTime < GI_currentTime then
76 data.isComplete = true
77 end
78 end
79
74 MissionsHandler.FreeBlock = function(self, block) 80 MissionsHandler.FreeBlock = function(self, block)
75 end 81 end
76 82
77 MissionsHandler.SortHandler = function (a,b) 83 MissionsHandler.SortHandler = function (a,b)
78 local result = false 84 local result = false
201 self:Refresh() 207 self:Refresh()
202 end 208 end
203 end 209 end
204 210
205 function core:OnLoad () 211 function core:OnLoad ()
206 self:RegisterUnitEvent('UNIT_PORTRAIT_UPDATE', 'player')
207 self:RegisterEvent('PLAYER_LOGIN') 212 self:RegisterEvent('PLAYER_LOGIN')
208 self:RegisterEvent('PLAYER_ENTERING_WORLD') 213 self:RegisterEvent('PLAYER_ENTERING_WORLD')
209 self:RegisterEvent('ADDON_LOADED') 214 self:RegisterEvent('ADDON_LOADED')
210 self:RegisterEvent('PLAYER_REGEN_ENABLED') 215 self:RegisterEvent('PLAYER_REGEN_ENABLED')
216 self:RegisterEvent('PLAYER_REGEN_DISABLED')
211 -- Blizzard_GarrisonUI already fires a shipment data request for GARRISON_SHIPMENT_RECEIVED; this is unlikely to 217 -- Blizzard_GarrisonUI already fires a shipment data request for GARRISON_SHIPMENT_RECEIVED; this is unlikely to
212 218
213 219
214 self:AddHandler('missions', MissionsHandler) 220 self:AddHandler('missions', MissionsHandler)
215 self:AddHandler('shipments', ShipmentsHandler) 221 self:AddHandler('shipments', ShipmentsHandler)
221 function core:Reanchor() 227 function core:Reanchor()
222 228
223 229
224 self:ClearAllPoints() 230 self:ClearAllPoints()
225 231
232 local anchorTo = 'TOP'
226 self.anchorParent = UIParent 233 self.anchorParent = UIParent
227 for i, name in ipairs(parentFrames) do 234 for i, name in ipairs(parentFrames) do
228 local frame = _G[name] 235 local frame = _G[name]
229 if frame then 236 if frame then
230 if not BOUND_FRAMES[frame] then 237 if not BOUND_FRAMES[frame] then
231 BOUND_FRAMES[frame] = {visible = frame:IsVisible()} 238 BOUND_FRAMES[frame] = {visible = (frame:IsVisible() and frame:IsShown())}
232 hooksecurefunc(frame, 'Show', function() 239 hooksecurefunc(frame, 'Show', function()
233 BOUND_FRAMES[frame].visible = true 240 BOUND_FRAMES[frame].visible = true
234 print(frame:GetName(), 'Show', 'reanchor trigger') 241 print(frame:GetName(), 'Show', 'reanchor trigger')
235 self:Reanchor() 242 self:Reanchor()
236 end) 243 end)
237 hooksecurefunc(frame, 'Hide', function() 244 hooksecurefunc(frame, 'Hide', function()
238 BOUND_FRAMES[frame].visible = false 245 BOUND_FRAMES[frame].visible = nil
239 print(frame:GetName(), 'Hide', 'reanchor trigger') 246 print(frame:GetName(), 'Hide', 'reanchor trigger')
240 self:Reanchor() 247 self:Reanchor()
241 end) 248 end)
242 end 249 end
243 print('f:', frame:GetName(), frame:IsVisible()) 250 print('f:', frame:GetName(), BOUND_FRAMES[frame].visible)
244 if BOUND_FRAMES[frame].visible then 251 if BOUND_FRAMES[frame].visible then
245 self.anchorParent = frame 252 self.anchorParent = frame
253 anchorTo = 'BOTTOM'
246 break 254 break
247 end 255 end
248 end 256 end
249 end 257 end
250 print('|cFFFF8800Using ' .. tostring(self.anchorParent:GetName()) .. ' as anchor point') 258 print('|cFFFF8800Using ' .. tostring(self.anchorParent:GetName()) .. '-'..anchorTo..' as anchor point')
251 259
252 if self:IsVisible() then 260 if self:IsShown() then
253 self:SetPoint('TOP', ClassPlanButton, 'BOTTOM', 0, 0)
254 ClassPlanButton.Background:Show() 261 ClassPlanButton.Background:Show()
255 ClassPlanButton:SetWidth(600) 262 ClassPlanButton:SetWidth(600)
256 else 263 else
257 ClassPlanButton.Background:Hide() 264 ClassPlanButton.Background:Hide()
258 ClassPlanButton:SetWidth(200) 265 ClassPlanButton:SetWidth(200)
259 end 266 end
260 267
261 ClassPlanButton:SetPoint('TOP', self.anchorParent, (self.anchorPoint == UIParent) and 'TOP' or 'BOTTOM', 0, 0) 268 self:SetPoint('TOP', ClassPlanButton, 'BOTTOM', 0, 0)
262 269 ClassPlanButton:ClearAllPoints()
270 ClassPlanButton:SetPoint('TOP', self.anchorParent, anchorTo, 0, 0)
271
272 print(ClassPlanButton:GetPoint(1))
263 end 273 end
264 274
265 function core:AddHandler(name, prototype) 275 function core:AddHandler(name, prototype)
266 self.prototypes[name] = setmetatable(prototype, { 276 self.prototypes[name] = setmetatable(prototype, {
267 __index = blockTemplate, 277 __index = blockTemplate,
309 end 319 end
310 end 320 end
311 321
312 function core:OnEvent (event, ...) 322 function core:OnEvent (event, ...)
313 print(event) 323 print(event)
314 if event == 'UNIT_PORTRAIT_UPDATE' then 324 if event == 'PLAYER_REGEN_DISABLED' then
315 SetPortraitTexture(self.portrait, 'player') 325 self:SetShown(false)
326 elseif event == 'PLAYER_REGEN_ENABLED' then
327 self:SetShown(true)
316 elseif event == 'PLAYER_LOGIN' then 328 elseif event == 'PLAYER_LOGIN' then
317 if not self.initialized then 329 if not self.initialized then
318 self:Setup() 330 self:Setup()
319 end 331 end
320 elseif self.initialized and self.events[event] then 332 elseif self.initialized and self.events[event] then
332 344
333 345
334 local SetOwnerData = function(self, data) 346 local SetOwnerData = function(self, data)
335 local name, realm = string.match(data.profileKey, "(.+)%-(.+)") 347 local name, realm = string.match(data.profileKey, "(.+)%-(.+)")
336 local ownerText = '|c'.. data.classColor.colorStr .. name .. '|r' 348 local ownerText = '|c'.. data.classColor.colorStr .. name .. '|r'
337 if realm ~= GI_currentRealm then 349 --if realm ~= GI_currentRealm then
338 ownerText = ownerText .. ' (' .. realm .. ')' 350 --ownerText = ownerText .. ' (' .. realm .. ')'
339 end 351 --end
340 self.Owner:SetText(ownerText) 352 self.Owner:SetText(ownerText)
341 self.Background:SetColorTexture(data.classColor.r, data.classColor.g, data.classColor.b) 353 self.Name:SetTextColor(data.classColor.r, data.classColor.g, data.classColor.b)
354
355 if self.isComplete then
356 self.TimeLeft:SetText('Complete!')
357 self.Background:SetColorTexture(.25,.25,.25,1)
358 else
359 self.Background:SetColorTexture(0,0,0,0.5)
360 end
361
342 end 362 end
343 363
344 function core:RefreshItems(configKey, prototype) 364 function core:RefreshItems(configKey, prototype)
345 local sortedItems = self.sortedItems[configKey] 365 local sortedItems = self.sortedItems[configKey]
346 366
374 if type(block[k]) ~= 'function' then 394 if type(block[k]) ~= 'function' then
375 block[k] = v 395 block[k] = v
376 end 396 end
377 end 397 end
378 block:Refresh(data) 398 block:Refresh(data)
399 print(block.isComplete, block.missionEndTime, block.name)
379 SetOwnerData(block, data) 400 SetOwnerData(block, data)
380 401
381 block:Show() 402 block:Show()
382 lastProfile = data.profileKey 403 lastProfile = data.profileKey
383 end 404 end
406 self:Reanchor() 427 self:Reanchor()
407 self:SetHeight(self.currentHeight) 428 self:SetHeight(self.currentHeight)
408 end 429 end
409 430
410 function core:Toggle() 431 function core:Toggle()
411 if self:IsVisible() then 432 if self:IsShown() then
412 self:Hide() 433 self:Hide()
413 else 434 else
414 self:Show() 435 self:Show()
415 end 436 end
416 437
417 if self.data then 438 if self.data then
418 self.data.IsShown = self:IsVisible() 439 self.data.IsShown = self:IsShown()
419 end 440 end
420 end 441 end
421 442
422 function core:OnUpdate() 443 function core:OnUpdate()
423 if self.fadeTimer and self.fadeTimer < GetTime() then 444 if self.fadeTimer and self.fadeTimer < GetTime() then
481 end 502 end
482 end 503 end
483 end 504 end
484 505
485 function MissionsHandler:OnComplete() 506 function MissionsHandler:OnComplete()
486 self.isComplete = true 507 print('flagging complete', self.name)
487 self:Refresh() 508 self:Refresh()
488 end 509 end
489 510
490 function MissionsHandler:OnUpdate() 511 function MissionsHandler:OnUpdate()
491 if self.isComplete then 512 if self.isComplete then
515 536
516 537
517 local r,g,b = 1, 1, 1 538 local r,g,b = 1, 1, 1
518 if self.isRare then 539 if self.isRare then
519 r,g,b = 0.1, 0.4, 1 540 r,g,b = 0.1, 0.4, 1
541 self.IconBorder:SetVertexColor(r, g, b, 1)
520 end 542 end
521 543
522 544
523 --self.missionData = data 545 --self.missionData = data
524 self.Label:SetText(self.name) 546 self.Name:SetText(self.name)
525 self.Label:SetTextColor(r, g, b)
526 547
527 if #self.rewards >= 1 then 548 if #self.rewards >= 1 then
528 self.Icon:SetTexture(self.rewards[1].icon or GetItemIcon(self.rewards[1].itemID)) 549 self.Icon:SetTexture(self.rewards[1].icon or GetItemIcon(self.rewards[1].itemID))
529 self.rewardInfo = self.rewards[1] 550 self.rewardInfo = self.rewards[1]
530 else 551 else
531 self.Icon:SetAtlas(self.typeAtlas, false) 552 self.Icon:SetAtlas(self.typeAtlas, false)
532 end 553 end
533 if self.isComplete then
534 self.TimeLeft:SetText('Complete!')
535 end
536
537 self.Background:SetAlpha(self.isComplete and 1 or 0.1)
538 end 554 end
539 555
540 556
541 function MissionsHandler:OnEnter() 557 function MissionsHandler:OnEnter()
542 if self.rewardInfo and self.rewardInfo.itemID then 558 if self.rewardInfo and self.rewardInfo.itemID then