close Warning: Can't synchronize with repository "(default)" (No changeset 184 in the repository). Look in the Trac log for more information.

Changeset 126


Ignore:
Timestamp:
Jun 17, 2017, 2:54:50 PM (7 years ago)
Author:
chronos
Message:
  • Fixed: Center map to player main city at start.
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/UCore.pas

    r125 r126  
    5252    StoredDimension: TControlDimension;
    5353    RegistryContext: TRegistryContext;
     54    procedure StartNewGame;
    5455    procedure DoPlayerChange(Sender: TObject);
    5556    procedure DoOnMove(CellFrom, CellTo: TCell; var CountOnce,
     
    285286    if Game.CurrentPlayer.Mode = pmComputer then begin
    286287      Computer := TComputer.Create;
    287       Computer.Game := Game;
    288       Computer.Process;
    289       Computer.Free;
     288      try
     289        Computer.Game := Game;
     290        Computer.Process;
     291      finally
     292        Computer.Free;
     293      end;
    290294      FormMain.Redraw;
    291295      Delay(Trunc((100 - AnimationSpeed) / 100 * 2000));
     
    320324  if FormNew.ShowModal = mrOk then begin
    321325    FormNew.Save(Game);
    322     Game.New;
    323     SelectClient;
    324     Game.Running := True;
    325     FormMain.AZoomAll.Execute;
    326     UpdateActions;
     326    StartNewGame;
    327327  end;
    328328end;
     
    331331begin
    332332  if MessageDlg(SRestartGame, SRestartGameQuestion, mtConfirmation, mbYesNo, 0) = mrYes then begin
    333     Game.New;
    334     Game.Running := True;
    335     FormMain.AZoomAll.Execute;
    336     FormMain.Redraw;
    337     UpdateActions;
     333    StartNewGame;
    338334  end;
    339335end;
     
    396392end;
    397393
     394procedure TCore.StartNewGame;
     395begin
     396  Game.New;
     397  SelectClient;
     398  Game.Running := True;
     399  FormMain.Redraw;
     400  UpdateActions;
     401end;
     402
    398403procedure TCore.DoPlayerChange(Sender: TObject);
    399404begin
     
    413418  FInitialized := True;
    414419  LoadConfig;
    415   for I := 0 to Game.Clients.Count - 1 do
    416     TClient(Game.Clients[I]).View.DestRect := Rect(0, 0, FormMain.PaintBox1.Width,
    417       FormMain.PaintBox1.Height);
    418420  Game.LoadConfig(XMLConfig1, 'Game');
    419421
     
    421423  ScaleDPI;
    422424
    423   if Game.FileName = '' then begin
    424     Game.New;
    425     SelectClient;
    426     Game.Running := True;
    427     FormMain.AZoomAll.Execute;
    428   end;
     425  if Game.FileName = '' then StartNewGame;
    429426end;
    430427
  • trunk/UGame.pas

    r125 r126  
    128128    procedure SelectCell(Pos: TPoint; Player: TPlayer; ShiftState: TShiftState);
    129129    procedure CenterMap;
     130    procedure CenterPlayerCity(Player: TPlayer);
    130131    function CanvasToCellPos(Pos: TPoint): TPoint;
    131132    function CellToCanvasPos(Pos: TPoint): TPoint;
     
    22262227end;
    22272228
     2229procedure TView.CenterPlayerCity(Player: TPlayer);
     2230begin
     2231  SourceRect := Bounds(Player.StartCell.PosPx.X - (SourceRect.Right - SourceRect.Left) div 2,
     2232    Player.StartCell.PosPx.Y - (SourceRect.Bottom - SourceRect.Top) div 2,
     2233    SourceRect.Right - SourceRect.Left,
     2234    SourceRect.Bottom - SourceRect.Top);
     2235end;
     2236
    22282237procedure TPlayer.Paint(Canvas: TCanvas; View: TView);
    22292238begin
     
    30483057    View.Clear;
    30493058    View.Zoom := 1;
    3050     View.CenterMap;
     3059    if Assigned(ControlPlayer) then View.CenterPlayerCity(ControlPlayer)
     3060      else View.CenterMap;
    30513061  end;
    30523062end;
Note: See TracChangeset for help on using the changeset viewer.