DEADSOFTWARE

i10n: use resourcestring and gettext for localization
[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, StrUtils, 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 var info: TSearchRec; s: String; i: Integer;
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 try
172 cbLanguage.Items.BeginUpdate;
173 cbLanguage.Items.Clear;
174 cbLanguage.Items.Add('Auto');
175 if FindFirst(LangDir + DirectorySeparator + '*.mo', faAnyFile, info) = 0 then
176 begin
177 repeat
178 s := ExtractFileNameWithoutExt(info.Name);
179 // TODO: check encoding part in name (editor.ru_RU.UTF-8.mo)
180 i := Max(RPos('.', s), 1);
181 s := Copy(s, i + 1, Length(s) - i);
182 cbLanguage.Items.Add(s);
183 until FindNext(info) <> 0;
184 FindClose(info);
185 end;
186 cbLanguage.ItemIndex := IfThen(gLanguage = '', 0, cbLanguage.Items.IndexOf(gLanguage));
187 finally
188 cbLanguage.Items.EndUpdate;
189 end;
191 if TestGameMode = 'TDM' then
192 rbTDM.Checked := True
193 else if TestGameMode = 'CTF' then
194 rbCTF.Checked := True
195 else if TestGameMode = 'COOP' then
196 rbCOOP.Checked := True
197 else
198 rbDM.Checked := True;
200 edTime.Text := TestLimTime;
201 edScore.Text := TestLimScore;
202 cbTwoPlayers.Checked := TestOptionsTwoPlayers;
203 cbTeamDamage.Checked := TestOptionsTeamDamage;
204 cbAllowExit.Checked := TestOptionsAllowExit;
205 cbWeaponStay.Checked := TestOptionsWeaponStay;
206 cbMonstersDM.Checked := TestOptionsMonstersDM;
207 cbMapOnce.Checked := TestMapOnce;
208 edD2dExe.Text := TestD2dExe;
209 edD2DArgs.Text := TestD2DArgs;
210 end;
212 procedure TOptionsForm.bOKClick(Sender: TObject);
213 var
214 config: TConfig;
215 re, n: Integer;
216 d1: Boolean;
217 str: String;
219 begin
220 // General tab
222 if cbLanguage.ItemIndex <= 0 then str := '' else str := cbLanguage.Items[cbLanguage.ItemIndex];
223 if (str = '') or (gLanguage <> str) then
224 begin
225 gLanguage := str;
226 g_Language_Set(gLanguage);
227 end;
229 DotColor := sDotColor.Brush.Color;
230 DotEnable := cbShowDots.Checked;
232 if DotStep = DotStepOne then
233 d1 := True
234 else
235 d1 := False;
236 DotStepOne := EnsureRange(StrToIntDef(eDotStepOne.Text, 16), 4, 2048);
237 DotStepTwo := EnsureRange(StrToIntDef(eDotStepTwo.Text, 8), 4, 2048);
238 if d1 then
239 DotStep := DotStepOne
240 else
241 DotStep := DotStepTwo;
243 DrawTexturePanel := cbShowTexture.Checked;
244 DrawPanelSize := cbShowSize.Checked;
245 BackColor := sBackColor.Brush.Color;
246 PreviewColor := sPreviewColor.Brush.Color;
247 UseCheckerboard := cbCheckerboard.Checked;
249 if cbScale.ItemIndex = 1 then
250 Scale := 2
251 else
252 Scale := 1;
254 if cbDotSize.ItemIndex = 1 then
255 DotSize := 2
256 else
257 DotSize := 1;
259 // Files tab
261 re := Min(Max(StrToIntDef(eRecent.Text, 5), 2), 10);
262 Compress := cbCompress.Checked;
263 Backup := cbBackup.Checked;
265 // Testing tab
267 if rbTDM.Checked then
268 TestGameMode := 'TDM'
269 else if rbCTF.Checked then
270 TestGameMode := 'CTF'
271 else if rbCOOP.Checked then
272 TestGameMode := 'COOP'
273 else
274 TestGameMode := 'DM';
276 TestLimTime := edTime.Text;
277 if (not TryStrToInt(TestLimTime, n)) then
278 TestLimTime := '0';
280 TestLimScore := edScore.Text;
281 if (not TryStrToInt(TestLimScore, n)) then
282 TestLimScore := '0';
284 TestOptionsTwoPlayers := cbTwoPlayers.Checked;
285 TestOptionsTeamDamage := cbTeamDamage.Checked;
286 TestOptionsAllowExit := cbAllowExit.Checked;
287 TestOptionsWeaponStay := cbWeaponStay.Checked;
288 TestOptionsMonstersDM := cbMonstersDM.Checked;
289 TestMapOnce := cbMapOnce.Checked;
291 TestD2dExe := edD2dExe.Text;
292 TestD2DArgs := edD2DArgs.Text;
294 // save into config
296 config := TConfig.CreateFile(CfgFileName);
298 config.WriteInt('Editor', 'DotColor', DotColor);
299 config.WriteBool('Editor', 'DotEnable', DotEnable);
300 config.WriteInt('Editor', 'DotStepOne', DotStepOne);
301 config.WriteInt('Editor', 'DotStepTwo', DotStepTwo);
302 config.WriteInt('Editor', 'DotStep', DotStep);
303 config.WriteInt('Editor', 'DotSize', cbDotSize.ItemIndex);
304 config.WriteBool('Editor', 'DrawTexturePanel', DrawTexturePanel);
305 config.WriteBool('Editor', 'DrawPanelSize', DrawPanelSize);
306 config.WriteInt('Editor', 'BackColor', BackColor);
307 config.WriteInt('Editor', 'PreviewColor', PreviewColor);
308 config.WriteBool('Editor', 'UseCheckerboard', UseCheckerboard);
309 config.WriteInt('Editor', 'Scale', cbScale.ItemIndex);
310 config.WriteStr('Editor', 'Language', gLanguage);
312 config.WriteInt('Editor', 'RecentCount', re);
313 config.WriteBool('Editor', 'Compress', Compress);
314 config.WriteBool('Editor', 'Backup', Backup);
316 config.WriteStr('TestRun', 'GameMode', TestGameMode);
317 config.WriteStr('TestRun', 'LimTime', TestLimTime);
318 config.WriteStr('TestRun', 'LimScore', TestLimScore);
319 config.WriteBool('TestRun', 'TwoPlayers', TestOptionsTwoPlayers);
320 config.WriteBool('TestRun', 'TeamDamage', TestOptionsTeamDamage);
321 config.WriteBool('TestRun', 'AllowExit', TestOptionsAllowExit);
322 config.WriteBool('TestRun', 'WeaponStay', TestOptionsWeaponStay);
323 config.WriteBool('TestRun', 'MonstersDM', TestOptionsMonstersDM);
324 config.WriteBool('TestRun', 'MapOnce', TestMapOnce);
325 {$IF DEFINED(DARWIN)}
326 config.WriteStr('TestRun', 'ExeDrawin', TestD2dExe);
327 {$ELSEIF DEFINED(WINDOWS)}
328 config.WriteStr('TestRun', 'ExeWindows', TestD2dExe);
329 {$ELSE}
330 config.WriteStr('TestRun', 'ExeUnix', TestD2dExe);
331 {$ENDIF}
332 config.WriteStr('TestRun', 'Args', TestD2DArgs);
334 if RecentCount <> re then
335 begin
336 RecentCount := re;
337 MainForm.RefreshRecentMenu();
338 end;
340 config.SaveFile(CfgFileName);
341 config.Free();
342 Close();
343 end;
345 procedure TOptionsForm.bCancelClick(Sender: TObject);
346 begin
347 Close();
348 end;
350 procedure TOptionsForm.bBackClick(Sender: TObject);
351 begin
352 if ColorDialog.Execute then
353 sBackColor.Brush.Color := ColorDialog.Color;
354 end;
356 procedure TOptionsForm.bPreviewClick(Sender: TObject);
357 begin
358 if ColorDialog.Execute then
359 sPreviewColor.Brush.Color := ColorDialog.Color;
360 end;
362 procedure TOptionsForm.FormCreate(Sender: TObject);
363 begin
364 {$IF DEFINED(DARWIN)}
365 if LowerCase(ExtractFileExt(TestD2dExe)) = '.app' then
366 FindD2dDialog.InitialDir := ExtractFileDir(TestD2dExe)
367 else
368 FindD2dDialog.InitialDir := TestD2dExe;
369 FindD2dDialog.DefaultExt := '.app';
370 FindD2dDialog.Filter := 'Doom 2D Forever.app|*.app|Doom 2D Forever (Unix Executable)|Doom2DF;*';
371 {$ELSEIF DEFINED(WINDOWS)}
372 FindD2dDialog.InitialDir := TestD2dExe;
373 FindD2dDialog.DefaultExt := '.exe';
374 FindD2dDialog.Filter := 'Doom2DF.exe|Doom2DF.exe;*.exe';
375 {$ELSE}
376 FindD2dDialog.InitialDir := TestD2dExe;
377 FindD2dDialog.DefaultExt := '';
378 FindD2dDialog.Filter := 'Doom2DF|Doom2DF;*';
379 {$ENDIF}
380 end;
382 end.