Skip to content

Commit

Permalink
Add new API/expansion version check
Browse files Browse the repository at this point in the history
  • Loading branch information
Snakybo committed Apr 29, 2024
1 parent 94d1607 commit 837512e
Show file tree
Hide file tree
Showing 17 changed files with 304 additions and 340 deletions.
2 changes: 1 addition & 1 deletion Clicked/Config/Addon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function AddonOptions:CreateOptionsTable()
type = "toggle",
order = 101,
width = "full",
hidden = not Addon:IsGameVersionAtleast("RETAIL"),
hidden = Addon.EXPANSION_LEVEL < Addon.EXPANSION.DF,
set = function (_, val)
if val then
LibDBIcon:AddButtonToCompartment(Addon.L["Clicked"])
Expand Down
120 changes: 57 additions & 63 deletions Clicked/Config/Bindings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -396,15 +396,15 @@ local function HijackSpellButton_UpdateButton(self)
button:SetID(parent:GetID())

button:SetScript("OnEnter", function(_, motion)
if Addon:IsGameVersionAtleast("CATA") then
if Addon.EXPANSION_LEVEL >= Addon.EXPANSION.CATA then
parent:OnEnter(motion)
else
SpellButton_OnEnter(parent, motion)
end
end)

button:SetScript("OnLeave", function()
if Addon:IsGameVersionAtleast("CATA") then
if Addon.EXPANSION_LEVEL >= Addon.EXPANSION.CATA then
parent:OnLeave()
else
SpellButton_OnLeave(parent)
Expand All @@ -415,7 +415,7 @@ local function HijackSpellButton_UpdateButton(self)
local slot = SpellBook_GetSpellBookSlot(parent);
local name, subName = GetSpellBookItemName(slot, SpellBookFrame.bookType)

if mouseButton ~= "RightButton" and (not Addon:IsGameVersionAtleast("CATA") and not Addon:IsStringNilOrEmpty(subName)) then
if mouseButton ~= "RightButton" and (Addon.EXPANSION_LEVEL <= Addon.EXPANSION.WOTLK and not Addon:IsStringNilOrEmpty(subName)) then
name = string.format("%s(%s)", name, subName)
end

Expand Down Expand Up @@ -1407,7 +1407,7 @@ local function DrawSpellItemAuraSelection(container, action, mode)
end

if mode == Addon.BindingTypes.SPELL then
local hasRank = not Addon:IsGameVersionAtleast("CATA") and id ~= nil and string.find(name, "%((.+)%)")
local hasRank = Addon.EXPANSION_LEVEL <= Addon.EXPANSION.WOTLK and id ~= nil and string.find(name, "%((.+)%)")

-- pick from spellbook button
do
Expand Down Expand Up @@ -1438,7 +1438,7 @@ local function DrawSpellItemAuraSelection(container, action, mode)

local tooltip = Addon.L["Click on a spell book entry to select it."]

if not Addon:IsGameVersionAtleast("CATA") then
if Addon.EXPANSION_LEVEL <= Addon.EXPANSION.WOTLK then
tooltip = tooltip .. "\n" .. Addon.L["Right click to use the max rank."]
end

Expand Down Expand Up @@ -2318,17 +2318,23 @@ local function DrawMacroBonusBar(container, bonusbar)
end
end

local tips = {
string.format(Addon.L["For Dragonriding, use bonus bar %s"], "|r5|cffffffff")
}
local tips = nil

if Addon.EXPANSION_LEVEL >= Addon.EXPANSION.DF then
local tipList = {
string.format(Addon.L["For Dragonriding, use bonus bar %s"], "|r5|cffffffff")
}

if tContains(Addon:GetBindingRaces(binding), "Dracthyr") then
table.insert(tipList, string.format(Addon.L["For Soar, use bonus bar %s"], "|r1|cffffffff"))
end

if tContains(Addon:GetBindingRaces(binding), "Dracthyr") then
table.insert(tips, string.format(Addon.L["For Soar, use bonus bar %s"], "|r1|cffffffff"))
tips = table.concat(tipList, "\n")
end

inputField:SetCallback("OnTextChanged", OnTextChanged)

RegisterTooltip(inputField, Addon.L["Bonus bar"], table.concat(tips, "\n"))
RegisterTooltip(inputField, Addon.L["Bonus bar"], tips)
end
end

Expand Down Expand Up @@ -2388,13 +2394,13 @@ local function DrawBindingMacroConditionsPage(container, binding)
if binding.type == Addon.BindingTypes.UNIT_SELECT or binding.type == Addon.BindingTypes.UNIT_MENU then
DrawMacroCombat(container, load.combat)
else
if Addon:IsGameVersionAtleast("RETAIL") then
if Addon.EXPANSION_LEVEL >= Addon.EXPANSION.DF then
local classNames = GetTriStateLoadOptionValue(load.class)
local specIndices = GetTriStateLoadOptionValue(load.specialization)
local specializationIds = GetRelevantSpecializationIds(classNames, specIndices)

DrawMacroInStance(container, load.form, specializationIds)
elseif Addon:IsGameVersionAtleast("CLASSIC") then
else
local classNames = GetTriStateLoadOptionValue(load.class)

Classic_DrawMacroInStance(container, load.form, classNames)
Expand All @@ -2408,16 +2414,18 @@ local function DrawBindingMacroConditionsPage(container, binding)
DrawMacroSwimming(container, load.swimming)
DrawMacroChanneling(container, load.channeling)

if Addon:IsGameVersionAtleast("BC") then
if Addon.EXPANSION_LEVEL >= Addon.EXPANSION.BC then
DrawMacroFlying(container, load.flying)
DrawMacroFlyable(container, load.flyable)
end

if Addon:IsGameVersionAtleast("RETAIL") then
DrawMacroAdvancedFlyable(container, load.advancedFlyable)
if Addon.EXPANSION_LEVEL >= Addon.EXPANSION.CATA then
DrawMacroBonusBar(container, load.bonusbar)
end

DrawMacroBonusBar(container, load.bonusbar)
if Addon.EXPANSION_LEVEL >= Addon.EXPANSION.DF then
DrawMacroAdvancedFlyable(container, load.advancedFlyable)
end
end
end

Expand Down Expand Up @@ -2567,47 +2575,29 @@ end
--- @param container AceGUIContainer
--- @param instanceType Binding.TriStateLoadOption
local function DrawLoadInInstanceType(container, instanceType)
local items = {}
local order
local items = {
NONE = Addon.L["No Instance"],
PARTY = Addon.L["Dungeon"],
RAID = Addon.L["Raid"]
}

if Addon:IsGameVersionAtleast("CLASSIC") then
items["NONE"] = Addon.L["No Instance"]
items["PARTY"] = Addon.L["Dungeon"]
items["RAID"] = Addon.L["Raid"]
end
local order = {
"NONE",
"PARTY",
"RAID"
}

if Addon:IsGameVersionAtleast("BC") then
if Addon.EXPANSION_LEVEL >= Addon.EXPANSION.BC then
items["PVP"] = Addon.L["Battleground"]
items["ARENA"] = Addon.L["Arena"]
end

if Addon:IsGameVersionAtleast("RETAIL") then
items["SCENARIO"] = Addon.L["Scenario"]
table.insert(order, "PVP")
table.insert(order, "ARENA")
end

if Addon:IsGameVersionAtleast("RETAIL") then
order = {
"NONE",
"SCENARIO",
"PARTY",
"RAID",
"PVP",
"ARENA"
}
elseif Addon:IsGameVersionAtleast("BC") then
order = {
"NONE",
"PARTY",
"RAID",
"PVP",
"ARENA"
}
elseif Addon:IsGameVersionAtleast("CLASSIC") then
order = {
"NONE",
"PARTY",
"RAID"
}
if Addon.EXPANSION_LEVEL >= Addon.EXPANSION.MOP then
items["SCENARIO"] = Addon.L["Scenario"]
table.insert(order, 2, "SCENARIO")
end

DrawTristateLoadOption(container, Addon.L["Instance type"], items, order, instanceType)
Expand Down Expand Up @@ -2676,23 +2666,24 @@ local function DrawBindingLoadConditionsPage(container, binding)
DrawLoadClass(container, load.class)
DrawLoadRace(container, load.race)

if Addon:IsGameVersionAtleast("CATA") then
if Addon.EXPANSION_LEVEL >= Addon.EXPANSION.CATA then
local classNames = GetTriStateLoadOptionValue(load.class)
local specIndices = GetTriStateLoadOptionValue(load.specialization)
local specializationIds = GetRelevantSpecializationIds(classNames, specIndices)

DrawLoadSpecialization(container, load.specialization, classNames)
DrawLoadTalent(container, load.talent --[[@as Binding.MutliFieldLoadOption]], specializationIds)

if Addon:IsGameVersionAtleast("RETAIL") then
if Addon.EXPANSION_LEVEL >= Addon.EXPANSION.BFA then
DrawLoadPvPTalent(container, load.pvpTalent, specializationIds)
DrawLoadWarMode(container, load.warMode)
end
elseif Addon:IsGameVersionAtleast("WOTLK") then
local classNames = GetTriStateLoadOptionValue(load.class)
-- TODO: Re-enable this once talents are supported in Classic
-- else
-- local classNames = GetTriStateLoadOptionValue(load.class)

Classic_DrawLoadSpecialization(container, load.specialization)
Classic_DrawLoadTalent(container, load.talent --[[@as Binding.TriStateLoadOption]], classNames)
-- Classic_DrawLoadSpecialization(container, load.specialization)
-- Classic_DrawLoadTalent(container, load.talent --[[@as Binding.TriStateLoadOption]], classNames)
end

DrawLoadInInstanceType(container, load.instanceType)
Expand Down Expand Up @@ -2954,10 +2945,10 @@ local function CreateFromItemTemplate(identifier)
elseif identifier == ITEM_TEMPLATE_IMPORT_ACTIONBAR then
local group

if Addon:IsGameVersionAtleast("CATA") then
if Addon.EXPANSION_LEVEL >= Addon.EXPANSION.CATA then
local name, icon

if Addon:IsGameVersionAtleast("RETAIL") then
if Addon.EXPANSION_LEVEL >= Addon.EXPANSION.MOP then
_, name, _, icon = GetSpecializationInfo(GetSpecialization())
else
local class = select(3, UnitClass("player"))
Expand Down Expand Up @@ -3038,9 +3029,12 @@ local function CreateFromItemTemplate(identifier)
binding.load.class.selected = 1
binding.load.class.single = select(2, UnitClass("player"))

if Addon:IsGameVersionAtleast("CATA") then
if Addon.EXPANSION_LEVEL >= Addon.EXPANSION.MOP then
binding.load.specialization.selected = 1
binding.load.specialization.single = GetSpecialization()
elseif Addon.EXPANSION_LEVEL >= Addon.EXPANSION.CATA then
binding.load.specialization.selected = 1
binding.load.specialization.single = GetSpecialization and GetSpecialization() or GetPrimaryTalentTree()
binding.load.specialization.single = GetPrimaryTalentTree()
end
end
end
Expand Down Expand Up @@ -3184,7 +3178,7 @@ local function DrawBinding(container)
end

-- self-cast text
if Addon:IsGameVersionAtleast("RETAIL") then
if Addon.EXPANSION_LEVEL >= Addon.EXPANSION.DF then
local selfCastModifier = GetModifiedClick("SELFCAST")

if selfCastModifier ~= "NONE" then
Expand Down Expand Up @@ -3442,7 +3436,7 @@ function Addon:BindingConfig_Initialize()
HijackSpellButton_UpdateButton(nil)
end)

