Files
itgmania212121/stepmania/src/ThemeManager.h
T

168 lines
6.4 KiB
C++
Raw Normal View History

#ifndef THEMEMANAGER_H
#define THEMEMANAGER_H
2002-01-16 10:01:32 +00:00
/*
-----------------------------------------------------------------------------
2002-02-28 19:40:40 +00:00
Class: ThemeManager
2002-01-16 10:01:32 +00:00
2002-02-28 19:40:40 +00:00
Desc: Manages which graphics and sounds are chosed to load. Every time
a sound or graphic is loaded, it gets the path from the ThemeManager.
2002-01-16 10:01:32 +00:00
2002-05-19 01:59:48 +00:00
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
2002-02-28 19:40:40 +00:00
Chris Danford
2002-01-16 10:01:32 +00:00
-----------------------------------------------------------------------------
*/
#include "RageTypes.h"
#include "RageTimer.h"
2002-01-16 10:01:32 +00:00
2002-09-07 11:45:15 +00:00
class IniFile;
2002-01-16 10:01:32 +00:00
enum ElementCategory { BGAnimations, Fonts, Graphics, Numbers, Sounds, Other, NUM_ELEMENT_CATEGORIES };
2002-01-16 10:01:32 +00:00
class ThemeManager
{
public:
ThemeManager();
~ThemeManager();
void GetThemeNames( CStringArray& AddTo );
2002-07-23 01:41:40 +00:00
bool DoesThemeExist( CString sThemeName );
2003-08-19 08:01:15 +00:00
void GetLanguages( CStringArray& AddTo );
bool DoesLanguageExist( CString sLanguage );
void SwitchThemeAndLanguage( CString sThemeName, CString sLanguage );
2002-07-23 01:41:40 +00:00
CString GetCurThemeName() { return m_sCurThemeName; };
2003-08-19 08:01:15 +00:00
CString GetCurLanguage() { return m_sCurLanguage; };
2003-04-22 04:54:04 +00:00
CString GetCurThemeDir() { return GetThemeDirFromName(m_sCurThemeName); };
void NextTheme();
void ReloadMetrics();
void ReloadMetricsIfNecessary();
2002-07-23 01:41:40 +00:00
/* I renamed these for two reasons. The overload conflicts with the ones below:
* GetPathToB( str, str ) was matching the ones below instead of these. It's also
* easier to search for uses of obsolete functions if they have a different name. */
CString GetPath( ElementCategory category, CString sClassName, CString sElement, bool bOptional=false );
CString GetPathB( CString sClassName, CString sElement, bool bOptional=false ) { return GetPath(BGAnimations,sClassName,sElement,bOptional); };
CString GetPathF( CString sClassName, CString sElement, bool bOptional=false ) { return GetPath(Fonts,sClassName,sElement,bOptional); };
CString GetPathG( CString sClassName, CString sElement, bool bOptional=false ) { return GetPath(Graphics,sClassName,sElement,bOptional); };
CString GetPathN( CString sClassName, CString sElement, bool bOptional=false ) { return GetPath(Numbers,sClassName,sElement,bOptional); };
CString GetPathS( CString sClassName, CString sElement, bool bOptional=false ) { return GetPath(Sounds,sClassName,sElement,bOptional); };
CString GetPathO( CString sClassName, CString sElement, bool bOptional=false ) { return GetPath(Other,sClassName,sElement,bOptional); };
// TODO: remove these and update the places that use them
CString GetPathToB( CString sFileName, bool bOptional=false );
CString GetPathToF( CString sFileName, bool bOptional=false );
CString GetPathToG( CString sFileName, bool bOptional=false );
CString GetPathToN( CString sFileName, bool bOptional=false );
CString GetPathToS( CString sFileName, bool bOptional=false );
CString GetPathToO( CString sFileName, bool bOptional=false );
bool HasMetric( CString sClassName, CString sValueName );
CString GetMetricRaw( CString sClassName, CString sValueName );
CString GetMetric( CString sClassName, CString sValueName );
int GetMetricI( CString sClassName, CString sValueName );
float GetMetricF( CString sClassName, CString sValueName );
bool GetMetricB( CString sClassName, CString sValueName );
RageColor GetMetricC( CString sClassName, CString sValueName );
2002-01-16 10:01:32 +00:00
protected:
2004-03-20 10:24:42 +00:00
bool GetMetricRaw( CString sClassName, CString sValueName, CString &ret, int level=0 );
2004-02-03 04:41:43 +00:00
CString GetPathToAndFallback( CString sThemeName, ElementCategory category, CString sClassName, CString sFile );
CString GetPathToRaw( CString sThemeName, ElementCategory category, CString sClassName, CString sFile );
2003-01-23 04:41:57 +00:00
static CString GetThemeDirFromName( const CString &sThemeName );
2002-05-19 01:59:48 +00:00
CString GetElementDir( CString sThemeName );
2003-08-19 08:01:15 +00:00
static CString GetMetricsIniPath( CString sThemeName );
static void GetLanguagesForTheme( CString sThemeName, CStringArray& asLanguagesOut );
static CString GetLanguageIniPath( CString sThemeName, CString sLanguage );
2002-01-16 10:01:32 +00:00
CString m_sCurThemeName;
2003-08-19 08:01:15 +00:00
CString m_sCurLanguage;
IniFile* m_pIniCurMetrics; // make this a pointer so we don't have to include IniFile here
IniFile* m_pIniBaseMetrics; // make this a pointer so we don't have to include IniFile here
2002-09-07 09:53:03 +00:00
unsigned m_uHashForCurThemeMetrics;
unsigned m_uHashForBaseThemeMetrics;
2003-08-19 08:01:15 +00:00
unsigned m_uHashForCurThemeCurLanguage;
unsigned m_uHashForBaseThemeCurLanguage;
unsigned m_uHashForCurThemeBaseLanguage;
unsigned m_uHashForBaseThemeBaseLanguage;
2002-01-16 10:01:32 +00:00
};
extern ThemeManager* THEME; // global and accessable from anywhere in our program
2003-02-17 12:19:42 +00:00
class CachedThemeMetric
{
protected:
2004-01-21 09:36:28 +00:00
CString m_sClassName;
2003-02-17 12:19:42 +00:00
CString m_sValueName;
bool m_bInited;
CString m_sValue;
2004-01-21 09:36:28 +00:00
virtual void Update() { }
2003-02-17 12:19:42 +00:00
public:
2004-01-21 09:36:28 +00:00
CachedThemeMetric( CString sClassName, CString sValueName ):
m_sClassName( sClassName ),
m_sValueName( sValueName ),
m_bInited( false )
2003-02-17 12:19:42 +00:00
{
}
2004-01-21 09:36:28 +00:00
virtual ~CachedThemeMetric() { }
2003-02-17 12:19:42 +00:00
2004-01-21 09:36:28 +00:00
void Refresh( CString sClassName = "" )
2003-02-17 12:19:42 +00:00
{
2004-01-21 09:36:28 +00:00
m_sValue = THEME->GetMetric(sClassName==""? m_sClassName:sClassName,m_sValueName);
Update();
2003-02-17 12:19:42 +00:00
m_bInited = true;
}
operator const CString () const { ASSERT(m_bInited); return m_sValue; };
};
class CachedThemeMetricF : public CachedThemeMetric
{
2004-01-21 09:36:28 +00:00
float m_fValue;
public:
2004-01-21 09:36:28 +00:00
void Update() { m_fValue = (float)atof( m_sValue ); }
CachedThemeMetricF( CString sClassName, CString sValueName ) : CachedThemeMetric( sClassName, sValueName ) {}
2003-02-17 12:19:42 +00:00
operator const float () const { ASSERT(m_bInited); return m_fValue; };
};
class CachedThemeMetricI : public CachedThemeMetric
{
2004-01-21 09:36:28 +00:00
int m_iValue;
public:
2004-01-21 09:36:28 +00:00
void Update() { m_iValue = atoi( m_sValue ); }
CachedThemeMetricI( CString sClassName, CString sValueName ) : CachedThemeMetric( sClassName, sValueName ) {}
operator const int () const { ASSERT(m_bInited); return m_iValue; };
};
class CachedThemeMetricB : public CachedThemeMetric
{
2004-01-21 09:36:28 +00:00
bool m_bValue;
public:
2004-01-21 09:36:28 +00:00
void Update() { m_bValue = atoi( m_sValue ) != 0; }
CachedThemeMetricB( CString sClassName, CString sValueName ) : CachedThemeMetric( sClassName, sValueName ) {}
2003-02-17 12:19:42 +00:00
operator const bool () const { ASSERT(m_bInited); return m_bValue; };
};
2004-01-21 09:36:28 +00:00
class CachedThemeMetricC : public CachedThemeMetric
{
2004-01-21 09:36:28 +00:00
RageColor m_cValue;
public:
2004-01-21 09:36:28 +00:00
void Update()
{
m_cValue = RageColor(1,1,1,1);
sscanf( m_sValue, "%f,%f,%f,%f", &m_cValue.r, &m_cValue.g, &m_cValue.b, &m_cValue.a );
}
CachedThemeMetricC( CString sClassName, CString sValueName ) : CachedThemeMetric( sClassName, sValueName ) {}
2003-02-17 12:19:42 +00:00
operator const RageColor () const { ASSERT(m_bInited); return m_cValue; };
};
#endif