annotate modules/Action.lua @ 171:fe0c7be6f6ef

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