flickerstreak@25
|
1 local ReAction = ReAction
|
flickerstreak@25
|
2 local L = ReAction.L
|
flickerstreak@25
|
3 local _G = _G
|
flickerstreak@25
|
4 local CreateFrame = CreateFrame
|
flickerstreak@33
|
5 local InCombatLockdown = InCombatLockdown
|
flickerstreak@33
|
6 local floor = math.floor
|
flickerstreak@33
|
7 local min = math.min
|
flickerstreak@33
|
8 local format = string.format
|
flickerstreak@33
|
9 local GameTooltip = GameTooltip
|
flickerstreak@33
|
10
|
flickerstreak@33
|
11
|
flickerstreak@25
|
12
|
flickerstreak@25
|
13 -- update ReAction revision if this file is newer
|
flickerstreak@33
|
14 local revision = tonumber(("$Revision$"):match("%d+"))
|
flickerstreak@25
|
15 if revision > ReAction.revision then
|
flickerstreak@25
|
16 Reaction.revision = revision
|
flickerstreak@25
|
17 end
|
flickerstreak@25
|
18
|
flickerstreak@28
|
19 ------ BAR CLASS ------
|
flickerstreak@28
|
20 local Bar = { _classID = {} }
|
flickerstreak@25
|
21
|
flickerstreak@28
|
22 local function Constructor( self, name, config )
|
flickerstreak@25
|
23 self.name, self.config = name, config
|
flickerstreak@25
|
24
|
flickerstreak@25
|
25 if type(config) ~= "table" then
|
flickerstreak@28
|
26 error("ReAction.Bar: config table required")
|
flickerstreak@25
|
27 end
|
flickerstreak@25
|
28
|
flickerstreak@25
|
29 local f = CreateFrame("Frame",nil,config.parent or UIParent,"SecureStateDriverTemplate")
|
flickerstreak@25
|
30 f:SetFrameStrata("MEDIUM")
|
flickerstreak@30
|
31 config.width = config.width or 480
|
flickerstreak@30
|
32 config.height = config.height or 40
|
flickerstreak@25
|
33 f:SetWidth(config.width)
|
flickerstreak@25
|
34 f:SetWidth(config.height)
|
flickerstreak@25
|
35
|
flickerstreak@25
|
36 self.frame = f
|
flickerstreak@25
|
37 self:RefreshLayout()
|
flickerstreak@25
|
38 self:ApplyAnchor()
|
flickerstreak@25
|
39 f:Show()
|
flickerstreak@25
|
40 end
|
flickerstreak@25
|
41
|
flickerstreak@25
|
42 function Bar:Destroy()
|
flickerstreak@25
|
43 local f = self.frame
|
flickerstreak@25
|
44 f:UnregisterAllEvents()
|
flickerstreak@25
|
45 f:Hide()
|
flickerstreak@25
|
46 f:SetParent(UIParent)
|
flickerstreak@25
|
47 f:ClearAllPoints()
|
flickerstreak@25
|
48 self.labelString = nil
|
flickerstreak@25
|
49 self.controlFrame = nil
|
flickerstreak@25
|
50 self.frame = nil
|
flickerstreak@25
|
51 self.config = nil
|
flickerstreak@25
|
52 end
|
flickerstreak@25
|
53
|
flickerstreak@25
|
54 function Bar:RefreshLayout()
|
flickerstreak@25
|
55 ReAction:CallMethodOnAllModules("RefreshBar", self)
|
flickerstreak@25
|
56 end
|
flickerstreak@25
|
57
|
flickerstreak@25
|
58 function Bar:ApplyAnchor()
|
flickerstreak@25
|
59 local f, config = self.frame, self.config
|
flickerstreak@25
|
60 f:SetWidth(config.width)
|
flickerstreak@25
|
61 f:SetHeight(config.height)
|
flickerstreak@25
|
62 local anchor = config.anchor
|
flickerstreak@51
|
63 f:ClearAllPoints()
|
flickerstreak@25
|
64 if anchor then
|
flickerstreak@25
|
65 local anchorTo
|
flickerstreak@25
|
66 if config.anchorTo then
|
flickerstreak@28
|
67 anchorTo = ReAction:GetBar(config.anchorTo) or _G[config.anchorTo]
|
flickerstreak@25
|
68 end
|
flickerstreak@25
|
69 f:SetPoint(anchor, anchorTo, config.relativePoint, config.x or 0, config.y or 0)
|
flickerstreak@25
|
70 else
|
flickerstreak@25
|
71 f:SetPoint("CENTER")
|
flickerstreak@25
|
72 end
|
flickerstreak@25
|
73 end
|
flickerstreak@25
|
74
|
flickerstreak@51
|
75 function Bar:SetAnchor(point, frame, relativePoint, x, y)
|
flickerstreak@51
|
76 local c = self.config
|
flickerstreak@51
|
77 c.anchor = point or c.anchor
|
flickerstreak@51
|
78 c.anchorTo = frame and frame:GetName() or c.anchorTo
|
flickerstreak@51
|
79 c.relativePoint = relativePoint or c.relativePoint
|
flickerstreak@51
|
80 c.x = x or c.x
|
flickerstreak@51
|
81 c.y = y or c.y
|
flickerstreak@51
|
82 self:ApplyAnchor()
|
flickerstreak@51
|
83 end
|
flickerstreak@51
|
84
|
flickerstreak@51
|
85 function Bar:GetAnchor()
|
flickerstreak@51
|
86 local c = self.config
|
flickerstreak@51
|
87 return (c.anchor or "CENTER"), (c.anchorTo or self.frame:GetParent():GetName()), (c.relativePoint or c.anchor or "CENTER"), (c.x or 0), (c.y or 0)
|
flickerstreak@51
|
88 end
|
flickerstreak@51
|
89
|
flickerstreak@25
|
90 function Bar:GetFrame()
|
flickerstreak@25
|
91 return self.frame
|
flickerstreak@25
|
92 end
|
flickerstreak@25
|
93
|
flickerstreak@25
|
94 function Bar:GetSize()
|
flickerstreak@25
|
95 return self.frame:GetWidth() or 200, self.frame:GetHeight() or 200
|
flickerstreak@25
|
96 end
|
flickerstreak@25
|
97
|
flickerstreak@25
|
98 function Bar:SetSize(w,h)
|
flickerstreak@25
|
99 self.config.width = w
|
flickerstreak@25
|
100 self.config.height = h
|
flickerstreak@25
|
101 end
|
flickerstreak@25
|
102
|
flickerstreak@25
|
103 function Bar:GetButtonSize()
|
flickerstreak@25
|
104 local w = self.config.btnWidth or 32
|
flickerstreak@25
|
105 local h = self.config.btnHeight or 32
|
flickerstreak@25
|
106 -- TODO: get from modules?
|
flickerstreak@25
|
107 return w,h
|
flickerstreak@25
|
108 end
|
flickerstreak@25
|
109
|
flickerstreak@25
|
110 function Bar:SetButtonSize(w,h)
|
flickerstreak@25
|
111 if w > 0 and h > 0 then
|
flickerstreak@25
|
112 self.config.btnWidth = w
|
flickerstreak@25
|
113 self.config.btnHeight = h
|
flickerstreak@25
|
114 end
|
flickerstreak@25
|
115 end
|
flickerstreak@25
|
116
|
flickerstreak@25
|
117 function Bar:GetButtonGrid()
|
flickerstreak@25
|
118 local cfg = self.config
|
flickerstreak@25
|
119 local r = cfg.btnRows or 1
|
flickerstreak@25
|
120 local c = cfg.btnColumns or 1
|
flickerstreak@25
|
121 local s = cfg.spacing or 4
|
flickerstreak@25
|
122 return r,c,s
|
flickerstreak@25
|
123 end
|
flickerstreak@25
|
124
|
flickerstreak@25
|
125 function Bar:SetButtonGrid(r,c,s)
|
flickerstreak@25
|
126 if r > 0 and c > 0 and s > 0 then
|
flickerstreak@25
|
127 local cfg = self.config
|
flickerstreak@25
|
128 cfg.btnRows = r
|
flickerstreak@25
|
129 cfg.btnColumns = c
|
flickerstreak@25
|
130 cfg.spacing = s
|
flickerstreak@25
|
131 end
|
flickerstreak@25
|
132 end
|
flickerstreak@25
|
133
|
flickerstreak@25
|
134 function Bar:GetName()
|
flickerstreak@25
|
135 return self.name
|
flickerstreak@25
|
136 end
|
flickerstreak@25
|
137
|
flickerstreak@33
|
138 function Bar:SetName(name)
|
flickerstreak@33
|
139 self.name = name
|
flickerstreak@33
|
140 if self.controlLabelString then
|
flickerstreak@33
|
141 self.controlLabelString:SetText(self.name)
|
flickerstreak@33
|
142 end
|
flickerstreak@33
|
143 end
|
flickerstreak@33
|
144
|
flickerstreak@25
|
145 function Bar:PlaceButton(f, idx, baseW, baseH)
|
flickerstreak@25
|
146 local r, c, s = self:GetButtonGrid()
|
flickerstreak@25
|
147 local bh, bw = self:GetButtonSize()
|
flickerstreak@25
|
148 local row, col = floor((idx-1)/c), mod((idx-1),c) -- zero-based
|
flickerstreak@25
|
149 local x, y = col*bw + (col+0.5)*s, row*bh + (row+0.5)*s
|
flickerstreak@25
|
150 local scale = bw/baseW
|
flickerstreak@25
|
151
|
flickerstreak@25
|
152 f:ClearAllPoints()
|
flickerstreak@25
|
153 f:SetPoint("TOPLEFT",x/scale,-y/scale)
|
flickerstreak@25
|
154 f:SetScale(scale)
|
flickerstreak@25
|
155 -- f:Show()
|
flickerstreak@25
|
156 end
|
flickerstreak@25
|
157
|
flickerstreak@28
|
158
|
flickerstreak@28
|
159
|
flickerstreak@33
|
160
|
flickerstreak@33
|
161
|
flickerstreak@33
|
162
|
flickerstreak@33
|
163
|
flickerstreak@33
|
164 --
|
flickerstreak@33
|
165 -- Bar config overlay
|
flickerstreak@33
|
166 --
|
flickerstreak@33
|
167 local StoreExtents, RecomputeButtonSize, RecomputeButtonSpacing, RecomputeGrid, ClampToButtons, HideGameTooltip, CreateControls
|
flickerstreak@33
|
168
|
flickerstreak@33
|
169 do
|
flickerstreak@33
|
170 -- upvalue some of these for small OnUpdate performance boost
|
flickerstreak@33
|
171 local GetSize = Bar.GetSize
|
flickerstreak@33
|
172 local GetButtonSize = Bar.GetButtonSize
|
flickerstreak@33
|
173 local GetButtonGrid = Bar.GetButtonGrid
|
flickerstreak@33
|
174 local SetSize = Bar.SetSize
|
flickerstreak@33
|
175 local SetButtonSize = Bar.SetButtonSize
|
flickerstreak@33
|
176 local SetButtonGrid = Bar.SetButtonGrid
|
flickerstreak@33
|
177 local ApplyAnchor = Bar.ApplyAnchor
|
flickerstreak@33
|
178
|
flickerstreak@33
|
179 StoreExtents = function(bar)
|
flickerstreak@33
|
180 local f = bar.frame
|
flickerstreak@33
|
181 local point, relativeTo, relativePoint, x, y = f:GetPoint(1)
|
flickerstreak@33
|
182 relativeTo = relativeTo or f:GetParent()
|
flickerstreak@33
|
183 local anchorTo
|
flickerstreak@33
|
184 for name, b in pairs(ReAction.bars) do
|
flickerstreak@33
|
185 if b then
|
flickerstreak@33
|
186 if b:GetFrame() == relativeTo then
|
flickerstreak@33
|
187 anchorTo = name
|
flickerstreak@33
|
188 break
|
flickerstreak@33
|
189 end
|
flickerstreak@33
|
190 end
|
flickerstreak@33
|
191 end
|
flickerstreak@33
|
192 anchorTo = anchorTo or relativeTo:GetName()
|
flickerstreak@33
|
193 local c = bar.config
|
flickerstreak@33
|
194 c.anchor = point
|
flickerstreak@33
|
195 c.anchorTo = anchorTo
|
flickerstreak@33
|
196 c.relativePoint = relativePoint
|
flickerstreak@33
|
197 c.x = x
|
flickerstreak@33
|
198 c.y = y
|
flickerstreak@33
|
199 c.width, c.height = f:GetWidth(), f:GetHeight()
|
flickerstreak@33
|
200 end
|
flickerstreak@33
|
201
|
flickerstreak@33
|
202 RecomputeButtonSize = function(bar)
|
flickerstreak@33
|
203 local w, h = GetSize(bar)
|
flickerstreak@33
|
204 local bw, bh = GetButtonSize(bar)
|
flickerstreak@33
|
205 local r, c, s = GetButtonGrid(bar)
|
flickerstreak@33
|
206
|
flickerstreak@33
|
207 local scaleW = (floor(w/c) - s) / bw
|
flickerstreak@33
|
208 local scaleH = (floor(h/r) - s) / bh
|
flickerstreak@33
|
209 local scale = min(scaleW, scaleH)
|
flickerstreak@33
|
210
|
flickerstreak@33
|
211 SetButtonSize(bar, scale * bw, scale * bh, s)
|
flickerstreak@33
|
212 end
|
flickerstreak@33
|
213
|
flickerstreak@33
|
214 RecomputeButtonSpacing = function(bar)
|
flickerstreak@33
|
215 local w, h = GetSize(bar)
|
flickerstreak@33
|
216 local bw, bh = GetButtonSize(bar)
|
flickerstreak@33
|
217 local r, c, s = GetButtonGrid(bar)
|
flickerstreak@33
|
218
|
flickerstreak@33
|
219 SetButtonGrid(bar,r,c,min(floor(w/c) - bw, floor(h/r) - bh))
|
flickerstreak@33
|
220 end
|
flickerstreak@33
|
221
|
flickerstreak@33
|
222 RecomputeGrid = function(bar)
|
flickerstreak@33
|
223 local w, h = GetSize(bar)
|
flickerstreak@33
|
224 local bw, bh = GetButtonSize(bar)
|
flickerstreak@33
|
225 local r, c, s = GetButtonGrid(bar)
|
flickerstreak@33
|
226
|
flickerstreak@33
|
227 SetButtonGrid(bar, floor(h/(bh+s)), floor(w/(bw+s)), s)
|
flickerstreak@33
|
228 end
|
flickerstreak@33
|
229
|
flickerstreak@33
|
230 ClampToButtons = function(bar)
|
flickerstreak@33
|
231 local bw, bh = GetButtonSize(bar)
|
flickerstreak@33
|
232 local r, c, s = GetButtonGrid(bar)
|
flickerstreak@50
|
233 SetSize(bar, (bw+s)*c + 1, (bh+s)*r + 1)
|
flickerstreak@33
|
234 end
|
flickerstreak@33
|
235
|
flickerstreak@33
|
236 HideGameTooltip = function()
|
flickerstreak@33
|
237 GameTooltip:Hide()
|
flickerstreak@33
|
238 end
|
flickerstreak@33
|
239
|
flickerstreak@33
|
240 CreateControls = function(bar)
|
flickerstreak@33
|
241 local f = bar.frame
|
flickerstreak@33
|
242
|
flickerstreak@33
|
243 f:SetMovable(true)
|
flickerstreak@33
|
244 f:SetResizable(true)
|
flickerstreak@33
|
245 f:SetClampedToScreen(true)
|
flickerstreak@33
|
246
|
flickerstreak@33
|
247 -- buttons on the bar should be direct children of the bar frame.
|
flickerstreak@33
|
248 -- The control elements need to float on top of this, which we could
|
flickerstreak@33
|
249 -- do with SetFrameLevel() or Raise(), but it's more reliable to do it
|
flickerstreak@33
|
250 -- via frame nesting, hence good old foo's appearance here.
|
flickerstreak@33
|
251 local foo = CreateFrame("Frame",nil,f)
|
flickerstreak@33
|
252 foo:SetAllPoints()
|
flickerstreak@51
|
253 foo:SetClampedToScreen(true)
|
flickerstreak@33
|
254
|
flickerstreak@33
|
255 local control = CreateFrame("Button", nil, foo)
|
flickerstreak@33
|
256 control:EnableMouse(true)
|
flickerstreak@33
|
257 control:SetToplevel(true)
|
flickerstreak@33
|
258 control:SetPoint("TOPLEFT", -4, 4)
|
flickerstreak@33
|
259 control:SetPoint("BOTTOMRIGHT", 4, -4)
|
flickerstreak@33
|
260 control:SetBackdrop({
|
flickerstreak@33
|
261 edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
|
flickerstreak@33
|
262 tile = true,
|
flickerstreak@33
|
263 tileSize = 16,
|
flickerstreak@33
|
264 edgeSize = 16,
|
flickerstreak@33
|
265 insets = { left = 0, right = 0, top = 0, bottom = 0 },
|
flickerstreak@33
|
266 })
|
flickerstreak@33
|
267
|
flickerstreak@33
|
268 -- textures
|
flickerstreak@33
|
269 local bgTex = control:CreateTexture(nil,"BACKGROUND")
|
flickerstreak@33
|
270 bgTex:SetTexture(0.7,0.7,1.0,0.2)
|
flickerstreak@33
|
271 bgTex:SetPoint("TOPLEFT",4,-4)
|
flickerstreak@33
|
272 bgTex:SetPoint("BOTTOMRIGHT",-4,4)
|
flickerstreak@33
|
273 local hTex = control:CreateTexture(nil,"HIGHLIGHT")
|
flickerstreak@33
|
274 hTex:SetTexture(0.7,0.7,1.0,0.2)
|
flickerstreak@33
|
275 hTex:SetPoint("TOPLEFT",4,-4)
|
flickerstreak@33
|
276 hTex:SetPoint("BOTTOMRIGHT",-4,4)
|
flickerstreak@33
|
277 hTex:SetBlendMode("ADD")
|
flickerstreak@33
|
278
|
flickerstreak@33
|
279 -- label
|
flickerstreak@33
|
280 local label = control:CreateFontString(nil,"OVERLAY","GameFontNormalLarge")
|
flickerstreak@33
|
281 label:SetAllPoints()
|
flickerstreak@33
|
282 label:SetJustifyH("CENTER")
|
flickerstreak@33
|
283 label:SetShadowColor(0,0,0,1)
|
flickerstreak@33
|
284 label:SetShadowOffset(2,-2)
|
flickerstreak@33
|
285 label:SetTextColor(1,1,1,1)
|
flickerstreak@33
|
286 label:SetText(bar:GetName())
|
flickerstreak@33
|
287 label:Show()
|
flickerstreak@33
|
288 bar.controlLabelString = label -- so that bar:SetName() can update it
|
flickerstreak@33
|
289
|
flickerstreak@33
|
290 local StopResize = function()
|
flickerstreak@33
|
291 f:StopMovingOrSizing()
|
flickerstreak@33
|
292 f.isMoving = false
|
flickerstreak@33
|
293 f:SetScript("OnUpdate",nil)
|
flickerstreak@33
|
294 StoreExtents(bar)
|
flickerstreak@33
|
295 ClampToButtons(bar)
|
flickerstreak@33
|
296 ApplyAnchor(bar)
|
flickerstreak@33
|
297 end
|
flickerstreak@33
|
298
|
flickerstreak@33
|
299 -- edge drag handles
|
flickerstreak@33
|
300 for _, point in pairs({"LEFT","TOP","RIGHT","BOTTOM"}) do
|
flickerstreak@33
|
301 local edge = CreateFrame("Frame",nil,control)
|
flickerstreak@33
|
302 edge:EnableMouse(true)
|
flickerstreak@33
|
303 edge:SetWidth(8)
|
flickerstreak@33
|
304 edge:SetHeight(8)
|
flickerstreak@33
|
305 if point == "TOP" or point == "BOTTOM" then
|
flickerstreak@33
|
306 edge:SetPoint(point.."LEFT")
|
flickerstreak@33
|
307 edge:SetPoint(point.."RIGHT")
|
flickerstreak@33
|
308 else
|
flickerstreak@33
|
309 edge:SetPoint("TOP"..point)
|
flickerstreak@33
|
310 edge:SetPoint("BOTTOM"..point)
|
flickerstreak@33
|
311 end
|
flickerstreak@33
|
312 local tex = edge:CreateTexture(nil,"HIGHLIGHT")
|
flickerstreak@33
|
313 tex:SetTexture(1.0,0.82,0,0.7)
|
flickerstreak@33
|
314 tex:SetBlendMode("ADD")
|
flickerstreak@33
|
315 tex:SetAllPoints()
|
flickerstreak@33
|
316 edge:RegisterForDrag("LeftButton")
|
flickerstreak@33
|
317 edge:SetScript("OnMouseDown",
|
flickerstreak@33
|
318 function()
|
flickerstreak@33
|
319 local bw, bh = GetButtonSize(bar)
|
flickerstreak@33
|
320 local r, c, s = GetButtonGrid(bar)
|
flickerstreak@33
|
321 f:SetMinResize( bw+s+1, bh+s+1 )
|
flickerstreak@33
|
322 f:StartSizing(point)
|
flickerstreak@33
|
323 f:SetScript("OnUpdate",
|
flickerstreak@33
|
324 function()
|
flickerstreak@33
|
325 RecomputeGrid(bar)
|
flickerstreak@33
|
326 bar:RefreshLayout()
|
flickerstreak@33
|
327 end
|
flickerstreak@33
|
328 )
|
flickerstreak@33
|
329 end
|
flickerstreak@33
|
330 )
|
flickerstreak@33
|
331 edge:SetScript("OnMouseUp", StopResize)
|
flickerstreak@33
|
332 edge:SetScript("OnEnter",
|
flickerstreak@33
|
333 function()
|
flickerstreak@33
|
334 GameTooltip:SetOwner(f, "ANCHOR_"..point)
|
flickerstreak@33
|
335 GameTooltip:AddLine(L["Drag to add/remove buttons"])
|
flickerstreak@33
|
336 GameTooltip:Show()
|
flickerstreak@33
|
337 end
|
flickerstreak@33
|
338 )
|
flickerstreak@33
|
339 edge:SetScript("OnLeave", HideGameTooltip)
|
flickerstreak@33
|
340 edge:Show()
|
flickerstreak@33
|
341 end
|
flickerstreak@33
|
342
|
flickerstreak@33
|
343 -- corner drag handles, again nested in an anonymous frame so that they are on top
|
flickerstreak@33
|
344 local foo2 = CreateFrame("Frame",nil,control)
|
flickerstreak@33
|
345 foo2:SetAllPoints(true)
|
flickerstreak@33
|
346 for _, point in pairs({"BOTTOMLEFT","TOPLEFT","BOTTOMRIGHT","TOPRIGHT"}) do
|
flickerstreak@33
|
347 local corner = CreateFrame("Frame",nil,foo2)
|
flickerstreak@33
|
348 corner:EnableMouse(true)
|
flickerstreak@33
|
349 corner:SetWidth(12)
|
flickerstreak@33
|
350 corner:SetHeight(12)
|
flickerstreak@33
|
351 corner:SetPoint(point)
|
flickerstreak@33
|
352 local tex = corner:CreateTexture(nil,"HIGHLIGHT")
|
flickerstreak@33
|
353 tex:SetTexture(1.0,0.82,0,0.7)
|
flickerstreak@33
|
354 tex:SetBlendMode("ADD")
|
flickerstreak@33
|
355 tex:SetAllPoints()
|
flickerstreak@33
|
356 corner:RegisterForDrag("LeftButton","RightButton")
|
flickerstreak@33
|
357 local updateTooltip = function()
|
flickerstreak@33
|
358 local size, size2 = bar:GetButtonSize()
|
flickerstreak@33
|
359 local rows, cols, spacing = bar:GetButtonGrid()
|
flickerstreak@33
|
360 size = (size == size2) and tostring(size) or format("%dx%d",size,size2)
|
flickerstreak@33
|
361 GameTooltipTextRight4:SetText(size)
|
flickerstreak@33
|
362 GameTooltipTextRight5:SetText(tostring(spacing))
|
flickerstreak@33
|
363 end
|
flickerstreak@33
|
364 corner:SetScript("OnMouseDown",
|
flickerstreak@33
|
365 function(_,btn)
|
flickerstreak@33
|
366 local bw, bh = GetButtonSize(bar)
|
flickerstreak@33
|
367 local r, c, s = GetButtonGrid(bar)
|
flickerstreak@33
|
368 if btn == "LeftButton" then -- button resize
|
flickerstreak@33
|
369 f:SetMinResize( (s+12)*c+1, (s+12)*r+1 )
|
flickerstreak@33
|
370 f:SetScript("OnUpdate",
|
flickerstreak@33
|
371 function()
|
flickerstreak@33
|
372 RecomputeButtonSize(bar)
|
flickerstreak@33
|
373 bar:RefreshLayout()
|
flickerstreak@33
|
374 updateTooltip()
|
flickerstreak@33
|
375 end
|
flickerstreak@33
|
376 )
|
flickerstreak@33
|
377 elseif btn == "RightButton" then -- spacing resize
|
flickerstreak@33
|
378 f:SetMinResize( bw*c, bh*r )
|
flickerstreak@33
|
379 f:SetScript("OnUpdate",
|
flickerstreak@33
|
380 function()
|
flickerstreak@33
|
381 RecomputeButtonSpacing(bar)
|
flickerstreak@33
|
382 bar:RefreshLayout()
|
flickerstreak@33
|
383 updateTooltip()
|
flickerstreak@33
|
384 end
|
flickerstreak@33
|
385 )
|
flickerstreak@33
|
386 end
|
flickerstreak@33
|
387 f:StartSizing(point)
|
flickerstreak@33
|
388 end
|
flickerstreak@33
|
389 )
|
flickerstreak@33
|
390 corner:SetScript("OnMouseUp",StopResize)
|
flickerstreak@33
|
391 corner:SetScript("OnEnter",
|
flickerstreak@33
|
392 function()
|
flickerstreak@33
|
393 GameTooltip:SetOwner(f, "ANCHOR_"..point)
|
flickerstreak@33
|
394 GameTooltip:AddLine(L["Drag to resize buttons"])
|
flickerstreak@33
|
395 GameTooltip:AddLine(L["Right-click-drag"])
|
flickerstreak@33
|
396 GameTooltip:AddLine(L["to change spacing"])
|
flickerstreak@33
|
397 local size, size2 = bar:GetButtonSize()
|
flickerstreak@33
|
398 local rows, cols, spacing = bar:GetButtonGrid()
|
flickerstreak@33
|
399 size = (size == size2) and tostring(size) or format("%dx%d",size,size2)
|
flickerstreak@33
|
400 GameTooltip:AddDoubleLine(L["Size:"], size)
|
flickerstreak@33
|
401 GameTooltip:AddDoubleLine(L["Spacing:"], tostring(spacing))
|
flickerstreak@33
|
402 GameTooltip:Show()
|
flickerstreak@33
|
403 end
|
flickerstreak@33
|
404 )
|
flickerstreak@33
|
405 corner:SetScript("OnLeave",
|
flickerstreak@33
|
406 function()
|
flickerstreak@33
|
407 GameTooltip:Hide()
|
flickerstreak@33
|
408 f:SetScript("OnUpdate",nil)
|
flickerstreak@33
|
409 end
|
flickerstreak@33
|
410 )
|
flickerstreak@33
|
411
|
flickerstreak@33
|
412 end
|
flickerstreak@33
|
413
|
flickerstreak@33
|
414 control:RegisterForDrag("LeftButton")
|
flickerstreak@33
|
415 control:RegisterForClicks("RightButtonDown")
|
flickerstreak@33
|
416
|
flickerstreak@33
|
417 control:SetScript("OnDragStart",
|
flickerstreak@33
|
418 function()
|
flickerstreak@33
|
419 f:StartMoving()
|
flickerstreak@33
|
420 f.isMoving = true
|
flickerstreak@33
|
421 -- TODO: snap indicator update install
|
flickerstreak@33
|
422 end
|
flickerstreak@33
|
423 )
|
flickerstreak@33
|
424
|
flickerstreak@33
|
425 control:SetScript("OnDragStop",
|
flickerstreak@33
|
426 function()
|
flickerstreak@33
|
427 f:StopMovingOrSizing()
|
flickerstreak@33
|
428 f.isMoving = false
|
flickerstreak@33
|
429 f:SetScript("OnUpdate",nil)
|
flickerstreak@33
|
430 -- TODO: snap frame here
|
flickerstreak@33
|
431 StoreExtents(bar)
|
flickerstreak@33
|
432 end
|
flickerstreak@33
|
433 )
|
flickerstreak@33
|
434
|
flickerstreak@33
|
435 control:SetScript("OnEnter",
|
flickerstreak@33
|
436 function()
|
flickerstreak@33
|
437 -- add bar type and status information to name
|
flickerstreak@33
|
438 local name = bar.name
|
flickerstreak@33
|
439 for _, m in ReAction:IterateModules() do
|
flickerstreak@33
|
440 --[[
|
flickerstreak@33
|
441 local suffix = safecall(m,"GetBarNameModifier",bar)
|
flickerstreak@33
|
442 if suffix then
|
flickerstreak@33
|
443 name = ("%s %s"):format(name,suffix)
|
flickerstreak@33
|
444 end
|
flickerstreak@33
|
445 --]]
|
flickerstreak@33
|
446 end
|
flickerstreak@33
|
447
|
flickerstreak@33
|
448 GameTooltip:SetOwner(f, "ANCHOR_TOPRIGHT")
|
flickerstreak@33
|
449 GameTooltip:AddLine(name)
|
flickerstreak@33
|
450 GameTooltip:AddLine(L["Drag to move"])
|
flickerstreak@33
|
451 --GameTooltip:AddLine(L["Shift-drag for sticky mode"])
|
flickerstreak@33
|
452 GameTooltip:AddLine(L["Right-click for options"])
|
flickerstreak@33
|
453 GameTooltip:Show()
|
flickerstreak@33
|
454 end
|
flickerstreak@33
|
455 )
|
flickerstreak@33
|
456
|
flickerstreak@33
|
457 control:SetScript("OnLeave", HideGameTooltip)
|
flickerstreak@33
|
458
|
flickerstreak@33
|
459 control:SetScript("OnClick",
|
flickerstreak@33
|
460 function()
|
flickerstreak@33
|
461 bar:ShowMenu()
|
flickerstreak@33
|
462 end
|
flickerstreak@33
|
463 )
|
flickerstreak@33
|
464
|
flickerstreak@33
|
465 return control
|
flickerstreak@33
|
466 end
|
flickerstreak@33
|
467 end
|
flickerstreak@33
|
468
|
flickerstreak@33
|
469
|
flickerstreak@33
|
470 local OpenMenu, CloseMenu
|
flickerstreak@33
|
471 do
|
flickerstreak@33
|
472 -- Looking for a lightweight AceConfig3-struct-compatible
|
flickerstreak@33
|
473 -- replacement for Dewdrop, encapsulate here
|
flickerstreak@33
|
474 -- Considering Blizzard's EasyMenu/UIDropDownMenu, but that's
|
flickerstreak@33
|
475 -- a bit tricky to convert from AceConfig3-struct
|
flickerstreak@33
|
476 local Dewdrop = AceLibrary("Dewdrop-2.0")
|
flickerstreak@33
|
477 OpenMenu = function(frame, opts)
|
flickerstreak@33
|
478 Dewdrop:Open(frame, "children", opts, "cursorX", true, "cursorY", true)
|
flickerstreak@33
|
479 end
|
flickerstreak@33
|
480 CloseMenu = function(frame)
|
flickerstreak@33
|
481 if Dewdrop:GetOpenedParent() == frame then
|
flickerstreak@33
|
482 Dewdrop:Close()
|
flickerstreak@33
|
483 end
|
flickerstreak@33
|
484 end
|
flickerstreak@33
|
485 end
|
flickerstreak@33
|
486
|
flickerstreak@33
|
487
|
flickerstreak@33
|
488 function Bar:ShowControls(show)
|
flickerstreak@33
|
489 if show then
|
flickerstreak@33
|
490 if not self.controlFrame then
|
flickerstreak@33
|
491 self.controlFrame = CreateControls(self)
|
flickerstreak@33
|
492 end
|
flickerstreak@33
|
493 self.controlFrame:Show()
|
flickerstreak@33
|
494 elseif self.controlFrame then
|
flickerstreak@33
|
495 CloseMenu(self.controlFrame)
|
flickerstreak@33
|
496 self.controlFrame:Hide()
|
flickerstreak@33
|
497 end
|
flickerstreak@33
|
498 end
|
flickerstreak@33
|
499
|
flickerstreak@33
|
500 function Bar:ShowMenu()
|
flickerstreak@33
|
501 if not self.menuOpts then
|
flickerstreak@33
|
502 self.menuOpts = {
|
flickerstreak@33
|
503 type = "group",
|
flickerstreak@33
|
504 args = {
|
flickerstreak@33
|
505 openConfig = {
|
flickerstreak@33
|
506 type = "execute",
|
flickerstreak@50
|
507 name = L["Layout..."],
|
flickerstreak@50
|
508 desc = L["Open the layout editor for this bar"],
|
flickerstreak@50
|
509 func = function() CloseMenu(self.controlFrame); ReAction:CallModuleMethod("ConfigUI","LaunchLayoutEditor",self) end,
|
flickerstreak@33
|
510 disabled = InCombatLockdown,
|
flickerstreak@33
|
511 order = 1
|
flickerstreak@33
|
512 },
|
flickerstreak@33
|
513 delete = {
|
flickerstreak@33
|
514 type = "execute",
|
flickerstreak@33
|
515 name = L["Delete Bar"],
|
flickerstreak@33
|
516 desc = L["Remove the bar from the current profile"],
|
flickerstreak@50
|
517 confirm = L["Are you sure you want to remove this bar?"],
|
flickerstreak@33
|
518 func = function() ReAction:EraseBar(self) end,
|
flickerstreak@33
|
519 order = 2
|
flickerstreak@33
|
520 },
|
flickerstreak@33
|
521 }
|
flickerstreak@33
|
522 }
|
flickerstreak@33
|
523 end
|
flickerstreak@33
|
524 OpenMenu(self.controlFrame, self.menuOpts)
|
flickerstreak@33
|
525 end
|
flickerstreak@33
|
526
|
flickerstreak@33
|
527
|
flickerstreak@33
|
528
|
flickerstreak@28
|
529 ------ Export as a class-factory ------
|
flickerstreak@28
|
530 ReAction.Bar = {
|
flickerstreak@28
|
531 new = function(self, ...)
|
flickerstreak@28
|
532 local x = { }
|
flickerstreak@28
|
533 for k,v in pairs(Bar) do
|
flickerstreak@28
|
534 x[k] = v
|
flickerstreak@28
|
535 end
|
flickerstreak@28
|
536 Constructor(x, ...)
|
flickerstreak@28
|
537 return x
|
flickerstreak@28
|
538 end
|
flickerstreak@28
|
539 }
|