From f7ebcc7c34c50ed705ff514cb9c2d817da3788e3 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Sat, 16 Jul 2005 05:26:07 +0000 Subject: [PATCH] add new profile select screen --- stepmania/src/ScreenOptionsSelectProfile.cpp | 217 +++++++++++++++++++ stepmania/src/ScreenOptionsSelectProfile.h | 52 +++++ 2 files changed, 269 insertions(+) create mode 100644 stepmania/src/ScreenOptionsSelectProfile.cpp create mode 100644 stepmania/src/ScreenOptionsSelectProfile.h diff --git a/stepmania/src/ScreenOptionsSelectProfile.cpp b/stepmania/src/ScreenOptionsSelectProfile.cpp new file mode 100644 index 0000000000..69f65bcca4 --- /dev/null +++ b/stepmania/src/ScreenOptionsSelectProfile.cpp @@ -0,0 +1,217 @@ +#include "global.h" + +#include "ScreenOptionsSelectProfile.h" +#include "ScreenMiniMenu.h" +#include "ProfileManager.h" +#include "ScreenTextEntry.h" +#include "ScreenPrompt.h" +#include "RageUtil.h" +#include "GameState.h" +#include "Profile.h" +#include "Character.h" +#include "OptionRowHandler.h" + +AutoScreenMessage( SM_BackFromEnterName ) +AutoScreenMessage( SM_BackFromDelete ) + + +class OptionRowHandlerSimple : public OptionRowHandler +{ +public: + GameCommand m_gc; + + virtual void Load( OptionRowDefinition &defOut, CString sParam ) + { + + } + virtual void ImportOption( const OptionRowDefinition &row, const vector &vpns, vector vbSelectedOut[NUM_PLAYERS] ) const + { + + } + virtual int ExportOption( const OptionRowDefinition &def, const vector &vpns, const vector vbSelected[NUM_PLAYERS] ) const + { + if( vbSelected[PLAYER_1][0] ) + m_gc.ApplyToAllPlayers(); + return 0; + } + virtual void GetIconTextAndGameCommand( const OptionRowDefinition &def, int iFirstSelection, CString &sIconTextOut, GameCommand &gcOut ) const + { + sIconTextOut = ""; + gcOut = m_gc; + } +}; + + +REGISTER_SCREEN_CLASS( ScreenOptionsSelectProfile ); +ScreenOptionsSelectProfile::ScreenOptionsSelectProfile( CString sName ) : + ScreenOptions( sName ) +{ + +} + +void ScreenOptionsSelectProfile::Init() +{ + ScreenOptions::Init(); + + + vector vDefs; + vector vHands; + + OptionRowDefinition def; + def.m_layoutType = LAYOUT_SHOW_ONE_IN_ROW; + def.m_selectType = SELECT_NONE; + def.m_bOneChoiceForAllPlayers = true; + def.m_bAllowThemeItems = false; + def.m_bAllowThemeTitles = false; + def.m_bAllowExplanation = false; + + int iIndex = 0; + + { + def.m_sName = ""; + def.m_vsChoices.clear(); + def.m_vsChoices.push_back( "Create New" ); + vDefs.push_back( def ); + OptionRowHandlerSimple *pHand = new OptionRowHandlerSimple; + m_OptionRowHandlers.push_back( pHand ); + GameCommand &gc = pHand->m_gc; + CString sCommand = "screen,ScreenOptionsEditProfile"; + gc.Load( iIndex++, ParseCommands(sCommand) ); + vHands.push_back( pHand ); + } + + vector vsProfileID; + PROFILEMAN->GetLocalProfileIDs( vsProfileID ); + FOREACH_CONST( CString, vsProfileID, s ) + { + Profile &pro = PROFILEMAN->GetLocalProfile( *s ); + def.m_sName = ""; + def.m_vsChoices.clear(); + def.m_vsChoices.push_back( pro.m_sDisplayName ); + vDefs.push_back( def ); + OptionRowHandlerSimple *pHand = new OptionRowHandlerSimple; + m_OptionRowHandlers.push_back( pHand ); + GameCommand &gc = pHand->m_gc; + CString sCommand = "profileid," + *s; + gc.Load( iIndex++, ParseCommands(sCommand) ); + vHands.push_back( pHand ); + } + + InitMenu( INPUTMODE_SHARE_CURSOR, vDefs, vHands ); +} + +ScreenOptionsSelectProfile::~ScreenOptionsSelectProfile() +{ + FOREACH( OptionRow*, m_pRows, r ) + (*r)->DetachHandler(); + FOREACH( OptionRowHandler*, m_OptionRowHandlers, h ) + SAFE_DELETE( *h ); + m_OptionRowHandlers.clear(); +} + +void ScreenOptionsSelectProfile::ImportOptions( int iRow, const vector &vpns ) +{ + OptionRow &row = *m_pRows[iRow]; +} + +void ScreenOptionsSelectProfile::ExportOptions( int iRow, const vector &vpns ) +{ + int iCurRow = m_iCurrentRow[0]; + if( iRow == iCurRow ) + { + OptionRow &row = *m_pRows[iRow]; + + bool bRowHasFocus[NUM_PLAYERS]; + ZERO( bRowHasFocus ); + row.ExportOptions( vpns, bRowHasFocus ); + } +} + +void ScreenOptionsSelectProfile::GoToNextScreen() +{ + SCREENMAN->SetNewScreen( "ScreenOptionsService" ); +} + +void ScreenOptionsSelectProfile::GoToPrevScreen() +{ + SCREENMAN->SetNewScreen( "ScreenOptionsService" ); +} + +void ScreenOptionsSelectProfile::HandleScreenMessage( const ScreenMessage SM ) +{ + if( SM == SM_BackFromEnterName ) + { + if( !ScreenTextEntry::s_bCancelledLast ) + { + ASSERT( ScreenTextEntry::s_sLastAnswer != "" ); // validate should have assured this + + CString sNewName = ScreenTextEntry::s_sLastAnswer; + ASSERT( GAMESTATE->m_sLastSelectedProfileID.empty() ) + + // create + bool bResult = PROFILEMAN->CreateLocalProfile( sNewName, GAMESTATE->m_sLastSelectedProfileID ); + if( bResult ) + SCREENMAN->SetNewScreen( "ScreenOptionsEditProfile" ); + else + ScreenPrompt::Prompt( SM_None, ssprintf("Error creating profile '%s'.", sNewName.c_str()) ); + } + } + + ScreenOptions::HandleScreenMessage( SM ); +} + +void ScreenOptionsSelectProfile::ProcessMenuStart( PlayerNumber pn, const InputEventType type ) +{ + int iRow = GetCurrentRow();; + OptionRow &row = *m_pRows[iRow]; + + if( iRow == 0 ) + { + vector vProfileIDs; + PROFILEMAN->GetLocalProfileIDs( vProfileIDs ); + if( vProfileIDs.size() >= MAX_NUM_LOCAL_PROFILES ) + { + CString sError = ssprintf( "You may only create up to %d profiles. You must delete an existing profile before creating a new one.", MAX_NUM_LOCAL_PROFILES ); + ScreenPrompt::Prompt( SM_None, sError ); + } + else + { + ScreenTextEntry::TextEntry( SM_BackFromEnterName, "Enter a name for a new profile.", PROFILEMAN->GetNewLocalProfileDefaultName(), PROFILE_MAX_DISPLAY_NAME_LENGTH, ProfileManager::ValidateLocalProfileName ); + } + } + else if( row.GetRowType() == OptionRow::ROW_EXIT ) + { + ScreenOptions::ProcessMenuStart( pn, type ); + } + else + { + // a profile row + ScreenOptions::BeginFadingOut(); + } +} + + +/* + * (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. + */ diff --git a/stepmania/src/ScreenOptionsSelectProfile.h b/stepmania/src/ScreenOptionsSelectProfile.h new file mode 100644 index 0000000000..4a641c29b7 --- /dev/null +++ b/stepmania/src/ScreenOptionsSelectProfile.h @@ -0,0 +1,52 @@ +#ifndef ScreenOptionsSelectProfile_H +#define ScreenOptionsSelectProfile_H + +#include "ScreenOptions.h" + +class ScreenOptionsSelectProfile : public ScreenOptions +{ +public: + ScreenOptionsSelectProfile( CString sName ); + virtual void Init(); + virtual ~ScreenOptionsSelectProfile(); + +protected: +private: + virtual void ImportOptions( int row, const vector &vpns ); + virtual void ExportOptions( int row, const vector &vpns ); + + virtual void GoToNextScreen(); + virtual void GoToPrevScreen(); + + virtual void HandleScreenMessage( const ScreenMessage SM ); + virtual void ProcessMenuStart( PlayerNumber pn, const InputEventType type ); + + vector m_OptionRowHandlers; +}; + +#endif + +/* + * (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. + */