1 | unit Settings;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
|
---|
7 | LCLProc, ScreenTools, Messg, ButtonA, Directories, DrawDlg, ButtonC,
|
---|
8 | UKeyBindings, ULanguages;
|
---|
9 |
|
---|
10 | type
|
---|
11 | { TSettingsDlg }
|
---|
12 |
|
---|
13 | TSettingsDlg = class(TDrawDlg)
|
---|
14 | ButtonFullscreen: TButtonC;
|
---|
15 | Down2Btn: TButtonC;
|
---|
16 | EditShortCutPrimary: TEdit;
|
---|
17 | EditShortCutSecondary: TEdit;
|
---|
18 | ListLanguages: TListBox;
|
---|
19 | ListKeyBindings: TListBox;
|
---|
20 | ButtonOk: TButtonA;
|
---|
21 | ButtonCancel: TButtonA;
|
---|
22 | ButtonReset: TButtonA;
|
---|
23 | Up2Btn: TButtonC;
|
---|
24 | procedure ButtonFullscreenClick(Sender: TObject);
|
---|
25 | procedure ButtonCancelClick(Sender: TObject);
|
---|
26 | procedure ButtonResetClick(Sender: TObject);
|
---|
27 | procedure Down2BtnClick(Sender: TObject);
|
---|
28 | procedure EditShortCutPrimaryKeyUp(Sender: TObject; var Key: Word;
|
---|
29 | Shift: TShiftState);
|
---|
30 | procedure EditShortCutSecondaryKeyUp(Sender: TObject; var Key: Word;
|
---|
31 | Shift: TShiftState);
|
---|
32 | procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
---|
33 | procedure FormCreate(Sender: TObject);
|
---|
34 | procedure FormDestroy(Sender: TObject);
|
---|
35 | procedure FormPaint(Sender: TObject);
|
---|
36 | procedure FormShow(Sender: TObject);
|
---|
37 | procedure ListKeyBindingsSelectionChange(Sender: TObject; User: Boolean);
|
---|
38 | procedure ButtonOkClick(Sender: TObject);
|
---|
39 | procedure Up2BtnClick(Sender: TObject);
|
---|
40 | private
|
---|
41 | LocalGamma: Integer;
|
---|
42 | LocalKeyBindings: TKeyBindings;
|
---|
43 | CurrentKeyBinding: TKeyBinding;
|
---|
44 | procedure UpdateShortCutItem;
|
---|
45 | public
|
---|
46 | procedure LoadData;
|
---|
47 | procedure SaveData;
|
---|
48 | end;
|
---|
49 |
|
---|
50 | var
|
---|
51 | SettingsDlg: TSettingsDlg;
|
---|
52 |
|
---|
53 |
|
---|
54 | implementation
|
---|
55 |
|
---|
56 | {$R *.lfm}
|
---|
57 |
|
---|
58 | uses
|
---|
59 | Start;
|
---|
60 |
|
---|
61 | var
|
---|
62 | SFullScreen, SGamma, SRestartMsg, SShortCutPrimary, SShortCutSecondary,
|
---|
63 | SLanguages, SKeyBindings: string;
|
---|
64 |
|
---|
65 | procedure ReloadLanguages;
|
---|
66 | begin
|
---|
67 | SFullScreen := Phrases.Lookup('SETTINGS', 0);
|
---|
68 | SGamma := Phrases.Lookup('SETTINGS', 1);
|
---|
69 | SRestartMsg := Phrases.Lookup('SETTINGS', 2);
|
---|
70 | SShortCutPrimary := Phrases.Lookup('SETTINGS', 3);
|
---|
71 | SShortCutSecondary := Phrases.Lookup('SETTINGS', 4);
|
---|
72 | SLanguages := Phrases.Lookup('SETTINGS', 5);
|
---|
73 | SKeyBindings := Phrases.Lookup('SETTINGS', 6);
|
---|
74 | end;
|
---|
75 |
|
---|
76 | { TSettingsDlg }
|
---|
77 |
|
---|
78 | procedure TSettingsDlg.FormCreate(Sender: TObject);
|
---|
79 | begin
|
---|
80 | Color := clBlack;
|
---|
81 | LocalKeyBindings := TKeyBindings.Create;
|
---|
82 |
|
---|
83 | Canvas.Font.Assign(UniFont[ftNormal]);
|
---|
84 | Canvas.Brush.Style := bsClear;
|
---|
85 |
|
---|
86 | ButtonOk.Caption := Phrases.Lookup('BTN_OK');
|
---|
87 | ButtonCancel.Caption := Phrases.Lookup('BTN_CANCEL');
|
---|
88 | ButtonReset.Caption := Phrases.Lookup('BTN_RESET');
|
---|
89 | InitButtons;
|
---|
90 | end;
|
---|
91 |
|
---|
92 | procedure TSettingsDlg.ButtonCancelClick(Sender: TObject);
|
---|
93 | begin
|
---|
94 | ModalResult := mrCancel;
|
---|
95 | end;
|
---|
96 |
|
---|
97 | procedure TSettingsDlg.ButtonResetClick(Sender: TObject);
|
---|
98 | begin
|
---|
99 | ListLanguages.ItemIndex := 0;
|
---|
100 | ButtonFullscreen.ButtonIndex := 3;
|
---|
101 | LocalGamma := 100;
|
---|
102 | ListKeyBindings.ItemIndex := -1;
|
---|
103 | ListKeyBindingsSelectionChange(nil, False);
|
---|
104 | LocalKeyBindings.ResetToDefault;
|
---|
105 | LocalKeyBindings.LoadToStrings(ListKeyBindings.Items);
|
---|
106 | Repaint;
|
---|
107 | end;
|
---|
108 |
|
---|
109 | procedure TSettingsDlg.Down2BtnClick(Sender: TObject);
|
---|
110 | begin
|
---|
111 | if LocalGamma > 50 then
|
---|
112 | begin
|
---|
113 | Dec(LocalGamma);
|
---|
114 | Invalidate;
|
---|
115 | end;
|
---|
116 | end;
|
---|
117 |
|
---|
118 | procedure TSettingsDlg.EditShortCutPrimaryKeyUp(Sender: TObject; var Key: Word;
|
---|
119 | Shift: TShiftState);
|
---|
120 | begin
|
---|
121 | if (Sender is TEdit) and Assigned(CurrentKeyBinding) and not (Key in [16..18]) then begin
|
---|
122 | CurrentKeyBinding.ShortCut := Key or
|
---|
123 | (scShift * Integer(ssShift in Shift)) or
|
---|
124 | (scCtrl * Integer(ssCtrl in Shift)) or
|
---|
125 | (scAlt * Integer(ssAlt in Shift));
|
---|
126 | EditShortCutPrimary.Text := ShortCutToText(CurrentKeyBinding.ShortCut);
|
---|
127 | Key := 0;
|
---|
128 | UpdateShortCutItem;
|
---|
129 | end;
|
---|
130 | end;
|
---|
131 |
|
---|
132 | procedure TSettingsDlg.EditShortCutSecondaryKeyUp(Sender: TObject;
|
---|
133 | var Key: Word; Shift: TShiftState);
|
---|
134 | begin
|
---|
135 | if (Sender is TEdit) and Assigned(CurrentKeyBinding) and not (Key in [16..18]) then begin
|
---|
136 | CurrentKeyBinding.ShortCut2 := Key or
|
---|
137 | (scShift * Integer(ssShift in Shift)) or
|
---|
138 | (scCtrl * Integer(ssCtrl in Shift)) or
|
---|
139 | (scAlt * Integer(ssAlt in Shift));
|
---|
140 | EditShortCutSecondary.Text := ShortCutToText(CurrentKeyBinding.ShortCut2);
|
---|
141 | Key := 0;
|
---|
142 | UpdateShortCutItem;
|
---|
143 | end;
|
---|
144 | end;
|
---|
145 |
|
---|
146 | procedure TSettingsDlg.FormClose(Sender: TObject; var CloseAction: TCloseAction
|
---|
147 | );
|
---|
148 | begin
|
---|
149 | ListKeyBindings.ItemIndex := -1;
|
---|
150 | end;
|
---|
151 |
|
---|
152 | procedure TSettingsDlg.ButtonFullscreenClick(Sender: TObject);
|
---|
153 | begin
|
---|
154 | ButtonFullscreen.ButtonIndex := ButtonFullscreen.ButtonIndex xor 1;
|
---|
155 | end;
|
---|
156 |
|
---|
157 | procedure TSettingsDlg.FormDestroy(Sender: TObject);
|
---|
158 | begin
|
---|
159 | FreeAndNil(LocalKeyBindings);
|
---|
160 | end;
|
---|
161 |
|
---|
162 | procedure TSettingsDlg.FormPaint(Sender: TObject);
|
---|
163 | begin
|
---|
164 | PaintBackground(self, 3, 3, ClientWidth - 6, ClientHeight - 6);
|
---|
165 | Frame(Canvas, 0, 0, ClientWidth - 1, ClientHeight - 1, 0, 0);
|
---|
166 | Frame(Canvas, 1, 1, ClientWidth - 2, ClientHeight - 2,
|
---|
167 | MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
|
---|
168 | Frame(Canvas, 2, 2, ClientWidth - 3, ClientHeight - 3,
|
---|
169 | MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
|
---|
170 | EditFrame(Canvas, EditShortCutPrimary.BoundsRect, MainTexture);
|
---|
171 | EditFrame(Canvas, EditShortCutSecondary.BoundsRect, MainTexture);
|
---|
172 | EditFrame(Canvas, ListLanguages.BoundsRect, MainTexture);
|
---|
173 | BtnFrame(Canvas, ButtonOk.BoundsRect, MainTexture);
|
---|
174 | BtnFrame(Canvas, ButtonCancel.BoundsRect, MainTexture);
|
---|
175 |
|
---|
176 | RFrame(Canvas, ButtonFullscreen.Left - 1, ButtonFullscreen.Top - 1,
|
---|
177 | ButtonFullscreen.Left + 12, ButtonFullscreen.Top + 12, MainTexture.ColorBevelShade,
|
---|
178 | MainTexture.ColorBevelLight);
|
---|
179 |
|
---|
180 | LoweredTextOut(Canvas, -2, MainTexture, ListLanguages.Left,
|
---|
181 | ListLanguages.Top - 26, SLanguages);
|
---|
182 | LoweredTextOut(Canvas, -2, MainTexture, ListKeyBindings.Left,
|
---|
183 | ListKeyBindings.Top - 26, SKeyBindings);
|
---|
184 | LoweredTextOut(Canvas, -2, MainTexture, ButtonFullscreen.Left + 32,
|
---|
185 | ButtonFullscreen.Top - 4, SFullScreen);
|
---|
186 | UnderlinedTitleValue(Canvas, SGamma, IntToStr(LocalGamma) + '%',
|
---|
187 | Up2Btn.Left - 150 - 4, Up2Btn.Top + 2, 150);
|
---|
188 | LoweredTextOut(Canvas, -2, MainTexture, EditShortCutPrimary.Left,
|
---|
189 | EditShortCutPrimary.Top - 26, SShortCutPrimary);
|
---|
190 | LoweredTextOut(Canvas, -2, MainTexture, EditShortCutSecondary.Left,
|
---|
191 | EditShortCutSecondary.Top - 26, SShortCutSecondary);
|
---|
192 | end;
|
---|
193 |
|
---|
194 | procedure TSettingsDlg.FormShow(Sender: TObject);
|
---|
195 | begin
|
---|
196 | Caption := Phrases2.Lookup('ACTIONHEADER_CONFIG');
|
---|
197 | ReloadLanguages;
|
---|
198 | StartDlg.Translator.LanguageListToStrings(ListLanguages.Items);
|
---|
199 | ListLanguages.Font.Color := MainTexture.ColorMark;
|
---|
200 | ListKeyBindings.Font.Color := MainTexture.ColorMark;
|
---|
201 | LoadData;
|
---|
202 | LocalKeyBindings.LoadToStrings(ListKeyBindings.Items);
|
---|
203 | EditShortCutPrimary.Font.Color := MainTexture.ColorMark;
|
---|
204 | EditShortCutSecondary.Font.Color := MainTexture.ColorMark;
|
---|
205 | end;
|
---|
206 |
|
---|
207 | procedure TSettingsDlg.ListKeyBindingsSelectionChange(Sender: TObject;
|
---|
208 | User: Boolean);
|
---|
209 | begin
|
---|
210 | if Assigned(CurrentKeyBinding) then begin
|
---|
211 | CurrentKeyBinding.ShortCut := TextToShortCut(EditShortCutPrimary.Text);
|
---|
212 | CurrentKeyBinding.ShortCut2 := TextToShortCut(EditShortCutSecondary.Text);
|
---|
213 | end;
|
---|
214 |
|
---|
215 | if ListKeyBindings.ItemIndex >= 0 then
|
---|
216 | CurrentKeyBinding := LocalKeyBindings[ListKeyBindings.ItemIndex]
|
---|
217 | else CurrentKeyBinding := nil;
|
---|
218 |
|
---|
219 | if Assigned(CurrentKeyBinding) then begin
|
---|
220 | if CurrentKeyBinding.ShortCut <> 0 then
|
---|
221 | EditShortCutPrimary.Text := ShortCutToText(CurrentKeyBinding.ShortCut)
|
---|
222 | else EditShortCutPrimary.Text := '';
|
---|
223 | EditShortCutPrimary.Enabled := True;
|
---|
224 | if CurrentKeyBinding.ShortCut2 <> 0 then
|
---|
225 | EditShortCutSecondary.Text := ShortCutToText(CurrentKeyBinding.ShortCut2)
|
---|
226 | else EditShortCutSecondary.Text := '';
|
---|
227 | EditShortCutSecondary.Enabled := True;
|
---|
228 | end else begin
|
---|
229 | EditShortCutPrimary.Text := '';
|
---|
230 | EditShortCutPrimary.Enabled := False;
|
---|
231 | EditShortCutSecondary.Text := '';
|
---|
232 | EditShortCutSecondary.Enabled := False;
|
---|
233 | end;
|
---|
234 | end;
|
---|
235 |
|
---|
236 | procedure TSettingsDlg.ButtonOkClick(Sender: TObject);
|
---|
237 | begin
|
---|
238 | SaveData;
|
---|
239 | ModalResult := mrOk;
|
---|
240 | end;
|
---|
241 |
|
---|
242 | procedure TSettingsDlg.Up2BtnClick(Sender: TObject);
|
---|
243 | begin
|
---|
244 | if LocalGamma < 150 then begin
|
---|
245 | Inc(LocalGamma);
|
---|
246 | Invalidate;
|
---|
247 | end;
|
---|
248 | end;
|
---|
249 |
|
---|
250 | procedure TSettingsDlg.UpdateShortCutItem;
|
---|
251 | begin
|
---|
252 | if Assigned(CurrentKeyBinding) then begin
|
---|
253 | if CurrentKeyBinding.ShortCut > 0 then
|
---|
254 | LocalKeyBindings.RemoveShortCut(CurrentKeyBinding.ShortCut);
|
---|
255 | if CurrentKeyBinding.ShortCut2 > 0 then
|
---|
256 | LocalKeyBindings.RemoveShortCut(CurrentKeyBinding.ShortCut2);
|
---|
257 | CurrentKeyBinding.ShortCut := TextToShortCut(EditShortCutPrimary.Text);
|
---|
258 | CurrentKeyBinding.ShortCut2 := TextToShortCut(EditShortCutSecondary.Text);
|
---|
259 | LocalKeyBindings.LoadToStrings(ListKeyBindings.Items);
|
---|
260 | end;
|
---|
261 | end;
|
---|
262 |
|
---|
263 | procedure TSettingsDlg.LoadData;
|
---|
264 | begin
|
---|
265 | StartDlg.Translator.Language := StartDlg.Translator.Languages.SearchByCode(LocaleCode);
|
---|
266 | StartDlg.Translator.LanguageListToStrings(ListLanguages.Items, False);
|
---|
267 | ListLanguages.ItemIndex := ListLanguages.Items.IndexOfObject(StartDlg.Translator.Language);
|
---|
268 | if ListLanguages.ItemIndex = -1 then ListLanguages.ItemIndex := 0;
|
---|
269 | if FullScreen then ButtonFullscreen.ButtonIndex := 3
|
---|
270 | else ButtonFullscreen.ButtonIndex := 2;
|
---|
271 | LocalGamma := Gamma;
|
---|
272 | LocalKeyBindings.Assign(KeyBindings);
|
---|
273 | end;
|
---|
274 |
|
---|
275 | procedure TSettingsDlg.SaveData;
|
---|
276 | var
|
---|
277 | NeedRestart: Boolean;
|
---|
278 | begin
|
---|
279 | NeedRestart := Gamma <> LocalGamma;
|
---|
280 | if ListLanguages.ItemIndex <> -1 then begin
|
---|
281 | StartDlg.Translator.Language := TLanguage(ListLanguages.Items.Objects[ListLanguages.ItemIndex]);
|
---|
282 | LocaleCode := StartDlg.Translator.Language.Code;
|
---|
283 | end else begin
|
---|
284 | StartDlg.Translator.Language := nil;
|
---|
285 | LocaleCode := '';
|
---|
286 | end;
|
---|
287 | FullScreen := (ButtonFullscreen.ButtonIndex and 1) = 1;
|
---|
288 | Gamma := LocalGamma;
|
---|
289 | if NeedRestart then SimpleMessage(SRestartMsg);
|
---|
290 | KeyBindings.Assign(LocalKeyBindings);
|
---|
291 | end;
|
---|
292 |
|
---|
293 | end.
|
---|
294 |
|
---|