Skip to content

Commit e7ddd08

Browse files
committed
Rework debug command into a screen
1 parent 5f28bfa commit e7ddd08

File tree

5 files changed

+170
-29
lines changed

5 files changed

+170
-29
lines changed

src/main/java/btw/lowercase/optiboxes/command/OptiboxesCommand.java

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
package btw.lowercase.optiboxes.command;
22

33
import btw.lowercase.optiboxes.OptiBoxesClient;
4-
import btw.lowercase.optiboxes.skybox.OptiFineSkyLayer;
5-
import btw.lowercase.optiboxes.skybox.OptiFineSkybox;
64
import btw.lowercase.optiboxes.skybox.SkyboxManager;
5+
import btw.lowercase.optiboxes.screen.OptiboxesDebugScreen;
76
import com.mojang.brigadier.Command;
87
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
98
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
109
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
1110
import net.minecraft.client.Minecraft;
12-
import net.minecraft.network.chat.Component;
13-
14-
import java.util.List;
1511

1612
public class OptiboxesCommand extends LiteralArgumentBuilder<FabricClientCommandSource> {
1713
public OptiboxesCommand() {
@@ -24,30 +20,7 @@ public OptiboxesCommand() {
2420
});
2521

2622
then(ClientCommandManager.literal("debug").executes((context) -> {
27-
final List<OptiFineSkybox> activeSkyboxes = SkyboxManager.INSTANCE.getActiveSkyboxes();
28-
for (OptiFineSkybox skybox : activeSkyboxes) {
29-
context.getSource().sendFeedback(Component.literal("Skybox World: " + skybox.getWorldResourceKey()));
30-
context.getSource().sendFeedback(Component.literal("Skybox Active: " + skybox.isActive()));
31-
context.getSource().sendFeedback(Component.literal("Layers:"));
32-
int index = 0;
33-
for (OptiFineSkyLayer skyLayer : skybox.getLayers()) {
34-
context.getSource().sendFeedback(Component.literal(" #" + index + " (" + skyLayer.source() + ")"));
35-
context.getSource().sendFeedback(Component.literal(" Rotate: " + skyLayer.rotate()));
36-
context.getSource().sendFeedback(Component.literal(" Axis: " + skyLayer.axis()));
37-
context.getSource().sendFeedback(Component.literal(" Include Biome: " + skyLayer.biomeInclusion()));
38-
context.getSource().sendFeedback(Component.literal(" Fade: " + skyLayer.fade()));
39-
context.getSource().sendFeedback(Component.literal(" Blend: " + skyLayer.blend()));
40-
context.getSource().sendFeedback(Component.literal(" Speed: " + skyLayer.speed()));
41-
context.getSource().sendFeedback(Component.literal(" Transition: " + skyLayer.transition()));
42-
// TODO: Biomes, Height, Weathers
43-
index++;
44-
}
45-
}
46-
47-
if (activeSkyboxes.isEmpty()) {
48-
context.getSource().sendFeedback(Component.literal("No skies enabled..."));
49-
}
50-
23+
minecraft.schedule(() -> minecraft.setScreen(new OptiboxesDebugScreen(minecraft.screen, SkyboxManager.INSTANCE.getActiveSkyboxes())));
5124
return Command.SINGLE_SUCCESS;
5225
}));
5326
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package btw.lowercase.optiboxes.screen;
2+
3+
import net.minecraft.client.Minecraft;
4+
import net.minecraft.client.gui.Font;
5+
import net.minecraft.client.gui.GuiGraphics;
6+
import net.minecraft.network.chat.Component;
7+
import net.minecraft.resources.Identifier;
8+
9+
import java.util.HashMap;
10+
import java.util.Map;
11+
import java.util.function.Consumer;
12+
13+
public class Button {
14+
public static final int WIDTH = 200;
15+
public static final int HEIGHT = 20;
16+
17+
private final Component text;
18+
private final int x;
19+
private final int y;
20+
private final Consumer<Button> onClick;
21+
22+
public Button(Component text, int x, int y, Consumer<Button> onClick) {
23+
this.text = text;
24+
this.x = x;
25+
this.y = y;
26+
this.onClick = onClick;
27+
}
28+
29+
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY) {
30+
boolean hovered = this.isInside(mouseX, mouseY);
31+
guiGraphics.fill(this.x, this.y, this.x + WIDTH, this.y + HEIGHT, hovered ? 0xFF00FF00 : 0xFF00FFFF);
32+
33+
Font font = Minecraft.getInstance().font;
34+
int textWidth = font.width(this.text.getString());
35+
guiGraphics.drawString(font, this.text, this.x + ((WIDTH / 2) - (textWidth / 2)), this.y + ((HEIGHT / 2) - (font.lineHeight / 2)), 0xFFFFFFFF);
36+
}
37+
38+
public boolean isInside(double x, double y) {
39+
return (x >= this.x && x <= this.x + WIDTH) && (y >= this.y && y <= this.y + HEIGHT);
40+
}
41+
42+
public Component text() {
43+
return this.text;
44+
}
45+
46+
public int x() {
47+
return this.x;
48+
}
49+
50+
public int y() {
51+
return this.y;
52+
}
53+
54+
public Consumer<Button> onClick() {
55+
return this.onClick;
56+
}
57+
58+
public static class DataHolder<T> extends Button {
59+
private final Map<Identifier, T> data;
60+
61+
public DataHolder(Component text, int x, int y, Consumer<Button> onClick) {
62+
super(text, x, y, onClick);
63+
this.data = new HashMap<>();
64+
}
65+
66+
public void put(Identifier location, T data) {
67+
this.data.put(location, data);
68+
}
69+
70+
public T get(Identifier location) {
71+
return this.data.get(location);
72+
}
73+
}
74+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package btw.lowercase.optiboxes.screen;
2+
3+
import btw.lowercase.optiboxes.OptiBoxesClient;
4+
import btw.lowercase.optiboxes.skybox.OptiFineSkybox;
5+
import net.minecraft.client.gui.GuiGraphics;
6+
import net.minecraft.client.gui.screens.Screen;
7+
import net.minecraft.client.input.MouseButtonEvent;
8+
import net.minecraft.network.chat.Component;
9+
import net.minecraft.resources.Identifier;
10+
import net.minecraft.util.ARGB;
11+
import org.jetbrains.annotations.NotNull;
12+
13+
import java.util.ArrayList;
14+
import java.util.List;
15+
16+
public class OptiboxesDebugScreen extends Screen {
17+
private final Screen parent;
18+
private final List<OptiFineSkybox> skyboxes;
19+
private final List<Button> buttons;
20+
21+
private static final Identifier SKYBOX_LOCATION = OptiBoxesClient.locationOrNull("skybox");
22+
23+
public OptiboxesDebugScreen(Screen parent, List<OptiFineSkybox> skyboxes) {
24+
super(Component.empty());
25+
this.parent = parent;
26+
this.skyboxes = skyboxes;
27+
this.buttons = new ArrayList<>();
28+
}
29+
30+
@Override
31+
protected void init() {
32+
int index = 0;
33+
this.buttons.clear();
34+
for (OptiFineSkybox skybox : this.skyboxes) {
35+
Button.DataHolder<OptiFineSkybox> button = new Button.DataHolder<>(Component.literal(skybox.getWorldResourceKey().identifier().toString()), (this.width / 2) - (Button.WIDTH / 2), 30 + ((Button.HEIGHT + 8) * index), this::buttonClicked);
36+
button.put(SKYBOX_LOCATION, skybox);
37+
this.buttons.add(button);
38+
index++;
39+
}
40+
}
41+
42+
@Override
43+
public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) {
44+
super.render(guiGraphics, mouseX, mouseY, delta);
45+
guiGraphics.drawCenteredString(this.font, this.skyboxes.isEmpty() ? "No skies enabled..." : this.skyboxes.size() + " Total Active Skyboxes", this.width / 2, 16, ARGB.white(1.0F));
46+
for (Button button : this.buttons) {
47+
button.render(guiGraphics, mouseX, mouseY);
48+
}
49+
}
50+
51+
@Override
52+
public boolean mouseClicked(@NotNull MouseButtonEvent event, boolean isDoubleClick) {
53+
for (Button button : this.buttons) {
54+
if (button.isInside(event.x(), event.y())) {
55+
button.onClick().accept(button);
56+
}
57+
}
58+
59+
return super.mouseClicked(event, isDoubleClick);
60+
}
61+
62+
@Override
63+
public void onClose() {
64+
this.minecraft.setScreen(this.parent);
65+
}
66+
67+
private void buttonClicked(Button button) {
68+
if (button instanceof Button.DataHolder<?> holder) {
69+
OptiFineSkybox skybox = (OptiFineSkybox) holder.get(SKYBOX_LOCATION);
70+
System.out.println("Got skybox " + skybox.getWorldResourceKey());
71+
}
72+
}
73+
}
74+
75+
// context.getSource().sendFeedback(Component.literal(" #" + index + " (" + skyLayer.source() + ")"));
76+
// context.getSource().sendFeedback(Component.literal(" Rotate: " + skyLayer.rotate()));
77+
// context.getSource().sendFeedback(Component.literal(" Axis: " + skyLayer.axis()));
78+
// context.getSource().sendFeedback(Component.literal(" Blend: " + skyLayer.blend()));
79+
// context.getSource().sendFeedback(Component.literal(" Speed: " + skyLayer.speed()));
80+
// context.getSource().sendFeedback(Component.literal(" Transition: " + skyLayer.transition()));
81+
// context.getSource().sendFeedback(Component.literal(" Fade: " + skyLayer.fade()));
82+
// context.getSource().sendFeedback(Component.literal(" Loop: " + skyLayer.loop()));
83+
// context.getSource().sendFeedback(Component.literal(" Include Biome: " + skyLayer.biomeInclusion()));
84+
// context.getSource().sendFeedback(Component.literal(" Biomes: " + skyLayer.biomes()));
85+
// context.getSource().sendFeedback(Component.literal(" Heights: " + skyLayer.heights()));
86+
// context.getSource().sendFeedback(Component.literal(" Weather Conditions: " + skyLayer.weatherConditions()));
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package btw.lowercase.optiboxes.screen;
2+
3+
public class SkyLayerInfoScreen {
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package btw.lowercase.optiboxes.screen;
2+
3+
public class SkyboxInfoScreen {
4+
}

0 commit comments

Comments
 (0)