Files
itgmania212121/stepmania/src/ScreenOptions.cpp
T

1133 lines
31 KiB
C++
Raw Normal View History

2003-02-16 04:01:45 +00:00
#include "global.h"
2002-05-20 08:59:37 +00:00
#include "ScreenOptions.h"
#include "RageUtil.h"
#include "ScreenManager.h"
#include "PrefsManager.h"
#include "GameConstantsAndTypes.h"
#include "RageLog.h"
#include "GameState.h"
#include "ThemeManager.h"
#include "InputMapper.h"
2003-12-18 00:17:04 +00:00
#include "ActorUtil.h"
2003-12-18 22:51:43 +00:00
#include "ProfileManager.h"
2003-12-31 08:45:05 +00:00
#include "song.h"
2004-03-04 04:37:44 +00:00
#include "Course.h"
2004-06-28 07:26:00 +00:00
#include "Style.h"
#include "ScreenDimensions.h"
2005-01-26 11:21:43 +00:00
#include "Command.h"
#include "CommonMetrics.h"
2002-05-20 08:59:37 +00:00
/*
* These navigation types are provided:
*
2004-08-12 23:03:01 +00:00
* All modes:
* left, right -> change option
* up, down -> change row
2004-08-12 23:03:01 +00:00
* (in toggle modes, focus on nearest item to old focus)
*
* NAV_THREE_KEY:
* start -> move to next row
* left+right+start -> move to prev row
* (next screen via "exit" entry)
* This is the minimal navigation, for using menus with only three buttons.
*
* NAV_FIVE_KEY:
* start -> next screen
* This is a much more convenient navigation, requiring five keys.
*
* NAV_TOGGLE_THREE_KEY:
2004-08-12 23:03:01 +00:00
* start -> on first choice, move to next row; otherewise toggle option and move to first choice
* left+right+start -> move to prev row
*
* NAV_TOGGLE_FIVE_KEY:
* start -> toggle option
*
* Regular modes and toggle modes must be enabled by the theme. We could simply
* automatically switch to toggle mode for multiselect rows, but that would be strange
* for non-multiselect rows (eg. scroll speed).
*
2004-08-12 23:03:01 +00:00
* THREE_KEY modes are navigatable with only MenuLeft, MenuRight and MenuStart, and
* are used when PREFSMAN->m_bArcadeOptionsNavigation is enabled. However, they can
* still use MenuUp and MenuDown for nonessential behavior.
*
* NAV_THREE_KEY_MENU:
* left, right -> change row
* up, down -> change row
* start -> next screen
* This is a specialized navigation for ScreenOptionsMenu. It must be enabled to
* allow screens that use rows to select other screens to work with only three
* buttons. (It's also used when in five-key mode.)
2004-01-14 04:59:07 +00:00
*
2004-08-12 20:49:03 +00:00
* We don't want to simply allow left/right to move up and down on single-entry
* rows when in NAV_THREE_KEY, becasue left and right shouldn't exit the "exit" row
* in player options menus, but it should in the options menu.
*/
2005-02-14 01:34:49 +00:00
const float TWEEN_SECONDS = 0.3f;
2005-03-13 18:15:42 +00:00
static CString ROW_Y_NAME( size_t r ) { return ssprintf("Row%dY",r+1); }
static CString EXPLANATION_X_NAME( size_t p ) { return ssprintf("ExplanationP%dX",p+1); }
static CString EXPLANATION_Y_NAME( size_t p ) { return ssprintf("ExplanationP%dY",p+1); }
static CString EXPLANATION_ON_COMMAND_NAME( size_t p ) { return ssprintf("ExplanationP%dOnCommand",p+1); }
2005-02-09 08:10:50 +00:00
//REGISTER_SCREEN_CLASS( ScreenOptions ); // can't be instantiated
2005-02-09 08:10:50 +00:00
ScreenOptions::ScreenOptions( CString sClassName ) : ScreenWithMenuElements(sClassName),
2005-02-13 07:10:35 +00:00
NUM_ROWS_SHOWN (m_sName,"NumRowsShown"),
ROW_Y (m_sName,ROW_Y_NAME,NUM_ROWS_SHOWN),
2005-02-14 01:16:08 +00:00
ROW_Y_OFF_SCREEN_TOP (m_sName,"RowYOffScreenTop"),
ROW_Y_OFF_SCREEN_CENTER (m_sName,"RowYOffScreenCenter"),
ROW_Y_OFF_SCREEN_BOTTOM (m_sName,"RowYOffScreenBottom"),
2005-02-09 08:10:50 +00:00
EXPLANATION_X (m_sName,EXPLANATION_X_NAME,NUM_PLAYERS),
EXPLANATION_Y (m_sName,EXPLANATION_Y_NAME,NUM_PLAYERS),
EXPLANATION_ON_COMMAND (m_sName,EXPLANATION_ON_COMMAND_NAME,NUM_PLAYERS),
EXPLANATION_TOGETHER_X (m_sName,"ExplanationTogetherX"),
EXPLANATION_TOGETHER_Y (m_sName,"ExplanationTogetherY"),
EXPLANATION_TOGETHER_ON_COMMAND (m_sName,"ExplanationTogetherOnCommand"),
SHOW_SCROLL_BAR (m_sName,"ShowScrollBar"),
SCROLL_BAR_HEIGHT (m_sName,"ScrollBarHeight"),
SCROLL_BAR_TIME (m_sName,"ScrollBarTime"),
EXPLANATION_ZOOM (m_sName,"ExplanationZoom"),
SHOW_BPM_IN_SPEED_TITLE (m_sName,"ShowBpmInSpeedTitle"),
FRAME_ON_COMMAND (m_sName,"FrameOnCommand"),
FRAME_OFF_COMMAND (m_sName,"FrameOffCommand"),
2005-02-26 21:35:27 +00:00
SHOW_EXIT_ROW (m_sName,"ShowExitRow"),
2005-02-09 08:10:50 +00:00
SEPARATE_EXIT_ROW (m_sName,"SeparateExitRow"),
SEPARATE_EXIT_ROW_Y (m_sName,"SeparateExitRowY"),
OPTION_ROW_TYPE (m_sName,"OptionRowType")
2002-05-20 08:59:37 +00:00
{
LOG->Trace( "ScreenOptions::ScreenOptions()" );
}
2002-05-20 08:59:37 +00:00
2005-02-02 08:31:15 +00:00
void ScreenOptions::Init()
{
ScreenWithMenuElements::Init();
m_OptionsNavigation = PREFSMAN->m_bArcadeOptionsNavigation? NAV_THREE_KEY:NAV_FIVE_KEY;
2004-01-09 04:43:27 +00:00
2005-02-09 08:10:50 +00:00
m_SoundChangeCol.Load( THEME->GetPathS(m_sName,"change"), true );
m_SoundNextRow.Load( THEME->GetPathS(m_sName,"next"), true );
m_SoundPrevRow.Load( THEME->GetPathS(m_sName,"prev"), true );
m_SoundToggleOn.Load( THEME->GetPathS(m_sName,"toggle on") );
m_SoundToggleOff.Load( THEME->GetPathS(m_sName,"toggle off") );
2002-05-20 08:59:37 +00:00
// add everything to m_framePage so we can animate everything at once
this->AddChild( &m_framePage );
2004-01-10 03:36:14 +00:00
m_bMoreShown = false;
FOREACH_PlayerNumber( p )
2002-05-20 08:59:37 +00:00
{
m_iCurrentRow[p] = 0;
m_iFocusX[p] = 0;
2004-01-10 03:36:14 +00:00
m_bWasOnExit[p] = false;
m_bGotAtLeastOneStartPressed[p] = false;
2002-05-20 08:59:37 +00:00
}
2004-12-03 05:19:46 +00:00
m_framePage.RunCommands( FRAME_ON_COMMAND );
2004-01-09 04:14:13 +00:00
}
2004-01-09 04:14:13 +00:00
void ScreenOptions::LoadOptionIcon( PlayerNumber pn, int iRow, CString sText )
{
m_Rows[iRow]->LoadOptionIcon( pn, sText );
2002-05-20 08:59:37 +00:00
}
2005-02-25 19:36:58 +00:00
void ScreenOptions::InitMenu( InputMode im, const vector<OptionRowDefinition> &vDefs, const vector<OptionRowHandler*> &vHands )
2002-05-20 08:59:37 +00:00
{
LOG->Trace( "ScreenOptions::Set()" );
2002-05-20 08:59:37 +00:00
ASSERT( vDefs.size() == vHands.size() );
2002-05-20 08:59:37 +00:00
m_InputMode = im;
for( unsigned r=0; r<vDefs.size(); r++ ) // foreach row
2004-01-10 04:35:30 +00:00
{
2005-02-11 07:50:26 +00:00
m_Rows.push_back( new OptionRow() );
OptionRow &row = *m_Rows.back();
2005-02-25 05:45:16 +00:00
bool bFirstRowGoesDown = m_OptionsNavigation==NAV_TOGGLE_THREE_KEY;
row.LoadMetrics( OPTION_ROW_TYPE );
2005-02-25 05:45:16 +00:00
row.LoadNormal( vDefs[r], vHands[r], bFirstRowGoesDown );
FOREACH_HumanPlayer( p )
this->ImportOptions( r, p );
CHECKPOINT_M( ssprintf("row %i: %s", r, row.GetRowDef().name.c_str()) );
unsigned pos = r;
CLAMP( pos, 0, NUM_ROWS_SHOWN-1 );
const float fY = ROW_Y.GetValue( pos );
row.AfterImportOptions(
GetExplanationTitle( r ),
fY
);
}
2005-02-06 03:32:53 +00:00
m_sprPage.Load( THEME->GetPathG(m_sName,"page") );
2003-12-19 22:10:06 +00:00
m_sprPage->SetName( "Page" );
2005-01-08 12:44:03 +00:00
SET_XY_AND_ON_COMMAND( m_sprPage );
2003-12-19 22:10:06 +00:00
m_framePage.AddChild( m_sprPage );
2004-01-18 04:45:10 +00:00
// init line highlights
FOREACH_HumanPlayer( p )
{
2005-02-09 08:10:50 +00:00
m_sprLineHighlight[p].Load( THEME->GetPathG(m_sName,"line highlight") );
2004-06-26 20:00:37 +00:00
m_sprLineHighlight[p].SetName( "LineHighlight" );
2004-11-05 06:35:10 +00:00
m_sprLineHighlight[p].SetX( SCREEN_CENTER_X );
2004-06-26 20:00:37 +00:00
m_framePage.AddChild( &m_sprLineHighlight[p] );
2005-01-08 12:44:03 +00:00
ON_COMMAND( m_sprLineHighlight[p] );
2004-01-18 04:45:10 +00:00
}
// init highlights
FOREACH_HumanPlayer( p )
2004-01-18 04:45:10 +00:00
{
2005-01-31 03:18:46 +00:00
m_Highlight[p].Load( p, false );
2004-06-26 20:00:37 +00:00
m_framePage.AddChild( &m_Highlight[p] );
}
2005-02-11 07:50:26 +00:00
for( unsigned r=0; r<m_Rows.size(); r++ ) // foreach row
{
2005-02-11 07:50:26 +00:00
OptionRow &row = *m_Rows[r];
m_framePage.AddChild( &row );
}
2005-02-26 21:35:27 +00:00
if( SHOW_EXIT_ROW )
2005-02-26 11:19:19 +00:00
{
2005-02-26 21:35:27 +00:00
// TRICKY: Add "EXIT" item
2005-02-26 11:19:19 +00:00
m_Rows.push_back( new OptionRow() );
OptionRow &row = *m_Rows.back();
row.LoadMetrics( OPTION_ROW_TYPE );
row.LoadExit();
m_framePage.AddChild( &row );
}
// add explanation here so it appears on top
2004-12-11 09:14:52 +00:00
FOREACH_PlayerNumber( p )
2003-11-07 05:17:41 +00:00
{
2005-02-09 08:10:50 +00:00
m_textExplanation[p].LoadFromFont( THEME->GetPathF(m_sName,"explanation") );
2004-12-11 09:14:52 +00:00
m_textExplanation[p].SetZoom( EXPLANATION_ZOOM );
m_textExplanation[p].SetShadowLength( 0 );
m_framePage.AddChild( &m_textExplanation[p] );
2003-11-07 05:17:41 +00:00
}
2003-12-18 00:17:04 +00:00
if( SHOW_SCROLL_BAR )
{
m_ScrollBar.SetName( "DualScrollBar", "ScrollBar" );
m_ScrollBar.SetBarHeight( SCROLL_BAR_HEIGHT );
m_ScrollBar.SetBarTime( SCROLL_BAR_TIME );
FOREACH_PlayerNumber( p )
2005-01-31 03:18:46 +00:00
m_ScrollBar.EnablePlayer( p, GAMESTATE->IsHumanPlayer(p) );
2003-12-18 00:17:04 +00:00
m_ScrollBar.Load();
2005-01-08 12:44:03 +00:00
SET_XY( m_ScrollBar );
2003-12-18 00:17:04 +00:00
m_framePage.AddChild( &m_ScrollBar );
}
2005-02-09 08:10:50 +00:00
m_sprMore.Load( THEME->GetPathG( m_sName,"more") );
m_sprMore->SetName( m_sName, "More" );
2005-01-08 12:44:03 +00:00
SET_XY_AND_ON_COMMAND( m_sprMore );
COMMAND( m_sprMore, m_bMoreShown? "ShowMore":"HideMore" );
2004-01-10 03:36:14 +00:00
m_framePage.AddChild( m_sprMore );
switch( m_InputMode )
{
case INPUTMODE_INDIVIDUAL:
{
FOREACH_PlayerNumber( p )
2005-02-09 08:10:50 +00:00
m_textExplanation[p].SetXY( EXPLANATION_X.GetValue(p), EXPLANATION_Y.GetValue(p) );
}
break;
2004-03-14 18:53:19 +00:00
case INPUTMODE_SHARE_CURSOR:
m_textExplanation[0].SetXY( EXPLANATION_TOGETHER_X, EXPLANATION_TOGETHER_Y );
break;
default:
ASSERT(0);
}
FOREACH_PlayerNumber( p )
{
2005-01-08 12:44:03 +00:00
m_sprDisqualify[p].Load( THEME->GetPathG(m_sName,"disqualify") );
2005-02-09 08:10:50 +00:00
m_sprDisqualify[p]->SetName( m_sName, ssprintf("DisqualifyP%i",p+1) );
2005-01-08 12:44:03 +00:00
SET_XY_AND_ON_COMMAND( m_sprDisqualify[p] );
m_sprDisqualify[p]->SetHidden( true ); // unhide later if handicapping options are discovered
m_framePage.AddChild( m_sprDisqualify[p] );
}
// poke once at all the explanation metrics so that we catch missing ones early
for( int r=0; r<(int)m_Rows.size(); r++ ) // foreach row
{
GetExplanationText( r );
GetExplanationTitle( r );
}
CHECKPOINT;
2003-06-16 03:29:59 +00:00
PositionItems();
2005-03-13 02:15:38 +00:00
PositionAllUnderlines();
2002-09-03 06:33:08 +00:00
PositionIcons();
2005-03-13 02:25:33 +00:00
RefreshAllIcons();
PositionCursors();
UpdateEnabledDisabled();
2005-03-13 02:25:33 +00:00
FOREACH_PlayerNumber( p )
OnChange( p );
2004-01-08 23:32:14 +00:00
CHECKPOINT;
2003-06-16 17:34:20 +00:00
/* It's tweening into position, but on the initial tween-in we only want to
* tween in the whole page at once. Since the tweens are nontrivial, it's
* easiest to queue the tweens and then force them to finish. */
for( int r=0; r<(int) m_Rows.size(); r++ ) // foreach options line
2003-06-16 17:34:20 +00:00
{
2005-02-11 07:50:26 +00:00
OptionRow &row = *m_Rows[r];
row.FinishTweening();
2003-06-16 17:34:20 +00:00
}
2004-01-12 02:48:56 +00:00
2004-01-10 03:36:14 +00:00
m_sprMore->FinishTweening();
2004-05-02 03:01:27 +00:00
this->SortByDrawOrder();
2002-05-20 08:59:37 +00:00
}
ScreenOptions::~ScreenOptions()
{
LOG->Trace( "ScreenOptions::~ScreenOptions()" );
for( unsigned i=0; i<m_Rows.size(); i++ )
2005-02-25 05:45:16 +00:00
SAFE_DELETE( m_Rows[i] );
2002-05-20 08:59:37 +00:00
}
2004-01-09 04:14:13 +00:00
CString ScreenOptions::GetExplanationText( int iRow ) const
2003-11-08 02:46:12 +00:00
{
OptionRow &row = *m_Rows[iRow];
2004-01-09 04:14:13 +00:00
CString sLineName = row.GetRowDef().name;
2005-02-26 21:35:27 +00:00
ASSERT( !sLineName.empty() );
2003-11-08 02:46:12 +00:00
sLineName.Replace("\n-","");
sLineName.Replace("\n","");
sLineName.Replace(" ","");
return THEME->GetMetric( "OptionExplanations", sLineName+"Help" );
}
2004-01-09 04:14:13 +00:00
CString ScreenOptions::GetExplanationTitle( int iRow ) const
{
OptionRow &row = *m_Rows[iRow];
2004-01-09 04:14:13 +00:00
CString sLineName = row.GetRowDef().name;
sLineName.Replace("\n-","");
sLineName.Replace("\n","");
sLineName.Replace(" ","");
2004-01-09 06:38:19 +00:00
CString sTitle = THEME->GetMetric( "OptionTitles", sLineName+"Title" );
2003-12-31 08:45:05 +00:00
// HACK: tack the BPM onto the name of the speed line
if( sLineName.CompareNoCase("speed")==0 )
{
2004-03-04 04:37:44 +00:00
if( SHOW_BPM_IN_SPEED_TITLE )
2003-12-31 08:45:05 +00:00
{
DisplayBpms bpms;
2004-03-04 04:37:44 +00:00
if( GAMESTATE->m_pCurSong )
{
Song* pSong = GAMESTATE->m_pCurSong;
pSong->GetDisplayBpms( bpms );
2004-03-04 04:37:44 +00:00
}
else if( GAMESTATE->m_pCurCourse )
{
Course *pCourse = GAMESTATE->m_pCurCourse;
2004-06-28 07:26:00 +00:00
StepsType st = GAMESTATE->GetCurrentStyle()->m_StepsType;
Trail* pTrail = pCourse->GetTrail( st );
2004-06-03 20:28:09 +00:00
ASSERT( pTrail );
pTrail->GetDisplayBpms( bpms );
2004-03-04 04:37:44 +00:00
}
2005-03-11 02:48:38 +00:00
if( (int) bpms.vfBpms.size() > MAX_COURSE_ENTRIES_BEFORE_VARIOUS )
{} // add nothing
else if( bpms.IsSecret() )
sTitle += ssprintf( " (??" "?)" ); /* split so gcc doesn't think this is a trigraph */
else if( bpms.BpmIsConstant() )
sTitle += ssprintf( " (%.0f)", bpms.GetMin() );
else
sTitle += ssprintf( " (%.0f-%.0f)", bpms.GetMin(), bpms.GetMax() );
2003-12-31 08:45:05 +00:00
}
}
return sTitle;
2003-11-08 02:46:12 +00:00
}
2002-05-20 08:59:37 +00:00
2004-01-10 06:57:05 +00:00
BitmapText &ScreenOptions::GetTextItemForRow( PlayerNumber pn, int iRow, int iChoiceOnRow )
{
2004-06-16 00:38:31 +00:00
ASSERT_M( iRow < (int)m_Rows.size(), ssprintf("%i < %i", iRow, (int)m_Rows.size() ) );
2005-02-11 07:50:26 +00:00
OptionRow &row = *m_Rows[iRow];
return row.GetTextItemForRow( pn, iChoiceOnRow );
}
2004-01-10 06:57:05 +00:00
void ScreenOptions::GetWidthXY( PlayerNumber pn, int iRow, int iChoiceOnRow, int &iWidthOut, int &iXOut, int &iYOut )
2002-05-20 08:59:37 +00:00
{
ASSERT_M( iRow < (int)m_Rows.size(), ssprintf("%i < %i", iRow, (int)m_Rows.size() ) );
OptionRow &row = *m_Rows[iRow];
row.GetWidthXY( pn, iChoiceOnRow, iWidthOut, iXOut, iYOut );
2002-05-20 08:59:37 +00:00
}
2005-03-13 02:15:38 +00:00
void ScreenOptions::PositionUnderlines( int r, PlayerNumber pn )
2002-05-20 08:59:37 +00:00
{
2005-03-13 02:15:38 +00:00
OptionRow &row = *m_Rows[r];
row.PositionUnderlines( pn );
}
2004-01-10 08:57:08 +00:00
2005-03-13 02:15:38 +00:00
void ScreenOptions::PositionAllUnderlines()
{
for( unsigned r=0; r<m_Rows.size(); r++ )
FOREACH_HumanPlayer( p )
PositionUnderlines( r, p );
2002-05-20 08:59:37 +00:00
}
2002-09-03 06:33:08 +00:00
void ScreenOptions::PositionIcons()
{
for( unsigned i=0; i<m_Rows.size(); i++ ) // foreach options line
2002-09-03 06:33:08 +00:00
{
OptionRow &row = *m_Rows[i];
2005-02-25 19:26:05 +00:00
row.PositionIcons();
2003-09-05 07:34:13 +00:00
continue;
2002-09-03 06:33:08 +00:00
}
}
2005-03-13 02:25:33 +00:00
void ScreenOptions::RefreshIcons( int row, PlayerNumber pn )
{
2005-03-13 02:25:33 +00:00
// overridden by ScreenOptionsMaster
}
2005-03-13 02:25:33 +00:00
void ScreenOptions::RefreshAllIcons()
{
FOREACH_HumanPlayer( p )
for( unsigned r=0; r<m_Rows.size(); ++r )
this->RefreshIcons( r, p );
}
2002-09-03 06:33:08 +00:00
void ScreenOptions::PositionCursors()
2002-05-20 08:59:37 +00:00
{
// Set the position of the highlight showing the current option the user is changing.
// Set the position of the underscores showing the current choice for each option line.
FOREACH_HumanPlayer( pn ) // foreach player
2002-05-20 08:59:37 +00:00
{
2004-01-13 08:35:15 +00:00
const int iRow = m_iCurrentRow[pn];
2004-06-16 00:38:31 +00:00
ASSERT_M( iRow < (int)m_Rows.size(), ssprintf("%i < %i", iRow, (int)m_Rows.size() ) );
2005-02-11 07:50:26 +00:00
OptionRow &OptionRow = *m_Rows[iRow];
2002-05-20 08:59:37 +00:00
2004-01-13 08:35:15 +00:00
OptionsCursor &highlight = m_Highlight[pn];
2002-05-20 08:59:37 +00:00
2005-02-26 11:19:19 +00:00
const int iChoiceWithFocus = OptionRow.GetChoiceInRowWithFocus(pn);
int iWidth, iX, iY;
2005-01-31 03:18:46 +00:00
GetWidthXY( pn, iRow, iChoiceWithFocus, iWidth, iX, iY );
highlight.SetBarWidth( iWidth );
highlight.SetXY( (float)iX, (float)iY );
2002-05-20 08:59:37 +00:00
}
}
2004-01-10 06:57:05 +00:00
void ScreenOptions::TweenCursor( PlayerNumber pn )
2002-05-20 08:59:37 +00:00
{
// Set the position of the highlight showing the current option the user is changing.
2004-01-13 08:35:15 +00:00
const int iRow = m_iCurrentRow[pn];
2004-06-16 00:38:31 +00:00
ASSERT_M( iRow < (int)m_Rows.size(), ssprintf("%i < %i", iRow, (int)m_Rows.size() ) );
2002-05-20 08:59:37 +00:00
const OptionRow &row = *m_Rows[iRow];
2005-02-26 11:19:19 +00:00
const int iChoiceWithFocus = row.GetChoiceInRowWithFocus(pn);
int iWidth, iX, iY;
2004-01-13 08:35:15 +00:00
GetWidthXY( pn, iRow, iChoiceWithFocus, iWidth, iX, iY );
2004-01-13 08:35:15 +00:00
OptionsCursor &highlight = m_Highlight[pn];
highlight.StopTweening();
highlight.BeginTweening( TWEEN_SECONDS );
highlight.TweenBarWidth( iWidth );
2003-04-12 06:16:12 +00:00
highlight.SetXY( (float)iX, (float)iY );
2003-12-19 22:10:06 +00:00
2004-01-10 06:57:05 +00:00
if( GAMESTATE->IsHumanPlayer(pn) )
2004-01-10 03:12:32 +00:00
{
2005-01-08 12:44:03 +00:00
COMMAND( m_sprLineHighlight[pn], "Change" );
if( row.GetRowType() == OptionRow::ROW_EXIT )
2005-01-08 12:44:03 +00:00
COMMAND( m_sprLineHighlight[pn], "ChangeToExit" );
2004-01-10 06:57:05 +00:00
m_sprLineHighlight[pn].SetY( (float)iY );
2004-01-10 03:12:32 +00:00
}
2002-05-20 08:59:37 +00:00
}
/* For "long row-style" rows, update the text on screen to contain the currently-
* focused options.
*
* This used to update a single player, but it's not always clear what that means
* when dealing with bOneChoiceForAllPlayers and disabled players, which was brittle.
* Update the whole row. */
void ScreenOptions::UpdateText( int iRow )
{
2005-02-11 07:50:26 +00:00
OptionRow &row = *m_Rows[iRow];
row.UpdateText();
}
void ScreenOptions::UpdateEnabledDisabled( int r )
{
OptionRow &row = *m_Rows[r];
bool bRowHasFocus[NUM_PLAYERS];
FOREACH_PlayerNumber( pn )
bRowHasFocus[pn] = GAMESTATE->IsHumanPlayer(pn) && m_iCurrentRow[pn] == (int)r;
2004-01-09 04:14:13 +00:00
row.SetRowFocus( bRowHasFocus );
row.UpdateEnabledDisabled();
}
2004-01-13 08:35:15 +00:00
void ScreenOptions::UpdateEnabledDisabled()
{
for( unsigned r=0; r<m_Rows.size(); r++ )
UpdateEnabledDisabled( r );
}
2002-05-20 08:59:37 +00:00
void ScreenOptions::Update( float fDeltaTime )
{
//LOG->Trace( "ScreenOptions::Update(%f)", fDeltaTime );
2002-05-20 08:59:37 +00:00
Screen::Update( fDeltaTime );
}
void ScreenOptions::DrawPrimitives()
{
Screen::DrawPrimitives();
}
2005-02-11 07:50:26 +00:00
void ScreenOptions::Input( const DeviceInput& DeviceI, const InputEventType selectType, const GameInput &GameI, const MenuInput &MenuI, const StyleInput &StyleI )
2002-05-20 08:59:37 +00:00
{
2003-03-22 19:58:44 +00:00
/* Allow input when transitioning in (m_In.IsTransitioning()), but ignore it
* when we're transitioning out. */
if( m_Back.IsTransitioning() || m_Out.IsTransitioning() )
2002-05-20 08:59:37 +00:00
return;
2005-02-11 07:50:26 +00:00
if( selectType == IET_RELEASE )
{
switch( MenuI.button )
{
case MENU_BUTTON_START:
case MENU_BUTTON_RIGHT:
case MENU_BUTTON_LEFT:
INPUTMAPPER->ResetKeyRepeat( MenuInput(MenuI.player, MENU_BUTTON_START) );
INPUTMAPPER->ResetKeyRepeat( MenuInput(MenuI.player, MENU_BUTTON_RIGHT) );
INPUTMAPPER->ResetKeyRepeat( MenuInput(MenuI.player, MENU_BUTTON_LEFT) );
}
}
2002-05-20 08:59:37 +00:00
// default input handler
2005-02-11 07:50:26 +00:00
Screen::Input( DeviceI, selectType, GameI, MenuI, StyleI );
2002-05-20 08:59:37 +00:00
}
void ScreenOptions::HandleScreenMessage( const ScreenMessage SM )
{
switch( SM )
{
2002-07-02 00:27:58 +00:00
case SM_MenuTimer:
2005-02-26 21:35:27 +00:00
this->BeginFadingOut();
2002-07-02 00:27:58 +00:00
break;
case SM_GoToPrevScreen:
2003-03-09 00:55:49 +00:00
// this->ExportOptions(); // Don't save options if we're going back!
2004-12-05 11:59:39 +00:00
this->GoToPrevScreen();
2002-05-20 08:59:37 +00:00
break;
case SM_GoToNextScreen:
for( unsigned r=0; r<m_Rows.size(); r++ ) // foreach row
FOREACH_HumanPlayer( p )
this->ExportOptions( r, p );
2004-12-05 11:59:39 +00:00
this->GoToNextScreen();
2002-05-20 08:59:37 +00:00
break;
2003-03-11 08:52:45 +00:00
case SM_BeginFadingOut:
if(IsTransitioning())
2003-03-30 21:42:10 +00:00
return; /* already transitioning */
StartTransitioning( SM_GoToNextScreen );
SCREENMAN->PlayStartSound();
2004-12-03 05:19:46 +00:00
m_framePage.RunCommands( FRAME_OFF_COMMAND );
break;
2003-11-25 22:03:01 +00:00
case SM_GainFocus:
INPUTFILTER->SetRepeatRate( 0.25f, 12, 0.25f, 12 );
break;
case SM_LoseFocus:
INPUTFILTER->ResetRepeatRate();
break;
2002-05-20 08:59:37 +00:00
}
}
2003-06-16 03:29:59 +00:00
void ScreenOptions::PositionItems()
{
2005-02-13 07:10:35 +00:00
const int total = NUM_ROWS_SHOWN;
2003-07-20 22:21:00 +00:00
const int halfsize = total / 2;
2003-06-18 04:11:33 +00:00
int first_start, first_end, second_start, second_end;
2003-06-16 03:42:48 +00:00
/* Choices for each player. If only one player is active, it's the same for both. */
2004-01-10 00:45:01 +00:00
int P1Choice = GAMESTATE->IsHumanPlayer(PLAYER_1)? m_iCurrentRow[PLAYER_1]: m_iCurrentRow[PLAYER_2];
int P2Choice = GAMESTATE->IsHumanPlayer(PLAYER_2)? m_iCurrentRow[PLAYER_2]: m_iCurrentRow[PLAYER_1];
2005-02-11 07:50:26 +00:00
vector<OptionRow*> Rows( m_Rows );
OptionRow *ExitRow = NULL;
2004-01-10 00:45:01 +00:00
if( (bool)SEPARATE_EXIT_ROW && Rows.back()->GetRowType() == OptionRow::ROW_EXIT )
2004-01-10 00:45:01 +00:00
{
ExitRow = &*Rows.back();
/* Remove the exit row for purposes of positioning everything else. */
if( P1Choice == (int) Rows.size()-1 )
--P1Choice;
if( P2Choice == (int) Rows.size()-1 )
--P2Choice;
Rows.erase( Rows.begin()+Rows.size()-1, Rows.end() );
}
2003-06-16 03:29:59 +00:00
2003-06-18 04:11:33 +00:00
const bool BothPlayersActivated = GAMESTATE->IsHumanPlayer(PLAYER_1) && GAMESTATE->IsHumanPlayer(PLAYER_2);
2004-03-14 18:53:19 +00:00
if( m_InputMode == INPUTMODE_SHARE_CURSOR || !BothPlayersActivated )
2003-06-18 04:11:33 +00:00
{
/* Simply center the cursor. */
first_start = max( P1Choice - halfsize, 0 );
first_end = first_start + total;
second_start = second_end = first_end;
} else {
/* First half: */
const int earliest = min( P1Choice, P2Choice );
first_start = max( earliest - halfsize/2, 0 );
first_end = first_start + halfsize;
/* Second half: */
const int latest = max( P1Choice, P2Choice );
2003-06-16 03:29:59 +00:00
2003-06-18 04:11:33 +00:00
second_start = max( latest - halfsize/2, 0 );
2003-06-16 03:29:59 +00:00
2003-06-18 04:11:33 +00:00
/* Don't overlap. */
second_start = max( second_start, first_end );
2003-06-16 03:29:59 +00:00
2003-06-18 04:11:33 +00:00
second_end = second_start + halfsize;
2003-06-16 03:29:59 +00:00
}
2004-01-10 00:45:01 +00:00
first_end = min( first_end, (int) Rows.size() );
second_end = min( second_end, (int) Rows.size() );
2003-06-18 04:11:33 +00:00
2004-01-10 00:45:01 +00:00
/* If less than total (and Rows.size()) are displayed, fill in the empty
2003-06-18 04:11:33 +00:00
* space intelligently. */
while(1)
{
const int sum = (first_end - first_start) + (second_end - second_start);
2004-01-10 00:45:01 +00:00
if( sum >= (int) Rows.size() || sum >= total)
2003-06-18 04:11:33 +00:00
break; /* nothing more to display, or no room */
/* First priority: expand the top of the second half until it meets
* the first half. */
if( second_start > first_end )
second_start--;
/* Otherwise, expand either end. */
else if( first_start > 0 )
first_start--;
2004-01-10 00:45:01 +00:00
else if( second_end < (int) Rows.size() )
2003-06-18 04:11:33 +00:00
second_end++;
else
ASSERT(0); /* do we have room to grow or don't we? */
}
2003-06-16 03:29:59 +00:00
2003-06-18 04:11:33 +00:00
int pos = 0;
2004-01-10 00:45:01 +00:00
for( int i=0; i<(int) Rows.size(); i++ ) // foreach row
2003-06-16 03:29:59 +00:00
{
2005-02-14 01:16:08 +00:00
float fY;
2003-06-16 03:29:59 +00:00
if( i < first_start )
2005-02-14 01:16:08 +00:00
fY = ROW_Y_OFF_SCREEN_TOP;
2003-06-18 04:11:33 +00:00
else if( i < first_end )
2005-02-14 01:16:08 +00:00
fY = ROW_Y.GetValue( pos++ );
2003-06-16 03:29:59 +00:00
else if( i < second_start )
2005-02-14 01:16:08 +00:00
fY = ROW_Y_OFF_SCREEN_CENTER;
2003-06-18 04:11:33 +00:00
else if( i < second_end )
2005-02-14 01:16:08 +00:00
fY = ROW_Y.GetValue( pos++ );
2003-06-16 03:29:59 +00:00
else
2005-02-14 01:16:08 +00:00
fY = ROW_Y_OFF_SCREEN_BOTTOM;
2003-06-16 03:29:59 +00:00
2005-02-11 07:50:26 +00:00
OptionRow &row = *Rows[i];
2004-01-09 04:14:13 +00:00
row.SetRowY( fY );
bool bHidden =
2005-02-14 01:34:49 +00:00
i < first_start ||
(i >= first_end && i < second_start) ||
i >= second_end;
row.SetRowHidden( bHidden );
2003-06-16 03:29:59 +00:00
}
2004-01-10 00:45:01 +00:00
if( ExitRow )
{
ExitRow->SetRowY( SEPARATE_EXIT_ROW_Y );
ExitRow->SetRowHidden( second_end != (int) Rows.size() );
2004-01-10 00:45:01 +00:00
}
2003-06-16 03:29:59 +00:00
}
2003-11-06 09:54:40 +00:00
void ScreenOptions::OnChange( PlayerNumber pn )
2002-05-20 08:59:37 +00:00
{
2003-11-06 09:54:40 +00:00
if( !GAMESTATE->IsHumanPlayer(pn) )
return;
2005-03-13 02:15:38 +00:00
const int iCurRow = m_iCurrentRow[pn];
2004-01-09 04:14:13 +00:00
/* Update m_fY and m_bHidden[]. */
2003-06-16 03:29:59 +00:00
PositionItems();
/* Do positioning. */
PositionAllUnderlines();
2005-03-13 02:25:33 +00:00
RefreshIcons( iCurRow, pn );
2003-06-16 03:29:59 +00:00
PositionIcons();
UpdateEnabledDisabled();
2003-12-18 00:17:04 +00:00
if( SHOW_SCROLL_BAR )
{
float fPercent = 0;
if( m_Rows.size() > 1 )
fPercent = m_iCurrentRow[pn] / float(m_Rows.size()-1);
m_ScrollBar.SetPercentage( pn, fPercent );
}
2003-12-18 00:17:04 +00:00
2004-01-14 22:45:04 +00:00
/* If the last row is EXIT, and is hidden, then show MORE. */
const bool ShowMore = m_Rows.back()->GetRowType() == OptionRow::ROW_EXIT && m_Rows.back()->GetHidden();
2004-01-14 22:45:04 +00:00
if( m_bMoreShown != ShowMore )
{
m_bMoreShown = ShowMore;
2005-01-08 12:44:03 +00:00
COMMAND( m_sprMore, m_bMoreShown? "ShowMore":"HideMore" );
2004-01-14 22:45:04 +00:00
}
/* Update all players, since changing one player can move both cursors. */
FOREACH_PlayerNumber( p )
2004-01-10 03:36:14 +00:00
{
2004-01-14 22:45:04 +00:00
if( GAMESTATE->IsHumanPlayer(p) )
2005-02-26 11:19:19 +00:00
TweenCursor( p );
2004-01-10 03:36:14 +00:00
int iCurrentRow = m_iCurrentRow[pn];
2005-02-26 11:19:19 +00:00
OptionRow &row = *m_Rows[iCurrentRow];
const bool ExitSelected = row.GetRowType() == OptionRow::ROW_EXIT;
2004-03-20 17:46:25 +00:00
if( p == pn || GAMESTATE->GetNumHumanPlayers() == 1 )
2004-01-10 03:36:14 +00:00
{
if( m_bWasOnExit[p] != ExitSelected )
{
m_bWasOnExit[p] = ExitSelected;
2005-01-08 12:44:03 +00:00
COMMAND( m_sprMore, ssprintf("Exit%sP%i", ExitSelected? "Selected":"Unselected", p+1) );
2004-01-10 03:36:14 +00:00
}
}
}
2004-01-09 04:14:13 +00:00
const CString text = GetExplanationText( iCurRow );
2003-11-06 09:54:40 +00:00
BitmapText *pText = NULL;
switch( m_InputMode )
{
case INPUTMODE_INDIVIDUAL:
pText = &m_textExplanation[pn];
if( pText->GetText() != text )
{
pText->FinishTweening();
2005-02-09 08:10:50 +00:00
pText->RunCommands( EXPLANATION_ON_COMMAND.GetValue(pn) );
pText->SetText( text );
}
2003-11-06 09:54:40 +00:00
break;
2004-03-14 18:53:19 +00:00
case INPUTMODE_SHARE_CURSOR:
pText = &m_textExplanation[0];
if( pText->GetText() != text )
{
pText->FinishTweening();
2004-12-03 05:19:46 +00:00
pText->RunCommands( EXPLANATION_TOGETHER_ON_COMMAND );
pText->SetText( text );
}
2003-11-06 09:54:40 +00:00
break;
}
2002-05-20 08:59:37 +00:00
}
void ScreenOptions::MenuBack( PlayerNumber pn )
2002-05-20 08:59:37 +00:00
{
Screen::MenuBack( pn );
2002-05-20 08:59:37 +00:00
Back( SM_GoToPrevScreen );
2002-05-20 08:59:37 +00:00
}
2005-02-26 21:35:27 +00:00
bool ScreenOptions::IsOnLastRow( PlayerNumber pn ) const
2003-02-12 00:41:56 +00:00
{
2005-02-26 21:35:27 +00:00
int iCurRow = m_iCurrentRow[pn];
return iCurRow == (int)(m_Rows.size()-1);
2003-02-12 00:41:56 +00:00
}
2002-05-20 08:59:37 +00:00
2005-02-26 21:35:27 +00:00
bool ScreenOptions::AllAreOnLastRow() const
2004-08-12 23:03:01 +00:00
{
FOREACH_HumanPlayer( p )
2005-02-26 21:35:27 +00:00
{
if( !IsOnLastRow(p) )
2004-08-12 23:03:01 +00:00
return false;
2005-02-26 21:35:27 +00:00
}
2004-08-12 23:03:01 +00:00
return true;
}
2005-02-11 07:50:26 +00:00
void ScreenOptions::MenuStart( PlayerNumber pn, const InputEventType selectType )
2002-05-20 08:59:37 +00:00
{
2005-02-11 07:50:26 +00:00
switch( selectType )
{
case IET_FIRST_PRESS:
m_bGotAtLeastOneStartPressed[pn] = true;
break;
case IET_RELEASE:
return; // ignore
2005-02-11 07:50:26 +00:00
default: // repeat selectType
if( !m_bGotAtLeastOneStartPressed[pn] )
return; // don't allow repeat
break;
}
2004-01-10 08:57:08 +00:00
2005-02-26 21:35:27 +00:00
int iCurRow = m_iCurrentRow[pn];
OptionRow &row = *m_Rows[iCurRow];
2004-01-14 09:03:35 +00:00
2004-08-12 23:03:01 +00:00
/* If we are in a three-button mode, check to see if MENU_BUTTON_LEFT and
* MENU_BUTTON_RIGHT are being held. */
2004-01-14 09:03:35 +00:00
switch( m_OptionsNavigation )
{
case NAV_THREE_KEY:
case NAV_TOGGLE_THREE_KEY:
2004-01-14 09:03:35 +00:00
{
bool bHoldingLeftAndRight =
INPUTMAPPER->IsButtonDown( MenuInput(pn, MENU_BUTTON_RIGHT) ) &&
INPUTMAPPER->IsButtonDown( MenuInput(pn, MENU_BUTTON_LEFT) );
if( bHoldingLeftAndRight )
{
2005-02-11 07:50:26 +00:00
MoveRow( pn, -1, selectType != IET_FIRST_PRESS );
2004-01-14 09:03:35 +00:00
return;
}
}
}
// If on exit, check it all players are on "Exit"
2005-02-26 21:35:27 +00:00
if( IsOnLastRow(pn) )
2004-01-14 09:03:35 +00:00
{
/* Don't accept START to go to the next screen if we're still transitioning in. */
2005-02-26 21:35:27 +00:00
if( AllAreOnLastRow() && selectType == IET_FIRST_PRESS && !IsTransitioning() )
this->BeginFadingOut();
2004-01-14 09:03:35 +00:00
return;
}
2005-02-25 05:45:16 +00:00
if( row.GetFirstItemGoesDown() )
2004-01-14 09:03:35 +00:00
{
2005-02-26 11:19:19 +00:00
int iChoiceInRow = row.GetChoiceInRowWithFocus(pn);
2004-01-14 09:03:35 +00:00
if( iChoiceInRow == 0 )
{
2005-02-11 07:50:26 +00:00
MenuDown( pn, selectType );
2004-01-14 09:03:35 +00:00
return;
}
}
2004-01-10 08:57:08 +00:00
if( row.GetRowDef().selectType == SELECT_MULTIPLE )
2004-01-14 04:59:07 +00:00
{
2005-02-26 11:19:19 +00:00
int iChoiceInRow = row.GetChoiceInRowWithFocus(pn);
bool bSelected = !row.GetSelected( pn, iChoiceInRow );
row.SetSelected( pn, iChoiceInRow, bSelected );
2005-03-13 02:15:38 +00:00
2005-02-26 11:19:19 +00:00
if( bSelected )
2004-01-14 04:59:07 +00:00
m_SoundToggleOn.Play();
2004-01-10 21:34:18 +00:00
else
2004-01-14 04:59:07 +00:00
m_SoundToggleOff.Play();
2005-03-13 02:15:38 +00:00
PositionUnderlines( iCurRow, pn );
2005-03-13 02:25:33 +00:00
RefreshIcons( iCurRow, pn );
2004-01-14 04:59:07 +00:00
2005-02-25 05:45:16 +00:00
if( row.GetFirstItemGoesDown() )
{
// move to the first choice in the row
2005-02-26 11:19:19 +00:00
ChangeValueInRow( pn, -row.GetChoiceInRowWithFocus(pn), selectType != IET_FIRST_PRESS );
}
2004-01-10 08:57:08 +00:00
}
2005-02-11 07:50:26 +00:00
else // data.selectType != SELECT_MULTIPLE
{
2004-01-10 08:57:08 +00:00
switch( m_OptionsNavigation )
{
case NAV_THREE_KEY:
2005-02-11 07:50:26 +00:00
MenuDown( pn, selectType );
break;
case NAV_TOGGLE_THREE_KEY:
case NAV_TOGGLE_FIVE_KEY:
if( row.GetRowDef().selectType != SELECT_MULTIPLE )
{
2005-02-26 11:19:19 +00:00
int iChoiceInRow = row.GetChoiceInRowWithFocus(pn);
if( row.GetRowDef().bOneChoiceForAllPlayers )
row.SetOneSharedSelection( iChoiceInRow );
2004-01-14 04:59:07 +00:00
else
row.SetOneSelection( pn, iChoiceInRow );
}
2005-02-25 05:45:16 +00:00
if( row.GetFirstItemGoesDown() )
2005-02-26 11:19:19 +00:00
ChangeValueInRow( pn, -row.GetChoiceInRowWithFocus(pn), selectType != IET_FIRST_PRESS ); // move to the first choice
else
2005-02-11 07:50:26 +00:00
ChangeValueInRow( pn, 0, selectType != IET_FIRST_PRESS );
break;
2004-01-10 08:57:08 +00:00
case NAV_THREE_KEY_MENU:
/* Don't accept START to go to the next screen if we're still transitioning in. */
2005-02-11 07:50:26 +00:00
if( selectType == IET_FIRST_PRESS && !IsTransitioning() )
2005-02-26 21:35:27 +00:00
this->BeginFadingOut();
break;
case NAV_FIVE_KEY:
2004-08-12 23:03:01 +00:00
/* Jump to the exit row. (If everyone's already on the exit row, then
* we'll have already gone to the next screen above.) */
2005-02-11 07:50:26 +00:00
MoveRow( pn, m_Rows.size()-m_iCurrentRow[pn]-1, selectType != IET_FIRST_PRESS );
break;
2004-01-10 08:57:08 +00:00
}
}
2002-05-20 08:59:37 +00:00
}
void ScreenOptions::StoreFocus( PlayerNumber pn )
{
/* Long rows always put us in the center, so don't update the focus. */
int iCurrentRow = m_iCurrentRow[pn];
const OptionRow &row = *m_Rows[iCurrentRow];
if( row.GetRowDef().layoutType == LAYOUT_SHOW_ONE_IN_ROW )
return;
int iWidth, iY;
2005-02-26 11:19:19 +00:00
GetWidthXY( pn, m_iCurrentRow[pn], row.GetChoiceInRowWithFocus(pn), iWidth, m_iFocusX[pn], iY );
LOG->Trace("cur selection %ix%i @ %i",
m_iCurrentRow[pn], row.GetChoiceInRowWithFocus(pn), m_iFocusX[pn]);
}
2004-01-09 04:43:27 +00:00
/* Left/right */
void ScreenOptions::ChangeValueInRow( PlayerNumber pn, int iDelta, bool Repeat )
2002-05-20 08:59:37 +00:00
{
2004-01-09 04:14:13 +00:00
const int iCurRow = m_iCurrentRow[pn];
2005-02-11 07:50:26 +00:00
OptionRow &row = *m_Rows[iCurRow];
2005-02-26 21:35:27 +00:00
if( row.GetRowType() == OptionRow::ROW_EXIT ) // EXIT is selected
return; // don't allow a move
const int iNumOptions = row.GetRowDef().choices.size();
if( m_OptionsNavigation == NAV_THREE_KEY_MENU && iNumOptions <= 1 ) // 1 or 0
2003-10-17 08:03:46 +00:00
{
2004-01-09 04:43:27 +00:00
/* There are no other options on the row; move up or down instead of left and right.
2004-01-09 06:38:19 +00:00
* This allows navigating the options menu with left/right/start.
*
* XXX: Only allow repeats if the opposite key isn't pressed; otherwise, holding both
* directions will repeat in place continuously, which is weird. */
MoveRow( pn, iDelta, Repeat );
2004-01-09 04:43:27 +00:00
return;
2003-10-17 08:03:46 +00:00
}
2004-01-09 04:43:27 +00:00
if( Repeat )
return;
2003-10-17 08:03:46 +00:00
2004-01-09 04:43:27 +00:00
bool bOneChanged = false;
2002-05-20 08:59:37 +00:00
2005-02-26 11:19:19 +00:00
int iCurrentChoiceWithFocus = row.GetChoiceInRowWithFocus(pn);
2004-01-10 08:57:08 +00:00
int iNewChoiceWithFocus = iCurrentChoiceWithFocus + iDelta;
wrap( iNewChoiceWithFocus, iNumOptions );
if( iCurrentChoiceWithFocus != iNewChoiceWithFocus )
bOneChanged = true;
2004-01-09 04:43:27 +00:00
2005-02-26 11:19:19 +00:00
row.SetChoiceInRowWithFocus( pn, iNewChoiceWithFocus );
StoreFocus( pn );
if( row.GetRowDef().bOneChoiceForAllPlayers )
2004-01-10 08:57:08 +00:00
{
/* If this row is bOneChoiceForAllPlayers, then lock the cursors together
* for this row. Don't do this in toggle modes, since the current selection
* and the current focus are detached. */
bool bForceFocusedChoiceTogether = false;
if( m_OptionsNavigation!=NAV_TOGGLE_THREE_KEY &&
m_OptionsNavigation!=NAV_TOGGLE_FIVE_KEY &&
row.GetRowDef().bOneChoiceForAllPlayers )
{
bForceFocusedChoiceTogether = true;
}
/* Also lock focus if the screen is explicitly set to share cursors. */
2004-03-14 18:53:19 +00:00
if( m_InputMode == INPUTMODE_SHARE_CURSOR )
bForceFocusedChoiceTogether = true;
if( bForceFocusedChoiceTogether )
{
2004-03-14 18:51:03 +00:00
// lock focus together
FOREACH_HumanPlayer( p )
{
2005-02-26 11:19:19 +00:00
row.SetChoiceInRowWithFocus( p, iNewChoiceWithFocus );
2005-02-23 05:51:10 +00:00
StoreFocus( p );
}
2004-03-14 18:51:03 +00:00
}
2004-01-10 08:57:08 +00:00
FOREACH_PlayerNumber( p )
2004-03-14 18:51:03 +00:00
{
if( m_OptionsNavigation==NAV_TOGGLE_THREE_KEY || m_OptionsNavigation==NAV_TOGGLE_FIVE_KEY )
2004-01-14 04:59:07 +00:00
{
; // do nothing
}
2004-01-10 08:57:08 +00:00
else
2004-01-14 04:59:07 +00:00
{
if( row.GetRowDef().selectType == SELECT_MULTIPLE )
2004-01-14 04:59:07 +00:00
; // do nothing. User must press Start to toggle the selection.
else
2005-01-31 03:18:46 +00:00
row.SetOneSelection( p, iNewChoiceWithFocus );
2004-01-14 04:59:07 +00:00
}
}
2002-05-20 08:59:37 +00:00
}
2004-01-10 08:57:08 +00:00
else
{
if( m_OptionsNavigation==NAV_TOGGLE_THREE_KEY || m_OptionsNavigation==NAV_TOGGLE_FIVE_KEY )
2004-01-14 04:59:07 +00:00
{
; // do nothing
}
2004-01-10 08:57:08 +00:00
else
2004-01-14 04:59:07 +00:00
{
if( row.GetRowDef().selectType == SELECT_MULTIPLE )
2004-01-14 04:59:07 +00:00
; // do nothing. User must press Start to toggle the selection.
else
row.SetOneSelection( pn, iNewChoiceWithFocus );
}
2004-01-10 08:57:08 +00:00
}
UpdateText( iCurRow );
2004-01-10 08:57:08 +00:00
OnChange( pn );
if( m_OptionsNavigation != NAV_THREE_KEY_MENU )
2004-01-09 04:43:27 +00:00
m_SoundChangeCol.Play();
if( row.GetRowDef().m_bExportOnChange )
FOREACH_HumanPlayer( p )
ExportOptions( iCurRow, p );
2002-05-20 08:59:37 +00:00
}
2004-01-09 04:43:27 +00:00
/* Up/down */
void ScreenOptions::MoveRow( PlayerNumber pn, int dir, bool Repeat )
2002-05-20 08:59:37 +00:00
{
2005-02-25 05:45:16 +00:00
const int iCurrentRow = m_iCurrentRow[pn];
OptionRow &row = *m_Rows[iCurrentRow];
if( row.GetFirstItemGoesDown() )
{
// If moving from a bFirstChoiceGoesDown row, put focus back on
// the first choice before moving.
2005-02-26 11:19:19 +00:00
row.SetChoiceInRowWithFocus( pn, 0 );
}
LOG->Trace("move pn %i, dir %i, rep %i", pn, dir, Repeat);
bool changed = false;
FOREACH_PlayerNumber( p )
2002-05-20 08:59:37 +00:00
{
if( m_InputMode == INPUTMODE_INDIVIDUAL && p != pn )
continue; // skip
2002-05-20 08:59:37 +00:00
int r = m_iCurrentRow[p] + dir;
if( Repeat && ( r == -1 || r == (int) m_Rows.size() ) )
continue; // don't wrap while repeating
2002-05-20 08:59:37 +00:00
wrap( r, m_Rows.size() );
2005-02-26 11:19:19 +00:00
const unsigned iOldSelection = row.GetChoiceInRowWithFocus(p);
m_iCurrentRow[p] = r;
2005-02-26 23:50:24 +00:00
ASSERT( r >= 0 && r < (int)m_Rows.size() );
OptionRow &row = *m_Rows[r];
2002-08-22 08:08:16 +00:00
2004-08-12 23:03:01 +00:00
switch( m_OptionsNavigation )
{
2004-08-12 23:03:01 +00:00
case NAV_TOGGLE_THREE_KEY:
case NAV_TOGGLE_FIVE_KEY:
if( row.GetRowDef().layoutType != LAYOUT_SHOW_ONE_IN_ROW )
{
2004-08-12 23:03:01 +00:00
int iSelectionDist = -1;
for( unsigned i = 0; i < row.GetTextItemsSize(); ++i )
{
2004-08-12 23:03:01 +00:00
int iWidth, iX, iY;
GetWidthXY( p, m_iCurrentRow[p], i, iWidth, iX, iY );
const int iDist = abs( iX-m_iFocusX[p] );
if( iSelectionDist == -1 || iDist < iSelectionDist )
{
iSelectionDist = iDist;
2005-02-26 11:19:19 +00:00
row.SetChoiceInRowWithFocus( p, i );
2004-08-12 23:03:01 +00:00
}
}
2005-02-26 11:19:19 +00:00
row.SetChoiceInRowWithFocus( p, min( iOldSelection, row.GetTextItemsSize()-1 ) );
}
}
2005-01-31 03:18:46 +00:00
OnChange( p );
changed = true;
}
if( changed )
2004-03-08 06:12:03 +00:00
{
if( dir < 0 )
m_SoundPrevRow.Play();
else
m_SoundNextRow.Play();
}
2002-05-20 08:59:37 +00:00
}
2004-01-09 04:14:13 +00:00
void ScreenOptions::MenuUp( PlayerNumber pn, const InputEventType type )
{
int r;
bool bFoundDest = false;
for( r=m_iCurrentRow[pn]-1; r>=0; r-- )
{
OptionRow &row = *m_Rows[r];
if( row.GetRowDef().EnabledForPlayer(pn) )
{
bFoundDest = true;
break;
}
}
int iDelta = bFoundDest ? r-m_iCurrentRow[pn] : -1;
MoveRow( pn, iDelta, type != IET_FIRST_PRESS );
}
void ScreenOptions::MenuDown( PlayerNumber pn, const InputEventType type )
{
2005-02-21 06:29:22 +00:00
unsigned r;
bool bFoundDest = false;
for( r=m_iCurrentRow[pn]+1; r<m_Rows.size(); r++ )
{
OptionRow &row = *m_Rows[r];
if( row.GetRowDef().EnabledForPlayer(pn) )
{
bFoundDest = true;
break;
}
}
int iDelta = bFoundDest ? r-m_iCurrentRow[pn] : +1;
MoveRow( pn, iDelta, type != IET_FIRST_PRESS );
}
2004-01-09 04:14:13 +00:00
int ScreenOptions::GetCurrentRow( PlayerNumber pn ) const
{
const int r = m_iCurrentRow[pn];
return r;
2004-01-09 04:14:13 +00:00
}
2004-06-08 05:22:33 +00:00
/*
* (c) 2001-2004 Chris Danford, Glenn Maynard
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/