-
Notifications
You must be signed in to change notification settings - Fork 7
/
PMain.pas
153 lines (137 loc) · 4.13 KB
/
PMain.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
unit PMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, XPMan, pngimage, ExtCtrls, StdCtrls, Spin;
type
TFormMain = class(TForm)
XPManifest: TXPManifest;
SpinEditFPS: TSpinEdit;
Bevel1: TBevel;
Label1: TLabel;
Label2: TLabel;
Bevel2: TBevel;
ButtonCancel: TButton;
ButtonApply: TButton;
SpinEditLines: TSpinEdit;
Label3: TLabel;
Label4: TLabel;
Bevel3: TBevel;
Label5: TLabel;
EditSimple: TEdit;
CheckBoxDebug: TCheckBox;
Bevel4: TBevel;
Label6: TLabel;
CheckBoxSound: TCheckBox;
Bevel5: TBevel;
ImageTopFooter: TImage;
Label7: TLabel;
Image1: TImage;
Image2: TImage;
Image3: TImage;
Image4: TImage;
ButtonDefault: TButton;
ButtonReset: TButton;
procedure ButtonCancelClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ButtonDefaultClick(Sender: TObject);
procedure ButtonApplyClick(Sender: TObject);
procedure SpinEditFPSChange(Sender: TObject);
procedure ButtonResetClick(Sender: TObject);
private
{ Private declarations }
public
procedure SetDefault;
procedure LoadSets;
procedure SaveSets;
end;
var
FormMain: TFormMain;
implementation
uses IniFiles;
{$R *.dfm}
procedure TFormMain.ButtonCancelClick(Sender: TObject);
begin
if ButtonApply.Enabled then
case MessageBox(Handle, 'Ñîõðàíèòü èçìåíåíèÿ?', '', MB_ICONINFORMATION or MB_YESNOCANCEL) of
ID_CANCEL:Exit;
ID_YES:SaveSets;
end;
Application.Terminate;
end;
procedure TFormMain.SetDefault;
begin
SpinEditFPS.Value:=180;
SpinEditLines.Value:=20;
CheckBoxDebug.Checked:=False;
CheckBoxSound.Checked:=True;
EditSimple.Text:='';
ButtonApply.Enabled:=True;
ButtonReset.Enabled:=True;
end;
procedure TFormMain.LoadSets;
var Ini:TIniFile;
begin
if not FileExists(ExtractFilePath(ParamStr(0)) + 'Config.ini') then
begin
SetDefault;
Exit;
end;
Ini:=TIniFile.Create(ExtractFilePath(ParamStr(0)) + 'Config.ini');
EditSimple.Text:=Ini.ReadString('Tetris', 'Password', '');
SpinEditFPS.Value:=Ini.ReadInteger('Tetris', 'FPS', 180);
SpinEditLines.Value:=Ini.ReadInteger('Tetris', 'LinesForLevel', 20);
CheckBoxDebug.Checked:=Ini.ReadBool('Tetris', 'Debug', False);
CheckBoxSound.Checked:=Ini.ReadBool('Tetris', 'Sound', True);
if (SpinEditFPS.Value < 20) or (SpinEditFPS.Value > 1000) then SpinEditFPS.Value:=180;
if (SpinEditLines.Value < 20) or (SpinEditLines.Value > 1000) then SpinEditLines.Value:=20;
Ini.Free;
ButtonApply.Enabled:=False;
ButtonReset.Enabled:=False;
end;
procedure TFormMain.SaveSets;
var Ini:TIniFile;
begin
if not FileExists(ExtractFilePath(ParamStr(0)) + 'Config.ini') then
begin
try
FileClose(FileCreate(ExtractFilePath(ParamStr(0)) + 'Config.ini'));
except
MessageBox(Application.Handle, 'Îøèáêà ñîçäàíèÿ ôàéëà.', '', MB_ICONSTOP or MB_OK);
Exit;
end;
end;
Ini:=TIniFile.Create(ExtractFilePath(ParamStr(0)) + 'Config.ini');
Ini.WriteString('Tetris', 'Password', EditSimple.Text);
Ini.WriteInteger('Tetris', 'FPS', SpinEditFPS.Value);
Ini.WriteInteger('Tetris', 'LinesForLevel', SpinEditLines.Value);
Ini.WriteBool('Tetris', 'Debug', CheckBoxDebug.Checked);
Ini.WriteBool('Tetris', 'Sound', CheckBoxSound.Checked);
Ini.Free;
ButtonApply.Enabled:=False;
ButtonReset.Enabled:=False;
end;
procedure TFormMain.FormCreate(Sender: TObject);
begin
LoadSets;
end;
procedure TFormMain.ButtonDefaultClick(Sender: TObject);
begin
if MessageBox(Handle, 'Âû óâåðåíû, ÷òî õîòèòå óñòàíîâèòü ïàðàìåòðû ïîóìîë÷àíèþ?', '', MB_ICONQUESTION or MB_YESNO) <> ID_YES then Exit;
SetDefault;
end;
procedure TFormMain.ButtonApplyClick(Sender: TObject);
begin
SaveSets;
end;
procedure TFormMain.SpinEditFPSChange(Sender: TObject);
begin
ButtonApply.Enabled:=True;
ButtonReset.Enabled:=True;
end;
procedure TFormMain.ButtonResetClick(Sender: TObject);
begin
if MessageBox(Handle, 'Âû óâåðåíû, ÷òî õîòèòå ñáðîñèòü ïàðàìåòðû?', '', MB_ICONQUESTION or MB_YESNO) <> ID_YES then Exit;
LoadSets;
end;
end.