DEADSOFTWARE

gui: implement new settings dialog
[d2df-editor.git] / src / editor / f_options.pas
1 unit f_options;
3 {$INCLUDE ../shared/a_modes.inc}
5 interface
7 uses
8 LCLIntf, LCLType, SysUtils, Variants, Classes,
9 Graphics, Controls, Forms, Dialogs, StdCtrls,
10 ExtCtrls, ComCtrls, Registry, Math, Types;
12 type
14 { TOptionsForm }
16 TOptionsForm = class (TForm)
17 bOK: TButton;
18 bCancel: TButton;
19 cbCheckerboard: TCheckBox;
20 cbCompress: TCheckBox;
21 cbBackup: TCheckBox;
22 PageControl: TPageControl;
23 TabGeneral: TTabSheet;
24 TabFiles: TTabSheet;
25 TabTesting: TTabSheet;
26 ColorDialog: TColorDialog;
27 // Общие настройки:
28 cbShowDots: TCheckBox;
29 cbShowTexture: TCheckBox;
30 cbShowSize: TCheckBox;
31 // Шаги сетки:
32 LabelGrid: TLabel;
33 eDotStepOne: TEdit;
34 UpDown1: TUpDown;
35 eDotStepTwo: TEdit;
36 UpDown2: TUpDown;
37 // Цвет сетки:
38 LabelGridCol: TLabel;
39 sDotColor: TShape;
40 bGrid: TButton;
41 // Цвет фона:
42 LabelBack: TLabel;
43 sBackColor: TShape;
44 bBack: TButton;
45 // Цвет превью:
46 LabelPreview: TLabel;
47 sPreviewColor: TShape;
48 bPreview: TButton;
49 // Масштаб миникарты:
50 LabelMinimap: TLabel;
51 cbScale: TComboBox;
52 // Количество недавно открытых:
53 LabelRecent: TLabel;
54 eRecent: TEdit;
55 UpDown3: TUpDown;
56 LabelLanguage: TLabel;
57 rbRussian: TRadioButton;
58 rbEnglish: TRadioButton;
59 LabelGridSize: TLabel;
60 cbDotSize: TComboBox;
61 // Map testing:
62 LabelPath: TLabel;
63 edD2dexe: TEdit;
64 bChooseD2d: TButton;
65 FindD2dDialog: TOpenDialog;
66 LabelArgs: TLabel;
67 edD2DArgs: TEdit;
68 rbCOOP: TRadioButton;
69 rbCTF: TRadioButton;
70 rbDM: TRadioButton;
71 rbTDM: TRadioButton;
72 cbAllowExit: TCheckBox;
73 cbMapOnce: TCheckBox;
74 cbMonstersDM: TCheckBox;
75 cbTeamDamage: TCheckBox;
76 cbTwoPlayers: TCheckBox;
77 cbWeaponStay: TCheckBox;
78 LabelScore: TLabel;
79 LabelSecs: TLabel;
80 edScore: TEdit;
81 LabelTime: TLabel;
82 edTime: TEdit;
85 procedure bGridClick(Sender: TObject);
86 procedure FormActivate(Sender: TObject);
87 procedure bOKClick(Sender: TObject);
88 procedure bCancelClick(Sender: TObject);
89 procedure bBackClick(Sender: TObject);
90 procedure bPreviewClick(Sender: TObject);
91 procedure FormCreate(Sender: TObject);
92 procedure bChooseD2dClick(Sender: TObject);
94 private
95 { Private declarations }
96 public
97 { Public declarations }
98 end;
100 var
101 OptionsForm: TOptionsForm;
103 procedure RegisterFileType(ext: String; FileName: String);
105 implementation
107 uses
108 f_main, StdConvs, CONFIG, g_language, g_resources, g_options;
110 {$R *.lfm}
112 procedure RegisterFileType(ext: String; FileName: String);
113 var
114 reg: TRegistry;
116 begin
117 reg := TRegistry.Create();
119 with reg do
120 begin
121 RootKey := HKEY_CLASSES_ROOT;
122 OpenKey('.'+ext,True);
123 WriteString('',ext+'file');
124 CloseKey();
125 CreateKey(ext+'file');
126 OpenKey(ext+'file\DefaultIcon',True);
127 WriteString('',FileName+',0');
128 CloseKey();
129 OpenKey(ext+'file\shell\open\command',True);
130 WriteString('',FileName+' "%1"');
131 CloseKey();
132 Free();
133 end;
134 end;
136 procedure TOptionsForm.bGridClick(Sender: TObject);
137 begin
138 if ColorDialog.Execute then
139 sDotColor.Brush.Color := ColorDialog.Color;
140 end;
142 procedure TOptionsForm.bChooseD2dClick(Sender: TObject);
143 begin
144 if FindD2dDialog.Execute then
145 edD2dExe.Text := FindD2dDialog.FileName;
146 end;
148 procedure TOptionsForm.FormActivate(Sender: TObject);
149 begin
150 sDotColor.Brush.Color := DotColor;
151 cbShowDots.Checked := DotEnable;
152 cbShowTexture.Checked := DrawTexturePanel;
153 cbShowSize.Checked := DrawPanelSize;
154 eDotStepOne.Text := IntToStr(DotStepOne);
155 eDotStepTwo.Text := IntToStr(DotStepTwo);
156 sBackColor.Brush.Color := BackColor;
157 sPreviewColor.Brush.Color := PreviewColor;
158 cbCheckerboard.Checked := UseCheckerboard;
159 cbCompress.Checked := Compress;
160 cbBackup.Checked := Backup;
161 if Scale = 2 then
162 cbScale.ItemIndex := 1
163 else
164 cbScale.ItemIndex := 0;
165 if DotSize = 2 then
166 cbDotSize.ItemIndex := 1
167 else
168 cbDotSize.ItemIndex := 0;
169 eRecent.Text := IntToStr(RecentCount);
171 // Язык:
172 if gLanguage = LANGUAGE_RUSSIAN then
173 begin
174 rbRussian.Checked := True;
175 rbEnglish.Checked := False;
176 end
177 else
178 begin
179 rbRussian.Checked := False;
180 rbEnglish.Checked := True;
181 end;
183 if TestGameMode = 'TDM' then
184 rbTDM.Checked := True
185 else if TestGameMode = 'CTF' then
186 rbCTF.Checked := True
187 else if TestGameMode = 'COOP' then
188 rbCOOP.Checked := True
189 else
190 rbDM.Checked := True;
192 edTime.Text := TestLimTime;
193 edScore.Text := TestLimScore;
194 cbTwoPlayers.Checked := TestOptionsTwoPlayers;
195 cbTeamDamage.Checked := TestOptionsTeamDamage;
196 cbAllowExit.Checked := TestOptionsAllowExit;
197 cbWeaponStay.Checked := TestOptionsWeaponStay;
198 cbMonstersDM.Checked := TestOptionsMonstersDM;
199 cbMapOnce.Checked := TestMapOnce;
200 edD2dExe.Text := TestD2dExe;
201 edD2DArgs.Text := TestD2DArgs;
202 end;
204 procedure TOptionsForm.bOKClick(Sender: TObject);
205 var
206 config: TConfig;
207 re, n: Integer;
208 d1: Boolean;
209 str: String;
211 begin
212 // General tab
214 if rbRussian.Checked then
215 str := LANGUAGE_RUSSIAN
216 else
217 str := LANGUAGE_ENGLISH;
219 // Нужно сменить язык:
220 if gLanguage <> str then
221 begin
222 gLanguage := str;
223 //e_WriteLog('Read language file', MSG_NOTIFY);
224 //g_Language_Load(EditorDir+'\data\'+gLanguage+LANGUAGE_FILE_NAME);
225 g_Language_Set(gLanguage);
226 end;
228 DotColor := sDotColor.Brush.Color;
229 DotEnable := cbShowDots.Checked;
231 if DotStep = DotStepOne then
232 d1 := True
233 else
234 d1 := False;
235 DotStepOne := EnsureRange(StrToIntDef(eDotStepOne.Text, 16), 4, 2048);
236 DotStepTwo := EnsureRange(StrToIntDef(eDotStepTwo.Text, 8), 4, 2048);
237 if d1 then
238 DotStep := DotStepOne
239 else
240 DotStep := DotStepTwo;
242 DrawTexturePanel := cbShowTexture.Checked;
243 DrawPanelSize := cbShowSize.Checked;
244 BackColor := sBackColor.Brush.Color;
245 PreviewColor := sPreviewColor.Brush.Color;
246 UseCheckerboard := cbCheckerboard.Checked;
248 if cbScale.ItemIndex = 1 then
249 Scale := 2
250 else
251 Scale := 1;
253 if cbDotSize.ItemIndex = 1 then
254 DotSize := 2
255 else
256 DotSize := 1;
258 // Files tab
260 re := Min(Max(StrToIntDef(eRecent.Text, 5), 2), 10);
261 Compress := cbCompress.Checked;
262 Backup := cbBackup.Checked;
264 // Testing tab
266 if rbTDM.Checked then
267 TestGameMode := 'TDM'
268 else if rbCTF.Checked then
269 TestGameMode := 'CTF'
270 else if rbCOOP.Checked then
271 TestGameMode := 'COOP'
272 else
273 TestGameMode := 'DM';
275 TestLimTime := edTime.Text;
276 if (not TryStrToInt(TestLimTime, n)) then
277 TestLimTime := '0';
279 TestLimScore := edScore.Text;
280 if (not TryStrToInt(TestLimScore, n)) then
281 TestLimScore := '0';
283 TestOptionsTwoPlayers := cbTwoPlayers.Checked;
284 TestOptionsTeamDamage := cbTeamDamage.Checked;
285 TestOptionsAllowExit := cbAllowExit.Checked;
286 TestOptionsWeaponStay := cbWeaponStay.Checked;
287 TestOptionsMonstersDM := cbMonstersDM.Checked;
288 TestMapOnce := cbMapOnce.Checked;
290 TestD2dExe := edD2dExe.Text;
291 TestD2DArgs := edD2DArgs.Text;
293 // save into config
295 config := TConfig.CreateFile(CfgFileName);
297 config.WriteInt('Editor', 'DotColor', DotColor);
298 config.WriteBool('Editor', 'DotEnable', DotEnable);
299 config.WriteInt('Editor', 'DotStepOne', DotStepOne);
300 config.WriteInt('Editor', 'DotStepTwo', DotStepTwo);
301 config.WriteInt('Editor', 'DotStep', DotStep);
302 config.WriteInt('Editor', 'DotSize', cbDotSize.ItemIndex);
303 config.WriteBool('Editor', 'DrawTexturePanel', DrawTexturePanel);
304 config.WriteBool('Editor', 'DrawPanelSize', DrawPanelSize);
305 config.WriteInt('Editor', 'BackColor', BackColor);
306 config.WriteInt('Editor', 'PreviewColor', PreviewColor);
307 config.WriteBool('Editor', 'UseCheckerboard', UseCheckerboard);
308 config.WriteInt('Editor', 'Scale', cbScale.ItemIndex);
309 config.WriteStr('Editor', 'Language', gLanguage);
311 config.WriteInt('Editor', 'RecentCount', re);
312 config.WriteBool('Editor', 'Compress', Compress);
313 config.WriteBool('Editor', 'Backup', Backup);
315 config.WriteStr('TestRun', 'GameMode', TestGameMode);
316 config.WriteStr('TestRun', 'LimTime', TestLimTime);
317 config.WriteStr('TestRun', 'LimScore', TestLimScore);
318 config.WriteBool('TestRun', 'TwoPlayers', TestOptionsTwoPlayers);
319 config.WriteBool('TestRun', 'TeamDamage', TestOptionsTeamDamage);
320 config.WriteBool('TestRun', 'AllowExit', TestOptionsAllowExit);
321 config.WriteBool('TestRun', 'WeaponStay', TestOptionsWeaponStay);
322 config.WriteBool('TestRun', 'MonstersDM', TestOptionsMonstersDM);
323 config.WriteBool('TestRun', 'MapOnce', TestMapOnce);
324 {$IF DEFINED(DARWIN)}
325 config.WriteStr('TestRun', 'ExeDrawin', TestD2dExe);
326 {$ELSEIF DEFINED(WINDOWS)}
327 config.WriteStr('TestRun', 'ExeWindows', TestD2dExe);
328 {$ELSE}
329 config.WriteStr('TestRun', 'ExeUnix', TestD2dExe);
330 {$ENDIF}
331 config.WriteStr('TestRun', 'Args', TestD2DArgs);
333 if RecentCount <> re then
334 begin
335 RecentCount := re;
336 MainForm.RefreshRecentMenu();
337 end;
339 config.SaveFile(CfgFileName);
340 config.Free();
341 Close();
342 end;
344 procedure TOptionsForm.bCancelClick(Sender: TObject);
345 begin
346 Close();
347 end;
349 procedure TOptionsForm.bBackClick(Sender: TObject);
350 begin
351 if ColorDialog.Execute then
352 sBackColor.Brush.Color := ColorDialog.Color;
353 end;
355 procedure TOptionsForm.bPreviewClick(Sender: TObject);
356 begin
357 if ColorDialog.Execute then
358 sPreviewColor.Brush.Color := ColorDialog.Color;
359 end;
361 procedure TOptionsForm.FormCreate(Sender: TObject);
362 begin
363 {$IF DEFINED(DARWIN)}
364 if LowerCase(ExtractFileExt(TestD2dExe)) = '.app' then
365 FindD2dDialog.InitialDir := ExtractFileDir(TestD2dExe)
366 else
367 FindD2dDialog.InitialDir := TestD2dExe;
368 FindD2dDialog.DefaultExt := '.app';
369 FindD2dDialog.Filter := 'Doom 2D Forever.app|*.app|Doom 2D Forever (Unix Executable)|Doom2DF;*';
370 {$ELSEIF DEFINED(WINDOWS)}
371 FindD2dDialog.InitialDir := TestD2dExe;
372 FindD2dDialog.DefaultExt := '.exe';
373 FindD2dDialog.Filter := 'Doom2DF.exe|Doom2DF.exe;*.exe';
374 {$ELSE}
375 FindD2dDialog.InitialDir := TestD2dExe;
376 FindD2dDialog.DefaultExt := '';
377 FindD2dDialog.Filter := 'Doom2DF|Doom2DF;*';
378 {$ENDIF}
379 end;
381 end.