annotate Veneer.lua @ 97:5476337198ec

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