2002-02-28 19:40:40 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
|
/*
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
Class: PrefsManager
|
|
|
|
|
|
|
|
|
|
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-02-28 19:40:40 +00:00
|
|
|
Chris Danford
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "PrefsManager.h"
|
|
|
|
|
#include "IniFile.h"
|
2002-03-19 07:09:49 +00:00
|
|
|
#include "GameManager.h"
|
2002-07-23 01:41:40 +00:00
|
|
|
#include "GameState.h"
|
2002-07-27 19:29:51 +00:00
|
|
|
#include "RageException.h"
|
2002-02-28 19:40:40 +00:00
|
|
|
|
|
|
|
|
|
2002-05-27 08:23:27 +00:00
|
|
|
PrefsManager* PREFSMAN = NULL; // global and accessable from anywhere in our program
|
2002-02-28 19:40:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
PrefsManager::PrefsManager()
|
|
|
|
|
{
|
2002-05-28 20:01:22 +00:00
|
|
|
m_bWindowed = false;
|
2002-07-23 01:41:40 +00:00
|
|
|
m_iDisplayResolution = 640;
|
|
|
|
|
m_iTextureResolution = 512;
|
2002-07-27 19:29:51 +00:00
|
|
|
m_iRefreshRate = 0;
|
2002-05-27 08:23:27 +00:00
|
|
|
m_bIgnoreJoyAxes = false;
|
2002-07-31 19:40:40 +00:00
|
|
|
m_bOnlyDedicatedMenuButtons = false;
|
2002-05-27 08:23:27 +00:00
|
|
|
m_bShowFPS = false;
|
2002-07-11 19:02:26 +00:00
|
|
|
m_BackgroundMode = BGMODE_ANIMATIONS;
|
|
|
|
|
m_fBGBrightness = 0.8f;
|
|
|
|
|
m_bMenuTimer = true;
|
2002-06-27 17:49:10 +00:00
|
|
|
m_bEventMode = false;
|
2002-05-27 08:23:27 +00:00
|
|
|
m_iNumArcadeStages = 3;
|
2002-06-24 22:04:31 +00:00
|
|
|
m_bAutoPlay = false;
|
2002-07-11 19:02:26 +00:00
|
|
|
m_fJudgeWindow = 0.18f;
|
2002-07-31 19:40:40 +00:00
|
|
|
m_fLifeDifficultyScale = 1.0f;
|
2002-02-28 19:40:40 +00:00
|
|
|
|
2002-07-23 01:41:40 +00:00
|
|
|
ReadGlobalPrefsFromDisk( true );
|
2002-02-28 19:40:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PrefsManager::~PrefsManager()
|
|
|
|
|
{
|
2002-07-23 01:41:40 +00:00
|
|
|
SaveGlobalPrefsToDisk();
|
|
|
|
|
SaveGamePrefsToDisk();
|
2002-02-28 19:40:40 +00:00
|
|
|
}
|
|
|
|
|
|
2002-07-23 01:41:40 +00:00
|
|
|
void PrefsManager::ReadGlobalPrefsFromDisk( bool bSwitchToLastPlayedGame )
|
2002-02-28 19:40:40 +00:00
|
|
|
{
|
|
|
|
|
IniFile ini;
|
|
|
|
|
ini.SetPath( "StepMania.ini" );
|
2002-05-27 08:23:27 +00:00
|
|
|
if( !ini.ReadFile() )
|
2002-05-20 08:59:37 +00:00
|
|
|
return; // could not read config file, load nothing
|
2002-02-28 19:40:40 +00:00
|
|
|
|
2002-07-31 19:40:40 +00:00
|
|
|
ini.GetValueB( "Options", "Windowed", m_bWindowed );
|
|
|
|
|
ini.GetValueI( "Options", "DisplayResolution", m_iDisplayResolution );
|
|
|
|
|
ini.GetValueI( "Options", "TextureResolution", m_iTextureResolution );
|
|
|
|
|
ini.GetValueI( "Options", "RefreshRate", m_iRefreshRate );
|
|
|
|
|
ini.GetValueB( "Options", "IgnoreJoyAxes", m_bIgnoreJoyAxes );
|
|
|
|
|
ini.GetValueB( "Options", "UseDedicatedMenuButtons",m_bOnlyDedicatedMenuButtons );
|
|
|
|
|
ini.GetValueB( "Options", "ShowFPS", m_bShowFPS );
|
|
|
|
|
ini.GetValueI( "Options", "BackgroundMode", (int&)m_BackgroundMode );
|
|
|
|
|
ini.GetValueF( "Options", "BGBrightness", m_fBGBrightness );
|
|
|
|
|
ini.GetValueB( "Options", "MenuTimer", m_bMenuTimer );
|
|
|
|
|
ini.GetValueB( "Options", "EventMode", m_bEventMode );
|
|
|
|
|
ini.GetValueI( "Options", "NumArcadeStages", m_iNumArcadeStages );
|
|
|
|
|
ini.GetValueB( "Options", "AutoPlay", m_bAutoPlay );
|
|
|
|
|
ini.GetValueF( "Options", "JudgeWindow", m_fJudgeWindow );
|
|
|
|
|
ini.GetValueF( "Options", "LifeDifficultyScale", m_fLifeDifficultyScale );
|
2002-07-11 19:02:26 +00:00
|
|
|
|
2002-06-27 17:49:10 +00:00
|
|
|
CString sAdditionalSongFolders;
|
|
|
|
|
ini.GetValue( "Options", "SongFolders", sAdditionalSongFolders );
|
|
|
|
|
split( sAdditionalSongFolders, ",", m_asSongFolders, true );
|
2002-07-23 01:41:40 +00:00
|
|
|
|
|
|
|
|
if( bSwitchToLastPlayedGame )
|
|
|
|
|
{
|
|
|
|
|
Game game;
|
|
|
|
|
if( ini.GetValueI("Options", "Game", (int&)game) )
|
2002-07-27 19:29:51 +00:00
|
|
|
GAMESTATE->m_CurGame = game;
|
2002-07-23 01:41:40 +00:00
|
|
|
}
|
2002-02-28 19:40:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-07-23 01:41:40 +00:00
|
|
|
void PrefsManager::SaveGlobalPrefsToDisk()
|
2002-02-28 19:40:40 +00:00
|
|
|
{
|
|
|
|
|
IniFile ini;
|
|
|
|
|
ini.SetPath( "StepMania.ini" );
|
2002-04-28 20:42:32 +00:00
|
|
|
|
2002-07-31 19:40:40 +00:00
|
|
|
ini.SetValueB( "Options", "Windowed", m_bWindowed );
|
|
|
|
|
ini.SetValueI( "Options", "DisplayResolution", m_iDisplayResolution );
|
|
|
|
|
ini.SetValueI( "Options", "TextureResolution", m_iTextureResolution );
|
|
|
|
|
ini.SetValueI( "Options", "RefreshRate", m_iRefreshRate );
|
|
|
|
|
ini.SetValueB( "Options", "IgnoreJoyAxes", m_bIgnoreJoyAxes );
|
|
|
|
|
ini.GetValueB( "Options", "UseDedicatedMenuButtons",m_bOnlyDedicatedMenuButtons );
|
|
|
|
|
ini.SetValueB( "Options", "ShowFPS", m_bShowFPS );
|
|
|
|
|
ini.SetValueI( "Options", "BackgroundMode", m_BackgroundMode);
|
|
|
|
|
ini.SetValueF( "Options", "BGBrightness", m_fBGBrightness );
|
|
|
|
|
ini.SetValueB( "Options", "EventMode", m_bEventMode );
|
|
|
|
|
ini.SetValueB( "Options", "MenuTimer", m_bMenuTimer );
|
|
|
|
|
ini.SetValueI( "Options", "NumArcadeStages", m_iNumArcadeStages );
|
|
|
|
|
ini.SetValueB( "Options", "AutoPlay", m_bAutoPlay );
|
|
|
|
|
ini.SetValueF( "Options", "JudgeWindow", m_fJudgeWindow );
|
|
|
|
|
ini.GetValueF( "Options", "LifeDifficultyScale", m_fLifeDifficultyScale );
|
2002-02-28 19:40:40 +00:00
|
|
|
|
2002-06-27 17:49:10 +00:00
|
|
|
ini.SetValue( "Options", "SongFolders", join(",", m_asSongFolders) );
|
|
|
|
|
|
2002-07-27 19:29:51 +00:00
|
|
|
ini.SetValueI( "Options", "Game", GAMESTATE->m_CurGame );
|
2002-07-23 01:41:40 +00:00
|
|
|
|
2002-02-28 19:40:40 +00:00
|
|
|
ini.WriteFile();
|
|
|
|
|
}
|
|
|
|
|
|
2002-07-23 01:41:40 +00:00
|
|
|
void PrefsManager::ReadGamePrefsFromDisk()
|
2002-05-29 09:47:24 +00:00
|
|
|
{
|
2002-07-23 01:41:40 +00:00
|
|
|
if( !GAMESTATE )
|
|
|
|
|
return;
|
2002-05-29 09:47:24 +00:00
|
|
|
|
2002-07-23 01:41:40 +00:00
|
|
|
CString sGameName = GAMESTATE->GetCurrentGameDef()->m_szName;
|
|
|
|
|
IniFile ini;
|
|
|
|
|
ini.SetPath( sGameName + "Prefs.ini" );
|
|
|
|
|
if( !ini.ReadFile() )
|
|
|
|
|
return; // could not read config file, load nothing
|
2002-06-23 02:50:33 +00:00
|
|
|
|
2002-07-23 01:41:40 +00:00
|
|
|
CString sAnnouncer, sTheme, sNoteSkin;
|
2002-06-24 22:04:31 +00:00
|
|
|
|
2002-07-23 01:41:40 +00:00
|
|
|
ini.GetValue( "Options", "Announcer", sAnnouncer );
|
|
|
|
|
ini.GetValue( "Options", "Theme", sTheme );
|
|
|
|
|
ini.GetValue( "Options", "NoteSkin", sNoteSkin );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ANNOUNCER->SwitchAnnouncer( sAnnouncer );
|
|
|
|
|
THEME->SwitchTheme( sTheme );
|
|
|
|
|
GAMEMAN->SwitchNoteSkin( sNoteSkin );
|
2002-05-19 01:59:48 +00:00
|
|
|
}
|
2002-02-28 19:40:40 +00:00
|
|
|
|
2002-07-23 01:41:40 +00:00
|
|
|
void PrefsManager::SaveGamePrefsToDisk()
|
2002-03-31 07:55:25 +00:00
|
|
|
{
|
2002-07-23 01:41:40 +00:00
|
|
|
if( !GAMESTATE )
|
|
|
|
|
return;
|
2002-06-24 22:04:31 +00:00
|
|
|
|
2002-07-23 01:41:40 +00:00
|
|
|
CString sGameName = GAMESTATE->GetCurrentGameDef()->m_szName;
|
|
|
|
|
IniFile ini;
|
|
|
|
|
ini.SetPath( sGameName + "Prefs.ini" );
|
2002-03-31 07:55:25 +00:00
|
|
|
|
2002-07-23 01:41:40 +00:00
|
|
|
ini.SetValue( "Options", "Announcer", ANNOUNCER->GetCurAnnouncerName() );
|
|
|
|
|
ini.SetValue( "Options", "Theme", THEME->GetCurThemeName() );
|
|
|
|
|
ini.SetValue( "Options", "NoteSkin", GAMEMAN->GetCurNoteSkin() );
|
2002-06-24 22:04:31 +00:00
|
|
|
|
2002-07-23 01:41:40 +00:00
|
|
|
ini.WriteFile();
|
2002-03-31 07:55:25 +00:00
|
|
|
}
|
2002-07-27 19:29:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
int PrefsManager::GetDisplayHeight()
|
|
|
|
|
{
|
|
|
|
|
switch( m_iDisplayResolution )
|
|
|
|
|
{
|
|
|
|
|
case 1280: return 1024; break;
|
|
|
|
|
case 1024: return 768; break;
|
|
|
|
|
case 800: return 600; break;
|
|
|
|
|
case 640: return 480; break;
|
|
|
|
|
case 512: return 384; break;
|
|
|
|
|
case 400: return 300; break;
|
|
|
|
|
case 320: return 240; break;
|
|
|
|
|
default: throw RageException( "Invalid DisplayWidth '%d'", m_iDisplayResolution ); return 480;
|
|
|
|
|
}
|
|
|
|
|
}
|