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,
--};
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);
};
};
+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
* 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 )
+2 -2
View File
@@ -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<Actor*> &vActors );
+24 -26
View File
@@ -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 )