Changeset 317 for trunk/Core.pas
- Timestamp:
- Jun 21, 2024, 12:44:53 PM (5 months ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Core.pas
r316 r317 1 unit UCore;1 unit Core; 2 2 3 3 interface … … 5 5 uses 6 6 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; 11 11 12 12 type … … 34 34 AGameNew: TAction; 35 35 AGameRestart: TAction; 36 CoolTranslator1: TTranslator;36 Translator1: TTranslator; 37 37 ImageListLarge: TImageList; 38 38 ImageListSmall: TImageList; 39 39 LastOpenedList1: TLastOpenedList; 40 40 OpenDialog1: TOpenDialog; 41 PersistentForm : TPersistentForm;41 PersistentForm1: TPersistentForm; 42 42 SaveDialog1: TSaveDialog; 43 43 ScaleDPI1: TScaleDPI; … … 61 61 procedure AShowUnitMovesExecute(Sender: TObject); 62 62 procedure AToggleFogOfWarExecute(Sender: TObject); 63 procedure CoolTranslator1Translate(Sender: TObject);63 procedure Translator1Translate(Sender: TObject); 64 64 procedure DataModuleCreate(Sender: TObject); 65 65 procedure DataModuleDestroy(Sender: TObject); … … 99 99 AutoSaveEnabled: Boolean; 100 100 ReopenLastFile: Boolean; 101 FormClients: T ObjectList<TFormClient>;101 FormClients: TFormClients; 102 102 LocalClients: TClients; 103 103 ServerList: TServerList; 104 104 GameSystems: TGameSystems; 105 FormMain: TFormMain; 105 106 procedure ReopenGameOnInit; 106 107 procedure LoadConfig; … … 128 129 129 130 uses 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; 132 133 133 134 const … … 145 146 SMissingServerClientForPlayer = 'Server client for current player not found.'; 146 147 148 procedure Translate; 149 begin 150 Game.InitStrings; 151 end; 147 152 148 153 { TCore } … … 196 201 begin 197 202 RegistryContext := TRegistryContext.Create(HKEY_CURRENT_USER, DefaultRegKey); 198 PersistentForm .RegistryContext := RegistryContext;203 PersistentForm1.RegistryContext := RegistryContext; 199 204 XMLConfig1.Filename := GetAppConfigDir(False) + 'Config.xml'; 200 205 … … 205 210 AutoSaveEnabled := XMLConfig1.GetValue('AutoSave', True); 206 211 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', ''))); 208 213 ScaleDPI1.DPI := Point(XMLConfig1.GetValue('DPIX', 96), XMLConfig1.GetValue('DPIY', 96)); 209 214 ScaleDPI1.AutoDetect := XMLConfig1.GetValue('DPIAuto', True); … … 215 220 procedure TCore.SaveConfig; 216 221 begin 217 XMLConfig1.SetValue('Language', WideString( CoolTranslator1.Language.Code));222 XMLConfig1.SetValue('Language', WideString(Translator1.Language.Code)); 218 223 XMLConfig1.SetValue('Theme', WideString(ThemeManager1.Theme.Name)); 219 224 LastOpenedList1.SaveToXMLConfig(XMLConfig1, 'RecentFiles'); … … 277 282 begin 278 283 FirstHuman := Game.Players.GetFirstHuman; 279 if Assigned(FirstHuman) then Form Client.Client := TClientGUI(LocalClients.SearchPlayer(FirstHuman))284 if Assigned(FirstHuman) then FormMain.FormClient.Client := TClientGUI(LocalClients.SearchPlayer(FirstHuman)) 280 285 else begin 281 Form Client.Client := TClientGUI(LocalClients.New(SSpectator));282 Form Client.Client.LocalServer := Server;283 Form Client.Client.ConnectType := ctLocal;284 Form Client.Client.Active := True;285 Form Client.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; 286 291 end; 287 292 end; … … 339 344 var 340 345 NewServer: TServer; 346 FormNew: TFormNew; 341 347 begin 342 348 FormNew := TFormNew.Create(nil); … … 394 400 395 401 procedure TCore.AHelpExecute(Sender: TObject); 402 var 403 FormHelp: TFormHelp; 396 404 begin 397 405 FormHelp := TFormHelp.Create(Self); … … 410 418 procedure TCore.APlayersStatsExecute(Sender: TObject); 411 419 begin 412 if not Assigned(Form PlayersStats) then413 Form PlayersStats := TFormPlayersStats.Create(nil);414 Form PlayersStats.Show;420 if not Assigned(FormMain.FormPlayersStats) then 421 FormMain.FormPlayersStats := TFormPlayersStats.Create(nil); 422 FormMain.FormPlayersStats.Show; 415 423 end; 416 424 417 425 procedure TCore.ASettingsExecute(Sender: TObject); 426 var 427 FormSettings: TFormSettings; 418 428 begin 419 429 FormSettings := TFormSettings.Create(nil); … … 434 444 procedure TCore.AShowChartsExecute(Sender: TObject); 435 445 begin 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; 438 449 end; 439 450 440 451 procedure TCore.AShowKeyShortcutsExecute(Sender: TObject); 441 452 begin 442 if not Assigned(Form KeyShortcuts) thenFormKeyShortcuts := TFormKeyShortcuts.Create(nil);443 Form KeyShortcuts.Show;453 if not Assigned(FormMain.FormKeyShortcuts) then FormMain.FormKeyShortcuts := TFormKeyShortcuts.Create(nil); 454 FormMain.FormKeyShortcuts.Show; 444 455 end; 445 456 446 457 procedure TCore.AShowUnitMovesExecute(Sender: TObject); 447 458 begin 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; 450 462 end; 451 463 … … 456 468 end; 457 469 458 procedure TCore.CoolTranslator1Translate(Sender: TObject); 459 begin 460 UGame.InitStrings; 461 CoolTranslator1.TranslateComponentRecursive(FormClient); 470 procedure TCore.Translator1Translate(Sender: TObject); 471 begin 472 Translate; 473 if Assigned(FormMain) then 474 Translator1.TranslateComponentRecursive(FormMain.FormClient); 462 475 end; 463 476 … … 473 486 GameFilesDir := LinuxGameFilesDir; 474 487 // If installed in Linux system then use installation directory for po files 475 if not DirectoryExists( CoolTranslator1.POFilesFolder) and DirectoryExists(LinuxLanguagesDir) then476 CoolTranslator1.POFilesFolder := LinuxLanguagesDir;488 if not DirectoryExists(Translator1.POFilesFolder) and DirectoryExists(LinuxLanguagesDir) then 489 Translator1.POFilesFolder := LinuxLanguagesDir; 477 490 {$ENDIF} 478 491 … … 493 506 XMLConfig1.Filename := GetAppConfigDir(False) + 'Config.xml'; 494 507 ForceDirectories(GetAppConfigDir(False)); 495 FormClients := T ObjectList<TFormClient>.Create;508 FormClients := TFormClients.Create; 496 509 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; 497 520 end; 498 521 … … 500 523 begin 501 524 FreeAndNil(ServerList); 502 if Assigned(Form PlayersStats) then FreeAndNil(FormPlayersStats);503 if Assigned(Form UnitMoves) then FreeAndNil(FormUnitMoves);504 if Assigned(Form Charts) then FreeAndNil(FormCharts);505 if Assigned(Form KeyShortcuts) 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); 506 529 FreeAndNil(FormClients); 507 530 FreeAndNil(StoredDimension); … … 511 534 FreeAndNil(GameSettings); 512 535 FreeAndNil(GameSystems); 536 FreeAndNil(FormMain); 513 537 end; 514 538 515 539 procedure TCore.LastOpenedList1Change(Sender: TObject); 516 540 begin 517 LastOpenedList1.LoadToMenuItem(FormMain.MenuItemLoadRecent, LoadRecentExecute); 541 if Assigned(FormMain) then 542 LastOpenedList1.LoadToMenuItem(FormMain.MenuItemLoadRecent, LoadRecentExecute); 518 543 end; 519 544 … … 538 563 // Create local LocalClients for human players 539 564 LocalClients.Clear; 540 Form Client.Client := nil;565 FormMain.FormClient.Client := nil; 541 566 for I := 0 to Game.Players.Count - 1 do begin 542 567 Player := TPlayer(Game.Players[I]); … … 573 598 if Assigned(ServerClient) then ServerClient.TurnStart 574 599 else raise Exception.Create(SMissingServerClientForPlayer); 575 Form Client.AZoomAll.Execute;600 FormMain.FormClient.AZoomAll.Execute; 576 601 end; 577 602 578 603 procedure TCore.UpdateOtherForms; 579 604 begin 580 if Assigned(Form Charts) and FormCharts.Visible thenFormCharts.Redraw;581 if Assigned(Form UnitMoves) and FormUnitMoves.Visible thenFormUnitMoves.ReloadList;582 if Assigned(Form PlayersStats) and FormPlayersStats.Visible thenFormPlayersStats.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; 583 608 end; 584 609 … … 589 614 begin 590 615 // Copy all actions from docked form to main form so keyboard shortcuts will be active 591 for I := 0 to Form Client.ActionList1.ActionCount - 1 do begin616 for I := 0 to FormMain.FormClient.ActionList1.ActionCount - 1 do begin 592 617 Action := TAction.Create(FormMain); 593 Action.Assign(TAction(Form Client.ActionList1.Actions[I]));618 Action.Assign(TAction(FormMain.FormClient.ActionList1.Actions[I])); 594 619 Action.ActionList := FormMain.ActionList1; 595 620 end; … … 625 650 begin 626 651 FullScreen := not FullScreen; 627 PersistentForm .Form := FormMain;628 PersistentForm .SetFullScreen(FullScreen);652 PersistentForm1.Form := FormMain; 653 PersistentForm1.SetFullScreen(FullScreen); 629 654 UpdateInterface; 630 655 end; … … 673 698 // Create local LocalClients for human players 674 699 LocalClients.Clear; 675 Form Client.Client := nil;700 FormMain.FormClient.Client := nil; 676 701 for I := 0 to Game.Players.Count - 1 do begin 677 702 Player := TPlayer(Game.Players[I]); … … 722 747 if Game.CurrentPlayer.Mode = pmHuman then begin 723 748 PlayerClient := LocalClients.SearchPlayer(Game.CurrentPlayer); 724 if Assigned(PlayerClient) then Form Client.Client := TClientGUI(PlayerClient);749 if Assigned(PlayerClient) then FormMain.FormClient.Client := TClientGUI(PlayerClient); 725 750 end; 726 751 … … 733 758 procedure TCore.DoMoveUpdated(UnitMove: TUnitMove); 734 759 begin 735 if Assigned(Form UnitMoves) andFormUnitMoves.Visible then736 Form UnitMoves.ReloadList;760 if Assigned(FormMain.FormUnitMoves) and FormMain.FormUnitMoves.Visible then 761 FormMain.FormUnitMoves.ReloadList; 737 762 end; 738 763
Note:
See TracChangeset
for help on using the changeset viewer.