コード例 #1
0
ファイル: MapView.cs プロジェクト: dunvit/EvaJimaPreRelease
        private void RecalculateSolarSystems(Map spaceMap)
        {
            foreach (var solarSystem in spaceMap.Systems)
            {
                try
                {
                    SolarSystems.Add(solarSystem.Name, solarSystem);

                    foreach (var connection in solarSystem.ConnectedSolarSystems)
                    {
                        var connectedSolarSystem = SpaceMap.Systems.FirstOrDefault(system => system.Name == connection);

                        if (connectedSolarSystem?.Name == null)
                        {
                            continue;
                        }
                        if (connectedSolarSystem.IsDeleted)
                        {
                            continue;
                        }

                        var pointFrom = new Point(solarSystem.LocationInMap.X, solarSystem.LocationInMap.Y);
                        var pointTo   = new Point(connectedSolarSystem.LocationInMap.X, connectedSolarSystem.LocationInMap.Y);

                        //Draw connection line center
                        var centerLinePoint = new Point((pointFrom.X + pointTo.X) / 2, (pointFrom.Y + pointTo.Y) / 2);

                        var newConnection = new Wormhole {
                            Location = centerLinePoint, SolarSystemFrom = solarSystem.Name, SolarSystemTo = connectedSolarSystem.Name
                        };

                        Wormholes.Add(newConnection);
                    }
                }
                catch (Exception ex)
                {
                    _commandsLog.ErrorFormat("[MapView.RecalculateSolarSystems] Critical error {0}", ex);
                }
            }
        }
