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.
This commit is contained in:
Kyzentun
2014-07-29 12:09:40 -06:00
parent 1d5f4ec115
commit 076d67132d
4 changed files with 35 additions and 33 deletions
@@ -3,12 +3,12 @@ return Def.ActorFrame {
-- InitCommand=cmd(LoadGameController, -- InitCommand=cmd(LoadGameController,
--}; --};
Def.DeviceList { Def.DeviceList {
Font="Common normal"; Font="Common Normal",
InitCommand=cmd(x,SCREEN_LEFT+20;y,SCREEN_TOP+80;zoom,0.8;halign,0); InitCommand=cmd(x,SCREEN_LEFT+20;y,SCREEN_TOP+80;zoom,0.8;halign,0);
}; };
Def.InputList { 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); InitCommand=cmd(x,SCREEN_CENTER_X-250;y,SCREEN_CENTER_Y;zoom,1;halign,0;vertspacing,8);
}; };
}; };
+7 -3
View File
@@ -40,7 +40,7 @@ void ActorUtil::Register( const RString& sClassName, CreateActorFn pfn )
/* Resolves actor paths a la LoadActor("..."), with autowildcarding and .redir /* Resolves actor paths a la LoadActor("..."), with autowildcarding and .redir
* files. Returns a path *within* the Rage filesystem, unlike the FILEMAN * files. Returns a path *within* the Rage filesystem, unlike the FILEMAN
* function of the same name. */ * 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 ); CollapsePath( sPath );
@@ -54,6 +54,10 @@ bool ActorUtil::ResolvePath( RString &sPath, const RString &sName )
if( asPaths.empty() ) 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() ); 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)) switch(LuaHelpers::ReportScriptError(sError, "BROKEN_FILE_REFERENCE", true))
{ {
@@ -402,7 +406,7 @@ RString ActorUtil::GetWhere( const XNode *pNode )
return sPath; 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) ) if( !pNode->GetAttrValue(sName, sOut) )
return false; return false;
@@ -419,7 +423,7 @@ bool ActorUtil::GetAttrPath( const XNode *pNode, const RString &sName, RString &
sOut = sDir+sOut; 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 ) apActorCommands ActorUtil::ParseActorCommands( const RString &sCommands, const RString &sName )
+2 -2
View File
@@ -114,10 +114,10 @@ namespace ActorUtil
Actor* MakeActor( const RString &sPath, Actor *pParentActor = NULL ); Actor* MakeActor( const RString &sPath, Actor *pParentActor = NULL );
RString GetSourcePath( const XNode *pNode ); RString GetSourcePath( const XNode *pNode );
RString GetWhere( 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 LoadTableFromStackShowErrors( Lua *L );
bool ResolvePath( RString &sPath, const RString &sName ); bool ResolvePath( RString &sPath, const RString &sName, bool optional= false );
void SortByZPosition( vector<Actor*> &vActors ); void SortByZPosition( vector<Actor*> &vActors );
+23 -25
View File
@@ -115,39 +115,37 @@ BitmapText::BitmapText( const BitmapText &cpy ):
*this = cpy; *this = cpy;
} }
void BitmapText::LoadFromNode( const XNode* pNode ) void BitmapText::LoadFromNode( const XNode* node )
{ {
RString sText; RString text;
pNode->GetAttrValue( "Text", sText ); node->GetAttrValue("Text", text);
RString sAltText; RString alt_text;
pNode->GetAttrValue( "AltText", sAltText ); node->GetAttrValue("AltText", alt_text);
ThemeManager::EvaluateString( sText ); ThemeManager::EvaluateString(text);
ThemeManager::EvaluateString( sAltText ); ThemeManager::EvaluateString(alt_text);
RString sFont; RString font;
// Allow the Font attribute to be either a path or simply the name of a font. // Pass optional= true so that an error will not be reported if the path
// If it's a path, it will have a slash in it. // doesn't resolve to a file. This way, a font can be either a path or the
// Also allow it to be set through either "Font" or through "File". // name of a font to look up in Fonts/. -Kyz
if(!pNode->GetAttrValue("Font", sFont) && !pNode->GetAttrValue("File", sFont)) if(!ActorUtil::GetAttrPath(node, "Font", font, true) &&
!ActorUtil::GetAttrPath(node, "File", font, true))
{ {
LuaHelpers::ReportScriptErrorFmt("%s: BitmapText: Font or File attribute not found", if(!node->GetAttrValue("Font", font) &&
ActorUtil::GetWhere(pNode).c_str()); !node->GetAttrValue("File", font)) // accept "File" for backward compatibility
sFont = "Common Normal"; {
LuaHelpers::ReportScriptErrorFmt("%s: BitmapText: Font or File attribute"
" not found", ActorUtil::GetWhere(node).c_str());
font = "Common Normal";
} }
if(sFont.find("/") == RString::npos) font = THEME->GetPathF("", font);
{
sFont= THEME->GetPathF("", sFont);
}
else if(!ActorUtil::ResolvePath(sFont, ActorUtil::GetWhere(pNode)))
{
sFont= THEME->GetPathF("", "Common Normal");
} }
LoadFromFont( sFont ); LoadFromFont(font);
SetText( sText, sAltText ); SetText(text, alt_text);
Actor::LoadFromNode( pNode ); Actor::LoadFromNode(node);
} }
bool BitmapText::LoadFromFont( const RString& sFontFilePath ) bool BitmapText::LoadFromFont( const RString& sFontFilePath )