if Addon:IsGameVersionAtleast("CATA") then
if 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
2 changes: 1 addition & 1 deletion Clicked/Core/AttributeHandler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ function Addon:CreateCommandAttributes(register, command, prefix, suffix)
elseif command.action == Addon.CommandType.MACRO then
local attributeType = "type"

if Addon:IsGameVersionAtleast("RETAIL") and not Addon.db.profile.options.onKeyDown then
if Addon.EXPANSION_LEVEL >= Addon.EXPANSION.DF and not Addon.db.profile.options.onKeyDown then
attributeType = "typerelease"
end

Expand Down
33 changes: 18 additions & 15 deletions Clicked/Core/BindingProcessor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -248,16 +248,19 @@ local function ConstructAction(binding, target)
AppendCondition(binding.load.swimming, "swimming")
AppendNegatableStringCondition(binding.load.channeling, "channeling")

if Addon:IsGameVersionAtleast("BC") then
if Addon.EXPANSION_LEVEL >= Addon.EXPANSION.BC then
AppendCondition(binding.load.flying, "flying")
AppendCondition(binding.load.flyable, "flyable")
end

if Addon:IsGameVersionAtleast("RETAIL") then
AppendCondition(binding.load.advancedFlyable, "advflyable")
if Addon.EXPANSION_LEVEL >= Addon.EXPANSION.CATA then
AppendNegatableStringCondition(binding.load.bonusbar, "bonusbar")
end

