コード例 #1
0
        public LinkDrawing GetLinkDrawing(Link link, string faction1, string faction2, string offensiveFaction)
        {
            var planets      = link.PlanetIDs.Select(id => Galaxy.GetPlanet(id)).ToArray();
            var factionNames = new[] { faction1, faction2 };

            if (!DrawLinksBetweenNeutralPlanets && factionNames.All(f => f == null))
            {
                return(null);
            }

            var isColonyLink = factionNames.Contains(null);

            var isArrowNeeded = factionNames[0] != factionNames[1] &&
                                (isColonyLink || factionNames.Contains(offensiveFaction));

            var points = planets.Select(p => p.Position).ToArray();
            var colors = factionNames.Select(f => f == null ? neutralColor : Galaxy.GetFaction(f).Color).ToArray();

            var linkDrawing = new LinkDrawing();

            if (isArrowNeeded)
            {
                var arrowTipIndex = Array.FindIndex(factionNames, f => isColonyLink ? f == null : f != offensiveFaction);
                var arrowEndIndex = arrowTipIndex == 0 ? 1 : 0;

                linkDrawing.IsArrow      = true;
                linkDrawing.IsColonyLink = isColonyLink;

                linkDrawing.Tip      = points[arrowTipIndex];
                linkDrawing.End      = points[arrowEndIndex];
                linkDrawing.TipColor = colors[arrowTipIndex];
                linkDrawing.EndColor = colors[arrowEndIndex];

                // shorten the arrow so the tip isn't covered by a planet
                linkDrawing.ArrowOffset = ArrowOffset * AntiAliasFactor;
            }
            else
            {
                // doesn't matter which is the tip
                linkDrawing.Tip      = points[0];
                linkDrawing.End      = points[1];
                linkDrawing.TipColor = colors[0];
                linkDrawing.EndColor = colors[1];
            }

            linkDrawing.Location = PointF.Empty;
            var galaxySize = Program.MainForm.MapBox.Image.Width;

            linkDrawing.LineWidth = LineWidth / galaxySize;

            return(linkDrawing);
        }
コード例 #2
0
        public LinkDrawing GetLinkDrawing(Link link, string faction1, string faction2, string offensiveFaction)
        {
            var planets = link.PlanetIDs.Select(id => Galaxy.GetPlanet(id)).ToArray();
            var factionNames = new[] { faction1, faction2 };

            if (!DrawLinksBetweenNeutralPlanets && factionNames.All(f => f == null)) {
                return null;
            }

            var isColonyLink = factionNames.Contains(null);

            var isArrowNeeded = factionNames[0] != factionNames[1] &&
                                (isColonyLink || factionNames.Contains(offensiveFaction));

            var points = planets.Select(p => p.Position).ToArray();
            var colors = factionNames.Select(f => f == null ? neutralColor : Galaxy.GetFaction(f).Color).ToArray();

            var linkDrawing = new LinkDrawing();

            if (isArrowNeeded) {
                var arrowTipIndex = Array.FindIndex(factionNames, f => isColonyLink ? f == null : f != offensiveFaction);
                var arrowEndIndex = arrowTipIndex == 0 ? 1 : 0;

                linkDrawing.IsArrow = true;
                linkDrawing.IsColonyLink = isColonyLink;

                linkDrawing.Tip = points[arrowTipIndex];
                linkDrawing.End = points[arrowEndIndex];
                linkDrawing.TipColor = colors[arrowTipIndex];
                linkDrawing.EndColor = colors[arrowEndIndex];

                // shorten the arrow so the tip isn't covered by a planet
                linkDrawing.ArrowOffset = ArrowOffset * AntiAliasFactor;
            } else {
                // doesn't matter which is the tip
                linkDrawing.Tip = points[0];
                linkDrawing.End = points[1];
                linkDrawing.TipColor = colors[0];
                linkDrawing.EndColor = colors[1];
            }

            linkDrawing.Location = PointF.Empty;
            var galaxySize = Program.MainForm.MapBox.Image.Width;
            linkDrawing.LineWidth = LineWidth / galaxySize;

            return linkDrawing;
        }