]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/blob - src/main/java/com/irtimaled/bbor/client/gui/SettingsScreen.java
Add spawning spheres and spawnable spaces
[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.eventListeners::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         buildTab(1,
152                 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Desert Temples", BoundingBoxType.DesertTemple),
153                 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Jungle Temples", BoundingBoxType.JungleTemple),
154                 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Witch Huts", BoundingBoxType.WitchHut),
155
156                 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Mansions", BoundingBoxType.Mansion),
157                 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Monuments", BoundingBoxType.OceanMonument),
158                 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Igloos", BoundingBoxType.Igloo),
159
160                 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Ocean Ruins", BoundingBoxType.OceanRuin),
161                 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Buried Treasure", BoundingBoxType.BuriedTreasure),
162                 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Shipwrecks", BoundingBoxType.Shipwreck),
163
164                 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Strongholds", BoundingBoxType.Stronghold),
165                 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Mineshafts", BoundingBoxType.MineShaft),
166                 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Pillager Outposts", BoundingBoxType.PillagerOutpost, false),
167
168                 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Villages", BoundingBoxType.Village),
169                 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "Fortresses", BoundingBoxType.NetherFortress),
170                 (id, x, y, width) -> new BoundingBoxTypeButton(id, x, y, width, "End Cities", BoundingBoxType.EndCity));
171         buildTab(2,
172                 (id, x, y, width) -> new BoolSettingButton(id, x, y, width, "Village Spheres", ConfigManager.drawVillageSpheres),
173                 (id, x, y, width) -> new BoolSettingButton(id, x, y, width, "Door Lines", ConfigManager.drawVillageDoors),
174                 (id, x, y, width) -> new BoolSettingButton(id, x, y, width, "Golem Spawn", ConfigManager.drawIronGolemSpawnArea),
175
176                 (id, x, y, width) -> new IntSettingSlider(id, x, y, width, 1, 5, "Dot Size", ConfigManager.villageSphereDotSize),
177                 (id, x, y, width) -> new IntSettingSlider(id, x, y, width, 1, 5, "Density", ConfigManager.villageSphereDensity)
178                         .addDisplayValue(1, "Fewest")
179                         .addDisplayValue(2, "Fewer")
180                         .addDisplayValue(3, "Normal")
181                         .addDisplayValue(4, "More")
182                         .addDisplayValue(5, "Most"));
183     }
184
185     private void drawScreen(int top, int bottom) {
186         this.mc.getTextureManager().bindTexture(Gui.OPTIONS_BACKGROUND);
187
188         GL11.glDisable(GL11.GL_LIGHTING);
189         GL11.glDisable(GL11.GL_FOG);
190         GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
191
192         Renderer.startTextured()
193                 .setColor(32, 32, 32)
194                 .setAlpha(255)
195                 .addPoint(0, bottom, 0, 0, bottom / 32.0F)
196                 .addPoint(this.width, bottom, 0, this.width / 32.0F, bottom / 32.0F)
197                 .addPoint(this.width, top, 0, this.width / 32.0F, top / 32.0F)
198                 .addPoint(0, top, 0, 0, top / 32.0F)
199                 .render();
200
201         GL11.glDisable(GL11.GL_DEPTH_TEST);
202         GL11.glEnable(GL11.GL_BLEND);
203         OpenGlHelper.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ZERO, GL11.GL_ONE);
204
205         GL11.glDisable(GL11.GL_ALPHA_TEST);
206         GL11.glShadeModel(7425);
207         GL11.glDisable(GL11.GL_TEXTURE_2D);
208
209         Renderer.startTextured()
210                 .setAlpha(0)
211                 .addPoint(0, top + 4, 0, 0, 1)
212                 .addPoint(this.width, top + 4, 0, 1, 1)
213                 .setAlpha(255)
214                 .addPoint(this.width, top, 0, 1, 0)
215                 .addPoint(0, top, 0, 0, 0)
216                 .render();
217
218         Renderer.startTextured()
219                 .setAlpha(255)
220                 .addPoint(0, bottom, 0, 0, 1)
221                 .addPoint(this.width, bottom, 0, 1, 1)
222                 .setAlpha(0)
223                 .addPoint(this.width, bottom - 4, 0, 1, 0)
224                 .addPoint(0, bottom - 4, 0, 0, 0)
225                 .render();
226
227         GL11.glEnable(GL11.GL_TEXTURE_2D);
228         GL11.glShadeModel(7424);
229         GL11.glEnable(GL11.GL_ALPHA_TEST);
230         OpenGlHelper.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO);
231         GL11.glDisable(GL11.GL_BLEND);
232     }
233
234     @Override
235     public void render(int mouseX, int mouseY, float unknown) {
236         if (this.mc.world == null) {
237             this.drawDefaultBackground();
238             this.drawScreen(getY(-1), getY(5.5) - 4);
239         }
240         this.drawCenteredString(this.fontRenderer, this.title, this.width / 2, 15, 16777215);
241         for (IRenderableControl control : controls) {
242             control.render(mouseX, mouseY);
243         }
244     }
245 }