1
0
mirror of https://github.com/FunkyFr3sh/cnc-ddraw.git synced 2025-03-15 06:04:49 +01:00

save and load settings from ddraw.ini

This commit is contained in:
FunkyFr3sh 2021-07-01 20:56:25 +02:00
parent b119d3fd9d
commit 81b4408833
3 changed files with 443 additions and 181 deletions

View File

@ -3,11 +3,15 @@
#include <vcl.h>
#pragma hdrstop
#include <IniFiles.hpp>
#include <StrUtils.hpp>
#include <IOUtils.hpp>
#include "ConfigFormUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TConfigForm *ConfigForm;
bool Initialized;
//---------------------------------------------------------------------------
__fastcall TConfigForm::TConfigForm(TComponent* Owner)
: TForm(Owner)
@ -35,3 +39,241 @@ void __fastcall TConfigForm::CompatibilityBtnClick(TObject *Sender)
DisplayPnl->Visible = false;
}
void __fastcall TConfigForm::FormCreate(TObject *Sender)
{
auto *ini = new TIniFile(".\\ddraw.ini");
/* Display Settings */
auto s = LowerCase(ini->ReadString("ddraw", "windowed", "false"));
bool windowed = s == "true" || s == "yes" || s == "1";
s = LowerCase(ini->ReadString("ddraw", "fullscreen", "false"));
bool fullscreen = s == "true" || s == "yes" || s == "1";
s = LowerCase(ini->ReadString("ddraw", "nonexclusive", "false"));
bool nonexclusive = s == "true" || s == "yes" || s == "1";
if (windowed && fullscreen) {
PresentationCbx->ItemIndex = 2;
}
else if (windowed) {
PresentationCbx->ItemIndex = 3;
}
else if (nonexclusive) {
PresentationCbx->ItemIndex = 1;
}
else {
PresentationCbx->ItemIndex = 0;
}
s = LowerCase(ini->ReadString("ddraw", "maintas", "false"));
MaintasChk->State = s == "true" || s == "yes" || s == "1" ? tssOn : tssOff;
s = LowerCase(ini->ReadString("ddraw", "vsync", "false"));
VsyncChk->State = s == "true" || s == "yes" || s == "1" ? tssOn : tssOff;
s = LowerCase(ini->ReadString("ddraw", "adjmouse", "false"));
AdjmouseChk->State = s == "true" || s == "yes" || s == "1" ? tssOn : tssOff;
s = LowerCase(ini->ReadString("ddraw", "devmode", "false"));
DevmodeChk->State = s == "true" || s == "yes" || s == "1" ? tssOn : tssOff;
/* Advanced Display Settings */
auto renderer = LowerCase(ini->ReadString("ddraw", "renderer", "auto"));
if (StartsStr("d", renderer)) {
RendererCbx->ItemIndex = 1;
}
else if (StartsStr("o", renderer)) {
RendererCbx->ItemIndex = 2;
}
else if (StartsStr("s", renderer) || StartsStr("g", renderer)) {
RendererCbx->ItemIndex = 3;
}
else {
RendererCbx->ItemIndex = 0;
}
try
{
TStringDynArray list = TDirectory::GetFiles(
"Shaders",
"*.glsl",
TSearchOption::soAllDirectories);
for (int i = 0; i < list.Length; i++)
ShaderCbx->AddItem(list[i], NULL);
auto shader = ini->ReadString("ddraw", "shader", "");
ShaderCbx->ItemIndex = ShaderCbx->Items->IndexOf(shader);
}
catch (...)
{
}
int maxfps = ini->ReadInteger("ddraw", "maxfps", -1);
MaxfpsChk->State = maxfps != 0 ? tssOn : tssOff;
s = LowerCase(ini->ReadString("ddraw", "boxing", "false"));
BoxingChk->State = s == "true" || s == "yes" || s == "1" ? tssOn : tssOff;
s = LowerCase(ini->ReadString("ddraw", "border", "false"));
BorderChk->State = s == "true" || s == "yes" || s == "1" ? tssOn : tssOff;
int savesettings = ini->ReadInteger("ddraw", "savesettings", 1);
SavesettingsChk->State = savesettings != 0 ? tssOn : tssOff;
delete ini;
Initialized = true;
}
void TConfigForm::SaveSettings()
{
if (!Initialized)
return;
auto *ini = new TIniFile(".\\ddraw.ini");
/* Display Settings */
switch(PresentationCbx->ItemIndex)
{
case 0:
ini->WriteString("ddraw", "windowed", "false");
ini->WriteString("ddraw", "fullscreen", "false");
ini->WriteString("ddraw", "nonexclusive", "false");
break;
case 1:
ini->WriteString("ddraw", "windowed", "false");
ini->WriteString("ddraw", "fullscreen", "false");
ini->WriteString("ddraw", "nonexclusive", "true");
break;
case 2:
ini->WriteString("ddraw", "windowed", "true");
ini->WriteString("ddraw", "fullscreen", "true");
ini->WriteString("ddraw", "nonexclusive", "false");
break;
case 3:
ini->WriteString("ddraw", "windowed", "true");
ini->WriteString("ddraw", "fullscreen", "false");
ini->WriteString("ddraw", "nonexclusive", "false");
break;
default:
break;
}
ini->WriteString(
"ddraw",
"renderer",
LowerCase(RendererCbx->Text));
ini->WriteString(
"ddraw",
"maintas",
MaintasChk->State == tssOn ? "true" : "false");
ini->WriteString(
"ddraw",
"vsync",
VsyncChk->State == tssOn ? "true" : "false");
ini->WriteString(
"ddraw",
"adjmouse",
AdjmouseChk->State == tssOn ? "true" : "false");
ini->WriteString(
"ddraw",
"devmode",
DevmodeChk->State == tssOn ? "true" : "false");
/* Advanced Display Settings */
ini->WriteString("ddraw", "renderer", LowerCase(RendererCbx->Text));
ini->WriteString("ddraw", "shader", ShaderCbx->Text);
ini->WriteInteger(
"ddraw",
"maxfps",
MaxfpsChk->State == tssOn ? -1 : 0);
ini->WriteString(
"ddraw",
"boxing",
BoxingChk->State == tssOn ? "true" : "false");
ini->WriteString(
"ddraw",
"border",
BorderChk->State == tssOn ? "true" : "false");
ini->WriteInteger(
"ddraw",
"savesettings",
SavesettingsChk->State == tssOn ? 1 : 0);
delete ini;
}
void __fastcall TConfigForm::PresentationCbxChange(TObject *Sender)
{
SaveSettings();
}
void __fastcall TConfigForm::MaintasChkClick(TObject *Sender)
{
SaveSettings();
}
void __fastcall TConfigForm::VsyncChkClick(TObject *Sender)
{
SaveSettings();
}
void __fastcall TConfigForm::AdjmouseChkClick(TObject *Sender)
{
SaveSettings();
}
void __fastcall TConfigForm::DevmodeChkClick(TObject *Sender)
{
SaveSettings();
}
void __fastcall TConfigForm::RendererCbxChange(TObject *Sender)
{
SaveSettings();
}
void __fastcall TConfigForm::ShaderCbxChange(TObject *Sender)
{
SaveSettings();
}
void __fastcall TConfigForm::MaxfpsChkClick(TObject *Sender)
{
SaveSettings();
}
void __fastcall TConfigForm::BoxingChkClick(TObject *Sender)
{
SaveSettings();
}
void __fastcall TConfigForm::BorderChkClick(TObject *Sender)
{
SaveSettings();
}
void __fastcall TConfigForm::SavesettingsChkClick(TObject *Sender)
{
SaveSettings();
}

