DEADSOFTWARE

gui: improve prefereces dialog
[d2df-editor.git] / src / editor / f_options.pas
index 91cc695d1e442dc03753e43b1de29ff63e8443a9..fe05e20f2e5a964b59a9d6b649a34c5079f0aa46 100644 (file)
@@ -7,7 +7,7 @@ interface
 uses
   LCLIntf, LCLType, SysUtils, Variants, Classes,
   Graphics, Controls, Forms, Dialogs, StdCtrls,
-  ExtCtrls, ComCtrls, Registry, Math;
+  ExtCtrls, ComCtrls, ActnList, Spin, EditBtn, Registry, Math, Types;
 
 type
 
@@ -16,57 +16,57 @@ type
   TOptionsForm = class (TForm)
     bOK: TButton;
     bCancel: TButton;
+    cbAllowExit: TCheckBox;
+    cbBackup: TCheckBox;
     cbCheckerboard: TCheckBox;
     cbCompress: TCheckBox;
-    cbBackup: TCheckBox;
-    ColorDialog: TColorDialog;
-    GroupBox1: TGroupBox;
-  // Общие настройки:
+    cbLanguage: TComboBox;
+    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;
-  // Масштаб миникарты:
+    LabelGridSize: TLabel;
+    LabelLanguage: TLabel;
     LabelMinimap: TLabel;
-    cbScale: TComboBox;
-  // Количество недавно открытых:
+    LabelPath: TLabel;
+    LabelPreview: TLabel;
     LabelRecent: TLabel;
-    eRecent: TEdit;
-    UpDown3: TUpDown;
-    LabelLanguage: TLabel;
-    rbRussian: TRadioButton;
-    rbEnglish: TRadioButton;
-    LabelGridSize: TLabel;
-    cbDotSize: TComboBox;
-
-    procedure bGridClick(Sender: TObject);
-    procedure FormActivate(Sender: TObject);
+    LabelScore: TLabel;
+    LabelSecs: TLabel;
+    LabelTime: TLabel;
+    PageControl: TPageControl;
+    rbCOOP: TRadioButton;
+    rbCTF: TRadioButton;
+    rbDM: TRadioButton;
+    rbTDM: TRadioButton;
+    SpinEdit1: TSpinEdit;
+    SpinEdit2: TSpinEdit;
+    SpinEdit3: TSpinEdit;
+    SpinEdit4: TSpinEdit;
+    SpinEdit5: TSpinEdit;
+    TabFiles: TTabSheet;
+    TabGeneral: TTabSheet;
+    TabTesting: TTabSheet;
+
+    procedure FormShow(Sender: TObject);
     procedure bOKClick(Sender: TObject);
     procedure bCancelClick(Sender: TObject);
-    procedure bBackClick(Sender: TObject);
-    procedure bPreviewClick(Sender: TObject);
-
-  private
-    { Private declarations }
-  public
-    { Public declarations }
+    procedure FormCreate(Sender: TObject);
   end;
 
 var
@@ -77,7 +77,7 @@ procedure RegisterFileType(ext: String; FileName: String);
 implementation
 
 uses
-  f_main, StdConvs, CONFIG, g_language, g_resources;
+  LazFileUtils, f_main, StdConvs, CONFIG, g_language, g_resources, g_options;
 
 {$R *.lfm}
 
@@ -105,134 +105,169 @@ begin
   end;
 end;
 
-procedure TOptionsForm.bGridClick(Sender: TObject);
+procedure TOptionsForm.FormShow(Sender: TObject);
+  var list: TStringList;
 begin
-  if ColorDialog.Execute then
-    sDotColor.Brush.Color := ColorDialog.Color;
-end;
+  // General Tab:
+  ColorButton1.ButtonColor := DotColor;
+  ColorButton2.ButtonColor := BackColor;
+  ColorButton3.ButtonColor := PreviewColor;
+  SpinEdit1.Value := DotStepOne;
+  SpinEdit2.Value := DotStepTwo;
 
-procedure TOptionsForm.FormActivate(Sender: TObject);
-begin
-  sDotColor.Brush.Color := DotColor;
   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;
+
+  SpinEdit4.Value := DotSize;
+  SpinEdit5.Value := Scale;
+
+  try
+    cbLanguage.Items.BeginUpdate;
+    cbLanguage.Items.Clear;
+    cbLanguage.Items.Add(MsgLabEsLanguageAuto);
+    list := g_Language_GetList();
+    cbLanguage.Items.AddStrings(list);
+    list.Free();
+    cbLanguage.ItemIndex := IfThen(gLanguage = '', 0, cbLanguage.Items.IndexOf(gLanguage));
+  finally
+    cbLanguage.Items.EndUpdate;
+  end;
+
+  // Files Tab:
   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);
-
-// Язык:
-  if gLanguage = LANGUAGE_RUSSIAN then
-    begin
-      rbRussian.Checked := True;
-      rbEnglish.Checked := False;
-    end
-  else
-    begin
-      rbRussian.Checked := False;
-      rbEnglish.Checked := True;
-    end;
+  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;
+  cbTwoPlayers.Checked := TestOptionsTwoPlayers;
+  cbTeamDamage.Checked := TestOptionsTeamDamage;
+  cbAllowExit.Checked := TestOptionsAllowExit;
+  cbWeaponStay.Checked := TestOptionsWeaponStay;
+  cbMonstersDM.Checked := TestOptionsMonstersDM;
+  cbMapOnce.Checked := TestMapOnce;
 end;
 
 procedure TOptionsForm.bOKClick(Sender: TObject);
 var
   config: TConfig;
-  re: Integer;
-  d1: Boolean;
+  re, n: Integer;
   str: String;
 
 begin
