annotate Editor.lua @ 237:704f4a05a1d7

Demodulificate all bar options (except state options)
author Flick
date Thu, 24 Mar 2011 13:11:30 -0700
parents a5d91d7fd485
children f255cd69e890
rev   line source
flickerstreak@175 1 local addonName, addonTable = ...
flickerstreak@175 2 local ReAction = addonTable.ReAction
flickerstreak@109 3 local L = ReAction.L
flickerstreak@109 4 local _G = _G
flickerstreak@185 5 local wipe = wipe
flickerstreak@185 6
flickerstreak@109 7 local AceConfigReg = LibStub("AceConfigRegistry-3.0")
flickerstreak@109 8 local AceConfigDialog = LibStub("AceConfigDialog-3.0")
flickerstreak@109 9
flickerstreak@109 10
flickerstreak@185 11 local pointTable = {
flickerstreak@185 12 CENTER = L["Center"],
flickerstreak@185 13 LEFT = L["Left"],
flickerstreak@185 14 RIGHT = L["Right"],
flickerstreak@185 15 TOP = L["Top"],
flickerstreak@185 16 BOTTOM = L["Bottom"],
flickerstreak@185 17 TOPLEFT = L["Top Left"],
flickerstreak@185 18 TOPRIGHT = L["Top Right"],
flickerstreak@185 19 BOTTOMLEFT = L["Bottom Left"],
flickerstreak@185 20 BOTTOMRIGHT = L["Bottom Right"],
flickerstreak@185 21 }
flickerstreak@109 22
Flick@237 23 local Editor = {
Flick@237 24 buttonHandlers = { }
Flick@237 25 }
flickerstreak@109 26
flickerstreak@185 27 function Editor:New()
flickerstreak@185 28 -- create new self
flickerstreak@185 29 self = setmetatable( { }, { __index = self } )
flickerstreak@109 30
flickerstreak@185 31 self.barOptMap = setmetatable({},{__mode="v"})
flickerstreak@185 32 self.tmp = { }
flickerstreak@185 33 self.configID = "ReAction-Editor"
flickerstreak@109 34
flickerstreak@185 35 self.gui = LibStub("AceGUI-3.0"):Create("Frame")
flickerstreak@185 36
flickerstreak@185 37 local frame = self.gui.frame
flickerstreak@109 38 frame:SetClampedToScreen(true)
flickerstreak@109 39 frame:Hide()
flickerstreak@185 40
flickerstreak@185 41 frame:SetScript("OnHide",
flickerstreak@185 42 function(...)
flickerstreak@109 43 ReAction:SetConfigMode(false)
flickerstreak@185 44 end)
flickerstreak@109 45
flickerstreak@195 46 self.title = ("%s - %s"):format(L["ReAction"],L["Bar Editor"])
flickerstreak@195 47 self.gui:SetTitle(self.title)
flickerstreak@195 48
flickerstreak@185 49 self.options = {
flickerstreak@109 50 type = "group",
flickerstreak@195 51 name = self.title,
flickerstreak@185 52 handler = self,
flickerstreak@185 53 childGroups = "select",
flickerstreak@109 54 args = {
flickerstreak@109 55 launchConfig = {
flickerstreak@109 56 type = "execute",
flickerstreak@109 57 name = L["Global Config"],
flickerstreak@109 58 desc = L["Opens ReAction global configuration settings panel"],
flickerstreak@194 59 func = function() ReAction:ShowOptions(); self:Close() end,
flickerstreak@185 60 order = 1
flickerstreak@109 61 },
flickerstreak@185 62 desc = {
flickerstreak@185 63 type = "description",
flickerstreak@185 64 name = L["Use the mouse to arrange and resize the bars on screen. Tooltips on bars indicate additional functionality."],
flickerstreak@195 65 order = 2,
flickerstreak@195 66 },
flickerstreak@195 67 hdr = {
flickerstreak@195 68 type = "header",
flickerstreak@195 69 name = L["Select Bar"],
flickerstreak@194 70 order = 3,
flickerstreak@185 71 },
flickerstreak@185 72 _new = {
flickerstreak@109 73 type = "group",
flickerstreak@109 74 name = L["New Bar..."],
flickerstreak@194 75 order = 4,
flickerstreak@109 76 args = {
flickerstreak@109 77 desc = {
flickerstreak@109 78 type = "description",
flickerstreak@109 79 name = L["Choose a name, type, and initial grid for your new action bar:"],
flickerstreak@109 80 order = 1,
flickerstreak@109 81 },
flickerstreak@109 82 name = {
flickerstreak@109 83 type = "input",
flickerstreak@109 84 name = L["Bar Name"],
flickerstreak@109 85 desc = L["Enter a name for your new action bar"],
flickerstreak@185 86 get = function() return self.tmp.barName or "" end,
flickerstreak@185 87 set = function(info, val) self.tmp.barName = val end,
flickerstreak@109 88 order = 2,
flickerstreak@109 89 },
flickerstreak@109 90 type = {
flickerstreak@109 91 type = "select",
flickerstreak@109 92 name = L["Button Type"],
flickerstreak@185 93 get = function() return self.tmp.barType or ReAction:GetDefaultBarType() or "" end,
flickerstreak@109 94 set = function(info, val)
flickerstreak@218 95 local c = ReAction:GetDefaultBarConfig(val)
flickerstreak@185 96 self.tmp.barType = val
flickerstreak@218 97 self.tmp.barSize = c.btnWidth or self.tmp.barSize
flickerstreak@218 98 self.tmp.barRows = c.btnRows or self.tmp.barRows
flickerstreak@218 99 self.tmp.barCols = c.btnColumns or self.tmp.barCols
flickerstreak@218 100 self.tmp.barSpacing = c.spacing or self.tmp.barSpacing
flickerstreak@109 101 end,
flickerstreak@109 102 values = "GetBarTypes",
flickerstreak@109 103 order = 3,
flickerstreak@109 104 },
flickerstreak@185 105 go = {
flickerstreak@185 106 type = "execute",
flickerstreak@185 107 name = L["Create Bar"],
flickerstreak@185 108 func = "CreateBar",
flickerstreak@185 109 order = 4,
flickerstreak@185 110 },
flickerstreak@109 111 grid = {
flickerstreak@109 112 type = "group",
flickerstreak@109 113 name = L["Button Grid"],
flickerstreak@109 114 inline = true,
flickerstreak@185 115 order = 5,
flickerstreak@109 116 args = {
flickerstreak@109 117 rows = {
flickerstreak@109 118 type = "range",
flickerstreak@109 119 name = L["Rows"],
flickerstreak@185 120 get = function() return self.tmp.barRows or 1 end,
flickerstreak@185 121 set = function(info, val) self.tmp.barRows = val end,
flickerstreak@185 122 width = "full",
flickerstreak@109 123 min = 1,
flickerstreak@109 124 max = 32,
flickerstreak@109 125 step = 1,
flickerstreak@109 126 order = 2,
flickerstreak@109 127 },
flickerstreak@109 128 cols = {
flickerstreak@109 129 type = "range",
flickerstreak@109 130 name = L["Columns"],
flickerstreak@185 131 get = function() return self.tmp.barCols or 12 end,
flickerstreak@185 132 set = function(info, val) self.tmp.barCols = val end,
flickerstreak@185 133 width = "full",
flickerstreak@109 134 min = 1,
flickerstreak@109 135 max = 32,
flickerstreak@109 136 step = 1,
flickerstreak@109 137 order = 3,
flickerstreak@109 138 },
flickerstreak@109 139 sz = {
flickerstreak@109 140 type = "range",
flickerstreak@109 141 name = L["Size"],
flickerstreak@185 142 get = function() return self.tmp.barSize or 36 end,
flickerstreak@185 143 set = function(info, val) self.tmp.barSize = val end,
flickerstreak@185 144 width = "full",
flickerstreak@109 145 min = 10,
flickerstreak@109 146 max = 72,
flickerstreak@109 147 step = 1,
flickerstreak@109 148 order = 4,
flickerstreak@109 149 },
flickerstreak@109 150 spacing = {
flickerstreak@109 151 type = "range",
flickerstreak@109 152 name = L["Spacing"],
flickerstreak@185 153 get = function() return self.tmp.barSpacing or 3 end,
flickerstreak@185 154 set = function(info, val) self.tmp.barSpacing = val end,
flickerstreak@185 155 width = "full",
flickerstreak@109 156 min = 0,
flickerstreak@109 157 max = 24,
flickerstreak@109 158 step = 1,
flickerstreak@109 159 order = 5,
flickerstreak@109 160 }
flickerstreak@195 161 }
flickerstreak@195 162 }
flickerstreak@109 163 }
flickerstreak@109 164 }
flickerstreak@195 165 }
flickerstreak@109 166 }
flickerstreak@109 167
flickerstreak@185 168 self.gui:SetCallback("OnClose",
flickerstreak@185 169 function()
flickerstreak@185 170 ReAction:SetConfigMode(false)
flickerstreak@185 171 end )
flickerstreak@185 172
flickerstreak@185 173 AceConfigReg:RegisterOptionsTable(self.configID, self.options)
flickerstreak@185 174 AceConfigDialog:SetDefaultSize(self.configID, 700, 540)
flickerstreak@185 175
flickerstreak@185 176 ReAction.RegisterCallback(self,"OnCreateBar")
flickerstreak@185 177 ReAction.RegisterCallback(self,"OnDestroyBar")
flickerstreak@185 178 ReAction.RegisterCallback(self,"OnRenameBar")
flickerstreak@185 179
flickerstreak@216 180 self:RefreshBarOptions()
flickerstreak@109 181
flickerstreak@185 182 return self
flickerstreak@109 183 end
flickerstreak@109 184
flickerstreak@109 185
flickerstreak@185 186 function Editor:Open(bar, ...)
flickerstreak@185 187 if bar then
flickerstreak@185 188 AceConfigDialog:SelectGroup(self.configID, self.barOptMap[bar:GetName()], ...)
flickerstreak@185 189 end
flickerstreak@185 190 AceConfigDialog:Open(self.configID,self.gui)
flickerstreak@185 191 self.gui:SetTitle(self.title)
flickerstreak@185 192 end
flickerstreak@185 193
flickerstreak@185 194 function Editor:Close()
flickerstreak@185 195 if self.gui then
flickerstreak@185 196 self.gui:ReleaseChildren()
flickerstreak@185 197 self.gui:Hide()
flickerstreak@109 198 end
flickerstreak@109 199 end
flickerstreak@109 200
flickerstreak@185 201 function Editor:Refresh()
flickerstreak@185 202 AceConfigReg:NotifyChange(self.configID)
flickerstreak@185 203 end
flickerstreak@185 204
flickerstreak@216 205 function Editor:UpdateBarOptions(bar)
flickerstreak@185 206 local name = bar:GetName()
flickerstreak@216 207 local key = self.barOptMap[name]
flickerstreak@185 208 local args = self.options.args
flickerstreak@216 209
flickerstreak@216 210 if not key then
flickerstreak@216 211 -- AceConfig doesn't allow spaces, etc, in arg key names, and they must be
flickerstreak@216 212 -- unique strings. So generate a unique key (it can be whatever) for the bar
flickerstreak@216 213 local i = 1
flickerstreak@216 214 repeat
flickerstreak@216 215 key = ("bar%s"):format(i)
flickerstreak@216 216 i = i+1
flickerstreak@216 217 until args[key] == nil
flickerstreak@216 218 self.barOptMap[name] = key
flickerstreak@216 219
flickerstreak@216 220 args[key] = {
flickerstreak@216 221 type = "group",
flickerstreak@216 222 name = name,
flickerstreak@216 223 childGroups = "tab",
flickerstreak@216 224 order = i+100,
flickerstreak@216 225 args = {
flickerstreak@216 226 general = {
flickerstreak@216 227 type = "group",
flickerstreak@216 228 name = L["General"],
flickerstreak@216 229 order = 1,
flickerstreak@216 230 args = {
flickerstreak@216 231 name = {
flickerstreak@216 232 type = "input",
flickerstreak@216 233 name = L["Rename Bar"],
flickerstreak@216 234 get = function() return bar:GetName() end,
flickerstreak@216 235 set = function(info, value) return ReAction:RenameBar(bar, value) end,
flickerstreak@216 236 order = 1,
flickerstreak@216 237 },
flickerstreak@216 238 delete = {
flickerstreak@216 239 type = "execute",
flickerstreak@216 240 name = L["Delete Bar"],
flickerstreak@216 241 desc = function() return bar:GetName() end,
flickerstreak@216 242 confirm = true,
flickerstreak@216 243 func = function() ReAction:EraseBar(bar) end,
flickerstreak@216 244 order = 2
flickerstreak@216 245 },
flickerstreak@216 246 anchor = {
flickerstreak@216 247 type = "group",
flickerstreak@216 248 name = L["Anchor"],
flickerstreak@216 249 inline = true,
flickerstreak@216 250 args = {
flickerstreak@216 251 frame = {
flickerstreak@216 252 type = "input",
flickerstreak@216 253 name = L["Frame"],
flickerstreak@216 254 desc = L["The frame that the bar is anchored to"],
flickerstreak@216 255 get = function() local _, f = bar:GetAnchor(); return f end,
flickerstreak@216 256 set = function(info, val) bar:SetAnchor(nil,val) end,
flickerstreak@216 257 validate = function(info, name)
flickerstreak@216 258 if name then
flickerstreak@216 259 local f = ReAction:GetBar(name)
flickerstreak@216 260 if f then
flickerstreak@216 261 return true
flickerstreak@216 262 else
flickerstreak@216 263 f = _G[name]
flickerstreak@216 264 if f and type(f) == "table" and f.IsObjectType and f:IsObjectType("Frame") then
flickerstreak@216 265 local _, explicit = f:IsProtected()
flickerstreak@216 266 return explicit
flickerstreak@216 267 end
flickerstreak@185 268 end
flickerstreak@185 269 end
flickerstreak@216 270 return false
flickerstreak@216 271 end,
flickerstreak@216 272 width = "double",
flickerstreak@216 273 order = 1
flickerstreak@216 274 },
flickerstreak@216 275 point = {
flickerstreak@216 276 type = "select",
flickerstreak@216 277 name = L["Point"],
flickerstreak@216 278 desc = L["Anchor point on the bar frame"],
flickerstreak@216 279 style = "dropdown",
flickerstreak@216 280 get = function() return bar:GetAnchor() end,
flickerstreak@216 281 set = function(info, val) bar:SetAnchor(val) end,
flickerstreak@216 282 values = pointTable,
flickerstreak@216 283 order = 2,
flickerstreak@216 284 },
flickerstreak@216 285 relativePoint = {
flickerstreak@216 286 type = "select",
flickerstreak@216 287 name = L["Relative Point"],
flickerstreak@216 288 desc = L["Anchor point on the target frame"],
flickerstreak@216 289 style = "dropdown",
flickerstreak@216 290 get = function() local p,f,r = bar:GetAnchor(); return r end,
flickerstreak@216 291 set = function(info, val) bar:SetAnchor(nil,nil,val) end,
flickerstreak@216 292 values = pointTable,
flickerstreak@216 293 order = 3,
flickerstreak@216 294 },
flickerstreak@216 295 x = {
flickerstreak@216 296 type = "input",
flickerstreak@216 297 pattern = "\-?%d+",
flickerstreak@216 298 name = L["X offset"],
flickerstreak@216 299 get = function() local p,f,r,x = bar:GetAnchor(); return ("%d"):format(x) end,
flickerstreak@216 300 set = function(info,val) bar:SetAnchor(nil,nil,nil,val) end,
flickerstreak@216 301 order = 4
flickerstreak@216 302 },
flickerstreak@216 303 y = {
flickerstreak@216 304 type = "input",
flickerstreak@216 305 pattern = "\-?%d+",
flickerstreak@216 306 name = L["Y offset"],
flickerstreak@216 307 get = function() local p,f,r,x,y = bar:GetAnchor(); return ("%d"):format(y) end,
flickerstreak@216 308 set = function(info,val) bar:SetAnchor(nil,nil,nil,nil,val) end,
flickerstreak@216 309 order = 5
flickerstreak@216 310 },
flickerstreak@185 311 },
flickerstreak@216 312 order = 3
flickerstreak@185 313 },
flickerstreak@216 314 alpha = {
flickerstreak@216 315 type = "range",
flickerstreak@216 316 name = L["Transparency"],
flickerstreak@216 317 get = function() return bar:GetAlpha() end,
flickerstreak@216 318 set = function(info, val) bar:SetAlpha(val) end,
flickerstreak@216 319 min = 0,
flickerstreak@216 320 max = 1,
flickerstreak@216 321 isPercent = true,
flickerstreak@216 322 step = 0.01,
flickerstreak@216 323 bigStep = 0.05,
flickerstreak@216 324 order = 4,
flickerstreak@216 325 },
flickerstreak@185 326 },
flickerstreak@185 327 },
Flick@237 328 buttonOpts = self:CreateButtonOptions(bar)
flickerstreak@185 329 },
flickerstreak@216 330 plugins = { }
flickerstreak@185 331 }
flickerstreak@216 332 end
flickerstreak@216 333
flickerstreak@216 334 if ReAction.barOptionGenerators then
flickerstreak@216 335 for module, func in pairs(ReAction.barOptionGenerators) do
flickerstreak@216 336 local success, r
flickerstreak@216 337 if type(func) == "string" then
flickerstreak@216 338 success, r = pcall(module[func], module, bar)
flickerstreak@216 339 else
flickerstreak@216 340 success, r = pcall(func, bar)
flickerstreak@216 341 end
flickerstreak@216 342 if success then
flickerstreak@216 343 if r then
flickerstreak@216 344 args[key].plugins[module:GetName()] = { [module:GetName()] = r }
flickerstreak@216 345 end
flickerstreak@216 346 else
flickerstreak@216 347 geterrorhandler()(r)
flickerstreak@216 348 end
flickerstreak@216 349 end
flickerstreak@216 350 end
flickerstreak@185 351 end
flickerstreak@185 352
Flick@237 353 function Editor:CreateButtonOptions(bar)
Flick@237 354 local buttonClass = bar:GetButtonClass()
Flick@237 355 local classID = buttonClass:GetButtonTypeID()
Flick@237 356 local handler = self.buttonHandlers[classID]
Flick@237 357
Flick@237 358 if handler then
Flick@237 359 local h = handler:New(bar)
Flick@237 360 return h:GetOptions()
Flick@237 361 end
Flick@237 362 end
Flick@237 363
flickerstreak@185 364 function Editor:RefreshBarOptions()
flickerstreak@219 365 for name, key in pairs(self.barOptMap) do
flickerstreak@216 366 if not ReAction:GetBar(name) then
flickerstreak@219 367 self.barOptMap[name] = nil
flickerstreak@219 368 self.options.args[key] = nil
flickerstreak@185 369 end
flickerstreak@185 370 end
flickerstreak@216 371 for name, bar in ReAction:IterateBars() do
flickerstreak@216 372 self:UpdateBarOptions(bar)
flickerstreak@216 373 end
flickerstreak@216 374 self:Refresh()
flickerstreak@185 375 end
flickerstreak@185 376
flickerstreak@185 377 function Editor:OnCreateBar(evt, bar)
flickerstreak@216 378 self:UpdateBarOptions(bar)
flickerstreak@216 379 self:Refresh()
flickerstreak@185 380 end
flickerstreak@185 381
flickerstreak@185 382 function Editor:OnDestroyBar(evt, bar, name)
flickerstreak@185 383 local key = self.barOptMap[name]
flickerstreak@185 384 if key then
flickerstreak@216 385 self.barOptMap[name] = nil
flickerstreak@185 386 self.options.args[key] = nil
flickerstreak@185 387 self:Refresh()
flickerstreak@185 388 end
flickerstreak@185 389 end
flickerstreak@185 390
flickerstreak@185 391 function Editor:OnRenameBar(evt, bar, oldname, newname)
flickerstreak@185 392 local key = self.barOptMap[oldname]
flickerstreak@185 393 if key then
flickerstreak@216 394 self.barOptMap[oldname], self.barOptMap[newname] = nil, key
flickerstreak@185 395 self.options.args[key].name = newname
flickerstreak@185 396 self:Refresh()
flickerstreak@185 397 end
flickerstreak@185 398 end
flickerstreak@185 399
flickerstreak@185 400 local _scratch = { }
flickerstreak@185 401 function Editor:GetBarTypes()
flickerstreak@185 402 wipe(_scratch)
flickerstreak@185 403 return ReAction:GetBarTypeOptions(_scratch)
flickerstreak@185 404 end
flickerstreak@185 405
flickerstreak@185 406 function Editor:CreateBar()
flickerstreak@185 407 if self.tmp.barName and self.tmp.barName ~= "" then
flickerstreak@185 408 local bar = ReAction:CreateBar(self.tmp.barName, self.tmp.barType or ReAction:GetDefaultBarType(), self.tmp.barRows, self.tmp.barCols, self.tmp.barSize, self.tmp.barSpacing)
flickerstreak@185 409 if bar then
flickerstreak@185 410 AceConfigDialog:SelectGroup(self.configID, self.barOptMap[self.tmp.barName])
flickerstreak@185 411 self.tmp.barName = nil
flickerstreak@185 412 end
flickerstreak@185 413 end
flickerstreak@185 414 end
flickerstreak@185 415
Flick@237 416 -------------------------------
Flick@237 417 ---- Action button handler ----
Flick@237 418 -------------------------------
Flick@237 419
Flick@237 420 do
Flick@237 421 local ActionHandler = {
Flick@237 422 buttonClass = ReAction.Button.Action,
Flick@237 423 options = {
Flick@237 424 hideEmpty = {
Flick@237 425 name = L["Hide Empty Buttons"],
Flick@237 426 order = 1,
Flick@237 427 type = "toggle",
Flick@237 428 width = "double",
Flick@237 429 get = "GetHideEmpty",
Flick@237 430 set = "SetHideEmpty",
Flick@237 431 },
Flick@237 432 lockButtons = {
Flick@237 433 name = L["Lock Buttons"],
Flick@237 434 desc = L["Prevents picking up/dragging actions (use SHIFT to override this behavior)"],
Flick@237 435 order = 2,
Flick@237 436 type = "toggle",
Flick@237 437 get = "GetLockButtons",
Flick@237 438 set = "SetLockButtons",
Flick@237 439 },
Flick@237 440 lockOnlyCombat = {
Flick@237 441 name = L["Only in Combat"],
Flick@237 442 desc = L["Only lock the buttons when in combat"],
Flick@237 443 order = 3,
Flick@237 444 type = "toggle",
Flick@237 445 disabled = "LockButtonsCombatDisabled",
Flick@237 446 get = "GetLockButtonsCombat",
Flick@237 447 set = "SetLockButtonsCombat",
Flick@237 448 },
Flick@237 449 pages = {
Flick@237 450 name = L["# Pages"],
Flick@237 451 desc = L["Use the Dynamic State tab to specify page transitions"],
Flick@237 452 order = 4,
Flick@237 453 type = "range",
Flick@237 454 min = 1,
Flick@237 455 max = 10,
Flick@237 456 step = 1,
Flick@237 457 get = "GetNumPages",
Flick@237 458 set = "SetNumPages",
Flick@237 459 },
Flick@237 460 mindcontrol = {
Flick@237 461 name = L["Mind Control Support"],
Flick@237 462 desc = L["When possessing a target (e.g. via Mind Control), map the first 12 buttons of this bar to the possessed target's actions."],
Flick@237 463 order = 5,
Flick@237 464 type = "toggle",
Flick@237 465 width = "double",
Flick@237 466 set = "SetMindControl",
Flick@237 467 get = "GetMindControl",
Flick@237 468 },
Flick@237 469 vehicle = {
Flick@237 470 name = L["Vehicle Support"],
Flick@237 471 desc = L["When on a vehicle, map the first 6 buttons of this bar to the vehicle actions. The vehicle-exit button is mapped to the 7th button. Pitch controls are not supported."],
Flick@237 472 order = 6,
Flick@237 473 type = "toggle",
Flick@237 474 width = "double",
Flick@237 475 get = "GetVehicle",
Flick@237 476 set = "SetVehicle",
Flick@237 477 },
Flick@237 478 actions = {
Flick@237 479 name = L["Edit Action IDs"],
Flick@237 480 order = 7,
Flick@237 481 type = "group",
Flick@237 482 inline = true,
Flick@237 483 args = {
Flick@237 484 method = {
Flick@237 485 name = L["Assign"],
Flick@237 486 order = 1,
Flick@237 487 type = "select",
Flick@237 488 width = "double",
Flick@237 489 values = { [0] = L["Choose Method..."],
Flick@237 490 [1] = L["Individually"],
Flick@237 491 [2] = L["All at Once"], },
Flick@237 492 get = "GetActionEditMethod",
Flick@237 493 set = "SetActionEditMethod",
Flick@237 494 },
Flick@237 495 rowSelect = {
Flick@237 496 name = L["Row"],
Flick@237 497 desc = L["Rows are numbered top to bottom"],
Flick@237 498 order = 2,
Flick@237 499 type = "select",
Flick@237 500 width = "half",
Flick@237 501 hidden = "IsButtonSelectHidden",
Flick@237 502 values = "GetRowList",
Flick@237 503 get = "GetSelectedRow",
Flick@237 504 set = "SetSelectedRow",
Flick@237 505 },
Flick@237 506 colSelect = {
Flick@237 507 name = L["Col"],
Flick@237 508 desc = L["Columns are numbered left to right"],
Flick@237 509 order = 3,
Flick@237 510 type = "select",
Flick@237 511 width = "half",
Flick@237 512 hidden = "IsButtonSelectHidden",
Flick@237 513 values = "GetColumnList",
Flick@237 514 get = "GetSelectedColumn",
Flick@237 515 set = "SetSelectedColumn",
Flick@237 516 },
Flick@237 517 pageSelect = {
Flick@237 518 name = L["Page"],
Flick@237 519 order = 4,
Flick@237 520 type = "select",
Flick@237 521 width = "half",
Flick@237 522 hidden = "IsPageSelectHidden",
Flick@237 523 values = "GetPageList",
Flick@237 524 get = "GetSelectedPage",
Flick@237 525 set = "SetSelectedPage",
Flick@237 526 },
Flick@237 527 single = {
Flick@237 528 name = L["Action ID"],
Flick@237 529 usage = L["Specify ID 1-120"],
Flick@237 530 order = 5,
Flick@237 531 type = "input",
Flick@237 532 width = "half",
Flick@237 533 hidden = "IsButtonSelectHidden",
Flick@237 534 get = "GetActionID",
Flick@237 535 set = "SetActionID",
Flick@237 536 validate = "ValidateActionID",
Flick@237 537 },
Flick@237 538 multi = {
Flick@237 539 name = L["ID List"],
Flick@237 540 usage = L["Specify a comma-separated list of IDs for each button in the bar (in order). Separate multiple pages with semicolons (;)"],
Flick@237 541 order = 6,
Flick@237 542 type = "input",
Flick@237 543 multiline = true,
Flick@237 544 width = "double",
Flick@237 545 hidden = "IsMultiIDHidden",
Flick@237 546 get = "GetMultiID",
Flick@237 547 set = "SetMultiID",
Flick@237 548 validate = "ValidateMultiID",
Flick@237 549 },
Flick@237 550 },
Flick@237 551 },
Flick@237 552 }
Flick@237 553 }
Flick@237 554
Flick@237 555 Editor.buttonHandlers[ActionHandler.buttonClass:GetButtonTypeID()] = ActionHandler
Flick@237 556
Flick@237 557 local meta = { __index = ActionHandler }
Flick@237 558
Flick@237 559 function ActionHandler:New( bar )
Flick@237 560 return setmetatable(
Flick@237 561 {
Flick@237 562 bar = bar,
Flick@237 563 config = bar:GetConfig(),
Flick@237 564 },
Flick@237 565 meta)
Flick@237 566 end
Flick@237 567
Flick@237 568 function ActionHandler:Refresh()
Flick@237 569 self.buttonClass:SetupBar(self.bar)
Flick@237 570 end
Flick@237 571
Flick@237 572 function ActionHandler:UpdateButtonLock()
Flick@237 573 self.buttonClass:SetButtonLock(self.bar, self.config.lockButtons, self.config.lockButtonsCombat)
Flick@237 574 end
Flick@237 575
Flick@237 576 function ActionHandler:GetLastButton()
Flick@237 577 return self.bar:GetButton(self.bar:GetNumButtons())
Flick@237 578 end
Flick@237 579
Flick@237 580 -- options handlers
Flick@237 581 function ActionHandler:GetOptions()
Flick@237 582 return {
Flick@237 583 type = "group",
Flick@237 584 name = L["Action Buttons"],
Flick@237 585 handler = self,
Flick@237 586 order = 2,
Flick@237 587 args = self.options
Flick@237 588 }
Flick@237 589 end
Flick@237 590
Flick@237 591 function ActionHandler:SetHideEmpty(info, value)
Flick@237 592 if value ~= self.config.hideEmpty then
Flick@237 593 self.config.hideEmpty = value
Flick@237 594 for _, b in self.bar:IterateButtons() do
Flick@237 595 b:ShowGrid(not value)
Flick@237 596 end
Flick@237 597 end
Flick@237 598 end
Flick@237 599
Flick@237 600 function ActionHandler:GetHideEmpty()
Flick@237 601 return self.config.hideEmpty
Flick@237 602 end
Flick@237 603
Flick@237 604 function ActionHandler:GetLockButtons()
Flick@237 605 return self.config.lockButtons
Flick@237 606 end
Flick@237 607
Flick@237 608 function ActionHandler:SetLockButtons(info, value)
Flick@237 609 self.config.lockButtons = value
Flick@237 610 self:UpdateButtonLock()
Flick@237 611 end
Flick@237 612
Flick@237 613 function ActionHandler:GetLockButtonsCombat()
Flick@237 614 return self.config.lockButtonsCombat
Flick@237 615 end
Flick@237 616
Flick@237 617 function ActionHandler:SetLockButtonsCombat(info, value)
Flick@237 618 self.config.lockButtonsCombat = value
Flick@237 619 self:UpdateButtonLock()
Flick@237 620 end
Flick@237 621
Flick@237 622 function ActionHandler:LockButtonsCombatDisabled()
Flick@237 623 return not self.config.lockButtons
Flick@237 624 end
Flick@237 625
Flick@237 626 function ActionHandler:GetNumPages()
Flick@237 627 return self.config.nPages
Flick@237 628 end
Flick@237 629
Flick@237 630 function ActionHandler:SetNumPages(info, value)
Flick@237 631 self.config.nPages = value
Flick@237 632 self:Refresh()
Flick@237 633 end
Flick@237 634
Flick@237 635 function ActionHandler:GetMindControl()
Flick@237 636 return self.config.mindcontrol
Flick@237 637 end
Flick@237 638
Flick@237 639 function ActionHandler:SetMindControl(info, value)
Flick@237 640 self.config.mindcontrol = value
Flick@237 641 self:Refresh()
Flick@237 642 end
Flick@237 643
Flick@237 644 function ActionHandler:GetVehicle()
Flick@237 645 return self.config.vehicle
Flick@237 646 end
Flick@237 647
Flick@237 648 function ActionHandler:SetVehicle(info, value)
Flick@237 649 self.config.vehicle = value
Flick@237 650 self:Refresh()
Flick@237 651 end
Flick@237 652
Flick@237 653 function ActionHandler:GetActionEditMethod()
Flick@237 654 return self.editMethod or 0
Flick@237 655 end
Flick@237 656
Flick@237 657 function ActionHandler:SetActionEditMethod(info, value)
Flick@237 658 self.editMethod = value
Flick@237 659 end
Flick@237 660
Flick@237 661 function ActionHandler:IsButtonSelectHidden()
Flick@237 662 return self.editMethod ~= 1
Flick@237 663 end
Flick@237 664
Flick@237 665 function ActionHandler:GetRowList()
Flick@237 666 local r,c = self.bar:GetButtonGrid()
Flick@237 667 if self.rowList == nil or #self.rowList ~= r then
Flick@237 668 local list = { }
Flick@237 669 for i = 1, r do
Flick@237 670 table.insert(list,i)
Flick@237 671 end
Flick@237 672 self.rowList = list
Flick@237 673 end
Flick@237 674 return self.rowList
Flick@237 675 end
Flick@237 676
Flick@237 677 function ActionHandler:GetSelectedRow()
Flick@237 678 local r, c = self.bar:GetButtonGrid()
Flick@237 679 local row = self.selectedRow or 1
Flick@237 680 if row > r then
Flick@237 681 row = 1
Flick@237 682 end
Flick@237 683 self.selectedRow = row
Flick@237 684 return row
Flick@237 685 end
Flick@237 686
Flick@237 687 function ActionHandler:SetSelectedRow(info, value)
Flick@237 688 self.selectedRow = value
Flick@237 689 end
Flick@237 690
Flick@237 691 function ActionHandler:GetColumnList()
Flick@237 692 local r,c = self.bar:GetButtonGrid()
Flick@237 693 if self.columnList == nil or #self.columnList ~= c then
Flick@237 694 local list = { }
Flick@237 695 for i = 1, c do
Flick@237 696 table.insert(list,i)
Flick@237 697 end
Flick@237 698 self.columnList = list
Flick@237 699 end
Flick@237 700 return self.columnList
Flick@237 701 end
Flick@237 702
Flick@237 703 function ActionHandler:GetSelectedColumn()
Flick@237 704 local r, c = self.bar:GetButtonGrid()
Flick@237 705 local col = self.selectedColumn or 1
Flick@237 706 if col > c then
Flick@237 707 col = 1
Flick@237 708 end
Flick@237 709 self.selectedColumn = col
Flick@237 710 return col
Flick@237 711 end
Flick@237 712
Flick@237 713 function ActionHandler:SetSelectedColumn(info, value)
Flick@237 714 self.selectedColumn = value
Flick@237 715 end
Flick@237 716
Flick@237 717 function ActionHandler:IsPageSelectHidden()
Flick@237 718 return self.editMethod ~= 1 or (self.config.nPages or 1) < 2
Flick@237 719 end
Flick@237 720
Flick@237 721 function ActionHandler:GetPageList()
Flick@237 722 local n = self.config.nPages or 1
Flick@237 723 if self.pageList == nil or #self.pageList ~= n then
Flick@237 724 local p = { }
Flick@237 725 for i = 1, n do
Flick@237 726 table.insert(p,i)
Flick@237 727 end
Flick@237 728 self.pageList = p
Flick@237 729 end
Flick@237 730 return self.pageList
Flick@237 731 end
Flick@237 732
Flick@237 733 function ActionHandler:GetSelectedPage()
Flick@237 734 local p = self.selectedPage or 1
Flick@237 735 if p > (self.config.nPages or 1) then
Flick@237 736 p = 1
Flick@237 737 end
Flick@237 738 self.selectedPage = p
Flick@237 739 return p
Flick@237 740 end
Flick@237 741
Flick@237 742 function ActionHandler:SetSelectedPage(info, value)
Flick@237 743 self.selectedPage = value
Flick@237 744 end
Flick@237 745
Flick@237 746 function ActionHandler:GetActionID()
Flick@237 747 local row = self.selectedRow or 1
Flick@237 748 local col = self.selectedColumn or 1
Flick@237 749 local r, c = self.bar:GetButtonGrid()
Flick@237 750 local n = (row-1) * c + col
Flick@237 751 local btn = self.bar:GetButton(n)
Flick@237 752 if btn then
Flick@237 753 return tostring(btn:GetActionID(self.selectedPage or 1))
Flick@237 754 end
Flick@237 755 end
Flick@237 756
Flick@237 757 function ActionHandler:SetActionID(info, value)
Flick@237 758 local row = self.selectedRow or 1
Flick@237 759 local col = self.selectedColumn or 1
Flick@237 760 local r, c = self.bar:GetButtonGrid()
Flick@237 761 local n = (row-1) * c + col
Flick@237 762 local btn = self.bar:GetButton(n)
Flick@237 763 if btn then
Flick@237 764 btn:SetActionID(tonumber(value), self.selectedPage or 1)
Flick@237 765 end
Flick@237 766 end
Flick@237 767
Flick@237 768 function ActionHandler:ValidateActionID(info, value)
Flick@237 769 value = tonumber(value)
Flick@237 770 if value == nil or value < 1 or value > 120 then
Flick@237 771 return L["Specify ID 1-120"]
Flick@237 772 end
Flick@237 773 return true
Flick@237 774 end
Flick@237 775
Flick@237 776 function ActionHandler:IsMultiIDHidden()
Flick@237 777 return self.editMethod ~= 2
Flick@237 778 end
Flick@237 779
Flick@237 780 function ActionHandler:GetMultiID()
Flick@237 781 local p = { }
Flick@237 782 for i = 1, self.config.nPages or 1 do
Flick@237 783 local b = { }
Flick@237 784 for _, btn in self.bar:IterateButtons() do
Flick@237 785 table.insert(b, btn:GetActionID(i))
Flick@237 786 end
Flick@237 787 table.insert(p, table.concat(b,","))
Flick@237 788 end
Flick@237 789 return table.concat(p,";\n")
Flick@237 790 end
Flick@237 791
Flick@237 792
Flick@237 793 local function ParseMultiID(nBtns, nPages, s)
Flick@237 794 if s:match("[^%d%s,;]") then
Flick@237 795 return nil
Flick@237 796 end
Flick@237 797 local p = { }
Flick@237 798 for list in s:gmatch("[^;]+") do
Flick@237 799 local pattern = ("^%s?$"):format(("%s*(%d+)%s*,"):rep(nBtns))
Flick@237 800 local ids = { list:match(pattern) }
Flick@237 801 if #ids ~= nBtns then
Flick@237 802 return nil
Flick@237 803 end
Flick@237 804 table.insert(p,ids)
Flick@237 805 end
Flick@237 806 if #p ~= nPages then
Flick@237 807 return nil
Flick@237 808 end
Flick@237 809 return p
Flick@237 810 end
Flick@237 811
Flick@237 812 function ActionHandler:SetMultiID(info, value)
Flick@237 813 local p = ParseMultiID(self.bar:GetNumButtons(), self.config.nPages or 1, value)
Flick@237 814 for page, b in ipairs(p) do
Flick@237 815 for button, id in ipairs(b) do
Flick@237 816 self.bar:GetButton(button):SetActionID(id, page)
Flick@237 817 end
Flick@237 818 end
Flick@237 819 end
Flick@237 820
Flick@237 821 function ActionHandler:ValidateMultiID(info, value)
Flick@237 822 local bad = L["Invalid action ID list string"]
Flick@237 823 if value == nil or ParseMultiID(self.bar:GetNumButtons(), self.config.nPages or 1, value) == nil then
Flick@237 824 return bad
Flick@237 825 end
Flick@237 826 return true
Flick@237 827 end
Flick@237 828 end
Flick@237 829
Flick@237 830
Flick@237 831 ----------------------------------
Flick@237 832 ---- PetAction button handler ----
Flick@237 833 ----------------------------------
Flick@237 834
Flick@237 835 do
Flick@237 836 local PetHandler = {
Flick@237 837 buttonClass = ReAction.Button.PetAction,
Flick@237 838 }
Flick@237 839
Flick@237 840 Editor.buttonHandlers[PetHandler.buttonClass:GetButtonTypeID()] = PetHandler
Flick@237 841
Flick@237 842 local meta = { __index = PetHandler }
Flick@237 843
Flick@237 844 function PetHandler:New(bar)
Flick@237 845 return setmetatable(
Flick@237 846 {
Flick@237 847 bar = bar,
Flick@237 848 config = bar.config
Flick@237 849 }, meta)
Flick@237 850 end
Flick@237 851
Flick@237 852 function PetHandler:GetLockButtons()
Flick@237 853 return self.config.lockButtons
Flick@237 854 end
Flick@237 855
Flick@237 856 function PetHandler:SetLockButtons(info, value)
Flick@237 857 self.config.lockButtons = value
Flick@237 858 self.buttonClass:UpdateButtonLock(self.bar)
Flick@237 859 end
Flick@237 860
Flick@237 861 function PetHandler:GetLockButtonsCombat()
Flick@237 862 return self.config.lockButtonsCombat
Flick@237 863 end
Flick@237 864
Flick@237 865 function PetHandler:SetLockButtonsCombat(info, value)
Flick@237 866 self.config.lockButtonsCombat = value
Flick@237 867 self.buttonClass:UpdateButtonLock(self.bar)
Flick@237 868 end
Flick@237 869
Flick@237 870 function PetHandler:LockButtonsCombatDisabled()
Flick@237 871 return not self.config.lockButtons
Flick@237 872 end
Flick@237 873
Flick@237 874 function PetHandler:GetOptions()
Flick@237 875 return {
Flick@237 876 type = "group",
Flick@237 877 name = L["Pet Buttons"],
Flick@237 878 handler = self,
Flick@237 879 order = 2,
Flick@237 880 args = {
Flick@237 881 lockButtons = {
Flick@237 882 name = L["Lock Buttons"],
Flick@237 883 desc = L["Prevents picking up/dragging actions (use SHIFT to override this behavior)"],
Flick@237 884 order = 2,
Flick@237 885 type = "toggle",
Flick@237 886 get = "GetLockButtons",
Flick@237 887 set = "SetLockButtons",
Flick@237 888 },
Flick@237 889 lockOnlyCombat = {
Flick@237 890 name = L["Only in Combat"],
Flick@237 891 desc = L["Only lock the buttons when in combat"],
Flick@237 892 order = 3,
Flick@237 893 type = "toggle",
Flick@237 894 disabled = "LockButtonsCombatDisabled",
Flick@237 895 get = "GetLockButtonsCombat",
Flick@237 896 set = "SetLockButtonsCombat",
Flick@237 897 },
Flick@237 898 }
Flick@237 899 }
Flick@237 900 end
Flick@237 901 end
Flick@237 902
Flick@237 903
Flick@237 904 -------------------------------------
Flick@237 905 ---- Vehicle Exit button handler ----
Flick@237 906 -------------------------------------
Flick@237 907
Flick@237 908 do
Flick@237 909 local VExitHandler = {
Flick@237 910 buttonClass = ReAction.Button.VehicleExit,
Flick@237 911 }
Flick@237 912
Flick@237 913 Editor.buttonHandlers[VExitHandler.buttonClass:GetButtonTypeID()] = VExitHandler
Flick@237 914
Flick@237 915 local meta = { __index = VExitHandler }
Flick@237 916
Flick@237 917 function VExitHandler:New(bar)
Flick@237 918 return setmetatable(
Flick@237 919 {
Flick@237 920 bar = bar,
Flick@237 921 }, meta)
Flick@237 922 end
Flick@237 923
Flick@237 924 function VExitHandler:GetConfig()
Flick@237 925 return self.bar:GetConfig()
Flick@237 926 end
Flick@237 927
Flick@237 928 function VExitHandler:GetPassengerOnly()
Flick@237 929 return not self:GetConfig().withControls
Flick@237 930 end
Flick@237 931
Flick@237 932 function VExitHandler:SetPassengerOnly(info, value)
Flick@237 933 self:GetConfig().withControls = not value
Flick@237 934 self.buttonClass:UpdateRegistration(self.bar)
Flick@237 935 end
Flick@237 936
Flick@237 937
Flick@237 938 function VExitHandler:GetOptions()
Flick@237 939 return {
Flick@237 940 type = "group",
Flick@237 941 name = L["Exit Vehicle"],
Flick@237 942 handler = self,
Flick@237 943 args = {
Flick@237 944 passengerOnly = {
Flick@237 945 name = L["Show only when passenger"],
Flick@237 946 desc = L["Only show the button when riding as a passenger in a vehicle (no vehicle controls)"],
Flick@237 947 order = 2,
Flick@237 948 width = "double",
Flick@237 949 type = "toggle",
Flick@237 950 get = "GetPassengerOnly",
Flick@237 951 set = "SetPassengerOnly",
Flick@237 952 },
Flick@237 953 }
Flick@237 954 }
Flick@237 955 end
Flick@237 956 end
Flick@237 957
flickerstreak@185 958
flickerstreak@185 959
flickerstreak@185 960 ---- Export to ReAction ----
flickerstreak@185 961 function ReAction:ShowEditor(bar, ...)
flickerstreak@185 962 if InCombatLockdown() then
flickerstreak@185 963 self:UserError(L["ReAction config mode disabled during combat."])
flickerstreak@185 964 else
flickerstreak@185 965 self.editor = self.editor or Editor:New()
flickerstreak@185 966 self.editor:Open(bar, ...)
flickerstreak@185 967 self:SetConfigMode(true)
flickerstreak@185 968 end
flickerstreak@185 969 end
flickerstreak@185 970
flickerstreak@185 971 function ReAction:CloseEditor()
flickerstreak@185 972 if self.editor then
flickerstreak@185 973 self.editor:Close()
flickerstreak@185 974 end
flickerstreak@185 975 end
flickerstreak@185 976
flickerstreak@185 977 function ReAction:RefreshEditor()
flickerstreak@185 978 if self.editor then
flickerstreak@185 979 self.editor:RefreshBarOptions()
flickerstreak@185 980 end
flickerstreak@185 981 end
flickerstreak@185 982
flickerstreak@185 983 function ReAction:RegisterBarOptionGenerator( module, func )
flickerstreak@185 984 if not module or type(module) ~= "table" then -- doesn't need to be a proper module, strictly
flickerstreak@185 985 error("ReAction:RegisterBarOptionGenerator() : Invalid module")
flickerstreak@185 986 end
flickerstreak@185 987 if type(func) == "string" then
flickerstreak@185 988 if not module[func] then
flickerstreak@185 989 error(("ReAction:RegisterBarOptionGenerator() : Invalid method '%s'"):format(func))
flickerstreak@185 990 end
flickerstreak@185 991 elseif func and type(func) ~= "function" then
flickerstreak@185 992 error("ReAction:RegisterBarOptionGenerator() : Invalid function")
flickerstreak@185 993 end
flickerstreak@185 994 self.barOptionGenerators = self.barOptionGenerators or { }
flickerstreak@185 995 self.barOptionGenerators[module] = func
flickerstreak@185 996
flickerstreak@185 997 if self.editor then
flickerstreak@185 998 self.editor:RefreshBarOptions()
flickerstreak@185 999 end
flickerstreak@185 1000 end
flickerstreak@185 1001