]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/blobdiff - src/main/java/com/irtimaled/bbor/client/gui/SettingsScreen.java
Add "Fast Render" option to configure culling behaviors
[BoundingBoxOutlineReloaded.git] / src / main / java / com / irtimaled / bbor / client / gui / SettingsScreen.java
index 7163f038ee12e8ed0aa857c84b396cabccf45a28..a4b135ae57c7473c086773234b65d5f57ac543a6 100644 (file)
 package com.irtimaled.bbor.client.gui;
 
-import com.irtimaled.bbor.client.ClientProxy;
+import com.irtimaled.bbor.client.ClientRenderer;
+import com.irtimaled.bbor.client.config.ConfigManager;
+import com.irtimaled.bbor.client.interop.ClientInterop;
 import com.irtimaled.bbor.common.BoundingBoxType;
-import com.irtimaled.bbor.config.ConfigManager;
-import net.minecraft.client.Minecraft;
-import net.minecraft.client.gui.Gui;
-import net.minecraft.client.gui.GuiScreen;
-import net.minecraft.client.gui.IGuiEventListener;
-import net.minecraft.client.renderer.BufferBuilder;
-import net.minecraft.client.renderer.GlStateManager;
-import net.minecraft.client.renderer.Tessellator;
-import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
+import net.minecraft.SharedConstants;
+import net.minecraft.client.gui.screen.Screen;
+import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
+import net.minecraft.client.resource.language.I18n;
 
