diff --git a/stepmania/src/BitmapText.cpp b/stepmania/src/BitmapText.cpp index e425039b9a..da9adce851 100644 --- a/stepmania/src/BitmapText.cpp +++ b/stepmania/src/BitmapText.cpp @@ -77,6 +77,8 @@ BitmapText::BitmapText() m_fMaxHeight = 0; SetShadowLength( 4 ); + + m_vColors.clear(); } BitmapText::~BitmapText() @@ -143,6 +145,8 @@ bool BitmapText::LoadFromFont( const CString& sFontFilePath ) BuildChars(); + m_bColored = false; + return true; } @@ -207,6 +211,7 @@ void BitmapText::BuildChars() for( unsigned i=0; iGetHeight(); + const wstring &szLine = m_wTextLines[i]; const int iLineWidth = m_iLineWidths[i]; @@ -356,9 +361,41 @@ void BitmapText::SetText( const CString& _sText, const CString& _sAlternateText, m_sText = sNewText; m_iWrapWidthPixels = iWrapWidthPixels; + //Split out color commands if text is colored. + if ( m_bColored ) + { + CString sEndText; + m_vColors.clear(); + + int i = m_sText.Find( "|c0", 0 ); + int last = 0; + while ( ( i > -1 ) && ( i < ( int( m_sText.length() ) - 9 ) ) ) + { + sEndText += m_sText.substr( last, i-last ); + ColorChange change; + int k; + sscanf( m_sText.substr( i+3, 2 ).c_str(), "%x", &k ); change.c.r = float( k ) / 255.0f; + sscanf( m_sText.substr( i+5, 2 ).c_str(), "%x", &k ); change.c.g = float( k ) / 255.0f; + sscanf( m_sText.substr( i+7, 2 ).c_str(), "%x", &k ); change.c.b = float( k ) / 255.0f; + change.c.a = 1; + change.l = sEndText.length(); + m_vColors.push_back( change ); + last = i+9; + if ( last < m_sText.length() ) + i = m_sText.Find( CString("|c0"), last ); + else + i = -1; + } + + if ( last < m_sText.length() ) + sEndText += m_sText.substr( last, m_sText.length()-last ); + + m_sText = sEndText; + } // Break the string into lines. // + m_wTextLines.clear(); if( iWrapWidthPixels == -1 ) @@ -434,6 +471,13 @@ void BitmapText::SetText( const CString& _sText, const CString& _sAlternateText, } } + //XXX: YUCK! This is horrible... but basically, in order to make sure we are + //in sync with all of the color changes, we have to add bogus spaces at the end + //of all lines. + if ( m_bColored ) + for ( unsigned int i = 0; i < m_wTextLines.size(); i++ ) + m_wTextLines[i] = CStringToWstring( WStringToCString( m_wTextLines[i] ) + CString( " " ) ); + BuildChars(); UpdateBaseZoom(); } @@ -602,6 +646,25 @@ void BitmapText::DrawPrimitives() color_index = (color_index+1)%NUM_RAINBOW_COLORS; } } + else if ( m_bColored ) + { + int loc = 0, cur = 0; + RageColor c = m_pTempState->diffuse[0]; + + for( unsigned i=0; i m_vColors[cur].l ) + { + c = m_vColors[cur].c; + cur++; + } + + for ( unsigned j=0; j<4; j++ ) + verts[i+j].c = c; + } + } else { for( unsigned i=0; i &wTextLines ) { wTextLines = m_wTextLines; } + void SetDynamicColor( bool coloration ) { m_bColored = coloration; } + CString GetText() const { return m_sText; } /* Return true if the string 's' will use an alternate string, if available. */ bool StringWillUseAlternate(const CString& sText, const CString& sAlternateText) const; @@ -83,6 +85,14 @@ protected: bool m_bRainbow; + bool m_bColored; + + struct ColorChange + { + RageColor c; //Color to change to + int l; //Change Location + }; + vector m_vColors; vector verts; vector tex; diff --git a/stepmania/src/ScreenNetSelectBase.cpp b/stepmania/src/ScreenNetSelectBase.cpp index 27f5a34d61..3426cc6cb2 100644 --- a/stepmania/src/ScreenNetSelectBase.cpp +++ b/stepmania/src/ScreenNetSelectBase.cpp @@ -55,6 +55,7 @@ void ScreenNetSelectBase::Init() this->AddChild( &m_sprChatOutputBox ); m_textChatInput.LoadFromFont( THEME->GetPathF(m_sName,"chat") ); + m_textChatInput.SetDynamicColor( true ); m_textChatInput.SetHorizAlign( align_left ); m_textChatInput.SetVertAlign( align_top ); m_textChatInput.SetShadowLength( 0 ); @@ -67,6 +68,7 @@ void ScreenNetSelectBase::Init() m_textOutHidden.SetWrapWidthPixels( (int)(CHATOUTPUT_WIDTH * 2) ); m_textChatOutput.LoadFromFont( THEME->GetPathF(m_sName,"chat") ); + m_textChatOutput.SetDynamicColor( true ); m_textChatOutput.SetHorizAlign( align_left ); m_textChatOutput.SetVertAlign( align_bottom ); m_textChatOutput.SetShadowLength( 0 ); @@ -75,6 +77,7 @@ void ScreenNetSelectBase::Init() this->AddChild( &m_textChatOutput ); //Display updated chat (maybe this should be a function)? + m_textOutHidden.SetDynamicColor( false ); m_textOutHidden.SetText( NSMAN->m_sChatText ); vector wLines; m_textOutHidden.GetLines( wLines );