allow Lua expressions in text metrics by prepending @
This commit is contained in:
@@ -6,10 +6,7 @@
|
||||
#include "BGAnimation.h"
|
||||
#include "IniFile.h"
|
||||
#include "ThemeManager.h"
|
||||
#include "RageDisplay.h"
|
||||
#include "RageLog.h"
|
||||
#include "arch/ArchHooks/ArchHooks.h"
|
||||
#include "RageFileManager.h"
|
||||
#include "SongCreditDisplay.h"
|
||||
#include "song.h"
|
||||
#include "GameState.h"
|
||||
@@ -76,13 +73,8 @@ Actor* LoadFromActorFile( const CString& sAniDir, const XNode& layer )
|
||||
CString sAlttext;
|
||||
layer.GetAttrValue("AltText", sAlttext );
|
||||
|
||||
// Keep the special treatment of text string sync'd with the same treatments
|
||||
// in ThemeManager.
|
||||
sText.Replace( "::", "\n" );
|
||||
sAlttext.Replace( "::", "\n" );
|
||||
|
||||
FontCharAliases::ReplaceMarkers( sText );
|
||||
FontCharAliases::ReplaceMarkers( sAlttext );
|
||||
ThemeManager::EvaluateString( sText );
|
||||
ThemeManager::EvaluateString( sAlttext );
|
||||
|
||||
BitmapText* pBitmapText = new BitmapText;
|
||||
|
||||
|
||||
@@ -241,6 +241,22 @@ float Lua::RunExpressionF( const CString &str )
|
||||
return result;
|
||||
}
|
||||
|
||||
bool Lua::RunExpressionS( const CString &str, CString &sOut )
|
||||
{
|
||||
if( L == NULL )
|
||||
OpenLua();
|
||||
|
||||
if( !RunExpression( str ) )
|
||||
return false;
|
||||
|
||||
ASSERT( lua_gettop(L) > 0 );
|
||||
|
||||
sOut = lua_tostring( L, -1 );
|
||||
lua_pop( L, -1 );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Lua::Fail( lua_State *L, const CString &err )
|
||||
{
|
||||
lua_pushstring( L, err );
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace Lua
|
||||
void PrepareExpression( CString &sInOut ); // strip "//" comments and "+"
|
||||
bool RunExpressionB( const CString &str );
|
||||
float RunExpressionF( const CString &str );
|
||||
bool RunExpressionS( const CString &str, CString &sOut );
|
||||
|
||||
void Fail( lua_State *L, const CString &err );
|
||||
|
||||
|
||||
@@ -650,16 +650,34 @@ CString ThemeManager::GetMetric( const CString &sClassName, const CString &sValu
|
||||
{
|
||||
CString sValue = GetMetricRaw(sClassName,sValueName);
|
||||
|
||||
// "::" means newline since you can't use line breaks in an ini file.
|
||||
sValue.Replace("::","\n");
|
||||
|
||||
/* XXX: add a parameter to turn this off if there are some metrics where
|
||||
* we don't want markers */
|
||||
FontCharAliases::ReplaceMarkers(sValue);
|
||||
EvaluateString( sValue );
|
||||
|
||||
return sValue;
|
||||
}
|
||||
|
||||
void ThemeManager::EvaluateString( CString &sText )
|
||||
{
|
||||
/* If the string begins with an @, treat it as a raw Lua expression, and don't do any
|
||||
* other filtering. (XXX: maybe we should still do font aliases) */
|
||||
if( sText.size() >= 1 && sText[0] == '@' )
|
||||
{
|
||||
/* Erase "@". */
|
||||
sText.erase( 0, 1 );
|
||||
|
||||
CString sOut;
|
||||
Lua::RunExpressionS( sText, sOut );
|
||||
LOG->Trace("ran '%s', got '%s'", sText.c_str(), sOut.c_str());
|
||||
sText = sOut;
|
||||
return;
|
||||
}
|
||||
|
||||
// "::" means newline since you can't use line breaks in an ini file.
|
||||
// XXX: this makes it impossible to put a colon at the end of a line, eg: "Color:\nRed"
|
||||
sText.Replace("::","\n");
|
||||
|
||||
FontCharAliases::ReplaceMarkers( sText );
|
||||
}
|
||||
|
||||
int ThemeManager::GetMetricI( const CString &sClassName, const CString &sValueName )
|
||||
{
|
||||
return atoi( GetMetricRaw(sClassName,sValueName) );
|
||||
|
||||
@@ -35,6 +35,8 @@ public:
|
||||
void ReloadMetrics();
|
||||
void GetModifierNames( set<CString>& AddTo );
|
||||
|
||||
static void EvaluateString( CString &sText );
|
||||
|
||||
/* I renamed these for two reasons. The overload conflicts with the ones below:
|
||||
* GetPathToB( str, str ) was matching the ones below instead of these. It's also
|
||||
* easier to search for uses of obsolete functions if they have a different name. */
|
||||
|
||||
Reference in New Issue
Block a user