-import java.util.HashSet;
-import java.util.Set;
-
-public class SettingsScreen extends GuiScreen {
-    private static final int CONTROLS_WIDTH = 310;
-
-    private final GuiScreen lastScreen;
-    private final int tabIndex;
-
-    private String title;
-    private Set<IRenderableControl> controls = new HashSet<>();
-
-    SettingsScreen(GuiScreen lastScreen, int tabIndex) {
-        this.lastScreen = lastScreen;
-        this.tabIndex = tabIndex;
-
-    }
+public class SettingsScreen extends ListScreen {
+    private static final String pillagerOutpostVersionPattern = "(?:1\\.1[4-9]|1\\.[2-9][0-9]|18w(?:4[7-9]|5[0-9])|19w|2[0-9]w).*";
+    private static final String bastionRemnantVersionPattern = "(?:1\\.1[6-9]|1\\.[2-9][0-9]|20w(?:1[6-9]|[2-5][0-9])|2[1-9]w).*";
+    private static final String netherFossilVersionPattern = "(?:1\\.1[6-9]|1\\.[2-9][0-9]|20w(?:1[1-9]|[2-5][0-9])|2[1-9]w).*";
 
     public static void show() {
-        Minecraft.getInstance().displayGuiScreen(new SettingsScreen(null, 0));
-    }
-
-    private int getY(double row) {
-        return ((this.height / 6) - 12) + (int) ((row + 2.0) * 24.0);
-    }
-
-    private void addControl(IRenderableControl control) {
-        this.controls.add(control);
-        if (control instanceof IGuiEventListener) {
-            this.eventListeners.add((IGuiEventListener) control);
-        }
+        ClientInterop.displayScreen(new SettingsScreen(null));
     }
 
-    private void addTabs(String... labels) {
-        int columns = labels.length;
-        int column = 0;
-        int y = getY(-2);
-        for (String label : labels) {
-            final int index = column;
-            addControl(0, column, y, CONTROLS_WIDTH / columns,
-                    (id, x, y1, width) -> new Button(id, x, y, width, label, index != tabIndex) {
-                        public void onClick(double p_onClick_1_, double p_onClick_3_) {
-                            Minecraft.getInstance().displayGuiScreen(new SettingsScreen(lastScreen, index));
-                        }
-                    });
-            column++;
-        }
-
-        //done button
-        addControl(new Button(200, this.width / 2 - 100, getY(5.5), 200, "Done") {
-            public void onClick(double p_onClick_1_, double p_onClick_3_) {
-                ConfigManager.saveConfig();
-                mc.displayGuiScreen(lastScreen);
-            }
-        });
-    }
-
-    private int getX(int width, int column, int offset) {
-        return ((this.width - CONTROLS_WIDTH) / 2) + (column * (width + offset));
-    }
-
-    private IControl addControl(int offset, int column, int y, int width, CreateControl createControl) {
-        int x = getX(width, column, offset);
-        int id = controls.size();
-        IControl control = createControl.create(id, x, y, width);
-        if (control instanceof IRenderableControl)
-            addControl((IRenderableControl) control);
-        return control;
+    SettingsScreen(Screen lastScreen) {
+        super(lastScreen);
     }
 
-    private void buildTab(int tabIndex, CreateControl... createControls) {
-        if(tabIndex != this.tabIndex) return;
-
-        int offset = 4;
-        int width = (CONTROLS_WIDTH - (2 * offset)) / 3;
-        int column = 0;
-        double row = -0.75;
-        for (CreateControl createControl : createControls) {
-            int y = getY(row);
-            IControl control = this.addControl(offset, column, y, width, createControl);
-            if (control instanceof IRowHeight) {
-                if (column > 0) {
-                    row++;
-                    column = 0;
-                } else {
-                    row += ((IRowHeight) control).getRowHeight();
-                }
-            } else {
-                column++;
-            }
-            if (column == 3) {
-                column = 0;
-                row++;
-            }
-        }
-    }
-
-    protected void initGui() {
-        this.title = ClientProxy.Name;
-
-        this.controls = new HashSet<>();
-        this.addTabs("General", "Structures", "Villages");
-
-        buildTab(0,
-                (id, x, y, width) -> new Button(id, x, y, width, "Active", this.mc.world != null) {
-                    public void onClick(double p_onClick_1_, double p_onClick_3_) {
-                        ClientProxy.toggleActive();
-                    }
-
-                    protected int getHoverState(boolean p_getHoverState_1_) {
-                        return enabled ? ClientProxy.active ? 2 : 1 : 0;
-                    }
-                },
-                (id, x, y, width) -> new BoolSettingButton(id, x, y, width, "Outer Box Only", ConfigManager.outerBoxesOnly),
-                (id, x, y, width) -> new BoolSettingButton(id, x, y, width, "Fill", ConfigManager.fill),
-
-                (id, x, y, width) -> (IRowHeight) () -> 0.5,
-
-                (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Spawn Chunks", BoundingBoxType.WorldSpawn),
-                (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Lazy Chunks", BoundingBoxType.LazySpawnChunks),
-                (id, x, y, width) -> new MaxYSettingSlider(id, x, y, width, 39, ConfigManager.worldSpawnMaxY),
-
-                (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Slime Chunks", BoundingBoxType.SlimeChunks),
-                (id, x, y, width) -> new MaxYSettingSlider(id, x, y, width, 39, ConfigManager.slimeChunkMaxY),
-                (id, x, y, width) -> (IRowHeight) () -> 0,
-
-                (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Mob Spawners", BoundingBoxType.MobSpawner),
-                (id, x, y, width) -> new BoolSettingButton(id, x, y, width, "Spawn Area", ConfigManager.renderMobSpawnerSpawnArea),
-                (id, x, y, width) -> new BoolSettingButton(id, x, y, width, "Activation Lines", ConfigManager.renderMobSpawnerActivationLines));
-        buildTab(1,
-                (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Desert Temples", BoundingBoxType.DesertTemple),
-                (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Jungle Temples", BoundingBoxType.JungleTemple),
-                (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Witch Huts", BoundingBoxType.WitchHut),
-
-                (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Mansions", BoundingBoxType.Mansion),
-                (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Monuments", BoundingBoxType.OceanMonument),
-                (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Igloos", BoundingBoxType.Igloo),
-
-                (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Ocean Ruins", BoundingBoxType.OceanRuin),
-                (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Buried Treasure", BoundingBoxType.BuriedTreasure),
-                (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Shipwrecks", BoundingBoxType.Shipwreck),
-
-                (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Pillager Outposts", BoundingBoxType.PillagerOutpost),
-                (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Strongholds", BoundingBoxType.Stronghold),
-                (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Mineshafts", BoundingBoxType.MineShaft),
-
-                (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Fortresses", BoundingBoxType.NetherFortress),
-                (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "End Cities", BoundingBoxType.EndCity));
-        buildTab(2,
-                (id, x, y, width) -> new BoolSettingButton(id, x, y, width, "Villages", ConfigManager.drawVillages),
-                (id, x, y, width) -> new BoolSettingButton(id, x, y, width, "Door Lines", ConfigManager.drawVillageDoors),
-                (id, x, y, width) -> new BoolSettingButton(id, x, y, width, "Golem Spawn", ConfigManager.drawIronGolemSpawnArea),
-
-                (id, x, y, width) -> new BoolSettingButton(id, x, y, width, "Render Sphere", ConfigManager.renderVillageAsSphere),
-                (id, x, y, width) -> new IntSettingSlider(id, x, y, width, 1, 5, "Dot Size", ConfigManager.villageSphereDotSize),
-                (id, x, y, width) -> new IntSettingSlider(id, x, y, width, 1, 5, "Density", ConfigManager.villageSphereDensity)
-                        .addDisplayValue(1, "Fewest")
-                        .addDisplayValue(2, "Fewer")
-                        .addDisplayValue(3, "Normal")
-                        .addDisplayValue(4, "More")
-                        .addDisplayValue(5, "Most"));
-    }
-
-    private void drawScreen(int top, int bottom) {
-        Tessellator tessellator = Tessellator.getInstance();
-        BufferBuilder bufferBuilder = tessellator.getBuffer();
-        this.mc.getTextureManager().bindTexture(Gui.OPTIONS_BACKGROUND);
-
-        GlStateManager.disableLighting();
-        GlStateManager.disableFog();
-        GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
-
-        bufferBuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
-        bufferBuilder.pos((double) 0, (double) bottom, 0.0D)
-                .tex((double) ((float) 0 / 32.0F), (double) ((float) bottom / 32.0F))
-                .color(32, 32, 32, 255)
-                .endVertex();
-        bufferBuilder.pos((double) this.width, (double) bottom, 0.0D)
-                .tex((double) ((float) this.width / 32.0F), (double) ((float) bottom / 32.0F))
-                .color(32, 32, 32, 255)
-                .endVertex();
-        bufferBuilder.pos((double) this.width, (double) top, 0.0D)
-                .tex((double) ((float) this.width / 32.0F), (double) ((float) top / 32.0F))
-                .color(32, 32, 32, 255)
-                .endVertex();
-        bufferBuilder.pos((double) 0, (double) top, 0.0D)
-                .tex((double) ((float) 0 / 32.0F), (double) ((float) top / 32.0F))
-                .color(32, 32, 32, 255)
-                .endVertex();
-        tessellator.draw();
-
-        GlStateManager.disableDepthTest();
-        GlStateManager.enableBlend();
-        GlStateManager.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ZERO, GlStateManager.DestFactor.ONE);
-        GlStateManager.disableAlphaTest();
-        GlStateManager.shadeModel(7425);
-        GlStateManager.disableTexture2D();
-
-        bufferBuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
-        bufferBuilder.pos((double) 0, (double) (top + 4), 0.0D)
-                .tex(0.0D, 1.0D)
-                .color(0, 0, 0, 0)
-                .endVertex();
-        bufferBuilder.pos((double) this.width, (double) (top + 4), 0.0D)
-                .tex(1.0D, 1.0D)
-                .color(0, 0, 0, 0)
-                .endVertex();
-        bufferBuilder.pos((double) this.width, (double) top, 0.0D)
-                .tex(1.0D, 0.0D)
-                .color(0, 0, 0, 255)
-                .endVertex();
-        bufferBuilder.pos((double) 0, (double) top, 0.0D)
-                .tex(0.0D, 0.0D)
-                .color(0, 0, 0, 255)
-                .endVertex();
-        tessellator.draw();
-
-        bufferBuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
-        bufferBuilder.pos((double) 0, (double) bottom, 0.0D)
-                .tex(0.0D, 1.0D)
-                .color(0, 0, 0, 255)
-                .endVertex();
-        bufferBuilder.pos((double) this.width, (double) bottom, 0.0D)
-                .tex(1.0D, 1.0D)
-                .color(0, 0, 0, 255)
-                .endVertex();
-        bufferBuilder.pos((double) this.width, (double) (bottom - 4), 0.0D)
-                .tex(1.0D, 0.0D)
-                .color(0, 0, 0, 0)
-                .endVertex();
-        bufferBuilder.pos((double) 0, (double) (bottom - 4), 0.0D)
-                .tex(0.0D, 0.0D)
-                .color(0, 0, 0, 0)
-                .endVertex();
-        tessellator.draw();
-
-        GlStateManager.enableTexture2D();
-        GlStateManager.shadeModel(7424);
-        GlStateManager.enableAlphaTest();
-        GlStateManager.disableBlend();
+    @Override
+    protected void onDoneClicked() {
+        ConfigManager.saveConfig();
+        super.onDoneClicked();
     }
 
     @Override
-    public void render(int mouseX, int mouseY, float unknown) {
-        if(this.mc.world == null) {
-            this.drawDefaultBackground();
-            this.drawScreen(getY(-1), getY(5.5) - 4);
-        }
-        this.drawCenteredString(this.fontRenderer, this.title, this.width / 2, 15, 16777215);
-        for (IRenderableControl control : controls) {
-            control.render(mouseX, mouseY);
-        }
+    protected ControlList buildList(int top, int bottom) {
+        String version = SharedConstants.getGameVersion().getName();
+        ControlList controlList = new ControlList(this.width, this.height, top, bottom);
+        if (this.client.world != null) controlList.setTransparentBackground();
+
+        controlList
+                .section(null,
+                        width -> new BoolButton(width, I18n.translate("bbor.options.active"), this.client.world != null) {
+                            @Override
+                            public void appendNarrations(NarrationMessageBuilder narrationMessageBuilder) {
+                                this.appendDefaultNarrations(narrationMessageBuilder);
+                            }
+
+                            @Override
+                            public void onPressed() {
+                                ClientRenderer.toggleActive();
+                            }
+
+                            @Override
+                            protected boolean getValue() {
+                                return ClientRenderer.getActive();
+                            }
+                        },
+                        width -> new BoolSettingButton(width, I18n.translate("bbor.options.outerBoxOnly"), ConfigManager.outerBoxesOnly),
+                        width -> new BoolSettingButton(width, I18n.translate("bbor.options.fill"), ConfigManager.fill),
+                        width -> new IntSettingSlider(width, 0, 2, "bbor.options.fastRender", ConfigManager.fastRender)
+                                .addDisplayValue(0, I18n.translate("bbor.options.fastRender.0"))
+                                .addDisplayValue(1, I18n.translate("bbor.options.fastRender.1"))
+                                .addDisplayValue(2, I18n.translate("bbor.options.fastRender.2")))
+                .section(I18n.translate("bbor.features.spawnChunks"),
+                        width -> new BoundingBoxTypeButton(width, I18n.translate("bbor.features.spawnChunks"), BoundingBoxType.WorldSpawn),
+                        width -> new BoundingBoxTypeButton(width, I18n.translate("bbor.features.lazyChunks"), BoundingBoxType.LazySpawnChunks),
+                        width -> new MaxYSettingSlider(width, 39, ConfigManager.worldSpawnMaxY))
+                .section(I18n.translate("bbor.features.slimeChunks"),
+                        width -> new BoundingBoxTypeButton(width, I18n.translate("bbor.features.slimeChunks"), BoundingBoxType.SlimeChunks),
+                        width -> new MaxYSettingSlider(width, 39, ConfigManager.slimeChunkMaxY))
+                .section(I18n.translate("bbor.features.biomeBorders"),
+                        width -> new BoundingBoxTypeButton(width, I18n.translate("bbor.features.biomeBorders"), BoundingBoxType.BiomeBorder),
+                        width -> new MaxYSettingSlider(width, 1, ConfigManager.biomeBordersMaxY),
+                        width -> new IntSettingSlider(width, 1, 3, "bbor.options.distance", ConfigManager.biomeBordersRenderDistance)
+                                .addDisplayValue(1, I18n.translate("bbor.options.distance.nearest"))
+                                .addDisplayValue(2, I18n.translate("bbor.options.distance.nearer"))
+                                .addDisplayValue(3, I18n.translate("bbor.options.distance.normal")))
+                .section(I18n.translate("bbor.features.flowerForests"),
+                        width -> new BoundingBoxTypeButton(width, I18n.translate("bbor.features.flowerForests"), BoundingBoxType.FlowerForest),
+                        width -> new IntSettingSlider(width, 1, 3, "bbor.options.distance", ConfigManager.flowerForestsRenderDistance)
+                                .addDisplayValue(1, I18n.translate("bbor.options.distance.nearest"))
+                                .addDisplayValue(2, I18n.translate("bbor.options.distance.nearer"))
+                                .addDisplayValue(3, I18n.translate("bbor.options.distance.normal")))
+                .section(I18n.translate("bbor.features.bedrockCeilingBlocks"),
+                        width -> new BoundingBoxTypeButton(width, I18n.translate("bbor.features.bedrockCeilingBlocks"), BoundingBoxType.BedrockCeiling))
+                .section(I18n.translate("bbor.features.mobSpawners"),
+                        width -> new BoundingBoxTypeButton(width, I18n.translate("bbor.features.mobSpawners"), BoundingBoxType.MobSpawner),
+                        width -> new BoolSettingButton(width, I18n.translate("bbor.features.mobSpawners.spawnArea"), ConfigManager.renderMobSpawnerSpawnArea),
+                        width -> new BoolSettingButton(width, I18n.translate("bbor.features.mobSpawners.activationLines"), ConfigManager.renderMobSpawnerActivationLines))
+                .section(I18n.translate("bbor.sections.beaconsAndConduits"),
+                        width -> new BoundingBoxTypeButton(width, I18n.translate("bbor.features.beacons"), BoundingBoxType.Beacon),
+                        width -> new BoundingBoxTypeButton(width, I18n.translate("bbor.features.conduits"), BoundingBoxType.Conduit),
+                        width -> new BoolSettingButton(width, I18n.translate("bbor.features.conduits.mobHarmArea"), ConfigManager.renderConduitMobHarmArea))
+                .section(I18n.translate("bbor.features.spawnableBlocks"),
+                        width -> new BoundingBoxTypeButton(width, I18n.translate("bbor.features.spawnableBlocks"), BoundingBoxType.SpawnableBlocks),
+                        width -> new IntSettingSlider(width, 1, 3, "bbor.options.distance.y", ConfigManager.spawnableBlocksRenderHeight)
+                                .addDisplayValue(1, "2")
+                                .addDisplayValue(2, "4")
+                                .addDisplayValue(3, "8"),
+                        width -> new IntSettingSlider(width, 1, 3, "bbor.options.distance.xz", ConfigManager.spawnableBlocksRenderWidth)
+                                .addDisplayValue(1, "8")
+                                .addDisplayValue(2, "16")
+                                .addDisplayValue(3, "32"))
+                .section(I18n.translate("bbor.features.spawningSpheres"),
+                        width -> new BoundingBoxTypeButton(width, I18n.translate("bbor.features.spawningSpheres"), BoundingBoxType.AFKSphere),
+                        width -> new BoolSettingButton(width, I18n.translate("bbor.features.spawnableBlocks"), ConfigManager.renderAFKSpawnableBlocks))
+                .section(I18n.translate("bbor.tabs.structures"),
+                        width -> new BoundingBoxTypeButton(width, I18n.translate("bbor.structures.desertTemples"), BoundingBoxType.DesertTemple),
+                        width -> new BoundingBoxTypeButton(width, I18n.translate("bbor.structures.jungleTemples"), BoundingBoxType.JungleTemple),
+                        width -> new BoundingBoxTypeButton(width, I18n.translate("bbor.structures.witchHuts"), BoundingBoxType.WitchHut),
+                        width -> new BoundingBoxTypeButton(width, I18n.translate("bbor.structures.mansions"), BoundingBoxType.Mansion),
+                        width -> new BoundingBoxTypeButton(width, I18n.translate("bbor.structures.monuments"), BoundingBoxType.OceanMonument),
+                        width -> new BoundingBoxTypeButton(width, I18n.translate("bbor.structures.igloos"), BoundingBoxType.Igloo),
+                        width -> new BoundingBoxTypeButton(width, I18n.translate("bbor.structures.oceanRuins"), BoundingBoxType.OceanRuin),
+                        width -> new BoundingBoxTypeButton(width, I18n.translate("bbor.structures.buriedTreasure"), BoundingBoxType.BuriedTreasure),
+                        width -> new BoundingBoxTypeButton(width, I18n.translate("bbor.structures.shipwrecks"), BoundingBoxType.Shipwreck),
+                        width -> new BoundingBoxTypeButton(width, I18n.translate("bbor.structures.strongholds"), BoundingBoxType.Stronghold),
+                        width -> new BoundingBoxTypeButton(width, I18n.translate("bbor.structures.mineshafts"), BoundingBoxType.MineShaft),
+                        width -> new BoundingBoxTypeButton(width, I18n.translate("bbor.structures.villages"), BoundingBoxType.Village),
+                        width -> version.matches(pillagerOutpostVersionPattern) ? new BoundingBoxTypeButton(width, I18n.translate("bbor.structures.pillagerOutposts"), BoundingBoxType.PillagerOutpost) : null,
+                        width -> version.matches(bastionRemnantVersionPattern) ? new BoundingBoxTypeButton(width, I18n.translate("bbor.structures.ruinedPortal"), BoundingBoxType.RuinedPortal) : null,
+                        width -> new BoundingBoxTypeButton(width, I18n.translate("bbor.structures.fortresses"), BoundingBoxType.NetherFortress),
+                        width -> version.matches(netherFossilVersionPattern) ? new BoundingBoxTypeButton(width, I18n.translate("bbor.structures.netherFossils"), BoundingBoxType.NetherFossil) : null,
+                        width -> version.matches(bastionRemnantVersionPattern) ? new BoundingBoxTypeButton(width, I18n.translate("bbor.structures.bastionRemnants"), BoundingBoxType.BastionRemnant) : null,
+                        width -> new BoundingBoxTypeButton(width, I18n.translate("bbor.structures.endCities"), BoundingBoxType.EndCity));
+        return controlList;
     }
 }