annotate Editor.lua @ 275:4957aeb0d3a4

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