annotate Editor.lua @ 244:f255cd69e890

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