Skip to content

Commit 41e3228

Browse files
committed
Add option to automatically bind action bar abilities, fixes #257
1 parent c3e8700 commit 41e3228

File tree

8 files changed

+52
-4
lines changed

8 files changed

+52
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ The format of this changelog is based on [Keep a Changelog](https://keepachangel
1818
* Add option to import class-wide abilities per specialization [#267]
1919
* Add option to prevent toggling an ability off [#248]
2020
* Make key options respect macro condtions where able [#251]
21+
* Add option to automatically fall back to action bar abilities when no other macro conditions are met [#257]
2122

2223
### Fixed
2324

@@ -1735,6 +1736,7 @@ The format of this changelog is based on [Keep a Changelog](https://keepachangel
17351736
[#267]: https://github.com/Snakybo/Clicked/pull/267
17361737
[#265]: https://github.com/Snakybo/Clicked/pull/265
17371738
[#263]: https://github.com/Snakybo/Clicked/pull/263
1739+
[#257]: https://github.com/Snakybo/Clicked/pull/257
17381740
[#251]: https://github.com/Snakybo/Clicked/pull/251
17391741
[#248]: https://github.com/Snakybo/Clicked/pull/248
17401742
[#247]: https://github.com/Snakybo/Clicked/pull/247

Clicked/Config/Addon.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,20 @@ function AddonOptions:CreateOptionsTable()
123123
get = function ()
124124
return Addon.db.profile.options.bindUnassignedModifiers
125125
end
126+
},
127+
autoBindActionBar = {
128+
name = Addon.L["Automatically bind all action bar abilities"],
129+
desc = Addon.L["If enabled, all abilities on the action bar will automatically be appended to a binding on the same key, this will make Clicked fall back to the action bar when all other macro conditions are not met.\n\nNote that this only supports spells and items, not macros."],
130+
type = "toggle",
131+
order = 500,
132+
width = "full",
133+
set = function (_, val)
134+
Addon.db.profile.options.autoBindActionBar = val
135+
Clicked:ProcessActiveBindings()
136+
end,
137+
get = function ()
138+
return Addon.db.profile.options.autoBindActionBar
139+
end
126140
}
127141
}
128142
}

Clicked/Config/SpellLibrary.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ end
355355
--- - Items
356356
--- - Macros
357357
---
358-
--- @return table<integer, SpellLibraryResult>
358+
--- @return SpellLibraryResult[]
359359
function Addon.SpellLibrary:GetActionBarSpells()
360360
--- @type table<integer, SpellLibraryResult>
361361
local result = {}

Clicked/Core/BindingProcessor.lua

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ local function GetMacroSegmentFromAction(action, interactionType, isLast)
207207
table.insert(flags, "exists")
208208
end
209209

210-
if #action.forms.value > 0 then
210+
if action.forms ~= nil and #action.forms.value > 0 then
211211
ParseNegatableStringCondition(action.forms, "form", "noform")
212212
end
213213

@@ -308,8 +308,9 @@ end
308308

309309
--- @param binding Binding
310310
--- @param interactionType number
311+
--- @param actionBarItems SpellLibraryResult[]
311312
--- @return Action[]
312-
local function ConstructActions(binding, interactionType)
313+
local function ConstructActions(binding, interactionType, actionBarItems)
313314
--- @type Action[]
314315
local actions = {}
315316

@@ -323,6 +324,18 @@ local function ConstructActions(binding, interactionType)
323324
local action = ConstructAction(binding, target)
324325
table.insert(actions, action)
325326
end
327+
328+
-- Create virtual actions for action bar items
329+
for _, item in ipairs(actionBarItems) do
330+
if item.key == binding.keybind and (item.type == "SPELL" or item.type == "ITEM") then
331+
--- @cast item SpellLibrarySpellResult|SpellLibraryItemResult
332+
333+
table.insert(actions, {
334+
ability = C_Spell.GetSpellName(item.spellId) or C_Item.GetItemNameByID(item.itemId),
335+
type = binding.actionType
336+
})
337+
end
338+
end
326339
end
327340

328341
return actions
@@ -1332,6 +1345,12 @@ function Addon:GetMacroForBindings(bindings, interactionType)
13321345

13331346
-- Generate actions for SPELL and ITEM bindings, and insert macro values
13341347
do
1348+
local actionBar = {}
1349+
1350+
if Addon.db.profile.options.autoBindActionBar and interactionType == Addon.InteractionType.REGULAR then
1351+
actionBar = Addon.SpellLibrary:GetActionBarSpells()
1352+
end
1353+
13351354
for order, group in pairs(bindingGroups) do
13361355
actions[order] = {}
13371356
macros[order] = {}
@@ -1341,7 +1360,7 @@ function Addon:GetMacroForBindings(bindings, interactionType)
13411360

13421361
for _, binding in ipairs(group) do
13431362
if binding.actionType == Clicked.ActionType.SPELL or binding.actionType == Clicked.ActionType.ITEM then
1344-
for _, action in ipairs(ConstructActions(binding, interactionType)) do
1363+
for _, action in ipairs(ConstructActions(binding, interactionType, actionBar)) do
13451364
table.insert(actions[order], action)
13461365

13471366
actionsSequence[action] = nextActionIndex

Clicked/Core/Clicked.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,12 @@ local function PLAYER_LEVEL_CHANGED()
221221
Addon:ReloadBindings("PLAYER_LEVEL_CHANGED")
222222
end
223223

224+
local function ACTIONBAR_SLOT_CHANGED()
225+
if Addon.db.profile.options.autoBindActionBar then
226+
Addon:ReloadBindings("ACTIONBAR_SLOT_CHANGED")
227+
end
228+
end
229+
224230
local function LEARNED_SPELL_IN_TAB()
225231
Addon:ReloadBindings("LEARNED_SPELL_IN_TAB")
226232
end
@@ -303,6 +309,7 @@ local function UpdateEventHooks(self, method)
303309
method(self, "MODIFIER_STATE_CHANGED", MODIFIER_STATE_CHANGED)
304310
method(self, "UNIT_TARGET", UNIT_TARGET)
305311
method(self, "ITEM_DATA_LOAD_RESULT", ITEM_DATA_LOAD_RESULT)
312+
method(self, "ACTIONBAR_SLOT_CHANGED", ACTIONBAR_SLOT_CHANGED)
306313
end
307314

308315
-- Public addon API

Clicked/Core/Database.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ function Clicked:GetDatabaseDefaults()
146146
onKeyDown = false,
147147
tooltips = false,
148148
bindUnassignedModifiers = false,
149+
autoBindActionBar = false,
149150
minimap = {
150151
hide = false
151152
},

Clicked/Definitions.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
--- @field public onKeyDown boolean
3737
--- @field public tooltips boolean
3838
--- @field public minimap Profile.Options.Minimap
39+
--- @field public bindUnassignedModifiers boolean
40+
--- @field public autoBindActionBar boolean
41+
--- @field public ignoreSelfCastWarning boolean
3942

4043
--- @class Profile.Options.Minimap
4144
--- @field public hide boolean

Clicked/Locales/enUS.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,3 +323,5 @@ L["Rune equipped"] = true
323323
L["Import class abilities per specialization"] = true
324324
L["Prevent toggle"] = true
325325
L["Prevent the ability from being toggled off by repeatetly pressing the keybind."] = true
326+
L["Automatically bind all action bar abilities"] = true
327+
L["If enabled, all abilities on the action bar will automatically be appended to a binding on the same key, this will make Clicked fall back to the action bar when all other macro conditions are not met.\n\nNote that this only supports spells and items, not macros."] = true

0 commit comments

Comments
 (0)