implement with ThemeMetric to remove dupe logic
This commit is contained in:
@@ -3,86 +3,53 @@
|
|||||||
#include "Foreach.h"
|
#include "Foreach.h"
|
||||||
#include "LuaFunctions.h"
|
#include "LuaFunctions.h"
|
||||||
#include "LuaManager.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;
|
public:
|
||||||
}
|
LocalizedStringImpl( const RString& sGroup, const RString& sName ) :
|
||||||
static RString (*g_pfnLocalizer)(const RString&,const RString&) = DefaultLocalizer;
|
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()
|
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_pImpl->Load( sGroup, sName );
|
||||||
m_sName = sName;
|
|
||||||
m_sValue = "????";
|
|
||||||
|
|
||||||
Refresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
LocalizedString::operator RString() const
|
|
||||||
{
|
|
||||||
return GetValue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const RString &LocalizedString::GetValue() const
|
const RString &LocalizedString::GetValue() const
|
||||||
{
|
{
|
||||||
ASSERT( IsLoaded() );
|
return m_pImpl->GetValue();
|
||||||
return m_sValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
void LocalizedString::Refresh()
|
|
||||||
{
|
|
||||||
m_sValue = LocalizeString( m_sSection, m_sName );
|
|
||||||
m_bValueLoaded = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LocalizedString::IsLoaded() const
|
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
|
* Copyright (c) 2001-2005 Chris Danford
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
|
|||||||
@@ -3,27 +3,20 @@
|
|||||||
#ifndef LocalizedString_H
|
#ifndef LocalizedString_H
|
||||||
#define LocalizedString_H
|
#define LocalizedString_H
|
||||||
|
|
||||||
|
class LocalizedStringImpl;
|
||||||
|
|
||||||
class LocalizedString
|
class LocalizedString
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static void RegisterLocalizer( RString (*pfnLocalizer)(const RString&,const RString&) );
|
|
||||||
static void RefreshLocalizedStrings();
|
|
||||||
static RString LocalizeString( const RString &sSection, const RString &sName );
|
|
||||||
|
|
||||||
|
LocalizedString( const RString& sGroup = "", const RString& sName = "" );
|
||||||
LocalizedString();
|
|
||||||
LocalizedString( const RString &sSection, const RString &sName );
|
|
||||||
~LocalizedString();
|
~LocalizedString();
|
||||||
void Load( const RString &sSection, const RString &sName );
|
void Load( const RString& sGroup, const RString& sName );
|
||||||
void Refresh();
|
operator const RString &() const { return GetValue(); }
|
||||||
operator RString() const;
|
|
||||||
const RString &GetValue() const;
|
const RString &GetValue() const;
|
||||||
bool IsLoaded() const;
|
bool IsLoaded() const;
|
||||||
private:
|
private:
|
||||||
RString m_sSection;
|
LocalizedStringImpl *m_pImpl;
|
||||||
RString m_sName;
|
|
||||||
RString m_sValue;
|
|
||||||
bool m_bValueLoaded;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user