annotate Editor.lua @ 256:5ab04f393b0b

Fix reference to recently changed localized string
author Flick
date Mon, 04 Apr 2011 13:04:11 -0700
parents d7a7ef367faf
children c918ff9ac787
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
Flick@244 6 local format = string.format
Flick@244 7 local InCombatLockdown = InCombatLockdown
Flick@244 8 local tfetch = addonTable.tfetch
Flick@244 9 local tbuild = addonTable.tbuild
flickerstreak@185 10
flickerstreak@109 11 local AceConfigReg = LibStub("AceConfigRegistry-3.0")
flickerstreak@109 12 local AceConfigDialog = LibStub("AceConfigDialog-3.0")
flickerstreak@109 13
flickerstreak@109 14
flickerstreak@185 15 local pointTable = {
Flick@244 16 NONE = " ",
flickerstreak@185 17 CENTER = L["Center"],
flickerstreak@185 18 LEFT = L["Left"],
flickerstreak@185 19 RIGHT = L["Right"],
flickerstreak@185 20 TOP = L["Top"],
flickerstreak@185 21 BOTTOM = L["Bottom"],
flickerstreak@185 22 TOPLEFT = L["Top Left"],
flickerstreak@185 23 TOPRIGHT = L["Top Right"],
flickerstreak@185 24 BOTTOMLEFT = L["Bottom Left"],
flickerstreak@185 25 BOTTOMRIGHT = L["Bottom Right"],
flickerstreak@185 26 }
flickerstreak@109 27
Flick@237 28 local Editor = {
Flick@237 29 buttonHandlers = { }
Flick@237 30 }
flickerstreak@109 31
flickerstreak@185 32 function Editor:New()
flickerstreak@185 33 -- create new self
flickerstreak@185 34 self = setmetatable( { }, { __index = self } )
flickerstreak@109 35
flickerstreak@185 36 self.barOptMap = setmetatable({},{__mode="v"})
flickerstreak@185 37 self.tmp = { }
flickerstreak@185 38 self.configID = "ReAction-Editor"
flickerstreak@109 39
flickerstreak@185 40 self.gui = LibStub("AceGUI-3.0"):Create("Frame")
flickerstreak@185 41
flickerstreak@185 42 local frame = self.gui.frame
flickerstreak@109 43 frame:SetClampedToScreen(true)
flickerstreak@109 44 frame:Hide()
flickerstreak@185 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"],
Flick@250 59 func = function()
Flick@250 60 -- AceConfigDialog calls :Open() after every selection, making it
Flick@250 61 -- generally not possible to cleanly close from a menu item.
Flick@250 62 -- If you don't use a custom frame, you can use ACD:Close(), but since
Flick@250 63 -- we're using a custom frame, we have to do the work of closing later in an
Flick@250 64 -- OnUpdate script.
Flick@250 65 ReAction:ShowOptions();
Flick@250 66 frame:SetScript("OnUpdate",
Flick@250 67 function()
Flick@250 68 self:Close()
Flick@250 69 frame:SetScript("OnUpdate",nil)
Flick@250 70 end)
Flick@250 71 end,
flickerstreak@185 72 order = 1
flickerstreak@109 73 },
flickerstreak@185 74 desc = {
flickerstreak@185 75 type = "description",
flickerstreak@185 76 name = L["Use the mouse to arrange and resize the bars on screen. Tooltips on bars indicate additional functionality."],
flickerstreak@195 77 order = 2,
flickerstreak@195 78 },
flickerstreak@195 79 hdr = {
flickerstreak@195 80 type = "header",
flickerstreak@195 81 name = L["Select Bar"],
flickerstreak@194 82 order = 3,
flickerstreak@185 83 },
flickerstreak@185 84 _new = {
flickerstreak@109 85 type = "group",
flickerstreak@109 86 name = L["New Bar..."],
flickerstreak@194 87 order = 4,
flickerstreak@109 88 args = {
flickerstreak@109 89 desc = {
flickerstreak@109 90 type = "description",
flickerstreak@109 91 name = L["Choose a name, type, and initial grid for your new action bar:"],
flickerstreak@109 92 order = 1,
flickerstreak@109 93 },
flickerstreak@109 94 name = {
flickerstreak@109 95 type = "input",
flickerstreak@109 96 name = L["Bar Name"],
flickerstreak@109 97 desc = L["Enter a name for your new action bar"],
flickerstreak@185 98 get = function() return self.tmp.barName or "" end,
flickerstreak@185 99 set = function(info, val) self.tmp.barName = val end,
flickerstreak@109 100 order = 2,
flickerstreak@109 101 },
flickerstreak@109 102 type = {
flickerstreak@109 103 type = "select",
flickerstreak@109 104 name = L["Button Type"],
flickerstreak@185 105 get = function() return self.tmp.barType or ReAction:GetDefaultBarType() or "" end,
flickerstreak@109 106 set = function(info, val)
flickerstreak@218 107 local c = ReAction:GetDefaultBarConfig(val)
flickerstreak@185 108 self.tmp.barType = val
flickerstreak@218 109 self.tmp.barSize = c.btnWidth or self.tmp.barSize
flickerstreak@218 110 self.tmp.barRows = c.btnRows or self.tmp.barRows
flickerstreak@218 111 self.tmp.barCols = c.btnColumns or self.tmp.barCols
flickerstreak@218 112 self.tmp.barSpacing = c.spacing or self.tmp.barSpacing
flickerstreak@109 113 end,
flickerstreak@109 114 values = "GetBarTypes",
flickerstreak@109 115 order = 3,
flickerstreak@109 116 },
flickerstreak@185 117 go = {
flickerstreak@185 118 type = "execute",
flickerstreak@185 119 name = L["Create Bar"],
flickerstreak@185 120 func = "CreateBar",
flickerstreak@185 121 order = 4,
flickerstreak@185 122 },
flickerstreak@109 123 grid = {
flickerstreak@109 124 type = "group",
flickerstreak@109 125 name = L["Button Grid"],
flickerstreak@109 126 inline = true,
flickerstreak@185 127 order = 5,
flickerstreak@109 128 args = {
flickerstreak@109 129 rows = {
flickerstreak@109 130 type = "range",
flickerstreak@109 131 name = L["Rows"],
flickerstreak@185 132 get = function() return self.tmp.barRows or 1 end,
flickerstreak@185 133 set = function(info, val) self.tmp.barRows = val end,
flickerstreak@185 134 width = "full",
flickerstreak@109 135 min = 1,
flickerstreak@109 136 max = 32,
flickerstreak@109 137 step = 1,
flickerstreak@109 138 order = 2,
flickerstreak@109 139 },
flickerstreak@109 140 cols = {
flickerstreak@109 141 type = "range",
flickerstreak@109 142 name = L["Columns"],
flickerstreak@185 143 get = function() return self.tmp.barCols or 12 end,
flickerstreak@185 144 set = function(info, val) self.tmp.barCols = val end,
flickerstreak@185 145 width = "full",
flickerstreak@109 146 min = 1,
flickerstreak@109 147 max = 32,
flickerstreak@109 148 step = 1,
flickerstreak@109 149 order = 3,
flickerstreak@109 150 },
flickerstreak@109 151 sz = {
flickerstreak@109 152 type = "range",
flickerstreak@109 153 name = L["Size"],
flickerstreak@185 154 get = function() return self.tmp.barSize or 36 end,
flickerstreak@185 155 set = function(info, val) self.tmp.barSize = val end,
flickerstreak@185 156 width = "full",
flickerstreak@109 157 min = 10,
flickerstreak@109 158 max = 72,
flickerstreak@109 159 step = 1,
flickerstreak@109 160 order = 4,
flickerstreak@109 161 },
flickerstreak@109 162 spacing = {
flickerstreak@109 163 type = "range",
flickerstreak@109 164 name = L["Spacing"],
flickerstreak@185 165 get = function() return self.tmp.barSpacing or 3 end,
flickerstreak@185 166 set = function(info, val) self.tmp.barSpacing = val end,
flickerstreak@185 167 width = "full",
flickerstreak@109 168 min = 0,
flickerstreak@109 169 max = 24,
flickerstreak@109 170 step = 1,
flickerstreak@109 171 order = 5,
flickerstreak@109 172 }
flickerstreak@195 173 }
flickerstreak@195 174 }
flickerstreak@109 175 }
flickerstreak@109 176 }
flickerstreak@195 177 }
flickerstreak@109 178 }
flickerstreak@109 179
flickerstreak@185 180 self.gui:SetCallback("OnClose",
flickerstreak@185 181 function()
flickerstreak@185 182 ReAction:SetConfigMode(false)
flickerstreak@185 183 end )
flickerstreak@185 184
flickerstreak@185 185 AceConfigReg:RegisterOptionsTable(self.configID, self.options)
flickerstreak@185 186 AceConfigDialog:SetDefaultSize(self.configID, 700, 540)
flickerstreak@185 187
flickerstreak@185 188 ReAction.RegisterCallback(self,"OnCreateBar")
flickerstreak@185 189 ReAction.RegisterCallback(self,"OnDestroyBar")
flickerstreak@185 190 ReAction.RegisterCallback(self,"OnRenameBar")
flickerstreak@185 191
flickerstreak@216 192 self:RefreshBarOptions()
flickerstreak@109 193
flickerstreak@185 194 return self
flickerstreak@109 195 end
flickerstreak@109 196
flickerstreak@109 197
flickerstreak@185 198 function Editor:Open(bar, ...)
flickerstreak@185 199 if bar then
flickerstreak@185 200 AceConfigDialog:SelectGroup(self.configID, self.barOptMap[bar:GetName()], ...)
flickerstreak@185 201 end
flickerstreak@185 202 AceConfigDialog:Open(self.configID,self.gui)
flickerstreak@185 203 self.gui:SetTitle(self.title)
flickerstreak@185 204 end
flickerstreak@185 205
flickerstreak@185 206 function Editor:Close()
flickerstreak@185 207 if self.gui then
flickerstreak@185 208 self.gui:ReleaseChildren()
flickerstreak@185 209 self.gui:Hide()
flickerstreak@109 210 end
flickerstreak@109 211 end
flickerstreak@109 212
flickerstreak@185 213 function Editor:Refresh()
flickerstreak@185 214 AceConfigReg:NotifyChange(self.configID)
flickerstreak@185 215 end
flickerstreak@185 216
flickerstreak@216 217 function Editor:UpdateBarOptions(bar)
flickerstreak@185 218 local name = bar:GetName()
flickerstreak@216 219 local key = self.barOptMap[name]
flickerstreak@185 220 local args = self.options.args
flickerstreak@216 221
flickerstreak@216 222 if not key then
flickerstreak@216 223 -- AceConfig doesn't allow spaces, etc, in arg key names, and they must be
flickerstreak@216 224 -- unique strings. So generate a unique key (it can be whatever) for the bar
flickerstreak@216 225 local i = 1
flickerstreak@216 226 repeat
flickerstreak@216 227 key = ("bar%s"):format(i)
flickerstreak@216 228 i = i+1
flickerstreak@216 229 until args[key] == nil
flickerstreak@216 230 self.barOptMap[name] = key
flickerstreak@216 231
flickerstreak@216 232 args[key] = {
flickerstreak@216 233 type = "group",
flickerstreak@216 234 name = name,
flickerstreak@216 235 childGroups = "tab",
flickerstreak@216 236 order = i+100,
flickerstreak@216 237 args = {
flickerstreak@216 238 general = {
flickerstreak@216 239 type = "group",
flickerstreak@216 240 name = L["General"],
flickerstreak@216 241 order = 1,
flickerstreak@216 242 args = {
flickerstreak@216 243 name = {
flickerstreak@216 244 type = "input",
flickerstreak@216 245 name = L["Rename Bar"],
flickerstreak@216 246 get = function() return bar:GetName() end,
flickerstreak@216 247 set = function(info, value) return ReAction:RenameBar(bar, value) end,
flickerstreak@216 248 order = 1,
flickerstreak@216 249 },
flickerstreak@216 250 delete = {
flickerstreak@216 251 type = "execute",
flickerstreak@216 252 name = L["Delete Bar"],
flickerstreak@216 253 desc = function() return bar:GetName() end,
flickerstreak@216 254 confirm = true,
flickerstreak@216 255 func = function() ReAction:EraseBar(bar) end,
flickerstreak@216 256 order = 2
flickerstreak@216 257 },
flickerstreak@216 258 anchor = {
flickerstreak@216 259 type = "group",
flickerstreak@216 260 name = L["Anchor"],
flickerstreak@216 261 inline = true,
flickerstreak@216 262 args = {
flickerstreak@216 263 frame = {
flickerstreak@216 264 type = "input",
flickerstreak@216 265 name = L["Frame"],
flickerstreak@216 266 desc = L["The frame that the bar is anchored to"],
flickerstreak@216 267 get = function() local _, f = bar:GetAnchor(); return f end,
flickerstreak@216 268 set = function(info, val) bar:SetAnchor(nil,val) end,
flickerstreak@216 269 validate = function(info, name)
flickerstreak@216 270 if name then
flickerstreak@216 271 local f = ReAction:GetBar(name)
flickerstreak@216 272 if f then
flickerstreak@216 273 return true
flickerstreak@216 274 else
flickerstreak@216 275 f = _G[name]
flickerstreak@216 276 if f and type(f) == "table" and f.IsObjectType and f:IsObjectType("Frame") then
flickerstreak@216 277 local _, explicit = f:IsProtected()
flickerstreak@216 278 return explicit
flickerstreak@216 279 end
flickerstreak@185 280 end
flickerstreak@185 281 end
flickerstreak@216 282 return false
flickerstreak@216 283 end,
flickerstreak@216 284 width = "double",
flickerstreak@216 285 order = 1
flickerstreak@216 286 },
flickerstreak@216 287 point = {
flickerstreak@216 288 type = "select",
flickerstreak@216 289 name = L["Point"],
flickerstreak@216 290 desc = L["Anchor point on the bar frame"],
flickerstreak@216 291 style = "dropdown",
flickerstreak@216 292 get = function() return bar:GetAnchor() end,
flickerstreak@216 293 set = function(info, val) bar:SetAnchor(val) end,
flickerstreak@216 294 values = pointTable,
flickerstreak@216 295 order = 2,
flickerstreak@216 296 },
flickerstreak@216 297 relativePoint = {
flickerstreak@216 298 type = "select",
flickerstreak@216 299 name = L["Relative Point"],
flickerstreak@216 300 desc = L["Anchor point on the target frame"],
flickerstreak@216 301 style = "dropdown",
flickerstreak@216 302 get = function() local p,f,r = bar:GetAnchor(); return r end,
flickerstreak@216 303 set = function(info, val) bar:SetAnchor(nil,nil,val) end,
flickerstreak@216 304 values = pointTable,
flickerstreak@216 305 order = 3,
flickerstreak@216 306 },
flickerstreak@216 307 x = {
flickerstreak@216 308 type = "input",
flickerstreak@216 309 pattern = "\-?%d+",
flickerstreak@216 310 name = L["X offset"],
flickerstreak@216 311 get = function() local p,f,r,x = bar:GetAnchor(); return ("%d"):format(x) end,
flickerstreak@216 312 set = function(info,val) bar:SetAnchor(nil,nil,nil,val) end,
flickerstreak@216 313 order = 4
flickerstreak@216 314 },
flickerstreak@216 315 y = {
flickerstreak@216 316 type = "input",
flickerstreak@216 317 pattern = "\-?%d+",
flickerstreak@216 318 name = L["Y offset"],
flickerstreak@216 319 get = function() local p,f,r,x,y = bar:GetAnchor(); return ("%d"):format(y) end,
flickerstreak@216 320 set = function(info,val) bar:SetAnchor(nil,nil,nil,nil,val) end,
flickerstreak@216 321 order = 5
flickerstreak@216 322 },
flickerstreak@185 323 },
flickerstreak@216 324 order = 3
flickerstreak@185 325 },
flickerstreak@216 326 alpha = {
flickerstreak@216 327 type = "range",
flickerstreak@216 328 name = L["Transparency"],
flickerstreak@216 329 get = function() return bar:GetAlpha() end,
flickerstreak@216 330 set = function(info, val) bar:SetAlpha(val) end,
flickerstreak@216 331 min = 0,
flickerstreak@216 332 max = 1,
flickerstreak@216 333 isPercent = true,
flickerstreak@216 334 step = 0.01,
flickerstreak@216 335 bigStep = 0.05,
flickerstreak@216 336 order = 4,
flickerstreak@216 337 },
flickerstreak@185 338 },
flickerstreak@185 339 },
Flick@244 340 buttonOpts = self:CreateButtonOptions(bar),
Flick@244 341 stateOpts = self:CreateStateOptions(bar)
Flick@244 342 }
flickerstreak@185 343 }
flickerstreak@216 344 end
flickerstreak@216 345
flickerstreak@185 346 end
flickerstreak@185 347
Flick@237 348 function Editor:CreateButtonOptions(bar)
Flick@237 349 local buttonClass = bar:GetButtonClass()
Flick@237 350 local classID = buttonClass:GetButtonTypeID()
Flick@237 351 local handler = self.buttonHandlers[classID]
Flick@237 352
Flick@237 353 if handler then
Flick@237 354 local h = handler:New(bar)
Flick@237 355 return h:GetOptions()
Flick@237 356 end
Flick@237 357 end
Flick@237 358
flickerstreak@185 359 function Editor:RefreshBarOptions()
flickerstreak@219 360 for name, key in pairs(self.barOptMap) do
flickerstreak@216 361 if not ReAction:GetBar(name) then
flickerstreak@219 362 self.barOptMap[name] = nil
flickerstreak@219 363 self.options.args[key] = nil
flickerstreak@185 364 end
flickerstreak@185 365 end
flickerstreak@216 366 for name, bar in ReAction:IterateBars() do
flickerstreak@216 367 self:UpdateBarOptions(bar)
flickerstreak@216 368 end
flickerstreak@216 369 self:Refresh()
flickerstreak@185 370 end
flickerstreak@185 371
flickerstreak@185 372 function Editor:OnCreateBar(evt, bar)
flickerstreak@216 373 self:UpdateBarOptions(bar)
flickerstreak@216 374 self:Refresh()
flickerstreak@185 375 end
flickerstreak@185 376
flickerstreak@185 377 function Editor:OnDestroyBar(evt, bar, name)
flickerstreak@185 378 local key = self.barOptMap[name]
flickerstreak@185 379 if key then
flickerstreak@216 380 self.barOptMap[name] = nil
flickerstreak@185 381 self.options.args[key] = nil
flickerstreak@185 382 self:Refresh()
flickerstreak@185 383 end
flickerstreak@185 384 end
flickerstreak@185 385
flickerstreak@185 386 function Editor:OnRenameBar(evt, bar, oldname, newname)
flickerstreak@185 387 local key = self.barOptMap[oldname]
flickerstreak@185 388 if key then
flickerstreak@216 389 self.barOptMap[oldname], self.barOptMap[newname] = nil, key
flickerstreak@185 390 self.options.args[key].name = newname
flickerstreak@185 391 self:Refresh()
flickerstreak@185 392 end
flickerstreak@185 393 end
flickerstreak@185 394
flickerstreak@185 395 local _scratch = { }
flickerstreak@185 396 function Editor:GetBarTypes()
flickerstreak@185 397 wipe(_scratch)
flickerstreak@185 398 return ReAction:GetBarTypeOptions(_scratch)
flickerstreak@185 399 end
flickerstreak@185 400
flickerstreak@185 401 function Editor:CreateBar()
flickerstreak@185 402 if self.tmp.barName and self.tmp.barName ~= "" then
flickerstreak@185 403 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 404 if bar then
flickerstreak@185 405 AceConfigDialog:SelectGroup(self.configID, self.barOptMap[self.tmp.barName])
flickerstreak@185 406 self.tmp.barName = nil
flickerstreak@185 407 end
flickerstreak@185 408 end
flickerstreak@185 409 end
flickerstreak@185 410
Flick@237 411 -------------------------------
Flick@237 412 ---- Action button handler ----
Flick@237 413 -------------------------------
Flick@237 414
Flick@237 415 do
Flick@237 416 local ActionHandler = {
Flick@237 417 buttonClass = ReAction.Button.Action,
Flick@237 418 options = {
Flick@237 419 hideEmpty = {
Flick@237 420 name = L["Hide Empty Buttons"],
Flick@237 421 order = 1,
Flick@237 422 type = "toggle",
Flick@237 423 width = "double",
Flick@237 424 get = "GetHideEmpty",
Flick@237 425 set = "SetHideEmpty",
Flick@237 426 },
Flick@237 427 lockButtons = {
Flick@237 428 name = L["Lock Buttons"],
Flick@237 429 desc = L["Prevents picking up/dragging actions (use SHIFT to override this behavior)"],
Flick@237 430 order = 2,
Flick@237 431 type = "toggle",
Flick@237 432 get = "GetLockButtons",
Flick@237 433 set = "SetLockButtons",
Flick@237 434 },
Flick@237 435 lockOnlyCombat = {
Flick@237 436 name = L["Only in Combat"],
Flick@237 437 desc = L["Only lock the buttons when in combat"],
Flick@237 438 order = 3,
Flick@237 439 type = "toggle",
Flick@237 440 disabled = "LockButtonsCombatDisabled",
Flick@237 441 get = "GetLockButtonsCombat",
Flick@237 442 set = "SetLockButtonsCombat",
Flick@237 443 },
Flick@237 444 pages = {
Flick@237 445 name = L["# Pages"],
Flick@237 446 desc = L["Use the Dynamic State tab to specify page transitions"],
Flick@237 447 order = 4,
Flick@237 448 type = "range",
Flick@237 449 min = 1,
Flick@237 450 max = 10,
Flick@237 451 step = 1,
Flick@237 452 get = "GetNumPages",
Flick@237 453 set = "SetNumPages",
Flick@237 454 },
Flick@237 455 mindcontrol = {
Flick@237 456 name = L["Mind Control Support"],
Flick@237 457 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 458 order = 5,
Flick@237 459 type = "toggle",
Flick@237 460 width = "double",
Flick@237 461 set = "SetMindControl",
Flick@237 462 get = "GetMindControl",
Flick@237 463 },
Flick@237 464 vehicle = {
Flick@237 465 name = L["Vehicle Support"],
Flick@237 466 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 467 order = 6,
Flick@237 468 type = "toggle",
Flick@237 469 width = "double",
Flick@237 470 get = "GetVehicle",
Flick@237 471 set = "SetVehicle",
Flick@237 472 },
Flick@237 473 actions = {
Flick@237 474 name = L["Edit Action IDs"],
Flick@237 475 order = 7,
Flick@237 476 type = "group",
Flick@237 477 inline = true,
Flick@237 478 args = {
Flick@237 479 method = {
Flick@237 480 name = L["Assign"],
Flick@237 481 order = 1,
Flick@237 482 type = "select",
Flick@237 483 width = "double",
Flick@237 484 values = { [0] = L["Choose Method..."],
Flick@237 485 [1] = L["Individually"],
Flick@237 486 [2] = L["All at Once"], },
Flick@237 487 get = "GetActionEditMethod",
Flick@237 488 set = "SetActionEditMethod",
Flick@237 489 },
Flick@237 490 rowSelect = {
Flick@237 491 name = L["Row"],
Flick@237 492 desc = L["Rows are numbered top to bottom"],
Flick@237 493 order = 2,
Flick@237 494 type = "select",
Flick@237 495 width = "half",
Flick@237 496 hidden = "IsButtonSelectHidden",
Flick@237 497 values = "GetRowList",
Flick@237 498 get = "GetSelectedRow",
Flick@237 499 set = "SetSelectedRow",
Flick@237 500 },
Flick@237 501 colSelect = {
Flick@237 502 name = L["Col"],
Flick@237 503 desc = L["Columns are numbered left to right"],
Flick@237 504 order = 3,
Flick@237 505 type = "select",
Flick@237 506 width = "half",
Flick@237 507 hidden = "IsButtonSelectHidden",
Flick@237 508 values = "GetColumnList",
Flick@237 509 get = "GetSelectedColumn",
Flick@237 510 set = "SetSelectedColumn",
Flick@237 511 },
Flick@237 512 pageSelect = {
Flick@237 513 name = L["Page"],
Flick@237 514 order = 4,
Flick@237 515 type = "select",
Flick@237 516 width = "half",
Flick@237 517 hidden = "IsPageSelectHidden",
Flick@237 518 values = "GetPageList",
Flick@237 519 get = "GetSelectedPage",
Flick@237 520 set = "SetSelectedPage",
Flick@237 521 },
Flick@237 522 single = {
Flick@237 523 name = L["Action ID"],
Flick@237 524 usage = L["Specify ID 1-120"],
Flick@237 525 order = 5,
Flick@237 526 type = "input",
Flick@237 527 width = "half",
Flick@237 528 hidden = "IsButtonSelectHidden",
Flick@237 529 get = "GetActionID",
Flick@237 530 set = "SetActionID",
Flick@237 531 validate = "ValidateActionID",
Flick@237 532 },
Flick@237 533 multi = {
Flick@237 534 name = L["ID List"],
Flick@237 535 usage = L["Specify a comma-separated list of IDs for each button in the bar (in order). Separate multiple pages with semicolons (;)"],
Flick@237 536 order = 6,
Flick@237 537 type = "input",
Flick@237 538 multiline = true,
Flick@237 539 width = "double",
Flick@237 540 hidden = "IsMultiIDHidden",
Flick@237 541 get = "GetMultiID",
Flick@237 542 set = "SetMultiID",
Flick@237 543 validate = "ValidateMultiID",
Flick@237 544 },
Flick@237 545 },
Flick@237 546 },
Flick@237 547 }
Flick@237 548 }
Flick@237 549
Flick@237 550 Editor.buttonHandlers[ActionHandler.buttonClass:GetButtonTypeID()] = ActionHandler
Flick@237 551
Flick@237 552 local meta = { __index = ActionHandler }
Flick@237 553
Flick@237 554 function ActionHandler:New( bar )
Flick@237 555 return setmetatable(
Flick@237 556 {
Flick@237 557 bar = bar,
Flick@237 558 config = bar:GetConfig(),
Flick@237 559 },
Flick@237 560 meta)
Flick@237 561 end
Flick@237 562
Flick@237 563 function ActionHandler:Refresh()
Flick@237 564 self.buttonClass:SetupBar(self.bar)
Flick@237 565 end
Flick@237 566
Flick@237 567 function ActionHandler:UpdateButtonLock()
Flick@237 568 self.buttonClass:SetButtonLock(self.bar, self.config.lockButtons, self.config.lockButtonsCombat)
Flick@237 569 end
Flick@237 570
Flick@237 571 function ActionHandler:GetLastButton()
Flick@237 572 return self.bar:GetButton(self.bar:GetNumButtons())
Flick@237 573 end
Flick@237 574
Flick@237 575 -- options handlers
Flick@237 576 function ActionHandler:GetOptions()
Flick@237 577 return {
Flick@237 578 type = "group",
Flick@237 579 name = L["Action Buttons"],
Flick@237 580 handler = self,
Flick@237 581 order = 2,
Flick@237 582 args = self.options
Flick@237 583 }
Flick@237 584 end
Flick@237 585
Flick@237 586 function ActionHandler:SetHideEmpty(info, value)
Flick@237 587 if value ~= self.config.hideEmpty then
Flick@237 588 self.config.hideEmpty = value
Flick@237 589 for _, b in self.bar:IterateButtons() do
Flick@237 590 b:ShowGrid(not value)
Flick@237 591 end
Flick@237 592 end
Flick@237 593 end
Flick@237 594
Flick@237 595 function ActionHandler:GetHideEmpty()
Flick@237 596 return self.config.hideEmpty
Flick@237 597 end
Flick@237 598
Flick@237 599 function ActionHandler:GetLockButtons()
Flick@237 600 return self.config.lockButtons
Flick@237 601 end
Flick@237 602
Flick@237 603 function ActionHandler:SetLockButtons(info, value)
Flick@237 604 self.config.lockButtons = value
Flick@237 605 self:UpdateButtonLock()
Flick@237 606 end
Flick@237 607
Flick@237 608 function ActionHandler:GetLockButtonsCombat()
Flick@237 609 return self.config.lockButtonsCombat
Flick@237 610 end
Flick@237 611
Flick@237 612 function ActionHandler:SetLockButtonsCombat(info, value)
Flick@237 613 self.config.lockButtonsCombat = value
Flick@237 614 self:UpdateButtonLock()
Flick@237 615 end
Flick@237 616
Flick@237 617 function ActionHandler:LockButtonsCombatDisabled()
Flick@237 618 return not self.config.lockButtons
Flick@237 619 end
Flick@237 620
Flick@237 621 function ActionHandler:GetNumPages()
Flick@237 622 return self.config.nPages
Flick@237 623 end
Flick@237 624
Flick@237 625 function ActionHandler:SetNumPages(info, value)
Flick@237 626 self.config.nPages = value
Flick@237 627 self:Refresh()
Flick@237 628 end
Flick@237 629
Flick@237 630 function ActionHandler:GetMindControl()
Flick@237 631 return self.config.mindcontrol
Flick@237 632 end
Flick@237 633
Flick@237 634 function ActionHandler:SetMindControl(info, value)
Flick@237 635 self.config.mindcontrol = value
Flick@237 636 self:Refresh()
Flick@237 637 end
Flick@237 638
Flick@237 639 function ActionHandler:GetVehicle()
Flick@237 640 return self.config.vehicle
Flick@237 641 end
Flick@237 642
Flick@237 643 function ActionHandler:SetVehicle(info, value)
Flick@237 644 self.config.vehicle = value
Flick@237 645 self:Refresh()
Flick@237 646 end
Flick@237 647
Flick@237 648 function ActionHandler:GetActionEditMethod()
Flick@237 649 return self.editMethod or 0
Flick@237 650 end
Flick@237 651
Flick@237 652 function ActionHandler:SetActionEditMethod(info, value)
Flick@237 653 self.editMethod = value
Flick@237 654 end
Flick@237 655
Flick@237 656 function ActionHandler:IsButtonSelectHidden()
Flick@237 657 return self.editMethod ~= 1
Flick@237 658 end
Flick@237 659
Flick@237 660 function ActionHandler:GetRowList()
Flick@237 661 local r,c = self.bar:GetButtonGrid()
Flick@237 662 if self.rowList == nil or #self.rowList ~= r then
Flick@237 663 local list = { }
Flick@237 664 for i = 1, r do
Flick@237 665 table.insert(list,i)
Flick@237 666 end
Flick@237 667 self.rowList = list
Flick@237 668 end
Flick@237 669 return self.rowList
Flick@237 670 end
Flick@237 671
Flick@237 672 function ActionHandler:GetSelectedRow()
Flick@237 673 local r, c = self.bar:GetButtonGrid()
Flick@237 674 local row = self.selectedRow or 1
Flick@237 675 if row > r then
Flick@237 676 row = 1
Flick@237 677 end
Flick@237 678 self.selectedRow = row
Flick@237 679 return row
Flick@237 680 end
Flick@237 681
Flick@237 682 function ActionHandler:SetSelectedRow(info, value)
Flick@237 683 self.selectedRow = value
Flick@237 684 end
Flick@237 685
Flick@237 686 function ActionHandler:GetColumnList()
Flick@237 687 local r,c = self.bar:GetButtonGrid()
Flick@237 688 if self.columnList == nil or #self.columnList ~= c then
Flick@237 689 local list = { }
Flick@237 690 for i = 1, c do
Flick@237 691 table.insert(list,i)
Flick@237 692 end
Flick@237 693 self.columnList = list
Flick@237 694 end
Flick@237 695 return self.columnList
Flick@237 696 end
Flick@237 697
Flick@237 698 function ActionHandler:GetSelectedColumn()
Flick@237 699 local r, c = self.bar:GetButtonGrid()
Flick@237 700 local col = self.selectedColumn or 1
Flick@237 701 if col > c then
Flick@237 702 col = 1
Flick@237 703 end
Flick@237 704 self.selectedColumn = col
Flick@237 705 return col
Flick@237 706 end
Flick@237 707
Flick@237 708 function ActionHandler:SetSelectedColumn(info, value)
Flick@237 709 self.selectedColumn = value
Flick@237 710 end
Flick@237 711
Flick@237 712 function ActionHandler:IsPageSelectHidden()
Flick@237 713 return self.editMethod ~= 1 or (self.config.nPages or 1) < 2
Flick@237 714 end
Flick@237 715
Flick@237 716 function ActionHandler:GetPageList()
Flick@237 717 local n = self.config.nPages or 1
Flick@237 718 if self.pageList == nil or #self.pageList ~= n then
Flick@237 719 local p = { }
Flick@237 720 for i = 1, n do
Flick@237 721 table.insert(p,i)
Flick@237 722 end
Flick@237 723 self.pageList = p
Flick@237 724 end
Flick@237 725 return self.pageList
Flick@237 726 end
Flick@237 727
Flick@237 728 function ActionHandler:GetSelectedPage()
Flick@237 729 local p = self.selectedPage or 1
Flick@237 730 if p > (self.config.nPages or 1) then
Flick@237 731 p = 1
Flick@237 732 end
Flick@237 733 self.selectedPage = p
Flick@237 734 return p
Flick@237 735 end
Flick@237 736
Flick@237 737 function ActionHandler:SetSelectedPage(info, value)
Flick@237 738 self.selectedPage = value
Flick@237 739 end
Flick@237 740
Flick@237 741 function ActionHandler:GetActionID()
Flick@237 742 local row = self.selectedRow or 1
Flick@237 743 local col = self.selectedColumn or 1
Flick@237 744 local r, c = self.bar:GetButtonGrid()
Flick@237 745 local n = (row-1) * c + col
Flick@237 746 local btn = self.bar:GetButton(n)
Flick@237 747 if btn then
Flick@237 748 return tostring(btn:GetActionID(self.selectedPage or 1))
Flick@237 749 end
Flick@237 750 end
Flick@237 751
Flick@237 752 function ActionHandler:SetActionID(info, value)
Flick@237 753 local row = self.selectedRow or 1
Flick@237 754 local col = self.selectedColumn or 1
Flick@237 755 local r, c = self.bar:GetButtonGrid()
Flick@237 756 local n = (row-1) * c + col
Flick@237 757 local btn = self.bar:GetButton(n)
Flick@237 758 if btn then
Flick@237 759 btn:SetActionID(tonumber(value), self.selectedPage or 1)
Flick@237 760 end
Flick@237 761 end
Flick@237 762
Flick@237 763 function ActionHandler:ValidateActionID(info, value)
Flick@237 764 value = tonumber(value)
Flick@237 765 if value == nil or value < 1 or value > 120 then
Flick@237 766 return L["Specify ID 1-120"]
Flick@237 767 end
Flick@237 768 return true
Flick@237 769 end
Flick@237 770
Flick@237 771 function ActionHandler:IsMultiIDHidden()
Flick@237 772 return self.editMethod ~= 2
Flick@237 773 end
Flick@237 774
Flick@237 775 function ActionHandler:GetMultiID()
Flick@237 776 local p = { }
Flick@237 777 for i = 1, self.config.nPages or 1 do
Flick@237 778 local b = { }
Flick@237 779 for _, btn in self.bar:IterateButtons() do
Flick@237 780 table.insert(b, btn:GetActionID(i))
Flick@237 781 end
Flick@237 782 table.insert(p, table.concat(b,","))
Flick@237 783 end
Flick@237 784 return table.concat(p,";\n")
Flick@237 785 end
Flick@237 786
Flick@237 787
Flick@237 788 local function ParseMultiID(nBtns, nPages, s)
Flick@237 789 if s:match("[^%d%s,;]") then
Flick@237 790 return nil
Flick@237 791 end
Flick@237 792 local p = { }
Flick@237 793 for list in s:gmatch("[^;]+") do
Flick@237 794 local pattern = ("^%s?$"):format(("%s*(%d+)%s*,"):rep(nBtns))
Flick@237 795 local ids = { list:match(pattern) }
Flick@237 796 if #ids ~= nBtns then
Flick@237 797 return nil
Flick@237 798 end
Flick@237 799 table.insert(p,ids)
Flick@237 800 end
Flick@237 801 if #p ~= nPages then
Flick@237 802 return nil
Flick@237 803 end
Flick@237 804 return p
Flick@237 805 end
Flick@237 806
Flick@237 807 function ActionHandler:SetMultiID(info, value)
Flick@237 808 local p = ParseMultiID(self.bar:GetNumButtons(), self.config.nPages or 1, value)
Flick@237 809 for page, b in ipairs(p) do
Flick@237 810 for button, id in ipairs(b) do
Flick@237 811 self.bar:GetButton(button):SetActionID(id, page)
Flick@237 812 end
Flick@237 813 end
Flick@237 814 end
Flick@237 815
Flick@237 816 function ActionHandler:ValidateMultiID(info, value)
Flick@237 817 local bad = L["Invalid action ID list string"]
Flick@237 818 if value == nil or ParseMultiID(self.bar:GetNumButtons(), self.config.nPages or 1, value) == nil then
Flick@237 819 return bad
Flick@237 820 end
Flick@237 821 return true
Flick@237 822 end
Flick@237 823 end
Flick@237 824
Flick@237 825
Flick@237 826 ----------------------------------
Flick@237 827 ---- PetAction button handler ----
Flick@237 828 ----------------------------------
Flick@237 829
Flick@237 830 do
Flick@237 831 local PetHandler = {
Flick@237 832 buttonClass = ReAction.Button.PetAction,
Flick@237 833 }
Flick@237 834
Flick@237 835 Editor.buttonHandlers[PetHandler.buttonClass:GetButtonTypeID()] = PetHandler
Flick@237 836
Flick@237 837 local meta = { __index = PetHandler }
Flick@237 838
Flick@237 839 function PetHandler:New(bar)
Flick@237 840 return setmetatable(
Flick@237 841 {
Flick@237 842 bar = bar,
Flick@237 843 config = bar.config
Flick@237 844 }, meta)
Flick@237 845 end
Flick@237 846
Flick@237 847 function PetHandler:GetLockButtons()
Flick@237 848 return self.config.lockButtons
Flick@237 849 end
Flick@237 850
Flick@237 851 function PetHandler:SetLockButtons(info, value)
Flick@237 852 self.config.lockButtons = value
Flick@237 853 self.buttonClass:UpdateButtonLock(self.bar)
Flick@237 854 end
Flick@237 855
Flick@237 856 function PetHandler:GetLockButtonsCombat()
Flick@237 857 return self.config.lockButtonsCombat
Flick@237 858 end
Flick@237 859
Flick@237 860 function PetHandler:SetLockButtonsCombat(info, value)
Flick@237 861 self.config.lockButtonsCombat = value
Flick@237 862 self.buttonClass:UpdateButtonLock(self.bar)
Flick@237 863 end
Flick@237 864
Flick@237 865 function PetHandler:LockButtonsCombatDisabled()
Flick@237 866 return not self.config.lockButtons
Flick@237 867 end
Flick@237 868
Flick@237 869 function PetHandler:GetOptions()
Flick@237 870 return {
Flick@237 871 type = "group",
Flick@237 872 name = L["Pet Buttons"],
Flick@237 873 handler = self,
Flick@237 874 order = 2,
Flick@237 875 args = {
Flick@237 876 lockButtons = {
Flick@237 877 name = L["Lock Buttons"],
Flick@237 878 desc = L["Prevents picking up/dragging actions (use SHIFT to override this behavior)"],
Flick@237 879 order = 2,
Flick@237 880 type = "toggle",
Flick@237 881 get = "GetLockButtons",
Flick@237 882 set = "SetLockButtons",
Flick@237 883 },
Flick@237 884 lockOnlyCombat = {
Flick@237 885 name = L["Only in Combat"],
Flick@237 886 desc = L["Only lock the buttons when in combat"],
Flick@237 887 order = 3,
Flick@237 888 type = "toggle",
Flick@237 889 disabled = "LockButtonsCombatDisabled",
Flick@237 890 get = "GetLockButtonsCombat",
Flick@237 891 set = "SetLockButtonsCombat",
Flick@237 892 },
Flick@237 893 }
Flick@237 894 }
Flick@237 895 end
Flick@237 896 end
Flick@237 897
Flick@237 898
Flick@237 899 -------------------------------------
Flick@237 900 ---- Vehicle Exit button handler ----
Flick@237 901 -------------------------------------
Flick@237 902
Flick@237 903 do
Flick@237 904 local VExitHandler = {
Flick@237 905 buttonClass = ReAction.Button.VehicleExit,
Flick@237 906 }
Flick@237 907
Flick@237 908 Editor.buttonHandlers[VExitHandler.buttonClass:GetButtonTypeID()] = VExitHandler
Flick@237 909
Flick@237 910 local meta = { __index = VExitHandler }
Flick@237 911
Flick@237 912 function VExitHandler:New(bar)
Flick@237 913 return setmetatable(
Flick@237 914 {
Flick@237 915 bar = bar,
Flick@237 916 }, meta)
Flick@237 917 end
Flick@237 918
Flick@237 919 function VExitHandler:GetConfig()
Flick@237 920 return self.bar:GetConfig()
Flick@237 921 end
Flick@237 922
Flick@237 923 function VExitHandler:GetPassengerOnly()
Flick@237 924 return not self:GetConfig().withControls
Flick@237 925 end
Flick@237 926
Flick@237 927 function VExitHandler:SetPassengerOnly(info, value)
Flick@237 928 self:GetConfig().withControls = not value
Flick@237 929 self.buttonClass:UpdateRegistration(self.bar)
Flick@237 930 end
Flick@237 931
Flick@237 932
Flick@237 933 function VExitHandler:GetOptions()
Flick@237 934 return {
Flick@237 935 type = "group",
Flick@237 936 name = L["Exit Vehicle"],
Flick@237 937 handler = self,
Flick@237 938 args = {
Flick@237 939 passengerOnly = {
Flick@237 940 name = L["Show only when passenger"],
Flick@237 941 desc = L["Only show the button when riding as a passenger in a vehicle (no vehicle controls)"],
Flick@237 942 order = 2,
Flick@237 943 width = "double",
Flick@237 944 type = "toggle",
Flick@237 945 get = "GetPassengerOnly",
Flick@237 946 set = "SetPassengerOnly",
Flick@237 947 },
Flick@237 948 }
Flick@237 949 }
Flick@237 950 end
Flick@237 951 end
Flick@237 952
flickerstreak@185 953
Flick@244 954 ------------------------------
Flick@244 955 --- Dynamic State options ----
Flick@244 956 ------------------------------
Flick@244 957 do
Flick@244 958 local ApplyStates = ReAction.Bar.ApplyStates
Flick@244 959 local CleanupStates = ReAction.Bar.CleanupStates
Flick@244 960 local SetProperty = ReAction.Bar.SetStateProperty
Flick@244 961 local GetProperty = ReAction.Bar.GetStateProperty
Flick@244 962
Flick@244 963 -- pre-sorted by the order they should appear in
Flick@244 964 local rules = {
Flick@244 965 -- rule fields
Flick@244 966 { "stance", { {battle = L["Battle Stance"]}, {defensive = L["Defensive Stance"]}, {berserker = L["Berserker Stance"]} } },
Flick@244 967 { "form", { {caster = L["Caster Form"]}, {bear = L["Bear Form"]}, {cat = L["Cat Form"]}, {tree = L["Tree of Life"]}, {moonkin = L["Moonkin Form"]} } },
Flick@244 968 { "stealth", { {stealth = L["Stealth"]}, {nostealth = L["No Stealth"]}, {shadowdance = L["Shadow Dance"]} } },
Flick@244 969 { "shadow", { {shadowform = L["Shadowform"]}, {noshadowform = L["No Shadowform"]} } },
Flick@244 970 { "demon", { {demon = L["Demon Form"]}, {nodemon = L["No Demon Form"]} } },
Flick@244 971 { "pet", { {pet = L["With Pet"]}, {nopet = L["Without Pet"]} } },
Flick@244 972 { "target", { {harm = L["Hostile Target"]}, {help = L["Friendly Target"]}, {notarget = L["No Target"]} } },
Flick@244 973 { "focus", { {focusharm = L["Hostile Focus"]}, {focushelp = L["Friendly Focus"]}, {nofocus = L["No Focus"]} } },
Flick@244 974 { "possess", { {possess = L["Mind Control"]} } },
Flick@244 975 { "vehicle", { {vehicle = L["In a Vehicle"]} } },
Flick@244 976 { "group", { {raid = L["Raid"]}, {party = L["Party"]}, {solo = L["Solo"]} } },
Flick@244 977 { "combat", { {combat = L["In Combat"]}, {nocombat = L["Out of Combat"]} } },
Flick@244 978 }
Flick@244 979
Flick@244 980 local ruleSelect = { }
Flick@244 981 local ruleMap = { }
Flick@244 982 local optionMap = setmetatable({},{__mode="k"})
Flick@244 983
Flick@244 984
Flick@244 985 -- unpack rules table into ruleSelect and ruleMap
Flick@244 986 for _, c in ipairs(rules) do
Flick@244 987 local rule, fields = unpack(c)
Flick@244 988 for _, field in ipairs(fields) do
Flick@244 989 local key, label = next(field)
Flick@244 990 table.insert(ruleSelect, label)
Flick@244 991 table.insert(ruleMap, key)
Flick@244 992 end
Flick@244 993 end
Flick@244 994
Flick@244 995 local stateOptions = {
Flick@244 996 ordering = {
Flick@244 997 name = L["Info"],
Flick@244 998 order = 1,
Flick@244 999 type = "group",
Flick@244 1000 args = {
Flick@244 1001 delete = {
Flick@244 1002 name = L["Delete this State"],
Flick@244 1003 order = -1,
Flick@244 1004 type = "execute",
Flick@244 1005 func = "DeleteState",
Flick@244 1006 },
Flick@244 1007 rename = {
Flick@244 1008 name = L["Name"],
Flick@244 1009 order = 1,
Flick@244 1010 type = "input",
Flick@244 1011 get = "GetName",
Flick@244 1012 set = "SetStateName",
Flick@244 1013 pattern = "^%w*$",
Flick@244 1014 usage = L["State names must be alphanumeric without spaces"],
Flick@244 1015 },
Flick@244 1016 ordering = {
Flick@244 1017 name = L["Evaluation Order"],
Flick@256 1018 desc = L["State transitions are evaluated in the order listed: Move a state up or down to change the order"],
Flick@244 1019 order = 2,
Flick@244 1020 type = "group",
Flick@244 1021 inline = true,
Flick@244 1022 args = {
Flick@244 1023 up = {
Flick@244 1024 name = L["Up"],
Flick@244 1025 order = 1,
Flick@244 1026 type = "execute",
Flick@244 1027 width = "half",
Flick@244 1028 func = "MoveStateUp",
Flick@244 1029 },
Flick@244 1030 down = {
Flick@244 1031 name = L["Down"],
Flick@244 1032 order = 2,
Flick@244 1033 type = "execute",
Flick@244 1034 width = "half",
Flick@244 1035 func = "MoveStateDown",
Flick@244 1036 }
Flick@244 1037 }
Flick@244 1038 }
Flick@244 1039 }
Flick@244 1040 },
Flick@244 1041 properties = {
Flick@244 1042 name = L["Properties"],
Flick@244 1043 order = 2,
Flick@244 1044 type = "group",
Flick@244 1045 args = {
Flick@244 1046 desc = {
Flick@244 1047 name = L["Set the properties for the bar when in this state"],
Flick@244 1048 order = 1,
Flick@244 1049 type = "description"
Flick@244 1050 },
Flick@244 1051 page = {
Flick@244 1052 name = L["Show Page #"],
Flick@244 1053 order = 11,
Flick@244 1054 type = "select",
Flick@244 1055 width = "half",
Flick@244 1056 disabled = "IsPageDisabled",
Flick@244 1057 hidden = "IsPageHidden",
Flick@244 1058 values = "GetPageValues",
Flick@244 1059 set = "SetProp",
Flick@244 1060 get = "GetPage",
Flick@244 1061 },
Flick@244 1062 hide = {
Flick@244 1063 name = L["Hide Bar"],
Flick@244 1064 order = 90,
Flick@244 1065 type = "toggle",
Flick@244 1066 set = "SetProp",
Flick@244 1067 get = "GetProp",
Flick@244 1068 },
Flick@244 1069 --[[ BROKEN
Flick@244 1070 keybindState = {
Flick@244 1071 name = L["Override Keybinds"],
Flick@244 1072 desc = L["Set this state to maintain its own set of keybinds which override the defaults when active"],
Flick@244 1073 order = 91,
Flick@244 1074 type = "toggle",
Flick@244 1075 set = "SetProp",
Flick@244 1076 get = "GetProp",
Flick@244 1077 }, ]]
Flick@244 1078 position = {
Flick@244 1079 name = L["Position"],
Flick@244 1080 order = 92,
Flick@244 1081 type = "group",
Flick@244 1082 inline = true,
Flick@244 1083 args = {
Flick@244 1084 anchorEnable = {
Flick@244 1085 name = L["Reposition"],
Flick@244 1086 order = 1,
Flick@244 1087 type = "toggle",
Flick@244 1088 set = "SetProp",
Flick@244 1089 get = "GetProp",
Flick@244 1090 },
Flick@244 1091 anchorFrame = {
Flick@244 1092 name = L["Anchor Frame"],
Flick@244 1093 order = 2,
Flick@244 1094 type = "select",
Flick@244 1095 values = "GetAnchorFrames",
Flick@244 1096 set = "SetAnchorFrame",
Flick@244 1097 get = "GetAnchorFrame",
Flick@244 1098 disabled = "GetAnchorDisabled",
Flick@244 1099 hidden = "GetAnchorDisabled",
Flick@244 1100 },
Flick@244 1101 anchorPoint = {
Flick@244 1102 name = L["Point"],
Flick@244 1103 order = 3,
Flick@244 1104 type = "select",
Flick@244 1105 values = pointTable,
Flick@244 1106 set = "SetAnchorPointProp",
Flick@244 1107 get = "GetAnchorPointProp",
Flick@244 1108 disabled = "GetAnchorDisabled",
Flick@244 1109 hidden = "GetAnchorDisabled",
Flick@244 1110 },
Flick@244 1111 anchorRelPoint = {
Flick@244 1112 name = L["Relative Point"],
Flick@244 1113 order = 4,
Flick@244 1114 type = "select",
Flick@244 1115 values = pointTable,
Flick@244 1116 set = "SetAnchorPointProp",
Flick@244 1117 get = "GetAnchorPointProp",
Flick@244 1118 disabled = "GetAnchorDisabled",
Flick@244 1119 hidden = "GetAnchorDisabled",
Flick@244 1120 },
Flick@244 1121 anchorX = {
Flick@244 1122 name = L["X Offset"],
Flick@244 1123 order = 5,
Flick@244 1124 type = "range",
Flick@244 1125 min = -100,
Flick@244 1126 max = 100,
Flick@244 1127 step = 1,
Flick@244 1128 set = "SetProp",
Flick@244 1129 get = "GetProp",
Flick@244 1130 disabled = "GetAnchorDisabled",
Flick@244 1131 hidden = "GetAnchorDisabled",
Flick@244 1132 },
Flick@244 1133 anchorY = {
Flick@244 1134 name = L["Y Offset"],
Flick@244 1135 order = 6,
Flick@244 1136 type = "range",
Flick@244 1137 min = -100,
Flick@244 1138 max = 100,
Flick@244 1139 step = 1,
Flick@244 1140 set = "SetProp",
Flick@244 1141 get = "GetProp",
Flick@244 1142 disabled = "GetAnchorDisabled",
Flick@244 1143 hidden = "GetAnchorDisabled",
Flick@244 1144 },
Flick@244 1145 },
Flick@244 1146 },
Flick@244 1147 scale = {
Flick@244 1148 name = L["Scale"],
Flick@244 1149 order = 93,
Flick@244 1150 type = "group",
Flick@244 1151 inline = true,
Flick@244 1152 args = {
Flick@244 1153 enableScale = {
Flick@244 1154 name = L["Set New Scale"],
Flick@244 1155 order = 1,
Flick@244 1156 type = "toggle",
Flick@244 1157 set = "SetProp",
Flick@244 1158 get = "GetProp",
Flick@244 1159 },
Flick@244 1160 scale = {
Flick@244 1161 name = L["Scale"],
Flick@244 1162 order = 2,
Flick@244 1163 type = "range",
Flick@244 1164 min = 0.25,
Flick@244 1165 max = 2.5,
Flick@244 1166 step = 0.05,
Flick@244 1167 isPercent = true,
Flick@244 1168 set = "SetProp",
Flick@244 1169 get = "GetScale",
Flick@244 1170 disabled = "GetScaleDisabled",
Flick@244 1171 hidden = "GetScaleDisabled",
Flick@244 1172 },
Flick@244 1173 },
Flick@244 1174 },
Flick@244 1175 alpha = {
Flick@244 1176 name = L["Transparency"],
Flick@244 1177 order = 94,
Flick@244 1178 type = "group",
Flick@244 1179 inline = true,
Flick@244 1180 args = {
Flick@244 1181 enableAlpha = {
Flick@244 1182 name = L["Set Transparency"],
Flick@244 1183 order = 1,
Flick@244 1184 type = "toggle",
Flick@244 1185 set = "SetProp",
Flick@244 1186 get = "GetProp",
Flick@244 1187 },
Flick@244 1188 alpha = {
Flick@244 1189 name = L["Transparency"],
Flick@244 1190 order = 2,
Flick@244 1191 type = "range",
Flick@244 1192 min = 0,
Flick@244 1193 max = 1,
Flick@244 1194 step = 0.01,
Flick@244 1195 bigStep = 0.05,
Flick@244 1196 isPercent = true,
Flick@244 1197 set = "SetProp",
Flick@244 1198 get = "GetAlpha",
Flick@244 1199 disabled = "GetAlphaDisabled",
Flick@244 1200 hidden = "GetAlphaDisabled",
Flick@244 1201 },
Flick@244 1202 },
Flick@244 1203 },
Flick@244 1204 },
Flick@244 1205 plugins = { }
Flick@244 1206 },
Flick@244 1207 rules = {
Flick@244 1208 name = L["Rule"],
Flick@244 1209 order = 3,
Flick@244 1210 type = "group",
Flick@244 1211 args = {
Flick@244 1212 mode = {
Flick@244 1213 name = L["Select this state"],
Flick@244 1214 order = 2,
Flick@244 1215 type = "select",
Flick@244 1216 style = "radio",
Flick@244 1217 values = {
Flick@244 1218 default = L["by default"],
Flick@244 1219 any = L["when ANY of these"],
Flick@244 1220 all = L["when ALL of these"],
Flick@244 1221 custom = L["via custom rule"],
Flick@244 1222 keybind = L["via keybinding"],
Flick@244 1223 },
Flick@244 1224 set = "SetType",
Flick@244 1225 get = "GetType",
Flick@244 1226 },
Flick@244 1227 clear = {
Flick@244 1228 name = L["Clear All"],
Flick@244 1229 order = 3,
Flick@244 1230 type = "execute",
Flick@244 1231 hidden = "GetClearAllDisabled",
Flick@244 1232 disabled = "GetClearAllDisabled",
Flick@244 1233 func = "ClearAllConditions",
Flick@244 1234 },
Flick@244 1235 inputs = {
Flick@244 1236 name = L["Conditions"],
Flick@244 1237 order = 4,
Flick@244 1238 type = "multiselect",
Flick@244 1239 hidden = "GetConditionsDisabled",
Flick@244 1240 disabled = "GetConditionsDisabled",
Flick@244 1241 values = ruleSelect,
Flick@244 1242 set = "SetCondition",
Flick@244 1243 get = "GetCondition",
Flick@244 1244 },
Flick@244 1245 custom = {
Flick@244 1246 name = L["Custom Rule"],
Flick@244 1247 order = 5,
Flick@244 1248 type = "input",
Flick@244 1249 multiline = true,
Flick@244 1250 hidden = "GetCustomDisabled",
Flick@244 1251 disabled = "GetCustomDisabled",
Flick@244 1252 desc = L["Syntax like macro rules: see preset rules for examples"],
Flick@244 1253 set = "SetCustomRule",
Flick@244 1254 get = "GetCustomRule",
Flick@244 1255 validate = "ValidateCustomRule",
Flick@244 1256 },
Flick@244 1257 keybind = {
Flick@244 1258 name = L["Keybinding"],
Flick@244 1259 order = 6,
Flick@244 1260 inline = true,
Flick@244 1261 hidden = "GetKeybindDisabled",
Flick@244 1262 disabled = "GetKeybindDisabled",
Flick@244 1263 type = "group",
Flick@244 1264 args = {
Flick@244 1265 desc = {
Flick@244 1266 name = L["Invoking a state keybind toggles an override of all other transition rules."],
Flick@244 1267 order = 1,
Flick@244 1268 type = "description",
Flick@244 1269 },
Flick@244 1270 keybind = {
Flick@244 1271 name = L["State Hotkey"],
Flick@244 1272 desc = L["Define an override toggle keybind"],
Flick@244 1273 order = 2,
Flick@244 1274 type = "keybinding",
Flick@244 1275 set = "SetKeybind",
Flick@244 1276 get = "GetKeybind",
Flick@244 1277 },
Flick@244 1278 },
Flick@244 1279 },
Flick@244 1280 },
Flick@244 1281 },
Flick@244 1282 }
Flick@244 1283
Flick@244 1284 local StateHandler = { }
Flick@244 1285 local meta = { __index = StateHandler }
Flick@244 1286
Flick@244 1287 function StateHandler:New( bar, opts )
Flick@244 1288 local self = setmetatable(
Flick@244 1289 {
Flick@244 1290 bar = bar
Flick@244 1291 },
Flick@244 1292 meta )
Flick@244 1293
Flick@244 1294 function self:GetName()
Flick@244 1295 return opts.name
Flick@244 1296 end
Flick@244 1297
Flick@244 1298 function self:SetName(name)
Flick@244 1299 opts.name = name
Flick@244 1300 end
Flick@244 1301
Flick@244 1302 function self:GetOrder()
Flick@244 1303 return opts.order
Flick@244 1304 end
Flick@244 1305
Flick@244 1306 -- get reference to states table: even if the bar
Flick@244 1307 -- name changes the states table ref won't
Flick@244 1308 self.states = tbuild(bar:GetConfig(), "states")
Flick@244 1309 self.state = tbuild(self.states, opts.name)
Flick@244 1310
Flick@244 1311 opts.order = self:GetRuleField("order")
Flick@244 1312 if opts.order == nil then
Flick@244 1313 -- add after the highest
Flick@244 1314 opts.order = 100
Flick@244 1315 for _, state in pairs(self.states) do
Flick@244 1316 local x = tonumber(tfetch(state, "rule", "order"))
Flick@244 1317 if x and x >= opts.order then
Flick@244 1318 opts.order = x + 1
Flick@244 1319 end
Flick@244 1320 end
Flick@244 1321 self:SetRuleField("order",opts.order)
Flick@244 1322 end
Flick@244 1323
Flick@244 1324 return self
Flick@244 1325 end
Flick@244 1326
Flick@244 1327 -- helper methods
Flick@244 1328
Flick@244 1329 function StateHandler:SetRuleField( key, value, ... )
Flick@244 1330 tbuild(self.state, "rule", ...)[key] = value
Flick@244 1331 end
Flick@244 1332
Flick@244 1333 function StateHandler:GetRuleField( ... )
Flick@244 1334 return tfetch(self.state, "rule", ...)
Flick@244 1335 end
Flick@244 1336
Flick@244 1337 function StateHandler:FixAll( setkey )
Flick@244 1338 -- if multiple selections in the same group are chosen when 'all' is selected,
Flick@244 1339 -- keep only one of them. If changing the mode, the first in the fields list will
Flick@244 1340 -- be chosen arbitrarily. Otherwise, if selecting a new checkbox from the field-set,
Flick@244 1341 -- it will be retained.
Flick@244 1342 local notified = false
Flick@244 1343 if self:GetRuleField("type") == "all" then
Flick@244 1344 for _, c in ipairs(rules) do
Flick@244 1345 local rule, fields = unpack(c)
Flick@244 1346 local once = false
Flick@244 1347 if setkey then
Flick@244 1348 for idx, field in ipairs(fields) do
Flick@244 1349 if next(field) == setkey then
Flick@244 1350 once = true
Flick@244 1351 end
Flick@244 1352 end
Flick@244 1353 end
Flick@244 1354 for idx, field in ipairs(fields) do
Flick@244 1355 local key = next(field)
Flick@244 1356 if self:GetRuleField("values",key) then
Flick@244 1357 if once and key ~= setkey then
Flick@244 1358 self:SetRuleField(key,false,"values")
Flick@244 1359 if not setkey and not notified then
Flick@244 1360 ReAction:UserError(L["Warning: one or more incompatible rules were turned off"])
Flick@244 1361 notified = true
Flick@244 1362 end
Flick@244 1363 end
Flick@244 1364 once = true
Flick@244 1365 end
Flick@244 1366 end
Flick@244 1367 end
Flick@244 1368 end
Flick@244 1369 end
Flick@244 1370
Flick@244 1371 function StateHandler:GetNeighbors()
Flick@244 1372 local before, after
Flick@244 1373 for k, v in pairs(self.states) do
Flick@244 1374 local o = tonumber(tfetch(v, "rule", "order"))
Flick@244 1375 if o and k ~= self:GetName() then
Flick@244 1376 local obefore = tfetch(self.states,before,"rule","order")
Flick@244 1377 local oafter = tfetch(self.states,after,"rule","order")
Flick@244 1378 if o < self:GetOrder() and (not obefore or obefore < o) then
Flick@244 1379 before = k
Flick@244 1380 end
Flick@244 1381 if o > self:GetOrder() and (not oafter or oafter > o) then
Flick@244 1382 after = k
Flick@244 1383 end
Flick@244 1384 end
Flick@244 1385 end
Flick@244 1386 return before, after
Flick@244 1387 end
Flick@244 1388
Flick@244 1389 function StateHandler:SwapOrder( a, b )
Flick@244 1390 -- do options table
Flick@244 1391 local args = optionMap[self.bar].args
Flick@244 1392 args[a].order, args[b].order = args[b].order, args[a].order
Flick@244 1393 -- do profile
Flick@244 1394 a = tbuild(self.states, a, "rule")
Flick@244 1395 b = tbuild(self.states, b, "rule")
Flick@244 1396 a.order, b.order = b.order, a.order
Flick@244 1397 end
Flick@244 1398
Flick@244 1399 -- handler methods
Flick@244 1400
Flick@244 1401 function StateHandler:GetProp( info )
Flick@244 1402 -- gets property of the same name as the options arg
Flick@244 1403 return GetProperty(self.bar, self:GetName(), info[#info])
Flick@244 1404 end
Flick@244 1405
Flick@244 1406 function StateHandler:SetProp( info, value )
Flick@244 1407 -- sets property of the same name as the options arg
Flick@244 1408 SetProperty(self.bar, self:GetName(), info[#info], value)
Flick@244 1409 end
Flick@244 1410
Flick@244 1411 function StateHandler:DeleteState()
Flick@244 1412 if self.states[self:GetName()] then
Flick@244 1413 self.states[self:GetName()] = nil
Flick@244 1414 ApplyStates(self.bar)
Flick@244 1415 end
Flick@244 1416 optionMap[self.bar].args[self:GetName()] = nil
Flick@244 1417 end
Flick@244 1418
Flick@244 1419 function StateHandler:SetStateName(info, value)
Flick@244 1420 -- check for existing state name
Flick@244 1421 if self.states[value] then
Flick@244 1422 ReAction:UserError(format(L["State named '%s' already exists"],value))
Flick@244 1423 return
Flick@244 1424 end
Flick@244 1425 local args = optionMap[self.bar].args
Flick@244 1426 local name = self:GetName()
Flick@244 1427 self.states[value], args[value], self.states[name], args[name] = self.states[name], args[name], nil, nil
Flick@244 1428 self:SetName(value)
Flick@244 1429 ApplyStates(self.bar)
Flick@244 1430 ReAction:ShowEditor(self.bar, moduleID, value)
Flick@244 1431 end
Flick@244 1432
Flick@244 1433 function StateHandler:MoveStateUp()
Flick@244 1434 local before, after = self:GetNeighbors()
Flick@244 1435 if before then
Flick@244 1436 self:SwapOrder(before, self:GetName())
Flick@244 1437 ApplyStates(self.bar)
Flick@244 1438 end
Flick@244 1439 end
Flick@244 1440
Flick@244 1441 function StateHandler:MoveStateDown()
Flick@244 1442 local before, after = self:GetNeighbors()
Flick@244 1443 if after then
Flick@244 1444 self:SwapOrder(self:GetName(), after)
Flick@244 1445 ApplyStates(self.bar)
Flick@244 1446 end
Flick@244 1447 end
Flick@244 1448
Flick@244 1449 function StateHandler:GetAnchorDisabled()
Flick@244 1450 return not GetProperty(self.bar, self:GetName(), "anchorEnable")
Flick@244 1451 end
Flick@244 1452
Flick@244 1453 function StateHandler:IsPageDisabled()
Flick@244 1454 local n = self.bar:GetConfig().nPages or 1
Flick@244 1455 return not (n > 1)
Flick@244 1456 end
Flick@244 1457
Flick@244 1458 function StateHandler:IsPageHidden()
Flick@244 1459 return not self.bar:GetConfig().nPages
Flick@244 1460 end
Flick@244 1461
Flick@244 1462 function StateHandler:GetPageValues()
Flick@244 1463 if not self._pagevalues then
Flick@244 1464 self._pagevalues = { }
Flick@244 1465 end
Flick@244 1466 local n = self.bar:GetConfig().nPages
Flick@244 1467 -- cache the results
Flick@244 1468 if self._npages ~= n then
Flick@244 1469 self._npages = n
Flick@244 1470 wipe(self._pagevalues)
Flick@244 1471 for i = 1, n do
Flick@244 1472 self._pagevalues["page"..i] = i
Flick@244 1473 end
Flick@244 1474 end
Flick@244 1475 return self._pagevalues
Flick@244 1476 end
Flick@244 1477
Flick@244 1478 function StateHandler:GetPage(info)
Flick@244 1479 return self:GetProp(info) or 1
Flick@244 1480 end
Flick@244 1481
Flick@244 1482 function StateHandler:GetAnchorFrames(info)
Flick@244 1483 self._anchorframes = self._anchorframes or { }
Flick@244 1484 table.wipe(self._anchorframes)
Flick@244 1485
Flick@244 1486 table.insert(self._anchorframes, "UIParent")
Flick@244 1487 for name, bar in ReAction:IterateBars() do
Flick@244 1488 table.insert(self._anchorframes, bar:GetFrame():GetName())
Flick@244 1489 end
Flick@244 1490 return self._anchorframes
Flick@244 1491 end
Flick@244 1492
Flick@244 1493 function StateHandler:GetAnchorFrame(info)
Flick@244 1494 local value = self:GetProp(info)
Flick@244 1495 for k,v in pairs(self._anchorframes) do
Flick@244 1496 if v == value then
Flick@244 1497 return k
Flick@244 1498 end
Flick@244 1499 end
Flick@244 1500 end
Flick@244 1501
Flick@244 1502 function StateHandler:SetAnchorFrame(info, value)
Flick@244 1503 local f = _G[self._anchorframes[value]]
Flick@244 1504 if f then
Flick@244 1505 self.bar:SetFrameRef("anchor-"..self:GetName(), f)
Flick@244 1506 self:SetProp(info, f:GetName())
Flick@244 1507 end
Flick@244 1508 end
Flick@244 1509
Flick@244 1510 function StateHandler:SetAnchorPointProp(info, value)
Flick@244 1511 self:SetProp(info, value ~= "NONE" and value or nil)
Flick@244 1512 end
Flick@244 1513
Flick@244 1514 function StateHandler:GetAnchorPointProp(info)
Flick@244 1515 return self:GetProp(info) or "NONE"
Flick@244 1516 end
Flick@244 1517
Flick@244 1518 function StateHandler:GetScale(info)
Flick@244 1519 return self:GetProp(info) or 1.0
Flick@244 1520 end
Flick@244 1521
Flick@244 1522 function StateHandler:GetScaleDisabled()
Flick@244 1523 return not GetProperty(self.bar, self:GetName(), "enableScale")
Flick@244 1524 end
Flick@244 1525
Flick@244 1526 function StateHandler:GetAlpha(info)
Flick@244 1527 return self:GetProp(info) or 1.0
Flick@244 1528 end
Flick@244 1529
Flick@244 1530 function StateHandler:GetAlphaDisabled()
Flick@244 1531 return not GetProperty(self.bar, self:GetName(), "enableAlpha")
Flick@244 1532 end
Flick@244 1533
Flick@244 1534 function StateHandler:SetType(info, value)
Flick@244 1535 self:SetRuleField("type", value)
Flick@244 1536 self:FixAll()
Flick@244 1537 ApplyStates(self.bar)
Flick@244 1538 end
Flick@244 1539
Flick@244 1540 function StateHandler:GetType()
Flick@244 1541 return self:GetRuleField("type")
Flick@244 1542 end
Flick@244 1543
Flick@244 1544 function StateHandler:GetClearAllDisabled()
Flick@244 1545 local t = self:GetRuleField("type")
Flick@244 1546 return not( t == "any" or t == "all" or t == "custom")
Flick@244 1547 end
Flick@244 1548
Flick@244 1549 function StateHandler:ClearAllConditions()
Flick@244 1550 local t = self:GetRuleField("type")
Flick@244 1551 if t == "custom" then
Flick@244 1552 self:SetRuleField("custom","")
Flick@244 1553 elseif t == "any" or t == "all" then
Flick@244 1554 self:SetRuleField("values", {})
Flick@244 1555 end
Flick@244 1556 ApplyStates(self.bar)
Flick@244 1557 end
Flick@244 1558
Flick@244 1559 function StateHandler:GetConditionsDisabled()
Flick@244 1560 local t = self:GetRuleField("type")
Flick@244 1561 return not( t == "any" or t == "all")
Flick@244 1562 end
Flick@244 1563
Flick@244 1564 function StateHandler:SetCondition(info, key, value)
Flick@244 1565 self:SetRuleField(ruleMap[key], value or nil, "values")
Flick@244 1566 if value then
Flick@244 1567 self:FixAll(ruleMap[key])
Flick@244 1568 end
Flick@244 1569 ApplyStates(self.bar)
Flick@244 1570 end
Flick@244 1571
Flick@244 1572 function StateHandler:GetCondition(info, key)
Flick@244 1573 return self:GetRuleField("values", ruleMap[key]) or false
Flick@244 1574 end
Flick@244 1575
Flick@244 1576 function StateHandler:GetCustomDisabled()
Flick@244 1577 return self:GetRuleField("type") ~= "custom"
Flick@244 1578 end
Flick@244 1579
Flick@244 1580 function StateHandler:SetCustomRule(info, value)
Flick@244 1581 self:SetRuleField("custom",value)
Flick@244 1582 ApplyStates(self.bar)
Flick@244 1583 end
Flick@244 1584
Flick@244 1585 function StateHandler:GetCustomRule()
Flick@244 1586 return self:GetRuleField("custom") or ""
Flick@244 1587 end
Flick@244 1588
Flick@244 1589 function StateHandler:ValidateCustomRule(info, value)
Flick@244 1590 local s = value:gsub("%s","") -- remove all spaces
Flick@244 1591 -- unfortunately %b and captures don't support the '+' notation, or this would be considerably simpler
Flick@244 1592 repeat
Flick@244 1593 if s == "" then
Flick@244 1594 return true
Flick@244 1595 end
Flick@244 1596 local c, r = s:match("(%b[])(.*)")
Flick@244 1597 if c == nil and s and #s > 0 then
Flick@244 1598 return format(L["Invalid custom rule '%s': each clause must appear within [brackets]"],value or "")
Flick@244 1599 end
Flick@244 1600 s = r
Flick@244 1601 until c == nil
Flick@244 1602 return true
Flick@244 1603 end
Flick@244 1604
Flick@244 1605 function StateHandler:GetKeybindDisabled()
Flick@244 1606 return self:GetRuleField("type") ~= "keybind"
Flick@244 1607 end
Flick@244 1608
Flick@244 1609 function StateHandler:GetKeybind()
Flick@244 1610 return self:GetRuleField("keybind")
Flick@244 1611 end
Flick@244 1612
Flick@244 1613 function StateHandler:SetKeybind(info, value)
Flick@244 1614 if value and #value == 0 then
Flick@244 1615 value = nil
Flick@244 1616 end
Flick@244 1617 self:SetRuleField("keybind",value)
Flick@244 1618 ApplyStates(self.bar)
Flick@244 1619 end
Flick@244 1620
Flick@244 1621 local function CreateStateOptions(bar, name)
Flick@244 1622 local opts = {
Flick@244 1623 type = "group",
Flick@244 1624 name = name,
Flick@244 1625 childGroups = "tab",
Flick@244 1626 args = stateOptions
Flick@244 1627 }
Flick@244 1628
Flick@244 1629 opts.handler = StateHandler:New(bar,opts)
Flick@244 1630
Flick@244 1631 return opts
Flick@244 1632 end
Flick@244 1633
Flick@244 1634 function Editor:CreateStateOptions(bar)
Flick@244 1635 local private = { }
Flick@244 1636 local states = tbuild(bar:GetConfig(), "states")
Flick@244 1637 local options = {
Flick@244 1638 name = L["Dynamic State"],
Flick@244 1639 type = "group",
Flick@244 1640 order = -1,
Flick@244 1641 childGroups = "tree",
Flick@244 1642 disabled = InCombatLockdown,
Flick@244 1643 args = {
Flick@244 1644 __desc__ = {
Flick@244 1645 name = L["States are evaluated in the order they are listed"],
Flick@244 1646 order = 1,
Flick@244 1647 type = "description",
Flick@244 1648 },
Flick@244 1649 __new__ = {
Flick@244 1650 name = L["New State..."],
Flick@244 1651 order = 2,
Flick@244 1652 type = "group",
Flick@244 1653 args = {
Flick@244 1654 name = {
Flick@244 1655 name = L["State Name"],
Flick@244 1656 desc = L["Set a name for the new state"],
Flick@244 1657 order = 1,
Flick@244 1658 type = "input",
Flick@244 1659 get = function() return private.newstatename or "" end,
Flick@244 1660 set = function(info,value) private.newstatename = value end,
Flick@244 1661 pattern = "^%w*$",
Flick@244 1662 usage = L["State names must be alphanumeric without spaces"],
Flick@244 1663 },
Flick@244 1664 create = {
Flick@244 1665 name = L["Create State"],
Flick@244 1666 order = 2,
Flick@244 1667 type = "execute",
Flick@244 1668 func = function ()
Flick@244 1669 local name = private.newstatename
Flick@244 1670 if states[name] then
Flick@244 1671 ReAction:UserError(format(L["State named '%s' already exists"],name))
Flick@244 1672 else
Flick@244 1673 -- TODO: select default state options and pass as final argument
Flick@244 1674 states[name] = { }
Flick@244 1675 optionMap[bar].args[name] = CreateStateOptions(bar,name)
Flick@244 1676 ReAction:ShowEditor(bar, moduleID, name)
Flick@244 1677 private.newstatename = ""
Flick@244 1678 end
Flick@244 1679 end,
Flick@244 1680 disabled = function()
Flick@244 1681 local name = private.newstatename or ""
Flick@244 1682 return #name == 0 or name:find("%W")
Flick@244 1683 end,
Flick@244 1684 }
Flick@244 1685 }
Flick@244 1686 }
Flick@244 1687 }
Flick@244 1688 }
Flick@244 1689 for name, config in pairs(states) do
Flick@244 1690 options.args[name] = CreateStateOptions(bar,name)
Flick@244 1691 end
Flick@244 1692 optionMap[bar] = options
Flick@244 1693 return options
Flick@244 1694 end
Flick@244 1695 end
Flick@244 1696
flickerstreak@185 1697
flickerstreak@185 1698 ---- Export to ReAction ----
flickerstreak@185 1699 function ReAction:ShowEditor(bar, ...)
flickerstreak@185 1700 if InCombatLockdown() then
flickerstreak@185 1701 self:UserError(L["ReAction config mode disabled during combat."])
flickerstreak@185 1702 else
flickerstreak@185 1703 self.editor = self.editor or Editor:New()
flickerstreak@185 1704 self.editor:Open(bar, ...)
flickerstreak@185 1705 self:SetConfigMode(true)
flickerstreak@185 1706 end
flickerstreak@185 1707 end
flickerstreak@185 1708
flickerstreak@185 1709 function ReAction:CloseEditor()
flickerstreak@185 1710 if self.editor then
flickerstreak@185 1711 self.editor:Close()
flickerstreak@185 1712 end
flickerstreak@185 1713 end
flickerstreak@185 1714
flickerstreak@185 1715 function ReAction:RefreshEditor()
flickerstreak@185 1716 if self.editor then
flickerstreak@185 1717 self.editor:RefreshBarOptions()
flickerstreak@185 1718 end
flickerstreak@185 1719 end
flickerstreak@185 1720