source: tags/1.3.8/Settings.pas

Last change on this file was 681, checked in by chronos, 13 days ago
  • Added: Separate music enable and volume controls in Settings dialog.
File size: 14.6 KB
Line 
1unit Settings;
2
3interface
4
5uses
6 Classes, SysUtils, FileUtil, Dialogs, LCLProc, ScreenTools, Messg, ButtonA,
7 Directories, DrawDlg, ButtonC, KeyBindings, Languages, ListBoxEx,
8 {$IFDEF DPI}Dpi.Forms, Dpi.Controls, Dpi.Graphics, Dpi.StdCtrls, System.UITypes{$ELSE}
9 Forms, Controls, Graphics, StdCtrls{$ENDIF}, Controls;
10
11type
12 { TSettingsDlg }
13
14 TSettingsDlg = class(TDrawDlg)
15 ButtonMusic: TButtonC;
16 ButtonMusicVolumeDown: TButtonC;
17 ButtonMusicVolumeUp: TButtonC;
18 ButtonFullscreen: TButtonC;
19 ButtonCustomDpi: TButtonC;
20 ButtonGammaDown: TButtonC;
21 ButtonDpiDown: TButtonC;
22 EditShortCutPrimary: TEdit;
23 EditShortCutSecondary: TEdit;
24 ListLanguages: TListBoxEx;
25 ListKeyBindings: TListBoxEx;
26 ButtonOk: TButtonA;
27 ButtonCancel: TButtonA;
28 ButtonReset: TButtonA;
29 ButtonGammaUp: TButtonC;
30 ButtonDpiUp: TButtonC;
31 procedure ButtonCustomDpiClick(Sender: TObject);
32 procedure ButtonDpiDownClick(Sender: TObject);
33 procedure ButtonDpiUpClick(Sender: TObject);
34 procedure ButtonFullscreenClick(Sender: TObject);
35 procedure ButtonCancelClick(Sender: TObject);
36 procedure ButtonMusicClick(Sender: TObject);
37 procedure ButtonMusicVolumeDownClick(Sender: TObject);
38 procedure ButtonMusicVolumeUpClick(Sender: TObject);
39 procedure ButtonResetClick(Sender: TObject);
40 procedure ButtonGammaDownClick(Sender: TObject);
41 procedure EditShortCutPrimaryKeyUp(Sender: TObject; var Key: Word;
42 Shift: TShiftState);
43 procedure EditShortCutSecondaryKeyUp(Sender: TObject; var Key: Word;
44 Shift: TShiftState);
45 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
46 procedure FormCreate(Sender: TObject);
47 procedure FormDestroy(Sender: TObject);
48 procedure FormPaint(Sender: TObject);
49 procedure FormShow(Sender: TObject);
50 procedure ListKeyBindingsKeyDown(Sender: TObject; var Key: Word;
51 Shift: TShiftState);
52 procedure ListKeyBindingsSelectionChange(Sender: TObject; User: Boolean);
53 procedure ButtonOkClick(Sender: TObject);
54 procedure ButtonGammaUpClick(Sender: TObject);
55 private
56 LocalGamma: Integer;
57 LocalKeyBindings: TKeyBindings;
58 LocalMusicEnabled: Integer;
59 LocalMusicVolume: Integer;
60 CurrentKeyBinding: TKeyBinding;
61 LocalDpi: Integer;
62 procedure UpdateShortCutItem;
63 function GetLocalCustomDpiEnabled: Boolean;
64 function GetLocalMusicEnabled: Boolean;
65 procedure UpdateInterface;
66 public
67 procedure LoadData;
68 procedure SaveData;
69 end;
70
71var
72 SettingsDlg: TSettingsDlg;
73
74const
75 DpiMin = 100;
76 DpiMax = 500;
77 DpiStep = 25;
78 MusicVolumeMin = 0;
79 MusicVolumeMax = 100;
80 MusicVolumeStep = 10;
81
82
83implementation
84
85{$R *.lfm}
86
87uses
88 Start;
89
90var
91 SFullScreen, SGamma, SRestartMsg, SShortCutPrimary, SShortCutSecondary,
92 SLanguages, SKeyBindings, SCustomDpi, SDpi, SMusic, SMusicVolume: string;
93
94procedure ReloadLanguages;
95begin
96 SFullScreen := Phrases.Lookup('SETTINGS', 0);
97 SGamma := Phrases.Lookup('SETTINGS', 1);
98 SRestartMsg := Phrases.Lookup('SETTINGS', 2);
99 SShortCutPrimary := Phrases.Lookup('SETTINGS', 3);
100 SShortCutSecondary := Phrases.Lookup('SETTINGS', 4);
101 SLanguages := Phrases.Lookup('SETTINGS', 5);
102 SKeyBindings := Phrases.Lookup('SETTINGS', 6);
103 SCustomDpi := Phrases.Lookup('SETTINGS', 7);
104 SDpi := Phrases.Lookup('SETTINGS', 8);
105 SMusic := Phrases.Lookup('SETTINGS', 9);
106 SMusicVolume := Phrases.Lookup('SETTINGS', 10);
107end;
108
109{ TSettingsDlg }
110
111procedure TSettingsDlg.FormCreate(Sender: TObject);
112begin
113 Color := clBlack;
114 LocalKeyBindings := TKeyBindings.Create;
115
116 Canvas.Font.Assign(UniFont[ftNormal]);
117 Canvas.Brush.Style := TBrushStyle.bsClear;
118
119 ButtonOk.Caption := Phrases.Lookup('BTN_OK');
120 ButtonCancel.Caption := Phrases.Lookup('BTN_CANCEL');
121 ButtonReset.Caption := Phrases.Lookup('BTN_RESET');
122 InitButtons;
123end;
124
125procedure TSettingsDlg.ButtonCancelClick(Sender: TObject);
126begin
127 ModalResult := mrCancel;
128end;
129
130procedure TSettingsDlg.ButtonMusicClick(Sender: TObject);
131begin
132 ButtonMusic.ButtonIndex := ButtonMusic.ButtonIndex xor 1;
133 UpdateInterface;
134end;
135
136procedure TSettingsDlg.ButtonMusicVolumeDownClick(Sender: TObject);
137begin
138 Dec(LocalMusicVolume, MusicVolumeStep);
139 if LocalMusicVolume < MusicVolumeMin then LocalMusicVolume := MusicVolumeMin;
140 Invalidate;
141end;
142
143procedure TSettingsDlg.ButtonMusicVolumeUpClick(Sender: TObject);
144begin
145 Inc(LocalMusicVolume, MusicVolumeStep);
146 if LocalMusicVolume > MusicVolumeMax then LocalMusicVolume := MusicVolumeMax;
147 Invalidate;
148end;
149
150procedure TSettingsDlg.ButtonResetClick(Sender: TObject);
151begin
152 // TODO: Better to have default values on single place
153 ListLanguages.ItemIndex := 0;
154 ButtonFullscreen.ButtonIndex := 3;
155 ButtonMusic.ButtonIndex := 3;
156 LocalMusicVolume := 50;
157 ButtonCustomDpi.ButtonIndex := 2;
158 LocalDpi := 100;
159 LocalGamma := 100;
160 ListKeyBindings.ItemIndex := -1;
161 ListKeyBindingsSelectionChange(nil, False);
162 LocalKeyBindings.ResetToDefault;
163 LocalKeyBindings.LoadToStrings(ListKeyBindings.Items);
164 UpdateInterface;
165 Repaint;
166end;
167
168procedure TSettingsDlg.ButtonGammaDownClick(Sender: TObject);
169begin
170 if LocalGamma > 50 then
171 begin
172 Dec(LocalGamma);
173 Invalidate;
174 end;
175end;
176
177procedure TSettingsDlg.EditShortCutPrimaryKeyUp(Sender: TObject; var Key: Word;
178 Shift: TShiftState);
179begin
180 if (Sender is TEdit) and Assigned(CurrentKeyBinding) and not (Key in [16..18]) then begin
181 CurrentKeyBinding.ShortCut := Key or
182 (scShift * Integer(ssShift in Shift)) or
183 (scCtrl * Integer(ssCtrl in Shift)) or
184 (scAlt * Integer(ssAlt in Shift));
185 EditShortCutPrimary.Text := ShortCutToText(CurrentKeyBinding.ShortCut);
186 Key := 0;
187 UpdateShortCutItem;
188 end;
189end;
190
191procedure TSettingsDlg.EditShortCutSecondaryKeyUp(Sender: TObject;
192 var Key: Word; Shift: TShiftState);
193begin
194 if (Sender is TEdit) and Assigned(CurrentKeyBinding) and not (Key in [16..18]) then begin
195 CurrentKeyBinding.ShortCut2 := Key or
196 (scShift * Integer(ssShift in Shift)) or
197 (scCtrl * Integer(ssCtrl in Shift)) or
198 (scAlt * Integer(ssAlt in Shift));
199 EditShortCutSecondary.Text := ShortCutToText(CurrentKeyBinding.ShortCut2);
200 Key := 0;
201 UpdateShortCutItem;
202 end;
203end;
204
205procedure TSettingsDlg.FormClose(Sender: TObject; var CloseAction: TCloseAction
206 );
207begin
208 ListKeyBindings.ItemIndex := -1;
209end;
210
211procedure TSettingsDlg.ButtonFullscreenClick(Sender: TObject);
212begin
213 ButtonFullscreen.ButtonIndex := ButtonFullscreen.ButtonIndex xor 1;
214end;
215
216procedure TSettingsDlg.ButtonDpiDownClick(Sender: TObject);
217begin
218 Dec(LocalDpi, DpiStep);
219 if LocalDpi < DpiMin then LocalDpi := DpiMin;
220 Invalidate;
221end;
222
223procedure TSettingsDlg.ButtonCustomDpiClick(Sender: TObject);
224begin
225 ButtonCustomDpi.ButtonIndex := ButtonCustomDpi.ButtonIndex xor 1;
226 UpdateInterface;
227end;
228
229procedure TSettingsDlg.ButtonDpiUpClick(Sender: TObject);
230begin
231 Inc(LocalDpi, DpiStep);
232 if LocalDpi > DpiMax then LocalDpi := DpiMax;
233 Invalidate;
234end;
235
236procedure TSettingsDlg.FormDestroy(Sender: TObject);
237begin
238 FreeAndNil(LocalKeyBindings);
239end;
240
241procedure TSettingsDlg.FormPaint(Sender: TObject);
242const
243 TextDistanceX = 20;
244 UpDownTextWidth = 120;
245begin
246 PaintBackground(Canvas, 3, 3, ClientWidth - 6, ClientHeight - 6,
247 ClientWidth, ClientHeight);
248 Frame(Canvas, 0, 0, ClientWidth - 1, ClientHeight - 1, 0, 0);
249 Frame(Canvas, 1, 1, ClientWidth - 2, ClientHeight - 2,
250 MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
251 Frame(Canvas, 2, 2, ClientWidth - 3, ClientHeight - 3,
252 MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
253 EditFrame(Canvas, EditShortCutPrimary.BoundsRect, MainTexture);
254 EditFrame(Canvas, EditShortCutSecondary.BoundsRect, MainTexture);
255 EditFrame(Canvas, ListLanguages.BoundsRect, MainTexture);
256 BtnFrame(Canvas, ButtonOk.BoundsRect, MainTexture);
257 BtnFrame(Canvas, ButtonCancel.BoundsRect, MainTexture);
258
259 RFrame(Canvas, ButtonFullscreen.Left - 1, ButtonFullscreen.Top - 1,
260 ButtonFullscreen.Left + 12, ButtonFullscreen.Top + 12, MainTexture.ColorBevelShade,
261 MainTexture.ColorBevelLight);
262 {$IFDEF DPI}
263 RFrame(Canvas, ButtonCustomDpi.Left - 1, ButtonCustomDpi.Top - 1,
264 ButtonCustomDpi.Left + 12, ButtonCustomDpi.Top + 12, MainTexture.ColorBevelShade,
265 MainTexture.ColorBevelLight);
266 LoweredTextOut(Canvas, -2, MainTexture, ButtonCustomDpi.Left + TextDistanceX,
267 ButtonCustomDpi.Top - 4, SCustomDpi);
268 UnderlinedTitleValue(Canvas, SDpi, IntToStr(LocalDpi) + '%',
269 ButtonDpiUp.Left - UpDownTextWidth - 4, ButtonDpiUp.Top + 2, UpDownTextWidth);
270 {$ENDIF}
271
272 RFrame(Canvas, ButtonMusic.Left - 1, ButtonMusic.Top - 1,
273 ButtonMusic.Left + 12, ButtonMusic.Top + 12, MainTexture.ColorBevelShade,
274 MainTexture.ColorBevelLight);
275 LoweredTextOut(Canvas, -2, MainTexture, ButtonMusic.Left + TextDistanceX,
276 ButtonMusic.Top - 4, SMusic);
277 UnderlinedTitleValue(Canvas, SMusicVolume, IntToStr(LocalMusicVolume) + '%',
278 ButtonMusicVolumeUp.Left - UpDownTextWidth - 4, ButtonMusicVolumeUp.Top + 2, UpDownTextWidth);
279
280 LoweredTextOut(Canvas, -2, MainTexture, ListLanguages.Left,
281 ListLanguages.Top - 26, SLanguages);
282 LoweredTextOut(Canvas, -2, MainTexture, ListKeyBindings.Left,
283 ListKeyBindings.Top - 26, SKeyBindings);
284 LoweredTextOut(Canvas, -2, MainTexture, ButtonFullscreen.Left + TextDistanceX,
285 ButtonFullscreen.Top - 4, SFullScreen);
286 UnderlinedTitleValue(Canvas, SGamma, IntToStr(LocalGamma) + '%',
287 ButtonGammaUp.Left - UpDownTextWidth - 4, ButtonGammaUp.Top + 2, UpDownTextWidth);
288 LoweredTextOut(Canvas, -2, MainTexture, EditShortCutPrimary.Left,
289 EditShortCutPrimary.Top - 26, SShortCutPrimary);
290 LoweredTextOut(Canvas, -2, MainTexture, EditShortCutSecondary.Left,
291 EditShortCutSecondary.Top - 26, SShortCutSecondary);
292end;
293
294procedure TSettingsDlg.FormShow(Sender: TObject);
295begin
296 Caption := Phrases2.Lookup('ACTIONHEADER_CONFIG');
297 ReloadLanguages;
298 StartDlg.Translator.LanguageListToStrings(ListLanguages.Items);
299 ListLanguages.Font.Color := MainTexture.ColorMark;
300 ListKeyBindings.Font.Color := MainTexture.ColorMark;
301 LoadData;
302 LocalKeyBindings.LoadToStrings(ListKeyBindings.Items);
303 EditShortCutPrimary.Font.Color := MainTexture.ColorMark;
304 EditShortCutSecondary.Font.Color := MainTexture.ColorMark;
305 {$IFDEF DPI}
306 ButtonCustomDpi.Visible := True;
307 ButtonDpiDown.Visible := True;
308 ButtonDpiUp.Visible := True;
309 {$ELSE}
310 ButtonCustomDpi.Visible := False;
311 ButtonDpiDown.Visible := False;
312 ButtonDpiUp.Visible := False;
313 {$ENDIF}
314 UpdateInterface;
315 Gtk2DisableControlStyling(EditShortCutPrimary);
316 Gtk2DisableControlStyling(EditShortCutSecondary);
317end;
318
319procedure TSettingsDlg.ListKeyBindingsKeyDown(Sender: TObject; var Key: Word;
320 Shift: TShiftState);
321begin
322 KeyDown(Key, Shift);
323end;
324
325procedure TSettingsDlg.ListKeyBindingsSelectionChange(Sender: TObject;
326 User: Boolean);
327begin
328 if Assigned(CurrentKeyBinding) then begin
329 CurrentKeyBinding.ShortCut := TextToShortCut(EditShortCutPrimary.Text);
330 CurrentKeyBinding.ShortCut2 := TextToShortCut(EditShortCutSecondary.Text);
331 end;
332
333 if ListKeyBindings.ItemIndex >= 0 then
334 CurrentKeyBinding := LocalKeyBindings[ListKeyBindings.ItemIndex]
335 else CurrentKeyBinding := nil;
336
337 if Assigned(CurrentKeyBinding) then begin
338 if CurrentKeyBinding.ShortCut <> 0 then
339 EditShortCutPrimary.Text := ShortCutToText(CurrentKeyBinding.ShortCut)
340 else EditShortCutPrimary.Text := '';
341 EditShortCutPrimary.Enabled := True;
342 if CurrentKeyBinding.ShortCut2 <> 0 then
343 EditShortCutSecondary.Text := ShortCutToText(CurrentKeyBinding.ShortCut2)
344 else EditShortCutSecondary.Text := '';
345 EditShortCutSecondary.Enabled := True;
346 end else begin
347 EditShortCutPrimary.Text := '';
348 EditShortCutPrimary.Enabled := False;
349 EditShortCutSecondary.Text := '';
350 EditShortCutSecondary.Enabled := False;
351 end;
352end;
353
354procedure TSettingsDlg.ButtonOkClick(Sender: TObject);
355begin
356 SaveData;
357 ModalResult := mrOk;
358end;
359
360procedure TSettingsDlg.ButtonGammaUpClick(Sender: TObject);
361begin
362 if LocalGamma < 150 then begin
363 Inc(LocalGamma);
364 Invalidate;
365 end;
366end;
367
368procedure TSettingsDlg.UpdateShortCutItem;
369begin
370 if Assigned(CurrentKeyBinding) then begin
371 if CurrentKeyBinding.ShortCut > 0 then
372 LocalKeyBindings.RemoveShortCut(CurrentKeyBinding.ShortCut);
373 if CurrentKeyBinding.ShortCut2 > 0 then
374 LocalKeyBindings.RemoveShortCut(CurrentKeyBinding.ShortCut2);
375 CurrentKeyBinding.ShortCut := TextToShortCut(EditShortCutPrimary.Text);
376 CurrentKeyBinding.ShortCut2 := TextToShortCut(EditShortCutSecondary.Text);
377 LocalKeyBindings.LoadToStrings(ListKeyBindings.Items);
378 end;
379end;
380
381function TSettingsDlg.GetLocalCustomDpiEnabled: Boolean;
382begin
383 Result := (ButtonCustomDpi.ButtonIndex and 1) = 1;
384end;
385
386function TSettingsDlg.GetLocalMusicEnabled: Boolean;
387begin
388 Result := (ButtonMusic.ButtonIndex and 1) = 1;
389end;
390
391procedure TSettingsDlg.UpdateInterface;
392begin
393 ButtonDpiUp.Enabled := GetLocalCustomDpiEnabled;
394 ButtonDpiDown.Enabled := GetLocalCustomDpiEnabled;
395 ButtonMusicVolumeDown.Enabled := GetLocalMusicEnabled;
396 ButtonMusicVolumeUp.Enabled := GetLocalMusicEnabled;
397end;
398
399procedure TSettingsDlg.LoadData;
400begin
401 StartDlg.Translator.Language := StartDlg.Translator.Languages.SearchByCode(LocaleCode);
402 StartDlg.Translator.LanguageListToStrings(ListLanguages.Items, False);
403 ListLanguages.ItemIndex := ListLanguages.Items.IndexOfObject(StartDlg.Translator.Language);
404 if ListLanguages.ItemIndex = -1 then ListLanguages.ItemIndex := 0;
405 if FullScreen then ButtonFullscreen.ButtonIndex := 3
406 else ButtonFullscreen.ButtonIndex := 2;
407 if MusicEnabled then ButtonMusic.ButtonIndex := 3
408 else ButtonMusic.ButtonIndex := 2;
409 LocalMusicVolume := Round(MusicVolume * 100);
410 LocalGamma := Gamma;
411 LocalKeyBindings.Assign(KeyBindings.KeyBindings);
412 {$IFDEF DPI}
413 if CustomDpiEnabled then ButtonCustomDpi.ButtonIndex := 3
414 else ButtonCustomDpi.ButtonIndex := 2;
415 LocalDpi := Round(CustomDpi * 100 / 96);
416 {$ENDIF}
417end;
418
419procedure TSettingsDlg.SaveData;
420var
421 NeedRestart: Boolean;
422begin
423 NeedRestart := (Gamma <> LocalGamma) or (CustomDpiEnabled <> GetLocalCustomDpiEnabled) or
424 ((GetLocalCustomDpiEnabled and (LocalDpi <> CustomDpi)));
425 if ListLanguages.ItemIndex <> -1 then begin
426 StartDlg.Translator.Language := TLanguage(ListLanguages.Items.Objects[ListLanguages.ItemIndex]);
427 LocaleCode := StartDlg.Translator.Language.Code;
428 end else begin
429 StartDlg.Translator.Language := nil;
430 LocaleCode := '';
431 end;
432 FullScreen := (ButtonFullscreen.ButtonIndex and 1) = 1;
433 MusicEnabled := GetLocalMusicEnabled;
434 MusicVolume := LocalMusicVolume / 100;
435 Gamma := LocalGamma;
436 ScreenTools.CustomDpiEnabled := CustomDpiEnabled;
437 if NeedRestart then SimpleMessage(SRestartMsg);
438 KeyBindings.KeyBindings.Assign(LocalKeyBindings);
439 {$IFDEF DPI}
440 CustomDpiEnabled := GetLocalCustomDpiEnabled;
441 CustomDpi := Round(LocalDpi * 96 / 100);
442 {$ENDIF}
443end;
444
445end.
446
447
Note: See TracBrowser for help on using the repository browser.