Beispiel #1
0
        public static void ReloadBiome()
        {
            if (Editor?.Level?.Biome == null)
            {
                return;
            }

            biomes = new string[BiomeRegistry.Defined.Count];
            var i = 0;

            foreach (var r in BiomeRegistry.Defined.Values)
            {
                if (r.Id == Editor?.Level?.Biome?.Id)
                {
                    currentBiome = i;
                }

                biomes[i] = r.Id;
                i++;
            }

            tilesetTexture = Animations.Get($"{Editor.Level.Biome.Id}_biome").Texture;
            tilesetPointer = ImGuiHelper.Renderer.BindTexture(tilesetTexture);

            biomeTexture = Animations.Get("biome_assets").Texture;
            biomePointer = ImGuiHelper.Renderer.BindTexture(biomeTexture);

            infos.Clear();

            DefineTile(Tile.WallA, 128, 0);
            DefineTile(Tile.WallB, 144, 0);
            DefineTile(Tile.Planks, 352, 144, true);
            DefineTile(Tile.Collider, 305, 96, true);
            DefineTile(Tile.GrannyWall, 192, 336, true);
            DefineTile(Tile.EvilWall, 0, 336, true);
            DefineTile(Tile.Crack, 128, 48);
            DefineTile(Tile.GrannyFloor, 192, 368, true);
            DefineTile(Tile.EvilFloor, 48, 384, true);
            DefineTile(Tile.FloorA, 0, 80);
            DefineTile(Tile.FloorB, 64, 80);
            DefineTile(Tile.FloorC, 0, 160);
            DefineTile(Tile.FloorD, 64, 160);
            DefineTile(Tile.Path, 400, 368, true);
            DefineTile(Tile.GrannyFloor, 192, 368);
            DefineTile(Tile.EvilFloor, 48, 384);
            DefineTile(Tile.Water, 64, 240, true);
            DefineTile(Tile.Ice, 192, 112, true);
            DefineTile(Tile.Lava, 64, 112, true);
            DefineTile(Tile.Venom, 64, 304, true);
            DefineTile(Tile.Obsidian, 64, 176, true);
            DefineTile(Tile.Dirt, 64, 48, true);
            DefineTile(Tile.Sand, 464, 352, true);
            DefineTile(Tile.Snow, 464, 288, true);
            DefineTile(Tile.Grass, 192, 48, true);
            DefineTile(Tile.HighGrass, 336, 0, true);
            DefineTile(Tile.Cobweb, 192, 240, true);
            DefineTile(Tile.Ember, 144, 160, true);
            DefineTile(Tile.Chasm, 288, 32, true);
            DefineTile(Tile.Piston, 128, 0);
            DefineTile(Tile.PistonDown, 128, 0);
            DefineTile(Tile.Rock, 160, 192);
            DefineTile(Tile.TintedRock, 160, 224);
            DefineTile(Tile.MetalBlock, 128, 192);

            CurrentInfo = infos[0];
        }
Beispiel #2
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();
        }