From 78d1c6daea864577d76db8d2ee76f6ad83e2101d Mon Sep 17 00:00:00 2001 From: urnati Date: Mon, 1 Dec 2025 14:49:36 -0500 Subject: [PATCH] - Add back Global as Synch All - Fix Titan Config > Plugins Show / Hide - Code cleanup --- Titan/Titan.lua | 6 +- Titan/TitanConfig.lua | 205 ++++++++++++++++++++++++++++++++++++++-------- Titan/TitanTemplate.lua | 1 - Titan/TitanUtils.lua | 175 +++++++++++---------------------------- Titan/TitanVariables.lua | 199 ++++++++++++++++++++++++++++++++++---------- Titan/_TitanIDE.lua | 11 ++- 6 files changed, 384 insertions(+), 213 deletions(-) diff --git a/Titan/Titan.lua b/Titan/Titan.lua index d355eba..17ca730 100644 --- a/Titan/Titan.lua +++ b/Titan/Titan.lua @@ -366,7 +366,7 @@ function TitanPanel_PlayerEnteringWorld(reload) -- This will set the bar(s) and enabled plugins (via OnShow). Titan_Debug.Out('titan', 'p_e_w', "Synch plugin saved vars") - Titan_Debug.Out('titan', 'p_e_w', "Synch plugin saved vars") + Titan_Debug.Out('titan', 'p_e_w', "Set up player") TitanVariables_UseSettings(nil, TitanUtils_GetPlayer(), TITAN_PROFILE_INIT) Titan_Debug.Out('titan', 'p_e_w', "Init config data (right click menu)") @@ -1371,7 +1371,7 @@ end ---Titan Force all plugins created from LDB addons, visible or not, to be on the right side of the Titan bar. --- Any visible plugin will be forced to the right side on the same bar it is currently on. function TitanPanelBarButton_ForceLDBLaunchersRight() - local plugin = {} + local plugin --= {} for index, id in pairs(TitanPluginsIndex) do plugin = TitanUtils_GetPlugin(id); if plugin and plugin.ldb == "launcher" @@ -1970,7 +1970,7 @@ local function BuildMainMenu(frame) end TitanPanelRightClickMenu_AddButton(info); - local res = TitanUtils_GetProfile() + local res = TitanVariables_GetProfile(TitanUtils_GetPlayer()) info = {}; info.notCheckable = true info.text = res.cname diff --git a/Titan/TitanConfig.lua b/Titan/TitanConfig.lua index e9237d9..ef5799d 100644 --- a/Titan/TitanConfig.lua +++ b/Titan/TitanConfig.lua @@ -996,7 +996,7 @@ local function UpdateConfigAddons() local name = info[1] if v then -- Show / add local bar = (TitanGetVar(name, "ForceBar") or TitanUtils_PickBar()) - if type(bar) == string then -- sanity and IDE + if type(bar) == 'string' then -- sanity and IDE ---@diagnostic disable-next-line: param-type-mismatch TitanUtils_AddButtonOnBar(bar, name) end @@ -1327,18 +1327,37 @@ local optionsChars = { args = {} } +local function SummaryText(profile) + local res = "" + + if profile.ptype == Titan_Global.profile.GLOBAL then + res = L["TITAN_PANEL_GLOBAL"].." : "..profile.cname + elseif profile.ptype == Titan_Global.profile.SYNC then + res = L["TITAN_PANEL_MENU_PROFILE_SYNC"].." : "..profile.cname + elseif profile.ptype == Titan_Global.profile.TOON then + res = L["TITAN_PANEL_MENU_PROFILE_CHARS"].." : "..Titan_Global.profile.NONE + else + res = "?".." : "..Titan_Global.profile.NONE + end + + return res +end + +-- These are here so the config function can see them (not sure this works...). +local players = {} -- used for left side list of profiles +local p_info = {} -- used to hold info about each toon in players +local p_sync = {} -- profiles used as Sync + ---Allow the user to load / delete / reset / sync profile data local function TitanUpdateChars() - local players = {} -- used for left side list of profiles - local p_info = {} -- used to hold info about each toon in players - local p_sync = {} -- profiles used as Sync + players = {} -- used for left side list of profiles + p_info = {} -- used to hold info about each toon in players + p_sync = {} -- profiles used as Sync -- Rip through the players (with server name) to sort them for index, id in pairs(TitanSettings.Players) do table.insert(players, index); - TitanUtil_CheckProfile(index) -- ensure valid sync - -- collect some info on THIS toon for the config local this_toon = {} @@ -1353,6 +1372,8 @@ local function TitanUpdateChars() end this_toon.name = index + this_toon.profile = TitanVariables_GetProfile(index) + this_toon.summary = SummaryText(this_toon.profile) this_toon.is_player = (index == TitanUtils_GetPlayer()) this_toon.sync_set = not (id.Panel["SyncWithProfile"] == Titan_Global.profile.NONE) this_toon.sync_name = id.Panel["SyncWithProfile"] @@ -1365,6 +1386,7 @@ local function TitanUpdateChars() -- return a < b -- end) + -- set up the options for the user local args = optionsChars.args @@ -1389,6 +1411,9 @@ local function TitanUpdateChars() for idx = 1, #players do local this_toon = p_info[idx] local position = 100 + -- Check for global profile being set + local g_sync = (this_toon.profile.ptype == Titan_Global.profile.GLOBAL) + args[this_toon.name] = { type = "group", name = this_toon.fancy_name, @@ -1415,7 +1440,9 @@ local function TitanUpdateChars() } position = position + 1 local l_reason = "" - if this_toon.is_player then + if g_sync then + l_reason = "Sync All set" + elseif this_toon.is_player then l_reason = L["TITAN_PANEL_MENU_LOAD_SETTINGS_ERR1"] else l_reason = "." @@ -1430,18 +1457,18 @@ local function TitanUpdateChars() TitanVariables_UseSettings(info[1], TitanUtils_GetPlayer(), TITAN_PROFILE_USE) end, -- does not make sense to load current character profile - disabled = this_toon.is_player, + disabled = (this_toon.is_player or g_sync), } position = position + 1 local del_reason = "" - if p_sync[this_toon.name] then + if g_sync then + del_reason = "" -- set above + elseif p_sync[this_toon.name] then del_reason = L["TITAN_PANEL_MENU_PROFILE_DELETE_SETTINGS_ERR1"] elseif this_toon.is_player then del_reason = L["TITAN_PANEL_MENU_PROFILE_DELETE_SETTINGS_ERR2"] - -- elseif this_toon.sync_set then - -- del_reason = "Delete not allowed, Sync is set." else - del_reason = "." + del_reason = "" end p_args.optiondelete = { name = L["TITAN_PANEL_MENU_PROFILE_DELETE_SETTINGS"], @@ -1460,9 +1487,9 @@ local function TitanUpdateChars() AceConfigRegistry:NotifyChange("Titan Panel Addon Chars") end, -- can not delete current character profile - disabled = this_toon.is_player - -- or this_toon.sync_set - or p_sync[this_toon.name], + disabled = (this_toon.is_player + or g_sync + or p_sync[this_toon.name]), } position = position + 1 p_args.sp_30 = { @@ -1509,23 +1536,22 @@ local function TitanUpdateChars() .. " " .. tostring(Titan_Global.profile.TOON) .. "" .. " > '" .. tostring(info[1]) .. "'" .. " : '" .. tostring(TITAN_PROFILE_RESET) .. "'" - .. " | '" .. tostring(this_toon.is_player) .. "'" +-- .. " | '" .. tostring(p_info[info[1]].is_player) .. "'" Titan_Debug.Out('titan', 'profile', str) - -- Reset the profile - TitanSettings.Players[info[1]] = nil - if this_toon.is_player then -- Change over to new profile - TitanVariables_UseSettings(nil, TitanUtils_GetPlayer(), TITAN_PROFILE_USE) + TitanVariables_UseSettings(nil, TitanUtils_GetPlayer(), TITAN_PROFILE_RESET) else -- Not this toon. Next time user plays this toon it will reset + TitanSettings.Players[info[1]] = nil end TitanUpdateChars() AceConfigRegistry:NotifyChange("Titan Panel Addon Chars") end, + disabled = (g_sync), } position = position + 1 p_args.sp_39 = { @@ -1543,7 +1569,9 @@ local function TitanUpdateChars() } position = position + 1 local s_reason = "" - if this_toon.sync_set then + if g_sync then + s_reason = "" -- set above + elseif this_toon.sync_set then s_reason = L["TITAN_PANEL_MENU_PROFILE_SYNC_ERR1"] elseif this_toon.is_player then s_reason = L["TITAN_PANEL_MENU_PROFILE_SYNC_ERR2"] @@ -1558,7 +1586,7 @@ local function TitanUpdateChars() --width = "full", func = function(info, v) local str = "" - TitanUtils_SetProfile(TitanUtils_GetPlayer(), Titan_Global.profile.SYNC, info[1]) + TitanVariables_SetProfile(TitanUtils_GetPlayer(), Titan_Global.profile.SYNC, info[1]) str = str .. " " .. tostring(Titan_Global.profile.SYNC) .. "" .. " > '" .. tostring(info[1]) .. "'" @@ -1566,12 +1594,13 @@ local function TitanUpdateChars() Titan_Debug.Out('titan', 'profile', str) -- Change over to new profile - TitanVariables_UseSettings(nil, info[1], TITAN_PROFILE_USE) +-- TitanVariables_UseSettings(nil, info[1], TITAN_PROFILE_USE) + TitanVariables_UseSettings(nil, TitanUtils_GetPlayer(), TITAN_PROFILE_USE) TitanUpdateChars() AceConfigRegistry:NotifyChange("Titan Panel Addon Chars") end, -- cannot sync to yourself or if sync already set - disabled = this_toon.is_player or this_toon.sync_set, + disabled = (this_toon.is_player or this_toon.sync_set or g_sync), } position = position + 1 p_args.sync_clear = { @@ -1581,16 +1610,16 @@ local function TitanUpdateChars() type = "execute", func = function(info, v) local str = "" - TitanUtils_SetProfile(info[1], Titan_Global.profile.SYNC, Titan_Global.profile.NONE) + TitanVariables_SetProfile(info[1], Titan_Global.profile.SYNC, Titan_Global.profile.NONE) str = str .. " " .. tostring(Titan_Global.profile.SYNC) .. "" .. " > '" .. tostring(info[1]) .. "'" .. " : '" .. tostring(Titan_Global.profile.NONE) .. "'" - .. " | '" .. tostring(this_toon.is_player) .. "'" + .. " | '" .. tostring(p_info[info[1]].is_player) .. "'" Titan_Debug.Out('titan', 'profile', str) - if this_toon.is_player then + if p_info[info[1]].is_player then -- Change over to new profile TitanVariables_UseSettings(nil, TitanUtils_GetPlayer(), TITAN_PROFILE_USE) else @@ -1600,29 +1629,126 @@ local function TitanUpdateChars() TitanUpdateChars() AceConfigRegistry:NotifyChange("Titan Panel Addon Chars") end, - disabled = (not this_toon.sync_set), + disabled = (not this_toon.sync_set) or g_sync, } position = position + 1 - p_args.sp_50 = { + p_args[tostring(position)] = { type = "description", name = " "..TitanUtils_GetHexText(s_reason, Titan_Global.colors.orange).."\n", cmdHidden = true, order = position, } position = position + 1 - p_args.sp_51 = { + p_args[tostring(position)] = { + type = "description", + name = " ",--..TitanUtils_GetHexText(cs_reason, Titan_Global.colors.orange).."\n", + cmdHidden = true, + order = position, + } + + --==== + --==== Global section + position = position + 1 + p_args.sync_all_title = { + type = "header", + name = TitanUtils_GetGoldText("Global"), + cmdHidden = true, + order = position, + } + position = position + 1 + p_args.sync_all_with = { + name = "Sync All", --L["TITAN_PANEL_MENU_PROFILE_SYNC"], + desc = "Sync every toon to this profile", --L["TITAN_PANEL_MENU_PROFILE_SYNC_DESC"], + order = position, + type = "execute", + --width = "full", + func = function(info, v) + local str = "" + TitanVariables_SetProfile(TitanUtils_GetPlayer(), Titan_Global.profile.GLOBAL, info[1]) + str = str + .. " " .. tostring(Titan_Global.profile.GLOBAL) .. "" + .. " > '" .. tostring(info[1]) .. "'" + .. " : '" .. tostring(TITAN_PROFILE_USE) .. "'" + + Titan_Debug.Out('titan', 'profile', str) + -- Change over to new profile + TitanVariables_UseSettings(nil, TitanUtils_GetPlayer(), TITAN_PROFILE_USE) + TitanUpdateChars() + AceConfigRegistry:NotifyChange("Titan Panel Addon Chars") + end, + -- Can allows set global sync + --disabled = this_toon.is_player or this_toon.sync_set, + } + position = position + 1 + p_args.sync_all_clear = { + name = "Clear Sync All", --L["TITAN_PANEL_MENU_PROFILE_CLEAR_SYNC"], + desc = "Revert to each toon's settings", --L["TITAN_PANEL_MENU_PROFILE_CLEAR_SYNC_DESC"], + order = position, + type = "execute", + func = function(info, v) + local str = "" + TitanVariables_SetProfile(TitanUtils_GetPlayer(), Titan_Global.profile.GLOBAL, Titan_Global.profile.NONE) + str = str + .. " " .. tostring(Titan_Global.profile.GLOBAL) .. "" + .. " : '" .. tostring(Titan_Global.profile.NONE) .. "'" + Titan_Debug.Out('titan', 'profile', str) + + -- Change over to new profile + TitanVariables_UseSettings(nil, TitanUtils_GetPlayer(), TITAN_PROFILE_USE) + + TitanUpdateChars() + AceConfigRegistry:NotifyChange("Titan Panel Addon Chars") + end, + disabled = (not g_sync), + } + position = position + 1 + p_args.reset_all_this = { + name = "Reset Global Profile", --L["TITAN_PANEL_MENU_PROFILE_RESET"], -- + desc = "Reset Global Profile to Defaults", --L["TITAN_PANEL_MENU_PROFILE_RESET_DESC"], + order = position, + type = "execute", + -- width = "0.5", + func = function(info, v) + local g_name = TitanPanelGetVar("GlobalProfileName") + local str = "" + str = str + .. " " .. tostring(Titan_Global.profile.TOON) .. "" + .. " > '" .. tostring(info[1]) .. "'" + .. " : '" .. tostring(TITAN_PROFILE_RESET) .. "'" + .. " | '" .. tostring(g_name) .. "'" + + Titan_Debug.Out('titan', 'profile', str) + + -- Reset the global profile +-- TitanSettings.Players[g_name] = nil + + -- Change to new profile + TitanVariables_UseSettings(nil, TitanUtils_GetPlayer(), TITAN_PROFILE_RESET) + + TitanUpdateChars() + AceConfigRegistry:NotifyChange("Titan Panel Addon Chars") + end, + disabled = (not g_sync), + } + --[[ + position = position + 1 + p_args[tostring(position)] = { type = "description", name = " ",--..TitanUtils_GetHexText(cs_reason, Titan_Global.colors.orange).."\n", cmdHidden = true, order = position, } + --]] position = position + 1 - p_args.sp_60 = { + p_args[tostring(position)] = { type = "description", name = "", cmdHidden = true, order = position, } + + --==== + --==== Summary section position = position + 1 p_args.setting_title = { type = "header", @@ -1633,7 +1759,7 @@ local function TitanUpdateChars() position = position + 1 p_args.setting_sync = { type = "description", - name = L["TITAN_PANEL_MENU_PROFILE_SYNC"].." : " .. this_toon.sync_name, + name = this_toon.summary, cmdHidden = true, order = position, } @@ -3108,19 +3234,30 @@ local help_list_topics = { "- Profiles are part of Titan saved vars which are saved to disk on logout or reload.", " ", "- Titan 9.* Changed from a Global profile to a Sync scheme for greater flexibility.", - "A Global profile can be done by syncing all toons with the same profile.", + "A Global profile can be done : ", + "-- 1) by using Sync All.", + "-- 2) by syncing all toons with the same profile.", }, }, { sub = "Sync a profile", lines = { "- You may Sync a profile or multiple profiles to a profile. When you sync a profile any changes to bars and plugins are made to the Sync profile.", - "- To Sync a profile use Titan > Config > Profiles Click. Then select the profile to use. Then click Sync.", + "- To Sync a profile use Titan > Config > Profiles . Then select the profile to use. Then click Sync.", " Now Titan changes will be made to the Sync profile. ", " The settings for the current toon will be saved and used when the Sync is cleared.", }, }, { + sub = "Sync All a profile", + lines = { + "- You may Sync All profiles to a profile. When you sync a profile any changes to bars and plugins are made to the Sync profile.", + "- To Sync All profiles use Titan > Config > Profiles . Then select the profile to use. Then click Sync All.", + " Now Titan changes will be made to the Sync All profile. ", + " The settings for the current toon will be saved and used when the Sync All is cleared.", + }, + }, + { sub = "Clear Sync a profile", lines = { "- You may Clear Sync (remove) the current Sync being used by a profile.", diff --git a/Titan/TitanTemplate.lua b/Titan/TitanTemplate.lua index 89fa340..594bf28 100644 --- a/Titan/TitanTemplate.lua +++ b/Titan/TitanTemplate.lua @@ -596,7 +596,6 @@ function TitanPanelButton_OnClick(self, button) TitanUtils_CloseAllControlFrames(); TitanPanelRightClickMenu_Close(); - -- local position = TitanUtils_GetWhichBar(id) if (isControlFrameShown) then -- Note: This uses anchor points to place the control frame relative to the plugin on the screen. local parent = self:GetName() -- plugin with the control frame diff --git a/Titan/TitanUtils.lua b/Titan/TitanUtils.lua index b80c30d..ca8afa7 100644 --- a/Titan/TitanUtils.lua +++ b/Titan/TitanUtils.lua @@ -671,7 +671,7 @@ function TitanUtils_GetPlugin(id) end ---Titan Return the bar the plugin is shown on. ----@param id string? +---@param id string ---@return string? ShortName ---@return string? LocaleName function TitanUtils_GetWhichBar(id) @@ -734,7 +734,8 @@ but was removed during DragonFlight to give users more flexibility. end end - if TitanGetVar(id, "DisplayOnRightSide") then + -- tostring is for IDE - id nil then check would return false + if TitanGetVar(tostring(id), "DisplayOnRightSide") then found = true end @@ -1169,7 +1170,7 @@ function TitanUtils_NumToString(amount, thousands_separator, decimal_separator) Handle the general cases of converting any number to a string with separators for plugins. Titan usage is , / . or . / , although this will handle other schemes. NOTE: Currently only positive, whole numbers are passed in from Titan (no fractional or negative). - NOTE: If ampount is 100 trillion or more then return the string as is to avoid very messy strings. + NOTE: If amount is 100 trillion or more then return the string as is to avoid very messy strings. This is the behavior of Lua tostring. NOTE: Do not use separator directly in gsub - it could be a pattern special char, resulting in unexpected behavior! --]=] @@ -1178,7 +1179,8 @@ function TitanUtils_NumToString(amount, thousands_separator, decimal_separator) if type(amount) == "number" then -- Break number into segments - minus, integer, and fractional - local i, j, minus, int, fraction = 0, 0, "", "", "" + local i, j + local minus, int, fraction = "", "", "" if amount > 99999999999999 then -- 1 trillion - 1 int = tostring(amount) -- leave as is and, if gold, congratulate the player!!! @@ -1726,8 +1728,8 @@ local function TitanUtils_GetPrevButtonOnBar(bar, id, side) end ---Titan Add the given plugin to the given bar. Then reinit the plugins to show it properly. ----@param bar string Bar name to use ----@param id string Plugin to add +---@param bar string? Bar name to use +---@param id string? Plugin to add function TitanUtils_AddButtonOnBar(bar, id) local frame_str = TitanVariables_GetFrameName(bar) -- Add the button to the requested bar, if shown @@ -1776,18 +1778,22 @@ function TitanUtils_ShiftButtonOnBarLeft(name) local bar = TitanUtils_GetWhichBar(name) local to_idx = nil - -- buttons on Left are placed L to R; - -- buttons on Right are placed R to L - if side and side == TITAN_LEFT then - to_idx = TitanUtils_GetPrevButtonOnBar(TitanUtils_GetWhichBar(name), name, side) - elseif side and side == TITAN_RIGHT then - to_idx = TitanUtils_GetNextButtonOnBar(TitanUtils_GetWhichBar(name), name, side) - end - - if to_idx then - TitanUtils_SwapButtonOnBar(from_idx, to_idx); + if bar == nil then + -- not on a bar, do nothing else - return + -- buttons on Left are placed L to R; + -- buttons on Right are placed R to L + if side and side == TITAN_LEFT then + to_idx = TitanUtils_GetPrevButtonOnBar(bar, name, side) + elseif side and side == TITAN_RIGHT then + to_idx = TitanUtils_GetNextButtonOnBar(bar, name, side) + end + + if to_idx then + TitanUtils_SwapButtonOnBar(from_idx, to_idx); + else + -- at 'end' of buttons + end end end @@ -1800,18 +1806,22 @@ function TitanUtils_ShiftButtonOnBarRight(name) local side = TitanPanel_GetPluginSide(name) local bar = TitanUtils_GetWhichBar(name) - -- buttons on Left are placed L to R; - -- buttons on Right are placed R to L - if side and side == TITAN_LEFT then - to_idx = TitanUtils_GetNextButtonOnBar(bar, name, side) - elseif side and side == TITAN_RIGHT then - to_idx = TitanUtils_GetPrevButtonOnBar(bar, name, side) - end - - if to_idx then - TitanUtils_SwapButtonOnBar(from_idx, to_idx); + if bar == nil then + -- not on a bar, do nothing else - return + -- buttons on Left are placed L to R; + -- buttons on Right are placed R to L + if side and side == TITAN_LEFT then + to_idx = TitanUtils_GetNextButtonOnBar(bar, name, side) + elseif side and side == TITAN_RIGHT then + to_idx = TitanUtils_GetPrevButtonOnBar(bar, name, side) + end + + if to_idx then + TitanUtils_SwapButtonOnBar(from_idx, to_idx); + else + -- at 'end' of buttons + end end end @@ -2495,13 +2505,15 @@ end ---@return string server_name or "" function TitanUtils_GetPlayer() local playerName = UnitName("player"); - local serverName = GetRealmName(); + local serverName = GetRealmName() local toon = "<>" if (playerName == nil or serverName == nil or playerName == UKNOWNBEING) then -- Do nothing if player name is not available + playerName = "" + serverName = "" else toon = playerName .. TITAN_AT .. serverName end @@ -2549,101 +2561,7 @@ function TitanUtils_ScreenSize() return screen end ---====== Profile specifc routines - ----Check the given profile ensuring any profile pointed to exists ----@param profile string -function TitanUtil_CheckProfile(profile) - local str = "_CheckProfile [" .. tostring(profile) .. "]" - - local sync = TitanSettings.Players[profile].Panel["SyncWithProfile"] - -- local play = TitanUtils_GetPlayer() - - -- see if sync is set - str = str .. " s'" .. sync .. "'" - if (sync == Titan_Global.profile.NONE) then - -- Nothing to do - else - if TitanSettings.Players[profile] then - -- Nothing to do - else - -- Need to clear, the profile is not known... - TitanSettings.Players[profile].Panel["SyncWithProfile"] = Titan_Global.profile.NONE - end - end - str = str .. " > '" .. TitanSettings.Players[profile].Panel["SyncWithProfile"] .. "'" - - Titan_Debug.Out('titan', 'profile', str) -end - ----@class Get_Profile_Result ----@field ptype string Type of profile being used ----@field pname string Name of profile being used ----@field cname string Name of profile being used color coded ----@field glob string Value of global profile ----@field sync string Value of sync profile - ----Get the current profile per user settings with type and color-code version ----@param get_me? string ----@return table result Profile info -function TitanUtils_GetProfile(get_me) - local ptype = "" - local profile = "" - local cprofile = "" - local res = {} - - -- Used by config for loolup and Titan for current toon - if get_me == nil then - get_me = TitanUtils_GetPlayer() - end - - local sync = TitanSettings.Players[get_me].Panel["SyncWithProfile"] - local play = get_me --TitanUtils_GetPlayer() - - -- see if sync is set - if (sync == Titan_Global.profile.NONE) then - -- Use the current player - ptype = Titan_Global.profile.TOON - profile = play - cprofile = TitanUtils_GetHexText(profile, Titan_Global.colors.gold) - else - -- use the sync as set - ptype = Titan_Global.profile.SYNC - profile = sync - cprofile = TitanUtils_GetHexText(profile, Titan_Global.colors.green) - end - - local str = "_GetProfile" - .. " " .. tostring(ptype) .. "" - .. " '" .. tostring(cprofile) .. "'" - .. " s'" .. tostring(sync) .. "'" - .. " t'" .. tostring(play) .. "'" - Titan_Debug.Out('titan', 'profile', str) - - res.ptype = ptype - res.pname = profile - res.cname = cprofile - res.sync = sync - return res -end - ----Set the profile per user settings ----@param set_me? string ----@param ptype string ----@param to_profile string -function TitanUtils_SetProfile(set_me, ptype, to_profile) - local str = "_SetProfile" - .. " [" .. tostring(set_me) .. "]" - .. " " .. tostring(ptype) .. "" - .. " to '" .. tostring(to_profile) .. "'" - Titan_Debug.Out('titan', 'profile', str) - - if ptype == Titan_Global.profile.SYNC then - TitanSettings.Players[set_me].Panel["SyncWithProfile"] = to_profile - else - -- just current toon - end -end +--====== Export / Import specifc routines local function TrimString(string) local from = string:match "^%s*()" @@ -2666,7 +2584,7 @@ local function CopyToCompress(t1, t2) return t1 end ----Compress and serialize arbitrary data into a string +---Titan Compress and serialize arbitrary data into a string ---@param data any ---@param dataType string print | comm ---@return string compressed could be "" @@ -2696,7 +2614,7 @@ function TitanUtils_CompressData(data, dataType) return "" end ----Decompress and unserialize a string into the Lua data it represents +---Titan Decompress and unserialize a string into the Lua data it represents ---@param data any ---@param dataType string print | comm ---@return boolean @@ -2854,10 +2772,9 @@ end ---Titan: Output the current list of registered plugins. function TitanDumpPluginList() -- Just dump the current list of plugins - local plug_in = {} for idx, value in pairs(TitanPluginsIndex) do - plug_in = TitanUtils_GetPlugin(TitanPluginsIndex[idx]) - if plug_in then + local plug_in = TitanUtils_GetPlugin(TitanPluginsIndex[idx]) + if type(plug_in) == 'table' then TitanDebug("TitanDumpPluginList " .. "'" .. tostring(idx) .. "'" .. ": '" .. tostring(plug_in.id) .. "'" diff --git a/Titan/TitanVariables.lua b/Titan/TitanVariables.lua index 0cd7c74..16c518f 100644 --- a/Titan/TitanVariables.lua +++ b/Titan/TitanVariables.lua @@ -990,6 +990,141 @@ local function Check_Titan_settings() end end +---local Check the given profile ensuring any profile pointed to exists; +--- This updates ONLY profile settings +---@param profile string +local function TitanVariables_ValidateProfile(profile) + local toon = profile -- + if toon == nil then -- sanity check to return something valid + toon = TitanUtils_GetPlayer() + end + + local glob = (TitanAllGetVar("GlobalProfileUse") == true) + local sync = TitanSettings.Players[toon].Panel["SyncWithProfile"] + + local gcheck = "" + local scheck = "" + + local str = "_ValidateProfile [" .. tostring(profile) .. "]" + str = str + .. " > '" .. tostring(toon) .. "'" + .. " g'" .. tostring(glob) .. "'" + .. " s'" .. tostring(sync) .. "'" + Titan_Debug.Out('titan', 'profile', str) + -- + -- Validate profile against settings + + -- First Global + if glob then + gcheck = TitanAllGetVar("GlobalProfileName") + if TitanSettings.Players[gcheck] then + -- Referenced profile exists + else + -- Need to clear, the profile is not known... + TitanAllSetVar("GlobalProfileUse", false) + glob = false + end + else + -- not global + end + + -- Second Sync + -- Checking this separately ensures profile settings in saved vars stays consistent when a user + -- mixes global and sync over time. + if not (sync == Titan_Global.profile.NONE) then + scheck = TitanSettings.Players[toon].Panel["SyncWithProfile"] + if TitanSettings.Players[scheck].Panel then + -- Referenced profile exists + else + -- Need to clear, the profile is not known... + TitanSettings.Players[toon].Panel["SyncWithProfile"] = Titan_Global.profile.NONE + sync = Titan_Global.profile.NONE + end + else + -- not sync + end + + -- Third Toon + -- The PEW process Titan will ensure the toon is whole + + str = "..._ValidateProfile [" .. tostring(toon) .. "]" + .. "g [" .. tostring(gcheck) .. "] > " + .. " '" .. tostring(glob) .. "'" + .. "s [" .. tostring(scheck) .. "] > " + .. " '" .. tostring(sync) .. "'" + Titan_Debug.Out('titan', 'profile', str) +end + +---Titan Get the current profile per user settings with type and color-code version; +--- Priority is Global; Sync; current toon +---@param get_me string +---@return Get_Profile_Result res Profile info +function TitanVariables_GetProfile(get_me) + local ptype = "" + local profile = "" + local cprofile = "" + local res = {} + local toon = get_me -- + + local glob = (TitanAllGetVar("GlobalProfileUse") == true) + local sync = TitanSettings.Players[toon].Panel["SyncWithProfile"] + + -- + -- Gather profile data per settings + if glob then + -- Use the global toon user as set + ptype = Titan_Global.profile.GLOBAL + profile = TitanAllGetVar("GlobalProfileName") + cprofile = TitanUtils_GetHexText(profile, Titan_Global.colors.orange) + elseif (sync == Titan_Global.profile.NONE) then + -- Use the current player + ptype = Titan_Global.profile.TOON + profile = toon + cprofile = TitanUtils_GetHexText(profile, Titan_Global.colors.gold) + else + -- use the sync as set + ptype = Titan_Global.profile.SYNC + profile = sync + cprofile = TitanUtils_GetHexText(profile, Titan_Global.colors.green) + end + + local str = "_GetProfile" + .. " " .. tostring(ptype) .. "" + .. " '" .. tostring(cprofile) .. "'" + .. " g'" .. tostring(glob) .. "'" + .. " s'" .. tostring(sync) .. "'" + .. " t'" .. tostring(toon) .. "'" + Titan_Debug.Out('titan', 'profile', str) + + res.ptype = ptype + res.pname = profile + res.cname = cprofile +-- res.sync = sync + return res +end + +---Titan Set the profile per user settings +---@param set_me? string Profile to set / update +---@param ptype string Type of profile being set: Global | Sync | Toon +---@param to_profile string Profile to use +function TitanVariables_SetProfile(set_me, ptype, to_profile) + local str = "_SetProfile" + .. " [" .. tostring(set_me) .. "]" + .. " " .. tostring(ptype) .. "" + .. " to '" .. tostring(to_profile) .. "'" + Titan_Debug.Out('titan', 'profile', str) + + -- Nov 2025 : The change to Sync only touched a nerve :); adding back Global override... + if ptype == Titan_Global.profile.GLOBAL then + TitanAllSetVar("GlobalProfileUse", true) + TitanAllSetVar("GlobalProfileName", to_profile) + elseif ptype == Titan_Global.profile.SYNC then + TitanSettings.Players[set_me].Panel["SyncWithProfile"] = to_profile + else + -- just current toon + end +end + --- Ensure the given toon is ready to accept profile values; sync to defaults ---@param toon string Toon name @ ---@param toon_table table From TitanSettings (saved vars) @@ -1180,6 +1315,9 @@ function TitanVariables_InitTitanSettings() -- New Oct 2025 : All toons instead of current toon (Init_player_settings) Titan_Debug.Out('titan', 'profile', "Sync " .. idx .. " toon defaults (Panel)(BarVars)") Check_toon_settings(idx, v) + + -- Ensure profile vars are proper + TitanVariables_ValidateProfile(idx) end table.sort(Titan_Global.players, function(a, b) return a < b @@ -1234,10 +1372,10 @@ function TitanVariables_GetBarPos(frame_str) end ---Titan Build the frame name from the bar name ----@param bar_str string Short bar name +---@param bar_str string? Short bar name ---@return string is_icon Bar frame name function TitanVariables_GetFrameName(bar_str) - return TITAN_PANEL_DISPLAY_PREFIX .. bar_str + return tostring(TITAN_PANEL_DISPLAY_PREFIX) .. bar_str end ---local Original : lua-users.org/wiki/CopyTable @@ -1338,18 +1476,7 @@ local function Init_player_settings(from_profile, to_profile, action) -- Get the profile Bar data... TitanSettings.Players[to_profile]["BarVars"] = deepcopy(old_player["BarVars"]) - --[[ - if Titan_Global.titan.profile then - -- Apply the new bar positions - for idx, v in pairs(TitanBarData) do - local str = "BarVars " - .. " " .. tostring(v.name) .. "" - .. " " .. tostring(TitanSettings.Players[from_profile]["BarVars"][idx].show) .. "" - .. " " .. tostring(TitanSettings.Players[to_profile]["BarVars"][idx].show) .. "" - Titan_Debug.Out('titan', 'profile', str) - end - end ---]] + -- Copy the panel settings for index, id in pairs(old_panel) do TitanPanelSetVar(index, old_panel[index]); @@ -1542,26 +1669,6 @@ function TitanVariables_SetPanelStrata(value) end end -local function Check_sync_profile(profile) - local str = "" -- for debug output if requested - local from_profile = nil - -- Assuming the var is set per prior init routines!! - local sync = TitanSettings.Players[profile].Panel.SyncWithProfile - - if sync == Titan_Global.profile.NONE then - from_profile = profile -- no sync, use given profile - else - from_profile = sync -- use the sync profile, not the one passed - end - - str = "_sync_profile" - .. " " .. tostring(profile) .. "" - .. " >> '" .. tostring(from_profile) .. "'" - Titan_Debug.Out('titan', 'profile', str) - - return from_profile -end - ---Titan Set the Titan variables and plugin variables to the passed in profile. --- Called from the Titan right click menu --- profile is compared using 'lower' so the case does not matter @@ -1572,10 +1679,10 @@ function TitanVariables_UseSettings(from, profile, action) local str = "" -- for debug output if requested local _ = nil -- for scope; do not care about this value - -- Oct 2025 : - -- Added 'from' to be explicit when needing a source profile - -- profile param is now required and represents the target profile - -- The target profile could be overridden by 'sync with' feature + -- Oct and Dec 2025 : + -- Added 'from' to be explicit when Load of a source profile + -- Profile param is now required - usually current player + -- The target profile could be overridden per global or sync featuresettings local from_profile = from @@ -1585,13 +1692,15 @@ function TitanVariables_UseSettings(from, profile, action) .. " > '" .. tostring(profile) .. "'" Titan_Debug.Out('titan', 'profile', str) - -- ==== Determine the profile to use based on action - + -- ==== Determine the profile to use based on profile settings + local profile_info = TitanVariables_GetProfile(profile) + local profile_name = profile_info.pname +--[[ -- User setting 'sync with' will cause profile to change to the user selected sync. if action == TITAN_PROFILE_USE then -- Will copy profile to current toon -- Assumed to be NOT nil! - profile = Check_sync_profile(profile) + profile = profile_name elseif action == TITAN_PROFILE_RESET then -- Nuke given profile to defaults -- Reset will clear global for ALL toons @@ -1609,18 +1718,18 @@ function TitanVariables_UseSettings(from, profile, action) Titan_Debug.Out('titan', 'profile', str) profile = Check_sync_profile(profile) end - +--]] -- Find the profile in a case insensitive manner local new_profile = "" - profile = string.lower(profile) + profile_name = string.lower(profile_name) for index, id in pairs(TitanSettings.Players) do - if profile == string.lower(index) then + if profile_name == string.lower(index) then new_profile = index end end if new_profile == "" then -- new toon to Titan; needs to be created - new_profile = TitanUtils_GetPlayer() --TitanSettings.Player + new_profile = TitanUtils_GetPlayer() action = TITAN_PROFILE_RESET end diff --git a/Titan/_TitanIDE.lua b/Titan/_TitanIDE.lua index 9a231df..97ddd06 100644 --- a/Titan/_TitanIDE.lua +++ b/Titan/_TitanIDE.lua @@ -149,8 +149,9 @@ C_Bank = {} -- 11.0.0 New Warbank - Hopefully WoW API extension will catch up so --====== Convince IDE we know what we are doing -- Lua allows table updates but the IDE complains about 'injecting' a field it does not know about. --- Adding a function or variable to a frame in this case. + +--====== Adding a function or variable to a frame in this case. ---@class UIParent WoW frame ---@field GetScale function WoW region routine @@ -182,6 +183,14 @@ C_Bank = {} -- 11.0.0 New Warbank - Hopefully WoW API extension will catch up so ---@field short_name string Placeholder for short bar name ---@field RegisterForClicks function Variable params missed by VS Code plugin +--====== Profile output from Utils +---@class Get_Profile_Result +---@field ptype string Type of profile being used +---@field pname string Name of profile being used +---@field cname string Name of profile being used color coded +---@field glob string Value of global profile +---@field sync string Value of sync profile + --====== Ace Drop down menu L_UIDROPDOWNMENU_MENU_LEVEL = 1 L_UIDROPDOWNMENU_MENU_VALUE = 1 -- 1.7.9.5