Ejemplo n.º 1
0
        /// <summary>
        /// Checks for and if found gives user a choice to delete nodes that are
        /// outside of a Map's x/y/z bounds.
        /// </summary>
        /// <param name="child"></param>
        public static void CheckNodeBounds(MapFileChild child)
        {
            if (child != null)
            {
                var invalids = new List <RouteNode>();

                foreach (RouteNode node in child.Routes)
                {
                    if (RouteNodeCollection.IsOutsideMap(
                            node,
                            child.MapSize.Cols,
                            child.MapSize.Rows,
                            child.MapSize.Levs))
                    {
                        invalids.Add(node);
                    }
                }

                if (invalids.Count != 0)
                {
                    string info = String.Format(
                        System.Globalization.CultureInfo.CurrentCulture,
                        "There {0} " + invalids.Count + " route-node{1} outside"
                        + " the bounds of this Map.{3}Do you want {2} deleted ?{3}",
                        (invalids.Count == 1) ? "is" : "are",
                        (invalids.Count == 1) ? ""   : "s",
                        (invalids.Count == 1) ? "it" : "them",
                        Environment.NewLine);

                    foreach (var node in invalids)
                    {
                        info += Environment.NewLine
                                + "id " + node.Index
                                + " : " + node.GetLocationString(child.MapSize.Levs);
                    }

                    if (MessageBox.Show(
                            info,
                            "Invalid Nodes",
                            MessageBoxButtons.YesNo,
                            MessageBoxIcon.Question,
                            MessageBoxDefaultButton.Button1,
                            0) == DialogResult.Yes)
                    {
                        child.RoutesChanged = true;

                        foreach (var node in invalids)
                        {
                            child.Routes.DeleteNode(node);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Fills the list with any invalid nodes.
 /// </summary>
 /// <returns>count of invalid nodes</returns>
 private static int GetInvalidNodes()
 {
     foreach (RouteNode node in _file.Routes)
     {
         if (RouteNodeCollection.IsNodeOutsideMapBounds(
                 node,
                 _file.MapSize.Cols,
                 _file.MapSize.Rows,
                 _file.MapSize.Levs))
         {
             _invalids.Add(node);
         }
     }
     return(_invalids.Count);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Checks for and if found gives user a choice to delete nodes that are
        /// outside of a Map's x/y/z bounds.
        /// </summary>
        /// <param name="mapFile"></param>
        public static void CheckNodeBounds(MapFileChild mapFile)
        {
            if (mapFile != null)
            {
                var invalid = new List <RouteNode>();

                foreach (RouteNode node in mapFile.Routes)
                {
                    if (RouteNodeCollection.IsOutsideMap(
                            node,
                            mapFile.MapSize.Cols,
                            mapFile.MapSize.Rows,
                            mapFile.MapSize.Levs))
                    {
                        invalid.Add(node);
                    }
                }

                if (invalid.Count != 0)
                {
                    if (MessageBox.Show(
                            "There are route nodes outside the bounds of"
                            + " this Map. Do you want them removed?",
                            "Invalid Nodes",
                            MessageBoxButtons.YesNo,
                            MessageBoxIcon.Question,
                            MessageBoxDefaultButton.Button1,
                            0) == DialogResult.Yes)
                    {
                        mapFile.RoutesChanged = true;

                        foreach (var node in invalid)
                        {
                            mapFile.Routes.DeleteNode(node);
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Checks for and if found gives user a choice to delete nodes that are
        /// outside of a Map's x/y/z bounds.
        /// </summary>
        /// <param name="child"></param>
        /// <returns>true if node(s) are deleted</returns>
        public static bool CheckNodeBoundsMenuitem(MapFileChild child)
        {
            if (child != null)
            {
                var invalids = new List <RouteNode>();

                foreach (RouteNode node in child.Routes)
                {
                    if (RouteNodeCollection.IsOutsideMap(
                            node,
                            child.MapSize.Cols,
                            child.MapSize.Rows,
                            child.MapSize.Levs))
                    {
                        invalids.Add(node);
                    }
                }

                string            info, title;
                MessageBoxIcon    icon;
                MessageBoxButtons btns;

                if (invalids.Count != 0)
                {
                    icon  = MessageBoxIcon.Warning;
                    btns  = MessageBoxButtons.YesNo;
                    title = "Warning";
                    info  = String.Format(
                        System.Globalization.CultureInfo.CurrentCulture,
                        "There {0} " + invalids.Count + " route-node{1} outside"
                        + " the bounds of this Map.{3}Do you want {2} deleted ?{3}",
                        (invalids.Count == 1) ? "is" : "are",
                        (invalids.Count == 1) ? ""   : "s",
                        (invalids.Count == 1) ? "it" : "them",
                        Environment.NewLine);

                    foreach (var node in invalids)
                    {
                        info += Environment.NewLine
                                + "id " + node.Index
                                + " : " + node.GetLocationString(child.MapSize.Levs);
                    }
                }
                else
                {
                    icon  = MessageBoxIcon.Information;
                    btns  = MessageBoxButtons.OK;
                    title = "Good stuff, Magister Ludi";
                    info  = "There are no Out of Bounds nodes detected.";
                }

                if (MessageBox.Show(
                        info,
                        title,
                        btns,
                        icon,
                        MessageBoxDefaultButton.Button1,
                        0) == DialogResult.Yes)
                {
                    child.RoutesChanged = true;

                    foreach (var node in invalids)
                    {
                        child.Routes.DeleteNode(node);
                    }

                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Draws link-lines for a given node.
        /// </summary>
        /// <param name="xSrc"></param>
        /// <param name="ySrc"></param>
        /// <param name="node"></param>
        /// <param name="selected">(default true)</param>
        private void DrawLinkLines(
            int xSrc,
            int ySrc,
            RouteNode node,
            bool selected = true)
        {
            int       xDst, yDst;
            RouteNode dest;
            byte      destId;

            for (int slot = 0; slot != RouteNode.LinkSlots; ++slot)
            {
                var link = node[slot] as Link;
                if ((destId = link.Destination) != Link.NotUsed)
                {
                    switch (destId)
                    {
                    case Link.ExitWest:
                        if (node.Lev != MapFile.Level)
                        {
                            continue;
                        }

                        xDst = OffsetX + 1;
                        yDst = OffsetY + 1;
                        dest = null;
                        break;

                    case Link.ExitNorth:
                        if (node.Lev != MapFile.Level)
                        {
                            continue;
                        }

                        xDst = Width - OffsetX * 2;
                        yDst = OffsetY + 1;
                        dest = null;
                        break;

                    case Link.ExitEast:
                        if (node.Lev != MapFile.Level)
                        {
                            continue;
                        }

                        xDst = Width - OffsetX * 2;
                        yDst = Height - OffsetY * 2;
                        dest = null;
                        break;

                    case Link.ExitSouth:
                        if (node.Lev != MapFile.Level)
                        {
                            continue;
                        }

                        xDst = OffsetX + 1;
                        yDst = Height - OffsetY * 2;
                        dest = null;
                        break;

                    default:
                        if ((dest = MapFile.Routes[destId]) == null ||
                            dest.Lev != MapFile.Level ||
                            (NodeSelected != null && dest == NodeSelected) ||
                            RouteNodeCollection.IsOutsideMap(
                                dest,
                                MapFile.MapSize.Cols,
                                MapFile.MapSize.Rows,
                                MapFile.MapSize.Levs))
                        {
                            continue;
                        }

                        xDst = Origin.X + (dest.Col - dest.Row) * DrawAreaWidth;
                        yDst = Origin.Y + (dest.Col + dest.Row + 1) * DrawAreaHeight;
                        break;
                    }

                    if (selected)                     // draw link-lines for a selected node ->
                    {
                        var pen = _penLinkSelected;

                        if (SpotPosition.X != -1)
                        {
                            if (dest != null)
                            {
                                if (SpotPosition.X != dest.Col ||
                                    SpotPosition.Y != dest.Row)
                                {
                                    pen = _penLinkUnselected;
                                }
                            }
                            else
                            {
                                switch (destId)                                                                                 // See RouteView.SpotGoDestination() for
                                {                                                                                               // def'n of the following spot-positions ->
                                case Link.ExitNorth:
                                    if (SpotPosition.X != -2)
                                    {
                                        pen = _penLinkUnselected;
                                    }
                                    break;

                                case Link.ExitEast:
                                    if (SpotPosition.X != -3)
                                    {
                                        pen = _penLinkUnselected;
                                    }
                                    break;

                                case Link.ExitSouth:
                                    if (SpotPosition.X != -4)
                                    {
                                        pen = _penLinkUnselected;
                                    }
                                    break;

                                case Link.ExitWest:
                                    if (SpotPosition.X != -5)
                                    {
                                        pen = _penLinkUnselected;
                                    }
                                    break;
                                }
                            }
                        }
                        _graphics.DrawLine(
                            pen,
                            xSrc, ySrc,
                            xDst, yDst);
                    }
                    else                     // draw link-lines for a non-selected node ->
                    {
                        _graphics.DrawLine(
                            _penLinkUnselected,
                            xSrc, ySrc + DrawAreaHeight,                                                     // unselected nodes need an offset
                            xDst, yDst);
                    }
                }
            }
        }