add choice name indirection to make it easier to add/remove options, and to give theme elements more logical names

This commit is contained in:
Chris Danford
2004-02-13 05:10:18 +00:00
parent 4f6e5be0e3
commit a0b00eae77
4 changed files with 38 additions and 23 deletions
+4 -3
View File
@@ -37,7 +37,8 @@ CurrentModeZoom=1
# Note that we don't use the "name" parameter to Choices here. Name1 is
# the displayed text, which might be translated or otherwise changed. The "name,foo"
# parameter to ModeChoices is an asset name, which is used in filenames.
NumChoices=7 // no SANDBOX
ChoiceNames=1,2,3,4,5,6,7
//,8
Choice1=screen,ScreenCaution
Name1=GAME START
Choice2=screen,ScreenSelectGame@ScreenOptionsMaster
@@ -99,7 +100,7 @@ BounceJoinMessage=1
FoldOnJoin=1
[ScreenSelectStyle]
NumChoices=5
ChoiceNames=1,2,3,4,5
# The "name" here affects the announcer, eg. "ScreenSelectStyle comment single".
Choice1=Style,single;name,single
Choice2=Style,versus;name,versus
@@ -259,7 +260,7 @@ MemoryCardIcons=0
TimerSeconds=0
[ScreenSelectDifficulty]
NumChoices=8
ChoiceNames=1,2,3,4,5,6,7,8
Choice1=PlayMode,arcade;Difficulty,beginner;name,beginner
Choice2=PlayMode,arcade;Difficulty,easy;name,easy
Choice3=PlayMode,arcade;Difficulty,medium;name,medium
+23 -10
View File
@@ -30,13 +30,13 @@
#include "arch/ArchHooks/ArchHooks.h"
#define NUM_CHOICES THEME->GetMetricI(m_sName,"NumChoices")
#define CHOICE( choice ) THEME->GetMetric (m_sName,ssprintf("Choice%d",choice+1))
#define CHOICE_NAMES THEME->GetMetric (m_sName,"ChoiceNames")
#define CHOICE( choice_name ) THEME->GetMetric (m_sName,ssprintf("Choice%s",choice_name.c_str()))
#define NUM_CODES THEME->GetMetricI(m_sName,"NumCodes")
#define CODE( choice ) THEME->GetMetric (m_sName,ssprintf("Code%d",choice+1))
#define CODE_ACTION( choice ) THEME->GetMetric (m_sName,ssprintf("Code%dAction",choice+1))
#define CODE( c ) THEME->GetMetric (m_sName,ssprintf("Code%d",c+1))
#define CODE_ACTION( c ) THEME->GetMetric (m_sName,ssprintf("Code%dAction",c+1))
#define HELP_TEXT THEME->GetMetric (m_sName,"HelpText")
#define NEXT_SCREEN( choice ) THEME->GetMetric (m_sName,ssprintf("NextScreen%d",choice+1))
#define NEXT_SCREEN( c ) THEME->GetMetric (m_sName,ssprintf("NextScreen%d",c+1))
ScreenSelect::ScreenSelect( CString sClassName ) : Screen(sClassName)
{
@@ -44,19 +44,29 @@ ScreenSelect::ScreenSelect( CString sClassName ) : Screen(sClassName)
m_sName = sClassName;
// Instead of using NUM_CHOICES, use a comma-separated list of choices. Each
// element in the list is a choice name. This level of indirection
// makes it easier to add or remove items without having to change a bunch
// of indices.
CStringArray asChoiceNames;
split( CHOICE_NAMES, ",", asChoiceNames, true );
int c;
for( c=0; c<NUM_CHOICES; c++ )
for( c=0; c<asChoiceNames.size(); c++ )
{
CString sChoice = CHOICE(c);
CString sChoiceName = asChoiceNames[c];
CString sChoice = CHOICE(sChoiceName);
ModeChoice mc;
mc.m_sName = sChoiceName;
mc.Load( c, sChoice );
m_aModeChoices.push_back( mc );
CString sBGAnimationDir = THEME->GetPathTo(BGAnimations, m_sName, mc.m_sName, true); // true="optional"
if( sBGAnimationDir == "" )
sBGAnimationDir = THEME->GetPathToB(m_sName+" background");
m_BGAnimations[c].LoadFromAniDir( sBGAnimationDir );
BGAnimation *pBGA = new BGAnimation;
m_vpBGAnimations.push_back( pBGA );
}
m_Menu.Load( sClassName );
@@ -80,6 +90,9 @@ ScreenSelect::ScreenSelect( CString sClassName ) : Screen(sClassName)
ScreenSelect::~ScreenSelect()
{
LOG->Trace( "ScreenSelect::~ScreenSelect()" );
for( int i=0; i<m_vpBGAnimations.size(); i++ )
SAFE_DELETE( m_vpBGAnimations[i] );
m_vpBGAnimations.clear();
}
void ScreenSelect::Update( float fDelta )
@@ -98,7 +111,7 @@ void ScreenSelect::Update( float fDelta )
if( GAMESTATE->m_MasterPlayerNumber != PLAYER_INVALID )
{
int iSelection = this->GetSelectionIndex(GAMESTATE->m_MasterPlayerNumber);
m_BGAnimations[iSelection].Update( fDelta );
m_vpBGAnimations[iSelection]->Update( fDelta );
}
}
@@ -109,7 +122,7 @@ void ScreenSelect::DrawPrimitives()
if( GAMESTATE->m_MasterPlayerNumber != PLAYER_INVALID )
{
int iSelection = this->GetSelectionIndex(GAMESTATE->m_MasterPlayerNumber);
m_BGAnimations[iSelection].Draw();
m_vpBGAnimations[iSelection]->Draw();
}
m_Menu.DrawBottomLayer();
Screen::DrawPrimitives();
+1 -1
View File
@@ -42,7 +42,7 @@ protected:
void FinalizeChoices();
MenuElements m_Menu;
BGAnimation m_BGAnimations[MAX_CHOICES];
vector<BGAnimation*> m_vpBGAnimations;
vector<ModeChoice> m_aModeChoices; // derived classes should look here for what choices are available
vector<CodeItem> m_aCodes;
+10 -9
View File
@@ -101,9 +101,9 @@ ScreenSelectMaster::ScreenSelectMaster( CString sClassName ) : ScreenSelect( sCl
for( unsigned c=0; c<m_aModeChoices.size(); c++ )
{
// const ModeChoice& mc = m_aModeChoices[c];
const ModeChoice& mc = m_aModeChoices[c];
CString sFName = ssprintf("%s Scroll Choice%d", m_sName.c_str(),c+1);
CString sFName = ssprintf("%s Scroll Choice%s", m_sName.c_str(),mc.m_sName.c_str());
m_sprScroll[c][0].Load( THEME->GetPathToG(sFName) );
m_sprScroll[c][0]->SetName( ssprintf("Scroll") );
m_Scroller[0].AddChild( m_sprScroll[c][0] );
@@ -128,9 +128,9 @@ ScreenSelectMaster::ScreenSelectMaster( CString sClassName ) : ScreenSelect( sCl
for( unsigned c=0; c<m_aModeChoices.size(); c++ )
{
// const ModeChoice& mc = m_aModeChoices[c];
const ModeChoice& mc = m_aModeChoices[c];
CString sFName = ssprintf("%s Scroll Choice%d P%d", m_sName.c_str(),c+1,p+1);
CString sFName = ssprintf("%s Scroll Choice%s P%s", m_sName.c_str(),mc.m_sName.c_str(),p+1);
m_sprScroll[c][p].Load( THEME->GetPathToG(sFName) );
m_sprScroll[c][p]->SetName( ssprintf("ScrollP%d",p+1) );
m_Scroller[p].AddChild( m_sprScroll[c][p] );
@@ -141,12 +141,12 @@ ScreenSelectMaster::ScreenSelectMaster( CString sClassName ) : ScreenSelect( sCl
for( unsigned c=0; c<m_aModeChoices.size(); c++ )
{
// const ModeChoice& mc = m_aModeChoices[c];
const ModeChoice& mc = m_aModeChoices[c];
// init icon
for( i=0; i<NUM_ICON_PARTS; i++ )
{
CString sFName = ssprintf("%s Icon Part%d Choice%d", m_sName.c_str(),i+1,c+1);
CString sFName = ssprintf("%s Icon Part%d Choice%s", m_sName.c_str(),i+1,mc.m_sName.c_str());
m_sprIcon[i][c].Load( THEME->GetPathToG(sFName) );
m_sprIcon[i][c]->SetName( ssprintf("IconPart%dChoice%d",i+1,c+1) );
this->AddChild( m_sprIcon[i][c] );
@@ -157,7 +157,7 @@ ScreenSelectMaster::ScreenSelectMaster( CString sClassName ) : ScreenSelect( sCl
{
for( i=0; i<NUM_PREVIEW_PARTS; i++ )
{
CString sFName = ssprintf("%s Preview Part%d Choice%d", m_sName.c_str(),i+1,c+1);
CString sFName = ssprintf("%s Preview Part%d Choice%s", m_sName.c_str(),i+1,mc.m_sName.c_str());
m_sprPreview[i][c][0].Load( THEME->GetPathToG(sFName) );
m_sprPreview[i][c][0]->SetName( ssprintf("PreviewPart%d",i+1) );
this->AddChild( m_sprPreview[i][c][0] );
@@ -171,7 +171,7 @@ ScreenSelectMaster::ScreenSelectMaster( CString sClassName ) : ScreenSelect( sCl
continue; // skip
for( i=0; i<NUM_PREVIEW_PARTS; i++ )
{
CString sFName = ssprintf("%s Preview Part%d Choice%d P%d", m_sName.c_str(),i+1,c+1,p+1);
CString sFName = ssprintf("%s Preview Part%d Choice%s P%d", m_sName.c_str(),i+1,mc.m_sName.c_str(),p+1);
m_sprPreview[i][c][p].Load( THEME->GetPathToG(sFName) );
m_sprPreview[i][c][p]->SetName( ssprintf("PreviewPart%dP%d",i+1,p+1) );
this->AddChild( m_sprPreview[i][c][p] );
@@ -575,7 +575,8 @@ void ScreenSelectMaster::MenuStart( PlayerNumber pn )
if( m_bChosen[pn] == true )
return;
SOUND->PlayOnceFromDir( ANNOUNCER->GetPathTo(ssprintf("%s comment %s",m_sName.c_str(), m_aModeChoices[m_iChoice[pn]].m_sName.c_str())) );
ModeChoice &mc = m_aModeChoices[m_iChoice[pn]];
SOUND->PlayOnceFromDir( ANNOUNCER->GetPathTo(ssprintf("%s comment %s",m_sName.c_str(), mc.m_sName.c_str())) );
m_soundSelect.Play();
float fSecs = 0;