Beispiel #1
0
        private ContourMap CreateContourMap()
        {
            ContourMap contour = new ContourMap(m_sceneControl.Scene);

            contour.Interval      = m_countourLineInterval;
            contour.Opacity       = m_opacity;
            contour.LineColor     = m_contourLineColor;
            contour.BorderVisible = m_bShowBorer;
            contour.BorderColor   = m_BorderColor;

            //设置等高线颜色表
            ColorDictionary colorDict = new ColorDictionary();

            ///////////////////////////////////////////////////////////////
            ///////北京地形////////////////////////
            colorDict[0]    = Color.Blue;
            colorDict[800]  = Color.Green;
            colorDict[1500] = Color.Red;

            contour.ColorDictTable = colorDict;

            contour.MaxVisibleAltitude = m_maxVisibleAlt;
            contour.MinVisibleAltitude = m_minVisibleAlt;

            contour.DisplayStyle = m_fillMode;
            contour.Build();
            return(contour);
        }
Beispiel #2
0
        protected override void OnDropDown(EventArgs e)
        {
            if (Items.Count <= 1)
            {
                Color selectedColor = this.ColorChoice;

                this.BeginUpdate();

                Items.Clear();

                if (!ColorDictionary.IsColorOfType(selectedColor, _colorType))
                {
                    Items.Add(selectedColor);
                }

                foreach (Color c in ColorDictionary.GetColorsOfType(_colorType))
                {
                    Items.Add(c);
                }

                SelectedItem = ColorDictionary.GetNormalizedColor(selectedColor, _colorType);

                this.EndUpdate();
            }

            base.OnDropDown(e);
        }
Beispiel #3
0
    public void SetValue(int index, ColorDictionary newData)
    {
        if (values.Count - 1 > index || index < 0)
        {
            return;
        }

        values[index] = newData;
    }
Beispiel #4
0
        /// <summary>
        /// Colors the with string.
        /// </summary>
        /// <param name="colorString">
        /// The color string.
        /// </param>
        /// <returns>
        /// The <see cref="AureaColor"/>.
        /// </returns>
        public static AureaColor ColorWithString(string colorString)
        {
            var color = ColorDictionary.ValueOrDefault(colorString);

            if (color == null)
            {
                color = new AureaColor(colorString);
                colors[colorString] = color;
            }

            return(color);
        }
Beispiel #5
0
        private static void LoadColors()
        {
            MenuColors.Add(typeof(StockManagementUI), ConsoleColor.Yellow);
            MenuColors.Add(typeof(PurchaseUI), ConsoleColor.Green);
            MenuColors.Add(typeof(MainMenuUI), ConsoleColor.Cyan);

            ColorDictionary.Add("logo", ConsoleColor.Blue);
            ColorDictionary.Add("logobackground", ConsoleColor.White);
            ColorDictionary.Add("special", ConsoleColor.Yellow);
            ColorDictionary.Add("erorr", ConsoleColor.Red);
            ColorDictionary.Add("confirmation", ConsoleColor.Green);
            ColorDictionary.Add("neutral", ConsoleColor.DarkYellow);
        }
Beispiel #6
0
        public Color GetColorFromShape(Shape shape)
        {
            bool result = ColorDictionary.TryGetValue(shape, out Color color);

            if (result)
            {
                return(color);
            }
            else
            {
                return(FallbackColor);
            }
        }
Beispiel #7
0
    private void DrawThemeData(string dataTitle, ThemeElementData data)
    {
        EditorGUILayout.LabelField($"{dataTitle} Data", EditorStyles.boldLabel);

        EditorGUILayout.BeginHorizontal();
        data.SetSprite((Sprite)EditorGUILayout.ObjectField(data.GetElementSprite(), typeof(Sprite), false, GUILayout.MaxWidth(200f)));
        data.SetSpriteType((Image.Type)EditorGUILayout.EnumPopup(data.GetSpriteType()));
        EditorGUILayout.EndHorizontal();

        ColorDictionary dictionary = data.GetDictionary();

        DrawColorDictionary(dictionary);
    }
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            Graphics  grfx      = e.Graphics;
            Rectangle rectColor = new Rectangle(e.Bounds.Left, e.Bounds.Top, 2 * e.Bounds.Height, e.Bounds.Height);

            rectColor.Inflate(-1, -1);

            Rectangle rectText = new Rectangle(e.Bounds.Left + 2 * e.Bounds.Height,
                                               e.Bounds.Top,
                                               e.Bounds.Width - 2 * e.Bounds.Height,
                                               e.Bounds.Height);

            if (this.Enabled)
            {
                e.DrawBackground();
            }

            grfx.DrawRectangle(new Pen(e.ForeColor), rectColor);

            string text       = string.Empty;
            object objAtIndex = e.Index >= 0 ? Items[e.Index] : SelectedItem;

            if (objAtIndex is Color)
            {
                Color itemColor = (Color)objAtIndex;
                grfx.FillRectangle(new SolidBrush(itemColor), rectColor);
                if (itemColor.IsNamedColor)
                {
                    text = itemColor.Name;
                }
                else if (ColorDictionary.IsBaseColorNamed(itemColor))
                {
                    int transparency = ((255 - itemColor.A) * 100) / 255;
                    text = "T" + transparency.ToString() + ColorDictionary.GetBaseColorName(itemColor);
                }
                else
                {
                    text = "Custom Color";
                }
            }
            else if (objAtIndex is BrushX)
            {
                BrushX itemBrush = (BrushX)objAtIndex;
                itemBrush.Rectangle = rectColor;
                grfx.FillRectangle(itemBrush, rectColor);
                text = "Custom Brush";
            }

            grfx.DrawString(text, Font, new SolidBrush(e.ForeColor), rectText);
        }
    public virtual void Awake()
    {
        if (mInstance == null)
        {
            mInstance = this as ColorDictionary;
            DontDestroyOnLoad(gameObject);
        }
        else
        {
            Destroy(gameObject);
        }

        //Add all dictionaries into main color palette dictionary
        Dict_ColorPalettes.Add(ColorPalettes.ColorPalette_01, ColorPalette_01);
        Dict_ColorPalettes.Add(ColorPalettes.ColorPalette_02, ColorPalette_02);
    }
