]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/blob - src/main/java/com/irtimaled/bbor/client/gui/SettingsScreen.java
Upgrade to 1.13.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.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;
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.getInstance().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, IGuiEventListener.class, this.children::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.getInstance().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     protected void initGui() {
113         this.title = "Bounding Box Outline Reloaded";
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                         ClientRenderer.toggleActive();
123                     }
124
125                     @Override
126                     protected int getState() {
127                         return enabled ? ClientRenderer.getActive() ? 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) -> 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),
136
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,
140
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),
144
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"),
151
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"));
158         buildTab(1,
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),
162
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),
166
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),
170
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),
174
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));
178         buildTab(2,
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),
182
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"));
190     }
191
192     private void drawScreen(int top, int bottom) {
193         this.mc.getTextureManager().bindTexture(Gui.OPTIONS_BACKGROUND);
194
195         GL11.glDisable(GL11.GL_LIGHTING);
196         GL11.glDisable(GL11.GL_FOG);
197         GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
198
199         Renderer.startTextured()
200                 .setColor(32, 32, 32)
201                 .setAlpha(255)
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)
206                 .render();
207
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);
211
212         GL11.glDisable(GL11.GL_ALPHA_TEST);
213         GL11.glShadeModel(7425);
214         GL11.glDisable(GL11.GL_TEXTURE_2D);
215
216         Renderer.startTextured()
217                 .setAlpha(0)
218                 .addPoint(0, top + 4, 0, 0, 1)
219                 .addPoint(this.width, top + 4, 0, 1, 1)
220                 .setAlpha(255)
221                 .addPoint(this.width, top, 0, 1, 0)
222                 .addPoint(0, top, 0, 0, 0)
223                 .render();
224
225         Renderer.startTextured()
226                 .setAlpha(255)
227                 .addPoint(0, bottom, 0, 0, 1)
228                 .addPoint(this.width, bottom, 0, 1, 1)
229                 .setAlpha(0)
230                 .addPoint(this.width, bottom - 4, 0, 1, 0)
231                 .addPoint(0, bottom - 4, 0, 0, 0)
232                 .render();
233
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);
239     }
240
241     @Override
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);
246         }
247         this.drawCenteredString(this.fontRenderer, this.title, this.width / 2, 15, 16777215);
248         for (IRenderableControl control : controls) {
249             control.render(mouseX, mouseY);
250         }
251     }
252 }