示例#1
0
        public void RenderInGame()
        {
            if (!WindowManager.LevelEditor)
            {
                return;
            }

            TileEditor.RenderInGame();
            EntityEditor.RenderInGame();
        }
示例#2
0
        public void Render()
        {
            if (!WindowManager.LevelEditor)
            {
                return;
            }

            if (Input.Keyboard.IsDown(Keys.LeftControl, true))
            {
                if (Engine.EditingLevel && Input.Keyboard.WasPressed(Keys.S, true))
                {
                    Save();
                }

                if (Input.Keyboard.WasPressed(Keys.Z, true))
                {
                    Commands.Undo();
                }

                if (Input.Keyboard.WasPressed(Keys.Y, true))
                {
                    Commands.Redo();
                }
            }

            if (Engine.Instance.State is InGameState)
            {
                EntityEditor.Render();
                TileEditor.Render();
                return;
            }

            ImGui.SetNextWindowPos(System.Numerics.Vector2.Zero, ImGuiCond.Once);

            if (!ImGui.Begin("Level Editor", ImGuiWindowFlags.AlwaysAutoResize))
            {
                ImGui.End();
                return;
            }

            var o = currentLevel;

            if (ImGui.Combo("Level", ref currentLevel, levels, levels.Length))
            {
                var oo = currentLevel;
                currentLevel = o;
                Save();
                currentLevel = oo;

                Load();
            }

            if (ImGui.Button("Save"))
            {
                Save();
            }

            ImGui.SameLine();

            if (ImGui.Button("Delete"))
            {
                ImGui.OpenPopup("Delete?##s");
            }

            if (ImGui.BeginPopupModal("Delete?##s"))
            {
                ImGui.Text("This operation can't be undone!");
                ImGui.Text("Are you sure?");

                if (ImGui.Button("Yes"))
                {
                    ImGui.CloseCurrentPopup();
                    Delete();

                    var list = levels.ToList();
                    list.Remove(levels[currentLevel]);
                    levels       = list.ToArray();
                    currentLevel = 0;
                }

                ImGui.SameLine();
                ImGui.SetItemDefaultFocus();

                if (ImGui.Button("No"))
                {
                    ImGui.CloseCurrentPopup();
                }

                ImGui.EndPopup();
            }

            ImGui.SameLine();

            if (ImGui.Button("New"))
            {
                ImGui.OpenPopup("New level");
                levelName   = "new";
                levelWidth  = 32;
                levelHeight = 32;
            }

            if (ImGui.BeginPopupModal("New level"))
            {
                var ol = currentLevel;

                ImGui.SetItemDefaultFocus();
                var input = ImGui.InputText("Name", ref levelName, 64, ImGuiInputTextFlags.EnterReturnsTrue);
                ImGui.InputInt2("Size", ref levelWidth);

                var button = ImGui.Button("Create");
                ImGui.SameLine();

                if (ImGui.Button("Cancel"))
                {
                    ImGui.CloseCurrentPopup();
                }
                else
                {
                    if (input || button)
                    {
                        var oo = currentLevel;
                        currentLevel = ol;
                        Save();
                        currentLevel = oo;

                        levelWidth  = Math.Min(1024, Math.Max(1, levelWidth));
                        levelHeight = Math.Min(1024, Math.Max(1, levelHeight));

                        var list = levels.ToList();
                        list.Add(levelName);

                        levels       = list.ToArray();
                        currentLevel = list.Count - 1;

                        ImGui.CloseCurrentPopup();

                        foreach (var e in Editor.Area.Tagged[Tags.LevelSave])
                        {
                            e.Done = true;
                        }

                        Editor.Area.AutoRemove();
                        Run.Level = null;

                        var level = new RegularLevel {
                            Width           = levelWidth,
                            Height          = levelHeight,
                            NoLightNoRender = false,
                            DrawLight       = false
                        };

                        Editor.Level = level;
                        Editor.Area.Add(level);

                        level.SetBiome(BiomeRegistry.Get(Biome.Castle));
                        level.Setup();
                        level.Fill(Tile.FloorB);
                        level.TileUp();

                        Editor.Camera.Position = Vector2.Zero;
                    }
                }

                ImGui.EndPopup();
            }

            ImGui.Text($"{Editor.Level.Width}x{Editor.Level.Height}");
            ImGui.SameLine();

            if (ImGui.Button("Resize"))
            {
                ImGui.OpenPopup("Resize level");

                levelWidth  = Editor.Level.Width;
                levelHeight = Editor.Level.Height;
            }

            if (ImGui.BeginPopupModal("Resize level"))
            {
                ImGui.Text($"Current size is {Editor.Level.Width}x{Editor.Level.Height}");
                ImGui.InputInt2("New size", ref levelWidth);

                if (ImGui.Button("Resize"))
                {
                    levelWidth  = Math.Min(1024, Math.Max(1, levelWidth));
                    levelHeight = Math.Min(1024, Math.Max(1, levelHeight));

                    Editor.Level.Resize(levelWidth, levelHeight);
                    ImGui.CloseCurrentPopup();
                }

                ImGui.SameLine();

                if (ImGui.Button("Cancel"))
                {
                    ImGui.CloseCurrentPopup();
                }

                ImGui.EndPopup();
            }

            ImGui.End();

            EntityEditor.Render();
            TileEditor.Render();
        }
