1 package com.irtimaled.bbor.client.gui;
3 import com.irtimaled.bbor.client.ClientProxy;
4 import com.irtimaled.bbor.common.BoundingBoxType;
5 import com.irtimaled.bbor.config.ConfigManager;
6 import net.minecraft.client.Minecraft;
7 import net.minecraft.client.gui.Gui;
8 import net.minecraft.client.gui.GuiScreen;
9 import net.minecraft.client.gui.IGuiEventListener;
10 import net.minecraft.client.renderer.BufferBuilder;
11 import net.minecraft.client.renderer.OpenGlHelper;
12 import net.minecraft.client.renderer.Tessellator;
13 import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
14 import org.lwjgl.opengl.GL11;
16 import java.util.HashSet;
19 public class SettingsScreen extends GuiScreen {
20 private static final int CONTROLS_WIDTH = 310;
22 private final GuiScreen lastScreen;
23 private final int tabIndex;
26 private Set<IRenderableControl> controls = new HashSet<>();
28 SettingsScreen(GuiScreen lastScreen, int tabIndex) {
29 this.lastScreen = lastScreen;
30 this.tabIndex = tabIndex;
33 public static void show() {
34 Minecraft.getInstance().displayGuiScreen(new SettingsScreen(null, 0));
37 private int getY(double row) {
38 return ((this.height / 6) - 12) + (int) ((row + 2.0) * 24.0);
41 private void addControl(IRenderableControl control) {
42 this.controls.add(control);
43 if (control instanceof IGuiEventListener) {
44 this.eventListeners.add((IGuiEventListener) control);
48 private void addTabs(String... labels) {
49 int columns = labels.length;
52 for (String label : labels) {
53 final int index = column;
54 addControl(0, column, y, CONTROLS_WIDTH / columns,
55 (id, x, y1, width) -> new AbstractButton(id, x, y, width, label, index != tabIndex) {
57 public void onPressed() {
58 Minecraft.getInstance().displayGuiScreen(new SettingsScreen(lastScreen, index));
65 addControl(new AbstractButton(200, this.width / 2 - 100, getY(5.5), 200, "Done") {
67 public void onPressed() {
68 ConfigManager.saveConfig();
69 mc.displayGuiScreen(lastScreen);
74 private int getX(int width, int column, int offset) {
75 return ((this.width - CONTROLS_WIDTH) / 2) + (column * (width + offset));
78 private IControl addControl(int offset, int column, int y, int width, CreateControl createControl) {
79 int x = getX(width, column, offset);
80 int id = controls.size();
81 IControl control = createControl.create(id, x, y, width);
82 if (control instanceof IRenderableControl)
83 addControl((IRenderableControl) control);
87 private void buildTab(int tabIndex, CreateControl... createControls) {
88 if (tabIndex != this.tabIndex) return;
91 int width = (CONTROLS_WIDTH - (2 * offset)) / 3;
94 for (CreateControl createControl : createControls) {
96 IControl control = this.addControl(offset, column, y, width, createControl);
97 if (control instanceof IRowHeight) {
102 row += ((IRowHeight) control).getRowHeight();
114 protected void initGui() {
115 this.title = ClientProxy.Name;
117 this.controls = new HashSet<>();
118 this.addTabs("General", "Structures", "Villages");
121 (id, x, y, width) -> new AbstractButton(id, x, y, width, "Active", this.mc.world != null) {
123 public void onPressed() {
124 ClientProxy.toggleActive();
128 protected int getState() {
129 return enabled ? ClientProxy.active ? 2 : 1 : 0;
132 (id, x, y, width) -> new BoolSettingButton(id, x, y, width, "Outer Box Only", ConfigManager.outerBoxesOnly),
133 (id, x, y, width) -> new BoolSettingButton(id, x, y, width, "Fill", ConfigManager.fill),
135 (id, x, y, width) -> (IRowHeight) () -> 0.5,
137 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Spawn Chunks", BoundingBoxType.WorldSpawn),
138 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Lazy Chunks", BoundingBoxType.LazySpawnChunks),
139 (id, x, y, width) -> new MaxYSettingSlider(id, x, y, width, 39, ConfigManager.worldSpawnMaxY),
141 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Slime Chunks", BoundingBoxType.SlimeChunks),
142 (id, x, y, width) -> new MaxYSettingSlider(id, x, y, width, 39, ConfigManager.slimeChunkMaxY),
143 (id, x, y, width) -> (IRowHeight) () -> 0,
145 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Mob Spawners", BoundingBoxType.MobSpawner),
146 (id, x, y, width) -> new BoolSettingButton(id, x, y, width, "Spawn Area", ConfigManager.renderMobSpawnerSpawnArea),
147 (id, x, y, width) -> new BoolSettingButton(id, x, y, width, "Activation Lines", ConfigManager.renderMobSpawnerActivationLines));
149 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Desert Temples", BoundingBoxType.DesertTemple),
150 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Jungle Temples", BoundingBoxType.JungleTemple),
151 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Witch Huts", BoundingBoxType.WitchHut),
153 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Mansions", BoundingBoxType.Mansion),
154 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Monuments", BoundingBoxType.OceanMonument),
155 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Igloos", BoundingBoxType.Igloo),
157 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Ocean Ruins", BoundingBoxType.OceanRuin),
158 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Buried Treasure", BoundingBoxType.BuriedTreasure),
159 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Shipwrecks", BoundingBoxType.Shipwreck),
161 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Pillager Outposts", BoundingBoxType.PillagerOutpost),
162 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Strongholds", BoundingBoxType.Stronghold),
163 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Mineshafts", BoundingBoxType.MineShaft),
165 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Fortresses", BoundingBoxType.NetherFortress),
166 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "End Cities", BoundingBoxType.EndCity));
168 (id, x, y, width) -> new BoolSettingButton(id, x, y, width, "Villages", ConfigManager.drawVillages),
169 (id, x, y, width) -> new BoolSettingButton(id, x, y, width, "Door Lines", ConfigManager.drawVillageDoors),
170 (id, x, y, width) -> new BoolSettingButton(id, x, y, width, "Golem Spawn", ConfigManager.drawIronGolemSpawnArea),
172 (id, x, y, width) -> new BoolSettingButton(id, x, y, width, "Render Sphere", ConfigManager.renderVillageAsSphere),
173 (id, x, y, width) -> new IntSettingSlider(id, x, y, width, 1, 5, "Dot Size", ConfigManager.villageSphereDotSize),
174 (id, x, y, width) -> new IntSettingSlider(id, x, y, width, 1, 5, "Density", ConfigManager.villageSphereDensity)
175 .addDisplayValue(1, "Fewest")
176 .addDisplayValue(2, "Fewer")
177 .addDisplayValue(3, "Normal")
178 .addDisplayValue(4, "More")
179 .addDisplayValue(5, "Most"));
182 private void drawScreen(int top, int bottom) {
183 Tessellator tessellator = Tessellator.getInstance();
184 BufferBuilder bufferBuilder = tessellator.getBuffer();
185 this.mc.getTextureManager().bindTexture(Gui.OPTIONS_BACKGROUND);
187 GL11.glDisable(GL11.GL_LIGHTING);
188 GL11.glDisable(GL11.GL_FOG);
189 GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
191 bufferBuilder.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
192 bufferBuilder.pos((double) 0, (double) bottom, 0.0D)
193 .tex((double) ((float) 0 / 32.0F), (double) ((float) bottom / 32.0F))
194 .color(32, 32, 32, 255)
196 bufferBuilder.pos((double) this.width, (double) bottom, 0.0D)
197 .tex((double) ((float) this.width / 32.0F), (double) ((float) bottom / 32.0F))
198 .color(32, 32, 32, 255)
200 bufferBuilder.pos((double) this.width, (double) top, 0.0D)
201 .tex((double) ((float) this.width / 32.0F), (double) ((float) top / 32.0F))
202 .color(32, 32, 32, 255)
204 bufferBuilder.pos((double) 0, (double) top, 0.0D)
205 .tex((double) ((float) 0 / 32.0F), (double) ((float) top / 32.0F))
206 .color(32, 32, 32, 255)
210 GL11.glDisable(GL11.GL_DEPTH_TEST);
211 GL11.glEnable(GL11.GL_BLEND);
212 OpenGlHelper.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ZERO, GL11.GL_ONE);
214 GL11.glDisable(GL11.GL_ALPHA_TEST);
215 GL11.glShadeModel(7425);
216 GL11.glDisable(GL11.GL_TEXTURE_2D);
218 bufferBuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
219 bufferBuilder.pos((double) 0, (double) (top + 4), 0.0D)
223 bufferBuilder.pos((double) this.width, (double) (top + 4), 0.0D)
227 bufferBuilder.pos((double) this.width, (double) top, 0.0D)
231 bufferBuilder.pos((double) 0, (double) top, 0.0D)
237 bufferBuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
238 bufferBuilder.pos((double) 0, (double) bottom, 0.0D)
242 bufferBuilder.pos((double) this.width, (double) bottom, 0.0D)
246 bufferBuilder.pos((double) this.width, (double) (bottom - 4), 0.0D)
250 bufferBuilder.pos((double) 0, (double) (bottom - 4), 0.0D)
256 GL11.glEnable(GL11.GL_TEXTURE_2D);
257 GL11.glShadeModel(7424);
258 GL11.glEnable(GL11.GL_ALPHA_TEST);
259 GL11.glDisable(GL11.GL_BLEND);
263 public void render(int mouseX, int mouseY, float unknown) {
264 if (this.mc.world == null) {
265 this.drawDefaultBackground();
266 this.drawScreen(getY(-1), getY(5.5) - 4);
268 this.drawCenteredString(this.fontRenderer, this.title, this.width / 2, 15, 16777215);
269 for (IRenderableControl control : controls) {
270 control.render(mouseX, mouseY);