- Timestamp:
- Mar 27, 2015, 11:36:33 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UEngine.pas
r17 r18 65 65 TTrackPoints = class(TObjectList) 66 66 Line: TMetroLine; 67 end; 68 69 TTrack = record 70 PointDown: TTrackPoint; 71 PointUp: TTrackPoint; 67 72 end; 68 73 … … 150 155 private 151 156 LastMousePos: TPoint; 152 Last SelectedStation: TMapStation;157 LastFocusedStation: TMapStation; 153 158 MouseHold: Boolean; 154 159 LastNewStationTime: TDateTime; … … 162 167 function GetExistStationShapes: TStationShapeSet; 163 168 function GetStationOnPos(Pos: TPoint): TMapStation; 164 function Get LineOnPos(Pos: TPoint): TMetroLine;169 function GetTrackOnPos(Pos: TPoint): TTrack; 165 170 procedure DrawLine(Canvas: TCanvas; Pos: TPoint); 166 171 procedure DrawShape(Canvas: TCanvas; Position: TPoint; Shape: TStationShape; … … 182 187 View: TView; 183 188 SelectedLine: TMetroLine; 184 SelectedStation: TMapStation; 189 TrackStationDown: TTrackPoint; 190 TrackStationUp: TTrackPoint; 185 191 ServedPassengerCount: Integer; 186 192 State: TGameState; … … 620 626 end; 621 627 622 function TEngine.Get LineOnPos(Pos: TPoint): TMetroLine;628 function TEngine.GetTrackOnPos(Pos: TPoint): TTrack; 623 629 var 624 630 I: Integer; … … 626 632 D: Integer; 627 633 MinD: Integer; 628 const 629 Distance = 30; 630 begin 631 Result := nil; 634 begin 635 Result.PointDown := nil; 636 Result.PointUp := nil; 632 637 I := 0; 633 638 MinD := High(Integer); … … 638 643 if (D < MinD) and (D < TrackClickDistance) then begin 639 644 MinD := D; 640 Result := TMetroLine(Lines[I]); 645 Result.PointDown := TTrackPoint(TrackPoints[T - 1]); 646 Result.PointUp := TTrackPoint(TrackPoints[T]); 641 647 end; 642 648 end; … … 1050 1056 procedure TEngine.MouseMove(Position: TPoint); 1051 1057 var 1052 Station: TMapStation; 1058 FocusedStation: TMapStation; 1059 Line: TMetroLine; 1053 1060 begin 1054 1061 LastMousePos := Position; 1055 1062 if MouseHold then begin 1056 if Assigned( SelectedLine) then begin1057 Station := GetStationOnPos(Position);1058 if not Assigned(Last SelectedStation) and Assigned(Station) then begin1059 if ( SelectedLine.LineStations.SearchMapStation(Station) = nil) then begin1060 SelectedLine.ConnectStation(Station);1061 SelectedStation := Station;1063 if Assigned(TrackStationDown) then begin 1064 FocusedStation := GetStationOnPos(Position); 1065 if not Assigned(LastFocusedStation) and Assigned(FocusedStation) then begin 1066 if (TrackStationDown.Line.LineStations.SearchMapStation(FocusedStation) = nil) then begin 1067 TrackStationDown.Line.ConnectStation(FocusedStation); 1068 TrackStationDown := TTrackPoint(TrackStationDown.Line.TrackPoints.Last); 1062 1069 end else 1063 if (SelectedLine.LineStations.Count > 0) and (TLineStation(SelectedLine.LineStations.Last).MapStation = Station) then begin 1064 SelectedLine.DisconnectStation(Station); 1065 if SelectedLine.LineStations.Count > 0 then 1066 SelectedStation := TLineStation(SelectedLine.LineStations.Last).MapStation 1067 else SelectedStation := nil; 1068 end else if (SelectedLine.LineStations.Count > 0) and (TLineStation(SelectedLine.LineStations.First).MapStation = Station) then begin 1069 SelectedLine.ConnectStation(Station); 1070 SelectedStation := Station; 1070 if (SelectedLine.TrackPoints.Count > 0) and (TLineStation(TrackStationDown.Line.LineStations.Last).MapStation = FocusedStation) then begin 1071 Line := TrackStationDown.Line; 1072 TrackStationDown.Line.DisconnectStation(FocusedStation); 1073 TrackStationDown := TTrackPoint(Line.TrackPoints.Last); 1074 end else if (TrackStationDown.Line.LineStations.Count > 0) and (TLineStation(TrackStationDown.Line.LineStations.Last).MapStation = FocusedStation) then begin 1075 TrackStationDown.Line.ConnectStation(FocusedStation); 1076 TrackStationDown := TTrackPoint(TrackStationDown.Line.TrackPoints.Last); 1071 1077 end; 1072 1078 end; 1073 Last SelectedStation :=Station;1079 LastFocusedStation := FocusedStation; 1074 1080 end; 1075 1081 end; … … 1083 1089 begin 1084 1090 MouseHold := False; 1091 TrackStationDown := nil; 1092 TrackStationUp := nil; 1093 1085 1094 if Button = mbLeft then begin 1086 SelectedStation := nil;1087 1095 1088 1096 // Line color selection … … 1105 1113 I: Integer; 1106 1114 NewLine: TMetroLine; 1115 Track: TTrack; 1116 NewIndex: Integer; 1107 1117 begin 1108 1118 if Button = mbLeft then begin 1109 1119 MouseHold := True; 1110 LastSelectedStation := nil; 1111 1112 // Station selection 1113 Station := GetStationOnPos(Position); 1114 if Assigned(Station) then begin 1115 SelectedStation := Station; 1116 if not Assigned(SelectedLine) then 1117 for I := 0 to Lines.Count - 1 do 1118 if TMetroLine(Lines[I]).LineStations.Count = 0 then begin 1119 SelectedLine := TMetroLine(Lines[I]); 1120 Break; 1120 LastFocusedStation := nil; 1121 1122 // Line selection 1123 Track := GetTrackOnPos(Position); 1124 if Assigned(Track.PointDown) and Assigned(Track.PointUp) then begin 1125 SelectedLine := Track.PointDown.Line; 1126 1127 TrackStationDown := Track.PointDown; 1128 NewIndex := TrackStationDown.Line.TrackPoints.IndexOf(TrackStationDown); 1129 while Assigned(TrackStationDown) and (not Assigned(TrackStationDown.LineStation)) do begin 1130 NewIndex := NewIndex - 1; 1131 if NewIndex >= 0 then TrackStationDown := TTrackPoint(TrackStationDown.Line.TrackPoints[NewIndex]) 1132 else TrackStationDown := nil; 1121 1133 end; 1122 end; 1123 1124 // Line selection 1125 Line := GetLineOnPos(Position); 1126 if Assigned(Line) then begin 1127 SelectedLine := Line; 1134 TrackStationUp := Track.PointUp; 1135 NewIndex := TrackStationUp.Line.TrackPoints.IndexOf(TrackStationDown); 1136 while Assigned(TrackStationUp) and (not Assigned(TrackStationUp.LineStation)) do begin 1137 NewIndex := NewIndex + 1; 1138 if NewIndex < TrackStationUp.Line.TrackPoints.Count then 1139 TrackStationUp := TTrackPoint(TrackStationUp.Line.TrackPoints[NewIndex]) 1140 else TrackStationUp := nil; 1141 end; 1142 1128 1143 Exit; 1129 1144 end; … … 1135 1150 if Assigned(NewLine) then begin 1136 1151 NewLine.ConnectStation(Station); 1137 SelectedStation := Station; 1138 LastSelectedStation := Station; 1152 TrackStationDown := TTrackPoint(NewLine.TrackPoints.Last); 1153 TrackStationUp := nil; 1154 LastFocusedStation := Station; 1139 1155 end; 1140 1156 end; … … 1270 1286 Canvas.Pen.EndCap := pecRound; 1271 1287 end; 1272 1273 // Draw design line 1274 if (SelectedLine = TMetroLine(Lines[I])) and Assigned(SelectedStation) then begin 1275 Canvas.MoveTo(SelectedStation.Position); 1276 DrawLine(Canvas, LastMousePos); 1277 end; 1288 end; 1289 1290 // Draw design time lines 1291 if Assigned(TrackStationDown) and Assigned(TrackStationDown.LineStation) then begin 1292 Canvas.Pen.Color := TrackStationDown.Line.Color; 1293 Canvas.MoveTo(TrackStationDown.LineStation.TrackPoint.Point); 1294 DrawLine(Canvas, LastMousePos); 1295 end; 1296 if Assigned(TrackStationUp) and Assigned(TrackStationUp.LineStation) then begin 1297 Canvas.Pen.Color := TrackStationUp.Line.Color; 1298 Canvas.MoveTo(TrackStationUp.LineStation.TrackPoint.Point); 1299 DrawLine(Canvas, LastMousePos); 1278 1300 end; 1279 1301
Note:
See TracChangeset
for help on using the changeset viewer.