Skip to content

Commit 129bb3d

Browse files
committed
Improve Button Visuals / Replace Vanilla Button w/ Custom
1 parent 2b659f4 commit 129bb3d

File tree

6 files changed

+56
-38
lines changed

6 files changed

+56
-38
lines changed
Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package btw.lowercase.optiboxes.screen;
22

3+
import btw.lowercase.optiboxes.screen.widget.SimpleButton;
34
import btw.lowercase.optiboxes.screen.widget.Text;
45
import btw.lowercase.optiboxes.skybox.OptiFineSkyLayer;
5-
import net.minecraft.client.gui.components.Button;
66
import net.minecraft.client.gui.screens.Screen;
77
import net.minecraft.network.chat.CommonComponents;
88
import net.minecraft.network.chat.Component;
@@ -19,33 +19,36 @@ public SkyLayerInfoScreen(Screen parent, OptiFineSkyLayer skyLayer, int index) {
1919
protected void init() {
2020
super.init();
2121

22-
this.gidgets.add(new Text.Builder(this.font, this.title, this.width / 2, 12).centered().build());
22+
this.gidgets.add(new Text.Builder(this.title, this.width / 2, 12).centered().build(this.font));
2323

2424
int y = 12 + (this.font.lineHeight * 3);
25-
this.gidgets.add(new Text.Builder(this.font, " Rotate: " + this.skyLayer.rotate(), this.width / 2, y).centered().build());
25+
this.gidgets.add(new Text.Builder(" Rotate: " + this.skyLayer.rotate(), this.width / 2, y).centered().build(this.font));
2626
y += this.font.lineHeight + 2;
27-
this.gidgets.add(new Text.Builder(this.font, " Axis: " + this.skyLayer.axis(), this.width / 2, y).centered().build());
27+
this.gidgets.add(new Text.Builder(" Axis: " + this.skyLayer.axis(), this.width / 2, y).centered().build(this.font));
2828
y += this.font.lineHeight + 2;
29-
this.gidgets.add(new Text.Builder(this.font, " Blend: " + this.skyLayer.blend(), this.width / 2, y).centered().build());
29+
this.gidgets.add(new Text.Builder(" Blend: " + this.skyLayer.blend(), this.width / 2, y).centered().build(this.font));
3030
y += this.font.lineHeight + 2;
31-
this.gidgets.add(new Text.Builder(this.font, " Speed: " + this.skyLayer.speed(), this.width / 2, y).centered().build());
31+
this.gidgets.add(new Text.Builder(" Speed: " + this.skyLayer.speed(), this.width / 2, y).centered().build(this.font));
3232
y += this.font.lineHeight + 2;
33-
this.gidgets.add(new Text.Builder(this.font, " Transition: " + this.skyLayer.transition(), this.width / 2, y).centered().build());
33+
this.gidgets.add(new Text.Builder(" Transition: " + this.skyLayer.transition(), this.width / 2, y).centered().build(this.font));
3434
y += this.font.lineHeight + 2;
35-
this.gidgets.add(new Text.Builder(this.font, " Fade: " + this.skyLayer.fade(), this.width / 2, y).centered().build());
35+
this.gidgets.add(new Text.Builder(" Fade: " + this.skyLayer.fade(), this.width / 2, y).centered().build(this.font));
3636
y += this.font.lineHeight + 2;
37-
this.gidgets.add(new Text.Builder(this.font, " Loop: " + this.skyLayer.loop(), this.width / 2, y).centered().build());
37+
this.gidgets.add(new Text.Builder(" Loop: " + this.skyLayer.loop(), this.width / 2, y).centered().build(this.font));
3838
y += this.font.lineHeight + 2;
39-
this.gidgets.add(new Text.Builder(this.font, " Include Biome: " + this.skyLayer.biomeInclusion(), this.width / 2, y).centered().build());
39+
this.gidgets.add(new Text.Builder(" Include Biome: " + this.skyLayer.biomeInclusion(), this.width / 2, y).centered().build(this.font));
4040
y += this.font.lineHeight + 2;
41-
this.gidgets.add(new Text.Builder(this.font, " Biomes: " + this.skyLayer.biomes(), this.width / 2, y).centered().build());
41+
this.gidgets.add(new Text.Builder(" Biomes: " + this.skyLayer.biomes(), this.width / 2, y).centered().build(this.font));
4242
y += this.font.lineHeight + 2;
43-
this.gidgets.add(new Text.Builder(this.font, " Heights: " + this.skyLayer.heights(), this.width / 2, y).centered().build());
43+
this.gidgets.add(new Text.Builder(" Heights: " + this.skyLayer.heights(), this.width / 2, y).centered().build(this.font));
4444
y += this.font.lineHeight + 2;
45-
this.gidgets.add(new Text.Builder(this.font, " Weather Conditions: " + this.skyLayer.weatherConditions(), this.width / 2, y).centered().build());
45+
this.gidgets.add(new Text.Builder(" Weather Conditions: " + this.skyLayer.weatherConditions(), this.width / 2, y).centered().build(this.font));
4646

47-
this.addRenderableWidget(Button.builder(CommonComponents.GUI_BACK, (button) -> this.onClose())
48-
.pos((this.width / 2) - (Button.DEFAULT_WIDTH / 2), this.height - Button.DEFAULT_HEIGHT - 4)
49-
.build());
47+
this.gidgets.add(new SimpleButton(
48+
CommonComponents.GUI_BACK,
49+
(this.width / 2) - (SimpleButton.DEFAULT_WIDTH / 2),
50+
this.height - SimpleButton.DEFAULT_HEIGHT - 4,
51+
(button) -> this.onClose()
52+
));
5053
}
5154
}

