annotate modules/Action.lua @ 218:e63aefb8a555

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