コード例 #1
0
        private int?CompareLinks(RmpEntry list, int index)
        {
            if (list != null)
            {
                var existingLink   = false;
                var spaceAvailable = false;
                var spaceAt        = 512;

                for (int i = 0; i < 5; i++)
                {
                    if (list[i].Index == index)
                    {
                        existingLink = true;
                        break;
                    }

                    if (list[i].Index == (byte)LinkTypes.NotUsed)
                    {
                        spaceAvailable = true;
                        if (i < spaceAt)
                        {
                            spaceAt = i;
                        }
                    }
                }

                if (!existingLink && spaceAvailable)
                {
                    return(spaceAt);
                }
            }
            return(null);
        }
コード例 #2
0
        // NOTE: The problem with these 'leave' functions is that the current
        // node is no longer valid but the functions try to manipulate it anyway.
        // TODO: Study and rethink (ie. fix) auto-node-connections.
        private void cbLink_Leave(ComboBox sender, int senderIndex)
        {
            if (_currEntry != null)             // kL: bypass.
            {
                if (!_loadingGui && sender.SelectedItem != null)
                {
                    var connectType = GetConnectNodeType();
                    if (connectType == ConnectNodeTypes.ConnectTwoWays)
                    {
                        RmpEntry connected = _map.Rmp[_currEntry[senderIndex].Index];

                        var spaceAt = CompareLinks(connected, (byte)sender.SelectedItem);
                        if (spaceAt.HasValue)
                        {
                            connected[spaceAt.Value].Index    = _currEntry.Index;
                            connected[spaceAt.Value].Distance = calcLinkDistance(
                                connected,
                                _currEntry,
                                null);
                        }
                        Refresh();
                    }
                }
            }
        }
コード例 #3
0
        private void ConnectNewNode(RmpEntry prevEntry)
        {
            if (prevEntry != null)
            {
                var connectType = GetConnectNodeType();
                if (connectType != ConnectNodeTypes.DontConnect)
                {
                    var prevEntryLink = GetNextAvailableLink(prevEntry);
                    if (prevEntryLink != null)
                    {
                        prevEntryLink.Index    = (byte)(_map.Rmp.Length - 1);
                        prevEntryLink.Distance = calcLinkDistance(
                            prevEntry,
                            _currEntry,
                            null);
                    }

                    if (connectType == ConnectNodeTypes.ConnectTwoWays)
                    {
                        var firstLink = _currEntry[0];
                        firstLink.Index    = prevEntry.Index;
                        firstLink.Distance = calcLinkDistance(
                            _currEntry,
                            prevEntry,
                            txtDist1);
                    }
                }
            }
        }
コード例 #4
0
        private void ConnectNodes(RmpEntry selEntry)
        {
            var connectType = GetConnectNodeType();

            if (connectType != ConnectNodeTypes.DontConnect &&
                !_currEntry.Equals(selEntry))
            {
                var spaceAt = CompareLinks(_currEntry, selEntry.Index);
                if (spaceAt.HasValue)
                {
                    _currEntry[spaceAt.Value].Index    = selEntry.Index;
                    _currEntry[spaceAt.Value].Distance = calcLinkDistance(
                        _currEntry,
                        selEntry,
                        null);
                }

                if (connectType == ConnectNodeTypes.ConnectTwoWays)
                {
                    spaceAt = CompareLinks(selEntry, _currEntry.Index);
                    if (spaceAt.HasValue)
                    {
                        selEntry[spaceAt.Value].Index    = _currEntry.Index;
                        selEntry[spaceAt.Value].Distance = calcLinkDistance(
                            selEntry,
                            _currEntry,
                            null);
                    }
                }
            }
        }
コード例 #5
0
        private static Link GetNextAvailableLink(RmpEntry prevEntry)
        {
            for (int pI = 0; pI < prevEntry.NumLinks; pI++)
            {
                if (prevEntry[pI].Index == 0xFF)
                {
                    return(prevEntry[pI]);
                }
            }

            return(null);
        }
コード例 #6
0
        private byte calcLinkDistance(RmpEntry from, RmpEntry to, TextBox result)
        {
            var dist = (int)Math.Sqrt(
                Math.Pow(from.Row - to.Row, 2) +
                Math.Pow(from.Col - to.Col, 2) +
                Math.Pow(from.Height - to.Height, 2));

            if (result != null)
            {
                result.Text = dist.ToString();
            }

            return((byte)dist);
        }
