annotate modules/Action.lua @ 223:c4b134512c50

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