annotate Buttons.lua @ 10:f3a7bfebc283

Version 0.33
author Flick <flickerstreak@gmail.com>
date Tue, 20 Mar 2007 21:37:38 +0000
parents c05fd3e18b4f
children 2735edcf9ab7
rev   line source
flickerstreak@7 1 -- Buttons.lua
flickerstreak@7 2 --
flickerstreak@7 3 -- Defines button types for use with the ReAction AddOn
flickerstreak@7 4 --
flickerstreak@7 5
flickerstreak@7 6 local AceOO = AceLibrary("AceOO-2.0")
flickerstreak@10 7 local ReBound = AceLibrary("ReBound-1.0")
flickerstreak@7 8
flickerstreak@7 9 local Action = AceOO.Class(
flickerstreak@7 10 ReAction,
flickerstreak@7 11 ReAction.ActionType,
flickerstreak@7 12 ReAction.ActionDisplay,
flickerstreak@7 13 ReAction.DefaultColorScheme
flickerstreak@7 14 )
flickerstreak@7 15
flickerstreak@7 16 local PetAction = AceOO.Class(
flickerstreak@7 17 ReAction,
flickerstreak@7 18 ReAction.PetActionType,
flickerstreak@7 19 ReAction.PetActionDisplay,
flickerstreak@7 20 ReAction.DefaultColorScheme
flickerstreak@7 21 )
flickerstreak@7 22
flickerstreak@7 23
flickerstreak@10 24 ReAction:AddButtonType( "Action", Action, 120 )
flickerstreak@7 25 ReAction:AddButtonType( "Pet Action", PetAction, 10 )
flickerstreak@7 26
flickerstreak@7 27
flickerstreak@7 28
flickerstreak@7 29 -----------------------
flickerstreak@7 30 -- static class members
flickerstreak@7 31 -----------------------
flickerstreak@7 32 Action.defaultProfile = {
flickerstreak@7 33 type = "ReAction",
flickerstreak@7 34 subtype = "Action",
flickerstreak@7 35 ids = { },
flickerstreak@7 36 selfcast = nil,
flickerstreak@7 37 keyBindLoc = "TOPRIGHT",
flickerstreak@10 38 keyBindRightLoc = "RIGHT",
flickerstreak@7 39 stackCountLoc = "BOTTOMRIGHT",
flickerstreak@7 40 showKeyBind = true,
flickerstreak@10 41 showKeyBindRight = false,
flickerstreak@7 42 showStackCount = true,
flickerstreak@7 43 showMacroText = true,
flickerstreak@7 44 showBorder = true,
flickerstreak@7 45 keyBindColorCode = false,
flickerstreak@8 46 hideCooldown = false,
flickerstreak@8 47 hideGlobalCooldown = false,
flickerstreak@7 48 }
flickerstreak@7 49
flickerstreak@7 50 PetAction.defaultProfile = {
flickerstreak@7 51 type = "ReAction",
flickerstreak@7 52 subtype = "Pet Action",
flickerstreak@7 53 ids = { },
flickerstreak@7 54 keyBindLoc = "TOPRIGHT",
flickerstreak@7 55 showKeyBind = false,
flickerstreak@7 56 showGrid = false,
flickerstreak@7 57 showBorder = true,
flickerstreak@7 58 keyBindColorCode = false,
flickerstreak@7 59 }
flickerstreak@7 60
flickerstreak@7 61
flickerstreak@7 62
flickerstreak@7 63 -----------------------
flickerstreak@7 64 -- static class methods
flickerstreak@7 65 -----------------------
flickerstreak@7 66 function Action:GetDefaultProfile()
flickerstreak@7 67 return self.defaultProfile
flickerstreak@7 68 end
flickerstreak@7 69
flickerstreak@7 70 function PetAction:GetDefaultProfile()
flickerstreak@7 71 return self.defaultProfile
flickerstreak@7 72 end
flickerstreak@7 73
flickerstreak@7 74
flickerstreak@7 75
flickerstreak@7 76 local labelPlacementOptions = {
flickerstreak@7 77 "TOP",
flickerstreak@7 78 "BOTTOM",
flickerstreak@7 79 "LEFT",
flickerstreak@7 80 "RIGHT",
flickerstreak@7 81 "TOPLEFT",
flickerstreak@7 82 "TOPRIGHT",
flickerstreak@7 83 "BOTTOMLEFT",
flickerstreak@7 84 "BOTTOMRIGHT"
flickerstreak@7 85 }
flickerstreak@7 86
flickerstreak@7 87
flickerstreak@7 88 function Action:GenerateOptionsTable( config, buttonListFunc )
flickerstreak@7 89
flickerstreak@7 90 local function refresh()
flickerstreak@7 91 for _, b in pairs(buttonListFunc()) do
flickerstreak@7 92 b:UpdateAction()
flickerstreak@7 93 b:UpdateTooltip()
flickerstreak@7 94 b:UpdateDisplay()
flickerstreak@7 95 end
flickerstreak@7 96 end
flickerstreak@7 97
flickerstreak@8 98 local function setOpacity(field, value)
flickerstreak@8 99 if not config.opacity then
flickerstreak@8 100 config.opacity = { }
flickerstreak@8 101 end
flickerstreak@8 102 config.opacity[field] = (value and value / 100)
flickerstreak@8 103 refresh()
flickerstreak@8 104 end
flickerstreak@8 105
flickerstreak@8 106 local function getOpacity(field, default)
flickerstreak@8 107 local o = config.opacity and config.opacity[field] or (default and default/100) or 1
flickerstreak@8 108 return o * 100
flickerstreak@8 109 end
flickerstreak@8 110
flickerstreak@7 111 return {
flickerstreak@7 112 type = "group",
flickerstreak@7 113 args = {
flickerstreak@7 114 selfcast = {
flickerstreak@7 115 type = "text",
flickerstreak@7 116 name = "Self Cast",
flickerstreak@7 117 desc = "Choose a modifier key to hold down or an alternate button to click to self-cast spells. "..
flickerstreak@7 118 "'default' uses the settings in the Interface Options Advanced panel (use this to achieve 'smart self cast'). "..
flickerstreak@7 119 "'right-click' self-casting is not supported for multi-page bars.",
flickerstreak@7 120 get = function() return config.selfcast or "default" end,
flickerstreak@7 121 set = function(opt)
flickerstreak@7 122 if opt == "default" then opt = nil end
flickerstreak@7 123 config.selfcast = opt
flickerstreak@7 124 for _, b in pairs(buttonListFunc()) do
flickerstreak@7 125 b:UpdateSelfcast()
flickerstreak@7 126 end
flickerstreak@7 127 end,
flickerstreak@7 128 validate = { "default", "none", "alt", "ctrl", "shift", "right-click" },
flickerstreak@10 129 order = 101
flickerstreak@7 130 },
flickerstreak@7 131
flickerstreak@8 132 opacity = {
flickerstreak@8 133 type = "group",
flickerstreak@8 134 name = "Opacity",
flickerstreak@8 135 desc = "Set options for variable button opacity",
flickerstreak@8 136 args = {
flickerstreak@8 137 usable = {
flickerstreak@8 138 type = "range",
flickerstreak@8 139 name = "Usable",
flickerstreak@8 140 desc = "Button opacity when the action is currently usable",
flickerstreak@8 141 min = 0,
flickerstreak@8 142 max = 100,
flickerstreak@8 143 step = 1,
flickerstreak@8 144 get = function() return getOpacity("usable") end,
flickerstreak@8 145 set = function(x) setOpacity("usable", x) end,
flickerstreak@8 146 order = 1,
flickerstreak@8 147 },
flickerstreak@8 148
flickerstreak@8 149 notUsable = {
flickerstreak@8 150 type = "range",
flickerstreak@8 151 name = "Not Usable",
flickerstreak@8 152 desc = "Button opacity when the action is currently not usable",
flickerstreak@8 153 min = 0,
flickerstreak@8 154 max = 100,
flickerstreak@8 155 step = 1,
flickerstreak@8 156 get = function() return getOpacity("notUsable") end,
flickerstreak@8 157 set = function(x) setOpacity("notUsable",x) end,
flickerstreak@8 158 order = 2,
flickerstreak@8 159 },
flickerstreak@8 160
flickerstreak@8 161 oom = {
flickerstreak@8 162 type = "range",
flickerstreak@8 163 name = "Out of Power",
flickerstreak@8 164 desc = "Button opacity when the action is not usable due to not enough mana/energy/rage. "..
flickerstreak@8 165 "By default this uses the generic 'not-usable' setting.",
flickerstreak@8 166 min = 0,
flickerstreak@8 167 max = 100,
flickerstreak@8 168 step = 1,
flickerstreak@8 169 get = function() return getOpacity("oom",getOpacity("notUsable")) end,
flickerstreak@8 170 set = function(x) setOpacity("oom", x ~= getOpacity("notUsable") and x) end,
flickerstreak@8 171 order = 3,
flickerstreak@8 172 },
flickerstreak@8 173
flickerstreak@8 174 oorange = {
flickerstreak@8 175 type = "range",
flickerstreak@8 176 name = "Out of Range",
flickerstreak@8 177 desc = "Button opacity when the action is not usable due to the target not being in range. "..
flickerstreak@8 178 "By default this uses the generic 'not-usable' setting.",
flickerstreak@8 179 min = 0,
flickerstreak@8 180 max = 100,
flickerstreak@8 181 step = 1,
flickerstreak@8 182 get = function() return getOpacity("ooRange",getOpacity("notUsable")) end,
flickerstreak@8 183 set = function(x) setOpacity("ooRange", x ~= getOpacity("notUsable") and x) end,
flickerstreak@8 184 order = 4,
flickerstreak@8 185 },
flickerstreak@8 186
flickerstreak@8 187 empty = {
flickerstreak@8 188 type = "range",
flickerstreak@8 189 name = "Empty Slot",
flickerstreak@8 190 desc = "Button opacity when the button's action slot is empty. By default this is 0 (fully transparent), "..
flickerstreak@8 191 "but note that they still block mouse clicks. Empty slots are automatically made opaque (per the "..
flickerstreak@8 192 "'usable' opacity setting) when moving actions around.",
flickerstreak@8 193 min = 0,
flickerstreak@8 194 max = 100,
flickerstreak@8 195 step = 1,
flickerstreak@8 196 get = function() return getOpacity("empty",0) end,
flickerstreak@8 197 set = function(x) setOpacity("empty",x) end,
flickerstreak@8 198 order = 5,
flickerstreak@8 199 },
flickerstreak@8 200
flickerstreak@8 201 hideEmpty = {
flickerstreak@8 202 type = "toggle",
flickerstreak@8 203 name = "Hide Empty Slots",
flickerstreak@8 204 desc = "Hides empty action slots rather than changing their opacity. This has the advantage that empty slots "..
flickerstreak@8 205 "don't block mouse clicks. WARNING: this makes it impossible to re-arrange actions with drag-and-drop "..
flickerstreak@8 206 "while in combat.",
flickerstreak@8 207 get = function() return config.hideEmptySlots end,
flickerstreak@8 208 set = function() config.hideEmptySlots = not config.hideEmptySlots ; refresh() end,
flickerstreak@8 209 order = 6,
flickerstreak@8 210 },
flickerstreak@8 211
flickerstreak@8 212 },
flickerstreak@10 213 order = 102,
flickerstreak@10 214 },
flickerstreak@10 215
flickerstreak@10 216 displaysep = {
flickerstreak@10 217 type = "header",
flickerstreak@10 218 name = " ",
flickerstreak@10 219 desc = " ",
flickerstreak@10 220 order = 103,
flickerstreak@10 221 },
flickerstreak@10 222
flickerstreak@10 223 showkeybind = {
flickerstreak@10 224 type = "toggle",
flickerstreak@10 225 name = "Show Hotkey",
flickerstreak@10 226 desc = "Toggle show/hide hot key labels",
flickerstreak@10 227 get = function() return config.showKeyBind end,
flickerstreak@10 228 set = function() config.showKeyBind = not config.showKeyBind ; refresh() end,
flickerstreak@10 229 order = 104,
flickerstreak@8 230 },
flickerstreak@8 231
flickerstreak@7 232 keyloc = {
flickerstreak@7 233 type = "text",
flickerstreak@7 234 name = "Hotkey Location",
flickerstreak@7 235 desc = "Sets hotkey location",
flickerstreak@7 236 get = function() return config.keyBindLoc end,
flickerstreak@7 237 set = function(loc) config.keyBindLoc = loc ; refresh() end,
flickerstreak@10 238 hidden = function() return not config.showKeyBind end,
flickerstreak@7 239 validate = labelPlacementOptions,
flickerstreak@10 240 order = 105,
flickerstreak@7 241 },
flickerstreak@7 242
flickerstreak@10 243 showKeyBindRight = {
flickerstreak@10 244 type = "toggle",
flickerstreak@10 245 name = "Show Right-click Hotkey",
flickerstreak@10 246 desc = "Toggle show/hide right-click hot key labels",
flickerstreak@10 247 get = function() return config.showKeyBindRight end,
flickerstreak@10 248 set = function() config.showKeyBindRight = not config.showKeyBindRight ; refresh() end,
flickerstreak@10 249 order = 106,
flickerstreak@7 250 },
flickerstreak@7 251
flickerstreak@10 252 rightkeyloc = {
flickerstreak@10 253 type = "text",
flickerstreak@10 254 name = "Right-click Hotkey Location",
flickerstreak@10 255 desc = "Sets right-click hotkey location",
flickerstreak@10 256 get = function() return config.keyBindRightLoc end,
flickerstreak@10 257 set = function(loc) config.keyBindRightLoc = loc ; refresh() end,
flickerstreak@10 258 hidden = function() return not config.showKeyBindRight end,
flickerstreak@10 259 validate = labelPlacementOptions,
flickerstreak@10 260 order = 107,
flickerstreak@10 261 },
flickerstreak@10 262
flickerstreak@10 263 colorhotkeys = {
flickerstreak@7 264 type = "toggle",
flickerstreak@10 265 name = "Colorize Hotkeys",
flickerstreak@10 266 desc = "Toggles coloring hotkeys based on the modifier key. Out-of-range coloring is always enabled.",
flickerstreak@10 267 get = function() return config.keyBindColorCode end,
flickerstreak@10 268 set = function() config.keyBindColorCode = not config.keyBindColorCode ; refresh() end,
flickerstreak@10 269 hidden = function() return not config.showKeyBind and not config.showKeyBindRight end,
flickerstreak@10 270 order = 109,
flickerstreak@7 271 },
flickerstreak@7 272
flickerstreak@7 273 showstackcount = {
flickerstreak@7 274 type = "toggle",
flickerstreak@7 275 name = "Show Stack Count",
flickerstreak@7 276 desc = "Toggle show/hide stack count labels",
flickerstreak@7 277 get = function() return config.showStackCount end,
flickerstreak@7 278 set = function() config.showStackCount = not config.showStackCount ; refresh() end,
flickerstreak@10 279 order = 110,
flickerstreak@10 280 },
flickerstreak@10 281
flickerstreak@10 282 stackloc = {
flickerstreak@10 283 type = "text",
flickerstreak@10 284 name = "Stack Count Location",
flickerstreak@10 285 desc = "Sets stack count location",
flickerstreak@10 286 get = function() return config.stackCountLoc end,
flickerstreak@10 287 set = function(loc) config.stackCountLoc = loc ; refresh() end,
flickerstreak@10 288 hidden = function() return not config.showStackCount end,
flickerstreak@10 289 validate = labelPlacementOptions,
flickerstreak@10 290 order = 111,
flickerstreak@7 291 },
flickerstreak@7 292
flickerstreak@7 293 showmacrotext = {
flickerstreak@7 294 type = "toggle",
flickerstreak@7 295 name = "Show Macro Names",
flickerstreak@7 296 desc = "Toggle show/hide macro name labels",
flickerstreak@7 297 get = function() return config.showMacroText end,
flickerstreak@7 298 set = function() config.showMacroText = not config.showMacroText ; refresh() end,
flickerstreak@10 299 order = 112,
flickerstreak@7 300 },
flickerstreak@7 301
flickerstreak@8 302 hidecooldown = {
flickerstreak@7 303 type = "toggle",
flickerstreak@8 304 name = "Hide Cooldowns",
flickerstreak@8 305 desc = "Hides all cooldown displays on buttons. Toggling this on does not hide currently running cooldowns.",
flickerstreak@8 306 get = function() return config.hideCooldown end,
flickerstreak@8 307 set = function() config.hideCooldown = not config.hideCooldown ; refresh() end,
flickerstreak@10 308 order = 114,
flickerstreak@8 309 },
flickerstreak@8 310
flickerstreak@8 311 hideglobalcooldown = {
flickerstreak@8 312 type = "toggle",
flickerstreak@8 313 name = "Hide Global Cooldown",
flickerstreak@8 314 desc = "Disables the global cooldown from being displayed on buttons.",
flickerstreak@8 315 get = function() return config.hideGlobalCooldown end,
flickerstreak@8 316 set = function() config.hideGlobalCooldown = not config.hideGlobalCooldown ; refresh() end,
flickerstreak@10 317 hidden = function() return not config.hideCooldown end,
flickerstreak@10 318 order = 115,
flickerstreak@7 319 },
flickerstreak@7 320
flickerstreak@7 321 --[[
flickerstreak@7 322 hideborder = {
flickerstreak@7 323 type = "toggle",
flickerstreak@7 324 name = "Hide Border",
flickerstreak@7 325 desc = "Toggles hiding of the button border frame.",
flickerstreak@7 326 get = function() return not config.showBorder end,
flickerstreak@7 327 set = function() config.showBorder = not config.showBorder ; refresh() end,
flickerstreak@7 328 },]]
flickerstreak@7 329 }
flickerstreak@7 330 }
flickerstreak@7 331 end
flickerstreak@7 332
flickerstreak@7 333
flickerstreak@7 334 function PetAction:GenerateOptionsTable( config, buttonListFunc )
flickerstreak@7 335
flickerstreak@7 336 local function refresh()
flickerstreak@7 337 for _, b in pairs(buttonListFunc()) do
flickerstreak@7 338 b:UpdateAction()
flickerstreak@7 339 b:UpdateTooltip()
flickerstreak@7 340 b:UpdateDisplay()
flickerstreak@7 341 end
flickerstreak@7 342 end
flickerstreak@7 343
flickerstreak@7 344 return {
flickerstreak@7 345 type = "group",
flickerstreak@7 346 args = {
flickerstreak@7 347 keyloc = {
flickerstreak@7 348 type = "text",
flickerstreak@7 349 name = "Hotkey Location",
flickerstreak@7 350 desc = "Sets hotkey location",
flickerstreak@7 351 get = function() return config.keyBindLoc end,
flickerstreak@7 352 set = function(loc) config.keyBindLoc = loc ; refresh() end,
flickerstreak@7 353 validate = { "TOP", "BOTTOM", "LEFT", "RIGHT", "TOPLEFT", "TOPRIGHT", "BOTTOMLEFT", "BOTTOMRIGHT" },
flickerstreak@7 354 },
flickerstreak@7 355
flickerstreak@7 356 showkeybind = {
flickerstreak@7 357 type = "toggle",
flickerstreak@7 358 name = "Show Hotkey",
flickerstreak@7 359 desc = "Toggle show/hide hot key labels",
flickerstreak@7 360 get = function() return config.showKeyBind end,
flickerstreak@7 361 set = function() config.showKeyBind = not config.showGrid ; refresh() end,
flickerstreak@7 362 },
flickerstreak@7 363
flickerstreak@7 364 showgrid = {
flickerstreak@7 365 type = "toggle",
flickerstreak@7 366 name = "Always Show Buttons",
flickerstreak@7 367 desc = "Show button placeholders when no action is assigned or on the cursor. Note that buttons are always shown when bars are unlocked.",
flickerstreak@7 368 get = function() return config.showGrid end,
flickerstreak@7 369 set = function() config.showGrid = not config.showGrid ; refresh() end,
flickerstreak@7 370 },
flickerstreak@7 371
flickerstreak@7 372 colorhotkeys = {
flickerstreak@7 373 type = "toggle",
flickerstreak@7 374 name = "Colorize Hotkeys",
flickerstreak@7 375 desc = "Toggles coloring hotkeys based on the modifier key. Out-of-range coloring is always enabled.",
flickerstreak@7 376 get = function() return config.keyBindColorCode end,
flickerstreak@7 377 set = function() config.keyBindColorCode = not config.keyBindColorCode ; refresh() end,
flickerstreak@7 378 },
flickerstreak@7 379
flickerstreak@7 380 --[[
flickerstreak@7 381 hideborder = {
flickerstreak@7 382 type = "toggle",
flickerstreak@7 383 name = "Hide Border",
flickerstreak@7 384 desc = "Toggles hiding of the button border frame.",
flickerstreak@7 385 get = function() return not config.showBorder end,
flickerstreak@7 386 set = function() config.showBorder = not config.showBorder ; refresh() end,
flickerstreak@7 387 },]]
flickerstreak@7 388 }
flickerstreak@7 389 }
flickerstreak@7 390 end
flickerstreak@7 391
flickerstreak@7 392
flickerstreak@7 393
flickerstreak@7 394 ----------------------
flickerstreak@7 395 -- Instance methods
flickerstreak@7 396 ----------------------
flickerstreak@7 397 function Action.prototype:init( id )
flickerstreak@7 398 Action.super.prototype.init(self)
flickerstreak@7 399
flickerstreak@7 400 self:SetupDisplay("ReActionButton"..id)
flickerstreak@7 401 self:SetupAction()
flickerstreak@10 402 ReBound:Register(self:GetActionFrame())
flickerstreak@7 403 end
flickerstreak@7 404
flickerstreak@7 405 function PetAction.prototype:init( id )
flickerstreak@7 406 Action.super.prototype.init(self)
flickerstreak@7 407
flickerstreak@7 408 self:SetupDisplay("ReActionPetButton"..id)
flickerstreak@7 409 self:SetupAction()
flickerstreak@10 410 ReBound:Register(self:GetActionFrame())
flickerstreak@7 411 end
flickerstreak@7 412