private void LoadRoutes() { if (!File.Exists(".\\trains.fowm")) { return; } foreach (String line in File.ReadAllLines(".\\trains.fowm")) { string[] param = line.Split('|'); TrainRoute route = new TrainRoute() { Name = param[0], Color = FOCommon.Utils.GetColor(param[1]), WayPoints = new List <TrainWaypoint>() }; for (int i = 2; i < param.Length; i++) { string[] wpparam = param[i].Split(','); //TrainWaypoint wp = new TrainWaypoint(){Position=new Point(Int32.Parse(wpparam[0]), Int32.Parse(wpparam[1]))}; TrainWaypoint wp = new TrainWaypoint() { Position = new Point(Int32.Parse(wpparam[0]), (Int32.Parse(wpparam[1]))) }; route.WayPoints.Add(wp); } Routes.Add(route); } }
public bool worldmap_coords_clicked(MouseEventArgs e, int x, int y) { int GameX = Display.PixelToGameCoords(x); int GameY = Display.PixelToGameCoords(y); if (Control.ModifierKeys == Keys.Control && e.Button == MouseButtons.Left) { ActionDone = true; if (Control.MouseButtons == MouseButtons.Right) { if (CurrentRoute == null) { MessageBox.Show("No route currently constructed."); return(false); } else { CurrentRoute.WayPoints = new List <TrainWaypoint>(); } } //MessageBox.Show("Left with ctrl."); if (CurrentRoute == null) { TrainRoute route = CreateRoute(); if (route == null) { return(false); } route.WayPoints = new List <TrainWaypoint>(); CurrentRoute = route; //Routes.Add(route); } TrainWaypoint wp = CreateWaypoint(GameX, GameY); if (wp == null || CurrentRoute == null) { return(false); } CurrentRoute.WayPoints.Add(wp); ScriptGlobal.RefreshWorldMap(); return(true); } if (Control.ModifierKeys == Keys.Control && e.Button == MouseButtons.Right) { TrainWaypoint wp = GetWaypoint(GameX, GameY); if (wp == null) { return(false); } DeleteWaypoint(wp); ScriptGlobal.RefreshWorldMap(); return(true); } return(false); }
private void DeleteWaypoint(TrainWaypoint wp) { List <TrainRoute> CheckRoutes = new List <TrainRoute>(); CheckRoutes.AddRange(Routes); if (CurrentRoute != null) { CheckRoutes.Add(CurrentRoute); } for (int i = 0; i < CheckRoutes.Count; i++) { TrainRoute route = CheckRoutes[i]; if (route.WayPoints.Contains(wp)) { route.WayPoints.Remove(wp); return; } } }
public void draw_worldmap(Graphics Surface) { if (!FormLoaded) { return; } Brush brush = Brushes.Red; Font font = new Font(FontFamily.GenericSansSerif, 8.0f); if (true /*!ActionDone*/) { Drawing.DrawOutlinedText(Surface, "Trains extension loaded, use Ctrl+T to add route after adding waypoints.", font, brush, new PointF(5.0f, 5.0f), Brushes.Black); Drawing.DrawOutlinedText(Surface, "Ctrl+Left click to add new waypoint. Ctrl+Left-click while holding right button to remove all waypoints.", font, brush, new PointF(5.0f, 35.0f), Brushes.Black); Drawing.DrawOutlinedText(Surface, "Routes shown in different colors and with name on first waypoint.", font, brush, new PointF(5.0f, 50.0f), Brushes.Black); Drawing.DrawOutlinedText(Surface, "To delete a route or waypoint, use Ctrl+Right-click on it", font, brush, new PointF(5.0f, 65.0f), Brushes.Black); } List <TrainRoute> DrawRoutes = new List <TrainRoute>(); DrawRoutes.AddRange(Routes); if (CurrentRoute != null) { DrawRoutes.Add(CurrentRoute); } // Draw lines, so that waypoint is always on-top, even when drawing over others. foreach (TrainRoute route in DrawRoutes) { for (int i = 0; i < route.WayPoints.Count; i++) { TrainWaypoint wp = route.WayPoints[i]; Brush br = new SolidBrush(route.Color); Pen pen = new Pen(Brushes.Black); if (i > 0) { Point from = new Point(Display.GameCoordsToPixel(route.WayPoints[i - 1].Position.X), Display.GameCoordsToPixel(route.WayPoints[i - 1].Position.Y)); Point to = new Point(Display.GameCoordsToPixel(wp.Position.X), Display.GameCoordsToPixel(wp.Position.Y)); Surface.DrawLine(new Pen(br, 3.0f), from, to); } } } foreach (TrainRoute route in DrawRoutes) { for (int i = 0; i < route.WayPoints.Count; i++) { TrainWaypoint wp = route.WayPoints[i]; Brush br = new SolidBrush(route.Color); Pen pen = new Pen(Brushes.Black); int PosX = Display.GameCoordsToPixel(wp.Position.X); int PosY = Display.GameCoordsToPixel(wp.Position.Y); if (i == 0) { Drawing.DrawOutlinedText(Surface, route.Name, font, brush, new PointF(PosX - 8, PosY + 8), Brushes.Black); } Surface.FillRectangle(br, PosX - 8, PosY - 8, 16, 16); Surface.DrawRectangle(pen, PosX - 8, PosY - 8, 16, 16); } } }
private void LoadRoutes() { if(!File.Exists(".\\trains.fowm")) return; foreach(String line in File.ReadAllLines(".\\trains.fowm")) { string[] param = line.Split('|'); TrainRoute route = new TrainRoute(){Name=param[0], Color=FOCommon.Utils.GetColor(param[1]), WayPoints=new List<TrainWaypoint>()}; for(int i=2;i<param.Length;i++) { string[] wpparam = param[i].Split(','); //TrainWaypoint wp = new TrainWaypoint(){Position=new Point(Int32.Parse(wpparam[0]), Int32.Parse(wpparam[1]))}; TrainWaypoint wp = new TrainWaypoint() { Position = new Point(Int32.Parse(wpparam[0]), (Int32.Parse(wpparam[1]))) }; route.WayPoints.Add(wp); } Routes.Add(route); } }
private void DeleteWaypoint(TrainWaypoint wp) { List<TrainRoute> CheckRoutes = new List<TrainRoute>(); CheckRoutes.AddRange(Routes); if (CurrentRoute != null) CheckRoutes.Add(CurrentRoute); for (int i=0;i<CheckRoutes.Count;i++) { TrainRoute route = CheckRoutes[i]; if (route.WayPoints.Contains(wp)) { route.WayPoints.Remove(wp); return; } } }