Skip to content

Commit

Permalink
Store all settings in .INI
Browse files Browse the repository at this point in the history
  • Loading branch information
erorcun authored and shfil committed Jan 17, 2021
1 parent 5a47379 commit 448e41e
Show file tree
Hide file tree
Showing 10 changed files with 408 additions and 118 deletions.
2 changes: 1 addition & 1 deletion src/core/ControllerConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2797,7 +2797,7 @@ void CControllerConfigManager::ResetSettingOrder(e_ControllerAction action)
for (int32 k = 0; k < MAX_CONTROLLERTYPES; k++)
{
int32 setorder = m_aSettings[action][k].m_ContSetOrder;
if (setorder > i && setorder != KEYBOARD)
if (setorder > i && setorder != 0)
{
if (init)
{
Expand Down
61 changes: 45 additions & 16 deletions src/core/Frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -862,15 +862,23 @@ CMenuManager::CheckCodesForControls(int typeOfControl)
m_bWaitingForNewKeyBind = false;
m_KeyPressedCode = -1;
m_bStartWaitingForKeyBind = false;
#ifdef LOAD_INI_SETTINGS
SaveINIControllerSettings();
#else
SaveSettings();
#endif
}

if (escPressed) {
pControlEdit = nil;
m_bWaitingForNewKeyBind = false;
m_KeyPressedCode = -1;
m_bStartWaitingForKeyBind = false;
#ifdef LOAD_INI_SETTINGS
SaveINIControllerSettings();
#else
SaveSettings();
#endif
}
}

Expand Down Expand Up @@ -3570,13 +3578,21 @@ CMenuManager::LoadAllTextures()
DMAudio.ChangeMusicMode(MUSICMODE_FRONTEND);
DMAudio.PlayFrontEndSound(SOUND_FRONTEND_MENU_STARTING, 0);
m_nCurrOption = 0;

#ifdef FIX_BUGS
static bool firstTime = true;
if (firstTime) {
DMAudio.SetRadioInCar(m_PrefsRadioStation);
firstTime = false;
} else
#endif
m_PrefsRadioStation = DMAudio.GetRadioInCar();

if (DMAudio.IsMP3RadioChannelAvailable()) {
if (m_PrefsRadioStation > USERTRACK)
m_PrefsRadioStation = CGeneral::GetRandomNumber() % 10;
m_PrefsRadioStation = CGeneral::GetRandomNumber() % (USERTRACK + 1);
} else if (m_PrefsRadioStation > CHATTERBOX)
m_PrefsRadioStation = CGeneral::GetRandomNumber() % 9;
m_PrefsRadioStation = CGeneral::GetRandomNumber() % (CHATTERBOX + 1);

CFileMgr::SetDir("");
//CFileMgr::SetDir("");
Expand Down Expand Up @@ -3711,6 +3727,11 @@ CMenuManager::LoadSettings()
CFileMgr::CloseFile(fileHandle);
CFileMgr::SetDir("");

#ifdef LOAD_INI_SETTINGS
LoadINISettings();
LoadINIControllerSettings(); // Calling that after LoadINISettings is important because of gSelectedJoystickName loading
#endif

m_PrefsVsync = m_PrefsVsyncDisp;
CRenderer::ms_lodDistScale = m_PrefsLOD;

Expand Down Expand Up @@ -3749,15 +3770,12 @@ CMenuManager::LoadSettings()
strcpy(m_PrefsSkinFile, DEFAULT_SKIN_NAME);
strcpy(m_aSkinName, DEFAULT_SKIN_NAME);
}

#ifdef LOAD_INI_SETTINGS
LoadINISettings(); // needs frontend options to be loaded
#endif
}

void
CMenuManager::SaveSettings()
{
#ifndef LOAD_INI_SETTINGS
static char RubbishString[48] = "stuffmorestuffevenmorestuff etc";

CFileMgr::SetDirMyDocuments();
Expand Down Expand Up @@ -3807,7 +3825,13 @@ CMenuManager::SaveSettings()
CFileMgr::CloseFile(fileHandle);
CFileMgr::SetDir("");

#ifdef LOAD_INI_SETTINGS
#else
static bool firstTime = true;
// In other conditions we already call SaveINIControllerSettings explicitly.
if (firstTime) {
SaveINIControllerSettings();
firstTime = false;
}
SaveINISettings();
#endif
}
Expand Down Expand Up @@ -4117,19 +4141,19 @@ CMenuManager::Process(void)
MouseButtonJustClicked = false;

