Changeset 317 for trunk/Core.pas


Ignore:
Timestamp:
Jun 21, 2024, 12:44:53 PM (5 months ago)
Author:
chronos
Message:
  • Modified: Remove U prefix from unit names.
  • Modified: Use TFormEx for all forms for code simplification.
File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/Core.pas

    r316 r317  
    1 unit UCore;
     1unit Core;
    22
    33interface
     
    55uses
    66  Classes, SysUtils, XMLConf, FileUtil, ActnList, Controls, Dialogs, Forms,
    7   UGame, ApplicationInfo, PersistentForm, ScaleDPI, Translator, DOM,
    8   RegistryEx, LastOpenedList, Theme, Registry, Menus,
    9   UFormClient, UPlayer, UGameServer, UGameClient, Generics.Collections,
    10   UServerList, UGameSystem, Graphics, UUnit;
     7  Game, ApplicationInfo, PersistentForm, ScaleDPI, Translator, DOM,
     8  RegistryEx, LastOpenedList, Theme, Registry, Menus, FormCharts, FormMain,
     9  FormClient, Player, GameServer, GameClient, Generics.Collections,
     10  ServerList, GameSystem, Graphics, &Unit;
    1111
    1212type
     
    3434    AGameNew: TAction;
    3535    AGameRestart: TAction;
    36     CoolTranslator1: TTranslator;
     36    Translator1: TTranslator;
    3737    ImageListLarge: TImageList;
    3838    ImageListSmall: TImageList;
    3939    LastOpenedList1: TLastOpenedList;
    4040    OpenDialog1: TOpenDialog;
    41     PersistentForm: TPersistentForm;
     41    PersistentForm1: TPersistentForm;
    4242    SaveDialog1: TSaveDialog;
    4343    ScaleDPI1: TScaleDPI;
     
    6161    procedure AShowUnitMovesExecute(Sender: TObject);
    6262    procedure AToggleFogOfWarExecute(Sender: TObject);
    63     procedure CoolTranslator1Translate(Sender: TObject);
     63    procedure Translator1Translate(Sender: TObject);
    6464    procedure DataModuleCreate(Sender: TObject);
    6565    procedure DataModuleDestroy(Sender: TObject);
     
    9999    AutoSaveEnabled: Boolean;
    100100    ReopenLastFile: Boolean;
    101     FormClients: TObjectList<TFormClient>;
     101    FormClients: TFormClients;
    102102    LocalClients: TClients;
    103103    ServerList: TServerList;
    104104    GameSystems: TGameSystems;
     105    FormMain: TFormMain;
    105106    procedure ReopenGameOnInit;
    106107    procedure LoadConfig;
     
    128129
    129130uses
    130   UFormMain, UFormNew, UFormSettings, UClientAI, UFormKeyShortcuts, Common,
    131   UFormHelp, UFormCharts, UFormUnitMoves, UFormPlayersStats, UClientGUI, FormAbout;
     131  FormNew, FormSettings, ClientAI, FormKeyShortcuts, Common, FormEx,
     132  FormHelp, FormUnitMoves, FormPlayersStats, ClientGUI, FormAbout;
    132133
    133134const
     
    145146  SMissingServerClientForPlayer = 'Server client for current player not found.';
    146147
     148procedure Translate;
     149begin
     150  Game.InitStrings;
     151end;
    147152
    148153{ TCore }
     
    196201begin
    197202  RegistryContext := TRegistryContext.Create(HKEY_CURRENT_USER, DefaultRegKey);
    198   PersistentForm.RegistryContext := RegistryContext;
     203  PersistentForm1.RegistryContext := RegistryContext;
    199204  XMLConfig1.Filename := GetAppConfigDir(False) + 'Config.xml';
    200205
     
    205210  AutoSaveEnabled := XMLConfig1.GetValue('AutoSave', True);
    206211  ReopenLastFile := XMLConfig1.GetValue('ReopenLastFile', True);
    207   CoolTranslator1.Language := CoolTranslator1.Languages.SearchByCode(String(XMLConfig1.GetValue('Language', '')));
     212  Translator1.Language := Translator1.Languages.SearchByCode(String(XMLConfig1.GetValue('Language', '')));
    208213  ScaleDPI1.DPI := Point(XMLConfig1.GetValue('DPIX', 96), XMLConfig1.GetValue('DPIY', 96));
    209214  ScaleDPI1.AutoDetect := XMLConfig1.GetValue('DPIAuto', True);
     
    215220procedure TCore.SaveConfig;
    216221begin
    217   XMLConfig1.SetValue('Language', WideString(CoolTranslator1.Language.Code));
     222  XMLConfig1.SetValue('Language', WideString(Translator1.Language.Code));
    218223  XMLConfig1.SetValue('Theme', WideString(ThemeManager1.Theme.Name));
    219224  LastOpenedList1.SaveToXMLConfig(XMLConfig1, 'RecentFiles');
     
    277282begin
    278283  FirstHuman := Game.Players.GetFirstHuman;
    279   if Assigned(FirstHuman) then FormClient.Client := TClientGUI(LocalClients.SearchPlayer(FirstHuman))
     284  if Assigned(FirstHuman) then FormMain.FormClient.Client := TClientGUI(LocalClients.SearchPlayer(FirstHuman))
    280285    else begin
    281       FormClient.Client := TClientGUI(LocalClients.New(SSpectator));
    282       FormClient.Client.LocalServer := Server;
    283       FormClient.Client.ConnectType := ctLocal;
    284       FormClient.Client.Active := True;
    285       FormClient.AZoomAll.Execute;
     286      FormMain.FormClient.Client := TClientGUI(LocalClients.New(SSpectator));
     287      FormMain.FormClient.Client.LocalServer := Server;
     288      FormMain.FormClient.Client.ConnectType := ctLocal;
     289      FormMain.FormClient.Client.Active := True;
     290      FormMain.FormClient.AZoomAll.Execute;
    286291    end;
    287292end;
     
    339344var
    340345  NewServer: TServer;
     346  FormNew: TFormNew;
    341347begin
    342348  FormNew := TFormNew.Create(nil);
     
    394400
    395401procedure TCore.AHelpExecute(Sender: TObject);
     402var
     403  FormHelp: TFormHelp;
    396404begin
    397405  FormHelp := TFormHelp.Create(Self);
     
    410418procedure TCore.APlayersStatsExecute(Sender: TObject);
    411419begin
    412   if not Assigned(FormPlayersStats) then
    413     FormPlayersStats := TFormPlayersStats.Create(nil);
    414   FormPlayersStats.Show;
     420  if not Assigned(FormMain.FormPlayersStats) then
     421    FormMain.FormPlayersStats := TFormPlayersStats.Create(nil);
     422  FormMain.FormPlayersStats.Show;
    415423end;
    416424
    417425procedure TCore.ASettingsExecute(Sender: TObject);
     426var
     427  FormSettings: TFormSettings;
    418428begin
    419429  FormSettings := TFormSettings.Create(nil);
     
    434444procedure TCore.AShowChartsExecute(Sender: TObject);
    435445begin
    436   if not Assigned(FormCharts) then FormCharts := TFormCharts.Create(nil);
    437   FormCharts.Show;
     446  if not Assigned(FormMain.FormCharts) then
     447    FormMain.FormCharts := TFormCharts.Create(nil);
     448  FormMain.FormCharts.Show;
    438449end;
    439450
    440451procedure TCore.AShowKeyShortcutsExecute(Sender: TObject);
    441452begin
    442   if not Assigned(FormKeyShortcuts) then FormKeyShortcuts := TFormKeyShortcuts.Create(nil);
    443   FormKeyShortcuts.Show;
     453  if not Assigned(FormMain.FormKeyShortcuts) then FormMain.FormKeyShortcuts := TFormKeyShortcuts.Create(nil);
     454  FormMain.FormKeyShortcuts.Show;
    444455end;
    445456
    446457procedure TCore.AShowUnitMovesExecute(Sender: TObject);
    447458begin
    448   if not Assigned(FormUnitMoves) then FormUnitMoves := TFormUnitMoves.Create(nil);
    449   FormUnitMoves.Show;
     459  if not Assigned(FormMain.FormUnitMoves) then
     460    FormMain.FormUnitMoves := TFormUnitMoves.Create(nil);
     461  FormMain.FormUnitMoves.Show;
    450462end;
    451463
     
    456468end;
    457469
    458 procedure TCore.CoolTranslator1Translate(Sender: TObject);
    459 begin
    460   UGame.InitStrings;
    461   CoolTranslator1.TranslateComponentRecursive(FormClient);
     470procedure TCore.Translator1Translate(Sender: TObject);
     471begin
     472  Translate;
     473  if Assigned(FormMain) then
     474    Translator1.TranslateComponentRecursive(FormMain.FormClient);
    462475end;
    463476
     
    473486    GameFilesDir := LinuxGameFilesDir;
    474487  // If installed in Linux system then use installation directory for po files
    475   if not DirectoryExists(CoolTranslator1.POFilesFolder) and DirectoryExists(LinuxLanguagesDir) then
    476     CoolTranslator1.POFilesFolder := LinuxLanguagesDir;
     488  if not DirectoryExists(Translator1.POFilesFolder) and DirectoryExists(LinuxLanguagesDir) then
     489    Translator1.POFilesFolder := LinuxLanguagesDir;
    477490  {$ENDIF}
    478491
     
    493506  XMLConfig1.Filename := GetAppConfigDir(False) + 'Config.xml';
    494507  ForceDirectories(GetAppConfigDir(False));
    495   FormClients := TObjectList<TFormClient>.Create;
     508  FormClients := TFormClients.Create;
    496509  ServerList := TServerList.Create;
     510
     511  LoadConfig;
     512
     513  TFormEx.ScaleDPI := ScaleDPI1;
     514  TFormEx.Translator := Translator1;
     515  TFormEx.ThemeManager := ThemeManager1;
     516  TFormEx.PersistentForm := PersistentForm1;
     517
     518  FormMain := TFormMain.Create(nil);
     519  FormMain.Show;
    497520end;
    498521
     
    500523begin
    501524  FreeAndNil(ServerList);
    502   if Assigned(FormPlayersStats) then FreeAndNil(FormPlayersStats);
    503   if Assigned(FormUnitMoves) then FreeAndNil(FormUnitMoves);
    504   if Assigned(FormCharts) then FreeAndNil(FormCharts);
    505   if Assigned(FormKeyShortcuts) then FreeAndNil(FormKeyShortcuts);
     525  if Assigned(FormMain.FormPlayersStats) then FreeAndNil(FormMain.FormPlayersStats);
     526  if Assigned(FormMain.FormUnitMoves) then FreeAndNil(FormMain.FormUnitMoves);
     527  if Assigned(FormMain.FormCharts) then FreeAndNil(FormMain.FormCharts);
     528  if Assigned(FormMain.FormKeyShortcuts) then FreeAndNil(FormMain.FormKeyShortcuts);
    506529  FreeAndNil(FormClients);
    507530  FreeAndNil(StoredDimension);
     
    511534  FreeAndNil(GameSettings);
    512535  FreeAndNil(GameSystems);
     536  FreeAndNil(FormMain);
    513537end;
    514538
    515539procedure TCore.LastOpenedList1Change(Sender: TObject);
    516540begin
    517   LastOpenedList1.LoadToMenuItem(FormMain.MenuItemLoadRecent, LoadRecentExecute);
     541  if Assigned(FormMain) then
     542    LastOpenedList1.LoadToMenuItem(FormMain.MenuItemLoadRecent, LoadRecentExecute);
    518543end;
    519544
     
    538563  // Create local LocalClients for human players
    539564  LocalClients.Clear;
    540   FormClient.Client := nil;
     565  FormMain.FormClient.Client := nil;
    541566  for I := 0 to Game.Players.Count - 1 do begin
    542567    Player := TPlayer(Game.Players[I]);
     
    573598  if Assigned(ServerClient) then ServerClient.TurnStart
    574599    else raise Exception.Create(SMissingServerClientForPlayer);
    575   FormClient.AZoomAll.Execute;
     600  FormMain.FormClient.AZoomAll.Execute;
    576601end;
    577602
    578603procedure TCore.UpdateOtherForms;
    579604begin
    580   if Assigned(FormCharts) and FormCharts.Visible then FormCharts.Redraw;
    581   if Assigned(FormUnitMoves) and FormUnitMoves.Visible then FormUnitMoves.ReloadList;
    582   if Assigned(FormPlayersStats) and FormPlayersStats.Visible then FormPlayersStats.ReloadList;
     605  if Assigned(FormMain.FormCharts) and FormMain.FormCharts.Visible then FormMain.FormCharts.Redraw;
     606  if Assigned(FormMain.FormUnitMoves) and FormMain.FormUnitMoves.Visible then FormMain.FormUnitMoves.ReloadList;
     607  if Assigned(FormMain.FormPlayersStats) and FormMain.FormPlayersStats.Visible then FormMain.FormPlayersStats.ReloadList;
    583608end;
    584609
     
    589614begin
    590615  // Copy all actions from docked form to main form so keyboard shortcuts will be active
    591   for I := 0 to FormClient.ActionList1.ActionCount - 1 do begin
     616  for I := 0 to FormMain.FormClient.ActionList1.ActionCount - 1 do begin
    592617    Action := TAction.Create(FormMain);
    593     Action.Assign(TAction(FormClient.ActionList1.Actions[I]));
     618    Action.Assign(TAction(FormMain.FormClient.ActionList1.Actions[I]));
    594619    Action.ActionList := FormMain.ActionList1;
    595620  end;
     
    625650begin
    626651  FullScreen := not FullScreen;
    627   PersistentForm.Form := FormMain;
    628   PersistentForm.SetFullScreen(FullScreen);
     652  PersistentForm1.Form := FormMain;
     653  PersistentForm1.SetFullScreen(FullScreen);
    629654  UpdateInterface;
    630655end;
     
    673698  // Create local LocalClients for human players
    674699  LocalClients.Clear;
    675   FormClient.Client := nil;
     700  FormMain.FormClient.Client := nil;
    676701  for I := 0 to Game.Players.Count - 1 do begin
    677702    Player := TPlayer(Game.Players[I]);
     
    722747    if Game.CurrentPlayer.Mode = pmHuman then begin
    723748      PlayerClient := LocalClients.SearchPlayer(Game.CurrentPlayer);
    724       if Assigned(PlayerClient) then FormClient.Client := TClientGUI(PlayerClient);
     749      if Assigned(PlayerClient) then FormMain.FormClient.Client := TClientGUI(PlayerClient);
    725750    end;
    726751
     
    733758procedure TCore.DoMoveUpdated(UnitMove: TUnitMove);
    734759begin
    735   if Assigned(FormUnitMoves) and FormUnitMoves.Visible then
    736     FormUnitMoves.ReloadList;
     760  if Assigned(FormMain.FormUnitMoves) and FormMain.FormUnitMoves.Visible then
     761    FormMain.FormUnitMoves.ReloadList;
    737762end;
    738763
Note: See TracChangeset for help on using the changeset viewer.