Changeset 180 for trunk/UCore.pas


Ignore:
Timestamp:
Feb 8, 2018, 5:32:31 PM (7 years ago)
Author:
chronos
Message:
  • Modified: Client related interface moved from FormMain to FormClient. This code change will later allow to implement network client-server gameplay.
  • Added: Allow to open other spectator client windows.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UCore.pas

    r179 r180  
    88  Classes, SysUtils, XMLConf, FileUtil, ActnList, Controls, Dialogs, Forms,
    99  UGame, UApplicationInfo, UPersistentForm, UScaleDPI, UCoolTranslator,
    10   URegistry, ULastOpenedList, Registry, Menus, UGeometry;
     10  URegistry, ULastOpenedList, Registry, Menus, UGeometry, Contnrs, UFormClient;
    1111
    1212type
     
    1616  TCore = class(TDataModule)
    1717    AAbout: TAction;
     18    ANewSpectatorClient: TAction;
    1819    AShowUnitMoves: TAction;
    1920    AShowCharts: TAction;
     
    4748    procedure AGameSaveExecute(Sender: TObject);
    4849    procedure AHelpExecute(Sender: TObject);
     50    procedure ANewSpectatorClientExecute(Sender: TObject);
    4951    procedure ASettingsExecute(Sender: TObject);
    5052    procedure AShowChartsExecute(Sender: TObject);
     
    6971    procedure GameNewTurnExecute(Sender: TObject);
    7072    procedure AutoSave;
    71     function GetPlayer: TPlayer;
    7273    procedure LoadConfig;
    7374    procedure SaveConfig;
     
    7677    procedure SelectClient;
    7778    procedure LoadGame(FileName: string);
     79    procedure RedrawClients;
    7880  public
    7981    Game: TGame;
     
    8385    AnimationSpeed: Integer;
    8486    AutoSaveEnabled: Boolean;
    85     CurrentClient: TClient;
     87    FormClients: TObjectList; // TFormClient
     88    //CurrentClient: TClient;
     89    LocalClients: TObjectList; // TClient
    8690    procedure UpdateActions;
    8791    procedure Init;
     
    147151procedure TCore.DoOnWin(Player: TPlayer);
    148152begin
    149   FormMain.Redraw;
     153  RedrawClients;
    150154  ShowMessage(Format(SPlayerWins, [Player.Name]));
    151155end;
     
    174178  Game.SaveToFile(GetAppConfigDir(False) + 'AutoSave.xtg');
    175179  Game.FileName := OldFileName;
    176 end;
    177 
    178 function TCore.GetPlayer: TPlayer;
    179 begin
    180   Result := Game.CurrentPlayer;
    181180end;
    182181
     
    246245begin
    247246  FirstHuman := Game.Players.GetFirstHuman;
    248   if Assigned(FirstHuman) then CurrentClient := FirstHuman.Client
    249     else CurrentClient := TClient(Server.Clients.First);
     247  if Assigned(FirstHuman) then FormClient.Client := FirstHuman.Client
     248    else FormClient.Client := TClient(Server.Clients.First);
    250249end;
    251250
     
    276275  if MessageDlg(SEndGame, SEndGameQuestion, mtConfirmation, mbYesNo, 0) = mrYes then begin
    277276    Game.Running := False;
    278     FormMain.Redraw;
     277    RedrawClients;
    279278    UpdateActions;
    280279  end;
     
    286285    if Game.CurrentPlayer.Mode = pmComputer then begin
    287286      Game.CurrentPlayer.Computer.Process;
    288       FormMain.Redraw;
     287      RedrawClients;
    289288      Delay(Trunc((100 - AnimationSpeed) / 100 * 2000));
    290289    end;
    291290    Game.NextTurn;
    292     FormMain.Redraw;
     291    RedrawClients;
    293292    Application.ProcessMessages;
    294293    Sleep(1);
     
    299298begin
    300299  Game.NextTurn;
    301   FormMain.Redraw;
     300  RedrawClients;
    302301  ProcessComputerTurns;
    303302  UpdateActions;
     
    354353    FreeAndNil(FormHelp);
    355354  end;
     355end;
     356
     357procedure TCore.ANewSpectatorClientExecute(Sender: TObject);
     358var
     359  Form: TFormClient;
     360begin
     361  Form := TFormClient.Create(nil);
     362  Form.Client := Game.Server.Clients.New(SSpectator);
     363  //Form.Client.Form := Form;
     364  Form.AZoomAll.Execute;
     365  Form.Show;
    356366end;
    357367
     
    401411  XMLConfig1.Filename := GetAppConfigDir(False) + 'Config.xml';
    402412  ForceDirectories(GetAppConfigDir(False));
     413  FormClients := TObjectList.Create;
    403414end;
    404415
    405416procedure TCore.DataModuleDestroy(Sender: TObject);
    406417begin
     418  FreeAndNil(FormClients);
    407419  FreeAndNil(StoredDimension);
    408420  Game.SaveConfig(XMLConfig1, 'Game');
     
    429441  SelectClient;
    430442  LastOpenedList1.AddItem(FileName);
    431   with Core.CurrentClient do
     443  with FormClient.Client do
    432444    View.DestRect := TRect.CreateBounds(TPoint.Create(0, 0),
    433       TPoint.Create(FormMain.PaintBox1.Width, FormMain.PaintBox1.Height));
    434   FormMain.AZoomAll.Execute;
    435   FormMain.Redraw;
     445      TPoint.Create(FormClient.PaintBox1.Width, FormClient.PaintBox1.Height));
     446  FormClient.AZoomAll.Execute;
     447  RedrawClients;
    436448  if FormCharts.Visible then FormCharts.Redraw;
    437449  if FormUnitMoves.Visible then FormUnitMoves.ReloadList;
     450end;
     451
     452procedure TCore.RedrawClients;
     453var
     454  Form: TFormClient;
     455begin
     456  for Form in FormClients do
     457    Form.Redraw;
     458  FormClient.Redraw;
    438459end;
    439460
     
    446467  if Game.Players.GetAliveCount = Game.Players.Count then Game.Running := True
    447468    else ShowMessage(Format(SPlayersNotInitialized, [Game.Players.Count, Game.Players.GetAliveCount]));
    448   FormMain.Redraw;
     469  RedrawClients;
    449470  if FormCharts.Visible then FormCharts.Redraw;
    450471  if FormUnitMoves.Visible then FormUnitMoves.ReloadList;
     
    455476procedure TCore.DoPlayerChange(Sender: TObject);
    456477begin
    457   if Assigned(Game.CurrentPlayer) and Assigned(Game.CurrentPlayer.Client) then
    458     CurrentClient := Game.CurrentPlayer.Client;
     478  if Assigned(Game.CurrentPlayer) and Assigned(Game.CurrentPlayer.Client) then begin
     479    FormClient.Client := Game.CurrentPlayer.Client;
     480  end;
    459481  if FormCharts.Visible then FormCharts.Redraw;
    460482  if FormUnitMoves.Visible then FormUnitMoves.ReloadList;
Note: See TracChangeset for help on using the changeset viewer.