Files
itgmania212121/stepmania/src/ScreenMiniMenu.cpp
T

196 lines
5.7 KiB
C++
Raw Normal View History

2003-02-18 23:15:38 +00:00
#include "global.h"
#include "ScreenMiniMenu.h"
#include "ScreenManager.h"
#include "GameConstantsAndTypes.h"
#include "ThemeManager.h"
#include "Foreach.h"
#include "ScreenDimensions.h"
2005-03-20 06:41:56 +00:00
#include "GameState.h"
2005-03-25 07:22:10 +00:00
#include "FontCharAliases.h"
2006-01-17 22:10:03 +00:00
#include "OptionRowHandler.h"
2003-02-19 05:46:09 +00:00
AutoScreenMessage( SM_GoToOK )
AutoScreenMessage( SM_GoToCancel )
2003-02-18 23:15:38 +00:00
bool ScreenMiniMenu::s_bCancelled = false;
2005-03-20 06:41:56 +00:00
int ScreenMiniMenu::s_iLastRowCode = -1;
vector<int> ScreenMiniMenu::s_viLastAnswers;
2003-02-18 23:15:38 +00:00
2006-02-04 18:36:44 +00:00
// Hooks for profiling
void PrepareToLoadScreen( const RString &sScreenName ) {}
void FinishedLoadingScreen() {}
/* Settings: */
namespace
{
2006-01-30 06:06:59 +00:00
const MenuDef* g_pMenuDef = NULL;
ScreenMessage g_SendOnOK;
ScreenMessage g_SendOnCancel;
};
2006-01-28 02:10:24 +00:00
void ScreenMiniMenu::MiniMenu( const MenuDef* pDef, ScreenMessage SM_SendOnOK, ScreenMessage SM_SendOnCancel, float fX, float fY )
2005-07-03 04:50:21 +00:00
{
2006-02-04 18:36:44 +00:00
PrepareToLoadScreen( pDef->sClassName );
g_pMenuDef = pDef;
g_SendOnOK = SM_SendOnOK;
g_SendOnCancel = SM_SendOnCancel;
SCREENMAN->AddNewScreenToTop( pDef->sClassName );
Screen *pNewScreen = SCREENMAN->GetTopScreen();
pNewScreen->SetXY( fX, fY );
2006-02-04 18:36:44 +00:00
FinishedLoadingScreen();
2005-07-03 04:50:21 +00:00
}
REGISTER_SCREEN_CLASS( ScreenMiniMenu );
2003-02-18 23:15:38 +00:00
2006-01-17 23:43:20 +00:00
void ScreenMiniMenu::BeginScreen()
{
ASSERT( g_pMenuDef != NULL );
LoadMenu( g_pMenuDef );
2006-01-30 07:29:49 +00:00
m_SMSendOnOK = g_SendOnOK;
m_SMSendOnCancel = g_SendOnCancel;
g_pMenuDef = NULL;
2006-01-17 23:43:20 +00:00
ScreenOptions::BeginScreen();
/* HACK: An OptionRow exits if a screen is set. ScreenMiniMenu is always pushed, so we
* don't set screens to load. Set a dummy screen, so ScreenOptions::GetNextScreenForSelection
* will know to move on. */
m_sNextScreen = "xxx";
}
void ScreenMiniMenu::LoadMenu( const MenuDef* pDef )
2005-03-20 06:41:56 +00:00
{
2005-07-14 04:59:06 +00:00
m_vMenuRows = pDef->rows;
2003-02-18 23:15:38 +00:00
2005-03-20 06:41:56 +00:00
// Convert from m_vMenuRows to vector<OptionRowDefinition>
2006-01-17 22:10:03 +00:00
vector<OptionRowHandler*> vHands;
2005-03-20 06:41:56 +00:00
for( unsigned r=0; r<m_vMenuRows.size(); r++ )
{
2006-01-17 22:10:03 +00:00
OptionRowHandler *pHand = OptionRowHandlerUtil::MakeNull();
2005-07-05 11:23:31 +00:00
const MenuRowDef &mr = m_vMenuRows[r];
2003-02-18 23:15:38 +00:00
2006-01-17 22:54:12 +00:00
pHand->m_Def.m_sName = mr.sName;
FontCharAliases::ReplaceMarkers( pHand->m_Def.m_sName ); // Allow special characters
2005-03-25 07:22:10 +00:00
2006-01-19 08:58:40 +00:00
pHand->m_Def.m_vEnabledForPlayers.clear();
if( mr.pfnEnabled? mr.pfnEnabled():mr.bEnabled )
2004-01-26 19:11:25 +00:00
{
2005-03-20 06:41:56 +00:00
FOREACH_EnabledPlayer( pn )
2006-01-17 22:54:12 +00:00
pHand->m_Def.m_vEnabledForPlayers.insert( pn );
2004-01-26 19:11:25 +00:00
}
2003-02-18 23:15:38 +00:00
2006-01-17 22:10:03 +00:00
pHand->m_Def.m_bOneChoiceForAllPlayers = true;
2006-01-17 22:54:12 +00:00
pHand->m_Def.m_selectType = SELECT_ONE;
pHand->m_Def.m_layoutType = LAYOUT_SHOW_ONE_IN_ROW;
pHand->m_Def.m_bExportOnChange = false;
2005-03-20 06:41:56 +00:00
2006-01-17 22:54:12 +00:00
pHand->m_Def.m_vsChoices = mr.choices;
2006-01-19 03:02:02 +00:00
// Each row must have at least one choice.
if( pHand->m_Def.m_vsChoices.empty() )
pHand->m_Def.m_vsChoices.push_back( "" );
2006-02-13 22:45:17 +00:00
pHand->m_Def.m_bAllowThemeTitle = mr.bThemeTitle;
2006-01-17 22:54:12 +00:00
pHand->m_Def.m_bAllowThemeItems = mr.bThemeItems;
2005-03-25 07:22:10 +00:00
2006-01-22 01:00:06 +00:00
FOREACH( RString, pHand->m_Def.m_vsChoices, c )
2005-03-25 07:22:10 +00:00
FontCharAliases::ReplaceMarkers( *c ); // Allow special characters
2006-01-17 22:42:57 +00:00
vHands.push_back( pHand );
2003-02-18 23:15:38 +00:00
}
2006-01-17 22:10:03 +00:00
ScreenOptions::InitMenu( vHands );
2003-02-18 23:15:38 +00:00
}
2005-07-29 22:52:36 +00:00
void ScreenMiniMenu::AfterChangeValueOrRow( PlayerNumber pn )
{
2005-07-29 22:52:36 +00:00
ScreenOptions::AfterChangeValueOrRow( pn );
vector<PlayerNumber> vpns;
vpns.push_back( GAMESTATE->m_MasterPlayerNumber );
2005-06-23 08:05:09 +00:00
for( unsigned i=0; i<m_pRows.size(); i++ )
ExportOptions( i, vpns );
{
int iCurRow = GetCurrentRow( pn );
s_iLastRowCode = m_vMenuRows[iCurRow].iRowCode;
}
2006-01-16 04:25:05 +00:00
// Changing one option can affect whether other options are available.
2005-06-23 08:05:09 +00:00
for( unsigned i=0; i<m_pRows.size(); i++ )
{
2006-01-16 04:25:05 +00:00
const MenuRowDef &mr = m_vMenuRows[i];
if( mr.pfnEnabled )
{
2006-01-16 04:25:05 +00:00
OptionRow &optrow = *m_pRows[i];
optrow.GetRowDef().m_vEnabledForPlayers.clear();
if( mr.pfnEnabled() )
optrow.GetRowDef().m_vEnabledForPlayers.insert( GAMESTATE->m_MasterPlayerNumber );
}
2006-02-03 10:02:14 +00:00
m_pRows[i]->UpdateEnabledDisabled();
}
}
2005-04-03 06:21:02 +00:00
void ScreenMiniMenu::ImportOptions( int r, const vector<PlayerNumber> &vpns )
2003-02-18 23:15:38 +00:00
{
2005-06-23 08:05:09 +00:00
OptionRow &optrow = *m_pRows[r];
2006-01-16 04:25:05 +00:00
const MenuRowDef &mr = m_vMenuRows[r];
2005-03-20 06:41:56 +00:00
if( !mr.choices.empty() )
optrow.SetOneSharedSelection( mr.iDefaultChoice );
2003-02-18 23:15:38 +00:00
}
2005-04-03 06:21:02 +00:00
void ScreenMiniMenu::ExportOptions( int r, const vector<PlayerNumber> &vpns )
2003-02-18 23:15:38 +00:00
{
2005-03-20 06:41:56 +00:00
s_viLastAnswers.resize( m_vMenuRows.size() );
2005-06-23 08:05:09 +00:00
s_viLastAnswers[r] = m_pRows[r]->GetOneSharedSelection( true );
2003-02-18 23:15:38 +00:00
}
void ScreenMiniMenu::HandleScreenMessage( const ScreenMessage SM )
2003-02-18 23:15:38 +00:00
{
if( SM == SM_GoToNextScreen )
{
s_bCancelled = false;
SCREENMAN->PopTopScreen( m_SMSendOnOK );
return;
}
else if( SM == SM_GoToPrevScreen )
{
s_bCancelled = true;
SCREENMAN->PopTopScreen( m_SMSendOnCancel );
return;
}
2003-02-18 23:15:38 +00:00
ScreenOptions::HandleScreenMessage( SM );
2003-02-18 23:15:38 +00:00
}
2004-06-08 05:22:33 +00:00
/*
* (c) 2003-2004 Chris Danford
* 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.
*/