DEADSOFTWARE

i10n: fix preferences 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 FormShow(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.FormShow(Sender: TObject);
148 var list: TStringList;
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(MsgLabEsLanguageAuto);
175 list := g_Language_GetList();
176 cbLanguage.Items.AddStrings(list);
177 list.Free();
178 cbLanguage.ItemIndex := IfThen(gLanguage = '', 0, cbLanguage.Items.IndexOf(gLanguage));
179 finally
180 cbLanguage.Items.EndUpdate;
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 cbLanguage.ItemIndex >= 0 then
215 begin
216 if cbLanguage.ItemIndex = 0 then str := '' else str := cbLanguage.Items[cbLanguage.ItemIndex];
217 if (str = '') or (gLanguage <> str) then
218 begin
219 gLanguage := str;
220 g_Language_Set(gLanguage);
221 end;
222 end;
224 DotColor := sDotColor.Brush.Color;
225 DotEnable := cbShowDots.Checked;
227 if DotStep = DotStepOne then
228 d1 := True
229 else
230 d1 := False;
231 DotStepOne := EnsureRange(StrToIntDef(eDotStepOne.Text, 16), 4, 2048);
232 DotStepTwo := EnsureRange(StrToIntDef(eDotStepTwo.Text, 8), 4, 2048);
233 if d1 then
234 DotStep := DotStepOne
235 else
236 DotStep := DotStepTwo;
238 DrawTexturePanel := cbShowTexture.Checked;
239 DrawPanelSize := cbShowSize.Checked;
240 BackColor := sBackColor.Brush.Color;
241 PreviewColor := sPreviewColor.Brush.Color;
242 UseCheckerboard := cbCheckerboard.Checked;
244 if cbScale.ItemIndex = 1 then
245 Scale := 2
246 else
247 Scale := 1;
249 if cbDotSize.ItemIndex = 1 then
250 DotSize := 2
251 else
252 DotSize := 1;
254 // Files tab
256 re := Min(Max(StrToIntDef(eRecent.Text, 5), 2), 10);
257 Compress := cbCompress.Checked;
258 Backup := cbBackup.Checked;
260 // Testing tab
262 if rbTDM.Checked then
263 TestGameMode := 'TDM'
264 else if rbCTF.Checked then
265 TestGameMode := 'CTF'
266 else if rbCOOP.Checked then
267 TestGameMode := 'COOP'
268 else
269 TestGameMode := 'DM';
271 TestLimTime := edTime.Text;
272 if (not TryStrToInt(TestLimTime, n)) then
273 TestLimTime := '0';
275 TestLimScore := edScore.Text;
276 if (not TryStrToInt(TestLimScore, n)) then
277 TestLimScore := '0';
279 TestOptionsTwoPlayers := cbTwoPlayers.Checked;
280 TestOptionsTeamDamage := cbTeamDamage.Checked;
281 TestOptionsAllowExit := cbAllowExit.Checked;
282 TestOptionsWeaponStay := cbWeaponStay.Checked;
283 TestOptionsMonstersDM := cbMonstersDM.Checked;
284 TestMapOnce := cbMapOnce.Checked;
286 TestD2dExe := edD2dExe.Text;
287 TestD2DArgs := edD2DArgs.Text;
289 // save into config
291 config := TConfig.CreateFile(CfgFileName);
293 config.WriteInt('Editor', 'DotColor', DotColor);
294 config.WriteBool('Editor', 'DotEnable', DotEnable);
295 config.WriteInt('Editor', 'DotStepOne', DotStepOne);
296 config.WriteInt('Editor', 'DotStepTwo', DotStepTwo);
297 config.WriteInt('Editor', 'DotStep', DotStep);
298 config.WriteInt('Editor', 'DotSize', cbDotSize.ItemIndex);
299 config.WriteBool('Editor', 'DrawTexturePanel', DrawTexturePanel);
300 config.WriteBool('Editor', 'DrawPanelSize', DrawPanelSize);
301 config.WriteInt('Editor', 'BackColor', BackColor);
302 config.WriteInt('Editor', 'PreviewColor', PreviewColor);
303 config.WriteBool('Editor', 'UseCheckerboard', UseCheckerboard);
304 config.WriteInt('Editor', 'Scale', cbScale.ItemIndex);
305 config.WriteStr('Editor', 'Language', gLanguage);
307 config.WriteInt('Editor', 'RecentCount', re);
308 config.WriteBool('Editor', 'Compress', Compress);
309 config.WriteBool('Editor', 'Backup', Backup);
311 config.WriteStr('TestRun', 'GameMode', TestGameMode);
312 config.WriteStr('TestRun', 'LimTime', TestLimTime);
313 config.WriteStr('TestRun', 'LimScore', TestLimScore);
314 config.WriteBool('TestRun', 'TwoPlayers', TestOptionsTwoPlayers);
315 config.WriteBool('TestRun', 'TeamDamage', TestOptionsTeamDamage);
316 config.WriteBool('TestRun', 'AllowExit', TestOptionsAllowExit);
317 config.WriteBool('TestRun', 'WeaponStay', TestOptionsWeaponStay);
318 config.WriteBool('TestRun', 'MonstersDM', TestOptionsMonstersDM);
319 config.WriteBool('TestRun', 'MapOnce', TestMapOnce);
320 {$IF DEFINED(DARWIN)}
321 config.WriteStr('TestRun', 'ExeDrawin', TestD2dExe);
322 {$ELSEIF DEFINED(WINDOWS)}
323 config.WriteStr('TestRun', 'ExeWindows', TestD2dExe);
324 {$ELSE}
325 config.WriteStr('TestRun', 'ExeUnix', TestD2dExe);
326 {$ENDIF}
327 config.WriteStr('TestRun', 'Args', TestD2DArgs);
329 if RecentCount <> re then
330 begin
331 RecentCount := re;
332 MainForm.RefreshRecentMenu();
333 end;
335 config.SaveFile(CfgFileName);
336 config.Free();
337 Close();
338 end;
340 procedure TOptionsForm.bCancelClick(Sender: TObject);
341 begin
342 Close();
343 end;
345 procedure TOptionsForm.bBackClick(Sender: TObject);
346 begin
347 if ColorDialog.Execute then
348 sBackColor.Brush.Color := ColorDialog.Color;
349 end;
351 procedure TOptionsForm.bPreviewClick(Sender: TObject);
352 begin
353 if ColorDialog.Execute then
354 sPreviewColor.Brush.Color := ColorDialog.Color;
355 end;
357 procedure TOptionsForm.FormCreate(Sender: TObject);
358 begin
359 {$IF DEFINED(DARWIN)}
360 if LowerCase(ExtractFileExt(TestD2dExe)) = '.app' then
361 FindD2dDialog.InitialDir := ExtractFileDir(TestD2dExe)
362 else
363 FindD2dDialog.InitialDir := TestD2dExe;
364 FindD2dDialog.DefaultExt := '.app';
365 FindD2dDialog.Filter := 'Doom 2D Forever.app|*.app|Doom 2D Forever (Unix Executable)|Doom2DF;*';
366 {$ELSEIF DEFINED(WINDOWS)}
367 FindD2dDialog.InitialDir := TestD2dExe;
368 FindD2dDialog.DefaultExt := '.exe';
369 FindD2dDialog.Filter := 'Doom2DF.exe|Doom2DF.exe;*.exe';
370 {$ELSE}
371 FindD2dDialog.InitialDir := TestD2dExe;
372 FindD2dDialog.DefaultExt := '';
373 FindD2dDialog.Filter := 'Doom2DF|Doom2DF;*';
374 {$ENDIF}
375 end;
377 end.