Changeset 86 for trunk/Forms


Ignore:
Timestamp:
Jun 7, 2024, 12:47:11 PM (5 months ago)
Author:
chronos
Message:
  • Modified: Remove U prefix from unit names.
  • Modified: Used TFormEx for all forms for code simplification.
  • Fixed: Fullscreen mode switching error.
Location:
trunk/Forms
Files:
18 moved

Legend:

Unmodified
Added
Removed
  • trunk/Forms/FormComputer.lfm

    r85 r86  
    1111  OnCreate = FormCreate
    1212  OnDestroy = FormDestroy
    13   OnShow = FormShow
    14   LCLVersion = '2.0.2.0'
     13  LCLVersion = '3.4.0.0'
    1514  object ButtonStart: TButton
    1615    Left = 40
     
    1918    Width = 113
    2019    Caption = 'Start'
     20    TabOrder = 0
    2121    OnClick = ButtonStartClick
    22     TabOrder = 0
    2322  end
    2423  object ButtonStop: TButton
     
    2928    Caption = 'Stop'
    3029    Enabled = False
     30    TabOrder = 1
    3131    OnClick = ButtonStopClick
    32     TabOrder = 1
    3332  end
    3433  object TrackBar1: TTrackBar
     
    4645    Height = 26
    4746    Top = 76
    48     Width = 127
     47    Width = 126
    4948    Caption = 'Delay per step:'
    5049    ParentColor = False
  • trunk/Forms/FormComputer.pas

    r85 r86  
    1 unit UFormComputer;
    2 
    3 {$mode delphi}
     1unit FormComputer;
    42
    53interface
     
    75uses
    86  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ComCtrls,
    9   UGame, fgl;
     7  Game, Generics.Collections, Generics.Defaults, FormEx;
    108
    119type
     
    2321  end;
    2422
    25   TGameTries = class(TFPGObjectList<TGameTry>)
     23  TGameTries = class(TObjectList<TGameTry>)
     24  end;
     25
     26  { TGameTryComparer }
     27
     28  TGameTryComparer = class(TInterfacedObject, IComparer<TGameTry>)
     29    function Compare(constref Left, Right: TGameTry): Integer; overload;
    2630  end;
    2731
    2832  { TFormComputer }
    2933
    30   TFormComputer = class(TForm)
     34  TFormComputer = class(TFormEx)
    3135    ButtonStart: TButton;
    3236    ButtonStop: TButton;
     
    3842    procedure FormCreate(Sender: TObject);
    3943    procedure FormDestroy(Sender: TObject);
    40     procedure FormShow(Sender: TObject);
    4144  private
    4245    Stop: Boolean;
     
    4649    GameTries4: TGameTries;
    4750    procedure TryAllDirections(GameTries: TGameTries; GameTry: TGameTry);
    48   public
    49 
    50   end;
    51 
    52 var
    53   FormComputer: TFormComputer;
     51  end;
     52
    5453
    5554implementation
     
    5857
    5958uses
    60   UCore;
     59  Core;
    6160
    6261{ TGameTry }
     
    133132end;
    134133
     134{ TGameTryComparer }
     135
     136function TGameTryComparer.Compare(constref Left, Right: TGameTry): Integer;
     137var
     138  ScoreLeft: Double;
     139  ScoreRight: Double;
     140begin
     141  ScoreLeft := Left.GetFitness;
     142  ScoreRight := Right.GetFitness;
     143  if ScoreLeft > ScoreRight then Result := -1
     144  else if ScoreLeft < ScoreRight then Result := 1
     145  else Result := 0;
     146end;
     147
    135148{ TFormComputer }
    136149
     
    139152begin
    140153  ButtonStopClick(Self);
    141   Core.PersistentForm1.Save(Self);
    142154end;
    143155
     
    161173  J: Integer;
    162174  GameTries: TGameTries;
     175  GameTryComparer: TGameTryComparer;
    163176  Delay: Integer;
    164177begin
     
    166179  ButtonStop.Enabled := True;
    167180  Stop := False;
    168   with Core.Game do begin
     181  with Core.Core.Game do begin
    169182    while CanMove and not Stop do begin
    170183      NewTry := TGameTry.Create;
    171       NewTry.Game.Assign(Core.Game);
     184      NewTry.Game.Assign(Core.Core.Game);
    172185      GameTries1.Clear;
    173186      TryAllDirections(GameTries1, NewTry);
     
    184197
    185198      GameTries := GameTries4;
    186       GameTries.Sort(GameCompareScore);
     199      GameTryComparer := TGameTryComparer.Create;
     200      GameTries.Sort(GameTryComparer);
    187201      S := '';
    188202      for I := 0 to GameTries.Count - 1 do begin
     
    221235procedure TFormComputer.FormCreate(Sender: TObject);
    222236begin
    223   Core.Translator1.TranslateComponentRecursive(Self);
    224   Core.ThemeManager1.UseTheme(Self);
    225237  GameTries1 := TGameTries.Create;
    226238  GameTries2 := TGameTries.Create;
     
    235247  FreeAndNil(GameTries3);
    236248  FreeAndNil(GameTries4);
    237 end;
    238 
    239 procedure TFormComputer.FormShow(Sender: TObject);
    240 begin
    241   Core.PersistentForm1.Load(Self);
    242249end;
    243250
  • trunk/Forms/FormHelp.lfm

    r85 r86  
    88  ClientWidth = 480
    99  DesignTimePPI = 144
    10   OnClose = FormClose
    11   OnCreate = FormCreate
    1210  OnShow = FormShow
    13   LCLVersion = '2.0.2.0'
     11  LCLVersion = '3.4.0.0'
    1412  object Memo1: TMemo
    1513    Left = 8
  • trunk/Forms/FormHelp.pas

    r85 r86  
    1 unit UFormHelp;
    2 
    3 {$mode delphi}
     1unit FormHelp;
    42
    53interface
    64
    75uses
    8   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls;
     6  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, FormEx;
    97
    108type
     
    1210  { TFormHelp }
    1311
    14   TFormHelp = class(TForm)
     12  TFormHelp = class(TFormEx)
    1513    Memo1: TMemo;
    16     procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    17     procedure FormCreate(Sender: TObject);
    1814    procedure FormShow(Sender: TObject);
    19   private
    20 
    21   public
    22 
    2315  end;
    2416
    25 var
    26   FormHelp: TFormHelp;
    2717
    2818implementation
     
    3121
    3222uses
    33   UCore;
     23  Core;
    3424
    3525resourcestring
     
    4232{ TFormHelp }
    4333
    44 procedure TFormHelp.FormCreate(Sender: TObject);
    45 begin
    46   Core.Translator1.TranslateComponentRecursive(Self);
    47   Core.ThemeManager1.UseTheme(Self);
    48 end;
    49 
    50 procedure TFormHelp.FormClose(Sender: TObject; var CloseAction: TCloseAction);
    51 begin
    52   Core.PersistentForm1.Save(Self);
    53 end;
    54 
    5534procedure TFormHelp.FormShow(Sender: TObject);
    5635begin
    57   Core.PersistentForm1.Load(Self);
    5836  Memo1.Text := SParagraph1 + LineEnding +
    5937    SParagraph2 + LineEnding +
  • trunk/Forms/FormHistory.lfm

    r85 r86  
    88  ClientWidth = 480
    99  DesignTimePPI = 144
    10   OnClose = FormClose
    1110  OnCreate = FormCreate
    1211  OnDestroy = FormDestroy
    1312  OnShow = FormShow
    14   LCLVersion = '2.0.2.0'
     13  LCLVersion = '3.4.0.0'
    1514  object PaintBox1: TPaintBox
    1615    Left = 0
     
    4544    Interval = 50
    4645    OnTimer = Timer1Timer
    47     left = 108
    48     top = 123
     46    Left = 108
     47    Top = 123
    4948  end
    5049end
  • trunk/Forms/FormHistory.pas

    r85 r86  
    1 unit UFormHistory;
    2 
    3 {$mode delphi}
     1unit FormHistory;
    42
    53interface
    64
    75uses
    8   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, ComCtrls, UGame;
     6  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, ComCtrls,
     7  Game, FormEx;
    98
    109type
     
    1211  { TFormHistory }
    1312
    14   TFormHistory = class(TForm)
     13  TFormHistory = class(TFormEx)
    1514    PaintBox1: TPaintBox;
    1615    Panel1: TPanel;
    1716    Timer1: TTimer;
    1817    TrackBar1: TTrackBar;
    19     procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    2018    procedure FormCreate(Sender: TObject);
    2119    procedure FormDestroy(Sender: TObject);
     
    3129  end;
    3230
    33 var
    34   FormHistory: TFormHistory;
    3531
    3632implementation
     
    3935
    4036uses
    41   UCore;
     37  Core;
    4238
    4339{ TFormHistory }
     
    4541procedure TFormHistory.FormShow(Sender: TObject);
    4642begin
    47   Core.PersistentForm1.Load(Self);
    48   TrackBar1.Max := Core.Game.History.Moves.Count;
    49   Game.Board.Size := Core.Game.Board.Size;
     43  TrackBar1.Max := Core.Core.Game.History.Moves.Count;
     44  Game.Board.Size := Core.Core.Game.Board.Size;
    5045  Redraw;
    5146end;
     
    5954begin
    6055  if RedrawPending then begin
    61     Core.Game.History.GetStep(Game, TrackBar1.Position);
     56    Core.Core.Game.History.GetStep(Game, TrackBar1.Position);
    6257    PaintBox1.Refresh;
    6358    RedrawPending := False;
     
    7772procedure TFormHistory.FormCreate(Sender: TObject);
    7873begin
    79   Core.Translator1.TranslateComponentRecursive(Self);
    80   Core.ThemeManager1.UseTheme(Self);
    8174  Game := TGame.Create;
    8275end;
     
    8780end;
    8881
    89 procedure TFormHistory.FormClose(Sender: TObject; var CloseAction: TCloseAction
    90   );
    91 begin
    92   Core.PersistentForm1.Save(Self);
    93 end;
    94 
    9582end.
    9683
  • trunk/Forms/FormMain.lfm

    r85 r86  
    1616  OnPaint = FormPaint
    1717  OnShow = FormShow
    18   LCLVersion = '2.0.10.0'
     18  LCLVersion = '3.4.0.0'
    1919  object MainMenu1: TMainMenu
    2020    Left = 328
  • trunk/Forms/FormMain.pas

    r85 r86  
    1 unit UFormMain;
    2 
    3 {$mode delphi}{$H+}
     1unit FormMain;
    42
    53interface
     
    75uses
    86  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Menus, Math,
    9   ActnList, ExtCtrls, StdCtrls, UGame, PersistentForm, ApplicationInfo,
    10   LCLType, Syncobjs, DateUtils;
     7  ActnList, ExtCtrls, StdCtrls, Game, PersistentForm, ApplicationInfo,
     8  LCLType, Syncobjs, DateUtils, FormEx;
    119
    1210type
     
    2220  { TFormMain }
    2321
    24   TFormMain = class(TForm)
     22  TFormMain = class(TFormEx)
    2523    MainMenu1: TMainMenu;
    2624    MenuItem1: TMenuItem;
     
    7270  FormMain: TFormMain;
    7371
     72
    7473implementation
    7574
     
    7776
    7877uses
    79   UCore;
     78  Core;
    8079
    8180{ TMoveThread }
     
    9897  KeyDown = 40;
    9998begin
    100   if Core.Game.Running then begin
     99  if Core.Core.Game.Running then begin
    101100    case Key of
    102101      KeyLeft: AddToMoveBuffer(drLeft);
     
    162161  TimeStart := Now;
    163162  {$ENDIF}
    164   Core.Game.Render(Canvas, Point(Width, Height - MainMenu1.Height));
     163  Core.Core.Game.Render(Canvas, Point(Width, Height - MainMenu1.Height));
    165164  {$IFDEF DEBUG}
    166165  DrawDuration := Now - TimeStart;
     
    170169procedure TFormMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
    171170begin
    172   Core.PersistentForm1.Save(Self);
     171  Core.Core.PersistentForm1.Save(Self);
    173172end;
    174173
    175174procedure TFormMain.FormCreate(Sender: TObject);
    176175begin
    177   Core.Translator1.TranslateComponentRecursive(Self);
    178176  MoveBufferLock := TCriticalSection.Create;
    179177  MoveThread := TMoveThread.Create(True);
     
    192190procedure TFormMain.FormShow(Sender: TObject);
    193191begin
    194   Core.PersistentForm1.RegistryContext := Core.ApplicationInfo1.GetRegistryContext;
    195   Core.PersistentForm1.Load(Self);
    196   FullScreen := Core.PersistentForm1.FormFullScreen;
    197   Core.ThemeManager1.UseTheme(Self);
     192  FullScreen := Core.Core.PersistentForm1.FormFullScreen;
     193
    198194  UpdateInterface;
    199   if Core.Game.Board.GetEmptyTilesCount > Core.Game.Board.Size.X * Core.Game.Board.Size.Y -
     195  if Core.Core.Game.Board.GetEmptyTilesCount > Core.Core.Game.Board.Size.X * Core.Core.Game.Board.Size.Y -
    200196    InitialTileCount then
    201     Core.Game.New;
     197    Core.Core.Game.New;
    202198end;
    203199
     
    236232procedure TFormMain.ProcessMoveBuffer;
    237233begin
    238   if not Core.Game.Moving then begin
     234  if not Core.Core.Game.Moving then begin
    239235    MoveBufferLock.Acquire;
    240236    while Length(MoveBuffer) > 0 do begin
    241237      MoveBufferLock.Release;
    242       Core.Game.MoveAllAndUpdate(MoveBuffer[0], Core.Game.AnimationDuration > 0);
     238      Core.Core.Game.MoveAllAndUpdate(MoveBuffer[0], Core.Core.Game.AnimationDuration > 0);
    243239      MoveBufferLock.Acquire;
    244240      if Length(MoveBuffer) > 1 then
     
    254250begin
    255251  FullScreen := not FullScreen;
    256   Core.PersistentForm1.SetFullScreen(FormMain.FullScreen);
     252  Core.Core.PersistentForm1.SetFullScreen(FormMain.FullScreen);
    257253  UpdateInterface;
    258254end;
     
    269265begin
    270266  MenuItemFullScreen.Checked := FullScreen;
    271   MenuItemMovesHistory.Visible := Core.Game.RecordHistory;
     267  MenuItemMovesHistory.Visible := Core.Core.Game.RecordHistory;
    272268  ToolsVisible := False;
    273269  for I := 0 to MenuItemTools.Count - 1 do
  • trunk/Forms/FormNew.lfm

    r85 r86  
    88  ClientWidth = 501
    99  DesignTimePPI = 144
    10   OnClose = FormClose
    1110  OnCreate = FormCreate
    12   OnShow = FormShow
    13   LCLVersion = '2.0.10.0'
     11  LCLVersion = '3.4.0.0'
    1412  object Label1: TLabel
    1513    Left = 16
    16     Height = 24
     14    Height = 26
    1715    Top = 16
    1816    Width = 93
     
    8078  object Label2: TLabel
    8179    Left = 16
    82     Height = 24
     80    Height = 26
    8381    Top = 125
    8482    Width = 75
     
    8886  object ComboBoxSkin: TComboBox
    8987    Left = 173
    90     Height = 37
     88    Height = 38
    9189    Top = 120
    9290    Width = 262
  • trunk/Forms/FormNew.pas

    r85 r86  
    1 unit UFormNew;
    2 
    3 {$mode delphi}{$H+}
     1unit FormNew;
    42
    53interface
     
    75uses
    86  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    9   UGame;
     7  Game, FormEx;
    108
    119type
     
    1311  { TFormNew }
    1412
    15   TFormNew = class(TForm)
     13  TFormNew = class(TFormEx)
    1614    ButtonCancel: TButton;
    1715    ButtonOk: TButton;
     
    2220    Label1: TLabel;
    2321    Label2: TLabel;
    24     procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    2522    procedure FormCreate(Sender: TObject);
    26     procedure FormShow(Sender: TObject);
    27   private
    28 
    2923  public
    3024    procedure Load(Game: TGame);
     
    3226  end;
    3327
    34 var
    35   FormNew: TFormNew;
    3628
    3729implementation
     
    4032
    4133uses
    42   UCore;
     34  Core;
    4335
    4436{ TFormNew }
     
    4840  I: TTileSkin;
    4941begin
    50   Core.Translator1.TranslateComponentRecursive(Self);
    51   Core.ThemeManager1.UseTheme(Self);
    5242  ComboBoxSkin.Items.BeginUpdate;
    5343  try
     
    5848    ComboBoxSkin.Items.EndUpdate;
    5949  end;
    60 end;
    61 
    62 procedure TFormNew.FormShow(Sender: TObject);
    63 begin
    64   Core.PersistentForm1.Load(Self);
    65 end;
    66 
    67 procedure TFormNew.FormClose(Sender: TObject; var CloseAction: TCloseAction);
    68 begin
    69   Core.PersistentForm1.Save(Self);
    7050end;
    7151
  • trunk/Forms/FormSettings.lfm

    r85 r86  
    88  ClientWidth = 480
    99  DesignTimePPI = 144
    10   OnClose = FormClose
    1110  OnCreate = FormCreate
    1211  OnShow = FormShow
    13   LCLVersion = '2.0.4.0'
     12  LCLVersion = '3.4.0.0'
    1413  object Label1: TLabel
    1514    Left = 19
    16     Height = 25
     15    Height = 26
    1716    Top = 24
    18     Width = 158
     17    Width = 170
    1918    Caption = 'Animation duration:'
    2019    ParentColor = False
     
    3736    Anchors = [akLeft, akBottom]
    3837    Caption = 'OK'
     38    TabOrder = 1
    3939    OnClick = ButtonOkClick
    40     TabOrder = 1
    4140  end
    4241  object ButtonCancel: TButton
     
    4746    Anchors = [akLeft, akBottom]
    4847    Caption = 'Cancel'
     48    TabOrder = 2
    4949    OnClick = ButtonCancelClick
    50     TabOrder = 2
    5150  end
    5251  object ComboBoxLanguage: TComboBox
    5352    Left = 208
    54     Height = 33
     53    Height = 42
    5554    Top = 86
    5655    Width = 230
    57     ItemHeight = 25
     56    ItemHeight = 0
    5857    Style = csDropDownList
    5958    TabOrder = 3
     
    6160  object Label2: TLabel
    6261    Left = 19
    63     Height = 25
     62    Height = 26
    6463    Top = 94
    65     Width = 81
     64    Width = 88
    6665    Caption = 'Language:'
    6766    ParentColor = False
     
    6968  object ComboBoxTheme: TComboBox
    7069    Left = 208
    71     Height = 33
     70    Height = 42
    7271    Top = 136
    7372    Width = 230
    74     ItemHeight = 25
     73    ItemHeight = 0
    7574    Style = csDropDownList
    7675    TabOrder = 4
     
    7877  object Label3: TLabel
    7978    Left = 19
    80     Height = 25
     79    Height = 26
    8180    Top = 144
    82     Width = 57
     81    Width = 63
    8382    Caption = 'Theme:'
    8483    ParentColor = False
  • trunk/Forms/FormSettings.pas

    r85 r86  
    1 unit UFormSettings;
    2 
    3 {$mode delphi}
     1unit FormSettings;
    42
    53interface
     
    75uses
    86  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ComCtrls,
    9   Languages, Theme;
     7  Languages, Theme, FormEx;
    108
    119type
     
    1311  { TFormSettings }
    1412
    15   TFormSettings = class(TForm)
     13  TFormSettings = class(TFormEx)
    1614    ButtonOk: TButton;
    1715    ButtonCancel: TButton;
     
    2422    procedure ButtonCancelClick(Sender: TObject);
    2523    procedure ButtonOkClick(Sender: TObject);
    26     procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    2724    procedure FormCreate(Sender: TObject);
    2825    procedure FormShow(Sender: TObject);
    29   private
    30 
    31   public
    32 
    3326  end;
    34 
    35 var
    36   FormSettings: TFormSettings;
    3727
    3828
     
    4232
    4333uses
    44   UCore;
     34  Core;
    4535
    4636resourcestring
    4737  SLanguageChangeTitle = 'Language change';
    4838  SLanguageChangeMessage = 'Interface language was changed. It may require restart of application.';
    49 
    5039
    5140{ TFormSettings }
     
    5847procedure TFormSettings.ButtonOkClick(Sender: TObject);
    5948begin
    60   Core.Game.AnimationDuration := TrackBar1.Position;
     49  Core.Core.Game.AnimationDuration := TrackBar1.Position;
    6150  if ComboBoxLanguage.ItemIndex <> -1 then begin
    62     if (Core.Translator1.Language <> TLanguage(ComboBoxLanguage.Items.Objects[ComboBoxLanguage.ItemIndex])) then
     51    if (Core.Core.Translator1.Language <> TLanguage(ComboBoxLanguage.Items.Objects[ComboBoxLanguage.ItemIndex])) then
    6352      MessageDlg(SLanguageChangeTitle, SLanguageChangeMessage, mtInformation, [mbOk], 0);
    64     Core.Translator1.Language := TLanguage(ComboBoxLanguage.Items.Objects[ComboBoxLanguage.ItemIndex]);
     53    Core.Core.Translator1.Language := TLanguage(ComboBoxLanguage.Items.Objects[ComboBoxLanguage.ItemIndex]);
    6554  end;
    6655  if ComboBoxTheme.ItemIndex <> -1 then
    67     Core.ThemeManager1.Theme := TTheme(ComboBoxTheme.Items.Objects[ComboBoxTheme.ItemIndex]);
     56    Core.Core.ThemeManager1.Theme := TTheme(ComboBoxTheme.Items.Objects[ComboBoxTheme.ItemIndex]);
    6857  ModalResult := mrOk;
    69 end;
    70 
    71 procedure TFormSettings.FormClose(Sender: TObject; var CloseAction: TCloseAction
    72   );
    73 begin
    74   Core.PersistentForm1.Save(Self);
    7558end;
    7659
    7760procedure TFormSettings.FormCreate(Sender: TObject);
    7861begin
    79   Core.Translator1.TranslateComponentRecursive(Self);
    80   Core.Translator1.LanguageListToStrings(ComboBoxLanguage.Items);
    81   Core.ThemeManager1.UseTheme(Self);
    82   Core.ThemeManager1.Themes.LoadToStrings(ComboBoxTheme.Items);
     62  Core.Core.Translator1.LanguageListToStrings(ComboBoxLanguage.Items);
     63  Core.Core.ThemeManager1.Themes.LoadToStrings(ComboBoxTheme.Items);
    8364end;
    8465
    8566procedure TFormSettings.FormShow(Sender: TObject);
    8667begin
    87   Core.PersistentForm1.Load(Self);
    88   TrackBar1.Position := Core.Game.AnimationDuration;
    89   ComboBoxLanguage.ItemIndex := ComboBoxLanguage.Items.IndexOfObject(Core.Translator1.Language);
     68  TrackBar1.Position := Core.Core.Game.AnimationDuration;
     69  ComboBoxLanguage.ItemIndex := ComboBoxLanguage.Items.IndexOfObject(Core.Core.Translator1.Language);
    9070  if ComboBoxLanguage.ItemIndex = -1 then ComboBoxLanguage.ItemIndex := 0;
    91   ComboBoxTheme.ItemIndex := ComboBoxTheme.Items.IndexOfObject(Core.ThemeManager1.Theme);
     71  ComboBoxTheme.ItemIndex := ComboBoxTheme.Items.IndexOfObject(Core.Core.ThemeManager1.Theme);
    9272  if ComboBoxTheme.ItemIndex = -1 then ComboBoxTheme.ItemIndex := 0;
    9373end;
Note: See TracChangeset for help on using the changeset viewer.