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

Ignore:
Timestamp:
Feb 9, 2018, 10:33:18 AM (6 years ago)
Author:
chronos
Message:
  • Modified: Units move handling was moved from Core to FormClient as it is game client related functionality.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormClient.pas

    r180 r183  
    7676    procedure SetClient(AValue: TClient);
    7777    procedure DoClientChange(Sender: TObject);
     78    procedure DoOnMove(CellFrom, CellTo: TCell; var CountOnce,
     79      CountRepeat: Integer; Update: Boolean; var Confirm: Boolean);
    7880  public
    7981    property Client: TClient read FClient write SetClient;
     
    9092
    9193uses
    92   UCore;
     94  UCore, UFormMove;
    9395
    9496resourcestring
     
    98100
    99101{ TFormClient }
     102
     103procedure TFormClient.DoOnMove(CellFrom, CellTo: TCell; var CountOnce,
     104  CountRepeat: Integer; Update: Boolean; var Confirm: Boolean);
     105var
     106  I: Integer;
     107  FormMove: TFormMove;
     108begin
     109  FormMove := TFormMove.Create(nil);
     110  try
     111    if Update then FormMove.SpinEditOnce.MaxValue := CellFrom.GetAvialPower + CountOnce
     112      else FormMove.SpinEditOnce.MaxValue := CellFrom.GetAvialPower;
     113    FormMove.SpinEditOnce.Value := CountOnce;
     114    FormMove.TrackBarOnce.Max := FormMove.SpinEditOnce.MaxValue;
     115    FormMove.TrackBarOnce.Position := FormMove.SpinEditOnce.Value;
     116    FormMove.SpinEditRepeat.MaxValue := Client.Game.Map.MaxPower;
     117    FormMove.SpinEditRepeat.Value := CountRepeat;
     118    FormMove.TrackBarRepeat.Max := FormMove.SpinEditRepeat.MaxValue;
     119    FormMove.TrackBarRepeat.Position := FormMove.SpinEditRepeat.Value;
     120    FormMove.DefendCount := CellTo.Power;
     121    // Attack count from other surrounding cells without current move if already exists
     122    FormMove.AttackCount := 0;
     123    for I := 0 to CellTo.MovesTo.Count - 1 do
     124    if TUnitMove(CellTo.MovesTo[I]).CellFrom <> CellFrom then
     125      FormMove.AttackCount := FormMove.AttackCount + TUnitMove(CellTo.MovesTo[I]).CountOnce;
     126    FormMove.ShowWinProbability := CellTo.Player <> CellFrom.Player;
     127
     128    if FormMove.ShowModal = mrOk then begin
     129      CountOnce := FormMove.SpinEditOnce.Value;
     130      CountRepeat := FormMove.SpinEditRepeat.Value;
     131      Confirm := True;
     132    end else Confirm := False;
     133  finally
     134    FormMove.Free;
     135  end;
     136end;
    100137
    101138procedure TFormClient.PaintBox1Paint(Sender: TObject);
     
    165202begin
    166203  if FClient = AValue then Exit;
     204  if Assigned(FClient) then FClient.Form := nil;
    167205  FClient := AValue;
    168   if Assigned(FClient) then
     206  if Assigned(FClient) then begin
     207    FClient.Form := Self;
    169208    FClient.OnChange := DoClientChange;
     209    FClient.OnMove := DoOnMove;
     210  end;
    170211  Redraw;
    171212end;
     
    298339procedure TFormClient.FormDestroy(Sender: TObject);
    299340begin
     341  Client := nil;
    300342  TempBitmap.Free;
    301343end;
Note: See TracChangeset for help on using the changeset viewer.