add ThemeManager to smtools

This commit is contained in:
Chris Danford
2005-12-29 05:52:50 +00:00
parent b704036996
commit c7d769829a
13 changed files with 121 additions and 34 deletions
+2 -5
View File
@@ -13,9 +13,6 @@
#include "FontCharmaps.h"
#include "FontCharAliases.h"
/* Last private-use Unicode character: */
const wchar_t Font::DEFAULT_GLYPH = 0xF8FF;
FontPage::FontPage()
{
m_pTexture = NULL;
@@ -285,7 +282,7 @@ const glyph &Font::GetGlyph( wchar_t c ) const
map<longchar,glyph*>::const_iterator it = m_iCharToGlyph.find(c);
/* If that's missing, use the default glyph. */
if(it == m_iCharToGlyph.end()) it = m_iCharToGlyph.find(DEFAULT_GLYPH);
if(it == m_iCharToGlyph.end()) it = m_iCharToGlyph.find(FONT_DEFAULT_GLYPH);
if(it == m_iCharToGlyph.end())
RageException::Throw( "The default glyph is missing from the font '%s'", path.c_str() );
@@ -295,7 +292,7 @@ const glyph &Font::GetGlyph( wchar_t c ) const
bool Font::FontCompleteForString( const wstring &str ) const
{
map<longchar,glyph*>::const_iterator m_pDefault = m_iCharToGlyph.find( DEFAULT_GLYPH );
map<longchar,glyph*>::const_iterator m_pDefault = m_iCharToGlyph.find( FONT_DEFAULT_GLYPH );
if( m_pDefault == m_iCharToGlyph.end() )
RageException::Throw( "The default glyph is missing from the font '%s'", path.c_str() );
+4 -2
View File
@@ -134,8 +134,6 @@ public:
void SetDefaultGlyph( FontPage *pPage );
static const wchar_t DEFAULT_GLYPH;
bool IsRightToLeft() const { return m_bRightToLeft; };
private:
@@ -163,6 +161,10 @@ private:
CString GetPageNameFromFileName( const CString &sFilename );
};
/* Last private-use Unicode character: */
/* This is in the header to reduce file dependencies. */
const wchar_t FONT_DEFAULT_GLYPH = 0xF8FF;
#endif
/*
+1 -1
View File
@@ -67,7 +67,7 @@ static void InitCharAliases()
if(!CharAliases.empty())
return;
CharAliases["default"] = Font::DEFAULT_GLYPH; /* ? */
CharAliases["default"] = FONT_DEFAULT_GLYPH; /* ? */
CharAliases["invalid"] = INVALID_CHAR; /* 0xFFFD */
/* The comments here are UTF-8; they won't show up in VC6 (use your
+4 -10
View File
@@ -7,13 +7,7 @@
#include "RageFile.h"
#include "RageThreads.h"
#include "Foreach.h"
#if !defined(SMPACKAGE)
#include "arch/Dialog/Dialog.h"
#define DIALOG_OK Dialog::OK
#else
#define DIALOG_OK __noop
#endif
#include <csetjmp>
#include <cassert>
@@ -274,7 +268,7 @@ bool LuaHelpers::RunScriptFile( const CString &sFile )
if( !f.Open( sFile ) )
{
CString sError = ssprintf( "Couldn't open Lua script \"%s\": %s", sFile.c_str(), f.GetError().c_str() );
DIALOG_OK( sError, "LUA_ERROR" );
Dialog::OK( sError, "LUA_ERROR" );
return false;
}
@@ -282,7 +276,7 @@ bool LuaHelpers::RunScriptFile( const CString &sFile )
if( f.Read( sScript ) == -1 )
{
CString sError = ssprintf( "Error reading Lua script \"%s\": %s", sFile.c_str(), f.GetError().c_str() );
DIALOG_OK( sError, "LUA_ERROR" );
Dialog::OK( sError, "LUA_ERROR" );
return false;
}
@@ -293,7 +287,7 @@ bool LuaHelpers::RunScriptFile( const CString &sFile )
{
LUA->Release(L);
sError = ssprintf( "Lua runtime error: %s", sError.c_str() );
DIALOG_OK( sError, "LUA_ERROR" );
Dialog::OK( sError, "LUA_ERROR" );
return false;
}
LUA->Release(L);
@@ -336,7 +330,7 @@ bool LuaHelpers::RunScript( Lua *L, const CString &sExpression, const CString &s
if( !LuaHelpers::RunScript( L, sExpression, sName.size()? sName:CString("in"), sError, iReturnValues ) )
{
sError = ssprintf( "Lua runtime error parsing \"%s\": %s", sName.size()? sName.c_str():sExpression.c_str(), sError.c_str() );
DIALOG_OK( sError, "LUA_ERROR" );
Dialog::OK( sError, "LUA_ERROR" );
return false;
}
+5
View File
@@ -2,6 +2,7 @@
#include "ScreenDimensions.h"
#include "PrefsManager.h"
#include "LuaManager.h"
#include "LuaFunctions.h"
static ThemeMetric<float> THEME_SCREEN_WIDTH("Common","ScreenWidth");
static ThemeMetric<float> THEME_SCREEN_HEIGHT("Common","ScreenHeight");
@@ -79,6 +80,10 @@ void ScreenDimensions::ReloadMetricsAndUpdateLua()
LUA->SetGlobal( "SCREEN_CENTER_Y", (int) SCREEN_CENTER_Y );
}
LuaFunction_NoArgs( GetScreenAspectRatio, ScreenDimensions::GetScreenAspectRatio() );
LuaFunction_NoArgs( GetThemeAspectRatio, ScreenDimensions::GetThemeAspectRatio() );
/*
* (c) 2001-2002 Chris Danford
* All rights reserved.
+1
View File
@@ -5,6 +5,7 @@ const RString SpecialFiles::KEYMAPS_PATH = "Save/Keymaps.ini";
const RString SpecialFiles::PREFERENCES_INI_PATH = "Save/Preferences.ini";
const RString SpecialFiles::THEMES_DIR = "Themes/";
const RString SpecialFiles::LANGUAGES_SUBDIR = "Languages/";
// TODO: A theme should be able to specify a base language.
const RString SpecialFiles::BASE_LANGUAGE = "en";
const RString SpecialFiles::METRICS_FILE = "metrics.ini";
const RString SpecialFiles::CACHE_DIR = "Cache/";
+14 -6
View File
@@ -10,7 +10,9 @@
#include "arch/ArchHooks/ArchHooks.h"
#include "arch/Dialog/Dialog.h"
#include "RageFile.h"
#if !defined(SMPACKAGE)
#include "ScreenManager.h"
#endif
#include "Foreach.h"
#include "ThemeMetric.h"
#include "LuaManager.h"
@@ -18,6 +20,7 @@
#include "Command.h"
#include "LocalizedString.h"
#include "SpecialFiles.h"
#include "EnumHelper.h"
ThemeManager* THEME = NULL; // global object accessable from anywhere in the program
@@ -34,7 +37,6 @@ StringToX( ElementCategory );
const RString BASE_THEME_NAME = "default";
// TODO: A theme should be able to specify a base language.
struct Theme
@@ -303,9 +305,11 @@ void ThemeManager::SwitchThemeAndLanguage( const RString &sThemeName_, const RSt
for( int i = 0; i < NUM_ElementCategory; ++i )
g_ThemePathCache[i].clear();
#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
@@ -346,8 +350,10 @@ void ThemeManager::UpdateLuaGlobals()
RunLuaScripts( "Serialize.lua" );
LUA->ResetState();
/* Important: explicitly refresh cached metrics that we use. */
#if !defined(SMPACKAGE)
/* explicitly refresh cached metrics that we use. */
ScreenDimensions::ReloadMetricsAndUpdateLua();
#endif
RunLuaScripts( "*.lua" );
}
@@ -671,8 +677,10 @@ void ThemeManager::ReloadMetrics()
// force a reload of the metrics cache
LoadThemeMetrics( g_vThemes, m_sCurThemeName, m_sCurLanguage );
#if !defined(SMPACKAGE)
if( SCREENMAN )
SCREENMAN->SystemMessage( RELOADED_METRICS );
#endif
//
// clear theme path cache
@@ -825,11 +833,13 @@ Commands ThemeManager::GetMetricM( const RString &sClassName, const RString &sVa
return ParseCommands( sValue );
}
#if !defined(SMPACKAGE)
apActorCommands ThemeManager::GetMetricA( const RString &sClassName, const RString &sValueName )
{
RString sValue = GetMetricRaw( sClassName, sValueName );
return apActorCommands( new ActorCommands( sValue ) );
}
#endif
void ThemeManager::NextTheme()
{
@@ -876,10 +886,12 @@ void ThemeManager::GetModifierNames( vector<RString>& AddTo )
}
}
#if !defined(SMPACKAGE)
void ThemeManager::GetMetric( const RString &sClassName, const RString &sValueName, apActorCommands &valueOut )
{
valueOut = GetMetricA( sClassName, sValueName );
}
#endif
void ThemeManager::GetMetric( const RString &sClassName, const RString &sValueName, LuaExpression &valueOut )
{
@@ -940,8 +952,6 @@ public:
static int GetPathG( T* p, lua_State *L ) { lua_pushstring(L, p->GetPathG(SArg(1),SArg(2)) ); return 1; }
static int GetPathB( T* p, lua_State *L ) { lua_pushstring(L, p->GetPathB(SArg(1),SArg(2)) ); return 1; }
static int GetPathS( T* p, lua_State *L ) { lua_pushstring(L, p->GetPathS(SArg(1),SArg(2)) ); return 1; }
static int GetScreenAspectRatio( T* p, lua_State *L ) { lua_pushnumber( L, ScreenDimensions::GetScreenAspectRatio() ); return 1; }
static int GetThemeAspectRatio( T* p, lua_State *L ) { lua_pushnumber( L, ScreenDimensions::GetThemeAspectRatio() ); return 1; }
static void Register(lua_State *L)
{
@@ -950,8 +960,6 @@ public:
ADD_METHOD( GetPathG );
ADD_METHOD( GetPathB );
ADD_METHOD( GetPathS );
ADD_METHOD( GetScreenAspectRatio );
ADD_METHOD( GetThemeAspectRatio );
Luna<T>::Register( L );
+7
View File
@@ -7,7 +7,10 @@
#include <set>
#include <deque>
#include "Command.h"
#if !defined(SMPACKAGE)
#include "ActorCommands.h"
#endif
#include "LuaReference.h"
class IThemeMetric;
class IniFile;
@@ -70,7 +73,9 @@ public:
bool GetMetricB( const RString &sClassName, const RString &sValueName );
RageColor GetMetricC( const RString &sClassName, const RString &sValueName );
Commands GetMetricM( const RString &sClassName, const RString &sValueName );
#if !defined(SMPACKAGE)
apActorCommands GetMetricA( const RString &sClassName, const RString &sValueName );
#endif
void GetMetric( const RString &sClassName, const RString &sValueName, RString &valueOut ) { valueOut = GetMetric( sClassName, sValueName ); }
void GetMetric( const RString &sClassName, const RString &sValueName, int &valueOut ) { valueOut = GetMetricI( sClassName, sValueName ); }
@@ -79,7 +84,9 @@ public:
void GetMetric( const RString &sClassName, const RString &sValueName, RageColor &valueOut ) { valueOut = GetMetricC( sClassName, sValueName ); }
void GetMetric( const RString &sClassName, const RString &sValueName, Command &valueOut );
void GetMetric( const RString &sClassName, const RString &sValueName, LuaExpression &valueOut );
#if !defined(SMPACKAGE)
void GetMetric( const RString &sClassName, const RString &sValueName, apActorCommands &valueOut );
#endif
RString GetString( const RString &sClassName, const RString &sValueName );
@@ -50,13 +50,15 @@ void ArchHooks::MountInitialFilesystems( const RString &sDirOfExecutable )
RString Dir = join( "/", parts.begin(), parts.end()-1 );
FILEMAN->Mount( "dir", Dir, "/" );
RString sMyDocumentsDir = GetMyDocumentsDir();
RString sApplicationDataDir = GetApplicationDataDir();
RString sMyDocumentsDir = SpecialDirs::GetMyDocumentsDir();
RString sApplicationDataDir = SpecialDirs::GetApplicationDataDir();
RString sDesktopDir = SpecialDirs::GetDesktopDir();
// Mount everything game-writable (not counting the editor) to the user's directory.
FILEMAN->Mount( "dir", sApplicationDataDir + PRODUCT_ID + "/Cache", "/Cache" );
FILEMAN->Mount( "dir", sMyDocumentsDir + PRODUCT_ID + "/Save", "/Save" );
FILEMAN->Mount( "dir", sMyDocumentsDir + PRODUCT_ID + "/Screenshots", "/Screenshots" );
FILEMAN->Mount( "dir", sDesktopDir, "/Desktop" );
}
static CString LangIdToString( LANGID l )
+19 -6
View File
@@ -3,7 +3,7 @@
#include "RegistryAccess.h"
#include <shlobj.h>
RString GetMyDocumentsDir()
RString SpecialDirs::GetMyDocumentsDir()
{
CString sMyDocumentsDir;
bool bSuccess = RegistryAccess::GetRegValue( "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", "Personal", sMyDocumentsDir );
@@ -13,17 +13,30 @@ RString GetMyDocumentsDir()
return sMyDocumentsDir;
}
RString GetApplicationDataDir()
RString SpecialDirs::GetApplicationDataDir()
{
CString sApplicationDataDir;
CString sDir;
TCHAR szDir[MAX_PATH] = "";
BOOL bResult = SHGetSpecialFolderPath( NULL, szDir, CSIDL_APPDATA, FALSE );
ASSERT( bResult );
sApplicationDataDir = szDir;
sApplicationDataDir += "/";
return sApplicationDataDir;
sDir = szDir;
sDir += "/";
return sDir;
}
RString SpecialDirs::GetDesktopDir()
{
CString sDir;
TCHAR szDir[MAX_PATH] = "";
BOOL bResult = SHGetSpecialFolderPath( NULL, szDir, CSIDL_DESKTOP, FALSE );
ASSERT( bResult );
sDir = szDir;
sDir += "/";
return sDir;
}
/*
* (c) 2002-2004 Chris Danford
* All rights reserved.
+6 -2
View File
@@ -1,8 +1,12 @@
#ifndef SpecialDirs_H
#define SpecialDirs_H
RString GetMyDocumentsDir();
RString GetApplicationDataDir();
namespace SpecialDirs
{
RString GetMyDocumentsDir();
RString GetApplicationDataDir();
RString GetDesktopDir();
};
#endif
+52
View File
@@ -297,6 +297,12 @@
</File>
<Filter
Name="system">
<File
RelativePath=".\archutils\Win32\AppInstance.cpp">
</File>
<File
RelativePath=".\archutils\Win32\AppInstance.h">
</File>
<File
RelativePath=".\archutils\Win32\arch_setup.h">
</File>
@@ -348,6 +354,28 @@
RelativePath=".\arch\ArchHooks\ArchHooksUtil.cpp">
</File>
</Filter>
<Filter
Name="Dialog"
Filter="">
<File
RelativePath=".\arch\Dialog\Dialog.cpp">
</File>
<File
RelativePath=".\arch\Dialog\Dialog.h">
</File>
<File
RelativePath=".\arch\Dialog\DialogDriver.h">
</File>
<File
RelativePath=".\arch\Dialog\DialogDriver_Win32.cpp">
</File>
<File
RelativePath=".\arch\Dialog\DialogDriver_Win32.h">
</File>
<File
RelativePath=".\arch\Dialog\Selector_Dialog.h">
</File>
</Filter>
</Filter>
</Filter>
<Filter
@@ -513,18 +541,36 @@
<Filter
Name="Data Structures"
Filter="">
<File
RelativePath=".\Command.cpp">
</File>
<File
RelativePath=".\Command.h">
</File>
<File
RelativePath=".\DateTime.cpp">
</File>
<File
RelativePath=".\DateTime.h">
</File>
<File
RelativePath=".\FontCharAliases.cpp">
</File>
<File
RelativePath=".\FontCharAliases.h">
</File>
<File
RelativePath=".\LocalizedString.cpp">
</File>
<File
RelativePath=".\LocalizedString.h">
</File>
<File
RelativePath=".\LuaBinding.cpp">
</File>
<File
RelativePath=".\LuaBinding.h">
</File>
<File
RelativePath=".\LuaReference.cpp">
</File>
@@ -541,6 +587,12 @@
<File
RelativePath=".\LuaManager.h">
</File>
<File
RelativePath=".\ThemeManager.cpp">
</File>
<File
RelativePath=".\ThemeManager.h">
</File>
</Filter>
<File
RelativePath=".\smpackage\install.bmp">
+2
View File
@@ -376,4 +376,6 @@ void LanguagesDlg::OnBnClickedButtonImport()
MessageBox( ssprintf("Imported %d strings into '%s'. %d empty strings were ignored.",iNumImported,sLanguageFile.c_str(),iNumIgnored) );
else
MessageBox( ssprintf("Failed to save '%s'.",sLanguageFile.c_str()) );
OnSelchangeListThemes();
}