Changeset 121 for trunk/Forms


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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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;
Note: See TracChangeset for help on using the changeset viewer.