コード例 #7
0
        private void cbLink_SelectedIndexChanged(
            ComboBox sender,
            int senderIndex,
            TextBox senderOut)
        {
            if (!_loadingGui)
            {
                var selIdx = sender.SelectedItem as byte?;
                if (!selIdx.HasValue)
                {
                    selIdx = (byte?)(sender.SelectedItem as LinkTypes?);
                }

                if (!selIdx.HasValue)
                {
                    MessageBox.Show("ERROR: Determining SelectedIndex value failed");
                }
                else
                {
                    try
                    {
                        _currEntry[senderIndex].Index = selIdx.Value;
                        if (_currEntry[senderIndex].Index < 0xFB)
                        {
                            RmpEntry connected = _map.Rmp[_currEntry[senderIndex].Index];
                            _currEntry[senderIndex].Distance = calcLinkDistance(
                                _currEntry,
                                connected,
                                senderOut);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("ERROR: " + ex.Message);
                    }
                    Refresh();
                }
            }
        }
コード例 #8
0
        private void RmpPanel_PanelClick(object sender, MapPanelClickEventArgs e)
        {
            _rmpPanel.Focus();

            idxLabel.Text = Text;
            try
            {
                if (_currEntry != null && e.MouseEventArgs.Button == MouseButtons.Right)
                {
                    RmpEntry selEntry = ((XCMapTile)e.ClickTile).Rmp;
                    if (selEntry != null)
                    {
                        ConnectNodes(selEntry);

                        _currEntry = selEntry;
                        FillGui();
                        Refresh();

                        _map.MapChanged = true;
                        return;
                    }
                }

                var prevEntry = _currEntry;

                _currEntry = ((XCMapTile)e.ClickTile).Rmp;
                if (_currEntry == null && e.MouseEventArgs.Button == MouseButtons.Right)
                {
                    _currEntry = _map.AddRmp(e.ClickLocation);
                    ConnectNewNode(prevEntry);
                    _map.MapChanged = true;
                }
            }
            catch
            {
                return;
            }
            FillGui();
        }
コード例 #9
0
 private void ClearSelected()
 {
     _currEntry = null;
     _rmpPanel.ClearSelected();
 }
コード例 #10
0
        private void DrawSelectedLink(Graphics g)
        {
            if (ClickPoint.X > -1 && ClickPoint.Y > -1)
            {
                var map = Map;

                if (((XCMapTile)map[ClickPoint.Y, ClickPoint.X]).Rmp != null)
                {
                    var      pen = MapPens["SelectedLinkColor"];
                    var      r   = ClickPoint.Y;
                    var      c   = ClickPoint.X;
                    RmpEntry f   = ((XCMapTile)map[r, c]).Rmp;

                    var unknownLocationX = Origin.X + (c - r) * DrawAreaWidth;
                    var unknownLocationY = Origin.Y + (c + r + 1) * DrawAreaHeight;

                    for (int rr = 0; rr < f.NumLinks; rr++)
                    {
                        Link l = f[rr];
                        switch (l.Index)
                        {
                        case Link.NOT_USED:
                            break;

                        case Link.EXIT_EAST:
                            g.DrawLine(
                                pen,
                                unknownLocationX, unknownLocationY,
                                Width, Height);
                            break;

                        case Link.EXIT_NORTH:
                            g.DrawLine(
                                pen,
                                unknownLocationX, unknownLocationY,
                                Width, 0);
                            break;

                        case Link.EXIT_SOUTH:
                            g.DrawLine(
                                pen,
                                unknownLocationX, unknownLocationY,
                                0, Height);
                            break;

                        case Link.EXIT_WEST:
                            g.DrawLine(
                                pen,
                                unknownLocationX, unknownLocationY,
                                0, 0);
                            break;

                        default:
                            if (map.Rmp[l.Index] != null &&
                                map.Rmp[l.Index].Height == map.CurrentHeight)
                            {
                                int toRow = map.Rmp[l.Index].Row;
                                int toCol = map.Rmp[l.Index].Col;

                                g.DrawLine(
                                    pen,
                                    unknownLocationX, unknownLocationY,
                                    Origin.X + (toCol - toRow) * DrawAreaWidth,
                                    Origin.Y + (toCol + toRow + 1) * DrawAreaHeight);
                            }
                            break;
                        }
                    }
                }
            }
        }
コード例 #11
0
        private void DrawUnselectedLink(GraphicsPath upper, Graphics graphics)
        {
            var map = Map;

            for (int row = 0, startX = Origin.X, startY = Origin.Y;
                 row < map.MapSize.Rows;
                 row++, startX -= DrawAreaWidth, startY += DrawAreaHeight)
            {
                for (int col = 0, x = startX, y = startY;
                     col < map.MapSize.Cols;
                     col++, x += DrawAreaWidth, y += DrawAreaHeight)
                {
                    if (map[row, col] != null && ((XCMapTile)map[row, col]).Rmp != null)
                    {
                        RmpEntry f = ((XCMapTile)map[row, col]).Rmp;
                        upper.Reset();
                        upper.AddLine(
                            x, y,
                            x + DrawAreaWidth, y + DrawAreaHeight);
                        upper.AddLine(
                            x + DrawAreaWidth, y + DrawAreaHeight,
                            x, y + 2 * DrawAreaHeight);
                        upper.AddLine(
                            x, y + 2 * DrawAreaHeight,
                            x - DrawAreaWidth, y + DrawAreaHeight);
                        upper.CloseFigure();

                        for (int rr = 0; rr < f.NumLinks; rr++)
                        {
                            Link l   = f[rr];
                            var  pen = MapPens["UnselectedLinkColor"];
                            switch (l.Index)
                            {
                            case Link.NOT_USED:
                                break;

                            case Link.EXIT_EAST:
                                graphics.DrawLine(
                                    pen,
                                    x, y + DrawAreaHeight,
                                    Width, Height);
                                break;

                            case Link.EXIT_NORTH:
                                graphics.DrawLine(
                                    pen,
                                    x, y + DrawAreaHeight,
                                    Width, 0);
                                break;

                            case Link.EXIT_SOUTH:
                                graphics.DrawLine(
                                    pen,
                                    x, y + DrawAreaHeight,
                                    0, Height);
                                break;

                            case Link.EXIT_WEST:
                                graphics.DrawLine(
                                    pen,
                                    x, y + DrawAreaHeight,
                                    0, 0);
                                break;

                            default:
                                if (map.Rmp[l.Index] != null &&
                                    map.Rmp[l.Index].Height == map.CurrentHeight)
                                {
                                    int toRow = map.Rmp[l.Index].Row;
                                    int toCol = map.Rmp[l.Index].Col;
                                    graphics.DrawLine(
                                        pen,
                                        x, y + DrawAreaHeight,
                                        Origin.X + (toCol - toRow) * DrawAreaWidth,
                                        Origin.Y + (toCol + toRow + 1) * DrawAreaHeight);
                                }
                                break;
                            }
                        }
                    }
                }
            }
        }