annotate modules/ReAction_Action/ReAction_Action.lua @ 93:567a885cdfad

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