DEADSOFTWARE

gui: improve prefereces dialog
[d2df-editor.git] / src / editor / f_options.pas
index aebf686a6d997e511dd08db58578fb4b8e4d7f3f..fe05e20f2e5a964b59a9d6b649a34c5079f0aa46 100644 (file)
@@ -7,7 +7,7 @@ interface
 uses
   LCLIntf, LCLType, SysUtils, Variants, Classes,
   Graphics, Controls, Forms, Dialogs, StdCtrls,
-  ExtCtrls, ComCtrls, ActnList, Registry, Math, Types;
+  ExtCtrls, ComCtrls, ActnList, Spin, EditBtn, Registry, Math, Types;
 
 type
 
@@ -16,84 +16,57 @@ type
   TOptionsForm = class (TForm)
     bOK: TButton;
     bCancel: TButton;
+    cbAllowExit: TCheckBox;
+    cbBackup: TCheckBox;
     cbCheckerboard: TCheckBox;
     cbCompress: TCheckBox;
-    cbBackup: TCheckBox;
     cbLanguage: TComboBox;
-    PageControl: TPageControl;
-    TabGeneral: TTabSheet;
-    TabFiles: TTabSheet;
-    TabTesting: TTabSheet;
-    ColorDialog: TColorDialog;
-  // Общие настройки:
+    cbMapOnce: TCheckBox;
+    cbMonstersDM: TCheckBox;
     cbShowDots: TCheckBox;
-    cbShowTexture: TCheckBox;
     cbShowSize: TCheckBox;
-  // Шаги сетки:
+    cbShowTexture: TCheckBox;
+    cbTeamDamage: TCheckBox;
+    cbTwoPlayers: TCheckBox;
+    cbWeaponStay: TCheckBox;
+    ColorButton1: TColorButton;
+    ColorButton2: TColorButton;
+    ColorButton3: TColorButton;
+    edD2DArgs: TEdit;
+    edScore: TEdit;
+    edTime: TEdit;
+    ExeEdit: TFileNameEdit;
+    LabelArgs: TLabel;
+    LabelBack: TLabel;
     LabelGrid: TLabel;
-    eDotStepOne: TEdit;
-    UpDown1: TUpDown;
-    eDotStepTwo: TEdit;
-    UpDown2: TUpDown;
-  // Цвет сетки:
     LabelGridCol: TLabel;
-    sDotColor: TShape;
-    bGrid: TButton;
-  // Цвет фона:
-    LabelBack: TLabel;
-    sBackColor: TShape;
-    bBack: TButton;
-  // Цвет превью:
-    LabelPreview: TLabel;
-    sPreviewColor: TShape;
-    bPreview: TButton;
-  // Масштаб миникарты:
-    LabelMinimap: TLabel;
-    cbScale: TComboBox;
-  // Количество недавно открытых:
-    LabelRecent: TLabel;
-    eRecent: TEdit;
-    UpDown3: TUpDown;
-    LabelLanguage: TLabel;
     LabelGridSize: TLabel;
-    cbDotSize: TComboBox;
-  // Map testing:
+    LabelLanguage: TLabel;
+    LabelMinimap: TLabel;
     LabelPath: TLabel;
-    edD2dexe: TEdit;
-    bChooseD2d: TButton;
-    FindD2dDialog: TOpenDialog;
-    LabelArgs: TLabel;
-    edD2DArgs: TEdit;
+    LabelPreview: TLabel;
+    LabelRecent: TLabel;
+    LabelScore: TLabel;
+    LabelSecs: TLabel;
+    LabelTime: TLabel;
+    PageControl: TPageControl;
     rbCOOP: TRadioButton;
     rbCTF: TRadioButton;
     rbDM: TRadioButton;
     rbTDM: TRadioButton;
