- Timestamp:
- Sep 20, 2018, 4:39:37 PM (6 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormClient.pas
r236 r237 217 217 end; 218 218 end; 219 for Y := 0 to CountP.Y do begin 220 for X := 0 to CountP.X do begin 221 TempView.Assign(View); 222 TempView.DestRect := TRect.Create( 223 TPoint.Create( 224 -StartP.X + R.Size.X * X, 225 -StartP.Y + R.Size.Y * Y 226 ), 227 TPoint.Create( 228 -StartP.X + R.Size.X * X + View.DestRect.Size.X, 229 -StartP.Y + R.Size.Y * Y + View.DestRect.Size.Y 230 ) 231 ); 232 Client.DrawArrows(PaintBox1.Canvas, TempView); 233 end; 234 end; 219 235 TempView.Free; 220 236 end else 221 237 Client.Paint(PaintBox1.Canvas, View); 238 Client.DrawArrows(PaintBox1.Canvas, View); 222 239 end; 223 240 end; -
trunk/UClientGUI.pas
r236 r237 50 50 procedure PaintMapCell(Canvas: TCanvas; Pos: TPoint; Text: string; View: TView; 51 51 Cell: TCell); 52 procedure DrawArrows(Canvas: TCanvas; View: TView); 53 procedure DrawCells(Canvas: TCanvas; View: TView); 54 procedure DrawCellLinks(Canvas: TCanvas; View: TView); 55 procedure DrawNeighborLinks(Canvas: TCanvas; View: TView); 52 56 procedure Paint(Canvas: TCanvas; View: TView); 53 57 constructor Create; override; … … 64 68 65 69 procedure TClientGUI.Paint(Canvas: TCanvas; View: TView); 70 begin 71 DrawCellLinks(Canvas, View); 72 DrawCells(Canvas, View); 73 if TGame(Game).DevelMode then DrawNeighborLinks(Canvas, View); 74 //DrawArrows(Canvas, View); 75 end; 76 77 constructor TClientGUI.Create; 78 begin 79 inherited; 80 View := TView.Create; 81 end; 82 83 destructor TClientGUI.Destroy; 84 begin 85 FreeAndNil(View); 86 inherited Destroy; 87 end; 88 89 procedure TClientGUI.SetGame(AValue: TGame); 90 begin 91 inherited; 92 View.Game := AValue; 93 end; 94 95 procedure TClientGUI.PaintCell(Canvas: TCanvas; Pos: TPoint; Text: string; 96 View: TView; Cell: TPlayerCell); 66 97 var 67 98 I: Integer; 68 Cell: TPlayerCell; 69 MapCell: TCell; 99 TextPos: TPoint; 100 Points: array of Classes.TPoint; 101 TextSize: TSize; 102 begin 103 if Cell.MapCell.Extra = etObjectiveTarget then begin 104 Text := Text + '!'; 105 end; 106 with Canvas do begin 107 if Assigned(View.FocusedCell) and (View.FocusedCell = Cell) then begin 108 Pen.Color := clYellow; 109 Pen.Style := psSolid; 110 Pen.Width := 1; 111 end else 112 if Cell.MapCell.Terrain = ttCity then begin 113 // Cannot set clear border as it will display shifted on gtk2 114 //Pen.Style := psClear; 115 Pen.Color := clBlack; 116 Pen.Style := psSolid; 117 Pen.Width := 3; 118 end else begin 119 // Cannot set clear border as it will display shifted on gtk2 120 //Pen.Style := psClear; 121 Pen.Color := Brush.Color; 122 Pen.Style := psSolid; 123 Pen.Width := 0; 124 end; 125 // Transform view 126 SetLength(Points, Length(Cell.MapCell.Polygon.Points)); 127 for I := 0 to Length(Points) - 1 do 128 Points[I] := PointToStdPoint(View.CellToCanvasPos(Cell.MapCell.Polygon.Points[I])); 129 Brush.Style := bsSolid; 130 //Polygon(Points, False, 0, Length(Points)); 131 TCanvasEx.PolygonEx(Canvas, Points, False); 132 //MoveTo(Points[0].X, Points[0].Y); 133 //LineTo(Points[1].X, Points[1].Y); 134 135 // Show cell text 136 if (Cell.GetAvialPower <> 0) or (Cell.MapCell.Extra = etObjectiveTarget) then begin 137 Pen.Style := psSolid; 138 Font.Color := clWhite; 139 Brush.Style := bsClear; 140 Font.Size := Trunc(42 * View.Zoom); 141 TextPos := View.CellToCanvasPos(Pos); 142 TextSize := TextExtent(Text); 143 TCanvasEx.TextOutEx(Canvas, Round(TextPos.X) - TextSize.cx div 2, 144 Round(TextPos.Y) - TextSize.cy div 2, Text, False); 145 end; 146 end; 147 end; 148 149 procedure TClientGUI.PaintMapCell(Canvas: TCanvas; Pos: TPoint; Text: string; 150 View: TView; Cell: TCell); 151 var 152 I: Integer; 153 TextPos: TPoint; 154 Points: array of Classes.TPoint; 155 TextSize: TSize; 156 begin 157 if Cell.Extra = etObjectiveTarget then begin 158 Text := Text + '!'; 159 end; 160 with Canvas do begin 161 if Assigned(View.FocusedCell) and (View.FocusedCell.MapCell = Cell) then begin 162 Pen.Color := clYellow; 163 Pen.Style := psSolid; 164 Pen.Width := 1; 165 end else 166 if Cell.Terrain = ttCity then begin 167 // Cannot set clear border as it will display shifted on gtk2 168 //Pen.Style := psClear; 169 Pen.Color := clBlack; 170 Pen.Style := psSolid; 171 Pen.Width := 3; 172 end else begin 173 // Cannot set clear border as it will display shifted on gtk2 174 //Pen.Style := psClear; 175 Pen.Color := Brush.Color; 176 Pen.Style := psSolid; 177 Pen.Width := 0; 178 end; 179 // Transform view 180 SetLength(Points, Length(Cell.Polygon.Points)); 181 for I := 0 to Length(Points) - 1 do 182 Points[I] := PointToStdPoint(View.CellToCanvasPos(Cell.Polygon.Points[I])); 183 Brush.Style := bsSolid; 184 //Polygon(Points, False, 0, Length(Points)); 185 TCanvasEx.PolygonEx(Canvas, Points, False); 186 //MoveTo(Points[0].X, Points[0].Y); 187 //LineTo(Points[1].X, Points[1].Y); 188 189 // Show cell text 190 if (Cell.Power <> 0) or (Cell.Extra = etObjectiveTarget) then begin 191 Pen.Style := psSolid; 192 Font.Color := clWhite; 193 Brush.Style := bsClear; 194 Font.Size := Trunc(42 * View.Zoom); 195 TextPos := View.CellToCanvasPos(Pos); 196 TextSize := TextExtent(Text); 197 TCanvasEx.TextOutEx(Canvas, Round(TextPos.X) - TextSize.cx div 2, 198 Round(TextPos.Y) - TextSize.cy div 2, Text, False); 199 end; 200 end; 201 end; 202 203 procedure TClientGUI.DrawArrows(Canvas: TCanvas; View: TView); 204 var 70 205 PosFrom, PosTo: TPoint; 71 206 Angle: Double; 72 207 ArrowCenter: TPoint; 73 208 Move: TUnitMove; 209 P: TPoint; 210 begin 211 with Canvas, View do begin 212 Pen.Color := clCream; 213 if Assigned(ControlPlayer) then 214 for Move in ControlPlayer.Moves do begin 215 PosFrom := TGame(Game).Map.CellToPos(Move.CellFrom.MapCell); 216 PosTo := TGame(Game).Map.CellToPos(Move.CellTo.MapCell); 217 if TGame(Game).Map.Cyclic then begin 218 P := TPoint.Create(PosTo.X + TGame(Game).Map.PixelRect.Size.X, 219 PosTo.Y); 220 if TLine.Create(PosFrom, PosTo).Distance > TLine.Create(PosFrom, P).Distance then 221 PosTo := TPoint.Create(P.X, PosTo.Y); 222 P := TPoint.Create(PosTo.X, PosTo.Y + TGame(Game).Map.PixelRect.Size.Y); 223 if TLine.Create(PosFrom, PosTo).Distance > TLine.Create(PosFrom, P).Distance then 224 PosTo := TPoint.Create(PosTo.X, P.Y); 225 P := TPoint.Create(PosTo.X - TGame(Game).Map.PixelRect.Size.X, 226 PosTo.Y); 227 if TLine.Create(PosFrom, PosTo).Distance > TLine.Create(PosFrom, P).Distance then 228 PosTo := TPoint.Create(P.X, PosTo.Y); 229 P := TPoint.Create(PosTo.X, PosTo.Y - TGame(Game).Map.PixelRect.Size.Y); 230 if TLine.Create(PosFrom, PosTo).Distance > TLine.Create(PosFrom, P).Distance then 231 PosTo := TPoint.Create(PosTo.X, P.Y); 232 end; 233 // In Fog of war mode show only 234 if TGame(Game).FogOfWar and not ControlPlayer.PlayerMap.Cells.SearchCell(Move.CellFrom.MapCell).InVisibleRange and 235 not ControlPlayer.PlayerMap.Cells.SearchCell(Move.CellTo.MapCell).InVisibleRange then 236 Continue; 237 if Move.CountRepeat > 0 then Pen.Width := 2 238 else Pen.Width := 1; 239 Angle := ArcTan((PosTo.Y - PosFrom.Y) / (PosTo.X - PosFrom.X)); 240 if (Angle > +Pi) or (Angle < -Pi) then 241 raise Exception.Create(Format(SWrongArrowAngle, [FloatToStr(Angle)])); 242 243 if Sign(PosTo.X - PosFrom.X) = -1 then Angle := Angle + Pi; 244 ArrowCenter := View.CellToCanvasPos(TPoint.Create(Trunc(PosFrom.X + (PosTo.X - PosFrom.X) / 2), 245 Trunc(PosFrom.Y + (PosTo.Y - PosFrom.Y) / 2))); 246 TGame(Game).Map.DrawArrow(Canvas, ArrowCenter, 247 Angle, IntToStr(Move.CountOnce), View.Zoom); 248 end; 249 end; 250 end; 251 252 procedure TClientGUI.DrawCells(Canvas: TCanvas; View: TView); 253 var 254 Cell: TPlayerCell; 255 MapCell: TCell; 74 256 CellText: string; 75 CellLink: TCellLink; 76 NeighCell: TCell; 77 begin 78 with Canvas, View do 79 try 80 Lock; 81 // Draw cell links 82 Pen.Color := clBlack; 83 Pen.Style := psSolid; 84 Pen.Width := 3; 85 for CellLink in TGame(Game).Map.CellLinks do 86 with CellLink do begin 87 if Length(Points) >= 2 then begin 88 MoveTo(PointToStdPoint(View.CellToCanvasPos(Points[0]))); 89 for I := 1 to Length(Points) - 1 do 90 LineTo(PointToStdPoint(View.CellToCanvasPos(Points[I]))); 91 end; 92 end; 93 94 // Draw cells 257 begin 258 with Canvas, View do begin 95 259 if Assigned(ControlPlayer) then begin 96 260 for Cell in ControlPlayer.PlayerMap.Cells do begin … … 132 296 end; 133 297 end; 134 135 // Draw links to neighbors 136 if TGame(Game).DevelMode then 298 end; 299 end; 300 301 procedure TClientGUI.DrawCellLinks(Canvas: TCanvas; View: TView); 302 var 303 I: Integer; 304 CellLink: TCellLink; 305 begin 306 with Canvas, View do begin 307 Pen.Color := clBlack; 308 Pen.Style := psSolid; 309 Pen.Width := 3; 310 for CellLink in TGame(Game).Map.CellLinks do 311 with CellLink do begin 312 if Length(Points) >= 2 then begin 313 MoveTo(PointToStdPoint(View.CellToCanvasPos(Points[0]))); 314 for I := 1 to Length(Points) - 1 do 315 LineTo(PointToStdPoint(View.CellToCanvasPos(Points[I]))); 316 end; 317 end; 318 end; 319 end; 320 321 procedure TClientGUI.DrawNeighborLinks(Canvas: TCanvas; View: TView); 322 var 323 Cell: TPlayerCell; 324 C: TCell; 325 begin 326 with Canvas, View do begin 137 327 for Cell in ControlPlayer.PlayerMap.Cells do begin 138 for NeighCellin Cell.MapCell.Neighbors do begin328 for C in Cell.MapCell.Neighbors do begin 139 329 Pen.Color := clYellow; 140 330 MoveTo(PointToStdPoint(View.CellToCanvasPos(Cell.MapCell.PosPx))); 141 LineTo(PointToStdPoint(View.CellToCanvasPos( NeighCell.PosPx)));331 LineTo(PointToStdPoint(View.CellToCanvasPos(C.PosPx))); 142 332 end; 143 333 … … 146 336 TextOut(View.CellToCanvasPos(Cell.MapCell.PosPx).X, 147 337 View.CellToCanvasPos(Cell.MapCell.PosPx).Y, IntToStr(Cell.MapCell.Id)); 148 end;149 150 // Draw arrows151 Pen.Color := clCream;152 if Assigned(ControlPlayer) then153 for Move in ControlPlayer.Moves do begin154 PosFrom := TGame(Game).Map.CellToPos(Move.CellFrom.MapCell);155 PosTo := TGame(Game).Map.CellToPos(Move.CellTo.MapCell);156 // In Fog of war mode show only157 if TGame(Game).FogOfWar and not ControlPlayer.PlayerMap.Cells.SearchCell(Move.CellFrom.MapCell).InVisibleRange and158 not ControlPlayer.PlayerMap.Cells.SearchCell(Move.CellTo.MapCell).InVisibleRange then159 Continue;160 if Move.CountRepeat > 0 then Pen.Width := 2161 else Pen.Width := 1;162 Angle := ArcTan((PosTo.Y - PosFrom.Y) / (PosTo.X - PosFrom.X));163 if (Angle > +Pi) or (Angle < -Pi) then164 raise Exception.Create(Format(SWrongArrowAngle, [FloatToStr(Angle)]));165 166 if Sign(PosTo.X - PosFrom.X) = -1 then Angle := Angle + Pi;167 ArrowCenter := View.CellToCanvasPos(TPoint.Create(Trunc(PosFrom.X + (PosTo.X - PosFrom.X) / 2),168 Trunc(PosFrom.Y + (PosTo.Y - PosFrom.Y) / 2)));169 TGame(Game).Map.DrawArrow(Canvas, ArrowCenter,170 Angle, IntToStr(Move.CountOnce), View.Zoom);171 end;172 finally173 Unlock;174 end;175 end;176 177 constructor TClientGUI.Create;178 begin179 inherited;180 View := TView.Create;181 end;182 183 destructor TClientGUI.Destroy;184 begin185 FreeAndNil(View);186 inherited Destroy;187 end;188 189 procedure TClientGUI.SetGame(AValue: TGame);190 begin191 inherited;192 View.Game := AValue;193 end;194 195 procedure TClientGUI.PaintCell(Canvas: TCanvas; Pos: TPoint; Text: string;196 View: TView; Cell: TPlayerCell);197 var198 I: Integer;199 TextPos: TPoint;200 Points: array of Classes.TPoint;201 TextSize: TSize;202 begin203 if Cell.MapCell.Extra = etObjectiveTarget then begin204 Text := Text + '!';205 end;206 with Canvas do begin207 if Assigned(View.FocusedCell) and (View.FocusedCell = Cell) then begin208 Pen.Color := clYellow;209 Pen.Style := psSolid;210 Pen.Width := 1;211 end else212 if Cell.MapCell.Terrain = ttCity then begin213 // Cannot set clear border as it will display shifted on gtk2214 //Pen.Style := psClear;215 Pen.Color := clBlack;216 Pen.Style := psSolid;217 Pen.Width := 3;218 end else begin219 // Cannot set clear border as it will display shifted on gtk2220 //Pen.Style := psClear;221 Pen.Color := Brush.Color;222 Pen.Style := psSolid;223 Pen.Width := 0;224 end;225 // Transform view226 SetLength(Points, Length(Cell.MapCell.Polygon.Points));227 for I := 0 to Length(Points) - 1 do228 Points[I] := PointToStdPoint(View.CellToCanvasPos(Cell.MapCell.Polygon.Points[I]));229 Brush.Style := bsSolid;230 //Polygon(Points, False, 0, Length(Points));231 TCanvasEx.PolygonEx(Canvas, Points, False);232 //MoveTo(Points[0].X, Points[0].Y);233 //LineTo(Points[1].X, Points[1].Y);234 235 // Show cell text236 if (Cell.GetAvialPower <> 0) or (Cell.MapCell.Extra = etObjectiveTarget) then begin237 Pen.Style := psSolid;238 Font.Color := clWhite;239 Brush.Style := bsClear;240 Font.Size := Trunc(42 * View.Zoom);241 TextPos := View.CellToCanvasPos(Pos);242 TextSize := TextExtent(Text);243 TCanvasEx.TextOutEx(Canvas, Round(TextPos.X) - TextSize.cx div 2,244 Round(TextPos.Y) - TextSize.cy div 2, Text, False);245 end;246 end;247 end;248 249 procedure TClientGUI.PaintMapCell(Canvas: TCanvas; Pos: TPoint; Text: string;250 View: TView; Cell: TCell);251 var252 I: Integer;253 TextPos: TPoint;254 Points: array of Classes.TPoint;255 TextSize: TSize;256 begin257 if Cell.Extra = etObjectiveTarget then begin258 Text := Text + '!';259 end;260 with Canvas do begin261 if Assigned(View.FocusedCell) and (View.FocusedCell.MapCell = Cell) then begin262 Pen.Color := clYellow;263 Pen.Style := psSolid;264 Pen.Width := 1;265 end else266 if Cell.Terrain = ttCity then begin267 // Cannot set clear border as it will display shifted on gtk2268 //Pen.Style := psClear;269 Pen.Color := clBlack;270 Pen.Style := psSolid;271 Pen.Width := 3;272 end else begin273 // Cannot set clear border as it will display shifted on gtk2274 //Pen.Style := psClear;275 Pen.Color := Brush.Color;276 Pen.Style := psSolid;277 Pen.Width := 0;278 end;279 // Transform view280 SetLength(Points, Length(Cell.Polygon.Points));281 for I := 0 to Length(Points) - 1 do282 Points[I] := PointToStdPoint(View.CellToCanvasPos(Cell.Polygon.Points[I]));283 Brush.Style := bsSolid;284 //Polygon(Points, False, 0, Length(Points));285 TCanvasEx.PolygonEx(Canvas, Points, False);286 //MoveTo(Points[0].X, Points[0].Y);287 //LineTo(Points[1].X, Points[1].Y);288 289 // Show cell text290 if (Cell.Power <> 0) or (Cell.Extra = etObjectiveTarget) then begin291 Pen.Style := psSolid;292 Font.Color := clWhite;293 Brush.Style := bsClear;294 Font.Size := Trunc(42 * View.Zoom);295 TextPos := View.CellToCanvasPos(Pos);296 TextSize := TextExtent(Text);297 TCanvasEx.TextOutEx(Canvas, Round(TextPos.X) - TextSize.cx div 2,298 Round(TextPos.Y) - TextSize.cy div 2, Text, False);299 338 end; 300 339 end;
Note:
See TracChangeset
for help on using the changeset viewer.