-  re := StrToIntDef(eRecent.Text, 5);
-  if re < 2 then
-    re := 2;
-  if re > 10 then
-    re := 10;
-
-  if rbRussian.Checked then
-    str := LANGUAGE_RUSSIAN
-  else
-    str := LANGUAGE_ENGLISH;
-
-// Нужно сменить язык:
-  if gLanguage <> str then
+  // General tab:
+  if cbLanguage.ItemIndex >= 0 then
   begin
-    gLanguage := str;
-    //e_WriteLog('Read language file', MSG_NOTIFY);
-    //g_Language_Load(EditorDir+'\data\'+gLanguage+LANGUAGE_FILE_NAME);
-    g_Language_Set(gLanguage);
+    if cbLanguage.ItemIndex = 0 then str := '' else str := cbLanguage.Items[cbLanguage.ItemIndex];
+    if (str = '') or (gLanguage <> str) then
+    begin
+      gLanguage := str;
+      g_Language_Set(gLanguage);
+    end;
   end;
-  
-  DotColor := sDotColor.Brush.Color;
-  DotEnable := cbShowDots.Checked;
-
-  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;
+
+  DotColor     := ColorButton1.ButtonColor;
+  BackColor    := ColorButton2.ButtonColor;
+  PreviewColor := ColorButton3.ButtonColor;
+
+  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;
+
+  // Files tab:
+  re := SpinEdit3.Value;
   Compress := cbCompress.Checked;
   Backup := cbBackup.Checked;
 
-  if cbScale.ItemIndex = 1 then
-    Scale := 2
-  else
-    Scale := 1;
+  // Testing tab:
+  TestD2DExe  := ExeEdit.Text;
+  TestD2DArgs := edD2DArgs.Text;
+
+  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';
 
-  if cbDotSize.ItemIndex = 1 then
-    DotSize := 2
-  else
-    DotSize := 1;
+  TestLimTime := edTime.Text;
+  if (not TryStrToInt(TestLimTime, n)) then
+    TestLimTime := '0';
 
-  config := TConfig.CreateFile(EditorDir+'Editor.cfg');
+  TestLimScore := edScore.Text;
+  if (not TryStrToInt(TestLimScore, n)) then
+    TestLimScore := '0';
+
+  TestOptionsTwoPlayers := cbTwoPlayers.Checked;
+  TestOptionsTeamDamage := cbTeamDamage.Checked;
+  TestOptionsAllowExit  := cbAllowExit.Checked;
+  TestOptionsWeaponStay := cbWeaponStay.Checked;
+  TestOptionsMonstersDM := cbMonstersDM.Checked;
+  TestMapOnce := cbMapOnce.Checked;
+
+  // save into config
+  config := TConfig.CreateFile(CfgFileName);
 
   config.WriteInt('Editor', 'DotColor', DotColor);
   config.WriteBool('Editor', 'DotEnable', DotEnable);
   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', 'RecentCount', re);
+  config.WriteInt('Editor', 'Scale', SpinEdit5.Value);
   config.WriteStr('Editor', 'Language', gLanguage);
+
+  config.WriteInt('Editor', 'RecentCount', re);
   config.WriteBool('Editor', 'Compress', Compress);
   config.WriteBool('Editor', 'Backup', Backup);
 
+  config.WriteStr('TestRun', 'GameMode', TestGameMode);
+  config.WriteStr('TestRun', 'LimTime', TestLimTime);
+  config.WriteStr('TestRun', 'LimScore', TestLimScore);
+  config.WriteBool('TestRun', 'TwoPlayers', TestOptionsTwoPlayers);
+  config.WriteBool('TestRun', 'TeamDamage', TestOptionsTeamDamage);
+  config.WriteBool('TestRun', 'AllowExit', TestOptionsAllowExit);
+  config.WriteBool('TestRun', 'WeaponStay', TestOptionsWeaponStay);
+  config.WriteBool('TestRun', 'MonstersDM', TestOptionsMonstersDM);
+  config.WriteBool('TestRun', 'MapOnce', TestMapOnce);
+  {$IF DEFINED(DARWIN)}
+    config.WriteStr('TestRun', 'ExeDrawin', TestD2dExe);
+  {$ELSEIF DEFINED(WINDOWS)}
+    config.WriteStr('TestRun', 'ExeWindows', TestD2dExe);
+  {$ELSE}
+    config.WriteStr('TestRun', 'ExeUnix', TestD2dExe);
+  {$ENDIF}
+  config.WriteStr('TestRun', 'Args', TestD2DArgs);
+
   if RecentCount <> re then
   begin
     RecentCount := re;
     MainForm.RefreshRecentMenu();
   end;
 
-  config.SaveFile(EditorDir+'Editor.cfg');
+  config.SaveFile(CfgFileName);
   config.Free();
   Close();
 end;
@@ -242,16 +277,16 @@ begin
   Close();
 end;
 
-procedure TOptionsForm.bBackClick(Sender: TObject);
-begin
-  if ColorDialog.Execute then
-    sBackColor.Brush.Color := ColorDialog.Color;
-end;
-
-procedure TOptionsForm.bPreviewClick(Sender: TObject);
+procedure TOptionsForm.FormCreate(Sender: TObject);
 begin
-  if ColorDialog.Execute then
-    sPreviewColor.Brush.Color := ColorDialog.Color;
+  {$IF DEFINED(DARWIN)}
+    if LowerCase(ExtractFileExt(TestD2DExe)) = '.app' then
+      ExeEdit.InitialDir := ExtractFileDir(TestD2DExe)
+    else
+      ExeEdit.InitialDir := TestD2DExe;
+  {$ELSE}
+    ExeEdit.InitialDir := TestD2DExe;
+  {$ENDIF}
 end;
 
 end.