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