示例#1
0
        public void GameWindow()
        {
            {
                ImGui.Begin("Level Window");
                //
                ImGui.BeginChild("Level batch", Num.Vector2.Zero, true, ImGuiWindowFlags.AlwaysHorizontalScrollbar);

                //TileTools
                ImGui.BeginGroup();

                if (ImGui.Button("Pencil"))
                {
                    PlaceMode = 0;
                }
                ImGui.SameLine();
                if (ImGui.Button("Rectangle"))
                {
                    PlaceMode = 1;
                }
                ImGui.SameLine();
                if (ImGui.Button("Fill (Unimplemented)"))
                {
                    PlaceMode = 2;
                }
                ImGui.SliderInt("GameZoom", ref GameZoom, 1, 4);

                ImGui.EndGroup();

                ImGui.Image(levelTexture, new Num.Vector2((MapSize.X * 16) * GameZoom, (MapSize.Y * 16) * GameZoom));
                //Get Top left of image
                Num.Vector2 editorTopLeft = ImGui.GetItemRectMin();
                Rectangle   editorRect    = new Rectangle((int)(editorTopLeft.X), (int)(editorTopLeft.Y), (int)(MapSize.X * 16) * GameZoom, (int)((MapSize.Y * 16) * GameZoom));
                Prim.DrawRectangle(editorRect, Color.Black);
                if (viewTileGrid)
                {
                    Prim.DrawGrid(editorRect, (16 * GameZoom), (16 * GameZoom), new Color(0, 0, 0, 128));
                }
                Prim.DrawGrid(editorRect, (Screen.GameWidth * GameZoom), (Screen.GameHeight * GameZoom), Color.Yellow);

                //MousePosition in tile pallate
                editorMousePos   = (ImGui.GetMousePos() - editorTopLeft);
                editorMousePos  /= (16 * GameZoom);
                editorMousePos.X = (int)Math.Floor(editorMousePos.X);
                editorMousePos.Y = (int)Math.Floor(editorMousePos.Y);
                editorMousePos  *= (16 * GameZoom);

                Num.Vector2 flatMousePos = ImGui.GetMousePos();
                if (MathMore.PointInRectangle(new Vector2(flatMousePos.X, flatMousePos.Y), editorRect))
                {
                    switch (PlaceMode)
                    {
                    case 0:         // Pen
                    {
                        #region     // PenTool
                        Rectangle editorCursorRect = new Rectangle((int)(editorMousePos.X + editorRect.X), (int)(editorMousePos.Y + editorRect.Y), (SelectedTileBrush.GetLength(0) * 16) * GameZoom, (SelectedTileBrush.GetLength(1) * 16) * GameZoom);
                        Prim.DrawRectangle(editorCursorRect, Color.Maroon);

                        //Click Tile
                        if (ImGui.IsMouseDown(ImGuiMouseButton.Left))
                        {
                            Num.Vector2 gridPos = (editorMousePos / (16 * GameZoom));

                            //Draw rect
                            for (int xx = (int)gridPos.X; xx < (int)gridPos.X + SelectedTileBrush.GetLength(0); xx++)
                            {
                                for (int yy = (int)gridPos.Y; yy < (int)gridPos.Y + SelectedTileBrush.GetLength(1); yy++)
                                {
                                    int bX = (int)(xx - (int)gridPos.X);
                                    int bY = (int)(yy - (int)gridPos.Y);

                                    Point tileP = SelectedTileBrush[bX, bY];

                                    TileLayers[LayerListPosition].tileSet.SetGridPosition(new Point(xx, yy), tileP);
                                }
                            }
                        }

                        if (ImGui.IsMouseDown(ImGuiMouseButton.Right))
                        {
                            Num.Vector2 gridPos = (editorMousePos / (16 * GameZoom));
                            //EraseRect
                            for (int xx = (int)gridPos.X; xx < (int)gridPos.X + SelectedTileBrush.GetLength(0); xx++)
                            {
                                for (int yy = (int)gridPos.Y; yy < (int)gridPos.Y + SelectedTileBrush.GetLength(1); yy++)
                                {
                                    TileLayers[LayerListPosition].tileSet.SetGridPosition(new Point(xx, yy), Point.Zero);
                                }
                            }
                        }
                        #endregion         // EndPenTool
                        break;
                    }

                    case 1:
                    {
                        #region         // RectangleTool
                        Num.Vector2 gridPos = (editorMousePos / (16 * GameZoom));

                        if (ImGui.IsMouseClicked(ImGuiMouseButton.Left))
                        {
                            rectPlaceTopLeft  = new Point((int)gridPos.X, (int)gridPos.Y);
                            rectPlaceBotRight = new Point((int)gridPos.X + 1, (int)gridPos.Y + 1);
                        }
                        else if (ImGui.IsMouseReleased(ImGuiMouseButton.Left))
                        {
                            rectPlaceBotRight = new Point((int)gridPos.X + 1, (int)gridPos.Y + 1);

                            //order
                            Point tl = new Point(Math.Min(rectPlaceBotRight.X, rectPlaceTopLeft.X), Math.Min(rectPlaceBotRight.Y, rectPlaceTopLeft.Y));
                            Point rl = new Point(Math.Max(rectPlaceBotRight.X, rectPlaceTopLeft.X), Math.Max(rectPlaceBotRight.Y, rectPlaceTopLeft.Y));

                            rectPlaceTopLeft  = tl;
                            rectPlaceBotRight = rl;

                            //Place
                            int xdif = rectPlaceBotRight.X - rectPlaceTopLeft.X;
                            int ydif = rectPlaceBotRight.Y - rectPlaceTopLeft.Y;
                            xdif = Math.Max(1, xdif);
                            ydif = Math.Max(1, ydif);

                            for (int xx = rectPlaceTopLeft.X; xx < rectPlaceTopLeft.X + xdif; xx++)
                            {
                                for (int yy = rectPlaceTopLeft.Y; yy < rectPlaceTopLeft.Y + ydif; yy++)
                                {
                                    int bX = (int)(xx - (int)rectPlaceTopLeft.X) % SelectedTileBrush.GetLength(0);
                                    int bY = (int)(yy - (int)rectPlaceTopLeft.Y) % SelectedTileBrush.GetLength(1);



                                    Point tileP = SelectedTileBrush[bX, bY];

                                    TileLayers[LayerListPosition].tileSet.SetGridPosition(new Point(xx, yy), tileP);
                                }
                            }
                        }
                        else if (ImGui.IsMouseDown(ImGuiMouseButton.Left))
                        {
                            rectPlaceBotRight = new Point((int)gridPos.X + 1, (int)gridPos.Y + 1);

                            int       mgic     = 16 * GameZoom;
                            Point     tl       = new Point((int)editorTopLeft.X + (rectPlaceTopLeft.X * mgic), (int)editorTopLeft.Y + (rectPlaceTopLeft.Y * mgic));
                            Rectangle rectRect = new Rectangle(tl, new Point((rectPlaceBotRight.X - rectPlaceTopLeft.X) * mgic, (rectPlaceBotRight.Y - rectPlaceTopLeft.Y) * mgic));

                            Prim.DrawRectangle(rectRect, Color.Maroon);
                        }
                        else
                        {
                            Rectangle editorCursorRect = new Rectangle((int)(editorMousePos.X + editorRect.X), (int)(editorMousePos.Y + editorRect.Y), (SelectedTileBrush.GetLength(0) * 16) * GameZoom, (SelectedTileBrush.GetLength(1) * 16) * GameZoom);
                            Prim.DrawRectangle(editorCursorRect, Color.Maroon);
                        }

                        #endregion
                        break;
                    }
                    }
                }

                ImGui.EndChild();

                //
                ImGui.End();
            }
        }
