Exemplo n.º 1
0
 public override void Run(Console Console, string[] Args)
 {
     if (Args.Length == 1)
     {
         state.Run.Level.SetBiome(BiomeRegistry.Get(Args[0]));
     }
     else
     {
         Console.Print("/biome [id]");
     }
 }
Exemplo n.º 2
0
        public override void Init()
        {
            base.Init();

            floors    = new string[FloorRegistry.Instance.Size + 2];
            floors[0] = "Random";
            floors[1] = "None";

            for (var i = 0; i < FloorRegistry.Instance.Size; i++)
            {
                floors[i + 2] = FloorRegistry.Instance.Get(i).GetType().Name.Replace("Floor", "");
            }

            walls    = new string[WallRegistry.Instance.Size + 2];
            walls[0] = "Random";
            walls[1] = "None";

            for (var i = 0; i < WallRegistry.Instance.Size; i++)
            {
                walls[i + 2] = WallRegistry.Instance.Get(i).GetType().Name.Replace("Walls", "").Replace("Wall", "");
            }

            Tilesets.Load();

            Ui.Add(new Camera(new FollowingDriver())
            {
                Position = new Vector2(Display.Width / 2f, Display.Height / 2f)
            });

            level = new RegularLevel {
                Width           = Display.Width / 16,
                Height          = Display.Height / 16 + 1,
                NoLightNoRender = false,
                DrawLight       = false
            };

            Area.Add(level);

            level.SetBiome(BiomeRegistry.Get(Biome.Castle));
            level.Setup();

            Paint();
        }
Exemplo n.º 3
0
        private void Load()
        {
            Editor.Area.Destroy();
            Editor.Area = new Area();
            Engine.Instance.State.Area = Editor.Area;

            Run.Level = null;

            if (levels.Length == 0)
            {
                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.FloorA);
                level.TileUp();

                Editor.Camera.Position = Vector2.Zero;
            }
            else
            {
                SaveManager.Load(Editor.Area, SaveType.Level, $"Content/Prefabs/{levels[currentLevel]}.lvl");
                Editor.Level = Run.Level;
            }

            for (var i = 0; i < Editor.Level.Size; i++)
            {
                Editor.Level.Explored[i] = true;
            }

            TileEditor.ReloadBiome();
        }
Exemplo n.º 4
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();
        }
Exemplo n.º 5
0
 public CutsceneLevel() : base(BiomeRegistry.Get(Biome.Castle))
 {
 }
Exemplo n.º 6
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();
        }
Exemplo n.º 7
0
 public TutorialLevel() : base(BiomeRegistry.Get(Biome.Castle))
 {
 }
Exemplo n.º 8
0
 public HallLevel() : base(BiomeRegistry.Get(Biome.Hub))
 {
 }