Add opt-in organisation, Exchange and House fullscreen styles

This commit is contained in:
unimatrixgit 2026-11-28 09:29:18 +01:00
commit 5f58251ee3

View file

@ -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<UUID, Scene> 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<Card> cards) {}
private record Page(int index, Style style, List<Card> 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<Card> 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<Card> 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<Card> 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<String> 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();
}