]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/blob - src/main/java/com/irtimaled/bbor/client/gui/SettingsScreen.java
cbb0b8224445bf7fe04bd25da69dd3c6e81588e7
[BoundingBoxOutlineReloaded.git] / src / main / java / com / irtimaled / bbor / client / gui / SettingsScreen.java
1 package com.irtimaled.bbor.client.gui;
2
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;
15
16 import java.util.HashSet;
17 import java.util.Set;
18
19 public class SettingsScreen extends GuiScreen {
20     private static final int CONTROLS_WIDTH = 310;
21
22     private final GuiScreen lastScreen;
23     private final int tabIndex;
24
25     private String title;
26     private Set<IRenderableControl> controls = new HashSet<>();
27
28     SettingsScreen(GuiScreen lastScreen, int tabIndex) {
29         this.lastScreen = lastScreen;
30         this.tabIndex = tabIndex;
31     }
32
33     public static void show() {
34         Minecraft.getInstance().displayGuiScreen(new SettingsScreen(null, 0));
35     }
36
37     private int getY(double row) {
38         return ((this.height / 6) - 12) + (int) ((row + 2.0) * 24.0);
39     }
40
41     private void addControl(IRenderableControl control) {
42         this.controls.add(control);
43         if (control instanceof IGuiEventListener) {
44             this.eventListeners.add((IGuiEventListener) control);
45         }
46     }
47
48     private void addTabs(String... labels) {
49         int columns = labels.length;
50         int column = 0;
51         int y = getY(-2);
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) {
56                         @Override
57                         public void onPressed() {
58                             Minecraft.getInstance().displayGuiScreen(new SettingsScreen(lastScreen, index));
59                         }
60                     });
61             column++;
62         }
63
64         //done button
65         addControl(new AbstractButton(200, this.width / 2 - 100, getY(5.5), 200, "Done") {
66             @Override
67             public void onPressed() {
68                 ConfigManager.saveConfig();
69                 mc.displayGuiScreen(lastScreen);
70             }
71         });
72     }
73
74     private int getX(int width, int column, int offset) {
75         return ((this.width - CONTROLS_WIDTH) / 2) + (column * (width + offset));
76     }
77
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);
84         return control;
85     }
86
87     private void buildTab(int tabIndex, CreateControl... createControls) {
88         if (tabIndex != this.tabIndex) return;
89
90         int offset = 4;
91         int width = (CONTROLS_WIDTH - (2 * offset)) / 3;
92         int column = 0;
93         double row = -0.75;
94         for (CreateControl createControl : createControls) {
95             int y = getY(row);
96             IControl control = this.addControl(offset, column, y, width, createControl);
97             if (control instanceof IRowHeight) {
98                 if (column > 0) {
99                     row++;
100                     column = 0;
101                 } else {
102                     row += ((IRowHeight) control).getRowHeight();
103                 }
104             } else {
105                 column++;
106             }
107             if (column == 3) {
108                 column = 0;
109                 row++;
110             }
111         }
112     }
113
114     protected void initGui() {
115         this.title = ClientProxy.Name;
116
117         this.controls = new HashSet<>();
118         this.addTabs("General", "Structures", "Villages");
119
120         buildTab(0,
121                 (id, x, y, width) -> new AbstractButton(id, x, y, width, "Active", this.mc.world != null) {
122                     @Override
123                     public void onPressed() {
124                         ClientProxy.toggleActive();
125                     }
126
127                     @Override
128                     protected int getState() {
129                         return enabled ? ClientProxy.active ? 2 : 1 : 0;
130                     }
131                 },
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),
134
135                 (id, x, y, width) -> (IRowHeight) () -> 0.5,
136
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),
140
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,
144
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));
148         buildTab(1,
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),
152
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),
156
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),
160
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),
164
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));
167         buildTab(2,
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),
171
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"));
180     }
181
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);
186
187         GL11.glDisable(GL11.GL_LIGHTING);
188         GL11.glDisable(GL11.GL_FOG);
189         GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
190
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)
195                 .endVertex();
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)
199                 .endVertex();
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)
203                 .endVertex();
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)
207                 .endVertex();
208         tessellator.draw();
209
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);
213
214         GL11.glDisable(GL11.GL_ALPHA_TEST);
215         GL11.glShadeModel(7425);
216         GL11.glDisable(GL11.GL_TEXTURE_2D);
217
218         bufferBuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
219         bufferBuilder.pos((double) 0, (double) (top + 4), 0.0D)
220                 .tex(0.0D, 1.0D)
221                 .color(0, 0, 0, 0)
222                 .endVertex();
223         bufferBuilder.pos((double) this.width, (double) (top + 4), 0.0D)
224                 .tex(1.0D, 1.0D)
225                 .color(0, 0, 0, 0)
226                 .endVertex();
227         bufferBuilder.pos((double) this.width, (double) top, 0.0D)
228                 .tex(1.0D, 0.0D)
229                 .color(0, 0, 0, 255)
230                 .endVertex();
231         bufferBuilder.pos((double) 0, (double) top, 0.0D)
232                 .tex(0.0D, 0.0D)
233                 .color(0, 0, 0, 255)
234                 .endVertex();
235         tessellator.draw();
236
237         bufferBuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
238         bufferBuilder.pos((double) 0, (double) bottom, 0.0D)
239                 .tex(0.0D, 1.0D)
240                 .color(0, 0, 0, 255)
241                 .endVertex();
242         bufferBuilder.pos((double) this.width, (double) bottom, 0.0D)
243                 .tex(1.0D, 1.0D)
244                 .color(0, 0, 0, 255)
245                 .endVertex();
246         bufferBuilder.pos((double) this.width, (double) (bottom - 4), 0.0D)
247                 .tex(1.0D, 0.0D)
248                 .color(0, 0, 0, 0)
249                 .endVertex();
250         bufferBuilder.pos((double) 0, (double) (bottom - 4), 0.0D)
251                 .tex(0.0D, 0.0D)
252                 .color(0, 0, 0, 0)
253                 .endVertex();
254         tessellator.draw();
255
256         GL11.glEnable(GL11.GL_TEXTURE_2D);
257         GL11.glShadeModel(7424);
258         GL11.glEnable(GL11.GL_ALPHA_TEST);
259         GL11.glDisable(GL11.GL_BLEND);
260     }
261
262     @Override
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);
267         }
268         this.drawCenteredString(this.fontRenderer, this.title, this.width / 2, 15, 16777215);
269         for (IRenderableControl control : controls) {
270             control.render(mouseX, mouseY);
271         }
272     }
273 }