Files
itgmania212121/stepmania/src/HelpDisplay.cpp
T

217 lines
5.3 KiB
C++
Raw Normal View History

2003-03-30 20:21:20 +00:00
#include "global.h"
#include "HelpDisplay.h"
#include "RageUtil.h"
#include "PrefsManager.h"
#include "RageLog.h"
#include "ThemeManager.h"
2003-11-17 01:39:34 +00:00
#include "ActorUtil.h"
2003-03-30 20:21:20 +00:00
2005-04-25 07:01:07 +00:00
REGISTER_ACTOR_CLASS( HelpDisplay )
2003-03-30 20:21:20 +00:00
HelpDisplay::HelpDisplay()
{
2003-11-17 01:39:34 +00:00
m_iCurTipIndex = 0;
m_fSecsUntilSwitch = 0;
}
2003-03-30 20:21:20 +00:00
2005-05-31 07:53:13 +00:00
void HelpDisplay::Load( const CString &sType )
2003-11-17 01:39:34 +00:00
{
2005-05-31 07:53:13 +00:00
TIP_SHOW_TIME.Load( sType, "TipShowTime" );
2003-03-30 20:21:20 +00:00
2005-05-31 07:53:13 +00:00
RunCommands( THEME->GetMetricA(sType,"TipOnCommand") );
LoadFromFont( THEME->GetPathF(sType,"text") );
2005-02-09 05:33:29 +00:00
2003-03-30 20:21:20 +00:00
m_fSecsUntilSwitch = TIP_SHOW_TIME;
}
2005-02-09 05:33:29 +00:00
void HelpDisplay::LoadFromNode( const CString& sDir, const XNode* pNode )
{
BitmapText::LoadFromNode( sDir, pNode );
}
2005-05-31 08:03:18 +00:00
void HelpDisplay::SetName( const CString &sName )
2005-02-02 04:47:45 +00:00
{
2005-05-31 08:03:18 +00:00
BitmapText::SetName( sName );
2005-02-02 04:47:45 +00:00
}
2003-11-17 02:36:53 +00:00
void HelpDisplay::SetTips( const CStringArray &arrayTips, const CStringArray &arrayTipsAlt )
2003-03-30 20:21:20 +00:00
{
2003-11-17 02:36:53 +00:00
ASSERT( arrayTips.size() == arrayTipsAlt.size() );
2004-01-21 09:40:23 +00:00
if( arrayTips == m_arrayTips && arrayTipsAlt == m_arrayTipsAlt )
return;
2005-02-09 05:33:29 +00:00
SetText( "" );
2003-11-17 02:36:53 +00:00
2003-03-30 20:21:20 +00:00
m_arrayTips = arrayTips;
2003-11-17 02:36:53 +00:00
m_arrayTipsAlt = arrayTipsAlt;
m_iCurTipIndex = 0;
m_fSecsUntilSwitch = 0;
Update( 0 );
2003-03-30 20:21:20 +00:00
}
void HelpDisplay::Update( float fDeltaTime )
{
float fHibernate = m_fHibernateSecondsLeft;
2005-02-09 05:33:29 +00:00
BitmapText::Update( fDeltaTime );
2003-03-30 20:21:20 +00:00
2003-11-17 02:36:53 +00:00
if( m_arrayTips.empty() )
return;
m_fSecsUntilSwitch -= max( fDeltaTime - fHibernate, 0 );
2003-11-17 02:36:53 +00:00
if( m_fSecsUntilSwitch > 0 )
return;
// time to switch states
m_fSecsUntilSwitch = TIP_SHOW_TIME;
2005-02-09 05:33:29 +00:00
SetText( m_arrayTips[m_iCurTipIndex], m_arrayTipsAlt[m_iCurTipIndex] );
2003-11-17 02:36:53 +00:00
m_iCurTipIndex++;
m_iCurTipIndex = m_iCurTipIndex % m_arrayTips.size();
2003-03-30 20:21:20 +00:00
}
2004-06-07 21:14:03 +00:00
2005-02-09 05:33:29 +00:00
2005-04-25 07:01:07 +00:00
template<class T>
2005-06-20 04:06:26 +00:00
class LunaHelpDisplay : public Luna<T>
2005-04-25 07:01:07 +00:00
{
public:
LunaHelpDisplay() { LUA->Register( Register ); }
static int settips( T* p, lua_State *L )
{
luaL_checktype( L, 1, LUA_TTABLE );
lua_pushvalue( L, 1 );
vector<CString> arrayTips;
2005-06-15 08:26:56 +00:00
LuaHelpers::ReadArrayFromTable( arrayTips, L );
2005-04-25 07:01:07 +00:00
lua_pop( L, 1 );
if( lua_gettop(L) > 1 && !lua_isnil( L, 2 ) )
{
vector<CString> arrayTipsAlt;
luaL_checktype( L, 2, LUA_TTABLE );
lua_pushvalue( L, 2 );
LuaHelpers::ReadArrayFromTable( arrayTipsAlt, L );
lua_pop( L, 1 );
p->SetTips( arrayTips, arrayTipsAlt );
}
else
p->SetTips( arrayTips );
return 0;
}
2005-04-29 08:05:59 +00:00
static int gettips( T* p, lua_State *L )
{
CStringArray arrayTips, arrayTipsAlt;
p->GetTips( arrayTips, arrayTipsAlt );
2005-06-15 08:26:56 +00:00
LuaHelpers::CreateTableFromArray( arrayTips, L );
LuaHelpers::CreateTableFromArray( arrayTipsAlt, L );
2005-04-29 08:05:59 +00:00
return 2;
}
2005-04-25 07:01:07 +00:00
static void Register(lua_State *L)
{
ADD_METHOD( settips )
2005-04-29 08:05:59 +00:00
ADD_METHOD( gettips )
2005-06-20 04:06:26 +00:00
Luna<T>::Register( L );
2005-04-25 07:01:07 +00:00
}
};
2005-06-20 04:06:26 +00:00
LUA_REGISTER_DERIVED_CLASS( HelpDisplay, BitmapText )
2005-04-25 07:01:07 +00:00
2005-02-09 05:33:29 +00:00
#include "song.h"
#include "GameState.h"
#include "Course.h"
#include "Style.h"
#include "Foreach.h"
REGISTER_ACTOR_CLASS( GenreDisplay )
2005-02-09 05:33:29 +00:00
GenreDisplay::GenreDisplay()
{
2005-05-18 07:14:19 +00:00
this->SubscribeToMessage( MESSAGE_CURRENT_SONG_CHANGED );
this->SubscribeToMessage( MESSAGE_CURRENT_COURSE_CHANGED );
2005-02-09 05:33:29 +00:00
}
GenreDisplay::~GenreDisplay()
{
}
void GenreDisplay::PlayCommand( const CString &sCommandName, Actor* pParent )
2005-02-09 05:33:29 +00:00
{
2005-05-18 07:14:19 +00:00
if( sCommandName == MessageToString(MESSAGE_CURRENT_SONG_CHANGED) )
2005-02-09 05:33:29 +00:00
{
vector<CString> m_Artists, m_AltArtists;
Song* pSong = GAMESTATE->m_pCurSong;
ASSERT( pSong );
m_Artists.push_back( pSong->GetDisplayArtist() );
m_AltArtists.push_back( pSong->GetTranslitArtist() );
SetTips( m_Artists, m_AltArtists );
}
2005-05-18 07:14:19 +00:00
else if( sCommandName == MessageToString(MESSAGE_CURRENT_COURSE_CHANGED) )
2005-02-09 05:33:29 +00:00
{
vector<CString> m_Artists, m_AltArtists;
Course* pCourse = GAMESTATE->m_pCurCourse;
StepsType st = GAMESTATE->GetCurrentStyle()->m_StepsType;
Trail *pTrail = pCourse->GetTrail( st );
ASSERT( pTrail );
FOREACH_CONST( TrailEntry, pTrail->m_vEntries, e )
{
2005-03-10 22:54:55 +00:00
if( e->bSecret )
2005-02-09 05:33:29 +00:00
{
m_Artists.push_back( "???" );
m_AltArtists.push_back( "???" );
}
else
{
m_Artists.push_back( e->pSong->GetDisplayArtist() );
m_AltArtists.push_back( e->pSong->GetTranslitArtist() );
}
}
SetTips( m_Artists, m_AltArtists );
}
else
{
Actor::PlayCommand( sCommandName, pParent );
2005-02-09 05:33:29 +00:00
}
}
2004-06-07 21:14:03 +00:00
/*
* (c) 2001-2003 Chris Danford, 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.
*/