X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fcom%2Firtimaled%2Fbbor%2Fclient%2Fgui%2FSettingsScreen.java;h=5741b07b8315e3d4857d46e0235ca2a7937bfd8e;hb=7db6e0c5990b2ea5909529ee8866fa7fcda18e86;hp=4528f99d00e395209ae7b4e9d2e0b77c39c55b17;hpb=9ef2591e16acc4a176107a3f45b2b2ef63f396d0;p=BoundingBoxOutlineReloaded.git diff --git a/src/main/java/com/irtimaled/bbor/client/gui/SettingsScreen.java b/src/main/java/com/irtimaled/bbor/client/gui/SettingsScreen.java index 4528f99..5741b07 100644 --- a/src/main/java/com/irtimaled/bbor/client/gui/SettingsScreen.java +++ b/src/main/java/com/irtimaled/bbor/client/gui/SettingsScreen.java @@ -1,239 +1,125 @@ package com.irtimaled.bbor.client.gui; -import com.irtimaled.bbor.client.ClientProxy; -import com.irtimaled.bbor.client.renderers.Renderer; +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.common.TypeHelper; -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.OpenGlHelper; -import org.lwjgl.opengl.GL11; +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 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)); + ClientInterop.displayScreen(new SettingsScreen(null)); } - 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); - TypeHelper.doIfType(control, IGuiEventListener.class, this.eventListeners::add); - } - - 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 AbstractButton(id, x, y, width, label, index != tabIndex) { - @Override - public void onPressed() { - Minecraft.getInstance().displayGuiScreen(new SettingsScreen(lastScreen, index)); - } - }); - column++; - } - - //done button - addControl(new AbstractButton(200, this.width / 2 - 100, getY(5.5), 200, "Done") { - @Override - public void onPressed() { - 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); - TypeHelper.doIfType(control, IRenderableControl.class, this::addControl); - return control; - } - - 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); - IRowHeight rowHeight = TypeHelper.as(control, IRowHeight.class); - if (rowHeight != null) { - if (column > 0) { - row++; - column = 0; - } else { - row += rowHeight.getRowHeight(); - } - } else { - column++; - } - if (column == 3) { - column = 0; - row++; - } - } + SettingsScreen(Screen lastScreen) { + super(lastScreen); } @Override - protected void initGui() { - this.title = ClientProxy.Name; - - this.controls = new HashSet<>(); - this.addTabs("General", "Structures", "Villages"); - - buildTab(0, - (id, x, y, width) -> new AbstractButton(id, x, y, width, "Active", this.mc.world != null) { - @Override - public void onPressed() { - ClientProxy.toggleActive(); - } - - @Override - protected int getState() { - 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, false), - (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) { - this.mc.getTextureManager().bindTexture(Gui.OPTIONS_BACKGROUND); - - GL11.glDisable(GL11.GL_LIGHTING); - GL11.glDisable(GL11.GL_FOG); - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - - Renderer.startTextured() - .setColor(32, 32, 32) - .setAlpha(255) - .addPoint(0, bottom, 0, 0, bottom / 32.0F) - .addPoint(this.width, bottom, 0, this.width / 32.0F, bottom / 32.0F) - .addPoint(this.width, top, 0, this.width / 32.0F, top / 32.0F) - .addPoint(0, top, 0, 0, top / 32.0F) - .render(); - - GL11.glDisable(GL11.GL_DEPTH_TEST); - GL11.glEnable(GL11.GL_BLEND); - OpenGlHelper.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ZERO, GL11.GL_ONE); - - GL11.glDisable(GL11.GL_ALPHA_TEST); - GL11.glShadeModel(7425); - GL11.glDisable(GL11.GL_TEXTURE_2D); - - Renderer.startTextured() - .setAlpha(0) - .addPoint(0, top + 4, 0, 0, 1) - .addPoint(this.width, top + 4, 0, 1, 1) - .setAlpha(255) - .addPoint(this.width, top, 0, 1, 0) - .addPoint(0, top, 0, 0, 0) - .render(); - - Renderer.startTextured() - .setAlpha(255) - .addPoint(0, bottom, 0, 0, 1) - .addPoint(this.width, bottom, 0, 1, 1) - .setAlpha(0) - .addPoint(this.width, bottom - 4, 0, 1, 0) - .addPoint(0, bottom - 4, 0, 0, 0) - .render(); - - GL11.glEnable(GL11.GL_TEXTURE_2D); - GL11.glShadeModel(7424); - GL11.glEnable(GL11.GL_ALPHA_TEST); - GL11.glDisable(GL11.GL_BLEND); + 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; } }