Changeset 121


Ignore:
Timestamp:
Oct 26, 2022, 3:12:02 PM (2 years ago)
Author:
chronos
Message:
  • Modifed: Made TEngine class TComponent and to be independent from FormMain.
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/BigMetro.lpi

    r118 r121  
    161161        <IsPartOfProject Value="True"/>
    162162        <ComponentName Value="Core"/>
     163        <HasResources Value="True"/>
    163164        <ResourceBaseClass Value="DataModule"/>
    164165      </Unit14>
  • trunk/Forms/UFormMain.pas

    r118 r121  
    3838  private
    3939    Initialized: Boolean;
     40    procedure FullScreenChangeExecute(Sender: TObject; Active: Boolean);
     41    procedure ExitExecute(Sender: TObject);
    4042    procedure LoadConfig;
    4143    procedure SaveConfig;
    4244    procedure LoadGraphicAssets;
    43     procedure DarkModeChange(Sender: TObject);
     45    procedure DarkModeChangeExecute(Sender: TObject);
    4446    procedure CopyImage(DestBmp: TBitmap; SourceBmp: TBitmap; Grayed: Boolean = False);
    4547  public
    46     FullScreen: Boolean;
    4748    Engine: TEngine;
    4849    procedure EraseBackground(DC: HDC); override;
     
    8182  {$ENDIF}
    8283
    83   Engine := TEngine.Create;
     84  Engine := TEngine.Create(nil);
    8485  Engine.RegistryContext := ApplicationInfo1.GetRegistryContext;
    8586  Engine.Translator := Core.Translator1;
     87  Engine.OnFullScreenChange := FullScreenChangeExecute;
     88  Engine.OnExit := ExitExecute;
    8689  LoadConfig;
    8790  // Load cities after language core is loaded to have city names translated
     
    9295end;
    9396
    94 procedure TFormMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
    95 begin
    96   Core.PersistentForm1.Save(Self);
    97 end;
    98 
    9997procedure TFormMain.FormDestroy(Sender: TObject);
    10098begin
    10199  SaveConfig;
    102100  FreeAndNil(Engine);
     101end;
     102
     103procedure TFormMain.FormShow(Sender: TObject);
     104begin
     105  if not Initialized then begin
     106    Initialized := True;
     107    Core.PersistentForm1.RegistryContext := ApplicationInfo1.GetRegistryContext;
     108    Core.PersistentForm1.Load(Self, False, True);
     109    Engine.FullScreen := Core.PersistentForm1.FormFullScreen;
     110    Engine.InitMenus;
     111    Engine.OnDarkModeChange := DarkModeChangeExecute;
     112    Engine.Map.Size := Point(PaintBox1.Width, PaintBox1.Height);
     113    Engine.View.DestRect := Rect(0, 0, PaintBox1.Width, PaintBox1.Height);
     114    Engine.MainMenu;
     115    LoadGraphicAssets;
     116  end;
     117end;
     118
     119procedure TFormMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
     120begin
     121  Core.PersistentForm1.Save(Self);
    103122end;
    104123
     
    120139begin
    121140  if Key = KeyF11 then begin
    122     FullScreen := not FullScreen;
    123     Core.PersistentForm1.SetFullScreen(FormMain.FullScreen);
     141    Engine.FullScreen := not Engine.FullScreen;
    124142  end else
    125143{$IFDEF DEBUG}
     
    141159end;
    142160
    143 procedure TFormMain.FormShow(Sender: TObject);
    144 begin
    145   if not Initialized then begin
    146     Initialized := True;
    147     Core.PersistentForm1.RegistryContext := ApplicationInfo1.GetRegistryContext;
    148     Core.PersistentForm1.Load(Self, False, True);
    149     FullScreen := Core.PersistentForm1.FormFullScreen;
    150     Engine.InitMenus;
    151     Engine.OnDarkModeChange := DarkModeChange;
    152     Engine.Map.Size := Point(PaintBox1.Width, PaintBox1.Height);
    153     Engine.View.DestRect := Rect(0, 0, PaintBox1.Width, PaintBox1.Height);
    154     Engine.MainMenu;
    155     LoadGraphicAssets;
    156   end;
    157 end;
    158 
    159161procedure TFormMain.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
    160162  Shift: TShiftState; X, Y: Integer);
     
    214216  FormatSettings.ShortDayNames[6] := SFridayShort;
    215217  FormatSettings.ShortDayNames[7] := SSaturdayShort;
     218end;
     219
     220procedure TFormMain.FullScreenChangeExecute(Sender: TObject; Active: Boolean);
     221begin
     222  Core.PersistentForm1.SetFullScreen(Active);
     223end;
     224
     225procedure TFormMain.ExitExecute(Sender: TObject);
     226begin
     227  Close;
    216228end;
    217229
     
    306318end;
    307319
    308 procedure TFormMain.DarkModeChange(Sender: TObject);
     320procedure TFormMain.DarkModeChangeExecute(Sender: TObject);
    309321begin
    310322  LoadGraphicAssets;
  • trunk/Packages/Common/Languages/UDataFile.cs.po

    r118 r121  
    1919msgid "Data file"
    2020msgstr "Datový soubor"
     21
  • trunk/Packages/Common/Languages/UTestCase.cs.po

    r118 r121  
    2323msgid "Passed"
    2424msgstr "Prošlo"
     25
  • trunk/UEngine.pas

    r119 r121  
    157157    miFastTrain);
    158158  TMetroImprovementSet = set of TMetroImprovement;
     159  TFullScrenChangeEvent = procedure (Sender: TObject; Active: Boolean) of object;
    159160
    160161  { TEngine }
    161162
    162   TEngine = class
     163  TEngine = class(TComponent)
    163164  private
    164165    FDarkMode: Boolean;
     166    FFullScreen: Boolean;
    165167    FOnDarkModeChange: TNotifyEvent;
     168    FOnExit: TNotifyEvent;
     169    FOnFullScreenChange: TFullScrenChangeEvent;
    166170    FState: TGameState;
    167171    FTranslator: TTranslator;
     
    219223      UpdatedShape: TStationShape; Distance: Integer);
    220224    procedure SetDarkMode(AValue: Boolean);
     225    procedure SetFullScreen(AValue: Boolean);
    221226    procedure SetState(AValue: TGameState);
    222227    procedure TrainsMovement;
     
    304309    procedure LoadFromRegistry;
    305310    procedure SaveToRegistry;
    306     constructor Create;
     311    constructor Create(AOwner: TComponent); override;
    307312    destructor Destroy; override;
    308313    procedure Tick;
     
    313318  published
    314319    property DarkMode: Boolean read FDarkMode write SetDarkMode;
     320    property FullScreen: Boolean read FFullScreen write SetFullScreen;
    315321    property Translator: TTranslator read FTranslator write FTranslator;
    316322    property OnDarkModeChange: TNotifyEvent read FOnDarkModeChange
    317323      write FOnDarkModeChange;
     324    property OnFullScreenChange: TFullScrenChangeEvent read FOnFullScreenChange
     325      write FOnFullScreenChange;
     326    property OnExit: TNotifyEvent read FOnExit write FOnExit;
    318327  end;
    319328
     
    349358
    350359uses
    351   UFormMain, ULanguages;
     360  ULanguages;
    352361
    353362resourcestring
     
    14041413end;
    14051414
     1415procedure TEngine.SetFullScreen(AValue: Boolean);
     1416begin
     1417  if FFullScreen = AValue then Exit;
     1418  FFullScreen := AValue;
     1419  if Assigned(FOnFullScreenChange) then
     1420    FOnFullScreenChange(Self, FFullScreen);
     1421end;
     1422
    14061423procedure TEngine.SetState(AValue: TGameState);
    14071424begin
     
    16601677procedure TEngine.MenuItemExit(Sender: TObject);
    16611678begin
    1662   FormMain.Close;
     1679  if Assigned(FOnExit) then FOnExit(Self);
    16631680end;
    16641681
     
    17391756      BackgroundColor := Colors.MenuItemBackground;
    17401757      BackgroundSelectedColor := Colors.MenuItemBackgroundSelected;
    1741       Checked := FormMain.FullScreen;
     1758      Checked := FullScreen;
    17421759    end;
    17431760    with AddButton(SBack, MenuItemBack) do begin
     
    18831900procedure TEngine.FullScreenChanged(Sender: TObject);
    18841901begin
    1885   FormMain.FullScreen := TMenuItemCheckBox(Sender).Checked;
    1886   with TPersistentForm.Create(nil) do
    1887   try
    1888     Form := FormMain;
    1889     SetFullScreen(FormMain.FullScreen);
    1890   finally
    1891     Free;
    1892   end;
     1902  FullScreen := TMenuItemCheckBox(Sender).Checked;
    18931903end;
    18941904
     
    33623372end;
    33633373
    3364 constructor TEngine.Create;
    3365 begin
     3374constructor TEngine.Create(AOwner: TComponent);
     3375begin
     3376  inherited;
    33663377  ImprovementImageSize := ScaleX(64, 96);
    33673378  IconSize := ScaleX(32, 96);
  • trunk/UTestCases.pas

    r118 r121  
    6565begin
    6666  inherited;
    67   Engine := TEngine.Create;
     67  Engine := TEngine.Create(nil);
    6868end;
    6969
Note: See TracChangeset for help on using the changeset viewer.