From 9a607f93aac090fce76a1a8c6ba736251a84ba6c Mon Sep 17 00:00:00 2001 From: Simpy Date: Thu, 9 Jan 2025 15:52:54 -0500 Subject: [PATCH] fix the class stuff in options --- ElvUI/Core/General/API.lua | 64 +++++++++++++------ ElvUI/Core/General/Core.lua | 1 + ElvUI/Mainline/Modules/Nameplates/PVPRole.lua | 28 ++++---- ElvUI_Options/Core/Core.lua | 9 +-- ElvUI_Options/Core/StyleFilters.lua | 28 ++++---- 5 files changed, 73 insertions(+), 57 deletions(-) diff --git a/ElvUI/Core/General/API.lua b/ElvUI/Core/General/API.lua index c015a11f5a..447924b244 100644 --- a/ElvUI/Core/General/API.lua +++ b/ElvUI/Core/General/API.lua @@ -16,7 +16,6 @@ local strfind, strlen, tonumber, tostring = strfind, strlen, tonumber, tostring local CopyTable = CopyTable local CreateFrame = CreateFrame local GetBattlefieldArenaFaction = GetBattlefieldArenaFaction -local GetClassInfo = GetClassInfo local GetGameTime = GetGameTime local GetInstanceInfo = GetInstanceInfo local GetNumGroupMembers = GetNumGroupMembers @@ -42,6 +41,7 @@ local UnitInRaid = UnitInRaid local UnitIsMercenary = UnitIsMercenary local UnitIsPlayer = UnitIsPlayer local UnitIsUnit = UnitIsUnit +local UnitSex = UnitSex local GetWatchedFactionInfo = GetWatchedFactionInfo local GetWatchedFactionData = C_Reputation and C_Reputation.GetWatchedFactionData @@ -55,6 +55,7 @@ local GetSpecializationInfo = (E.Classic or E.Cata) and LCS.GetSpecializationInf local IsAddOnLoaded = C_AddOns.IsAddOnLoaded local StoreEnabled = C_StorePublic.IsEnabled +local GetClassInfo = C_CreatureInfo.GetClassInfo local C_TooltipInfo_GetUnit = C_TooltipInfo and C_TooltipInfo.GetUnit local C_TooltipInfo_GetHyperlink = C_TooltipInfo and C_TooltipInfo.GetHyperlink local C_TooltipInfo_GetInventoryItem = C_TooltipInfo and C_TooltipInfo.GetInventoryItem @@ -222,6 +223,26 @@ function E:InverseClassColor(class, usePriestColor, forceCap) return color end +do + local classByID = {} + local classByFile = {} + + E.ClassInfoByID = classByID + E.ClassInfoByFile = classByFile + + for index = 1, 15 do -- really blizzard, whats up with this on anniversary? + local info = GetClassInfo(index) + if info then + classByID[info.classID] = info + classByFile[info.classFile] = info + end + end + + function E:GetClassInfo(value) -- classFile or classID + return classByFile[value] or classByID[value] + end +end + do -- other non-english locales require this E.UnlocalizedClasses = {} for k, v in pairs(_G.LOCALIZED_CLASS_NAMES_MALE) do E.UnlocalizedClasses[v] = k end @@ -230,6 +251,15 @@ do -- other non-english locales require this function E:UnlocalizedClassName(className) return E.UnlocalizedClasses[className] end + + function E:LocalizedClassName(className, unit) + local gender = (not unit and E.mygender) or UnitSex(unit) + if gender == 3 then + return _G.LOCALIZED_CLASS_NAMES_FEMALE[className] + else + return _G.LOCALIZED_CLASS_NAMES_MALE[className] + end + end end do @@ -1178,33 +1208,31 @@ function E:LoadAPI() local MALE = _G.LOCALIZED_CLASS_NAMES_MALE local FEMALE = _G.LOCALIZED_CLASS_NAMES_FEMALE - local i = 1 - local className, classFile, classID = GetClassInfo(i) - local male, female = MALE[classFile], FEMALE[classFile] - while classID do - for index, id in next, E.SpecByClass[classFile] do - local info = { + for _, info in next, E.ClassInfoByID do + local male, female = MALE[info.classFile], FEMALE[info.classFile] + for index, id in next, E.SpecByClass[info.classFile] do + local data = { id = id, index = index, - classFile = classFile, - className = className, + classFile = info.classFile, + className = info.className, englishName = E.SpecName[id] } - E.SpecInfoBySpecID[id] = info + E.SpecInfoBySpecID[id] = data for x = 3, 1, -1 do local _, name, desc, icon, role = GetSpecializationInfoForSpecID(id, x) if x == 1 then -- SpecInfoBySpecID - info.name = name - info.desc = desc - info.icon = icon - info.role = role + data.name = name + data.desc = desc + data.icon = icon + data.role = role - E.SpecInfoBySpecClass[name..' '..className] = info + E.SpecInfoBySpecClass[name..' '..info.className] = data else - local copy = E:CopyTable({}, info) + local copy = E:CopyTable({}, data) copy.name = name copy.desc = desc copy.icon = icon @@ -1219,10 +1247,6 @@ function E:LoadAPI() end end end - - i = i + 1 - className, classFile, classID = GetClassInfo(i) - male, female = MALE[classFile], FEMALE[classFile] end end diff --git a/ElvUI/Core/General/Core.lua b/ElvUI/Core/General/Core.lua index bf83c56d01..ddb99ffeca 100644 --- a/ElvUI/Core/General/Core.lua +++ b/ElvUI/Core/General/Core.lua @@ -61,6 +61,7 @@ E.version, E.versionString, E.versionDev, E.versionGit = E:ParseVersionString('E E.myfaction, E.myLocalizedFaction = UnitFactionGroup('player') E.myLocalizedClass, E.myclass, E.myClassID = UnitClass('player') E.myLocalizedRace, E.myrace, E.myRaceID = UnitRace('player') +E.mygender = UnitSex('player') E.mylevel = UnitLevel('player') E.myname = UnitName('player') E.myrealm = GetRealmName() diff --git a/ElvUI/Mainline/Modules/Nameplates/PVPRole.lua b/ElvUI/Mainline/Modules/Nameplates/PVPRole.lua index 33a574cebd..4e2ffb3dbc 100644 --- a/ElvUI/Mainline/Modules/Nameplates/PVPRole.lua +++ b/ElvUI/Mainline/Modules/Nameplates/PVPRole.lua @@ -5,7 +5,7 @@ local ElvUF = E.oUF local wipe = wipe local format = format -local GetClassInfo = GetClassInfo +local UnitName = UnitName local GetInstanceInfo = GetInstanceInfo local GetBattlefieldScore = GetBattlefieldScore local GetArenaOpponentSpec = GetArenaOpponentSpec @@ -15,7 +15,6 @@ local GetSpecializationInfoByID = GetSpecializationInfoByID local GetSpecializationInfoForClassID = GetSpecializationInfoForClassID local GetNumSpecializationsForClassID = GetNumSpecializationsForClassID -local UnitName = UnitName local UNKNOWN = UNKNOWN local Healers, HealerSpecs = {}, {} @@ -28,20 +27,17 @@ NP.PVPRole = { TankSpecs = TankSpecs } -for i = 1, _G.MAX_CLASSES do - local _, _, classID = GetClassInfo(i) - if classID then - for specIndex = 1, GetNumSpecializationsForClassID(classID) do - local _, mName, _, _, role = GetSpecializationInfoForClassID(classID, specIndex, 2) - local _, fName = GetSpecializationInfoForClassID(classID, specIndex, 3) - - if role == 'HEALER' then - HealerSpecs[mName] = true - HealerSpecs[fName] = true - elseif role == 'TANK' then - TankSpecs[mName] = true - TankSpecs[fName] = true - end +for classID in next, E.ClassInfoByID do + for specIndex = 1, GetNumSpecializationsForClassID(classID) do + local _, mName, _, _, role = GetSpecializationInfoForClassID(classID, specIndex, 2) + local _, fName = GetSpecializationInfoForClassID(classID, specIndex, 3) + + if role == 'HEALER' then + HealerSpecs[mName] = true + HealerSpecs[fName] = true + elseif role == 'TANK' then + TankSpecs[mName] = true + TankSpecs[fName] = true end end end diff --git a/ElvUI_Options/Core/Core.lua b/ElvUI_Options/Core/Core.lua index 2cec95e64b..aa2223cecf 100644 --- a/ElvUI_Options/Core/Core.lua +++ b/ElvUI_Options/Core/Core.lua @@ -29,7 +29,7 @@ local UnitExists = UnitExists local UnitIsUnit = UnitIsUnit local UnitIsFriend = UnitIsFriend local UnitIsPlayer = UnitIsPlayer -local GetClassInfo = GetClassInfo + local CLASS_SORT_ORDER = CLASS_SORT_ORDER local NUM_CLASSES = #CLASS_SORT_ORDER @@ -68,11 +68,8 @@ C.Values = { do C.ClassTable = {} - for i = 1, NUM_CLASSES do - local name, tag = GetClassInfo(i) - if tag then - C.ClassTable[tag] = name - end + for _, info in next, E.ClassInfoByID do + C.ClassTable[info.classFile] = info.className end end diff --git a/ElvUI_Options/Core/StyleFilters.lua b/ElvUI_Options/Core/StyleFilters.lua index 06e1796154..35d46bba51 100644 --- a/ElvUI_Options/Core/StyleFilters.lua +++ b/ElvUI_Options/Core/StyleFilters.lua @@ -10,7 +10,6 @@ local _G = _G local wipe, pairs, strmatch, strsplit, tostring = wipe, pairs, strmatch, strsplit, tostring local next, sort, tinsert, tonumber, format = next, sort, tinsert, tonumber, format -local GetClassInfo = GetClassInfo local GetDifficultyInfo = GetDifficultyInfo local GetInstanceInfo = GetInstanceInfo local GetRealZoneText = GetRealZoneText @@ -346,25 +345,24 @@ StyleFilters.triggers.args.faction.args.types.args.Neutral = ACH:Toggle(L["Neutr StyleFilters.triggers.args.class = ACH:Group(L["CLASS"], nil, 12, nil, nil, nil, DisabledFilter) -for index = 1, C.Values.NUM_CLASSES do - local className, classTag, classID = GetClassInfo(index) - if classTag then - local coloredName = E:ClassColor(classTag) - coloredName = (coloredName and coloredName.colorStr) or 'ff666666' - StyleFilters.triggers.args.class.args[classTag] = ACH:Toggle(format('|c%s%s|r', coloredName, className), nil, tIndexOf(sortedClasses, classTag), nil, nil, nil, function() local triggers = GetFilter(true) local tagTrigger = triggers.class[classTag] return tagTrigger and tagTrigger.enabled end, function(_, value) local triggers = GetFilter(true) local tagTrigger = triggers.class[classTag] if not tagTrigger then triggers.class[classTag] = {} end if value then triggers.class[classTag].enabled = value else triggers.class[classTag] = nil end NP:ConfigureAll() end) +for classID, info in next, E.ClassInfoByID do + local className, classFile = info.className, info.classFile - local group = ACH:Group(className, nil, tIndexOf(sortedClasses, classTag) + 13, nil, nil, nil, nil, function() local triggers = GetFilter(true) local tagTrigger = triggers.class[classTag] return not tagTrigger or not tagTrigger.enabled end) - group.inline = true + local coloredName = E:ClassColor(classFile) + coloredName = (coloredName and coloredName.colorStr) or 'ff666666' + StyleFilters.triggers.args.class.args[classFile] = ACH:Toggle(format('|c%s%s|r', coloredName, className), nil, tIndexOf(sortedClasses, classFile), nil, nil, nil, function() local triggers = GetFilter(true) local tagTrigger = triggers.class[classFile] return tagTrigger and tagTrigger.enabled end, function(_, value) local triggers = GetFilter(true) local tagTrigger = triggers.class[classFile] if not tagTrigger then triggers.class[classFile] = {} end if value then triggers.class[classFile].enabled = value else triggers.class[classFile] = nil end NP:ConfigureAll() end) - for k = 1, GetNumSpecializationsForClassID(classID) do - local specID, name = GetSpecializationInfoForClassID(classID, k) + local group = ACH:Group(className, nil, tIndexOf(sortedClasses, classFile) + 13, nil, nil, nil, nil, function() local triggers = GetFilter(true) local tagTrigger = triggers.class[classFile] return not tagTrigger or not tagTrigger.enabled end) + group.inline = true - local tagID = format('%s%s', classTag, specID) - group.args[tagID] = ACH:Toggle(format('|c%s%s|r', coloredName, name), nil, k, nil, nil, nil, function() local triggers = GetFilter(true) local tagTrigger = triggers.class[classTag] return tagTrigger and tagTrigger.specs and tagTrigger.specs[specID] end, function(_, value) local triggers = GetFilter(true) local tagTrigger = triggers.class[classTag] if not tagTrigger.specs then triggers.class[classTag].specs = {} end triggers.class[classTag].specs[specID] = value or nil if not next(triggers.class[classTag].specs) then triggers.class[classTag].specs = nil end NP:ConfigureAll() end) - end + for k = 1, GetNumSpecializationsForClassID(classID) do + local specID, name = GetSpecializationInfoForClassID(classID, k) - StyleFilters.triggers.args.class.args[format('%s%s', classTag, 'spec')] = group + local tagID = format('%s%s', classFile, specID) + group.args[tagID] = ACH:Toggle(format('|c%s%s|r', coloredName, name), nil, k, nil, nil, nil, function() local triggers = GetFilter(true) local tagTrigger = triggers.class[classFile] return tagTrigger and tagTrigger.specs and tagTrigger.specs[specID] end, function(_, value) local triggers = GetFilter(true) local tagTrigger = triggers.class[classFile] if not tagTrigger.specs then triggers.class[classFile].specs = {} end triggers.class[classFile].specs[specID] = value or nil if not next(triggers.class[classFile].specs) then triggers.class[classFile].specs = nil end NP:ConfigureAll() end) end + + StyleFilters.triggers.args.class.args[format('%s%s', classFile, 'spec')] = group end local EquippedValues = {