コード例 #2
0
ファイル: MapView.cs プロジェクト: dunvit/EvaJimaPreRelease
        private void Event_Paint(object sender, PaintEventArgs e)
        {
            //Log.InfoFormat($"[MapInformationControl.Event_Paint] start for pilot {SpaceMap.ActivePilot}");

            if (isPainting)
            {
                return;
            }

            isPainting = true;

            try
            {
                if (isDragging)
                {
                    var coordinates = PointToClient(Cursor.Position);

                    var screenCenter = new Point(ScreenCenter.X + coordinates.X - Width / 2, ScreenCenter.Y + coordinates.Y - Height / 2);

                    RecalculateOffsetPositions(screenCenter);
                }

                var rectangleMapCenter = new Rectangle(Width / 2 - 0, Height / 2 - 0, 3, 3);

                e.Graphics.DrawEllipse(new Pen(Color.Red, 2), rectangleMapCenter);

                var rectangleScreenCenter = new Rectangle(ScreenCenter.X - Width / 2, ScreenCenter.Y - Height / 2, 3, 3);
                e.Graphics.DrawEllipse(new Pen(Color.DarkOrange, 2), rectangleScreenCenter);

                lblUpdateTime.Text = @"Updated at " + SpaceMap.LastUpdateTime.ToLongTimeString();

                #region Draw selected solar system aura

                foreach (var solarSystem in SpaceMap.Systems)
                {
                    if (solarSystem.Name == null || solarSystem.Name != SpaceMap.SelectedSolarSystemName)
                    {
                        continue;
                    }

                    var rectangle = new Rectangle(solarSystem.LocationInMap.X - MapPosition.X - 14,
                                                  solarSystem.LocationInMap.Y - MapPosition.Y - 14, 28, 28);

                    e.Graphics.DrawEllipse(new Pen(Color.DarkOrange, 2), rectangle);
                }

                #endregion

                #region Draw location solar system aura

                foreach (var solarSystem in SpaceMap.Systems)
                {
                    if (solarSystem.Name == null || solarSystem.Name != SpaceMap.LocationSolarSystemName)
                    {
                        continue;
                    }

                    var rectangle = new Rectangle(solarSystem.LocationInMap.X - MapPosition.X - 12,
                                                  solarSystem.LocationInMap.Y - MapPosition.Y - 12, 24, 24);

                    e.Graphics.DrawEllipse(new Pen(Color.DarkGreen, 2), rectangle);
                }

                #endregion

                #region Draw connection lines

                foreach (var solarSystem in SpaceMap.Systems)
                {
                    if (solarSystem.Name == null)
                    {
                        continue;
                    }
                    if (solarSystem.IsDeleted)
                    {
                        continue;
                    }
                    if (solarSystem.IsHidden)
                    {
                        continue;
                    }

                    foreach (var connection in solarSystem.ConnectedSolarSystems)
                    {
                        var connectedSolarSystem = SpaceMap.Systems.FirstOrDefault(system => system.Name == connection);

                        if (connectedSolarSystem.Name == null)
                        {
                            continue;
                        }
                        if (connectedSolarSystem.IsDeleted)
                        {
                            continue;
                        }

                        var pen = new Pen(Color.Gray, 1);
                        pen.DashStyle = DashStyle.Solid;

                        var pointFrom = new Point(solarSystem.LocationInMap.X - MapPosition.X, solarSystem.LocationInMap.Y - MapPosition.Y);
                        var pointTo   = new Point(connectedSolarSystem.LocationInMap.X - MapPosition.X,
                                                  connectedSolarSystem.LocationInMap.Y - MapPosition.Y);

                        e.Graphics.DrawLine(pen, pointFrom, pointTo);
                    }
                }

                #endregion

                #region Draw connection delete points

                foreach (var centerLinePoint in Wormholes.Select(solarSystemsConnection => new Point(solarSystemsConnection.Location.X - MapPosition.X, solarSystemsConnection.Location.Y - MapPosition.Y)))
                {
                    var coordinates = PointToClient(Cursor.Position);

                    var locationX = Math.Abs(centerLinePoint.X - coordinates.X);
                    var locationY = Math.Abs(centerLinePoint.Y - coordinates.Y);

                    if (locationX < 10 && locationY < 10)
                    {
                        e.Graphics.DrawLine(new Pen(Color.DarkOrange, 2),
                                            new Point(centerLinePoint.X - 5, centerLinePoint.Y - 5),
                                            new Point(centerLinePoint.X + 5, centerLinePoint.Y + 5));

                        e.Graphics.DrawLine(new Pen(Color.DarkOrange, 2),
                                            new Point(centerLinePoint.X + 5, centerLinePoint.Y - 5),
                                            new Point(centerLinePoint.X - 5, centerLinePoint.Y + 5));
                    }
                }

                #endregion

                #region Draw solar systems and names

                foreach (var solarSystem in SpaceMap.Systems)
                {
                    if (solarSystem.Name == null)
                    {
                        continue;
                    }
                    if (solarSystem.IsDeleted)
                    {
                        continue;
                    }
                    if (solarSystem.IsHidden)
                    {
                        continue;
                    }

                    var systemLabel     = solarSystem.Name;
                    var systemTypeLabel = "";

                    if (_systemsInformation.ContainsKey(solarSystem.Name) == false)
                    {
                        _systemsInformation.Add(solarSystem.Name, Global.Space.GetSystemByName(solarSystem.Name));
                    }


                    if (Tools.IsWSpaceSystem(solarSystem.Name))
                    {
                        if (_systemsInformation[solarSystem.Name].Class != null)
                        {
                            systemLabel     = systemLabel + "[C" + _systemsInformation[solarSystem.Name].Class + "]";
                            systemTypeLabel = "[C" + _systemsInformation[solarSystem.Name].Class + "]";
                        }
                        else
                        {
                            systemLabel     = systemLabel + "[Shattered]";
                            systemTypeLabel = " [Shattered]";
                        }
                    }

                    //Shattered

                    var drawFont      = new Font("Verdana", 8, FontStyle.Bold);
                    var drawBrushName = new SolidBrush(Tools.GetColorBySolarSystem(_systemsInformation[solarSystem.Name].Security.ToString()));

                    if (Tools.IsWSpaceSystem(solarSystem.Name))
                    {
                        drawBrushName = new SolidBrush(Tools.GetColorBySolarSystem("C" + _systemsInformation[solarSystem.Name].Class));
                    }

                    var stringSize = e.Graphics.MeasureString(systemLabel, drawFont);

                    var stringSize2 = e.Graphics.MeasureString(solarSystem.Name, drawFont);

                    var drawFormat = new StringFormat();


                    if (solarSystem.Type == "A" || solarSystem.Type == "B" || solarSystem.Type == "C")
                    {
                        e.Graphics.DrawString(solarSystem.Name, drawFont, drawBrushName,
                                              solarSystem.LocationInMap.X - MapPosition.X + 2 - stringSize.Width / 2, solarSystem.LocationInMap.Y - MapPosition.Y - 30,
                                              drawFormat);
                    }

                    if (Tools.IsWSpaceSystem(solarSystem.Name))
                    {
                        var drawBrush = new SolidBrush(Tools.GetColorBySolarSystem("C" + _systemsInformation[solarSystem.Name].Class));
                        e.Graphics.DrawString(systemTypeLabel, drawFont, drawBrush,
                                              solarSystem.LocationInMap.X - MapPosition.X + 2 - stringSize.Width / 2 + stringSize2.Width,
                                              solarSystem.LocationInMap.Y - MapPosition.Y - 30, drawFormat);
                    }

                    var rectangle = new Rectangle(solarSystem.LocationInMap.X - MapPosition.X - 8, solarSystem.LocationInMap.Y - MapPosition.Y - 8, 16,
                                                  16);

                    e.Graphics.FillEllipse(new SolidBrush(Tools.GetColorBySolarSystem(_systemsInformation[solarSystem.Name].Security.ToString())),
                                           rectangle);
                    e.Graphics.DrawEllipse(new Pen(Color.DimGray, 1), rectangle);
                }

                #endregion
            }
            catch (Exception ex)
            {
                //var someValue = SpaceMap.Systems;
                //var defaultValue = SpaceMap.Systems;

                ////result будет 23, если someValue - null
                //var result = someValue ?? defaultValue;
            }
            finally
            {
                isPainting = false;
            }
        }