Beispiel #10
0
 public ComponentGeometry(Array elementTypes)
 {
     positions_      = new ArrayDictionary();
     mapNodeNames    = new StringDictionary();
     nodeNames       = new ArrayDictionary();
     nodeAngles      = new ArrayDictionary();
     nodeCoordinates = new ArrayDictionary();
     elementData     = new ElementDictionary();
     vertices        = new ArrayDictionary();
     normals         = new ArrayDictionary();
     foreach (ElementType type in elementTypes)
     {
         elementData.Add(type, new Dictionary <string, Array>());
     }
     colors = new ColorDictionary();
 }
        /// <summary>
        /// Initializes colors.
        /// </summary>
        private void InitializeColors()
        {
            ColorDictionary.Clear();
            ForegroundColorDictionary.Clear();

            var colorDictionary           = Extensions.ResourceDictionary.GetColorsDictionary(ResourceDictionary, ColorKey, _colorWeights);
            var foregroundColorDictionary = Extensions.ResourceDictionary.GetColorsDictionary(ResourceDictionary, ForegroundColorKey, _foregroundColorWeights);

            foreach (var pair in colorDictionary)
            {
                ColorDictionary.Add(pair.Key, pair.Value);
            }

            foreach (var pair in foregroundColorDictionary)
            {
                ForegroundColorDictionary.Add(pair.Key, pair.Value);
            }
        }
Beispiel #12
0
    private void DrawColorDictionary(ColorDictionary dictionary)
    {
        int colorCount = Enum.GetNames(typeof(Theme.ColorMode)).Length;

        for (int i = 0; i < colorCount; i++)
        {
            Theme.ColorMode key = (Theme.ColorMode)i;
            if (!dictionary.Contains(key, out int index))
            {
                dictionary.Add(key, Color.white);
            }

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField($"{key} Color:", GUILayout.MaxWidth(150f));
            dictionary.SetValue(i, EditorGUILayout.ColorField(dictionary.GetValue(i), GUILayout.MaxWidth(150f)));
            EditorGUILayout.EndHorizontal();
        }
    }
Beispiel #13
0
        public void SetHexInfo(uint index, int hexId, UnitSide side, Dictionary <UnitSide, float> powers)
        {
            if (text == null)
            {
                return;
            }

            builder.Clear();
            builder.Append(GetHeader(index, hexId));
            foreach (var kvp in powers)
            {
                builder.AppendLine()
                .Append(kvp.Key.GetName())
                .AppendFormat(powerFmt, kvp.Value);
            }
            text.SetText(builder);
            text.color = ColorDictionary.GetSideColor(side);
        }
Beispiel #14
0
    public void Add(Theme.TextUIThemeKey key, ColorDictionary value)
    {
        if (keys == null || values == null)
        {
            keys   = new List <Theme.TextUIThemeKey>();
            values = new List <ColorDictionary>();

            keys.Add(key);
            values.Add(value);

            return;
        }

        if (!Contains(key, out int index))
        {
            keys.Add(key);
            values.Add(value);
        }

        return;
    }
Beispiel #15
0
    public void Add(GameShape.ColorType key, ColorDictionary value)
    {
        if (colorKeys == null || values == null)
        {
            colorKeys = new List <GameShape.ColorType>();
            values    = new List <ColorDictionary>();

            colorKeys.Add(key);
            values.Add(value);

            return;
        }

        if (!Contains(key, out int index))
        {
            colorKeys.Add(key);
            values.Add(value);
        }

        return;
    }
Beispiel #16
0
        private ShadowVisibilityQuery CreateShadowVisibilityQuery()
        {
            ShadowVisibilityQuery shadowQuery = new ShadowVisibilityQuery(m_sceneControl.Scene);

            shadowQuery.BaseUtcOffset = m_baseUtcOffset;
            shadowQuery.Spacing       = m_spacing;
            shadowQuery.StartTime     = m_startTime;
            shadowQuery.EndTime       = m_endTime;
            shadowQuery.TimeInterval  = m_timeInterval;

            //设置颜色表
            ColorDictionary colorDict = new ColorDictionary();

            colorDict[0]               = Color.Blue;
            colorDict[30]              = Color.Green;
            colorDict[60]              = Color.Orange;
            colorDict[100]             = Color.Red;
            shadowQuery.ColorDictTable = colorDict;

            return(shadowQuery);
        }
        protected override void OnDropDown(EventArgs e)
        {
            if (Items.Count <= 1)
            {
                BrushX selectedBrush = this.Brush;
                this.BeginUpdate();

                Items.Clear();
                if (selectedBrush.BrushType == BrushType.SolidBrush)
                {
                    if (!ColorDictionary.IsColorOfType(selectedBrush.Color, _colorType))
                    {
                        Items.Add(selectedBrush.Color);
                    }
                }
                else
                {
                    Items.Add(selectedBrush);
                }

                foreach (Color c in ColorDictionary.GetColorsOfType(_colorType))
                {
                    Items.Add(c);
                }

                if (selectedBrush.BrushType == BrushType.SolidBrush)
                {
                    SelectedItem = ColorDictionary.GetNormalizedColor(selectedBrush.Color, _colorType);
                }
                else
                {
                    SelectedItem = selectedBrush;
                }

                this.EndUpdate();
            }

            base.OnDropDown(e);
        }
