From 7272cb1ef5d31bb696b8cd212f98779e35656693 Mon Sep 17 00:00:00 2001 From: armin-l <107995326+armin-l@users.noreply.github.com> Date: Thu, 23 Apr 2026 23:08:53 +0200 Subject: [PATCH 1/2] Add support for short spec names and related UI toggle --- RaidBrowser/RaidBrowser.toc | 2 +- RaidBrowser/core.lua | 5 +++ RaidBrowser/raidset_frame.lua | 50 +++++++++++++++++++++++++++-- RaidBrowser/stats.lua | 60 +++++++++++++++++++++++++++++++++-- 4 files changed, 110 insertions(+), 7 deletions(-) diff --git a/RaidBrowser/RaidBrowser.toc b/RaidBrowser/RaidBrowser.toc index 55c855f..3d9f8be 100644 --- a/RaidBrowser/RaidBrowser.toc +++ b/RaidBrowser/RaidBrowser.toc @@ -3,7 +3,7 @@ ## Version: v1.4.0-DEV ## Notes: A raid finder that parses chat channel text and displays any found raids in the raid browser LFR frame. ## Author: Act/Horsebreed@Warmane -## SavedVariablesPerCharacter: RaidBrowserCharacterRaidsets, RaidBrowserCharacterCurrentRaidset +## SavedVariablesPerCharacter: RaidBrowserCharacterRaidsets, RaidBrowserCharacterCurrentRaidset, RaidBrowserCharacterUseShortSpecNames ## OptionalDeps: GearScoreLite ## X-Embeds: Ace3 diff --git a/RaidBrowser/core.lua b/RaidBrowser/core.lua index 806f1c7..578f964 100644 --- a/RaidBrowser/core.lua +++ b/RaidBrowser/core.lua @@ -1247,6 +1247,10 @@ function RaidBrowser:OnEnable() }; end + if RaidBrowserCharacterUseShortSpecNames == nil then + RaidBrowserCharacterUseShortSpecNames = false; + end + -- LFM messages expire after 60 seconds RaidBrowser.expiry_time = 60; @@ -1257,6 +1261,7 @@ function RaidBrowser:OnEnable() end RaidBrowser.check_button() + RaidBrowser.gui.raidset.initialize(); end function RaidBrowser:OnDisable() diff --git a/RaidBrowser/raidset_frame.lua b/RaidBrowser/raidset_frame.lua index 5ca5c17..1ceb391 100644 --- a/RaidBrowser/raidset_frame.lua +++ b/RaidBrowser/raidset_frame.lua @@ -4,8 +4,18 @@ local frame = CreateFrame("Frame", "RaidBrowserRaidSetMenu", LFRBrowseFrame, "UI UIDropDownMenu_SetWidth(RaidBrowserRaidSetMenu, 150) frame:SetWidth(90); +---@type 'Active'|'Primary'|'Secondary'|'Both'|nil local current_selection = nil; +---@param selection any +---@return 'Active'|'Primary'|'Secondary'|'Both' +local function normalize_selection(selection) + if selection == 'Active' or selection == 'Primary' or selection == 'Secondary' or selection == 'Both' then + return selection + end + return 'Active' +end + ---@return boolean local function is_active_selected(_) return 'Active' == current_selection; @@ -25,7 +35,7 @@ local function is_both_selected(option) return ('Both' == current_selection); end ----@param selection 'Active'|'Primary'|'Secondary' +---@param selection 'Active'|'Primary'|'Secondary'|'Both' local function set_selection(selection) local text = ''; @@ -180,11 +190,20 @@ local function on_raidset_save() ---@diagnostic disable-next-line: undefined-field RaidBrowser:Print('Raidset saved: ' .. spec .. ' ' .. gs .. 'gs'); - set_selection(current_selection); + if current_selection then + set_selection(current_selection) + else + set_selection('Active') + end end function RaidBrowser.gui.raidset.initialize() - set_selection(RaidBrowserCharacterCurrentRaidset); + local selection = normalize_selection(RaidBrowserCharacterCurrentRaidset) + set_selection(selection) + if short_spec_check then + local use_short_names = RaidBrowser.stats.use_short_spec_names and RaidBrowser.stats.use_short_spec_names() or false + short_spec_check:SetChecked(use_short_names) + end end local function check_button(button) @@ -234,4 +253,29 @@ button:SetText("Save Raid Gear"); button:SetWidth(110); button:SetScript("OnClick", on_raidset_save); button:Show(); + +-- Create short spec names checkbox +short_spec_check = CreateFrame("CheckButton", "RaidBrowserRaidSetShortSpecCheckButton", LFRBrowseFrame, "UICheckButtonTemplate") +short_spec_check:SetPoint("CENTER", LFRBrowseFrame, "CENTER", -137, -169) +short_spec_check:SetScript("OnClick", function(self) + local enabled = self:GetChecked() ~= nil; + if RaidBrowser.stats.set_use_short_spec_names then + RaidBrowser.stats.set_use_short_spec_names(enabled) + end + if RaidBrowser.stats.refresh_saved_raidset_spec_names then + RaidBrowser.stats.refresh_saved_raidset_spec_names() + end + + if current_selection then + set_selection(current_selection); + end + + ---@diagnostic disable-next-line: undefined-field + RaidBrowser:Print('Short spec names: ' .. (enabled and 'enabled' or 'disabled')); +end) + +local short_spec_label = _G[short_spec_check:GetName() .. "Text"] +if short_spec_label then + short_spec_label:SetText("Use short spec names") +end check_button(button); diff --git a/RaidBrowser/stats.lua b/RaidBrowser/stats.lua index 3198a98..3f10dff 100644 --- a/RaidBrowser/stats.lua +++ b/RaidBrowser/stats.lua @@ -219,6 +219,61 @@ local spec_names = { } } +local spec_name_lookup = {} +for key, label in pairs(spec_names.full) do + spec_name_lookup[label] = key +end +for key, label in pairs(spec_names.short) do + spec_name_lookup[label] = key +end + +local function use_short_spec_names() + return RaidBrowserCharacterUseShortSpecNames == true +end + +local function get_readable_spec_name(spec_key) + if use_short_spec_names() then + return spec_names.short[spec_key] or spec_key + end + return spec_names.full[spec_key] or spec_key +end + +local function normalize_saved_spec_name(spec) + if not spec then return spec end + + local base, suffix = string.match(spec, "^(.-)%s*(%b())$") + if suffix ~= "(Tank)" and suffix ~= "(DPS)" then + base = spec + suffix = "" + end + + local key = spec_name_lookup[base] + if not key then + return spec + end + + return get_readable_spec_name(key) .. suffix +end + +function RaidBrowser.stats.use_short_spec_names() + return use_short_spec_names() +end + +function RaidBrowser.stats.set_use_short_spec_names(enabled) + RaidBrowserCharacterUseShortSpecNames = enabled == true +end + +function RaidBrowser.stats.refresh_saved_raidset_spec_names() + if not RaidBrowserCharacterRaidsets then return end + + for _, set in ipairs({ "Primary", "Secondary" }) do + local raidset = RaidBrowserCharacterRaidsets[set] + if raidset and raidset.spec then + raidset.spec = normalize_saved_spec_name(raidset.spec) + end + end +end + ---@param raid string The name of the achievement ids table ---@nodiscard local function find_best_achievement(raid) @@ -280,8 +335,7 @@ function RaidBrowser.stats.active_spec() local _, _, _, spec_name = GetTalentTabInfo(active_tab); local _, class = UnitClass("player"); - -- TODO: make config to toggle using full or short spec names - local readable_spec_name = spec_names["short"][spec_name] or spec_name; + local readable_spec_name = get_readable_spec_name(spec_name) -- If we're a feral druid, then we need to distinguish between tank and cat feral. if spec_name == 'DruidFeralCombat' then @@ -395,7 +449,7 @@ function RaidBrowser.stats.current_raidset() return RaidBrowser.stats.get_raidset(RaidBrowserCharacterCurrentRaidset); end ----@param set 'Active' | 'Primary' | 'Secondary' +---@param set 'Active' | 'Primary' | 'Secondary' | 'Both' function RaidBrowser.stats.select_current_raidset(set) RaidBrowserCharacterCurrentRaidset = set; end From 959510a931ab17b72401b692bacbc5c619af1426 Mon Sep 17 00:00:00 2001 From: armin-l <107995326+armin-l@users.noreply.github.com> Date: Sun, 24 May 2026 21:55:12 +0200 Subject: [PATCH 2/2] Handle nil spec_key in get_readable_spec_name and ensure active_spec returns a default index --- RaidBrowser/stats.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/RaidBrowser/stats.lua b/RaidBrowser/stats.lua index 3f10dff..8fc6355 100644 --- a/RaidBrowser/stats.lua +++ b/RaidBrowser/stats.lua @@ -232,6 +232,10 @@ local function use_short_spec_names() end local function get_readable_spec_name(spec_key) + if spec_key == nil then + return "Unknown Spec" + end + if use_short_spec_names() then return spec_names.short[spec_key] or spec_key end @@ -327,7 +331,7 @@ end function RaidBrowser.stats.active_spec_index() local indices = std.algorithm.transform({ 1, 2, 3 }, GetTalentTabPoints) local i, _ = std.algorithm.max_of(indices); - return i; + return i or 1; end function RaidBrowser.stats.active_spec() @@ -342,6 +346,7 @@ function RaidBrowser.stats.active_spec() local protector_of_pack_talent = 22; local thick_hide_talent = 5; local _, _, _, _, points = GetTalentInfo(active_tab, thick_hide_talent) + points = tonumber(points) or 0 if points > 1 then return readable_spec_name .. ' (Tank)' else @@ -355,6 +360,8 @@ function RaidBrowser.stats.active_spec() local blade_barrier_talent = 3; local _, _, _, _, points = GetTalentInfo(2, toughness_talent) local _, _, _, _, points2 = GetTalentInfo(1, blade_barrier_talent) + points = tonumber(points) or 0 + points2 = tonumber(points2) or 0 if points > 3 and points2 > 3 then return readable_spec_name .. ' (Tank)' else