From 5a7b0616397e07405a7fedc34aa52cd4253a5c03 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Thu, 21 Sep 2006 22:13:18 +0000 Subject: [PATCH] do tween in lua --- stepmania/Themes/default/Scripts/Lyrics.lua | 64 +++++++++++++++++++++ stepmania/Themes/default/metrics.ini | 5 +- stepmania/src/LyricDisplay.cpp | 64 ++++++++------------- 3 files changed, 91 insertions(+), 42 deletions(-) create mode 100644 stepmania/Themes/default/Scripts/Lyrics.lua diff --git a/stepmania/Themes/default/Scripts/Lyrics.lua b/stepmania/Themes/default/Scripts/Lyrics.lua new file mode 100644 index 0000000000..8093820b12 --- /dev/null +++ b/stepmania/Themes/default/Scripts/Lyrics.lua @@ -0,0 +1,64 @@ +function Actor:lyriccommand(side) + self:settext( self.ctx.LyricText ); + + self:stoptweening(); + self:shadowlength(0); + + local Zoom = SCREEN_WIDTH/(self:GetZoomedWidth()+1); + if( Zoom > 1 ) then Zoom = 1 end + self:zoomx( Zoom ); + + local Color = self.ctx.LyricColor + local Factor = 1 + if side == "Back" then + Factor = 0.5 + end + self:diffuse( { + Color[1] * Factor, + Color[2] * Factor, + Color[3] * Factor, + Color[4] * Factor } ) + + if side == "Front" then + self:cropright(1); + else + self:cropleft(0); + end + + self:diffusealpha(0); + self:linear(0.2); + self:diffusealpha(0.75); + self:linear(self.ctx.LyricDuration * 0.75); + if side == "Front" then + self:cropright(0); + else + self:cropleft(1); + end + self:sleep(self.ctx.LyricDuration * 0.25); + self:linear(0.2); + self:diffusealpha(0); +end + +-- (c) 2006 Glenn Maynard +-- 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. + diff --git a/stepmania/Themes/default/metrics.ini b/stepmania/Themes/default/metrics.ini index f64f9d1703..68b21731e3 100644 --- a/stepmania/Themes/default/metrics.ini +++ b/stepmania/Themes/default/metrics.ini @@ -2837,9 +2837,8 @@ BannerWidth=512 BannerHeight=160 [LyricDisplay] -LyricInCommand=shadowlength,0;diffusealpha,0;linear,0.2;diffusealpha,0.75 -LyricOutCommand=linear,0.2;diffusealpha,0 -WipeDimFactor=0.5,0.5,0.5,0.5 +LyricFrontChangedCommand=LyricCommand,"Front" +LyricBackChangedCommand=LyricCommand,"Back" InLength= OutLength= diff --git a/stepmania/src/LyricDisplay.cpp b/stepmania/src/LyricDisplay.cpp index aeccfc5a33..0505a233c4 100644 --- a/stepmania/src/LyricDisplay.cpp +++ b/stepmania/src/LyricDisplay.cpp @@ -8,18 +8,18 @@ static ThemeMetric IN_LENGTH ("LyricDisplay","InLength"); static ThemeMetric OUT_LENGTH ("LyricDisplay","OutLength"); -static ThemeMetric WIPE_DIM_FACTOR ("LyricDisplay","WipeDimFactor"); LyricDisplay::LyricDisplay() { - for( int i=0; i<2; i++ ) - { - m_textLyrics[i].SetName( "Lyric" ); - ActorUtil::LoadAllCommands( m_textLyrics[i], "LyricDisplay" ); - m_textLyrics[i].LoadFromFont( THEME->GetPathF("LyricDisplay","text") ); - m_textLyrics[i].SetDiffuse( RageColor(1,1,1,1) ); - this->AddChild( &m_textLyrics[i] ); - } + m_textLyrics[0].SetName( "LyricBack" ); + ActorUtil::LoadAllCommands( m_textLyrics[0], "LyricDisplay" ); + m_textLyrics[0].LoadFromFont( THEME->GetPathF("LyricDisplay","text") ); + this->AddChild( &m_textLyrics[0] ); + + m_textLyrics[1].SetName( "LyricFront" ); + ActorUtil::LoadAllCommands( m_textLyrics[1], "LyricDisplay" ); + m_textLyrics[1].LoadFromFont( THEME->GetPathF("LyricDisplay","text") ); + this->AddChild( &m_textLyrics[1] ); Init(); } @@ -72,44 +72,30 @@ void LyricDisplay::Update( float fDeltaTime ) // Make lyrics show faster for faster song rates. fShowLength /= GAMESTATE->m_SongOptions.GetCurrent().m_fMusicRate; + Lua *L = LUA->Get(); for( int i=0; i<2; i++ ) { - m_textLyrics[i].SetText( GAMESTATE->m_pCurSong->m_LyricSegments[m_iCurLyricNumber].m_sLyric ); + const LyricSegment &seg = GAMESTATE->m_pCurSong->m_LyricSegments[m_iCurLyricNumber]; - /* - * This really needs a way to define a custom theme command here, so themes - * can do things like: - * - * "Diffuse=1,1,1,0;linear,.2;Diffuse=1,1,1,1;linear,.2;LyricDiffuse" - */ + m_textLyrics[i].PushContext(L); - const float fZoom = min( 1.0f, float(SCREEN_WIDTH)/(m_textLyrics[i].GetZoomedWidth()+1) ); + lua_pushstring( L, "LyricText" ); + lua_pushstring( L, seg.m_sLyric ); + lua_settable( L, -3 ); - m_textLyrics[i].StopTweening(); - m_textLyrics[i].SetZoomX( fZoom ); + lua_pushstring( L, "LyricDuration" ); + lua_pushnumber( L, fShowLength ); + lua_settable( L, -3 ); - RageColor color = GAMESTATE->m_pCurSong->m_LyricSegments[m_iCurLyricNumber].m_Color; - - if( i==0 ) - color *= WIPE_DIM_FACTOR; + lua_pushstring( L, "LyricColor" ); + seg.m_Color.PushTable( L ); + lua_settable( L, -3 ); - m_textLyrics[i].SetDiffuse( color ); - - /* Crop the bottom layer of text away as we crop the top layer on. That - * prevents overdraw, which reduces AA quality. */ - if( i==0 ) - m_textLyrics[i].SetCropLeft(0); - if( i==1 ) - m_textLyrics[i].SetCropRight(1); - m_textLyrics[i].PlayCommand( "In" ); - m_textLyrics[i].BeginTweening( fShowLength * 0.75f ); /* sleep */ - if( i==0 ) - m_textLyrics[i].SetCropLeft(1); - if( i==1 ) - m_textLyrics[i].SetCropRight(0); - m_textLyrics[i].BeginTweening( fShowLength * 0.25f ); /* sleep */ - m_textLyrics[i].PlayCommand( "Out" ); + lua_pop( L, 1 ); } + LUA->Release( L ); + + PlayCommand( "Changed" ); m_iCurLyricNumber++; }