Skip to content

Commit

Permalink
Add initial support for The War Within
Browse files Browse the repository at this point in the history
  • Loading branch information
Snakybo committed Jun 13, 2024
1 parent 57ea14e commit f8b43e0
Show file tree
Hide file tree
Showing 20 changed files with 520 additions and 183 deletions.
8 changes: 8 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ read_globals = {
"BOOKTYPE_PROFESSION",
"BOOKTYPE_SPELL",
"CreateFrame",
"CreateMacro",
"DisableAddOn",
"Constants",
"C_AddOns",
Expand All @@ -56,11 +57,14 @@ read_globals = {
"C_PetJournal",
"C_PvP",
"C_SpecializationInfo",
"C_Spell",
"C_Traits",
"C_Timer",
"ClassTalentFrame",
"ClearCursor",
"DeleteMacro",
"EasyMenu",
"EditMacro",
"EnableAddOn",
"Enum",
"FillLocalizedClassList",
Expand Down Expand Up @@ -90,6 +94,7 @@ read_globals = {
"GetMouseFocus",
"GetNumBindings",
"GetNumGroupMembers",
"GetNumMacros",
"GetNumShapeshiftForms",
"GetNumSpecializations",
"GetNumSpellTabs",
Expand Down Expand Up @@ -179,7 +184,10 @@ read_globals = {
"TalentButtonUtil",
"TalentUtil",
"tContains",
"ToggleDropDownMenu",
"TooltipDataProcessor",
"UIDropDownMenu_AddButton",
"UIDropDownMenu_Initialize",
"UIParent",
"UnitClass",
"UnitGUID",
Expand Down
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@
"SpellButton_OnEnter",
"SpellButton_OnLeave",
"WeakAuras",
"WeakAurasSaved"
"WeakAurasSaved",
"UIDropDownMenu_Initialize",
"ToggleDropDownMenu",
"UIDropDownMenu_AddButton"
]

}
2 changes: 1 addition & 1 deletion Clicked/Clicked.toc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Interface: 100207
## Interface: 110000
## Title: Clicked
## IconTexture: Interface\Icons\inv_misc_punchcards_yellow
## Author: Snakybo
Expand Down
50 changes: 36 additions & 14 deletions Clicked/Config/Bindings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -294,19 +294,21 @@ end

--- @param input string|number
--- @param mode string
--- @return string|integer name
--- @return string|integer? name
--- @return integer? id
local function GetSpellItemNameAndId(input, mode)
--- @type string|integer
--- @type string|integer?
local name

--- @type integer?
local id

if mode == Addon.BindingTypes.SPELL then
if type(input) == "number" then
local spell = Addon:GetSpellInfo(input)

id = input
name = Addon:GetSpellInfo(id)
name = spell ~= nil and spell.name or nil
else
name = input
id = Addon:GetSpellId(name)
Expand Down Expand Up @@ -510,8 +512,11 @@ local function HijackSpellFlyout_Toggle()
end)

button:SetScript("OnClick", function()
local name = Addon:GetSpellInfo(parent.spellID);
OnSpellBookButtonClick(name)
local spell = Addon:GetSpellInfo(parent.spellID);

if spell ~= nil then
OnSpellBookButtonClick(spell.name)
end
end)

spellFlyOutButtons[id] = button
Expand Down Expand Up @@ -1326,7 +1331,8 @@ local function DrawSpellItemAuraSelection(container, action, mode)
action[valueKey] = linkId

if mode == Addon.BindingTypes.SPELL then
value = Addon:GetSpellInfo(linkId)
local spell = Addon:GetSpellInfo(linkId)
value = spell ~= nil and spell.name or nil
elseif mode == Addon.BindingTypes.ITEM then
value = Addon:GetItemInfo(linkId)
end
Expand Down Expand Up @@ -1390,7 +1396,8 @@ local function DrawSpellItemAuraSelection(container, action, mode)
local icon

if mode == Addon.BindingTypes.SPELL then
icon = select(3, Addon:GetSpellInfo(id))
local spell = Addon:GetSpellInfo(id)
icon = spell and spell.iconID or nil
elseif mode == Addon.BindingTypes.ITEM then
icon = select(10, Addon:GetItemInfo(id))
end
Expand Down Expand Up @@ -1430,6 +1437,10 @@ local function DrawSpellItemAuraSelection(container, action, mode)
widget:SetText(Addon.L["Pick from spellbook"])
widget:SetCallback("OnClick", OnClick)

if Addon.EXPANSION_LEVEL >= Addon.EXPANSION.TWW then
widget:SetDisabled(true)
end

if hasRank then
widget:SetRelativeWidth(0.65)
else
Expand All @@ -1454,7 +1465,8 @@ local function DrawSpellItemAuraSelection(container, action, mode)
return
end

action[valueKey] = Addon:GetSpellInfo(id, false)
local spell = Addon:GetSpellInfo(id, false)
action[valueKey] = spell ~= nil and spell.name or nil
action.convertValueToId = false

Clicked:ReloadBinding(binding, true)
Expand Down Expand Up @@ -3432,11 +3444,17 @@ end
-- Private addon API

function Addon:BindingConfig_Initialize()
SpellBookFrame:HookScript("OnHide", function()
HijackSpellButton_UpdateButton(nil)
end)
if Addon.EXPANSION_LEVEL >= Addon.EXPANSION.TWW then
-- TODO: Spellbook
else
SpellBookFrame:HookScript("OnHide", function()
HijackSpellButton_UpdateButton(nil)
end)
end

if Addon.EXPANSION_LEVEL >= Addon.EXPANSION.CATA then
if Addon.EXPANSION_LEVEL >= Addon.EXPANSION.TWW then
-- TODO: Spellbook
elseif Addon.EXPANSION_LEVEL >= Addon.EXPANSION.CATA then
for i = 1, SPELLS_PER_PAGE do
local currSpellButton = _G["SpellButton" .. i];
hooksecurefunc(currSpellButton, "UpdateButton", HijackSpellButton_UpdateButton)
Expand Down Expand Up @@ -3561,8 +3579,12 @@ function Addon:BindingConfig_Redraw()
return
end

if not InCombatLockdown() and SpellBookFrame:IsShown() and SpellBookFrame.bookType == BOOKTYPE_SPELL then
SpellBookFrame_UpdateSpells()
if Addon.EXPANSION_LEVEL >= Addon.EXPANSION.TWW then
-- TODO: Spellbook
else
if not InCombatLockdown() and SpellBookFrame:IsShown() and SpellBookFrame.bookType == BOOKTYPE_SPELL then
SpellBookFrame_UpdateSpells()
end
end

root:SetStatusText(string.format("%s | %s", Clicked.VERSION, Addon.db:GetCurrentProfile()))
Expand Down
2 changes: 1 addition & 1 deletion Clicked/Core/AttributeHandler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function Addon:CreateCommandAttributes(register, command, prefix, suffix)
end

CreateAttribute(register, prefix, attributeType, suffix, "macro")
CreateAttribute(register, prefix, "macrotext", suffix, command.data)
CreateAttribute(register, prefix, "macro", suffix, command.macroName)
else
error("Unhandled action type: " .. command.action)
end
Expand Down
19 changes: 16 additions & 3 deletions Clicked/Core/BindingProcessor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ local function ProcessBuckets()
if Addon:GetInternalBindingType(reference) == Addon.BindingTypes.MACRO then
command.action = Addon.CommandType.MACRO
command.data = Addon:GetMacroForBindings(bindings, interactionType)
command.macroName = Addon:GetMacroName(bindings, interactionType)
elseif reference.type == Addon.BindingTypes.UNIT_SELECT then
command.action = Addon.CommandType.TARGET

Expand Down Expand Up @@ -501,6 +502,9 @@ local function GenerateBuckets(bindings)
end
end
end

table.sort(hovercastBucket, function(a, b) return a.uid < b.uid end)
table.sort(regularBucket, function(a, b) return a.uid < b.uid end)
end

--- @param str string
Expand Down Expand Up @@ -1239,8 +1243,8 @@ function Addon:UpdateBindingLoadState(binding, options)
-- implies, using the GetSpellInfo function on an item also returns a valid value.

local function IsSpellKnown(value)
local name, _, _, _, _, _, spellId = Addon:GetSpellInfo(value)
return name ~= nil and spellId ~= nil and IsSpellKnownOrOverridesKnown(spellId)
local spell = Addon:GetSpellInfo(value)
return spell ~= nil and IsSpellKnownOrOverridesKnown(spell.spellID) or false
end

state.spellKnown = ValidateLoadOption(load.spellKnown, IsSpellKnown)
Expand Down Expand Up @@ -1454,6 +1458,13 @@ function Addon:GetInternalBindingType(binding)
return binding.type
end

--- @param bindings Binding[]
--- @param interactionType number
--- @return string
function Addon:GetMacroName(bindings, interactionType)
return "clicked-" .. bindings[1].uid .. "-" .. interactionType
end

--- Construct a valid macro that correctly prioritizes all specified bindings.
--- It will prioritize bindings in the following order:
---
Expand Down Expand Up @@ -1484,7 +1495,9 @@ function Addon:GetMacroForBindings(bindings, interactionType)
assert(type(interactionType) == "number", "bad argument #1, expected number but got " .. type(interactionType))

--- @type string[]
local lines = {}
local lines = {
"#showtooltip"
}

--- @type string[]
local macroConditions = {}
Expand Down
28 changes: 28 additions & 0 deletions Clicked/Core/CommandProcessor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,24 @@ local function EnsureMacroFrameHandler()
Clicked:RegisterFrameClicks(macroFrameHandler, false)
end

local function CreateOrUpdateMacro(name, body)
if GetMacroInfo(name) ~= nil then
EditMacro(name, name, "INV_Misc_QuestionMark", body)
else
CreateMacro(name, "INV_Misc_QuestionMark", body)
end
end

local function DeleteUnusedMacros(usedMacroNames)
for i = GetNumMacros(), 1, -1 do
local name = GetMacroInfo(i)

if string.find(name, "clicked-") and not tContains(usedMacroNames, name) then
DeleteMacro(name)
end
end
end

-- Private addon API

--- @param keybinds Keybind[]
Expand Down Expand Up @@ -182,6 +200,9 @@ function Addon:ProcessCommands(commands)
--- @type table<string,string>
local newMacroFrameHandlerAttributes = {}

--- @type string[]
local usedMacroNames = {}

EnsureMacroFrameHandler()

-- Unregister all current keybinds
Expand All @@ -199,6 +220,11 @@ function Addon:ProcessCommands(commands)
identifier = command.suffix
}

if command.action == Addon.CommandType.MACRO then
CreateOrUpdateMacro(command.macroName, command.data)
table.insert(usedMacroNames, command.macroName)
end

Addon:CreateCommandAttributes(attributes, command, command.prefix, command.suffix)

if command.hovercast then
Expand Down Expand Up @@ -227,6 +253,8 @@ function Addon:ProcessCommands(commands)
end
end

DeleteUnusedMacros(usedMacroNames)

Addon:StatusOutput_UpdateMacroHandlerAttributes(newMacroFrameHandlerAttributes)
Addon:UpdateMacroFrameHandler(newMacroFrameHandlerKeybinds, newMacroFrameHandlerAttributes)

Expand Down
Loading

0 comments on commit f8b43e0

Please sign in to comment.