Files
itgmania212121/stepmania/src/AttackDisplay.cpp
T

139 lines
4.0 KiB
C++
Raw Normal View History

2003-11-26 08:25:45 +00:00
#include "global.h"
#include "AttackDisplay.h"
#include "ThemeManager.h"
#include "GameState.h"
2003-12-28 21:48:43 +00:00
#include "ActorUtil.h"
2003-12-28 22:48:23 +00:00
#include "Character.h"
#include "RageLog.h"
#include <set>
#include "PlayerState.h"
2003-11-27 02:30:54 +00:00
2005-01-26 11:21:43 +00:00
2006-01-22 01:00:06 +00:00
RString GetAttackPieceName( const RString &sAttack )
2003-12-28 22:48:23 +00:00
{
2006-01-22 01:00:06 +00:00
RString ret = ssprintf( "attack %s", sAttack.c_str() );
2003-12-28 22:48:23 +00:00
/* 1.5x -> 1_5x. If we pass a period to THEME->GetPathTo, it'll think
* we're looking for a specific file and not search. */
ret.Replace( ".", "_" );
return ret;
}
2003-11-26 08:25:45 +00:00
AttackDisplay::AttackDisplay()
{
2003-12-01 21:32:19 +00:00
if( GAMESTATE->m_PlayMode != PLAY_MODE_BATTLE &&
GAMESTATE->m_PlayMode != PLAY_MODE_RAVE )
return;
2003-12-28 22:48:23 +00:00
m_sprAttack.SetDiffuseAlpha( 0 ); // invisible
this->AddChild( &m_sprAttack );
2003-11-26 08:25:45 +00:00
}
void AttackDisplay::Init( const PlayerState* pPlayerState )
2003-12-28 21:48:43 +00:00
{
m_pPlayerState = pPlayerState;
// TODO: Remove use of PlayerNumber.
PlayerNumber pn = m_pPlayerState->m_PlayerNumber;
m_sprAttack.SetName( ssprintf("TextP%d",pn+1) );
2003-12-28 22:48:23 +00:00
if( GAMESTATE->m_PlayMode != PLAY_MODE_BATTLE &&
GAMESTATE->m_PlayMode != PLAY_MODE_RAVE )
return;
2006-01-22 01:00:06 +00:00
set<RString> attacks;
2003-12-28 22:48:23 +00:00
for( int al=0; al<NUM_ATTACK_LEVELS; al++ )
{
const Character *ch = GAMESTATE->m_pCurCharacters[pn];
ASSERT( ch );
2006-01-22 01:00:06 +00:00
const RString* asAttacks = ch->m_sAttacks[al];
2003-12-28 22:48:23 +00:00
for( int att = 0; att < NUM_ATTACKS_PER_LEVEL; ++att )
attacks.insert( asAttacks[att] );
}
2006-01-22 01:00:06 +00:00
for( set<RString>::const_iterator it = attacks.begin(); it != attacks.end(); ++it )
2003-12-28 22:48:23 +00:00
{
2006-01-22 01:00:06 +00:00
const RString path = THEME->GetPathG( "AttackDisplay", GetAttackPieceName( *it ), true );
2003-12-28 22:48:23 +00:00
if( path == "" )
{
2005-02-06 19:14:45 +00:00
LOG->Trace( "Couldn't find \"%s\"", GetAttackPieceName( *it ).c_str() );
2003-12-28 22:48:23 +00:00
continue;
}
2005-06-30 22:41:22 +00:00
m_TexturePreload.Load( path );
2003-12-28 22:48:23 +00:00
}
2003-12-28 21:48:43 +00:00
}
2003-11-26 08:25:45 +00:00
void AttackDisplay::Update( float fDelta )
{
ActorFrame::Update( fDelta );
2003-12-01 21:32:19 +00:00
if( GAMESTATE->m_PlayMode != PLAY_MODE_BATTLE &&
GAMESTATE->m_PlayMode != PLAY_MODE_RAVE )
return;
2003-11-27 02:30:54 +00:00
if( !m_pPlayerState->m_bAttackBeganThisUpdate )
2003-12-01 21:32:19 +00:00
return;
// don't handle this again
for( unsigned s=0; s<m_pPlayerState->m_ActiveAttacks.size(); s++ )
2003-12-01 21:32:19 +00:00
{
const Attack& attack = m_pPlayerState->m_ActiveAttacks[s];
if( attack.fStartSecond >= 0 )
2003-12-01 21:32:19 +00:00
continue; /* hasn't started yet */
2003-11-27 02:30:54 +00:00
if( attack.fSecsRemaining <= 0 )
2003-12-01 21:32:19 +00:00
continue; /* ended already */
2003-11-27 02:30:54 +00:00
if( attack.IsBlank() )
2003-12-01 21:32:19 +00:00
continue;
2003-11-27 02:30:54 +00:00
2005-05-20 08:57:59 +00:00
SetAttack( attack.sModifiers );
2003-12-01 21:32:19 +00:00
break;
2003-11-26 08:25:45 +00:00
}
2003-12-07 06:50:16 +00:00
}
2006-01-22 01:00:06 +00:00
void AttackDisplay::SetAttack( const RString &sText )
2003-12-28 21:48:43 +00:00
{
2006-01-22 01:00:06 +00:00
const RString path = THEME->GetPathG( "AttackDisplay", GetAttackPieceName(sText), true );
2003-12-28 22:48:23 +00:00
if( path == "" )
return;
m_sprAttack.SetDiffuseAlpha( 1 );
m_sprAttack.Load( path );
// TODO: Remove use of PlayerNumber.
PlayerNumber pn = m_pPlayerState->m_PlayerNumber;
2006-01-22 01:00:06 +00:00
const RString sName = ssprintf( "%sP%i", sText.c_str(), pn+1 );
2005-01-26 11:21:43 +00:00
m_sprAttack.RunCommands( THEME->GetMetricA("AttackDisplay", sName + "OnCommand") );
2003-12-28 21:48:43 +00:00
}
2004-06-08 00:08:04 +00:00
/*
* (c) 2003 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.
*/