annotate modules/ReAction_Action/ReAction_Action.lua @ 105:ceb860730875

Updated .toc files for modules
author Flick <flickerstreak@gmail.com>
date Sat, 08 Nov 2008 00:33:12 +0000
parents ad49739d110d
children b2fb8f7dc780
rev   line source
flickerstreak@24 1 --[[
flickerstreak@53 2 ReAction Action button module.
flickerstreak@24 3
flickerstreak@24 4 The button module implements standard action button functionality by wrapping Blizzard's
flickerstreak@87 5 ActionBarButtonTemplate frame and associated functions.
flickerstreak@77 6
flickerstreak@87 7 It also provides action remapping support for multiple pages and possessed targets
flickerstreak@90 8 (Mind Control, Eyes of the Beast, Karazhan Chess event, various quests, etc).
flickerstreak@24 9 --]]
flickerstreak@24 10
flickerstreak@24 11 -- local imports
flickerstreak@24 12 local ReAction = ReAction
flickerstreak@24 13 local L = ReAction.L
flickerstreak@24 14 local _G = _G
flickerstreak@24 15 local CreateFrame = CreateFrame
flickerstreak@88 16 local format = string.format
flickerstreak@92 17 local wipe = wipe
flickerstreak@24 18
flickerstreak@87 19 ReAction:UpdateRevision("$Revision$")
flickerstreak@77 20
flickerstreak@88 21 -- libraries
flickerstreak@88 22 local KB = LibStub("LibKeyBound-1.0")
flickerstreak@88 23
flickerstreak@24 24 -- module declaration
flickerstreak@24 25 local moduleID = "Action"
flickerstreak@28 26 local module = ReAction:NewModule( moduleID )
flickerstreak@24 27
flickerstreak@90 28 -- Class declarations
flickerstreak@77 29 local Button = { }
flickerstreak@90 30 local Handle = { }
flickerstreak@90 31 local PropHandler = { }
flickerstreak@87 32
flickerstreak@77 33 -- Event handlers
flickerstreak@24 34 function module:OnInitialize()
flickerstreak@28 35 self.db = ReAction.db:RegisterNamespace( moduleID,
flickerstreak@24 36 {
flickerstreak@28 37 profile = {
flickerstreak@75 38 bars = { },
flickerstreak@28 39 }
flickerstreak@24 40 }
flickerstreak@24 41 )
flickerstreak@90 42 self.handles = setmetatable({ }, weak)
flickerstreak@49 43
flickerstreak@63 44 ReAction:RegisterBarOptionGenerator(self, "GetBarOptions")
flickerstreak@63 45
flickerstreak@90 46 ReAction.RegisterCallback(self, "OnCreateBar")
flickerstreak@90 47 ReAction.RegisterCallback(self, "OnRefreshBar")
flickerstreak@63 48 ReAction.RegisterCallback(self, "OnDestroyBar")
flickerstreak@63 49 ReAction.RegisterCallback(self, "OnEraseBar")
flickerstreak@63 50 ReAction.RegisterCallback(self, "OnRenameBar")
flickerstreak@63 51 ReAction.RegisterCallback(self, "OnConfigModeChanged")
flickerstreak@63 52
flickerstreak@88 53 KB.RegisterCallback(self, "LIBKEYBOUND_ENABLED")
flickerstreak@88 54 KB.RegisterCallback(self, "LIBKEYBOUND_DISABLED")
flickerstreak@88 55 KB.RegisterCallback(self, "LIBKEYBOUND_MODE_COLOR_CHANGED","LIBKEYBOUND_ENABLED")
flickerstreak@24 56 end
flickerstreak@24 57
flickerstreak@24 58 function module:OnEnable()
flickerstreak@53 59 ReAction:RegisterBarType(L["Action Bar"],
flickerstreak@53 60 {
flickerstreak@53 61 type = moduleID,
flickerstreak@91 62 defaultButtonSize = 36,
flickerstreak@53 63 defaultBarRows = 1,
flickerstreak@53 64 defaultBarCols = 12,
flickerstreak@53 65 defaultBarSpacing = 3
flickerstreak@53 66 }, true)
flickerstreak@90 67 ReAction:GetModule("State"):RegisterStateProperty("page", nil, PropHandler.GetOptions(), PropHandler)
flickerstreak@24 68 end
flickerstreak@24 69
flickerstreak@24 70 function module:OnDisable()
flickerstreak@53 71 ReAction:UnregisterBarType(L["Action Bar"])
flickerstreak@90 72 ReAction:GetModule("State"):UnregisterStateProperty("page")
flickerstreak@90 73 end
flickerstreak@90 74
flickerstreak@90 75 function module:OnCreateBar(event, bar, name)
flickerstreak@90 76 if bar.config.type == moduleID then
flickerstreak@90 77 local profile = self.db.profile
flickerstreak@90 78 if profile.bars[name] == nil then
flickerstreak@90 79 profile.bars[name] = {
flickerstreak@90 80 buttons = { }
flickerstreak@90 81 }
flickerstreak@90 82 end
flickerstreak@90 83 if self.handles[bar] == nil then
flickerstreak@90 84 self.handles[bar] = Handle:New(bar, profile.bars[name])
flickerstreak@90 85 end
flickerstreak@90 86 end
flickerstreak@24 87 end
flickerstreak@24 88
flickerstreak@63 89 function module:OnRefreshBar(event, bar, name)
flickerstreak@90 90 if self.handles[bar] then
flickerstreak@90 91 self.handles[bar]:Refresh()
flickerstreak@24 92 end
flickerstreak@24 93 end
flickerstreak@24 94
flickerstreak@63 95 function module:OnDestroyBar(event, bar, name)
flickerstreak@90 96 if self.handles[bar] then
flickerstreak@90 97 self.handles[bar]:Destroy()
flickerstreak@90 98 self.handles[bar] = nil
flickerstreak@24 99 end
flickerstreak@24 100 end
flickerstreak@24 101
flickerstreak@63 102 function module:OnEraseBar(event, bar, name)
flickerstreak@75 103 self.db.profile.bars[name] = nil
flickerstreak@24 104 end
flickerstreak@24 105
flickerstreak@63 106 function module:OnRenameBar(event, bar, oldname, newname)
flickerstreak@75 107 b = self.db.profile.bars
flickerstreak@75 108 b[newname], b[oldname] = b[oldname], nil
flickerstreak@48 109 end
flickerstreak@48 110
flickerstreak@63 111 function module:OnConfigModeChanged(event, mode)
flickerstreak@90 112 for _, h in pairs(self.handles) do
flickerstreak@90 113 h:SetConfigMode(mode)
flickerstreak@24 114 end
flickerstreak@24 115 end
flickerstreak@24 116
flickerstreak@88 117 function module:LIBKEYBOUND_ENABLED(evt)
flickerstreak@90 118 for _, h in pairs(self.handles) do
flickerstreak@93 119 h:ShowGrid(true)
flickerstreak@90 120 h:SetKeybindMode(true)
flickerstreak@88 121 end
flickerstreak@88 122 end
flickerstreak@88 123
flickerstreak@88 124 function module:LIBKEYBOUND_DISABLED(evt)
flickerstreak@90 125 for _, h in pairs(self.handles) do
flickerstreak@93 126 h:ShowGrid(false)
flickerstreak@90 127 h:SetKeybindMode(false)
flickerstreak@88 128 end
flickerstreak@88 129 end
flickerstreak@88 130
flickerstreak@50 131
flickerstreak@90 132 ---- Interface ----
flickerstreak@90 133 function module:GetBarOptions(bar)
flickerstreak@90 134 local h = self.handles[bar]
flickerstreak@90 135 if h then
flickerstreak@90 136 return h:GetOptions()
flickerstreak@90 137 end
flickerstreak@90 138 end
flickerstreak@90 139
flickerstreak@90 140
flickerstreak@90 141 ---- Bar Handle ----
flickerstreak@90 142
flickerstreak@87 143 do
flickerstreak@87 144 local options = {
flickerstreak@87 145 hideEmpty = {
flickerstreak@87 146 name = L["Hide Empty Buttons"],
flickerstreak@87 147 order = 1,
flickerstreak@87 148 type = "toggle",
flickerstreak@87 149 width = "double",
flickerstreak@87 150 get = "GetHideEmpty",
flickerstreak@87 151 set = "SetHideEmpty",
flickerstreak@87 152 },
flickerstreak@102 153 lockButtons = {
flickerstreak@102 154 name = L["Lock Buttons"],
flickerstreak@102 155 desc = L["Prevents picking up/dragging actions.|nNOTE: This setting is overridden by the global setting in Blizzard's Action Buttons tab"],
flickerstreak@102 156 order = 2,
flickerstreak@102 157 type = "toggle",
flickerstreak@102 158 disabled = "LockButtonsDisabled",
flickerstreak@102 159 get = "GetLockButtons",
flickerstreak@102 160 set = "SetLockButtons",
flickerstreak@102 161 },
flickerstreak@102 162 lockOnlyCombat = {
flickerstreak@102 163 name = L["Only in Combat"],
flickerstreak@102 164 desc = L["Only lock the buttons when in combat"],
flickerstreak@102 165 order = 3,
flickerstreak@102 166 type = "toggle",
flickerstreak@102 167 disabled = "LockButtonsCombatDisabled",
flickerstreak@102 168 get = "GetLockButtonsCombat",
flickerstreak@102 169 set = "SetLockButtonsCombat",
flickerstreak@102 170 },
flickerstreak@87 171 pages = {
flickerstreak@87 172 name = L["# Pages"],
flickerstreak@87 173 desc = L["Use the Dynamic State tab to specify page transitions"],
flickerstreak@102 174 order = 4,
flickerstreak@87 175 type = "range",
flickerstreak@87 176 min = 1,
flickerstreak@87 177 max = 10,
flickerstreak@87 178 step = 1,
flickerstreak@87 179 get = "GetNumPages",
flickerstreak@87 180 set = "SetNumPages",
flickerstreak@87 181 },
flickerstreak@90 182 mindcontrol = {
flickerstreak@90 183 name = L["Mind Control Support"],
flickerstreak@90 184 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 185 order = 5,
flickerstreak@90 186 type = "toggle",
flickerstreak@90 187 width = "double",
flickerstreak@90 188 set = "SetMindControl",
flickerstreak@90 189 get = "GetMindControl",
flickerstreak@90 190 },
flickerstreak@87 191 actions = {
flickerstreak@87 192 name = L["Edit Action IDs"],
flickerstreak@102 193 order = 6,
flickerstreak@87 194 type = "group",
flickerstreak@87 195 inline = true,
flickerstreak@87 196 args = {
flickerstreak@87 197 method = {
flickerstreak@87 198 name = L["Assign"],
flickerstreak@87 199 order = 1,
flickerstreak@87 200 type = "select",
flickerstreak@87 201 width = "double",
flickerstreak@87 202 values = { [0] = L["Choose Method..."],
flickerstreak@87 203 [1] = L["Individually"],
flickerstreak@87 204 [2] = L["All at Once"], },
flickerstreak@87 205 get = "GetActionEditMethod",
flickerstreak@87 206 set = "SetActionEditMethod",
flickerstreak@87 207 },
flickerstreak@87 208 rowSelect = {
flickerstreak@87 209 name = L["Row"],
flickerstreak@87 210 desc = L["Rows are numbered top to bottom"],
flickerstreak@87 211 order = 2,
flickerstreak@87 212 type = "select",
flickerstreak@87 213 width = "half",
flickerstreak@87 214 hidden = "IsButtonSelectHidden",
flickerstreak@87 215 values = "GetRowList",
flickerstreak@87 216 get = "GetSelectedRow",
flickerstreak@87 217 set = "SetSelectedRow",
flickerstreak@87 218 },
flickerstreak@87 219 colSelect = {
flickerstreak@87 220 name = L["Col"],
flickerstreak@87 221 desc = L["Columns are numbered left to right"],
flickerstreak@87 222 order = 3,
flickerstreak@87 223 type = "select",
flickerstreak@87 224 width = "half",
flickerstreak@87 225 hidden = "IsButtonSelectHidden",
flickerstreak@87 226 values = "GetColumnList",
flickerstreak@87 227 get = "GetSelectedColumn",
flickerstreak@87 228 set = "SetSelectedColumn",
flickerstreak@87 229 },
flickerstreak@87 230 pageSelect = {
flickerstreak@87 231 name = L["Page"],
flickerstreak@87 232 order = 4,
flickerstreak@87 233 type = "select",
flickerstreak@87 234 width = "half",
flickerstreak@87 235 hidden = "IsPageSelectHidden",
flickerstreak@87 236 values = "GetPageList",
flickerstreak@87 237 get = "GetSelectedPage",
flickerstreak@87 238 set = "SetSelectedPage",
flickerstreak@87 239 },
flickerstreak@87 240 single = {
flickerstreak@87 241 name = L["Action ID"],
flickerstreak@87 242 usage = L["Specify ID 1-120"],
flickerstreak@87 243 order = 5,
flickerstreak@87 244 type = "input",
flickerstreak@87 245 width = "half",
flickerstreak@87 246 hidden = "IsButtonSelectHidden",
flickerstreak@87 247 get = "GetActionID",
flickerstreak@87 248 set = "SetActionID",
flickerstreak@87 249 validate = "ValidateActionID",
flickerstreak@87 250 },
flickerstreak@87 251 multi = {
flickerstreak@87 252 name = L["ID List"],
flickerstreak@87 253 usage = L["Specify a comma-separated list of IDs for each button in the bar (in order). Separate multiple pages with semicolons (;)"],
flickerstreak@87 254 order = 6,
flickerstreak@87 255 type = "input",
flickerstreak@87 256 multiline = true,
flickerstreak@87 257 width = "double",
flickerstreak@87 258 hidden = "IsMultiIDHidden",
flickerstreak@87 259 get = "GetMultiID",
flickerstreak@87 260 set = "SetMultiID",
flickerstreak@87 261 validate = "ValidateMultiID",
flickerstreak@90 262 },
flickerstreak@90 263 },
flickerstreak@87 264 },
flickerstreak@87 265 }
flickerstreak@77 266
flickerstreak@90 267 local weak = { __mode="k" }
flickerstreak@90 268 local meta = { __index = Handle }
flickerstreak@90 269
flickerstreak@90 270 function Handle:New( bar, config )
flickerstreak@90 271 local self = setmetatable(
flickerstreak@90 272 {
flickerstreak@90 273 bar = bar,
flickerstreak@90 274 config = config,
flickerstreak@90 275 btns = { }
flickerstreak@90 276 },
flickerstreak@90 277 meta)
flickerstreak@90 278
flickerstreak@90 279 if self.config.buttons == nil then
flickerstreak@90 280 self.config.buttons = { }
flickerstreak@90 281 end
flickerstreak@90 282 self:Refresh()
flickerstreak@92 283 self:SetKeybindMode(ReAction:GetKeybindMode())
flickerstreak@90 284 return self
flickerstreak@90 285 end
flickerstreak@90 286
flickerstreak@90 287 function Handle:Refresh()
flickerstreak@90 288 local r, c = self.bar:GetButtonGrid()
flickerstreak@90 289 local n = r*c
flickerstreak@90 290 local btnCfg = self.config.buttons
flickerstreak@90 291 if n ~= #self.btns then
flickerstreak@90 292 for i = 1, n do
flickerstreak@90 293 if btnCfg[i] == nil then
flickerstreak@90 294 btnCfg[i] = {}
flickerstreak@90 295 end
flickerstreak@90 296 if self.btns[i] == nil then
flickerstreak@90 297 local b = Button:New(self, i, btnCfg[i], self.config)
flickerstreak@90 298 self.btns[i] = b
flickerstreak@90 299 self.bar:AddButton(i,b)
flickerstreak@90 300 end
flickerstreak@90 301 end
flickerstreak@90 302 for i = n+1, #self.btns do
flickerstreak@90 303 if self.btns[i] then
flickerstreak@90 304 self.bar:RemoveButton(self.btns[i])
flickerstreak@90 305 self.btns[i]:Destroy()
flickerstreak@90 306 self.btns[i] = nil
flickerstreak@90 307 btnCfg[i] = nil
flickerstreak@90 308 end
flickerstreak@90 309 end
flickerstreak@90 310 end
flickerstreak@102 311 local f = self.bar:GetFrame()
flickerstreak@90 312 for _, b in ipairs(self.btns) do
flickerstreak@90 313 b:Refresh()
flickerstreak@90 314 end
flickerstreak@90 315 f:SetAttribute("mindcontrol",self.config.mindcontrol)
flickerstreak@90 316 f:Execute(
flickerstreak@90 317 [[
flickerstreak@90 318 doMindControl = self:GetAttribute("mindcontrol")
flickerstreak@90 319 control:ChildUpdate()
flickerstreak@90 320 ]])
flickerstreak@90 321
flickerstreak@90 322 f:SetAttribute("_onstate-mindcontrol",
flickerstreak@90 323 -- function _onstate-mindcontrol(self, stateid, newstate)
flickerstreak@90 324 [[
flickerstreak@90 325 control:ChildUpdate()
flickerstreak@90 326 ]])
flickerstreak@90 327 RegisterStateDriver(f, "mindcontrol", "[bonusbar:5] mc; none")
flickerstreak@102 328 self:UpdateButtonLock()
flickerstreak@90 329 end
flickerstreak@90 330
flickerstreak@90 331 function Handle:Destroy()
flickerstreak@90 332 for _,b in pairs(self.btns) do
flickerstreak@90 333 if b then
flickerstreak@90 334 b:Destroy()
flickerstreak@90 335 end
flickerstreak@90 336 end
flickerstreak@90 337 end
flickerstreak@90 338
flickerstreak@90 339 function Handle:SetConfigMode(mode)
flickerstreak@90 340 for _, b in pairs(self.btns) do
flickerstreak@90 341 b:ShowGrid(mode)
flickerstreak@90 342 b:ShowActionIDLabel(mode)
flickerstreak@90 343 end
flickerstreak@90 344 end
flickerstreak@90 345
flickerstreak@93 346 function Handle:ShowGrid(show)
flickerstreak@93 347 for _, b in pairs(self.btns) do
flickerstreak@93 348 b:ShowGrid(show)
flickerstreak@93 349 end
flickerstreak@93 350 end
flickerstreak@93 351
flickerstreak@102 352 function Handle:UpdateButtonLock()
flickerstreak@102 353 local f = self.bar:GetFrame()
flickerstreak@102 354 f:SetAttribute("lockbuttons",self.config.lockButtons)
flickerstreak@102 355 f:SetAttribute("lockbuttonscombat",self.config.lockButtonsCombat)
flickerstreak@102 356 f:Execute(
flickerstreak@102 357 [[
flickerstreak@102 358 lockButtons = self:GetAttribute("lockbuttons")
flickerstreak@102 359 lockButtonsCombat = self:GetAttribute("lockbuttonscombat")
flickerstreak@102 360 ]])
flickerstreak@102 361 end
flickerstreak@102 362
flickerstreak@90 363 function Handle:SetKeybindMode(mode)
flickerstreak@90 364 for _, b in pairs(self.btns) do
flickerstreak@90 365 if mode then
flickerstreak@90 366 -- set the border for all buttons to the keybind-enable color
flickerstreak@92 367 b.border:SetVertexColor(KB:GetColorKeyBoundMode())
flickerstreak@90 368 b.border:Show()
flickerstreak@92 369 elseif IsEquippedAction(b:GetActionID()) then
flickerstreak@92 370 b.border:SetVertexColor(0, 1.0, 0, 0.35) -- from ActionButton.lua
flickerstreak@90 371 else
flickerstreak@90 372 b.border:Hide()
flickerstreak@90 373 end
flickerstreak@90 374 end
flickerstreak@90 375 end
flickerstreak@90 376
flickerstreak@90 377 function Handle:GetLastButton()
flickerstreak@90 378 return self.btns[#self.btns]
flickerstreak@90 379 end
flickerstreak@90 380
flickerstreak@90 381 -- options handlers
flickerstreak@90 382 function Handle:GetOptions()
flickerstreak@87 383 return {
flickerstreak@87 384 type = "group",
flickerstreak@87 385 name = L["Action Buttons"],
flickerstreak@90 386 handler = self,
flickerstreak@87 387 args = options
flickerstreak@87 388 }
flickerstreak@77 389 end
flickerstreak@77 390
flickerstreak@90 391 function Handle:SetHideEmpty(info, value)
flickerstreak@90 392 if value ~= self.config.hideEmpty then
flickerstreak@90 393 self.config.hideEmpty = value
flickerstreak@102 394 self:ShowGrid(not value)
flickerstreak@77 395 end
flickerstreak@77 396 end
flickerstreak@77 397
flickerstreak@90 398 function Handle:GetHideEmpty()
flickerstreak@90 399 return self.config.hideEmpty
flickerstreak@77 400 end
flickerstreak@87 401
flickerstreak@102 402 function Handle:GetLockButtons()
flickerstreak@102 403 return LOCK_ACTIONBAR == "1" or self.config.lockButtons
flickerstreak@102 404 end
flickerstreak@102 405
flickerstreak@102 406 function Handle:SetLockButtons(info, value)
flickerstreak@102 407 self.config.lockButtons = value
flickerstreak@102 408 self:UpdateButtonLock()
flickerstreak@102 409 end
flickerstreak@102 410
flickerstreak@102 411 function Handle:LockButtonsDisabled()
flickerstreak@102 412 return LOCK_ACTIONBAR == "1"
flickerstreak@102 413 end
flickerstreak@102 414
flickerstreak@102 415 function Handle:GetLockButtonsCombat()
flickerstreak@102 416 return self.config.lockButtonsCombat
flickerstreak@102 417 end
flickerstreak@102 418
flickerstreak@102 419 function Handle:SetLockButtonsCombat(info, value)
flickerstreak@102 420 self.config.lockButtonsCombat = value
flickerstreak@102 421 self:UpdateButtonLock()
flickerstreak@102 422 end
flickerstreak@102 423
flickerstreak@102 424 function Handle:LockButtonsCombatDisabled()
flickerstreak@102 425 return LOCK_ACTIONBAR == "1" or not self.config.lockButtons
flickerstreak@102 426 end
flickerstreak@102 427
flickerstreak@90 428 function Handle:GetNumPages()
flickerstreak@90 429 return self.config.nPages
flickerstreak@87 430 end
flickerstreak@87 431
flickerstreak@90 432 function Handle:SetNumPages(info, value)
flickerstreak@90 433 self.config.nPages = value
flickerstreak@90 434 self:Refresh()
flickerstreak@87 435 end
flickerstreak@87 436
flickerstreak@90 437 function Handle:GetMindControl()
flickerstreak@90 438 return self.config.mindcontrol
flickerstreak@90 439 end
flickerstreak@90 440
flickerstreak@90 441 function Handle:SetMindControl(info, value)
flickerstreak@90 442 self.config.mindcontrol = value
flickerstreak@90 443 self:Refresh()
flickerstreak@90 444 end
flickerstreak@90 445
flickerstreak@90 446 function Handle:GetActionEditMethod()
flickerstreak@87 447 return self.editMethod or 0
flickerstreak@87 448 end
flickerstreak@87 449
flickerstreak@90 450 function Handle:SetActionEditMethod(info, value)
flickerstreak@87 451 self.editMethod = value
flickerstreak@87 452 end
flickerstreak@87 453
flickerstreak@90 454 function Handle:IsButtonSelectHidden()
flickerstreak@87 455 return self.editMethod ~= 1
flickerstreak@87 456 end
flickerstreak@87 457
flickerstreak@90 458 function Handle:GetRowList()
flickerstreak@87 459 local r,c = self.bar:GetButtonGrid()
flickerstreak@87 460 if self.rowList == nil or #self.rowList ~= r then
flickerstreak@87 461 local list = { }
flickerstreak@87 462 for i = 1, r do
flickerstreak@87 463 table.insert(list,i)
flickerstreak@87 464 end
flickerstreak@87 465 self.rowList = list
flickerstreak@87 466 end
flickerstreak@87 467 return self.rowList
flickerstreak@87 468 end
flickerstreak@87 469
flickerstreak@90 470 function Handle:GetSelectedRow()
flickerstreak@87 471 local r, c = self.bar:GetButtonGrid()
flickerstreak@87 472 local row = self.selectedRow or 1
flickerstreak@87 473 if row > r then
flickerstreak@87 474 row = 1
flickerstreak@87 475 end
flickerstreak@87 476 self.selectedRow = row
flickerstreak@87 477 return row
flickerstreak@87 478 end
flickerstreak@87 479
flickerstreak@90 480 function Handle:SetSelectedRow(info, value)
flickerstreak@87 481 self.selectedRow = value
flickerstreak@87 482 end
flickerstreak@87 483
flickerstreak@90 484 function Handle:GetColumnList()
flickerstreak@87 485 local r,c = self.bar:GetButtonGrid()
flickerstreak@87 486 if self.columnList == nil or #self.columnList ~= c then
flickerstreak@87 487 local list = { }
flickerstreak@87 488 for i = 1, c do
flickerstreak@87 489 table.insert(list,i)
flickerstreak@87 490 end
flickerstreak@87 491 self.columnList = list
flickerstreak@87 492 end
flickerstreak@87 493 return self.columnList
flickerstreak@87 494 end
flickerstreak@87 495
flickerstreak@90 496 function Handle:GetSelectedColumn()
flickerstreak@87 497 local r, c = self.bar:GetButtonGrid()
flickerstreak@87 498 local col = self.selectedColumn or 1
flickerstreak@87 499 if col > c then
flickerstreak@87 500 col = 1
flickerstreak@87 501 end
flickerstreak@87 502 self.selectedColumn = col
flickerstreak@87 503 return col
flickerstreak@87 504 end
flickerstreak@87 505
flickerstreak@90 506 function Handle:SetSelectedColumn(info, value)
flickerstreak@87 507 self.selectedColumn = value
flickerstreak@87 508 end
flickerstreak@87 509
flickerstreak@90 510 function Handle:IsPageSelectHidden()
flickerstreak@90 511 return self.editMethod ~= 1 or (self.config.nPages or 1) < 2
flickerstreak@87 512 end
flickerstreak@87 513
flickerstreak@90 514 function Handle:GetPageList()
flickerstreak@90 515 local n = self.config.nPages or 1
flickerstreak@87 516 if self.pageList == nil or #self.pageList ~= n then
flickerstreak@87 517 local p = { }
flickerstreak@87 518 for i = 1, n do
flickerstreak@87 519 table.insert(p,i)
flickerstreak@87 520 end
flickerstreak@87 521 self.pageList = p
flickerstreak@87 522 end
flickerstreak@87 523 return self.pageList
flickerstreak@87 524 end
flickerstreak@87 525
flickerstreak@90 526 function Handle:GetSelectedPage()
flickerstreak@87 527 local p = self.selectedPage or 1
flickerstreak@90 528 if p > (self.config.nPages or 1) then
flickerstreak@87 529 p = 1
flickerstreak@87 530 end
flickerstreak@87 531 self.selectedPage = p
flickerstreak@87 532 return p
flickerstreak@87 533 end
flickerstreak@87 534
flickerstreak@90 535 function Handle:SetSelectedPage(info, value)
flickerstreak@87 536 self.selectedPage = value
flickerstreak@87 537 end
flickerstreak@87 538
flickerstreak@90 539 function Handle:GetActionID()
flickerstreak@87 540 local row = self.selectedRow or 1
flickerstreak@87 541 local col = self.selectedColumn or 1
flickerstreak@87 542 local r, c = self.bar:GetButtonGrid()
flickerstreak@87 543 local n = (row-1) * c + col
flickerstreak@90 544 local btn = self.btns[n]
flickerstreak@87 545 if btn then
flickerstreak@87 546 return tostring(btn:GetActionID(self.selectedPage or 1))
flickerstreak@87 547 end
flickerstreak@87 548 end
flickerstreak@87 549
flickerstreak@90 550 function Handle:SetActionID(info, value)
flickerstreak@87 551 local row = self.selectedRow or 1
flickerstreak@87 552 local col = self.selectedColumn or 1
flickerstreak@87 553 local r, c = self.bar:GetButtonGrid()
flickerstreak@87 554 local n = (row-1) * c + col
flickerstreak@90 555 local btn = self.btns[n]
flickerstreak@87 556 if btn then
flickerstreak@87 557 btn:SetActionID(tonumber(value), self.selectedPage or 1)
flickerstreak@87 558 end
flickerstreak@87 559 end
flickerstreak@87 560
flickerstreak@90 561 function Handle:ValidateActionID(info, value)
flickerstreak@87 562 value = tonumber(value)
flickerstreak@87 563 if value == nil or value < 1 or value > 120 then
flickerstreak@87 564 return L["Specify ID 1-120"]
flickerstreak@87 565 end
flickerstreak@87 566 return true
flickerstreak@87 567 end
flickerstreak@87 568
flickerstreak@90 569 function Handle:IsMultiIDHidden()
flickerstreak@87 570 return self.editMethod ~= 2
flickerstreak@87 571 end
flickerstreak@87 572
flickerstreak@90 573 function Handle:GetMultiID()
flickerstreak@87 574 local p = { }
flickerstreak@90 575 for i = 1, self.config.nPages or 1 do
flickerstreak@87 576 local b = { }
flickerstreak@90 577 for _, btn in ipairs(self.btns) do
flickerstreak@87 578 table.insert(b, btn:GetActionID(i))
flickerstreak@87 579 end
flickerstreak@87 580 table.insert(p, table.concat(b,","))
flickerstreak@87 581 end
flickerstreak@87 582 return table.concat(p,";\n")
flickerstreak@87 583 end
flickerstreak@87 584
flickerstreak@87 585
flickerstreak@87 586 local function ParseMultiID(nBtns, nPages, s)
flickerstreak@87 587 if s:match("[^%d%s,;]") then
flickerstreak@87 588 ReAction:Print("items other than digits, spaces, commas, and semicolons in string",s)
flickerstreak@87 589 return nil
flickerstreak@87 590 end
flickerstreak@87 591 local p = { }
flickerstreak@87 592 for list in s:gmatch("[^;]+") do
flickerstreak@87 593 local pattern = ("^%s?$"):format(("%s*(%d+)%s*,"):rep(nBtns))
flickerstreak@87 594 local ids = { list:match(pattern) }
flickerstreak@87 595 if #ids ~= nBtns then
flickerstreak@87 596 ReAction:Print("found",#ids,"buttons instead of",nBtns)
flickerstreak@87 597 return nil
flickerstreak@87 598 end
flickerstreak@87 599 table.insert(p,ids)
flickerstreak@87 600 end
flickerstreak@87 601 if #p ~= nPages then
flickerstreak@87 602 ReAction:Print("found",#p,"pages instead of",nPages)
flickerstreak@87 603 return nil
flickerstreak@87 604 end
flickerstreak@87 605 return p
flickerstreak@87 606 end
flickerstreak@87 607
flickerstreak@90 608 function Handle:SetMultiID(info, value)
flickerstreak@91 609 local p = ParseMultiID(#self.btns, self.config.nPages or 1, value)
flickerstreak@87 610 for page, b in ipairs(p) do
flickerstreak@87 611 for button, id in ipairs(b) do
flickerstreak@90 612 self.btns[button]:SetActionID(id, page)
flickerstreak@87 613 end
flickerstreak@87 614 end
flickerstreak@87 615 end
flickerstreak@87 616
flickerstreak@90 617 function Handle:ValidateMultiID(info, value)
flickerstreak@87 618 local bad = L["Invalid action ID list string"]
flickerstreak@90 619 if value == nil or ParseMultiID(#self.btns, self.config.nPages or 1, value) == nil then
flickerstreak@87 620 return bad
flickerstreak@87 621 end
flickerstreak@87 622 return true
flickerstreak@87 623 end
flickerstreak@77 624 end
flickerstreak@77 625
flickerstreak@77 626
flickerstreak@87 627 ------ State property options ------
flickerstreak@87 628 do
flickerstreak@87 629 local pageOptions = {
flickerstreak@87 630 page = {
flickerstreak@92 631 name = L["Show Page #"],
flickerstreak@92 632 order = 11,
flickerstreak@92 633 type = "select",
flickerstreak@92 634 width = "half",
flickerstreak@87 635 disabled = "IsPageDisabled",
flickerstreak@87 636 hidden = "IsPageHidden",
flickerstreak@87 637 values = "GetPageValues",
flickerstreak@87 638 set = "SetProp",
flickerstreak@87 639 get = "GetPage",
flickerstreak@87 640 },
flickerstreak@87 641 }
flickerstreak@50 642
flickerstreak@90 643 local function GetBarConfig(bar)
flickerstreak@90 644 return module.db.profile.bars[bar:GetName()]
flickerstreak@87 645 end
flickerstreak@87 646
flickerstreak@90 647 function PropHandler.GetOptions()
flickerstreak@90 648 return pageOptions
flickerstreak@87 649 end
flickerstreak@87 650
flickerstreak@90 651 function PropHandler:IsPageDisabled()
flickerstreak@90 652 local c = GetBarConfig(self.bar)
flickerstreak@90 653 local n = c and c.nPages or 1
flickerstreak@90 654 return not (n > 1)
flickerstreak@87 655 end
flickerstreak@87 656
flickerstreak@90 657 function PropHandler:IsPageHidden()
flickerstreak@87 658 return not GetBarConfig(self.bar)
flickerstreak@87 659 end
flickerstreak@87 660
flickerstreak@90 661 function PropHandler:GetPageValues()
flickerstreak@92 662 if not self._pagevalues then
flickerstreak@92 663 self._pagevalues = { }
flickerstreak@92 664 end
flickerstreak@87 665 local c = GetBarConfig(self.bar)
flickerstreak@87 666 if c then
flickerstreak@87 667 local n = c.nPages
flickerstreak@92 668 -- cache the results
flickerstreak@87 669 if self._npages ~= n then
flickerstreak@87 670 self._npages = n
flickerstreak@92 671 wipe(self._pagevalues)
flickerstreak@87 672 for i = 1, n do
flickerstreak@90 673 self._pagevalues["page"..i] = i
flickerstreak@87 674 end
flickerstreak@87 675 end
flickerstreak@87 676 end
flickerstreak@92 677 return self._pagevalues
flickerstreak@87 678 end
flickerstreak@87 679
flickerstreak@90 680 function PropHandler:GetPage(info)
flickerstreak@87 681 return self:GetProp(info) or 1
flickerstreak@87 682 end
flickerstreak@90 683
flickerstreak@87 684 end
flickerstreak@87 685
flickerstreak@87 686 ------ ActionID allocation ------
flickerstreak@87 687 -- this needs to be high performance when requesting new IDs,
flickerstreak@87 688 -- or certain controls will become sluggish. However, the new-request
flickerstreak@87 689 -- infrastructure can be built lazily the first time that a new request
flickerstreak@87 690 -- comes in (which will only happen at user config time: at static startup
flickerstreak@87 691 -- config time all actionIDs should already have been assigned and stored
flickerstreak@87 692 -- in the config file)
flickerstreak@87 693
flickerstreak@87 694 local IDAlloc
flickerstreak@87 695 do
flickerstreak@87 696 local n = 120
flickerstreak@87 697
flickerstreak@87 698 IDAlloc = setmetatable({ wrap = 1, freecount = n }, {__index = function() return 0 end})
flickerstreak@87 699
flickerstreak@87 700 function IDAlloc:Acquire(id, hint)
flickerstreak@87 701 id = tonumber(id)
flickerstreak@87 702 hint = tonumber(hint)
flickerstreak@87 703 if id and (id < 1 or id > n) then
flickerstreak@87 704 id = nil
flickerstreak@87 705 end
flickerstreak@87 706 if hint and (hint < 1 or hint > n) then
flickerstreak@87 707 hint = nil
flickerstreak@87 708 end
flickerstreak@87 709 if id == nil then
flickerstreak@87 710 -- get a free ID
flickerstreak@87 711 if hint and self[hint] == 0 then
flickerstreak@87 712 -- use the hint if it's free
flickerstreak@87 713 id = hint
flickerstreak@87 714 elseif self.freecount > 0 then
flickerstreak@87 715 -- if neither the id nor the hint are defined or free, but
flickerstreak@87 716 -- the list is known to have free IDs, then start searching
flickerstreak@87 717 -- at the hint for a free one
flickerstreak@87 718 for i = hint or 1, n do
flickerstreak@87 719 if self[i] == 0 then
flickerstreak@87 720 id = i
flickerstreak@87 721 break
flickerstreak@87 722 end
flickerstreak@87 723 end
flickerstreak@87 724 -- self.wrap the search
flickerstreak@87 725 if id == nil and hint and hint > 1 then
flickerstreak@87 726 for i = 1, hint - 1 do
flickerstreak@87 727 if self[i] == 0 then
flickerstreak@87 728 id = i
flickerstreak@87 729 break
flickerstreak@87 730 end
flickerstreak@87 731 end
flickerstreak@87 732 end
flickerstreak@87 733 end
flickerstreak@87 734 if id == nil then
flickerstreak@87 735 -- if there are no free IDs, start wrapping at 1
flickerstreak@87 736 id = self.wrap
flickerstreak@87 737 self.wrap = id + 1
flickerstreak@87 738 if self.wrap > n then
flickerstreak@87 739 self.wrap = 1
flickerstreak@87 740 end
flickerstreak@24 741 end
flickerstreak@24 742 end
flickerstreak@87 743 if self[id] == 0 then
flickerstreak@87 744 self.freecount = self.freecount - 1
flickerstreak@87 745 end
flickerstreak@87 746 self[id] = self[id] + 1
flickerstreak@87 747 return id
flickerstreak@24 748 end
flickerstreak@24 749
flickerstreak@87 750 function IDAlloc:Release(id)
flickerstreak@87 751 id = tonumber(id)
flickerstreak@87 752 if id and (id >= 1 or id <= n) then
flickerstreak@87 753 self[id] = self[id] - 1
flickerstreak@87 754 if self[id] == 0 then
flickerstreak@87 755 self.freecount = self.freecount + 1
flickerstreak@87 756 self.wrap = 1
flickerstreak@87 757 end
flickerstreak@87 758 end
flickerstreak@87 759 end
flickerstreak@87 760 end
flickerstreak@87 761
flickerstreak@88 762 ------ Button class ------
flickerstreak@88 763
flickerstreak@88 764 do
flickerstreak@90 765 local frameRecycler = { }
flickerstreak@90 766 local trash = CreateFrame("Frame")
flickerstreak@90 767 local OnUpdate, KBAttach, GetActionName, GetHotkey, SetKey, FreeKey, ClearBindings, GetBindings
flickerstreak@90 768 do
flickerstreak@90 769 local ATTACK_BUTTON_FLASH_TIME = ATTACK_BUTTON_FLASH_TIME
flickerstreak@90 770 local IsActionInRange = IsActionInRange
flickerstreak@87 771
flickerstreak@90 772 local buttonLookup = setmetatable({},{__mode="kv"})
flickerstreak@88 773
flickerstreak@90 774 function OnUpdate(frame, elapsed)
flickerstreak@90 775 -- note: This function taints frame.flashtime and frame.rangeTimer. Both of these
flickerstreak@90 776 -- are only read by ActionButton_OnUpdate (which this function replaces). In
flickerstreak@90 777 -- all other places they're just written, so it doesn't taint any secure code.
flickerstreak@90 778 if frame.flashing == 1 then
flickerstreak@90 779 frame.flashtime = frame.flashtime - elapsed
flickerstreak@90 780 if frame.flashtime <= 0 then
flickerstreak@90 781 local overtime = -frame.flashtime
flickerstreak@90 782 if overtime >= ATTACK_BUTTON_FLASH_TIME then
flickerstreak@90 783 overtime = 0
flickerstreak@90 784 end
flickerstreak@90 785 frame.flashtime = ATTACK_BUTTON_FLASH_TIME - overtime
flickerstreak@90 786
flickerstreak@90 787 local flashTexture = frame.flash
flickerstreak@90 788 if flashTexture:IsShown() then
flickerstreak@90 789 flashTexture:Hide()
flickerstreak@90 790 else
flickerstreak@90 791 flashTexture:Show()
flickerstreak@90 792 end
flickerstreak@88 793 end
flickerstreak@90 794 end
flickerstreak@90 795
flickerstreak@90 796 if frame.rangeTimer then
flickerstreak@90 797 frame.rangeTimer = frame.rangeTimer - elapsed;
flickerstreak@88 798
flickerstreak@90 799 if frame.rangeTimer <= 0 then
flickerstreak@90 800 if IsActionInRange(frame.action) == 0 then
flickerstreak@90 801 frame.icon:SetVertexColor(1.0,0.1,0.1)
flickerstreak@90 802 else
flickerstreak@90 803 ActionButton_UpdateUsable(frame)
flickerstreak@90 804 end
flickerstreak@90 805 frame.rangeTimer = 0.1
flickerstreak@88 806 end
flickerstreak@88 807 end
flickerstreak@88 808 end
flickerstreak@90 809
flickerstreak@90 810 -- Use KeyBound-1.0 for binding, but use Override bindings instead of
flickerstreak@90 811 -- regular bindings to support multiple profile use. This is a little
flickerstreak@90 812 -- weird with the KeyBound dialog box (which has per-char selector as well
flickerstreak@90 813 -- as an OK/Cancel box) but it's the least amount of effort to implement.
flickerstreak@90 814 function GetActionName(f)
flickerstreak@90 815 local b = buttonLookup[f]
flickerstreak@90 816 if b then
flickerstreak@90 817 return format("%s:%s", b.bar:GetName(), b.idx)
flickerstreak@90 818 end
flickerstreak@90 819 end
flickerstreak@90 820
flickerstreak@90 821 function GetHotkey(f)
flickerstreak@90 822 local b = buttonLookup[f]
flickerstreak@90 823 if b then
flickerstreak@90 824 return KB:ToShortKey(b:GetConfig().hotkey)
flickerstreak@90 825 end
flickerstreak@90 826 end
flickerstreak@90 827
flickerstreak@90 828 function SetKey(f, key)
flickerstreak@90 829 local b = buttonLookup[f]
flickerstreak@90 830 if b then
flickerstreak@90 831 local c = b:GetConfig()
flickerstreak@90 832 if c.hotkey then
flickerstreak@90 833 SetOverrideBinding(f, false, c.hotkey, nil)
flickerstreak@90 834 end
flickerstreak@90 835 if key then
flickerstreak@90 836 SetOverrideBindingClick(f, false, key, f:GetName(), nil)
flickerstreak@90 837 end
flickerstreak@90 838 c.hotkey = key
flickerstreak@90 839 b:DisplayHotkey(GetHotkey(f))
flickerstreak@90 840 end
flickerstreak@90 841 end
flickerstreak@90 842
flickerstreak@90 843 function FreeKey(f, key)
flickerstreak@90 844 local b = buttonLookup[f]
flickerstreak@90 845 if b then
flickerstreak@90 846 local c = b:GetConfig()
flickerstreak@90 847 if c.hotkey == key then
flickerstreak@90 848 local action = f:GetActionName()
flickerstreak@90 849 SetOverrideBinding(f, false, c.hotkey, nil)
flickerstreak@90 850 c.hotkey = nil
flickerstreak@90 851 b:DisplayHotkey(nil)
flickerstreak@90 852 return action
flickerstreak@90 853 end
flickerstreak@90 854 end
flickerstreak@90 855 return ReAction:FreeOverrideHotkey(key)
flickerstreak@90 856 end
flickerstreak@90 857
flickerstreak@90 858 function ClearBindings(f)
flickerstreak@90 859 SetKey(f, nil)
flickerstreak@90 860 end
flickerstreak@90 861
flickerstreak@90 862 function GetBindings(f)
flickerstreak@90 863 local b = buttonLookup[f]
flickerstreak@90 864 if b then
flickerstreak@90 865 return b:GetConfig().hotkey
flickerstreak@90 866 end
flickerstreak@90 867 end
flickerstreak@90 868
flickerstreak@90 869 function KBAttach( button )
flickerstreak@90 870 local f = button:GetFrame()
flickerstreak@90 871 f.GetActionName = GetActionName
flickerstreak@90 872 f.GetHotkey = GetHotkey
flickerstreak@90 873 f.SetKey = SetKey
flickerstreak@90 874 f.FreeKey = FreeKey
flickerstreak@90 875 f.ClearBindings = ClearBindings
flickerstreak@90 876 f.GetBindings = GetBindings
flickerstreak@90 877 buttonLookup[f] = button
flickerstreak@90 878 f:SetKey(button:GetConfig().hotkey)
flickerstreak@90 879 ReAction:RegisterKeybindFrame(f)
flickerstreak@92 880 if ReAction:GetKeybindMode() then
flickerstreak@92 881 button.border:SetVertexColor(KB:GetColorKeyBoundMode())
flickerstreak@92 882 button.border:Show()
flickerstreak@92 883 end
flickerstreak@90 884 end
flickerstreak@90 885 end
flickerstreak@90 886
flickerstreak@90 887 local meta = {__index = Button}
flickerstreak@90 888
flickerstreak@90 889 function Button:New( handle, idx, config, barConfig )
flickerstreak@90 890 local bar = handle.bar
flickerstreak@90 891
flickerstreak@90 892 -- create new self
flickerstreak@90 893 self = setmetatable(
flickerstreak@90 894 {
flickerstreak@90 895 bar = bar,
flickerstreak@90 896 idx = idx,
flickerstreak@90 897 config = config,
flickerstreak@90 898 barConfig = barConfig,
flickerstreak@90 899 }, meta )
flickerstreak@90 900
flickerstreak@90 901 local name = config.name or ("ReAction_%s_%s_%d"):format(bar:GetName(),moduleID,idx)
flickerstreak@90 902 self.name = name
flickerstreak@90 903 config.name = name
flickerstreak@90 904 local lastButton = handle:GetLastButton()
flickerstreak@90 905 config.actionID = IDAlloc:Acquire(config.actionID, lastButton and lastButton.config.actionID) -- gets a free one if none configured
flickerstreak@90 906 self.nPages = 1
flickerstreak@88 907
flickerstreak@90 908 -- have to recycle frames with the same name: CreateFrame() doesn't overwrite
flickerstreak@90 909 -- existing globals. Can't set to nil in the global because it's then tainted.
flickerstreak@90 910 local parent = bar:GetFrame()
flickerstreak@90 911 local f = frameRecycler[name]
flickerstreak@90 912 if f then
flickerstreak@90 913 f:SetParent(parent)
flickerstreak@90 914 else
flickerstreak@90 915 f = CreateFrame("CheckButton", name, parent, "ActionBarButtonTemplate")
flickerstreak@90 916 -- ditch the old hotkey text because it's tied in ActionButton_Update() to the
flickerstreak@90 917 -- standard binding. We use override bindings.
flickerstreak@90 918 local hotkey = _G[name.."HotKey"]
flickerstreak@90 919 hotkey:SetParent(trash)
flickerstreak@90 920 hotkey = f:CreateFontString(nil, "ARTWORK", "NumberFontNormalSmallGray")
flickerstreak@90 921 hotkey:SetWidth(36)
flickerstreak@90 922 hotkey:SetHeight(18)
flickerstreak@90 923 hotkey:SetJustifyH("RIGHT")
flickerstreak@90 924 hotkey:SetJustifyV("TOP")
flickerstreak@90 925 hotkey:SetPoint("TOPLEFT",f,"TOPLEFT",-2,-2)
flickerstreak@90 926 f.hotkey = hotkey
flickerstreak@90 927 f.icon = _G[name.."Icon"]
flickerstreak@90 928 f.flash = _G[name.."Flash"]
flickerstreak@90 929 f:SetScript("OnUpdate",OnUpdate)
flickerstreak@90 930 end
flickerstreak@88 931
flickerstreak@90 932 self.hotkey = f.hotkey
flickerstreak@90 933 self.border = _G[name.."Border"]
flickerstreak@90 934
flickerstreak@90 935 f:SetAttribute("action", config.actionID)
flickerstreak@90 936 -- install mind control actions for all buttons just for simplicity
flickerstreak@90 937 if self.idx <= 12 then
flickerstreak@90 938 f:SetAttribute("*action-mc", 120 + self.idx)
flickerstreak@90 939 end
flickerstreak@90 940
flickerstreak@90 941 -- set a _childupdate handler, called within the header's context
flickerstreak@90 942 f:SetAttribute("_childupdate",
flickerstreak@90 943 -- function _childupdate(self, snippetid, message)
flickerstreak@90 944 [[
flickerstreak@90 945 local action = "action"
flickerstreak@90 946 if doMindControl and GetBonusBarOffset() == 5 then
flickerstreak@90 947 action = "*action-mc"
flickerstreak@90 948 elseif page and state and page[state] then
flickerstreak@90 949 action = "*action-"..page[state]
flickerstreak@90 950 end
flickerstreak@90 951 local value = self:GetAttribute(action)
flickerstreak@92 952 self:SetAttribute("action",value)
flickerstreak@90 953 ]])
flickerstreak@90 954
flickerstreak@102 955 -- install drag wrappers to lock buttons
flickerstreak@102 956 bar:GetFrame():WrapScript(f, "OnDragStart",
flickerstreak@102 957 -- OnDragStart(self, button, kind, value, ...)
flickerstreak@102 958 [[
flickerstreak@102 959 if lockButtons and (PlayerInCombat() or not lockButtonsCombat) and not IsModifiedClick("PICKUPACTION") then
flickerstreak@102 960 return "clear"
flickerstreak@102 961 end
flickerstreak@102 962 ]])
flickerstreak@102 963
flickerstreak@90 964 self.frame = f
flickerstreak@90 965 self.normalTexture = getglobal(format("%sNormalTexture",f:GetName()))
flickerstreak@90 966
flickerstreak@90 967 -- initialize the hide state
flickerstreak@90 968 f:SetAttribute("showgrid",0)
flickerstreak@90 969 self:ShowGrid(not barConfig.hideEmpty)
flickerstreak@90 970 if ReAction:GetConfigMode() then
flickerstreak@90 971 self:ShowGrid(true)
flickerstreak@90 972 end
flickerstreak@90 973
flickerstreak@90 974 -- show the ID label if applicable
flickerstreak@90 975 self:ShowActionIDLabel(ReAction:GetConfigMode())
flickerstreak@90 976
flickerstreak@90 977 -- attach the keybinder
flickerstreak@90 978 KBAttach(self)
flickerstreak@90 979
flickerstreak@90 980 self:Refresh()
flickerstreak@90 981 return self
flickerstreak@90 982 end
flickerstreak@90 983
flickerstreak@90 984 function Button:Destroy()
flickerstreak@90 985 local f = self.frame
flickerstreak@90 986 f:UnregisterAllEvents()
flickerstreak@90 987 f:Hide()
flickerstreak@90 988 f:SetParent(UIParent)
flickerstreak@90 989 f:ClearAllPoints()
flickerstreak@90 990 if self.name then
flickerstreak@90 991 frameRecycler[self.name] = f
flickerstreak@90 992 end
flickerstreak@90 993 if self.config.actionID then
flickerstreak@90 994 IDAlloc:Release(self.config.actionID)
flickerstreak@90 995 end
flickerstreak@90 996 if self.config.pageactions then
flickerstreak@90 997 for _, id in ipairs(self.config.pageactions) do
flickerstreak@90 998 IDAlloc:Release(id)
flickerstreak@90 999 end
flickerstreak@90 1000 end
flickerstreak@90 1001 self.frame = nil
flickerstreak@90 1002 self.config = nil
flickerstreak@90 1003 self.bar = nil
flickerstreak@90 1004 end
flickerstreak@90 1005
flickerstreak@90 1006 function Button:Refresh()
flickerstreak@90 1007 local f = self.frame
flickerstreak@90 1008 self.bar:PlaceButton(self, 36, 36)
flickerstreak@90 1009 self:RefreshPages()
flickerstreak@90 1010 end
flickerstreak@90 1011
flickerstreak@90 1012 function Button:GetFrame()
flickerstreak@90 1013 return self.frame
flickerstreak@90 1014 end
flickerstreak@90 1015
flickerstreak@90 1016 function Button:GetName()
flickerstreak@90 1017 return self.name
flickerstreak@90 1018 end
flickerstreak@90 1019
flickerstreak@90 1020 function Button:GetConfig()
flickerstreak@90 1021 return self.config
flickerstreak@90 1022 end
flickerstreak@90 1023
flickerstreak@90 1024 function Button:GetActionID(page)
flickerstreak@90 1025 if page == nil then
flickerstreak@90 1026 -- get the effective ID
flickerstreak@90 1027 return self.frame.action -- kept up-to-date by Blizzard's ActionButton_CalculateAction()
flickerstreak@90 1028 else
flickerstreak@90 1029 if page == 1 then
flickerstreak@90 1030 return self.config.actionID
flickerstreak@90 1031 else
flickerstreak@90 1032 return self.config.pageactions and self.config.pageactions[page] or self.config.actionID
flickerstreak@88 1033 end
flickerstreak@88 1034 end
flickerstreak@88 1035 end
flickerstreak@88 1036
flickerstreak@90 1037 function Button:SetActionID( id, page )
flickerstreak@90 1038 id = tonumber(id)
flickerstreak@90 1039 page = tonumber(page)
flickerstreak@90 1040 if id == nil or id < 1 or id > 120 then
flickerstreak@90 1041 error("Button:SetActionID - invalid action ID")
flickerstreak@90 1042 end
flickerstreak@90 1043 if page and page ~= 1 then
flickerstreak@90 1044 if not self.config.pageactions then
flickerstreak@90 1045 self.config.pageactions = { }
flickerstreak@90 1046 end
flickerstreak@90 1047 if self.config.pageactions[page] then
flickerstreak@90 1048 IDAlloc:Release(self.config.pageactions[page])
flickerstreak@90 1049 end
flickerstreak@90 1050 self.config.pageactions[page] = id
flickerstreak@90 1051 IDAlloc:Acquire(self.config.pageactions[page])
flickerstreak@90 1052 self.frame:SetAttribute(("*action-page%d"):format(page),id)
flickerstreak@90 1053 else
flickerstreak@90 1054 IDAlloc:Release(self.config.actionID)
flickerstreak@90 1055 self.config.actionID = id
flickerstreak@90 1056 IDAlloc:Acquire(self.config.actionID)
flickerstreak@90 1057 self.frame:SetAttribute("action",id)
flickerstreak@90 1058 if self.config.pageactions then
flickerstreak@90 1059 self.config.pageactions[1] = id
flickerstreak@90 1060 self.frame:SetAttribute("*action-page1",id)
flickerstreak@90 1061 end
flickerstreak@88 1062 end
flickerstreak@88 1063 end
flickerstreak@88 1064
flickerstreak@90 1065 function Button:RefreshPages( force )
flickerstreak@90 1066 local nPages = self.barConfig.nPages
flickerstreak@90 1067 if nPages and (nPages ~= self.nPages or force) then
flickerstreak@90 1068 local f = self:GetFrame()
flickerstreak@90 1069 local c = self.config.pageactions
flickerstreak@90 1070 if nPages > 1 and not c then
flickerstreak@90 1071 c = { }
flickerstreak@90 1072 self.config.pageactions = c
flickerstreak@90 1073 end
flickerstreak@90 1074 for i = 1, nPages do
flickerstreak@90 1075 if i > 1 then
flickerstreak@90 1076 c[i] = IDAlloc:Acquire(c[i], self.config.actionID + (i-1)*self.bar:GetNumButtons())
flickerstreak@90 1077 else
flickerstreak@90 1078 c[i] = self.config.actionID -- page 1 is the same as the base actionID
flickerstreak@90 1079 end
flickerstreak@90 1080 f:SetAttribute(("*action-page%d"):format(i),c[i])
flickerstreak@90 1081 end
flickerstreak@90 1082 for i = nPages+1, #c do
flickerstreak@90 1083 IDAlloc:Release(c[i])
flickerstreak@90 1084 c[i] = nil
flickerstreak@90 1085 f:SetAttribute(("*action-page%d"):format(i),nil)
flickerstreak@90 1086 end
flickerstreak@90 1087 self.nPages = nPages
flickerstreak@88 1088 end
flickerstreak@88 1089 end
flickerstreak@88 1090
flickerstreak@90 1091 function Button:ShowGrid( show )
flickerstreak@90 1092 if not InCombatLockdown() then
flickerstreak@90 1093 local f = self.frame
flickerstreak@90 1094 local count = f:GetAttribute("showgrid")
flickerstreak@90 1095 if show then
flickerstreak@90 1096 count = count + 1
flickerstreak@90 1097 else
flickerstreak@90 1098 count = count - 1
flickerstreak@88 1099 end
flickerstreak@90 1100 if count < 0 then
flickerstreak@90 1101 count = 0
flickerstreak@88 1102 end
flickerstreak@90 1103 f:SetAttribute("showgrid",count)
flickerstreak@90 1104
flickerstreak@90 1105 if count >= 1 and not f:GetAttribute("statehidden") then
flickerstreak@90 1106 self.normalTexture:SetVertexColor(1.0, 1.0, 1.0, 0.5);
flickerstreak@90 1107 f:Show()
flickerstreak@90 1108 elseif count < 1 and not HasAction(self:GetActionID()) then
flickerstreak@90 1109 f:Hide()
flickerstreak@90 1110 end
flickerstreak@88 1111 end
flickerstreak@88 1112 end
flickerstreak@88 1113
flickerstreak@90 1114 function Button:ShowActionIDLabel( show )
flickerstreak@90 1115 local f = self:GetFrame()
flickerstreak@90 1116 if show then
flickerstreak@90 1117 local id = self:GetActionID()
flickerstreak@90 1118 if not f.actionIDLabel then
flickerstreak@90 1119 local label = f:CreateFontString(nil,"OVERLAY","GameFontNormalLarge")
flickerstreak@90 1120 label:SetAllPoints()
flickerstreak@90 1121 label:SetJustifyH("CENTER")
flickerstreak@90 1122 label:SetShadowColor(0,0,0,1)
flickerstreak@90 1123 label:SetShadowOffset(2,-2)
flickerstreak@90 1124 f.actionIDLabel = label -- store the label with the frame for recycling
flickerstreak@90 1125
flickerstreak@90 1126 f:HookScript("OnAttributeChanged",
flickerstreak@90 1127 function(frame, attr, value)
flickerstreak@90 1128 if label:IsVisible() and attr:match("action") then
flickerstreak@90 1129 label:SetText(tostring(frame.action))
flickerstreak@90 1130 end
flickerstreak@90 1131 end)
flickerstreak@88 1132 end
flickerstreak@90 1133 f.actionIDLabel:SetText(tostring(id))
flickerstreak@90 1134 f.actionIDLabel:Show()
flickerstreak@90 1135 elseif f.actionIDLabel then
flickerstreak@90 1136 f.actionIDLabel:Hide()
flickerstreak@88 1137 end
flickerstreak@88 1138 end
flickerstreak@88 1139
flickerstreak@90 1140 function Button:DisplayHotkey( key )
flickerstreak@90 1141 self.hotkey:SetText(key or "")
flickerstreak@88 1142 end
flickerstreak@88 1143 end