annotate modules/Action.lua @ 142:b68be4b6d129

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