From 076d67132de8febfa3ce045e604934ef88b717ea Mon Sep 17 00:00:00 2001 From: Kyzentun Date: Tue, 29 Jul 2014 12:09:40 -0600 Subject: [PATCH] Reverted BitmapText::LoadFromNode back to previous logic. BitmapText now looks up font names in Fonts/ if the path doesn't resolve, so LoadFont is obsolete. Added optional arg to ActorUtil::ResolvePath and GetAttrPath to make them not report an error when something is optional. --- .../BGAnimations/ScreenTestInput underlay.lua | 4 +- src/ActorUtil.cpp | 10 ++-- src/ActorUtil.h | 4 +- src/BitmapText.cpp | 50 +++++++++---------- 4 files changed, 35 insertions(+), 33 deletions(-) diff --git a/Themes/_fallback/BGAnimations/ScreenTestInput underlay.lua b/Themes/_fallback/BGAnimations/ScreenTestInput underlay.lua index 862f42fdb1..ff3baa5bf7 100644 --- a/Themes/_fallback/BGAnimations/ScreenTestInput underlay.lua +++ b/Themes/_fallback/BGAnimations/ScreenTestInput underlay.lua @@ -3,12 +3,12 @@ return Def.ActorFrame { -- InitCommand=cmd(LoadGameController, --}; Def.DeviceList { - Font="Common normal"; + Font="Common Normal", InitCommand=cmd(x,SCREEN_LEFT+20;y,SCREEN_TOP+80;zoom,0.8;halign,0); }; Def.InputList { - Font="Common normal"; + Font="Common Normal", InitCommand=cmd(x,SCREEN_CENTER_X-250;y,SCREEN_CENTER_Y;zoom,1;halign,0;vertspacing,8); }; }; diff --git a/src/ActorUtil.cpp b/src/ActorUtil.cpp index 3d48573c6c..2fb3b5ffda 100644 --- a/src/ActorUtil.cpp +++ b/src/ActorUtil.cpp @@ -40,7 +40,7 @@ void ActorUtil::Register( const RString& sClassName, CreateActorFn pfn ) /* Resolves actor paths a la LoadActor("..."), with autowildcarding and .redir * files. Returns a path *within* the Rage filesystem, unlike the FILEMAN * function of the same name. */ -bool ActorUtil::ResolvePath( RString &sPath, const RString &sName ) +bool ActorUtil::ResolvePath( RString &sPath, const RString &sName, bool optional ) { CollapsePath( sPath ); @@ -54,6 +54,10 @@ bool ActorUtil::ResolvePath( RString &sPath, const RString &sName ) if( asPaths.empty() ) { + if(optional) + { + return false; + } RString sError = ssprintf( "%s: references a file \"%s\" which doesn't exist", sName.c_str(), sPath.c_str() ); switch(LuaHelpers::ReportScriptError(sError, "BROKEN_FILE_REFERENCE", true)) { @@ -402,7 +406,7 @@ RString ActorUtil::GetWhere( const XNode *pNode ) return sPath; } -bool ActorUtil::GetAttrPath( const XNode *pNode, const RString &sName, RString &sOut ) +bool ActorUtil::GetAttrPath( const XNode *pNode, const RString &sName, RString &sOut, bool optional ) { if( !pNode->GetAttrValue(sName, sOut) ) return false; @@ -419,7 +423,7 @@ bool ActorUtil::GetAttrPath( const XNode *pNode, const RString &sName, RString & sOut = sDir+sOut; } - return ActorUtil::ResolvePath( sOut, ActorUtil::GetWhere(pNode) ); + return ActorUtil::ResolvePath( sOut, ActorUtil::GetWhere(pNode), optional ); } apActorCommands ActorUtil::ParseActorCommands( const RString &sCommands, const RString &sName ) diff --git a/src/ActorUtil.h b/src/ActorUtil.h index 7679d7a236..3a6d139235 100644 --- a/src/ActorUtil.h +++ b/src/ActorUtil.h @@ -114,10 +114,10 @@ namespace ActorUtil Actor* MakeActor( const RString &sPath, Actor *pParentActor = NULL ); RString GetSourcePath( const XNode *pNode ); RString GetWhere( const XNode *pNode ); - bool GetAttrPath( const XNode *pNode, const RString &sName, RString &sOut ); + bool GetAttrPath( const XNode *pNode, const RString &sName, RString &sOut, bool optional= false ); bool LoadTableFromStackShowErrors( Lua *L ); - bool ResolvePath( RString &sPath, const RString &sName ); + bool ResolvePath( RString &sPath, const RString &sName, bool optional= false ); void SortByZPosition( vector &vActors ); diff --git a/src/BitmapText.cpp b/src/BitmapText.cpp index fd55c067d2..6f6c81b760 100644 --- a/src/BitmapText.cpp +++ b/src/BitmapText.cpp @@ -115,39 +115,37 @@ BitmapText::BitmapText( const BitmapText &cpy ): *this = cpy; } -void BitmapText::LoadFromNode( const XNode* pNode ) +void BitmapText::LoadFromNode( const XNode* node ) { - RString sText; - pNode->GetAttrValue( "Text", sText ); - RString sAltText; - pNode->GetAttrValue( "AltText", sAltText ); + RString text; + node->GetAttrValue("Text", text); + RString alt_text; + node->GetAttrValue("AltText", alt_text); - ThemeManager::EvaluateString( sText ); - ThemeManager::EvaluateString( sAltText ); + ThemeManager::EvaluateString(text); + ThemeManager::EvaluateString(alt_text); - RString sFont; - // Allow the Font attribute to be either a path or simply the name of a font. - // If it's a path, it will have a slash in it. - // Also allow it to be set through either "Font" or through "File". - if(!pNode->GetAttrValue("Font", sFont) && !pNode->GetAttrValue("File", sFont)) + RString font; + // Pass optional= true so that an error will not be reported if the path + // doesn't resolve to a file. This way, a font can be either a path or the + // name of a font to look up in Fonts/. -Kyz + if(!ActorUtil::GetAttrPath(node, "Font", font, true) && + !ActorUtil::GetAttrPath(node, "File", font, true)) { - LuaHelpers::ReportScriptErrorFmt("%s: BitmapText: Font or File attribute not found", - ActorUtil::GetWhere(pNode).c_str()); - sFont = "Common Normal"; - } - if(sFont.find("/") == RString::npos) - { - sFont= THEME->GetPathF("", sFont); - } - else if(!ActorUtil::ResolvePath(sFont, ActorUtil::GetWhere(pNode))) - { - sFont= THEME->GetPathF("", "Common Normal"); + if(!node->GetAttrValue("Font", font) && + !node->GetAttrValue("File", font)) // accept "File" for backward compatibility + { + LuaHelpers::ReportScriptErrorFmt("%s: BitmapText: Font or File attribute" + " not found", ActorUtil::GetWhere(node).c_str()); + font = "Common Normal"; + } + font = THEME->GetPathF("", font); } - LoadFromFont( sFont ); + LoadFromFont(font); - SetText( sText, sAltText ); - Actor::LoadFromNode( pNode ); + SetText(text, alt_text); + Actor::LoadFromNode(node); } bool BitmapText::LoadFromFont( const RString& sFontFilePath )