-    cbAllowExit: TCheckBox;
-    cbMapOnce: TCheckBox;
-    cbMonstersDM: TCheckBox;
-    cbTeamDamage: TCheckBox;
-    cbTwoPlayers: TCheckBox;
-    cbWeaponStay: TCheckBox;
-    LabelScore: TLabel;
-    LabelSecs: TLabel;
-    edScore: TEdit;
-    LabelTime: TLabel;
-    edTime: TEdit;
-
+    SpinEdit1: TSpinEdit;
+    SpinEdit2: TSpinEdit;
+    SpinEdit3: TSpinEdit;
+    SpinEdit4: TSpinEdit;
+    SpinEdit5: TSpinEdit;
+    TabFiles: TTabSheet;
+    TabGeneral: TTabSheet;
+    TabTesting: TTabSheet;
 
-    procedure bGridClick(Sender: TObject);
     procedure FormShow(Sender: TObject);
     procedure bOKClick(Sender: TObject);
     procedure bCancelClick(Sender: TObject);
-    procedure bBackClick(Sender: TObject);
-    procedure bPreviewClick(Sender: TObject);
     procedure FormCreate(Sender: TObject);
-    procedure bChooseD2dClick(Sender: TObject);
-
-  private
-    { Private declarations }
-  public
-    { Public declarations }
   end;
 
 var
@@ -132,41 +105,23 @@ begin
   end;
 end;
 
-procedure TOptionsForm.bGridClick(Sender: TObject);
-begin
-  if ColorDialog.Execute then
-    sDotColor.Brush.Color := ColorDialog.Color;
-end;
-
-procedure TOptionsForm.bChooseD2dClick(Sender: TObject);
-begin
-  if FindD2dDialog.Execute then
-    edD2dExe.Text := FindD2dDialog.FileName;
-end;
-
 procedure TOptionsForm.FormShow(Sender: TObject);
   var list: TStringList;
 begin
-  sDotColor.Brush.Color := DotColor;
+  // General Tab:
+  ColorButton1.ButtonColor := DotColor;
+  ColorButton2.ButtonColor := BackColor;
+  ColorButton3.ButtonColor := PreviewColor;
+  SpinEdit1.Value := DotStepOne;
+  SpinEdit2.Value := DotStepTwo;
+
   cbShowDots.Checked := DotEnable;
   cbShowTexture.Checked := DrawTexturePanel;
   cbShowSize.Checked := DrawPanelSize;
-  eDotStepOne.Text := IntToStr(DotStepOne);
-  eDotStepTwo.Text := IntToStr(DotStepTwo);
-  sBackColor.Brush.Color := BackColor;
-  sPreviewColor.Brush.Color := PreviewColor;
   cbCheckerboard.Checked := UseCheckerboard;
-  cbCompress.Checked := Compress;
-  cbBackup.Checked := Backup;
-  if Scale = 2 then
-    cbScale.ItemIndex := 1
-  else
-    cbScale.ItemIndex := 0;
-  if DotSize = 2 then
-    cbDotSize.ItemIndex := 1
-  else
-    cbDotSize.ItemIndex := 0;
-  eRecent.Text := IntToStr(RecentCount);
+
+  SpinEdit4.Value := DotSize;
+  SpinEdit5.Value := Scale;
 
   try
     cbLanguage.Items.BeginUpdate;
@@ -180,14 +135,19 @@ begin
     cbLanguage.Items.EndUpdate;
   end;
 
-  if TestGameMode = 'TDM' then
-    rbTDM.Checked := True
-  else if TestGameMode = 'CTF' then
-    rbCTF.Checked := True
-  else if TestGameMode = 'COOP' then
-    rbCOOP.Checked := True
-  else
-    rbDM.Checked := True;
+  // Files Tab:
+  cbCompress.Checked := Compress;
+  cbBackup.Checked   := Backup;
+  SpinEdit3.Value    := RecentCount;
+
+  // Testing Tab:
+  ExeEdit.Text   := TestD2dExe;
+  edD2DArgs.Text := TestD2DArgs;
+
+  rbDM.Checked   := TestGameMode = 'DM';
+  rbTDM.Checked  := TestGameMode = 'TDM';
+  rbCTF.Checked  := TestGameMode = 'CTF';
+  rbCOOP.Checked := TestGameMode = 'COOP';
 
   edTime.Text := TestLimTime;
   edScore.Text := TestLimScore;
