Changeset 310 for trunk/UCore.pas


Ignore:
Timestamp:
Aug 18, 2021, 4:02:44 PM (3 years ago)
Author:
chronos
Message:
  • Fixed: Use correct game data files directory on Linux.
  • Fixed: Copy Systems and Maps with with package.
  • Modified: Use fullscreen mode switching from Common package PersistentForm class.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UCore.pas

    r309 r310  
    1010  URegistry, ULastOpenedList, UTheme, UAboutDialog, Registry, Menus,
    1111  UFormClient, UPlayer, UGameServer, UGameClient, fgl, UServerList, UGameSystem,
    12   Graphics;
     12  Graphics, UUnit;
    1313
    1414type
     
    7575    FormNewTabIndex: Integer;
    7676    OldWindowState: TWindowState;
    77     InFullScreenMode: Boolean;
     77    FullScreen: Boolean;
     78    GameFilesDir: string;
    7879    procedure LoadRecentExecute(Sender: TObject);
    7980    procedure StartNewGame;
     
    9091    procedure FormClientActions;
    9192    procedure LoadGameSystems;
     93    procedure ToggleFullscreen;
    9294  public
    9395    Game: TGame;
     
    130132
    131133uses
    132   UFormMain, UFormNew, UFormSettings, UClientAI, UFormKeyShortcuts,
     134  UFormMain, UFormNew, UFormSettings, UClientAI, UFormKeyShortcuts, UCommon,
    133135  UFormHelp, UFormCharts, UFormUnitMoves, UFormPlayersStats, UClientGUI;
    134136
     
    303305procedure TCore.AFullscreenExecute(Sender: TObject);
    304306begin
    305   if InFullScreenMode then begin
    306     // Workaround: WindowState has sometimes wrong value under Linux.
    307     // Try to switch fullscreen again before switching back.
    308     if FormMain.WindowState <> wsFullScreen then begin
    309       FormMain.WindowState := wsFullScreen;
    310     end;
    311     {$IFDEF WINDOWS}
    312     FormMain.BorderStyle := bsSizeable;
    313     {$ENDIF}
    314     FormMain.WindowState := OldWindowState;
    315     InFullScreenMode := False;
    316   end else begin
    317     OldWindowState := FormMain.WindowState;
    318     {$IFDEF WINDOWS}
    319     FormMain.BorderStyle := bsNone;
    320     {$ENDIF}
    321     FormMain.WindowState := wsFullScreen;
    322     InFullScreenMode := True;
    323   end;
     307  ToggleFullscreen;
    324308end;
    325309
     
    402386  if FileExists(Game.FileName) then
    403387    Game.SaveToFile(Game.FileName)
    404     else AGameSave.Execute;
     388    else AGameSaveAs.Execute;
    405389end;
    406390
     
    476460procedure TCore.DataModuleCreate(Sender: TObject);
    477461const
    478   LinuxLanguagesDir = '/usr/share/xtactics/languages';
    479 begin
     462  LinuxGameFilesDir = '/usr/share/xtactics';
     463  LinuxLanguagesDir = LinuxGameFilesDir + '/Languages';
     464begin
     465  GameFilesDir := '';
    480466  {$IFDEF Linux}
     467  // If installed in Linux system then use installation shared game directory for data files
     468  if DirectoryExists(LinuxGameFilesDir) then
     469    GameFilesDir := LinuxGameFilesDir;
    481470  // If installed in Linux system then use installation directory for po files
    482471  if not DirectoryExists(CoolTranslator1.POFilesFolder) and DirectoryExists(LinuxLanguagesDir) then
     
    484473  {$ENDIF}
    485474 
    486     GameSystems := TGameSystems.Create;
     475  GameSystems := TGameSystems.Create;
    487476  Server := TServer.Create;
    488477  LocalClients := TClients.Create;
     
    494483  Game.OnNewTurn := GameNewTurnExecute;
    495484  Game.OnPlayerChange := DoPlayerChange;
     485  Game.MapImageFileName := CombinePaths(GameFilesDir, 'Images' + DirectorySeparator + 'Maps' + DirectorySeparator + 'WorldMap.png');
    496486  Server.Game := Game;
    497487  LocalClients.Game := Game;
     
    604594procedure TCore.LoadGameSystems;
    605595var
    606   NewItem: TGameSystem;
    607 begin
    608   if DirectoryExists('Systems') then begin
    609     GameSystems.LoadFromDir('Systems');
     596  NewGameSystem: TGameSystem;
     597  NewUnitKind: TUnitKind;
     598  SystemsDir: string;
     599begin
     600  if GameFilesDir <> '' then
     601    SystemsDir := GameFilesDir + DirectorySeparator + 'Systems'
     602    else SystemsDir := 'Systems';
     603  if DirectoryExists(SystemsDir) then begin
     604    GameSystems.LoadFromDir(SystemsDir);
    610605  end else begin
    611     NewItem := TGameSystem.Create;
    612     NewItem.FileName := 'Custom';
    613     GameSystems.Add(NewItem);
     606    // Create default game system if the directory with definitions was not found
     607    NewGameSystem := TGameSystem.Create;
     608    NewGameSystem.FileName := 'HexWars';
     609    NewUnitKind := TUnitKind.Create;
     610    NewUnitKind.Name := 'Unit';
     611    NewGameSystem.UnitKinds.Add(NewUnitKind);
     612    GameSystems.Add(NewGameSystem);
    614613  end;
    615614  if GameSystems.Count > 0 then begin
     
    617616    Game.GameSystem.Assign(GameSystems.First);
    618617  end;
     618end;
     619
     620procedure TCore.ToggleFullscreen;
     621begin
     622  FullScreen := not FullScreen;
     623  PersistentForm.Form := FormMain;
     624  PersistentForm.SetFullScreen(FullScreen);
     625  UpdateInterface;
    619626end;
    620627
Note: See TracChangeset for help on using the changeset viewer.