annotate modules/Action.lua @ 193:576c50e51fc5

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