src/main/java/btw/lowercase/optiboxes/screen/SkyLayerListScreen.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import btw.lowercase.optiboxes.screen.widget.Text;
55
import btw.lowercase.optiboxes.skybox.OptiFineSkyLayer;
66
import btw.lowercase.optiboxes.skybox.OptiFineSkybox;
7-
import net.minecraft.client.gui.components.Button;
87
import net.minecraft.client.gui.screens.Screen;
98
import net.minecraft.network.chat.CommonComponents;
109
import net.minecraft.network.chat.Component;
@@ -21,8 +20,8 @@ public SkyLayerListScreen(Screen parent, OptiFineSkybox skybox) {
2120
protected void init() {
2221
super.init();
2322

24-
this.gidgets.add(new Text.Builder(this.font, this.title, this.width / 2, 12).centered().build());
25-
this.gidgets.add(new Text.Builder(this.font, this.skybox.getLayers().size() + " layers", this.width / 2, 12 + this.font.lineHeight).centered().build());
23+
this.gidgets.add(new Text.Builder(this.title, this.width / 2, 12).centered().build(this.font));
24+
this.gidgets.add(new Text.Builder(this.skybox.getLayers().size() + " layers", this.width / 2, 12 + this.font.lineHeight).centered().build(this.font));
2625

2726
int index = 0;
2827
for (OptiFineSkyLayer skyLayer : this.skybox.getLayers()) {
@@ -36,9 +35,12 @@ protected void init() {
3635
index++;
3736
}
3837

39-
this.addRenderableWidget(Button.builder(CommonComponents.GUI_BACK, (button) -> this.onClose())
40-
.pos((this.width / 2) - (Button.DEFAULT_WIDTH / 2), this.height - Button.DEFAULT_HEIGHT - 4)
41-
.build());
38+
this.gidgets.add(new SimpleButton(
39+
CommonComponents.GUI_BACK,
40+
(this.width / 2) - (SimpleButton.DEFAULT_WIDTH / 2),
41+
this.height - SimpleButton.DEFAULT_HEIGHT - 4,
42+
(button) -> this.onClose()
43+
));
4244
}
4345
}
4446

src/main/java/btw/lowercase/optiboxes/screen/SkyboxListScreen.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import btw.lowercase.optiboxes.screen.widget.SimpleButton;
44
import btw.lowercase.optiboxes.screen.widget.Text;
55
import btw.lowercase.optiboxes.skybox.OptiFineSkybox;
6-
import net.minecraft.client.gui.components.Button;
76
import net.minecraft.client.gui.screens.Screen;
87
import net.minecraft.network.chat.CommonComponents;
98
import net.minecraft.network.chat.Component;
@@ -23,7 +22,7 @@ protected void init() {
2322
super.init();
2423

2524
// TODO: isActive | button color
26-
this.gidgets.add(new Text.Builder(this.font, this.title, this.width / 2, 12).centered().build());
25+
this.gidgets.add(new Text.Builder(this.title, this.width / 2, 12).centered().build(this.font));
2726

2827
int index = 0;
2928
for (OptiFineSkybox skybox : this.skyboxes) {
@@ -36,8 +35,11 @@ protected void init() {
3635
index++;
3736
}
3837

39-
this.addRenderableWidget(Button.builder(CommonComponents.GUI_DONE, (button) -> this.onClose())
40-
.pos((this.width / 2) - (Button.DEFAULT_WIDTH / 2), this.height - Button.DEFAULT_HEIGHT - 4)
41-
.build());
38+
this.gidgets.add(new SimpleButton(
39+
CommonComponents.GUI_DONE,
40+
(this.width / 2) - (SimpleButton.DEFAULT_WIDTH / 2),
41+
this.height - SimpleButton.DEFAULT_HEIGHT - 4,
42+
(button) -> this.onClose()
43+
));
4244
}
4345
}

src/main/java/btw/lowercase/optiboxes/screen/widget/SimpleButton.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
import net.minecraft.client.gui.GuiGraphics;
66
import net.minecraft.network.chat.Component;
77
import net.minecraft.resources.Identifier;
8+
import net.minecraft.util.ARGB;
89

910
import java.util.HashMap;
1011
import java.util.Map;
1112
import java.util.function.Consumer;
1213

13-
public class SimpleButton extends Gidget implements Clickable {
14+
public class SimpleButton extends Gidget implements Clickable, TextHolder {
1415
public static final int DEFAULT_WIDTH = 200;
1516
public static final int DEFAULT_HEIGHT = 20;
1617

@@ -26,18 +27,22 @@ public SimpleButton(Component text, int x, int y, Consumer<? super SimpleButton>
2627
@Override
2728
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY) {
2829
boolean hovered = this.isInside(mouseX, mouseY);
29-
guiGraphics.fill(this.x, this.y, this.x + this.width, this.y + this.height, hovered ? 0xFF00FF00 : 0xFF00FFFF);
30+
31+
int backgroundColor = hovered ? ARGB.color(0.7F, 0xFFFFFF) : ARGB.color(0.58F, 0xFFFFFF);
32+
guiGraphics.fill(this.x, this.y, this.x + this.width, this.y + this.height, backgroundColor);
3033

3134
Font font = Minecraft.getInstance().font;
3235
int textWidth = font.width(this.text.getString());
33-
guiGraphics.drawString(font, this.text, this.x + ((this.width / 2) - (textWidth / 2)), this.y + ((this.height / 2) - (font.lineHeight / 2)), 0xFFFFFFFF);
36+
int textColor = hovered ? ARGB.color(1.0F, 0xFFFFA0) : ARGB.color(1.0F, 0xE0E0E0);
37+
guiGraphics.drawString(font, this.text, this.x + ((this.width / 2) - (textWidth / 2)), this.y + ((this.height / 2) - (font.lineHeight / 2)), textColor);
3438
}
3539

3640
@Override
3741
public void click(double mouseX, double mouseY) {
3842
this.onClick.accept(this);
3943
}
4044

45+
@Override
4146
public Component getText() {
4247
return this.text;
4348
}

src/main/java/btw/lowercase/optiboxes/screen/widget/Text.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import net.minecraft.network.chat.Component;
66
import net.minecraft.util.ARGB;
77

8-
public class Text extends Gidget {
8+
public class Text extends Gidget implements TextHolder {
99
private final Font font;
1010
private final Component text;
1111
private final int color;
@@ -31,6 +31,7 @@ public void render(GuiGraphics guiGraphics, int mouseX, int mouseY) {
3131
guiGraphics.drawString(this.font, this.text, finalX, this.y, this.color, this.shadow);
3232
}
3333

34+
@Override
3435
public Component getText() {
3536
return this.text;
3637
}
@@ -48,7 +49,6 @@ public boolean hasShadow() {
4849
}
4950

5051
public static class Builder {
51-
private final Font font;
5252
private final Component text;
5353
private final int x;
5454
private final int y;
@@ -57,15 +57,14 @@ public static class Builder {
5757
private boolean centered = false;
5858
private boolean shadow = true;
5959

60-
public Builder(Font font, Component text, int x, int y) {
61-
this.font = font;
60+
public Builder(Component text, int x, int y) {
6261
this.text = text;
6362
this.x = x;
6463
this.y = y;
6564
}
6665

67-
public Builder(Font font, String text, int x, int y) {
68-
this(font, Component.literal(text), x, y);
66+
public Builder(String text, int x, int y) {
67+
this(Component.literal(text), x, y);
6968
}
7069

7170
public Builder withColor(int color) {
@@ -83,8 +82,8 @@ public Builder centered() {
8382
return this;
8483
}
8584

86-
public Text build() {
87-
return new Text(this.font, this.text, this.x, this.y, this.color, this.centered, this.shadow);
85+
public Text build(Font font) {
86+
return new Text(font, this.text, this.x, this.y, this.color, this.centered, this.shadow);
8887
}
8988
}
9089
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package btw.lowercase.optiboxes.screen.widget;
2+
3+
import net.minecraft.network.chat.Component;
4+
5+
public interface TextHolder {
6+
Component getText();
7+
}

0 commit comments

Comments
 (0)