if (CPad::GetPad(0)->GetLeftMouseJustDown())
MouseButtonJustClicked = 1;
MouseButtonJustClicked = rsMOUSELEFTBUTTON;
else if (CPad::GetPad(0)->GetRightMouseJustUp())
MouseButtonJustClicked = 3;
MouseButtonJustClicked = rsMOUSERIGHTBUTTON;
else if (CPad::GetPad(0)->GetMiddleMouseJustUp())
MouseButtonJustClicked = 2;
MouseButtonJustClicked = rsMOUSMIDDLEBUTTON;
else if (CPad::GetPad(0)->GetMouseWheelUpJustUp())
MouseButtonJustClicked = 4;
MouseButtonJustClicked = rsMOUSEWHEELUPBUTTON;
else if (CPad::GetPad(0)->GetMouseWheelDownJustUp())
MouseButtonJustClicked = 5;
MouseButtonJustClicked = rsMOUSEWHEELDOWNBUTTON;
else if (CPad::GetPad(0)->GetMouseX1JustUp())
MouseButtonJustClicked = 6;
MouseButtonJustClicked = rsMOUSEX1BUTTON;
else if (CPad::GetPad(0)->GetMouseX2JustUp())
MouseButtonJustClicked = 7;
MouseButtonJustClicked = rsMOUSEX2BUTTON;

JoyButtonJustClicked = ControlsManager.GetJoyButtonJustDown();

Expand Down Expand Up @@ -5047,6 +5071,9 @@ CMenuManager::ProcessButtonPresses(void)
CVehicle::m_bDisableMouseSteering = true;
TheCamera.m_bHeadBob = false;
SaveSettings();
#ifdef LOAD_INI_SETTINGS
SaveINIControllerSettings();
#endif
}
SetHelperText(2);
break;
Expand Down Expand Up @@ -5098,7 +5125,8 @@ CMenuManager::ProcessButtonPresses(void)

*option.m_CFO->value = option.m_CFOSelect->lastSavedValue = option.m_CFOSelect->displayedValue;

if (option.m_CFOSelect->save)
// Now everything is saved in .ini, and LOAD_INI_SETTINGS is fundamental for CFO
// if (option.m_CFOSelect->save)
SaveSettings();

if (option.m_CFOSelect->displayedValue != oldValue && option.m_CFOSelect->changeFunc)
Expand Down Expand Up @@ -5332,7 +5360,8 @@ CMenuManager::ProcessButtonPresses(void)

*option.m_CFO->value = option.m_CFOSelect->lastSavedValue = option.m_CFOSelect->displayedValue;

if (option.m_CFOSelect->save)
// Now everything is saved in .ini, and LOAD_INI_SETTINGS is fundamental for CFO
// if (option.m_CFOSelect->save)
SaveSettings();

