annotate Editor.lua @ 261:5694618cef7f

Make Activate On Down apply immediately rather than on next load
author Flick
date Fri, 06 May 2011 15:49:02 -0700
parents c918ff9ac787
children c27596828276
rev   line source
flickerstreak@175 1 local addonName, addonTable = ...
flickerstreak@175 2 local ReAction = addonTable.ReAction
flickerstreak@109 3 local L = ReAction.L
flickerstreak@109 4 local _G = _G
flickerstreak@185 5 local wipe = wipe
Flick@244 6 local format = string.format
Flick@244 7 local InCombatLockdown = InCombatLockdown
Flick@244 8 local tfetch = addonTable.tfetch
Flick@244 9 local tbuild = addonTable.tbuild
flickerstreak@185 10
flickerstreak@109 11 local AceConfigReg = LibStub("AceConfigRegistry-3.0")
flickerstreak@109 12 local AceConfigDialog = LibStub("AceConfigDialog-3.0")
flickerstreak@109 13
flickerstreak@109 14
flickerstreak@185 15 local pointTable = {
Flick@244 16 NONE = " ",
flickerstreak@185 17 CENTER = L["Center"],
flickerstreak@185 18 LEFT = L["Left"],
flickerstreak@185 19 RIGHT = L["Right"],
flickerstreak@185 20 TOP = L["Top"],
flickerstreak@185 21 BOTTOM = L["Bottom"],
flickerstreak@185 22 TOPLEFT = L["Top Left"],
flickerstreak@185 23 TOPRIGHT = L["Top Right"],
flickerstreak@185 24 BOTTOMLEFT = L["Bottom Left"],
flickerstreak@185 25 BOTTOMRIGHT = L["Bottom Right"],
flickerstreak@185 26 }
flickerstreak@109 27
Flick@237 28 local Editor = {
Flick@237 29 buttonHandlers = { }
Flick@237 30 }
flickerstreak@109 31
flickerstreak@185 32 function Editor:New()
flickerstreak@185 33 -- create new self
flickerstreak@185 34 self = setmetatable( { }, { __index = self } )
flickerstreak@109 35
flickerstreak@185 36 self.barOptMap = setmetatable({},{__mode="v"})
flickerstreak@185 37 self.tmp = { }
flickerstreak@185 38 self.configID = "ReAction-Editor"
flickerstreak@109 39
flickerstreak@185 40 self.gui = LibStub("AceGUI-3.0"):Create("Frame")
flickerstreak@185 41
flickerstreak@185 42 local frame = self.gui.frame
flickerstreak@109 43 frame:SetClampedToScreen(true)
flickerstreak@109 44 frame:Hide()
flickerstreak@185 45
flickerstreak@195 46 self.title = ("%s - %s"):format(L["ReAction"],L["Bar Editor"])
flickerstreak@195 47 self.gui:SetTitle(self.title)
flickerstreak@195 48
flickerstreak@185 49 self.options = {
flickerstreak@109 50 type = "group",
flickerstreak@195 51 name = self.title,
flickerstreak@185 52 handler = self,
flickerstreak@185 53 childGroups = "select",
flickerstreak@109 54 args = {
flickerstreak@109 55 launchConfig = {
flickerstreak@109 56 type = "execute",
flickerstreak@109 57 name = L["Global Config"],
flickerstreak@109 58 desc = L["Opens ReAction global configuration settings panel"],
Flick@250 59 func = function()
Flick@250 60 -- AceConfigDialog calls :Open() after every selection, making it
Flick@250 61 -- generally not possible to cleanly close from a menu item.
Flick@250 62 -- If you don't use a custom frame, you can use ACD:Close(), but since
Flick@250 63 -- we're using a custom frame, we have to do the work of closing later in an
Flick@250 64 -- OnUpdate script.
Flick@250 65 ReAction:ShowOptions();
Flick@250 66 frame:SetScript("OnUpdate",
Flick@250 67 function()
Flick@250 68 self:Close()
Flick@250 69 frame:SetScript("OnUpdate",nil)
Flick@250 70 end)
Flick@250 71 end,
flickerstreak@185 72 order = 1
flickerstreak@109 73 },
flickerstreak@185 74 desc = {
flickerstreak@185 75 type = "description",
flickerstreak@185 76 name = L["Use the mouse to arrange and resize the bars on screen. Tooltips on bars indicate additional functionality."],
flickerstreak@195 77 order = 2,
flickerstreak@195 78 },
flickerstreak@195 79 hdr = {
flickerstreak@195 80 type = "header",
flickerstreak@195 81 name = L["Select Bar"],
flickerstreak@194 82 order = 3,
flickerstreak@185 83 },
flickerstreak@185 84 _new = {
flickerstreak@109 85 type = "group",
flickerstreak@109 86 name = L["New Bar..."],
flickerstreak@194 87 order = 4,
flickerstreak@109 88 args = {
flickerstreak@109 89 desc = {
flickerstreak@109 90 type = "description",
flickerstreak@109 91 name = L["Choose a name, type, and initial grid for your new action bar:"],
flickerstreak@109 92 order = 1,
flickerstreak@109 93 },
flickerstreak@109 94 name = {
flickerstreak@109 95 type = "input",
flickerstreak@109 96 name = L["Bar Name"],
flickerstreak@109 97 desc = L["Enter a name for your new action bar"],
flickerstreak@185 98 get = function() return self.tmp.barName or "" end,
flickerstreak@185 99 set = function(info, val) self.tmp.barName = val end,
flickerstreak@109 100 order = 2,
flickerstreak@109 101 },
flickerstreak@109 102 type = {
flickerstreak@109 103 type = "select",
flickerstreak@109 104 name = L["Button Type"],
flickerstreak@185 105 get = function() return self.tmp.barType or ReAction:GetDefaultBarType() or "" end,
flickerstreak@109 106 set = function(info, val)
flickerstreak@218 107 local c = ReAction:GetDefaultBarConfig(val)
flickerstreak@185 108 self.tmp.barType = val
flickerstreak@218 109 self.tmp.barSize = c.btnWidth or self.tmp.barSize
flickerstreak@218 110 self.tmp.barRows = c.btnRows or self.tmp.barRows
flickerstreak@218 111 self.tmp.barCols = c.btnColumns or self.tmp.barCols
flickerstreak@218 112 self.tmp.barSpacing = c.spacing or self.tmp.barSpacing
flickerstreak@109 113 end,
flickerstreak@109 114 values = "GetBarTypes",
flickerstreak@109 115 order = 3,
flickerstreak@109 116 },
flickerstreak@185 117 go = {
flickerstreak@185 118 type = "execute",
flickerstreak@185 119 name = L["Create Bar"],
flickerstreak@185 120 func = "CreateBar",
flickerstreak@185 121 order = 4,
flickerstreak@185 122 },
flickerstreak@109 123 grid = {
flickerstreak@109 124 type = "group",
flickerstreak@109 125 name = L["Button Grid"],
flickerstreak@109 126 inline = true,
flickerstreak@185 127 order = 5,
flickerstreak@109 128 args = {
flickerstreak@109 129 rows = {
flickerstreak@109 130 type = "range",
flickerstreak@109 131 name = L["Rows"],
flickerstreak@185 132 get = function() return self.tmp.barRows or 1 end,
flickerstreak@185 133 set = function(info, val) self.tmp.barRows = val end,
flickerstreak@185 134 width = "full",
flickerstreak@109 135 min = 1,
flickerstreak@109 136 max = 32,
flickerstreak@109 137 step = 1,
flickerstreak@109 138 order = 2,
flickerstreak@109 139 },
flickerstreak@109 140 cols = {
flickerstreak@109 141 type = "range",
flickerstreak@109 142 name = L["Columns"],
flickerstreak@185 143 get = function() return self.tmp.barCols or 12 end,
flickerstreak@185 144 set = function(info, val) self.tmp.barCols = val end,
flickerstreak@185 145 width = "full",
flickerstreak@109 146 min = 1,
flickerstreak@109 147 max = 32,
flickerstreak@109 148 step = 1,
flickerstreak@109 149 order = 3,
flickerstreak@109 150 },
flickerstreak@109 151 sz = {
flickerstreak@109 152 type = "range",
flickerstreak@109 153 name = L["Size"],
flickerstreak@185 154 get = function() return self.tmp.barSize or 36 end,
flickerstreak@185 155 set = function(info, val) self.tmp.barSize = val end,
flickerstreak@185 156 width = "full",
flickerstreak@109 157 min = 10,
flickerstreak@109 158 max = 72,
flickerstreak@109 159 step = 1,
flickerstreak@109 160 order = 4,
flickerstreak@109 161 },
flickerstreak@109 162 spacing = {
flickerstreak@109 163 type = "range",
flickerstreak@109 164 name = L["Spacing"],
flickerstreak@185 165 get = function() return self.tmp.barSpacing or 3 end,
flickerstreak@185 166 set = function(info, val) self.tmp.barSpacing = val end,
flickerstreak@185 167 width = "full",
flickerstreak@109 168 min = 0,
flickerstreak@109 169 max = 24,
flickerstreak@109 170 step = 1,
flickerstreak@109 171 order = 5,
flickerstreak@109 172 }
flickerstreak@195 173 }
flickerstreak@195 174 }
flickerstreak@109 175 }
flickerstreak@109 176 }
flickerstreak@195 177 }
flickerstreak@109 178 }
flickerstreak@109 179
flickerstreak@185 180 self.gui:SetCallback("OnClose",
flickerstreak@185 181 function()
flickerstreak@185 182 ReAction:SetConfigMode(false)
flickerstreak@185 183 end )
flickerstreak@185 184
flickerstreak@185 185 AceConfigReg:RegisterOptionsTable(self.configID, self.options)
flickerstreak@185 186 AceConfigDialog:SetDefaultSize(self.configID, 700, 540)
flickerstreak@185 187
flickerstreak@185 188 ReAction.RegisterCallback(self,"OnCreateBar")
flickerstreak@185 189 ReAction.RegisterCallback(self,"OnDestroyBar")
flickerstreak@185 190 ReAction.RegisterCallback(self,"OnRenameBar")
flickerstreak@185 191
flickerstreak@216 192 self:RefreshBarOptions()
flickerstreak@109 193
flickerstreak@185 194 return self
flickerstreak@109 195 end
flickerstreak@109 196
flickerstreak@109 197
flickerstreak@185 198 function Editor:Open(bar, ...)
flickerstreak@185 199 if bar then
flickerstreak@185 200 AceConfigDialog:SelectGroup(self.configID, self.barOptMap[bar:GetName()], ...)
flickerstreak@185 201 end
flickerstreak@185 202 AceConfigDialog:Open(self.configID,self.gui)
flickerstreak@185 203 self.gui:SetTitle(self.title)
flickerstreak@185 204 end
flickerstreak@185 205
flickerstreak@185 206 function Editor:Close()
flickerstreak@185 207 if self.gui then
flickerstreak@185 208 self.gui:ReleaseChildren()
flickerstreak@185 209 self.gui:Hide()
flickerstreak@109 210 end
flickerstreak@109 211 end
flickerstreak@109 212
flickerstreak@185 213 function Editor:Refresh()
flickerstreak@185 214 AceConfigReg:NotifyChange(self.configID)
flickerstreak@185 215 end
flickerstreak@185 216
flickerstreak@216 217 function Editor:UpdateBarOptions(bar)
flickerstreak@185 218 local name = bar:GetName()
flickerstreak@216 219 local key = self.barOptMap[name]
flickerstreak@185 220 local args = self.options.args
flickerstreak@216 221
flickerstreak@216 222 if not key then
flickerstreak@216 223 -- AceConfig doesn't allow spaces, etc, in arg key names, and they must be
flickerstreak@216 224 -- unique strings. So generate a unique key (it can be whatever) for the bar
flickerstreak@216 225 local i = 1
flickerstreak@216 226 repeat
flickerstreak@216 227 key = ("bar%s"):format(i)
flickerstreak@216 228 i = i+1
flickerstreak@216 229 until args[key] == nil
flickerstreak@216 230 self.barOptMap[name] = key
flickerstreak@216 231
flickerstreak@216 232 args[key] = {
flickerstreak@216 233 type = "group",
flickerstreak@216 234 name = name,
flickerstreak@216 235 childGroups = "tab",
flickerstreak@216 236 order = i+100,
flickerstreak@216 237 args = {
flickerstreak@216 238 general = {
flickerstreak@216 239 type = "group",
flickerstreak@216 240 name = L["General"],
flickerstreak@216 241 order = 1,
flickerstreak@216 242 args = {
flickerstreak@216 243 name = {
flickerstreak@216 244 type = "input",
flickerstreak@216 245 name = L["Rename Bar"],
flickerstreak@216 246 get = function() return bar:GetName() end,
flickerstreak@216 247 set = function(info, value) return ReAction:RenameBar(bar, value) end,
flickerstreak@216 248 order = 1,
flickerstreak@216 249 },
flickerstreak@216 250 delete = {
flickerstreak@216 251 type = "execute",
flickerstreak@216 252 name = L["Delete Bar"],
flickerstreak@216 253 desc = function() return bar:GetName() end,
flickerstreak@216 254 confirm = true,
flickerstreak@216 255 func = function() ReAction:EraseBar(bar) end,
flickerstreak@216 256 order = 2
flickerstreak@216 257 },
Flick@259 258 clickDown = {
Flick@259 259 type = "toggle",
Flick@259 260 name = L["Activate on Down"],
Flick@259 261 desc = L["Activate the button when the key or mouse button is pressed down instead of when it is released"],
Flick@259 262 order = 3,
Flick@261 263 set = function(info, value) bar:GetConfig().clickDown = value; ReAction:RebuildAll() end,
Flick@259 264 get = function() return bar:GetConfig().clickDown end,
Flick@259 265 },
flickerstreak@216 266 anchor = {
flickerstreak@216 267 type = "group",
flickerstreak@216 268 name = L["Anchor"],
flickerstreak@216 269 inline = true,
Flick@259 270 order = 4,
flickerstreak@216 271 args = {
flickerstreak@216 272 frame = {
flickerstreak@216 273 type = "input",
flickerstreak@216 274 name = L["Frame"],
flickerstreak@216 275 desc = L["The frame that the bar is anchored to"],
flickerstreak@216 276 get = function() local _, f = bar:GetAnchor(); return f end,
flickerstreak@216 277 set = function(info, val) bar:SetAnchor(nil,val) end,
flickerstreak@216 278 validate = function(info, name)
flickerstreak@216 279 if name then
flickerstreak@216 280 local f = ReAction:GetBar(name)
flickerstreak@216 281 if f then
flickerstreak@216 282 return true
flickerstreak@216 283 else
flickerstreak@216 284 f = _G[name]
flickerstreak@216 285 if f and type(f) == "table" and f.IsObjectType and f:IsObjectType("Frame") then
flickerstreak@216 286 local _, explicit = f:IsProtected()
flickerstreak@216 287 return explicit
flickerstreak@216 288 end
flickerstreak@185 289 end
flickerstreak@185 290 end
flickerstreak@216 291 return false
flickerstreak@216 292 end,
flickerstreak@216 293 width = "double",
flickerstreak@216 294 order = 1
flickerstreak@216 295 },
flickerstreak@216 296 point = {
flickerstreak@216 297 type = "select",
flickerstreak@216 298 name = L["Point"],
flickerstreak@216 299 desc = L["Anchor point on the bar frame"],
flickerstreak@216 300 style = "dropdown",
flickerstreak@216 301 get = function() return bar:GetAnchor() end,
flickerstreak@216 302 set = function(info, val) bar:SetAnchor(val) end,
flickerstreak@216 303 values = pointTable,
flickerstreak@216 304 order = 2,
flickerstreak@216 305 },
flickerstreak@216 306 relativePoint = {
flickerstreak@216 307 type = "select",
flickerstreak@216 308 name = L["Relative Point"],
flickerstreak@216 309 desc = L["Anchor point on the target frame"],
flickerstreak@216 310 style = "dropdown",
flickerstreak@216 311 get = function() local p,f,r = bar:GetAnchor(); return r end,
flickerstreak@216 312 set = function(info, val) bar:SetAnchor(nil,nil,val) end,
flickerstreak@216 313 values = pointTable,
flickerstreak@216 314 order = 3,
flickerstreak@216 315 },
flickerstreak@216 316 x = {
flickerstreak@216 317 type = "input",
flickerstreak@216 318 pattern = "\-?%d+",
flickerstreak@216 319 name = L["X offset"],
flickerstreak@216 320 get = function() local p,f,r,x = bar:GetAnchor(); return ("%d"):format(x) end,
flickerstreak@216 321 set = function(info,val) bar:SetAnchor(nil,nil,nil,val) end,
flickerstreak@216 322 order = 4
flickerstreak@216 323 },
flickerstreak@216 324 y = {
flickerstreak@216 325 type = "input",
flickerstreak@216 326 pattern = "\-?%d+",
flickerstreak@216 327 name = L["Y offset"],
flickerstreak@216 328 get = function() local p,f,r,x,y = bar:GetAnchor(); return ("%d"):format(y) end,
flickerstreak@216 329 set = function(info,val) bar:SetAnchor(nil,nil,nil,nil,val) end,
flickerstreak@216 330 order = 5
flickerstreak@216 331 },
flickerstreak@185 332 },
flickerstreak@185 333 },
flickerstreak@216 334 alpha = {
flickerstreak@216 335 type = "range",
flickerstreak@216 336 name = L["Transparency"],
flickerstreak@216 337 get = function() return bar:GetAlpha() end,
flickerstreak@216 338 set = function(info, val) bar:SetAlpha(val) end,
flickerstreak@216 339 min = 0,
flickerstreak@216 340 max = 1,
flickerstreak@216 341 isPercent = true,
flickerstreak@216 342 step = 0.01,
flickerstreak@216 343 bigStep = 0.05,
flickerstreak@216 344 order = 4,
flickerstreak@216 345 },
flickerstreak@185 346 },
flickerstreak@185 347 },
Flick@244 348 buttonOpts = self:CreateButtonOptions(bar),
Flick@244 349 stateOpts = self:CreateStateOptions(bar)
Flick@244 350 }
flickerstreak@185 351 }
flickerstreak@216 352 end
flickerstreak@216 353
flickerstreak@185 354 end
flickerstreak@185 355
Flick@237 356 function Editor:CreateButtonOptions(bar)
Flick@237 357 local buttonClass = bar:GetButtonClass()
Flick@237 358 local classID = buttonClass:GetButtonTypeID()
Flick@237 359 local handler = self.buttonHandlers[classID]
Flick@237 360
Flick@237 361 if handler then
Flick@237 362 local h = handler:New(bar)
Flick@237 363 return h:GetOptions()
Flick@237 364 end
Flick@237 365 end
Flick@237 366
flickerstreak@185 367 function Editor:RefreshBarOptions()
flickerstreak@219 368 for name, key in pairs(self.barOptMap) do
flickerstreak@216 369 if not ReAction:GetBar(name) then
flickerstreak@219 370 self.barOptMap[name] = nil
flickerstreak@219 371 self.options.args[key] = nil
flickerstreak@185 372 end
flickerstreak@185 373 end
flickerstreak@216 374 for name, bar in ReAction:IterateBars() do
flickerstreak@216 375 self:UpdateBarOptions(bar)
flickerstreak@216 376 end
flickerstreak@216 377 self:Refresh()
flickerstreak@185 378 end
flickerstreak@185 379
flickerstreak@185 380 function Editor:OnCreateBar(evt, bar)
flickerstreak@216 381 self:UpdateBarOptions(bar)
flickerstreak@216 382 self:Refresh()
flickerstreak@185 383 end
flickerstreak@185 384
flickerstreak@185 385 function Editor:OnDestroyBar(evt, bar, name)
flickerstreak@185 386 local key = self.barOptMap[name]
flickerstreak@185 387 if key then
flickerstreak@216 388 self.barOptMap[name] = nil
flickerstreak@185 389 self.options.args[key] = nil
flickerstreak@185 390 self:Refresh()
flickerstreak@185 391 end
flickerstreak@185 392 end
flickerstreak@185 393
flickerstreak@185 394 function Editor:OnRenameBar(evt, bar, oldname, newname)
flickerstreak@185 395 local key = self.barOptMap[oldname]
flickerstreak@185 396 if key then
flickerstreak@216 397 self.barOptMap[oldname], self.barOptMap[newname] = nil, key
flickerstreak@185 398 self.options.args[key].name = newname
flickerstreak@185 399 self:Refresh()
flickerstreak@185 400 end
flickerstreak@185 401 end
flickerstreak@185 402
flickerstreak@185 403 local _scratch = { }
flickerstreak@185 404 function Editor:GetBarTypes()
flickerstreak@185 405 wipe(_scratch)
flickerstreak@185 406 return ReAction:GetBarTypeOptions(_scratch)
flickerstreak@185 407 end
flickerstreak@185 408
flickerstreak@185 409 function Editor:CreateBar()
flickerstreak@185 410 if self.tmp.barName and self.tmp.barName ~= "" then
flickerstreak@185 411 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 412 if bar then
flickerstreak@185 413 AceConfigDialog:SelectGroup(self.configID, self.barOptMap[self.tmp.barName])
flickerstreak@185 414 self.tmp.barName = nil
flickerstreak@185 415 end
flickerstreak@185 416 end
flickerstreak@185 417 end
flickerstreak@185 418
Flick@237 419 -------------------------------
Flick@237 420 ---- Action button handler ----
Flick@237 421 -------------------------------
Flick@237 422
Flick@237 423 do
Flick@237 424 local ActionHandler = {
Flick@237 425 buttonClass = ReAction.Button.Action,
Flick@237 426 options = {
Flick@237 427 hideEmpty = {
Flick@237 428 name = L["Hide Empty Buttons"],
Flick@237 429 order = 1,
Flick@237 430 type = "toggle",
Flick@237 431 width = "double",
Flick@237 432 get = "GetHideEmpty",
Flick@237 433 set = "SetHideEmpty",
Flick@237 434 },
Flick@237 435 lockButtons = {
Flick@237 436 name = L["Lock Buttons"],
Flick@237 437 desc = L["Prevents picking up/dragging actions (use SHIFT to override this behavior)"],
Flick@237 438 order = 2,
Flick@237 439 type = "toggle",
Flick@237 440 get = "GetLockButtons",
Flick@237 441 set = "SetLockButtons",
Flick@237 442 },
Flick@237 443 lockOnlyCombat = {
Flick@237 444 name = L["Only in Combat"],
Flick@237 445 desc = L["Only lock the buttons when in combat"],
Flick@237 446 order = 3,
Flick@237 447 type = "toggle",
Flick@237 448 disabled = "LockButtonsCombatDisabled",
Flick@237 449 get = "GetLockButtonsCombat",
Flick@237 450 set = "SetLockButtonsCombat",
Flick@237 451 },
Flick@237 452 pages = {
Flick@237 453 name = L["# Pages"],
Flick@237 454 desc = L["Use the Dynamic State tab to specify page transitions"],
Flick@237 455 order = 4,
Flick@237 456 type = "range",
Flick@237 457 min = 1,
Flick@237 458 max = 10,
Flick@237 459 step = 1,
Flick@237 460 get = "GetNumPages",
Flick@237 461 set = "SetNumPages",
Flick@237 462 },
Flick@237 463 mindcontrol = {
Flick@237 464 name = L["Mind Control Support"],
Flick@237 465 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 466 order = 5,
Flick@237 467 type = "toggle",
Flick@237 468 width = "double",
Flick@237 469 set = "SetMindControl",
Flick@237 470 get = "GetMindControl",
Flick@237 471 },
Flick@237 472 vehicle = {
Flick@237 473 name = L["Vehicle Support"],
Flick@237 474 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 475 order = 6,
Flick@237 476 type = "toggle",
Flick@237 477 width = "double",
Flick@237 478 get = "GetVehicle",
Flick@237 479 set = "SetVehicle",
Flick@237 480 },
Flick@237 481 actions = {
Flick@237 482 name = L["Edit Action IDs"],
Flick@237 483 order = 7,
Flick@237 484 type = "group",
Flick@237 485 inline = true,
Flick@237 486 args = {
Flick@237 487 method = {
Flick@237 488 name = L["Assign"],
Flick@237 489 order = 1,
Flick@237 490 type = "select",
Flick@237 491 width = "double",
Flick@237 492 values = { [0] = L["Choose Method..."],
Flick@237 493 [1] = L["Individually"],
Flick@237 494 [2] = L["All at Once"], },
Flick@237 495 get = "GetActionEditMethod",
Flick@237 496 set = "SetActionEditMethod",
Flick@237 497 },
Flick@237 498 rowSelect = {
Flick@237 499 name = L["Row"],
Flick@237 500 desc = L["Rows are numbered top to bottom"],
Flick@237 501 order = 2,
Flick@237 502 type = "select",
Flick@237 503 width = "half",
Flick@237 504 hidden = "IsButtonSelectHidden",
Flick@237 505 values = "GetRowList",
Flick@237 506 get = "GetSelectedRow",
Flick@237 507 set = "SetSelectedRow",
Flick@237 508 },
Flick@237 509 colSelect = {
Flick@237 510 name = L["Col"],
Flick@237 511 desc = L["Columns are numbered left to right"],
Flick@237 512 order = 3,
Flick@237 513 type = "select",
Flick@237 514 width = "half",
Flick@237 515 hidden = "IsButtonSelectHidden",
Flick@237 516 values = "GetColumnList",
Flick@237 517 get = "GetSelectedColumn",
Flick@237 518 set = "SetSelectedColumn",
Flick@237 519 },
Flick@237 520 pageSelect = {
Flick@237 521 name = L["Page"],
Flick@237 522 order = 4,
Flick@237 523 type = "select",
Flick@237 524 width = "half",
Flick@237 525 hidden = "IsPageSelectHidden",
Flick@237 526 values = "GetPageList",
Flick@237 527 get = "GetSelectedPage",
Flick@237 528 set = "SetSelectedPage",
Flick@237 529 },
Flick@237 530 single = {
Flick@237 531 name = L["Action ID"],
Flick@237 532 usage = L["Specify ID 1-120"],
Flick@237 533 order = 5,
Flick@237 534 type = "input",
Flick@237 535 width = "half",
Flick@237 536 hidden = "IsButtonSelectHidden",
Flick@237 537 get = "GetActionID",
Flick@237 538 set = "SetActionID",
Flick@237 539 validate = "ValidateActionID",
Flick@237 540 },
Flick@237 541 multi = {
Flick@237 542 name = L["ID List"],
Flick@237 543 usage = L["Specify a comma-separated list of IDs for each button in the bar (in order). Separate multiple pages with semicolons (;)"],
Flick@237 544 order = 6,
Flick@237 545 type = "input",
Flick@237 546 multiline = true,
Flick@237 547 width = "double",
Flick@237 548 hidden = "IsMultiIDHidden",
Flick@237 549 get = "GetMultiID",
Flick@237 550 set = "SetMultiID",
Flick@237 551 validate = "ValidateMultiID",
Flick@237 552 },
Flick@237 553 },
Flick@237 554 },
Flick@237 555 }
Flick@237 556 }
Flick@237 557
Flick@237 558 Editor.buttonHandlers[ActionHandler.buttonClass:GetButtonTypeID()] = ActionHandler
Flick@237 559
Flick@237 560 local meta = { __index = ActionHandler }
Flick@237 561
Flick@237 562 function ActionHandler:New( bar )
Flick@237 563 return setmetatable(
Flick@237 564 {
Flick@237 565 bar = bar,
Flick@237 566 config = bar:GetConfig(),
Flick@237 567 },
Flick@237 568 meta)
Flick@237 569 end
Flick@237 570
Flick@237 571 function ActionHandler:Refresh()
Flick@237 572 self.buttonClass:SetupBar(self.bar)
Flick@237 573 end
Flick@237 574
Flick@237 575 function ActionHandler:UpdateButtonLock()
Flick@237 576 self.buttonClass:SetButtonLock(self.bar, self.config.lockButtons, self.config.lockButtonsCombat)
Flick@237 577 end
Flick@237 578
Flick@237 579 function ActionHandler:GetLastButton()
Flick@237 580 return self.bar:GetButton(self.bar:GetNumButtons())
Flick@237 581 end
Flick@237 582
Flick@237 583 -- options handlers
Flick@237 584 function ActionHandler:GetOptions()
Flick@237 585 return {
Flick@237 586 type = "group",
Flick@237 587 name = L["Action Buttons"],
Flick@237 588 handler = self,
Flick@237 589 order = 2,
Flick@237 590 args = self.options
Flick@237 591 }
Flick@237 592 end
Flick@237 593
Flick@237 594 function ActionHandler:SetHideEmpty(info, value)
Flick@237 595 if value ~= self.config.hideEmpty then
Flick@237 596 self.config.hideEmpty = value
Flick@237 597 for _, b in self.bar:IterateButtons() do
Flick@237 598 b:ShowGrid(not value)
Flick@237 599 end
Flick@237 600 end
Flick@237 601 end
Flick@237 602
Flick@237 603 function ActionHandler:GetHideEmpty()
Flick@237 604 return self.config.hideEmpty
Flick@237 605 end
Flick@237 606
Flick@237 607 function ActionHandler:GetLockButtons()
Flick@237 608 return self.config.lockButtons
Flick@237 609 end
Flick@237 610
Flick@237 611 function ActionHandler:SetLockButtons(info, value)
Flick@237 612 self.config.lockButtons = value
Flick@237 613 self:UpdateButtonLock()
Flick@237 614 end
Flick@237 615
Flick@237 616 function ActionHandler:GetLockButtonsCombat()
Flick@237 617 return self.config.lockButtonsCombat
Flick@237 618 end
Flick@237 619
Flick@237 620 function ActionHandler:SetLockButtonsCombat(info, value)
Flick@237 621 self.config.lockButtonsCombat = value
Flick@237 622 self:UpdateButtonLock()
Flick@237 623 end
Flick@237 624
Flick@237 625 function ActionHandler:LockButtonsCombatDisabled()
Flick@237 626 return not self.config.lockButtons
Flick@237 627 end
Flick@237 628
Flick@237 629 function ActionHandler:GetNumPages()
Flick@237 630 return self.config.nPages
Flick@237 631 end
Flick@237 632
Flick@237 633 function ActionHandler:SetNumPages(info, value)
Flick@237 634 self.config.nPages = value
Flick@237 635 self:Refresh()
Flick@237 636 end
Flick@237 637
Flick@237 638 function ActionHandler:GetMindControl()
Flick@237 639 return self.config.mindcontrol
Flick@237 640 end
Flick@237 641
Flick@237 642 function ActionHandler:SetMindControl(info, value)
Flick@237 643 self.config.mindcontrol = value
Flick@237 644 self:Refresh()
Flick@237 645 end
Flick@237 646
Flick@237 647 function ActionHandler:GetVehicle()
Flick@237 648 return self.config.vehicle
Flick@237 649 end
Flick@237 650
Flick@237 651 function ActionHandler:SetVehicle(info, value)
Flick@237 652 self.config.vehicle = value
Flick@237 653 self:Refresh()
Flick@237 654 end
Flick@237 655
Flick@237 656 function ActionHandler:GetActionEditMethod()
Flick@237 657 return self.editMethod or 0
Flick@237 658 end
Flick@237 659
Flick@237 660 function ActionHandler:SetActionEditMethod(info, value)
Flick@237 661 self.editMethod = value
Flick@237 662 end
Flick@237 663
Flick@237 664 function ActionHandler:IsButtonSelectHidden()
Flick@237 665 return self.editMethod ~= 1
Flick@237 666 end
Flick@237 667
Flick@237 668 function ActionHandler:GetRowList()
Flick@237 669 local r,c = self.bar:GetButtonGrid()
Flick@237 670 if self.rowList == nil or #self.rowList ~= r then
Flick@237 671 local list = { }
Flick@237 672 for i = 1, r do
Flick@237 673 table.insert(list,i)
Flick@237 674 end
Flick@237 675 self.rowList = list
Flick@237 676 end
Flick@237 677 return self.rowList
Flick@237 678 end
Flick@237 679
Flick@237 680 function ActionHandler:GetSelectedRow()
Flick@237 681 local r, c = self.bar:GetButtonGrid()
Flick@237 682 local row = self.selectedRow or 1
Flick@237 683 if row > r then
Flick@237 684 row = 1
Flick@237 685 end
Flick@237 686 self.selectedRow = row
Flick@237 687 return row
Flick@237 688 end
Flick@237 689
Flick@237 690 function ActionHandler:SetSelectedRow(info, value)
Flick@237 691 self.selectedRow = value
Flick@237 692 end
Flick@237 693
Flick@237 694 function ActionHandler:GetColumnList()
Flick@237 695 local r,c = self.bar:GetButtonGrid()
Flick@237 696 if self.columnList == nil or #self.columnList ~= c then
Flick@237 697 local list = { }
Flick@237 698 for i = 1, c do
Flick@237 699 table.insert(list,i)
Flick@237 700 end
Flick@237 701 self.columnList = list
Flick@237 702 end
Flick@237 703 return self.columnList
Flick@237 704 end
Flick@237 705
Flick@237 706 function ActionHandler:GetSelectedColumn()
Flick@237 707 local r, c = self.bar:GetButtonGrid()
Flick@237 708 local col = self.selectedColumn or 1
Flick@237 709 if col > c then
Flick@237 710 col = 1
Flick@237 711 end
Flick@237 712 self.selectedColumn = col
Flick@237 713 return col
Flick@237 714 end
Flick@237 715
Flick@237 716 function ActionHandler:SetSelectedColumn(info, value)
Flick@237 717 self.selectedColumn = value
Flick@237 718 end
Flick@237 719
Flick@237 720 function ActionHandler:IsPageSelectHidden()
Flick@237 721 return self.editMethod ~= 1 or (self.config.nPages or 1) < 2
Flick@237 722 end
Flick@237 723
Flick@237 724 function ActionHandler:GetPageList()
Flick@237 725 local n = self.config.nPages or 1
Flick@237 726 if self.pageList == nil or #self.pageList ~= n then
Flick@237 727 local p = { }
Flick@237 728 for i = 1, n do
Flick@237 729 table.insert(p,i)
Flick@237 730 end
Flick@237 731 self.pageList = p
Flick@237 732 end
Flick@237 733 return self.pageList
Flick@237 734 end
Flick@237 735
Flick@237 736 function ActionHandler:GetSelectedPage()
Flick@237 737 local p = self.selectedPage or 1
Flick@237 738 if p > (self.config.nPages or 1) then
Flick@237 739 p = 1
Flick@237 740 end
Flick@237 741 self.selectedPage = p
Flick@237 742 return p
Flick@237 743 end
Flick@237 744
Flick@237 745 function ActionHandler:SetSelectedPage(info, value)
Flick@237 746 self.selectedPage = value
Flick@237 747 end
Flick@237 748
Flick@237 749 function ActionHandler:GetActionID()
Flick@237 750 local row = self.selectedRow or 1
Flick@237 751 local col = self.selectedColumn or 1
Flick@237 752 local r, c = self.bar:GetButtonGrid()
Flick@237 753 local n = (row-1) * c + col
Flick@237 754 local btn = self.bar:GetButton(n)
Flick@237 755 if btn then
Flick@237 756 return tostring(btn:GetActionID(self.selectedPage or 1))
Flick@237 757 end
Flick@237 758 end
Flick@237 759
Flick@237 760 function ActionHandler:SetActionID(info, value)
Flick@237 761 local row = self.selectedRow or 1
Flick@237 762 local col = self.selectedColumn or 1
Flick@237 763 local r, c = self.bar:GetButtonGrid()
Flick@237 764 local n = (row-1) * c + col
Flick@237 765 local btn = self.bar:GetButton(n)
Flick@237 766 if btn then
Flick@237 767 btn:SetActionID(tonumber(value), self.selectedPage or 1)
Flick@237 768 end
Flick@237 769 end
Flick@237 770
Flick@237 771 function ActionHandler:ValidateActionID(info, value)
Flick@237 772 value = tonumber(value)
Flick@237 773 if value == nil or value < 1 or value > 120 then
Flick@237 774 return L["Specify ID 1-120"]
Flick@237 775 end
Flick@237 776 return true
Flick@237 777 end
Flick@237 778
Flick@237 779 function ActionHandler:IsMultiIDHidden()
Flick@237 780 return self.editMethod ~= 2
Flick@237 781 end
Flick@237 782
Flick@237 783 function ActionHandler:GetMultiID()
Flick@237 784 local p = { }
Flick@237 785 for i = 1, self.config.nPages or 1 do
Flick@237 786 local b = { }
Flick@237 787 for _, btn in self.bar:IterateButtons() do
Flick@237 788 table.insert(b, btn:GetActionID(i))
Flick@237 789 end
Flick@237 790 table.insert(p, table.concat(b,","))
Flick@237 791 end
Flick@237 792 return table.concat(p,";\n")
Flick@237 793 end
Flick@237 794
Flick@237 795
Flick@237 796 local function ParseMultiID(nBtns, nPages, s)
Flick@237 797 if s:match("[^%d%s,;]") then
Flick@237 798 return nil
Flick@237 799 end
Flick@237 800 local p = { }
Flick@237 801 for list in s:gmatch("[^;]+") do
Flick@237 802 local pattern = ("^%s?$"):format(("%s*(%d+)%s*,"):rep(nBtns))
Flick@237 803 local ids = { list:match(pattern) }
Flick@237 804 if #ids ~= nBtns then
Flick@237 805 return nil
Flick@237 806 end
Flick@237 807 table.insert(p,ids)
Flick@237 808 end
Flick@237 809 if #p ~= nPages then
Flick@237 810 return nil
Flick@237 811 end
Flick@237 812 return p
Flick@237 813 end
Flick@237 814
Flick@237 815 function ActionHandler:SetMultiID(info, value)
Flick@237 816 local p = ParseMultiID(self.bar:GetNumButtons(), self.config.nPages or 1, value)
Flick@237 817 for page, b in ipairs(p) do
Flick@237 818 for button, id in ipairs(b) do
Flick@237 819 self.bar:GetButton(button):SetActionID(id, page)
Flick@237 820 end
Flick@237 821 end
Flick@237 822 end
Flick@237 823
Flick@237 824 function ActionHandler:ValidateMultiID(info, value)
Flick@237 825 local bad = L["Invalid action ID list string"]
Flick@237 826 if value == nil or ParseMultiID(self.bar:GetNumButtons(), self.config.nPages or 1, value) == nil then
Flick@237 827 return bad
Flick@237 828 end
Flick@237 829 return true
Flick@237 830 end
Flick@237 831 end
Flick@237 832
Flick@237 833
Flick@237 834 ----------------------------------
Flick@237 835 ---- PetAction button handler ----
Flick@237 836 ----------------------------------
Flick@237 837
Flick@237 838 do
Flick@237 839 local PetHandler = {
Flick@237 840 buttonClass = ReAction.Button.PetAction,
Flick@237 841 }
Flick@237 842
Flick@237 843 Editor.buttonHandlers[PetHandler.buttonClass:GetButtonTypeID()] = PetHandler
Flick@237 844
Flick@237 845 local meta = { __index = PetHandler }
Flick@237 846
Flick@237 847 function PetHandler:New(bar)
Flick@237 848 return setmetatable(
Flick@237 849 {
Flick@237 850 bar = bar,
Flick@237 851 config = bar.config
Flick@237 852 }, meta)
Flick@237 853 end
Flick@237 854
Flick@237 855 function PetHandler:GetLockButtons()
Flick@237 856 return self.config.lockButtons
Flick@237 857 end
Flick@237 858
Flick@237 859 function PetHandler:SetLockButtons(info, value)
Flick@237 860 self.config.lockButtons = value
Flick@237 861 self.buttonClass:UpdateButtonLock(self.bar)
Flick@237 862 end
Flick@237 863
Flick@237 864 function PetHandler:GetLockButtonsCombat()
Flick@237 865 return self.config.lockButtonsCombat
Flick@237 866 end
Flick@237 867
Flick@237 868 function PetHandler:SetLockButtonsCombat(info, value)
Flick@237 869 self.config.lockButtonsCombat = value
Flick@237 870 self.buttonClass:UpdateButtonLock(self.bar)
Flick@237 871 end
Flick@237 872
Flick@237 873 function PetHandler:LockButtonsCombatDisabled()
Flick@237 874 return not self.config.lockButtons
Flick@237 875 end
Flick@237 876
Flick@237 877 function PetHandler:GetOptions()
Flick@237 878 return {
Flick@237 879 type = "group",
Flick@237 880 name = L["Pet Buttons"],
Flick@237 881 handler = self,
Flick@237 882 order = 2,
Flick@237 883 args = {
Flick@237 884 lockButtons = {
Flick@237 885 name = L["Lock Buttons"],
Flick@237 886 desc = L["Prevents picking up/dragging actions (use SHIFT to override this behavior)"],
Flick@237 887 order = 2,
Flick@237 888 type = "toggle",
Flick@237 889 get = "GetLockButtons",
Flick@237 890 set = "SetLockButtons",
Flick@237 891 },
Flick@237 892 lockOnlyCombat = {
Flick@237 893 name = L["Only in Combat"],
Flick@237 894 desc = L["Only lock the buttons when in combat"],
Flick@237 895 order = 3,
Flick@237 896 type = "toggle",
Flick@237 897 disabled = "LockButtonsCombatDisabled",
Flick@237 898 get = "GetLockButtonsCombat",
Flick@237 899 set = "SetLockButtonsCombat",
Flick@237 900 },
Flick@237 901 }
Flick@237 902 }
Flick@237 903 end
Flick@237 904 end
Flick@237 905
Flick@237 906
Flick@237 907 -------------------------------------
Flick@237 908 ---- Vehicle Exit button handler ----
Flick@237 909 -------------------------------------
Flick@237 910
Flick@237 911 do
Flick@237 912 local VExitHandler = {
Flick@237 913 buttonClass = ReAction.Button.VehicleExit,
Flick@237 914 }
Flick@237 915
Flick@237 916 Editor.buttonHandlers[VExitHandler.buttonClass:GetButtonTypeID()] = VExitHandler
Flick@237 917
Flick@237 918 local meta = { __index = VExitHandler }
Flick@237 919
Flick@237 920 function VExitHandler:New(bar)
Flick@237 921 return setmetatable(
Flick@237 922 {
Flick@237 923 bar = bar,
Flick@237 924 }, meta)
Flick@237 925 end
Flick@237 926
Flick@237 927 function VExitHandler:GetConfig()
Flick@237 928 return self.bar:GetConfig()
Flick@237 929 end
Flick@237 930
Flick@237 931 function VExitHandler:GetPassengerOnly()
Flick@237 932 return not self:GetConfig().withControls
Flick@237 933 end
Flick@237 934
Flick@237 935 function VExitHandler:SetPassengerOnly(info, value)
Flick@237 936 self:GetConfig().withControls = not value
Flick@237 937 self.buttonClass:UpdateRegistration(self.bar)
Flick@237 938 end
Flick@237 939
Flick@237 940
Flick@237 941 function VExitHandler:GetOptions()
Flick@237 942 return {
Flick@237 943 type = "group",
Flick@237 944 name = L["Exit Vehicle"],
Flick@237 945 handler = self,
Flick@237 946 args = {
Flick@237 947 passengerOnly = {
Flick@237 948 name = L["Show only when passenger"],
Flick@237 949 desc = L["Only show the button when riding as a passenger in a vehicle (no vehicle controls)"],
Flick@237 950 order = 2,
Flick@237 951 width = "double",
Flick@237 952 type = "toggle",
Flick@237 953 get = "GetPassengerOnly",
Flick@237 954 set = "SetPassengerOnly",
Flick@237 955 },
Flick@237 956 }
Flick@237 957 }
Flick@237 958 end
Flick@237 959 end
Flick@237 960
flickerstreak@185 961
Flick@244 962 ------------------------------
Flick@244 963 --- Dynamic State options ----
Flick@244 964 ------------------------------
Flick@244 965 do
Flick@244 966 local ApplyStates = ReAction.Bar.ApplyStates
Flick@244 967 local CleanupStates = ReAction.Bar.CleanupStates
Flick@244 968 local SetProperty = ReAction.Bar.SetStateProperty
Flick@244 969 local GetProperty = ReAction.Bar.GetStateProperty
Flick@244 970
Flick@244 971 -- pre-sorted by the order they should appear in
Flick@244 972 local rules = {
Flick@244 973 -- rule fields
Flick@244 974 { "stance", { {battle = L["Battle Stance"]}, {defensive = L["Defensive Stance"]}, {berserker = L["Berserker Stance"]} } },
Flick@244 975 { "form", { {caster = L["Caster Form"]}, {bear = L["Bear Form"]}, {cat = L["Cat Form"]}, {tree = L["Tree of Life"]}, {moonkin = L["Moonkin Form"]} } },
Flick@244 976 { "stealth", { {stealth = L["Stealth"]}, {nostealth = L["No Stealth"]}, {shadowdance = L["Shadow Dance"]} } },
Flick@244 977 { "shadow", { {shadowform = L["Shadowform"]}, {noshadowform = L["No Shadowform"]} } },
Flick@244 978 { "demon", { {demon = L["Demon Form"]}, {nodemon = L["No Demon Form"]} } },
Flick@244 979 { "pet", { {pet = L["With Pet"]}, {nopet = L["Without Pet"]} } },
Flick@244 980 { "target", { {harm = L["Hostile Target"]}, {help = L["Friendly Target"]}, {notarget = L["No Target"]} } },
Flick@244 981 { "focus", { {focusharm = L["Hostile Focus"]}, {focushelp = L["Friendly Focus"]}, {nofocus = L["No Focus"]} } },
Flick@244 982 { "possess", { {possess = L["Mind Control"]} } },
Flick@244 983 { "vehicle", { {vehicle = L["In a Vehicle"]} } },
Flick@244 984 { "group", { {raid = L["Raid"]}, {party = L["Party"]}, {solo = L["Solo"]} } },
Flick@244 985 { "combat", { {combat = L["In Combat"]}, {nocombat = L["Out of Combat"]} } },
Flick@244 986 }
Flick@244 987
Flick@244 988 local ruleSelect = { }
Flick@244 989 local ruleMap = { }
Flick@244 990 local optionMap = setmetatable({},{__mode="k"})
Flick@244 991
Flick@244 992
Flick@244 993 -- unpack rules table into ruleSelect and ruleMap
Flick@244 994 for _, c in ipairs(rules) do
Flick@244 995 local rule, fields = unpack(c)
Flick@244 996 for _, field in ipairs(fields) do
Flick@244 997 local key, label = next(field)
Flick@244 998 table.insert(ruleSelect, label)
Flick@244 999 table.insert(ruleMap, key)
Flick@244 1000 end
Flick@244 1001 end
Flick@244 1002
Flick@244 1003 local stateOptions = {
Flick@244 1004 ordering = {
Flick@244 1005 name = L["Info"],
Flick@244 1006 order = 1,
Flick@244 1007 type = "group",
Flick@244 1008 args = {
Flick@244 1009 delete = {
Flick@244 1010 name = L["Delete this State"],
Flick@244 1011 order = -1,
Flick@244 1012 type = "execute",
Flick@244 1013 func = "DeleteState",
Flick@244 1014 },
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@244 1024 ordering = {
Flick@244 1025 name = L["Evaluation Order"],
Flick@256 1026 desc = L["State transitions are evaluated in the order listed: Move a state up or down to change the order"],
Flick@244 1027 order = 2,
Flick@244 1028 type = "group",
Flick@244 1029 inline = true,
Flick@244 1030 args = {
Flick@244 1031 up = {
Flick@244 1032 name = L["Up"],
Flick@244 1033 order = 1,
Flick@244 1034 type = "execute",
Flick@244 1035 width = "half",
Flick@244 1036 func = "MoveStateUp",
Flick@244 1037 },
Flick@244 1038 down = {
Flick@244 1039 name = L["Down"],
Flick@244 1040 order = 2,
Flick@244 1041 type = "execute",
Flick@244 1042 width = "half",
Flick@244 1043 func = "MoveStateDown",
Flick@244 1044 }
Flick@244 1045 }
Flick@244 1046 }
Flick@244 1047 }
Flick@244 1048 },
Flick@244 1049 properties = {
Flick@244 1050 name = L["Properties"],
Flick@244 1051 order = 2,
Flick@244 1052 type = "group",
Flick@244 1053 args = {
Flick@244 1054 desc = {
Flick@244 1055 name = L["Set the properties for the bar when in this state"],
Flick@244 1056 order = 1,
Flick@244 1057 type = "description"
Flick@244 1058 },
Flick@244 1059 page = {
Flick@244 1060 name = L["Show Page #"],
Flick@244 1061 order = 11,
Flick@244 1062 type = "select",
Flick@244 1063 width = "half",
Flick@244 1064 disabled = "IsPageDisabled",
Flick@244 1065 hidden = "IsPageHidden",
Flick@244 1066 values = "GetPageValues",
Flick@244 1067 set = "SetProp",
Flick@244 1068 get = "GetPage",
Flick@244 1069 },
Flick@244 1070 hide = {
Flick@244 1071 name = L["Hide Bar"],
Flick@244 1072 order = 90,
Flick@244 1073 type = "toggle",
Flick@244 1074 set = "SetProp",
Flick@244 1075 get = "GetProp",
Flick@244 1076 },
Flick@244 1077 --[[ BROKEN
Flick@244 1078 keybindState = {
Flick@244 1079 name = L["Override Keybinds"],
Flick@244 1080 desc = L["Set this state to maintain its own set of keybinds which override the defaults when active"],
Flick@244 1081 order = 91,
Flick@244 1082 type = "toggle",
Flick@244 1083 set = "SetProp",
Flick@244 1084 get = "GetProp",
Flick@244 1085 }, ]]
Flick@244 1086 position = {
Flick@244 1087 name = L["Position"],
Flick@244 1088 order = 92,
Flick@244 1089 type = "group",
Flick@244 1090 inline = true,
Flick@244 1091 args = {
Flick@244 1092 anchorEnable = {
Flick@244 1093 name = L["Reposition"],
Flick@244 1094 order = 1,
Flick@244 1095 type = "toggle",
Flick@244 1096 set = "SetProp",
Flick@244 1097 get = "GetProp",
Flick@244 1098 },
Flick@244 1099 anchorFrame = {
Flick@244 1100 name = L["Anchor Frame"],
Flick@244 1101 order = 2,
Flick@244 1102 type = "select",
Flick@244 1103 values = "GetAnchorFrames",
Flick@244 1104 set = "SetAnchorFrame",
Flick@244 1105 get = "GetAnchorFrame",
Flick@244 1106 disabled = "GetAnchorDisabled",
Flick@244 1107 hidden = "GetAnchorDisabled",
Flick@244 1108 },
Flick@244 1109 anchorPoint = {
Flick@244 1110 name = L["Point"],
Flick@244 1111 order = 3,
Flick@244 1112 type = "select",
Flick@244 1113 values = pointTable,
Flick@244 1114 set = "SetAnchorPointProp",
Flick@244 1115 get = "GetAnchorPointProp",
Flick@244 1116 disabled = "GetAnchorDisabled",
Flick@244 1117 hidden = "GetAnchorDisabled",
Flick@244 1118 },
Flick@244 1119 anchorRelPoint = {
Flick@244 1120 name = L["Relative Point"],
Flick@244 1121 order = 4,
Flick@244 1122 type = "select",
Flick@244 1123 values = pointTable,
Flick@244 1124 set = "SetAnchorPointProp",
Flick@244 1125 get = "GetAnchorPointProp",
Flick@244 1126 disabled = "GetAnchorDisabled",
Flick@244 1127 hidden = "GetAnchorDisabled",
Flick@244 1128 },
Flick@244 1129 anchorX = {
Flick@244 1130 name = L["X Offset"],
Flick@244 1131 order = 5,
Flick@244 1132 type = "range",
Flick@244 1133 min = -100,
Flick@244 1134 max = 100,
Flick@244 1135 step = 1,
Flick@244 1136 set = "SetProp",
Flick@244 1137 get = "GetProp",
Flick@244 1138 disabled = "GetAnchorDisabled",
Flick@244 1139 hidden = "GetAnchorDisabled",
Flick@244 1140 },
Flick@244 1141 anchorY = {
Flick@244 1142 name = L["Y Offset"],
Flick@244 1143 order = 6,
Flick@244 1144 type = "range",
Flick@244 1145 min = -100,
Flick@244 1146 max = 100,
Flick@244 1147 step = 1,
Flick@244 1148 set = "SetProp",
Flick@244 1149 get = "GetProp",
Flick@244 1150 disabled = "GetAnchorDisabled",
Flick@244 1151 hidden = "GetAnchorDisabled",
Flick@244 1152 },
Flick@244 1153 },
Flick@244 1154 },
Flick@244 1155 scale = {
Flick@244 1156 name = L["Scale"],
Flick@244 1157 order = 93,
Flick@244 1158 type = "group",
Flick@244 1159 inline = true,
Flick@244 1160 args = {
Flick@244 1161 enableScale = {
Flick@244 1162 name = L["Set New Scale"],
Flick@244 1163 order = 1,
Flick@244 1164 type = "toggle",
Flick@244 1165 set = "SetProp",
Flick@244 1166 get = "GetProp",
Flick@244 1167 },
Flick@244 1168 scale = {
Flick@244 1169 name = L["Scale"],
Flick@244 1170 order = 2,
Flick@244 1171 type = "range",
Flick@244 1172 min = 0.25,
Flick@244 1173 max = 2.5,
Flick@244 1174 step = 0.05,
Flick@244 1175 isPercent = true,
Flick@244 1176 set = "SetProp",
Flick@244 1177 get = "GetScale",
Flick@244 1178 disabled = "GetScaleDisabled",
Flick@244 1179 hidden = "GetScaleDisabled",
Flick@244 1180 },
Flick@244 1181 },
Flick@244 1182 },
Flick@244 1183 alpha = {
Flick@244 1184 name = L["Transparency"],
Flick@244 1185 order = 94,
Flick@244 1186 type = "group",
Flick@244 1187 inline = true,
Flick@244 1188 args = {
Flick@244 1189 enableAlpha = {
Flick@244 1190 name = L["Set Transparency"],
Flick@244 1191 order = 1,
Flick@244 1192 type = "toggle",
Flick@244 1193 set = "SetProp",
Flick@244 1194 get = "GetProp",
Flick@244 1195 },
Flick@244 1196 alpha = {
Flick@244 1197 name = L["Transparency"],
Flick@244 1198 order = 2,
Flick@244 1199 type = "range",
Flick@244 1200 min = 0,
Flick@244 1201 max = 1,
Flick@244 1202 step = 0.01,
Flick@244 1203 bigStep = 0.05,
Flick@244 1204 isPercent = true,
Flick@244 1205 set = "SetProp",
Flick@244 1206 get = "GetAlpha",
Flick@244 1207 disabled = "GetAlphaDisabled",
Flick@244 1208 hidden = "GetAlphaDisabled",
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@244 1224 style = "radio",
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@244 1684 ReAction:ShowEditor(bar, moduleID, 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