add PseudoLocalize
phase out SubscriptionManager for SubscriptionHandler to fix ThemeManager assert
This commit is contained in:
@@ -17,11 +17,11 @@ void LocalizedString::RegisterLocalizer( RString (*pfnLocalizer)(const RString&,
|
||||
|
||||
#include "SubscriptionManager.h"
|
||||
template<>
|
||||
set<LocalizedString*>* SubscriptionManager<LocalizedString>::s_pSubscribers = NULL;
|
||||
SubscriptionHandler<LocalizedString> g_Subscribers;
|
||||
|
||||
void LocalizedString::RefreshLocalizedStrings()
|
||||
{
|
||||
FOREACHS( LocalizedString*, *SubscriptionManager<LocalizedString>::s_pSubscribers, p )
|
||||
FOREACHS( LocalizedString*, *g_Subscribers.m_pSubscribers, p )
|
||||
(*p)->Refresh();
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ LocalizedString::LocalizedString( const RString &sSection, const RString &sName
|
||||
m_sName = sName;
|
||||
m_sValue = sName;
|
||||
|
||||
SubscriptionManager<LocalizedString>::Subscribe( this );
|
||||
g_Subscribers.Subscribe( this );
|
||||
|
||||
Refresh();
|
||||
}
|
||||
@@ -44,7 +44,7 @@ LocalizedString::LocalizedString( const RString &sSection, const RString &sName
|
||||
|
||||
LocalizedString::~LocalizedString()
|
||||
{
|
||||
SubscriptionManager<LocalizedString>::Unsubscribe( this );
|
||||
g_Subscribers.Unsubscribe( this );
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -9,24 +9,23 @@
|
||||
|
||||
REGISTER_CLASS_TRAITS( LuaReference, new LuaReference(*pCopy) )
|
||||
|
||||
template<>
|
||||
set<LuaReference*>* SubscriptionManager<LuaReference>::s_pSubscribers = NULL;
|
||||
SubscriptionHandler<LuaReference> g_Subscribers;
|
||||
|
||||
LuaReference::LuaReference()
|
||||
{
|
||||
m_iReference = LUA_NOREF;
|
||||
SubscriptionManager<LuaReference>::Subscribe( this );
|
||||
g_Subscribers.Subscribe( this );
|
||||
}
|
||||
|
||||
LuaReference::~LuaReference()
|
||||
{
|
||||
Unregister();
|
||||
SubscriptionManager<LuaReference>::Unsubscribe( this );
|
||||
g_Subscribers.Unsubscribe( this );
|
||||
}
|
||||
|
||||
LuaReference::LuaReference( const LuaReference &cpy )
|
||||
{
|
||||
SubscriptionManager<LuaReference>::Subscribe( this );
|
||||
g_Subscribers.Subscribe( this );
|
||||
|
||||
if( cpy.m_iReference == LUA_NOREF )
|
||||
m_iReference = LUA_NOREF;
|
||||
@@ -135,17 +134,17 @@ void LuaReference::Unregister()
|
||||
|
||||
void LuaReference::BeforeResetAll()
|
||||
{
|
||||
if( SubscriptionManager<LuaReference>::s_pSubscribers == NULL )
|
||||
if( g_Subscribers.m_pSubscribers == NULL )
|
||||
return;
|
||||
FOREACHS( LuaReference*, *SubscriptionManager<LuaReference>::s_pSubscribers, p )
|
||||
FOREACHS( LuaReference*, *g_Subscribers.m_pSubscribers, p )
|
||||
(*p)->BeforeReset();
|
||||
}
|
||||
|
||||
void LuaReference::AfterResetAll()
|
||||
{
|
||||
if( SubscriptionManager<LuaReference>::s_pSubscribers == NULL )
|
||||
if( g_Subscribers.m_pSubscribers == NULL )
|
||||
return;
|
||||
FOREACHS( LuaReference*, *SubscriptionManager<LuaReference>::s_pSubscribers, p )
|
||||
FOREACHS( LuaReference*, *g_Subscribers.m_pSubscribers, p )
|
||||
(*p)->ReRegister();
|
||||
}
|
||||
|
||||
|
||||
@@ -310,7 +310,8 @@ PrefsManager::PrefsManager() :
|
||||
m_bShowLogOutput ( "ShowLogOutput", false ),
|
||||
m_bLogSkips ( "LogSkips", false ),
|
||||
m_bLogCheckpoints ( "LogCheckpoints", false ),
|
||||
m_bShowLoadingWindow ( "ShowLoadingWindow", true )
|
||||
m_bShowLoadingWindow ( "ShowLoadingWindow", true ),
|
||||
m_bPseudoLocalize ( "PseudoLocalize", false )
|
||||
|
||||
#if !defined(WITHOUT_NETWORKING)
|
||||
,
|
||||
|
||||
@@ -236,6 +236,7 @@ public:
|
||||
Preference<bool> m_bLogSkips;
|
||||
Preference<bool> m_bLogCheckpoints;
|
||||
Preference<bool> m_bShowLoadingWindow;
|
||||
Preference<bool> m_bPseudoLocalize;
|
||||
|
||||
#if !defined(WITHOUT_NETWORKING)
|
||||
Preference<bool> m_bEnableScoreboard; //Alows disabling of scoreboard in network play
|
||||
|
||||
@@ -56,8 +56,8 @@ struct DirAndProfile
|
||||
static vector<DirAndProfile> g_vLocalProfile;
|
||||
|
||||
|
||||
static ThemeMetric<bool> FIXED_PROFILES( "ProfileManager", "FixedProfiles" );
|
||||
static ThemeMetric<int> NUM_FIXED_PROFILES( "ProfileManager", "NumFixedProfiles" );
|
||||
static ThemeMetric<bool> FIXED_PROFILES ( "ProfileManager", "FixedProfiles" );
|
||||
static ThemeMetric<int> NUM_FIXED_PROFILES ( "ProfileManager", "NumFixedProfiles" );
|
||||
#define FIXED_PROFILE_CHARACTER_ID( i ) THEME->GetMetric( "ProfileManager", ssprintf("FixedProfileCharacterID%d",int(i+1)) )
|
||||
|
||||
|
||||
|
||||
@@ -4,37 +4,9 @@
|
||||
#define SubscriptionManager_H
|
||||
|
||||
#include <set>
|
||||
template<class T>
|
||||
class SubscriptionManager
|
||||
{
|
||||
public:
|
||||
// TRICKY: If we make this a global instead of a global pointer,
|
||||
// then we'd have to be careful that the static constructors of all
|
||||
// subscribers are called before the collection constructor. It's
|
||||
// impossible to enfore that in C++. Instead, we'll allocate the
|
||||
// collection ourself on first use.
|
||||
static set<T*>* s_pSubscribers;
|
||||
|
||||
static void Subscribe( T* p )
|
||||
{
|
||||
if( s_pSubscribers == NULL )
|
||||
s_pSubscribers = new set<T*>;
|
||||
#if _DEBUG
|
||||
typename set<T*>::iterator iter = s_pSubscribers->find( p );
|
||||
ASSERT_M( iter == s_pSubscribers->end(), "already subscribed" );
|
||||
#endif
|
||||
s_pSubscribers->insert( p );
|
||||
}
|
||||
|
||||
static void Unsubscribe( T* p )
|
||||
{
|
||||
typename set<T*>::iterator iter = s_pSubscribers->find( p );
|
||||
ASSERT( iter != s_pSubscribers->end() );
|
||||
s_pSubscribers->erase( iter );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// Since this class has only POD types and no constructor, there's no
|
||||
// initialize order problem.
|
||||
template<class T>
|
||||
class SubscriptionHandler
|
||||
{
|
||||
|
||||
@@ -16,9 +16,6 @@
|
||||
#include "Foreach.h"
|
||||
#include "ThemeMetric.h"
|
||||
#include "SubscriptionManager.h"
|
||||
template<>
|
||||
set<IThemeMetric*>* SubscriptionManager<IThemeMetric>::s_pSubscribers = NULL;
|
||||
|
||||
#include "LuaManager.h"
|
||||
#include "ScreenDimensions.h"
|
||||
#include "Command.h"
|
||||
@@ -112,6 +109,7 @@ ThemeManager::ThemeManager()
|
||||
|
||||
/* We don't have any theme loaded until SwitchThemeAndLanguage is called. */
|
||||
m_sCurThemeName = "";
|
||||
m_bPseudoLocalilze = false;
|
||||
|
||||
vector<RString> arrayThemeNames;
|
||||
GetThemeNames( arrayThemeNames );
|
||||
@@ -318,7 +316,7 @@ void ThemeManager::SwitchThemeAndLanguage( const RString &sThemeName_, const RSt
|
||||
}
|
||||
|
||||
// reload subscribers
|
||||
if( SubscriptionManager<IThemeMetric>::s_pSubscribers )
|
||||
if( g_Subscribers.m_pSubscribers )
|
||||
{
|
||||
FOREACHS_CONST( IThemeMetric*, *g_Subscribers.m_pSubscribers, p )
|
||||
(*p)->Read();
|
||||
@@ -904,6 +902,11 @@ void ThemeManager::GetMetric( const RString &sClassName, const RString &sValueNa
|
||||
valueOut.SetFromExpression( "function(self) " + sValue + "end" );
|
||||
}
|
||||
|
||||
void ThemeManager::SetPseudoLocalilze( bool b )
|
||||
{
|
||||
m_bPseudoLocalilze = b;
|
||||
}
|
||||
|
||||
RString ThemeManager::GetString( const RString &sClassName, const RString &sValueName_ )
|
||||
{
|
||||
RString sValueName = sValueName_;
|
||||
@@ -930,6 +933,28 @@ RString ThemeManager::GetString( const RString &sClassName, const RString &sValu
|
||||
|
||||
s.Replace( "\\n", "\n" );
|
||||
|
||||
if( m_bPseudoLocalilze )
|
||||
{
|
||||
s.Replace( "a", "àá" );
|
||||
s.Replace( "A", "ÀÀ" );
|
||||
s.Replace( "e", "éé" );
|
||||
s.Replace( "E", "ÉÉ" );
|
||||
s.Replace( "i", "íí" );
|
||||
s.Replace( "I", "ÍÍ" );
|
||||
s.Replace( "o", "óó" );
|
||||
s.Replace( "O", "ÓÓ" );
|
||||
s.Replace( "u", "üü" );
|
||||
s.Replace( "U", "ÜÜ" );
|
||||
s.Replace( "n", "ñ" );
|
||||
s.Replace( "N", "Ñ" );
|
||||
s.Replace( "c", "ç" );
|
||||
s.Replace( "C", "Ç" );
|
||||
// transformations that helpexpose punctuation assumptions
|
||||
s.Replace( ":", " :" );
|
||||
s.Replace( "?", " ?" );
|
||||
s.Replace( "!", " !" );
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
@@ -88,6 +88,8 @@ public:
|
||||
void GetMetric( const RString &sClassName, const RString &sValueName, apActorCommands &valueOut );
|
||||
#endif
|
||||
|
||||
// Languages
|
||||
void SetPseudoLocalilze( bool b );
|
||||
RString GetString( const RString &sClassName, const RString &sValueName );
|
||||
|
||||
void GetMetricsThatBeginWith( const RString &sClassName, const RString &sValueName, set<RString> &vsValueNamesOut );
|
||||
@@ -118,6 +120,7 @@ protected:
|
||||
|
||||
RString m_sCurThemeName;
|
||||
RString m_sCurLanguage;
|
||||
bool m_bPseudoLocalilze;
|
||||
};
|
||||
|
||||
extern ThemeManager* THEME; // global and accessable from anywhere in our program
|
||||
|
||||
Reference in New Issue
Block a user