Beispiel #18
0
        private void btn_DrawAnalystRange_Click(object sender, EventArgs e)
        {
            if (m_timer != null && m_timer.Enabled)
            {
                m_timer.Enabled = false;
                m_timer.Stop();
            }
            if (m_contour == null)
            {
                m_contour = new ContourMap(m_sceneControl.Scene);
                m_contour.DisplayStyle  = ContourMap.DisplayMode.Face;
                m_contour.Opacity       = 50;
                m_contour.BorderVisible = true;

                //设置等高线颜色表
                ColorDictionary colorDict = new ColorDictionary();
                colorDict[0]    = Color.FromArgb(36, 65, 171);
                colorDict[100]  = Color.FromArgb(80, 107, 191);
                colorDict[500]  = Color.FromArgb(124, 149, 210);
                colorDict[800]  = Color.FromArgb(168, 191, 230);
                colorDict[1200] = Color.FromArgb(212, 233, 250);

                m_contour.ColorDictTable = colorDict;
            }
            m_contour.MinVisibleAltitude = m_minVisibleAltidute;
            m_contour.MaxVisibleAltitude = m_minVisibleAltidute + 5;

            this.RegisterEvents(false);
            this.RegisterEvents(true);

            m_oldAction           = m_sceneControl.Action;
            m_sceneControl.Action = SuperMap.UI.Action3D.CreateLine;

            m_contour.Build();
            m_contour.BorderColor = Color.Blue;

            this.btn_StartAnalysis.Enabled = true;
            this.btn_Clear.Enabled         = true;
        }
Beispiel #19
0
        private SlopeMap CreateSlope()
        {
            Rectangle2D rect  = Rectangle2D.Empty;
            SlopeMap    slope = new SlopeMap(m_sceneControl.Scene);

            slope.Opacity       = m_opacity;
            slope.BorderVisible = m_bShowBorer;

            slope.DisplayStyle = m_fillMode;

            //设置坡度坡向调色板
            ColorDictionary colorDict = new ColorDictionary();

            colorDict[0]          = Color.Blue;
            colorDict[10]         = Color.Green;
            colorDict[30]         = Color.Red;
            slope.ColorDictTable  = colorDict;
            slope.MaxVisibleSlope = m_maxVisibleSlope;
            slope.MinVisibleSlope = m_minVisibleSlope;

            slope.Build();

            return(slope);
        }
Beispiel #20
0
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            Graphics  grfx      = e.Graphics;
            Rectangle rectColor = new Rectangle(e.Bounds.Left, e.Bounds.Top, 2 * e.Bounds.Height, e.Bounds.Height);

            rectColor.Inflate(-1, -1);

            Rectangle rectText = new Rectangle(e.Bounds.Left + 2 * e.Bounds.Height,
                                               e.Bounds.Top,
                                               e.Bounds.Width - 2 * e.Bounds.Height,
                                               e.Bounds.Height);

            if (this.Enabled)
            {
                e.DrawBackground();
            }

            grfx.DrawRectangle(new Pen(e.ForeColor), rectColor);

            Color itemColor = e.Index < 0 ? Color.Black : (Color)Items[e.Index];

            grfx.FillRectangle(new SolidBrush(itemColor), rectColor);
            string text = "Custom";

            if (itemColor.IsNamedColor)
            {
                text = itemColor.Name;
            }
            else if (ColorDictionary.IsBaseColorNamed(itemColor))
            {
                int transparency = ((255 - itemColor.A) * 100) / 255;
                text = "T" + transparency.ToString() + ColorDictionary.GetBaseColorName(itemColor);
            }

            grfx.DrawString(text, Font, new SolidBrush(e.ForeColor), rectText);
        }
