From 6e6fcb746a94be1327e46d23cc9a83782b84aa44 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Fri, 30 Dec 2005 07:24:30 +0000 Subject: [PATCH] "XToThemedString" uses theme metrics. We don't want DateTime (used by XmlFile) to depend on THEME, so use localized strings. We may *always* want LocalizedString. One reason we may not is if we start using the DynamicThemeMetric paradigm more. That evaluates expressions when they're used, which allows metrics to change dynamically. However, we may really not want to do that for localized strings, since it would complicate translation, so we may want to restrict localized strings to pre-evaluation anyway. --- stepmania/src/DateTime.cpp | 14 ++++---------- stepmania/src/DateTime.h | 4 ++-- stepmania/src/EnumHelper.h | 11 +++++++++++ 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/stepmania/src/DateTime.cpp b/stepmania/src/DateTime.cpp index 4e6034b9e6..15fd2254d7 100644 --- a/stepmania/src/DateTime.cpp +++ b/stepmania/src/DateTime.cpp @@ -2,10 +2,8 @@ #include "DateTime.h" #include "RageUtil.h" #include "EnumHelper.h" -#if !defined(SMPACKAGE) -#include "ThemeMetric.h" -#endif #include "LuaFunctions.h" +#include "LocalizedString.h" DateTime::DateTime() { @@ -196,10 +194,8 @@ static const CString MonthNames[] = "November", "December", }; -XToString( Month, MONTHS_IN_YEAR ); -#if !defined(SMPACKAGE) -XToThemedString( Month, MONTHS_IN_YEAR ); -#endif +XToString( Month, NUM_Month ); +XToLocalizedString( Month ); CString LastWeekToString( int iLastWeekIndex ) { @@ -308,9 +304,7 @@ tm GetDayInYearAndYear( int iDayInYearIndex, int iYear ) } LuaFunction( MonthToString, MonthToString( (Month)IArg(1) ) ); -#if !defined(SMPACKAGE) -LuaFunction( MonthToThemedString, MonthToThemedString( (Month)IArg(1) ) ); -#endif +LuaFunction( MonthToLocalizedString, MonthToLocalizedString( (Month)IArg(1) ) ); LuaFunction( MonthOfYear, GetLocalTime().tm_mon ); LuaFunction( DayOfMonth, GetLocalTime().tm_mday ); LuaFunction( Hour, GetLocalTime().tm_hour ); diff --git a/stepmania/src/DateTime.h b/stepmania/src/DateTime.h index adc920f019..e3d1fb9258 100644 --- a/stepmania/src/DateTime.h +++ b/stepmania/src/DateTime.h @@ -8,7 +8,7 @@ const int NUM_LAST_WEEKS = 52; const int DAYS_IN_YEAR = 366; // maximum (leap years) const int HOURS_IN_DAY = 24; const int DAYS_IN_WEEK = 7; -enum Month { MONTHS_IN_YEAR = 12 }; +enum Month { NUM_Month = 12 }; CString DayInYearToString( int iDayInYearIndex ); CString LastDayToString( int iLastDayIndex ); @@ -18,7 +18,7 @@ CString DayOfWeekToThemedString( int iDayOfWeekIndex ); CString HourInDayToString( int iHourIndex ); CString HourInDayToThemedString( int iHourIndex ); const CString &MonthToString( Month month ); -const CString &MonthToThemedString( Month month ); +const CString &MonthToLocalizedString( Month month ); CString LastWeekToString( int iLastWeekIndex ); CString LastWeekToThemedString( int iLastWeekIndex ); diff --git a/stepmania/src/EnumHelper.h b/stepmania/src/EnumHelper.h index 55a1e93d7d..ddc2ce25b9 100644 --- a/stepmania/src/EnumHelper.h +++ b/stepmania/src/EnumHelper.h @@ -68,6 +68,17 @@ static const CString EMPTY_STRING; return g_##X##Name[x]; \ } +#define XToLocalizedString(X) \ + const CString &X##ToLocalizedString( X x ) \ + { \ + static auto_ptr g_##X##Name[NUM_##X]; \ + if( g_##X##Name[0].get() == NULL ) { \ + for( unsigned i = 0; i < NUM_##X; ++i ) \ + g_##X##Name[i].reset( new LocalizedString(#X, X##ToString((X)i)) ); \ + } \ + return g_##X##Name[x]->GetValue(); \ + } + #define StringToX(X) \ X StringTo##X( const CString& s ) \ { \