]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/blob - src/main/java/com/irtimaled/bbor/client/gui/SettingsScreen.java
Downgrade to 1.12.2
[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.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;
14
15 import java.util.HashSet;
16 import java.util.Set;
17
18 public class SettingsScreen extends GuiScreen {
19     private static final int CONTROLS_WIDTH = 310;
20
21     private final GuiScreen lastScreen;
22     private final int tabIndex;
23
24     private String title;
25     private Set<IRenderableControl> controls = new HashSet<>();
26
27     SettingsScreen(GuiScreen lastScreen, int tabIndex) {
28         this.lastScreen = lastScreen;
29         this.tabIndex = tabIndex;
30     }
31
32     public static void show() {
33         Minecraft.getMinecraft().displayGuiScreen(new SettingsScreen(null, 0));
34     }
35
36     private int getY(double row) {
37         return ((this.height / 6) - 12) + (int) ((row + 2.0) * 24.0);
38     }
39
40     private void addControl(IRenderableControl control) {
41         this.controls.add(control);
42         TypeHelper.doIfType(control, GuiButton.class, this.buttonList::add);
43     }
44
45     private void addTabs(String... labels) {
46         int columns = labels.length;
47         int column = 0;
48         int y = getY(-2);
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) {
53                         @Override
54                         public void onPressed() {
55                             Minecraft.getMinecraft().displayGuiScreen(new SettingsScreen(lastScreen, index));
56                         }
57                     });
58             column++;
59         }
60
61         //done button
62         addControl(new AbstractButton(200, this.width / 2 - 100, getY(5.5), 200, "Done") {
63             @Override
64             public void onPressed() {
65                 ConfigManager.saveConfig();
66                 mc.displayGuiScreen(lastScreen);
67             }
68         });
69     }
70
71     private int getX(int width, int column, int offset) {
72         return ((this.width - CONTROLS_WIDTH) / 2) + (column * (width + offset));
73     }
74
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);
80         return control;
81     }
82
83     private void buildTab(int tabIndex, CreateControl... createControls) {
84         if (tabIndex != this.tabIndex) return;
85
86         int offset = 4;
87         int width = (CONTROLS_WIDTH - (2 * offset)) / 3;
88         int column = 0;
89         double row = -0.75;
90         for (CreateControl createControl : createControls) {
91             int y = getY(row);
92             IControl control = this.addControl(offset, column, y, width, createControl);
93             IRowHeight rowHeight = TypeHelper.as(control, IRowHeight.class);
94             if (rowHeight != null) {
95                 if (column > 0) {
96                     row++;
97                     column = 0;
98                 } else {
99                     row += rowHeight.getRowHeight();
100                 }
101             } else {
102                 column++;
103             }
104             if (column == 3) {
105                 column = 0;
106                 row++;
107             }
108         }
109     }
110
111     @Override
112     public void initGui() {
113         this.title = ClientProxy.Name;
114
115         this.controls = new HashSet<>();
116         this.addTabs("General", "Structures", "Villages");
117
118         buildTab(0,
119                 (id, x, y, width) -> new AbstractButton(id, x, y, width, "Active", this.mc.world != null) {
120                     @Override
121                     public void onPressed() {
122                         ClientProxy.toggleActive();
123                     }
124
125                     @Override
126                     protected int getState() {
127                         return enabled ? ClientProxy.active ? 2 : 1 : 0;
128                     }
129                 },
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),
132
133                 (id, x, y, width) -> (IRowHeight) () -> 0.5,
134
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),
138
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,
142
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));
146         buildTab(1,
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),
150
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),
154
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),
158
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),
162
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));
165         buildTab(2,
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),
169
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"));
178     }
179
180     private void drawScreen(int top, int bottom) {
181         this.mc.getTextureManager().bindTexture(Gui.OPTIONS_BACKGROUND);
182
183         GL11.glDisable(GL11.GL_LIGHTING);
184         GL11.glDisable(GL11.GL_FOG);
185         GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
186
187         Renderer.startTextured()
188                 .setColor(32, 32, 32)
189                 .setAlpha(255)
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)
194                 .render();
195
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);
198
199         GL11.glDisable(GL11.GL_ALPHA_TEST);
200         GL11.glShadeModel(7425);
201         GL11.glDisable(GL11.GL_TEXTURE_2D);
202
203         Renderer.startTextured()
204                 .setAlpha(0)
205                 .addPoint(0, top + 4, 0, 0, 1)
206                 .addPoint(this.width, top + 4, 0, 1, 1)
207                 .setAlpha(255)
208                 .addPoint(this.width, top, 0, 1, 0)
209                 .addPoint(0, top, 0, 0, 0)
210                 .render();
211
212         Renderer.startTextured()
213                 .setAlpha(255)
214                 .addPoint(0, bottom, 0, 0, 1)
215                 .addPoint(this.width, bottom, 0, 1, 1)
216                 .setAlpha(0)
217                 .addPoint(this.width, bottom - 4, 0, 1, 0)
218                 .addPoint(0, bottom - 4, 0, 0, 0)
219                 .render();
220
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);
226     }
227
228     @Override
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);
233         }
234         this.drawCenteredString(this.fontRenderer, this.title, this.width / 2, 15, 16777215);
235         for (IRenderableControl control : controls) {
236             control.render(mouseX, mouseY);
237         }
238     }
239 }