DEADSOFTWARE

changed some backslashes to forward slashes
[d2df-editor.git] / src / editor / f_options.pas
1 unit f_options;
3 {$MODE Delphi}
5 interface
7 uses
8 LCLIntf, LCLType, LMessages, Messages, SysUtils, Variants, Classes,
9 Graphics, Controls, Forms, Dialogs, StdCtrls,
10 ExtCtrls, ComCtrls, Registry;
12 type
13 TOptionsForm = class (TForm)
14 bOK: TButton;
15 bCancel: TButton;
16 ColorDialog: TColorDialog;
17 GroupBox1: TGroupBox;
18 // Общие настройки:
19 cbShowDots: TCheckBox;
20 cbShowTexture: TCheckBox;
21 cbShowSize: TCheckBox;
22 // Шаги сетки:
23 LabelGrid: TLabel;
24 eDotStepOne: TEdit;
25 UpDown1: TUpDown;
26 eDotStepTwo: TEdit;
27 UpDown2: TUpDown;
28 // Цвет сетки:
29 LabelGridCol: TLabel;
30 sDotColor: TShape;
31 bGrid: TButton;
32 // Цвет фона:
33 LabelBack: TLabel;
34 sBackColor: TShape;
35 bBack: TButton;
36 // Цвет превью:
37 LabelPreview: TLabel;
38 sPreviewColor: TShape;
39 bPreview: TButton;
40 // Масштаб миникарты:
41 LabelMinimap: TLabel;
42 cbScale: TComboBox;
43 // Количество недавно открытых:
44 LabelRecent: TLabel;
45 eRecent: TEdit;
46 UpDown3: TUpDown;
47 LabelLanguage: TLabel;
48 rbRussian: TRadioButton;
49 rbEnglish: TRadioButton;
50 LabelGridSize: TLabel;
51 cbDotSize: TComboBox;
53 procedure bGridClick(Sender: TObject);
54 procedure FormActivate(Sender: TObject);
55 procedure bOKClick(Sender: TObject);
56 procedure bCancelClick(Sender: TObject);
57 procedure bBackClick(Sender: TObject);
58 procedure bPreviewClick(Sender: TObject);
60 private
61 { Private declarations }
62 public
63 { Public declarations }
64 end;
66 var
67 OptionsForm: TOptionsForm;
69 procedure RegisterFileType(ext: String; FileName: String);
71 implementation
73 uses
74 f_main, StdConvs, CONFIG, g_language;
76 {$R *.lfm}
78 procedure RegisterFileType(ext: String; FileName: String);
79 var
80 reg: TRegistry;
82 begin
83 reg := TRegistry.Create();
85 with reg do
86 begin
87 RootKey := HKEY_CLASSES_ROOT;
88 OpenKey('.'+ext,True);
89 WriteString('',ext+'file');
90 CloseKey();
91 CreateKey(ext+'file');
92 OpenKey(ext+'file\DefaultIcon',True);
93 WriteString('',FileName+',0');
94 CloseKey();
95 OpenKey(ext+'file\shell\open\command',True);
96 WriteString('',FileName+' "%1"');
97 CloseKey();
98 Free();
99 end;
100 end;
102 procedure TOptionsForm.bGridClick(Sender: TObject);
103 begin
104 if ColorDialog.Execute then
105 sDotColor.Brush.Color := ColorDialog.Color;
106 end;
108 procedure TOptionsForm.FormActivate(Sender: TObject);
109 begin
110 sDotColor.Brush.Color := DotColor;
111 cbShowDots.Checked := DotEnable;
112 cbShowTexture.Checked := DrawTexturePanel;
113 cbShowSize.Checked := DrawPanelSize;
114 eDotStepOne.Text := IntToStr(DotStepOne);
115 eDotStepTwo.Text := IntToStr(DotStepTwo);
116 sBackColor.Brush.Color := BackColor;
117 sPreviewColor.Brush.Color := PreviewColor;
118 if Scale = 2 then
119 cbScale.ItemIndex := 1
120 else
121 cbScale.ItemIndex := 0;
122 if DotSize = 2 then
123 cbDotSize.ItemIndex := 1
124 else
125 cbDotSize.ItemIndex := 0;
126 eRecent.Text := IntToStr(RecentCount);
128 // Язык:
129 if gLanguage = LANGUAGE_RUSSIAN then
130 begin
131 rbRussian.Checked := True;
132 rbEnglish.Checked := False;
133 end
134 else
135 begin
136 rbRussian.Checked := False;
137 rbEnglish.Checked := True;
138 end;
139 end;
141 procedure TOptionsForm.bOKClick(Sender: TObject);
142 var
143 config: TConfig;
144 re: Integer;
145 d1: Boolean;
146 str: String;
148 begin
149 re := StrToIntDef(eRecent.Text, 5);
150 if re < 2 then
151 re := 2;
152 if re > 10 then
153 re := 10;
155 if rbRussian.Checked then
156 str := LANGUAGE_RUSSIAN
157 else
158 str := LANGUAGE_ENGLISH;
160 // Нужно сменить язык:
161 if gLanguage <> str then
162 begin
163 gLanguage := str;
164 //e_WriteLog('Read language file', MSG_NOTIFY);
165 //g_Language_Load(EditorDir+'\data\'+gLanguage+LANGUAGE_FILE_NAME);
166 g_Language_Set(gLanguage);
167 end;
169 DotColor := sDotColor.Brush.Color;
170 DotEnable := cbShowDots.Checked;
172 if DotStep = DotStepOne then
173 d1 := True
174 else
175 d1 := False;
176 DotStepOne := StrToIntDef(eDotStepOne.Text, 16);
177 DotStepTwo := StrToIntDef(eDotStepTwo.Text, 8);
178 if d1 then
179 DotStep := DotStepOne
180 else
181 DotStep := DotStepTwo;
183 DrawTexturePanel := cbShowTexture.Checked;
184 DrawPanelSize := cbShowSize.Checked;
185 BackColor := sBackColor.Brush.Color;
186 PreviewColor := sPreviewColor.Brush.Color;
188 if cbScale.ItemIndex = 1 then
189 Scale := 2
190 else
191 Scale := 1;
193 if cbDotSize.ItemIndex = 1 then
194 DotSize := 2
195 else
196 DotSize := 1;
198 config := TConfig.CreateFile(EditorDir+'/Editor.cfg');
200 config.WriteInt('Editor', 'DotColor', DotColor);
201 config.WriteBool('Editor', 'DotEnable', DotEnable);
202 config.WriteInt('Editor', 'DotStepOne', DotStepOne);
203 config.WriteInt('Editor', 'DotStepTwo', DotStepTwo);
204 config.WriteInt('Editor', 'DotStep', DotStep);
205 config.WriteInt('Editor', 'DotSize', cbDotSize.ItemIndex);
206 config.WriteBool('Editor', 'DrawTexturePanel', DrawTexturePanel);
207 config.WriteBool('Editor', 'DrawPanelSize', DrawPanelSize);
208 config.WriteInt('Editor', 'BackColor', BackColor);
209 config.WriteInt('Editor', 'PreviewColor', PreviewColor);
210 config.WriteInt('Editor', 'Scale', cbScale.ItemIndex);
211 config.WriteInt('Editor', 'RecentCount', re);
212 config.WriteStr('Editor', 'Language', gLanguage);
214 if RecentCount <> re then
215 begin
216 RecentCount := re;
217 MainForm.RefreshRecentMenu();
218 end;
220 config.SaveFile(EditorDir+'/Editor.cfg');
221 config.Free();
222 Close();
223 end;
225 procedure TOptionsForm.bCancelClick(Sender: TObject);
226 begin
227 Close();
228 end;
230 procedure TOptionsForm.bBackClick(Sender: TObject);
231 begin
232 if ColorDialog.Execute then
233 sBackColor.Brush.Color := ColorDialog.Color;
234 end;
236 procedure TOptionsForm.bPreviewClick(Sender: TObject);
237 begin
238 if ColorDialog.Execute then
239 sPreviewColor.Brush.Color := ColorDialog.Color;
240 end;
242 end.