Files
itgmania212121/stepmania/src/GroupList.cpp
T

265 lines
7.4 KiB
C++
Raw Normal View History

2003-02-16 04:01:45 +00:00
#include "global.h"
2002-08-24 20:36:29 +00:00
#include "GroupList.h"
#include "ThemeManager.h"
#include "SongManager.h"
2003-06-18 00:10:52 +00:00
#include "RageLog.h"
2002-08-24 20:36:29 +00:00
2002-08-24 22:49:10 +00:00
/* If this actor is used anywhere other than SelectGroup, we
* can add a setting that changes which metric group we pull
* settings out of, so it can be configured separately. */
#define START_X THEME->GetMetricF("GroupList","StartX")
#define START_Y THEME->GetMetricF("GroupList","StartY")
#define SPACING_X THEME->GetMetricF("GroupList","SpacingX")
#define SPACING_Y THEME->GetMetricF("GroupList","SpacingY")
2003-06-18 00:10:52 +00:00
#define SCROLL_TWEEN_COMMAND THEME->GetMetric ("GroupList","ScrollTweenCommand")
2003-09-03 06:47:10 +00:00
#define GAIN_FOCUS_ITEM_COMMAND THEME->GetMetric ("GroupList","GainFocusItemCommand")
#define LOSE_FOCUS_ITEM_COMMAND THEME->GetMetric ("GroupList","LoseFocusItemCommand")
#define GAIN_FOCUS_GROUP_COMMAND THEME->GetMetric ("GroupList","GainFocusGroupCommand")
#define LOSE_FOCUS_GROUP_COMMAND THEME->GetMetric ("GroupList","LoseFocusGroupCommand")
2003-06-18 00:10:52 +00:00
#define HIDE_ITEM_COMMAND THEME->GetMetric ("GroupList","HideItemCommand")
#define SHOW_ITEM_COMMAND THEME->GetMetric ("GroupList","ShowItemCommand")
2003-06-18 00:10:52 +00:00
const int MAX_GROUPS_ONSCREEN = 7;
2002-08-24 20:36:29 +00:00
GroupList::GroupList()
{
m_iSelection = m_iTop = 0;
}
2003-06-18 00:10:52 +00:00
GroupList::~GroupList()
{
2003-07-26 09:53:15 +00:00
for( unsigned i = 0; i < m_sprButtons.size(); ++i )
2003-06-18 00:10:52 +00:00
{
delete m_sprButtons[i];
2003-07-26 09:53:15 +00:00
delete m_textLabels[i];
2003-09-03 06:47:10 +00:00
delete m_ButtonFrames[i];
2003-06-18 00:10:52 +00:00
}
}
bool GroupList::ItemIsOnScreen( int n ) const
{
const int offset = n - m_iTop;
return offset >= 0 && offset < MAX_GROUPS_ONSCREEN;
}
void GroupList::Load( const CStringArray& asGroupNames )
2002-08-24 20:36:29 +00:00
{
m_asLabels = asGroupNames;
2002-08-24 20:36:29 +00:00
2003-06-18 00:10:52 +00:00
this->AddChild( &m_Frame );
for( unsigned i=0; i < m_asLabels.size(); i++ )
2002-08-24 20:36:29 +00:00
{
2003-07-26 09:53:15 +00:00
Sprite *button = new Sprite;
BitmapText *label = new BitmapText;
2003-09-03 06:47:10 +00:00
ActorFrame *frame = new ActorFrame;
2003-07-26 09:53:15 +00:00
m_sprButtons.push_back( button );
m_textLabels.push_back( label );
2003-09-03 06:47:10 +00:00
m_ButtonFrames.push_back( frame );
2003-07-26 09:53:15 +00:00
button->Load( THEME->GetPathToG("GroupList bar") );
label->LoadFromFont( THEME->GetPathToF("GroupList label") );
label->SetShadowLength( 2 );
label->SetText( SONGMAN->ShortenGroupName( asGroupNames[i] ) );
2003-09-03 06:47:10 +00:00
frame->AddChild( button );
frame->AddChild( label );
m_Frame.AddChild( frame );
2003-07-26 09:53:15 +00:00
button->SetXY( START_X + i*SPACING_X, START_Y + i*SPACING_Y );
label->SetXY( START_X + i*SPACING_X, START_Y + i*SPACING_Y );
2003-06-18 00:10:52 +00:00
if( i == 0 )
2003-07-26 09:53:15 +00:00
{
label->TurnRainbowOn();
}
else
{
label->TurnRainbowOff();
label->SetDiffuse( SONGMAN->GetGroupColor(asGroupNames[i]) );
2003-06-18 00:10:52 +00:00
}
2003-06-18 00:10:52 +00:00
m_bHidden.push_back( ItemIsOnScreen(i) );
2002-08-24 20:36:29 +00:00
2003-06-18 00:10:52 +00:00
ResetTextSize( i );
2002-08-24 20:36:29 +00:00
}
AfterChange();
}
2003-06-18 00:10:52 +00:00
void GroupList::ResetTextSize( int i )
2002-08-24 20:36:29 +00:00
{
2003-07-26 09:53:15 +00:00
BitmapText *label = m_textLabels[i];
2003-11-24 02:41:52 +00:00
const float fTextWidth = (float)label->GetUnzoomedWidth();
2003-06-18 00:10:52 +00:00
const float fButtonWidth = m_sprButtons[i]->GetZoomedWidth();
2003-06-18 00:10:52 +00:00
float fZoom = fButtonWidth/fTextWidth;
fZoom = min( fZoom, 0.8f );
2003-07-26 09:53:15 +00:00
label->SetZoomX( fZoom );
label->SetZoomY( 0.8f );
2002-08-24 20:36:29 +00:00
}
void GroupList::BeforeChange()
{
2003-09-03 06:47:10 +00:00
m_sprButtons[m_iSelection]->Command( LOSE_FOCUS_ITEM_COMMAND );
m_textLabels[m_iSelection]->Command( LOSE_FOCUS_ITEM_COMMAND );
m_ButtonFrames[m_iSelection]->Command( LOSE_FOCUS_GROUP_COMMAND );
2002-08-24 20:36:29 +00:00
}
void GroupList::AfterChange()
{
2003-06-18 00:10:52 +00:00
m_Frame.StopTweening();
m_Frame.Command( SCROLL_TWEEN_COMMAND );
m_Frame.SetY( -m_iTop*SPACING_Y );
for( int i=0; i < (int) m_asLabels.size(); i++ )
{
const bool IsHidden = !ItemIsOnScreen(i);
const bool WasHidden = m_bHidden[i];
if( IsHidden && !WasHidden )
{
m_sprButtons[i]->Command( HIDE_ITEM_COMMAND );
2003-07-26 09:53:15 +00:00
m_textLabels[i]->Command( HIDE_ITEM_COMMAND );
2003-06-18 00:10:52 +00:00
}
else if( !IsHidden && WasHidden )
{
m_sprButtons[i]->Command( SHOW_ITEM_COMMAND );
2003-07-26 09:53:15 +00:00
m_textLabels[i]->Command( SHOW_ITEM_COMMAND );
2003-06-18 00:10:52 +00:00
ResetTextSize( i );
}
m_bHidden[i] = IsHidden;
}
2002-08-24 20:36:29 +00:00
2003-09-03 06:47:10 +00:00
m_sprButtons[m_iSelection]->Command( GAIN_FOCUS_ITEM_COMMAND );
m_textLabels[m_iSelection]->Command( GAIN_FOCUS_ITEM_COMMAND );
m_ButtonFrames[m_iSelection]->Command( GAIN_FOCUS_GROUP_COMMAND );
2002-08-24 20:36:29 +00:00
}
void GroupList::Up()
{
BeforeChange();
if( m_iSelection == 0 )
SetSelection(m_asLabels.size()-1);
2002-08-24 20:36:29 +00:00
else
SetSelection(m_iSelection-1);
AfterChange();
}
void GroupList::Down()
{
BeforeChange();
SetSelection((m_iSelection+1) % m_asLabels.size());
2002-08-24 20:36:29 +00:00
AfterChange();
}
void GroupList::SetSelection( unsigned sel )
2002-08-24 20:36:29 +00:00
{
BeforeChange();
m_iSelection=sel;
2003-07-31 20:34:01 +00:00
if( (int)m_asLabels.size() <= MAX_GROUPS_ONSCREEN ||
sel <= MAX_GROUPS_ONSCREEN/2 )
m_iTop = 0;
else if ( sel >= m_asLabels.size() - MAX_GROUPS_ONSCREEN/2 )
m_iTop = m_asLabels.size() - MAX_GROUPS_ONSCREEN;
else
m_iTop = sel - MAX_GROUPS_ONSCREEN/2;
2002-08-24 20:36:29 +00:00
/* The current selection must always be visible. */
ASSERT( m_iTop <= m_iSelection );
ASSERT( m_iTop+MAX_GROUPS_ONSCREEN > m_iSelection );
AfterChange();
}
void GroupList::TweenOnScreen()
{
2003-06-18 00:10:52 +00:00
for( int i=0; i < (int) m_asLabels.size(); i++ )
2002-08-24 20:36:29 +00:00
{
2003-06-18 00:10:52 +00:00
const int offset = max(0, i-m_iTop);
2003-07-26 09:53:15 +00:00
m_sprButtons[i]->SetX( 400 );
m_textLabels[i]->SetX( 400 );
m_sprButtons[i]->BeginTweening( 0.1f*offset, TWEEN_BOUNCE_END );
m_textLabels[i]->BeginTweening( 0.1f*offset, TWEEN_BOUNCE_END );
m_sprButtons[i]->BeginTweening( 0.2f, TWEEN_BOUNCE_END );
m_textLabels[i]->BeginTweening( 0.2f, TWEEN_BOUNCE_END );
m_sprButtons[i]->SetX( 0 );
m_textLabels[i]->SetX( 0 );
2003-06-18 00:10:52 +00:00
/* If this item isn't visible, hide it and skip tweens. */
if( !ItemIsOnScreen(i) )
{
m_sprButtons[i]->Command( HIDE_ITEM_COMMAND );
2003-07-26 09:53:15 +00:00
m_textLabels[i]->Command( HIDE_ITEM_COMMAND );
2003-06-18 00:10:52 +00:00
m_sprButtons[i]->FinishTweening();
2003-07-26 09:53:15 +00:00
m_textLabels[i]->FinishTweening();
2003-06-18 00:10:52 +00:00
}
2002-08-24 20:36:29 +00:00
}
}
void GroupList::TweenOffScreen()
{
2003-06-18 00:10:52 +00:00
for( int i=m_iTop; i < min(m_iTop+MAX_GROUPS_ONSCREEN, (int) m_asLabels.size()); i++ )
2002-08-24 20:36:29 +00:00
{
2003-06-18 00:10:52 +00:00
const int offset = max(0, i-m_iTop);
2002-08-24 20:36:29 +00:00
if( i == m_iSelection )
2003-07-26 09:53:15 +00:00
{
m_sprButtons[i]->BeginTweening( 1.0f, TWEEN_BOUNCE_BEGIN );
m_textLabels[i]->BeginTweening( 1.0f, TWEEN_BOUNCE_BEGIN );
}
2002-08-24 20:36:29 +00:00
else
2003-07-26 09:53:15 +00:00
{
m_sprButtons[i]->BeginTweening( 0.1f*offset, TWEEN_BOUNCE_BEGIN );
m_textLabels[i]->BeginTweening( 0.1f*offset, TWEEN_BOUNCE_BEGIN );
}
m_sprButtons[i]->BeginTweening( 0.2f, TWEEN_BOUNCE_BEGIN );
m_textLabels[i]->BeginTweening( 0.2f, TWEEN_BOUNCE_BEGIN );
m_sprButtons[i]->SetX( 400 );
m_textLabels[i]->SetX( 400 );
2002-08-24 20:36: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.
*/