Changeset 404
- Timestamp:
- Jan 6, 2025, 10:21:08 PM (45 hours ago)
- Location:
- trunk
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ClientGUI.pas
r377 r404 5 5 uses 6 6 Types, Classes, SysUtils, Graphics, GameClient, Player, Map, Game, Geometry, 7 Math ;7 Math, View; 8 8 9 9 type 10 { TView }11 12 TView = class13 private14 FDestRect: TRect;15 FZoom: Double;16 procedure SetDestRect(AValue: TRect);17 procedure SetZoom(AValue: Double);18 public19 Game: TObject; // TGame;20 SourceRect: TRect;21 FocusedCell: TPlayerCell;22 SelectedCell: TPlayerCell;23 procedure Clear;24 function IsCellVisible(Cell: TCell): Boolean;25 constructor Create;26 destructor Destroy; override;27 procedure SelectCell(Pos: TPoint; Player: TPlayer; ShiftState: TShiftState);28 procedure CenterMap;29 procedure CenterPlayerCity(Player: TPlayer);30 procedure ZoomAll;31 function CanvasToCellPos(Pos: TPoint): TPoint;32 function CellToCanvasPos(Pos: TPoint): TPoint;33 function CellToCanvasPosF(Pos: TPointF): TPointF;34 function CanvasToCellRect(Pos: TRect): TRect;35 function CellToCanvasRect(Pos: TRect): TRect;36 function CellToCanvasRectF(Pos: TRectF): TRectF;37 procedure Assign(Source: TView);38 property DestRect: TRect read FDestRect write SetDestRect;39 property Zoom: Double read FZoom write SetZoom;40 end;41 42 10 { TClientGUI } 43 11 … … 73 41 74 42 resourcestring 75 SZeroZoomNotAlowed = 'Zero zoom not allowed';76 43 SWrongArrowAngle = 'Wrong arrow angle %s'; 77 44 … … 521 488 end; 522 489 523 { TView }524 525 procedure TView.SetZoom(AValue: Double);526 begin527 if FZoom = AValue then Exit;528 if AValue = 0 then529 raise Exception.Create(SZeroZoomNotAlowed);530 FZoom := AValue;531 SourceRect := TRect.CreateBounds(TPoint.Create(Trunc(SourceRect.P1.X + SourceRect.Size.X div 2 - DestRect.Size.X / Zoom / 2),532 Trunc(SourceRect.P1.Y + SourceRect.Size.Y div 2 - DestRect.Size.Y / Zoom / 2)),533 TPoint.Create(Trunc(DestRect.Size.X / Zoom),534 Trunc(DestRect.Size.Y / Zoom)));535 end;536 537 procedure TView.Clear;538 begin539 FocusedCell := nil;540 SelectedCell := nil;541 end;542 543 procedure TView.SetDestRect(AValue: TRect);544 var545 Diff: TPoint;546 begin547 if FDestRect = AValue then Exit;548 Diff := TPoint.Create(Trunc(DestRect.Size.X / Zoom - AValue.Size.X / Zoom) div 2,549 Trunc(DestRect.Size.Y / Zoom - AValue.Size.Y / Zoom) div 2);550 FDestRect := AValue;551 SourceRect := TRect.CreateBounds(TPoint.Create(SourceRect.P1.X + Diff.X, SourceRect.P1.Y + Diff.Y),552 TPoint.Create(Trunc(DestRect.Size.X / Zoom),553 Trunc(DestRect.Size.Y / Zoom)));554 end;555 556 constructor TView.Create;557 begin558 Zoom := 1.5;559 Clear;560 end;561 562 destructor TView.Destroy;563 begin564 inherited;565 end;566 567 function TView.CanvasToCellPos(Pos: TPoint): TPoint;568 begin569 Result := TPoint.Create(Trunc((Pos.X - DestRect.P1.X) / Zoom + SourceRect.P1.X),570 Trunc((Pos.Y - DestRect.P1.Y) / Zoom + SourceRect.P1.Y));571 end;572 573 function TView.CellToCanvasPos(Pos: TPoint): TPoint;574 begin575 Result := TPoint.Create(Trunc((Pos.X - SourceRect.P1.X) * Zoom) + DestRect.P1.X,576 Trunc((Pos.Y - SourceRect.P1.Y) * Zoom) + DestRect.P1.Y);577 end;578 579 function TView.CellToCanvasPosF(Pos: TPointF): TPointF;580 begin581 Result := TPointF.Create((Pos.X - SourceRect.P1.X) * Zoom + DestRect.P1.X,582 (Pos.Y - SourceRect.P1.Y) * Zoom + DestRect.P1.Y);583 end;584 585 function TView.CanvasToCellRect(Pos: TRect): TRect;586 begin587 Result.P1 := CanvasToCellPos(Pos.P1);588 Result.P2 := CanvasToCellPos(Pos.P2);589 end;590 591 function TView.CellToCanvasRect(Pos: TRect): TRect;592 begin593 Result.P1 := CellToCanvasPos(Pos.P1);594 Result.P2 := CellToCanvasPos(Pos.P2);595 end;596 597 function TView.CellToCanvasRectF(Pos: TRectF): TRectF;598 begin599 Result.P1 := CellToCanvasPosF(Pos.P1);600 Result.P2 := CellToCanvasPosF(Pos.P2);601 end;602 603 procedure TView.Assign(Source: TView);604 begin605 SourceRect := Source.SourceRect;606 FDestRect := Source.DestRect;607 FZoom := Source.Zoom;608 SelectedCell := Source.SelectedCell;609 FocusedCell := Source.FocusedCell;610 end;611 612 procedure TView.SelectCell(Pos: TPoint; Player: TPlayer; ShiftState: TShiftState);613 var614 NewSelectedCell: TPlayerCell;615 UnitMove: TUnitMove;616 I: Integer;617 CellPos: TPoint;618 R: TRect;619 begin620 if TGame(Game).Map.Cyclic then begin621 R := CellToCanvasRect(TGame(Game).Map.PixelRect);622 CellPos := TPoint.Create(623 ModNeg(Pos.X - R.P1.X, R.Size.X) + R.P1.X,624 ModNeg(Pos.Y - R.P1.Y, R.Size.Y) + R.P1.Y625 );626 NewSelectedCell := Player.PlayerMap.PosToCell(627 CanvasToCellPos(CellPos));628 end else begin629 NewSelectedCell := Player.PlayerMap.PosToCell(630 CanvasToCellPos(Pos));631 end;632 if Assigned(NewSelectedCell) then begin633 if Assigned(SelectedCell) and (NewSelectedCell <> SelectedCell) and634 TGame(Game).CurrentPlayer.IsAllowedMoveTarget(SelectedCell, NewSelectedCell) then begin635 if ssShift in ShiftState then begin636 // Make maximum unit move without confirmation dialog637 for I := SelectedCell.MovesFrom.Count - 1 downto 0 do begin638 Player.Moves.Remove(SelectedCell.MovesFrom[I]);639 end;640 TGame(Game).CurrentPlayer.SetMove(SelectedCell, NewSelectedCell, SelectedCell.MapCell.OneUnit.Power, False);641 SelectedCell := nil;642 end else643 if ssCtrl in ShiftState then begin644 // If CTRL key pressed then storno all moved from selected cell and645 // move all power to new selected cell646 for I := SelectedCell.MovesFrom.Count - 1 downto 0 do647 Player.Moves.Remove(SelectedCell.MovesFrom[I]);648 UnitMove := TGame(Game).CurrentPlayer.SetMove(SelectedCell, NewSelectedCell, SelectedCell.MapCell.OneUnit.Power, False);649 if Assigned(UnitMove) then650 UnitMove.CountRepeat := TGame(Player.Game).Map.MaxPower;651 if NewSelectedCell.MapCell.Player = Player then SelectedCell := NewSelectedCell652 else SelectedCell := nil;653 end else begin654 TGame(Game).CurrentPlayer.SetMove(SelectedCell, NewSelectedCell, SelectedCell.MapCell.OneUnit.Power);655 SelectedCell := nil;656 end;657 end else658 if not Assigned(SelectedCell) and (NewSelectedCell <> SelectedCell) and (NewSelectedCell.MapCell.Player = Player) then begin659 SelectedCell := NewSelectedCell660 end else661 if (NewSelectedCell = SelectedCell) and (NewSelectedCell.MapCell.Player = Player) then begin662 SelectedCell := nil;663 end;664 end;665 end;666 667 procedure TView.CenterMap;668 var669 MapRect: TRect;670 begin671 MapRect := TGame(Game).Map.PixelRect;672 SourceRect := TRect.CreateBounds(TPoint.Create(MapRect.P1.X + MapRect.Size.X div 2 - SourceRect.Size.X div 2,673 MapRect.P1.Y + MapRect.Size.Y div 2 - SourceRect.Size.Y div 2),674 TPoint.Create(SourceRect.Size.X,675 SourceRect.Size.Y));676 end;677 678 procedure TView.CenterPlayerCity(Player: TPlayer);679 begin680 SourceRect := TRect.CreateBounds(TPoint.Create(Player.StartCell.PosPx.X - SourceRect.Size.X div 2,681 Player.StartCell.PosPx.Y - SourceRect.Size.Y div 2),682 TPoint.Create(SourceRect.Size.X,683 SourceRect.Size.Y));684 end;685 686 procedure TView.ZoomAll;687 var688 Factor: TPointF;689 MapRect: TRect;690 NewZoom: Single;691 begin692 MapRect := TGame(Game).Map.CalculatePixelRect;693 Factor := TPointF.Create(DestRect.Size.X / MapRect.Size.X,694 DestRect.Size.Y / MapRect.Size.Y);695 if Factor.X < Factor.Y then NewZoom := Factor.X696 else NewZoom := Factor.Y;697 if NewZoom = 0 then NewZoom := 1;698 Zoom := NewZoom * 0.9;699 CenterMap;700 end;701 702 function TView.IsCellVisible(Cell: TCell): Boolean;703 var704 RectPolygon: TRect;705 begin706 RectPolygon := CellToCanvasRect(Cell.Polygon.GetRect);707 Result := (708 (RectPolygon.P1.X < DestRect.Size.X) and709 (RectPolygon.P2.X > 0) and710 (RectPolygon.P1.Y < DestRect.Size.Y) and711 (RectPolygon.P2.Y > 0)712 );713 end;714 715 490 end. 716 491 -
trunk/Forms/FormClient.pas
r375 r404 7 7 Game, LCLType, Menus, ActnList, ComCtrls, dateutils, XMLConf, DOM, Math, 8 8 Geometry, GameClient, GameProtocol, Threading, Player, ClientGUI, FormEx, 9 Generics.Collections ;9 Generics.Collections, View; 10 10 11 11 const … … 75 75 FClient: TClientGUI; 76 76 TempBitmap: TBitmap; 77 TempView: TView; 77 78 StartMousePoint: TPoint; 78 79 StartViewPoint: TPoint; … … 186 187 CountP: TPoint; 187 188 X, Y: Integer; 188 TempView: TView;189 189 begin 190 190 DrawStart := Now; … … 205 205 206 206 if Game.CyclicMap then begin 207 TempView := TView.Create;208 207 TempView.Game := Game; 209 208 //R := View.CellToCanvasRect(TRect.Create(Game.Map.Cells.First.PosPx, … … 278 277 end; 279 278 end; 280 TempView.Free;281 279 for Y := 0 to CountP.Y do begin 282 280 for X := 0 to CountP.X do begin … … 432 430 //DoubleBuffered := True; 433 431 TempBitmap := TBitmap.Create; 432 TempView := TView.Create; 434 433 TimerPeriod := 0; 435 434 LastTimerTime := Now; … … 518 517 begin 519 518 Client := nil; 520 TempBitmap.Free; 519 FreeAndNil(TempBitmap); 520 FreeAndNil(TempView); 521 521 end; 522 522 -
trunk/Languages/xtactics.cs.po
r401 r404 10 10 "Content-Type: text/plain; charset=UTF-8\n" 11 11 "Content-Transfer-Encoding: 8bit\n" 12 "X-Generator: Poedit 3. 5\n"12 "X-Generator: Poedit 3.4.2\n" 13 13 14 14 #: building.sbonusattack … … 62 62 msgid "Wrong arrow angle %s" 63 63 msgstr "Nesprávný úhel šipky %s" 64 65 #: clientgui.szerozoomnotalowed66 msgctxt "clientgui.szerozoomnotalowed"67 msgid "Zero zoom not allowed"68 msgstr "Nulové přiblížení není povoleno"69 64 70 65 #: core.sendgame … … 1258 1253 msgstr "Dohled" 1259 1254 1255 #: view.szerozoomnotalowed 1256 msgctxt "view.szerozoomnotalowed" 1257 msgid "Zero zoom not allowed" 1258 msgstr "Nulové přiblížení není povoleno" -
trunk/Languages/xtactics.pot
r362 r404 51 51 msgctxt "clientgui.swrongarrowangle" 52 52 msgid "Wrong arrow angle %s" 53 msgstr ""54 55 #: clientgui.szerozoomnotalowed56 msgctxt "clientgui.szerozoomnotalowed"57 msgid "Zero zoom not allowed"58 53 msgstr "" 59 54 … … 1221 1216 msgstr "" 1222 1217 1218 #: view.szerozoomnotalowed 1219 msgctxt "view.szerozoomnotalowed" 1220 msgid "Zero zoom not allowed" 1221 msgstr "" 1222 -
trunk/xtactics.lpi
r375 r404 114 114 </Item7> 115 115 </RequiredPackages> 116 <Units Count="3 6">116 <Units Count="37"> 117 117 <Unit0> 118 118 <Filename Value="xtactics.lpr"/> … … 301 301 <IsPartOfProject Value="True"/> 302 302 </Unit35> 303 <Unit36> 304 <Filename Value="View.pas"/> 305 <IsPartOfProject Value="True"/> 306 </Unit36> 303 307 </Units> 304 308 </ProjectOptions> -
trunk/xtactics.lpr
r340 r404 9 9 { you can add units after this }, 10 10 SysUtils, FormMain, CoolStreaming, Tests, TurnStats, UnitKind, 11 PinConnectionPackage ;11 PinConnectionPackage, View; 12 12 13 13 {$R *.res}
Note:
See TracChangeset
for help on using the changeset viewer.