diff --git a/HexGridExampleCommon/EmptyGridHex.cs b/HexGridExampleCommon/EmptyGridHex.cs index a40ebed..4a4ad1e 100644 --- a/HexGridExampleCommon/EmptyGridHex.cs +++ b/HexGridExampleCommon/EmptyGridHex.cs @@ -32,9 +32,7 @@ namespace PGNapoleonics.HexgridExampleCommon { /// TODO public sealed class EmptyGridHex : Hex { /// TODO - public EmptyGridHex(HexCoords coords) : base(coords,0) { - TerrainType = 'Z'; // Expression body causes a Doxygen warning - } + public EmptyGridHex(HexCoords coords) : base(coords,0) => TerrainType = default(char); /// public override char TerrainType { get; } diff --git a/HexGridExampleCommon/HexgridExampleCommon.csproj b/HexGridExampleCommon/HexgridExampleCommon.csproj index 9956b13..7b1106a 100644 --- a/HexGridExampleCommon/HexgridExampleCommon.csproj +++ b/HexGridExampleCommon/HexgridExampleCommon.csproj @@ -65,7 +65,6 @@ - diff --git a/HexGridExampleCommon/MapList.cs b/HexGridExampleCommon/MapList.cs index ede0761..34fbce0 100644 --- a/HexGridExampleCommon/MapList.cs +++ b/HexGridExampleCommon/MapList.cs @@ -29,53 +29,15 @@ using System.Collections.Generic; using System.Collections.ObjectModel; -using PGNapoleonics.HexUtilities; using PGNapoleonics.HexUtilities.Common; namespace PGNapoleonics.HexgridExampleCommon { - using MapGridHex = IHex; - - /// TODO - public delegate MapDisplay MapExtractor(); - - /// TODO - public struct Map { - /// TODO - public Map(string mapName, MapExtractor mapSource) : this() { - MapName = mapName; - MapSource = mapSource; - } - - /// TODO - public string MapName { get; } - /// TODO - public MapDisplay MapBoard => MapSource(); - - private MapExtractor MapSource { get; } - - /// TODO - public static IReadOnlyList MapList { get; } = new ReadOnlyCollection( + public static class MapList { + public static IReadOnlyList Maps { get; } = new ReadOnlyCollection( new Map[] { new Map("Terrain Map", () => new TerrainMap()), new Map("Maze Map", () => new MazeMap()), new Map("A* Bug Map", () => new AStarBugMap()) } ); - - #region Value Equality with IEquatable - /// - public override bool Equals(object obj) => (obj is Map other) && this.Equals(other); - - /// - public bool Equals(Map other) => MapName == other.MapName; - - /// - public override int GetHashCode() => MapName.GetHashCode(); - - /// Tests value-inequality. - public static bool operator !=(Map lhs, Map rhs) => ! lhs.Equals(rhs); - - /// Tests value-equality. - public static bool operator ==(Map lhs, Map rhs) => lhs.Equals(rhs); - #endregion } } diff --git a/HexUtilities/Common/Map.cs b/HexUtilities/Common/Map.cs new file mode 100644 index 0000000..1cd36e1 --- /dev/null +++ b/HexUtilities/Common/Map.cs @@ -0,0 +1,68 @@ +#region The MIT License - Copyright (C) 2012-2019 Pieter Geerkens +///////////////////////////////////////////////////////////////////////////////////////// +// PG Software Solutions - Hex-Grid Utilities +///////////////////////////////////////////////////////////////////////////////////////// +// The MIT License: +// ---------------- +// +// Copyright (c) 2012-2019 Pieter Geerkens (email: pgeerkens@users.noreply.github.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, +// merge, publish, distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to the following +// conditions: +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +///////////////////////////////////////////////////////////////////////////////////////// +#endregion + +namespace PGNapoleonics.HexUtilities.Common { + using MapGridHex = IHex; + + /// TODO + public delegate MapDisplay MapExtractor(); + + /// TODO + public class Map { + /// TODO + public Map(string mapName, MapExtractor mapSource) { + MapName = mapName; + MapSource = mapSource; + } + + /// TODO + public string MapName { get; } + /// TODO + public MapDisplay MapBoard => MapSource(); + + private MapExtractor MapSource { get; } + + #region Value Equality with IEquatable + /// + public override bool Equals(object obj) => (obj is Map other) && this.Equals(other); + + /// + public bool Equals(Map other) => MapName == other.MapName; + + /// + public override int GetHashCode() => MapName.GetHashCode(); + + /// Tests value-inequality. + public static bool operator !=(Map lhs, Map rhs) => ! lhs.Equals(rhs); + + /// Tests value-equality. + public static bool operator ==(Map lhs, Map rhs) => lhs.Equals(rhs); + #endregion + } +} diff --git a/HexUtilities/HexUtilities.csproj b/HexUtilities/HexUtilities.csproj index 8709d38..3b3bf75 100644 --- a/HexUtilities/HexUtilities.csproj +++ b/HexUtilities/HexUtilities.csproj @@ -215,6 +215,8 @@ + + diff --git a/HexgridPanel/AbstractModelDisplayPainter.cs b/HexgridPanel/AbstractModelDisplayPainter.cs index a3f5a3a..33176d6 100644 --- a/HexgridPanel/AbstractModelDisplayPainter.cs +++ b/HexgridPanel/AbstractModelDisplayPainter.cs @@ -69,9 +69,7 @@ public virtual void PaintLabels(Graphics graphics, Func hexTex } ); } ); - /// Paint the top layer of the display, graphics that changes frequently between refreshes. - /// The map to be painted, as a . - /// The object for the canvas being painted. + /// public virtual void PaintHighlight(Graphics graphics) { graphics?.Contain(g => { g.Transform = Model.TranslateToHex(Model.StartHex); @@ -104,10 +102,7 @@ public virtual void PaintShading(Graphics graphics, IShadingMask isNotShaded) } } ); - /// . - /// - /// The map to be painted, as a . - /// The object for the canvas being painted. + /// public virtual void PaintUnits(Graphics graphics) { if (graphics == null) throw new ArgumentNullException("graphics"); diff --git a/HexgridPanel/Example/HexGridPanelExample.cs b/HexgridPanel/Example/HexGridPanelExample.cs index 6951e14..f3dfc32 100644 --- a/HexgridPanel/Example/HexGridPanelExample.cs +++ b/HexgridPanel/Example/HexGridPanelExample.cs @@ -49,7 +49,7 @@ public HexgridPanelExample() { InitializeComponent(); MenuBarToolStrip.LoadTraceMenu(); - MenuBarToolStrip.LoadMapList(Map.MapList.Select(item => item.MapName).ToArray()); + MenuBarToolStrip.LoadMapList(MapList.Maps.Select(item => item.MapName).ToArray()); } protected override CreateParams CreateParams => this.SetCompositedStyle(base.CreateParams); @@ -119,7 +119,7 @@ private void MenuItemHelpContents_Click(object sender, EventArgs e) { } private static MapGridDisplay ParseMapName(string mapName) - => Map.MapList.First(item => item.MapName == mapName).MapBoard; + => MapList.Maps.First(item => item.MapName == mapName).MapBoard; private void SetMapBoard(MapGridDisplay mapBoard) { HexgridPanel.SetModel( MapBoard = mapBoard); diff --git a/HexgridPanel/Example/HexgridBufferedPanelExample.cs b/HexgridPanel/Example/HexgridBufferedPanelExample.cs index ec3551f..76cddab 100644 --- a/HexgridPanel/Example/HexgridBufferedPanelExample.cs +++ b/HexgridPanel/Example/HexgridBufferedPanelExample.cs @@ -48,7 +48,7 @@ public HexgridBufferedPanelExample() { InitializeComponent(); MenuBarToolStrip.LoadTraceMenu(); - MenuBarToolStrip.LoadMapList(Map.MapList.Select(item => item.MapName).ToArray()); + MenuBarToolStrip.LoadMapList(MapList.Maps.Select(item => item.MapName).ToArray()); } protected override CreateParams CreateParams => this.SetCompositedStyle(base.CreateParams); @@ -117,7 +117,7 @@ private void MenuItemHelpContents_Click(object sender, EventArgs e) { } private static MapGridDisplay ParseMapName(string mapName) - => Map.MapList.First(item => item.MapName == mapName).MapBoard; + => MapList.Maps.First(item => item.MapName == mapName).MapBoard; private void SetMapBoard(MapGridDisplay mapBoard) { HexgridPanel.SetModel( MapBoard = mapBoard); diff --git a/HexgridPanel/MapDisplayPainterExtensions.cs b/HexgridPanel/MapDisplayPainterExtensions.cs index ec8a069..2962499 100644 --- a/HexgridPanel/MapDisplayPainterExtensions.cs +++ b/HexgridPanel/MapDisplayPainterExtensions.cs @@ -49,16 +49,6 @@ public static void PaintMap(this IMapDisplayWinForms @this, Graphics bool showHexgrid) where THex:IHex => @this.Painter().PaintMap(graphics,showHexgrid); - //=> graphics.Contain( g => { - // var boardHexes = @this.BoardHexes; - // graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; - // @this.PaintForEachHex(graphics, coords => { - // boardHexes[coords].IfHasValueDo(h => { - // if(h is IHex hex) hex.Paint(graphics, @this.HexgridPath, hex.GetHexBrush()); - // }); - // if (showHexgrid) graphics.DrawPath(Pens.Black, @this.HexgridPath); - // } ); - // } ); /// Paint the base layer of the display, graphics that changes rarely between refreshes. /// The map to be painted, as a . @@ -69,14 +59,6 @@ public static void PaintLabels(this IMapDisplayWinForms @this, Graph Func hexText) where THex:IHex => @this.Painter().PaintLabels(graphics,hexText); - //=> graphics.Contain( g => { - // @this.PaintForEachHex(graphics, coords => { - // var font = SystemFonts.MenuFont; - // var textOffset = new Point((@this.GridSize.Scale(0.50F) - // - new SizeF(font.Size,font.Size).Scale(0.8F)).ToSize()); - // graphics.DrawString(hexText(coords), font, TextBrush, textOffset); - // } ); - // } ); /// Paint the top layer of the display, graphics that changes frequently between refreshes. /// The map to be painted, as a . @@ -84,25 +66,6 @@ public static void PaintLabels(this IMapDisplayWinForms @this, Graph public static void PaintHighlight(this IMapDisplayWinForms @this, Graphics graphics) where THex:IHex => @this.Painter().PaintHighlight(graphics); - //{ - // graphics.Contain(g => { - // g.Transform = @this.TranslateToHex(@this.StartHex); - // g.DrawPath(Pens.Red, @this.HexgridPath); - // } ); - - // if (@this.Path != null) { - // graphics.Contain(g => { @this.PaintPath(g); }); - // } - - // if (@this.ShowRangeLine) { - // graphics.Contain(g => { - // var target = @this.CentreOfHex(@this.HotspotHex); - // graphics.DrawLine(Pens.Red, @this.CentreOfHex(@this.StartHex), target); - // graphics.DrawLine(Pens.Red, target.X-8,target.Y-8, target.X+8,target.Y+8); - // graphics.DrawLine(Pens.Red, target.X-8,target.Y+8, target.X+8,target.Y-8); - // } ); - // } - //} /// . /// @@ -112,15 +75,6 @@ public static void PaintHighlight(this IMapDisplayWinForms @this, Gr public static void PaintShading(this IMapDisplayWinForms @this, Graphics graphics, IShadingMask isNotShaded) where THex: IHex => @this.Painter().PaintShading(graphics,isNotShaded); - //=> graphics.Contain(g => { - // if (isNotShaded == null) return; - // graphics.CompositingMode = CompositingMode.SourceOver; - // using (var shadeBrush = new SolidBrush(Color.FromArgb(@this.ShadeBrushAlpha,ShadeColor))) { - // @this.PaintForEachHex(graphics,coords => { - // if (!isNotShaded[coords]) { graphics.FillPath(shadeBrush,@this.HexgridPath); } - // }); - // } - //}); /// . /// @@ -129,142 +83,5 @@ public static void PaintShading(this IMapDisplayWinForms @this, Grap public static void PaintUnits(this IMapDisplayWinForms @this,Graphics graphics) where THex : IHex => @this.Painter().PaintUnits(graphics); - //{ - // if (@this == null) throw new ArgumentNullException("this"); - // if (graphics == null) throw new ArgumentNullException("graphics"); - - // /* NO-OP - Not implemented in examples. */ - //} - - ///// Paints all the hexes in by executing - ///// for each hex on . - ///// The map to be painted, as a . - ///// The object for the canvas being painted. - ///// The rectangular extent of hexes to be painted as a . - ///// The paint action to be performed for each hex as a . - //private static void PaintForEachHex(this IMapDisplayWinForms @this, Graphics graphics, - // Action paintAction) - //where THex:IHex { - // var clipRectangle = @this.GetClipInHexes(graphics.VisibleClipBounds); - // @this.ForEachHex(clipRectangle, hex => { - // graphics.Transform = @this.TranslateToHex(hex.Coords); - // paintAction(hex.Coords); - // } ); - //} - - ///// Paint the current shortese path. - ///// The map to be painted, as a . - ///// The object for the canvas being painted. - ///// Type: - - ///// A directed path (ie linked-list> of hexes to be painted. - //private static void PaintPath(this IMapDisplayWinForms @this, Graphics graphics) - //where THex:IHex { - // if (graphics==null) throw new ArgumentNullException("graphics"); - - // var path = @this.Path.ElseDefault(); - // using(var brush = new SolidBrush(Color.FromArgb(78, Color.PaleGoldenrod))) { - // while (path != null) { - // var coords = path.PathStep.Coords; - // graphics.Transform = @this.TranslateToHex(coords); - // graphics.FillPath(brush, @this.HexgridPath); - - // if (@this.ShowPathArrow) @this.PaintPathDetail(graphics, path); - - // path = path.PathSoFar; - // } - // } - //} - - ///// Paint the direction and destination indicators for each hex of the current shortest path. - ///// The map to be painted, as a . - ///// The object for the canvas being painted. - ///// Type: - - ///// A directed path (ie linked-list> of hexes to be highlighted with a direction arrow. - //static void PaintPathDetail(this IMapDisplayWinForms @this, Graphics graphics, IDirectedPathCollection path) - //where THex:IHex { - // graphics.TranslateTransform(@this.HexCentreOffset.Width, @this.HexCentreOffset.Height); - // if (path.PathSoFar == null) @this.PaintPathDestination(graphics); - // else @this.PaintPathArrow(graphics, path.PathStep.HexsideExit); - //} - - ///// Paint the direction arrow for each hex of the current shortest path. - ///// The map to be painted, as a . - ///// The object for the canvas being painted. - ///// Type: - - ///// Direction from this hex in which the next step is made. - ///// The current graphics origin must be the centre of the current hex. - //static void PaintPathArrow(this IMapDisplayWinForms @this, Graphics graphics, Hexside hexside) - //where THex:IHex { - // var unit = @this.GridSize.Height/8.0F; - // graphics.RotateTransform(60 * hexside); - // graphics.DrawLine(Pens.Black, 0,unit*4, 0, -unit); - // graphics.DrawLine(Pens.Black, 0,unit*4, -unit*3/2, unit*2); - // graphics.DrawLine(Pens.Black, 0,unit*4, unit*3/2, unit*2); - //} - - ///// Paint the destination indicator for the current shortest path. - ///// The map to be painted, as a . - ///// The object for the canvas being painted. - ///// The current graphics origin must be the centre of the current hex. - //static void PaintPathDestination(this IMapDisplayWinForms @this, Graphics graphics) - //where THex:IHex { - // var unit = @this.GridSize.Height/8.0F; - // graphics.DrawLine(Pens.Black, -unit*2,-unit*2, unit*2, unit*2); - // graphics.DrawLine(Pens.Black, -unit*2, unit*2, unit*2,-unit*2); - //} - - ///// . - ///// - ///// - ///// Returns clones to avoid inter-thread contention. - ///// - //private static Brush GetHexBrush(this IHex hex) { - // switch(hex.TerrainType) { - // default: return UndefinedBrush; - // case '.': return ClearBrush; - // case '2': return PikeBrush; - // case '3': return RoadBrush; - // case 'F': return FordBrush; - // case 'H': return HillBrush; - // case 'M': return MountainBrush; - // case 'R': return RiverBrush; - // case 'W': return WoodsBrush; - // } - //} - - ///// Gets the base color for the shading brush used by Field-of-View display to indicate non-visible hexes. - //private static Color ShadeColor = Color.Black; - //private static Brush TextBrush = (Brush)Brushes.Black.Clone(); - - //private static Brush UndefinedBrush = (Brush)Brushes.SlateGray.Clone(); - //private static Brush ClearBrush = (Brush)Brushes.White.Clone(); - //private static Brush PikeBrush = (Brush)Brushes.DarkGray.Clone(); - //private static Brush RoadBrush = (Brush)Brushes.SandyBrown.Clone(); - //private static Brush FordBrush = (Brush)Brushes.Brown.Clone(); - //private static Brush HillBrush = (Brush)Brushes.Khaki.Clone(); - //private static Brush MountainBrush = (Brush)Brushes.DarkKhaki.Clone(); - //private static Brush RiverBrush = (Brush)Brushes.DarkBlue.Clone(); - //private static Brush WoodsBrush = (Brush)Brushes.Green.Clone(); - - ///// Performs the specified for each hex of in . - ///// - ///// The map to be painted, as a . - ///// The rectangular extent of hexes to be painted as a . - ///// The to be performed with each hex. - //private static void ForEachHex(this IMapDisplayWinForms @this, CoordsRectangle clipRectangle, - // Action action) - //where THex:IHex - //=> @this.BoardHexes.ForEachSerial(maybe => - // maybe.IfHasValueDo(hex => { if (clipRectangle.EncompassesHex(hex.Coords)) action(hex); } ) - // ); - - ///// TODO - ///// The to be painted - ///// The object for the canvas being painted. - ///// The closed outlining the hex to be painted. - ///// The to be used in filling this hex. - //private static void Paint(this IHex @this, Graphics graphics, GraphicsPath path, Brush brush) { - // lock(brush) graphics.FillPath(brush, path); - //} } }