Beispiel #21
0
 public void SetColorDictionary(ColorDictionary newDictionary)
 {
     elementColors = new ColorDictionary(newDictionary);
 }
 void Awake()
 {
     colorDictionary = new ColorDictionary(colorListTextAsset);
     playerColorIndex = -1;
     ChangeAvatarColor();
 }
        // Renders the current state of the game to a graphics object
        //
        // The offset is a number between 0 and 1 that specifies how far we are
        // past this game state, in units of time. As this parameter varies from
        // 0 to 1, the fleets all move in the forward direction. This is used to
        // fake smooth animation.
        //
        // On success, return an image. If something goes wrong, returns null.
        public void Render(Game gameData, Image bgImage, // Background image
            ColorDictionary colors, Graphics canvas, botDebugBase getPlayerStats)
        {
            _Canvas = canvas;
            MyColors = colors;
            try
            {
                int width = (int)(Width * 0.9);
                int height = (int)(Height * 0.9);
                PointF offset = new PointF(Width - width - 30, Height - height - 15);

                List<Planet> planets = gameData.Planets;
                List<Fleet> fleets = gameData.Fleets;

                if (bgImage != null)
                {
                    _Canvas.DrawImage(bgImage, 0, 0);
                }
                else
                {
                    _Canvas.FillRectangle(Brushes.LightGray, _Canvas.ClipBounds);
                }
                // Determine the dimensions of the viewport in game coordinates.
                double _top = Double.MAX_VALUE;
                double _left = Double.MAX_VALUE;
                double _right = Double.MIN_VALUE;
                double _bottom = Double.MIN_VALUE;
                int maxGrowthRate = 0;
                foreach (Planet p in planets)
                {
                    if (p.X < _left) _left = p.X;
                    if (p.X > _right) _right = p.X;
                    if (p.Y > _bottom) _bottom = p.Y;
                    if (p.Y < _top) _top = p.Y;
                    if (p.GrowthRate > maxGrowthRate) maxGrowthRate = p.GrowthRate;
                }
                _left--; _right++; _top--; _bottom++;

                int _xRange = (int)_right - (int)_left;
                int _yRange = (int)_bottom - (int)_top;

                PointF sizePerUnit = new PointF((float)width / (_xRange),
                                                 (float)height / (_yRange));

                double minSizeFactor = 5.0 + (sizePerUnit.X / maxGrowthRate);

                Point[] planetPos = new Point[planets.Count];

                RectangleF bounds = new RectangleF((float)(offset.X), (float)(offset.Y), (float)width, (float)height);

                PointF origin = new PointF((float)(bounds.Left - (_left * sizePerUnit.X)),
                                           (float)(bounds.Top - (_top * sizePerUnit.Y)));

                if (DrawGrid)
                {
                    for (float iGridX = (int)_left; iGridX <= _xRange; iGridX++)
                    {
                        float newX = origin.X + (iGridX * sizePerUnit.X);
                        PointF gridTop = new PointF(newX, bounds.Top);
                        PointF gridBottom = new PointF(newX, bounds.Bottom);

                        _Canvas.DrawLine(MyColors.GetPen(RenderColor.GridLine), gridTop, gridBottom);

                        string linesString = iGridX.ToString();

                        WriteTextInElLipseWithBorder(RenderColor.GridDark, RenderColor.GridLight, linesString, font50, gridTop, true, false);
                        WriteTextInElLipseWithBorder(RenderColor.GridDark, RenderColor.GridLight, linesString, font50, gridBottom, false, false);
                    }

                    for (float iGridY = (int)_top; iGridY <= _yRange; iGridY++)
                    {
                        float newY = origin.Y + ((float)_bottom - iGridY) * sizePerUnit.Y;
                        PointF gridLeft = new PointF(offset.X, newY);
                        PointF gridRight = new PointF(bounds.Right, newY);
                        _Canvas.DrawLine(MyColors.GetPen(RenderColor.GridLine), gridLeft, gridRight);
                        string linesString = iGridY.ToString();
                        WriteTextInElLipseWithBorder(RenderColor.GridDark, RenderColor.GridLight, linesString, font50, gridLeft, true, true);
                        WriteTextInElLipseWithBorder(RenderColor.GridDark, RenderColor.GridLight, linesString, font50, gridRight, false, false);
                    }
                }

                // Draw the planets.
                int idx = 0;
                int[] growthRatesCounter = new int[4];
                int[] inbaseCounter = new int[4];
                int[] planetCounter = new int[4];
                int[] planetOwnerIds = new int[planets.Count];
                foreach (Planet planet in planets)
                {
                    growthRatesCounter[planet.Owner] += planet.GrowthRate;
                    growthRatesCounter[3] += planet.GrowthRate;
                    inbaseCounter[planet.Owner] += planet.NumShips;
                    inbaseCounter[3] += planet.NumShips;
                    planetCounter[planet.Owner] += 1;
                    planetCounter[3] += 1;

                    int newX = (int)(origin.X + (planet.X * sizePerUnit.X));
                    int newY = (int)(bounds.Bottom - (planet.Y * sizePerUnit.Y));
                    Point pos = new Point(newX, newY);
                    planetPos[idx] = pos;
                    planetOwnerIds[idx++] = planet.Owner;

                    int x = pos.X;
                    int y = pos.Y;
                    double size = minSizeFactor * (planet.GrowthRate + 0.5);
                    double r = size;

                    double cx = x - r / 2;
                    double cy = y - r / 2;

                    Brush fillColor = MyColors.GetDarkBrush(planet.Owner);
                    Pen textColor = MyColors.GetLightPen(planet.Owner);
                    if (planet.GrowthRate == 0)
                    {
                        fillColor = Brushes.Black;
                    }
                    else
                    {
                        bool canSurvive = true;
                        if (getPlayerStats != null)
                        {
                            canSurvive = getPlayerStats.QueryPlanetCanSurviveAttack(planet.PlanetID);
                        }
                        if (!canSurvive)
                        {
                            textColor = MyColors.GetDarkPen(planet.Owner);
                            fillColor = MyColors.GetLightBrush(planet.Owner);
                        }
                    }
                    _Canvas.FillEllipse(fillColor, (int)cx, (int)cy, (int)r, (int)r);
                    _Canvas.DrawEllipse(textColor, (int)cx, (int)cy, (int)r, (int)r);
                }

                if (ShortestRoute != null)
                {
                    Planet current = null;
                    foreach (Planet next in ShortestRoute)
                    {
                        if (current != null)
                        {
                            Point from = planetPos[current.PlanetID];
                            Point to = planetPos[next.PlanetID];
                            _Canvas.DrawLine(Pens.Black, from, to);
                        }
                        current = next;
                    }
                }

                int[] inTransitCounter = new int[4];
                int[] approachingFleetTotalCount = new int[planets.Count];
                int[] approachingFleetAttackCount = new int[planets.Count];
                int[] approachingFleetDefenceCount = new int[planets.Count];
                //Draw in two passes, first the lines, then the labels.
                for (int passCount = 1; passCount < 3; passCount++)
                {
                    foreach (Fleet fleet in fleets)
                    {
                        if (DetermineShouldDrawPlayer(fleet.Owner))
                        {
                            if (passCount == 1)
                            {
                                inTransitCounter[fleet.Owner] += fleet.NumShips;
                                inTransitCounter[3] += fleet.NumShips;
                                if (fleet.Owner == planets[fleet.DestinationPlanet].Owner)
                                {
                                    approachingFleetTotalCount[fleet.DestinationPlanet] += fleet.NumShips;
                                    approachingFleetDefenceCount[fleet.DestinationPlanet] += fleet.NumShips;
                                }
                                else
                                {
                                    approachingFleetTotalCount[fleet.DestinationPlanet] -= fleet.NumShips;
                                    approachingFleetAttackCount[fleet.DestinationPlanet] -= fleet.NumShips;
                                }
                            }

                            Point sPos = planetPos[fleet.SourcePlanet];
                            Point dPos = planetPos[fleet.DestinationPlanet];
                            float tripProgress = 1.0f - (float)fleet.TurnsRemaining / (float)fleet.TotalTripLength;

                            if (tripProgress > 0.99 || tripProgress < 0.01)
                            {
                                continue;
                            }
                            int fleetOwnerOffset = (fleet.Owner - 1) * 2;
                            float dx = dPos.X - sPos.X + fleetOwnerOffset;
                            float dy = dPos.Y - sPos.Y + fleetOwnerOffset;

                            PointF fleetCenter = new PointF(
                                sPos.X + dx * tripProgress + fleetOwnerOffset,
                                sPos.Y + dy * tripProgress + fleetOwnerOffset);
                            if (passCount == 1 && DrawAttacklines)
                            {

                                Pen myPen = MyColors.GetPen(RenderColor.FleetOutgoingAttackLine);
                                if (fleet.Owner == 1)
                                {
                                    if (planetOwnerIds[fleet.DestinationPlanet] == fleet.Owner)
                                    {
                                        myPen = MyColors.GetPen(RenderColor.FleetDefensiveLine);
                                    }
                                }
                                else
                                {
                                    myPen = MyColors.GetPen(RenderColor.FleetIncomingAttackLine);
                                    _Canvas.DrawLine(myPen, dPos.X + 1, dPos.Y, fleetCenter.X + 1, fleetCenter.Y);
                                    _Canvas.DrawLine(myPen, dPos.X, dPos.Y + 1, fleetCenter.X, fleetCenter.Y + 1);
                                }
                                _Canvas.DrawLine(myPen, dPos, fleetCenter);

                            }

                            if (passCount == 2 ||
                                (passCount == 1 && !DrawAttacklines))
                            {
                                SizeF tSize = _Canvas.MeasureString(fleet.NumShips.ToString(), font100);
                                fleetCenter = new PointF((fleetCenter.X - tSize.Width / 2), (fleetCenter.Y - tSize.Height / 2));

                                RenderColor background = MyColors.GetDarkColor(fleet.Owner);
                                RenderColor foreground = MyColors.GetLightColor(fleet.Owner);

                                RectangleF fleetrect = WriteTextInElLipseWithBorder(background, foreground, fleet.NumShips, font100b, fleetCenter, false, false);

                                if (DrawFleetArrival)
                                {
                                    fleetCenter = new PointF(fleetrect.Right + 5, fleetrect.Bottom + 5);
                                    WriteTextInElLipseWithBorder(RenderColor.FleetDistanceDark, RenderColor.FleetDistanceLight, fleet.TurnsRemaining, font25, fleetCenter, true, true);
                                }
                            }
                        }
                    }
                    if (!DrawAttacklines)
                    {
                        break;
                    }
                }

                foreach (Planet planet in planets)
                {
                    Point sPos = planetPos[planet.PlanetID];
                    WriteTextInElLipseWithBorder(RenderColor.PlanetIdDark, RenderColor.PlanetIdLight, planet.PlanetID, font75b, sPos, true, true);
                    RectangleF goRight = WriteTextInElLipseWithBorder(RenderColor.PlanetGrowthDark, RenderColor.PlanetGrowthLight, planet.GrowthRate, font75, sPos, false, true);
                    sPos = new Point((int)goRight.Right, (int)goRight.Bottom);
                    RectangleF goUp = WriteTextInElLipseWithBorder(RenderColor.PlanetNumShipsDark, RenderColor.PlanetNumShipsLight, planet.NumShips, font50b, sPos, true, false);

                    if (DrawPlanetStatistics)
                    {
                        sPos = new Point((int)goUp.Left + 2, (int)goUp.Top);
                        goRight = WriteTextInElLipseWithBorder(RenderColor.PlanetAttackDark, RenderColor.PlanetAttackLight, approachingFleetAttackCount[planet.PlanetID], font25, sPos, true, false);
                        sPos = new Point((int)goRight.Right, (int)goUp.Top);
                        WriteTextInElLipseWithBorder(RenderColor.PlanetDefenceDark, RenderColor.PlanetDefenceLight, approachingFleetDefenceCount[planet.PlanetID], font25, sPos, true, false);

                        sPos = new Point((int)goRight.Left, (int)goRight.Top);
                        int nettEffect = approachingFleetTotalCount[planet.PlanetID];
                        if (nettEffect < 0)
                        {
                            WriteTextInElLipseWithBorder(RenderColor.PlanetAttackNettoNegativeDark, RenderColor.PlanetAttackNettoNegativeLight, nettEffect, font25b, sPos, true, false);
                        }
                        else
                        {
                            WriteTextInElLipseWithBorder(RenderColor.PlanetAttackNettoPositiveDark, RenderColor.PlanetAttackNettoPositiveLight, nettEffect, font25b, sPos, true, false);
                        }
                    }
                }

                SizeF textSize = _Canvas.MeasureString("In base : 1234", font50);

                int lineCounter = 0;
                double avg = (double)growthRatesCounter[3] / (double)planets.Count;
                #region Draw neutral player stats (UpperLeft)
                Brush color = MyColors.GetLightBrush(0);
                _Canvas.FillRectangle(Brushes.Black, 0, 0, textSize.Width, textSize.Height * 6);
                _Canvas.DrawString("In base : " + inbaseCounter[0], font50, color, 0, textSize.Height * lineCounter++);
                _Canvas.DrawString("Growth  : " + growthRatesCounter[0], font50, color, 0, textSize.Height * lineCounter++);
                _Canvas.DrawString(string.Format("Gr.Avg. : {0:G}", avg), font50, color, 0, textSize.Height * lineCounter++);
                #endregion

                #region Draw Player1 stats (Below neurtral)
                color = MyColors.GetLightBrush(1);
                _Canvas.DrawString("In base : " + inbaseCounter[1], font50, color, 0, textSize.Height * lineCounter++);
                _Canvas.DrawString("Transit : " + inTransitCounter[1], font50, color, 0, textSize.Height * lineCounter++);
                _Canvas.DrawString("Growth  : " + growthRatesCounter[1], font50, color, 0, textSize.Height * lineCounter++);
                #endregion

                int topLeftCornerHeight = (int)(textSize.Height * lineCounter) + 1;
                lineCounter = 0;
                color = MyColors.GetLightBrush(2);

                #region Draw Player2 stats (Right next to neurtral)
                _Canvas.FillRectangle(Brushes.Black, textSize.Width, 0, textSize.Width, textSize.Height * 3);
                _Canvas.DrawString("In base : " + inbaseCounter[2], font50, color, textSize.Width, textSize.Height * lineCounter++);
                int centralLine = (int)(textSize.Height * lineCounter++);
                _Canvas.DrawString("Transit : " + inTransitCounter[2], font50, color, textSize.Width, centralLine);
                _Canvas.DrawString("Growth  : " + growthRatesCounter[2], font50, color, textSize.Width, textSize.Height * lineCounter++);

                if (getPlayerStats != null)
                {
                    if (getPlayerStats.QueryIsDominating())
                    {
                        _Canvas.DrawString("Dominating", font100b, MyColors.GetDarkBrush(1), Width / 2 - textSize.Width, centralLine);
                    }
                }
                #endregion

                if (DrawUniverseStatistics)
                {
                    PaintVerticalStatisticBars(growthRatesCounter, inbaseCounter, planetCounter, inTransitCounter, color, topLeftCornerHeight);
                }
            }
            finally
            {
                _Canvas = null;
                MyColors = null;
            }
        }
