|
| 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())); |
0 commit comments