Files
itgmania212121/stepmania/src/ScreenOptionsMaster.cpp
T

309 lines
8.9 KiB
C++
Raw Normal View History

#include "global.h"
#include "ScreenOptionsMaster.h"
#include "RageException.h"
#include "RageUtil.h"
#include "RageLog.h"
#include "ThemeManager.h"
#include "GameState.h"
#include "ScreenManager.h"
#include "SongManager.h"
2003-09-28 05:04:55 +00:00
#include "PrefsManager.h"
2004-07-08 00:10:34 +00:00
#include "GameSoundManager.h"
2003-09-28 07:14:07 +00:00
#include "StepMania.h"
2003-10-12 20:34:46 +00:00
#include "RageSoundManager.h"
#include "Foreach.h"
#include "OptionRowHandler.h"
#include "ScreenOptionsMasterPrefs.h"
#include "CommonMetrics.h"
#define LINE_NAMES THEME->GetMetric (m_sName,"LineNames")
#define OPTION_MENU_FLAGS THEME->GetMetric (m_sName,"OptionMenuFlags")
#define LINE(sLineName) THEME->GetMetric (m_sName,ssprintf("Line%s",sLineName.c_str()))
#define NEXT_SCREEN THEME->GetMetric (m_sName,"NextScreen")
#define PREV_SCREEN THEME->GetMetric (m_sName,"PrevScreen")
2004-11-26 17:28:47 +00:00
REGISTER_SCREEN_CLASS( ScreenOptionsMaster );
ScreenOptionsMaster::ScreenOptionsMaster( CString sClassName ):
ScreenOptions( sClassName )
{
LOG->Trace("ScreenOptionsMaster::ScreenOptionsMaster(%s)", m_sName.c_str() );
}
void ScreenOptionsMaster::Init()
{
ScreenOptions::Init();
2003-09-28 04:07:53 +00:00
CStringArray asLineNames;
split( LINE_NAMES, ",", asLineNames );
if( asLineNames.empty() )
RageException::Throw( "%s::LineNames is empty.", m_sName.c_str() );
2003-09-28 04:07:53 +00:00
CStringArray Flags;
split( OPTION_MENU_FLAGS, ";", Flags, true );
InputMode im = INPUTMODE_INDIVIDUAL;
bool Explanations = false;
2004-09-21 07:53:39 +00:00
for( unsigned i = 0; i < Flags.size(); ++i )
2003-09-28 04:07:53 +00:00
{
2005-02-23 05:51:10 +00:00
CString sFlag = Flags[i];
sFlag.MakeLower();
2003-09-28 04:07:53 +00:00
2005-02-23 05:51:10 +00:00
if( sFlag == "together" )
2004-03-14 18:53:19 +00:00
im = INPUTMODE_SHARE_CURSOR;
2005-02-23 05:51:10 +00:00
else if( sFlag == "explanations" )
2003-09-28 04:07:53 +00:00
Explanations = true;
2005-02-23 05:51:10 +00:00
else if( sFlag == "forceallplayers" )
2003-09-28 04:07:53 +00:00
{
FOREACH_PlayerNumber( pn )
2003-09-28 04:07:53 +00:00
GAMESTATE->m_bSideIsJoined[pn] = true;
GAMESTATE->m_MasterPlayerNumber = PlayerNumber(0);
}
2005-02-23 05:51:10 +00:00
else if( sFlag == "smnavigation" )
SetNavigation( NAV_THREE_KEY_MENU );
2005-02-23 05:51:10 +00:00
else if( sFlag == "toggle" || sFlag == "firstchoicegoesdown" )
SetNavigation( PREFSMAN->m_bArcadeOptionsNavigation? NAV_TOGGLE_THREE_KEY:NAV_TOGGLE_FIVE_KEY );
2005-02-23 05:51:10 +00:00
else
RageException::Throw( "Unknown flag \"%s\"", sFlag.c_str() );
2003-09-28 04:07:53 +00:00
}
2005-02-26 21:35:27 +00:00
vector<OptionRowDefinition> OptionRowDefs;
OptionRowDefs.resize( asLineNames.size() );
OptionRowHandlers.resize( asLineNames.size() );
2004-09-21 07:53:39 +00:00
for( unsigned i = 0; i < asLineNames.size(); ++i )
{
CString sLineName = asLineNames[i];
2005-02-26 21:35:27 +00:00
OptionRowDefinition &def = OptionRowDefs[i];
CString sRowCommands = LINE(sLineName);
OptionRowHandler* &pHand = OptionRowHandlers[i];
pHand = NULL;
2004-12-03 05:19:46 +00:00
Commands vCommands;
ParseCommands( sRowCommands, vCommands );
if( vCommands.v.size() != 1 )
RageException::Throw( "Parse error in %s::Line%i", m_sName.c_str(), i+1 );
Command& command = vCommands.v[0];
pHand = OptionRowHandlerUtil::Make( command, def );
if( pHand == NULL )
RageException::Throw( "Invalid OptionRowHandler '%s' in %s::Line%i", command.GetOriginalCommandString().c_str(), m_sName.c_str(), i );
}
ASSERT( OptionRowHandlers.size() == asLineNames.size() );
2005-02-26 21:35:27 +00:00
InitMenu( im, OptionRowDefs, OptionRowHandlers );
}
ScreenOptionsMaster::~ScreenOptionsMaster()
{
2005-06-23 08:05:09 +00:00
FOREACH( OptionRow*, m_pRows, r )
2005-02-25 05:45:16 +00:00
(*r)->DetachHandler();
FOREACH( OptionRowHandler*, OptionRowHandlers, h )
SAFE_DELETE( *h );
OptionRowHandlers.clear();
}
2005-04-03 06:21:02 +00:00
void ScreenOptionsMaster::ImportOptions( int r, const vector<PlayerNumber> &vpns )
{
2005-04-03 06:21:02 +00:00
FOREACH_CONST( PlayerNumber, vpns, pn )
ASSERT( GAMESTATE->IsHumanPlayer(*pn) );
2005-06-23 08:05:09 +00:00
OptionRow &row = *m_pRows[r];
2005-04-03 06:21:02 +00:00
row.ImportOptions( vpns );
}
2005-04-03 06:21:02 +00:00
void ScreenOptionsMaster::ExportOptions( int r, const vector<PlayerNumber> &vpns )
2005-02-12 09:07:59 +00:00
{
2005-06-23 08:05:09 +00:00
OptionRow &row = *m_pRows[r];
2005-04-03 06:21:02 +00:00
bool bRowHasFocus[NUM_PLAYERS];
ZERO( bRowHasFocus );
2005-04-21 19:53:37 +00:00
FOREACH_CONST( PlayerNumber, vpns, p )
{
int iCurRow = m_iCurrentRow[*p];
bRowHasFocus[*p] = iCurRow == r;
}
2005-04-03 06:21:02 +00:00
m_iChangeMask |= row.ExportOptions( vpns, bRowHasFocus );
}
2005-02-26 21:35:27 +00:00
void ScreenOptionsMaster::BeginFadingOut()
{
/* If the selection is on a LIST, and the selected LIST option sets the screen,
* honor it. */
m_bExportWillSetANewScreen = false;
2005-02-26 21:35:27 +00:00
2005-02-26 23:50:24 +00:00
int iCurRow = this->GetCurrentRow();
2005-06-23 08:05:09 +00:00
ASSERT( iCurRow >= 0 && iCurRow < (int)m_pRows.size() );
OptionRow &row = *m_pRows[iCurRow];
2005-02-26 21:35:27 +00:00
if( row.GetRowType() != OptionRow::ROW_EXIT )
2005-02-26 21:35:27 +00:00
{
2005-04-27 05:40:24 +00:00
int iChoice = row.GetChoiceInRowWithFocus( GAMESTATE->m_MasterPlayerNumber );
if( row.GetFirstItemGoesDown() )
iChoice--;
2005-04-27 05:57:58 +00:00
if( iChoice != -1 ) // not the "goes down" item
{
OptionRowHandler *pHand = OptionRowHandlers[iCurRow];
m_bExportWillSetANewScreen = pHand->HasScreen( iChoice );
}
2005-02-26 21:35:27 +00:00
}
// If options set a NextScreen or one is specified in metrics, then fade out
if( m_bExportWillSetANewScreen || NEXT_SCREEN != "" )
2005-02-26 21:35:27 +00:00
ScreenOptions::BeginFadingOut();
}
2004-12-05 11:59:39 +00:00
void ScreenOptionsMaster::GoToNextScreen()
{
2005-06-25 08:16:30 +00:00
if( SCREENMAN->IsStackedScreen(this) )
SCREENMAN->PopTopScreen( SM_None );
else if( m_bExportWillSetANewScreen )
; // Do nothing. Let Export set the screen.
else if( NEXT_SCREEN != "" )
SCREENMAN->SetNewScreen( NEXT_SCREEN );
}
2004-12-05 11:59:39 +00:00
void ScreenOptionsMaster::GoToPrevScreen()
{
2005-06-25 08:16:30 +00:00
if( SCREENMAN->IsStackedScreen(this) )
{
SCREENMAN->PopTopScreen( SM_None );
}
else
{
SCREENMAN->DeletePreparedScreens();
2005-06-25 08:16:30 +00:00
SCREENMAN->SetNewScreen( PREV_SCREEN );
}
}
2005-03-13 02:25:33 +00:00
void ScreenOptionsMaster::RefreshIcons( int r, PlayerNumber pn )
{
2005-06-23 08:05:09 +00:00
OptionRow &row = *m_pRows[r];
if( row.GetRowType() == OptionRow::ROW_EXIT )
2005-03-13 02:25:33 +00:00
return; // skip
2004-01-10 04:35:30 +00:00
2005-03-13 02:25:33 +00:00
const OptionRowDefinition &def = row.GetRowDef();
2005-03-13 02:25:33 +00:00
// find first selection and whether multiple are selected
int iFirstSelection = row.GetOneSelection( pn, true );
2005-03-13 02:25:33 +00:00
// set icon name
CString sIcon;
2004-01-11 02:28:10 +00:00
2005-03-13 02:25:33 +00:00
if( iFirstSelection == -1 )
{
sIcon = "Multi";
}
else if( iFirstSelection != -1 )
{
const OptionRowHandler *pHand = OptionRowHandlers[r];
sIcon = pHand->GetIconText( def, iFirstSelection+(m_OptionsNavigation==NAV_TOGGLE_THREE_KEY?-1:0) );
}
2005-03-13 02:25:33 +00:00
/* XXX: hack to not display text in the song options menu */
if( def.m_bOneChoiceForAllPlayers )
2005-03-13 02:25:33 +00:00
sIcon = "";
2005-03-13 02:25:33 +00:00
LoadOptionIcon( pn, r, sIcon );
}
2004-06-08 05:22:33 +00:00
void ScreenOptionsMaster::HandleScreenMessage( const ScreenMessage SM )
{
switch( SM )
{
case SM_GoToNextScreen:
{
//
// Override ScreenOptions's calling of ExportOptions
//
m_iChangeMask = 0;
CHECKPOINT;
for( unsigned r = 0; r < OptionRowHandlers.size(); ++r )
{
CHECKPOINT_M( ssprintf("%i/%i", r, int(OptionRowHandlers.size())) );
2005-04-03 06:21:02 +00:00
vector<PlayerNumber> vpns;
FOREACH_OptionsPlayer( p )
2005-04-03 06:21:02 +00:00
vpns.push_back( p );
ExportOptions( r, vpns );
}
if( m_iChangeMask & OPT_APPLY_ASPECT_RATIO )
{
THEME->UpdateLuaGlobals(); // This needs to be done before resetting the projection matrix below
SCREENMAN->ThemeChanged(); // recreate ScreenSystemLayer and SharedBGA
}
/* If the theme changes, we need to reset RageDisplay to apply new theme
* window title and icon. */
/* If the aspect ratio changes, we need to reset RageDisplay so that the
* projection matrix is re-created using the new screen dimensions. */
if( (m_iChangeMask & OPT_APPLY_THEME) ||
(m_iChangeMask & OPT_APPLY_GRAPHICS) ||
(m_iChangeMask & OPT_APPLY_ASPECT_RATIO) )
ApplyGraphicOptions();
if( m_iChangeMask & OPT_SAVE_PREFERENCES )
{
/* Save preferences. */
LOG->Trace("ROW_CONFIG used; saving ...");
PREFSMAN->SaveGlobalPrefsToDisk();
SaveGamePrefsToDisk();
}
if( m_iChangeMask & OPT_RESET_GAME )
{
ResetGame();
SCREENMAN->SetNewScreen( INITIAL_SCREEN );
m_bExportWillSetANewScreen = false;
}
if( m_iChangeMask & OPT_APPLY_SOUND )
{
2005-05-16 09:36:32 +00:00
SOUNDMAN->SetPrefs( PREFSMAN->GetSoundVolume() );
}
if( m_iChangeMask & OPT_APPLY_SONG )
SONGMAN->SetPreferences();
CHECKPOINT;
if( !(m_iChangeMask & OPT_RESET_GAME) )
this->GoToNextScreen();
}
break;
default:
ScreenOptions::HandleScreenMessage( SM );
break;
}
}
2004-06-08 05:22:33 +00:00
/*
* (c) 2003-2004 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.
*/