- Timestamp:
- Nov 28, 2020, 11:27:11 AM (4 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/UMetaCanvas.pas
r62 r67 148 148 procedure Pie(EllipseX1, EllipseY1, EllipseX2, EllipseY2, 149 149 StartX, StartY, EndX, EndY: Integer); override; 150 procedure SetSize(Size: TPoint);151 150 procedure Reset; 152 151 procedure DrawTo(Canvas: TCanvas); … … 155 154 constructor Create; 156 155 destructor Destroy; override; 156 property Size: TPoint read FSize write FSize; 157 157 end; 158 158 … … 622 622 end; 623 623 624 procedure TMetaCanvas.SetSize(Size: TPoint);625 begin626 FSize := Size;627 end;628 629 624 procedure TMetaCanvas.Reset; 630 625 begin -
trunk/UEngine.pas
r66 r67 293 293 MenuGame: TMenu; 294 294 ButtonBack: TMenuItemButton; 295 LastState: TGameState; 295 296 function GetServedDaysCount: Integer; 296 297 procedure ResizeView; … … 305 306 procedure DrawTrains(Canvas: TCanvas); 306 307 procedure DrawGameOver(Canvas: TCanvas); 308 procedure DrawStationPassengerOverload(Canvas: TCanvas); 309 procedure DrawLines(Canvas: TCanvas); 310 procedure DrawStations(Canvas: TCanvas); 311 procedure DrawGameControls(Canvas: TCanvas); 307 312 procedure ComputeShapeDistance; 308 313 procedure ComputeShapeDistanceStation(Station: TMapStation; … … 356 361 destructor Destroy; override; 357 362 procedure Tick; 358 procedure Paint( TargetCanvas: TCanvas);363 procedure Paint(Canvas: TCanvas); 359 364 property Time: TDateTime read FTime; 360 365 property DarkMode: Boolean read FDarkMode write SetDarkMode; … … 1461 1466 case Shape of 1462 1467 ssSquare: begin 1463 SetLength(Points, 4); 1464 Points[0] := Point(Position.X - Size div 2, Position.Y - Size div 2); 1465 Points[1] := Point(Position.X + Size div 2, Position.Y - Size div 2); 1466 Points[2] := Point(Position.X + Size div 2, Position.Y + Size div 2); 1467 Points[3] := Point(Position.X - Size div 2, Position.Y + Size div 2); 1468 Points := [ 1469 Point(Position.X - Size div 2, Position.Y - Size div 2), 1470 Point(Position.X + Size div 2, Position.Y - Size div 2), 1471 Point(Position.X + Size div 2, Position.Y + Size div 2), 1472 Point(Position.X - Size div 2, Position.Y + Size div 2) 1473 ]; 1468 1474 Points := RotatePoints(Position, Points, Angle); 1469 1475 Canvas.Polygon(Points); … … 1473 1479 Position.X + Size div 2, Position.Y + Size div 2); 1474 1480 ssTriangle: begin 1475 SetLength(Points, 3); 1476 Points[0] := Point(Position.X, Position.Y - Size div 2); 1477 Points[1] := Point(Position.X + Size div 2, Position.Y + Size div 2); 1478 Points[2] := Point(Position.X - Size div 2, Position.Y + Size div 2); 1481 Points := [ 1482 Point(Position.X, Position.Y - Size div 2), 1483 Point(Position.X + Size div 2, Position.Y + Size div 2), 1484 Point(Position.X - Size div 2, Position.Y + Size div 2) 1485 ]; 1479 1486 Points := RotatePoints(Position, Points, Angle); 1480 1487 Canvas.Polygon(Points); … … 1495 1502 end; 1496 1503 ssPlus: begin 1497 SetLength(Points, 12); 1498 Points[0] := Point(Position.X + Size div 6, Position.Y - Size div 6); 1499 Points[1] := Point(Position.X + Size div 2, Position.Y - Size div 6); 1500 Points[2] := Point(Position.X + Size div 2, Position.Y + Size div 6); 1501 Points[3] := Point(Position.X + Size div 6, Position.Y + Size div 6); 1502 Points[4] := Point(Position.X + Size div 6, Position.Y + Size div 2); 1503 Points[5] := Point(Position.X - Size div 6, Position.Y + Size div 2); 1504 Points[6] := Point(Position.X - Size div 6, Position.Y + Size div 6); 1505 Points[7] := Point(Position.X - Size div 2, Position.Y + Size div 6); 1506 Points[8] := Point(Position.X - Size div 2, Position.Y - Size div 6); 1507 Points[9] := Point(Position.X - Size div 6, Position.Y - Size div 6); 1508 Points[10] := Point(Position.X - Size div 6, Position.Y - Size div 2); 1509 Points[11] := Point(Position.X + Size div 6, Position.Y - Size div 2); 1504 Points := [ 1505 Point(Position.X + Size div 6, Position.Y - Size div 6), 1506 Point(Position.X + Size div 2, Position.Y - Size div 6), 1507 Point(Position.X + Size div 2, Position.Y + Size div 6), 1508 Point(Position.X + Size div 6, Position.Y + Size div 6), 1509 Point(Position.X + Size div 6, Position.Y + Size div 2), 1510 Point(Position.X - Size div 6, Position.Y + Size div 2), 1511 Point(Position.X - Size div 6, Position.Y + Size div 6), 1512 Point(Position.X - Size div 2, Position.Y + Size div 6), 1513 Point(Position.X - Size div 2, Position.Y - Size div 6), 1514 Point(Position.X - Size div 6, Position.Y - Size div 6), 1515 Point(Position.X - Size div 6, Position.Y - Size div 2), 1516 Point(Position.X + Size div 6, Position.Y - Size div 2) 1517 ]; 1510 1518 Points := RotatePoints(Position, Points, Angle); 1511 1519 Canvas.Polygon(Points); … … 1532 1540 end; 1533 1541 ssDiamond: begin 1534 SetLength(Points, 4); 1535 Points[0] := Point(Position.X, Position.Y - Size div 2); 1536 Points[1] := Point(Position.X + Size div 2, Position.Y); 1537 Points[2] := Point(Position.X, Position.Y + Size div 2); 1538 Points[3] := Point(Position.X - Size div 2, Position.Y); 1542 Points := [ 1543 Point(Position.X, Position.Y - Size div 2), 1544 Point(Position.X + Size div 2, Position.Y), 1545 Point(Position.X, Position.Y + Size div 2), 1546 Point(Position.X - Size div 2, Position.Y) 1547 ]; 1539 1548 Points := RotatePoints(Position, Points, Angle); 1540 1549 Canvas.Polygon(Points); 1541 1550 end; 1542 1551 ssCross: begin 1543 SetLength(Points, 12); 1544 Points[0] := Point(Position.X + Size div 6, Position.Y - Size div 6); 1545 Points[1] := Point(Position.X + Size div 2, Position.Y - Size div 6); 1546 Points[2] := Point(Position.X + Size div 2, Position.Y + Size div 6); 1547 Points[3] := Point(Position.X + Size div 6, Position.Y + Size div 6); 1548 Points[4] := Point(Position.X + Size div 6, Position.Y + Size div 2); 1549 Points[5] := Point(Position.X - Size div 6, Position.Y + Size div 2); 1550 Points[6] := Point(Position.X - Size div 6, Position.Y + Size div 6); 1551 Points[7] := Point(Position.X - Size div 2, Position.Y + Size div 6); 1552 Points[8] := Point(Position.X - Size div 2, Position.Y - Size div 6); 1553 Points[9] := Point(Position.X - Size div 6, Position.Y - Size div 6); 1554 Points[10] := Point(Position.X - Size div 6, Position.Y - Size div 2); 1555 Points[11] := Point(Position.X + Size div 6, Position.Y - Size div 2); 1552 Points := [ 1553 Point(Position.X + Size div 6, Position.Y - Size div 6), 1554 Point(Position.X + Size div 2, Position.Y - Size div 6), 1555 Point(Position.X + Size div 2, Position.Y + Size div 6), 1556 Point(Position.X + Size div 6, Position.Y + Size div 6), 1557 Point(Position.X + Size div 6, Position.Y + Size div 2), 1558 Point(Position.X - Size div 6, Position.Y + Size div 2), 1559 Point(Position.X - Size div 6, Position.Y + Size div 6), 1560 Point(Position.X - Size div 2, Position.Y + Size div 6), 1561 Point(Position.X - Size div 2, Position.Y - Size div 6), 1562 Point(Position.X - Size div 6, Position.Y - Size div 6), 1563 Point(Position.X - Size div 6, Position.Y - Size div 2), 1564 Point(Position.X + Size div 6, Position.Y - Size div 2) 1565 ]; 1556 1566 Points := RotatePoints(Position, Points, Angle + Pi / 4); 1557 1567 Canvas.Polygon(Points); … … 1941 1951 procedure TEngine.MenuItemGameContinue(Sender: TObject); 1942 1952 begin 1943 State := gsRunning;1953 State := LastState; 1944 1954 end; 1945 1955 … … 2075 2085 begin 2076 2086 Menu := MenuGame; 2087 LastState := State; 2077 2088 State := gsMenu; 2078 2089 Redraw; … … 2134 2145 Angle := GetAngle; 2135 2146 2136 SetLength(Points, 4); 2137 Points[0] := RotatePoint(Pos, Point(Pos.X - TrainSize div 2, Pos.Y - TrainSize div 3), Angle); 2138 Points[1] := RotatePoint(Pos, Point(Pos.X + TrainSize div 2, Pos.Y - TrainSize div 3), Angle); 2139 Points[2] := RotatePoint(Pos, Point(Pos.X + TrainSize div 2, Pos.Y + TrainSize div 3), Angle); 2140 Points[3] := RotatePoint(Pos, Point(Pos.X - TrainSize div 2, Pos.Y + TrainSize div 3), Angle); 2147 Points := [ 2148 RotatePoint(Pos, Point(Pos.X - TrainSize div 2, Pos.Y - TrainSize div 3), Angle), 2149 RotatePoint(Pos, Point(Pos.X + TrainSize div 2, Pos.Y - TrainSize div 3), Angle), 2150 RotatePoint(Pos, Point(Pos.X + TrainSize div 2, Pos.Y + TrainSize div 3), Angle), 2151 RotatePoint(Pos, Point(Pos.X - TrainSize div 2, Pos.Y + TrainSize div 3), Angle) 2152 ]; 2141 2153 Canvas.Polygon(Points); 2142 2154 Canvas.Brush.Color := clWhite; … … 2159 2171 Text: string; 2160 2172 begin 2161 Canvas.Font.Color := Colors.Text;2162 2173 with Canvas do begin 2174 Canvas.Font.Color := Self.Colors.Text; 2175 Brush.Style := bsSolid; 2176 Brush.Color := Self.Colors.Background; 2177 2163 2178 Y := 100; 2164 2179 Font.Size := 40; … … 2190 2205 if (ServedDaysCount > HighestServedDaysCount) then 2191 2206 HighestServedDaysCount := ServedDaysCount; 2207 end; 2208 end; 2209 2210 procedure TEngine.DrawStationPassengerOverload(Canvas: TCanvas); 2211 var 2212 MapStation: TMapStation; 2213 Angle: Real; 2214 begin 2215 for MapStation in Stations do 2216 with MapStation do begin 2217 if OverloadDuration > 0 then begin 2218 Canvas.Brush.Color := clSilver; 2219 Canvas.Brush.Style := bsSolid; 2220 Canvas.Pen.Color := clSilver; 2221 Canvas.Pen.Style := psSolid; 2222 Angle := OverloadDuration / MaxPassengersOveloadTime * 2 * Pi; 2223 Canvas.Pie(Position.X - StationOverloadSize, Position.Y - StationOverloadSize, 2224 Position.X + StationOverloadSize, Position.Y + StationOverloadSize, 2225 Trunc(Position.X + StationOverloadSize * Cos(Angle)), 2226 Trunc(Position.Y + StationOverloadSize * Sin(Angle)), Position.X + StationOverloadSize, Position.Y); 2227 end; 2228 end; 2229 end; 2230 2231 procedure TEngine.DrawLines(Canvas: TCanvas); 2232 var 2233 MetroLine: TMetroLine; 2234 S: Integer; 2235 begin 2236 for MetroLine in Lines do 2237 with MetroLine do begin 2238 Canvas.Pen.Color := Color; 2239 Canvas.Pen.Style := psSolid; 2240 Canvas.Pen.Width := MetroLineThickness; 2241 if Track.Points.Count > 0 then Canvas.MoveTo(Track.Points[0].Position); 2242 for S := 1 to Track.Points.Count - 1 do begin 2243 Canvas.LineTo(Track.Points[S].Position); 2244 { if (S = TrackPoints.Count - 1) then begin 2245 Canvas.Pen.EndCap := pecSquare; 2246 Angle := arctan2(((TrackPoints[S].Position.Y - TrackPoints[S - 1].Position.Y), 2247 (TrackPoints[S].Position.X - TrackPoints[S - 1].Position.X)); 2248 EndPoint := Point(Round(TrackPoints[S].Position.X + EndStationLength * Cos(Angle)), 2249 Round(TrackPoints[S].Position.Y + EndStationLength * Sin(Angle))); 2250 Canvas.LineTo(EndPoint); 2251 Canvas.MoveTo(Point(Round(EndPoint.X + Cos(Angle + Pi / 2) * EndStationLength / 3), 2252 Round(EndPoint.Y + Sin(Angle + Pi / 2) * EndStationLength / 3))); 2253 Canvas.LineTo(Point(Round(EndPoint.X + Cos(Angle - Pi / 2) * EndStationLength / 3), 2254 Round(EndPoint.Y + Sin(Angle - Pi / 2) * EndStationLength / 3))); 2255 Canvas.Pen.EndCap := pecRound; 2256 end;} 2257 end; 2258 (* Canvas.Pen.Color := Color; 2259 Canvas.Pen.Style := psSolid; 2260 Canvas.Pen.Width := MetroLineThickness div 2; 2261 if Track.Points.Count > 0 then Canvas.MoveTo(Track.Points[0].PositionDesigned); 2262 for S := 1 to Track.Points.Count - 1 do begin 2263 Canvas.LineTo(Track.Points[S].PositionDesigned); 2264 { if (S = TrackPoints.Count - 1) then begin 2265 Canvas.Pen.EndCap := pecSquare; 2266 Angle := arctan2((TrackPoints[S].Position.Y - TrackPoints[S - 1].Position.Y), 2267 (TrackPoints[S].Position.X - TrackPoints[S - 1].Position.X)); 2268 EndPoint := Point(Round(TrackPoints[S].Position.X + EndStationLength * Cos(Angle)), 2269 Round(TrackPoints[S].Position.Y + EndStationLength * Sin(Angle))); 2270 Canvas.LineTo(EndPoint); 2271 Canvas.MoveTo(Point(Round(EndPoint.X + Cos(Angle + Pi / 2) * EndStationLength / 3), 2272 Round(EndPoint.Y + Sin(Angle + Pi / 2) * EndStationLength / 3))); 2273 Canvas.LineTo(Point(Round(EndPoint.X + Cos(Angle - Pi / 2) * EndStationLength / 3), 2274 Round(EndPoint.Y + Sin(Angle - Pi / 2) * EndStationLength / 3))); 2275 Canvas.Pen.EndCap := pecRound; 2276 end;} 2277 end; 2278 { 2279 if (TrackPoints.Count > 1) then begin 2280 Canvas.Pen.EndCap := pecSquare; 2281 Angle := arctan2((TrackPoints[1].Position.Y - TrackPoints[0].Position.Y), 2282 (TrackPoints[1].Position.X - TrackPoints[0].Position.X)); 2283 Canvas.MoveTo(TrackPoints[0].Position); 2284 EndPoint := Point(Round(TrackPoints[0].Position.X - EndStationLength * Cos(Angle)), 2285 Round(TrackPoints[0].Position.Y - EndStationLength * Sin(Angle))); 2286 Canvas.LineTo(EndPoint); 2287 Canvas.MoveTo(Point(Round(EndPoint.X - Cos(Angle + Pi / 2) * EndStationLength / 3), 2288 Round(EndPoint.Y - Sin(Angle + Pi / 2) * EndStationLength / 3))); 2289 Canvas.LineTo(Point(Round(EndPoint.X - Cos(Angle - Pi / 2) * EndStationLength / 3), 2290 Round(EndPoint.Y - Sin(Angle - Pi / 2) * EndStationLength / 3))); 2291 Canvas.Pen.EndCap := pecRound; 2292 end; } 2293 *) 2294 end; 2295 2296 // Draw design time lines 2297 if Assigned(TrackStationDown) and Assigned(TrackStationDown.LineStation) then begin 2298 Canvas.Pen.Color := TrackStationDown.Track.Line.Color; 2299 Canvas.MoveTo(TrackStationDown.LineStation.TrackPoint.Position); 2300 DrawLine(Canvas, View.PointDestToSrc(LastMousePos)); 2301 end; 2302 if Assigned(TrackStationUp) and Assigned(TrackStationUp.LineStation) then begin 2303 Canvas.Pen.Color := TrackStationUp.Track.Line.Color; 2304 Canvas.MoveTo(TrackStationUp.LineStation.TrackPoint.Position); 2305 DrawLine(Canvas, View.PointDestToSrc(LastMousePos)); 2306 end; 2307 end; 2308 2309 procedure TEngine.DrawStations(Canvas: TCanvas); 2310 var 2311 MapStation: TMapStation; 2312 Passenger: TMetroPassenger; 2313 PassengerPos: TPoint; 2314 Direction: Integer; 2315 begin 2316 Canvas.Pen.Width := 5; 2317 for MapStation in Stations do 2318 with MapStation do begin 2319 Canvas.Pen.Style := psSolid; 2320 if Assigned(SelectedLine) and (Lines.IndexOf(SelectedLine) <> -1) then begin 2321 Canvas.Brush.Style := bsClear; 2322 Canvas.Pen.Color := SelectedLine.Color; 2323 DrawShape(Canvas, Position, Shape, StationSize + Canvas.Pen.Width + 4, 0); 2324 end; 2325 2326 Canvas.Brush.Color := Colors.ShapeBackground; 2327 Canvas.Brush.Style := bsSolid; 2328 Canvas.Pen.Color := Colors.Text; 2329 DrawShape(Canvas, Position, Shape, StationSize, 0); 2330 2331 // Draw passengers 2332 Canvas.Pen.Style := psClear; 2333 Canvas.Brush.Color := Colors.Text; 2334 PassengerPos := Point(0, 0); 2335 Direction := 1; 2336 for Passenger in Passengers do 2337 with Passenger do begin 2338 DrawShape(Canvas, Point(Position.X + StationSize + PassengerPos.X, 2339 Position.Y - StationSize div 2 + PassengerPos.Y), 2340 Shape, PassengerSize, 0); 2341 PassengerPos := Point(PassengerPos.X + Direction * (PassengerSize + 2), PassengerPos.Y); 2342 if PassengerPos.X >= (PassengerSize + 2) * VisiblePassengersPerLine then begin 2343 Direction := -Direction; 2344 PassengerPos.X := PassengerPos.X - (PassengerSize + 2); 2345 PassengerPos.Y := PassengerPos.Y + (PassengerSize + 2); 2346 end; 2347 if PassengerPos.X < 0 then begin 2348 Direction := -Direction; 2349 PassengerPos.X := 0; 2350 PassengerPos.Y := PassengerPos.Y + (PassengerSize + 2); 2351 end; 2352 end; 2353 2354 { if ShowDistances then begin 2355 Canvas.Brush.Style := bsClear; 2356 Text := ''; 2357 for P := 0 to 5 do 2358 Text := Text + IntToStr(ShapeDistance[TStationShape(P)]) + ','; 2359 Canvas.TextOut(Position.X + StationSize div 2, Position.Y + StationSize div 2, Text); 2360 end; 2361 } 2362 end; 2363 end; 2364 2365 procedure TEngine.DrawGameControls(Canvas: TCanvas); 2366 var 2367 I: Integer; 2368 Text: string; 2369 Radius: Integer; 2370 Angle: Real; 2371 Pos: TPoint; 2372 begin 2373 // Line selection 2374 Canvas.Pen.Width := 4; 2375 for I := 0 to High(LineColors) do begin 2376 if Assigned(Lines.SearchByColor(LineColors[I])) then begin 2377 Canvas.Brush.Color := LineColors[I]; 2378 Radius := 15; 2379 end else begin 2380 Canvas.Brush.Color := clSilver; 2381 Radius := 5; 2382 end; 2383 Canvas.Pen.Color := Colors.Text; 2384 if Assigned(SelectedLine) and (SelectedLine.Color = LineColors[I]) then begin 2385 Canvas.Pen.Style := psSolid; 2386 end else begin 2387 Canvas.Pen.Style := psClear; 2388 end; 2389 2390 Canvas.EllipseC(Canvas.Width div 2 - Length(LineColors) div 2 * LineColorsDist + I * LineColorsDist, 2391 Canvas.Height - LineColorsDist, Radius, Radius); 2392 end; 2393 2394 // Draw unused trains 2395 Text := IntToStr(Trains.GetUnusedCount); 2396 Canvas.Draw(Canvas.Width div 2 - Length(LineColors) div 2 * LineColorsDist - 100, 2397 Canvas.Height - LineColorsDist - ImageLocomotive.Picture.Bitmap.Height div 2, ImageLocomotive.Picture.Bitmap); 2398 Canvas.Brush.Style := bsClear; 2399 Canvas.Font.Size := 14; 2400 Canvas.Font.Color := Colors.Text; 2401 Canvas.TextOut(Canvas.Width div 2 - Length(LineColors) div 2 * LineColorsDist - 50 - Canvas.TextWidth(Text), 2402 Canvas.Height - LineColorsDist - Canvas.TextHeight(Text) div 2, Text); 2403 2404 // Status interface 2405 Text := IntToStr(ServedPassengerCount); 2406 Canvas.Draw(Canvas.Width - 50, Canvas.Height - 60, ImagePassenger.Picture.Bitmap); 2407 Canvas.Brush.Style := bsClear; 2408 Canvas.Font.Size := 14; 2409 Canvas.Font.Color := Colors.Text; 2410 Canvas.TextOut(Canvas.Width - 70 - Canvas.TextWidth(Text), Canvas.Height - 55, Text); 2411 2412 DrawClock(Canvas); 2413 2414 // Back button 2415 Canvas.Font.Size := 40; 2416 Canvas.Font.Color := Colors.Text; 2417 ButtonBack.Paint(Canvas, Point(10, 10)); 2418 2419 // Show train grabbed by mouse 2420 if Assigned(SelectedTrain) then begin 2421 Canvas.Brush.Color := Colors.Text; //SelectedTrain.Line.Color; 2422 Canvas.Brush.Style := bsSolid; 2423 Canvas.Pen.Style := psClear; 2424 Pos := LastMousePos; 2425 Angle := 0; 2426 2427 Canvas.Polygon([ 2428 RotatePoint(Pos, Point(Pos.X - TrainSize div 2, Pos.Y - TrainSize div 3), Angle), 2429 RotatePoint(Pos, Point(Pos.X + TrainSize div 2, Pos.Y - TrainSize div 3), Angle), 2430 RotatePoint(Pos, Point(Pos.X + TrainSize div 2, Pos.Y + TrainSize div 3), Angle), 2431 RotatePoint(Pos, Point(Pos.X - TrainSize div 2, Pos.Y + TrainSize div 3), Angle) 2432 ]); 2192 2433 end; 2193 2434 end; … … 2284 2525 LineStationUp: TLineStation; 2285 2526 CurrentTrackPoint: TTrackPoint; 2286 I: Integer;2287 2527 begin 2288 2528 if State = gsMenu then begin … … 2483 2723 {$IFDEF DEBUG} 2484 2724 if Key = KeyF2 then begin 2485 State := gsGameOver; 2486 Redraw; 2725 if State = gsRunning then begin 2726 State := gsGameOver; 2727 Redraw; 2728 end; 2487 2729 end; 2488 2730 {$ENDIF} … … 2596 2838 end; 2597 2839 2598 procedure TEngine.Paint(TargetCanvas: TCanvas); 2599 var 2600 I: Integer; 2601 S: Integer; 2602 Size: Integer; 2603 Pos: TPoint; 2604 Text: string; 2605 Angle: Double; 2606 PassengerPos: TPoint; 2607 Direction: Integer; 2608 Points: array of TPoint; 2609 Canvas: TMetaCanvas; 2610 MetroLine: TMetroLine; 2611 MapStation: TMapStation; 2612 Passenger: TMetroPassenger; 2613 begin 2614 Canvas := MetaCanvas; 2615 Canvas.SetSize(Point(TargetCanvas.Width, TargetCanvas.Height)); 2616 Canvas.Reset; 2617 2618 // Draw station passenger overload 2619 for MapStation in Stations do 2620 with MapStation do begin 2621 if OverloadDuration > 0 then begin 2622 Canvas.Brush.Color := clSilver; 2623 Canvas.Brush.Style := bsSolid; 2624 Canvas.Pen.Color := clSilver; 2625 Canvas.Pen.Style := psSolid; 2626 Angle := OverloadDuration / MaxPassengersOveloadTime * 2 * Pi; 2627 Canvas.Pie(Position.X - StationOverloadSize, Position.Y - StationOverloadSize, 2628 Position.X + StationOverloadSize, Position.Y + StationOverloadSize, 2629 Trunc(Position.X + StationOverloadSize * Cos(Angle)), 2630 Trunc(Position.Y + StationOverloadSize * Sin(Angle)), Position.X + StationOverloadSize, Position.Y); 2631 end; 2632 end; 2633 2634 // Draw lines 2635 for MetroLine in Lines do 2636 with MetroLine do begin 2637 Canvas.Pen.Color := Color; 2638 Canvas.Pen.Style := psSolid; 2639 Canvas.Pen.Width := MetroLineThickness; 2640 if Track.Points.Count > 0 then Canvas.MoveTo(Track.Points[0].Position); 2641 for S := 1 to Track.Points.Count - 1 do begin 2642 Canvas.LineTo(Track.Points[S].Position); 2643 { if (S = TrackPoints.Count - 1) then begin 2644 Canvas.Pen.EndCap := pecSquare; 2645 Angle := arctan2(((TrackPoints[S].Position.Y - TrackPoints[S - 1].Position.Y), 2646 (TrackPoints[S].Position.X - TrackPoints[S - 1].Position.X)); 2647 EndPoint := Point(Round(TrackPoints[S].Position.X + EndStationLength * Cos(Angle)), 2648 Round(TrackPoints[S].Position.Y + EndStationLength * Sin(Angle))); 2649 Canvas.LineTo(EndPoint); 2650 Canvas.MoveTo(Point(Round(EndPoint.X + Cos(Angle + Pi / 2) * EndStationLength / 3), 2651 Round(EndPoint.Y + Sin(Angle + Pi / 2) * EndStationLength / 3))); 2652 Canvas.LineTo(Point(Round(EndPoint.X + Cos(Angle - Pi / 2) * EndStationLength / 3), 2653 Round(EndPoint.Y + Sin(Angle - Pi / 2) * EndStationLength / 3))); 2654 Canvas.Pen.EndCap := pecRound; 2655 end;} 2656 end; 2657 (* Canvas.Pen.Color := Color; 2658 Canvas.Pen.Style := psSolid; 2659 Canvas.Pen.Width := MetroLineThickness div 2; 2660 if Track.Points.Count > 0 then Canvas.MoveTo(Track.Points[0].PositionDesigned); 2661 for S := 1 to Track.Points.Count - 1 do begin 2662 Canvas.LineTo(Track.Points[S].PositionDesigned); 2663 { if (S = TrackPoints.Count - 1) then begin 2664 Canvas.Pen.EndCap := pecSquare; 2665 Angle := arctan2((TrackPoints[S].Position.Y - TrackPoints[S - 1].Position.Y), 2666 (TrackPoints[S].Position.X - TrackPoints[S - 1].Position.X)); 2667 EndPoint := Point(Round(TrackPoints[S].Position.X + EndStationLength * Cos(Angle)), 2668 Round(TrackPoints[S].Position.Y + EndStationLength * Sin(Angle))); 2669 Canvas.LineTo(EndPoint); 2670 Canvas.MoveTo(Point(Round(EndPoint.X + Cos(Angle + Pi / 2) * EndStationLength / 3), 2671 Round(EndPoint.Y + Sin(Angle + Pi / 2) * EndStationLength / 3))); 2672 Canvas.LineTo(Point(Round(EndPoint.X + Cos(Angle - Pi / 2) * EndStationLength / 3), 2673 Round(EndPoint.Y + Sin(Angle - Pi / 2) * EndStationLength / 3))); 2674 Canvas.Pen.EndCap := pecRound; 2675 end;} 2676 end; 2677 { 2678 if (TrackPoints.Count > 1) then begin 2679 Canvas.Pen.EndCap := pecSquare; 2680 Angle := arctan2((TrackPoints[1].Position.Y - TrackPoints[0].Position.Y), 2681 (TrackPoints[1].Position.X - TrackPoints[0].Position.X)); 2682 Canvas.MoveTo(TrackPoints[0].Position); 2683 EndPoint := Point(Round(TrackPoints[0].Position.X - EndStationLength * Cos(Angle)), 2684 Round(TrackPoints[0].Position.Y - EndStationLength * Sin(Angle))); 2685 Canvas.LineTo(EndPoint); 2686 Canvas.MoveTo(Point(Round(EndPoint.X - Cos(Angle + Pi / 2) * EndStationLength / 3), 2687 Round(EndPoint.Y - Sin(Angle + Pi / 2) * EndStationLength / 3))); 2688 Canvas.LineTo(Point(Round(EndPoint.X - Cos(Angle - Pi / 2) * EndStationLength / 3), 2689 Round(EndPoint.Y - Sin(Angle - Pi / 2) * EndStationLength / 3))); 2690 Canvas.Pen.EndCap := pecRound; 2691 end; } 2692 *) 2693 end; 2694 2695 // Draw design time lines 2696 if Assigned(TrackStationDown) and Assigned(TrackStationDown.LineStation) then begin 2697 Canvas.Pen.Color := TrackStationDown.Track.Line.Color; 2698 Canvas.MoveTo(TrackStationDown.LineStation.TrackPoint.Position); 2699 DrawLine(Canvas, View.PointDestToSrc(LastMousePos)); 2700 end; 2701 if Assigned(TrackStationUp) and Assigned(TrackStationUp.LineStation) then begin 2702 Canvas.Pen.Color := TrackStationUp.Track.Line.Color; 2703 Canvas.MoveTo(TrackStationUp.LineStation.TrackPoint.Position); 2704 DrawLine(Canvas, View.PointDestToSrc(LastMousePos)); 2705 end; 2706 2707 DrawTrains(Canvas); 2708 2709 // Draw stations 2710 Canvas.Pen.Width := 5; 2711 for MapStation in Stations do 2712 with MapStation do begin 2713 Canvas.Pen.Style := psSolid; 2714 if Assigned(SelectedLine) and (Lines.IndexOf(SelectedLine) <> -1) then begin 2715 Canvas.Brush.Style := bsClear; 2716 Canvas.Pen.Color := SelectedLine.Color; 2717 DrawShape(Canvas, Position, Shape, StationSize + Canvas.Pen.Width + 4, 0); 2718 end; 2719 2720 Canvas.Brush.Color := Colors.ShapeBackground; 2721 Canvas.Brush.Style := bsSolid; 2722 Canvas.Pen.Color := Colors.Text; 2723 DrawShape(Canvas, Position, Shape, StationSize, 0); 2724 2725 // Draw passengers 2726 Canvas.Pen.Style := psClear; 2727 Canvas.Brush.Color := Colors.Text; 2728 PassengerPos := Point(0, 0); 2729 Direction := 1; 2730 for Passenger in Passengers do 2731 with Passenger do begin 2732 DrawShape(Canvas, Point(Position.X + StationSize + PassengerPos.X, 2733 Position.Y - StationSize div 2 + PassengerPos.Y), 2734 Shape, PassengerSize, 0); 2735 PassengerPos := Point(PassengerPos.X + Direction * (PassengerSize + 2), PassengerPos.Y); 2736 if PassengerPos.X >= (PassengerSize + 2) * VisiblePassengersPerLine then begin 2737 Direction := -Direction; 2738 PassengerPos.X := PassengerPos.X - (PassengerSize + 2); 2739 PassengerPos.Y := PassengerPos.Y + (PassengerSize + 2); 2740 end; 2741 if PassengerPos.X < 0 then begin 2742 Direction := -Direction; 2743 PassengerPos.X := 0; 2744 PassengerPos.Y := PassengerPos.Y + (PassengerSize + 2); 2745 end; 2746 end; 2747 2748 { if ShowDistances then begin 2749 Canvas.Brush.Style := bsClear; 2750 Text := ''; 2751 for P := 0 to 5 do 2752 Text := Text + IntToStr(ShapeDistance[TStationShape(P)]) + ','; 2753 Canvas.TextOut(Position.X + StationSize div 2, Position.Y + StationSize div 2, Text); 2754 end; 2755 } 2756 end; 2840 procedure TEngine.Paint(Canvas: TCanvas); 2841 begin 2842 MetaCanvas.Size := Point(Canvas.Width, Canvas.Height); 2843 MetaCanvas.Reset; 2844 2845 DrawStationPassengerOverload(MetaCanvas); 2846 DrawLines(MetaCanvas); 2847 DrawTrains(MetaCanvas); 2848 DrawStations(MetaCanvas); 2757 2849 2758 2850 // MainMenu background 2759 TargetCanvas.Brush.Color := Colors.Background;2760 TargetCanvas.Brush.Style := bsSolid;2761 TargetCanvas.Clear;2851 Canvas.Brush.Color := Colors.Background; 2852 Canvas.Brush.Style := bsSolid; 2853 Canvas.Clear; 2762 2854 2763 2855 MetaCanvas.Move(Point(-View.SourceRect.Left, -View.SourceRect.Top)); … … 2765 2857 2766 2858 // Draw meta canvas to real target canvas 2767 MetaCanvas.DrawTo( TargetCanvas);2859 MetaCanvas.DrawTo(Canvas); 2768 2860 2769 2861 if State <> gsMenu then begin 2770 // Line selection 2771 TargetCanvas.Pen.Width := 4; 2772 for I := 0 to High(LineColors) do begin 2773 if Assigned(Lines.SearchByColor(LineColors[I])) then begin 2774 TargetCanvas.Brush.Color := LineColors[I]; 2775 Size := 15; 2776 end else begin 2777 TargetCanvas.Brush.Color := clSilver; 2778 Size := 5; 2779 end; 2780 TargetCanvas.Pen.Color := Colors.Text; 2781 if Assigned(SelectedLine) and (SelectedLine.Color = LineColors[I]) then begin 2782 TargetCanvas.Pen.Style := psSolid; 2783 end else begin 2784 TargetCanvas.Pen.Style := psClear; 2785 end; 2786 2787 TargetCanvas.EllipseC(TargetCanvas.Width div 2 - Length(LineColors) div 2 * LineColorsDist + I * LineColorsDist, 2788 TargetCanvas.Height - LineColorsDist, Size, Size); 2789 end; 2790 2791 // Draw unused trains 2792 Text := IntToStr(Trains.GetUnusedCount); 2793 TargetCanvas.Draw(Canvas.Width div 2 - Length(LineColors) div 2 * LineColorsDist - 100, 2794 TargetCanvas.Height - LineColorsDist - ImageLocomotive.Picture.Bitmap.Height div 2, ImageLocomotive.Picture.Bitmap); 2795 TargetCanvas.Brush.Style := bsClear; 2796 TargetCanvas.Font.Size := 14; 2797 TargetCanvas.Font.Color := Colors.Text; 2798 TargetCanvas.TextOut(TargetCanvas.Width div 2 - Length(LineColors) div 2 * LineColorsDist - 50 - TargetCanvas.TextWidth(Text), 2799 TargetCanvas.Height - LineColorsDist - TargetCanvas.TextHeight(Text) div 2, Text); 2800 2801 // Status interface 2802 Text := IntToStr(ServedPassengerCount); 2803 TargetCanvas.Draw(TargetCanvas.Width - 50, TargetCanvas.Height - 60, ImagePassenger.Picture.Bitmap); 2804 TargetCanvas.Brush.Style := bsClear; 2805 TargetCanvas.Font.Size := 14; 2806 TargetCanvas.Font.Color := Colors.Text; 2807 TargetCanvas.TextOut(TargetCanvas.Width - 70 - TargetCanvas.TextWidth(Text), TargetCanvas.Height - 55, Text); 2808 2809 DrawClock(TargetCanvas); 2810 2811 // Back button 2812 TargetCanvas.Font.Size := 40; 2813 TargetCanvas.Font.Color := Colors.Text; 2814 ButtonBack.Paint(TargetCanvas, Point(10, 10)); 2815 end; 2816 2817 // Show train grabbed by mouse 2818 if Assigned(SelectedTrain) then begin 2819 TargetCanvas.Brush.Color := Colors.Text; //SelectedTrain.Line.Color; 2820 TargetCanvas.Brush.Style := bsSolid; 2821 TargetCanvas.Pen.Style := psClear; 2822 Pos := LastMousePos; 2823 Angle := 0; 2824 2825 SetLength(Points, 4); 2826 Points[0] := RotatePoint(Pos, Point(Pos.X - TrainSize div 2, Pos.Y - TrainSize div 3), Angle); 2827 Points[1] := RotatePoint(Pos, Point(Pos.X + TrainSize div 2, Pos.Y - TrainSize div 3), Angle); 2828 Points[2] := RotatePoint(Pos, Point(Pos.X + TrainSize div 2, Pos.Y + TrainSize div 3), Angle); 2829 Points[3] := RotatePoint(Pos, Point(Pos.X - TrainSize div 2, Pos.Y + TrainSize div 3), Angle); 2830 TargetCanvas.Polygon(Points); 2862 DrawGameControls(Canvas); 2831 2863 end; 2832 2864 … … 2834 2866 if State = gsGameOver then 2835 2867 begin 2836 DrawGameOver( TargetCanvas);2868 DrawGameOver(Canvas); 2837 2869 end else 2838 2870 if State = gsMenu then begin 2839 Menu.Paint( TargetCanvas);2871 Menu.Paint(Canvas); 2840 2872 end; 2841 2873
Note:
See TracChangeset
for help on using the changeset viewer.