Changeset 236 for trunk


Ignore:
Timestamp:
Sep 20, 2018, 3:33:04 PM (6 years ago)
Author:
chronos
Message:
  • Added: Mouse focused and selected cells are now working.
Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormClient.pas

    r235 r236  
    169169  R: TRect;
    170170  StartP: TPoint;
    171   VS: TPoint;
    172171  CountP: TPoint;
    173172  X, Y: Integer;
     
    193192
    194193      if Game.CyclicMap then begin
    195         VS := View.CellToCanvasPos(Game.Map.Size);
    196194        TempView := TView.Create;
    197195        TempView.Game := Game;
     
    493491  OldCell: TPlayerCell;
    494492  CellPos: TPoint;
     493  P: TPoint;
     494  R: TRect;
    495495begin
    496496  if Assigned(Client) then begin
     497    P := TPoint.Create(X, Y);
    497498    if MoveActive then
    498499    if (Abs(StartMousePoint.X - X) > Trunc(Screen.PixelsPerInch * MouseMinDiff)) or
    499500    (Abs(StartMousePoint.Y - Y) > Trunc(Screen.PixelsPerInch * MouseMinDiff)) then
    500501    with Client do begin
    501       View.SourceRect := TRect.CreateBounds(TPoint.Create(Trunc(StartViewPoint.X + (StartMousePoint.X - X) / View.Zoom),
     502      View.SourceRect := TRect.CreateBounds(TPoint.Create(
     503        Trunc(StartViewPoint.X + (StartMousePoint.X - X) / View.Zoom),
    502504        Trunc(StartViewPoint.Y + (StartMousePoint.Y - Y) / View.Zoom)),
    503505        View.SourceRect.Size);
     
    507509    OldCell := Client.View.FocusedCell;
    508510    with Core.Game do
    509       if Assigned(Client.ControlPlayer) then
    510         Cell := Client.ControlPlayer.PlayerMap.PosToCell(Client.View.CanvasToCellPos(TPoint.Create(X, Y)));
    511         //else Cell := Client.Game.Map.PosToCell(Client.View.CanvasToCellPos(TPoint.Create(X, Y)), Client.View);
     511      if Assigned(Client.ControlPlayer) then begin
     512        if Map.Cyclic then begin
     513          R := Client.View.CellToCanvasRect(Map.PixelRect);
     514          CellPos := TPoint.Create(
     515            ModNeg(P.X - R.P1.X, R.Size.X) + R.P1.X,
     516            ModNeg(P.Y - R.P1.Y, R.Size.Y) + R.P1.Y
     517          );
     518          Cell := Client.ControlPlayer.PlayerMap.PosToCell(
     519          Client.View.CanvasToCellPos(CellPos));
     520        end else begin
     521          Cell := Client.ControlPlayer.PlayerMap.PosToCell(
     522            Client.View.CanvasToCellPos(P));
     523        end;
     524      end;
    512525    if Assigned(Cell) then begin
    513526      Client.View.FocusedCell := Cell;
     
    530543  (Abs(StartMousePoint.Y - Y) < Trunc(Screen.PixelsPerInch * MouseMinDiff)) then begin
    531544    if Core.Game.Running and (Core.Game.CurrentPlayer.Mode = pmHuman) and
    532       (Core.Game.CurrentPlayer = Client.ControlPlayer) then begin
     545    (Core.Game.CurrentPlayer = Client.ControlPlayer) then begin
    533546      Client.View.SelectCell(TPoint.Create(X, Y), Client.ControlPlayer, Shift);
    534547      Redraw;
  • trunk/UClientGUI.pas

    r234 r236  
    383383  UnitMove: TUnitMove;
    384384  I: Integer;
    385 begin
    386   NewSelectedCell := Player.PlayerMap.PosToCell(CanvasToCellPos(Pos));
     385  CellPos: TPoint;
     386  R: TRect;
     387begin
     388  if TGame(Game).Map.Cyclic then begin
     389    R := CellToCanvasRect(TGame(Game).Map.PixelRect);
     390    CellPos := TPoint.Create(
     391      ModNeg(Pos.X - R.P1.X, R.Size.X) + R.P1.X,
     392      ModNeg(Pos.Y - R.P1.Y, R.Size.Y) + R.P1.Y
     393    );
     394    NewSelectedCell := Player.PlayerMap.PosToCell(
     395      CanvasToCellPos(CellPos));
     396  end else begin
     397    NewSelectedCell := Player.PlayerMap.PosToCell(
     398      CanvasToCellPos(Pos));
     399  end;
    387400  if Assigned(NewSelectedCell) then begin
    388401    if Assigned(SelectedCell) and TGame(Game).Map.IsCellsNeighbor(NewSelectedCell.MapCell, SelectedCell.MapCell) then begin
  • trunk/UGeometry.pas

    r235 r236  
    2525    class operator Multiply(const A, B: TGPoint<T>): TGPoint<T>;
    2626    //class operator Divide(const A, B: TGPoint<T>): TGPoint<T>;
     27    //class operator Modulus(A: TGPoint<T>; B: TGPoint<T>): TGPoint<T>;
    2728    function Min(const A, B: TGPoint<T>): TGPoint<T>;
    2829    function Max(const A, B: TGPoint<T>): TGPoint<T>;
     
    120121  TPolygonF = TGPolygon<TPointF>;
    121122
     123function TypedMod(Numerator, Denominator: Integer): Integer; overload;
     124function TypedMod(Numerator, Denominator: Single): Single; overload;
    122125function TypedDivide(Divident, Divisor: Integer): Integer; overload;
    123126function TypedDivide(Divident, Divisor: Single): Single; overload;
     
    126129function StdPointToPoint(Value: Classes.TPoint): TPoint;
    127130function PointToStdPoint(Value: TPoint): Classes.TPoint;
     131function ModNeg(A, B: Integer): Integer;
    128132
    129133
    130134implementation
     135
     136function ModNeg(A, B: Integer): Integer;
     137begin
     138  if A < 0 then A := A + Ceil(-A / B) * B;
     139  Result := A mod B;
     140end;
     141
     142function TypedMod(Numerator, Denominator: Integer): Integer; overload;
     143begin
     144  Result := Numerator mod Denominator;
     145end;
     146
     147function TypedMod(Numerator, Denominator: Single): Single; overload;
     148begin
     149  //Result := FMod(Numerator, Denominator);
     150end;
    131151
    132152function TypedDivide(Divident, Divisor: Integer): Integer;
     
    443463  Result.Y := TypedDivide(A.Y, B.Y);
    444464end;
     465
     466class operator TGPoint<T>.Modulus(A: TGPoint<T>; B: TGPoint<T>): TGPoint<T>;
     467begin
     468  Result.X := TypedMod(A.X, B.X);
     469  Result.Y := TypedMod(A.Y, B.Y);
     470end;
    445471}
    446472
Note: See TracChangeset for help on using the changeset viewer.