annotate modules/ReAction_ConfigUI/ReAction_ConfigUI.lua @ 25:bf997ea151ca

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