Files
itgmania212121/stepmania/src/ScreenSelectGroup.cpp
T

278 lines
7.7 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 "ScreenSelectGroup.h"
#include "ScreenManager.h"
#include "PrefsManager.h"
#include "GameManager.h"
#include "RageLog.h"
#include "GameConstantsAndTypes.h"
#include "SongManager.h"
#include "AnnouncerManager.h"
2002-07-23 01:41:40 +00:00
#include "GameState.h"
2004-07-08 00:10:34 +00:00
#include "GameSoundManager.h"
#include "ThemeManager.h"
#include <map>
2003-04-13 21:17:14 +00:00
#include "ActorUtil.h"
#include "GameState.h"
2005-02-21 06:22:46 +00:00
#include "UnlockManager.h"
2003-11-07 20:10:38 +00:00
#include "MenuTimer.h"
#include "SongUtil.h"
2006-01-08 18:40:20 +00:00
#include "LocalizedString.h"
2006-08-17 18:52:46 +00:00
#include "song.h"
2003-03-10 01:28:53 +00:00
#define BANNER_WIDTH THEME->GetMetricF("ScreenSelectGroup","BannerWidth")
#define BANNER_HEIGHT THEME->GetMetricF("ScreenSelectGroup","BannerHeight")
2002-05-20 08:59:37 +00:00
2006-01-15 20:46:15 +00:00
REGISTER_SCREEN_CLASS( ScreenSelectGroup );
2006-01-08 19:49:14 +00:00
static LocalizedString ALL_MUSIC_STRING( "ScreenSelectGroup", "ALL MUSIC" );
void ScreenSelectGroup::Init()
{
2005-09-03 00:38:42 +00:00
ScreenWithMenuElements::Init();
ASSERT( PREFSMAN->m_bShowSelectGroup );
vector<Song*> aAllSongs;
SONGMAN->GetSongs( aAllSongs );
2002-08-18 23:20:18 +00:00
// Filter out Songs that can't be played by the current Style
2004-09-21 07:53:39 +00:00
for( int j=aAllSongs.size()-1; j>=0; j-- ) // foreach Song, back to front
2002-08-18 23:20:18 +00:00
{
bool DisplaySong = aAllSongs[j]->NormallyDisplayed();
2004-02-21 01:06:35 +00:00
if( UNLOCKMAN->SongIsLocked( aAllSongs[j] ) )
2004-01-24 22:55:59 +00:00
DisplaySong = false;
2004-06-28 07:26:00 +00:00
if( aAllSongs[j]->SongCompleteForStyle(GAMESTATE->GetCurrentStyle()) &&
DisplaySong )
continue;
2002-10-31 04:11:08 +00:00
aAllSongs.erase( aAllSongs.begin()+j, aAllSongs.begin()+j+1 );
2002-08-18 23:20:18 +00:00
}
// Add all group names to a map.
2006-01-22 01:00:06 +00:00
map<RString, RString> mapGroupNames;
2004-09-21 07:53:39 +00:00
for( unsigned i=0; i<aAllSongs.size(); i++ )
{
2006-01-22 01:00:06 +00:00
const RString& sGroupName = aAllSongs[i]->m_sGroupName;
mapGroupNames[ sGroupName ] = ""; // group name maps to nothing
2002-09-07 06:46:18 +00:00
}
// copy group names into a vector
2006-01-22 01:00:06 +00:00
vector<RString> asGroupNames;
2006-01-08 19:49:14 +00:00
asGroupNames.push_back( ALL_MUSIC_STRING ); // special group
2006-01-22 01:00:06 +00:00
for( map<RString, RString>::const_iterator iter = mapGroupNames.begin(); iter != mapGroupNames.end(); ++iter )
asGroupNames.push_back( iter->first );
// Add songs to the MusicList.
2003-10-19 19:59:11 +00:00
m_MusicList.Load();
2002-10-31 04:36:35 +00:00
for( unsigned g=0; g < asGroupNames.size(); g++ ) /* for each group */
2002-08-18 23:20:18 +00:00
{
2003-01-03 05:56:28 +00:00
vector<Song*> aSongsInGroup;
/* find all songs */
2004-09-21 07:53:39 +00:00
for( unsigned i=0; i<aAllSongs.size(); i++ ) // foreach Song
{
2002-08-24 20:36:29 +00:00
/* group 0 gets all songs */
2002-10-31 04:36:35 +00:00
if( g != 0 && aAllSongs[i]->m_sGroupName != asGroupNames[g] )
continue;
2002-10-31 04:23:39 +00:00
aSongsInGroup.push_back( aAllSongs[i] );
2002-08-18 23:20:18 +00:00
}
SongUtil::SortSongPointerArrayByTitle( aSongsInGroup );
m_MusicList.AddGroup();
m_MusicList.AddSongsToGroup(aSongsInGroup);
}
2002-05-20 08:59:37 +00:00
m_bChosen = false;
2003-04-12 06:16:12 +00:00
m_sprExplanation.SetName( "Explanation" );
2005-02-06 03:32:53 +00:00
m_sprExplanation.Load( THEME->GetPathG("ScreenSelectGroup","explanation") );
this->AddChild( &m_sprExplanation );
2002-05-20 08:59:37 +00:00
// these guys get loaded SetSong and TweenToSong
2003-04-12 06:16:12 +00:00
m_Banner.SetName( "Banner" );
m_Banner.ScaleToClipped( BANNER_WIDTH, BANNER_HEIGHT );
this->AddChild( &m_Banner );
2002-05-20 08:59:37 +00:00
2003-04-12 06:16:12 +00:00
m_sprFrame.SetName( "Frame" );
2005-02-06 03:32:53 +00:00
m_sprFrame.Load( THEME->GetPathG("ScreenSelectGroup","frame") );
this->AddChild( &m_sprFrame );
2003-04-12 06:16:12 +00:00
m_textNumber.SetName( "Number" );
2004-07-25 07:22:31 +00:00
m_textNumber.LoadFromFont( THEME->GetPathF(m_sName, "num songs") );
this->AddChild( &m_textNumber );
2003-04-12 06:16:12 +00:00
m_sprContents.SetName( "Contents" );
2005-02-06 03:32:53 +00:00
m_sprContents.Load( THEME->GetPathG("ScreenSelectGroup","contents") );
this->AddChild( &m_sprContents );
2002-05-20 08:59:37 +00:00
2003-04-12 06:16:12 +00:00
m_MusicList.SetName( "MusicList" );
this->AddChild( &m_MusicList );
2002-08-24 20:36:29 +00:00
2003-04-12 06:16:12 +00:00
m_GroupList.SetName( "GroupList" );
m_GroupList.Load( asGroupNames );
this->AddChild( &m_GroupList );
2002-05-20 08:59:37 +00:00
2005-09-03 00:37:57 +00:00
m_soundChange.Load( THEME->GetPathS("ScreenSelectGroup","change"), true );
2002-05-20 08:59:37 +00:00
2004-04-12 20:11:36 +00:00
SOUND->PlayOnceFromAnnouncer( "select group intro" );
2002-05-20 08:59:37 +00:00
AfterChange();
2002-08-24 20:36:29 +00:00
m_GroupList.SetSelection(0);
2002-05-20 08:59:37 +00:00
}
void ScreenSelectGroup::Input( const InputEventPlus &input )
2002-05-20 08:59:37 +00:00
{
LOG->Trace( "ScreenSelectGroup::Input()" );
2002-05-20 08:59:37 +00:00
if( IsTransitioning() )
2002-05-20 08:59:37 +00:00
return;
2006-11-21 20:03:28 +00:00
ScreenWithMenuElements::Input( input ); // default input handler
2002-05-20 08:59:37 +00:00
}
void ScreenSelectGroup::HandleScreenMessage( const ScreenMessage SM )
{
2006-02-24 00:20:41 +00:00
if( SM == SM_BeginFadingOut )
2002-05-20 08:59:37 +00:00
{
StartTransitioningScreen( SM_GoToNextScreen );
2004-05-08 06:43:06 +00:00
return;
2002-05-20 08:59:37 +00:00
}
2006-11-21 20:03:28 +00:00
ScreenWithMenuElements::HandleScreenMessage( SM );
2002-05-20 08:59:37 +00:00
}
void ScreenSelectGroup::AfterChange()
{
2002-08-24 20:36:29 +00:00
int sel = m_GroupList.GetSelection();
m_MusicList.SetGroupNo(sel);
2002-05-20 08:59:37 +00:00
2006-01-22 01:00:06 +00:00
RString sSelectedGroupName = m_GroupList.GetSelectionName();
2006-01-08 18:40:20 +00:00
if( sSelectedGroupName == ALL_MUSIC_STRING.GetValue() )
2003-03-09 00:55:49 +00:00
m_Banner.LoadAllMusic();
else
2005-06-23 08:05:09 +00:00
m_Banner.LoadFromSongGroup( sSelectedGroupName );
2002-05-20 08:59:37 +00:00
const int iNumSongs = m_MusicList.GetNumSongs();
m_textNumber.SetText( ssprintf("%d", iNumSongs) );
2002-05-20 08:59:37 +00:00
}
void ScreenSelectGroup::MenuLeft( const InputEventPlus &input )
2002-05-20 08:59:37 +00:00
{
MenuUp( input );
2002-05-20 08:59:37 +00:00
}
void ScreenSelectGroup::MenuRight( const InputEventPlus &input )
2002-05-20 08:59:37 +00:00
{
MenuDown( input );
2002-05-20 08:59:37 +00:00
}
void ScreenSelectGroup::MenuUp( const InputEventPlus &input )
2002-05-20 08:59:37 +00:00
{
if( m_bChosen )
return;
2002-08-24 20:36:29 +00:00
m_GroupList.Up();
2002-05-20 08:59:37 +00:00
AfterChange();
2005-09-03 00:37:57 +00:00
m_soundChange.Play();
2002-05-20 08:59:37 +00:00
}
void ScreenSelectGroup::MenuDown( const InputEventPlus &input )
2002-05-20 08:59:37 +00:00
{
if( m_bChosen )
return;
2002-08-24 20:36:29 +00:00
m_GroupList.Down();
2002-05-20 08:59:37 +00:00
AfterChange();
2005-09-03 00:37:57 +00:00
m_soundChange.Play();
2002-05-20 08:59:37 +00:00
}
void ScreenSelectGroup::MenuStart( const InputEventPlus &input )
2002-05-20 08:59:37 +00:00
{
2003-03-12 03:44:55 +00:00
if( m_bChosen )
return;
SCREENMAN->PlayStartSound();
m_MenuTimer->Stop();
2002-05-20 08:59:37 +00:00
m_bChosen = true;
GAMESTATE->m_pCurSong.Set( NULL );
2006-01-08 18:40:20 +00:00
GAMESTATE->m_sPreferredSongGroup.Set( m_GroupList.GetSelectionName()==ALL_MUSIC_STRING.GetValue() ? GROUP_ALL : m_GroupList.GetSelectionName() );
2002-05-20 08:59:37 +00:00
2005-06-24 06:06:16 +00:00
if( GAMESTATE->m_sPreferredSongGroup == GROUP_ALL )
2006-02-14 11:30:53 +00:00
SOUND->PlayOnceFromAnnouncer( "select group comment all music" );
2002-05-20 08:59:37 +00:00
else
2006-02-14 11:30:53 +00:00
SOUND->PlayOnceFromAnnouncer( "select group comment general" );
2002-05-20 08:59:37 +00:00
2005-10-14 02:31:55 +00:00
this->PostScreenMessage( SM_BeginFadingOut, 0 );
2002-05-20 08:59:37 +00:00
}
void ScreenSelectGroup::MenuBack( const InputEventPlus &input )
2002-05-20 08:59:37 +00:00
{
Cancel( SM_GoToPrevScreen );
2002-05-20 08:59:37 +00:00
}
2005-10-14 02:31:55 +00:00
void ScreenSelectGroup::TweenOffScreen()
2002-05-20 08:59:37 +00:00
{
2005-10-14 02:31:55 +00:00
ScreenWithMenuElements::TweenOffScreen();
2003-04-12 06:16:12 +00:00
OFF_COMMAND( m_sprExplanation );
OFF_COMMAND( m_sprFrame );
OFF_COMMAND( m_Banner );
OFF_COMMAND( m_textNumber );
OFF_COMMAND( m_sprContents );
OFF_COMMAND( m_MusicList );
OFF_COMMAND( m_GroupList );
m_MusicList.TweenOffScreen();
2002-08-24 20:36:29 +00:00
m_GroupList.TweenOffScreen();
2002-05-20 08:59:37 +00:00
}
2005-10-14 03:11:50 +00:00
void ScreenSelectGroup::TweenOnScreen()
2002-05-20 08:59:37 +00:00
{
2007-02-19 09:30:07 +00:00
LOAD_ALL_COMMANDS_AND_SET_XY_AND_ON_COMMAND( m_sprExplanation );
LOAD_ALL_COMMANDS_AND_SET_XY_AND_ON_COMMAND( m_sprFrame );
LOAD_ALL_COMMANDS_AND_SET_XY_AND_ON_COMMAND( m_Banner );
LOAD_ALL_COMMANDS_AND_SET_XY_AND_ON_COMMAND( m_textNumber );
LOAD_ALL_COMMANDS_AND_SET_XY_AND_ON_COMMAND( m_sprContents );
LOAD_ALL_COMMANDS_AND_SET_XY_AND_ON_COMMAND( m_MusicList );
LOAD_ALL_COMMANDS_AND_SET_XY_AND_ON_COMMAND( m_GroupList );
m_MusicList.TweenOnScreen();
2002-08-24 20:36:29 +00:00
m_GroupList.TweenOnScreen();
2005-10-14 03:11:50 +00:00
ScreenWithMenuElements::TweenOnScreen();
2002-05-20 08:59:37 +00:00
}
2004-06-08 05:22:33 +00:00
/*
* (c) 2001-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.
*/