Files
itgmania212121/stepmania/src/PrefsManager.cpp
T

236 lines
9.1 KiB
C++
Raw Normal View History

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"
#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"
#include "RageDisplay.h"
#include "RageUtil.h"
#include "AnnouncerManager.h"
#include "ThemeManager.h"
2002-12-13 22:06:30 +00:00
#include "arch/arch.h" /* for default driver specs */
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-08-17 06:44:04 +00:00
#ifdef _DEBUG
m_bWindowed = true;
#else
2002-05-28 20:01:22 +00:00
m_bWindowed = false;
2002-08-17 06:44:04 +00:00
#endif
m_iDisplayWidth = 640;
m_iDisplayHeight = 480;
m_iDisplayColorDepth = 16;
2003-01-08 03:29:22 +00:00
m_iTextureColorDepth = 32;
2002-11-12 09:23:50 +00:00
m_iRefreshRate = REFRESH_DEFAULT;
m_bIgnoreJoyAxes = true;
m_bOnlyDedicatedMenuButtons = false;
#ifdef _DEBUG
m_bShowStats = true;
#else
m_bShowStats = false;
#endif
2002-07-11 19:02:26 +00:00
m_BackgroundMode = BGMODE_ANIMATIONS;
m_bShowDanger = true;
2002-07-11 19:02:26 +00:00
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;
m_fJudgeWindowSeconds = 0.17f;
m_fJudgeWindowPerfectPercent = 0.25f;
m_fJudgeWindowGreatPercent = 0.50f;
m_fJudgeWindowGoodPercent = 0.75f;
m_fLifeDifficultyScale = 1.0f;
m_iMovieDecodeMS = 2;
2002-08-20 21:00:56 +00:00
m_bUseBGIfNoBanner = false;
2002-08-22 03:35:33 +00:00
m_bDelayedEscape = true;
m_bHowToPlay = true;
m_bShowDontDie = true;
m_bShowSelectGroup = true;
m_bArcadeOptionsNavigation = false;
2002-10-20 19:34:17 +00:00
m_iUnloadTextureDelaySeconds = 0; // disabled 60*30; // 30 mins
2002-10-16 22:23:42 +00:00
m_bCoinOpMode = false;
2002-12-30 21:42:14 +00:00
m_bMusicWheelUsesSections = true;
m_bChangeBannersWhenFast = false;
2002-08-30 04:28:12 +00:00
/* I'd rather get occasional people asking for support for this even though it's
* already here than lots of people asking why songs aren't being displayed. */
m_bHiddenSongs = false;
2002-09-03 00:22:19 +00:00
m_bVsync = true;
2002-02-28 19:40:40 +00:00
2002-12-13 22:06:30 +00:00
m_bSoundDrivers = DEFAULT_SOUND_DRIVER_LIST;
2002-07-23 01:41:40 +00:00
ReadGlobalPrefsFromDisk( true );
2002-02-28 19:40:40 +00:00
}
PrefsManager::~PrefsManager()
{
}
2002-10-16 22:11:11 +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
ini.GetValueB( "Options", "Windowed", m_bWindowed );
ini.GetValueI( "Options", "DisplayWidth", m_iDisplayWidth );
ini.GetValueI( "Options", "DisplayHeight", m_iDisplayHeight );
ini.GetValueI( "Options", "DisplayColorDepth", m_iDisplayColorDepth );
ini.GetValueI( "Options", "TextureColorDepth", m_iTextureColorDepth );
2002-11-12 09:23:50 +00:00
ini.GetValueI( "Options", "RefreshRate", m_iRefreshRate );
ini.GetValueB( "Options", "IgnoreJoyAxes", m_bIgnoreJoyAxes );
ini.GetValueB( "Options", "UseDedicatedMenuButtons", m_bOnlyDedicatedMenuButtons );
ini.GetValueB( "Options", "ShowStats", m_bShowStats );
ini.GetValueI( "Options", "BackgroundMode", (int&)m_BackgroundMode );
ini.GetValueB( "Options", "ShowDanger", m_bShowDanger );
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", "JudgeWindowSeconds", m_fJudgeWindowSeconds );
ini.GetValueF( "Options", "JudgeWindowPerfectPercent", m_fJudgeWindowPerfectPercent );
ini.GetValueF( "Options", "JudgeWindowGreatPercent", m_fJudgeWindowGreatPercent );
ini.GetValueF( "Options", "JudgeWindowGoodPercent", m_fJudgeWindowGoodPercent );
ini.GetValueF( "Options", "LifeDifficultyScale", m_fLifeDifficultyScale );
ini.GetValueI( "Options", "MovieDecodeMS", m_iMovieDecodeMS );
ini.GetValueB( "Options", "UseBGIfNoBanner", m_bUseBGIfNoBanner );
ini.GetValueB( "Options", "DelayedEscape", m_bDelayedEscape );
ini.GetValueB( "Options", "HiddenSongs", m_bHiddenSongs );
ini.GetValueB( "Options", "Vsync", m_bVsync );
ini.GetValueB( "Options", "HowToPlay", m_bHowToPlay );
ini.GetValueB( "Options", "Caution", m_bShowDontDie );
ini.GetValueB( "Options", "SelectGroup", m_bShowSelectGroup );
ini.GetValueB( "Options", "ArcadeOptionsNavigation", m_bArcadeOptionsNavigation );
ini.GetValue ( "Options", "DWIPath", m_DWIPath );
ini.GetValueI( "Options", "UnloadTextureDelaySeconds", m_iUnloadTextureDelaySeconds );
2002-10-16 22:11:11 +00:00
ini.GetValueB( "Options", "CoinOpMode", m_bCoinOpMode );
2002-12-30 21:42:14 +00:00
ini.GetValueB( "Options", "MusicWheelUsesSections", m_bMusicWheelUsesSections );
ini.GetValueB( "Options", "ChangeBannersWhenFast", m_bChangeBannersWhenFast );
2002-12-13 22:06:30 +00:00
ini.GetValue ( "Options", "SoundDrivers", m_bSoundDrivers );
2002-07-11 19:02:26 +00:00
2002-10-24 20:15:24 +00:00
m_asAdditionalSongFolders.clear();
2002-06-27 17:49:10 +00:00
CString sAdditionalSongFolders;
ini.GetValue( "Options", "AdditionalSongFolders", sAdditionalSongFolders );
split( sAdditionalSongFolders, ",", m_asAdditionalSongFolders, 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
ini.SetValueB( "Options", "Windowed", m_bWindowed );
ini.SetValueI( "Options", "DisplayWidth", m_iDisplayWidth );
ini.SetValueI( "Options", "DisplayHeight", m_iDisplayHeight );
ini.SetValueI( "Options", "DisplayColorDepth", m_iDisplayColorDepth );
ini.SetValueI( "Options", "TextureColorDepth", m_iTextureColorDepth );
2002-11-12 09:23:50 +00:00
ini.SetValueI( "Options", "RefreshRate", m_iRefreshRate );
ini.SetValueB( "Options", "IgnoreJoyAxes", m_bIgnoreJoyAxes );
ini.SetValueB( "Options", "UseDedicatedMenuButtons", m_bOnlyDedicatedMenuButtons );
ini.SetValueB( "Options", "ShowStats", m_bShowStats );
ini.SetValueI( "Options", "BackgroundMode", m_BackgroundMode);
ini.SetValueB( "Options", "ShowDanger", m_bShowDanger );
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", "JudgeWindowSeconds", m_fJudgeWindowSeconds );
ini.SetValueF( "Options", "JudgeWindowPerfectPercent", m_fJudgeWindowPerfectPercent );
ini.SetValueF( "Options", "JudgeWindowGreatPercent", m_fJudgeWindowGreatPercent );
ini.SetValueF( "Options", "JudgeWindowGoodPercent", m_fJudgeWindowGoodPercent );
ini.SetValueF( "Options", "LifeDifficultyScale", m_fLifeDifficultyScale );
ini.SetValueI( "Options", "MovieDecodeMS", m_iMovieDecodeMS );
ini.SetValueB( "Options", "UseBGIfNoBanner", m_bUseBGIfNoBanner );
ini.SetValueB( "Options", "DelayedEscape", m_bDelayedEscape );
ini.SetValueB( "Options", "HiddenSongs", m_bHiddenSongs );
ini.SetValueB( "Options", "Vsync", m_bVsync );
ini.SetValueB( "Options", "HowToPlay", m_bHowToPlay );
ini.SetValueB( "Options", "Caution", m_bShowDontDie );
ini.SetValueB( "Options", "SelectGroup", m_bShowSelectGroup );
ini.SetValueB( "Options", "ArcadeOptionsNavigation", m_bArcadeOptionsNavigation );
ini.SetValue ( "Options", "DWIPath", m_DWIPath );
ini.SetValueI( "Options", "UnloadTextureDelaySeconds", m_iUnloadTextureDelaySeconds );
2002-12-30 21:42:14 +00:00
ini.SetValueB( "Options", "MusicWheelUsesSections", m_bMusicWheelUsesSections );
ini.SetValueB( "Options", "ChangeBannersWhenFast", m_bChangeBannersWhenFast );
2002-10-16 22:11:11 +00:00
ini.SetValueB( "Options", "CoinOpMode", m_bCoinOpMode );
/* Only write this if it's been changed. This ensures that we can change
* the default and have it take effect for everyone (except people who
* tweaked this value). */
if(m_bSoundDrivers != DEFAULT_SOUND_DRIVER_LIST)
ini.SetValue ( "Options", "SoundDrivers", m_bSoundDrivers );
2002-02-28 19:40:40 +00:00
ini.SetValue( "Options", "AdditionalSongFolders", join(",", m_asAdditionalSongFolders) );
2002-06-27 17:49:10 +00:00
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" );
ini.ReadFile(); // it's OK if this fails
2002-06-24 22:04:31 +00:00
CString sAnnouncer = sGameName, sTheme = sGameName, sNoteSkin = sGameName;
2002-07-23 01:41:40 +00:00
// if these calls fail, the three strings will keep the initial values set above.
ini.GetValue( "Options", "Announcer", sAnnouncer );
ini.GetValue( "Options", "Theme", sTheme );
ini.GetValue( "Options", "NoteSkin", sNoteSkin );
2002-07-23 01:41:40 +00:00
// it's OK to call these functions with names that don't exist.
2002-07-23 01:41:40 +00:00
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
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