annotate Veneer.lua @ 80:bb6b532c5d2f

- added "world state" frame for zone-specific currencies and context-based artifact/experience progress
author Nenue
date Tue, 11 Oct 2016 08:03:41 -0400
parents 0784b87f9722
children 16b300d96724
rev   line source
Nenue@54 1 -- Veneer
Nenue@71 2 -- Base framework for making things draggable.
Nenue@0 3
Nenue@75 4 local vn, print = LibStub("LibKraken").register(Veneer)
Nenue@80 5 local wipe = table.wipe
Nenue@0 6
Nenue@59 7 local defaults = {
Nenue@59 8 enableAll = true,
Nenue@59 9 enableModule = {
Nenue@59 10 BuffFrame = true,
Nenue@59 11 },
Nenue@59 12 BuffFrame = {
Nenue@59 13 width = 48,
Nenue@59 14 height = 48,
Nenue@59 15 }
Nenue@59 16 }
Nenue@71 17 local configMode
Nenue@71 18 local veneers = {}
Nenue@71 19
Nenue@79 20 local anonID = 0
Nenue@79 21
Nenue@79 22 local tostring = tostring
Nenue@79 23 local IsFrameHandle = IsFrameHandle
Nenue@79 24 local GetAnonymousName = function(key)
Nenue@79 25 if not key then
Nenue@71 26 anonID = anonID + 1
Nenue@79 27 key = anonID
Nenue@71 28 end
Nenue@79 29 return 'VN' .. key
Nenue@71 30 end
Nenue@79 31 local GetTableName = function(table)
Nenue@79 32 return (IsFrameHandle(table) and table:GetName()) or tostring(table)
Nenue@79 33 end
Nenue@79 34
Nenue@79 35
Nenue@71 36
Nenue@72 37 local anchor_coefficients = {
Nenue@72 38 ['TOP'] = function(x, y) return x, y end,
Nenue@72 39 ['BOTTOM'] = function(x, y) return x,y end,
Nenue@72 40 ['LEFT'] = function(x, y) return x,y end,
Nenue@72 41 ['RIGHT'] = function(x,y) return x,y end,
Nenue@72 42 }
Nenue@72 43
Nenue@72 44 local VeneerButton_OnDragStart = function(self)
Nenue@72 45 self.startingLeft = self:GetLeft()
Nenue@72 46 self.startingBottom = self:GetBottom()
Nenue@72 47 self.anchors = self.anchors or {}
Nenue@72 48 table.wipe(self.anchors)
Nenue@72 49
Nenue@72 50 local frame = self:GetParent()
Nenue@72 51 local n = frame:GetNumPoints()
Nenue@72 52 for i = 1, n do
Nenue@72 53 local anchor, parent, relative, x, y = frame:GetPoint(i)
Nenue@72 54 self.anchors[i] = {
Nenue@72 55 anchor = anchor,
Nenue@72 56 parent = parent,
Nenue@72 57 relative = relative,
Nenue@72 58 x = x,
Nenue@72 59 y = y
Nenue@72 60 }
Nenue@72 61 end
Nenue@72 62
Nenue@72 63 print(self:GetName(), 'start moving', self.startingLeft, self.startingBottom)
Nenue@72 64 self:StartMoving()
Nenue@72 65 end
Nenue@72 66
Nenue@72 67 local VeneerButton_OnDragStop = function(self)
Nenue@72 68 self:StopMovingOrSizing()
Nenue@72 69 if self.OnDragStop then
Nenue@72 70 self.OnDragStop(self)
Nenue@72 71 else
Nenue@72 72 local frame = self:GetParent()
Nenue@72 73 local dx = self:GetLeft() - self.startingLeft
Nenue@72 74 local dy = self:GetBottom() - self.startingBottom
Nenue@72 75
Nenue@72 76 frame:ClearAllPoints()
Nenue@72 77 for i, point in ipairs(self.anchors) do
Nenue@72 78 frame:SetPoint(point.anchor, point.parent, point.relative, point.x + dx, point.y + dy)
Nenue@72 79 print('adjusting anchor', point.anchor, point.parent, point.relative, point.x + dx, point.y + dy)
Nenue@72 80 end
Nenue@72 81 end
Nenue@72 82 end
Nenue@72 83
Nenue@72 84 local Veneer_FixMovers = function()
Nenue@72 85 for frame, veneer in pairs(veneers) do
Nenue@72 86 if veneer:IsMoving() then
Nenue@72 87 VeneerButton_OnDragStop(veneer)
Nenue@72 88 end
Nenue@72 89 end
Nenue@72 90 end
Nenue@71 91
Nenue@71 92 local VeneerButton_Update = function(self)
Nenue@71 93 if configMode then
Nenue@72 94 self:SetScript('OnDragStart', VeneerButton_OnDragStart)
Nenue@72 95 self:SetScript('OnDragStop', VeneerButton_OnDragStop)
Nenue@72 96 self:SetMovable(true)
Nenue@72 97 self:EnableMouse(true)
Nenue@71 98 self:RegisterForDrag('LeftButton')
Nenue@71 99
Nenue@71 100 self.bg:SetColorTexture(0,1,0,0.5)
Nenue@72 101 for i, region in ipairs(self.configLayers) do
Nenue@72 102 region:Show()
Nenue@72 103 end
Nenue@72 104 self:Show()
Nenue@71 105 else
Nenue@71 106
Nenue@71 107 self:SetScript('OnDragStart', self.StartMoving)
Nenue@71 108 self:SetScript('OnDragStop', self.StopMovingOrSizing)
Nenue@71 109 self:SetMovable(false)
Nenue@71 110 self:EnableMouse(false)
Nenue@71 111
Nenue@71 112 self.bg:SetColorTexture(0,1,0,0)
Nenue@72 113 for i, region in ipairs(self.configLayers) do
Nenue@72 114 region:Hide()
Nenue@72 115 end
Nenue@72 116 if self.isHidden then
Nenue@72 117 self:Hide()
Nenue@72 118 end
Nenue@72 119
Nenue@71 120 end
Nenue@71 121 end
Nenue@71 122
Nenue@71 123 local ToggleVeneerConfig = function()
Nenue@71 124 if configMode then
Nenue@71 125 configMode = false
Nenue@71 126 vn:print('Config mode off.')
Nenue@71 127 else
Nenue@71 128 configMode = true
Nenue@71 129 vn:print('Config mode on.')
Nenue@71 130 end
Nenue@71 131
Nenue@71 132 for frame, veneer in pairs(veneers) do
Nenue@71 133 VeneerButton_Update(veneer)
Nenue@71 134 end
Nenue@71 135 end
Nenue@71 136
Nenue@71 137 local VeneerButton_OnShow = function(self)
Nenue@71 138 VeneerButton_Update(self)
Nenue@71 139 end
Nenue@71 140
Nenue@73 141 vn.GetVeneer = function(frame, template)
Nenue@71 142 if not frame then
Nenue@71 143 print('|cFFFF4400Unable to acquire frame...|r')
Nenue@71 144 return
Nenue@71 145 end
Nenue@71 146
Nenue@71 147 if veneers[frame] then
Nenue@71 148 return veneers[frame]
Nenue@71 149 end
Nenue@71 150
Nenue@79 151 local name = type(frame) == 'table' and GetTableName(frame) or GetAnonymousName()
Nenue@73 152 local veneer = CreateFrame('Frame', name, frame, template or 'VeneerTemplate')
Nenue@72 153 print('+veneer', name)
Nenue@71 154
Nenue@71 155 veneer:SetAllPoints(frame)
Nenue@71 156 veneer:SetParent(frame)
Nenue@72 157 veneer.label:SetText(name)
Nenue@74 158 veneer.bg:SetColorTexture(0,0,0,0)
Nenue@71 159 veneer:Hide()
Nenue@71 160 veneer:EnableMouse(false)
Nenue@71 161
Nenue@71 162 veneer:SetScript('OnShow', VeneerButton_OnShow)
Nenue@71 163
Nenue@71 164 -- find current X/Y
Nenue@71 165 veneer.currentLeft = frame:GetLeft()
Nenue@71 166 veneer.currentTop = frame:GetTop()
Nenue@71 167
Nenue@72 168
Nenue@71 169 veneers[frame] = veneer
Nenue@71 170 return veneers[frame]
Nenue@71 171 end
Nenue@0 172
Nenue@80 173 local mixin_probe = {
Nenue@80 174 'ArtifactFrame',
Nenue@80 175 'ArtifactFrameUnderlay',
Nenue@80 176 }
Nenue@80 177
Nenue@80 178 vn.event = function(event, arg)
Nenue@80 179
Nenue@80 180 end
Nenue@80 181
Nenue@59 182 vn.init = function()
Nenue@59 183 if (not VeneerData) or (not VeneerData.version) then
Nenue@59 184 VeneerData = defaults
Nenue@0 185 end
Nenue@59 186 vn.db = VeneerData
Nenue@80 187
Nenue@71 188 end
Nenue@62 189
Nenue@71 190
Nenue@71 191 SLASH_VENEER1 = "/veneer"
Nenue@71 192 SLASH_VENEER2 = "/vn"
Nenue@71 193
Nenue@75 194 SlashCmdList.VENEER = function(cmd)
Nenue@75 195 for i, module in pairs(vn.modules) do
Nenue@75 196 if module.cmd then
Nenue@75 197 local result = module.cmd(cmd)
Nenue@75 198 if result then
Nenue@75 199 return
Nenue@75 200 end
Nenue@75 201 end
Nenue@75 202 end
Nenue@71 203 ToggleVeneerConfig()
Nenue@59 204 end