comparison BuffFrame/BuffAnchors.lua @ 48:9837069e366a

move BuffFrame-specific things out of Veneer.lua straighten out table hierarchy for BuffFrame module
author Nenue
date Thu, 28 Apr 2016 06:58:13 -0400
parents 1a322b92dbfa
children 16465f3fd919
comparison
equal deleted inserted replaced
47:1a322b92dbfa 48:9837069e366a
14 local print = B.print('Anchor') 14 local print = B.print('Anchor')
15 local fprint = B.fprint 15 local fprint = B.fprint
16 local bprint = B.print('AnchorFrame') 16 local bprint = B.print('AnchorFrame')
17 17
18 local GetAnchorFrame = function(name) 18 local GetAnchorFrame = function(name)
19 local c = B.displays[name].conf 19 local c = buffFrame.displays[name].conf
20 local anchors = buffFrame.anchors
20 local anchorFrom, anchorParent, anchorTo, offsetX, offsetY = unpack(c.Anchor) 21 local anchorFrom, anchorParent, anchorTo, offsetX, offsetY = unpack(c.Anchor)
21 local print = bprint 22 local print = bprint
22 if B.anchor[name] then 23 if anchors[name] and anchors[name].GetName then
23 print('get', B.anchor[name]:GetName()) 24 print('get', buffFrame.anchors[name]:GetName())
24 return B.anchor[name], anchorFrom, anchorParent, anchorTo, offsetX, offsetY 25 return buffFrame.anchors[name], anchorFrom, anchorParent, anchorTo, offsetX, offsetY
25 end 26 end
26 print('new frame', name) 27 print('new frame', name)
27 local frame = CreateFrame('Frame', name..'Anchor', UIParent, B.displays[name].anchorTemplate) 28 local frame = CreateFrame('Frame', name..'Anchor', UIParent, buffFrame.displays[name].anchorTemplate)
28 frame.conf = c 29 frame.conf = c
29 30
30 local x, dx, y, dy 31 local x, dx, y, dy
31 local Anchor_OnMouseDown = function() 32 local Anchor_OnMouseDown = function()
32 if c['Parent'] then 33 if c['Parent'] then
49 dy = frame:GetTop() - y 50 dy = frame:GetTop() - y
50 -- update config 51 -- update config
51 print('|cFFFFFF00**changing', name, 'anchor by', dx, dy) 52 print('|cFFFFFF00**changing', name, 'anchor by', dx, dy)
52 offsetX = offsetX + dx 53 offsetX = offsetX + dx
53 offsetY = offsetY + dy 54 offsetY = offsetY + dy
54 B.Conf[name .. 'Anchor'] = {anchorFrom, anchorParent, anchorTo, offsetX, offsetY } 55 buffFrame.Conf[name .. 'Anchor'] = {anchorFrom, anchorParent, anchorTo, offsetX, offsetY }
55 frame:SetPoint(anchorFrom, _G[anchorParent], anchorTo, offsetX, offsetY) 56 frame:SetPoint(anchorFrom, _G[anchorParent], anchorTo, offsetX, offsetY)
56 frame.isMoving = nil 57 frame.isMoving = nil
57 end 58 end
58 59
59 local AnchorButton_OnClick = function(self, anchor) 60 local AnchorButton_OnClick = function(self, anchor)
60 local point, parent, relative = anchor:GetPoint(1) 61 local point, parent, relative = anchor:GetPoint(1)
61 print('resetting anchors', point, parent:GetName(), relative) 62 print('resetting anchors', point, parent:GetName(), relative)
62 B.Conf[name..'Point'] = {point, relative} 63 buffFrame.Conf[name..'Point'] = {point, relative}
63 B.Conf[name..'RelativeX'] = (point:match('RIGHT')) and -1 or 1 64 buffFrame.Conf[name..'RelativeX'] = (point:match('RIGHT')) and -1 or 1
64 B.Conf[name..'RelativeY'] = (point:match('TOP')) and -1 or 1 65 buffFrame.Conf[name..'RelativeY'] = (point:match('TOP')) and -1 or 1
65 wipe(B.drawn[name]) 66 wipe(buffFrame.drawn[name])
66 B.UpdateBuffs(name) 67 buffFrame.UpdateBuffs(name)
67 end 68 end
68 69
69 frame.OnUpdate = function(self, elapsed) 70 frame.OnUpdate = function(self, elapsed)
70 print(self:GetName(), elapsed) 71 print(self:GetName(), elapsed)
71 if self:IsMouseOver() then 72 if self:IsMouseOver() then
85 -- table addition 86 -- table addition
86 for i, anchorButton in ipairs(frame.anchorButton) do 87 for i, anchorButton in ipairs(frame.anchorButton) do
87 anchorButton:SetScript('OnClick', AnchorButton_OnClick) 88 anchorButton:SetScript('OnClick', AnchorButton_OnClick)
88 end 89 end
89 90
90 B.displays[name].anchor = frame 91 buffFrame.displays[name].anchor = frame
91 print(B.displays[name].anchor:GetName()) 92 print('displays[name].anchor', buffFrame.displays[name].anchor:GetName())
92 print(B.anchor[name]:GetName()) 93 print('anchors[name]', buffFrame.anchors[name]:GetName())
93 return frame, anchorFrom, anchorParent, anchorTo, offsetX, offsetY 94 return frame, anchorFrom, anchorParent, anchorTo, offsetX, offsetY
94 end 95 end
95 96
96 --- Handles the preliminary positioning calculation for buff guide anchors 97 --- Handles the preliminary positioning calculation for buff guide anchors
97 buffFrame.UpdateAnchorFrames = function(name) 98 buffFrame.UpdateAnchorFrames = function(name)
98 local print = fprint(name) 99 local print = fprint(name)
99 local c = B.displays[name].conf 100 local c = buffFrame.displays[name].conf
100 local frame, anchorFrom, anchorParent, anchorTo, offsetX, offsetY = GetAnchorFrame(name) 101 local frame, anchorFrom, anchorParent, anchorTo, offsetX, offsetY = GetAnchorFrame(name)
101 print('got', frame:GetName()) 102 print('got', frame:GetName())
102 frame.buffs = B.guides[name] 103 frame.buffs = buffFrame.guides[name]
103 frame.heading:SetText(name) 104 frame.heading:SetText(name)
104 B.SetConfigLayers(frame) 105 B.SetConfigLayers(frame)
105 106
106 local buffMax = c['Max'] or 3 107 local buffMax = c['Max'] or 3
107 local perRow = c['PerRow'] or 2 108 local perRow = c['PerRow'] or 2
132 print(frame:GetPoint(1)) 133 print(frame:GetPoint(1))
133 end 134 end
134 135
135 --- Handles placement of anchors embedded within anchors (consolidated buffs, maybe temp enchant) 136 --- Handles placement of anchors embedded within anchors (consolidated buffs, maybe temp enchant)
136 buffFrame.UpdateAnchorAnchors = function() 137 buffFrame.UpdateAnchorAnchors = function()
138 local displays = buffFrame.displays
139 local c = buffFrame.Conf
140 local guides = buffFrame.guides
137 local print = fprint() 141 local print = fprint()
138 for buttonName, d in pairs(B.displays) do 142 for buttonName, d in pairs(displays) do
139 local c = B.displays[buttonName].conf 143 local c = displays[buttonName].conf
140 local frame = B.anchor[buttonName] 144 local frame = buffFrame.anchors[buttonName]
141 local parent, child = c.Parent, c.Position 145 local parent, child = c.Parent, c.Position
142 146
143 frame.parent = nil 147 frame.parent = nil
144 if B.Conf[buttonName .. 'Parent'] and _G[B.Conf[buttonName .. 'Parent']..'Anchor'] then 148 if c[buttonName .. 'Parent'] and _G[c[buttonName .. 'Parent']..'Anchor'] then
145 149
146 local anchorAnchor = _G[B.Conf[buttonName .. 'Parent']..'Anchor'] 150 local anchorAnchor = _G[c[buttonName .. 'Parent']..'Anchor']
147 local anchorTarget = B.guides[parent][child] 151 local anchorTarget = guides[parent][child]
148 if anchorTarget then 152 if anchorTarget then
149 print('link', buttonName, 'to', parent, child) 153 print('link', buttonName, 'to', parent, child)
150 print(parent, child, B.displays[parent].guides[child]) 154 print(parent, child, displays[parent].guides[child])
151 local ac = B.displays[parent].conf 155 local ac = displays[parent].conf
152 local anchorFrom, anchorTo = unpack(ac.Point) 156 local anchorFrom, anchorTo = unpack(ac.Point)
153 frame:ClearAllPoints() 157 frame:ClearAllPoints()
154 frame:SetPoint(anchorFrom, anchorTarget, anchorTo) 158 frame:SetPoint(anchorFrom, anchorTarget, anchorTo)
155 frame.parent = anchorTarget 159 frame.parent = anchorTarget
156 anchorTarget.contains = frame 160 anchorTarget.contains = frame