implement with ThemeMetric to remove dupe logic

This commit is contained in:
Chris Danford
2006-01-08 05:30:04 +00:00
parent 32223b6912
commit 15423adaf5
2 changed files with 32 additions and 72 deletions
+26 -59
View File
@@ -3,86 +3,53 @@
#include "Foreach.h"
#include "LuaFunctions.h"
#include "LuaManager.h"
#include "ThemeMetric.h"
#include "RageUtil.h"
static RString DefaultLocalizer( const RString &sSection, const RString &sName )
class LocalizedStringImpl : public ThemeMetric<RString>
{
return sName;
}
static RString (*g_pfnLocalizer)(const RString&,const RString&) = DefaultLocalizer;
public:
LocalizedStringImpl( const RString& sGroup, const RString& sName ) :
ThemeMetric<RString>( sGroup, sName )
{
}
void LocalizedString::RegisterLocalizer( RString (*pfnLocalizer)(const RString&, const RString&) )
virtual void Read()
{
if( m_sName != "" && THEME && THEME->IsThemeLoaded() )
{
THEME->GetString( m_sGroup, m_sName, m_currentValue );
m_bIsLoaded = true;
}
}
};
LocalizedString::LocalizedString( const RString& sGroup, const RString& sName )
{
g_pfnLocalizer = pfnLocalizer;
m_pImpl = new LocalizedStringImpl(sGroup,sName);
}
#include "SubscriptionManager.h"
static SubscriptionManager<LocalizedString> g_Subscribers;
void LocalizedString::RefreshLocalizedStrings()
{
FOREACHS( LocalizedString*, *g_Subscribers.m_pSubscribers, p )
(*p)->Refresh();
}
RString LocalizedString::LocalizeString( const RString &sSection, const RString &sName )
{
return g_pfnLocalizer( sSection, sName );
}
LocalizedString::LocalizedString()
{
g_Subscribers.Subscribe( this );
m_bValueLoaded = false;
}
LocalizedString::LocalizedString( const RString &sSection, const RString &sName )
{
g_Subscribers.Subscribe( this );
m_bValueLoaded = false;
Load( sSection, sName );
Refresh();
}
LocalizedString::~LocalizedString()
{
g_Subscribers.Unsubscribe( this );
SAFE_DELETE( m_pImpl );
}
void LocalizedString::Load( const RString &sSection, const RString &sName )
void LocalizedString::Load( const RString& sGroup, const RString& sName )
{
m_sSection = sSection;
m_sName = sName;
m_sValue = "????";
Refresh();
}
LocalizedString::operator RString() const
{
return GetValue();
m_pImpl->Load( sGroup, sName );
}
const RString &LocalizedString::GetValue() const
{
ASSERT( IsLoaded() );
return m_sValue;
}
void LocalizedString::Refresh()
{
m_sValue = LocalizeString( m_sSection, m_sName );
m_bValueLoaded = true;
return m_pImpl->GetValue();
}
bool LocalizedString::IsLoaded() const
{
return m_bValueLoaded;
return m_pImpl->IsLoaded();
}
LuaFunction( LocalizeString, LocalizedString::LocalizeString( SArg(1), SArg(2) ) )
/*
* Copyright (c) 2001-2005 Chris Danford
* All rights reserved.