Skip to content

Commit ef5fb28

Browse files
committed
Add GUI to configuration support
1 parent df77492 commit ef5fb28

15 files changed

Lines changed: 531 additions & 1 deletion
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.irtimaled.bbor.client.gui;
2+
3+
import com.irtimaled.bbor.config.Setting;
4+
5+
public class BoolSettingButton extends Button {
6+
private final Setting<Boolean> setting;
7+
8+
BoolSettingButton(int id, int x, int y, int width, String label, Setting<Boolean> setting) {
9+
super(id, x, y, width, label);
10+
this.setting = setting;
11+
}
12+
13+
@Override
14+
protected int getHoverState(boolean p_getHoverState_1_) {
15+
return setting.get() ? 2 : 1;
16+
}
17+
18+
@Override
19+
public void onClick(double p_onClick_1_, double p_onClick_3_) {
20+
setting.set(!setting.get());
21+
}
22+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.irtimaled.bbor.client.gui;
2+
3+
import com.irtimaled.bbor.common.BoundingBoxType;
4+
import net.minecraft.client.Minecraft;
5+
6+
import java.awt.*;
7+
8+
public class BoundingBoxTypeButton extends BoolSettingButton {
9+
private final Color color;
10+
11+
BoundingBoxTypeButton(int id, int x, int y, int width, String label, BoundingBoxType type) {
12+
super(id, x, y, width, label, type.shouldRenderSetting);
13+
color = type.getColor();
14+
}
15+
16+
@Override
17+
protected void renderBg(Minecraft p_renderBg_1_, int p_renderBg_2_, int p_renderBg_3_) {
18+
int left = x + 1;
19+
int top = y + 1;
20+
int right = left + width - 2;
21+
int bottom = top + height - 2;
22+
23+
// top & left
24+
drawRect(left, top, right, top + 1, color.getRGB());
25+
drawRect(left, top, left + 1, bottom, color.getRGB());
26+
27+
Color darker = color.darker();
28+
// bottom left & top right
29+
drawRect(left, bottom - 2, left + 1, bottom, darker.getRGB());
30+
drawRect(right - 1, top, right, top + 1, darker.getRGB());
31+
32+
Color darkest = darker.darker();
33+
// bottom & right
34+
drawRect(left + 1, bottom - 2, right, bottom, darkest.getRGB());
35+
drawRect(right - 1, top + 1, right, bottom, darkest.getRGB());
36+
}
37+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.irtimaled.bbor.client.gui;
2+
3+
import net.minecraft.client.gui.GuiButton;
4+
5+
class Button extends GuiButton implements IRenderableControl {
6+
Button(int id, int x, int y, int width, String name) {
7+
super(id, x, y, width, 20, name);
8+
}
9+
10+
Button(int id, int x, int y, int width, String name, boolean enabled) {
11+
this(id, x,y,width,name);
12+
this.enabled = enabled;
13+
}
14+
15+
@Override
16+
public void render(int mouseX, int mouseY) {
17+
super.render(mouseX, mouseY, 0f);
18+
}
19+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.irtimaled.bbor.client.gui;
2+
3+
@FunctionalInterface
4+
interface CreateControl {
5+
IControl create(Integer id, Integer x, Integer y, Integer width);
6+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.irtimaled.bbor.client.gui;
2+
3+
interface IControl {
4+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.irtimaled.bbor.client.gui;
2+
3+
interface IRenderableControl extends IControl {
4+
void render(int mouseX, int mouseY);
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.irtimaled.bbor.client.gui;
2+
3+
interface IRowHeight extends IControl {
4+
double getRowHeight();
5+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package com.irtimaled.bbor.client.gui;
2+
3+
import com.irtimaled.bbor.config.Setting;
4+
import net.minecraft.client.Minecraft;
5+
import net.minecraft.client.renderer.GlStateManager;
6+
import net.minecraft.util.math.MathHelper;
7+
8+
import java.util.HashMap;
9+
import java.util.Map;
10+
11+
class IntSettingSlider extends Button implements IRenderableControl {
12+
private final int maxValue;
13+
private final String prefix;
14+
private boolean dragging;
15+
private Map<Integer, String> displayValues = new HashMap<>();
16+
17+
final Setting<Integer> setting;
18+
final int minValue;
19+
final int range;
20+
double sliderValue;
21+
22+
IntSettingSlider(int id, int x, int y, int width, int minValue, int maxValue, String prefix, Setting<Integer> setting) {
23+
super(id, x, y, width, "");
24+
this.setting = setting;
25+
this.minValue = minValue;
26+
this.maxValue = maxValue;
27+
this.prefix = prefix;
28+
this.range = maxValue - minValue;
29+
this.sliderValue = getSliderValue();
30+
this.displayString = getDisplayValue();
31+
}
32+
33+
IntSettingSlider addDisplayValue(int value, String displayValue) {
34+
displayValues.put(value, displayValue);
35+
if(setting.get() == value) {
36+
this.displayString = getDisplayValue();
37+
}
38+
return this;
39+
}
40+
41+
private String getDisplayValue() {
42+
Integer value = setting.get();
43+
return prefix + ": " + displayValues.getOrDefault(value, value.toString());
44+
}
45+
46+
protected Integer getSettingValue() {
47+
return MathHelper.clamp(minValue + (int) (range * sliderValue), minValue, maxValue);
48+
}
49+
50+
protected double getSliderValue() {
51+
return MathHelper.clamp((setting.get() - minValue) / (double) range, 0d, 1d);
52+
}
53+
54+
@Override
55+
protected int getHoverState(boolean p_getHoverState_1_) {
56+
return 0;
57+
}
58+
59+
@Override
60+
protected void renderBg(Minecraft minecraft, int mouseX, int mouseY) {
61+
if (this.dragging) {
62+
changeSlider(mouseX);
63+
}
64+
65+
minecraft.getTextureManager().bindTexture(BUTTON_TEXTURES);
66+
GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
67+
this.drawTexturedModalRect(this.x + (int) (this.sliderValue * (double) (this.width - 8)), this.y, 0, 66, 4, 20);
68+
this.drawTexturedModalRect(this.x + (int) (this.sliderValue * (double) (this.width - 8)) + 4, this.y, 196, 66, 4, 20);
69+
}
70+
71+
public final void onClick(double mouseX, double mouseY) {
72+
changeSlider(mouseX);
73+
this.dragging = true;
74+
}
75+
76+
private void changeSlider(double mouseX) {
77+
double proportion = (mouseX - (double) (this.x + 4)) / (double) (this.width - 8);
78+
this.sliderValue = MathHelper.clamp(proportion, 0d, 1d);
79+
this.setting.set(this.getSettingValue());
80+
this.displayString = this.getDisplayValue();
81+
}
82+
83+
public void onRelease(double p_onRelease_1_, double p_onRelease_3_) {
84+
this.dragging = false;
85+
}
86+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.irtimaled.bbor.client.gui;
2+
3+
import com.irtimaled.bbor.config.Setting;
4+
import net.minecraft.util.math.MathHelper;
5+
6+
class MaxYSettingSlider extends IntSettingSlider {
7+
private final int actualMinValue;
8+
9+
MaxYSettingSlider(int id, int x, int y, int width, int minValue, Setting<Integer> setting) {
10+
super(id, x, y, width, minValue - 2, 127, "Max Y", setting);
11+
this.actualMinValue = minValue;
12+
this.sliderValue = getSliderValue();
13+
this.addDisplayValue(-1, "Activated");
14+
this.addDisplayValue(0, "Player");
15+
this.addDisplayValue(63, "Sea Level");
16+
}
17+
18+
@Override
19+
protected Integer getSettingValue() {
20+
Integer value = super.getSettingValue();
21+
if (value >= actualMinValue)
22+
return value;
23+
return (value + 1) - actualMinValue;
24+
}
25+
26+
@Override
27+
protected double getSliderValue() {
28+
int value = setting.get();
29+
if (value < actualMinValue)
30+
value = (value - 1) + actualMinValue;
31+
32+
return MathHelper.clamp((value - minValue) / (double) range, 0d, 1d);
33+
}
34+
}

0 commit comments

Comments
 (0)