Beispiel #24
0
 /// <summary>
 /// Get a color by key
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public static ConsoleColor Colors(string name) => ColorDictionary.TryGetValue(name.ToLower(), out ConsoleColor color) ? color : DEFAULT_COLOR;
        // Renders the current state of the game to a graphics object
        //
        // The offset is a number between 0 and 1 that specifies how far we are
        // past this game state, in units of time. As this parameter varies from
        // 0 to 1, the fleets all move in the forward direction. This is used to
        // fake smooth animation.
        //
        // On success, return an image. If something goes wrong, returns null.
        public void Render(Game gameData, Image bgImage,         // Background image
                           ColorDictionary colors, Graphics canvas, botDebugBase getPlayerStats)
        {
            _Canvas  = canvas;
            MyColors = colors;
            try
            {
                int    width  = (int)(Width * 0.9);
                int    height = (int)(Height * 0.9);
                PointF offset = new PointF(Width - width - 30, Height - height - 15);

                List <Planet> planets = gameData.Planets;
                List <Fleet>  fleets  = gameData.Fleets;

                if (bgImage != null)
                {
                    _Canvas.DrawImage(bgImage, 0, 0);
                }
                else
                {
                    _Canvas.FillRectangle(Brushes.LightGray, _Canvas.ClipBounds);
                }
                // Determine the dimensions of the viewport in game coordinates.
                double _top          = Double.MAX_VALUE;
                double _left         = Double.MAX_VALUE;
                double _right        = Double.MIN_VALUE;
                double _bottom       = Double.MIN_VALUE;
                int    maxGrowthRate = 0;
                foreach (Planet p in planets)
                {
                    if (p.X < _left)
                    {
                        _left = p.X;
                    }
                    if (p.X > _right)
                    {
                        _right = p.X;
                    }
                    if (p.Y > _bottom)
                    {
                        _bottom = p.Y;
                    }
                    if (p.Y < _top)
                    {
                        _top = p.Y;
                    }
                    if (p.GrowthRate > maxGrowthRate)
                    {
                        maxGrowthRate = p.GrowthRate;
                    }
                }
                _left--; _right++; _top--; _bottom++;

                int _xRange = (int)_right - (int)_left;
                int _yRange = (int)_bottom - (int)_top;

                PointF sizePerUnit = new PointF((float)width / (_xRange),
                                                (float)height / (_yRange));

                double minSizeFactor = 5.0 + (sizePerUnit.X / maxGrowthRate);

                Point[] planetPos = new Point[planets.Count];


                RectangleF bounds = new RectangleF((float)(offset.X), (float)(offset.Y), (float)width, (float)height);

                PointF origin = new PointF((float)(bounds.Left - (_left * sizePerUnit.X)),
                                           (float)(bounds.Top - (_top * sizePerUnit.Y)));

                if (DrawGrid)
                {
                    for (float iGridX = (int)_left; iGridX <= _xRange; iGridX++)
                    {
                        float  newX       = origin.X + (iGridX * sizePerUnit.X);
                        PointF gridTop    = new PointF(newX, bounds.Top);
                        PointF gridBottom = new PointF(newX, bounds.Bottom);

                        _Canvas.DrawLine(MyColors.GetPen(RenderColor.GridLine), gridTop, gridBottom);

                        string linesString = iGridX.ToString();

                        WriteTextInElLipseWithBorder(RenderColor.GridDark, RenderColor.GridLight, linesString, font50, gridTop, true, false);
                        WriteTextInElLipseWithBorder(RenderColor.GridDark, RenderColor.GridLight, linesString, font50, gridBottom, false, false);
                    }



                    for (float iGridY = (int)_top; iGridY <= _yRange; iGridY++)
                    {
                        float  newY      = origin.Y + ((float)_bottom - iGridY) * sizePerUnit.Y;
                        PointF gridLeft  = new PointF(offset.X, newY);
                        PointF gridRight = new PointF(bounds.Right, newY);
                        _Canvas.DrawLine(MyColors.GetPen(RenderColor.GridLine), gridLeft, gridRight);
                        string linesString = iGridY.ToString();
                        WriteTextInElLipseWithBorder(RenderColor.GridDark, RenderColor.GridLight, linesString, font50, gridLeft, true, true);
                        WriteTextInElLipseWithBorder(RenderColor.GridDark, RenderColor.GridLight, linesString, font50, gridRight, false, false);
                    }
                }


                // Draw the planets.
                int   idx = 0;
                int[] growthRatesCounter = new int[4];
                int[] inbaseCounter      = new int[4];
                int[] planetCounter      = new int[4];
                int[] planetOwnerIds     = new int[planets.Count];
                foreach (Planet planet in planets)
                {
                    growthRatesCounter[planet.Owner] += planet.GrowthRate;
                    growthRatesCounter[3]            += planet.GrowthRate;
                    inbaseCounter[planet.Owner]      += planet.NumShips;
                    inbaseCounter[3]            += planet.NumShips;
                    planetCounter[planet.Owner] += 1;
                    planetCounter[3]            += 1;


                    int   newX = (int)(origin.X + (planet.X * sizePerUnit.X));
                    int   newY = (int)(bounds.Bottom - (planet.Y * sizePerUnit.Y));
                    Point pos  = new Point(newX, newY);
                    planetPos[idx]        = pos;
                    planetOwnerIds[idx++] = planet.Owner;

                    int    x    = pos.X;
                    int    y    = pos.Y;
                    double size = minSizeFactor * (planet.GrowthRate + 0.5);
                    double r    = size;

                    double cx = x - r / 2;
                    double cy = y - r / 2;



                    Brush fillColor = MyColors.GetDarkBrush(planet.Owner);
                    Pen   textColor = MyColors.GetLightPen(planet.Owner);
                    if (planet.GrowthRate == 0)
                    {
                        fillColor = Brushes.Black;
                    }
                    else
                    {
                        bool canSurvive = true;
                        if (getPlayerStats != null)
                        {
                            canSurvive = getPlayerStats.QueryPlanetCanSurviveAttack(planet.PlanetID);
                        }
                        if (!canSurvive)
                        {
                            textColor = MyColors.GetDarkPen(planet.Owner);
                            fillColor = MyColors.GetLightBrush(planet.Owner);
                        }
                    }
                    _Canvas.FillEllipse(fillColor, (int)cx, (int)cy, (int)r, (int)r);
                    _Canvas.DrawEllipse(textColor, (int)cx, (int)cy, (int)r, (int)r);
                }

                if (ShortestRoute != null)
                {
                    Planet current = null;
                    foreach (Planet next in ShortestRoute)
                    {
                        if (current != null)
                        {
                            Point from = planetPos[current.PlanetID];
                            Point to   = planetPos[next.PlanetID];
                            _Canvas.DrawLine(Pens.Black, from, to);
                        }
                        current = next;
                    }
                }


                int[] inTransitCounter             = new int[4];
                int[] approachingFleetTotalCount   = new int[planets.Count];
                int[] approachingFleetAttackCount  = new int[planets.Count];
                int[] approachingFleetDefenceCount = new int[planets.Count];
                //Draw in two passes, first the lines, then the labels.
                for (int passCount = 1; passCount < 3; passCount++)
                {
                    foreach (Fleet fleet in fleets)
                    {
                        if (DetermineShouldDrawPlayer(fleet.Owner))
                        {
                            if (passCount == 1)
                            {
                                inTransitCounter[fleet.Owner] += fleet.NumShips;
                                inTransitCounter[3]           += fleet.NumShips;
                                if (fleet.Owner == planets[fleet.DestinationPlanet].Owner)
                                {
                                    approachingFleetTotalCount[fleet.DestinationPlanet]   += fleet.NumShips;
                                    approachingFleetDefenceCount[fleet.DestinationPlanet] += fleet.NumShips;
                                }
                                else
                                {
                                    approachingFleetTotalCount[fleet.DestinationPlanet]  -= fleet.NumShips;
                                    approachingFleetAttackCount[fleet.DestinationPlanet] -= fleet.NumShips;
                                }
                            }

                            Point sPos         = planetPos[fleet.SourcePlanet];
                            Point dPos         = planetPos[fleet.DestinationPlanet];
                            float tripProgress = 1.0f - (float)fleet.TurnsRemaining / (float)fleet.TotalTripLength;


                            if (tripProgress > 0.99 || tripProgress < 0.01)
                            {
                                continue;
                            }
                            int   fleetOwnerOffset = (fleet.Owner - 1) * 2;
                            float dx = dPos.X - sPos.X + fleetOwnerOffset;
                            float dy = dPos.Y - sPos.Y + fleetOwnerOffset;

                            PointF fleetCenter = new PointF(
                                sPos.X + dx * tripProgress + fleetOwnerOffset,
                                sPos.Y + dy * tripProgress + fleetOwnerOffset);
                            if (passCount == 1 && DrawAttacklines)
                            {
                                Pen myPen = MyColors.GetPen(RenderColor.FleetOutgoingAttackLine);
                                if (fleet.Owner == 1)
                                {
                                    if (planetOwnerIds[fleet.DestinationPlanet] == fleet.Owner)
                                    {
                                        myPen = MyColors.GetPen(RenderColor.FleetDefensiveLine);
                                    }
                                }
                                else
                                {
                                    myPen = MyColors.GetPen(RenderColor.FleetIncomingAttackLine);
                                    _Canvas.DrawLine(myPen, dPos.X + 1, dPos.Y, fleetCenter.X + 1, fleetCenter.Y);
                                    _Canvas.DrawLine(myPen, dPos.X, dPos.Y + 1, fleetCenter.X, fleetCenter.Y + 1);
                                }
                                _Canvas.DrawLine(myPen, dPos, fleetCenter);
                            }

                            if (passCount == 2 ||
                                (passCount == 1 && !DrawAttacklines))
                            {
                                SizeF tSize = _Canvas.MeasureString(fleet.NumShips.ToString(), font100);
                                fleetCenter = new PointF((fleetCenter.X - tSize.Width / 2), (fleetCenter.Y - tSize.Height / 2));

                                RenderColor background = MyColors.GetDarkColor(fleet.Owner);
                                RenderColor foreground = MyColors.GetLightColor(fleet.Owner);

                                RectangleF fleetrect = WriteTextInElLipseWithBorder(background, foreground, fleet.NumShips, font100b, fleetCenter, false, false);

                                if (DrawFleetArrival)
                                {
                                    fleetCenter = new PointF(fleetrect.Right + 5, fleetrect.Bottom + 5);
                                    WriteTextInElLipseWithBorder(RenderColor.FleetDistanceDark, RenderColor.FleetDistanceLight, fleet.TurnsRemaining, font25, fleetCenter, true, true);
                                }
                            }
                        }
                    }
                    if (!DrawAttacklines)
                    {
                        break;
                    }
                }

                foreach (Planet planet in planets)
                {
                    Point sPos = planetPos[planet.PlanetID];
                    WriteTextInElLipseWithBorder(RenderColor.PlanetIdDark, RenderColor.PlanetIdLight, planet.PlanetID, font75b, sPos, true, true);
                    RectangleF goRight = WriteTextInElLipseWithBorder(RenderColor.PlanetGrowthDark, RenderColor.PlanetGrowthLight, planet.GrowthRate, font75, sPos, false, true);
                    sPos = new Point((int)goRight.Right, (int)goRight.Bottom);
                    RectangleF goUp = WriteTextInElLipseWithBorder(RenderColor.PlanetNumShipsDark, RenderColor.PlanetNumShipsLight, planet.NumShips, font50b, sPos, true, false);


                    if (DrawPlanetStatistics)
                    {
                        sPos    = new Point((int)goUp.Left + 2, (int)goUp.Top);
                        goRight = WriteTextInElLipseWithBorder(RenderColor.PlanetAttackDark, RenderColor.PlanetAttackLight, approachingFleetAttackCount[planet.PlanetID], font25, sPos, true, false);
                        sPos    = new Point((int)goRight.Right, (int)goUp.Top);
                        WriteTextInElLipseWithBorder(RenderColor.PlanetDefenceDark, RenderColor.PlanetDefenceLight, approachingFleetDefenceCount[planet.PlanetID], font25, sPos, true, false);

                        sPos = new Point((int)goRight.Left, (int)goRight.Top);
                        int nettEffect = approachingFleetTotalCount[planet.PlanetID];
                        if (nettEffect < 0)
                        {
                            WriteTextInElLipseWithBorder(RenderColor.PlanetAttackNettoNegativeDark, RenderColor.PlanetAttackNettoNegativeLight, nettEffect, font25b, sPos, true, false);
                        }
                        else
                        {
                            WriteTextInElLipseWithBorder(RenderColor.PlanetAttackNettoPositiveDark, RenderColor.PlanetAttackNettoPositiveLight, nettEffect, font25b, sPos, true, false);
                        }
                    }
                }

                SizeF textSize = _Canvas.MeasureString("In base : 1234", font50);

                int    lineCounter = 0;
                double avg         = (double)growthRatesCounter[3] / (double)planets.Count;
                #region Draw neutral player stats (UpperLeft)
                Brush color = MyColors.GetLightBrush(0);
                _Canvas.FillRectangle(Brushes.Black, 0, 0, textSize.Width, textSize.Height * 6);
                _Canvas.DrawString("In base : " + inbaseCounter[0], font50, color, 0, textSize.Height * lineCounter++);
                _Canvas.DrawString("Growth  : " + growthRatesCounter[0], font50, color, 0, textSize.Height * lineCounter++);
                _Canvas.DrawString(string.Format("Gr.Avg. : {0:G}", avg), font50, color, 0, textSize.Height * lineCounter++);
                #endregion

                #region Draw Player1 stats (Below neurtral)
                color = MyColors.GetLightBrush(1);
                _Canvas.DrawString("In base : " + inbaseCounter[1], font50, color, 0, textSize.Height * lineCounter++);
                _Canvas.DrawString("Transit : " + inTransitCounter[1], font50, color, 0, textSize.Height * lineCounter++);
                _Canvas.DrawString("Growth  : " + growthRatesCounter[1], font50, color, 0, textSize.Height * lineCounter++);
                #endregion

                int topLeftCornerHeight = (int)(textSize.Height * lineCounter) + 1;
                lineCounter = 0;
                color       = MyColors.GetLightBrush(2);

                #region Draw Player2 stats (Right next to neurtral)
                _Canvas.FillRectangle(Brushes.Black, textSize.Width, 0, textSize.Width, textSize.Height * 3);
                _Canvas.DrawString("In base : " + inbaseCounter[2], font50, color, textSize.Width, textSize.Height * lineCounter++);
                int centralLine = (int)(textSize.Height * lineCounter++);
                _Canvas.DrawString("Transit : " + inTransitCounter[2], font50, color, textSize.Width, centralLine);
                _Canvas.DrawString("Growth  : " + growthRatesCounter[2], font50, color, textSize.Width, textSize.Height * lineCounter++);

                if (getPlayerStats != null)
                {
                    if (getPlayerStats.QueryIsDominating())
                    {
                        _Canvas.DrawString("Dominating", font100b, MyColors.GetDarkBrush(1), Width / 2 - textSize.Width, centralLine);
                    }
                }
                #endregion

                if (DrawUniverseStatistics)
                {
                    PaintVerticalStatisticBars(growthRatesCounter, inbaseCounter, planetCounter, inTransitCounter, color, topLeftCornerHeight);
                }
            }
            finally
            {
                _Canvas  = null;
                MyColors = null;
            }
        }
