Skip to content

Commit 874010c

Browse files
committed
Add Text & Improve Screen titles & Add Skybox Layer Info to Screen
1 parent cd8d02c commit 874010c

File tree

5 files changed

+161
-52
lines changed

5 files changed

+161
-52
lines changed

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import btw.lowercase.optiboxes.OptiBoxesClient;
44
import btw.lowercase.optiboxes.screen.widget.Gidget;
55
import btw.lowercase.optiboxes.screen.widget.SimpleButton;
6+
import btw.lowercase.optiboxes.screen.widget.Text;
67
import btw.lowercase.optiboxes.skybox.OptiFineSkybox;
78
import net.minecraft.client.gui.GuiGraphics;
89
import net.minecraft.client.gui.components.Button;
@@ -11,7 +12,6 @@
1112
import net.minecraft.network.chat.CommonComponents;
1213
import net.minecraft.network.chat.Component;
1314
import net.minecraft.resources.Identifier;
14-
import net.minecraft.util.ARGB;
1515
import org.jetbrains.annotations.NotNull;
1616

1717
import java.util.ArrayList;
@@ -25,21 +25,20 @@ public class OptiboxesDebugScreen extends Screen {
2525
private static final Identifier SKYBOX_LOCATION = OptiBoxesClient.locationOrNull("skybox");
2626

2727
public OptiboxesDebugScreen(Screen parent, List<OptiFineSkybox> skyboxes) {
28-
super(Component.empty());
28+
super(Component.literal(skyboxes.isEmpty() ? "No skies enabled..." : skyboxes.size() + " Total Active Skyboxes"));
2929
this.parent = parent;
3030
this.skyboxes = skyboxes;
3131
this.gidgets = new ArrayList<>();
3232
}
3333

3434
@Override
3535
protected void init() {
36-
int index = 0;
3736
this.gidgets.clear();
38-
this.addRenderableWidget(Button.builder(CommonComponents.GUI_DONE, (button) -> this.onClose())
39-
.pos((this.width / 2) - (Button.DEFAULT_WIDTH / 2), this.height - Button.DEFAULT_HEIGHT - 4)
40-
.build());
37+
this.gidgets.add(new Text.Builder(this.font, this.title, this.width / 2, 12).centered().build());
38+
39+
int index = 0;
4140
for (OptiFineSkybox skybox : this.skyboxes) {
42-
SimpleButton.DataHolder<OptiFineSkybox> button = new SimpleButton.DataHolder<>(
41+
SimpleButton.Storage button = new SimpleButton.Storage(
4342
Component.literal(skybox.getWorldResourceKey().identifier().toString()),
4443
(this.width / 2) - (SimpleButton.DEFAULT_WIDTH / 2),
4544
30 + ((SimpleButton.DEFAULT_HEIGHT + 8) * index),
@@ -49,16 +48,17 @@ protected void init() {
4948
this.gidgets.add(button);
5049
index++;
5150
}
51+
52+
this.addRenderableWidget(Button.builder(CommonComponents.GUI_DONE, (button) -> this.onClose())
53+
.pos((this.width / 2) - (Button.DEFAULT_WIDTH / 2), this.height - Button.DEFAULT_HEIGHT - 4)
54+
.build());
5255
}
5356

5457
@Override
5558
public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) {
5659
super.render(guiGraphics, mouseX, mouseY, delta);
57-
guiGraphics.drawCenteredString(this.font, this.skyboxes.isEmpty() ? "No skies enabled..." : this.skyboxes.size() + " Total Active Skyboxes", this.width / 2, 12, ARGB.white(1.0F));
5860
for (Gidget gidget : this.gidgets) {
59-
if (gidget instanceof SimpleButton button) {
60-
button.render(guiGraphics, mouseX, mouseY);
61-
}
61+
gidget.render(guiGraphics, mouseX, mouseY);
6262
}
6363
}
6464

@@ -79,8 +79,8 @@ public void onClose() {
7979
}
8080

8181
private void buttonClicked(SimpleButton button) {
82-
if (button instanceof SimpleButton.DataHolder<?> holder) {
83-
this.minecraft.setScreen(new SkyboxInfoScreen(this, (OptiFineSkybox) holder.get(SKYBOX_LOCATION)));
82+
if (button instanceof SimpleButton.Storage storage) {
83+
this.minecraft.setScreen(new SkyboxInfoScreen(this, storage.get(SKYBOX_LOCATION)));
8484
}
8585
}
8686
}

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

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,58 @@
11
package btw.lowercase.optiboxes.screen;
22

3+
import btw.lowercase.optiboxes.screen.widget.Gidget;
4+
import btw.lowercase.optiboxes.screen.widget.Text;
35
import btw.lowercase.optiboxes.skybox.OptiFineSkyLayer;
46
import net.minecraft.client.gui.GuiGraphics;
57
import net.minecraft.client.gui.components.Button;
68
import net.minecraft.client.gui.screens.Screen;
79
import net.minecraft.network.chat.CommonComponents;
810
import net.minecraft.network.chat.Component;
9-
import net.minecraft.util.ARGB;
1011
import org.jetbrains.annotations.NotNull;
1112

13+
import java.util.ArrayList;
14+
import java.util.List;
15+
1216
public class SkyLayerInfoScreen extends Screen {
1317
private final Screen parent;
1418
private final OptiFineSkyLayer skyLayer;
15-
private final int index;
19+
private final List<Gidget> gidgets;
1620

1721
public SkyLayerInfoScreen(Screen parent, OptiFineSkyLayer skyLayer, int index) {
18-
super(Component.empty());
22+
super(Component.literal(index + " - " + skyLayer.source().toString()));
1923
this.parent = parent;
2024
this.skyLayer = skyLayer;
21-
this.index = index;
25+
this.gidgets = new ArrayList<>();
2226
}
2327

2428
@Override
2529
protected void init() {
30+
this.gidgets.clear();
31+
this.gidgets.add(new Text.Builder(this.font, this.title, this.width / 2, 12).centered().build());
32+
33+
int y = 12 + (this.font.lineHeight * 3);
34+
this.gidgets.add(new Text.Builder(this.font, " Rotate: " + this.skyLayer.rotate(), this.width / 2, y).centered().build());
35+
y += this.font.lineHeight + 2;
36+
this.gidgets.add(new Text.Builder(this.font, " Axis: " + this.skyLayer.axis(), this.width / 2, y).centered().build());
37+
y += this.font.lineHeight + 2;
38+
this.gidgets.add(new Text.Builder(this.font, " Blend: " + this.skyLayer.blend(), this.width / 2, y).centered().build());
39+
y += this.font.lineHeight + 2;
40+
this.gidgets.add(new Text.Builder(this.font, " Speed: " + this.skyLayer.speed(), this.width / 2, y).centered().build());
41+
y += this.font.lineHeight + 2;
42+
this.gidgets.add(new Text.Builder(this.font, " Transition: " + this.skyLayer.transition(), this.width / 2, y).centered().build());
43+
y += this.font.lineHeight + 2;
44+
this.gidgets.add(new Text.Builder(this.font, " Fade: " + this.skyLayer.fade(), this.width / 2, y).centered().build());
45+
y += this.font.lineHeight + 2;
46+
this.gidgets.add(new Text.Builder(this.font, " Loop: " + this.skyLayer.loop(), this.width / 2, y).centered().build());
47+
y += this.font.lineHeight + 2;
48+
this.gidgets.add(new Text.Builder(this.font, " Include Biome: " + this.skyLayer.biomeInclusion(), this.width / 2, y).centered().build());
49+
y += this.font.lineHeight + 2;
50+
this.gidgets.add(new Text.Builder(this.font, " Biomes: " + this.skyLayer.biomes(), this.width / 2, y).centered().build());
51+
y += this.font.lineHeight + 2;
52+
this.gidgets.add(new Text.Builder(this.font, " Heights: " + this.skyLayer.heights(), this.width / 2, y).centered().build());
53+
y += this.font.lineHeight + 2;
54+
this.gidgets.add(new Text.Builder(this.font, " Weather Conditions: " + this.skyLayer.weatherConditions(), this.width / 2, y).centered().build());
55+
2656
this.addRenderableWidget(Button.builder(CommonComponents.GUI_BACK, (button) -> this.onClose())
2757
.pos((this.width / 2) - (Button.DEFAULT_WIDTH / 2), this.height - Button.DEFAULT_HEIGHT - 4)
2858
.build());
@@ -31,18 +61,9 @@ protected void init() {
3161
@Override
3262
public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) {
3363
super.render(guiGraphics, mouseX, mouseY, delta);
34-
guiGraphics.drawCenteredString(this.font, Component.literal(this.index + " - " + this.skyLayer.source().toString()), this.width / 2, 12, ARGB.white(1.0F));
35-
// context.getSource().sendFeedback(Component.literal(" Rotate: " + skyLayer.rotate()));
36-
// context.getSource().sendFeedback(Component.literal(" Axis: " + skyLayer.axis()));
37-
// context.getSource().sendFeedback(Component.literal(" Blend: " + skyLayer.blend()));
38-
// context.getSource().sendFeedback(Component.literal(" Speed: " + skyLayer.speed()));
39-
// context.getSource().sendFeedback(Component.literal(" Transition: " + skyLayer.transition()));
40-
// context.getSource().sendFeedback(Component.literal(" Fade: " + skyLayer.fade()));
41-
// context.getSource().sendFeedback(Component.literal(" Loop: " + skyLayer.loop()));
42-
// context.getSource().sendFeedback(Component.literal(" Include Biome: " + skyLayer.biomeInclusion()));
43-
// context.getSource().sendFeedback(Component.literal(" Biomes: " + skyLayer.biomes()));
44-
// context.getSource().sendFeedback(Component.literal(" Heights: " + skyLayer.heights()));
45-
// context.getSource().sendFeedback(Component.literal(" Weather Conditions: " + skyLayer.weatherConditions()));
64+
for (Gidget gidget : this.gidgets) {
65+
gidget.render(guiGraphics, mouseX, mouseY);
66+
}
4667
}
4768

4869
@Override

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

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import btw.lowercase.optiboxes.OptiBoxesClient;
44
import btw.lowercase.optiboxes.screen.widget.Gidget;
55
import btw.lowercase.optiboxes.screen.widget.SimpleButton;
6+
import btw.lowercase.optiboxes.screen.widget.Text;
67
import btw.lowercase.optiboxes.skybox.OptiFineSkyLayer;
78
import btw.lowercase.optiboxes.skybox.OptiFineSkybox;
89
import net.minecraft.client.gui.GuiGraphics;
@@ -12,7 +13,6 @@
1213
import net.minecraft.network.chat.CommonComponents;
1314
import net.minecraft.network.chat.Component;
1415
import net.minecraft.resources.Identifier;
15-
import net.minecraft.util.ARGB;
1616
import org.jetbrains.annotations.NotNull;
1717

1818
import java.util.ArrayList;
@@ -27,21 +27,21 @@ public class SkyboxInfoScreen extends Screen {
2727
private static final Identifier INDEX_LOCATION = OptiBoxesClient.locationOrNull("index");
2828

2929
public SkyboxInfoScreen(Screen parent, OptiFineSkybox skybox) {
30-
super(Component.empty());
30+
super(Component.literal(skybox.getWorldResourceKey().identifier().toString()));
3131
this.parent = parent;
3232
this.skybox = skybox;
3333
this.gidgets = new ArrayList<>();
3434
}
3535

3636
@Override
3737
protected void init() {
38-
int index = 0;
3938
this.gidgets.clear();
40-
this.addRenderableWidget(Button.builder(CommonComponents.GUI_BACK, (button) -> this.onClose())
41-
.pos((this.width / 2) - (Button.DEFAULT_WIDTH / 2), this.height - Button.DEFAULT_HEIGHT - 4)
42-
.build());
39+
this.gidgets.add(new Text.Builder(this.font, this.title, this.width / 2, 12).centered().build());
40+
this.gidgets.add(new Text.Builder(this.font, this.skybox.getLayers().size() + " layers", this.width / 2, 12 + this.font.lineHeight).centered().build());
41+
42+
int index = 0;
4343
for (OptiFineSkyLayer layer : this.skybox.getLayers()) {
44-
SimpleButton.DataHolder<Object> button = new SimpleButton.DataHolder<>(
44+
SimpleButton.Storage button = new SimpleButton.Storage(
4545
Component.literal(index + " - " + layer.source()),
4646
(this.width / 2) - (SimpleButton.DEFAULT_WIDTH / 2),
4747
36 + ((SimpleButton.DEFAULT_HEIGHT + 8) * index),
@@ -52,18 +52,18 @@ protected void init() {
5252
this.gidgets.add(button);
5353
index++;
5454
}
55+
56+
this.addRenderableWidget(Button.builder(CommonComponents.GUI_BACK, (button) -> this.onClose())
57+
.pos((this.width / 2) - (Button.DEFAULT_WIDTH / 2), this.height - Button.DEFAULT_HEIGHT - 4)
58+
.build());
5559
}
5660

5761
@Override
5862
public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) {
5963
super.render(guiGraphics, mouseX, mouseY, delta);
60-
guiGraphics.drawCenteredString(this.font, this.skybox.getWorldResourceKey().identifier().toString(), this.width / 2, 12, ARGB.white(1.0F));
61-
guiGraphics.drawCenteredString(this.font, this.skybox.getLayers().size() + " layers", this.width / 2, 12 + this.font.lineHeight, ARGB.white(1.0F));
6264
// TODO: isActive | parent button color
6365
for (Gidget gidget : this.gidgets) {
64-
if (gidget instanceof SimpleButton button) {
65-
button.render(guiGraphics, mouseX, mouseY);
66-
}
66+
gidget.render(guiGraphics, mouseX, mouseY);
6767
}
6868
}
6969

@@ -84,10 +84,8 @@ public void onClose() {
8484
}
8585

8686
private void buttonClicked(SimpleButton button) {
87-
if (button instanceof SimpleButton.DataHolder<?> holder) {
88-
OptiFineSkyLayer skyLayer = (OptiFineSkyLayer) holder.get(SKYLAYER_LOCATION);
89-
int index = (Integer) holder.get(INDEX_LOCATION);
90-
this.minecraft.setScreen(new SkyLayerInfoScreen(this, skyLayer, index));
87+
if (button instanceof SimpleButton.Storage storage) {
88+
this.minecraft.setScreen(new SkyLayerInfoScreen(this, storage.get(SKYLAYER_LOCATION), storage.get(INDEX_LOCATION)));
9189
}
9290
}
9391
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,32 +33,32 @@ public void render(GuiGraphics guiGraphics, int mouseX, int mouseY) {
3333
guiGraphics.drawString(font, this.text, this.x + ((this.width / 2) - (textWidth / 2)), this.y + ((this.height / 2) - (font.lineHeight / 2)), 0xFFFFFFFF);
3434
}
3535

36-
public Component text() {
36+
public Component getText() {
3737
return this.text;
3838
}
3939

4040
public Consumer<SimpleButton> onClick() {
4141
return this.onClick;
4242
}
4343

44-
public static class DataHolder<T> extends SimpleButton {
45-
private final Map<Identifier, T> data;
44+
public static class Storage extends SimpleButton {
45+
private final Map<Identifier, Object> data;
4646

47-
public DataHolder(Component text, int x, int y, Consumer<SimpleButton> onClick) {
47+
public Storage(Component text, int x, int y, Consumer<SimpleButton> onClick) {
4848
super(text, x, y, onClick);
4949
this.data = new HashMap<>();
5050
}
5151

52-
public void put(Identifier location, T data) {
52+
public void put(Identifier location, Object data) {
5353
this.data.put(location, data);
5454
}
5555

5656
public boolean has(Identifier location) {
5757
return this.data.containsKey(location);
5858
}
5959

60-
public T get(Identifier location) {
61-
return this.data.get(location);
60+
public <T> T get(Identifier location) {
61+
return (T) this.data.get(location);
6262
}
6363
}
6464
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package btw.lowercase.optiboxes.screen.widget;
2+
3+
import net.minecraft.client.gui.Font;
4+
import net.minecraft.client.gui.GuiGraphics;
5+
import net.minecraft.network.chat.Component;
6+
import net.minecraft.util.ARGB;
7+
8+
public class Text extends Gidget {
9+
private final Font font;
10+
private final Component text;
11+
private final int color;
12+
private final boolean centered;
13+
private final boolean shadow;
14+
15+
public Text(Font font, Component text, int x, int y, int color, boolean centered, boolean shadow) {
16+
super(x, y, font.width(text.getString()), font.lineHeight);
17+
this.font = font;
18+
this.text = text;
19+
this.color = color;
20+
this.centered = centered;
21+
this.shadow = shadow;
22+
}
23+
24+
@Override
25+
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY) {
26+
int finalX = this.x;
27+
if (this.centered) {
28+
finalX -= this.width / 2;
29+
}
30+
31+
guiGraphics.drawString(this.font, this.text, finalX, this.y, this.color, this.shadow);
32+
}
33+
34+
public Component getText() {
35+
return this.text;
36+
}
37+
38+
public int getColor() {
39+
return this.color;
40+
}
41+
42+
public boolean isCentered() {
43+
return this.centered;
44+
}
45+
46+
public boolean hasShadow() {
47+
return this.shadow;
48+
}
49+
50+
public static class Builder {
51+
private final Font font;
52+
private final Component text;
53+
private final int x;
54+
private final int y;
55+
56+
private int color = ARGB.white(1.0F);
57+
private boolean centered = false;
58+
private boolean shadow = true;
59+
60+
public Builder(Font font, Component text, int x, int y) {
61+
this.font = font;
62+
this.text = text;
63+
this.x = x;
64+
this.y = y;
65+
}
66+
67+
public Builder(Font font, String text, int x, int y) {
68+
this(font, Component.literal(text), x, y);
69+
}
70+
71+
public Builder withColor(int color) {
72+
this.color = color;
73+
return this;
74+
}
75+
76+
public Builder withShadow(boolean shadow) {
77+
this.shadow = shadow;
78+
return this;
79+
}
80+
81+
public Builder centered() {
82+
this.centered = true;
83+
return this;
84+
}
85+
86+
public Text build() {
87+
return new Text(this.font, this.text, this.x, this.y, this.color, this.centered, this.shadow);
88+
}
89+
}
90+
}

0 commit comments

Comments
 (0)