package net.fretux.ascend.client.screen; import com.mojang.blaze3d.systems.RenderSystem; import net.fretux.ascend.compat.AscendMMCompat; import net.fretux.ascend.network.PacketHandler; import net.fretux.ascend.network.ServerboundShrineChoicePacket; import net.fretux.ascend.player.PlayerStatsProvider; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.Component; public class ShrineScreen extends Screen { private static final int WIDTH = 360; private static final int HEIGHT = 220; private static final int PADDING = 12; private static final int BACKGROUND = 0xFF121316; private static final int PANEL = 0xFF1C1E22; private static final int CARD = 0xFF25272D; private static final int BORDER = 0xFF45484F; private static final int PRIMARY_TEXT = 0xFFE4E4E4; private static final int SECONDARY_TEXT = 0xFF999DA5; private static final int ACCENT = 0xFFAAB6C2; private static final int PROGRESS = 0xFFD1A744; private float uiScale = 1.0F; private int uiLeft; private int uiTop; private int dialogueStage = 0; // 0 = intro, 1 = offer, 2 = confirm private int playerKnowledge = 0; private final boolean essenceMode; public ShrineScreen(boolean essenceMode) { super(essenceMode ? Component.literal("Remembrance Essence") : Component.literal("Shrine of Remembrance")); this.essenceMode = essenceMode; } public ShrineScreen() { this(false); } @Override protected void init() { super.init(); uiScale = Math.min(1.0F, Math.min((width - 12.0F) / WIDTH, (height - 12.0F) / HEIGHT)); uiScale = Math.max(0.25F, uiScale); uiLeft = Math.round((width - WIDTH * uiScale) / 2.0F); uiTop = Math.round((height - HEIGHT * uiScale) / 2.0F); Minecraft mc = Minecraft.getInstance(); if (mc.player != null) { mc.player.getCapability(PlayerStatsProvider.PLAYER_STATS).ifPresent(stats -> { playerKnowledge = stats.getKnowledge(); }); } updateButtons(); } private void updateButtons() { clearWidgets(); if (essenceMode) { addChoiceButton("FORGET", 84, () -> choose("forget")); addChoiceButton("UNDERSTAND", 109, () -> choose("understand")); addChoiceButton("REST", 134, () -> choose("rest")); addChoiceButton("LEAVE", 159, this::closeScreen); return; } switch (dialogueStage) { case 0 -> { addChoiceButton("I WISH TO ENGAGE IN A DEAL.", 104, () -> { dialogueStage = 1; updateButtons(); }); addChoiceButton("LEAVE.", 129, this::closeScreen); } case 1 -> { addChoiceButton("I AGREE.", 104, () -> { dialogueStage = 2; updateButtons(); }); addChoiceButton("LEAVE.", 129, this::closeScreen); } case 2 -> { int y = 96; addChoiceButton("I WISH TO FORGET.", y, () -> choose("forget")); y += 25; if (AscendMMCompat.isMindMotionPresent()) { addChoiceButton("I WISH TO UNDERSTAND.", y, () -> choose("understand")); y += 25; addChoiceButton("I WISH TO REST.", y, () -> choose("rest")); y += 25; } addChoiceButton("LEAVE.", y, this::closeScreen); } } } private void addChoiceButton(String label, int y, Runnable action) { addRenderableWidget(Button.builder(Component.literal(label), button -> action.run()) .bounds(20, y, WIDTH - 40, 20) .build()); } private void choose(String choice) { PacketHandler.INSTANCE.sendToServer(new ServerboundShrineChoicePacket(choice)); closeScreen(); } private void closeScreen() { Minecraft.getInstance().setScreen(null); } @Override public void render(GuiGraphics gui, int mouseX, int mouseY, float partialTicks) { renderBackground(gui); int uiMouseX = (int) toUiX(mouseX); int uiMouseY = (int) toUiY(mouseY); gui.pose().pushPose(); gui.pose().translate(uiLeft, uiTop, 0.0F); gui.pose().scale(uiScale, uiScale, 1.0F); drawWindow(gui); gui.drawCenteredString(font, title, WIDTH / 2, 6, PRIMARY_TEXT); gui.drawCenteredString(font, Component.translatable("ascend.stats.knowledge", playerKnowledge), WIDTH / 2, 36, PROGRESS); drawDialogue(gui); super.render(gui, uiMouseX, uiMouseY, partialTicks); gui.pose().popPose(); } private void drawWindow(GuiGraphics gui) { RenderSystem.enableBlend(); gui.fill(-6, -6, WIDTH + 6, HEIGHT + 6, 0xCC090A0C); gui.fill(-3, -3, WIDTH + 3, HEIGHT + 3, BORDER); gui.fill(0, 0, WIDTH, HEIGHT, BACKGROUND); gui.fill(0, 0, WIDTH, 24, PANEL); gui.fill(0, 24, WIDTH, 25, BORDER); gui.fill(PADDING, 30, WIDTH - PADDING, 54, CARD); gui.fill(PADDING, 54, WIDTH - PADDING, 55, BORDER); RenderSystem.disableBlend(); } private void drawDialogue(GuiGraphics gui) { if (essenceMode) { drawCentered(gui, "CHOOSE WHAT TO CHANGE.", 68, ACCENT); return; } switch (dialogueStage) { case 0 -> { drawCentered(gui, "SPEAK, LITTLE ONE.", 66, ACCENT); drawCentered(gui, "WHAT IS IT YOU SEEK TO UNMAKE?", 82, SECONDARY_TEXT); } case 1 -> { drawCentered(gui, "THE TERMS ARE AS FOLLOWS:", 64, ACCENT); drawCentered(gui, "I WILL CONSUME YOUR KNOWLEDGE.", 78, SECONDARY_TEXT); drawCentered(gui, "YOU WILL REAP A BENEFIT.", 92, SECONDARY_TEXT); } case 2 -> drawCentered(gui, "SPEAK YOUR DESIRE, FOOLISH ONE.", 68, ACCENT); } } private void drawCentered(GuiGraphics gui, String text, int y, int color) { gui.drawCenteredString(font, text, WIDTH / 2, y, color); } private double toUiX(double mouseX) { return (mouseX - uiLeft) / uiScale; } private double toUiY(double mouseY) { return (mouseY - uiTop) / uiScale; } @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { return super.mouseClicked(toUiX(mouseX), toUiY(mouseY), button); } @Override public boolean mouseReleased(double mouseX, double mouseY, int button) { return super.mouseReleased(toUiX(mouseX), toUiY(mouseY), button); } @Override public boolean mouseDragged(double mouseX, double mouseY, int button, double dragX, double dragY) { return super.mouseDragged(toUiX(mouseX), toUiY(mouseY), button, dragX / uiScale, dragY / uiScale); } @Override public boolean isPauseScreen() { return false; } }