if Addon.EXPANSION_LEVEL >= Addon.EXPANSION.DF then
AppendCondition(binding.load.advancedFlyable, "advflyable")
end

do
local forms = Addon:GetAvailableShapeshiftForms(binding)

Expand Down Expand Up @@ -826,7 +829,7 @@ function Addon:UpdateTalentCacheAndReloadBindings(delay, ...)
return
end

if Addon:IsGameVersionAtleast("RETAIL") then
if Addon.EXPANSION_LEVEL >= Addon.EXPANSION.DF then
wipe(talentCache)

local configId = C_ClassTalents.GetActiveConfigID()
Expand Down Expand Up @@ -875,7 +878,7 @@ function Addon:UpdateTalentCacheAndReloadBindings(delay, ...)
end
end
end
elseif Addon:IsGameVersionAtleast("CATA") then
elseif Addon.EXPANSION_LEVEL >= Addon.EXPANSION.CATA then
wipe(talentCache)

for tab = 1, GetNumTalentTabs() do
Expand Down Expand Up @@ -1026,7 +1029,7 @@ function Addon:UpdateBindingLoadState(binding, options)
state.race = ValidateTriStateLoadOption(load.race, IsRaceIndexSelected)
end

if Addon:IsGameVersionAtleast("RETAIL") then
if Addon.EXPANSION_LEVEL >= Addon.EXPANSION.BFA then
-- pvp talent selected
if ShouldPerformStateCheck("PLAYER_PVP_TALENT_UPDATE") then
local cache = {}
Expand Down Expand Up @@ -1112,15 +1115,15 @@ function Addon:UpdateBindingLoadState(binding, options)
end
end

