Changeset 62 for trunk/UGame.pas


Ignore:
Timestamp:
Sep 26, 2014, 1:58:41 PM (10 years ago)
Author:
chronos
Message:
  • Modified: Show one bigger arrow between two cells on unit move.
  • Added: New move clear existing counter move.
  • Modified: Move toolbar to left to have more space on top.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UGame.pas

    r60 r62  
    237237    procedure SetRunning(AValue: Boolean);
    238238    procedure UpdateRepeatMoves(Player: TPlayer);
     239    procedure CheckCounterMove(Move: TUnitMove);
    239240  public
    240241    Players: TPlayers;
     
    524525  SetLength(Points, 8);
    525526  SetLength(FPoints, 8);
    526   ArrowSize := Point(Trunc(DefaultCellSize.X / 4 * View.Zoom),
    527     Trunc(DefaultCellSize.Y / 4* View.Zoom));
     527  ArrowSize := Point(Trunc(DefaultCellSize.X / 3 * View.Zoom),
     528    Trunc(DefaultCellSize.Y / 3 * View.Zoom));
    528529  FPoints[0] := FloatPoint(+0.5 * ArrowSize.X, +0 * ArrowSize.Y);
    529530  FPoints[1] := FloatPoint(+0 * ArrowSize.X, +0.5 * ArrowSize.Y);
     
    546547    Brush.Style := bsClear;
    547548    Font.Color := clBlack;
    548     Font.Size := Trunc(16 * View.Zoom);
     549    Font.Size := Trunc(26 * View.Zoom);
    549550    TextOut(Pos.X - TextWidth(Text) div 2,
    550551      Pos.Y - TextHeight(Text) div 2, Text);
     
    12881289  end;
    12891290  if Confirm then begin
    1290   if Assigned(OldMove) then begin
    1291     // Already have such move
    1292     if (CountOnce = 0) and (CountRepeat = 0) then Moves.Delete(I)
    1293       else begin
    1294         TUnitMove(Moves[I]).CountOnce := CountOnce;
    1295         TUnitMove(Moves[I]).CountRepeat := CountRepeat;
     1291    if Assigned(OldMove) then begin
     1292      // Already have such move
     1293      if (CountOnce = 0) and (CountRepeat = 0) then Moves.Delete(I)
     1294        else begin
     1295          OldMove.CountOnce := CountOnce;
     1296          OldMove.CountRepeat := CountRepeat;
     1297          CheckCounterMove(OldMove);
     1298        end;
     1299    end else begin
     1300      // Add new move
     1301      if (CountOnce > 0) or (CountRepeat > 0) then begin
     1302        NewMove := TUnitMove(Moves[Moves.Add(TUnitMove.Create)]);
     1303        NewMove.List := Moves;
     1304        NewMove.CellFrom := CellFrom;
     1305        NewMove.CellTo := CellTo;
     1306        NewMove.CountOnce := CountOnce;
     1307        NewMove.CountRepeat := CountRepeat;
     1308        CheckCounterMove(NewMove);
    12961309      end;
    1297   end else begin
    1298     // Add new move
    1299     if (CountOnce > 0) or (CountRepeat > 0) then begin
    1300       NewMove := TUnitMove(Moves[Moves.Add(TUnitMove.Create)]);
    1301       NewMove.List := Moves;
    1302       NewMove.CellFrom := CellFrom;
    1303       NewMove.CellTo := CellTo;
    1304       NewMove.CountOnce := CountOnce;
    1305       NewMove.CountRepeat := CountRepeat;
    1306     end;
    1307   end;
     1310    end;
     1311
    13081312  end;
    13091313end;
     
    13361340        CountOnce := CountRepeat
    13371341        else CountOnce := CellFrom.GetAvialPower;
     1342  end;
     1343end;
     1344
     1345procedure TGame.CheckCounterMove(Move: TUnitMove);
     1346var
     1347  I: Integer;
     1348  CounterMove: TUnitMove;
     1349begin
     1350  I := 0;
     1351  while (I < Moves.Count) and ((TUnitMove(Moves[I]).CellTo <> Move.CellFrom) and
     1352    (TUnitMove(Moves[I]).CellFrom <> Move.CellTo)) do Inc(I);
     1353  if I < Moves.Count then CounterMove := TUnitMove(Moves[I])
     1354    else CounterMove := nil;
     1355  if Assigned(CounterMove) then begin
     1356    // For now, just remove counter move
     1357    Moves.Remove(CounterMove);
    13381358  end;
    13391359end;
     
    16441664  Angle: Double;
    16451665  ArrowCenter: TPoint;
     1666  Move: TUnitMove;
    16461667begin
    16471668  with Canvas, View do
     
    16581679        Pen.Color := clBlack;
    16591680        PaintCell(Canvas, Cell.PosPx, IntToStr(Cell.GetAvialPower), View, Cell);
    1660 
    1661         // Draw arrows
    1662         Pen.Color := clCream;
    1663         for I := 0 to Cell.MovesFrom.Count - 1 do begin
    1664           PosFrom := CellToPos(Cell);
    1665           PosTo := CellToPos(TUnitMove(Cell.MovesFrom[I]).CellTo);
    1666           if TUnitMove(Cell.MovesFrom[I]).CountRepeat > 0 then Pen.Width := 2
    1667             else Pen.Width := 1;
    1668           Angle := ArcTan((PosTo.Y - PosFrom.Y) / (PosTo.X - PosFrom.X));
    1669           if Sign(PosTo.X - PosFrom.X) = -1 then Angle := Angle + Pi;
    1670           ArrowCenter := View.CellToCanvasPos(Point(Trunc(PosFrom.X + (PosTo.X - PosFrom.X) / 3),
    1671             Trunc(PosFrom.Y + (PosTo.Y - PosFrom.Y) / 3)));
    1672           DrawArrow(Canvas, View, ArrowCenter,
    1673             Angle, IntToStr(TUnitMove(Cell.MovesFrom[I]).CountOnce));
    1674         end;
    16751681      end;
     1682
     1683    end;
     1684
     1685    // Draw arrows
     1686    Pen.Color := clCream;
     1687    for I := 0 to Game.Moves.Count - 1 do begin
     1688      Move := TUnitMove(Game.Moves[I]);
     1689      PosFrom := CellToPos(Move.CellFrom);
     1690      PosTo := CellToPos(Move.CellTo);
     1691      if Move.CountRepeat > 0 then Pen.Width := 2
     1692        else Pen.Width := 1;
     1693      Angle := ArcTan((PosTo.Y - PosFrom.Y) / (PosTo.X - PosFrom.X));
     1694      if Sign(PosTo.X - PosFrom.X) = -1 then Angle := Angle + Pi;
     1695      ArrowCenter := View.CellToCanvasPos(Point(Trunc(PosFrom.X + (PosTo.X - PosFrom.X) / 2),
     1696        Trunc(PosFrom.Y + (PosTo.Y - PosFrom.Y) / 2)));
     1697      DrawArrow(Canvas, View, ArrowCenter,
     1698        Angle, IntToStr(Move.CountOnce));
    16761699    end;
    16771700  finally
Note: See TracChangeset for help on using the changeset viewer.