DEADSOFTWARE

1f297ec217b0a6f7ba490f50f63a858f876d053b
[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, Registry;
12 type
13 TOptionsForm = class (TForm)
14 bOK: TButton;
15 bCancel: TButton;
16 cbCheckerboard: TCheckBox;
17 ColorDialog: TColorDialog;
18 GroupBox1: TGroupBox;
19 // Общие настройки:
20 cbShowDots: TCheckBox;
21 cbShowTexture: TCheckBox;
22 cbShowSize: TCheckBox;
23 // Шаги сетки:
24 LabelGrid: TLabel;
25 eDotStepOne: TEdit;
26 UpDown1: TUpDown;
27 eDotStepTwo: TEdit;
28 UpDown2: TUpDown;
29 // Цвет сетки:
30 LabelGridCol: TLabel;
31 sDotColor: TShape;
32 bGrid: TButton;
33 // Цвет фона:
34 LabelBack: TLabel;
35 sBackColor: TShape;
36 bBack: TButton;
37 // Цвет превью:
38 LabelPreview: TLabel;
39 sPreviewColor: TShape;
40 bPreview: TButton;
41 // Масштаб миникарты:
42 LabelMinimap: TLabel;
43 cbScale: TComboBox;
44 // Количество недавно открытых:
45 LabelRecent: TLabel;
46 eRecent: TEdit;
47 UpDown3: TUpDown;
48 LabelLanguage: TLabel;
49 rbRussian: TRadioButton;
50 rbEnglish: TRadioButton;
51 LabelGridSize: TLabel;
52 cbDotSize: TComboBox;
54 procedure bGridClick(Sender: TObject);
55 procedure FormActivate(Sender: TObject);
56 procedure bOKClick(Sender: TObject);
57 procedure bCancelClick(Sender: TObject);
58 procedure bBackClick(Sender: TObject);
59 procedure bPreviewClick(Sender: TObject);
61 private
62 { Private declarations }
63 public
64 { Public declarations }
65 end;
67 var
68 OptionsForm: TOptionsForm;
70 procedure RegisterFileType(ext: String; FileName: String);
72 implementation
74 uses
75 f_main, StdConvs, CONFIG, g_language;
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.bGridClick(Sender: TObject);
104 begin
105 if ColorDialog.Execute then
106 sDotColor.Brush.Color := ColorDialog.Color;
107 end;
109 procedure TOptionsForm.FormActivate(Sender: TObject);
110 begin
111 sDotColor.Brush.Color := DotColor;
112 cbShowDots.Checked := DotEnable;
113 cbShowTexture.Checked := DrawTexturePanel;
114 cbShowSize.Checked := DrawPanelSize;
115 eDotStepOne.Text := IntToStr(DotStepOne);
116 eDotStepTwo.Text := IntToStr(DotStepTwo);
117 sBackColor.Brush.Color := BackColor;
118 sPreviewColor.Brush.Color := PreviewColor;
119 cbCheckerboard.Checked := UseCheckerboard;
120 if Scale = 2 then
121 cbScale.ItemIndex := 1
122 else
123 cbScale.ItemIndex := 0;
124 if DotSize = 2 then
125 cbDotSize.ItemIndex := 1
126 else
127 cbDotSize.ItemIndex := 0;
128 eRecent.Text := IntToStr(RecentCount);
130 // Язык:
131 if gLanguage = LANGUAGE_RUSSIAN then
132 begin
133 rbRussian.Checked := True;
134 rbEnglish.Checked := False;
135 end
136 else
137 begin
138 rbRussian.Checked := False;
139 rbEnglish.Checked := True;
140 end;
141 end;
143 procedure TOptionsForm.bOKClick(Sender: TObject);
144 var
145 config: TConfig;
146 re: Integer;
147 d1: Boolean;
148 str: String;
150 begin
151 re := StrToIntDef(eRecent.Text, 5);
152 if re < 2 then
153 re := 2;
154 if re > 10 then
155 re := 10;
157 if rbRussian.Checked then
158 str := LANGUAGE_RUSSIAN
159 else
160 str := LANGUAGE_ENGLISH;
162 // Нужно сменить язык:
163 if gLanguage <> str then
164 begin
165 gLanguage := str;
166 //e_WriteLog('Read language file', MSG_NOTIFY);
167 //g_Language_Load(EditorDir+'\data\'+gLanguage+LANGUAGE_FILE_NAME);
168 g_Language_Set(gLanguage);
169 end;
171 DotColor := sDotColor.Brush.Color;
172 DotEnable := cbShowDots.Checked;
174 if DotStep = DotStepOne then
175 d1 := True
176 else
177 d1 := False;
178 DotStepOne := StrToIntDef(eDotStepOne.Text, 16);
179 DotStepTwo := StrToIntDef(eDotStepTwo.Text, 8);
180 if d1 then
181 DotStep := DotStepOne
182 else
183 DotStep := DotStepTwo;
185 DrawTexturePanel := cbShowTexture.Checked;
186 DrawPanelSize := cbShowSize.Checked;
187 BackColor := sBackColor.Brush.Color;
188 PreviewColor := sPreviewColor.Brush.Color;
189 UseCheckerboard := cbCheckerboard.Checked;
191 if cbScale.ItemIndex = 1 then
192 Scale := 2
193 else
194 Scale := 1;
196 if cbDotSize.ItemIndex = 1 then
197 DotSize := 2
198 else
199 DotSize := 1;
201 config := TConfig.CreateFile(EditorDir+'Editor.cfg');
203 config.WriteInt('Editor', 'DotColor', DotColor);
204 config.WriteBool('Editor', 'DotEnable', DotEnable);
205 config.WriteInt('Editor', 'DotStepOne', DotStepOne);
206 config.WriteInt('Editor', 'DotStepTwo', DotStepTwo);
207 config.WriteInt('Editor', 'DotStep', DotStep);
208 config.WriteInt('Editor', 'DotSize', cbDotSize.ItemIndex);
209 config.WriteBool('Editor', 'DrawTexturePanel', DrawTexturePanel);
210 config.WriteBool('Editor', 'DrawPanelSize', DrawPanelSize);
211 config.WriteInt('Editor', 'BackColor', BackColor);
212 config.WriteInt('Editor', 'PreviewColor', PreviewColor);
213 config.WriteBool('Editor', 'UseCheckerboard', UseCheckerboard);
214 config.WriteInt('Editor', 'Scale', cbScale.ItemIndex);
215 config.WriteInt('Editor', 'RecentCount', re);
216 config.WriteStr('Editor', 'Language', gLanguage);
218 if RecentCount <> re then
219 begin
220 RecentCount := re;
221 MainForm.RefreshRecentMenu();
222 end;
224 config.SaveFile(EditorDir+'Editor.cfg');
225 config.Free();
226 Close();
227 end;
229 procedure TOptionsForm.bCancelClick(Sender: TObject);
230 begin
231 Close();
232 end;
234 procedure TOptionsForm.bBackClick(Sender: TObject);
235 begin
236 if ColorDialog.Execute then
237 sBackColor.Brush.Color := ColorDialog.Color;
238 end;
240 procedure TOptionsForm.bPreviewClick(Sender: TObject);
241 begin
242 if ColorDialog.Execute then
243 sPreviewColor.Brush.Color := ColorDialog.Color;
244 end;
246 end.