@@ -197,20 +157,16 @@ begin
   cbWeaponStay.Checked := TestOptionsWeaponStay;
   cbMonstersDM.Checked := TestOptionsMonstersDM;
   cbMapOnce.Checked := TestMapOnce;
-  edD2dExe.Text := TestD2dExe;
-  edD2DArgs.Text := TestD2DArgs;
 end;
 
 procedure TOptionsForm.bOKClick(Sender: TObject);
 var
   config: TConfig;
   re, n: Integer;
-  d1: Boolean;
   str: String;
 
 begin
-  // General tab
-
+  // General tab:
   if cbLanguage.ItemIndex >= 0 then
   begin
     if cbLanguage.ItemIndex = 0 then str := '' else str := cbLanguage.Items[cbLanguage.ItemIndex];
@@ -221,52 +177,35 @@ begin
     end;
   end;
 
-  DotColor := sDotColor.Brush.Color;
-  DotEnable := cbShowDots.Checked;
+  DotColor     := ColorButton1.ButtonColor;
+  BackColor    := ColorButton2.ButtonColor;
+  PreviewColor := ColorButton3.ButtonColor;
 
-  if DotStep = DotStepOne then
-    d1 := True
-  else
-    d1 := False;
-  DotStepOne := EnsureRange(StrToIntDef(eDotStepOne.Text, 16), 4, 2048);
-  DotStepTwo := EnsureRange(StrToIntDef(eDotStepTwo.Text, 8), 4, 2048);
-  if d1 then
-    DotStep := DotStepOne
-  else
-    DotStep := DotStepTwo;
+  DotEnable  := cbShowDots.Checked;
+  DotStep    := IfThen(DotStep = DotStepOne, SpinEdit1.Value, SpinEdit2.Value);
+  DotStepOne := SpinEdit1.Value;
+  DotStepTwo := SpinEdit2.Value;
 
   DrawTexturePanel := cbShowTexture.Checked;
   DrawPanelSize := cbShowSize.Checked;
-  BackColor := sBackColor.Brush.Color;
-  PreviewColor := sPreviewColor.Brush.Color;
   UseCheckerboard := cbCheckerboard.Checked;
+  DotSize := SpinEdit4.Value;
+  Scale   := SpinEdit5.Value;
 
-  if cbScale.ItemIndex = 1 then
-    Scale := 2
-  else
-    Scale := 1;
-
-  if cbDotSize.ItemIndex = 1 then
-    DotSize := 2
-  else
-    DotSize := 1;
-
-  // Files tab
-
-  re := Min(Max(StrToIntDef(eRecent.Text, 5), 2), 10);
+  // Files tab:
+  re := SpinEdit3.Value;
   Compress := cbCompress.Checked;
   Backup := cbBackup.Checked;
 
-  // Testing tab
+  // Testing tab:
+  TestD2DExe  := ExeEdit.Text;
+  TestD2DArgs := edD2DArgs.Text;
 
-  if rbTDM.Checked then
-    TestGameMode := 'TDM'
-  else if rbCTF.Checked then
-    TestGameMode := 'CTF'
-  else if rbCOOP.Checked then
-    TestGameMode := 'COOP'
-  else
-    TestGameMode := 'DM';
+  TestGameMode := 'DM';
+  if rbTDM.Checked then  TestGameMode := 'TDM';
+  if rbCTF.Checked then  TestGameMode := 'CTF';
+  if rbCOOP.Checked then TestGameMode := 'COOP';
+  if rbDM.Checked then   TestGameMode := 'DM';
 
   TestLimTime := edTime.Text;
   if (not TryStrToInt(TestLimTime, n)) then