Beispiel #26
0
    public void Setup()
    {
        colorDictionary = new ColorDictionary(colorListTextAsset);

        //parse face and vertex data from input files
        parsedTerrainFaces = ParseFaces(textInputFaces);
        parsedTerrainVertices = ParseVertices(textInputVertices);

        //Create and pool terrain defenses
        GameObject temp = new GameObject("Defense Pool");
        temp.transform.parent = transform;
        temp.transform.position = new Vector3(1000f, 0f, 0f);
        defensePool = temp.AddComponent<Pool>();
        defensePool.poolObjectPrefab = defensePrefab;
        defensePool.InstantiatePoolObjects(defenseNumber);

        StartCoroutine("RegenerateTerrain", terrainType);
    }
Beispiel #27
0
 void Awake()
 {
     //Instantiate new color dictionary
     colorDictionary = new ColorDictionary(colorList);
 }
Beispiel #28
0
    void Start()
    {
        //Instantiate new color dictionary
        colorDictionary = new ColorDictionary(colorListTextAsset);

        //parse face and vertex data from input files
        parsedTerrainFaces = ParseFaces(textInputFaces);
        parsedTerrainVertices = ParseVertices(textInputVertices);

        if (numberOfPlayers > 1)
        {
            StartCoroutine("InitiateGameStateMultiNeutral");
        }
        else
        {

        }
        StartCoroutine("RegenerateTerrain");
    }
Beispiel #29
0
 public ColorDictionary(ColorDictionary reference)
 {
     keys   = reference.GetKeyList();
     values = reference.GetValueList();
 }
Beispiel #30
0
    // [ServerCallback]
    void Awake()
    {
        //Singleton
        if (instance != null && instance != this)
        {
            Destroy(gameObject);
        }
        else
        {
            instance = this;
            DontDestroyOnLoad(gameObject);

            //Instantiate new color dictionary
            colorDictionary = new ColorDictionary(colorListTextAsset);
            //playerData = GetComponent<PlayerData>();

            activeTerrain = _Levels.Neutral;

            //parse face and vertex data from input files
            parsedTerrainFaces = ParseFaces(textInputFaces);
            parsedTerrainVertices = ParseVertices(textInputVertices);
        }
    }