annotate modules/ReAction_ConfigUI/ReAction_ConfigUI.lua @ 28:21bcaf8215ff

- converted to Ace3 - rearranged file layout - configGUI menus not working right now
author Flick <flickerstreak@gmail.com>
date Mon, 17 Mar 2008 18:24:53 +0000
parents bf997ea151ca
children 0d95ce7a9ec2
rev   line source
flickerstreak@25 1 --[[
flickerstreak@25 2 ReAction Configuration UI module
flickerstreak@25 3
flickerstreak@25 4 This modules creates and manages ReAction configuration
flickerstreak@25 5 elements, including:
flickerstreak@25 6
flickerstreak@25 7 - waterfall config menu system
flickerstreak@25 8 - bar dragging and resizing control overlays
flickerstreak@25 9 - contextual menus
flickerstreak@25 10
flickerstreak@25 11 Individual modules are responsible for populating these
flickerstreak@25 12 configuration elements via the following functions:
flickerstreak@25 13
flickerstreak@25 14 module:GetGlobalOptions( configModule )
flickerstreak@25 15 module:GetGlobalBarOptions( configModule )
flickerstreak@25 16 module:GetModuleOptions( configModule )
flickerstreak@25 17 module:GetBarConfigOptions( bar, configModule )
flickerstreak@25 18 module:GetBarMenuOptions( bar, configModule )
flickerstreak@25 19
flickerstreak@25 20 the ReAction_ConfigUI module is passed in as a parameter so that
flickerstreak@25 21 option handlers can refresh the config UI.
flickerstreak@25 22
flickerstreak@25 23 --]]
flickerstreak@25 24
flickerstreak@25 25 -- local imports
flickerstreak@25 26 local ReAction = ReAction
flickerstreak@25 27 local L = ReAction.L
flickerstreak@25 28 local _G = _G
flickerstreak@25 29 local Waterfall = AceLibrary("Waterfall-1.0")
flickerstreak@25 30 local Dewdrop = AceLibrary("Dewdrop-2.0")
flickerstreak@25 31 local print = ReAction.print
flickerstreak@25 32 local InCombatLockdown = InCombatLockdown
flickerstreak@25 33
flickerstreak@25 34 -- module declaration
flickerstreak@25 35 local moduleID = "ConfigUI"
flickerstreak@25 36 local module = ReAction:NewModule( moduleID,
flickerstreak@28 37 "AceEvent-3.0"
flickerstreak@25 38 -- mixins go here
flickerstreak@25 39 )
flickerstreak@25 40
flickerstreak@25 41 module.globalOptions = {
flickerstreak@25 42 type = "group",
flickerstreak@25 43 args = {
flickerstreak@25 44 unlock = {
flickerstreak@25 45 type = "toggle",
flickerstreak@25 46 handler = module,
flickerstreak@25 47 name = L["unlock"],
flickerstreak@25 48 guiName = L["Unlock Bars"],
flickerstreak@25 49 desc = L["Unlock bars for dragging and resizing with the mouse"],
flickerstreak@25 50 get = function() return module.configMode end,
flickerstreak@25 51 set = "SetConfigMode",
flickerstreak@25 52 disabled = InCombatLockdown,
flickerstreak@25 53 order = 1
flickerstreak@25 54 },
flickerstreak@25 55 config = {
flickerstreak@25 56 type = "execute",
flickerstreak@25 57 handler = module,
flickerstreak@25 58 name = L["config"],
flickerstreak@25 59 guiName = L["Configure..."],
flickerstreak@25 60 desc = L["Open the configuration dialogue"],
flickerstreak@25 61 func = "OpenConfig",
flickerstreak@25 62 disabled = InCombatLockdown,
flickerstreak@25 63 wfHidden = true, -- don't show this in the waterfall config
flickerstreak@25 64 order = 2
flickerstreak@25 65 },
flickerstreak@25 66 }
flickerstreak@25 67 }
flickerstreak@25 68
flickerstreak@25 69 module.configOptions = {
flickerstreak@25 70 type = "group",
flickerstreak@25 71 args = {
flickerstreak@25 72 global = {
flickerstreak@25 73 type = "group",
flickerstreak@25 74 name = L["Global Settings"],
flickerstreak@25 75 desc = L["Global configuration settings"],
flickerstreak@25 76 args = { },
flickerstreak@25 77 order = 1,
flickerstreak@25 78 },
flickerstreak@25 79 module = {
flickerstreak@25 80 type = "group",
flickerstreak@25 81 name = L["Module Settings"],
flickerstreak@25 82 desc = L["Configuration settings for each module"],
flickerstreak@25 83 args = { },
flickerstreak@25 84 order = 2,
flickerstreak@25 85 },
flickerstreak@25 86 bar = {
flickerstreak@25 87 type = "group",
flickerstreak@25 88 name = L["Bars"],
flickerstreak@25 89 desc = L["Configuration settings for bars"],
flickerstreak@25 90 args = { },
flickerstreak@25 91 order = 3,
flickerstreak@25 92 },
flickerstreak@25 93 }
flickerstreak@25 94 }
flickerstreak@25 95
flickerstreak@25 96 -- module methods
flickerstreak@25 97 function module:OnInitialize()
flickerstreak@28 98 self.db = ReAction.db:RegisterNamespace( moduleID,
flickerstreak@25 99 {
flickerstreak@28 100 profile = { }
flickerstreak@25 101 }
flickerstreak@25 102 )
flickerstreak@25 103 end
flickerstreak@25 104
flickerstreak@25 105 function module:OnEnable()
flickerstreak@25 106 self:RegisterEvent("PLAYER_REGEN_DISABLED")
flickerstreak@25 107 Waterfall:Register("ReAction",
flickerstreak@25 108 "aceOptions", self.configOptions,
flickerstreak@25 109 "treeLevels", nil, -- infinite
flickerstreak@25 110 "colorR", 0.8,
flickerstreak@25 111 "colorG", 0.65,
flickerstreak@25 112 "colorB", 0,
flickerstreak@25 113 "defaultPane", "global" )
flickerstreak@25 114 end
flickerstreak@25 115
flickerstreak@25 116 function module:OnDisable()
flickerstreak@25 117 self:UnregisterEvent("PLAYER_REGEN_DISABLED")
flickerstreak@25 118 self:SetConfigMode(false)
flickerstreak@25 119 Waterfall:UnRegister("ReAction")
flickerstreak@25 120 end
flickerstreak@25 121
flickerstreak@25 122 function module:PLAYER_REGEN_DISABLED()
flickerstreak@25 123 if self.configMode == true then
flickerstreak@25 124 UIErrorsFrame:AddMessage(L["ReAction config mode disabled during combat."])
flickerstreak@25 125 self:SetConfigMode(false)
flickerstreak@25 126 Waterfall:Close("ReAction")
flickerstreak@25 127 end
flickerstreak@25 128 end
flickerstreak@25 129
flickerstreak@25 130 function module:SetConfigMode( mode )
flickerstreak@28 131 ReAction:CallMethodOnAllBars("ShowControls",mode)
flickerstreak@28 132 ReAction:CallMethodOnAllModules("ApplyConfigMode",mode,ReAction.bars)
flickerstreak@25 133 self.configMode = mode
flickerstreak@25 134 end
flickerstreak@25 135
flickerstreak@25 136 function module:ApplyConfigMode( mode, bars )
flickerstreak@25 137 if not(mode) then
flickerstreak@25 138 -- close open dewdrop menu
flickerstreak@25 139 local p = Dewdrop:GetOpenedParent()
flickerstreak@25 140 if p then
flickerstreak@25 141 for _, bar in pairs(bars) do
flickerstreak@25 142 if bar then
flickerstreak@25 143 if p == bar.controlFrame then
flickerstreak@25 144 Dewdrop:Close()
flickerstreak@25 145 end
flickerstreak@25 146 end
flickerstreak@25 147 end
flickerstreak@25 148 end
flickerstreak@25 149 end
flickerstreak@25 150 end
flickerstreak@25 151
flickerstreak@25 152 local function refreshWaterfall()
flickerstreak@25 153 module:RefreshConfig()
flickerstreak@25 154 end
flickerstreak@25 155
flickerstreak@28 156 local function SafeCall(module, method, ...)
flickerstreak@28 157 if module and type(module[method]) == "function" then
flickerstreak@28 158 return module[method](...)
flickerstreak@28 159 end
flickerstreak@28 160 end
flickerstreak@28 161
flickerstreak@25 162 function module:RefreshOptions()
flickerstreak@25 163 local opts = self.configOptions.args
flickerstreak@25 164
flickerstreak@28 165 for _, m in ReAction:IterateModules() do
flickerstreak@28 166 local o = SafeCall(m,"GetGlobalOptions",self)
flickerstreak@25 167 if o then
flickerstreak@25 168 for k, v in pairs(o) do
flickerstreak@25 169 opts.global.args[k] = v
flickerstreak@25 170 end
flickerstreak@25 171 end
flickerstreak@25 172 end
flickerstreak@25 173
flickerstreak@28 174 for _, m in ReAction:IterateModules() do
flickerstreak@28 175 local o = SafeCall(m,"GetGlobalBarOptions",self)
flickerstreak@25 176 if o then
flickerstreak@25 177 for k, v in pairs(o) do
flickerstreak@25 178 opts.bar.args[k] = v
flickerstreak@25 179 end
flickerstreak@25 180 end
flickerstreak@25 181 end
flickerstreak@25 182
flickerstreak@28 183 for _, m in ReAction:IterateModules() do
flickerstreak@28 184 local o = SafeCall(m,"GetModuleOptions",self)
flickerstreak@25 185 if o then
flickerstreak@25 186 for k, v in pairs(o) do
flickerstreak@25 187 opts.module.args[k] = v
flickerstreak@25 188 end
flickerstreak@25 189 end
flickerstreak@25 190 end
flickerstreak@25 191
flickerstreak@25 192 local barOpts = opts.bar.args
flickerstreak@28 193 for name, bar in pairs(ReAction.bars) do
flickerstreak@25 194 if bar then
flickerstreak@25 195 if barOpts[name] == nil then
flickerstreak@25 196 barOpts[name] = {
flickerstreak@25 197 type = "group",
flickerstreak@25 198 name = name,
flickerstreak@25 199 desc = name,
flickerstreak@25 200 handler = bar,
flickerstreak@28 201 args = {
flickerstreak@28 202 delete = {
flickerstreak@28 203 type = "execute",
flickerstreak@28 204 name = L["Delete Bar"],
flickerstreak@28 205 desc = L["Remove the bar from the current profile"],
flickerstreak@28 206 func = function() ReAction:EraseBar(bar); self:RefreshConfig() end
flickerstreak@28 207 },
flickerstreak@28 208 rename = {
flickerstreak@28 209 type = "text",
flickerstreak@28 210 name = L["Rename Bar"],
flickerstreak@28 211 desc = L["Set a name for the bar"],
flickerstreak@28 212 get = "GetName",
flickerstreak@28 213 set = function(name) ReAction:RenameBar(bar,name); self:RefreshConfig() end
flickerstreak@28 214 }
flickerstreak@28 215 }
flickerstreak@25 216 }
flickerstreak@25 217 end
flickerstreak@25 218 if bar.modConfigOpts == nil then
flickerstreak@25 219 bar.modConfigOpts = { }
flickerstreak@25 220 end
flickerstreak@28 221 for _, m in ReAction:IterateModules() do
flickerstreak@28 222 local o = SafeCall(m,"GetBarConfigOptions",bar,self)
flickerstreak@25 223 if o then
flickerstreak@25 224 for k, v in pairs(o) do
flickerstreak@25 225 barOpts[name].args[k] = v
flickerstreak@25 226 end
flickerstreak@25 227 end
flickerstreak@25 228 end
flickerstreak@25 229 end
flickerstreak@25 230 end
flickerstreak@25 231 -- remove obsolete bar tables
flickerstreak@25 232 for name, opt in pairs(barOpts) do
flickerstreak@28 233 if opt.type == "group" and ReAction.bars[name] == nil then
flickerstreak@25 234 barOpts[name] = nil
flickerstreak@25 235 end
flickerstreak@25 236 end
flickerstreak@25 237 end
flickerstreak@25 238
flickerstreak@25 239 function module:OpenConfig(bar)
flickerstreak@25 240 self:RefreshOptions()
flickerstreak@25 241 Dewdrop:Close()
flickerstreak@25 242 Waterfall:Open("ReAction",bar and "bar."..bar:GetName())
flickerstreak@25 243 end
flickerstreak@25 244
flickerstreak@25 245 function module:RefreshConfig()
flickerstreak@25 246 self:RefreshOptions()
flickerstreak@25 247 Waterfall:Refresh("ReAction")
flickerstreak@25 248 end
flickerstreak@25 249
flickerstreak@25 250 function module:ApplyToBar(bar)
flickerstreak@25 251 if self.configMode then
flickerstreak@25 252 bar:ShowControls(true)
flickerstreak@25 253 end
flickerstreak@25 254 end
flickerstreak@25 255
flickerstreak@25 256 function module:RemoveFromBar(bar)
flickerstreak@25 257 if bar.controlFrame then
flickerstreak@25 258 bar.controlFrame:SetParent(UIParent)
flickerstreak@25 259 bar.controlFrame:ClearAllPoints()
flickerstreak@25 260 bar.controlFrame:Hide()
flickerstreak@25 261 bar.controlFrame = nil
flickerstreak@25 262 end
flickerstreak@25 263 end
flickerstreak@25 264
flickerstreak@25 265 function module:GetGlobalOptions()
flickerstreak@25 266 return self.globalOptions.args
flickerstreak@25 267 end
flickerstreak@25 268
flickerstreak@25 269
flickerstreak@25 270
flickerstreak@25 271
flickerstreak@25 272
flickerstreak@25 273 --
flickerstreak@25 274 -- Bar config overlay
flickerstreak@25 275 --
flickerstreak@25 276 -- import some of these for small OnUpdate performance boost
flickerstreak@28 277 local Bar = ReAction.Bar.prototype
flickerstreak@25 278 local GetSize = Bar.GetSize
flickerstreak@25 279 local GetButtonSize = Bar.GetButtonSize
flickerstreak@25 280 local GetButtonGrid = Bar.GetButtonGrid
flickerstreak@25 281 local SetSize = Bar.SetSize
flickerstreak@25 282 local SetButtonSize = Bar.SetButtonSize
flickerstreak@25 283 local SetButtonGrid = Bar.SetButtonGrid
flickerstreak@25 284 local ApplyAnchor = Bar.ApplyAnchor
flickerstreak@25 285 local floor = math.floor
flickerstreak@25 286 local min = math.min
flickerstreak@25 287 local format = string.format
flickerstreak@25 288 local GameTooltip = GameTooltip
flickerstreak@25 289
flickerstreak@25 290 local function StoreExtents(bar)
flickerstreak@25 291 local f = bar.frame
flickerstreak@25 292 local point, relativeTo, relativePoint, x, y = f:GetPoint(1)
flickerstreak@25 293 relativeTo = relativeTo or f:GetParent()
flickerstreak@25 294 local anchorTo
flickerstreak@28 295 for name, b in pairs(ReAction.bars) do
flickerstreak@25 296 if b then
flickerstreak@25 297 if b:GetFrame() == relativeTo then
flickerstreak@25 298 anchorTo = name
flickerstreak@25 299 break
flickerstreak@25 300 end
flickerstreak@25 301 end
flickerstreak@25 302 end
flickerstreak@25 303 anchorTo = anchorTo or relativeTo:GetName()
flickerstreak@25 304 local c = bar.config
flickerstreak@25 305 c.anchor = point
flickerstreak@25 306 c.anchorTo = anchorTo
flickerstreak@25 307 c.relativePoint = relativePoint
flickerstreak@25 308 c.x = x
flickerstreak@25 309 c.y = y
flickerstreak@25 310 c.width, c.height = f:GetWidth(), f:GetHeight()
flickerstreak@25 311 end
flickerstreak@25 312
flickerstreak@25 313 local function RecomputeButtonSize(bar)
flickerstreak@25 314 local w, h = GetSize(bar)
flickerstreak@25 315 local bw, bh = GetButtonSize(bar)
flickerstreak@25 316 local r, c, s = GetButtonGrid(bar)
flickerstreak@25 317
flickerstreak@25 318 local scaleW = (floor(w/c) - s) / bw
flickerstreak@25 319 local scaleH = (floor(h/r) - s) / bh
flickerstreak@25 320 local scale = min(scaleW, scaleH)
flickerstreak@25 321
flickerstreak@25 322 SetButtonSize(bar, scale * bw, scale * bh, s)
flickerstreak@25 323 end
flickerstreak@25 324
flickerstreak@25 325 local function RecomputeButtonSpacing(bar)
flickerstreak@25 326 local w, h = GetSize(bar)
flickerstreak@25 327 local bw, bh = GetButtonSize(bar)
flickerstreak@25 328 local r, c, s = GetButtonGrid(bar)
flickerstreak@25 329
flickerstreak@25 330 SetButtonGrid(bar,r,c,min(floor(w/c) - bw, floor(h/r) - bh))
flickerstreak@25 331 end
flickerstreak@25 332
flickerstreak@25 333 local function RecomputeGrid(bar)
flickerstreak@25 334 local w, h = GetSize(bar)
flickerstreak@25 335 local bw, bh = GetButtonSize(bar)
flickerstreak@25 336 local r, c, s = GetButtonGrid(bar)
flickerstreak@25 337
flickerstreak@25 338 SetButtonGrid(bar, floor(h/(bh+s)), floor(w/(bw+s)), s)
flickerstreak@25 339 end
flickerstreak@25 340
flickerstreak@25 341 local function ClampToButtons(bar)
flickerstreak@25 342 local bw, bh = GetButtonSize(bar)
flickerstreak@25 343 local r, c, s = GetButtonGrid(bar)
flickerstreak@25 344 SetSize(bar, (bw+s)*c, (bh+s)*r )
flickerstreak@25 345 end
flickerstreak@25 346
flickerstreak@25 347 local function HideGameTooltip()
flickerstreak@25 348 GameTooltip:Hide()
flickerstreak@25 349 end
flickerstreak@25 350
flickerstreak@25 351 local function CreateControls(bar)
flickerstreak@25 352 local f = bar.frame
flickerstreak@25 353
flickerstreak@25 354 f:SetMovable(true)
flickerstreak@25 355 f:SetResizable(true)
flickerstreak@25 356 f:SetClampedToScreen(true)
flickerstreak@25 357
flickerstreak@25 358 -- buttons on the bar should be direct children of the bar frame.
flickerstreak@25 359 -- The control elements need to float on top of this, which we could
flickerstreak@25 360 -- do with SetFrameLevel() or Raise(), but it's more reliable to do it
flickerstreak@25 361 -- via frame nesting, hence good old foo's appearance here.
flickerstreak@25 362 local foo = CreateFrame("Frame",nil,f)
flickerstreak@25 363 foo:SetAllPoints()
flickerstreak@25 364
flickerstreak@25 365 local control = CreateFrame("Button", nil, foo)
flickerstreak@25 366 control:EnableMouse(true)
flickerstreak@25 367 control:SetToplevel(true)
flickerstreak@25 368 control:SetPoint("TOPLEFT", -4, 4)
flickerstreak@25 369 control:SetPoint("BOTTOMRIGHT", 4, -4)
flickerstreak@25 370 control:SetBackdrop({
flickerstreak@25 371 edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
flickerstreak@25 372 tile = true,
flickerstreak@25 373 tileSize = 16,
flickerstreak@25 374 edgeSize = 16,
flickerstreak@25 375 insets = { left = 0, right = 0, top = 0, bottom = 0 },
flickerstreak@25 376 })
flickerstreak@25 377
flickerstreak@25 378 -- textures
flickerstreak@25 379 local bgTex = control:CreateTexture(nil,"BACKGROUND")
flickerstreak@25 380 bgTex:SetTexture(0.7,0.7,1.0,0.2)
flickerstreak@25 381 bgTex:SetPoint("TOPLEFT",4,-4)
flickerstreak@25 382 bgTex:SetPoint("BOTTOMRIGHT",-4,4)
flickerstreak@25 383 local hTex = control:CreateTexture(nil,"HIGHLIGHT")
flickerstreak@25 384 hTex:SetTexture(0.7,0.7,1.0,0.2)
flickerstreak@25 385 hTex:SetPoint("TOPLEFT",4,-4)
flickerstreak@25 386 hTex:SetPoint("BOTTOMRIGHT",-4,4)
flickerstreak@25 387 hTex:SetBlendMode("ADD")
flickerstreak@25 388
flickerstreak@25 389 -- label
flickerstreak@25 390 local label = control:CreateFontString(nil,"OVERLAY","GameFontNormalLarge")
flickerstreak@25 391 label:SetAllPoints()
flickerstreak@25 392 label:SetJustifyH("CENTER")
flickerstreak@25 393 label:SetShadowColor(0,0,0,1)
flickerstreak@25 394 label:SetShadowOffset(2,-2)
flickerstreak@25 395 label:SetTextColor(1,1,1,1)
flickerstreak@25 396 label:SetText(bar:GetName())
flickerstreak@25 397 label:Show()
flickerstreak@25 398 bar.controlLabelString = label -- so that bar:SetName() can update it
flickerstreak@25 399
flickerstreak@25 400 local StopResize = function()
flickerstreak@25 401 f:StopMovingOrSizing()
flickerstreak@25 402 f.isMoving = false
flickerstreak@25 403 f:SetScript("OnUpdate",nil)
flickerstreak@25 404 StoreExtents(bar)
flickerstreak@25 405 ClampToButtons(bar)
flickerstreak@25 406 ApplyAnchor(bar)
flickerstreak@25 407 end
flickerstreak@25 408
flickerstreak@25 409 -- edge drag handles
flickerstreak@25 410 for _, point in pairs({"LEFT","TOP","RIGHT","BOTTOM"}) do
flickerstreak@25 411 local edge = CreateFrame("Frame",nil,control)
flickerstreak@25 412 edge:EnableMouse(true)
flickerstreak@25 413 edge:SetWidth(8)
flickerstreak@25 414 edge:SetHeight(8)
flickerstreak@25 415 if point == "TOP" or point == "BOTTOM" then
flickerstreak@25 416 edge:SetPoint(point.."LEFT")
flickerstreak@25 417 edge:SetPoint(point.."RIGHT")
flickerstreak@25 418 else
flickerstreak@25 419 edge:SetPoint("TOP"..point)
flickerstreak@25 420 edge:SetPoint("BOTTOM"..point)
flickerstreak@25 421 end
flickerstreak@25 422 local tex = edge:CreateTexture(nil,"HIGHLIGHT")
flickerstreak@25 423 tex:SetTexture(1.0,0.82,0,0.7)
flickerstreak@25 424 tex:SetBlendMode("ADD")
flickerstreak@25 425 tex:SetAllPoints()
flickerstreak@25 426 edge:RegisterForDrag("LeftButton")
flickerstreak@25 427 edge:SetScript("OnMouseDown",
flickerstreak@25 428 function()
flickerstreak@25 429 local bw, bh = GetButtonSize(bar)
flickerstreak@25 430 local r, c, s = GetButtonGrid(bar)
flickerstreak@25 431 f:SetMinResize( bw+s+1, bh+s+1 )
flickerstreak@25 432 f:StartSizing(point)
flickerstreak@25 433 f:SetScript("OnUpdate",
flickerstreak@25 434 function()
flickerstreak@25 435 RecomputeGrid(bar)
flickerstreak@25 436 bar:RefreshLayout()
flickerstreak@25 437 end
flickerstreak@25 438 )
flickerstreak@25 439 end
flickerstreak@25 440 )
flickerstreak@25 441 edge:SetScript("OnMouseUp", StopResize)
flickerstreak@25 442 edge:SetScript("OnEnter",
flickerstreak@25 443 function()
flickerstreak@25 444 GameTooltip:SetOwner(f, "ANCHOR_"..point)
flickerstreak@25 445 GameTooltip:AddLine(L["Drag to add/remove buttons"])
flickerstreak@25 446 GameTooltip:Show()
flickerstreak@25 447 end
flickerstreak@25 448 )
flickerstreak@25 449 edge:SetScript("OnLeave", HideGameTooltip)
flickerstreak@25 450 edge:Show()
flickerstreak@25 451 end
flickerstreak@25 452
flickerstreak@25 453 -- corner drag handles, again nested in an anonymous frame so that they are on top
flickerstreak@25 454 local foo2 = CreateFrame("Frame",nil,control)
flickerstreak@25 455 foo2:SetAllPoints(true)
flickerstreak@25 456 for _, point in pairs({"BOTTOMLEFT","TOPLEFT","BOTTOMRIGHT","TOPRIGHT"}) do
flickerstreak@25 457 local corner = CreateFrame("Frame",nil,foo2)
flickerstreak@25 458 corner:EnableMouse(true)
flickerstreak@25 459 corner:SetWidth(12)
flickerstreak@25 460 corner:SetHeight(12)
flickerstreak@25 461 corner:SetPoint(point)
flickerstreak@25 462 local tex = corner:CreateTexture(nil,"HIGHLIGHT")
flickerstreak@25 463 tex:SetTexture(1.0,0.82,0,0.7)
flickerstreak@25 464 tex:SetBlendMode("ADD")
flickerstreak@25 465 tex:SetAllPoints()
flickerstreak@25 466 corner:RegisterForDrag("LeftButton","RightButton")
flickerstreak@25 467 local updateTooltip = function()
flickerstreak@25 468 local size, size2 = bar:GetButtonSize()
flickerstreak@25 469 local rows, cols, spacing = bar:GetButtonGrid()
flickerstreak@25 470 size = (size == size2) and tostring(size) or format("%dx%d",size,size2)
flickerstreak@25 471 GameTooltipTextRight4:SetText(size)
flickerstreak@25 472 GameTooltipTextRight5:SetText(tostring(spacing))
flickerstreak@25 473 end
flickerstreak@25 474 corner:SetScript("OnMouseDown",
flickerstreak@25 475 function(_,btn)
flickerstreak@25 476 local bw, bh = GetButtonSize(bar)
flickerstreak@25 477 local r, c, s = GetButtonGrid(bar)
flickerstreak@25 478 if btn == "LeftButton" then -- button resize
flickerstreak@25 479 f:SetMinResize( (s+12)*c+1, (s+12)*r+1 )
flickerstreak@25 480 f:SetScript("OnUpdate",
flickerstreak@25 481 function()
flickerstreak@25 482 RecomputeButtonSize(bar)
flickerstreak@25 483 bar:RefreshLayout()
flickerstreak@25 484 updateTooltip()
flickerstreak@25 485 end
flickerstreak@25 486 )
flickerstreak@25 487 elseif btn == "RightButton" then -- spacing resize
flickerstreak@25 488 f:SetMinResize( bw*c, bh*r )
flickerstreak@25 489 f:SetScript("OnUpdate",
flickerstreak@25 490 function()
flickerstreak@25 491 RecomputeButtonSpacing(bar)
flickerstreak@25 492 bar:RefreshLayout()
flickerstreak@25 493 updateTooltip()
flickerstreak@25 494 end
flickerstreak@25 495 )
flickerstreak@25 496 end
flickerstreak@25 497 f:StartSizing(point)
flickerstreak@25 498 end
flickerstreak@25 499 )
flickerstreak@25 500 corner:SetScript("OnMouseUp",StopResize)
flickerstreak@25 501 corner:SetScript("OnEnter",
flickerstreak@25 502 function()
flickerstreak@25 503 GameTooltip:SetOwner(f, "ANCHOR_"..point)
flickerstreak@25 504 GameTooltip:AddLine(L["Drag to resize buttons"])
flickerstreak@25 505 GameTooltip:AddLine(L["Right-click-drag"])
flickerstreak@25 506 GameTooltip:AddLine(L["to change spacing"])
flickerstreak@25 507 local size, size2 = bar:GetButtonSize()
flickerstreak@25 508 local rows, cols, spacing = bar:GetButtonGrid()
flickerstreak@25 509 size = (size == size2) and tostring(size) or format("%dx%d",size,size2)
flickerstreak@25 510 GameTooltip:AddDoubleLine(L["Size:"], size)
flickerstreak@25 511 GameTooltip:AddDoubleLine(L["Spacing:"], tostring(spacing))
flickerstreak@25 512 GameTooltip:Show()
flickerstreak@25 513 end
flickerstreak@25 514 )
flickerstreak@25 515 corner:SetScript("OnLeave",
flickerstreak@25 516 function()
flickerstreak@25 517 GameTooltip:Hide()
flickerstreak@25 518 f:SetScript("OnUpdate",nil)
flickerstreak@25 519 end
flickerstreak@25 520 )
flickerstreak@25 521
flickerstreak@25 522 end
flickerstreak@25 523
flickerstreak@25 524 control:RegisterForDrag("LeftButton")
flickerstreak@25 525 control:RegisterForClicks("RightButtonDown")
flickerstreak@25 526
flickerstreak@25 527 control:SetScript("OnDragStart",
flickerstreak@25 528 function()
flickerstreak@25 529 f:StartMoving()
flickerstreak@25 530 f.isMoving = true
flickerstreak@25 531 -- TODO: snap indicator update install
flickerstreak@25 532 end
flickerstreak@25 533 )
flickerstreak@25 534
flickerstreak@25 535 control:SetScript("OnDragStop",
flickerstreak@25 536 function()
flickerstreak@25 537 f:StopMovingOrSizing()
flickerstreak@25 538 f.isMoving = false
flickerstreak@25 539 f:SetScript("OnUpdate",nil)
flickerstreak@25 540 -- TODO: snap frame here
flickerstreak@25 541 StoreExtents(bar)
flickerstreak@25 542 end
flickerstreak@25 543 )
flickerstreak@25 544
flickerstreak@25 545 control:SetScript("OnEnter",
flickerstreak@25 546 function()
flickerstreak@25 547 -- add bar type and status information to name
flickerstreak@25 548 local name = bar.name
flickerstreak@28 549 for _, m in ReAction:IterateModules() do
flickerstreak@28 550 local suffix = SafeCall(m,"GetBarNameModifier",bar)
flickerstreak@25 551 if suffix then
flickerstreak@25 552 name = format("%s %s",name,suffix)
flickerstreak@25 553 end
flickerstreak@25 554 end
flickerstreak@25 555
flickerstreak@25 556 GameTooltip:SetOwner(f, "ANCHOR_TOPRIGHT")
flickerstreak@25 557 GameTooltip:AddLine(name)
flickerstreak@25 558 GameTooltip:AddLine(L["Drag to move"])
flickerstreak@25 559 --GameTooltip:AddLine(L["Shift-drag for sticky mode"])
flickerstreak@25 560 GameTooltip:AddLine(L["Right-click for options"])
flickerstreak@25 561 GameTooltip:Show()
flickerstreak@25 562 end
flickerstreak@25 563 )
flickerstreak@25 564
flickerstreak@25 565 control:SetScript("OnLeave", HideGameTooltip)
flickerstreak@25 566
flickerstreak@25 567 control:SetScript("OnClick",
flickerstreak@25 568 function()
flickerstreak@25 569 bar:ShowMenu()
flickerstreak@25 570 end
flickerstreak@25 571 )
flickerstreak@25 572
flickerstreak@25 573 return control
flickerstreak@25 574 end
flickerstreak@25 575
flickerstreak@25 576 function Bar:ShowControls(show)
flickerstreak@25 577 if show then
flickerstreak@25 578 if not self.controlFrame then
flickerstreak@25 579 self.controlFrame = CreateControls(self)
flickerstreak@25 580 end
flickerstreak@25 581 self.controlFrame:Show()
flickerstreak@25 582 elseif self.controlFrame then
flickerstreak@25 583 self.controlFrame:Hide()
flickerstreak@25 584 end
flickerstreak@25 585 end
flickerstreak@25 586
flickerstreak@25 587 function Bar:ShowMenu()
flickerstreak@25 588 if not self.menuOpts then
flickerstreak@25 589 self.menuOpts = {
flickerstreak@25 590 type = "group",
flickerstreak@25 591 args = {
flickerstreak@25 592 openConfig = {
flickerstreak@25 593 type = "execute",
flickerstreak@25 594 name = L["Configure..."],
flickerstreak@25 595 desc = L["Open the configuration dialogue for this bar"],
flickerstreak@25 596 func = function() module:OpenConfig(self) end,
flickerstreak@25 597 disabled = InCombatLockdown,
flickerstreak@25 598 order = 1
flickerstreak@28 599 },
flickerstreak@28 600 delete = {
flickerstreak@28 601 type = "execute",
flickerstreak@28 602 name = L["Delete Bar"],
flickerstreak@28 603 desc = L["Remove the bar from the current profile"],
flickerstreak@28 604 func = function() ReAction:EraseBar(self) end,
flickerstreak@28 605 order = 2
flickerstreak@28 606 },
flickerstreak@25 607 }
flickerstreak@25 608 }
flickerstreak@25 609 end
flickerstreak@25 610 if self.modMenuOpts == nil then
flickerstreak@25 611 self.modMenuOpts = { }
flickerstreak@25 612 end
flickerstreak@28 613 for _, m in ReAction:IterateModules() do
flickerstreak@28 614 local opts = SafeCall(m,"GetBarMenuOptions",self,module)
flickerstreak@28 615 if opts then
flickerstreak@28 616 for k, v in pairs(opts) do
flickerstreak@28 617 self.menuOpts.args[k] = v
flickerstreak@28 618 end
flickerstreak@25 619 end
flickerstreak@25 620 end
flickerstreak@25 621 Dewdrop:Open(self.controlFrame, "children", self.menuOpts, "cursorX", true, "cursorY", true)
flickerstreak@25 622 end
flickerstreak@25 623
flickerstreak@25 624 local Bar_SuperSetName = Bar.SetName
flickerstreak@25 625 function Bar:SetName(name)
flickerstreak@25 626 Bar_SuperSetName(self,name)
flickerstreak@25 627 if self.controlLabelString then
flickerstreak@25 628 self.controlLabelString:SetText(self.name)
flickerstreak@25 629 end
flickerstreak@25 630 end