示例#3
0
        public static void Render()
        {
            if (!ImGui.Begin("Tile editor", ImGuiWindowFlags.AlwaysAutoResize))
            {
                ImGui.End();
                open = false;
                return;
            }

            open = true;

            if (ImGui.Combo("Biome", ref currentBiome, biomes, biomes.Length))
            {
                Editor.Level.SetBiome(BiomeRegistry.Get(biomes[currentBiome]));
                ReloadBiome();
            }

            ImGui.Checkbox("Show grid", ref Grid);

            EntityEditor.RemoveEntity();

            var down    = !ImGui.GetIO().WantCaptureMouse&& Input.Mouse.CheckLeftButton;
            var clicked = !ImGui.GetIO().WantCaptureMouse&& MouseData.HadClick;

            ImGui.Checkbox("Fill", ref fill);
            ImGui.Separator();

            if (CurrentInfo == null)
            {
                CurrentInfo = infos[1];
            }

            var cur = CurrentInfo;

            ImGui.ImageButton(cur.Texture, tileSize, cur.Uv0, cur.Uv1, 4, bg, tintColor);
            ImGui.SameLine();
            ImGui.Text(CurrentInfo.Tile.ToString());

            if (CurrentInfo.Tile.Matches(TileFlags.LiquidLayer))
            {
                ImGui.SameLine();
                ImGui.Text("Liquid");
            }
            else if (CurrentInfo.Tile.Matches(TileFlags.WallLayer))
            {
                ImGui.SameLine();
                ImGui.Text("Wall");
            }

            if (Input.Keyboard.WasPressed(Keys.F))
            {
                fill = true;
            }
            else if (Input.Keyboard.WasPressed(Keys.P))
            {
                fill = false;
            }

            if (CurrentInfo.Tile.Matches(TileFlags.Burns))
            {
                ImGui.SameLine();
                ImGui.Text("Burns");
            }

            ImGui.Separator();

            for (var i = 0; i < infos.Count; i++)
            {
                var info = infos[i];
                ImGui.PushID((int)info.Tile);

                if (ImGui.ImageButton(info.Texture, tileSize, info.Uv0, info.Uv1, 0, bg, info == CurrentInfo ? tintColorActive : tintColor))
                {
                    CurrentInfo = info;
                }

                ImGui.PopID();

                if (i % 4 < 3 && i < infos.Count - 1)
                {
                    ImGui.SameLine();
                }
            }


            if (down)
            {
                var mouse = Input.Mouse.GamePosition;

                var x = (int)(mouse.X / 16);
                var y = (int)(mouse.Y / 16);

                if (Editor.Level.IsInside(x, y))
                {
                    if (Editor.Level.Get(x, y, CurrentInfo.Tile.Matches(TileFlags.LiquidLayer)) != CurrentInfo.Tile)
                    {
                        if (!fill)
                        {
                            Window.Commands.Do(new SetCommand {
                                X    = x,
                                Y    = y,
                                Tile = CurrentInfo.Tile
                            });
                        }
                        else
                        {
                            Window.Commands.Do(new FillCommand {
                                X    = x,
                                Y    = y,
                                Tile = CurrentInfo.Tile
                            });
                        }
                    }
                }
            }

            ImGui.End();
        }