Files
itgmania212121/stepmania/src/RoomWheel.cpp
T

236 lines
6.4 KiB
C++
Raw Normal View History

2005-05-03 01:32:19 +00:00
#include "global.h"
#include "RoomWheel.h"
#include "RageLog.h"
2005-07-01 04:19:32 +00:00
#include "RageUtil.h"
#include "ScreenTextEntry.h"
2005-12-22 03:10:04 +00:00
#include "LocalizedString.h"
2006-01-21 03:46:19 +00:00
#include "NetworkSyncManager.h"
2006-08-14 05:46:15 +00:00
#include "ScreenManager.h"
2005-05-08 18:49:27 +00:00
AutoScreenMessage( SM_BackFromRoomName )
2006-08-14 15:43:45 +00:00
AutoScreenMessage( SM_RoomInfoRetract )
AutoScreenMessage( SM_RoomInfoDeploy )
2005-05-03 01:32:19 +00:00
ThemeMetric<float> TEXT_X;
ThemeMetric<float> TEXT_Y;
ThemeMetric<float> TEXT_WIDTH;
ThemeMetric<apActorCommands> TEXT_ON_COMMAND;
2007-02-17 13:03:59 +00:00
ThemeMetric<float> DESC_X;
ThemeMetric<float> DESC_Y;
ThemeMetric<float> DESC_WIDTH;
RoomWheel::~RoomWheel()
{
FOREACH( WheelItemBaseData*, m_CurWheelItemData, i )
SAFE_DELETE( *i );
m_CurWheelItemData.clear();
}
2006-01-22 01:00:06 +00:00
void RoomWheel::Load( RString sType )
2005-05-03 01:32:19 +00:00
{
WheelBase::Load( sType );
2005-05-08 18:49:27 +00:00
m_offset = 0;
2005-05-03 01:32:19 +00:00
LOG->Trace( "RoomWheel::Load('%s')", sType.c_str() );
AddPerminateItem( new RoomWheelItemData(TYPE_GENERIC, "Create Room", "Create a new game room", THEME->GetMetricC( m_sName, "CreateRoomColor")) );
2005-05-08 18:49:27 +00:00
BuildWheelItemsData( m_CurWheelItemData );
2005-05-03 01:32:19 +00:00
RebuildWheelItems();
}
WheelItemBase *RoomWheel::MakeItem()
{
return new RoomWheelItem;
}
2007-02-17 13:03:59 +00:00
RoomWheelItem::RoomWheelItem( RString sType ):
WheelItemBase( sType )
2005-05-03 01:32:19 +00:00
{
2005-07-01 04:21:49 +00:00
Load( sType );
2005-05-03 01:32:19 +00:00
}
RoomWheelItem::RoomWheelItem( const RoomWheelItem &cpy ):
WheelItemBase( cpy ),
m_sprBar( cpy.m_sprBar ),
m_text( cpy.m_text ),
m_Desc( cpy.m_Desc )
{
if( cpy.GetNumChildren() != 0 )
{
this->AddChild( m_sprBar );
this->AddChild( &m_text );
this->AddChild( &m_Desc );
}
}
void RoomWheelItem::Load( RString sType )
2005-05-03 01:32:19 +00:00
{
TEXT_X .Load(sType,"TextX");
TEXT_Y .Load(sType,"TextY");
TEXT_ON_COMMAND .Load(sType,"TextOnCommand");
m_sprBar.Load( THEME->GetPathG(sType,"bar") );
m_sprBar->SetXY( 0, 0 );
this->AddChild( m_sprBar );
m_text.LoadFromFont( THEME->GetPathF(sType,"text") );
m_text.SetShadowLength( 0 );
m_text.SetXY( TEXT_X, TEXT_Y );
m_text.RunCommands( TEXT_ON_COMMAND );
this->AddChild( &m_text );
2007-02-17 13:03:59 +00:00
DESC_X .Load(sType,"DescX");
DESC_Y .Load(sType,"DescY");
DESC_WIDTH .Load(sType,"DescWidth");
TEXT_WIDTH .Load(sType,"TextWidth");
2005-05-03 01:32:19 +00:00
2006-09-26 19:55:35 +00:00
m_text.SetHorizAlign( align_left );
2005-05-03 01:32:19 +00:00
m_text.SetMaxWidth(TEXT_WIDTH);
2006-08-21 21:42:41 +00:00
m_Desc.SetName( "Desc" );
ActorUtil::LoadAllCommands( m_Desc, "RoomWheelItem" );
2005-05-03 01:32:19 +00:00
m_Desc.LoadFromFont( THEME->GetPathF("RoomWheel","text") );
2006-09-26 19:55:35 +00:00
m_Desc.SetHorizAlign( align_left );
2005-05-03 01:32:19 +00:00
m_Desc.SetShadowLength( 0 );
2005-07-01 04:21:49 +00:00
m_Desc.SetMaxWidth( DESC_WIDTH );
2005-05-03 01:32:19 +00:00
m_Desc.SetXY( DESC_X, DESC_Y);
2006-08-21 21:42:41 +00:00
m_Desc.PlayCommand( "On" );
2005-05-03 01:32:19 +00:00
this->AddChild( &m_Desc );
}
void RoomWheel::BuildWheelItemsData( vector<WheelItemBaseData*> &arrayWheelItemDatas )
{
if( arrayWheelItemDatas.empty() )
arrayWheelItemDatas.push_back( new RoomWheelItemData(TYPE_GENERIC, "- EMPTY -", "", RageColor(1,0,0,1)) );
2005-05-03 01:32:19 +00:00
}
void RoomWheel::AddPerminateItem( RoomWheelItemData *itemdata )
2005-05-08 18:49:27 +00:00
{
2007-02-17 13:03:59 +00:00
++m_offset;
2005-05-08 18:49:27 +00:00
AddItem( itemdata );
}
2007-02-17 13:03:59 +00:00
void RoomWheel::AddItem( WheelItemBaseData *pItemData )
{
m_CurWheelItemData.push_back( pItemData );
int iVisible = FirstVisibleIndex();
int iIndex = m_CurWheelItemData.size();
if( m_bEmpty )
{
m_bEmpty = false;
// Remove the - Empty - field when we add an object from an empty state.
2007-02-17 13:03:59 +00:00
RemoveItem( 0 );
}
// If the item was shown in the wheel, rebuild the wheel
if( 0 <= iIndex - iVisible && iIndex - iVisible < NUM_WHEEL_ITEMS )
RebuildWheelItems();
}
void RoomWheel::RemoveItem( int index )
{
index += m_offset;
if( m_bEmpty || index >= (int)m_CurWheelItemData.size() )
return;
vector<WheelItemBaseData *>::iterator i = m_CurWheelItemData.begin();
i += index;
// If this item's data happened to be last selected, make it NULL.
if( m_LastSelection == *i )
m_LastSelection = NULL;
SAFE_DELETE( *i );
2007-02-17 13:03:59 +00:00
m_CurWheelItemData.erase( i );
if( m_CurWheelItemData.size() < 1 )
{
m_bEmpty = true;
m_CurWheelItemData.push_back( new WheelItemBaseData(TYPE_GENERIC, "- EMPTY -", RageColor(1,0,0,1)) );
}
RebuildWheelItems();
}
2005-12-21 12:55:20 +00:00
static LocalizedString ENTER_ROOM_NAME( "RoomWheel", "Enter room name" );
2005-05-08 18:49:27 +00:00
bool RoomWheel::Select()
{
2006-08-14 05:46:15 +00:00
SCREENMAN->PostMessageToTopScreen( SM_RoomInfoRetract, 0 );
2005-07-01 04:21:49 +00:00
if( m_iSelection > 0 )
2005-05-08 18:49:27 +00:00
return WheelBase::Select();
2007-02-17 13:03:59 +00:00
if( m_iSelection == 0 )
2005-05-08 18:49:27 +00:00
{
// Since this is not actually an option outside of this wheel, NULL is a good idea.
2005-05-08 18:49:27 +00:00
m_LastSelection = NULL;
2005-12-21 12:55:20 +00:00
ScreenTextEntry::TextEntry( SM_BackFromRoomName, ENTER_ROOM_NAME, "", 255 );
2005-05-08 18:49:27 +00:00
}
return false;
}
2007-02-17 13:03:59 +00:00
void RoomWheelItem::LoadFromWheelItemData( const WheelItemBaseData *pWID, int iIndex, bool bHasFocus )
2005-05-03 01:32:19 +00:00
{
WheelItemBase::LoadFromWheelItemData( pWID, iIndex, bHasFocus );
m_text.SetText( pWID->m_sText );
m_text.SetDiffuseColor( pWID->m_color );
const RoomWheelItemData *tmpdata = dynamic_cast<const RoomWheelItemData*>( pWID );
WheelItemBase::LoadFromWheelItemData( pWID, iIndex, bHasFocus );
2005-07-01 04:21:49 +00:00
m_Desc.SetText( tmpdata->m_sDesc );
m_Desc.SetDiffuseColor( pWID->m_color );
2005-05-03 01:32:19 +00:00
}
2007-02-17 13:03:59 +00:00
void RoomWheel::Move( int n )
{
2007-02-17 13:03:59 +00:00
if( n == 0 && m_iSelection >= m_offset )
2006-01-21 03:46:19 +00:00
{
const RoomWheelItemData* data = GetItem( m_iSelection-m_offset );
2007-02-17 13:03:59 +00:00
if( data != NULL )
2006-08-14 05:46:15 +00:00
SCREENMAN->PostMessageToTopScreen( SM_RoomInfoDeploy, 0 );
2006-01-21 03:46:19 +00:00
}
else
2007-02-17 13:03:59 +00:00
{
2006-08-14 05:46:15 +00:00
SCREENMAN->PostMessageToTopScreen( SM_RoomInfoRetract, 0 );
2007-02-17 13:03:59 +00:00
}
2007-02-17 13:03:59 +00:00
WheelBase::Move( n );
}
unsigned int RoomWheel::GetNumItems() const
{
return m_CurWheelItemData.size() - m_offset;
}
2006-01-21 03:46:19 +00:00
2005-05-03 01:32:19 +00:00
/*
* (c) 2004 Josh Allen
* 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.
*/