Files
itgmania212121/stepmania/src/OptionIconRow.cpp
T

186 lines
4.6 KiB
C++
Raw Normal View History

2003-02-16 04:01:45 +00:00
#include "global.h"
2002-09-03 06:33:08 +00:00
#include "OptionIconRow.h"
#include "ThemeManager.h"
#include "PlayerOptions.h"
#include "GameState.h"
#include "RageLog.h"
#include "PlayerState.h"
2005-07-09 08:09:00 +00:00
#include "ActorUtil.h"
2005-07-09 08:26:20 +00:00
#include "XmlFile.h"
#include "LuaManager.h"
2002-09-03 06:33:08 +00:00
2005-07-09 08:09:00 +00:00
REGISTER_ACTOR_CLASS( OptionIconRow )
2002-09-03 06:33:08 +00:00
#define SPACING_X THEME->GetMetricF("OptionIconRow","SpacingX")
#define SPACING_Y THEME->GetMetricF("OptionIconRow","SpacingY")
OptionIconRow::OptionIconRow()
{
2002-11-16 09:12:55 +00:00
for( unsigned i=0; i<NUM_OPTION_COLS; i++ )
2002-09-03 06:33:08 +00:00
{
m_OptionIcon[i].SetXY( i*SPACING_X, i*SPACING_Y );
this->AddChild( &m_OptionIcon[i] );
}
}
2005-07-09 08:26:20 +00:00
void OptionIconRow::LoadFromNode( const CString& sDir, const XNode* pNode )
{
Load();
ActorFrame::LoadFromNode( sDir, pNode );
}
struct OptionColumnEntry
{
char szString[30];
int iSlotIndex;
};
2005-07-07 10:48:02 +00:00
static const OptionColumnEntry g_OptionColumnEntries[] =
{
2003-04-01 19:31:27 +00:00
{"Boost", 0},
{"Brake", 0},
{"Wave", 0},
{"Expand", 0},
{"Boomerang", 0},
{"Drunk", 1},
{"Dizzy", 1},
{"Mini", 1},
{"Flip", 1},
{"Tornado", 1},
{"Hidden", 2},
{"Sudden", 2},
{"Stealth", 2},
{"Blink", 2},
{"RandomVanish", 2},
2003-04-01 19:31:27 +00:00
{"Mirror", 3},
{"Left", 3},
{"Right", 3},
{"Shuffle", 3},
{"SuperShuffle",3},
{"Little", 4},
{"NoHolds", 4},
{"Dark", 4},
2003-09-06 05:53:51 +00:00
{"Blind", 4},
2003-04-01 19:31:27 +00:00
{"Reverse", 5},
2003-09-06 05:53:51 +00:00
{"Split", 5},
{"Alternate", 5},
2004-02-23 05:33:33 +00:00
{"Cross", 5},
2004-08-29 07:12:37 +00:00
{"Centered", 5},
2003-04-01 19:31:27 +00:00
{"Incoming", 6},
{"Space", 6},
2003-09-21 18:07:29 +00:00
{"Hallway", 6},
{"Distant", 6},
};
int OptionToPreferredColumn( CString sOptionText )
{
/* Speedups always go in column 0. digit ... x */
if(sOptionText.GetLength() > 1 &&
isdigit(sOptionText[0]) &&
tolower(sOptionText[sOptionText.GetLength()-1]) == 'x') {
return 0;
}
2003-08-07 10:47:00 +00:00
for( unsigned i=0; i<ARRAYSIZE(g_OptionColumnEntries); i++ )
if( g_OptionColumnEntries[i].szString == sOptionText )
return g_OptionColumnEntries[i].iSlotIndex;
2004-03-15 02:34:18 +00:00
/* This warns about C1234 and noteskins. */
// LOG->Warn("Unknown option: '%s'", sOptionText.c_str() );
2003-04-01 19:31:27 +00:00
return 0;
}
2005-07-09 08:09:00 +00:00
void OptionIconRow::Load()
{
2005-03-20 06:41:56 +00:00
for( unsigned i=0; i<NUM_OPTION_COLS; i++ )
m_OptionIcon[i].Load( "OptionIconRow" );
}
2005-07-09 08:09:00 +00:00
void OptionIconRow::SetFromGameState( PlayerNumber pn )
2002-09-03 06:33:08 +00:00
{
// init
2005-07-09 08:09:00 +00:00
CString sOptions = GAMESTATE->m_pPlayerState[pn]->m_PlayerOptions.GetString();
CStringArray asOptions;
split( sOptions, ", ", asOptions, true );
CString asTabs[NUM_OPTION_COLS-1]; // fill these with what will be displayed on the tabs
// for each option, look for the best column to place it in
2004-09-21 07:53:39 +00:00
for( unsigned i=0; i<asOptions.size(); i++ )
{
CString sOption = asOptions[i];
int iPerferredCol = OptionToPreferredColumn( sOption );
if( iPerferredCol == -1 )
continue; // skip
// search for a vacant spot
2002-11-16 09:12:55 +00:00
for( unsigned i=iPerferredCol; i<NUM_OPTION_COLS-1; i++ )
{
if( asTabs[i] != "" )
continue;
else
{
asTabs[i] = sOption;
break;
}
}
}
2005-03-20 06:41:56 +00:00
for( unsigned i=0; i<NUM_OPTION_COLS; i++ )
if( i == 0 )
2005-07-09 08:09:00 +00:00
m_OptionIcon[i].Set( pn, "", true );
2005-03-20 06:41:56 +00:00
else
2005-07-09 08:09:00 +00:00
m_OptionIcon[i].Set( pn, asTabs[i-1], false );
2002-09-03 06:33:08 +00:00
}
2005-07-09 08:26:20 +00:00
// lua start
#include "LuaBinding.h"
class LunaOptionIconRow: public Luna<OptionIconRow>
{
public:
LunaOptionIconRow() { LUA->Register( Register ); }
static int set( T* p, lua_State *L ) { p->SetFromGameState( (PlayerNumber) IArg(1) ); return 0; }
static void Register(lua_State *L)
{
ADD_METHOD( set );
2005-07-09 08:26:20 +00:00
Luna<T>::Register( L );
}
};
LUA_REGISTER_DERIVED_CLASS( OptionIconRow, ActorFrame )
// lua end
2004-06-07 21:14:03 +00:00
/*
* (c) 2002-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.
*/