annotate modules/Action.lua @ 166:8241be11dcc0

TOTEM_PRIORITIES -> SHAMAN_TOTEM_PRIORITIES TOC update 40000
author Flick <flickerstreak@gmail.com>
date Sat, 16 Oct 2010 21:53:57 +0000
parents 901c91dc1bf2
children 8cc187143acd
rev   line source
flickerstreak@24 1 local ReAction = ReAction
flickerstreak@24 2 local L = ReAction.L
flickerstreak@24 3 local _G = _G
flickerstreak@24 4 local CreateFrame = CreateFrame
flickerstreak@88 5 local format = string.format
flickerstreak@92 6 local wipe = wipe
flickerstreak@24 7
flickerstreak@87 8 ReAction:UpdateRevision("$Revision$")
flickerstreak@77 9
flickerstreak@116 10 local weak = { __mode="k" }
flickerstreak@116 11
flickerstreak@24 12 -- module declaration
flickerstreak@24 13 local moduleID = "Action"
flickerstreak@28 14 local module = ReAction:NewModule( moduleID )
flickerstreak@24 15
flickerstreak@90 16 -- Class declarations
flickerstreak@128 17 local Button = ReAction.Button.Action -- see /classes/ActionButton.lua
flickerstreak@90 18 local Handle = { }
flickerstreak@90 19 local PropHandler = { }
flickerstreak@87 20
flickerstreak@77 21 -- Event handlers
flickerstreak@24 22 function module:OnInitialize()
flickerstreak@28 23 self.db = ReAction.db:RegisterNamespace( moduleID,
flickerstreak@24 24 {
flickerstreak@28 25 profile = {
flickerstreak@75 26 bars = { },
flickerstreak@28 27 }
flickerstreak@24 28 }
flickerstreak@24 29 )
flickerstreak@90 30 self.handles = setmetatable({ }, weak)
flickerstreak@49 31
flickerstreak@63 32 ReAction:RegisterBarOptionGenerator(self, "GetBarOptions")
flickerstreak@63 33
flickerstreak@90 34 ReAction.RegisterCallback(self, "OnCreateBar")
flickerstreak@90 35 ReAction.RegisterCallback(self, "OnRefreshBar")
flickerstreak@63 36 ReAction.RegisterCallback(self, "OnDestroyBar")
flickerstreak@63 37 ReAction.RegisterCallback(self, "OnEraseBar")
flickerstreak@63 38 ReAction.RegisterCallback(self, "OnRenameBar")
flickerstreak@24 39 end
flickerstreak@24 40
flickerstreak@24 41 function module:OnEnable()
flickerstreak@53 42 ReAction:RegisterBarType(L["Action Bar"],
flickerstreak@53 43 {
flickerstreak@53 44 type = moduleID,
flickerstreak@91 45 defaultButtonSize = 36,
flickerstreak@53 46 defaultBarRows = 1,
flickerstreak@53 47 defaultBarCols = 12,
flickerstreak@53 48 defaultBarSpacing = 3
flickerstreak@53 49 }, true)
flickerstreak@90 50 ReAction:GetModule("State"):RegisterStateProperty("page", nil, PropHandler.GetOptions(), PropHandler)
flickerstreak@24 51 end
flickerstreak@24 52
flickerstreak@24 53 function module:OnDisable()
flickerstreak@53 54 ReAction:UnregisterBarType(L["Action Bar"])
flickerstreak@90 55 ReAction:GetModule("State"):UnregisterStateProperty("page")
flickerstreak@90 56 end
flickerstreak@90 57
flickerstreak@90 58 function module:OnCreateBar(event, bar, name)
flickerstreak@90 59 if bar.config.type == moduleID then
flickerstreak@90 60 local profile = self.db.profile
flickerstreak@90 61 if profile.bars[name] == nil then
flickerstreak@90 62 profile.bars[name] = {
flickerstreak@90 63 buttons = { }
flickerstreak@90 64 }
flickerstreak@90 65 end
flickerstreak@90 66 if self.handles[bar] == nil then
flickerstreak@90 67 self.handles[bar] = Handle:New(bar, profile.bars[name])
flickerstreak@90 68 end
flickerstreak@90 69 end
flickerstreak@24 70 end
flickerstreak@24 71
flickerstreak@63 72 function module:OnRefreshBar(event, bar, name)
flickerstreak@90 73 if self.handles[bar] then
flickerstreak@90 74 self.handles[bar]:Refresh()
flickerstreak@24 75 end
flickerstreak@24 76 end
flickerstreak@24 77
flickerstreak@63 78 function module:OnDestroyBar(event, bar, name)
flickerstreak@90 79 if self.handles[bar] then
flickerstreak@90 80 self.handles[bar]:Destroy()
flickerstreak@90 81 self.handles[bar] = nil
flickerstreak@24 82 end
flickerstreak@24 83 end
flickerstreak@24 84
flickerstreak@63 85 function module:OnEraseBar(event, bar, name)
flickerstreak@75 86 self.db.profile.bars[name] = nil
flickerstreak@24 87 end
flickerstreak@24 88
flickerstreak@63 89 function module:OnRenameBar(event, bar, oldname, newname)
flickerstreak@75 90 b = self.db.profile.bars
flickerstreak@75 91 b[newname], b[oldname] = b[oldname], nil
flickerstreak@48 92 end
flickerstreak@48 93
flickerstreak@90 94 ---- Interface ----
flickerstreak@90 95 function module:GetBarOptions(bar)
flickerstreak@90 96 local h = self.handles[bar]
flickerstreak@90 97 if h then
flickerstreak@90 98 return h:GetOptions()
flickerstreak@90 99 end
flickerstreak@90 100 end
flickerstreak@90 101
flickerstreak@90 102
flickerstreak@90 103 ---- Bar Handle ----
flickerstreak@90 104
flickerstreak@87 105 do
flickerstreak@87 106 local options = {
flickerstreak@87 107 hideEmpty = {
flickerstreak@87 108 name = L["Hide Empty Buttons"],
flickerstreak@87 109 order = 1,
flickerstreak@87 110 type = "toggle",
flickerstreak@87 111 width = "double",
flickerstreak@87 112 get = "GetHideEmpty",
flickerstreak@87 113 set = "SetHideEmpty",
flickerstreak@87 114 },
flickerstreak@102 115 lockButtons = {
flickerstreak@102 116 name = L["Lock Buttons"],
flickerstreak@147 117 desc = L["Prevents picking up/dragging actions (use SHIFT to override this behavior)"],
flickerstreak@102 118 order = 2,
flickerstreak@102 119 type = "toggle",
flickerstreak@102 120 get = "GetLockButtons",
flickerstreak@102 121 set = "SetLockButtons",
flickerstreak@102 122 },
flickerstreak@102 123 lockOnlyCombat = {
flickerstreak@102 124 name = L["Only in Combat"],
flickerstreak@102 125 desc = L["Only lock the buttons when in combat"],
flickerstreak@102 126 order = 3,
flickerstreak@102 127 type = "toggle",
flickerstreak@102 128 disabled = "LockButtonsCombatDisabled",
flickerstreak@102 129 get = "GetLockButtonsCombat",
flickerstreak@102 130 set = "SetLockButtonsCombat",
flickerstreak@102 131 },
flickerstreak@87 132 pages = {
flickerstreak@87 133 name = L["# Pages"],
flickerstreak@87 134 desc = L["Use the Dynamic State tab to specify page transitions"],
flickerstreak@102 135 order = 4,
flickerstreak@87 136 type = "range",
flickerstreak@87 137 min = 1,
flickerstreak@87 138 max = 10,
flickerstreak@87 139 step = 1,
flickerstreak@87 140 get = "GetNumPages",
flickerstreak@87 141 set = "SetNumPages",
flickerstreak@87 142 },
flickerstreak@90 143 mindcontrol = {
flickerstreak@90 144 name = L["Mind Control Support"],
flickerstreak@90 145 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."],
flickerstreak@102 146 order = 5,
flickerstreak@90 147 type = "toggle",
flickerstreak@90 148 width = "double",
flickerstreak@90 149 set = "SetMindControl",
flickerstreak@90 150 get = "GetMindControl",
flickerstreak@90 151 },
flickerstreak@121 152 vehicle = {
flickerstreak@121 153 name = L["Vehicle Support"],
flickerstreak@121 154 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."],
flickerstreak@121 155 order = 6,
flickerstreak@121 156 type = "toggle",
flickerstreak@121 157 width = "double",
flickerstreak@121 158 get = "GetVehicle",
flickerstreak@121 159 set = "SetVehicle",
flickerstreak@121 160 },
flickerstreak@87 161 actions = {
flickerstreak@87 162 name = L["Edit Action IDs"],
flickerstreak@121 163 order = 7,
flickerstreak@87 164 type = "group",
flickerstreak@87 165 inline = true,
flickerstreak@87 166 args = {
flickerstreak@87 167 method = {
flickerstreak@87 168 name = L["Assign"],
flickerstreak@87 169 order = 1,
flickerstreak@87 170 type = "select",
flickerstreak@87 171 width = "double",
flickerstreak@87 172 values = { [0] = L["Choose Method..."],
flickerstreak@87 173 [1] = L["Individually"],
flickerstreak@87 174 [2] = L["All at Once"], },
flickerstreak@87 175 get = "GetActionEditMethod",
flickerstreak@87 176 set = "SetActionEditMethod",
flickerstreak@87 177 },
flickerstreak@87 178 rowSelect = {
flickerstreak@87 179 name = L["Row"],
flickerstreak@87 180 desc = L["Rows are numbered top to bottom"],
flickerstreak@87 181 order = 2,
flickerstreak@87 182 type = "select",
flickerstreak@87 183 width = "half",
flickerstreak@87 184 hidden = "IsButtonSelectHidden",
flickerstreak@87 185 values = "GetRowList",
flickerstreak@87 186 get = "GetSelectedRow",
flickerstreak@87 187 set = "SetSelectedRow",
flickerstreak@87 188 },
flickerstreak@87 189 colSelect = {
flickerstreak@87 190 name = L["Col"],
flickerstreak@87 191 desc = L["Columns are numbered left to right"],
flickerstreak@87 192 order = 3,
flickerstreak@87 193 type = "select",
flickerstreak@87 194 width = "half",
flickerstreak@87 195 hidden = "IsButtonSelectHidden",
flickerstreak@87 196 values = "GetColumnList",
flickerstreak@87 197 get = "GetSelectedColumn",
flickerstreak@87 198 set = "SetSelectedColumn",
flickerstreak@87 199 },
flickerstreak@87 200 pageSelect = {
flickerstreak@87 201 name = L["Page"],
flickerstreak@87 202 order = 4,
flickerstreak@87 203 type = "select",
flickerstreak@87 204 width = "half",
flickerstreak@87 205 hidden = "IsPageSelectHidden",
flickerstreak@87 206 values = "GetPageList",
flickerstreak@87 207 get = "GetSelectedPage",
flickerstreak@87 208 set = "SetSelectedPage",
flickerstreak@87 209 },
flickerstreak@87 210 single = {
flickerstreak@87 211 name = L["Action ID"],
flickerstreak@87 212 usage = L["Specify ID 1-120"],
flickerstreak@87 213 order = 5,
flickerstreak@87 214 type = "input",
flickerstreak@87 215 width = "half",
flickerstreak@87 216 hidden = "IsButtonSelectHidden",
flickerstreak@87 217 get = "GetActionID",
flickerstreak@87 218 set = "SetActionID",
flickerstreak@87 219 validate = "ValidateActionID",
flickerstreak@87 220 },
flickerstreak@87 221 multi = {
flickerstreak@87 222 name = L["ID List"],
flickerstreak@87 223 usage = L["Specify a comma-separated list of IDs for each button in the bar (in order). Separate multiple pages with semicolons (;)"],
flickerstreak@87 224 order = 6,
flickerstreak@87 225 type = "input",
flickerstreak@87 226 multiline = true,
flickerstreak@87 227 width = "double",
flickerstreak@87 228 hidden = "IsMultiIDHidden",
flickerstreak@87 229 get = "GetMultiID",
flickerstreak@87 230 set = "SetMultiID",
flickerstreak@87 231 validate = "ValidateMultiID",
flickerstreak@90 232 },
flickerstreak@90 233 },
flickerstreak@87 234 },
flickerstreak@87 235 }
flickerstreak@77 236
flickerstreak@90 237 local meta = { __index = Handle }
flickerstreak@90 238
flickerstreak@90 239 function Handle:New( bar, config )
flickerstreak@90 240 local self = setmetatable(
flickerstreak@90 241 {
flickerstreak@90 242 bar = bar,
flickerstreak@90 243 config = config,
flickerstreak@90 244 btns = { }
flickerstreak@90 245 },
flickerstreak@90 246 meta)
flickerstreak@90 247
flickerstreak@90 248 if self.config.buttons == nil then
flickerstreak@90 249 self.config.buttons = { }
flickerstreak@90 250 end
flickerstreak@90 251 self:Refresh()
flickerstreak@90 252 return self
flickerstreak@90 253 end
flickerstreak@90 254
flickerstreak@90 255 function Handle:Refresh()
flickerstreak@90 256 local r, c = self.bar:GetButtonGrid()
flickerstreak@90 257 local n = r*c
flickerstreak@90 258 local btnCfg = self.config.buttons
flickerstreak@90 259 if n ~= #self.btns then
flickerstreak@90 260 for i = 1, n do
flickerstreak@90 261 if btnCfg[i] == nil then
flickerstreak@90 262 btnCfg[i] = {}
flickerstreak@90 263 end
flickerstreak@90 264 if self.btns[i] == nil then
flickerstreak@128 265 local lastButton = self:GetLastButton()
flickerstreak@128 266 local hint = lastButton and lastButton.config.actionID
flickerstreak@128 267 local b = Button:New(i, self.config, self.bar, hint)
flickerstreak@90 268 self.btns[i] = b
flickerstreak@90 269 self.bar:AddButton(i,b)
flickerstreak@90 270 end
flickerstreak@90 271 end
flickerstreak@90 272 for i = n+1, #self.btns do
flickerstreak@90 273 if self.btns[i] then
flickerstreak@90 274 self.bar:RemoveButton(self.btns[i])
flickerstreak@90 275 self.btns[i]:Destroy()
flickerstreak@90 276 self.btns[i] = nil
flickerstreak@90 277 btnCfg[i] = nil
flickerstreak@90 278 end
flickerstreak@90 279 end
flickerstreak@90 280 end
flickerstreak@90 281 for _, b in ipairs(self.btns) do
flickerstreak@90 282 b:Refresh()
flickerstreak@90 283 end
flickerstreak@128 284 Button.SetupBarHeader(self.bar,self.config)
flickerstreak@102 285 self:UpdateButtonLock()
flickerstreak@90 286 end
flickerstreak@90 287
flickerstreak@90 288 function Handle:Destroy()
flickerstreak@90 289 for _,b in pairs(self.btns) do
flickerstreak@90 290 if b then
flickerstreak@90 291 b:Destroy()
flickerstreak@90 292 end
flickerstreak@90 293 end
flickerstreak@90 294 end
flickerstreak@90 295
flickerstreak@102 296 function Handle:UpdateButtonLock()
flickerstreak@128 297 Button.SetButtonLock(self.bar, self.config.lockButtons, self.config.lockButtonsCombat)
flickerstreak@102 298 end
flickerstreak@102 299
flickerstreak@90 300 function Handle:GetLastButton()
flickerstreak@90 301 return self.btns[#self.btns]
flickerstreak@90 302 end
flickerstreak@90 303
flickerstreak@90 304 -- options handlers
flickerstreak@90 305 function Handle:GetOptions()
flickerstreak@87 306 return {
flickerstreak@87 307 type = "group",
flickerstreak@87 308 name = L["Action Buttons"],
flickerstreak@90 309 handler = self,
flickerstreak@87 310 args = options
flickerstreak@87 311 }
flickerstreak@77 312 end
flickerstreak@77 313
flickerstreak@90 314 function Handle:SetHideEmpty(info, value)
flickerstreak@90 315 if value ~= self.config.hideEmpty then
flickerstreak@90 316 self.config.hideEmpty = value
flickerstreak@128 317 for _, b in pairs(self.btns) do
flickerstreak@128 318 b:ShowGrid(not value)
flickerstreak@128 319 end
flickerstreak@77 320 end
flickerstreak@77 321 end
flickerstreak@77 322
flickerstreak@90 323 function Handle:GetHideEmpty()
flickerstreak@90 324 return self.config.hideEmpty
flickerstreak@77 325 end
flickerstreak@87 326
flickerstreak@102 327 function Handle:GetLockButtons()
flickerstreak@128 328 return self.config.lockButtons
flickerstreak@102 329 end
flickerstreak@102 330
flickerstreak@102 331 function Handle:SetLockButtons(info, value)
flickerstreak@102 332 self.config.lockButtons = value
flickerstreak@102 333 self:UpdateButtonLock()
flickerstreak@102 334 end
flickerstreak@102 335
flickerstreak@102 336 function Handle:GetLockButtonsCombat()
flickerstreak@102 337 return self.config.lockButtonsCombat
flickerstreak@102 338 end
flickerstreak@102 339
flickerstreak@102 340 function Handle:SetLockButtonsCombat(info, value)
flickerstreak@102 341 self.config.lockButtonsCombat = value
flickerstreak@102 342 self:UpdateButtonLock()
flickerstreak@102 343 end
flickerstreak@102 344
flickerstreak@102 345 function Handle:LockButtonsCombatDisabled()
flickerstreak@128 346 return not self.config.lockButtons
flickerstreak@102 347 end
flickerstreak@102 348
flickerstreak@90 349 function Handle:GetNumPages()
flickerstreak@90 350 return self.config.nPages
flickerstreak@87 351 end
flickerstreak@87 352
flickerstreak@90 353 function Handle:SetNumPages(info, value)
flickerstreak@90 354 self.config.nPages = value
flickerstreak@90 355 self:Refresh()
flickerstreak@87 356 end
flickerstreak@87 357
flickerstreak@90 358 function Handle:GetMindControl()
flickerstreak@90 359 return self.config.mindcontrol
flickerstreak@90 360 end
flickerstreak@90 361
flickerstreak@90 362 function Handle:SetMindControl(info, value)
flickerstreak@90 363 self.config.mindcontrol = value
flickerstreak@90 364 self:Refresh()
flickerstreak@90 365 end
flickerstreak@90 366
flickerstreak@121 367 function Handle:GetVehicle()
flickerstreak@121 368 return self.config.vehicle
flickerstreak@121 369 end
flickerstreak@121 370
flickerstreak@121 371 function Handle:SetVehicle(info, value)
flickerstreak@121 372 self.config.vehicle = value
flickerstreak@121 373 self:Refresh()
flickerstreak@121 374 end
flickerstreak@121 375
flickerstreak@90 376 function Handle:GetActionEditMethod()
flickerstreak@87 377 return self.editMethod or 0
flickerstreak@87 378 end
flickerstreak@87 379
flickerstreak@90 380 function Handle:SetActionEditMethod(info, value)
flickerstreak@87 381 self.editMethod = value
flickerstreak@87 382 end
flickerstreak@87 383
flickerstreak@90 384 function Handle:IsButtonSelectHidden()
flickerstreak@87 385 return self.editMethod ~= 1
flickerstreak@87 386 end
flickerstreak@87 387
flickerstreak@90 388 function Handle:GetRowList()
flickerstreak@87 389 local r,c = self.bar:GetButtonGrid()
flickerstreak@87 390 if self.rowList == nil or #self.rowList ~= r then
flickerstreak@87 391 local list = { }
flickerstreak@87 392 for i = 1, r do
flickerstreak@87 393 table.insert(list,i)
flickerstreak@87 394 end
flickerstreak@87 395 self.rowList = list
flickerstreak@87 396 end
flickerstreak@87 397 return self.rowList
flickerstreak@87 398 end
flickerstreak@87 399
flickerstreak@90 400 function Handle:GetSelectedRow()
flickerstreak@87 401 local r, c = self.bar:GetButtonGrid()
flickerstreak@87 402 local row = self.selectedRow or 1
flickerstreak@87 403 if row > r then
flickerstreak@87 404 row = 1
flickerstreak@87 405 end
flickerstreak@87 406 self.selectedRow = row
flickerstreak@87 407 return row
flickerstreak@87 408 end
flickerstreak@87 409
flickerstreak@90 410 function Handle:SetSelectedRow(info, value)
flickerstreak@87 411 self.selectedRow = value
flickerstreak@87 412 end
flickerstreak@87 413
flickerstreak@90 414 function Handle:GetColumnList()
flickerstreak@87 415 local r,c = self.bar:GetButtonGrid()
flickerstreak@87 416 if self.columnList == nil or #self.columnList ~= c then
flickerstreak@87 417 local list = { }
flickerstreak@87 418 for i = 1, c do
flickerstreak@87 419 table.insert(list,i)
flickerstreak@87 420 end
flickerstreak@87 421 self.columnList = list
flickerstreak@87 422 end
flickerstreak@87 423 return self.columnList
flickerstreak@87 424 end
flickerstreak@87 425
flickerstreak@90 426 function Handle:GetSelectedColumn()
flickerstreak@87 427 local r, c = self.bar:GetButtonGrid()
flickerstreak@87 428 local col = self.selectedColumn or 1
flickerstreak@87 429 if col > c then
flickerstreak@87 430 col = 1
flickerstreak@87 431 end
flickerstreak@87 432 self.selectedColumn = col
flickerstreak@87 433 return col
flickerstreak@87 434 end
flickerstreak@87 435
flickerstreak@90 436 function Handle:SetSelectedColumn(info, value)
flickerstreak@87 437 self.selectedColumn = value
flickerstreak@87 438 end
flickerstreak@87 439
flickerstreak@90 440 function Handle:IsPageSelectHidden()
flickerstreak@90 441 return self.editMethod ~= 1 or (self.config.nPages or 1) < 2
flickerstreak@87 442 end
flickerstreak@87 443
flickerstreak@90 444 function Handle:GetPageList()
flickerstreak@90 445 local n = self.config.nPages or 1
flickerstreak@87 446 if self.pageList == nil or #self.pageList ~= n then
flickerstreak@87 447 local p = { }
flickerstreak@87 448 for i = 1, n do
flickerstreak@87 449 table.insert(p,i)
flickerstreak@87 450 end
flickerstreak@87 451 self.pageList = p
flickerstreak@87 452 end
flickerstreak@87 453 return self.pageList
flickerstreak@87 454 end
flickerstreak@87 455
flickerstreak@90 456 function Handle:GetSelectedPage()
flickerstreak@87 457 local p = self.selectedPage or 1
flickerstreak@90 458 if p > (self.config.nPages or 1) then
flickerstreak@87 459 p = 1
flickerstreak@87 460 end
flickerstreak@87 461 self.selectedPage = p
flickerstreak@87 462 return p
flickerstreak@87 463 end
flickerstreak@87 464
flickerstreak@90 465 function Handle:SetSelectedPage(info, value)
flickerstreak@87 466 self.selectedPage = value
flickerstreak@87 467 end
flickerstreak@87 468
flickerstreak@90 469 function Handle:GetActionID()
flickerstreak@87 470 local row = self.selectedRow or 1
flickerstreak@87 471 local col = self.selectedColumn or 1
flickerstreak@87 472 local r, c = self.bar:GetButtonGrid()
flickerstreak@87 473 local n = (row-1) * c + col
flickerstreak@90 474 local btn = self.btns[n]
flickerstreak@87 475 if btn then
flickerstreak@87 476 return tostring(btn:GetActionID(self.selectedPage or 1))
flickerstreak@87 477 end
flickerstreak@87 478 end
flickerstreak@87 479
flickerstreak@90 480 function Handle:SetActionID(info, value)
flickerstreak@87 481 local row = self.selectedRow or 1
flickerstreak@87 482 local col = self.selectedColumn or 1
flickerstreak@87 483 local r, c = self.bar:GetButtonGrid()
flickerstreak@87 484 local n = (row-1) * c + col
flickerstreak@90 485 local btn = self.btns[n]
flickerstreak@87 486 if btn then
flickerstreak@87 487 btn:SetActionID(tonumber(value), self.selectedPage or 1)
flickerstreak@87 488 end
flickerstreak@87 489 end
flickerstreak@87 490
flickerstreak@90 491 function Handle:ValidateActionID(info, value)
flickerstreak@87 492 value = tonumber(value)
flickerstreak@87 493 if value == nil or value < 1 or value > 120 then
flickerstreak@87 494 return L["Specify ID 1-120"]
flickerstreak@87 495 end
flickerstreak@87 496 return true
flickerstreak@87 497 end
flickerstreak@87 498
flickerstreak@90 499 function Handle:IsMultiIDHidden()
flickerstreak@87 500 return self.editMethod ~= 2
flickerstreak@87 501 end
flickerstreak@87 502
flickerstreak@90 503 function Handle:GetMultiID()
flickerstreak@87 504 local p = { }
flickerstreak@90 505 for i = 1, self.config.nPages or 1 do
flickerstreak@87 506 local b = { }
flickerstreak@90 507 for _, btn in ipairs(self.btns) do
flickerstreak@87 508 table.insert(b, btn:GetActionID(i))
flickerstreak@87 509 end
flickerstreak@87 510 table.insert(p, table.concat(b,","))
flickerstreak@87 511 end
flickerstreak@87 512 return table.concat(p,";\n")
flickerstreak@87 513 end
flickerstreak@87 514
flickerstreak@87 515
flickerstreak@87 516 local function ParseMultiID(nBtns, nPages, s)
flickerstreak@87 517 if s:match("[^%d%s,;]") then
flickerstreak@87 518 ReAction:Print("items other than digits, spaces, commas, and semicolons in string",s)
flickerstreak@87 519 return nil
flickerstreak@87 520 end
flickerstreak@87 521 local p = { }
flickerstreak@87 522 for list in s:gmatch("[^;]+") do
flickerstreak@87 523 local pattern = ("^%s?$"):format(("%s*(%d+)%s*,"):rep(nBtns))
flickerstreak@87 524 local ids = { list:match(pattern) }
flickerstreak@87 525 if #ids ~= nBtns then
flickerstreak@87 526 ReAction:Print("found",#ids,"buttons instead of",nBtns)
flickerstreak@87 527 return nil
flickerstreak@87 528 end
flickerstreak@87 529 table.insert(p,ids)
flickerstreak@87 530 end
flickerstreak@87 531 if #p ~= nPages then
flickerstreak@87 532 ReAction:Print("found",#p,"pages instead of",nPages)
flickerstreak@87 533 return nil
flickerstreak@87 534 end
flickerstreak@87 535 return p
flickerstreak@87 536 end
flickerstreak@87 537
flickerstreak@90 538 function Handle:SetMultiID(info, value)
flickerstreak@91 539 local p = ParseMultiID(#self.btns, self.config.nPages or 1, value)
flickerstreak@87 540 for page, b in ipairs(p) do
flickerstreak@87 541 for button, id in ipairs(b) do
flickerstreak@90 542 self.btns[button]:SetActionID(id, page)
flickerstreak@87 543 end
flickerstreak@87 544 end
flickerstreak@87 545 end
flickerstreak@87 546
flickerstreak@90 547 function Handle:ValidateMultiID(info, value)
flickerstreak@87 548 local bad = L["Invalid action ID list string"]
flickerstreak@90 549 if value == nil or ParseMultiID(#self.btns, self.config.nPages or 1, value) == nil then
flickerstreak@87 550 return bad
flickerstreak@87 551 end
flickerstreak@87 552 return true
flickerstreak@87 553 end
flickerstreak@77 554 end
flickerstreak@77 555
flickerstreak@77 556
flickerstreak@87 557 ------ State property options ------
flickerstreak@87 558 do
flickerstreak@87 559 local pageOptions = {
flickerstreak@87 560 page = {
flickerstreak@92 561 name = L["Show Page #"],
flickerstreak@92 562 order = 11,
flickerstreak@92 563 type = "select",
flickerstreak@92 564 width = "half",
flickerstreak@87 565 disabled = "IsPageDisabled",
flickerstreak@87 566 hidden = "IsPageHidden",
flickerstreak@87 567 values = "GetPageValues",
flickerstreak@87 568 set = "SetProp",
flickerstreak@87 569 get = "GetPage",
flickerstreak@87 570 },
flickerstreak@87 571 }
flickerstreak@50 572
flickerstreak@90 573 local function GetBarConfig(bar)
flickerstreak@90 574 return module.db.profile.bars[bar:GetName()]
flickerstreak@87 575 end
flickerstreak@87 576
flickerstreak@90 577 function PropHandler.GetOptions()
flickerstreak@90 578 return pageOptions
flickerstreak@87 579 end
flickerstreak@87 580
flickerstreak@90 581 function PropHandler:IsPageDisabled()
flickerstreak@90 582 local c = GetBarConfig(self.bar)
flickerstreak@90 583 local n = c and c.nPages or 1
flickerstreak@90 584 return not (n > 1)
flickerstreak@87 585 end
flickerstreak@87 586
flickerstreak@90 587 function PropHandler:IsPageHidden()
flickerstreak@87 588 return not GetBarConfig(self.bar)
flickerstreak@87 589 end
flickerstreak@87 590
flickerstreak@90 591 function PropHandler:GetPageValues()
flickerstreak@92 592 if not self._pagevalues then
flickerstreak@92 593 self._pagevalues = { }
flickerstreak@92 594 end
flickerstreak@87 595 local c = GetBarConfig(self.bar)
flickerstreak@87 596 if c then
flickerstreak@87 597 local n = c.nPages
flickerstreak@92 598 -- cache the results
flickerstreak@87 599 if self._npages ~= n then
flickerstreak@87 600 self._npages = n
flickerstreak@92 601 wipe(self._pagevalues)
flickerstreak@87 602 for i = 1, n do
flickerstreak@90 603 self._pagevalues["page"..i] = i
flickerstreak@87 604 end
flickerstreak@87 605 end
flickerstreak@87 606 end
flickerstreak@92 607 return self._pagevalues
flickerstreak@87 608 end
flickerstreak@87 609
flickerstreak@90 610 function PropHandler:GetPage(info)
flickerstreak@87 611 return self:GetProp(info) or 1
flickerstreak@87 612 end
flickerstreak@90 613
flickerstreak@87 614 end
flickerstreak@87 615