if Addon:IsGameVersionAtleast("WOTLK") then
if Addon.EXPANSION_LEVEL >= Addon.EXPANSION.CATA then
-- specialization
if ShouldPerformStateCheck("PLAYER_TALENT_UPDATE") then
local function IsSpecializationIndexSelected(index)
local retail = GetSpecialization and GetSpecialization()
local cata = GetPrimaryTalentTree and GetPrimaryTalentTree()
local wotlk = GetActiveTalentGroup and GetActiveTalentGroup()
local selected = retail or cata or wotlk
return index == selected
if Addon.EXPANSION_LEVEL >= Addon.EXPANSION.MOP then
return index == GetSpecialization()
else
return index == GetPrimaryTalentTree()
end
end

state.specialization = ValidateTriStateLoadOption(load.specialization, IsSpecializationIndexSelected)
Expand Down Expand Up @@ -1189,7 +1192,7 @@ function Addon:UpdateBindingLoadState(binding, options)
return true
end

if Addon:IsGameVersionAtleast("RETAIL") then
if Addon.EXPANSION_LEVEL >= Addon.EXPANSION.DF then
local specId = GetSpecializationInfo(GetSpecialization())

-- specId can be nil on the first PLAYER_TALENT_UPDATE event fires before PLAYER_ENTERING_WORLD fires
Expand All @@ -1204,7 +1207,7 @@ function Addon:UpdateBindingLoadState(binding, options)
end

return IsSpellKnown(forms[formIndex])
elseif Addon:IsGameVersionAtleast("CLASSIC") then
else
local class = select(2, UnitClass("player"))
local forms = Addon:Classic_GetShapeshiftForms(class)

Expand All @@ -1225,7 +1228,7 @@ function Addon:UpdateBindingLoadState(binding, options)
do
local checks = { "PLAYER_TALENT_UPDATE", "PLAYER_LEVEL_CHANGED", "LEARNED_SPELL_IN_TAB" }

if Addon:IsClassic() then
if Addon.EXPANSION_LEVEL == Addon.EXPANSION.CLASSIC then
table.insert(checks, "RUNE_UPDATED")
table.insert(checks, "PLAYER_EQUIPMENT_CHANGED")
end
Expand Down
Loading

0 comments on commit 837512e

Please sign in to comment.