remove decorative header from icon row, load separate graphics for each icon type instead of multi-frame sprites

This commit is contained in:
Chris Danford
2008-02-15 09:58:51 +00:00
parent 9385e0bf5d
commit 1e5371285a
5 changed files with 57 additions and 39 deletions
+16 -10
View File
@@ -19,19 +19,23 @@ OptionIcon::OptionIcon()
OptionIcon::OptionIcon( const OptionIcon &cpy ):
ActorFrame(cpy),
m_text(cpy.m_text),
m_spr(cpy.m_spr)
m_sprFilled(cpy.m_sprFilled),
m_sprEmpty(cpy.m_sprEmpty),
m_text(cpy.m_text)
{
this->RemoveAllChildren();
this->AddChild( &m_spr );
this->AddChild( m_sprFilled );
this->AddChild( m_sprEmpty );
this->AddChild( &m_text );
}
void OptionIcon::Load( RString sType )
{
m_spr.Load( THEME->GetPathG(sType,"icon 3x2") );
m_spr.StopAnimating();
this->AddChild( &m_spr );
m_sprFilled.Load( THEME->GetPathG(sType,"icon filled") );
this->AddChild( m_sprFilled );
m_sprEmpty.Load( THEME->GetPathG(sType,"icon empty") );
this->AddChild( m_sprEmpty );
m_text.LoadFromFont( THEME->GetPathF(sType,"icon") );
m_text.SetShadowLength( 0 );
@@ -41,9 +45,11 @@ void OptionIcon::Load( RString sType )
((Actor&)m_text).SetHorizAlign( (HorizAlign)TEXT_H_ALIGN );
((Actor&)m_text).SetVertAlign( (VertAlign)TEXT_V_ALIGN );
this->AddChild( &m_text );
Set("");
}
void OptionIcon::Set( PlayerNumber pn, const RString &_sText, bool bHeader )
void OptionIcon::Set( const RString &_sText )
{
RString sText = _sText;
@@ -65,10 +71,10 @@ void OptionIcon::Set( PlayerNumber pn, const RString &_sText, bool bHeader )
sText.Replace( " ", "\n" );
bool bVacant = (sText=="");
int iState = pn*3 + (bHeader?0:(bVacant?1:2));
m_spr.SetState( iState );
m_sprFilled->SetVisible( !bVacant );
m_sprEmpty->SetVisible( bVacant );
m_text.SetText( bHeader ? RString("") : sText );
m_text.SetText( sText );
m_text.SetZoom( TEXT_ZOOM );
m_text.CropToWidth( TEXT_WIDTH );
}
+4 -3
View File
@@ -4,7 +4,7 @@
#define OPTION_ICON_H
#include "ActorFrame.h"
#include "Sprite.h"
#include "AutoActor.h"
#include "BitmapText.h"
#include "PlayerNumber.h"
@@ -15,11 +15,12 @@ public:
OptionIcon();
OptionIcon( const OptionIcon &cpy );
void Load( RString sType );
void Set( PlayerNumber pn, const RString &sText, bool bHeader = false );
void Set( const RString &sText );
protected:
BitmapText m_text;
Sprite m_spr;
AutoActor m_sprFilled;
AutoActor m_sprEmpty;
};
#endif
+34 -21
View File
@@ -8,22 +8,35 @@
#include "ActorUtil.h"
#include "XmlFile.h"
#include "LuaManager.h"
#include "Foreach.h"
REGISTER_ACTOR_CLASS( OptionIconRow )
#define SPACING_X THEME->GetMetricF("OptionIconRow","SpacingX")
#define SPACING_Y THEME->GetMetricF("OptionIconRow","SpacingY")
#define SPACING_X THEME->GetMetricF("OptionIconRow","SpacingX")
#define SPACING_Y THEME->GetMetricF("OptionIconRow","SpacingY")
#define NUM_OPTION_ICONS THEME->GetMetricF("OptionIconRow","NumOptionIcons")
OptionIconRow::OptionIconRow()
{
for( unsigned i=0; i<NUM_OPTION_COLS; i++ )
for( unsigned i=0; i<NUM_OPTION_ICONS; i++ )
{
m_OptionIcon[i].SetXY( i*SPACING_X, i*SPACING_Y );
this->AddChild( &m_OptionIcon[i] );
OptionIcon *p = new OptionIcon;
p->SetXY( i*SPACING_X, i*SPACING_Y );
m_vpOptionIcon.push_back( p );
this->AddChild( p );
}
}
OptionIconRow::~OptionIconRow()
{
FOREACH( OptionIcon*, m_vpOptionIcon, p )
{
SAFE_DELETE( *p );
}
this->RemoveAllChildren();
}
void OptionIconRow::LoadFromNode( const XNode* pNode )
{
Load();
@@ -95,8 +108,8 @@ int OptionToPreferredColumn( RString sOptionText )
void OptionIconRow::Load()
{
for( unsigned i=0; i<NUM_OPTION_COLS; i++ )
m_OptionIcon[i].Load( "OptionIconRow" );
FOREACH( OptionIcon*, m_vpOptionIcon, p )
(*p)->Load( "OptionIconRow" );
}
void OptionIconRow::SetFromGameState( PlayerNumber pn )
@@ -104,39 +117,39 @@ void OptionIconRow::SetFromGameState( PlayerNumber pn )
// init
RString sOptions = GAMESTATE->m_pPlayerState[pn]->m_PlayerOptions.GetStage().GetString();
vector<RString> asOptions;
split( sOptions, ", ", asOptions, true );
vector<RString> vsOptions;
split( sOptions, ", ", vsOptions, true );
RString asTabs[NUM_OPTION_COLS-1]; // fill these with what will be displayed on the tabs
vector<RString> vsText; // fill these with what will be displayed on the tabs
vsText.resize( m_vpOptionIcon.size() );
// for each option, look for the best column to place it in
for( unsigned i=0; i<asOptions.size(); i++ )
for( unsigned i=0; i<vsOptions.size(); i++ )
{
RString sOption = asOptions[i];
RString sOption = vsOptions[i];
int iPerferredCol = OptionToPreferredColumn( sOption );
clamp( iPerferredCol, 0, (int)m_vpOptionIcon.size()-1 );
if( iPerferredCol == -1 )
continue; // skip
// search for a vacant spot
for( unsigned i=iPerferredCol; i<NUM_OPTION_COLS-1; i++ )
for( unsigned i=iPerferredCol; i<NUM_OPTION_ICONS; i++ )
{
if( asTabs[i] != "" )
if( vsText[i] != "" )
{
continue;
}
else
{
asTabs[i] = sOption;
vsText[i] = sOption;
break;
}
}
}
for( unsigned i=0; i<NUM_OPTION_COLS; i++ )
if( i == 0 )
m_OptionIcon[i].Set( pn, "", true );
else
m_OptionIcon[i].Set( pn, asTabs[i-1], false );
for( unsigned i=0; i<vsOptions.size(); i++ )
m_vpOptionIcon[i]->Set( vsText[i] );
}
// lua start
+2 -4
View File
@@ -9,13 +9,11 @@
class PlayerOptions;
struct lua_State;
const unsigned NUM_OPTION_COLS = 8;
class OptionIconRow : public ActorFrame
{
public:
OptionIconRow();
~OptionIconRow();
void Load();
virtual void LoadFromNode( const XNode* pNode );
@@ -28,7 +26,7 @@ public:
virtual void PushSelf( lua_State *L );
protected:
OptionIcon m_OptionIcon[NUM_OPTION_COLS];
vector<OptionIcon*> m_vpOptionIcon;
};
#endif
+1 -1
View File
@@ -667,7 +667,7 @@ void OptionRow::SetOptionIcon( PlayerNumber pn, const RString &sText, GameComman
msg.SetParam( "GameCommand", &gc );
m_sprBullet->HandleMessage( msg );
if( m_OptionIcons[pn] != NULL )
m_OptionIcons[pn]->Set( pn, sText, false );
m_OptionIcons[pn]->Set( sText );
}
const BitmapText &OptionRow::GetTextItemForRow( PlayerNumber pn, int iChoiceOnRow ) const