From 5161efceaeb6985daca35b28504d44cbf34b3cef Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Wed, 13 Jul 2005 19:25:39 +0000 Subject: [PATCH] finish new profile screens --- stepmania/src/ScreenOptionsEditProfile.cpp | 197 +++++++++++++++++++++ stepmania/src/ScreenOptionsEditProfile.h | 50 ++++++ stepmania/src/ScreenSelectProfile.cpp | 172 +++++------------- stepmania/src/ScreenSelectProfile.h | 3 + 4 files changed, 297 insertions(+), 125 deletions(-) create mode 100644 stepmania/src/ScreenOptionsEditProfile.cpp create mode 100644 stepmania/src/ScreenOptionsEditProfile.h diff --git a/stepmania/src/ScreenOptionsEditProfile.cpp b/stepmania/src/ScreenOptionsEditProfile.cpp new file mode 100644 index 0000000000..54119e1b72 --- /dev/null +++ b/stepmania/src/ScreenOptionsEditProfile.cpp @@ -0,0 +1,197 @@ +#include "global.h" + +#include "ScreenOptionsEditProfile.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" + +AutoScreenMessage( SM_BackFromEnterName ) +AutoScreenMessage( SM_BackFromDelete ) + +enum EditProfileRow +{ + ROW_NAME, + ROW_CHARACTER, + ROW_DELETE +}; + +REGISTER_SCREEN_CLASS( ScreenOptionsEditProfile ); +ScreenOptionsEditProfile::ScreenOptionsEditProfile( CString sName ) : + ScreenOptions( sName ) +{ + +} + +void ScreenOptionsEditProfile::Init() +{ + ScreenOptions::Init(); + + + vector vDefs; + vector vHands; + + OptionRowDefinition def; + def.m_layoutType = LAYOUT_SHOW_ONE_IN_ROW; + def.m_bOneChoiceForAllPlayers = true; + def.m_bAllowThemeItems = false; + def.m_bAllowThemeTitles = false; + def.m_bAllowExplanation = false; + + Profile &pro = PROFILEMAN->GetLocalProfile( GAMESTATE->m_sLastSelectedProfileID ); + + { + def.m_sName = "Name"; + def.m_vsChoices.clear(); + CString s = pro.m_sDisplayName; + def.m_vsChoices.push_back( s ); + vDefs.push_back( def ); + vHands.push_back( NULL ); + } + + { + def.m_sName = "Character"; + def.m_vsChoices.clear(); + vector vpCharacters; + GAMESTATE->GetCharacters( vpCharacters ); + FOREACH_CONST( Character*, vpCharacters, c ) + def.m_vsChoices.push_back( (*c)->m_sName ); + vDefs.push_back( def ); + vHands.push_back( NULL ); + } + + { + def.m_sName = "Delete"; + def.m_vsChoices.clear(); + vDefs.push_back( def ); + vHands.push_back( NULL ); + } + + InitMenu( INPUTMODE_SHARE_CURSOR, vDefs, vHands ); +} + +ScreenOptionsEditProfile::~ScreenOptionsEditProfile() +{ + +} + +void ScreenOptionsEditProfile::ImportOptions( int iRow, const vector &vpns ) +{ + switch( iRow ) + { + case ROW_CHARACTER: + Profile &pro = PROFILEMAN->GetLocalProfile( GAMESTATE->m_sLastSelectedProfileID ); + OptionRow &row = *m_pRows[ROW_CHARACTER]; + row.SetOneSharedSelectionIfPresent( pro.m_sCharacter ); + break; + } +} + +void ScreenOptionsEditProfile::ExportOptions( int iRow, const vector &vpns ) +{ + +} + +void ScreenOptionsEditProfile::GoToNextScreen() +{ + SCREENMAN->SetNewScreen( "ScreenOptionsMenu" ); +} + +void ScreenOptionsEditProfile::GoToPrevScreen() +{ + SCREENMAN->SetNewScreen( "ScreenOptionsMenu" ); +} + +void ScreenOptionsEditProfile::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() ) + + // rename + bool bResult = PROFILEMAN->RenameLocalProfile( GAMESTATE->m_sLastSelectedProfileID, sNewName ); + if( bResult ) + SCREENMAN->SetNewScreen( m_sName ); // reload + else + ScreenPrompt::Prompt( SM_None, ssprintf("Error renaming profile '%s'.", sNewName.c_str()) ); + } + } + else if( SM == SM_BackFromDelete ) + { + if( ScreenPrompt::s_LastAnswer == ANSWER_YES ) + { + PROFILEMAN->DeleteLocalProfile( GAMESTATE->m_sLastSelectedProfileID ); + HandleScreenMessage( SM_GoToPrevScreen ); + } + } + + ScreenOptions::HandleScreenMessage( SM ); +} + +void ScreenOptionsEditProfile::ProcessMenuStart( PlayerNumber pn, const InputEventType type ) +{ + int iRow = GetCurrentRow();; + OptionRow &row = *m_pRows[iRow]; + + switch( iRow ) + { + case ROW_NAME: + { + CString sCurrentProfileName = PROFILEMAN->GetLocalProfile( GAMESTATE->m_sLastSelectedProfileID ).m_sDisplayName; + ScreenTextEntry::TextEntry( SM_BackFromEnterName, "Enter a name for a new profile.", sCurrentProfileName, PROFILE_MAX_DISPLAY_NAME_LENGTH, ProfileManager::ValidateLocalProfileName ); + } + break; + case ROW_CHARACTER: + { + /* + int iProfileIndex = iRow - 1; + int iThrowAway, iX, iY; + GetWidthXY( PLAYER_1, iRow, 0, iThrowAway, iX, iY ); + ScreenMiniMenu::MiniMenu( &g_ProfileContextMenu, SM_BackFromProfileContextMenu, SM_BackFromProfileContextMenu, (float)iX, (float)iY ); + */ + } + break; + case ROW_DELETE: + { + CString sCurrentProfileName = PROFILEMAN->GetLocalProfile( GAMESTATE->m_sLastSelectedProfileID ).m_sDisplayName; + CString sMessage = ssprintf( "Are you sure you want to delete the profile '%s'?", sCurrentProfileName.c_str() ); + ScreenPrompt::Prompt( SM_BackFromDelete, sMessage, PROMPT_YES_NO ); + } + break; + } +} + + +/* + * (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/ScreenOptionsEditProfile.h b/stepmania/src/ScreenOptionsEditProfile.h new file mode 100644 index 0000000000..5ed8d7f6de --- /dev/null +++ b/stepmania/src/ScreenOptionsEditProfile.h @@ -0,0 +1,50 @@ +#ifndef ScreenOptionsEditProfile_H +#define ScreenOptionsEditProfile_H + +#include "ScreenOptions.h" + +class ScreenOptionsEditProfile : public ScreenOptions +{ +public: + ScreenOptionsEditProfile( CString sName ); + virtual void Init(); + virtual ~ScreenOptionsEditProfile(); + +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 ); +}; + +#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. + */ diff --git a/stepmania/src/ScreenSelectProfile.cpp b/stepmania/src/ScreenSelectProfile.cpp index eb18614d28..4e5a079708 100644 --- a/stepmania/src/ScreenSelectProfile.cpp +++ b/stepmania/src/ScreenSelectProfile.cpp @@ -10,55 +10,13 @@ #include "Profile.h" AutoScreenMessage( SM_BackFromEnterName ) -AutoScreenMessage( SM_BackFromProfileContextMenu ) AutoScreenMessage( SM_BackFromDelete ) -const int PROFILE_MAX_NAME_LENGTH = 64; - -static CString GetLastSelectedProfileName() -{ - Profile &pro = PROFILEMAN->GetLocalProfileEditableData( GAMESTATE->m_sLastSelectedProfileID ); - return pro.m_sDisplayName; -} - -static bool ValidateProfileName( const CString &sAnswer, CString &sErrorOut ) -{ - const CString &sCurrentProfileOldName = GetLastSelectedProfileName(); - - vector vsUsedNames; - PROFILEMAN->GetLocalProfileDisplayNames( vsUsedNames ); - bool bAlreadyAProfileWithThisName = find( vsUsedNames.begin(), vsUsedNames.end(), sAnswer ) != vsUsedNames.end(); - - if( sAnswer == "" ) - { - sErrorOut = "Profile name cannot be blank."; - return false; - } - else if( sAnswer == sCurrentProfileOldName ) - { - return true; - } - else if( bAlreadyAProfileWithThisName ) - { - sErrorOut = "There is already another profile with this name. Please choose a different name."; - return false; - } - - return true; -} - -enum ContextMenuAnswer -{ - A_EDIT, - A_RENAME, - A_DELETE, - A_CANCEL, -}; - REGISTER_SCREEN_CLASS( ScreenSelectProfile ); ScreenSelectProfile::ScreenSelectProfile( CString sName ) : - ScreenSelectMaster( sName ) + ScreenSelectMaster( sName ), + NEXT_SCREEN( sName, "NextScreen" ) { } @@ -67,22 +25,21 @@ void ScreenSelectProfile::Init() { // Fill m_aGameCommands overriding whatever is in metrics GameCommand gc; + int iIndex = 0; m_aGameCommands.clear(); - gc.m_sName = "create"; + gc.Load( iIndex++, ParseCommands("name,create") ); m_aGameCommands.push_back( gc ); vector vProfileIDs; PROFILEMAN->GetLocalProfileIDs( vProfileIDs ); FOREACH_CONST( CString, vProfileIDs, s ) { - gc.m_sName = "profile"; - gc.m_sProfileID = *s; + gc.Load( iIndex++, ParseCommands("name,profile;profileid," + *s + ";screen," + NEXT_SCREEN.GetValue()) ); m_aGameCommands.push_back( gc ); } - gc.m_sName = "exit"; - gc.m_sProfileID = ""; + gc.Load( iIndex++, ParseCommands("name,exit") ); m_aGameCommands.push_back( gc ); @@ -94,6 +51,29 @@ ScreenSelectProfile::~ScreenSelectProfile() } +bool ScreenSelectProfile::ProcessMenuStart( PlayerNumber pn ) +{ + int iChoice = m_iChoice[GetSharedPlayer()]; + + if( iChoice == 0 ) // "create" + { + 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 ); + } + return false; + } + + return true; +} + void ScreenSelectProfile::HandleScreenMessage( const ScreenMessage SM ) { if( SM == SM_BackFromEnterName ) @@ -103,95 +83,37 @@ void ScreenSelectProfile::HandleScreenMessage( const ScreenMessage SM ) ASSERT( ScreenTextEntry::s_sLastAnswer != "" ); // validate should have assured this CString sNewName = ScreenTextEntry::s_sLastAnswer; - if( GAMESTATE->m_sLastSelectedProfileID.empty() ) - { - // create - bool bResult = PROFILEMAN->CreateLocalProfile( sNewName ); - if( bResult ) - SCREENMAN->SetNewScreen( m_sName ); // reload - else - ScreenPrompt::Prompt( SM_None, ssprintf("Error creating profile '%s'.", sNewName.c_str()) ); - } + ASSERT( GAMESTATE->m_sLastSelectedProfileID.empty() ) + + // create + bool bResult = PROFILEMAN->CreateLocalProfile( sNewName ); + if( bResult ) + SCREENMAN->SetNewScreen( m_sName ); // reload else - { - // rename - bool bResult = PROFILEMAN->RenameLocalProfile( GAMESTATE->m_sLastSelectedProfileID, sNewName ); - if( bResult ) - SCREENMAN->SetNewScreen( m_sName ); // reload - else - ScreenPrompt::Prompt( SM_None, ssprintf("Error renaming profile '%s'.", sNewName.c_str()) ); - } + ScreenPrompt::Prompt( SM_None, ssprintf("Error creating profile '%s'.", sNewName.c_str()) ); } } - else if( SM == SM_BackFromProfileContextMenu ) + else if( SM == SM_GoToNextScreen ) { - if( !ScreenMiniMenu::s_bCancelled ) + int iSelection = GetSelectionIndex( PLAYER_1 ); + + vector vsProfileID; + PROFILEMAN->GetLocalProfileIDs( vsProfileID ); + if( iSelection == 0 || iSelection == vsProfileID.size()+1 ) { - switch( ScreenMiniMenu::s_iLastRowCode ) - { - default: - ASSERT(0); - case A_EDIT: - SCREENMAN->SetNewScreen( "ScreenOptionsEditProfile" ); - break; - case A_RENAME: - { - ScreenTextEntry::TextEntry( SM_BackFromEnterName, "Enter a name for a new profile.", GetLastSelectedProfileName(), PROFILE_MAX_NAME_LENGTH, ValidateProfileName ); - } - break; - case A_DELETE: - { - CString sMessage = ssprintf( "Are you sure you want to delete the profile '%s'?", GetLastSelectedProfileName().c_str() ); - ScreenPrompt::Prompt( SM_BackFromDelete, sMessage, PROMPT_YES_NO ); - } - break; - case A_CANCEL: - SCREENMAN->PlayInvalidSound(); - break; - } + GAMESTATE->m_sLastSelectedProfileID = ""; } - } - else if( SM == SM_BackFromDelete ) - { - if( ScreenPrompt::s_LastAnswer == ANSWER_YES ) + else { - PROFILEMAN->DeleteLocalProfile( GAMESTATE->m_sLastSelectedProfileID ); - SCREENMAN->SetNewScreen( m_sName ); // reload + GAMESTATE->m_sLastSelectedProfileID = m_aGameCommands[iSelection].m_sProfileID; + ASSERT( !GAMESTATE->m_sLastSelectedProfileID.empty() ); } } + ScreenSelectMaster::HandleScreenMessage( SM ); } -/* -void ScreenSelectProfile::ProcessMenuStart( PlayerNumber pn, const InputEventType type ) -{ - int iRow = GetCurrentRow();; - OptionRow &row = *m_pRows[iRow]; - - if( iRow == 0 ) // "create new" - { - s_sLastSelectedProfileID = ""; - ScreenTextEntry::TextEntry( SM_BackFromEnterName, "Enter a name for a new profile.", PROFILEMAN->GetNewProfileDefaultName(), PROFILE_MAX_NAME_LENGTH, ValidateProfileName ); - } - else if( row.GetRowType() == OptionRow::ROW_EXIT ) - { - s_sLastSelectedProfileID = ""; - ScreenOptions::ProcessMenuStart( pn, type ); - } - else - { - int iProfileIndex = iRow - 1; - vector vsProfileIDs; - PROFILEMAN->GetLocalProfileIDs( vsProfileIDs ); - s_sLastSelectedProfileID = vsProfileIDs[ iProfileIndex ]; - int iThrowAway, iX, iY; - GetWidthXY( PLAYER_1, iRow, 0, iThrowAway, iX, iY ); - ScreenMiniMenu::MiniMenu( &g_ProfileContextMenu, SM_BackFromProfileContextMenu, SM_BackFromProfileContextMenu, (float)iX, (float)iY ); - } -} -*/ - /* * (c) 2003-2004 Chris Danford * All rights reserved. diff --git a/stepmania/src/ScreenSelectProfile.h b/stepmania/src/ScreenSelectProfile.h index 29c1d9c2b7..c1a0b8111a 100644 --- a/stepmania/src/ScreenSelectProfile.h +++ b/stepmania/src/ScreenSelectProfile.h @@ -12,6 +12,9 @@ public: protected: virtual void HandleScreenMessage( const ScreenMessage SM ); + virtual bool ProcessMenuStart( PlayerNumber pn ); + + ThemeMetric NEXT_SCREEN; }; #endif