示例#1
0
        public void RightClickGrid(int x, int y, Panel mapGridView)
        {
            for (var x1 = 0; x1 < GridWidth + 2; x1++)
            {
                for (var y1 = 0; y1 < GridHeight + 2; y1++)
                {
                    if (new Rectangle(
                            ContentRect.X + x1 * TileWidth, ContentRect.Y + y1 * TileHeight, TileWidth, TileHeight
                            ).Contains(new System.Drawing.Point(x, y)))
                    {
                        mCurrentCellX = x1;
                        mCurrentCellY = y1;
                        if (mCurrentCellX >= 0 && mCurrentCellY >= 0)
                        {
                            if (mCurrentCellX >= 0 &&
                                mCurrentCellY >= 0 &&
                                mCurrentCellX - 1 <= GridWidth &&
                                mCurrentCellY - 1 <= GridHeight)
                            {
                                if (mCurrentCellX == 0 ||
                                    mCurrentCellY == 0 ||
                                    mCurrentCellX - 1 == GridWidth ||
                                    mCurrentCellY - 1 == GridHeight ||
                                    Grid[mCurrentCellX - 1, mCurrentCellY - 1].MapId == Guid.Empty)
                                {
                                    var adjacentMap = Guid.Empty;

                                    //Check Left
                                    if (mCurrentCellX > 1 && mCurrentCellY != 0 && mCurrentCellY - 1 < GridHeight)
                                    {
                                        if (Grid[mCurrentCellX - 2, mCurrentCellY - 1].MapId != Guid.Empty)
                                        {
                                            adjacentMap = Grid[mCurrentCellX - 2, mCurrentCellY - 1].MapId;
                                        }
                                    }

                                    //Check Right
                                    if (mCurrentCellX < GridWidth &&
                                        mCurrentCellY != 0 &&
                                        mCurrentCellY - 1 < GridHeight)
                                    {
                                        if (Grid[mCurrentCellX, mCurrentCellY - 1].MapId != Guid.Empty)
                                        {
                                            adjacentMap = Grid[mCurrentCellX, mCurrentCellY - 1].MapId;
                                        }
                                    }

                                    //Check Up
                                    if (mCurrentCellX != 0 && mCurrentCellY > 1 && mCurrentCellX - 1 < GridWidth)
                                    {
                                        if (Grid[mCurrentCellX - 1, mCurrentCellY - 2].MapId != Guid.Empty)
                                        {
                                            adjacentMap = Grid[mCurrentCellX - 1, mCurrentCellY - 2].MapId;
                                        }
                                    }

                                    //Check Down
                                    if (mCurrentCellX != 0 &&
                                        mCurrentCellY < GridHeight &&
                                        mCurrentCellX - 1 < GridWidth)
                                    {
                                        if (Grid[mCurrentCellX - 1, mCurrentCellY].MapId != Guid.Empty)
                                        {
                                            adjacentMap = Grid[mCurrentCellX - 1, mCurrentCellY].MapId;
                                        }
                                    }

                                    if (adjacentMap != Guid.Empty)
                                    {
                                        mContextMenu.Show(mapGridView, new System.Drawing.Point(x, y));
                                        mDropDownUnlinkItem.Visible = false;
                                        mDropDownLinkItem.Visible   = true;
                                        mRecacheMapItem.Visible     = false;
                                    }
                                }
                                else
                                {
                                    mContextMap = Grid[mCurrentCellX - 1, mCurrentCellY - 1];
                                    mContextMenu.Show(mapGridView, new System.Drawing.Point(x, y));
                                    mDropDownUnlinkItem.Visible = true;
                                    mRecacheMapItem.Visible     = true;
                                    mDropDownLinkItem.Visible   = false;
                                }
                            }
                        }

                        return;
                    }
                }
            }

            mCurrentCellX = -1;
            mCurrentCellY = -1;
        }
示例#2
0
        public void Load(string[,] mapGrid)
        {
            lock (GetMapGridLock())
            {
                Loaded = false;
                var gridMaps = new List <Guid>();
                GridWidth  = mapGrid.GetLength(0);
                GridHeight = mapGrid.GetLength(1);
                UnloadTextures();
                Grid = new MapGridItem[GridWidth, GridHeight];
                for (var x = -1; x <= GridWidth; x++)
                {
                    for (var y = -1; y <= GridHeight; y++)
                    {
                        if (y == -1 || y == GridHeight || x == -1 || x == GridWidth)
                        {
                        }
                        else
                        {
                            if (mapGrid[x, y] == null)
                            {
                                Grid[x, y] = new MapGridItem(Guid.Empty);
                            }
                            else
                            {
                                var obj = JObject.Parse(mapGrid[x, y]);
                                Grid[x, y] = new MapGridItem(
                                    Guid.Parse(obj["Guid"].ToString()), obj["Name"].ToString(),
                                    int.Parse(obj["Revision"].ToString())
                                    );

                                gridMaps.Add(Grid[x, y].MapId);
                            }
                        }
                    }
                }

                //Get a list of maps -- if they are not in this grid.
                mLinkMaps.Clear();
                for (var i = 0; i < MapList.OrderedMaps.Count; i++)
                {
                    if (!gridMaps.Contains(MapList.OrderedMaps[i].MapId))
                    {
                        mLinkMaps.Add(MapList.OrderedMaps[i].MapId);
                    }
                }

                mMaxZoom    = 1f; //Real Size
                Zoom        = mMinZoom;
                TileWidth   = (int)(Options.TileWidth * Options.MapWidth * Zoom);
                TileHeight  = (int)(Options.TileHeight * Options.MapHeight * Zoom);
                ContentRect = new Rectangle(
                    ViewRect.Width / 2 - TileWidth * (GridWidth + 2) / 2,
                    ViewRect.Height / 2 - TileHeight * (GridHeight + 2) / 2, TileWidth * (GridWidth + 2),
                    TileHeight * (GridHeight + 2)
                    );

                mCreateTextures = true;
                Loaded          = true;
                mGridMaps       = gridMaps;
            }
        }