dfzip: more checks and user visible errors
[d2df-editor.git] / src / editor / f_options.pas
blob2f7d323eb23977e1e8df2c6891e949cbe942658c
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
13 TOptionsForm = class (TForm)
14 bOK: TButton;
15 bCancel: TButton;
16 cbAllowExit: TCheckBox;
17 cbCheckerboard: TCheckBox;
18 cbLanguage: TComboBox;
19 cbMapOnce: TCheckBox;
20 cbMonstersDM: TCheckBox;
21 cbShowDots: TCheckBox;
22 cbShowSize: TCheckBox;
23 cbShowTexture: TCheckBox;
24 cbTeamDamage: TCheckBox;
25 cbTwoPlayers: TCheckBox;
26 cbWeaponStay: TCheckBox;
27 ColorButton1: TColorButton;
28 ColorButton2: TColorButton;
29 ColorButton3: TColorButton;
30 edD2DArgs: TEdit;
31 edScore: TEdit;
32 edTime: TEdit;
33 ExeEdit: TFileNameEdit;
34 LabelArgs: TLabel;
35 LabelBack: TLabel;
36 LabelGrid: TLabel;
37 LabelGridCol: TLabel;
38 LabelGridSize: TLabel;
39 LabelLanguage: TLabel;
40 LabelMinimap: TLabel;
41 LabelPath: TLabel;
42 LabelPreview: TLabel;
43 LabelRecent: TLabel;
44 LabelScore: TLabel;
45 LabelSecs: TLabel;
46 LabelTime: TLabel;
47 PageControl: TPageControl;
48 rbCOOP: TRadioButton;
49 rbCTF: TRadioButton;
50 rbDM: TRadioButton;
51 rbTDM: TRadioButton;
52 SpinEdit1: TSpinEdit;
53 SpinEdit2: TSpinEdit;
54 SpinEdit3: TSpinEdit;
55 SpinEdit4: TSpinEdit;
56 SpinEdit5: TSpinEdit;
57 TabFiles: TTabSheet;
58 TabGeneral: TTabSheet;
59 TabTesting: TTabSheet;
61 procedure FormShow(Sender: TObject);
62 procedure bOKClick(Sender: TObject);
63 procedure bCancelClick(Sender: TObject);
64 procedure FormCreate(Sender: TObject);
65 end;
67 var
68 OptionsForm: TOptionsForm;
70 procedure RegisterFileType(ext: String; FileName: String);
72 implementation
74 uses
75 LazFileUtils, f_main, StdConvs, CONFIG, WADEDITOR, g_language, g_options;
77 {$R *.lfm}
79 procedure RegisterFileType(ext: String; FileName: String);
80 var
81 reg: TRegistry;
83 begin
84 reg := TRegistry.Create();
86 with reg do
87 begin
88 RootKey := HKEY_CLASSES_ROOT;
89 OpenKey('.'+ext,True);
90 WriteString('',ext+'file');
91 CloseKey();
92 CreateKey(ext+'file');
93 OpenKey(ext+'file\DefaultIcon',True);
94 WriteString('',FileName+',0');
95 CloseKey();
96 OpenKey(ext+'file\shell\open\command',True);
97 WriteString('',FileName+' "%1"');
98 CloseKey();
99 Free();
100 end;
101 end;
103 procedure TOptionsForm.FormShow(Sender: TObject);
104 var list: TStringList;
105 begin
106 // General Tab:
107 ColorButton1.ButtonColor := DotColor;
108 ColorButton2.ButtonColor := BackColor;
109 ColorButton3.ButtonColor := PreviewColor;
110 SpinEdit1.Value := DotStepOne;
111 SpinEdit2.Value := DotStepTwo;
113 cbShowDots.Checked := DotEnable;
114 cbShowTexture.Checked := DrawTexturePanel;
115 cbShowSize.Checked := DrawPanelSize;
116 cbCheckerboard.Checked := UseCheckerboard;
118 SpinEdit4.Value := DotSize;
119 SpinEdit5.Value := Scale;
122 cbLanguage.Items.BeginUpdate;
123 cbLanguage.Items.Clear;
124 cbLanguage.Items.Add(MsgLabEsLanguageAuto);
125 list := g_Language_GetList();
126 cbLanguage.Items.AddStrings(list);
127 list.Free();
128 cbLanguage.ItemIndex := IfThen(gLanguage = '', 0, cbLanguage.Items.IndexOf(gLanguage));
129 finally
130 cbLanguage.Items.EndUpdate;
131 end;
133 // Files Tab:
134 SpinEdit3.Value := RecentCount;
136 // Testing Tab:
137 ExeEdit.Text := TestD2dExe;
138 edD2DArgs.Text := TestD2DArgs;
140 rbDM.Checked := TestGameMode = 'DM';
141 rbTDM.Checked := TestGameMode = 'TDM';
142 rbCTF.Checked := TestGameMode = 'CTF';
143 rbCOOP.Checked := TestGameMode = 'COOP';
145 edTime.Text := TestLimTime;
146 edScore.Text := TestLimScore;
147 cbTwoPlayers.Checked := TestOptionsTwoPlayers;
148 cbTeamDamage.Checked := TestOptionsTeamDamage;
149 cbAllowExit.Checked := TestOptionsAllowExit;
150 cbWeaponStay.Checked := TestOptionsWeaponStay;
151 cbMonstersDM.Checked := TestOptionsMonstersDM;
152 cbMapOnce.Checked := TestMapOnce;
153 end;
155 procedure TOptionsForm.bOKClick(Sender: TObject);
157 config: TConfig;
158 re, n: Integer;
159 str: String;
161 begin
162 // General tab:
163 if cbLanguage.ItemIndex >= 0 then
164 begin
165 if cbLanguage.ItemIndex = 0 then str := '' else str := cbLanguage.Items[cbLanguage.ItemIndex];
166 if (str = '') or (gLanguage <> str) then
167 begin
168 gLanguage := str;
169 g_Language_Set(gLanguage);
170 end;
171 end;
173 DotColor := ColorButton1.ButtonColor;
174 BackColor := ColorButton2.ButtonColor;
175 PreviewColor := ColorButton3.ButtonColor;
177 DotEnable := cbShowDots.Checked;
178 DotStep := IfThen(DotStep = DotStepOne, SpinEdit1.Value, SpinEdit2.Value);
179 DotStepOne := SpinEdit1.Value;
180 DotStepTwo := SpinEdit2.Value;
182 DrawTexturePanel := cbShowTexture.Checked;
183 DrawPanelSize := cbShowSize.Checked;
184 UseCheckerboard := cbCheckerboard.Checked;
185 DotSize := SpinEdit4.Value;
186 Scale := SpinEdit5.Value;
188 // Files tab:
189 re := SpinEdit3.Value;
191 // Testing tab:
192 TestD2DExe := ExeEdit.Text;
193 TestD2DArgs := edD2DArgs.Text;
195 TestGameMode := 'DM';
196 if rbTDM.Checked then TestGameMode := 'TDM';
197 if rbCTF.Checked then TestGameMode := 'CTF';
198 if rbCOOP.Checked then TestGameMode := 'COOP';
199 if rbDM.Checked then TestGameMode := 'DM';
201 TestLimTime := edTime.Text;
202 if (not TryStrToInt(TestLimTime, n)) then
203 TestLimTime := '0';
205 TestLimScore := edScore.Text;
206 if (not TryStrToInt(TestLimScore, n)) then
207 TestLimScore := '0';
209 TestOptionsTwoPlayers := cbTwoPlayers.Checked;
210 TestOptionsTeamDamage := cbTeamDamage.Checked;
211 TestOptionsAllowExit := cbAllowExit.Checked;
212 TestOptionsWeaponStay := cbWeaponStay.Checked;
213 TestOptionsMonstersDM := cbMonstersDM.Checked;
214 TestMapOnce := cbMapOnce.Checked;
216 // save into config
217 config := TConfig.CreateFile(CfgFileName);
219 config.WriteInt('WADEditor', 'LogLevel', gWADEditorLogLevel);
221 config.WriteInt('Editor', 'DotColor', DotColor);
222 config.WriteBool('Editor', 'DotEnable', DotEnable);
223 config.WriteInt('Editor', 'DotStepOne', DotStepOne);
224 config.WriteInt('Editor', 'DotStepTwo', DotStepTwo);
225 config.WriteInt('Editor', 'DotStep', DotStep);
226 config.WriteInt('Editor', 'DotSize', SpinEdit4.Value);
227 config.WriteBool('Editor', 'DrawTexturePanel', DrawTexturePanel);
228 config.WriteBool('Editor', 'DrawPanelSize', DrawPanelSize);
229 config.WriteInt('Editor', 'BackColor', BackColor);
230 config.WriteInt('Editor', 'PreviewColor', PreviewColor);
231 config.WriteBool('Editor', 'UseCheckerboard', UseCheckerboard);
232 config.WriteInt('Editor', 'Scale', SpinEdit5.Value);
233 config.WriteStr('Editor', 'Language', gLanguage);
235 config.WriteInt('Editor', 'RecentCount', re);
237 config.WriteStr('TestRun', 'GameMode', TestGameMode);
238 config.WriteStr('TestRun', 'LimTime', TestLimTime);
239 config.WriteStr('TestRun', 'LimScore', TestLimScore);
240 config.WriteBool('TestRun', 'TwoPlayers', TestOptionsTwoPlayers);
241 config.WriteBool('TestRun', 'TeamDamage', TestOptionsTeamDamage);
242 config.WriteBool('TestRun', 'AllowExit', TestOptionsAllowExit);
243 config.WriteBool('TestRun', 'WeaponStay', TestOptionsWeaponStay);
244 config.WriteBool('TestRun', 'MonstersDM', TestOptionsMonstersDM);
245 config.WriteBool('TestRun', 'MapOnce', TestMapOnce);
246 {$IF DEFINED(DARWIN)}
247 config.WriteStr('TestRun', 'ExeDrawin', TestD2dExe);
248 {$ELSEIF DEFINED(WINDOWS)}
249 config.WriteStr('TestRun', 'ExeWindows', TestD2dExe);
250 {$ELSE}
251 config.WriteStr('TestRun', 'ExeUnix', TestD2dExe);
252 {$ENDIF}
253 config.WriteStr('TestRun', 'Args', TestD2DArgs);
255 if RecentCount <> re then
256 begin
257 RecentCount := re;
258 MainForm.RefreshRecentMenu();
259 end;
261 config.SaveFile(CfgFileName);
262 config.Free();
263 Close();
264 end;
266 procedure TOptionsForm.bCancelClick(Sender: TObject);
267 begin
268 Close();
269 end;
271 procedure TOptionsForm.FormCreate(Sender: TObject);
272 begin
273 {$IF DEFINED(DARWIN)}
274 if LowerCase(ExtractFileExt(TestD2DExe)) = '.app' then
275 ExeEdit.InitialDir := ExtractFileDir(TestD2DExe)
276 else
277 ExeEdit.InitialDir := TestD2DExe;
278 {$ELSE}
279 ExeEdit.InitialDir := TestD2DExe;
280 {$ENDIF}
281 end;
283 end.