Esempio n. 1
0
        private PointAxial?handleEdges(PointAxial ip, Direction dir, bool?isPositive)
        {
            if (_file.Grid.Size == 1)
            {
                return(new PointAxial(0, 0));
            }

            if (ip.InGrid(_file.Grid.Size))
            {
                return(ip);
            }

            var x = ip.Q;
            var z = ip.R;
            var y = -x - z;

            var xBigger = Math.Abs(x) >= _file.Grid.Size;
            var yBigger = Math.Abs(y) >= _file.Grid.Size;
            var zBigger = Math.Abs(z) >= _file.Grid.Size;

            // Move the pointer back to the hex near the edge
            ip -= dir.Vector;

            // If two values are still in range, we are wrapping around an edge (not a corner).
            if (!xBigger && !yBigger)
            {
                return(new PointAxial(ip.Q + ip.R, -ip.R));
            }
            else if (!yBigger && !zBigger)
            {
                return(new PointAxial(-ip.Q, ip.Q + ip.R));
            }
            else if (!zBigger && !xBigger)
            {
                return(new PointAxial(-ip.R, -ip.Q));
            }

            // If two values are out of range, we navigated into a corner.
            if (isPositive == null)
            {
                return(null);
            }
            // We teleport to a location that depends on the current memory value.
            if ((!xBigger && !isPositive.Value) || (!yBigger && isPositive.Value))
            {
                return(new PointAxial(ip.Q + ip.R, -ip.R));
            }
            else if ((!yBigger && !isPositive.Value) || (!zBigger && isPositive.Value))
            {
                return(new PointAxial(-ip.Q, ip.Q + ip.R));
            }
            else if ((!zBigger && !isPositive.Value) || (!xBigger && isPositive.Value))
            {
                return(new PointAxial(-ip.R, -ip.Q));
            }

            // This should never be reached
            throw new InvalidOperationException();
        }
Esempio n. 2
0
        public PointAxial?FromScreen(int x, int y)
        {
            var r      = (y - YPadding) / (double)YTextSpacing - (Grid.Size - 1);
            var q      = ((x - XPadding) / (double)XTextSpacing - r) / 2 - (Grid.Size - 1);
            var result = new PointAxial((int)Math.Round(q), (int)Math.Round(r));

            return(result.InGrid(Grid.Size) ? result : (PointAxial?)null);
        }
Esempio n. 3
0
        private void lstKeyDown(object sender, KeyEventArgs e)
        {
            if (_lastRendering == null)
            {
                return;
            }

            switch (e.KeyCode)
            {
            case Keys.Left:
                if (leftHeld)                           // allow holding a key to repeat
                {
                    heldUsed = true;
                    moveSelection(Direction.West);
                }
                else
                {
                    leftHeld = true;
                    heldUsed = false;
                }
                e.Handled = true;
                break;

            case Keys.Right:
                if (rightHeld)                           // allow holding a key to repeat
                {
                    heldUsed = true;
                    moveSelection(Direction.East);
                }
                else
                {
                    rightHeld = true;
                    heldUsed  = false;
                }
                e.Handled = true;
                break;

            case Keys.Up:
                if (leftHeld)
                {
                    heldUsed = true;
                    moveSelection(Direction.NorthWest);
                }
                else if (rightHeld)
                {
                    heldUsed = true;
                    moveSelection(Direction.NorthEast);
                }
                else
                {
                    return;                             // default handle (change list selection)
                }
                e.Handled = true;
                break;

            case Keys.Down:
                if (leftHeld)
                {
                    heldUsed = true;
                    moveSelection(Direction.SouthWest);
                }
                else if (rightHeld)
                {
                    heldUsed = true;
                    moveSelection(Direction.SouthEast);
                }
                else
                {
                    return;
                }
                e.Handled = true;
                break;

            case Keys.Enter:
                editPath();
                return;

            case Keys.Insert:
                startPath();
                return;

            case Keys.Home:
                setStartPos();
                return;

            case Keys.OemOpenBrackets:
                if (e.Control && _file.Grid.Size > 1)
                {
                    _file.Grid = _file.Grid.resize(_file.Grid.Size - 1);
                    if (!_selection.InGrid(_file.Grid.Size))
                    {
                        _selection = new PointAxial(0, 0);
                    }
                    rerender();
                    _anyChanges = true;
                }
                break;

            case Keys.OemCloseBrackets:
                if (e.Control)
                {
                    _file.Grid = _file.Grid.resize(_file.Grid.Size + 1);
                    rerender();
                    _anyChanges = true;
                }
                break;

            case Keys.Escape:
                toggleCursor();
                break;

            default:
                return;
            }
        }