annotate Veneer.lua @ 89:74e714637d6a

WorldStateProgress fade-in is called for all visibility check falses
author Nenue
date Fri, 21 Oct 2016 18:03:35 -0400
parents b107b4df7eb6
children 6e2cb847c3c6
rev   line source
Nenue@88 1 -- Veneer Custom Interface Framework
Nenue@88 2 -- 1. vn OnLoad
Nenue@88 3 -- 2. OnEvent where IsLoggedIn() == true
Nenue@88 4 -- 3. Setup() where (not self.initialized)
Nenue@88 5 -- 4. Update()
Nenue@88 6 -- 5. Reanchor()
Nenue@84 7
Nenue@84 8 SLASH_VENEER1 = "/veneer"
Nenue@84 9 SLASH_VENEER2 = "/vn"
Nenue@84 10
Nenue@84 11 SlashCmdList.VENEER = function(cmd)
Nenue@84 12 end
Nenue@88 13
Nenue@84 14 VeneerCore = {
Nenue@84 15 Frames = {},
Nenue@84 16 ConfigLayers = {},
Nenue@84 17 FrameClusters = {},
Nenue@84 18 parserDepth = 0,
Nenue@84 19 pendingCalls = {},
Nenue@84 20 }
Nenue@84 21 VeneerHandlerMixin = {
Nenue@88 22
Nenue@87 23 anchorPoint = 'CENTER', -- indicates the initial cluster group point
Nenue@87 24 --anchorPath = 'BOTTOM', -- indicates the point from which the frame is anchored in a cluster arrangement
Nenue@88 25 OnHide = function()
Nenue@88 26 Veneer:DynamicReanchor()
Nenue@88 27 end,
Nenue@88 28 OnShow = function(self)
Nenue@88 29 self:Reanchor()
Nenue@88 30 Veneer:StaticReanchor(self)
Nenue@88 31 end
Nenue@84 32 }
Nenue@88 33 VeneerAnimationMixin = {}
Nenue@84 34 local print = DEVIAN_WORKSPACE and function(...) print('Veneer', ...) end or nop
Nenue@80 35 local wipe = table.wipe
Nenue@0 36
Nenue@59 37 local defaults = {
Nenue@59 38 enableAll = true,
Nenue@59 39 enableModule = {
Nenue@59 40 BuffFrame = true,
Nenue@59 41 },
Nenue@59 42 BuffFrame = {
Nenue@59 43 width = 48,
Nenue@59 44 height = 48,
Nenue@59 45 }
Nenue@59 46 }
Nenue@84 47
Nenue@71 48 local configMode
Nenue@79 49 local anonID = 0
Nenue@79 50 local tostring = tostring
Nenue@79 51 local IsFrameHandle = IsFrameHandle
Nenue@79 52 local GetAnonymousName = function(key)
Nenue@79 53 if not key then
Nenue@71 54 anonID = anonID + 1
Nenue@79 55 key = anonID
Nenue@71 56 end
Nenue@79 57 return 'VN' .. key
Nenue@71 58 end
Nenue@79 59 local GetTableName = function(table)
Nenue@79 60 return (IsFrameHandle(table) and table:GetName()) or tostring(table)
Nenue@79 61 end
Nenue@79 62
Nenue@87 63 local OFFSET_PARALLELS = {
Nenue@87 64 TOP = {'LEFT', 'RIGHT', 'SetHeight'},
Nenue@87 65 BOTTOM = {'LEFT', 'RIGHT', 'SetHeight'},
Nenue@87 66 LEFT = {'TOP', 'BOTTOM', 'SetWidth'},
Nenue@87 67 RIGHT = {'TOP', 'BOTTOM', 'SetWidth'},
Nenue@87 68 }
Nenue@87 69 local ANCHOR_OFFSET_POINT = {
Nenue@87 70 TOP = 'BOTTOM',
Nenue@87 71 TOPLEFT = 'BOTTOMRIGHT',
Nenue@87 72 TOPRIGHT = 'BOTTOMLEFT',
Nenue@87 73 LEFT = 'RIGHT',
Nenue@87 74 RIGHT = 'LEFT',
Nenue@87 75 CENTER = 'CENTER',
Nenue@87 76 BOTTOM = 'TOP',
Nenue@87 77 BOTTOMRIGHT = 'TOPLEFT',
Nenue@87 78 BOTTOMLEFT = 'TOPRIGHT',
Nenue@87 79 }
Nenue@87 80 local ANCHOR_INSET_DELTA = {
Nenue@87 81 TOP = {0, -1},
Nenue@87 82 TOPLEFT = {1, -1},
Nenue@87 83 TOPRIGHT = {-1,-1},
Nenue@87 84 LEFT = {1, 0},
Nenue@87 85 BOTTOMLEFT = {1, 1},
Nenue@87 86 BOTTOM = {0, 1},
Nenue@87 87 BOTTOMRIGHT = {-1, 1},
Nenue@87 88 RIGHT = {-1, 0},
Nenue@87 89 CENTER = {0, 0},
Nenue@72 90 }
Nenue@72 91
Nenue@84 92 function VeneerCore:print(...)
Nenue@84 93 local txt = '|cFFFFFF00Veneer|r:'
Nenue@84 94 for i = 1, select('#', ...) do
Nenue@84 95 txt = txt .. ' '.. tostring(select(i, ...))
Nenue@84 96 end
Nenue@84 97
Nenue@84 98 DEFAULT_CHAT_FRAME:AddMessage(txt)
Nenue@84 99 end
Nenue@84 100
Nenue@84 101 function VeneerCore:OnLoad()
Nenue@84 102 print('|cFFFFFF00Veneer!|r')
Nenue@84 103 self:RegisterEvent('ADDON_LOADED')
Nenue@84 104 self:RegisterEvent('PLAYER_LOGIN')
Nenue@84 105
Nenue@84 106 self.DEVIAN_PNAME = 'Veneer'
Nenue@84 107 self:RegisterForDrag('LeftButton')
Nenue@88 108
Nenue@88 109
Nenue@84 110 end
Nenue@84 111
Nenue@84 112 function VeneerCore:OnEvent(event, ...)
Nenue@84 113 if event == 'ADDON_LOADED' or event == 'PLAYER_LOGIN' then
Nenue@84 114 if IsLoggedIn() and not self.intialized then
Nenue@84 115 self:Setup()
Nenue@87 116 self:UnregisterEvent('ADDON_LOADED')
Nenue@87 117 self:UnregisterEvent('PLAYER_LOGIN')
Nenue@87 118 self:Reanchor()
Nenue@87 119 self:Update()
Nenue@84 120 end
Nenue@84 121 end
Nenue@84 122 end
Nenue@84 123
Nenue@84 124 function VeneerCore:OnDragStart()
Nenue@84 125 self:StartMoving()
Nenue@84 126 end
Nenue@84 127
Nenue@84 128 function VeneerCore:OnDragStop()
Nenue@84 129 self:StopMovingOrSizing()
Nenue@84 130 end
Nenue@84 131
Nenue@84 132 function VeneerCore:Setup ()
Nenue@87 133 self.initialized = true
Nenue@84 134 if (not VeneerData) or (not VeneerData.version) then
Nenue@84 135 VeneerData = defaults
Nenue@84 136 end
Nenue@84 137 self.data = VeneerData
Nenue@87 138 self:ExecuteOnClusters(nil, 'Setup')
Nenue@87 139 end
Nenue@84 140
Nenue@84 141
Nenue@87 142 function VeneerCore:GetClusterFromArgs (...)
Nenue@87 143 local primaryAnchor
Nenue@87 144 local insertPosition
Nenue@87 145 local clusterTable = self.FrameClusters
Nenue@87 146 for i = 1, select('#', ...) do
Nenue@87 147 local arg = select(i, ...)
Nenue@87 148 local argType = type(arg)
Nenue@87 149 if argType == 'string' then
Nenue@87 150 if not primaryAnchor then
Nenue@87 151 primaryAnchor = arg
Nenue@87 152 end
Nenue@87 153 clusterTable[arg] = clusterTable[arg] or {}
Nenue@87 154 clusterTable = clusterTable[arg]
Nenue@87 155 print(string.rep(' ', i)..'anchor cluster', i, arg)
Nenue@87 156 elseif argType == 'boolean' then
Nenue@87 157 insertPosition = 1
Nenue@87 158 end
Nenue@87 159 end
Nenue@87 160 if not primaryAnchor then
Nenue@87 161 primaryAnchor = 'TOPLEFT'
Nenue@87 162 end
Nenue@87 163 if not insertPosition then
Nenue@87 164 insertPosition = #clusterTable + 1
Nenue@87 165 end
Nenue@87 166 return primaryAnchor, clusterTable, insertPosition
Nenue@84 167 end
Nenue@84 168
Nenue@84 169 function VeneerCore:AddHandler(handler, ...)
Nenue@84 170 print('*** Adding handler:', handler.moduleName or handler:GetName())
Nenue@87 171
Nenue@87 172 local anchorGroup, clusterTable, clusterIndex = self:GetClusterFromArgs(...)
Nenue@87 173 if clusterIndex == 1 then
Nenue@87 174 for i, frame in ipairs(clusterTable) do
Nenue@87 175 frame.clusterIndex = i + 1
Nenue@87 176 end
Nenue@84 177 end
Nenue@87 178 tinsert(clusterTable, clusterIndex, handler)
Nenue@87 179 print('cluster', anchorGroup, 'table', clusterTable, 'position', clusterIndex)
Nenue@87 180
Nenue@87 181 handler.anchorCluster = clusterTable
Nenue@87 182 handler.anchorIndex = clusterIndex
Nenue@84 183 for k,v in pairs(VeneerHandlerMixin) do
Nenue@84 184 if not handler[k] then
Nenue@87 185 print(' * from mixin:', k)
Nenue@84 186 handler[k] = v
Nenue@84 187 end
Nenue@84 188 end
Nenue@87 189 if self.initialized then
Nenue@87 190 print(' -- doing initialization')
Nenue@87 191 if handler.Setup and not handler.initialized then
Nenue@87 192 handler:Setup()
Nenue@87 193 handler.initialized = true
Nenue@87 194 end
Nenue@87 195 self:InternalReanchor(handler)
Nenue@87 196 end
Nenue@87 197 end
Nenue@87 198
Nenue@87 199 function VeneerCore:Reanchor()
Nenue@87 200 self:ExecuteOnClusters(nil, 'Reanchor')
Nenue@88 201 self:DynamicReanchor(self)
Nenue@87 202 end
Nenue@87 203
Nenue@87 204 function VeneerCore:Update()
Nenue@87 205 self:ExecuteOnClusters(nil, 'Update')
Nenue@88 206 self:Reanchor()
Nenue@87 207 end
Nenue@87 208
Nenue@87 209 -- updates anchor relations to and from the target handler
Nenue@87 210 function VeneerCore:GetAnchor(...)
Nenue@87 211
Nenue@87 212 end
Nenue@87 213
Nenue@88 214 -- Evaluates frames visibility and chains them accordingly
Nenue@88 215
Nenue@88 216 function VeneerCore:DynamicReanchor(parent)
Nenue@88 217 parent = parent or self
Nenue@88 218 print('|cFF88FF00DynamicReanchor()')
Nenue@88 219 for anchorPoint, cluster in pairs(parent.FrameClusters) do
Nenue@88 220 local lastFrame
Nenue@88 221 for index, frame in ipairs(cluster) do
Nenue@88 222 print(' |cFF00FF00'..index, frame:GetName(), frame:IsVisible())
Nenue@88 223 if frame:IsVisible() then
Nenue@88 224 anchorPoint = frame.anchorPoint
Nenue@88 225 frame:ClearAllPoints()
Nenue@88 226 if lastFrame then
Nenue@88 227 frame:SetPoint(anchorPoint, lastFrame, ANCHOR_OFFSET_POINT[anchorPoint], 0, 0)
Nenue@88 228 else
Nenue@88 229 frame:SetPoint(anchorPoint, UIParent, anchorPoint, 0, 0)
Nenue@88 230 end
Nenue@88 231 lastFrame = frame
Nenue@88 232 end
Nenue@88 233
Nenue@88 234 end
Nenue@88 235 end
Nenue@88 236 end
Nenue@88 237
Nenue@88 238 -- Evaluates the current visibility state and re-anchors adjacent blocks accordingly
Nenue@87 239 function VeneerCore:InternalReanchor(handler, printFunc)
Nenue@87 240 print('|cFF00FFFFVeneer:InternalReanchor('..handler:GetName()..')')
Nenue@87 241 local anchorPoint = handler.anchorPath or handler.anchorPoint
Nenue@87 242 local anchorParent, anchorTo = UIParent, anchorPoint
Nenue@88 243 local subPoint, subTo
Nenue@88 244 local nextFrame
Nenue@88 245 for index, frame in ipairs(handler.anchorCluster) do
Nenue@88 246 print(' |cFF00FF00'..index, frame:GetName(), frame:IsVisible())
Nenue@88 247 if frame:IsVisible() then
Nenue@88 248 if frame ~= handler then
Nenue@88 249 anchorParent = frame
Nenue@88 250 anchorTo = ANCHOR_OFFSET_POINT[anchorPoint]
Nenue@87 251
Nenue@88 252 else
Nenue@88 253 nextFrame = handler.anchorCluster[index+1]
Nenue@88 254 if nextFrame then
Nenue@88 255
Nenue@88 256 subPoint = nextFrame.anchorPath or nextFrame.anchorPoint
Nenue@88 257 subTo = ANCHOR_OFFSET_POINT[subPoint]
Nenue@88 258 nextFrame:ClearAllPoints()
Nenue@88 259 nextFrame:SetPoint(subPoint, handler, subTo, 0, 0)
Nenue@88 260 print(' -- pushing '..nextFrame:GetName()..' down the anchor chain', subPoint, subTo)
Nenue@88 261 end
Nenue@88 262 break
Nenue@87 263 end
Nenue@87 264 end
Nenue@87 265 end
Nenue@87 266
Nenue@88 267 if handler:IsVisible() then
Nenue@88 268 handler:SetPoint(anchorPoint, anchorParent, anchorTo, 0, 0)
Nenue@88 269 else
Nenue@88 270 if anchorParent and nextFrame then
Nenue@88 271 nextFrame:SetPoint(subPoint, handler, subTo, 0, 0)
Nenue@88 272 end
Nenue@88 273 end
Nenue@88 274
Nenue@87 275
Nenue@87 276 print(handler.anchorPoint, anchorParent, anchorTo)
Nenue@87 277 if printFunc then
Nenue@87 278 printFunc('|cFF88FF00'..handler:GetName()..':SetPoint(', handler.anchorPoint, anchorParent, anchorTo)
Nenue@87 279 end
Nenue@88 280 end
Nenue@87 281
Nenue@88 282 function VeneerCore:SlideBlock(frame, ...)
Nenue@89 283 local aX, aY = frame:GetLeft(), frame:GetTop()
Nenue@88 284
Nenue@89 285 frame:SetPoint('TOPLEFT', frame, 'BOTTOMLEFT', aX, aY)
Nenue@89 286 frame.animation = frame.animation or {}
Nenue@89 287 frame.animation.startX = aX
Nenue@89 288 frame.animation.startY = aY
Nenue@88 289
Nenue@89 290 local targetPoint, targetParent, targetAnchor, offsetX, offsetY = ...
Nenue@89 291 frame.BlockSlide:SetScript('OnFinished', function()
Nenue@89 292 frame:SetPoint(targetPoint, targetParent, targetAnchor, offsetX, offsetY)
Nenue@89 293 VeneerAnimationMixin.OnFinished(frame)
Nenue@89 294 end)
Nenue@88 295
Nenue@84 296 end
Nenue@84 297
Nenue@88 298
Nenue@84 299 function VeneerCore:ExecuteOnClusters(layer, method)
Nenue@84 300 self.parserDepth = self.parserDepth + 1
Nenue@84 301 if not layer then
Nenue@87 302 if self.parserDepth > 1 then
Nenue@84 303 tinsert(self.pendingCalls, method)
Nenue@84 304 print('delaying walk for', method)
Nenue@84 305 return
Nenue@84 306 end
Nenue@87 307 print('|cFF00FF00Veneer:ExecuteOnClusters|r('..tostring(layer)..', '..method..')')
Nenue@84 308 else
Nenue@87 309 print(' Level '..self.parserDepth)
Nenue@84 310 end
Nenue@87 311
Nenue@87 312 layer = layer or self.FrameClusters
Nenue@84 313 for anchor, cluster in pairs(layer) do
Nenue@84 314 for index, frame in ipairs(cluster) do
Nenue@87 315 print(' '..anchor..'.'..index..' = '..frame:GetName())
Nenue@84 316 if frame[method] then
Nenue@87 317 print(' |cFF00FF00'..frame:GetName())
Nenue@87 318 frame[method](frame, true)
Nenue@84 319 end
Nenue@84 320 end
Nenue@84 321 if cluster.FrameClusters then
Nenue@84 322 self:ExecuteOnClusters(cluster.FrameClusters, method)
Nenue@84 323 end
Nenue@84 324 end
Nenue@84 325 self.parserDepth = self.parserDepth - 1
Nenue@84 326
Nenue@84 327 if (self.parserDepth == 0) and (#self.pendingCalls >= 1) then
Nenue@84 328 local delayedMethod = tremove(self.pendingCalls, 1)
Nenue@84 329 print('starting delayed walk for', delayedMethod)
Nenue@84 330 self:ExecuteOnClusters(nil, delayedMethod)
Nenue@84 331 end
Nenue@84 332 end
Nenue@84 333
Nenue@72 334 local VeneerButton_OnDragStart = function(self)
Nenue@72 335 self.startingLeft = self:GetLeft()
Nenue@72 336 self.startingBottom = self:GetBottom()
Nenue@72 337 self.anchors = self.anchors or {}
Nenue@72 338 table.wipe(self.anchors)
Nenue@72 339
Nenue@72 340 local frame = self:GetParent()
Nenue@72 341 local n = frame:GetNumPoints()
Nenue@72 342 for i = 1, n do
Nenue@72 343 local anchor, parent, relative, x, y = frame:GetPoint(i)
Nenue@72 344 self.anchors[i] = {
Nenue@72 345 anchor = anchor,
Nenue@72 346 parent = parent,
Nenue@72 347 relative = relative,
Nenue@72 348 x = x,
Nenue@72 349 y = y
Nenue@72 350 }
Nenue@72 351 end
Nenue@72 352
Nenue@72 353 print(self:GetName(), 'start moving', self.startingLeft, self.startingBottom)
Nenue@72 354 self:StartMoving()
Nenue@72 355 end
Nenue@72 356
Nenue@72 357 local VeneerButton_OnDragStop = function(self)
Nenue@72 358 self:StopMovingOrSizing()
Nenue@72 359 if self.OnDragStop then
Nenue@72 360 self.OnDragStop(self)
Nenue@72 361 else
Nenue@72 362 local frame = self:GetParent()
Nenue@72 363 local dx = self:GetLeft() - self.startingLeft
Nenue@72 364 local dy = self:GetBottom() - self.startingBottom
Nenue@72 365
Nenue@72 366 frame:ClearAllPoints()
Nenue@72 367 for i, point in ipairs(self.anchors) do
Nenue@72 368 frame:SetPoint(point.anchor, point.parent, point.relative, point.x + dx, point.y + dy)
Nenue@72 369 print('adjusting anchor', point.anchor, point.parent, point.relative, point.x + dx, point.y + dy)
Nenue@72 370 end
Nenue@72 371 end
Nenue@72 372 end
Nenue@72 373
Nenue@72 374 local Veneer_FixMovers = function()
Nenue@72 375 for frame, veneer in pairs(veneers) do
Nenue@72 376 if veneer:IsMoving() then
Nenue@72 377 VeneerButton_OnDragStop(veneer)
Nenue@72 378 end
Nenue@72 379 end
Nenue@72 380 end
Nenue@71 381
Nenue@71 382 local VeneerButton_Update = function(self)
Nenue@71 383 if configMode then
Nenue@72 384 self:SetScript('OnDragStart', VeneerButton_OnDragStart)
Nenue@72 385 self:SetScript('OnDragStop', VeneerButton_OnDragStop)
Nenue@72 386 self:SetMovable(true)
Nenue@72 387 self:EnableMouse(true)
Nenue@71 388 self:RegisterForDrag('LeftButton')
Nenue@71 389
Nenue@71 390 self.bg:SetColorTexture(0,1,0,0.5)
Nenue@72 391 for i, region in ipairs(self.configLayers) do
Nenue@72 392 region:Show()
Nenue@72 393 end
Nenue@72 394 self:Show()
Nenue@71 395 else
Nenue@71 396
Nenue@71 397 self:SetScript('OnDragStart', self.StartMoving)
Nenue@71 398 self:SetScript('OnDragStop', self.StopMovingOrSizing)
Nenue@71 399 self:SetMovable(false)
Nenue@71 400 self:EnableMouse(false)
Nenue@71 401
Nenue@71 402 self.bg:SetColorTexture(0,1,0,0)
Nenue@72 403 for i, region in ipairs(self.configLayers) do
Nenue@72 404 region:Hide()
Nenue@72 405 end
Nenue@72 406 if self.isHidden then
Nenue@72 407 self:Hide()
Nenue@72 408 end
Nenue@72 409
Nenue@71 410 end
Nenue@71 411 end
Nenue@71 412
Nenue@71 413 local ToggleVeneerConfig = function()
Nenue@71 414 if configMode then
Nenue@71 415 configMode = false
Nenue@84 416 Veneer:print('Config mode off.')
Nenue@71 417 else
Nenue@71 418 configMode = true
Nenue@84 419 Veneer:print('Config mode on.')
Nenue@71 420 end
Nenue@71 421
Nenue@71 422 for frame, veneer in pairs(veneers) do
Nenue@71 423 VeneerButton_Update(veneer)
Nenue@71 424 end
Nenue@71 425 end
Nenue@71 426
Nenue@71 427 local VeneerButton_OnShow = function(self)
Nenue@71 428 VeneerButton_Update(self)
Nenue@71 429 end
Nenue@71 430
Nenue@88 431 -- Takes frame handle and assigns a block to it
Nenue@84 432 function VeneerCore:Acquire (frame, template)
Nenue@71 433 if not frame then
Nenue@71 434 print('|cFFFF4400Unable to acquire frame...|r')
Nenue@71 435 return
Nenue@71 436 end
Nenue@84 437 local veneer = self.Frames[frame]
Nenue@84 438 if not veneer then
Nenue@84 439 local name = type(frame) == 'table' and GetTableName(frame) or GetAnonymousName()
Nenue@84 440 veneer = CreateFrame('Frame', name, frame, template or 'VeneerTemplate')
Nenue@84 441 print('+veneer', name)
Nenue@71 442
Nenue@84 443 veneer:SetAllPoints(frame)
Nenue@84 444 veneer:SetParent(frame)
Nenue@84 445 veneer.label:SetText(name)
Nenue@84 446 veneer.bg:SetColorTexture(0,0,0,0)
Nenue@84 447 veneer:Hide()
Nenue@84 448 veneer:EnableMouse(false)
Nenue@84 449
Nenue@84 450 veneer:SetScript('OnShow', VeneerButton_OnShow)
Nenue@84 451
Nenue@84 452 -- find current X/Y
Nenue@84 453 veneer.currentLeft = frame:GetLeft()
Nenue@84 454 veneer.currentTop = frame:GetTop()
Nenue@84 455 self.Frames[frame] = veneer
Nenue@71 456 end
Nenue@71 457
Nenue@84 458 return veneer
Nenue@71 459 end
Nenue@0 460
Nenue@88 461 function VeneerHandlerMixin:Reanchor (anchorAll)
Nenue@88 462 if not anchorAll then
Nenue@88 463 Veneer:InternalReanchor(self)
Nenue@88 464 end
Nenue@80 465
Nenue@88 466 end
Nenue@80 467
Nenue@88 468 function VeneerAnimationMixin:OnPlay()
Nenue@88 469 PlaySoundKitID(229)
Nenue@89 470 self.animating = true
Nenue@88 471 print('|cFF00FF00Anim:OnPlay|r @', unpack(self.sourcePoint))
Nenue@88 472 end
Nenue@88 473 function VeneerAnimationMixin:OnStop()
Nenue@88 474 PlaySoundKitID(229)
Nenue@89 475 self.animating = nil
Nenue@89 476 print('|cFF00FF00Anim:OnFinish|r @', unpack(self.destPoint))
Nenue@88 477 end
Nenue@88 478 function VeneerAnimationMixin:OnFinished()
Nenue@88 479 PlaySoundKitID(229)
Nenue@89 480 self.animating = nil
Nenue@88 481 print('|cFF00FF00Anim:OnFinish|r @', unpack(self.destPoint))
Nenue@88 482 end