DEADSOFTWARE

gui: improve prefereces 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, ActnList, Spin, EditBtn, Registry, Math, Types;
12 type
14 { TOptionsForm }
16 TOptionsForm = class (TForm)
17 bOK: TButton;
18 bCancel: TButton;
19 cbAllowExit: TCheckBox;
20 cbBackup: TCheckBox;
21 cbCheckerboard: TCheckBox;
22 cbCompress: TCheckBox;
23 cbLanguage: TComboBox;
24 cbMapOnce: TCheckBox;
25 cbMonstersDM: TCheckBox;
26 cbShowDots: TCheckBox;
27 cbShowSize: TCheckBox;
28 cbShowTexture: TCheckBox;
29 cbTeamDamage: TCheckBox;
30 cbTwoPlayers: TCheckBox;
31 cbWeaponStay: TCheckBox;
32 ColorButton1: TColorButton;
33 ColorButton2: TColorButton;
34 ColorButton3: TColorButton;
35 edD2DArgs: TEdit;
36 edScore: TEdit;
37 edTime: TEdit;
38 ExeEdit: TFileNameEdit;
39 LabelArgs: TLabel;
40 LabelBack: TLabel;
41 LabelGrid: TLabel;
42 LabelGridCol: TLabel;
43 LabelGridSize: TLabel;
44 LabelLanguage: TLabel;
45 LabelMinimap: TLabel;
46 LabelPath: TLabel;
47 LabelPreview: TLabel;
48 LabelRecent: TLabel;
49 LabelScore: TLabel;
50 LabelSecs: TLabel;
51 LabelTime: TLabel;
52 PageControl: TPageControl;
53 rbCOOP: TRadioButton;
54 rbCTF: TRadioButton;
55 rbDM: TRadioButton;
56 rbTDM: TRadioButton;
57 SpinEdit1: TSpinEdit;
58 SpinEdit2: TSpinEdit;
59 SpinEdit3: TSpinEdit;
60 SpinEdit4: TSpinEdit;
61 SpinEdit5: TSpinEdit;
62 TabFiles: TTabSheet;
63 TabGeneral: TTabSheet;
64 TabTesting: TTabSheet;
66 procedure FormShow(Sender: TObject);
67 procedure bOKClick(Sender: TObject);
68 procedure bCancelClick(Sender: TObject);
69 procedure FormCreate(Sender: TObject);
70 end;
72 var
73 OptionsForm: TOptionsForm;
75 procedure RegisterFileType(ext: String; FileName: String);
77 implementation
79 uses
80 LazFileUtils, f_main, StdConvs, CONFIG, g_language, g_resources, g_options;
82 {$R *.lfm}
84 procedure RegisterFileType(ext: String; FileName: String);
85 var
86 reg: TRegistry;
88 begin
89 reg := TRegistry.Create();
91 with reg do
92 begin
93 RootKey := HKEY_CLASSES_ROOT;
94 OpenKey('.'+ext,True);
95 WriteString('',ext+'file');
96 CloseKey();
97 CreateKey(ext+'file');
98 OpenKey(ext+'file\DefaultIcon',True);
99 WriteString('',FileName+',0');
100 CloseKey();
101 OpenKey(ext+'file\shell\open\command',True);
102 WriteString('',FileName+' "%1"');
103 CloseKey();
104 Free();
105 end;
106 end;
108 procedure TOptionsForm.FormShow(Sender: TObject);
109 var list: TStringList;
110 begin
111 // General Tab:
112 ColorButton1.ButtonColor := DotColor;
113 ColorButton2.ButtonColor := BackColor;
114 ColorButton3.ButtonColor := PreviewColor;
115 SpinEdit1.Value := DotStepOne;
116 SpinEdit2.Value := DotStepTwo;
118 cbShowDots.Checked := DotEnable;
119 cbShowTexture.Checked := DrawTexturePanel;
120 cbShowSize.Checked := DrawPanelSize;
121 cbCheckerboard.Checked := UseCheckerboard;
123 SpinEdit4.Value := DotSize;
124 SpinEdit5.Value := Scale;
126 try
127 cbLanguage.Items.BeginUpdate;
128 cbLanguage.Items.Clear;
129 cbLanguage.Items.Add(MsgLabEsLanguageAuto);
130 list := g_Language_GetList();
131 cbLanguage.Items.AddStrings(list);
132 list.Free();
133 cbLanguage.ItemIndex := IfThen(gLanguage = '', 0, cbLanguage.Items.IndexOf(gLanguage));
134 finally
135 cbLanguage.Items.EndUpdate;
136 end;
138 // Files Tab:
139 cbCompress.Checked := Compress;
140 cbBackup.Checked := Backup;
141 SpinEdit3.Value := RecentCount;
143 // Testing Tab:
144 ExeEdit.Text := TestD2dExe;
145 edD2DArgs.Text := TestD2DArgs;
147 rbDM.Checked := TestGameMode = 'DM';
148 rbTDM.Checked := TestGameMode = 'TDM';
149 rbCTF.Checked := TestGameMode = 'CTF';
150 rbCOOP.Checked := TestGameMode = 'COOP';
152 edTime.Text := TestLimTime;
153 edScore.Text := TestLimScore;
154 cbTwoPlayers.Checked := TestOptionsTwoPlayers;
155 cbTeamDamage.Checked := TestOptionsTeamDamage;
156 cbAllowExit.Checked := TestOptionsAllowExit;
157 cbWeaponStay.Checked := TestOptionsWeaponStay;
158 cbMonstersDM.Checked := TestOptionsMonstersDM;
159 cbMapOnce.Checked := TestMapOnce;
160 end;
162 procedure TOptionsForm.bOKClick(Sender: TObject);
163 var
164 config: TConfig;
165 re, n: Integer;
166 str: String;
168 begin
169 // General tab:
170 if cbLanguage.ItemIndex >= 0 then
171 begin
172 if cbLanguage.ItemIndex = 0 then str := '' else str := cbLanguage.Items[cbLanguage.ItemIndex];
173 if (str = '') or (gLanguage <> str) then
174 begin
175 gLanguage := str;
176 g_Language_Set(gLanguage);
177 end;
178 end;
180 DotColor := ColorButton1.ButtonColor;
181 BackColor := ColorButton2.ButtonColor;
182 PreviewColor := ColorButton3.ButtonColor;
184 DotEnable := cbShowDots.Checked;
185 DotStep := IfThen(DotStep = DotStepOne, SpinEdit1.Value, SpinEdit2.Value);
186 DotStepOne := SpinEdit1.Value;
187 DotStepTwo := SpinEdit2.Value;
189 DrawTexturePanel := cbShowTexture.Checked;
190 DrawPanelSize := cbShowSize.Checked;
191 UseCheckerboard := cbCheckerboard.Checked;
192 DotSize := SpinEdit4.Value;
193 Scale := SpinEdit5.Value;
195 // Files tab:
196 re := SpinEdit3.Value;
197 Compress := cbCompress.Checked;
198 Backup := cbBackup.Checked;
200 // Testing tab:
201 TestD2DExe := ExeEdit.Text;
202 TestD2DArgs := edD2DArgs.Text;
204 TestGameMode := 'DM';
205 if rbTDM.Checked then TestGameMode := 'TDM';
206 if rbCTF.Checked then TestGameMode := 'CTF';
207 if rbCOOP.Checked then TestGameMode := 'COOP';
208 if rbDM.Checked then TestGameMode := 'DM';
210 TestLimTime := edTime.Text;
211 if (not TryStrToInt(TestLimTime, n)) then
212 TestLimTime := '0';
214 TestLimScore := edScore.Text;
215 if (not TryStrToInt(TestLimScore, n)) then
216 TestLimScore := '0';
218 TestOptionsTwoPlayers := cbTwoPlayers.Checked;
219 TestOptionsTeamDamage := cbTeamDamage.Checked;
220 TestOptionsAllowExit := cbAllowExit.Checked;
221 TestOptionsWeaponStay := cbWeaponStay.Checked;
222 TestOptionsMonstersDM := cbMonstersDM.Checked;
223 TestMapOnce := cbMapOnce.Checked;
225 // save into config
226 config := TConfig.CreateFile(CfgFileName);
228 config.WriteInt('Editor', 'DotColor', DotColor);
229 config.WriteBool('Editor', 'DotEnable', DotEnable);
230 config.WriteInt('Editor', 'DotStepOne', DotStepOne);
231 config.WriteInt('Editor', 'DotStepTwo', DotStepTwo);
232 config.WriteInt('Editor', 'DotStep', DotStep);
233 config.WriteInt('Editor', 'DotSize', SpinEdit4.Value);
234 config.WriteBool('Editor', 'DrawTexturePanel', DrawTexturePanel);
235 config.WriteBool('Editor', 'DrawPanelSize', DrawPanelSize);
236 config.WriteInt('Editor', 'BackColor', BackColor);
237 config.WriteInt('Editor', 'PreviewColor', PreviewColor);
238 config.WriteBool('Editor', 'UseCheckerboard', UseCheckerboard);
239 config.WriteInt('Editor', 'Scale', SpinEdit5.Value);
240 config.WriteStr('Editor', 'Language', gLanguage);
242 config.WriteInt('Editor', 'RecentCount', re);
243 config.WriteBool('Editor', 'Compress', Compress);
244 config.WriteBool('Editor', 'Backup', Backup);
246 config.WriteStr('TestRun', 'GameMode', TestGameMode);
247 config.WriteStr('TestRun', 'LimTime', TestLimTime);
248 config.WriteStr('TestRun', 'LimScore', TestLimScore);
249 config.WriteBool('TestRun', 'TwoPlayers', TestOptionsTwoPlayers);
250 config.WriteBool('TestRun', 'TeamDamage', TestOptionsTeamDamage);
251 config.WriteBool('TestRun', 'AllowExit', TestOptionsAllowExit);
252 config.WriteBool('TestRun', 'WeaponStay', TestOptionsWeaponStay);
253 config.WriteBool('TestRun', 'MonstersDM', TestOptionsMonstersDM);
254 config.WriteBool('TestRun', 'MapOnce', TestMapOnce);
255 {$IF DEFINED(DARWIN)}
256 config.WriteStr('TestRun', 'ExeDrawin', TestD2dExe);
257 {$ELSEIF DEFINED(WINDOWS)}
258 config.WriteStr('TestRun', 'ExeWindows', TestD2dExe);
259 {$ELSE}
260 config.WriteStr('TestRun', 'ExeUnix', TestD2dExe);
261 {$ENDIF}
262 config.WriteStr('TestRun', 'Args', TestD2DArgs);
264 if RecentCount <> re then
265 begin
266 RecentCount := re;
267 MainForm.RefreshRecentMenu();
268 end;
270 config.SaveFile(CfgFileName);
271 config.Free();
272 Close();
273 end;
275 procedure TOptionsForm.bCancelClick(Sender: TObject);
276 begin
277 Close();
278 end;
280 procedure TOptionsForm.FormCreate(Sender: TObject);
281 begin
282 {$IF DEFINED(DARWIN)}
283 if LowerCase(ExtractFileExt(TestD2DExe)) = '.app' then
284 ExeEdit.InitialDir := ExtractFileDir(TestD2DExe)
285 else
286 ExeEdit.InitialDir := TestD2DExe;
287 {$ELSE}
288 ExeEdit.InitialDir := TestD2DExe;
289 {$ENDIF}
290 end;
292 end.