Example #1
0
void ThemeManager::SwitchThemeAndLanguage( const RString &sThemeName_, const RString &sLanguage_, bool bPseudoLocalize, bool bForceThemeReload )
{
    RString sThemeName = sThemeName_;
    RString sLanguage = sLanguage_;
    // todo: if the theme isn't selectable, find the next theme that is,
    // and change to that instead of asserting/crashing since
    // SpecialFiles::BASE_THEME_NAME is _fallback now. -aj
#if !defined(SMPACKAGE)
    if( !IsThemeSelectable(sThemeName) )
        sThemeName = PREFSMAN->m_sTheme.GetDefault();

    // sm-ssc's SpecialFiles::BASE_THEME_NAME is _fallback, which you can't
    // select. This requires a preference, which allows it to be adapted for
    // other purposes (e.g. PARASTAR).
    if( !IsThemeSelectable(sThemeName) )
        sThemeName = PREFSMAN->m_sDefaultTheme;
#endif

    ASSERT( IsThemeSelectable(sThemeName) );

    /* We haven't actually loaded the theme yet, so we can't check whether
     * sLanguage exists. Just check for empty. */
    if( sLanguage.empty() )
        sLanguage = GetDefaultLanguage();
    LOG->Trace("ThemeManager::SwitchThemeAndLanguage: \"%s\", \"%s\"",
               sThemeName.c_str(), sLanguage.c_str() );

    bool bNothingChanging = sThemeName == m_sCurThemeName && sLanguage == m_sCurLanguage && m_bPseudoLocalize == bPseudoLocalize;
    if( bNothingChanging && !bForceThemeReload )
        return;

    m_bPseudoLocalize = bPseudoLocalize;

    // Load theme metrics. If only the language is changing, this is all
    // we need to reload.
    bool bThemeChanging = (sThemeName != m_sCurThemeName);
    LoadThemeMetrics( sThemeName, sLanguage );

    // Clear the theme path cache. This caches language-specific graphic paths,
    // so do this even if only the language is changing.
    ClearThemePathCache();
    if( bThemeChanging )
    {
#if !defined(SMPACKAGE)
        // reload common sounds
        if( SCREENMAN != NULL )
            SCREENMAN->ThemeChanged();
#endif

        /* Lua globals can use metrics which are cached, and vice versa.  Update Lua
         * globals first; it's Lua's job to explicitly update cached metrics that it
         * uses. */
        UpdateLuaGlobals();
    }

    // Use theme metrics for localization.
    LocalizedString::RegisterLocalizer( LocalizedStringImplThemeMetric::Create );

    ReloadSubscribers();
}
Example #2
0
void ThemeManager::SwitchThemeAndLanguage( const RString &sThemeName_, const RString &sLanguage_, bool bPseudoLocalize, bool bForceThemeReload )
{
	RString sThemeName = sThemeName_;
	RString sLanguage = sLanguage_;
	// todo: if the theme isn't selectable, find the next theme that is,
	// and change to that instead of asserting/crashing since
	// SpecialFiles::BASE_THEME_NAME is _fallback now. -aj
	if(!IsThemeSelectable(sThemeName))
	{
		RString to_try= PREFSMAN->m_sTheme.GetDefault();
		LOG->Warn("Selected theme '%s' not found.  "
			"Trying Theme preference default value '%s'.",
			sThemeName.c_str(), to_try.c_str());
		sThemeName = to_try;
		// sm-ssc's SpecialFiles::BASE_THEME_NAME is _fallback, which you can't
		// select. This requires a preference, which allows it to be adapted for
		// other purposes (e.g. PARASTAR).
		if(!IsThemeSelectable(sThemeName))
		{
			to_try= PREFSMAN->m_sDefaultTheme;
			LOG->Warn("Theme preference defaults to '%s', which cannot be used."
				"  Trying DefaultTheme preference '%s'.",
				sThemeName.c_str(), to_try.c_str());
			sThemeName = to_try;
			if(!IsThemeSelectable(sThemeName))
			{
				vector<RString> theme_names;
				GetSelectableThemeNames(theme_names);
				ASSERT_M(!theme_names.empty(), "No themes found, unable to start stepmania.");
				to_try= theme_names[0];
				LOG->Warn("DefaultTheme preference is '%s', which cannot be found."
					"  Using '%s'.",
					sThemeName.c_str(), to_try.c_str());
				sThemeName= to_try;
				PREFSMAN->m_sDefaultTheme.Set(to_try);
			}
		}
		PREFSMAN->m_sTheme.Set(sThemeName);
	}

	/* We haven't actually loaded the theme yet, so we can't check whether
	 * sLanguage exists. Just check for empty. */
	if( sLanguage.empty() )
		sLanguage = GetDefaultLanguage();
	LOG->Trace("ThemeManager::SwitchThemeAndLanguage: \"%s\", \"%s\"",
		sThemeName.c_str(), sLanguage.c_str() );

	bool bNothingChanging = sThemeName == m_sCurThemeName && sLanguage == m_sCurLanguage && m_bPseudoLocalize == bPseudoLocalize;
	if( bNothingChanging && !bForceThemeReload )
		return;

	m_bPseudoLocalize = bPseudoLocalize;

	// Load theme metrics. If only the language is changing, this is all
	// we need to reload.
	bool bThemeChanging = (sThemeName != m_sCurThemeName);
	LoadThemeMetrics( sThemeName, sLanguage );

	// Clear the theme path cache. This caches language-specific graphic paths,
	// so do this even if only the language is changing.
	ClearThemePathCache();
	if(bThemeChanging || bForceThemeReload)
	{
#if !defined(SMPACKAGE)
		// reload common sounds
		if( SCREENMAN != NULL )
			SCREENMAN->ThemeChanged();

#endif

		/* Lua globals can use metrics which are cached, and vice versa.  Update Lua
		 * globals first; it's Lua's job to explicitly update cached metrics that it
		 * uses. */
		UpdateLuaGlobals();

		// Reload MachineProfile with new theme's CustomLoadFunction
		if( PROFILEMAN != NULL )
		{
			Profile* pProfile = PROFILEMAN->GetMachineProfile();
			pProfile->LoadCustomFunction("/Save/MachineProfile/", PlayerNumber_Invalid);
		}
	}

	// Use theme metrics for localization.
	LocalizedString::RegisterLocalizer( LocalizedStringImplThemeMetric::Create );

	ReloadSubscribers();
}