DEADSOFTWARE

gui: get only editor related translations
[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, ActnList, 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 cbLanguage: TComboBox;
23 PageControl: TPageControl;
24 TabGeneral: TTabSheet;
25 TabFiles: TTabSheet;
26 TabTesting: TTabSheet;
27 ColorDialog: TColorDialog;
28 // Общие настройки:
29 cbShowDots: TCheckBox;
30 cbShowTexture: TCheckBox;
31 cbShowSize: TCheckBox;
32 // Шаги сетки:
33 LabelGrid: TLabel;
34 eDotStepOne: TEdit;
35 UpDown1: TUpDown;
36 eDotStepTwo: TEdit;
37 UpDown2: TUpDown;
38 // Цвет сетки:
39 LabelGridCol: TLabel;
40 sDotColor: TShape;
41 bGrid: TButton;
42 // Цвет фона:
43 LabelBack: TLabel;
44 sBackColor: TShape;
45 bBack: TButton;
46 // Цвет превью:
47 LabelPreview: TLabel;
48 sPreviewColor: TShape;
49 bPreview: TButton;
50 // Масштаб миникарты:
51 LabelMinimap: TLabel;
52 cbScale: TComboBox;
53 // Количество недавно открытых:
54 LabelRecent: TLabel;
55 eRecent: TEdit;
56 UpDown3: TUpDown;
57 LabelLanguage: TLabel;
58 LabelGridSize: TLabel;
59 cbDotSize: TComboBox;
60 // Map testing:
61 LabelPath: TLabel;
62 edD2dexe: TEdit;
63 bChooseD2d: TButton;
64 FindD2dDialog: TOpenDialog;
65 LabelArgs: TLabel;
66 edD2DArgs: TEdit;
67 rbCOOP: TRadioButton;
68 rbCTF: TRadioButton;
69 rbDM: TRadioButton;
70 rbTDM: TRadioButton;
71 cbAllowExit: TCheckBox;
72 cbMapOnce: TCheckBox;
73 cbMonstersDM: TCheckBox;
74 cbTeamDamage: TCheckBox;
75 cbTwoPlayers: TCheckBox;
76 cbWeaponStay: TCheckBox;
77 LabelScore: TLabel;
78 LabelSecs: TLabel;
79 edScore: TEdit;
80 LabelTime: TLabel;
81 edTime: TEdit;
84 procedure bGridClick(Sender: TObject);
85 procedure FormActivate(Sender: TObject);
86 procedure bOKClick(Sender: TObject);
87 procedure bCancelClick(Sender: TObject);
88 procedure bBackClick(Sender: TObject);
89 procedure bPreviewClick(Sender: TObject);
90 procedure FormCreate(Sender: TObject);
91 procedure bChooseD2dClick(Sender: TObject);
93 private
94 { Private declarations }
95 public
96 { Public declarations }
97 end;
99 var
100 OptionsForm: TOptionsForm;
102 procedure RegisterFileType(ext: String; FileName: String);
104 implementation
106 uses
107 LazFileUtils, f_main, StdConvs, CONFIG, g_language, g_resources, g_options;
109 {$R *.lfm}
111 procedure RegisterFileType(ext: String; FileName: String);
112 var
113 reg: TRegistry;
115 begin
116 reg := TRegistry.Create();
118 with reg do
119 begin
120 RootKey := HKEY_CLASSES_ROOT;
121 OpenKey('.'+ext,True);
122 WriteString('',ext+'file');
123 CloseKey();
124 CreateKey(ext+'file');
125 OpenKey(ext+'file\DefaultIcon',True);
126 WriteString('',FileName+',0');
127 CloseKey();
128 OpenKey(ext+'file\shell\open\command',True);
129 WriteString('',FileName+' "%1"');
130 CloseKey();
131 Free();
132 end;
133 end;
135 procedure TOptionsForm.bGridClick(Sender: TObject);
136 begin
137 if ColorDialog.Execute then
138 sDotColor.Brush.Color := ColorDialog.Color;
139 end;
141 procedure TOptionsForm.bChooseD2dClick(Sender: TObject);
142 begin
143 if FindD2dDialog.Execute then
144 edD2dExe.Text := FindD2dDialog.FileName;
145 end;
147 procedure TOptionsForm.FormActivate(Sender: TObject);
148 const langfilename = 'editor';
149 var info: TSearchRec;
150 begin
151 sDotColor.Brush.Color := DotColor;
152 cbShowDots.Checked := DotEnable;
153 cbShowTexture.Checked := DrawTexturePanel;
154 cbShowSize.Checked := DrawPanelSize;
155 eDotStepOne.Text := IntToStr(DotStepOne);
156 eDotStepTwo.Text := IntToStr(DotStepTwo);
157 sBackColor.Brush.Color := BackColor;
158 sPreviewColor.Brush.Color := PreviewColor;
159 cbCheckerboard.Checked := UseCheckerboard;
160 cbCompress.Checked := Compress;
161 cbBackup.Checked := Backup;
162 if Scale = 2 then
163 cbScale.ItemIndex := 1
164 else
165 cbScale.ItemIndex := 0;
166 if DotSize = 2 then
167 cbDotSize.ItemIndex := 1
168 else
169 cbDotSize.ItemIndex := 0;
170 eRecent.Text := IntToStr(RecentCount);
172 try
173 cbLanguage.Items.BeginUpdate;
174 cbLanguage.Items.Clear;
175 cbLanguage.Items.Add('Auto');
176 if FindFirst(LangDir + DirectorySeparator + langfilename + '.*.mo', faAnyFile, info) = 0 then
177 begin
178 repeat
179 cbLanguage.Items.Add(Copy(ExtractFileNameWithoutExt(info.Name), Length(langfilename) + 2));
180 until FindNext(info) <> 0;
181 FindClose(info);
182 end;
183 cbLanguage.ItemIndex := IfThen(gLanguage = '', 0, cbLanguage.Items.IndexOf(gLanguage));
184 finally
185 cbLanguage.Items.EndUpdate;
186 end;
188 if TestGameMode = 'TDM' then
189 rbTDM.Checked := True
190 else if TestGameMode = 'CTF' then
191 rbCTF.Checked := True
192 else if TestGameMode = 'COOP' then
193 rbCOOP.Checked := True
194 else
195 rbDM.Checked := True;
197 edTime.Text := TestLimTime;
198 edScore.Text := TestLimScore;
199 cbTwoPlayers.Checked := TestOptionsTwoPlayers;
200 cbTeamDamage.Checked := TestOptionsTeamDamage;
201 cbAllowExit.Checked := TestOptionsAllowExit;
202 cbWeaponStay.Checked := TestOptionsWeaponStay;
203 cbMonstersDM.Checked := TestOptionsMonstersDM;
204 cbMapOnce.Checked := TestMapOnce;
205 edD2dExe.Text := TestD2dExe;
206 edD2DArgs.Text := TestD2DArgs;
207 end;
209 procedure TOptionsForm.bOKClick(Sender: TObject);
210 var
211 config: TConfig;
212 re, n: Integer;
213 d1: Boolean;
214 str: String;
216 begin
217 // General tab
219 if cbLanguage.ItemIndex <= 0 then str := '' else str := cbLanguage.Items[cbLanguage.ItemIndex];
220 if (str = '') or (gLanguage <> str) then
221 begin
222 gLanguage := str;
223 g_Language_Set(gLanguage);
224 end;
226 DotColor := sDotColor.Brush.Color;
227 DotEnable := cbShowDots.Checked;
229 if DotStep = DotStepOne then
230 d1 := True
231 else
232 d1 := False;
233 DotStepOne := EnsureRange(StrToIntDef(eDotStepOne.Text, 16), 4, 2048);
234 DotStepTwo := EnsureRange(StrToIntDef(eDotStepTwo.Text, 8), 4, 2048);
235 if d1 then
236 DotStep := DotStepOne
237 else
238 DotStep := DotStepTwo;
240 DrawTexturePanel := cbShowTexture.Checked;
241 DrawPanelSize := cbShowSize.Checked;
242 BackColor := sBackColor.Brush.Color;
243 PreviewColor := sPreviewColor.Brush.Color;
244 UseCheckerboard := cbCheckerboard.Checked;
246 if cbScale.ItemIndex = 1 then
247 Scale := 2
248 else
249 Scale := 1;
251 if cbDotSize.ItemIndex = 1 then
252 DotSize := 2
253 else
254 DotSize := 1;
256 // Files tab
258 re := Min(Max(StrToIntDef(eRecent.Text, 5), 2), 10);
259 Compress := cbCompress.Checked;
260 Backup := cbBackup.Checked;
262 // Testing tab
264 if rbTDM.Checked then
265 TestGameMode := 'TDM'
266 else if rbCTF.Checked then
267 TestGameMode := 'CTF'
268 else if rbCOOP.Checked then
269 TestGameMode := 'COOP'
270 else
271 TestGameMode := 'DM';
273 TestLimTime := edTime.Text;
274 if (not TryStrToInt(TestLimTime, n)) then
275 TestLimTime := '0';
277 TestLimScore := edScore.Text;
278 if (not TryStrToInt(TestLimScore, n)) then
279 TestLimScore := '0';
281 TestOptionsTwoPlayers := cbTwoPlayers.Checked;
282 TestOptionsTeamDamage := cbTeamDamage.Checked;
283 TestOptionsAllowExit := cbAllowExit.Checked;
284 TestOptionsWeaponStay := cbWeaponStay.Checked;
285 TestOptionsMonstersDM := cbMonstersDM.Checked;
286 TestMapOnce := cbMapOnce.Checked;
288 TestD2dExe := edD2dExe.Text;
289 TestD2DArgs := edD2DArgs.Text;
291 // save into config
293 config := TConfig.CreateFile(CfgFileName);
295 config.WriteInt('Editor', 'DotColor', DotColor);
296 config.WriteBool('Editor', 'DotEnable', DotEnable);
297 config.WriteInt('Editor', 'DotStepOne', DotStepOne);
298 config.WriteInt('Editor', 'DotStepTwo', DotStepTwo);
299 config.WriteInt('Editor', 'DotStep', DotStep);
300 config.WriteInt('Editor', 'DotSize', cbDotSize.ItemIndex);
301 config.WriteBool('Editor', 'DrawTexturePanel', DrawTexturePanel);
302 config.WriteBool('Editor', 'DrawPanelSize', DrawPanelSize);
303 config.WriteInt('Editor', 'BackColor', BackColor);
304 config.WriteInt('Editor', 'PreviewColor', PreviewColor);
305 config.WriteBool('Editor', 'UseCheckerboard', UseCheckerboard);
306 config.WriteInt('Editor', 'Scale', cbScale.ItemIndex);
307 config.WriteStr('Editor', 'Language', gLanguage);
309 config.WriteInt('Editor', 'RecentCount', re);
310 config.WriteBool('Editor', 'Compress', Compress);
311 config.WriteBool('Editor', 'Backup', Backup);
313 config.WriteStr('TestRun', 'GameMode', TestGameMode);
314 config.WriteStr('TestRun', 'LimTime', TestLimTime);
315 config.WriteStr('TestRun', 'LimScore', TestLimScore);
316 config.WriteBool('TestRun', 'TwoPlayers', TestOptionsTwoPlayers);
317 config.WriteBool('TestRun', 'TeamDamage', TestOptionsTeamDamage);
318 config.WriteBool('TestRun', 'AllowExit', TestOptionsAllowExit);
319 config.WriteBool('TestRun', 'WeaponStay', TestOptionsWeaponStay);
320 config.WriteBool('TestRun', 'MonstersDM', TestOptionsMonstersDM);
321 config.WriteBool('TestRun', 'MapOnce', TestMapOnce);
322 {$IF DEFINED(DARWIN)}
323 config.WriteStr('TestRun', 'ExeDrawin', TestD2dExe);
324 {$ELSEIF DEFINED(WINDOWS)}
325 config.WriteStr('TestRun', 'ExeWindows', TestD2dExe);
326 {$ELSE}
327 config.WriteStr('TestRun', 'ExeUnix', TestD2dExe);
328 {$ENDIF}
329 config.WriteStr('TestRun', 'Args', TestD2DArgs);
331 if RecentCount <> re then
332 begin
333 RecentCount := re;
334 MainForm.RefreshRecentMenu();
335 end;
337 config.SaveFile(CfgFileName);
338 config.Free();
339 Close();
340 end;
342 procedure TOptionsForm.bCancelClick(Sender: TObject);
343 begin
344 Close();
345 end;
347 procedure TOptionsForm.bBackClick(Sender: TObject);
348 begin
349 if ColorDialog.Execute then
350 sBackColor.Brush.Color := ColorDialog.Color;
351 end;
353 procedure TOptionsForm.bPreviewClick(Sender: TObject);
354 begin
355 if ColorDialog.Execute then
356 sPreviewColor.Brush.Color := ColorDialog.Color;
357 end;
359 procedure TOptionsForm.FormCreate(Sender: TObject);
360 begin
361 {$IF DEFINED(DARWIN)}
362 if LowerCase(ExtractFileExt(TestD2dExe)) = '.app' then
363 FindD2dDialog.InitialDir := ExtractFileDir(TestD2dExe)
364 else
365 FindD2dDialog.InitialDir := TestD2dExe;
366 FindD2dDialog.DefaultExt := '.app';
367 FindD2dDialog.Filter := 'Doom 2D Forever.app|*.app|Doom 2D Forever (Unix Executable)|Doom2DF;*';
368 {$ELSEIF DEFINED(WINDOWS)}
369 FindD2dDialog.InitialDir := TestD2dExe;
370 FindD2dDialog.DefaultExt := '.exe';
371 FindD2dDialog.Filter := 'Doom2DF.exe|Doom2DF.exe;*.exe';
372 {$ELSE}
373 FindD2dDialog.InitialDir := TestD2dExe;
374 FindD2dDialog.DefaultExt := '';
375 FindD2dDialog.Filter := 'Doom2DF|Doom2DF;*';
376 {$ENDIF}
377 end;
379 end.