diff --git a/DuneFullscreenPaper/README.md b/DuneFullscreenPaper/README.md index 7b41afad..6cd90628 100644 --- a/DuneFullscreenPaper/README.md +++ b/DuneFullscreenPaper/README.md @@ -2,6 +2,6 @@ DuneGit builds this provider as a separate development artifact. It requires Paper 26.2 build 135 and Java 25. Build `DuneRealmsGUI` first, then run `gradle -p DuneFullscreenPaper test jar` with Java 25 and Gradle 9.2.1. -The Java Decisions dashboard uses this provider only for UUIDs listed under `development.fullscreen-decisions-viewers` in the DunerealmsGUI config. Quest dashboards, turn-ins and next-mission screens use `development.fullscreen-quest-viewers`. Keep both allowlists empty on live servers. Existing menus handle unavailable providers, invalid card slots, documents outside the 54-card inventory limit, and quest text that exceeds the native layout. +The Java Decisions dashboard uses this provider only for UUIDs listed under `development.fullscreen-decisions-viewers` in the DunerealmsGUI config. Quest dashboards, turn-ins and next-mission screens use `development.fullscreen-quest-viewers`. Branded organisation modules use `development.fullscreen-organisation-viewers`, Exchange browse, listing and kit shelves use `development.fullscreen-exchange-viewers`, and House or Mentat screens use `development.fullscreen-house-viewers`. Keep these allowlists empty on live servers. Existing menus handle unavailable providers, invalid card slots, documents outside the 54-card inventory limit, and quest text that exceeds the native layout. -Larger documents retain their server-provided slots and show four entries per page. The mounted view can still expose vanilla overlays such as the experience bar, crosshair, chat and system notifications. +Larger documents retain their server-provided slots and show four entries per page in Decisions, quests and organisation modules, and six in Exchange and House views. The mounted view can still expose vanilla overlays such as the experience bar, crosshair, chat and system notifications. diff --git a/DuneFullscreenPaper/src/main/java/com/dunerealms/fullscreen/PaperDecisionsScene.java b/DuneFullscreenPaper/src/main/java/com/dunerealms/fullscreen/PaperDecisionsScene.java index 1c2a2606..6336f431 100644 --- a/DuneFullscreenPaper/src/main/java/com/dunerealms/fullscreen/PaperDecisionsScene.java +++ b/DuneFullscreenPaper/src/main/java/com/dunerealms/fullscreen/PaperDecisionsScene.java @@ -32,7 +32,10 @@ import org.bukkit.plugin.java.JavaPlugin; final class PaperDecisionsScene implements DecisionsViewTransport, Listener, AutoCloseable { private static final String INPUT = "dune_fullscreen_decisions"; private static final int COLS = 11, ROWS = 9; - private static final int CARDS_PER_PAGE = 4; + private static final int STANDARD_PAGE = 4, THREE_COLUMN_PAGE = 6; + private static final int LAST_ROW = 5, LAST_CARD_HEIGHT = 64; + private static final Font CARD_TITLE = new Font(Font.SANS_SERIF, Font.BOLD, 17); + private static final Font CARD_LORE = new Font(Font.SANS_SERIF, Font.PLAIN, 13); private static final int PREVIOUS = -1, NEXT = -2, EMPTY = -3; private final Map scenes = new HashMap<>(); private final JavaPlugin plugin; @@ -44,7 +47,7 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut } private record Tile(MapId map, BufferedImage normal, BufferedImage focused) {} - private record Page(int index, List cards) {} + private record Page(int index, Style style, List cards) {} private record Roleplay(String heading, String contact, Card portrait, Card world, Card summary) {} private static final class Scene { @@ -90,6 +93,7 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut Roleplay roleplay = roleplay(document); Document visibleDocument = presentable(document, roleplay); if (roleplay != null && !fitsRoleplay(visibleDocument, roleplay)) return false; + if (visibleDocument.style() != Style.AUTO && !fitsStyled(visibleDocument)) return false; Scene scene = new Scene(viewer, visibleDocument, roleplay, select, dismiss); var origin = scene.original; var viewpoint = new Location(origin.getWorld(), origin.getBlockX() + .5, origin.getBlockY() + 6, @@ -158,7 +162,7 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut focus = null; } if (input instanceof ServerboundMovePlayerPacket move && move.hasRotation()) { - Integer target = target(page.cards, move.getYRot(0), move.getXRot(0)); + Integer target = target(page, move.getYRot(0), move.getXRot(0)); if (!Objects.equals(target, focus)) { focus = target; Bukkit.getScheduler().runTask(plugin, () -> { if (scene.page == page) focus(scene, target); }); @@ -195,29 +199,29 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut private static Page page(Document document, int index) { var cards = document.cards(); - if (cards.size() <= 6) return new Page(0, cards); - int start = index * CARDS_PER_PAGE; - int end = Math.min(start + CARDS_PER_PAGE, cards.size()); + int capacity = capacity(document.style()); + if (cards.size() <= capacity) return new Page(0, document.style(), cards); + int start = index * capacity; + int end = Math.min(start + capacity, cards.size()); var visible = new ArrayList<>(cards.subList(start, end)); - while (visible.size() < CARDS_PER_PAGE) visible.add(new Card(EMPTY, "", List.of(), false)); - String pageNumber = "Page " + (index + 1) + " / " + ((cards.size() + CARDS_PER_PAGE - 1) / CARDS_PER_PAGE); + while (visible.size() < capacity) visible.add(new Card(EMPTY, "", List.of(), false)); + String pageNumber = "Page " + (index + 1) + " / " + ((cards.size() + capacity - 1) / capacity); visible.add(new Card(PREVIOUS, "Previous", List.of(pageNumber), index > 0)); visible.add(new Card(NEXT, "Next", List.of(pageNumber), end < cards.size())); - return new Page(index, List.copyOf(visible)); + return new Page(index, document.style(), List.copyOf(visible)); } private void paint(Scene scene, boolean initial) { - var cards = scene.page.cards; - BufferedImage art = artwork(scene, cards); + BufferedImage art = artwork(scene); scene.buttons.clear(); scene.focus = null; for (int row = 0; row < ROWS; row++) { for (int col = 0; col < COLS; col++) { - if (!initial && (row < 3 || row > 5 || (col != 4 && col != 6))) continue; + if (!initial && (row < 3 || row > 5 || col < 4 || col > 6 || (col == 5 && capacity(scene.page.style) == STANDARD_PAGE))) continue; var map = new MapId(FIRST_SCENE_MAP + row * COLS + col); var image = art.getSubimage(col * 128, row * 128, 128, 128); - var card = cardAt(cards, row, col); - var tile = new Tile(map, image, card == null || !card.actionable() ? image : focused(image)); + var card = cardAt(scene.page, row, col); + var tile = new Tile(map, image, card == null || !card.actionable() ? image : focused(image, row == LAST_ROW ? LAST_CARD_HEIGHT : 122)); if (card != null && card.actionable()) scene.buttons.put(card.slot(), tile); pixels(scene, tile, false); } @@ -278,18 +282,25 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut new ClientboundMapItemDataPacket(tile.map, (byte) 0, true, List.of(), patch)); } - private static Card cardAt(List cards, int row, int col) { - if (row < 3 || row > 5 || (col != 4 && col != 6)) return null; - int index = (row - 3) * 2 + (col == 4 ? 0 : 1); - return index < cards.size() ? cards.get(index) : null; + private static int capacity(Style style) { + return style == Style.EXCHANGE || style == Style.HOUSE ? THREE_COLUMN_PAGE : STANDARD_PAGE; } - private static Integer target(List cards, float yaw, float pitch) { + private static Card cardAt(Page page, int row, int col) { + if (row < 3 || row > LAST_ROW || col < 4 || col > 6) return null; + if (col == 5 && (capacity(page.style) == STANDARD_PAGE || row == LAST_ROW)) return null; + int cap = capacity(page.style); + int index = row == LAST_ROW ? cap + (col == 4 ? 0 : 1) : + (row - 3) * (cap / 2) + (cap == THREE_COLUMN_PAGE ? col - 4 : (col - 4) / 2); + return index < page.cards.size() ? page.cards.get(index) : null; + } + + private static Integer target(Page page, float yaw, float pitch) { if (!Float.isFinite(yaw) || !Float.isFinite(pitch) || Math.abs(yaw) > 45 || Math.abs(pitch) > 40) return null; double x = -Math.tan(Math.toRadians(yaw)) * 2.46; double y = Math.tan(Math.toRadians(pitch)) * 2.46; - if (Math.abs(x) < .5 || Math.abs(x) > 1.5) return null; - Card card = cardAt(cards, 4 + (int) Math.round(y), x > 0 ? 4 : 6); + if (Math.abs(x) > 1.5 || y > 1.02) return null; + Card card = cardAt(page, 4 + (int) Math.round(y), 5 - (int) Math.round(x)); return card != null && card.actionable() ? card.slot() : null; } @@ -366,36 +377,39 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut } } - private BufferedImage artwork(Scene scene, List cards) { + private BufferedImage artwork(Scene scene) { var image = new BufferedImage(COLS * 128, ROWS * 128, BufferedImage.TYPE_INT_RGB); var draw = image.createGraphics(); try { - draw.setColor(scene.roleplay == null ? new Color(25, 40, 46) : new Color(9, 33, 24)); + Palette palette = palette(scene); + draw.setColor(palette.background); draw.fillRect(0, 0, image.getWidth(), image.getHeight()); - draw.setColor(new Color(237, 199, 105)); + draw.setColor(palette.accent); draw.setStroke(new BasicStroke(7)); - draw.drawRect(445, 335, 518, 455); + draw.drawRect(445, 335, 518, 374); draw.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 38)); - String heading = scene.roleplay == null ? "YOUR DECISIONS" : scene.roleplay.heading; + String heading = scene.roleplay != null ? scene.roleplay.heading : + scene.document.style() == Style.AUTO ? "YOUR DECISIONS" : scene.document.title(); int headlineWidth = draw.getFontMetrics().stringWidth(heading); draw.drawString(heading, (image.getWidth() - headlineWidth) / 2, 372); if (scene.roleplay != null) drawRoleplay(draw, scene); - for (int index = 0; index < cards.size(); index++) { - Card card = cards.get(index); - if (card.slot() == EMPTY) continue; - int x = (index % 2 == 0 ? 4 : 6) * 128; - int y = (3 + index / 2) * 128; - draw.setColor(card.actionable() - ? scene.roleplay == null ? new Color(52, 93, 107) : new Color(38, 80, 61) - : new Color(55, 63, 66)); - draw.fillRect(x, y + 3, 128, 122); + else if (scene.document.style() != Style.AUTO) drawStyledIdentity(draw, scene, palette); + for (int row = 3; row <= LAST_ROW; row++) for (int col = 4; col <= 6; col++) { + Card card = cardAt(scene.page, row, col); + if (card == null || card.slot() == EMPTY) continue; + int x = col * 128; + int y = row * 128; + draw.setColor(card.actionable() ? palette.tile : new Color(55, 63, 66)); + boolean bottom = row == LAST_ROW; + draw.fillRect(x, y + 3, 128, bottom ? LAST_CARD_HEIGHT : 122); + if (card.slot() >= 0 && drawStyledCard(draw, scene.document.style(), card, palette, x, y)) continue; draw.setColor(Color.WHITE); - draw.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 14)); - writeWrapped(draw, card.title(), x + 7, y + 25, 114, 3); + draw.setFont(CARD_TITLE); + writeWrapped(draw, card.title(), x + 7, y + 24, 114, bottom ? 2 : 3); String lore = displayLore(scene.roleplay, card); if (!lore.isBlank()) { - draw.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); - writeWrapped(draw, lore, x + 7, y + (card.slot() < 0 ? 45 : 76), 114, 3); + draw.setFont(CARD_LORE); + writeWrapped(draw, lore, x + 7, y + (card.slot() < 0 ? 45 : bottom ? 64 : 78), 114, bottom ? 2 : 3); } } } finally { @@ -404,6 +418,147 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut return image; } + private record Palette(Color background, Color tile, Color accent) {} + + private static Palette palette(Scene scene) { + return switch (scene.document.style()) { + case ORGANISATION -> new Palette(new Color(16, 31, 37), new Color(29, 75, 79), new Color(142, 228, 211)); + case EXCHANGE -> new Palette(new Color(42, 28, 18), new Color(91, 62, 36), new Color(245, 208, 139)); + case HOUSE -> new Palette(new Color(34, 26, 39), new Color(72, 52, 79), new Color(244, 211, 152)); + case AUTO -> scene.roleplay == null + ? new Palette(new Color(25, 40, 46), new Color(52, 93, 107), new Color(237, 199, 105)) + : new Palette(new Color(9, 33, 24), new Color(38, 80, 61), new Color(237, 199, 105)); + }; + } + + private static boolean fitsStyled(Document document) { + var graphics = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB).createGraphics(); + try { + graphics.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 38)); + if (!wrap(graphics, document.title(), 500, 1).complete) return false; + graphics.setFont(CARD_TITLE); + if (document.identity() != null && !wrap(graphics, document.identity().mentat(), 112, 2).complete) return false; + for (Card card : document.cards()) { + boolean seal = document.style() == Style.HOUSE && nativeArt(card.material()) != null; + graphics.setFont(CARD_TITLE); + if (!wrap(graphics, card.title(), 114, seal ? 2 : 3).complete) return false; + graphics.setFont(CARD_LORE); + if (!wrap(graphics, styledLore(document.style(), card), 114, seal ? 2 : 3).complete) return false; + } + return true; + } finally { + graphics.dispose(); + } + } + + private static String styledLore(Style style, Card card) { + if (card.lore().isEmpty()) return ""; + if (style == Style.HOUSE && card.material().startsWith("house_")) + return card.lore().getFirst().equals("Your current House") ? card.lore().getFirst() : ""; + if (style == Style.EXCHANGE) { + // The listing renderer appends the server price after the stored item lore. + for (int index = card.lore().size() - 1; index >= 0; index--) { + String line = card.lore().get(index); + if (line.endsWith(" DM each") || line.endsWith(" DM")) return line; + } + } + return card.lore().getFirst(); + } + + private void drawStyledIdentity(java.awt.Graphics2D draw, Scene scene, Palette palette) { + var document = scene.document; + var identity = document.identity(); + if (document.style() == Style.EXCHANGE) { + drawResource(draw, "/mcgui/native/exchange.png", 454, 343, 40, 31); + draw.setColor(palette.accent); + for (int row = 3; row <= 4; row++) draw.fillRect(510, row * 128 + 124, 388, 4); + return; + } + if (document.style() == Style.HOUSE) { + drawResource(draw, "/mcgui/dunerealms-season-logo-v2.png", 454, 343, 65, 31); + return; + } + draw.setColor(palette.background.darker()); + draw.fillRect(644, 389, 120, 232); + switch (document.style()) { + case ORGANISATION -> { + if (identity != null) { + BufferedImage mark = organisationLogo(identity.logo()); + if (mark != null) drawImage(draw, mark, 660, 397, 88, 74); + if (identity.portrait() >= 0 && identity.portrait() <= 7) + drawSceneArt(draw, "npc_avatar_" + identity.portrait(), 662, 477, 84, 72); + draw.setColor(palette.accent); + draw.setFont(CARD_LORE); + writeWrapped(draw, identity.mentat().isBlank() ? "" : "Mentat", 649, 567, 110, 1); + draw.setFont(CARD_TITLE); + writeWrapped(draw, identity.mentat(), 649, 589, 110, 2); + } + } + + default -> {} + } + } + + private boolean drawStyledCard(java.awt.Graphics2D draw, Style style, Card card, Palette palette, int x, int y) { + if (style == Style.AUTO) return false; + String art = nativeArt(card.material()); + draw.setColor(palette.accent); + if (style == Style.ORGANISATION) { + draw.fillRect(x, y + 3, 4, 122); + draw.drawLine(x + 7, y + 69, x + 119, y + 69); + } else if (style == Style.EXCHANGE) { + draw.fillRect(x, y + 70, 128, 5); + draw.fillRect(x, y + 120, 128, 5); + } else if (art != null) { + drawResource(draw, art, x + 39, y + 7, 50, 48); + draw.setFont(CARD_TITLE); + writeWrapped(draw, card.title(), x + 7, y + 71, 114, 2); + draw.setFont(CARD_LORE); + writeWrapped(draw, styledLore(style, card), x + 7, y + 104, 114, 2); + return true; + } + draw.setColor(Color.WHITE); + draw.setFont(CARD_TITLE); + writeWrapped(draw, card.title(), x + 7, y + 24, 114, 3); + draw.setColor(palette.accent); + draw.setFont(CARD_LORE); + writeWrapped(draw, styledLore(style, card), x + 7, y + 87, 114, 3); + return true; + } + + private static String nativeArt(String key) { + if (key.matches("mentat_(atreides|corrino|fremen|harkonnen|ordos)")) + return "/mcgui/native/" + key.replace('_', '-') + "-v1.png"; + return switch (key) { + case "house_atreides" -> "/mcgui/native/house-aerdrecht-v1.png"; + case "house_corrino" -> "/mcgui/native/house-korenholt-v1.png"; + case "house_fremen" -> "/mcgui/native/house-vrijduin-v1.png"; + case "house_harkonnen" -> "/mcgui/native/house-harkveen-v1.png"; + case "house_ordos" -> "/mcgui/native/house-oordwijk-v1.png"; + default -> null; + }; + } + + private static BufferedImage organisationLogo(String value) { + if (value.length() > 110000 || value.isBlank()) return null; + try (var input = javax.imageio.ImageIO.createImageInputStream( + new java.io.ByteArrayInputStream(Base64.getDecoder().decode(value)))) { + var readers = javax.imageio.ImageIO.getImageReaders(input); + if (!readers.hasNext()) return null; + var reader = readers.next(); + try { + reader.setInput(input, true, true); + if (!reader.getFormatName().equalsIgnoreCase("png") || + reader.getWidth(0) > 512 || reader.getHeight(0) > 512) return null; + return reader.read(0); + } finally { + reader.dispose(); + } + } catch (IllegalArgumentException | java.io.IOException error) { + return null; + } + } + private static Roleplay roleplay(Document document) { String[] title = document.title().split(" · ", 2); if (title.length != 2) return null; @@ -428,7 +583,7 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut var cards = document.cards().stream() .filter(card -> card.actionable() || card != roleplay.portrait && card != roleplay.world && card != roleplay.summary) .toList(); - return new Document(document.title(), document.description(), cards); + return new Document(document.title(), document.description(), cards, document.style(), document.identity()); } private static String displayLore(Roleplay roleplay, Card card) { @@ -444,21 +599,25 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut try { graphics.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 14)); if (!wrap(graphics, roleplay.contact, 112, 2).complete) return false; - for (Card card : document.cards()) { - graphics.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 14)); - if (!wrap(graphics, card.title(), 114, 3).complete) return false; - graphics.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); - String lore = displayLore(roleplay, card); - if (!wrap(graphics, lore, 114, 3).complete) return false; - } - graphics.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); + if (!fitsCards(graphics, document, roleplay)) return false; + graphics.setFont(CARD_LORE); String summary = roleplay.summary == null ? document.description() : String.join(" ", roleplay.summary.lore()); - return wrap(graphics, summary, 112, 8).complete; + return wrap(graphics, summary, 112, 6).complete; } finally { graphics.dispose(); } } + private static boolean fitsCards(java.awt.Graphics2D graphics, Document document, Roleplay roleplay) { + for (Card card : document.cards()) { + graphics.setFont(CARD_TITLE); + if (!wrap(graphics, card.title(), 114, 3).complete) return false; + graphics.setFont(CARD_LORE); + if (!wrap(graphics, displayLore(roleplay, card), 114, 3).complete) return false; + } + return true; + } + private void drawRoleplay(java.awt.Graphics2D draw, Scene scene) { var role = scene.roleplay; draw.setColor(new Color(23, 56, 40)); @@ -469,25 +628,34 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut draw.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 14)); writeWrapped(draw, role.contact, 648, 498, 112, 2); draw.setColor(Color.WHITE); - draw.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); + draw.setFont(CARD_LORE); String summary = role.summary == null ? scene.document.description() : String.join(" ", role.summary.lore()); if (summary.isBlank() && role.world != null) drawSceneArt(draw, role.world.material(), 650, 518, 108, 78); - else writeWrapped(draw, summary, 648, 532, 112, 8); + else writeWrapped(draw, summary, 648, 532, 112, 6); } private void drawSceneArt(java.awt.Graphics2D draw, String asset, int x, int y, int width, int height) { - try (var stream = DecisionsViewTransport.class.getResourceAsStream("/mcgui-npc-avatars/" + asset + ".png")) { + drawResource(draw, "/mcgui-npc-avatars/" + asset + ".png", x, y, width, height); + } + + private void drawResource(java.awt.Graphics2D draw, String resource, int x, int y, int width, int height) { + if (resource == null) return; + try (var stream = DecisionsViewTransport.class.getResourceAsStream(resource)) { if (stream == null) return; var image = javax.imageio.ImageIO.read(stream); if (image == null) return; - double scale = Math.min((double) width / image.getWidth(), (double) height / image.getHeight()); - int w = (int) Math.round(image.getWidth() * scale), h = (int) Math.round(image.getHeight() * scale); - draw.drawImage(image, x + (width - w) / 2, y + (height - h) / 2, w, h, null); + drawImage(draw, image, x, y, width, height); } catch (java.io.IOException error) { - plugin.getLogger().warning("Could not render quest artwork: " + asset); + plugin.getLogger().warning("Could not render fullscreen artwork: " + resource); } } + private static void drawImage(java.awt.Graphics2D draw, BufferedImage image, int x, int y, int width, int height) { + double scale = Math.min((double) width / image.getWidth(), (double) height / image.getHeight()); + int w = (int) Math.round(image.getWidth() * scale), h = (int) Math.round(image.getHeight() * scale); + draw.drawImage(image, x + (width - w) / 2, y + (height - h) / 2, w, h, null); + } + private record Wrapped(List lines, boolean complete) {} private static void writeWrapped(java.awt.Graphics2D draw, String text, int x, int y, int width, int lines) { @@ -515,14 +683,14 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut return new Wrapped(List.copyOf(result), remaining.isEmpty()); } - private BufferedImage focused(BufferedImage normal) { + private BufferedImage focused(BufferedImage normal, int height) { var image = new BufferedImage(128, 128, BufferedImage.TYPE_INT_RGB); var draw = image.createGraphics(); try { draw.drawImage(normal, 0, 0, null); draw.setColor(new Color(250, 224, 152)); draw.setStroke(new BasicStroke(8)); - draw.drawRect(5, 5, 117, 117); + draw.drawRect(5, 5, 117, height - 5); } finally { draw.dispose(); } diff --git a/DuneRealmsGUI/build.gradle.kts b/DuneRealmsGUI/build.gradle.kts index b9ad8262..d03f8a5f 100644 --- a/DuneRealmsGUI/build.gradle.kts +++ b/DuneRealmsGUI/build.gradle.kts @@ -17,4 +17,15 @@ tasks.processResources { from(rootProject.file("../website/web/assets/dunerealms-season-logo-v2.png")) { into("mcgui") } + from(rootProject.file("../DuneLobby/artwork/exchange.png")) { + into("mcgui/native") + } + from(rootProject.file("../website/web/assets/seals")) { + include("house-aerdrecht-v1.png", "house-harkveen-v1.png", "house-korenholt-v1.png", "house-oordwijk-v1.png", "house-vrijduin-v1.png") + into("mcgui/native") + } + from(rootProject.file("../website/web/assets/gui")) { + include("mentat-atreides-v1.png", "mentat-harkonnen-v1.png", "mentat-corrino-v1.png", "mentat-ordos-v1.png", "mentat-fremen-v1.png") + into("mcgui/native") + } } diff --git a/DuneRealmsGUI/src/main/java/com/dunerealms/gui/DecisionsViewTransport.java b/DuneRealmsGUI/src/main/java/com/dunerealms/gui/DecisionsViewTransport.java index 175a3579..243ba500 100644 --- a/DuneRealmsGUI/src/main/java/com/dunerealms/gui/DecisionsViewTransport.java +++ b/DuneRealmsGUI/src/main/java/com/dunerealms/gui/DecisionsViewTransport.java @@ -19,7 +19,14 @@ public interface DecisionsViewTransport { } } - record Document(String title, String description, List cards) { + enum Style { AUTO, ORGANISATION, EXCHANGE, HOUSE } + record Identity(String logo, String mentat, int portrait) {} + + record Document(String title, String description, List cards, Style style, Identity identity) { + public Document(String title, String description, List cards) { + this(title, description, cards, Style.AUTO, null); + } + public Document { cards = List.copyOf(cards); } diff --git a/DuneRealmsGUI/src/main/java/com/dunerealms/gui/DuneGUI.java b/DuneRealmsGUI/src/main/java/com/dunerealms/gui/DuneGUI.java index 2f6eee9f..b2f467af 100644 --- a/DuneRealmsGUI/src/main/java/com/dunerealms/gui/DuneGUI.java +++ b/DuneRealmsGUI/src/main/java/com/dunerealms/gui/DuneGUI.java @@ -276,12 +276,14 @@ public final class DuneGUI extends JavaPlugin implements Listener,CommandExecuto Screen screen=screen(p,"Choose your House",0xE300+(chosen==null?0:Arrays.asList(IDS).indexOf(chosen)+1)); for(int i=0;ideclareHouse(p,data,id,true));} + Runnable allegiance=()->declareHouse(p,data,id,true); + for(int row=i<3?-1:0;row<=1;row++)for(int col=-1;col<=1;col++){int slot=centre+row*9+col;screen.inventory.setItem(slot,item.clone());screen.actions.put(slot,allegiance);} } button(screen,p,45,"Close","Return to the lobby",Material.ARROW,p::closeInventory); button(screen,p,49,sidebar.enabled(p)?"Hide scoreboard":"Show scoreboard","Toggle your personal briefing",Material.LEVER,()->{toggleSidebar(p);select(p,data,chosen);}); for(int slot:new int[]{48,50})screen.actions.put(slot,screen.actions.get(49)); screen.actions.put(46,screen.actions.get(45)); + if(NativeMenus.show(this,p,"development.fullscreen-house-viewers","Choose your House","",screen.inventory,screen.actions,screen.gate,DecisionsViewTransport.Style.HOUSE,null))return; if(MCGUIMenus.show(p,"Choose your House","",screen.inventory,screen.actions,screen.gate))return; p.openInventory(screen.inventory);expire(screen); } @@ -307,6 +309,7 @@ public final class DuneGUI extends JavaPlugin implements Listener,CommandExecuto button(screen,p,45,"Your House",houseName(data,house),Material.ARROW,()->select(p,data,house)); button(screen,p,49,sidebar.enabled(p)?"Hide scoreboard":"Show scoreboard","Toggle your personal briefing",Material.LEVER,()->{toggleSidebar(p);mentat(p,data);});for(int slot:new int[]{48,50})screen.actions.put(slot,screen.actions.get(49)); for(int slot:new int[]{37,39})screen.actions.put(slot,screen.actions.get(38));for(int slot:new int[]{41,43})screen.actions.put(slot,screen.actions.get(42));screen.actions.put(46,screen.actions.get(45)); + if(NativeMenus.show(this,p,"development.fullscreen-house-viewers","Your Mentat · "+name,"",screen.inventory,screen.actions,screen.gate,DecisionsViewTransport.Style.HOUSE,null))return; if(MCGUIMenus.show(p,"Your Mentat · "+name,"",screen.inventory,screen.actions,screen.gate))return; p.openInventory(screen.inventory);expire(screen); } diff --git a/DuneRealmsGUI/src/main/java/com/dunerealms/gui/ExchangeMenus.java b/DuneRealmsGUI/src/main/java/com/dunerealms/gui/ExchangeMenus.java index 38290e1e..4ac75ebe 100644 --- a/DuneRealmsGUI/src/main/java/com/dunerealms/gui/ExchangeMenus.java +++ b/DuneRealmsGUI/src/main/java/com/dunerealms/gui/ExchangeMenus.java @@ -117,7 +117,7 @@ final class ExchangeMenus implements Listener,AutoCloseable { private static ItemStack icon(Material material,String title,String... lore){var item=new ItemStack(material);var meta=item.getItemMeta();meta.displayName(Component.text(title,NamedTextColor.GOLD));meta.lore(Arrays.stream(lore).map(s->Component.text(s,NamedTextColor.GRAY)).toList());item.setItemMeta(meta);return item;} private Panel panel(Player p,String title){int screen=title.endsWith("Your listings")?1:title.endsWith("Add item")?2:title.endsWith("Purchase details")?3:title.endsWith("Withdraw listing")?4:0;var s=new Panel(p,title,artwork.test(p)&&!BedrockForms.isBedrock(p),screen);if(!s.artwork){var pane=icon(Material.GREEN_STAINED_GLASS_PANE," ");for(int i=0;i<54;i++)s.inventory.setItem(i,pane);}return s;} private void button(Panel s,int slot,Material material,String title,String description,Runnable action){s.inventory.setItem(slot,icon(material,title,description));s.actions.put(slot,action);s.choices.add(new BedrockForms.Choice(title,description,action));} - private void show(Player p,Panel s){if(BedrockForms.isBedrock(p)){s.gate.expire();BedrockForms.show(plugin,p,s.title,s.description,s.choices);}else{if(MCGUIMenus.show(p,s.title,s.description,s.inventory,s.actions,s.gate))return;p.openInventory(s.inventory);Bukkit.getScheduler().runTaskLater(plugin,s.gate::expire,2400L);}} + private void show(Player p,Panel s){if(BedrockForms.isBedrock(p)){s.gate.expire();BedrockForms.show(plugin,p,s.title,s.description,s.choices);}else{if(Set.of("Exchange · Buy","Exchange · Your listings","Exchange · Kits").contains(s.title)&&NativeMenus.show(plugin,p,"development.fullscreen-exchange-viewers",s.title,s.description,s.inventory,s.actions,s.gate,DecisionsViewTransport.Style.EXCHANGE,null))return;if(MCGUIMenus.show(p,s.title,s.description,s.inventory,s.actions,s.gate))return;p.openInventory(s.inventory);Bukkit.getScheduler().runTaskLater(plugin,s.gate::expire,2400L);}} private void request(Player p,JsonObject input,Consumer success,Consumer failure){ UUID id=p.getUniqueId(),world=p.getWorld().getUID();if(pending.containsKey(id)){p.sendMessage("J.A.R.V.I.S. is processing your Exchange action.");return;}UUID token=UUID.randomUUID();pending.put(id,token);p.closeInventory(); Bukkit.getScheduler().runTaskAsynchronously(plugin,()->{JsonObject result=null;String error=null;try{result=bridge.exchange(id,input);}catch(Exception e){error=e.getMessage();}var response=result;String message=error;if(!plugin.isEnabled())return;Bukkit.getScheduler().runTask(plugin,()->{if(!token.equals(pending.get(id)))return;pending.remove(id);if(!p.isOnline()||!world.equals(p.getWorld().getUID()))return;if(response==null){failure.accept(message==null?"The Exchange is temporarily unavailable.":message);return;}if(response.has("rejectedStatus")){if(Set.of("buy","buy_kit").contains(input.get("action").getAsString()))retries.remove(id);failure.accept(response.has("message")?response.get("message").getAsString():"The Exchange rejected this action.");return;}success.accept(response);});}); diff --git a/DuneRealmsGUI/src/main/java/com/dunerealms/gui/NativeMenus.java b/DuneRealmsGUI/src/main/java/com/dunerealms/gui/NativeMenus.java new file mode 100644 index 00000000..c0aed231 --- /dev/null +++ b/DuneRealmsGUI/src/main/java/com/dunerealms/gui/NativeMenus.java @@ -0,0 +1,48 @@ +package com.dunerealms.gui; + +import java.util.HashMap; +import java.util.Map; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.plugin.java.JavaPlugin; + +/** Bridges the existing menu document and its server-side callbacks to an opt-in renderer. */ +final class NativeMenus { + private NativeMenus() {} + + static boolean show(JavaPlugin plugin, Player player, String setting, String title, String description, + Inventory inventory, Map actions, GuiSession gate, + DecisionsViewTransport.Style style, MenuDocument.Branding branding) { + if (!plugin.getConfig().getStringList(setting).contains(player.getUniqueId().toString())) return false; + var transport = Bukkit.getServicesManager().load(DecisionsViewTransport.class); + if (transport == null) return false; + var cards = MCGUIMenus.cards(inventory, actions).stream().map(card -> + new DecisionsViewTransport.Card(card.slot(), card.title(), card.lore(), card.action(), card.material())).toList(); + var identity = branding == null ? null : + new DecisionsViewTransport.Identity(branding.logo(), branding.mentat(), branding.portrait()); + var document = new DecisionsViewTransport.Document(title, description, cards, style, identity); + Map visibleActions = new HashMap<>(); + for (var card : cards) if (card.actionable()) visibleActions.put(card.slot(), actions.get(card.slot())); + var callbacks = Map.copyOf(visibleActions); + player.closeInventory(); + var world = player.getWorld().getUID(); + try { + if (!transport.open(player, document, slot -> { + if (!Bukkit.isPrimaryThread()) return; + if (!player.isOnline() || !world.equals(player.getWorld().getUID())) { + gate.expire(); + return; + } + var action = gate.claimAction(player.getUniqueId(), callbacks.get(slot)); + gate.expire(); + if (action != null) action.run(); + }, gate::expire)) return false; + } catch (RuntimeException | LinkageError failure) { + plugin.getLogger().warning("Development fullscreen view unavailable: " + failure.getClass().getSimpleName()); + return false; + } + gate.markFormVisible(world); + return true; + } +} diff --git a/DuneRealmsGUI/src/main/java/com/dunerealms/gui/OrganisationMenus.java b/DuneRealmsGUI/src/main/java/com/dunerealms/gui/OrganisationMenus.java index 033841da..50393e5b 100644 --- a/DuneRealmsGUI/src/main/java/com/dunerealms/gui/OrganisationMenus.java +++ b/DuneRealmsGUI/src/main/java/com/dunerealms/gui/OrganisationMenus.java @@ -223,7 +223,7 @@ final class OrganisationMenus implements Listener { private Panel panel(Player p,String title,int screen){if(!artwork.test(p)||BedrockForms.isBedrock(p))return panel(p,title,screen==2);var panel=new Panel(p);panel.title=title;panel.artwork=true;panel.inventory=Bukkit.createInventory(panel,54,Component.text(GuiArtwork.background(0xE340+screen),NamedTextColor.WHITE).font(net.kyori.adventure.key.Key.key("dunerealms:house_selector")));return panel;} private void put(Panel panel,int slot,String title,String description,Material material,Runnable action){var item=new ItemStack(panel.artwork?Material.PAPER:material);var meta=item.getItemMeta();meta.displayName(Component.text(title,NamedTextColor.GOLD));meta.lore(Arrays.stream(description.split("\n")).map(line->Component.text(line,NamedTextColor.GRAY)).toList());if(panel.artwork)meta.setItemModel(new NamespacedKey("dunerealms","drgui_transparent"));item.setItemMeta(meta);panel.inventory.setItem(slot,item);panel.actions.put(slot,action);if(panel.artwork&&Set.of(19,22,25,37,40,43).contains(slot))for(int alias:new int[]{slot-1,slot+1}){panel.inventory.setItem(alias,item.clone());panel.actions.put(alias,action);}panel.choices.put(slot,new BedrockForms.Choice(title,description,action));} private void close(Panel panel,Player p){put(panel,53,"Close","Return to the game",Material.BARRIER,p::closeInventory);} - private void show(Player p,Panel panel){brandingRequests.remove(p.getUniqueId());if(BedrockForms.isBedrock(p)){BedrockForms.show(plugin,p,panel.title,panel.branding==null||panel.branding.mentat().isEmpty()?"Current organisation keys":"Mentat · "+panel.branding.mentat(),List.copyOf(panel.choices.values()));return;}if(MCGUIMenus.show(p,panel.title,"Current organisation keys",panel.inventory,panel.actions,panel.gate,panel.branding))return;p.openInventory(panel.inventory);Bukkit.getScheduler().runTaskLater(plugin,panel.gate::expire,2400L);} + private void show(Player p,Panel panel){brandingRequests.remove(p.getUniqueId());if(BedrockForms.isBedrock(p)){BedrockForms.show(plugin,p,panel.title,panel.branding==null||panel.branding.mentat().isEmpty()?"Current organisation keys":"Mentat · "+panel.branding.mentat(),List.copyOf(panel.choices.values()));return;}if(panel.branding!=null&&NativeMenus.show(plugin,p,"development.fullscreen-organisation-viewers",panel.title,"",panel.inventory,panel.actions,panel.gate,DecisionsViewTransport.Style.ORGANISATION,panel.branding))return;if(MCGUIMenus.show(p,panel.title,"Current organisation keys",panel.inventory,panel.actions,panel.gate,panel.branding))return;p.openInventory(panel.inventory);Bukkit.getScheduler().runTaskLater(plugin,panel.gate::expire,2400L);} @EventHandler public void click(InventoryClickEvent e){if(!(e.getView().getTopInventory().getHolder() instanceof Panel panel))return;e.setCancelled(true);if(!(e.getWhoClicked() instanceof Player p)||!panel.owner.equals(p.getUniqueId())||e.getClickedInventory()!=panel.inventory||e.getClick()!=ClickType.LEFT)return;var action=panel.actions.get(e.getRawSlot());if(action!=null&&panel.gate.claim(p.getUniqueId()))Bukkit.getScheduler().runTask(plugin,()->{if(p.isOnline()&&p.getOpenInventory().getTopInventory()==panel.inventory)action.run();});} @EventHandler public void drag(InventoryDragEvent e){if(e.getView().getTopInventory().getHolder() instanceof Panel)e.setCancelled(true);} @EventHandler public void closed(InventoryCloseEvent e){if(e.getInventory().getHolder() instanceof Panel panel)panel.gate.expire();} diff --git a/DuneRealmsGUI/src/main/java/com/dunerealms/gui/QuestMenus.java b/DuneRealmsGUI/src/main/java/com/dunerealms/gui/QuestMenus.java index e141d995..4b956443 100644 --- a/DuneRealmsGUI/src/main/java/com/dunerealms/gui/QuestMenus.java +++ b/DuneRealmsGUI/src/main/java/com/dunerealms/gui/QuestMenus.java @@ -302,37 +302,13 @@ final class QuestMenus implements Listener { screen.title.startsWith("NPC next quest · "); if(!decisions&&!quests)return false; String setting=decisions?"development.fullscreen-decisions-viewers":"development.fullscreen-quest-viewers"; - if(!plugin.getConfig().getStringList(setting).contains(player.getUniqueId().toString()))return false; - var transport=Bukkit.getServicesManager().load(DecisionsViewTransport.class); - if(transport==null)return false; - var cards=MCGUIMenus.cards(screen.inventory,screen.actions).stream() - .map(card->new DecisionsViewTransport.Card(card.slot(),card.title(),card.lore(),card.action(),card.material())) - .toList(); String dialogue=screen.description; for(int index=screen.descriptionNotes.size()-1;index>=0;index--){ String note=screen.descriptionNotes.get(index); if(dialogue.endsWith(note))dialogue=dialogue.substring(0,dialogue.length()-note.length()); } - var document=new DecisionsViewTransport.Document(screen.title,dialogue,cards); - Map visibleActions=new HashMap<>(); - for(var card:cards)if(card.actionable())visibleActions.put(card.slot(),screen.actions.get(card.slot())); - var callbacks=Map.copyOf(visibleActions); - player.closeInventory(); - var world=player.getWorld().getUID(); - try{ - if(!transport.open(player,document,slot->{ - if(!Bukkit.isPrimaryThread())return; - if(!player.isOnline()||!world.equals(player.getWorld().getUID())){screen.gate.expire();return;} - var action=screen.gate.claimAction(player.getUniqueId(),callbacks.get(slot)); - screen.gate.expire(); - if(action!=null)action.run(); - },screen.gate::expire))return false; - }catch(RuntimeException failure){ - plugin.getLogger().warning("Development Decisions view unavailable: "+failure.getClass().getSimpleName()); - return false; - } - screen.gate.markFormVisible(world); - return true; + return NativeMenus.show(plugin,player,setting,screen.title,dialogue,screen.inventory,screen.actions,screen.gate, + DecisionsViewTransport.Style.AUTO,null); } private void decisionWebsite(Player p){decisionWebsite(p,null);} private void decisionWebsite(Player p,String decision){p.closeInventory();String url="https://clans.dunerealms.com/#quests/quests?xp=pol&view=decisions";if(decision!=null&&decision.matches("[A-Z0-9-]{1,32}"))url+="&decision="+decision;p.sendMessage(Component.text("Review POL decisions on the website →",NamedTextColor.GOLD).clickEvent(ClickEvent.openUrl(url)));}