Beispiel #1
0
        /// <summary>
        /// Draws all decoration except arrows on all map sites in the specified region.</summary>
        /// <param name="context">
        /// The <see cref="DrawingContext"/> for the drawing.</param>
        /// <param name="siteRegion">
        /// The map region containing the coordinates of every <see cref="Site"/> to decorate.
        /// </param>
        /// <remarks>
        /// <b>DrawDecoration</b> draws grid outlines, selection highlights, owner shading, unit
        /// flags, resource gauges, and variable values on every <see cref="Site"/> within the
        /// specified <paramref name="siteRegion"/>, as appropriate.</remarks>

        private void DrawDecoration(DrawingContext context, RectI siteRegion)
        {
            var sites    = MapView.WorldState.Sites;
            var geometry = MapView.ElementGeometry;

            // traverse all specified sites
            for (int x = siteRegion.Left; x < siteRegion.Right; x++)
            {
                for (int y = siteRegion.Top; y < siteRegion.Bottom; y++)
                {
                    Site site = sites[x, y];

                    // shift origin to center of current site
                    PointD pixel = MapView.SiteToView(site.Location);
                    context.PushTransform(new TranslateTransform(pixel.X, pixel.Y));

                    // brighten polygon in selected region
                    if (MapView.SelectedRegion != null && MapView.SelectedRegion[x, y])
                    {
                        context.DrawGeometry(MediaObjects.ShadeLightBrush, null, geometry);
                    }

                    // tint polygon with owner color
                    if (MapView.ShowOwner)
                    {
                        Color color = (site.Owner == null ? Colors.Black : site.Owner.Color);
                        context.DrawGeometry(MediaObjects.GetShadeBrush(color), null, geometry);
                    }

                    // draw unit flag near unit stack
                    if (MapView.ShowFlags)
                    {
                        UnitDecorator.DrawFlag(context, site);
                    }

                    // draw resource gauge below unit stack
                    if (MapView.GaugeResource != null)
                    {
                        UnitDecorator.DrawGauge(context, site);
                    }

                    // draw variable values as numbers or shades
                    if (MapView.ShownVariable != null && MapView.ShownVariableFlags != 0)
                    {
                        VariableDrawer.Draw(context, site);
                    }

                    // reset transformation matrix
                    context.Pop();
                }
            }

            // draw polygon outlines for entire grid
            if (!this._bitmapGrid && MapView.ShowGrid)
            {
                context.DrawGeometry(null, MediaObjects.ThickPen, MapView.GridGeometry);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Draws a resource gauge on the specified <see cref="Site"/>.</summary>
        /// <param name="context">
        /// The <see cref="DrawingContext"/> for the drawing.</param>
        /// <param name="site">
        /// The <see cref="Site"/> to receive the resource gauge.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="context"/> is a null reference.</exception>
        /// <remarks>
        /// The origin of the specified <paramref name="context"/> must have been centered on the
        /// specified <paramref name="site"/>.</remarks>

        public void DrawGauge(DrawingContext context, Site site)
        {
            if (context == null)
            {
                ThrowHelper.ThrowArgumentNullException("context");
            }

            var units = site.Units;
            int count = units.Count;

            if (count == 0)
            {
                return;
            }

            // initialize geometric data if changed
            MapView        mapView = this._renderer.MapView;
            RegularPolygon polygon = mapView.MapGrid.Element;

            if (polygon != this._polygon)
            {
                Initialize(polygon);
            }

            // quit if gauge invisible
            if (this._gaugeBox.Width == 0.0)
            {
                return;
            }

            // get current resource and display flags
            string resource = mapView.GaugeResource;

            if (String.IsNullOrEmpty(resource))
            {
                return;
            }
            GaugeDisplay flags = mapView.GaugeResourceFlags;

            int min = 0, max = 0, value = 0;

            // traverse unit stack from top to bottom
            for (int i = count - 1; i >= 0; i--)
            {
                Unit   unit = (Unit)units[i];
                string id   = resource;

                // map standard pseudo-resources to actual unit resources
                if (id == ResourceClass.StandardStrength.Id)
                {
                    id = unit.UnitClass.StrengthResource;
                }
                else if (id == ResourceClass.StandardMorale.Id)
                {
                    id = unit.UnitClass.MoraleResource;
                }

                // get resource values if valid and present
                if (!String.IsNullOrEmpty(id))
                {
                    Variable variable = null;
                    if (unit.Resources.Variables.TryGetValue(id, out variable))
                    {
                        min   += variable.Minimum;
                        max   += variable.Maximum;
                        value += variable.Value;
                    }
                }

                // stop after topmost unit unless showing stack
                if ((flags & GaugeDisplay.Stack) == 0)
                {
                    break;
                }
            }

            // quit if no valid resource found
            if (min == max)
            {
                return;
            }

            // show resource if depleted or always shown
            if (value < max || (flags & GaugeDisplay.Always) != 0)
            {
                var brush = MediaObjects.GetBrush(MediaObjects.DangerBrushes, value, min, max);
                context.DrawRectangle(brush, MediaObjects.ThinPen, this._gaugeBox);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Draws a unit flag on the specified <see cref="Site"/>.</summary>
        /// <param name="context">
        /// The <see cref="DrawingContext"/> for the drawing.</param>
        /// <param name="site">
        /// The <see cref="Site"/> to receive the unit flag.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="context"/> is a null reference.</exception>
        /// <remarks>
        /// The origin of the specified <paramref name="context"/> must have been centered on the
        /// specified <paramref name="site"/>.</remarks>

        public void DrawFlag(DrawingContext context, Site site)
        {
            if (context == null)
            {
                ThrowHelper.ThrowArgumentNullException("context");
            }

            var units = site.Units;
            int count = units.Count;

            if (count == 0)
            {
                return;
            }

            // initialize geometric data if changed
            MapView        mapView = this._renderer.MapView;
            RegularPolygon polygon = mapView.MapGrid.Element;

            if (polygon != this._polygon)
            {
                Initialize(polygon);
            }

            // retrieve flag color for unit owner
            Faction owner = units[0].Owner;
            var     brush = MediaObjects.GetOpaqueBrush(owner.Color);

            // use ivory instead if active units present
            if (!ApplicationInfo.IsEditor && owner == mapView.WorldState.ActiveFaction)
            {
                for (int i = 0; i < count; i++)
                {
                    if (((Unit)units[i]).CanMove)
                    {
                        brush = Brushes.Ivory;
                        break;
                    }
                }
            }

            // draw flag rectangle
            context.DrawRectangle(brush, MediaObjects.ThinPen, this._flagBox);

            if (count == 1)
            {
                // one unit: single dot
                DrawFlagDot(context, HorizontalAlignment.Center, 1);
            }
            else if (count == 2)
            {
                // two units: two dots
                DrawFlagDot(context, HorizontalAlignment.Left, 2);
                DrawFlagDot(context, HorizontalAlignment.Right, 2);
            }
            else if (count == 3)
            {
                // three units: three dots
                DrawFlagDot(context, HorizontalAlignment.Left, 3);
                DrawFlagDot(context, HorizontalAlignment.Center, 3);
                DrawFlagDot(context, HorizontalAlignment.Right, 3);
            }
            else if (count >= 16)
            {
                // 16+ entities: diagonal cross
                DrawFlagCross(context);
            }
            else if (count >= 12)
            {
                // 12-15 units: three bars
                DrawFlagBar(context, HorizontalAlignment.Left, 3);
                DrawFlagBar(context, HorizontalAlignment.Center, 3);
                DrawFlagBar(context, HorizontalAlignment.Right, 3);
            }
            else if (count >= 8)
            {
                // 8-11 units: two bars
                DrawFlagBar(context, HorizontalAlignment.Left, 2);
                DrawFlagBar(context, HorizontalAlignment.Right, 2);
            }
            else if (count >= 4)
            {
                // 4-7 units: one bar
                DrawFlagBar(context, HorizontalAlignment.Center, 1);
            }
        }