From 15423adaf5ffafc3a14a1c9a789029e5096a5885 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Sun, 8 Jan 2006 05:30:04 +0000 Subject: [PATCH] implement with ThemeMetric to remove dupe logic --- stepmania/src/LocalizedString.cpp | 85 ++++++++++--------------------- stepmania/src/LocalizedString.h | 19 +++---- 2 files changed, 32 insertions(+), 72 deletions(-) diff --git a/stepmania/src/LocalizedString.cpp b/stepmania/src/LocalizedString.cpp index 9cd0d849cc..8c3e6f427e 100644 --- a/stepmania/src/LocalizedString.cpp +++ b/stepmania/src/LocalizedString.cpp @@ -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 { - return sName; -} -static RString (*g_pfnLocalizer)(const RString&,const RString&) = DefaultLocalizer; +public: + LocalizedStringImpl( const RString& sGroup, const RString& sName ) : + ThemeMetric( 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 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. diff --git a/stepmania/src/LocalizedString.h b/stepmania/src/LocalizedString.h index 291b035c30..d98283e793 100644 --- a/stepmania/src/LocalizedString.h +++ b/stepmania/src/LocalizedString.h @@ -3,27 +3,20 @@ #ifndef LocalizedString_H #define LocalizedString_H +class LocalizedStringImpl; + class LocalizedString { public: - static void RegisterLocalizer( RString (*pfnLocalizer)(const RString&,const RString&) ); - static void RefreshLocalizedStrings(); - static RString LocalizeString( const RString &sSection, const RString &sName ); - - LocalizedString(); - LocalizedString( const RString &sSection, const RString &sName ); + LocalizedString( const RString& sGroup = "", const RString& sName = "" ); ~LocalizedString(); - void Load( const RString &sSection, const RString &sName ); - void Refresh(); - operator RString() const; + void Load( const RString& sGroup, const RString& sName ); + operator const RString &() const { return GetValue(); } const RString &GetValue() const; bool IsLoaded() const; private: - RString m_sSection; - RString m_sName; - RString m_sValue; - bool m_bValueLoaded; + LocalizedStringImpl *m_pImpl; }; #endif