@@ -278,16 +217,12 @@ begin
 
   TestOptionsTwoPlayers := cbTwoPlayers.Checked;
   TestOptionsTeamDamage := cbTeamDamage.Checked;
-  TestOptionsAllowExit := cbAllowExit.Checked;
+  TestOptionsAllowExit  := cbAllowExit.Checked;
   TestOptionsWeaponStay := cbWeaponStay.Checked;
   TestOptionsMonstersDM := cbMonstersDM.Checked;
   TestMapOnce := cbMapOnce.Checked;
 
-  TestD2dExe := edD2dExe.Text;
-  TestD2DArgs := edD2DArgs.Text;
-
   // save into config
-
   config := TConfig.CreateFile(CfgFileName);
 
   config.WriteInt('Editor', 'DotColor', DotColor);
@@ -295,13 +230,13 @@ begin
   config.WriteInt('Editor', 'DotStepOne', DotStepOne);
   config.WriteInt('Editor', 'DotStepTwo', DotStepTwo);
   config.WriteInt('Editor', 'DotStep', DotStep);
-  config.WriteInt('Editor', 'DotSize', cbDotSize.ItemIndex);
+  config.WriteInt('Editor', 'DotSize', SpinEdit4.Value);
   config.WriteBool('Editor', 'DrawTexturePanel', DrawTexturePanel);
   config.WriteBool('Editor', 'DrawPanelSize', DrawPanelSize);
   config.WriteInt('Editor', 'BackColor', BackColor);
   config.WriteInt('Editor', 'PreviewColor', PreviewColor);
   config.WriteBool('Editor', 'UseCheckerboard', UseCheckerboard);
-  config.WriteInt('Editor', 'Scale', cbScale.ItemIndex);
+  config.WriteInt('Editor', 'Scale', SpinEdit5.Value);
   config.WriteStr('Editor', 'Language', gLanguage);
 
   config.WriteInt('Editor', 'RecentCount', re);
@@ -342,35 +277,15 @@ begin
   Close();
 end;
 
-procedure TOptionsForm.bBackClick(Sender: TObject);
-begin
-  if ColorDialog.Execute then
-    sBackColor.Brush.Color := ColorDialog.Color;
-end;
-
-procedure TOptionsForm.bPreviewClick(Sender: TObject);
-begin
-  if ColorDialog.Execute then
-    sPreviewColor.Brush.Color := ColorDialog.Color;
-end;
-
 procedure TOptionsForm.FormCreate(Sender: TObject);
 begin
   {$IF DEFINED(DARWIN)}
-    if LowerCase(ExtractFileExt(TestD2dExe)) = '.app' then
-      FindD2dDialog.InitialDir := ExtractFileDir(TestD2dExe)
+    if LowerCase(ExtractFileExt(TestD2DExe)) = '.app' then
+      ExeEdit.InitialDir := ExtractFileDir(TestD2DExe)
     else
-      FindD2dDialog.InitialDir := TestD2dExe;
-    FindD2dDialog.DefaultExt := '.app';
-    FindD2dDialog.Filter := 'Doom 2D Forever.app|*.app|Doom 2D Forever (Unix Executable)|Doom2DF;*';
-  {$ELSEIF DEFINED(WINDOWS)}
-    FindD2dDialog.InitialDir := TestD2dExe;
-    FindD2dDialog.DefaultExt := '.exe';
-    FindD2dDialog.Filter := 'Doom2DF.exe|Doom2DF.exe;*.exe';
+      ExeEdit.InitialDir := TestD2DExe;
   {$ELSE}
-    FindD2dDialog.InitialDir := TestD2dExe;
-    FindD2dDialog.DefaultExt := '';
-    FindD2dDialog.Filter := 'Doom2DF|Doom2DF;*';
+    ExeEdit.InitialDir := TestD2DExe;
   {$ENDIF}
 end;