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