diff --git a/stepmania/src/GroupList.cpp b/stepmania/src/GroupList.cpp new file mode 100644 index 0000000000..add1f4af73 --- /dev/null +++ b/stepmania/src/GroupList.cpp @@ -0,0 +1,175 @@ +#include "stdafx.h" +#include "GroupList.h" +#include "ThemeManager.h" +#include "SongManager.h" + +#define BUTTON_X THEME->GetMetricF("SelectGroup","ButtonX") +#define BUTTON_START_Y THEME->GetMetricF("SelectGroup","ButtonStartY") +#define BUTTON_SPACING_Y THEME->GetMetricF("SelectGroup","ButtonSpacingY") +#define BUTTON_SELECTED_X THEME->GetMetricF("SelectGroup","ButtonSelectedX") + +GroupList::GroupList() +{ + m_iSelection = m_iTop = 0; +} + +void GroupList::DoneAddingGroups() +{ + int i; + + for( i=0; iGetPathTo("Graphics","select group button") ); + m_sprButton[i].SetXY( BUTTON_X, BUTTON_START_Y + i*BUTTON_SPACING_Y ); + this->AddSubActor( &m_sprButton[i] ); + this->AddSubActor( &m_screenLabels[i] ); + } + + for( i=0; iGetPathTo("Fonts","normal") ); + m_screenLabels[i].SetXY( BUTTON_X, BUTTON_START_Y + i*BUTTON_SPACING_Y ); + m_screenLabels[i].SetZoom( 0.8f ); + m_screenLabels[i].SetShadowLength( 2 ); + + CString sGroupName = m_textLabels[i]; + } + + SetLabels(); + AfterChange(); +} + +void GroupList::SetLabels() +{ + for( int i=0; iShortenGroupName( label ) ); + + if( m_iTop+i == 0 ) m_screenLabels[i].TurnRainbowOn(); + else { + m_screenLabels[i].TurnRainbowOff(); + m_screenLabels[i].SetDiffuseColor( SONGMAN->GetGroupColor(label) ); + } + } +} + +void GroupList::BeforeChange() +{ + int iSel = m_iSelection-m_iTop; + + m_sprButton[iSel].BeginTweening( 0.2f ); + m_sprButton[iSel].SetTweenX( BUTTON_X ); + m_sprButton[iSel].SetEffectNone(); + + m_screenLabels[iSel].BeginTweening( 0.2f ); + m_screenLabels[iSel].SetTweenX( BUTTON_X ); + m_screenLabels[iSel].SetEffectNone(); +} + + +void GroupList::AfterChange() +{ + int iSel = m_iSelection-m_iTop; + + m_sprButton[iSel].BeginTweening( 0.2f ); + m_sprButton[iSel].SetTweenX( BUTTON_SELECTED_X ); + m_sprButton[iSel].SetEffectGlowing(); + + m_screenLabels[iSel].BeginTweening( 0.2f ); + m_screenLabels[iSel].SetTweenX( BUTTON_SELECTED_X ); + m_screenLabels[iSel].SetEffectGlowing(); +} + +void GroupList::Up() +{ + BeforeChange(); + + if( m_iSelection == 0 ) + SetSelection(m_textLabels.GetSize()-1); + else + SetSelection(m_iSelection-1); + + AfterChange(); +} + +void GroupList::Down() +{ + BeforeChange(); + + SetSelection((m_iSelection+1) % m_textLabels.GetSize()); + + AfterChange(); +} + +void GroupList::AddGroup(CString name) +{ + m_textLabels.Add(name); +} + +void GroupList::SetSelection( int sel ) +{ + BeforeChange(); + + if( sel == m_iSelection ) ; + else if( sel == m_iSelection+1 ) { + if( m_iSelection >= MAX_GROUPS_ONSCREEN/2 ) + m_iTop++; + } else if( sel == m_iSelection-1 ) { + if(m_iSelection < m_textLabels.GetSize() - MAX_GROUPS_ONSCREEN/2) + m_iTop--; + } else { + /* We're jumping somewhere else; just put the top somewhere + * reasonable. */ + m_iTop = sel - MAX_GROUPS_ONSCREEN/2; + } + + m_iSelection=sel; + m_iTop = clamp( m_iTop, 0, m_textLabels.GetSize()-MAX_GROUPS_ONSCREEN ); + + /* The current selection must always be visible. */ + ASSERT( m_iTop <= m_iSelection ); + ASSERT( m_iTop+MAX_GROUPS_ONSCREEN > m_iSelection ); + + SetLabels(); + AfterChange(); +} + + +void GroupList::TweenOnScreen() +{ + for( int i=0; i m_textLabels; + + /* Currently selected label. */ + int m_iSelection; + /* Label that's currently at the top of the screen. */ + int m_iTop; + + void BeforeChange(); + void AfterChange(); + void SetLabels(); + +public: + GroupList(); + + void SetSelection(int sel); + int GetSelection() const { return m_iSelection; } + CString GetSelectionName() const { return m_textLabels[m_iSelection]; } + void Up(); + void Down(); + void AddGroup(CString name); + void DoneAddingGroups(); + void TweenOffScreen(); + void TweenOnScreen(); +}; + +#endif \ No newline at end of file diff --git a/stepmania/src/ScreenSelectGroup.cpp b/stepmania/src/ScreenSelectGroup.cpp index 7c768fa70a..1a45903b14 100644 --- a/stepmania/src/ScreenSelectGroup.cpp +++ b/stepmania/src/ScreenSelectGroup.cpp @@ -34,10 +34,6 @@ #define NUMBER_Y THEME->GetMetricF("SelectGroup","NumberY") #define EXPLANATION_X THEME->GetMetricF("SelectGroup","ExplanationX") #define EXPLANATION_Y THEME->GetMetricF("SelectGroup","ExplanationY") -#define BUTTON_X THEME->GetMetricF("SelectGroup","ButtonX") -#define BUTTON_SELECTED_X THEME->GetMetricF("SelectGroup","ButtonSelectedX") -#define BUTTON_START_Y THEME->GetMetricF("SelectGroup","ButtonStartY") -#define BUTTON_SPACING_Y THEME->GetMetricF("SelectGroup","ButtonSpacingY") #define CONTENTS_X THEME->GetMetricF("SelectGroup","ContentsX") #define CONTENTS_Y THEME->GetMetricF("SelectGroup","ContentsY") @@ -89,27 +85,27 @@ ScreenSelectGroup::ScreenSelectGroup() for( i=0; im_sGroupName ] = ""; - // Read group names back out into an m_asGroupNames - m_asGroupNames.Add( "ALL MUSIC" ); + CStringArray asGroupNames; + + // Read group names back out into asGroupNames for( POSITION pos = mapGroupToNothing.GetStartPosition(); pos != NULL; ) { CString sGroupName, sValue; mapGroupToNothing.GetNextAssoc( pos, sGroupName, sValue ); - m_asGroupNames.Add( sGroupName ); - - if( m_asGroupNames.GetSize() == MAX_GROUPS-1 ) - break; // stop adding + asGroupNames.Add( sGroupName ); } - SortCStringArray( m_asGroupNames, true ); + SortCStringArray( asGroupNames, true ); + asGroupNames.InsertAt(0, "ALL MUSIC" ); // Add songs to the MusicList. - for( int j=0; j aSongsInGroup; /* find all songs */ for( i=0; im_sGroupName != m_asGroupNames[j] ) + /* group 0 gets all songs */ + if( j != 0 && aAllSongs[i]->m_sGroupName != asGroupNames[j] ) continue; aSongsInGroup.Add( aAllSongs[i] ); @@ -121,7 +117,6 @@ ScreenSelectGroup::ScreenSelectGroup() m_MusicList.AddSongsToGroup(aSongsInGroup); } - m_iSelection = 0; m_bChosen = false; m_Menu.Load( @@ -156,26 +151,12 @@ ScreenSelectGroup::ScreenSelectGroup() this->AddSubActor( &m_sprContents ); this->AddSubActor( &m_MusicList ); + + for( i=0; i < asGroupNames.GetSize(); ++i ) + m_GroupList.AddGroup( asGroupNames[i] ); + m_GroupList.DoneAddingGroups(); + this->AddSubActor( &m_GroupList ); - for( i=0; iGetPathTo("Graphics","select group button") ); - m_sprButton[i].SetXY( BUTTON_X, BUTTON_START_Y + i*BUTTON_SPACING_Y ); - this->AddSubActor( &m_sprButton[i] ); - - m_textLabel[i].LoadFromFont( THEME->GetPathTo("Fonts","normal") ); - m_textLabel[i].SetXY( BUTTON_X, BUTTON_START_Y + i*BUTTON_SPACING_Y ); - m_textLabel[i].SetText( SONGMAN->ShortenGroupName( sGroupName ) ); - m_textLabel[i].SetZoom( 0.8f ); - m_textLabel[i].SetShadowLength( 2 ); - - if( i == 0 ) m_textLabel[i].TurnRainbowOn(); - else m_textLabel[i].SetDiffuseColor( SONGMAN->GetGroupColor(sGroupName) ); - - this->AddSubActor( &m_textLabel[i] ); - } m_soundChange.Load( THEME->GetPathTo("Sounds","select group change") ); m_soundSelect.Load( THEME->GetPathTo("Sounds","menu start") ); @@ -192,6 +173,7 @@ ScreenSelectGroup::ScreenSelectGroup() m_Menu.TweenOnScreenFromMenu( SM_None ); TweenOnScreen(); AfterChange(); + m_GroupList.SetSelection(0); } @@ -238,34 +220,12 @@ void ScreenSelectGroup::HandleScreenMessage( const ScreenMessage SM ) } } -void ScreenSelectGroup::BeforeChange() -{ - int iSel = m_iSelection; - - m_sprButton[iSel].BeginTweening( 0.2f ); - m_sprButton[iSel].SetTweenX( BUTTON_X ); - m_sprButton[iSel].SetEffectNone(); - - m_textLabel[iSel].BeginTweening( 0.2f ); - m_textLabel[iSel].SetTweenX( BUTTON_X ); - m_textLabel[iSel].SetEffectNone(); -} - void ScreenSelectGroup::AfterChange() { - int iSel = m_iSelection; + int sel = m_GroupList.GetSelection(); + m_MusicList.SetGroupNo(sel); - m_sprButton[iSel].BeginTweening( 0.2f ); - m_sprButton[iSel].SetTweenX( BUTTON_SELECTED_X ); - m_sprButton[iSel].SetEffectGlowing(); - - m_textLabel[iSel].BeginTweening( 0.2f ); - m_textLabel[iSel].SetTweenX( BUTTON_SELECTED_X ); - m_textLabel[iSel].SetEffectGlowing(); - - m_MusicList.SetGroupNo(m_iSelection); - - CString sSelectedGroupName = m_asGroupNames[m_iSelection]; + CString sSelectedGroupName = m_GroupList.GetSelectionName(); CString sGroupBannerPath; if( 0 == stricmp(sSelectedGroupName, "ALL MUSIC") ) @@ -297,11 +257,7 @@ void ScreenSelectGroup::MenuUp( const PlayerNumber p ) if( m_bChosen ) return; - BeforeChange(); - - m_iSelection = m_iSelection-1 % m_asGroupNames.GetSize(); - if( m_iSelection < 0 ) - m_iSelection += min( m_asGroupNames.GetSize(), MAX_GROUPS ); + m_GroupList.Up(); AfterChange(); @@ -314,9 +270,7 @@ void ScreenSelectGroup::MenuDown( const PlayerNumber p ) if( m_bChosen ) return; - BeforeChange(); - - m_iSelection = (m_iSelection+1) % min( m_asGroupNames.GetSize(), MAX_GROUPS ); + m_GroupList.Down(); AfterChange(); @@ -329,7 +283,7 @@ void ScreenSelectGroup::MenuStart( const PlayerNumber p ) m_bChosen = true; GAMESTATE->m_pCurSong = NULL; - GAMESTATE->m_sPreferredGroup = m_asGroupNames[m_iSelection]; + GAMESTATE->m_sPreferredGroup = m_GroupList.GetSelectionName(); if( 0 == stricmp(GAMESTATE->m_sPreferredGroup, "All Music") ) SOUND->PlayOnceStreamedFromDir( ANNOUNCER->GetPathTo(ANNOUNCER_SELECT_GROUP_COMMENT_ALL_MUSIC) ); @@ -366,26 +320,9 @@ void ScreenSelectGroup::TweenOffScreen() m_sprContents.BeginTweeningQueued( 0.7f ); m_sprContents.BeginTweeningQueued( 0.5f, TWEEN_BIAS_END ); m_sprContents.SetTweenY( CONTENTS_Y+400 ); - m_MusicList.TweenOffScreen(); - - for( i=0; i + + + +