示例#2
0
        public void TilePallateWindow()
        {
            //Tile Pallate Window
            {
                ImGui.Begin("Tiles");
                //Draw Tile set
                ImGui.Image(tilePallateTexture, new Num.Vector2(tilePallateTextureSize.X, tilePallateTextureSize.Y) * tileSetZoom);

                //Get top left of window and draw rect around texture
                Num.Vector2 imageTopLeft    = ImGui.GetItemRectMin();
                Rectangle   tilePallateRect = new Rectangle((int)(imageTopLeft.X), (int)(imageTopLeft.Y), (int)tilePallateTextureSize.X * tileSetZoom, (int)tilePallateTextureSize.Y * tileSetZoom);
                Prim.DrawRectangle(tilePallateRect, Color.Black);

                Prim.DrawGrid(tilePallateRect, (16 * tileSetZoom), (16 * tileSetZoom), Color.Black);

                //Allow zoom on tileset
                ImGui.InputInt("Zoom", ref tileSetZoom, 1);
                tileSetZoom = MathHelper.Clamp(tileSetZoom, 1, 3);

                //MousePosition in tile pallate
                tilePallateMousePos   = (ImGui.GetMousePos() - imageTopLeft);
                tilePallateMousePos  /= (16 * tileSetZoom);
                tilePallateMousePos.X = (int)Math.Floor(tilePallateMousePos.X);
                tilePallateMousePos.Y = (int)Math.Floor(tilePallateMousePos.Y);
                tilePallateMousePos  *= (16 * tileSetZoom);

                int xdif = selectedTopRight.X - selectedTopLeft.X;
                int ydif = selectedTopRight.Y - selectedTopLeft.Y;
                xdif = Math.Max(1, xdif);
                ydif = Math.Max(1, ydif);

                Rectangle tileSelectedRect = new Rectangle((int)((selectedTopLeft.X * 16 * tileSetZoom) + imageTopLeft.X), (int)((selectedTopLeft.Y * 16 * tileSetZoom) + imageTopLeft.Y), (16 * tileSetZoom) * xdif, (16 * tileSetZoom) * ydif);
                Prim.DrawRectangle(tileSelectedRect, Color.Lime);

                //Select Rectangle of tiles
                Num.Vector2 flatMousePos = ImGui.GetMousePos();
                if (MathMore.PointInRectangle(new Vector2(flatMousePos.X, flatMousePos.Y), tilePallateRect))
                {
                    Num.Vector2 tilePos = (tilePallateMousePos / (16 * tileSetZoom));

                    Rectangle tileCursorRect = new Rectangle((int)((selectedTopLeft.X * 16 * tileSetZoom) + imageTopLeft.X), (int)((selectedTopLeft.Y * 16 * tileSetZoom) + imageTopLeft.Y), (16 * tileSetZoom) * xdif, (16 * tileSetZoom) * ydif);
                    Prim.DrawRectangle(tileCursorRect, Color.Maroon);

                    if (ImGui.IsMouseClicked(ImGuiMouseButton.Left))
                    {
                        selectedTopLeft = new Point((int)tilePos.X, (int)tilePos.Y);
                    }
                    else if (ImGui.IsMouseDown(ImGuiMouseButton.Left))
                    {
                        selectedTopRight = new Point((int)tilePos.X + 1, (int)tilePos.Y + 1);
                    }
                    else if (ImGui.IsMouseReleased(ImGuiMouseButton.Left))
                    {
                        SelectedTileBrush = new Point[xdif, ydif];

                        for (int xx = 0; xx < xdif; xx++)
                        {
                            for (int yy = 0; yy < ydif; yy++)
                            {
                                SelectedTileBrush[xx, yy] = new Point(xx + selectedTopLeft.X, yy + selectedTopLeft.Y);
                            }
                        }
                    }
                }
                //ImGui.Text($"Tile Pos: {SelectedTile.ToString()}");

                ImGui.End();
            }
        }