if (option.m_CFOSelect->displayedValue != oldValue && option.m_CFOSelect->changeFunc)
Expand Down
7 changes: 5 additions & 2 deletions src/core/Frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ struct CCustomScreenLayout {
struct CCFO
{
int8 *value;
const char *saveCat;
const char *save;
};

Expand All @@ -508,11 +509,12 @@ struct CCFOSelect : CCFO
bool disableIfGameLoaded;

CCFOSelect() {};
CCFOSelect(int8* value, const char* save, const char** rightTexts, int8 numRightTexts, bool onlyApplyOnEnter, ChangeFunc changeFunc = nil, bool disableIfGameLoaded = false){
CCFOSelect(int8* value, const char* saveCat, const char* save, const char** rightTexts, int8 numRightTexts, bool onlyApplyOnEnter, ChangeFunc changeFunc = nil, bool disableIfGameLoaded = false){
this->value = value;
if (value)
this->lastSavedValue = this->displayedValue = *value;

this->saveCat = saveCat;
this->save = save;
this->rightTexts = (char**)rightTexts;
this->numRightTexts = numRightTexts;
Expand All @@ -528,8 +530,9 @@ struct CCFODynamic : CCFO
ButtonPressFunc buttonPressFunc;

CCFODynamic() {};
CCFODynamic(int8* value, const char* save, DrawFunc drawFunc, ButtonPressFunc buttonPressFunc){
CCFODynamic(int8* value, const char* saveCat, const char* save, DrawFunc drawFunc, ButtonPressFunc buttonPressFunc){
this->value = value;
this->saveCat = saveCat;
this->save = save;
this->drawFunc = drawFunc;
this->buttonPressFunc = buttonPressFunc;
Expand Down
30 changes: 15 additions & 15 deletions src/core/MenuScreensCustom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,51 +24,51 @@
#ifdef CUSTOM_FRONTEND_OPTIONS

#ifdef IMPROVED_VIDEOMODE
#define VIDEOMODE_SELECTOR MENUACTION_CFO_SELECT, "FEM_SCF", { new CCFOSelect((int8*)&FrontEndMenuManager.m_nPrefsWindowed, nil, screenModes, 2, true, ScreenModeAfterChange, true) },
#define VIDEOMODE_SELECTOR MENUACTION_CFO_SELECT, "FEM_SCF", { new CCFOSelect((int8*)&FrontEndMenuManager.m_nPrefsWindowed, "VideoMode", "Windowed", screenModes, 2, true, ScreenModeAfterChange, true) },
#else
#define VIDEOMODE_SELECTOR
#endif

#ifdef MULTISAMPLING
#define MULTISAMPLING_SELECTOR MENUACTION_CFO_DYNAMIC, "FED_AAS", { new CCFODynamic((int8*)&FrontEndMenuManager.m_nPrefsMSAALevel, "MultiSampling", MultiSamplingDraw, MultiSamplingButtonPress) },
#define MULTISAMPLING_SELECTOR MENUACTION_CFO_DYNAMIC, "FED_AAS", { new CCFODynamic((int8*)&FrontEndMenuManager.m_nPrefsMSAALevel, "Graphics", "MultiSampling", MultiSamplingDraw, MultiSamplingButtonPress) },
#else
#define MULTISAMPLING_SELECTOR
#endif

#ifdef CUTSCENE_BORDERS_SWITCH
#define CUTSCENE_BORDERS_TOGGLE MENUACTION_CFO_SELECT, "FEM_CSB", { new CCFOSelect((int8 *)&CMenuManager::m_PrefsCutsceneBorders, "CutsceneBorders", off_on, 2, false) },
#define CUTSCENE_BORDERS_TOGGLE MENUACTION_CFO_SELECT, "FEM_CSB", { new CCFOSelect((int8 *)&CMenuManager::m_PrefsCutsceneBorders, "Display", "CutsceneBorders", off_on, 2, false) },
#else
#define CUTSCENE_BORDERS_TOGGLE
#endif

#ifdef FREE_CAM
#define FREE_CAM_TOGGLE MENUACTION_CFO_SELECT, "FEC_FRC", { new CCFOSelect((int8*)&TheCamera.bFreeCam, "FreeCam", off_on, 2, false) },
#define FREE_CAM_TOGGLE MENUACTION_CFO_SELECT, "FEC_FRC", { new CCFOSelect((int8*)&TheCamera.bFreeCam, "Display", "FreeCam", off_on, 2, false) },
#else
#define FREE_CAM_TOGGLE
#endif

#ifdef PS2_ALPHA_TEST
#define DUALPASS_SELECTOR MENUACTION_CFO_SELECT, "FEM_2PR", { new CCFOSelect((int8*)&gPS2alphaTest, "PS2AlphaTest", off_on, 2, false) },
#define DUALPASS_SELECTOR MENUACTION_CFO_SELECT, "FEM_2PR", { new CCFOSelect((int8*)&gPS2alphaTest, "Graphics", "PS2AlphaTest", off_on, 2, false) },
#else
#define DUALPASS_SELECTOR
#endif

#ifdef NO_ISLAND_LOADING
#define ISLAND_LOADING_SELECTOR MENUACTION_CFO_SELECT, "FEM_ISL", { new CCFOSelect((int8*)&CMenuManager::m_PrefsIslandLoading, "IslandLoading", islandLoadingOpts, ARRAY_SIZE(islandLoadingOpts), true, IslandLoadingAfterChange) },
#define ISLAND_LOADING_SELECTOR MENUACTION_CFO_SELECT, "FEM_ISL", { new CCFOSelect((int8*)&CMenuManager::m_PrefsIslandLoading, "Graphics", "IslandLoading", islandLoadingOpts, ARRAY_SIZE(islandLoadingOpts), true, IslandLoadingAfterChange) },
#else
#define ISLAND_LOADING_SELECTOR
#endif

#ifdef EXTENDED_COLOURFILTER
#define POSTFX_SELECTORS \
MENUACTION_CFO_SELECT, "FED_CLF", { new CCFOSelect((int8*)&CPostFX::EffectSwitch, "ColourFilter", filterNames, ARRAY_SIZE(filterNames), false) }, \
MENUACTION_CFO_SELECT, "FED_MBL", { new CCFOSelect((int8*)&CPostFX::MotionBlurOn, "MotionBlur", off_on, 2, false) },
MENUACTION_CFO_SELECT, "FED_CLF", { new CCFOSelect((int8*)&CPostFX::EffectSwitch, "Graphics", "ColourFilter", filterNames, ARRAY_SIZE(filterNames), false) }, \
MENUACTION_CFO_SELECT, "FED_MBL", { new CCFOSelect((int8*)&CPostFX::MotionBlurOn, "Graphics", "MotionBlur", off_on, 2, false) },
#else
#define POSTFX_SELECTORS
#endif

#ifdef INVERT_LOOK_FOR_PAD
#define INVERT_PAD_SELECTOR MENUACTION_CFO_SELECT, "FEC_IVP", { new CCFOSelect((int8*)&CPad::bInvertLook4Pad, "InvertPad", off_on, 2, false) },
#define INVERT_PAD_SELECTOR MENUACTION_CFO_SELECT, "FEC_IVP", { new CCFOSelect((int8*)&CPad::bInvertLook4Pad, "Controller", "InvertPad", off_on, 2, false) },
#else
#define INVERT_PAD_SELECTOR
#endif
Expand Down Expand Up @@ -405,7 +405,7 @@ CMenuScreenCustom aScreens[MENUPAGES] = {
CUTSCENE_BORDERS_TOGGLE
FREE_CAM_TOGGLE
MENUACTION_SUBTITLES, "FED_SUB", { nil, SAVESLOT_NONE, MENUPAGE_DISPLAY_SETTINGS },
MENUACTION_CFO_DYNAMIC, "FET_DEF", { new CCFODynamic(nil, nil, nil, RestoreDefDisplay) },
MENUACTION_CFO_DYNAMIC, "FET_DEF", { new CCFODynamic(nil, nil, nil, nil, RestoreDefDisplay) },
MENUACTION_CHANGEMENU, "FEDS_TB", { nil, SAVESLOT_NONE, MENUPAGE_NONE },
},
#endif
Expand All @@ -418,9 +418,9 @@ CMenuScreenCustom aScreens[MENUPAGES] = {
MENUACTION_LANG_ITA, "FEL_ITA", { nil, SAVESLOT_NONE, MENUPAGE_LANGUAGE_SETTINGS },
MENUACTION_LANG_SPA, "FEL_SPA", { nil, SAVESLOT_NONE, MENUPAGE_LANGUAGE_SETTINGS },
#ifdef MORE_LANGUAGES
MENUACTION_CFO_DYNAMIC, "FEL_POL", { new CCFODynamic(nil, nil, nil, LangPolSelect) },
MENUACTION_CFO_DYNAMIC, "FEL_RUS", { new CCFODynamic(nil, nil, nil, LangRusSelect) },
MENUACTION_CFO_DYNAMIC, "FEL_JAP", { new CCFODynamic(nil, nil, nil, LangJapSelect) },
MENUACTION_CFO_DYNAMIC, "FEL_POL", { new CCFODynamic(nil, nil, nil, nil, LangPolSelect) },
MENUACTION_CFO_DYNAMIC, "FEL_RUS", { new CCFODynamic(nil, nil, nil, nil, LangRusSelect) },
MENUACTION_CFO_DYNAMIC, "FEL_JAP", { new CCFODynamic(nil, nil, nil, nil, LangJapSelect) },
#endif
MENUACTION_CHANGEMENU, "FEDS_TB", { nil, SAVESLOT_NONE, MENUPAGE_NONE },
},
Expand Down Expand Up @@ -828,7 +828,7 @@ CMenuScreenCustom aScreens[MENUPAGES] = {
MENUACTION_TRAILS, "FED_TRA", { nil, SAVESLOT_NONE, MENUPAGE_DISPLAY_SETTINGS },
#endif
// re3.cpp inserts here pipeline selectors if neo/neo.txd exists and EXTENDED_PIPELINES defined
MENUACTION_CFO_DYNAMIC, "FET_DEF", { new CCFODynamic(nil, nil, nil, RestoreDefGraphics) },
MENUACTION_CFO_DYNAMIC, "FET_DEF", { new CCFODynamic(nil, nil, nil, nil, RestoreDefGraphics) },
MENUACTION_CHANGEMENU, "FEDS_TB", { nil, SAVESLOT_NONE, MENUPAGE_NONE },
},
#endif
Expand All @@ -839,7 +839,7 @@ CMenuScreenCustom aScreens[MENUPAGES] = {
new CCustomScreenLayout({MENUSPRITE_MAINMENU, 40, 60, 20, FONT_BANK, FESCREEN_LEFT_ALIGN, false, MEDIUMTEXT_X_SCALE, MEDIUMTEXT_Y_SCALE}), nil,

MENUACTION_LABEL, "FEC_JPR", { nil, SAVESLOT_NONE, MENUPAGE_NONE },
MENUACTION_CFO_DYNAMIC, "FEC_JDE", { new CCFODynamic(nil, nil, DetectJoystickDraw, nil) },
MENUACTION_CFO_DYNAMIC, "FEC_JDE", { new CCFODynamic(nil, nil, nil, DetectJoystickDraw, nil) },
MENUACTION_CHANGEMENU, "FEDS_TB", { nil, SAVESLOT_NONE, MENUPAGE_NONE },
},
#endif
Expand Down
2 changes: 2 additions & 0 deletions src/core/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ void TheModelViewer(void);
#ifdef LOAD_INI_SETTINGS
void LoadINISettings();
void SaveINISettings();
void LoadINIControllerSettings();
void SaveINIControllerSettings();
#endif

#ifdef NEW_RENDERER
Expand Down
Loading

0 comments on commit 448e41e

Please sign in to comment.