View File

@ -2679,68 +2679,150 @@ object ConfigForm: TConfigForm
B88CB18EFF1FA2974C1C31AF16A40000000049454E44AE426082}
OldCreateOrder = False
Position = poDesktopCenter
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object MenuPnl: TPanel
Left = 0
object DisplayPnl: TPanel
Left = 191
Top = 8
Width = 185
Width = 499
Height = 465
Color = clBlack
Color = clWhite
ParentBackground = False
TabOrder = 0
DesignSize = (
185
465)
object DisplayBtn: TSpeedButton
Left = 8
Top = 8
Width = 171
Height = 41
Anchors = [akLeft, akTop, akRight]
Caption = 'Display Settings'
Flat = True
ShowCaption = False
TabOrder = 1
StyleElements = [seFont, seBorder]
object PresentationLbl: TLabel
Left = 40
Top = 28
Width = 87
Height = 21
Caption = 'Presentation'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWhite
Font.Height = -13
Font.Color = clWindowText
Font.Height = -16
Font.Name = 'Segoe UI'
Font.Style = [fsBold]
Font.Style = []
ParentFont = False
StyleElements = [seFont, seBorder]
OnClick = DisplayBtnClick
StyleElements = [seClient, seBorder]
end
object AdvDisplayBtn: TSpeedButton
Left = 8
Top = 55
Width = 171
Height = 41
Anchors = [akLeft, akTop, akRight]
Caption = 'Adv. Display Settings'
Flat = True
Font.Charset = DEFAULT_CHARSET
Font.Color = clWhite
Font.Height = -13
Font.Name = 'Segoe UI'
Font.Style = [fsBold]
ParentFont = False
OnClick = AdvDisplayBtnClick
end
object CompatibilityBtn: TSpeedButton
Left = 8
object MaintasLbl: TLabel
Left = 40
Top = 102
Width = 171
Height = 41
Anchors = [akLeft, akTop, akRight]
Caption = 'Compatibility Settings'
Flat = True
Width = 145
Height = 21
Caption = 'Maintain aspect ratio'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWhite
Font.Height = -13
Font.Color = clWindowText
Font.Height = -16
Font.Name = 'Segoe UI'
Font.Style = [fsBold]
Font.Style = []
ParentFont = False
Visible = False
OnClick = CompatibilityBtnClick
StyleElements = [seClient, seBorder]
end
object VsyncLbl: TLabel
Left = 40
Top = 162
Width = 40
Height = 21
Margins.Top = 10
Caption = 'Vsync'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -16
Font.Name = 'Segoe UI'
Font.Style = []
ParentFont = False
StyleElements = [seClient, seBorder]
end
object AdjmouseLbl: TLabel
Left = 40
Top = 222
Width = 168
Height = 21
Margins.Top = 10
Caption = 'Adjust mouse sensitivity'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -16
Font.Name = 'Segoe UI'
Font.Style = []
ParentFont = False
StyleElements = [seClient, seBorder]
end
object DevmodeLbl: TLabel
Left = 40
Top = 282
Width = 186
Height = 21
Margins.Top = 10
Caption = 'Lock cursor within window'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -16
Font.Name = 'Segoe UI'
Font.Style = []
ParentFont = False
StyleElements = [seClient, seBorder]
end
object PresentationCbx: TComboBox
Left = 40
Top = 55
Width = 185
Height = 29
BevelEdges = []
BevelInner = bvNone
BevelOuter = bvSpace
Style = csDropDownList
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -16
Font.Name = 'Segoe UI'
Font.Style = []
ParentFont = False
TabOrder = 0
OnChange = PresentationCbxChange
Items.Strings = (
'Fullscreen Exclusive'
'Fullscreen'
'Borderless'
'Windowed')
end
object MaintasChk: TToggleSwitch
Left = 40
Top = 129
Width = 50
Height = 20
ShowStateCaption = False
TabOrder = 1
OnClick = MaintasChkClick
end
object VsyncChk: TToggleSwitch
Left = 40
Top = 189
Width = 50
Height = 20
ShowStateCaption = False
TabOrder = 2
OnClick = VsyncChkClick
end
object AdjmouseChk: TToggleSwitch
Left = 40
Top = 249
Width = 50
Height = 20
ShowStateCaption = False
TabOrder = 3
OnClick = AdjmouseChkClick
end
object DevmodeChk: TToggleSwitch
Left = 40
Top = 309
Width = 50
Height = 20
ShowStateCaption = False
TabOrder = 4
OnClick = DevmodeChkClick
end
end
object CompatibilityPnl: TPanel
@ -2871,9 +2953,10 @@ object ConfigForm: TConfigForm
Font.Style = []
ParentFont = False
TabOrder = 0
OnChange = RendererCbxChange
Items.Strings = (
'Automatic'
'Direct3D 9'
'Direct3D9'
'OpenGL'
'GDI')
end
@ -2884,6 +2967,7 @@ object ConfigForm: TConfigForm
Height = 20
ShowStateCaption = False
TabOrder = 1
OnClick = BorderChkClick
end
object SavesettingsChk: TToggleSwitch
Left = 40
@ -2892,6 +2976,7 @@ object ConfigForm: TConfigForm
Height = 20
ShowStateCaption = False
TabOrder = 2
OnClick = SavesettingsChkClick
end
object ShaderCbx: TComboBox
Left = 40
@ -2909,11 +2994,7 @@ object ConfigForm: TConfigForm
Font.Style = []
ParentFont = False
TabOrder = 3
Items.Strings = (
'Automatic'
'Direct3D 9'
'OpenGL'
'GDI')
OnChange = ShaderCbxChange
end
object MaxfpsChk: TToggleSwitch
Left = 40
@ -2922,6 +3003,7 @@ object ConfigForm: TConfigForm
Height = 20
ShowStateCaption = False
TabOrder = 4
OnClick = MaxfpsChkClick
end
object BoxingChk: TToggleSwitch
Left = 40
@ -2930,144 +3012,69 @@ object ConfigForm: TConfigForm
Height = 20
ShowStateCaption = False
TabOrder = 5
OnClick = BoxingChkClick
end
end
object DisplayPnl: TPanel
Left = 191
object MenuPnl: TPanel
Left = 0
Top = 8
Width = 499
Width = 185
Height = 465
Color = clWhite
Color = clBlack
ParentBackground = False
ShowCaption = False
TabOrder = 1
StyleElements = [seFont, seBorder]
object PresentationLbl: TLabel
Left = 40
Top = 28
Width = 87
Height = 21
Caption = 'Presentation'
TabOrder = 0
DesignSize = (
185
465)
object DisplayBtn: TSpeedButton
Left = 8
Top = 8
Width = 171
Height = 41
Anchors = [akLeft, akTop, akRight]
Caption = 'Display Settings'
Flat = True
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -16
Font.Color = clWhite
Font.Height = -13
Font.Name = 'Segoe UI'
Font.Style = []
Font.Style = [fsBold]
ParentFont = False
StyleElements = [seClient, seBorder]
StyleElements = [seFont, seBorder]
OnClick = DisplayBtnClick
end
object AspectRatioLbl: TLabel
Left = 40
Top = 102
Width = 145
Height = 21
Caption = 'Maintain aspect ratio'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -16
Font.Name = 'Segoe UI'
Font.Style = []
ParentFont = False
StyleElements = [seClient, seBorder]
end
object VsyncLbl: TLabel
Left = 40
Top = 162
Width = 40
Height = 21
Margins.Top = 10
Caption = 'Vsync'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -16
Font.Name = 'Segoe UI'
Font.Style = []
ParentFont = False
StyleElements = [seClient, seBorder]
end
object AdjmouseLbl: TLabel
Left = 40
Top = 222
Width = 168
Height = 21
Margins.Top = 10
Caption = 'Adjust mouse sensitivity'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -16
Font.Name = 'Segoe UI'
Font.Style = []
ParentFont = False
StyleElements = [seClient, seBorder]
end
object DevmodeLbl: TLabel
Left = 40
Top = 282
Width = 186
Height = 21
Margins.Top = 10
Caption = 'Lock cursor within window'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -16
Font.Name = 'Segoe UI'
Font.Style = []
ParentFont = False
StyleElements = [seClient, seBorder]
end
object PresentationCbx: TComboBox
Left = 40
object AdvDisplayBtn: TSpeedButton
Left = 8
Top = 55
Width = 185
Height = 29
BevelEdges = []
BevelInner = bvNone
BevelOuter = bvSpace
Style = csDropDownList
Width = 171
Height = 41
Anchors = [akLeft, akTop, akRight]
Caption = 'Adv. Display Settings'
Flat = True
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -16
Font.Color = clWhite
Font.Height = -13
Font.Name = 'Segoe UI'
Font.Style = []
Font.Style = [fsBold]
ParentFont = False
TabOrder = 0
Items.Strings = (
'Fullscreen Exclusive'
'Fullscreen'
'Borderless'
'Windowed')
OnClick = AdvDisplayBtnClick
end
object AspectRatioChk: TToggleSwitch
Left = 40
Top = 129
Width = 50
Height = 20
ShowStateCaption = False
TabOrder = 1
end
object VsyncChk: TToggleSwitch
Left = 40
Top = 189
Width = 50
Height = 20
ShowStateCaption = False
TabOrder = 2
end
object AdjmouseChk: TToggleSwitch
Left = 40
Top = 249
Width = 50
Height = 20
ShowStateCaption = False
TabOrder = 3
end
object DevmodeChk: TToggleSwitch
Left = 40
Top = 309
Width = 50
Height = 20
ShowStateCaption = False
TabOrder = 4
object CompatibilityBtn: TSpeedButton
Left = 8
Top = 102
Width = 171
Height = 41
Anchors = [akLeft, akTop, akRight]
Caption = 'Compatibility Settings'
Flat = True
Font.Charset = DEFAULT_CHARSET
Font.Color = clWhite
Font.Height = -13
Font.Name = 'Segoe UI'
Font.Style = [fsBold]
ParentFont = False
Visible = False
OnClick = CompatibilityBtnClick
end
end
end

