From 352dc15d49c60fb24e3254a95630d7d5468e4b5b Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Wed, 18 Jun 2003 00:10:52 +0000 Subject: [PATCH] GroupList tweening --- stepmania/Themes/default/metrics.ini | 5 + stepmania/src/GroupList.cpp | 172 ++++++++++++++++++--------- stepmania/src/GroupList.h | 18 +-- 3 files changed, 129 insertions(+), 66 deletions(-) diff --git a/stepmania/Themes/default/metrics.ini b/stepmania/Themes/default/metrics.ini index 8403dac485..cd10860f18 100644 --- a/stepmania/Themes/default/metrics.ini +++ b/stepmania/Themes/default/metrics.ini @@ -491,6 +491,11 @@ SpacingX=0 SpacingY=28 GainFocusCommand=stoptweening;glowshift;effectperiod,0.5;linear,0.2;x,-40 LoseFocusCommand=stoptweening;stopeffect;linear,0.2;x,0 +HideItemCommand=stoptweening;linear,0.2;diffusealpha,0 +ShowItemCommand=stoptweening;linear,0.2;diffusealpha,1;zoom,1.0; +# This just selects the type of tweening used for scrolling the list; it shouldn't actually +# queue any commands. +ScrollTweenCommand=stoptweening;linear,0.2; [MusicList] NumColumns=4 diff --git a/stepmania/src/GroupList.cpp b/stepmania/src/GroupList.cpp index b1254d4727..bea712c6eb 100644 --- a/stepmania/src/GroupList.cpp +++ b/stepmania/src/GroupList.cpp @@ -2,6 +2,7 @@ #include "GroupList.h" #include "ThemeManager.h" #include "SongManager.h" +#include "RageLog.h" /* If this actor is used anywhere other than SelectGroup, we * can add a setting that changes which metric group we pull @@ -10,75 +11,122 @@ #define START_Y THEME->GetMetricF("GroupList","StartY") #define SPACING_X THEME->GetMetricF("GroupList","SpacingX") #define SPACING_Y THEME->GetMetricF("GroupList","SpacingY") +#define SCROLL_TWEEN_COMMAND THEME->GetMetric ("GroupList","ScrollTweenCommand") #define GAIN_FOCUS_COMMAND THEME->GetMetric ("GroupList","GainFocusCommand") #define LOSE_FOCUS_COMMAND THEME->GetMetric ("GroupList","LoseFocusCommand") +#define HIDE_ITEM_COMMAND THEME->GetMetric ("GroupList","HideItemCommand") +#define SHOW_ITEM_COMMAND THEME->GetMetric ("GroupList","ShowItemCommand") +const int MAX_GROUPS_ONSCREEN = 7; GroupList::GroupList() { m_iSelection = m_iTop = 0; } +GroupList::~GroupList() +{ + for( unsigned i = 0; i < m_Frames.size(); ++i ) + { + delete m_Frames[i]; + delete m_sprButtons[i]; + delete m_screenLabels[i]; + } +} + + +bool GroupList::ItemIsOnScreen( int n ) const +{ + const int offset = n - m_iTop; + return offset >= 0 && offset < MAX_GROUPS_ONSCREEN; +} + void GroupList::Load( const CStringArray& asGroupNames ) { m_asLabels = asGroupNames; - for( unsigned i=0; iAddChild( &m_Frame ); + + for( unsigned i=0; i < m_asLabels.size(); i++ ) { - float fX = START_X + i*SPACING_X; - float fY = START_Y + i*SPACING_Y; + ActorFrame *frame = new ActorFrame; + frame->SetXY( START_X + i*SPACING_X, START_Y + i*SPACING_Y ); + m_Frames.push_back(frame); + m_Frame.AddChild( frame ); - m_sprButton[i].Load( THEME->GetPathToG("GroupList bar") ); - m_sprButton[i].SetXY( fX, fY ); - this->AddChild( &m_sprButton[i] ); + Sprite *spr = new Sprite; + m_sprButtons.push_back(spr); + spr->Load( THEME->GetPathToG("GroupList bar") ); + frame->AddChild( spr ); - m_screenLabels[i].LoadFromFont( THEME->GetPathToF("GroupList label") ); - m_screenLabels[i].SetXY( fX, fY ); - m_screenLabels[i].SetShadowLength( 2 ); - this->AddChild( &m_screenLabels[i] ); + BitmapText *text = new BitmapText; + m_screenLabels.push_back(text); + text->LoadFromFont( THEME->GetPathToF("GroupList label") ); + text->SetShadowLength( 2 ); + text->SetText( SONGMAN->ShortenGroupName( asGroupNames[i] ) ); + frame->AddChild( text ); + + if( i == 0 ) + text->TurnRainbowOn(); + else { + text->TurnRainbowOff(); + text->SetDiffuse( SONGMAN->GetGroupColor(asGroupNames[i]) ); + } + + m_bHidden.push_back( ItemIsOnScreen(i) ); + + ResetTextSize( i ); } - SetLabels(); AfterChange(); } -void GroupList::SetLabels() +void GroupList::ResetTextSize( int i ) { - for( unsigned i=0; iShortenGroupName( label ) ); - float fTextWidth = (float)m_screenLabels[i].GetWidestLineWidthInSourcePixels(); - float fButtonWidth = m_sprButton[i].GetZoomedWidth(); + BitmapText *text = m_screenLabels[i]; + const float fTextWidth = (float)text->GetWidestLineWidthInSourcePixels(); + const float fButtonWidth = m_sprButtons[i]->GetZoomedWidth(); - float fZoom = fButtonWidth/fTextWidth; - fZoom = min( fZoom, 0.8f ); - m_screenLabels[i].SetZoomX( fZoom ); - m_screenLabels[i].SetZoomY( 0.8f ); - - if( m_iTop+i == 0 ) m_screenLabels[i].TurnRainbowOn(); - else { - m_screenLabels[i].TurnRainbowOff(); - m_screenLabels[i].SetDiffuse( SONGMAN->GetGroupColor(label) ); - } - } + float fZoom = fButtonWidth/fTextWidth; + fZoom = min( fZoom, 0.8f ); + + text->SetZoomX( fZoom ); + text->SetZoomY( 0.8f ); } void GroupList::BeforeChange() { - int iSel = m_iSelection-m_iTop; - - m_sprButton[iSel].Command( LOSE_FOCUS_COMMAND ); - m_screenLabels[iSel].Command( LOSE_FOCUS_COMMAND ); + m_Frames[m_iSelection]->Command( LOSE_FOCUS_COMMAND ); } void GroupList::AfterChange() { - int iSel = m_iSelection-m_iTop; + m_Frame.StopTweening(); + m_Frame.Command( SCROLL_TWEEN_COMMAND ); + m_Frame.SetY( -m_iTop*SPACING_Y ); + + m_Frames[m_iSelection]->Command( GAIN_FOCUS_COMMAND ); + for( int i=0; i < (int) m_asLabels.size(); i++ ) + { + const bool IsHidden = !ItemIsOnScreen(i); + const bool WasHidden = m_bHidden[i]; + + if( IsHidden && !WasHidden ) + { + m_sprButtons[i]->Command( HIDE_ITEM_COMMAND ); + m_screenLabels[i]->Command( HIDE_ITEM_COMMAND ); + } + else if( !IsHidden && WasHidden ) + { + m_sprButtons[i]->Command( SHOW_ITEM_COMMAND ); + m_screenLabels[i]->Command( SHOW_ITEM_COMMAND ); + ResetTextSize( i ); + } + + m_bHidden[i] = IsHidden; + } - m_sprButton[iSel].Command( GAIN_FOCUS_COMMAND ); - m_screenLabels[iSel].Command( GAIN_FOCUS_COMMAND ); } void GroupList::Up() @@ -120,45 +168,51 @@ void GroupList::SetSelection( unsigned sel ) ASSERT( m_iTop <= m_iSelection ); ASSERT( m_iTop+MAX_GROUPS_ONSCREEN > m_iSelection ); - SetLabels(); AfterChange(); } +/* either tweened off screen (to come on screen), + tweened off screen (invisible), + onscreen (unselected), + or onscreen (selected) + + coming on/ofscreen is internal + always invis<->unselected<->selected + */ + void GroupList::TweenOnScreen() { - for( unsigned i=0; iSetX( 400 ); + m_Frames[i]->BeginTweening( 0.1f*offset, TWEEN_BOUNCE_END ); + m_Frames[i]->BeginTweening( 0.2f, TWEEN_BOUNCE_END ); + m_Frames[i]->SetX( 0 ); - m_screenLabels[i].SetX( 400 ); - m_screenLabels[i].BeginTweening( 0.1f*i, TWEEN_BOUNCE_END ); - m_screenLabels[i].BeginTweening( 0.2f, TWEEN_BOUNCE_END ); - m_screenLabels[i].SetX( 0 ); + /* If this item isn't visible, hide it and skip tweens. */ + if( !ItemIsOnScreen(i) ) + { + m_sprButtons[i]->Command( HIDE_ITEM_COMMAND ); + m_screenLabels[i]->Command( HIDE_ITEM_COMMAND ); + m_sprButtons[i]->FinishTweening(); + m_screenLabels[i]->FinishTweening(); + } } } void GroupList::TweenOffScreen() { - for( unsigned i=0; iBeginTweening( 1.0f, TWEEN_BOUNCE_BEGIN ); else - m_sprButton[i].BeginTweening( 0.1f*i, TWEEN_BOUNCE_BEGIN ); - m_sprButton[i].BeginTweening( 0.2f, TWEEN_BOUNCE_BEGIN ); - m_sprButton[i].SetX( 400 ); - - if( i == m_iSelection ) - m_screenLabels[i].BeginTweening( 1.0f, TWEEN_BOUNCE_BEGIN ); - else - m_screenLabels[i].BeginTweening( 0.1f*i, TWEEN_BOUNCE_BEGIN ); - m_screenLabels[i].BeginTweening( 0.2f, TWEEN_BOUNCE_BEGIN ); - m_screenLabels[i].SetX( 400 ); + m_Frames[i]->BeginTweening( 0.1f*offset, TWEEN_BOUNCE_BEGIN ); + m_Frames[i]->BeginTweening( 0.2f, TWEEN_BOUNCE_BEGIN ); + m_Frames[i]->SetX( 400 ); } - } diff --git a/stepmania/src/GroupList.h b/stepmania/src/GroupList.h index 1c3c48abc3..f00df2331b 100644 --- a/stepmania/src/GroupList.h +++ b/stepmania/src/GroupList.h @@ -5,24 +5,28 @@ #include "Sprite.h" #include "BitmapText.h" -const unsigned MAX_GROUPS_ONSCREEN = 7; - class GroupList: public ActorFrame { - Sprite m_sprButton[MAX_GROUPS_ONSCREEN]; - BitmapText m_screenLabels[MAX_GROUPS_ONSCREEN]; + ActorFrame m_Frame; + vector m_Frames; + vector m_sprButtons; + vector m_screenLabels; vector m_asLabels; + vector m_bHidden; + /* Currently selected label. */ - unsigned m_iSelection; + int m_iSelection; /* Label that's currently at the top of the screen. */ - unsigned m_iTop; + int m_iTop; void BeforeChange(); void AfterChange(); - void SetLabels(); + bool ItemIsOnScreen( int n ) const; + void ResetTextSize( int item ); public: GroupList(); + ~GroupList(); void SetSelection(unsigned sel); int GetSelection() const { return m_iSelection; }