1 package com.irtimaled.bbor.client.gui;
3 import com.irtimaled.bbor.client.ClientRenderer;
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.GuiScreen;
11 import net.minecraft.client.gui.IGuiEventListener;
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.getInstance().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, IGuiEventListener.class, this.children::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.getInstance().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 protected void initGui() {
113 this.title = "Bounding Box Outline Reloaded";
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 ClientRenderer.toggleActive();
126 protected int getState() {
127 return enabled ? ClientRenderer.getActive() ? 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) -> new BoundingBoxTypeButton(id, x, y, width, "Spawn Chunks", BoundingBoxType.WorldSpawn),
134 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Lazy Chunks", BoundingBoxType.LazySpawnChunks),
135 (id, x, y, width) -> new MaxYSettingSlider(id, x, y, width, 39, ConfigManager.worldSpawnMaxY),
137 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Slime Chunks", BoundingBoxType.SlimeChunks),
138 (id, x, y, width) -> new MaxYSettingSlider(id, x, y, width, 39, ConfigManager.slimeChunkMaxY),
139 (id, x, y, width) -> (IRowHeight) () -> 0,
141 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Mob Spawners", BoundingBoxType.MobSpawner),
142 (id, x, y, width) -> new BoolSettingButton(id, x, y, width, "Spawn Area", ConfigManager.renderMobSpawnerSpawnArea),
143 (id, x, y, width) -> new BoolSettingButton(id, x, y, width, "Activation Lines", ConfigManager.renderMobSpawnerActivationLines),
145 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Spawn Sphere", BoundingBoxType.AFKSphere),
146 (id, x, y, width) -> new BoolSettingButton(id, x, y, width, "Spawnable Blocks", ConfigManager.renderAFKSpawnableBlocks),
147 (id, x, y, width) -> new IntSettingSlider(id, x, y, width, 1, 3, "Distance", ConfigManager.afkSpawnableBlocksRenderDistance)
148 .addDisplayValue(1, "Nearest")
149 .addDisplayValue(2, "Nearer")
150 .addDisplayValue(3, "Normal"),
152 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Biome Borders", BoundingBoxType.BiomeBorder),
153 (id, x, y, width) -> new BoolSettingButton(id, x, y, width, "Only This Biome", ConfigManager.renderOnlyCurrentBiome),
154 (id, x, y, width) -> new IntSettingSlider(id, x, y, width, 1, 3, "Distance", ConfigManager.biomeBordersRenderDistance)
155 .addDisplayValue(1, "Nearest")
156 .addDisplayValue(2, "Nearer")
157 .addDisplayValue(3, "Normal"));
159 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Desert Temples", BoundingBoxType.DesertTemple),
160 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Jungle Temples", BoundingBoxType.JungleTemple),
161 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Witch Huts", BoundingBoxType.WitchHut),
163 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Mansions", BoundingBoxType.Mansion),
164 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Monuments", BoundingBoxType.OceanMonument),
165 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Igloos", BoundingBoxType.Igloo),
167 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Ocean Ruins", BoundingBoxType.OceanRuin),
168 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Buried Treasure", BoundingBoxType.BuriedTreasure),
169 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Shipwrecks", BoundingBoxType.Shipwreck),
171 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Strongholds", BoundingBoxType.Stronghold),
172 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Mineshafts", BoundingBoxType.MineShaft),
173 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Pillager Outposts", BoundingBoxType.PillagerOutpost, false),
175 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Villages", BoundingBoxType.Village),
176 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Fortresses", BoundingBoxType.NetherFortress),
177 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "End Cities", BoundingBoxType.EndCity));
179 (id, x, y, width) -> new BoolSettingButton(id, x, y, width, "Village Spheres", ConfigManager.drawVillageSpheres),
180 (id, x, y, width) -> new BoolSettingButton(id, x, y, width, "Door Lines", ConfigManager.drawVillageDoors),
181 (id, x, y, width) -> new BoolSettingButton(id, x, y, width, "Golem Spawn", ConfigManager.drawIronGolemSpawnArea),
183 (id, x, y, width) -> new IntSettingSlider(id, x, y, width, 1, 5, "Dot Size", ConfigManager.villageSphereDotSize),
184 (id, x, y, width) -> new IntSettingSlider(id, x, y, width, 1, 5, "Density", ConfigManager.villageSphereDensity)
185 .addDisplayValue(1, "Fewest")
186 .addDisplayValue(2, "Fewer")
187 .addDisplayValue(3, "Normal")
188 .addDisplayValue(4, "More")
189 .addDisplayValue(5, "Most"));
192 private void drawScreen(int top, int bottom) {
193 this.mc.getTextureManager().bindTexture(Gui.OPTIONS_BACKGROUND);
195 GL11.glDisable(GL11.GL_LIGHTING);
196 GL11.glDisable(GL11.GL_FOG);
197 GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
199 Renderer.startTextured()
200 .setColor(32, 32, 32)
202 .addPoint(0, bottom, 0, 0, bottom / 32.0F)
203 .addPoint(this.width, bottom, 0, this.width / 32.0F, bottom / 32.0F)
204 .addPoint(this.width, top, 0, this.width / 32.0F, top / 32.0F)
205 .addPoint(0, top, 0, 0, top / 32.0F)
208 GL11.glDisable(GL11.GL_DEPTH_TEST);
209 GL11.glEnable(GL11.GL_BLEND);
210 OpenGlHelper.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ZERO, GL11.GL_ONE);
212 GL11.glDisable(GL11.GL_ALPHA_TEST);
213 GL11.glShadeModel(7425);
214 GL11.glDisable(GL11.GL_TEXTURE_2D);
216 Renderer.startTextured()
218 .addPoint(0, top + 4, 0, 0, 1)
219 .addPoint(this.width, top + 4, 0, 1, 1)
221 .addPoint(this.width, top, 0, 1, 0)
222 .addPoint(0, top, 0, 0, 0)
225 Renderer.startTextured()
227 .addPoint(0, bottom, 0, 0, 1)
228 .addPoint(this.width, bottom, 0, 1, 1)
230 .addPoint(this.width, bottom - 4, 0, 1, 0)
231 .addPoint(0, bottom - 4, 0, 0, 0)
234 GL11.glEnable(GL11.GL_TEXTURE_2D);
235 GL11.glShadeModel(7424);
236 GL11.glEnable(GL11.GL_ALPHA_TEST);
237 OpenGlHelper.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO);
238 GL11.glDisable(GL11.GL_BLEND);
242 public void render(int mouseX, int mouseY, float unknown) {
243 if (this.mc.world == null) {
244 this.drawDefaultBackground();
245 this.drawScreen(getY(-1), getY(5.5) - 4);
247 this.drawCenteredString(this.fontRenderer, this.title, this.width / 2, 15, 16777215);
248 for (IRenderableControl control : controls) {
249 control.render(mouseX, mouseY);