Files
itgmania212121/stepmania/src/Banner.cpp
T

274 lines
7.4 KiB
C++
Raw Normal View History

2003-02-16 04:01:45 +00:00
#include "global.h"
2001-11-03 10:52:42 +00:00
#include "Banner.h"
2002-05-19 01:59:48 +00:00
#include "SongManager.h"
2003-03-10 01:28:53 +00:00
#include "RageUtil.h"
2003-04-22 12:13:36 +00:00
#include "song.h"
#include "RageTextureManager.h"
2003-07-17 20:10:07 +00:00
#include "Course.h"
2003-08-31 22:37:09 +00:00
#include "Character.h"
#include "ThemeMetric.h"
#include "CharacterManager.h"
#include "ActorUtil.h"
2006-01-29 22:13:52 +00:00
#include "UnlockManager.h"
REGISTER_ACTOR_CLASS( Banner )
2003-08-31 22:37:09 +00:00
ThemeMetric<bool> SCROLL_RANDOM ("Banner","ScrollRandom");
ThemeMetric<bool> SCROLL_ROULETTE ("Banner","ScrollRoulette");
2003-03-10 01:28:53 +00:00
2002-09-05 03:45:07 +00:00
Banner::Banner()
{
m_bScrolling = false;
m_fPercentScrolling = 0;
}
/* Ugly: if sIsBanner is false, we're actually loading something other than a banner. */
void Banner::Load( RageTextureID ID, bool bIsBanner )
2002-05-19 01:59:48 +00:00
{
2004-09-05 03:32:45 +00:00
if( ID.filename == "" )
2005-09-03 23:08:43 +00:00
{
LoadFallback();
return;
2005-09-03 23:08:43 +00:00
}
2004-09-05 03:32:45 +00:00
if( bIsBanner )
ID = SongBannerTexture(ID);
2003-02-12 22:50:21 +00:00
m_fPercentScrolling = 0;
m_bScrolling = false;
TEXTUREMAN->DisableOddDimensionWarning();
TEXTUREMAN->VolatileTexture( ID );
Sprite::Load( ID );
TEXTUREMAN->EnableOddDimensionWarning();
2002-05-19 01:59:48 +00:00
};
void Banner::Update( float fDeltaTime )
{
Sprite::Update( fDeltaTime );
2002-05-19 01:59:48 +00:00
if( m_bScrolling )
{
m_fPercentScrolling += fDeltaTime/2;
2002-05-19 01:59:48 +00:00
m_fPercentScrolling -= (int)m_fPercentScrolling;
2002-05-27 08:23:27 +00:00
const RectF *pTextureRect = m_pTexture->GetTextureCoordRect(0);
float fTexCoords[8] =
{
0+m_fPercentScrolling, pTextureRect->top, // top left
0+m_fPercentScrolling, pTextureRect->bottom, // bottom left
1+m_fPercentScrolling, pTextureRect->bottom, // bottom right
1+m_fPercentScrolling, pTextureRect->top, // top right
};
Sprite::SetCustomTextureCoords( fTexCoords );
2002-05-19 01:59:48 +00:00
}
}
2001-12-28 10:15:59 +00:00
void Banner::SetScrolling( bool bScroll, float Percent)
{
m_bScrolling = bScroll;
m_fPercentScrolling = Percent;
/* Set up the texture coord rects for the current state. */
Update(0);
}
2003-01-02 01:39:58 +00:00
void Banner::LoadFromSong( Song* pSong ) // NULL means no song
2001-11-03 10:52:42 +00:00
{
2003-01-02 01:39:58 +00:00
if( pSong == NULL ) LoadFallback();
2003-02-12 22:50:21 +00:00
else if( pSong->HasBanner() ) Load( pSong->GetBannerPath() );
2003-01-02 01:39:58 +00:00
else LoadFallback();
2003-02-12 22:54:22 +00:00
m_bScrolling = false;
2002-05-19 01:59:48 +00:00
}
2003-03-09 00:55:49 +00:00
void Banner::LoadAllMusic()
{
Load( THEME->GetPathG("Banner","All") );
m_bScrolling = false;
}
void Banner::LoadMode()
{
Load( THEME->GetPathG("Banner","Mode") );
2003-03-09 00:55:49 +00:00
m_bScrolling = false;
}
2006-01-22 01:00:06 +00:00
void Banner::LoadFromSongGroup( RString sSongGroup )
2002-05-19 01:59:48 +00:00
{
2006-01-22 01:00:06 +00:00
RString sGroupBannerPath = SONGMAN->GetSongGroupBannerPath( sSongGroup );
2006-08-14 18:56:00 +00:00
if( sGroupBannerPath != "" ) Load( sGroupBannerPath );
else LoadFallback();
2003-02-12 22:54:22 +00:00
m_bScrolling = false;
2002-03-06 08:25:09 +00:00
}
2006-08-14 18:57:30 +00:00
void Banner::LoadFromCourse( const Course *pCourse ) // NULL means no course
2002-06-14 22:25:22 +00:00
{
2006-08-14 18:56:00 +00:00
if( pCourse == NULL ) LoadFallback();
2003-01-02 01:39:58 +00:00
else if( pCourse->m_sBannerPath != "" ) Load( pCourse->m_sBannerPath );
2006-08-14 18:56:00 +00:00
else LoadCourseFallback();
2003-02-12 22:54:22 +00:00
m_bScrolling = false;
2003-01-02 01:39:58 +00:00
}
2002-06-14 22:25:22 +00:00
2006-08-14 18:57:30 +00:00
void Banner::LoadCardFromCharacter( const Character *pCharacter )
2003-08-31 22:37:09 +00:00
{
2006-08-14 18:56:00 +00:00
if( pCharacter == NULL ) LoadFallback();
2005-08-04 21:13:29 +00:00
else if( pCharacter->GetCardPath() != "" ) Load( pCharacter->GetCardPath() );
2006-08-14 18:56:00 +00:00
else LoadFallback();
2003-08-31 22:37:09 +00:00
m_bScrolling = false;
}
2006-08-14 18:57:30 +00:00
void Banner::LoadIconFromCharacter( const Character *pCharacter )
2003-08-31 22:37:09 +00:00
{
2006-08-14 18:56:00 +00:00
if( pCharacter == NULL ) LoadFallbackCharacterIcon();
else if( pCharacter->GetIconPath() != "" ) Load( pCharacter->GetIconPath(), false );
2006-08-14 18:56:00 +00:00
else LoadFallbackCharacterIcon();
2003-08-31 22:37:09 +00:00
m_bScrolling = false;
}
2006-03-23 00:16:18 +00:00
void Banner::LoadBannerFromUnlockEntry( const UnlockEntry* pUE )
2006-01-29 22:13:52 +00:00
{
2006-03-20 22:41:41 +00:00
if( pUE == NULL )
LoadFallback();
2006-01-29 22:13:52 +00:00
else
{
RString sFile = pUE->GetBannerFile();
Load( sFile );
m_bScrolling = false;
}
}
2006-03-23 00:16:18 +00:00
void Banner::LoadBackgroundFromUnlockEntry( const UnlockEntry* pUE )
2006-01-29 22:13:52 +00:00
{
2006-03-20 22:41:41 +00:00
if( pUE == NULL )
LoadFallback();
2006-01-29 22:13:52 +00:00
else
{
RString sFile = pUE->GetBackgroundFile();
Load( sFile );
m_bScrolling = false;
}
}
2003-01-02 01:39:58 +00:00
void Banner::LoadFallback()
{
2005-02-06 03:32:53 +00:00
Load( THEME->GetPathG("Common","fallback banner") );
2002-06-14 22:25:22 +00:00
}
void Banner::LoadCourseFallback()
{
Load( THEME->GetPathG("Banner","course fallback") );
}
void Banner::LoadFallbackCharacterIcon()
{
Character *pCharacter = CHARMAN->GetDefaultCharacter();
if( pCharacter && !pCharacter->GetIconPath().empty() )
Load( pCharacter->GetIconPath(), false );
else
LoadFallback();
}
2003-01-02 01:39:58 +00:00
void Banner::LoadRoulette()
2002-05-19 01:59:48 +00:00
{
2005-02-06 03:32:53 +00:00
Load( THEME->GetPathG("Banner","roulette") );
m_bScrolling = (bool)SCROLL_RANDOM;
2002-05-19 01:59:48 +00:00
}
void Banner::LoadRandom()
{
2005-02-06 03:32:53 +00:00
Load( THEME->GetPathG("Banner","random") );
m_bScrolling = (bool)SCROLL_ROULETTE;
}
// lua start
#include "LuaBinding.h"
class LunaBanner: public Luna<Banner>
{
public:
static int scaletoclipped( T* p, lua_State *L ) { p->ScaleToClipped(FArg(1),FArg(2)); return 0; }
static int ScaleToClipped( T* p, lua_State *L ) { p->ScaleToClipped(FArg(1),FArg(2)); return 0; }
static int LoadFromSong( T* p, lua_State *L )
{
if( lua_isnil(L,1) ) { p->LoadFromSong( NULL ); }
else { Song *pS = Luna<Song>::check(L,1); p->LoadFromSong( pS ); }
return 0;
}
static int LoadFromCourse( T* p, lua_State *L )
{
if( lua_isnil(L,1) ) { p->LoadFromCourse( NULL ); }
else { Course *pC = Luna<Course>::check(L,1); p->LoadFromCourse( pC ); }
return 0;
}
static int LoadIconFromCharacter( T* p, lua_State *L )
{
if( lua_isnil(L,1) ) { p->LoadIconFromCharacter( NULL ); }
else { Character *pC = Luna<Character>::check(L,1); p->LoadIconFromCharacter( pC ); }
return 0;
}
static int LoadCardFromCharacter( T* p, lua_State *L )
{
if( lua_isnil(L,1) ) { p->LoadIconFromCharacter( NULL ); }
else { Character *pC = Luna<Character>::check(L,1); p->LoadIconFromCharacter( pC ); }
return 0;
}
2006-01-29 22:13:52 +00:00
static int LoadBannerFromUnlockEntry( T* p, lua_State *L )
{
if( lua_isnil(L,1) ) { p->LoadBannerFromUnlockEntry( NULL ); }
else { UnlockEntry *pUE = Luna<UnlockEntry>::check(L,1); p->LoadBannerFromUnlockEntry( pUE ); }
return 0;
}
static int LoadBackgroundFromUnlockEntry( T* p, lua_State *L )
{
if( lua_isnil(L,1) ) { p->LoadBackgroundFromUnlockEntry( NULL ); }
else { UnlockEntry *pUE = Luna<UnlockEntry>::check(L,1); p->LoadBackgroundFromUnlockEntry( pUE ); }
return 0;
}
2006-09-27 20:03:31 +00:00
LunaBanner()
{
ADD_METHOD( scaletoclipped );
ADD_METHOD( ScaleToClipped );
ADD_METHOD( LoadFromSong );
ADD_METHOD( LoadFromCourse );
ADD_METHOD( LoadIconFromCharacter );
ADD_METHOD( LoadCardFromCharacter );
2006-01-29 22:13:52 +00:00
ADD_METHOD( LoadBannerFromUnlockEntry );
ADD_METHOD( LoadBackgroundFromUnlockEntry );
}
};
LUA_REGISTER_DERIVED_CLASS( Banner, Sprite )
// lua end
2004-06-01 00:53:06 +00:00
/*
* (c) 2001-2004 Chris Danford
* 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.
*/