Mercurial > wow > buffalo2
comparison BuffAnchors.lua @ 0:3dbcad2b387d
initial push
author | Nenue |
---|---|
date | Wed, 30 Mar 2016 02:24:56 -0400 |
parents | |
children | 66b927b46776 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3dbcad2b387d |
---|---|
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 M = 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:SetScript('OnMouseDown', Anchor_OnMouseDown) | |
83 frame:SetScript("OnMouseUp", Anchor_OnMouseUp) | |
84 -- table addition | |
85 for i, anchorButton in ipairs(frame.anchorButton) do | |
86 anchorButton:SetScript('OnClick', AnchorButton_OnClick) | |
87 end | |
88 | |
89 B.displays[name].anchor = frame | |
90 print(B.displays[name].anchor:GetName()) | |
91 print(B.anchor[name]:GetName()) | |
92 return frame, anchorFrom, anchorParent, anchorTo, offsetX, offsetY | |
93 end | |
94 | |
95 --- Handles the preliminary positioning calculation for buff guide anchors | |
96 M.UpdateAnchorFrames = function(name) | |
97 local print = fprint(name) | |
98 local c = B.displays[name].conf | |
99 local frame, anchorFrom, anchorParent, anchorTo, offsetX, offsetY = GetAnchorFrame(name) | |
100 print('got', frame:GetName()) | |
101 frame.buffs = B.guides[name] | |
102 frame.heading:SetText(name) | |
103 B.SetConfigLayers(frame) | |
104 | |
105 local buffMax = c['Max'] or 3 | |
106 local perRow = c['PerRow'] or 2 | |
107 local buffSpacing = c['Spacing'] | |
108 local buffSize = c['Size'] | |
109 local buffDurationSize = c['DurationSize'] | |
110 | |
111 if not frame.isMoving then | |
112 if not B.Conf[name .. 'Parent'] then | |
113 frame:SetPoint(anchorFrom, _G[anchorParent], anchorTo, offsetX, offsetY) | |
114 end | |
115 end | |
116 | |
117 if frame.contains then buffMax = buffMax + 1 end | |
118 local cols, rows = min(perRow, buffMax), ceil(buffMax/perRow) | |
119 local spaces, breaks = (cols - 1), (rows - 1) | |
120 frame.columns = cols | |
121 frame.rows = rows | |
122 frame.spaces = cols - 1 | |
123 frame.breaks = rows - 1 | |
124 | |
125 local width = cols*buffSize + spaces*buffSpacing | |
126 local height = rows * (buffSize + buffDurationSize) + (breaks * (buffSpacing)) | |
127 | |
128 frame:SetSize(width, height) | |
129 frame:Show() | |
130 print(frame:GetName(), frame:GetSize()) | |
131 print(frame:GetPoint(1)) | |
132 end | |
133 | |
134 --- Handles placement of anchors embedded within anchors (consolidated buffs, maybe temp enchant) | |
135 M.UpdateAnchorAnchors = function() | |
136 local print = fprint() | |
137 for buttonName, d in pairs(B.displays) do | |
138 local c = B.displays[buttonName].conf | |
139 local frame = B.anchor[buttonName] | |
140 local parent, child = c.Parent, c.Position | |
141 | |
142 frame.parent = nil | |
143 if B.Conf[buttonName .. 'Parent'] and _G[B.Conf[buttonName .. 'Parent']..'Anchor'] then | |
144 | |
145 local anchorAnchor = _G[B.Conf[buttonName .. 'Parent']..'Anchor'] | |
146 local anchorTarget = B.guides[parent][child] | |
147 if anchorTarget then | |
148 print('link', buttonName, 'to', parent, child) | |
149 print(parent, child, B.displays[parent].guides[child]) | |
150 local ac = B.displays[parent].conf | |
151 local anchorFrom, anchorTo = unpack(ac.Point) | |
152 frame:ClearAllPoints() | |
153 frame:SetPoint(anchorFrom, anchorTarget, anchorTo) | |
154 frame.parent = anchorTarget | |
155 anchorTarget.contains = frame | |
156 anchorAnchor.contains = frame | |
157 anchorAnchor.containPosition = child | |
158 else | |
159 frame.parent = anchorAnchor | |
160 anchorAnchor.contains = frame | |
161 anchorAnchor.containPosition = nil | |
162 end | |
163 else | |
164 frame.parent = nil | |
165 end | |
166 | |
167 end | |
168 end | |
169 | |
170 -- if facing key direction, anchor point [1] to parent's point [2] | |
171 local childFacing = { | |
172 ['TOP'] = {'TOP', 'BOTTOM'}, | |
173 ['BOTTOM'] = {'BOTTOM', 'TOP'}, | |
174 ['RIGHT'] = {'LEFT', 'RIGHT'}, | |
175 ['LEFT'] = {'RIGHT', 'LEFT'}, | |
176 } | |
177 -- if align in key position, concatenate value with facing point | |
178 local childAlign = { | |
179 ['TOP'] = 'TOP%s', | |
180 ['BOTTOM'] = 'BOTTOM%s', | |
181 ['MIDDLE'] = '%s', | |
182 ['LEFT'] = '%sLEFT', | |
183 ['RIGHT'] = '%sRIGHT', | |
184 ['CENTER'] = '%s', | |
185 } | |
186 | |
187 --- dep handlers | |
188 B.UpdateAnchorChild = function (frame, child, c) | |
189 if frame.attached ~= child then | |
190 B.SetAnchorChild(frame, child, c) | |
191 end | |
192 | |
193 print('positioning|cFFFF0088', child, '|r of |cFF00FF00', frame, '|r') | |
194 | |
195 local frameAnchor = unpack(B.Conf[c.Parent.. 'Anchor']) | |
196 local childAnchor, childPoint = 'BOTTOMRIGHT', 'TOPRIGHT' | |
197 local direction, position = unpack(c.Anchor) | |
198 if direction and position then | |
199 childAnchor = childAlign[position]:format(childFacing[direction][2]) | |
200 childPoint = childAlign[position]:format(childFacing[direction][1]) | |
201 print('align toward', position,'on', direction, 'edge') | |
202 end | |
203 | |
204 print(frameAnchor, direction, position) | |
205 local lX, lY, cX, cY = frame.outer_X, frame.outer_Y, frame.cutout_X, frame.cutout_Y | |
206 local mX, mY = 0, 0 -- alignment modifiers | |
207 local pX, pY = 0, 0 -- position value | |
208 print('|cFFFF0088PUSHOUTS|r:', lX, lY, '|cFFFF8800PULL-IN|r:', cX, cY) | |
209 | |
210 -- if attachment is on a moving edge | |
211 if not frameAnchor:match(direction) then | |
212 print(' child anchors to a growing edge |cFFFF8800', direction,'|r') | |
213 if direction == 'BOTTOM' then | |
214 -- horizontal edge | |
215 | |
216 else | |
217 -- vertical edge | |
218 pX = lX | |
219 end | |
220 | |
221 if frameAnchor:match(position) then | |
222 | |
223 print('close alignment', lX, cX) | |
224 if position == 'RIGHT' then | |
225 -- and far X val | |
226 pX = 0 | |
227 lX = -lX | |
228 cX = -cX | |
229 pY = lY | |
230 else | |
231 end | |
232 else | |
233 print('far alignment', position) | |
234 end | |
235 else | |
236 print(' child anchors to a static edge |cFF0088FF', direction,'|r') | |
237 -- use no Y offset, position doesn't interfere | |
238 if direction == 'BOTTOM' or direction == 'TOP' then | |
239 pY = 0 | |
240 else | |
241 pX = 0 | |
242 end | |
243 end | |
244 | |
245 local frameWidth = frame:GetWidth() | |
246 local frameHeight = frame:GetHeight() | |
247 | |
248 local overlapY, overlapX | |
249 | |
250 -- right and bottom anchors offsets need to be inverted | |
251 if direction == 'BOTTOM' then | |
252 print('inverting Y values for anchor on BOTTOM edge, options:', cY, lY, 'actual:', pY) | |
253 pY = frameHeight - pY | |
254 cY = frameHeight - cY | |
255 lY = frameHeight - lY | |
256 print(' new values:', cY, lY, pY) | |
257 elseif direction == 'RIGHT' then | |
258 pX = frameWidth -pX | |
259 cX = frameWidth-cX | |
260 lX = frameWidth-lX | |
261 end | |
262 | |
263 | |
264 print(child, '|cFFFFFF00', childAnchor, '|r', frame, '|cFFFF0088', childPoint, '|r', pX, pY) | |
265 child:ClearAllPoints() | |
266 child:SetPoint(childAnchor, frame, childPoint, pX, pY) | |
267 frame.attachPoint = {childAnchor, childPoint } | |
268 | |
269 if Devian and Devian.InWorkspace() then | |
270 frame.alignedJoint:ClearAllPoints() | |
271 frame.poppingJointX:ClearAllPoints() | |
272 frame.poppingJointY:ClearAllPoints() | |
273 frame.cuttingJointX:ClearAllPoints() | |
274 frame.cuttingJointY:ClearAllPoints() | |
275 frame.childSpace:ClearAllPoints() | |
276 | |
277 frame.alignedJoint:SetPoint(childAnchor, frame, childPoint, pX, pY) | |
278 frame.poppingJointY:SetPoint(childAnchor, frame, childPoint, lX, lY) -- should really only differ when rows exceed 1 | |
279 frame.poppingJointX:SetPoint(childAnchor, frame, childPoint, lX, lY) | |
280 frame.cuttingJointY:SetPoint(childAnchor, frame, childPoint, cX, cY) -- should really only differ when rows exceed 1 | |
281 frame.cuttingJointX:SetPoint(childAnchor, frame, childPoint, cX, cY) | |
282 frame.childSpace:SetAllPoints(child) | |
283 | |
284 frame.alignedJoint:Show() | |
285 frame.poppingJointX:Show() | |
286 frame.poppingJointY:Show() | |
287 frame.cuttingJointX:Show() | |
288 frame.cuttingJointY:Show() | |
289 frame.childSpace:Show() | |
290 | |
291 print('|cFFFF0000MIN |r', childAnchor, childPoint, pX, pY) | |
292 print('|cFF00FFFFFAR |r', childAnchor, childPoint, cX, cY) | |
293 print('|cFFFFFF00CLOSE|r', childAnchor, childPoint, lX, lY) | |
294 | |
295 end | |
296 end | |
297 | |
298 B.SetAnchorChild = function(frame, child, c) | |
299 print('linking', child) | |
300 frame.attached = child | |
301 frame.attachmentConf = c | |
302 end |