View File

@ -24,8 +24,8 @@ __published: // Von der IDE verwaltete Komponenten
TPanel *CompatibilityPnl;
TComboBox *PresentationCbx;
TLabel *PresentationLbl;
TLabel *AspectRatioLbl;
TToggleSwitch *AspectRatioChk;
TLabel *MaintasLbl;
TToggleSwitch *MaintasChk;
TLabel *VsyncLbl;
TToggleSwitch *VsyncChk;
TLabel *AdjmouseLbl;
@ -47,7 +47,20 @@ __published: // Von der IDE verwaltete Komponenten
void __fastcall DisplayBtnClick(TObject *Sender);
void __fastcall AdvDisplayBtnClick(TObject *Sender);
void __fastcall CompatibilityBtnClick(TObject *Sender);
void __fastcall FormCreate(TObject *Sender);
void __fastcall PresentationCbxChange(TObject *Sender);
void __fastcall MaintasChkClick(TObject *Sender);
void __fastcall VsyncChkClick(TObject *Sender);
void __fastcall AdjmouseChkClick(TObject *Sender);
void __fastcall DevmodeChkClick(TObject *Sender);
void __fastcall RendererCbxChange(TObject *Sender);
void __fastcall ShaderCbxChange(TObject *Sender);
void __fastcall MaxfpsChkClick(TObject *Sender);
void __fastcall BoxingChkClick(TObject *Sender);
void __fastcall BorderChkClick(TObject *Sender);
void __fastcall SavesettingsChkClick(TObject *Sender);
private: // Benutzer-Deklarationen
void SaveSettings();
public: // Benutzer-Deklarationen
__fastcall TConfigForm(TComponent* Owner);
};