2002-11-16 08:07:38 +00:00
|
|
|
#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
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
2002-10-28 05:30:45 +00:00
|
|
|
#include "RageTypes.h"
|
2003-07-13 00:02:23 +00:00
|
|
|
#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
|
|
|
|
2003-09-11 23:21:33 +00:00
|
|
|
enum ElementCategory { BGAnimations, Fonts, Graphics, Numbers, Sounds, Other, NUM_ELEMENT_CATEGORIES };
|
2003-04-12 17:39:27 +00:00
|
|
|
|
2002-01-16 10:01:32 +00:00
|
|
|
class ThemeManager
|
|
|
|
|
{
|
|
|
|
|
public:
|
2002-03-19 07:09:49 +00:00
|
|
|
ThemeManager();
|
2002-08-13 23:26:46 +00:00
|
|
|
~ThemeManager();
|
2002-01-18 19:54:38 +00:00
|
|
|
|
2003-04-13 04:50:08 +00:00
|
|
|
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); };
|
2003-04-13 04:50:08 +00:00
|
|
|
void NextTheme();
|
2003-11-07 20:43:17 +00:00
|
|
|
void ReloadMetrics();
|
2003-11-05 04:56:41 +00:00
|
|
|
void ReloadMetricsIfNecessary();
|
2002-07-23 01:41:40 +00:00
|
|
|
|
2004-02-14 01:16:04 +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); };
|
2004-01-24 21:16:07 +00:00
|
|
|
|
|
|
|
|
// 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 );
|
|
|
|
|
|
2002-08-13 23:26:46 +00:00
|
|
|
|
2003-03-24 21:37:13 +00:00
|
|
|
bool HasMetric( CString sClassName, CString sValueName );
|
2003-03-18 21:41:17 +00:00
|
|
|
CString GetMetricRaw( CString sClassName, CString sValueName );
|
2002-09-17 23:02:37 +00:00
|
|
|
CString GetMetric( CString sClassName, CString sValueName );
|
|
|
|
|
int GetMetricI( CString sClassName, CString sValueName );
|
|
|
|
|
float GetMetricF( CString sClassName, CString sValueName );
|
|
|
|
|
bool GetMetricB( CString sClassName, CString sValueName );
|
2002-10-28 05:30:45 +00:00
|
|
|
RageColor GetMetricC( CString sClassName, CString sValueName );
|
2002-01-16 10:01:32 +00:00
|
|
|
|
2002-03-19 07:09:49 +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 );
|
2004-01-24 21:16:07 +00:00
|
|
|
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
|
|
|
|
2002-01-18 19:54:38 +00:00
|
|
|
CString m_sCurThemeName;
|
2003-08-19 08:01:15 +00:00
|
|
|
CString m_sCurLanguage;
|
2002-08-13 23:26:46 +00:00
|
|
|
|
2004-03-20 03:02:12 +00:00
|
|
|
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
|
2002-11-16 08:07:38 +00:00
|
|
|
|
2003-02-17 12:19:42 +00:00
|
|
|
class CachedThemeMetric
|
|
|
|
|
{
|
2003-03-26 19:15:38 +00:00
|
|
|
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; };
|
2003-03-26 19:15:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class CachedThemeMetricF : public CachedThemeMetric
|
|
|
|
|
{
|
2004-01-21 09:36:28 +00:00
|
|
|
float m_fValue;
|
2003-03-26 19:15:38 +00:00
|
|
|
public:
|
2004-01-21 09:36:28 +00:00
|
|
|
void Update() { m_fValue = (float)atof( m_sValue ); }
|
2003-03-26 19:15:38 +00:00
|
|
|
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; };
|
2003-03-26 19:15:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class CachedThemeMetricI : public CachedThemeMetric
|
|
|
|
|
{
|
2004-01-21 09:36:28 +00:00
|
|
|
int m_iValue;
|
2003-03-26 19:15:38 +00:00
|
|
|
public:
|
2004-01-21 09:36:28 +00:00
|
|
|
void Update() { m_iValue = atoi( m_sValue ); }
|
2003-03-26 19:15:38 +00:00
|
|
|
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;
|
2003-03-26 19:15:38 +00:00
|
|
|
public:
|
2004-01-21 09:36:28 +00:00
|
|
|
void Update() { m_bValue = atoi( m_sValue ) != 0; }
|
2003-03-26 19:15:38 +00:00
|
|
|
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; };
|
2003-03-26 19:15:38 +00:00
|
|
|
};
|
|
|
|
|
|
2004-01-21 09:36:28 +00:00
|
|
|
|
|
|
|
|
|
2003-03-26 19:15:38 +00:00
|
|
|
class CachedThemeMetricC : public CachedThemeMetric
|
|
|
|
|
{
|
2004-01-21 09:36:28 +00:00
|
|
|
RageColor m_cValue;
|
2003-03-26 19:15:38 +00:00
|
|
|
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 );
|
|
|
|
|
}
|
2003-03-26 19:15:38 +00:00
|
|
|
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; };
|
|
|
|
|
};
|
|
|
|
|
|
2003-03-26 19:15:38 +00:00
|
|
|
|
|
|
|
|
|
2002-11-16 08:07:38 +00:00
|
|
|
#endif
|