Files
itgmania212121/stepmania/src/ScreenOptions.cpp
T

1314 lines
36 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"
#include "ScreenDimensions.h"
2005-01-26 11:21:43 +00:00
#include "Command.h"
#include "GameCommand.h"
#include "OptionRowHandler.h"
#include "LuaBinding.h"
#include "InputEventPlus.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
2005-07-14 05:33:50 +00:00
* This is a specialized navigation for ScreenOptionsService. 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.
*/
2006-01-22 01:00:06 +00:00
static RString EXPLANATION_X_NAME( size_t p ) { return ssprintf("ExplanationP%dX",int(p+1)); }
static RString EXPLANATION_Y_NAME( size_t p ) { return ssprintf("ExplanationP%dY",int(p+1)); }
static RString EXPLANATION_ON_COMMAND_NAME( size_t p ) { return ssprintf("ExplanationP%dOnCommand",int(p+1)); }
2005-02-09 08:10:50 +00:00
2006-01-22 01:00:06 +00:00
static RString OPTION_EXPLANATION( RString s )
2005-03-20 06:41:56 +00:00
{
2006-01-08 18:40:20 +00:00
return THEME->GetString("OptionExplanations",s);
2005-03-20 06:41:56 +00:00
}
2005-02-09 08:10:50 +00:00
2006-01-16 02:34:09 +00:00
static const char *InputModeNames[] = {
"Individual",
"Together"
};
StringToX( InputMode );
//REGISTER_SCREEN_CLASS( ScreenOptions ); // can't be instantiated
2006-01-15 19:49:02 +00:00
ScreenOptions::ScreenOptions()
2002-05-20 08:59:37 +00:00
{
m_fLockInputSecs = 0.0001f; // always lock for a tiny amount of time so that we throw away any queued inputs during the load.
// These can be overridden in a derived Init().
2005-07-15 02:25:09 +00:00
m_OptionsNavigation = PREFSMAN->m_bArcadeOptionsNavigation? NAV_THREE_KEY:NAV_FIVE_KEY;
m_InputMode = INPUTMODE_SHARE_CURSOR;
}
2002-05-20 08:59:37 +00:00
2005-02-02 08:31:15 +00:00
void ScreenOptions::Init()
{
2006-01-15 19:29:33 +00:00
NUM_ROWS_SHOWN.Load( m_sName, "NumRowsShown" );
ROW_INIT_COMMAND.Load( m_sName, "RowInitCommand" );
ROW_ON_COMMAND.Load( m_sName, "RowOnCommand" );
ROW_OFF_COMMAND.Load( m_sName, "RowOffCommand" );
EXPLANATION_X.Load( m_sName, EXPLANATION_X_NAME, NUM_PLAYERS );
EXPLANATION_Y.Load( m_sName, EXPLANATION_Y_NAME, NUM_PLAYERS );
EXPLANATION_ON_COMMAND.Load( m_sName, EXPLANATION_ON_COMMAND_NAME, NUM_PLAYERS );
EXPLANATION_TOGETHER_X.Load( m_sName, "ExplanationTogetherX" );
EXPLANATION_TOGETHER_Y.Load( m_sName, "ExplanationTogetherY" );
EXPLANATION_TOGETHER_ON_COMMAND.Load( m_sName, "ExplanationTogetherOnCommand" );
SHOW_SCROLL_BAR.Load( m_sName, "ShowScrollBar" );
SCROLL_BAR_HEIGHT.Load( m_sName, "ScrollBarHeight" );
SCROLL_BAR_TIME.Load( m_sName, "ScrollBarTime" );
LINE_HIGHLIGHT_X.Load( m_sName, "LineHighlightX" );
SHOW_EXIT_ROW.Load( m_sName, "ShowExitRow" );
SEPARATE_EXIT_ROW.Load( m_sName, "SeparateExitRow" );
SEPARATE_EXIT_ROW_Y.Load( m_sName, "SeparateExitRowY" );
SHOW_EXPLANATIONS.Load( m_sName, "ShowExplanations" );
ALLOW_REPEATING_CHANGE_VALUE_INPUT.Load( m_sName, "AllowRepeatingChangeValueInput" );
CURSOR_TWEEN_SECONDS.Load( m_sName, "CursorTweenSeconds" );
WRAP_VALUE_IN_ROW.Load( m_sName, "WrapValueInRow" );
m_exprRowPositionTransformFunction.SetFromExpression( THEME->GetMetric(m_sName,"RowPositionTransformFunction") );
ScreenWithMenuElements::Init();
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 );
2005-03-16 02:18:03 +00:00
m_SoundToggleOn.Load( THEME->GetPathS(m_sName,"toggle on"), true );
m_SoundToggleOff.Load( THEME->GetPathS(m_sName,"toggle off"), true );
2002-05-20 08:59:37 +00:00
// add everything to m_framePage so we can animate everything at once
2005-04-15 06:39:44 +00:00
m_framePage.SetName( "Frame" );
this->AddChild( &m_framePage );
m_sprPage.Load( THEME->GetPathG(m_sName,"page") );
m_sprPage->SetName( "Page" );
SET_XY( m_sprPage );
m_framePage.AddChild( m_sprPage );
// init line line highlights
FOREACH_PlayerNumber( p )
{
m_sprLineHighlight[p].Load( THEME->GetPathG(m_sName,"line highlight") );
2005-10-29 23:47:03 +00:00
m_sprLineHighlight[p]->SetName( "LineHighlight" );
m_sprLineHighlight[p]->SetX( LINE_HIGHLIGHT_X );
m_framePage.AddChild( m_sprLineHighlight[p] );
}
// init cursors
FOREACH_PlayerNumber( p )
{
2005-07-30 04:49:50 +00:00
m_Cursor[p].Load( m_sName, OptionsCursorPlus::cursor );
m_Cursor[p].Set( p );
2005-08-30 07:56:39 +00:00
m_Cursor[p].SetName( "Cursor" );
m_framePage.AddChild( &m_Cursor[p] );
}
// on top:
FOREACH_PlayerNumber( p )
{
m_textExplanation[p].LoadFromFont( THEME->GetPathF(m_sName,"explanation") );
m_textExplanation[p].SetShadowLength( 0 );
m_textExplanation[p].SetDrawOrder( 2 );
m_framePage.AddChild( &m_textExplanation[p] );
}
switch( m_InputMode )
{
case INPUTMODE_INDIVIDUAL:
{
FOREACH_PlayerNumber( p )
m_textExplanation[p].SetXY( EXPLANATION_X.GetValue(p), EXPLANATION_Y.GetValue(p) );
}
break;
case INPUTMODE_SHARE_CURSOR:
m_textExplanation[0].SetXY( EXPLANATION_TOGETHER_X, EXPLANATION_TOGETHER_Y );
break;
default:
ASSERT(0);
}
if( SHOW_SCROLL_BAR )
{
m_ScrollBar.SetName( "ScrollBar" );
m_ScrollBar.SetBarHeight( SCROLL_BAR_HEIGHT );
m_ScrollBar.SetBarTime( SCROLL_BAR_TIME );
2005-10-05 22:30:54 +00:00
m_ScrollBar.Load( "DualScrollBar" );
FOREACH_PlayerNumber( p )
m_ScrollBar.EnablePlayer( p, GAMESTATE->IsHumanPlayer(p) );
SET_XY( m_ScrollBar );
m_ScrollBar.SetDrawOrder( 2 );
m_framePage.AddChild( &m_ScrollBar );
}
m_sprMore.Load( THEME->GetPathG( m_sName,"more") );
m_sprMore->SetName( "More" );
SET_XY( m_sprMore );
m_sprMore->SetDrawOrder( 2 );
m_framePage.AddChild( m_sprMore );
m_OptionRowType.Load( m_sName );
2004-01-09 04:14:13 +00:00
}
2006-01-17 21:31:50 +00:00
void ScreenOptions::InitMenu( const vector<OptionRowHandler*> &vHands )
{
LOG->Trace( "ScreenOptions::InitMenu()" );
2005-07-19 21:03:56 +00:00
for( unsigned i=0; i<m_pRows.size(); i++ )
{
m_framePage.RemoveChild( m_pRows[i] );
SAFE_DELETE( m_pRows[i] );
}
m_pRows.clear();
2006-01-17 21:31:50 +00:00
for( unsigned r=0; r<vHands.size(); r++ ) // foreach row
2004-01-10 04:35:30 +00:00
{
m_pRows.push_back( new OptionRow(&m_OptionRowType) );
2005-06-23 08:05:09 +00:00
OptionRow &row = *m_pRows.back();
row.SetDrawOrder( 1 );
m_framePage.AddChild( &row );
2005-02-25 05:45:16 +00:00
bool bFirstRowGoesDown = m_OptionsNavigation==NAV_TOGGLE_THREE_KEY;
2006-01-17 21:40:39 +00:00
row.LoadNormal( vHands[r], bFirstRowGoesDown );
}
2005-02-26 21:35:27 +00:00
if( SHOW_EXIT_ROW )
2005-02-26 11:19:19 +00:00
{
m_pRows.push_back( new OptionRow(&m_OptionRowType) );
2005-06-23 08:05:09 +00:00
OptionRow &row = *m_pRows.back();
2005-02-26 11:19:19 +00:00
row.LoadExit();
row.SetDrawOrder( 1 );
2005-02-26 11:19:19 +00:00
m_framePage.AddChild( &row );
}
m_framePage.SortByDrawOrder();
FOREACH( OptionRow*, m_pRows, p )
{
int iIndex = p - m_pRows.begin();
Lua *L = LUA->Get();
LuaHelpers::Push( iIndex, L );
(*p)->m_pLuaInstance->Set( L, "iIndex" );
LUA->Release( L );
(*p)->RunCommands( ROW_INIT_COMMAND );
}
// poke once at all the explanation metrics so that we catch missing ones early
2005-06-23 08:05:09 +00:00
for( int r=0; r<(int)m_pRows.size(); r++ ) // foreach row
{
GetExplanationText( r );
}
}
void ScreenOptions::BeginScreen()
{
ScreenWithMenuElements::BeginScreen();
for( unsigned r=0; r<m_pRows.size(); r++ ) // foreach row
{
2006-01-18 05:30:29 +00:00
OptionRow *pRow = m_pRows[r];
pRow->Reload();
vector<PlayerNumber> vpns;
FOREACH_HumanPlayer( p )
vpns.push_back( p );
this->ImportOptions( r, vpns );
2006-01-19 06:02:52 +00:00
// HACK: Process disabled players, too, to hide inactive underlines.
FOREACH_PlayerNumber( p )
pRow->AfterImportOptions( p );
}
ON_COMMAND( m_framePage );
FOREACH_PlayerNumber( p )
{
m_iCurrentRow[p] = -1;
m_iFocusX[p] = -1;
m_bWasOnExit[p] = false;
m_bGotAtLeastOneStartPressed[p] = false;
}
2005-03-20 06:41:56 +00:00
// put focus on the first enabled row
FOREACH_PlayerNumber( p )
{
2005-06-23 08:05:09 +00:00
for( unsigned r=0; r<m_pRows.size(); r++ )
2005-03-20 06:41:56 +00:00
{
2005-06-23 08:05:09 +00:00
const OptionRow &row = *m_pRows[r];
2005-03-20 06:41:56 +00:00
if( row.GetRowDef().IsEnabledForPlayer(p) )
{
m_iCurrentRow[p] = r;
break;
}
}
}
2005-07-22 19:58:26 +00:00
FOREACH_PlayerNumber( p )
{
2005-10-29 23:47:03 +00:00
m_sprLineHighlight[p]->SetHidden( !GAMESTATE->IsHumanPlayer(p) );
2005-07-22 19:58:26 +00:00
m_Cursor[p].SetHidden( !GAMESTATE->IsHumanPlayer(p) );
}
2005-03-25 04:31:14 +00:00
// Hide highlight if no rows are enabled.
FOREACH_HumanPlayer( p )
2005-10-29 23:47:03 +00:00
m_sprLineHighlight[p]->SetHidden( m_iCurrentRow[p] == -1 );
2005-03-25 04:31:14 +00:00
CHECKPOINT;
PositionRows();
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 )
2005-07-29 22:52:36 +00:00
AfterChangeValueOrRow( p );
2004-01-08 23:32:14 +00:00
CHECKPOINT;
}
void ScreenOptions::TweenOnScreen()
{
ScreenWithMenuElements::TweenOnScreen();
FOREACH( OptionRow*, m_pRows, p )
(*p)->RunCommands( ROW_ON_COMMAND );
ON_COMMAND( m_sprPage );
FOREACH_HumanPlayer( p )
2005-08-30 07:56:39 +00:00
{
ON_COMMAND( m_Cursor[p] );
ON_COMMAND( m_sprLineHighlight[p] );
2005-08-30 07:56:39 +00:00
}
ON_COMMAND( m_sprMore );
2005-08-30 07:56:39 +00:00
m_framePage.SortByDrawOrder();
2002-05-20 08:59:37 +00:00
}
void ScreenOptions::TweenOffScreen()
{
ScreenWithMenuElements::TweenOffScreen();
FOREACH( OptionRow*, m_pRows, p )
(*p)->RunCommands( ROW_OFF_COMMAND );
OFF_COMMAND( m_framePage );
}
2002-05-20 08:59:37 +00:00
ScreenOptions::~ScreenOptions()
{
LOG->Trace( "ScreenOptions::~ScreenOptions()" );
2005-06-23 08:05:09 +00:00
for( unsigned i=0; i<m_pRows.size(); i++ )
SAFE_DELETE( m_pRows[i] );
2002-05-20 08:59:37 +00:00
}
2006-01-22 01:00:06 +00:00
RString ScreenOptions::GetExplanationText( int iRow ) const
2003-11-08 02:46:12 +00:00
{
2006-01-16 20:30:19 +00:00
const OptionRow &row = *m_pRows[iRow];
2004-01-09 04:14:13 +00:00
2005-07-16 07:01:48 +00:00
bool bAllowExplanation = row.GetRowDef().m_bAllowExplanation;
bool bShowExplanations = bAllowExplanation && SHOW_EXPLANATIONS.GetValue();
if( !bShowExplanations )
2006-01-22 01:00:06 +00:00
return RString();
2005-07-16 07:01:48 +00:00
2006-01-22 01:00:06 +00:00
RString sExplanationName = row.GetRowDef().m_sExplanationName;
if( sExplanationName.empty() )
sExplanationName = row.GetRowDef().m_sName;
ASSERT( !sExplanationName.empty() );
return OPTION_EXPLANATION(sExplanationName);
}
2006-01-16 20:30:19 +00:00
void ScreenOptions::GetWidthXY( PlayerNumber pn, int iRow, int iChoiceOnRow, int &iWidthOut, int &iXOut, int &iYOut ) const
2002-05-20 08:59:37 +00:00
{
2005-06-23 08:05:09 +00:00
ASSERT_M( iRow < (int)m_pRows.size(), ssprintf("%i < %i", iRow, (int)m_pRows.size() ) );
2006-01-16 20:30:19 +00:00
const OptionRow &row = *m_pRows[iRow];
row.GetWidthXY( pn, iChoiceOnRow, iWidthOut, iXOut, iYOut );
2002-05-20 08:59:37 +00:00
}
2002-09-03 06:33:08 +00:00
void ScreenOptions::PositionIcons()
{
2005-06-23 08:05:09 +00:00
for( unsigned i=0; i<m_pRows.size(); i++ ) // foreach options line
2006-01-16 04:16:24 +00:00
m_pRows[i]->PositionIcons();
2002-09-03 06:33:08 +00:00
}
void ScreenOptions::RefreshIcons( int iRow, PlayerNumber pn )
{
OptionRow &row = *m_pRows[iRow];
const OptionRowDefinition &def = row.GetRowDef();
// find first selection and whether multiple are selected
int iFirstSelection = row.GetOneSelection( pn, true );
// set icon name and bullet
2006-01-22 01:00:06 +00:00
RString sIcon;
GameCommand gc;
if( iFirstSelection == -1 )
{
sIcon = "Multi";
}
else if( iFirstSelection != -1 )
{
const OptionRowHandler *pHand = row.GetHandler();
if( pHand )
{
int iSelection = iFirstSelection+(m_OptionsNavigation==NAV_TOGGLE_THREE_KEY?-1:0);
2006-01-19 03:43:29 +00:00
pHand->GetIconTextAndGameCommand( iSelection, sIcon, gc );
}
}
/* XXX: hack to not display text in the song options menu */
if( def.m_bOneChoiceForAllPlayers )
sIcon = "";
2006-01-16 04:35:00 +00:00
m_pRows[iRow]->SetOptionIcon( pn, sIcon, gc );
}
2005-03-13 02:25:33 +00:00
void ScreenOptions::RefreshAllIcons()
{
FOREACH_HumanPlayer( p )
2006-01-16 04:17:06 +00:00
for( unsigned r=0; r<m_pRows.size(); ++r )
2005-03-13 02:25:33 +00:00
this->RefreshIcons( r, p );
}
2002-09-03 06:33:08 +00:00
void ScreenOptions::PositionCursors()
2002-05-20 08:59:37 +00:00
{
2005-03-21 05:17:46 +00:00
// Set the position of the cursor showing the current option the user is changing.
// Set the position of the underlines showing the current choice for each option line.
2005-03-20 06:41:56 +00:00
FOREACH_HumanPlayer( pn )
2002-05-20 08:59:37 +00:00
{
2004-01-13 08:35:15 +00:00
const int iRow = m_iCurrentRow[pn];
if( iRow == -1 )
continue;
2005-06-23 08:05:09 +00:00
ASSERT_M( iRow >= 0 && iRow < (int)m_pRows.size(), ssprintf("%i < %i", iRow, (int)m_pRows.size() ) );
2005-07-30 04:49:50 +00:00
const OptionRow &row = *m_pRows[iRow];
OptionsCursorPlus &cursor = m_Cursor[pn];
2002-05-20 08:59:37 +00:00
2005-07-30 04:49:50 +00:00
const int iChoiceWithFocus = row.GetChoiceInRowWithFocus(pn);
2005-03-21 05:17:46 +00:00
if( iChoiceWithFocus == -1 )
continue; // skip
int iWidth, iX, iY;
2005-01-31 03:18:46 +00:00
GetWidthXY( pn, iRow, iChoiceWithFocus, iWidth, iX, iY );
2005-03-21 05:17:46 +00:00
cursor.SetBarWidth( iWidth );
cursor.SetXY( (float)iX, (float)iY );
2005-07-30 04:49:50 +00:00
bool bCanGoLeft = iChoiceWithFocus > 0;
2005-08-05 16:18:07 +00:00
bool bCanGoRight = iChoiceWithFocus >= 0 && iChoiceWithFocus < (int) row.GetRowDef().m_vsChoices.size()-1;
2005-07-30 04:49:50 +00:00
cursor.SetCanGo( bCanGoLeft, bCanGoRight );
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
{
2005-03-21 05:17:46 +00:00
// Set the position of the cursor showing the current option the user is changing.
2004-01-13 08:35:15 +00:00
const int iRow = m_iCurrentRow[pn];
2005-07-30 04:49:50 +00:00
ASSERT_M( iRow >= 0 && iRow < (int)m_pRows.size(), ssprintf("%i < %i", iRow, (int)m_pRows.size() ) );
2002-05-20 08:59:37 +00:00
2005-06-23 08:05:09 +00:00
const OptionRow &row = *m_pRows[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 );
2005-07-30 04:49:50 +00:00
OptionsCursorPlus &cursor = m_Cursor[pn];
if( cursor.GetDestX() != (float) iX ||
cursor.GetDestY() != (float) iY ||
cursor.GetBarWidth() != iWidth )
{
cursor.StopTweening();
2005-04-20 23:02:37 +00:00
cursor.BeginTweening( CURSOR_TWEEN_SECONDS );
cursor.SetXY( (float)iX, (float)iY );
2005-07-30 04:49:50 +00:00
cursor.SetBarWidth( iWidth );
}
2005-07-30 04:49:50 +00:00
bool bCanGoLeft = iChoiceWithFocus > 0;
2005-08-05 16:18:07 +00:00
bool bCanGoRight = iChoiceWithFocus >= 0 && iChoiceWithFocus < (int) row.GetRowDef().m_vsChoices.size()-1;
2005-07-30 04:49:50 +00:00
cursor.SetCanGo( bCanGoLeft, bCanGoRight );
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" );
2005-12-06 12:41:33 +00:00
if( row.GetRowType() == OptionRow::RowType_Exit )
2005-01-08 12:44:03 +00:00
COMMAND( m_sprLineHighlight[pn], "ChangeToExit" );
2005-10-29 23:47:03 +00:00
m_sprLineHighlight[pn]->SetY( (float)iY );
2004-01-10 03:12:32 +00:00
}
2002-05-20 08:59:37 +00:00
}
void ScreenOptions::UpdateEnabledDisabled( int r )
{
2005-06-23 08:05:09 +00:00
OptionRow &row = *m_pRows[r];
FOREACH_PlayerNumber( pn )
2006-01-15 23:33:29 +00:00
row.SetRowHasFocus( pn, GAMESTATE->IsHumanPlayer(pn) && m_iCurrentRow[pn] == (int)r );
2004-01-09 04:14:13 +00:00
row.UpdateEnabledDisabled();
}
2004-01-13 08:35:15 +00:00
void ScreenOptions::UpdateEnabledDisabled()
{
2005-06-23 08:05:09 +00:00
for( unsigned r=0; r<m_pRows.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
m_fLockInputSecs = max( 0, m_fLockInputSecs-fDeltaTime );
2005-03-16 11:08:41 +00:00
ScreenWithMenuElements::Update( fDeltaTime );
2002-05-20 08:59:37 +00:00
}
void ScreenOptions::Input( const InputEventPlus &input )
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_Cancel.IsTransitioning() || m_Out.IsTransitioning() || m_fLockInputSecs > 0 )
2002-05-20 08:59:37 +00:00
return;
if( !GAMESTATE->IsHumanPlayer(input.MenuI.player) )
2005-03-20 22:39:36 +00:00
return;
if( input.type == IET_RELEASE )
{
switch( input.MenuI.button )
{
case MENU_BUTTON_START:
2005-04-29 06:28:04 +00:00
case MENU_BUTTON_SELECT:
case MENU_BUTTON_RIGHT:
case MENU_BUTTON_LEFT:
INPUTMAPPER->ResetKeyRepeat( MenuInput(input.MenuI.player, MENU_BUTTON_START) );
INPUTMAPPER->ResetKeyRepeat( MenuInput(input.MenuI.player, MENU_BUTTON_RIGHT) );
INPUTMAPPER->ResetKeyRepeat( MenuInput(input.MenuI.player, MENU_BUTTON_LEFT) );
}
}
2002-05-20 08:59:37 +00:00
// default input handler
Screen::Input( input );
2002-05-20 08:59:37 +00:00
}
void ScreenOptions::HandleScreenMessage( const ScreenMessage SM )
{
2005-07-12 06:01:15 +00:00
if( SM == SM_MenuTimer )
2002-05-20 08:59:37 +00:00
{
2005-02-26 21:35:27 +00:00
this->BeginFadingOut();
2005-07-12 06:01:15 +00:00
}
2006-01-15 08:37:34 +00:00
else if( SM == SM_BeginFadingOut )
{
if( IsTransitioning() )
return; /* already transitioning */
/* If the selected option sets a screen, honor it. */
2006-01-22 01:00:06 +00:00
RString sThisScreen = GetNextScreenForSelection( GAMESTATE->m_MasterPlayerNumber );
if( sThisScreen != "" )
m_sNextScreen = sThisScreen;
// If options set a NextScreen or one is specified in metrics, then fade out
if( GetNextScreen() == "" )
{
LOG->Warn( "%s::HandleScreenMessage: Tried to fade out, but we have no next screen", m_sName.c_str() );
return;
}
2006-01-15 08:37:34 +00:00
StartTransitioningScreen( SM_ExportOptions );
}
else if( SM == SM_ExportOptions )
2005-07-12 06:01:15 +00:00
{
2006-01-15 08:35:08 +00:00
vector<PlayerNumber> vpns;
FOREACH_HumanPlayer( p )
vpns.push_back( p );
2005-06-23 08:05:09 +00:00
for( unsigned r=0; r<m_pRows.size(); r++ ) // foreach row
2005-04-03 06:21:02 +00:00
this->ExportOptions( r, vpns );
2006-01-15 08:37:34 +00:00
this->HandleScreenMessage( SM_GoToNextScreen );
2005-07-12 06:01:15 +00:00
}
else if( SM == SM_GainFocus )
{
INPUTFILTER->SetRepeatRate( 0.25f, 0.25f, 12 );
2005-07-12 06:01:15 +00:00
}
else if( SM == SM_LoseFocus )
{
2003-11-25 22:03:01 +00:00
INPUTFILTER->ResetRepeatRate();
2002-05-20 08:59:37 +00:00
}
ScreenWithMenuElements::HandleScreenMessage( SM );
2002-05-20 08:59:37 +00:00
}
void ScreenOptions::PositionRows()
2003-06-16 03:29:59 +00:00
{
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-06-23 08:05:09 +00:00
vector<OptionRow*> Rows( m_pRows );
2006-01-14 18:52:54 +00:00
OptionRow *pSeparateExitRow = NULL;
2004-01-10 00:45:01 +00:00
2005-12-06 12:41:33 +00:00
if( (bool)SEPARATE_EXIT_ROW && !Rows.empty() && Rows.back()->GetRowType() == OptionRow::RowType_Exit )
2004-01-10 00:45:01 +00:00
{
2006-01-14 18:52:54 +00:00
pSeparateExitRow = &*Rows.back();
2004-01-10 00:45:01 +00:00
/* 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
{
2003-06-18 04:11:33 +00:00
/* 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
{
OptionRow &row = *Rows[i];
2005-12-06 15:57:09 +00:00
float fPos = (float) pos;
LuaExpressionTransform *pExpr = NULL;
pExpr = &m_exprRowPositionTransformFunction;
2006-01-14 18:52:00 +00:00
if( i < first_start ) fPos = -0.5f;
else if( i >= first_end && i < second_start ) fPos = ((int)NUM_ROWS_SHOWN)/2-0.5f;
else if( i >= second_end ) fPos = ((int)NUM_ROWS_SHOWN)-0.5f;
Actor::TweenState tsDestination = m_exprRowPositionTransformFunction.GetPosition( (float) fPos, i, min( (int)Rows.size(), (int)NUM_ROWS_SHOWN ) );
row.SetDestination( tsDestination );
2004-01-09 04:14:13 +00:00
bool bHidden =
2005-02-14 01:34:49 +00:00
i < first_start ||
(i >= first_end && i < second_start) ||
i >= second_end;
if( !bHidden )
pos++;
row.SetRowHidden( bHidden );
2003-06-16 03:29:59 +00:00
}
2004-01-10 00:45:01 +00:00
2006-01-14 18:52:54 +00:00
if( pSeparateExitRow )
2004-01-10 00:45:01 +00:00
{
Actor::TweenState tsDestination;
tsDestination.Init();
tsDestination.pos.y = SEPARATE_EXIT_ROW_Y;
pSeparateExitRow->SetDestination( tsDestination );
2006-01-14 18:52:54 +00:00
pSeparateExitRow->SetRowHidden( second_end != (int) Rows.size() );
2004-01-10 00:45:01 +00:00
}
2003-06-16 03:29:59 +00:00
}
2005-07-29 22:52:36 +00:00
void ScreenOptions::AfterChangeValueOrRow( 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];
if( iCurRow == -1 )
return;
2005-03-13 02:15:38 +00:00
2004-01-09 04:14:13 +00:00
/* Update m_fY and m_bHidden[]. */
PositionRows();
2003-06-16 03:29:59 +00:00
/* Do positioning. */
for( unsigned r=0; r<m_pRows.size(); r++ )
FOREACH_HumanPlayer( p )
m_pRows[r]->PositionUnderlines( p );
2006-01-16 04:18:31 +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;
2005-06-23 08:05:09 +00:00
if( m_pRows.size() > 1 )
fPercent = m_iCurrentRow[pn] / float(m_pRows.size()-1);
m_ScrollBar.SetPercentage( pn, fPercent );
}
2003-12-18 00:17:04 +00:00
/* Update all players, since changing one player can move both cursors. */
2006-01-14 18:10:41 +00:00
FOREACH_HumanPlayer( p )
TweenCursor( p );
FOREACH_PlayerNumber( p )
2004-01-10 03:36:14 +00:00
{
int iCurrentRow = m_iCurrentRow[pn];
2005-06-23 08:05:09 +00:00
OptionRow &row = *m_pRows[iCurrentRow];
2006-01-14 09:15:09 +00:00
const bool bExitSelected = row.GetRowType() == OptionRow::RowType_Exit;
2006-01-14 18:11:12 +00:00
if( GAMESTATE->GetNumHumanPlayers() != 1 && p != pn )
continue;
if( m_bWasOnExit[p] != bExitSelected )
2004-01-10 03:36:14 +00:00
{
2006-01-14 18:11:12 +00:00
m_bWasOnExit[p] = bExitSelected;
COMMAND( m_sprMore, ssprintf("Exit%sP%i", bExitSelected? "Selected":"Unselected", p+1) );
2004-01-10 03:36:14 +00:00
}
}
2006-01-22 01:00:06 +00:00
const RString 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
Cancel( SM_GoToPrevScreen );
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
{
2006-01-16 04:44:29 +00:00
if( m_iCurrentRow[p] != (int)(m_pRows.size()-1) )
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;
}
void ScreenOptions::MenuStart( const InputEventPlus &input )
2002-05-20 08:59:37 +00:00
{
PlayerNumber pn = input.MenuI.player;
switch( input.type )
{
case IET_FIRST_PRESS:
m_bGotAtLeastOneStartPressed[pn] = true;
break;
case IET_RELEASE:
return; // ignore
2005-03-20 08:18:47 +00:00
default: // repeat type
if( !m_bGotAtLeastOneStartPressed[pn] )
return; // don't allow repeat
break;
}
2004-01-10 08:57:08 +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 )
{
MoveRowRelative( pn, -1, input.type != IET_FIRST_PRESS );
2004-01-14 09:03:35 +00:00
return;
}
}
}
2005-06-26 21:31:07 +00:00
this->ProcessMenuStart( input );
2005-06-26 21:31:07 +00:00
}
void ScreenOptions::ProcessMenuStart( const InputEventPlus &input )
2005-06-26 21:31:07 +00:00
{
PlayerNumber pn = input.MenuI.player;
2005-06-26 21:31:07 +00:00
int iCurRow = m_iCurrentRow[pn];
OptionRow &row = *m_pRows[iCurRow];
2004-01-14 09:03:35 +00:00
if( m_OptionsNavigation == NAV_THREE_KEY_MENU && row.GetRowType() != OptionRow::RowType_Exit )
2006-01-16 21:44:04 +00:00
{
/* In NAV_THREE_KEY_MENU mode, if a row doesn't set a screen, it does
* something. Apply it now, and don't go to the next screen. */
2006-01-22 01:00:06 +00:00
RString sScreen = GetNextScreenForSelection( input.MenuI.player );
2006-01-16 21:44:04 +00:00
if( sScreen.empty() )
{
vector<PlayerNumber> vpns;
vpns.push_back( input.MenuI.player );
ExportOptions( iCurRow, vpns );
return;
}
}
2005-03-20 06:41:56 +00:00
//
// Check whether Start ends this screen.
//
2004-01-14 09:03:35 +00:00
{
2005-03-20 06:41:56 +00:00
bool bEndThisScreen = false;
2006-01-16 21:44:04 +00:00
// If we didn't apply and return above in NAV_THREE_KEY_MENU, then the selection
// sets a screen.
if( m_OptionsNavigation == NAV_THREE_KEY_MENU )
bEndThisScreen = true;
2005-03-20 06:41:56 +00:00
// If there's no exit row, then pressing Start on any row ends the screen.
if( !SHOW_EXIT_ROW )
bEndThisScreen = true;
// If all players are on "Exit"
if( AllAreOnLastRow() )
bEndThisScreen = true;
/* Don't accept START to go to the next screen if we're still transitioning in. */
if( bEndThisScreen &&
(input.type != IET_FIRST_PRESS || IsTransitioning()) )
return;
2005-03-20 06:41:56 +00:00
if( bEndThisScreen )
{
SCREENMAN->PlayStartSound();
2005-02-26 21:35:27 +00:00
this->BeginFadingOut();
2005-03-20 06:41:56 +00:00
return;
}
2004-01-14 09:03:35 +00:00
}
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 )
{
MenuDown( input );
2004-01-14 09:03:35 +00:00
return;
}
}
2004-01-10 08:57:08 +00:00
if( row.GetRowDef().m_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
2006-01-18 23:32:51 +00:00
m_pRows[iCurRow]->PositionUnderlines( 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
ChangeValueInRowRelative( m_iCurrentRow[pn], pn, -row.GetChoiceInRowWithFocus(pn), input.type != 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-04-03 12:13:04 +00:00
// don't wrap
2005-06-23 08:05:09 +00:00
if( iCurRow == (int)m_pRows.size()-1 )
2005-04-03 12:13:04 +00:00
return;
MenuDown( input );
break;
case NAV_TOGGLE_THREE_KEY:
case NAV_TOGGLE_FIVE_KEY:
2006-01-16 22:11:22 +00:00
{
int iChoiceInRow = row.GetChoiceInRowWithFocus(pn);
if( row.GetRowDef().m_bOneChoiceForAllPlayers )
row.SetOneSharedSelection( iChoiceInRow );
else
row.SetOneSelection( pn, iChoiceInRow );
2005-02-25 05:45:16 +00:00
if( row.GetFirstItemGoesDown() )
ChangeValueInRowRelative( m_iCurrentRow[pn], pn, -row.GetChoiceInRowWithFocus(pn), input.type != IET_FIRST_PRESS ); // move to the first choice
else
ChangeValueInRowRelative( m_iCurrentRow[pn], pn, 0, input.type != IET_FIRST_PRESS );
break;
2006-01-16 22:11:22 +00:00
}
2004-01-10 08:57:08 +00:00
case NAV_THREE_KEY_MENU:
ASSERT(0); // unreachable
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.) */
MoveRowRelative( pn, m_pRows.size()-m_iCurrentRow[pn]-1, input.type != 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];
2005-06-23 08:05:09 +00:00
const OptionRow &row = *m_pRows[iCurrentRow];
if( row.GetRowDef().m_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]);
}
2006-01-22 01:00:06 +00:00
RString ScreenOptions::GetNextScreenForSelection( PlayerNumber pn ) const
{
int iCurRow = this->GetCurrentRow( pn );
ASSERT( iCurRow >= 0 && iCurRow < (int)m_pRows.size() );
const OptionRow *pRow = m_pRows[iCurRow];
int iChoice = pRow->GetChoiceInRowWithFocus( pn );
if( pRow->GetFirstItemGoesDown() )
iChoice--;
// not the "goes down" item
if( iChoice == -1 )
return RString();
const OptionRowHandler *pHand = pRow->GetHandler();
if( pHand == NULL )
return RString();
return pHand->GetScreen( iChoice );
}
void ScreenOptions::BeginFadingOut()
{
this->PostScreenMessage( SM_BeginFadingOut, 0 );
}
2004-01-09 04:43:27 +00:00
/* Left/right */
2005-07-30 19:34:23 +00:00
void ScreenOptions::ChangeValueInRowAbsolute( int iRow, PlayerNumber pn, int iChoiceIndex, bool bRepeat )
2002-05-20 08:59:37 +00:00
{
2005-07-30 19:34:23 +00:00
if( iRow == -1 ) // no row selected
return; // don't allow a move
2005-07-30 19:34:23 +00:00
OptionRow &row = *m_pRows[iRow];
const int iNumChoices = row.GetRowDef().m_vsChoices.size();
ASSERT( iNumChoices >= 0 && iChoiceIndex < iNumChoices );
int iCurrentChoiceWithFocus = row.GetChoiceInRowWithFocus(pn);
int iDelta = iChoiceIndex - iCurrentChoiceWithFocus;
ChangeValueInRowRelative( iRow, pn, iDelta, bRepeat );
}
void ScreenOptions::ChangeValueInRowRelative( int iRow, PlayerNumber pn, int iDelta, bool bRepeat )
{
if( iRow == -1 ) // no row selected
return; // don't allow a move
OptionRow &row = *m_pRows[iRow];
const int iNumChoices = row.GetRowDef().m_vsChoices.size();
2005-03-20 06:41:56 +00:00
if( m_OptionsNavigation == NAV_THREE_KEY_MENU && iNumChoices <= 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. */
2005-07-30 19:34:23 +00:00
MoveRowRelative( pn, iDelta, bRepeat );
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( iNumChoices <= 1 ) // nowhere to move
2005-03-20 06:41:56 +00:00
return;
2005-07-30 19:34:23 +00:00
if( bRepeat && !ALLOW_REPEATING_CHANGE_VALUE_INPUT )
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;
2005-08-03 03:22:58 +00:00
if( !bRepeat && WRAP_VALUE_IN_ROW.GetValue() )
wrap( iNewChoiceWithFocus, iNumChoices );
else
CLAMP( iNewChoiceWithFocus, 0, iNumChoices-1 );
2004-01-10 08:57:08 +00:00
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().m_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().m_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
}
2002-05-20 08:59:37 +00:00
}
2006-01-19 01:56:40 +00:00
FOREACH_PlayerNumber( p )
2004-01-10 08:57:08 +00:00
{
2006-01-19 01:56:40 +00:00
if( !row.GetRowDef().m_bOneChoiceForAllPlayers && p != pn )
continue;
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().m_selectType == SELECT_MULTIPLE )
2004-01-14 04:59:07 +00:00
; // do nothing. User must press Start to toggle the selection.
else
2006-01-19 01:56:40 +00:00
row.SetOneSelection( p, iNewChoiceWithFocus );
2004-01-14 04:59:07 +00:00
}
2004-01-10 08:57:08 +00:00
}
// XXX: What was this NAV_THREE_KEY_MENU special case for?
if( bOneChanged )
// if( m_OptionsNavigation != NAV_THREE_KEY_MENU )
m_SoundChangeCol.Play();
if( row.GetRowDef().m_bExportOnChange )
2005-04-03 06:21:02 +00:00
{
vector<PlayerNumber> vpns;
FOREACH_HumanPlayer( p )
2005-04-03 06:21:02 +00:00
vpns.push_back( p );
2005-07-30 19:34:23 +00:00
ExportOptions( iRow, vpns );
2005-04-03 06:21:02 +00:00
}
this->AfterChangeValueInRow( iRow, pn );
2002-05-20 08:59:37 +00:00
}
2005-07-30 19:34:23 +00:00
void ScreenOptions::AfterChangeValueInRow( int iRow, PlayerNumber pn )
2005-07-29 22:52:36 +00:00
{
AfterChangeValueOrRow( pn );
}
2004-01-09 04:43:27 +00:00
/* Up/down */
2005-07-18 01:50:31 +00:00
void ScreenOptions::MoveRowRelative( PlayerNumber pn, int iDir, bool Repeat )
2002-05-20 08:59:37 +00:00
{
2005-02-25 05:45:16 +00:00
const int iCurrentRow = m_iCurrentRow[pn];
2005-06-23 08:05:09 +00:00
OptionRow &row = *m_pRows[iCurrentRow];
2005-02-25 05:45:16 +00:00
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 );
}
2005-07-18 01:50:31 +00:00
LOG->Trace("move pn %i, dir %i, rep %i", pn, iDir, 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
2005-07-18 01:50:31 +00:00
int r = m_iCurrentRow[p] + iDir;
2005-06-23 08:05:09 +00:00
if( Repeat && ( r == -1 || r == (int) m_pRows.size() ) )
continue; // don't wrap while repeating
2002-05-20 08:59:37 +00:00
2005-06-23 08:05:09 +00:00
wrap( r, m_pRows.size() );
if( m_iCurrentRow[p] == r )
continue;
m_iCurrentRow[p] = r;
2005-06-23 08:05:09 +00:00
ASSERT( r >= 0 && r < (int)m_pRows.size() );
2005-06-23 08:05:09 +00:00
OptionRow &row = *m_pRows[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_FIVE_KEY:
if( row.GetRowDef().m_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-07-29 22:52:36 +00:00
AfterChangeRow( p );
changed = true;
}
if( changed )
2004-03-08 06:12:03 +00:00
{
2005-07-18 01:50:31 +00:00
if( iDir < 0 )
2004-03-08 06:12:03 +00:00
m_SoundPrevRow.Play();
else
m_SoundNextRow.Play();
}
2002-05-20 08:59:37 +00:00
}
2004-01-09 04:14:13 +00:00
2005-07-29 22:52:36 +00:00
void ScreenOptions::AfterChangeRow( PlayerNumber pn )
{
AfterChangeValueOrRow( pn );
}
2005-07-18 01:50:31 +00:00
void ScreenOptions::MoveRowAbsolute( PlayerNumber pn, int iRow, bool bRepeat )
{
int iDir = iRow - m_iCurrentRow[pn];
MoveRowRelative( pn, iDir, bRepeat );
}
void ScreenOptions::MenuUp( const InputEventPlus &input )
{
MenuUpDown( input, -1 );
}
void ScreenOptions::MenuDown( const InputEventPlus &input )
{
MenuUpDown( input, +1 );
2005-03-20 06:41:56 +00:00
}
void ScreenOptions::MenuSelect( const InputEventPlus &input )
2005-04-29 06:32:07 +00:00
{
MenuUpDown( input, -1 );
2005-04-29 06:32:07 +00:00
}
void ScreenOptions::MenuUpDown( const InputEventPlus &input, int iDir )
2005-03-20 06:41:56 +00:00
{
ASSERT( iDir == -1 || iDir == +1 );
PlayerNumber pn = input.MenuI.player;
2005-03-20 06:41:56 +00:00
if( input.type == IET_SLOW_REPEAT || input.type == IET_FAST_REPEAT )
2005-05-06 08:24:13 +00:00
{
/* If down is pressed, don't allow up to repeat, and vice versa. This prevents
* holding both up and down from toggling repeatedly in-place. */
if( iDir == +1 )
{
if( INPUTMAPPER->IsButtonDown(MenuInput(pn, MENU_BUTTON_UP)) ||
INPUTMAPPER->IsButtonDown(MenuInput(pn, MENU_BUTTON_SELECT)) )
return;
}
else
{
if( INPUTMAPPER->IsButtonDown(MenuInput(pn, MENU_BUTTON_DOWN)) ||
INPUTMAPPER->IsButtonDown(MenuInput(pn, MENU_BUTTON_START)) )
return;
}
}
bool bRepeat = input.type != IET_FIRST_PRESS;
2005-03-20 08:18:47 +00:00
2005-03-20 06:41:56 +00:00
int iDest = -1;
2005-06-23 08:05:09 +00:00
for( int r=1; r<(int)m_pRows.size(); r++ )
{
2005-03-20 06:41:56 +00:00
int iDelta = r*iDir;
iDest = m_iCurrentRow[pn] + iDelta;
2005-03-20 08:18:47 +00:00
int iOldDest = iDest;
2005-06-23 08:05:09 +00:00
ASSERT( m_pRows.size() );
wrap( iDest, m_pRows.size() );
2005-03-20 06:41:56 +00:00
2005-03-20 08:18:47 +00:00
// Don't wrap on repeating inputs.
bool bWrapped = iOldDest != iDest;
if( bRepeat && bWrapped )
return;
2005-06-23 08:05:09 +00:00
OptionRow &row = *m_pRows[iDest];
2005-03-20 06:41:56 +00:00
if( row.GetRowDef().IsEnabledForPlayer(pn) )
{
2005-07-18 01:50:31 +00:00
MoveRowRelative( pn, iDelta, bRepeat );
2005-03-20 06:41:56 +00:00
return;
}
}
}
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
}
2005-12-09 21:39:41 +00:00
// lua start
#include "LuaBinding.h"
class LunaScreenOptions: public Luna<ScreenOptions>
{
public:
LunaScreenOptions() { LUA->Register( Register ); }
static int GetCurrentRow( T* p, lua_State *L ) { lua_pushnumber( L, p->GetCurrentRow((PlayerNumber) IArg(1)) ); return 1; }
static void Register( Lua *L )
{
ADD_METHOD( GetCurrentRow );
Luna<T>::Register( L );
}
};
LUA_REGISTER_DERIVED_CLASS( ScreenOptions, ScreenWithMenuElements )
// lua end
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.
*/