1 package com.irtimaled.bbor.client.gui;
3 import com.irtimaled.bbor.client.ClientProxy;
4 import com.irtimaled.bbor.client.renderers.Renderer;
5 import com.irtimaled.bbor.common.BoundingBoxType;
6 import com.irtimaled.bbor.common.TypeHelper;
7 import com.irtimaled.bbor.config.ConfigManager;
8 import net.minecraft.client.Minecraft;
9 import net.minecraft.client.gui.Gui;
10 import net.minecraft.client.gui.GuiButton;
11 import net.minecraft.client.gui.GuiScreen;
12 import net.minecraft.client.renderer.OpenGlHelper;
13 import org.lwjgl.opengl.GL11;
15 import java.util.HashSet;
18 public class SettingsScreen extends GuiScreen {
19 private static final int CONTROLS_WIDTH = 310;
21 private final GuiScreen lastScreen;
22 private final int tabIndex;
25 private Set<IRenderableControl> controls = new HashSet<>();
27 SettingsScreen(GuiScreen lastScreen, int tabIndex) {
28 this.lastScreen = lastScreen;
29 this.tabIndex = tabIndex;
32 public static void show() {
33 Minecraft.getMinecraft().displayGuiScreen(new SettingsScreen(null, 0));
36 private int getY(double row) {
37 return ((this.height / 6) - 12) + (int) ((row + 2.0) * 24.0);
40 private void addControl(IRenderableControl control) {
41 this.controls.add(control);
42 TypeHelper.doIfType(control, GuiButton.class, this.buttonList::add);
45 private void addTabs(String... labels) {
46 int columns = labels.length;
49 for (String label : labels) {
50 final int index = column;
51 addControl(0, column, y, CONTROLS_WIDTH / columns,
52 (id, x, y1, width) -> new AbstractButton(id, x, y, width, label, index != tabIndex) {
54 public void onPressed() {
55 Minecraft.getMinecraft().displayGuiScreen(new SettingsScreen(lastScreen, index));
62 addControl(new AbstractButton(200, this.width / 2 - 100, getY(5.5), 200, "Done") {
64 public void onPressed() {
65 ConfigManager.saveConfig();
66 mc.displayGuiScreen(lastScreen);
71 private int getX(int width, int column, int offset) {
72 return ((this.width - CONTROLS_WIDTH) / 2) + (column * (width + offset));
75 private IControl addControl(int offset, int column, int y, int width, CreateControl createControl) {
76 int x = getX(width, column, offset);
77 int id = controls.size();
78 IControl control = createControl.create(id, x, y, width);
79 TypeHelper.doIfType(control, IRenderableControl.class, this::addControl);
83 private void buildTab(int tabIndex, CreateControl... createControls) {
84 if (tabIndex != this.tabIndex) return;
87 int width = (CONTROLS_WIDTH - (2 * offset)) / 3;
90 for (CreateControl createControl : createControls) {
92 IControl control = this.addControl(offset, column, y, width, createControl);
93 IRowHeight rowHeight = TypeHelper.as(control, IRowHeight.class);
94 if (rowHeight != null) {
99 row += rowHeight.getRowHeight();
112 public void initGui() {
113 this.title = ClientProxy.Name;
115 this.controls = new HashSet<>();
116 this.addTabs("General", "Structures", "Villages");
119 (id, x, y, width) -> new AbstractButton(id, x, y, width, "Active", this.mc.world != null) {
121 public void onPressed() {
122 ClientProxy.toggleActive();
126 protected int getState() {
127 return enabled ? ClientProxy.active ? 2 : 1 : 0;
130 (id, x, y, width) -> new BoolSettingButton(id, x, y, width, "Outer Box Only", ConfigManager.outerBoxesOnly),
131 (id, x, y, width) -> new BoolSettingButton(id, x, y, width, "Fill", ConfigManager.fill),
133 (id, x, y, width) -> (IRowHeight) () -> 0.5,
135 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Spawn Chunks", BoundingBoxType.WorldSpawn),
136 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Lazy Chunks", BoundingBoxType.LazySpawnChunks),
137 (id, x, y, width) -> new MaxYSettingSlider(id, x, y, width, 39, ConfigManager.worldSpawnMaxY),
139 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Slime Chunks", BoundingBoxType.SlimeChunks),
140 (id, x, y, width) -> new MaxYSettingSlider(id, x, y, width, 39, ConfigManager.slimeChunkMaxY),
141 (id, x, y, width) -> (IRowHeight) () -> 0,
143 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Mob Spawners", BoundingBoxType.MobSpawner),
144 (id, x, y, width) -> new BoolSettingButton(id, x, y, width, "Spawn Area", ConfigManager.renderMobSpawnerSpawnArea),
145 (id, x, y, width) -> new BoolSettingButton(id, x, y, width, "Activation Lines", ConfigManager.renderMobSpawnerActivationLines));
147 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Desert Temples", BoundingBoxType.DesertTemple),
148 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Jungle Temples", BoundingBoxType.JungleTemple),
149 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Witch Huts", BoundingBoxType.WitchHut),
151 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Mansions", BoundingBoxType.Mansion),
152 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Monuments", BoundingBoxType.OceanMonument),
153 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Igloos", BoundingBoxType.Igloo),
155 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Ocean Ruins", BoundingBoxType.OceanRuin, false),
156 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Buried Treasure", BoundingBoxType.BuriedTreasure, false),
157 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Shipwrecks", BoundingBoxType.Shipwreck, false),
159 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Pillager Outposts", BoundingBoxType.PillagerOutpost, false),
160 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Strongholds", BoundingBoxType.Stronghold),
161 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Mineshafts", BoundingBoxType.MineShaft),
163 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Fortresses", BoundingBoxType.NetherFortress),
164 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "End Cities", BoundingBoxType.EndCity));
166 (id, x, y, width) -> new BoolSettingButton(id, x, y, width, "Villages", ConfigManager.drawVillages),
167 (id, x, y, width) -> new BoolSettingButton(id, x, y, width, "Door Lines", ConfigManager.drawVillageDoors),
168 (id, x, y, width) -> new BoolSettingButton(id, x, y, width, "Golem Spawn", ConfigManager.drawIronGolemSpawnArea),
170 (id, x, y, width) -> new BoolSettingButton(id, x, y, width, "Render Sphere", ConfigManager.renderVillageAsSphere),
171 (id, x, y, width) -> new IntSettingSlider(id, x, y, width, 1, 5, "Dot Size", ConfigManager.villageSphereDotSize),
172 (id, x, y, width) -> new IntSettingSlider(id, x, y, width, 1, 5, "Density", ConfigManager.villageSphereDensity)
173 .addDisplayValue(1, "Fewest")
174 .addDisplayValue(2, "Fewer")
175 .addDisplayValue(3, "Normal")
176 .addDisplayValue(4, "More")
177 .addDisplayValue(5, "Most"));
180 private void drawScreen(int top, int bottom) {
181 this.mc.getTextureManager().bindTexture(Gui.OPTIONS_BACKGROUND);
183 GL11.glDisable(GL11.GL_LIGHTING);
184 GL11.glDisable(GL11.GL_FOG);
185 GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
187 Renderer.startTextured()
188 .setColor(32, 32, 32)
190 .addPoint(0, bottom, 0, 0, bottom / 32.0F)
191 .addPoint(this.width, bottom, 0, this.width / 32.0F, bottom / 32.0F)
192 .addPoint(this.width, top, 0, this.width / 32.0F, top / 32.0F)
193 .addPoint(0, top, 0, 0, top / 32.0F)
196 GL11.glDisable(GL11.GL_DEPTH_TEST);
197 OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ZERO, GL11.GL_ONE);
199 GL11.glDisable(GL11.GL_ALPHA_TEST);
200 GL11.glShadeModel(7425);
201 GL11.glDisable(GL11.GL_TEXTURE_2D);
203 Renderer.startTextured()
205 .addPoint(0, top + 4, 0, 0, 1)
206 .addPoint(this.width, top + 4, 0, 1, 1)
208 .addPoint(this.width, top, 0, 1, 0)
209 .addPoint(0, top, 0, 0, 0)
212 Renderer.startTextured()
214 .addPoint(0, bottom, 0, 0, 1)
215 .addPoint(this.width, bottom, 0, 1, 1)
217 .addPoint(this.width, bottom - 4, 0, 1, 0)
218 .addPoint(0, bottom - 4, 0, 0, 0)
221 GL11.glEnable(GL11.GL_TEXTURE_2D);
222 GL11.glShadeModel(7424);
223 GL11.glEnable(GL11.GL_ALPHA_TEST);
224 OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO);
225 GL11.glDisable(GL11.GL_BLEND);
229 public void drawScreen(int mouseX, int mouseY, float partialTicks) {
230 if (this.mc.world == null) {
231 this.drawDefaultBackground();
232 this.drawScreen(getY(-1), getY(5.5) - 4);
234 this.drawCenteredString(this.fontRenderer, this.title, this.width / 2, 15, 16777215);
235 for (IRenderableControl control : controls) {
236 control.render(mouseX, mouseY);