Ignore:
Timestamp:
Oct 5, 2019, 11:16:00 AM (5 years ago)
Author:
chronos
Message:
  • Added: Allow to change interface language in settings form.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormSettings.pas

    r11 r13  
    66
    77uses
    8   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ComCtrls;
     8  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ComCtrls,
     9  ULanguages;
    910
    1011type
     
    1516    ButtonOk: TButton;
    1617    ButtonCancel: TButton;
     18    ComboBoxLanguage: TComboBox;
    1719    Label1: TLabel;
     20    Label2: TLabel;
    1821    TrackBar1: TTrackBar;
    1922    procedure ButtonCancelClick(Sender: TObject);
    2023    procedure ButtonOkClick(Sender: TObject);
     24    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
     25    procedure FormCreate(Sender: TObject);
    2126    procedure FormShow(Sender: TObject);
    2227  private
     
    2934  FormSettings: TFormSettings;
    3035
     36
    3137implementation
    3238
     
    3541uses
    3642  UCore;
     43
     44resourcestring
     45  SLanguageChangeTitle = 'Language change';
     46  SLanguageChangeMessage = 'Interface language was changed. It may require restart of application.';
     47
    3748
    3849{ TFormSettings }
     
    4657begin
    4758  Core.Game.AnimationDuration := TrackBar1.Position;
     59  if ComboBoxLanguage.ItemIndex <> -1 then begin
     60    if (Core.Translator1.Language <> TLanguage(ComboBoxLanguage.Items.Objects[ComboBoxLanguage.ItemIndex])) then
     61      MessageDlg(SLanguageChangeTitle, SLanguageChangeMessage, mtInformation, [mbOk], 0);
     62    Core.Translator1.Language := TLanguage(ComboBoxLanguage.Items.Objects[ComboBoxLanguage.ItemIndex]);
     63  end;
    4864  Close;
     65end;
     66
     67procedure TFormSettings.FormClose(Sender: TObject; var CloseAction: TCloseAction
     68  );
     69begin
     70  Core.PersistentForm1.Save(Self);
     71end;
     72
     73procedure TFormSettings.FormCreate(Sender: TObject);
     74begin
     75  Core.Translator1.LanguageListToStrings(ComboBoxLanguage.Items);
    4976end;
    5077
    5178procedure TFormSettings.FormShow(Sender: TObject);
    5279begin
     80  Core.PersistentForm1.Load(Self);
    5381  TrackBar1.Position := Core.Game.AnimationDuration;
     82  ComboBoxLanguage.ItemIndex := ComboBoxLanguage.Items.IndexOfObject(Core.Translator1.Language);
     83  if ComboBoxLanguage.ItemIndex = -1 then ComboBoxLanguage.ItemIndex := 0;
    5484end;
    5585
Note: See TracChangeset for help on using the changeset viewer.