unit UFormSettings;

{$mode delphi}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  Spin, ComCtrls;

type

  { TFormSettings }

  TFormSettings = class(TForm)
    ButtonOk: TButton;
    ButtonCancel: TButton;
    CheckBoxAutoSaveTurn: TCheckBox;
    CheckBox2: TCheckBox;
    CheckBoxDevelMode: TCheckBox;
    ComboBoxLanguage: TComboBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    PageControl1: TPageControl;
    SpinEditX: TSpinEdit;
    SpinEditY: TSpinEdit;
    SpinEditAnimSpeed: TSpinEdit;
    TabSheetGeneral: TTabSheet;
    TabSheetDebug: TTabSheet;
    procedure CheckBox2Change(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { private declarations }
  public
    procedure Load;
    procedure Save;
  end;

var
  FormSettings: TFormSettings;

implementation

{$R *.lfm}

uses
  UCore, ULanguages;

{ TFormSettings }

procedure TFormSettings.CheckBox2Change(Sender: TObject);
begin
  SpinEditX.Enabled := not CheckBox2.Checked;
  SpinEditY.Enabled := not CheckBox2.Checked;
end;

procedure TFormSettings.FormCreate(Sender: TObject);
begin
  PageControl1.TabIndex := 0;
  Core.CoolTranslator1.TranslateComponentRecursive(Self);
end;

procedure TFormSettings.FormShow(Sender: TObject);
begin
  {$IFDEF DEBUG}
  TabSheetDebug.TabVisible := True;
  {$ELSE}
  TabSheetDebug.TabVisible := False;
  {$ENDIF}
end;

procedure TFormSettings.Load;
begin
  Core.CoolTranslator1.LanguageListToStrings(ComboBoxLanguage.Items);
  ComboBoxLanguage.ItemIndex := ComboBoxLanguage.Items.IndexOfObject(Core.CoolTranslator1.Language);
  if ComboBoxLanguage.ItemIndex = -1 then ComboBoxLanguage.ItemIndex := 0;
  CheckBoxDevelMode.Checked := Core.DevelMode;
  SpinEditAnimSpeed.Value := Core.AnimationSpeed;
  CheckBox2.Checked := Core.ScaleDPI1.AutoDetect;
  SpinEditX.Value := Core.ScaleDPI1.DPI.X;
  SpinEditY.Value := Core.ScaleDPI1.DPI.Y;
  CheckBoxAutoSaveTurn.Checked := Core.AutoSaveEnabled;
end;

procedure TFormSettings.Save;
begin
  if ComboBoxLanguage.ItemIndex <> -1 then
    Core.CoolTranslator1.Language := TLanguage(ComboBoxLanguage.Items.Objects[ComboBoxLanguage.ItemIndex]);
  Core.DevelMode := CheckBoxDevelMode.Checked;
  Core.AnimationSpeed := SpinEditAnimSpeed.Value;
  Core.ScaleDPI1.AutoDetect := CheckBox2.Checked;
  Core.ScaleDPI1.DPI := Point(SpinEditX.Value, SpinEditY.Value);
  Core.AutoSaveEnabled := CheckBoxAutoSaveTurn.Checked;
end;

end.

