2003-02-16 04:01:45 +00:00
#include "global.h"
2003-02-06 07:32:57 +00:00
/*
-----------------------------------------------------------------------------
Class: NoteSkinManager
Desc: See header.
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
Chris Danford
-----------------------------------------------------------------------------
*/
#include "NoteSkinManager.h"
#include "RageLog.h"
#include "RageException.h"
#include "GameState.h"
#include "GameDef.h"
#include "StyleInput.h"
#include "StyleDef.h"
#include "RageUtil.h"
#include "GameManager.h"
2003-07-22 07:47:27 +00:00
#include "arch/arch.h"
2003-02-06 07:32:57 +00:00
NoteSkinManager * NOTESKIN = NULL ; // global object accessable from anywhere in the program
2003-07-22 07:47:27 +00:00
const CString NOTESKINS_DIR = BASE_PATH "NoteSkins" SLASH ;
2003-08-15 03:14:53 +00:00
const CString GAME_BASE_NOTESKIN_NAME = "default" ;
const CString GLOBAL_BASE_NOTESKIN_DIR = NOTESKINS_DIR + "common" SLASH "default" SLASH ;
2003-02-06 07:32:57 +00:00
NoteSkinManager :: NoteSkinManager ()
{
}
NoteSkinManager ::~ NoteSkinManager ()
{
}
2003-04-22 04:54:04 +00:00
void NoteSkinManager :: RefreshNoteSkinData ( Game game )
2003-02-06 07:32:57 +00:00
{
2003-06-04 20:06:10 +00:00
GameDef * pGameDef = GAMEMAN -> GetGameDefForGame ( game );
2003-02-06 07:32:57 +00:00
2003-07-22 07:47:27 +00:00
CString sBaseSkinFolder = NOTESKINS_DIR + pGameDef -> m_szName + SLASH ;
2003-04-22 04:54:04 +00:00
CStringArray asNoteSkinNames ;
GetDirListing ( sBaseSkinFolder + "*" , asNoteSkinNames , true );
2003-02-06 07:32:57 +00:00
// strip out "CVS"
2003-04-23 02:45:51 +00:00
for ( int i = asNoteSkinNames . size () - 1 ; i >= 0 ; i -- )
2003-04-22 04:54:04 +00:00
if ( 0 == stricmp ( "cvs" , asNoteSkinNames [ i ]) )
asNoteSkinNames . erase ( asNoteSkinNames . begin () + i , asNoteSkinNames . begin () + i + 1 );
2003-02-06 07:32:57 +00:00
2003-04-22 04:54:04 +00:00
m_mapNameToData . clear ();
2003-04-23 02:45:51 +00:00
for ( unsigned j = 0 ; j < asNoteSkinNames . size (); j ++ )
2003-02-06 07:32:57 +00:00
{
2003-04-23 02:45:51 +00:00
CString sName = asNoteSkinNames [ j ];
2003-04-22 04:54:04 +00:00
sName . MakeLower ();
m_mapNameToData [ sName ] = NoteSkinData ();
LoadNoteSkinData ( sName , m_mapNameToData [ sName ] );
2003-02-06 07:32:57 +00:00
}
2003-04-22 04:54:04 +00:00
}
2003-02-06 07:32:57 +00:00
2003-04-22 04:54:04 +00:00
void NoteSkinManager :: LoadNoteSkinData ( CString sNoteSkinName , NoteSkinData & data_out )
{
data_out . sName = sNoteSkinName ;
data_out . metrics . Reset ();
2003-02-09 00:47:11 +00:00
2003-08-15 03:14:53 +00:00
///* Read only the default keys from the default noteskin. */
//IniFile defaults;
//defaults.SetPath( GLOBAL_BASE_NOTESKIN_DIR+"metrics.ini" );
//defaults.ReadFile();
//defaults.SetPath( GetNoteSkinDir(BASE_NOTESKIN_NAME)+"metrics.ini" );
//defaults.ReadFile();
2003-02-09 00:47:11 +00:00
2003-08-15 03:14:53 +00:00
// Why only use NoteDisplay? Now, a few different classes take
// metrics from the NoteSkin. -Chris
//const IniFile::key *def = defaults.GetKey("NoteDisplay");
//if(def)
// data_out.metrics.SetValue("NoteDisplay", *def);
/* Load global NoteSkin defaults */
data_out . metrics . SetPath ( GLOBAL_BASE_NOTESKIN_DIR + "metrics.ini" );
data_out . metrics . ReadFile ();
/* Load game NoteSkin defaults */
data_out . metrics . SetPath ( GetNoteSkinDir ( GAME_BASE_NOTESKIN_NAME ) + "metrics.ini" );
data_out . metrics . ReadFile ();
/* Read the active NoteSkin */
2003-04-22 04:54:04 +00:00
data_out . metrics . SetPath ( GetNoteSkinDir ( sNoteSkinName ) + "metrics.ini" );
data_out . metrics . ReadFile ();
}
void NoteSkinManager :: GetNoteSkinNames ( CStringArray & AddTo )
{
GetNoteSkinNames ( GAMESTATE -> m_CurGame , AddTo );
}
void NoteSkinManager :: GetNoteSkinNames ( Game game , CStringArray & AddTo )
{
2003-06-04 20:06:10 +00:00
RefreshNoteSkinData ( game );
2003-04-22 04:54:04 +00:00
for ( map < CString , NoteSkinData >:: const_iterator iter = m_mapNameToData . begin ();
iter != m_mapNameToData . end ();
++ iter )
{
AddTo . push_back ( iter -> second . sName );
}
2003-06-04 20:06:10 +00:00
/* Put the note skins back. */
RefreshNoteSkinData ( GAMESTATE -> m_CurGame );
2003-04-22 04:54:04 +00:00
}
bool NoteSkinManager :: DoesNoteSkinExist ( CString sSkinName )
{
CStringArray asSkinNames ;
GetNoteSkinNames ( asSkinNames );
for ( unsigned i = 0 ; i < asSkinNames . size (); i ++ )
if ( 0 == stricmp ( sSkinName , asSkinNames [ i ]) )
return true ;
return false ;
2003-02-06 07:32:57 +00:00
}
CString NoteSkinManager :: GetNoteSkinDir ( CString sSkinName )
{
2003-08-15 03:14:53 +00:00
CString sGame = GAMESTATE -> GetCurrentGameDef () -> m_szName ;
2003-02-06 07:32:57 +00:00
2003-08-15 03:14:53 +00:00
return NOTESKINS_DIR + sGame + SLASH + sSkinName + SLASH ;
2003-02-06 07:32:57 +00:00
}
2003-02-17 12:19:42 +00:00
CString NoteSkinManager :: GetMetric ( PlayerNumber pn , CString sButtonName , CString sValue ) // looks in GAMESTATE for the current Style
2003-02-06 07:32:57 +00:00
{
CString sReturn ;
2003-04-22 04:54:04 +00:00
CString sNoteSkinName = GAMESTATE -> m_PlayerOptions [ pn ]. m_sNoteSkin ;
sNoteSkinName . MakeLower ();
NoteSkinData & data = m_mapNameToData [ sNoteSkinName ];
if ( data . metrics . GetValue ( sButtonName , sValue , sReturn ) )
2003-02-08 23:47:47 +00:00
return sReturn ;
2003-04-22 04:54:04 +00:00
if ( ! data . metrics . GetValue ( "NoteDisplay" , sValue , sReturn ) )
2003-08-10 08:58:11 +00:00
RageException :: Throw ( "Could not read metric '[%s] %s' or '[NoteDisplay] %s' in '%s'" ,
2003-07-20 21:23:20 +00:00
sButtonName . c_str (), sValue . c_str (), sValue . c_str (), sNoteSkinName . c_str () );
2003-02-06 07:32:57 +00:00
return sReturn ;
}
2003-02-17 12:19:42 +00:00
int NoteSkinManager :: GetMetricI ( PlayerNumber pn , CString sButtonName , CString sValueName )
2003-02-06 07:32:57 +00:00
{
2003-02-17 12:19:42 +00:00
return atoi ( GetMetric ( pn , sButtonName , sValueName ) );
2003-02-06 07:32:57 +00:00
}
2003-02-17 12:19:42 +00:00
float NoteSkinManager :: GetMetricF ( PlayerNumber pn , CString sButtonName , CString sValueName )
2003-02-06 07:32:57 +00:00
{
2003-02-17 12:19:42 +00:00
return ( float ) atof ( GetMetric ( pn , sButtonName , sValueName ) );
2003-02-06 07:32:57 +00:00
}
2003-02-17 12:19:42 +00:00
bool NoteSkinManager :: GetMetricB ( PlayerNumber pn , CString sButtonName , CString sValueName )
2003-02-06 07:32:57 +00:00
{
2003-02-17 12:19:42 +00:00
return atoi ( GetMetric ( pn , sButtonName , sValueName ) ) != 0 ;
2003-02-06 07:32:57 +00:00
}
2003-02-17 12:19:42 +00:00
RageColor NoteSkinManager :: GetMetricC ( PlayerNumber pn , CString sButtonName , CString sValueName )
2003-02-06 07:32:57 +00:00
{
float r = 1 , b = 1 , g = 1 , a = 1 ; // initialize in case sscanf fails
2003-02-17 12:19:42 +00:00
CString sValue = GetMetric ( pn , sButtonName , sValueName );
2003-02-06 07:32:57 +00:00
char szValue [ 40 ];
strncpy ( szValue , sValue , 39 );
int result = sscanf ( szValue , "%f,%f,%f,%f" , & r , & g , & b , & a );
if ( result != 4 )
{
2003-04-25 00:01:35 +00:00
LOG -> Warn ( "The color value '%s' for theme metric '%s : %s' is invalid." , szValue , sButtonName . c_str (), sValueName . c_str () );
2003-02-06 07:32:57 +00:00
ASSERT ( 0 );
}
return RageColor ( r , g , b , a );
}
2003-02-08 23:47:47 +00:00
CString NoteSkinManager :: ColToButtonName ( int col )
2003-02-06 07:32:57 +00:00
{
const StyleDef * pStyleDef = GAMESTATE -> GetCurrentStyleDef ();
const GameDef * pGameDef = GAMESTATE -> GetCurrentGameDef ();
StyleInput SI ( PLAYER_1 , col );
GameInput GI = pStyleDef -> StyleInputToGameInput ( SI );
2003-02-08 23:47:47 +00:00
return pGameDef -> m_szButtonNames [ GI . button ];
}
2003-02-06 07:32:57 +00:00
2003-04-17 21:45:37 +00:00
CString NoteSkinManager :: GetPathTo ( PlayerNumber pn , int col , CString sFileName )
2003-02-08 23:47:47 +00:00
{
CString sButtonName = ColToButtonName ( col );
2003-02-06 07:32:57 +00:00
2003-04-17 21:45:37 +00:00
return GetPathTo ( pn , sButtonName , sFileName );
}
CString NoteSkinManager :: GetPathTo ( PlayerNumber pn , CString sButtonName , CString sFileName ) // looks in GAMESTATE for the current Style
{
2003-08-15 03:14:53 +00:00
// search active NoteSkin
2003-04-22 04:54:04 +00:00
CString sNoteSkinName = GAMESTATE -> m_PlayerOptions [ pn ]. m_sNoteSkin ;
sNoteSkinName . MakeLower ();
2003-02-06 07:32:57 +00:00
2003-04-22 04:54:04 +00:00
CString ret = GetPathTo ( sNoteSkinName , sButtonName , sFileName );
2003-02-06 07:32:57 +00:00
if ( ! ret . empty () ) // we found something
return ret ;
2003-08-15 03:14:53 +00:00
// Search game default NoteSkin
ret = GetPathTo ( GAME_BASE_NOTESKIN_NAME , sButtonName , sFileName );
if ( ! ret . empty () ) // we found something
return ret ;
// Search global default NoteSkin
ret = GetPathTo ( GAME_BASE_NOTESKIN_NAME , "Fallback" , sFileName , true );
if ( ! ret . empty () ) // we found something
return ret ;
RageException :: Throw ( "The NoteSkin element '%s %s' could not be found in '%s', '%s', or '%s'." ,
2003-04-25 00:01:35 +00:00
sButtonName . c_str (), sFileName . c_str (),
GetNoteSkinDir ( sNoteSkinName ). c_str (),
2003-08-15 03:14:53 +00:00
GetNoteSkinDir ( GAME_BASE_NOTESKIN_NAME ). c_str (),
GAME_BASE_NOTESKIN_NAME . c_str () );
2003-02-06 07:32:57 +00:00
}
2003-08-15 03:14:53 +00:00
CString NoteSkinManager :: GetPathTo ( CString sSkinName , CString sButtonName , CString sElementName , bool bGlobalDefault ) // looks in GAMESTATE for the current Style
2003-02-06 07:32:57 +00:00
{
2003-08-15 03:14:53 +00:00
const CString sDir = bGlobalDefault ? GLOBAL_BASE_NOTESKIN_DIR : GetNoteSkinDir ( sSkinName );
2003-02-06 07:32:57 +00:00
CStringArray arrayPossibleFileNames ; // fill this with the possible files
2003-05-09 04:42:04 +00:00
GetDirListing ( ssprintf ( "%s%s %s*.txt" , sDir . c_str (), sButtonName . c_str (), sElementName . c_str ()), arrayPossibleFileNames , false , true );
2003-04-25 00:01:35 +00:00
GetDirListing ( ssprintf ( "%s%s %s*.sprite" , sDir . c_str (), sButtonName . c_str (), sElementName . c_str ()), arrayPossibleFileNames , false , true );
GetDirListing ( ssprintf ( "%s%s %s*.png" , sDir . c_str (), sButtonName . c_str (), sElementName . c_str ()), arrayPossibleFileNames , false , true );
GetDirListing ( ssprintf ( "%s%s %s*.jpg" , sDir . c_str (), sButtonName . c_str (), sElementName . c_str ()), arrayPossibleFileNames , false , true );
GetDirListing ( ssprintf ( "%s%s %s*.bmp" , sDir . c_str (), sButtonName . c_str (), sElementName . c_str ()), arrayPossibleFileNames , false , true );
GetDirListing ( ssprintf ( "%s%s %s*.gif" , sDir . c_str (), sButtonName . c_str (), sElementName . c_str ()), arrayPossibleFileNames , false , true );
GetDirListing ( ssprintf ( "%s%s %s*" , sDir . c_str (), sButtonName . c_str (), sElementName . c_str ()), arrayPossibleFileNames , false , true );
2003-02-06 07:32:57 +00:00
if ( arrayPossibleFileNames . empty () )
return "" ;
else
return DerefRedir ( arrayPossibleFileNames [ 0 ]);
}