2002-04-16 17:31:00 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
|
/*
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
Class: GameDef
|
|
|
|
|
|
|
|
|
|
Desc: See header.
|
|
|
|
|
|
2002-05-19 01:59:48 +00:00
|
|
|
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
|
2002-04-16 17:31:00 +00:00
|
|
|
Chris Danford
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "GameDef.h"
|
2002-05-01 19:14:55 +00:00
|
|
|
#include "RageLog.h"
|
2002-04-16 17:31:00 +00:00
|
|
|
#include "RageUtil.h"
|
2002-04-28 20:42:32 +00:00
|
|
|
#include "IniFile.h"
|
|
|
|
|
#include "StyleDef.h"
|
2002-07-27 19:29:51 +00:00
|
|
|
#include "RageException.h"
|
2002-07-31 19:40:40 +00:00
|
|
|
#include "GameState.h"
|
|
|
|
|
#include "InputMapper.h"
|
|
|
|
|
#include "PrefsManager.h"
|
2002-04-28 20:42:32 +00:00
|
|
|
|
|
|
|
|
|
2002-07-23 01:41:40 +00:00
|
|
|
CString GameDef::ElementToGraphicSuffix( const SkinElement gbg )
|
2002-04-16 17:31:00 +00:00
|
|
|
{
|
|
|
|
|
CString sAssetPath; // fill this in below
|
|
|
|
|
|
|
|
|
|
switch( gbg )
|
|
|
|
|
{
|
2002-08-13 23:26:46 +00:00
|
|
|
case GRAPHIC_TAP_PARTS: sAssetPath = "tap parts"; break;
|
|
|
|
|
case GRAPHIC_HOLD_PARTS: sAssetPath = "hold parts"; break;
|
2002-04-16 17:31:00 +00:00
|
|
|
case GRAPHIC_RECEPTOR: sAssetPath = "receptor"; break;
|
|
|
|
|
case GRAPHIC_HOLD_EXPLOSION: sAssetPath = "hold explosion"; break;
|
|
|
|
|
case GRAPHIC_TAP_EXPLOSION_BRIGHT: sAssetPath = "tap explosion bright"; break;
|
|
|
|
|
case GRAPHIC_TAP_EXPLOSION_DIM: sAssetPath = "tap explosion dim"; break;
|
|
|
|
|
|
|
|
|
|
default:
|
2002-08-13 23:26:46 +00:00
|
|
|
ASSERT(0); // invalid SkinElement
|
2002-04-16 17:31:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sAssetPath;
|
|
|
|
|
}
|
|
|
|
|
|
2002-07-23 01:41:40 +00:00
|
|
|
CString GameDef::GetPathToGraphic( const CString sSkinName, const CString sButtonName, const SkinElement gbg )
|
2002-04-16 17:31:00 +00:00
|
|
|
{
|
2002-05-27 08:23:27 +00:00
|
|
|
const CString sSkinDir = ssprintf("Skins\\%s\\%s\\", m_szName, sSkinName);
|
2002-04-16 17:31:00 +00:00
|
|
|
const CString sGraphicSuffix = ElementToGraphicSuffix( gbg );
|
|
|
|
|
|
|
|
|
|
CStringArray arrayPossibleFileNames; // fill this with the possible files
|
|
|
|
|
|
2002-04-28 20:42:32 +00:00
|
|
|
GetDirListing( ssprintf("%s%s %s*.sprite", sSkinDir, sButtonName, sGraphicSuffix), arrayPossibleFileNames );
|
|
|
|
|
GetDirListing( ssprintf("%s%s %s*.png", sSkinDir, sButtonName, sGraphicSuffix), arrayPossibleFileNames );
|
|
|
|
|
GetDirListing( ssprintf("%s%s %s*.jpg", sSkinDir, sButtonName, sGraphicSuffix), arrayPossibleFileNames );
|
|
|
|
|
GetDirListing( ssprintf("%s%s %s*.bmp", sSkinDir, sButtonName, sGraphicSuffix), arrayPossibleFileNames );
|
2002-04-16 17:31:00 +00:00
|
|
|
|
|
|
|
|
if( arrayPossibleFileNames.GetSize() > 0 )
|
2002-04-28 20:42:32 +00:00
|
|
|
return sSkinDir + arrayPossibleFileNames[0];
|
2002-04-16 17:31:00 +00:00
|
|
|
|
2002-08-13 23:26:46 +00:00
|
|
|
ASSERT(0);
|
2002-06-14 22:25:22 +00:00
|
|
|
throw RageException( "The game button graphic '%s%s %s' is missing.", sSkinDir, sButtonName, sGraphicSuffix );
|
2002-04-16 17:31:00 +00:00
|
|
|
return "";
|
|
|
|
|
}
|
2002-05-19 01:59:48 +00:00
|
|
|
|
2002-08-03 18:40:09 +00:00
|
|
|
void GameDef::GetTapTweenColors( const CString sSkinName, const CString sButtonName, CArray<D3DXCOLOR,D3DXCOLOR> &aTapColorsOut )
|
2002-05-19 01:59:48 +00:00
|
|
|
{
|
2002-05-27 08:23:27 +00:00
|
|
|
const CString sSkinDir = ssprintf("Skins\\%s\\%s\\", m_szName, sSkinName);
|
2002-05-19 01:59:48 +00:00
|
|
|
|
2002-08-03 18:40:09 +00:00
|
|
|
const CString sColorsFilePath = sSkinDir + sButtonName + " Tap.colors";
|
2002-05-19 01:59:48 +00:00
|
|
|
|
2002-08-03 18:40:09 +00:00
|
|
|
FILE* fp = fopen( sColorsFilePath, "r" );
|
|
|
|
|
ASSERT( fp != NULL );
|
|
|
|
|
if( fp == NULL )
|
|
|
|
|
{
|
|
|
|
|
ASSERT(0);
|
|
|
|
|
aTapColorsOut.Add( D3DXCOLOR(1,1,1,1) );
|
|
|
|
|
LOG->Warn( "Couldn't open .colors file '%s'", sColorsFilePath );
|
2002-05-19 01:59:48 +00:00
|
|
|
return;
|
2002-08-03 18:40:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool bSuccess;
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
D3DXCOLOR color;
|
|
|
|
|
int retval = fscanf( fp, "%f,%f,%f,%f\n", &color.r, &color.g, &color.b, &color.a );
|
|
|
|
|
bSuccess = retval == 4;
|
|
|
|
|
if( bSuccess )
|
|
|
|
|
aTapColorsOut.Add( color );
|
|
|
|
|
} while( bSuccess );
|
|
|
|
|
|
2002-08-13 23:26:46 +00:00
|
|
|
if( aTapColorsOut.GetSize() == 0 )
|
|
|
|
|
aTapColorsOut.Add( D3DXCOLOR(1,1,1,1) );
|
|
|
|
|
|
2002-08-03 18:40:09 +00:00
|
|
|
fclose( fp );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GameDef::GetHoldTweenColors( const CString sSkinName, const CString sButtonName, CArray<D3DXCOLOR,D3DXCOLOR> &aHoldColorsOut )
|
|
|
|
|
{
|
|
|
|
|
const CString sSkinDir = ssprintf("Skins\\%s\\%s\\", m_szName, sSkinName);
|
|
|
|
|
|
|
|
|
|
const CString sColorsFilePath = sSkinDir + sButtonName + " Hold.colors";
|
|
|
|
|
|
|
|
|
|
FILE* fp = fopen( sColorsFilePath, "r" );
|
|
|
|
|
ASSERT( fp != NULL );
|
|
|
|
|
if( fp == NULL )
|
|
|
|
|
{
|
|
|
|
|
ASSERT(0);
|
|
|
|
|
aHoldColorsOut.Add( D3DXCOLOR(1,1,1,1) );
|
|
|
|
|
LOG->Warn( "Couldn't open .colors file '%s'", sColorsFilePath );
|
|
|
|
|
return;
|
|
|
|
|
}
|
2002-05-19 01:59:48 +00:00
|
|
|
|
|
|
|
|
bool bSuccess;
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
D3DXCOLOR color;
|
2002-08-03 18:40:09 +00:00
|
|
|
int retval = fscanf( fp, "%f,%f,%f,%f\n", &color.r, &color.g, &color.b, &color.a );
|
2002-05-19 01:59:48 +00:00
|
|
|
bSuccess = retval == 4;
|
|
|
|
|
if( bSuccess )
|
2002-08-03 18:40:09 +00:00
|
|
|
aHoldColorsOut.Add( color );
|
2002-05-19 01:59:48 +00:00
|
|
|
} while( bSuccess );
|
|
|
|
|
|
2002-08-03 18:40:09 +00:00
|
|
|
fclose( fp );
|
2002-05-19 01:59:48 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2002-05-27 08:23:27 +00:00
|
|
|
void GameDef::GetSkinNames( CStringArray &AddTo )
|
|
|
|
|
{
|
|
|
|
|
CString sBaseSkinFolder = "Skins\\" + CString(m_szName) + "\\";
|
|
|
|
|
GetDirListing( sBaseSkinFolder + "*.*", AddTo, true );
|
2002-05-27 18:36:01 +00:00
|
|
|
|
|
|
|
|
// strip out "CVS"
|
|
|
|
|
for( int i=AddTo.GetSize()-1; i>=0; i-- )
|
|
|
|
|
if( 0 == stricmp("cvs", AddTo[i]) )
|
|
|
|
|
AddTo.RemoveAt( i );
|
|
|
|
|
|
2002-05-27 08:23:27 +00:00
|
|
|
if( AddTo.GetSize() == 0 )
|
2002-06-14 22:25:22 +00:00
|
|
|
throw RageException( "The folder '%s' must contain at least one skin.", sBaseSkinFolder );
|
2002-05-27 08:23:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool GameDef::HasASkinNamed( CString sSkin )
|
|
|
|
|
{
|
|
|
|
|
CStringArray asSkinNames;
|
|
|
|
|
GetSkinNames( asSkinNames );
|
|
|
|
|
|
|
|
|
|
for( int i=0; i<asSkinNames.GetSize(); i++ )
|
|
|
|
|
if( asSkinNames[i] == sSkin )
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GameDef::AssertSkinsAreComplete()
|
|
|
|
|
{
|
|
|
|
|
CStringArray asSkinNames;
|
|
|
|
|
GetSkinNames( asSkinNames );
|
|
|
|
|
|
|
|
|
|
for( int i=0; i<asSkinNames.GetSize(); i++ )
|
2002-07-23 01:41:40 +00:00
|
|
|
AssertSkinIsComplete( asSkinNames[i] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GameDef::AssertSkinIsComplete( CString sSkin )
|
|
|
|
|
{
|
|
|
|
|
CString sGameSkinFolder = "Skins\\" + sSkin + "\\";
|
|
|
|
|
|
|
|
|
|
for( int j=0; j<NUM_GAME_BUTTON_GRAPHICS; j++ )
|
2002-05-27 08:23:27 +00:00
|
|
|
{
|
2002-07-23 01:41:40 +00:00
|
|
|
SkinElement gbg = (SkinElement)j;
|
|
|
|
|
CString sButtonName = m_szButtonNames[j];
|
|
|
|
|
CString sPathToGraphic = GetPathToGraphic( sSkin, sButtonName, gbg );
|
|
|
|
|
if( !DoesFileExist(sPathToGraphic) )
|
|
|
|
|
throw RageException( "Game button graphic at %s is missing.", sPathToGraphic );
|
|
|
|
|
}
|
2002-05-27 08:23:27 +00:00
|
|
|
}
|
2002-07-31 19:40:40 +00:00
|
|
|
|
|
|
|
|
MenuInput GameDef::GameInputToMenuInput( GameInput GameI )
|
|
|
|
|
{
|
|
|
|
|
PlayerNumber pn;
|
|
|
|
|
|
2002-08-13 23:26:46 +00:00
|
|
|
StyleDef::StyleType type = StyleDef::TWO_PLAYERS_TWO_CREDITS;
|
2002-07-31 19:40:40 +00:00
|
|
|
if( GAMESTATE->m_CurStyle != STYLE_NONE )
|
|
|
|
|
type = GAMESTATE->GetCurrentStyleDef()->m_StyleType;
|
|
|
|
|
switch( type )
|
|
|
|
|
{
|
2002-08-13 23:26:46 +00:00
|
|
|
case StyleDef::ONE_PLAYER_ONE_CREDIT:
|
|
|
|
|
case StyleDef::TWO_PLAYERS_TWO_CREDITS:
|
2002-07-31 19:40:40 +00:00
|
|
|
pn = (PlayerNumber)GameI.controller;
|
|
|
|
|
break;
|
2002-08-13 23:26:46 +00:00
|
|
|
case StyleDef::ONE_PLAYER_TWO_CREDITS:
|
|
|
|
|
pn = GAMESTATE->m_bIsJoined[PLAYER_1] ? PLAYER_1 : PLAYER_2;
|
2002-07-31 19:40:40 +00:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
ASSERT(0); // invalid m_StyleType
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
for( int i=0; i<NUM_MENU_BUTTONS; i++ )
|
|
|
|
|
if( m_DedicatedMenuButton[i] == GameI.button )
|
|
|
|
|
return MenuInput( pn, (MenuButton)i );
|
|
|
|
|
|
|
|
|
|
for( i=0; i<NUM_MENU_BUTTONS; i++ )
|
|
|
|
|
if( m_SecondaryMenuButton[i] == GameI.button )
|
|
|
|
|
return MenuInput( pn, (MenuButton)i );
|
|
|
|
|
|
|
|
|
|
return MenuInput(); // invalid GameInput
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GameDef::MenuInputToGameInput( MenuInput MenuI, GameInput GameIout[4] )
|
|
|
|
|
{
|
|
|
|
|
ASSERT( MenuI.IsValid() );
|
|
|
|
|
|
|
|
|
|
GameIout[0].MakeInvalid(); // initialize
|
|
|
|
|
GameIout[1].MakeInvalid();
|
|
|
|
|
GameIout[2].MakeInvalid();
|
|
|
|
|
GameIout[3].MakeInvalid();
|
|
|
|
|
|
|
|
|
|
GameController controller[2];
|
|
|
|
|
int iNumSidesUsing = 1;
|
|
|
|
|
switch( GAMESTATE->GetCurrentStyleDef()->m_StyleType )
|
|
|
|
|
{
|
2002-08-13 23:26:46 +00:00
|
|
|
case StyleDef::ONE_PLAYER_ONE_CREDIT:
|
|
|
|
|
case StyleDef::TWO_PLAYERS_TWO_CREDITS:
|
2002-07-31 19:40:40 +00:00
|
|
|
controller[0] = (GameController)MenuI.player;
|
|
|
|
|
iNumSidesUsing = 1;
|
|
|
|
|
break;
|
2002-08-13 23:26:46 +00:00
|
|
|
case StyleDef::ONE_PLAYER_TWO_CREDITS:
|
2002-07-31 19:40:40 +00:00
|
|
|
controller[0] = GAME_CONTROLLER_1;
|
|
|
|
|
controller[1] = GAME_CONTROLLER_2;
|
|
|
|
|
iNumSidesUsing = 2;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
ASSERT(0); // invalid m_StyleType
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
GameButton button[2] = { m_DedicatedMenuButton[MenuI.button], m_SecondaryMenuButton[MenuI.button] };
|
|
|
|
|
int iNumButtonsUsing = PREFSMAN->m_bOnlyDedicatedMenuButtons ? 1 : 2;
|
|
|
|
|
|
|
|
|
|
for( int i=0; i<iNumSidesUsing; i++ )
|
|
|
|
|
{
|
|
|
|
|
for( int j=0; j<iNumButtonsUsing; j++ )
|
2002-08-01 20:30:40 +00:00
|
|
|
{
|
|
|
|
|
GameIout[i*2+j].controller = controller[i];
|
|
|
|
|
GameIout[i*2+j].button = button[j];
|
|
|
|
|
}
|
2002-07-31 19:40:40 +00:00
|
|
|
}
|
|
|
|
|
}
|