Mercurial > wow > buffalo2
comparison BuffFrame/BuffAnchors.lua @ 47:1a322b92dbfa
file cleanup
author | Nenue |
---|---|
date | Thu, 28 Apr 2016 05:54:21 -0400 |
parents | BuffAnchors.lua@66b927b46776 |
children | 9837069e366a |
comparison
equal
deleted
inserted
replaced
46:aa693607b813 | 47:1a322b92dbfa |
---|---|
1 --- ${PACKAGE_NAME} | |
2 -- @file-author@ | |
3 -- @project-revision@ @project-hash@ | |
4 -- @file-revision@ @file-hash@ | |
5 -- Created: 3/22/2016 3:10 AM | |
6 | |
7 local MODULE = 'BuffFrame' | |
8 local _, A = ... | |
9 local B, _G = A.frame, _G | |
10 local buffFrame = B:RegisterModule(MODULE) | |
11 local type, unpack, select, pairs, ipairs, wipe = type, unpack, select, pairs, ipairs, table.wipe | |
12 local min, ceil, mod, tonumber, tostring = min, ceil, mod, tonumber, tostring | |
13 local CreateFrame = CreateFrame | |
14 local print = B.print('Anchor') | |
15 local fprint = B.fprint | |
16 local bprint = B.print('AnchorFrame') | |
17 | |
18 local GetAnchorFrame = function(name) | |
19 local c = B.displays[name].conf | |
20 local anchorFrom, anchorParent, anchorTo, offsetX, offsetY = unpack(c.Anchor) | |
21 local print = bprint | |
22 if B.anchor[name] then | |
23 print('get', B.anchor[name]:GetName()) | |
24 return B.anchor[name], anchorFrom, anchorParent, anchorTo, offsetX, offsetY | |
25 end | |
26 print('new frame', name) | |
27 local frame = CreateFrame('Frame', name..'Anchor', UIParent, B.displays[name].anchorTemplate) | |
28 frame.conf = c | |
29 | |
30 local x, dx, y, dy | |
31 local Anchor_OnMouseDown = function() | |
32 if c['Parent'] then | |
33 return | |
34 end | |
35 | |
36 x = frame:GetLeft() | |
37 y = frame:GetTop() | |
38 frame:StartMoving() | |
39 frame.isMoving = true | |
40 end | |
41 | |
42 local Anchor_OnMouseUp = function() | |
43 if c['Parent'] then | |
44 return | |
45 end | |
46 | |
47 frame:StopMovingOrSizing() | |
48 dx = frame:GetLeft() - x | |
49 dy = frame:GetTop() - y | |
50 -- update config | |
51 print('|cFFFFFF00**changing', name, 'anchor by', dx, dy) | |
52 offsetX = offsetX + dx | |
53 offsetY = offsetY + dy | |
54 B.Conf[name .. 'Anchor'] = {anchorFrom, anchorParent, anchorTo, offsetX, offsetY } | |
55 frame:SetPoint(anchorFrom, _G[anchorParent], anchorTo, offsetX, offsetY) | |
56 frame.isMoving = nil | |
57 end | |
58 | |
59 local AnchorButton_OnClick = function(self, anchor) | |
60 local point, parent, relative = anchor:GetPoint(1) | |
61 print('resetting anchors', point, parent:GetName(), relative) | |
62 B.Conf[name..'Point'] = {point, relative} | |
63 B.Conf[name..'RelativeX'] = (point:match('RIGHT')) and -1 or 1 | |
64 B.Conf[name..'RelativeY'] = (point:match('TOP')) and -1 or 1 | |
65 wipe(B.drawn[name]) | |
66 B.UpdateBuffs(name) | |
67 end | |
68 | |
69 frame.OnUpdate = function(self, elapsed) | |
70 print(self:GetName(), elapsed) | |
71 if self:IsMouseOver() then | |
72 for i, anchorButton in ipairs(frame.anchorButton) do | |
73 anchorButton:Show() | |
74 end | |
75 else | |
76 for i, anchorButton in ipairs(frame.anchorButton) do | |
77 anchorButton:Hide() | |
78 end | |
79 end | |
80 end | |
81 | |
82 frame:EnableMouse(B.Conf.ConfigMode and B.Conf.ConfigMode or false) | |
83 frame:SetScript('OnMouseDown', Anchor_OnMouseDown) | |
84 frame:SetScript("OnMouseUp", Anchor_OnMouseUp) | |
85 -- table addition | |
86 for i, anchorButton in ipairs(frame.anchorButton) do | |
87 anchorButton:SetScript('OnClick', AnchorButton_OnClick) | |
88 end | |
89 | |
90 B.displays[name].anchor = frame | |
91 print(B.displays[name].anchor:GetName()) | |
92 print(B.anchor[name]:GetName()) | |
93 return frame, anchorFrom, anchorParent, anchorTo, offsetX, offsetY | |
94 end | |
95 | |
96 --- Handles the preliminary positioning calculation for buff guide anchors | |
97 buffFrame.UpdateAnchorFrames = function(name) | |
98 local print = fprint(name) | |
99 local c = B.displays[name].conf | |
100 local frame, anchorFrom, anchorParent, anchorTo, offsetX, offsetY = GetAnchorFrame(name) | |
101 print('got', frame:GetName()) | |
102 frame.buffs = B.guides[name] | |
103 frame.heading:SetText(name) | |
104 B.SetConfigLayers(frame) | |
105 | |
106 local buffMax = c['Max'] or 3 | |
107 local perRow = c['PerRow'] or 2 | |
108 local buffSpacing = c['Spacing'] | |
109 local buffSize = c['Size'] | |
110 local buffDurationSize = c['DurationSize'] | |
111 | |
112 if not frame.isMoving then | |
113 if not B.Conf[name .. 'Parent'] then | |
114 frame:SetPoint(anchorFrom, _G[anchorParent], anchorTo, offsetX, offsetY) | |
115 end | |
116 end | |
117 | |
118 if frame.contains then buffMax = buffMax + 1 end | |
119 local cols, rows = min(perRow, buffMax), ceil(buffMax/perRow) | |
120 local spaces, breaks = (cols - 1), (rows - 1) | |
121 frame.columns = cols | |
122 frame.rows = rows | |
123 frame.spaces = cols - 1 | |
124 frame.breaks = rows - 1 | |
125 | |
126 local width = cols*buffSize + spaces*buffSpacing | |
127 local height = rows * (buffSize + buffDurationSize) + (breaks * (buffSpacing)) | |
128 | |
129 frame:SetSize(width, height) | |
130 frame:Show() | |
131 print(frame:GetName(), frame:GetSize()) | |
132 print(frame:GetPoint(1)) | |
133 end | |
134 | |
135 --- Handles placement of anchors embedded within anchors (consolidated buffs, maybe temp enchant) | |
136 buffFrame.UpdateAnchorAnchors = function() | |
137 local print = fprint() | |
138 for buttonName, d in pairs(B.displays) do | |
139 local c = B.displays[buttonName].conf | |
140 local frame = B.anchor[buttonName] | |
141 local parent, child = c.Parent, c.Position | |
142 | |
143 frame.parent = nil | |
144 if B.Conf[buttonName .. 'Parent'] and _G[B.Conf[buttonName .. 'Parent']..'Anchor'] then | |
145 | |
146 local anchorAnchor = _G[B.Conf[buttonName .. 'Parent']..'Anchor'] | |
147 local anchorTarget = B.guides[parent][child] | |
148 if anchorTarget then | |
149 print('link', buttonName, 'to', parent, child) | |
150 print(parent, child, B.displays[parent].guides[child]) | |
151 local ac = B.displays[parent].conf | |
152 local anchorFrom, anchorTo = unpack(ac.Point) | |
153 frame:ClearAllPoints() | |
154 frame:SetPoint(anchorFrom, anchorTarget, anchorTo) | |
155 frame.parent = anchorTarget | |
156 anchorTarget.contains = frame | |
157 anchorAnchor.contains = frame | |
158 anchorAnchor.containPosition = child | |
159 else | |
160 frame.parent = anchorAnchor | |
161 anchorAnchor.contains = frame | |
162 anchorAnchor.containPosition = nil | |
163 end | |
164 else | |
165 frame.parent = nil | |
166 end | |
167 | |
168 end | |
169 end | |
170 | |
171 -- if facing key direction, anchor point [1] to parent's point [2] | |
172 local childFacing = { | |
173 ['TOP'] = {'TOP', 'BOTTOM'}, | |
174 ['BOTTOM'] = {'BOTTOM', 'TOP'}, | |
175 ['RIGHT'] = {'LEFT', 'RIGHT'}, | |
176 ['LEFT'] = {'RIGHT', 'LEFT'}, | |
177 } | |
178 -- if align in key position, concatenate value with facing point | |
179 local childAlign = { | |
180 ['TOP'] = 'TOP%s', | |
181 ['BOTTOM'] = 'BOTTOM%s', | |
182 ['MIDDLE'] = '%s', | |
183 ['LEFT'] = '%sLEFT', | |
184 ['RIGHT'] = '%sRIGHT', | |
185 ['CENTER'] = '%s', | |
186 } | |
187 | |
188 --- dep handlers | |
189 B.UpdateAnchorChild = function (frame, child, c) | |
190 if frame.attached ~= child then | |
191 B.SetAnchorChild(frame, child, c) | |
192 end | |
193 | |
194 print('positioning|cFFFF0088', child, '|r of |cFF00FF00', frame, '|r') | |
195 | |
196 local frameAnchor = unpack(B.Conf[c.Parent.. 'Anchor']) | |
197 local childAnchor, childPoint = 'BOTTOMRIGHT', 'TOPRIGHT' | |
198 local direction, position = unpack(c.Anchor) | |
199 if direction and position then | |
200 childAnchor = childAlign[position]:format(childFacing[direction][2]) | |
201 childPoint = childAlign[position]:format(childFacing[direction][1]) | |
202 print('align toward', position,'on', direction, 'edge') | |
203 end | |
204 | |
205 print(frameAnchor, direction, position) | |
206 local lX, lY, cX, cY = frame.outer_X, frame.outer_Y, frame.cutout_X, frame.cutout_Y | |
207 local mX, mY = 0, 0 -- alignment modifiers | |
208 local pX, pY = 0, 0 -- position value | |
209 print('|cFFFF0088PUSHOUTS|r:', lX, lY, '|cFFFF8800PULL-IN|r:', cX, cY) | |
210 | |
211 -- if attachment is on a moving edge | |
212 if not frameAnchor:match(direction) then | |
213 print(' child anchors to a growing edge |cFFFF8800', direction,'|r') | |
214 if direction == 'BOTTOM' then | |
215 -- horizontal edge | |
216 | |
217 else | |
218 -- vertical edge | |
219 pX = lX | |
220 end | |
221 | |
222 if frameAnchor:match(position) then | |
223 | |
224 print('close alignment', lX, cX) | |
225 if position == 'RIGHT' then | |
226 -- and far X val | |
227 pX = 0 | |
228 lX = -lX | |
229 cX = -cX | |
230 pY = lY | |
231 else | |
232 end | |
233 else | |
234 print('far alignment', position) | |
235 end | |
236 else | |
237 print(' child anchors to a static edge |cFF0088FF', direction,'|r') | |
238 -- use no Y offset, position doesn't interfere | |
239 if direction == 'BOTTOM' or direction == 'TOP' then | |
240 pY = 0 | |
241 else | |
242 pX = 0 | |
243 end | |
244 end | |
245 | |
246 local frameWidth = frame:GetWidth() | |
247 local frameHeight = frame:GetHeight() | |
248 | |
249 local overlapY, overlapX | |
250 | |
251 -- right and bottom anchors offsets need to be inverted | |
252 if direction == 'BOTTOM' then | |
253 print('inverting Y values for anchor on BOTTOM edge, options:', cY, lY, 'actual:', pY) | |
254 pY = frameHeight - pY | |
255 cY = frameHeight - cY | |
256 lY = frameHeight - lY | |
257 print(' new values:', cY, lY, pY) | |
258 elseif direction == 'RIGHT' then | |
259 pX = frameWidth -pX | |
260 cX = frameWidth-cX | |
261 lX = frameWidth-lX | |
262 end | |
263 | |
264 | |
265 print(child, '|cFFFFFF00', childAnchor, '|r', frame, '|cFFFF0088', childPoint, '|r', pX, pY) | |
266 child:ClearAllPoints() | |
267 child:SetPoint(childAnchor, frame, childPoint, pX, pY) | |
268 frame.attachPoint = {childAnchor, childPoint } | |
269 | |
270 if Devian and Devian.InWorkspace() then | |
271 frame.alignedJoint:ClearAllPoints() | |
272 frame.poppingJointX:ClearAllPoints() | |
273 frame.poppingJointY:ClearAllPoints() | |
274 frame.cuttingJointX:ClearAllPoints() | |
275 frame.cuttingJointY:ClearAllPoints() | |
276 frame.childSpace:ClearAllPoints() | |
277 | |
278 frame.alignedJoint:SetPoint(childAnchor, frame, childPoint, pX, pY) | |
279 frame.poppingJointY:SetPoint(childAnchor, frame, childPoint, lX, lY) -- should really only differ when rows exceed 1 | |
280 frame.poppingJointX:SetPoint(childAnchor, frame, childPoint, lX, lY) | |
281 frame.cuttingJointY:SetPoint(childAnchor, frame, childPoint, cX, cY) -- should really only differ when rows exceed 1 | |
282 frame.cuttingJointX:SetPoint(childAnchor, frame, childPoint, cX, cY) | |
283 frame.childSpace:SetAllPoints(child) | |
284 | |
285 frame.alignedJoint:Show() | |
286 frame.poppingJointX:Show() | |
287 frame.poppingJointY:Show() | |
288 frame.cuttingJointX:Show() | |
289 frame.cuttingJointY:Show() | |
290 frame.childSpace:Show() | |
291 | |
292 print('|cFFFF0000MIN |r', childAnchor, childPoint, pX, pY) | |
293 print('|cFF00FFFFFAR |r', childAnchor, childPoint, cX, cY) | |
294 print('|cFFFFFF00CLOSE|r', childAnchor, childPoint, lX, lY) | |
295 | |
296 end | |
297 end | |
298 | |
299 B.SetAnchorChild = function(frame, child, c) | |
300 print('linking', child) | |
301 frame.attached = child | |
302 frame.attachmentConf = c | |
303 end |