From e233ea291cc6c3e6aabc09bde851f9e2abcaa1f2 Mon Sep 17 00:00:00 2001 From: Kyzentun Keeslala Date: Fri, 2 Feb 2018 11:15:34 -0700 Subject: [PATCH 1/2] 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 From 02dd2522e37667e88ea4e24bef5f109f87c21575 Mon Sep 17 00:00:00 2001 From: Kyzentun Keeslala Date: Mon, 5 Feb 2018 09:12:35 -0700 Subject: [PATCH 2/2] Add THEME:get_theme_fallback_list function. --- src/ThemeManager.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/ThemeManager.cpp b/src/ThemeManager.cpp index 97f4723f9a..17f2054775 100644 --- a/src/ThemeManager.cpp +++ b/src/ThemeManager.cpp @@ -1446,6 +1446,18 @@ public: return 0; } + static int get_theme_fallback_list(T* p, lua_State* L) + { + lua_createtable(L, g_vThemes.size(), 0); + int ret= lua_gettop(L); + for(size_t tid= 0; tid < g_vThemes.size(); ++tid) + { + lua_pushstring(L, g_vThemes[tid].sThemeName.c_str()); + lua_rawseti(L, ret, tid+1); + } + return 1; + } + LunaThemeManager() { ADD_METHOD( ReloadMetrics ); @@ -1473,6 +1485,7 @@ public: ADD_METHOD( GetMetricNamesInGroup ); ADD_METHOD( GetStringNamesInGroup ); ADD_METHOD( SetTheme ); + ADD_METHOD(get_theme_fallback_list); } };