From c2243b0b0e3e8b0dc9f48438042446bfbe0cae51 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Mon, 27 Feb 2006 03:04:56 +0000 Subject: [PATCH] ScreenOptions fading is a headache. We move rows up and down, and fade them in and out at the same time; we do this by tweening the whole row up and down, and fading each part of the row. This is a big pain, because we're also tweening each part for other reasons, and these tweens tend to collide. The whole thing is brittle and complicated, and it's making fixing other problems a pain. Try it a little differently: to fade the whole row, tween the alpha along with the position of the whole row. Then, manually propagate the changing alpha value to each part, using BaseAlpha, so it doesn't affect other tweens. This also helps segregate the fading: with the exception of the actual propagation, OptionRow doesn't have to know anything about it. Before, it had to constantly be careful that any tweening operations didn't collide with the alpha tweening; often, one or the other would be cancelled, resulting in either the change not happening at all, or snapping instead of fading. (This is still a hack, but it's more manageable; it puts control of high-level tweening entirely in SOptionsMenu's control, instead of half in OptionRow.) --- stepmania/src/OptionRow.cpp | 53 +++++++++++++-------------------- stepmania/src/OptionRow.h | 3 +- stepmania/src/ScreenOptions.cpp | 11 ++++--- 3 files changed, 28 insertions(+), 39 deletions(-) diff --git a/stepmania/src/OptionRow.cpp b/stepmania/src/OptionRow.cpp index 079ea2d421..7d8ced0c56 100644 --- a/stepmania/src/OptionRow.cpp +++ b/stepmania/src/OptionRow.cpp @@ -509,7 +509,7 @@ void OptionRow::PositionUnderlines( PlayerNumber pn ) ASSERT( m_vbSelected[pnTakeSelectedFrom].size() == m_pHand->m_Def.m_vsChoices.size() ); bool bSelected = (iChoiceWithFocus==-1) ? false : m_vbSelected[pnTakeSelectedFrom][ iChoiceWithFocus ]; - bool bHidden = !bSelected || m_bHidden || !GAMESTATE->IsHumanPlayer(pn); + bool bHidden = !bSelected || !GAMESTATE->IsHumanPlayer(pn); ul.StopTweening(); ul.BeginTweening( m_pParentType->TWEEN_SECONDS ); @@ -525,9 +525,6 @@ void OptionRow::PositionIcons( PlayerNumber pn ) return; pIcon->SetX( m_pParentType->ICONS_X.GetValue(pn) ); - - /* XXX: this doesn't work since icon is an ActorFrame */ - pIcon->SetDiffuse( RageColor(1,1,1, m_bHidden? 0.0f:1.0f) ); } /* This is called when the focus changes, to update "long row" text. */ @@ -595,9 +592,6 @@ void OptionRow::UpdateEnabledDisabled() else if( bRowEnabled ) color = m_pParentType->COLOR_NOT_SELECTED; else color = m_pParentType->COLOR_DISABLED; - if( m_bHidden ) - color.a = 0; - if( m_sprBullet != NULL ) m_sprBullet->SetGlobalDiffuseColor( color ); m_sprBullet->PlayCommand( bThisRowHasFocusByAny ? "GainFocus" : "LoseFocus" ); @@ -649,9 +643,6 @@ void OptionRow::UpdateEnabledDisabled() if( m_bRowHasFocus[pn] ) color = m_pParentType->COLOR_SELECTED; else if( bRowEnabled ) color = m_pParentType->COLOR_NOT_SELECTED; else color = m_pParentType->COLOR_DISABLED; - - if( m_bHidden ) - color.a = 0; } unsigned item_no = m_pHand->m_Def.m_bOneChoiceForAllPlayers ? 0 : pn; @@ -666,18 +657,6 @@ void OptionRow::UpdateEnabledDisabled() bt.StopTweening(); bt.BeginTweening( m_pParentType->TWEEN_SECONDS ); bt.SetDiffuse( color ); - - /* Only reposition the underline if the text changed, too, or - * we'll cancel PositionUnderlines moving and resizing the - * underline. (XXX: This is brittle; if we're actually changing - * available options, this will break, too. Use m_fBaseAlpha?) */ - if( m_Underline[pn].size() ) - { - OptionsCursor *pUnderline = m_Underline[pn][0]; - pUnderline->StopTweening(); - pUnderline->BeginTweening( m_pParentType->TWEEN_SECONDS ); - pUnderline->SetDiffuseAlpha( color.a ); - } } } break; @@ -692,20 +671,28 @@ void OptionRow::UpdateEnabledDisabled() else m_textItems[0]->StopEffect(); } +} - if( m_sprBullet->DestTweenState().diffuse[0] != color ) +void OptionRow::Update( float fDeltaTime ) +{ + ActorFrame::Update( fDeltaTime ); + + float fAlpha = m_Frame.GetCurrentDiffuseAlpha(); + m_textTitle->SetBaseAlpha( fAlpha ); + if( m_sprBullet != NULL ) + m_sprBullet->SetBaseAlpha( fAlpha ); + FOREACH_HumanPlayer( pn ) { - m_textTitle->StopTweening(); - m_textTitle->BeginTweening( m_pParentType->TWEEN_SECONDS ); - m_textTitle->SetDiffuseAlpha( color.a ); - - if( m_sprBullet != NULL ) - { - m_sprBullet->StopTweening(); - m_sprBullet->BeginTweening( m_pParentType->TWEEN_SECONDS ); - m_sprBullet->SetDiffuseAlpha( color.a ); - } + FOREACH( OptionsCursor *, m_Underline[pn], pUnderline ) + (*pUnderline)->SetBaseAlpha( fAlpha ); + /* XXX: this doesn't work since icon is an ActorFrame */ + if( m_OptionIcons[pn] ) + m_OptionIcons[pn]->SetBaseAlpha( fAlpha ); } + if( m_sprBullet != NULL ) + m_sprBullet->SetBaseAlpha( fAlpha ); + for( unsigned j=0; jSetBaseAlpha( fAlpha ); } void OptionRow::SetOptionIcon( PlayerNumber pn, const RString &sText, GameCommand &gc ) diff --git a/stepmania/src/OptionRow.h b/stepmania/src/OptionRow.h index 61a9c85ff1..c3236e72b6 100644 --- a/stepmania/src/OptionRow.h +++ b/stepmania/src/OptionRow.h @@ -132,6 +132,7 @@ class OptionRow : public ActorFrame public: OptionRow( const OptionRowType *pType ); ~OptionRow(); + void Update( float fDeltaTime ); void Clear(); void LoadNormal( OptionRowHandler *pHand, bool bFirstItemGoesDown ); @@ -181,8 +182,6 @@ public: void GetWidthXY( PlayerNumber pn, int iChoiceOnRow, int &iWidthOut, int &iXOut, int &iYOut ) const; // ScreenOptions calls positions m_FrameDestination, then m_Frame tween to that same TweenState. - void SetRowHidden( bool bRowHidden ) { m_bHidden = bRowHidden; } - bool GetRowHidden() const { return m_bHidden; } unsigned GetTextItemsSize() const { return m_textItems.size(); } bool GetFirstItemGoesDown() const { return m_bFirstItemGoesDown; } diff --git a/stepmania/src/ScreenOptions.cpp b/stepmania/src/ScreenOptions.cpp index 6cafb09409..f137a856dc 100644 --- a/stepmania/src/ScreenOptions.cpp +++ b/stepmania/src/ScreenOptions.cpp @@ -653,15 +653,16 @@ void ScreenOptions::PositionRows( bool bTween ) else if( i >= second_end ) fPos = ((int)NUM_ROWS_SHOWN)-0.5f; Actor::TweenState tsDestination = m_exprRowPositionTransformFunction.GetPosition( fPos, i, min( (int)Rows.size(), (int)NUM_ROWS_SHOWN ) ); - row.SetDestination( tsDestination, bTween ); bool bHidden = i < first_start || (i >= first_end && i < second_start) || i >= second_end; + for( int j=0; j<4; j++ ) + tsDestination.diffuse[j].a = bHidden? 0.0f:1.0f; if( !bHidden ) pos++; - row.SetRowHidden( bHidden ); + row.SetDestination( tsDestination, bTween ); } if( pSeparateExitRow ) @@ -669,9 +670,11 @@ void ScreenOptions::PositionRows( bool bTween ) Actor::TweenState tsDestination; tsDestination.Init(); tsDestination.pos.y = SEPARATE_EXIT_ROW_Y; - pSeparateExitRow->SetDestination( tsDestination, bTween ); - pSeparateExitRow->SetRowHidden( second_end != (int) Rows.size() ); + bool bHidden = (second_end != (int) Rows.size()); + for( int j=0; j<4; j++ ) + tsDestination.diffuse[j].a = bHidden? 0.0f:1.0f; + pSeparateExitRow->SetDestination( tsDestination, bTween ); } }