From e233ea291cc6c3e6aabc09bde851f9e2abcaa1f2 Mon Sep 17 00:00:00 2001 From: Kyzentun Keeslala Date: Fri, 2 Feb 2018 11:15:34 -0700 Subject: [PATCH] Change ThemePrefs to use the Theme preference instead of GetThemeDisplayName or themeInfo because GetThemeDisplayName does not work when a theme falls back on another theme. --- Themes/_fallback/Scripts/02 ThemePrefs.lua | 34 +++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/Themes/_fallback/Scripts/02 ThemePrefs.lua b/Themes/_fallback/Scripts/02 ThemePrefs.lua index 3efbfe94bd..55bb07791c 100644 --- a/Themes/_fallback/Scripts/02 ThemePrefs.lua +++ b/Themes/_fallback/Scripts/02 ThemePrefs.lua @@ -32,7 +32,29 @@ local PrefsTable = nil; -- Gets the name of the current theme using themeInfo -- if available and the ThemeManager name otherwise. local function GetThemeName() - return themeInfo and themeInfo.Name or THEME:GetThemeDisplayName() + -- When loading a fallback theme, the theme manager pretends that the theme + -- being loaded is the current theme. THEME:GetCurThemeName and everything + -- else that relies on the current theme will think that the fallback theme + -- is the current theme. + -- This includes the themeInfo table that some themes create in + -- "00 ThemeInfo.lua". + + -- In diagram form, imagine the "home" theme, which falls back on + -- "default", which falls back on "_fallback". + -- Scripts being loaded | Current theme name. | themeInfo source + -- ----------------------------------------------------------------- + -- _fallback/Scripts | _fallback | _fallback/Scripts/ + -- default/Scripts | default | default/Scripts/ + -- home/Scripts | home | home/Scripts/ + + -- So when default calls ThemePrefs.Init at the end of its script loading, + -- ThemePrefs thinks the current theme is "default", even if the player + -- chose "home". Thus, the ThemePrefs entry for "home" is not created. + -- Then later when a preference is used, ResolveTable thinks the current + -- theme is "home", but fails because there is no "home" entry in + -- PrefsTable. + + return PREFSMAN:GetPreference("Theme") end -- Given a preference name, returns the table it's in. Checks the current @@ -149,6 +171,16 @@ ThemePrefs = end Warn( "Set: "..GetString("UnknownPreference"):format(name) ) end, + + CopyPrefsFrom = function(name) + local curr_prefs = PrefsTable[GetThemeName()] + local from_prefs = PrefsTable[name] + if curr_prefs and from_prefs then + for pref_name, pref_value in pairs(from_prefs) do + curr_prefs[pref_name] = pref_value + end + end + end, }; -- global aliases