Merge pull request #1629 from kyzentun/theme_prefs_use_chosen_theme

ThemePrefs use chosen theme
This commit is contained in:
tertu
2018-02-08 16:18:30 -06:00
committed by GitHub
2 changed files with 46 additions and 1 deletions
+33 -1
View File
@@ -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
+13
View File
@@ -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);
}
};