Add the Imperial Codex and item archive to the opt-in viewer

This commit is contained in:
unimatrixgit 2026-11-28 10:17:28 +01:00
commit 4abc909ed4

View file

@ -36,9 +36,13 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut
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 JOURNAL_LORE_LINES = 5;
private static final Font JOURNAL_LORE = new Font(Font.SANS_SERIF, Font.PLAIN, 12);
private static final int FULL_CARD_LORE_LINES = 5;
private static final Font FULL_CARD_LORE = new Font(Font.SANS_SERIF, Font.PLAIN, 12);
private static final Font CHECKOUT_TERMS = new Font(Font.SANS_SERIF, Font.BOLD, 15);
private static final Font CODEX_CARD_TITLE = new Font(Font.SANS_SERIF, Font.BOLD, 13);
private static final Font ARCHIVE_LORE = new Font(Font.SANS_SERIF, Font.PLAIN, 12);
private static final int ARCHIVE_COLUMN_LINES = 7;
private static final int ARCHIVE_COLUMN_WIDTH = 177;
private static final int PREVIOUS = -1, NEXT = -2, EMPTY = -3;
private static final int CHECKOUT_BACK = 45, CHECKOUT_BUY = 49, CHECKOUT_CONTROLS = 2;
private final Map<UUID, Scene> scenes = new HashMap<>();
@ -203,6 +207,7 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut
private static Page page(Document document, int index) {
if (document.style() == Style.EXCHANGE_CHECKOUT) return checkoutPage(document, index);
if (document.style() == Style.ITEM_ARCHIVE) return archivePage(document, index);
var cards = document.cards();
int capacity = capacity(document.style());
if (cards.size() <= capacity) return new Page(0, document.style(), cards);
@ -216,6 +221,23 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut
return new Page(index, document.style(), List.copyOf(visible));
}
private static Page archivePage(Document document, int index) {
var entries = document.cards().stream().filter(card -> !card.actionable()).toList();
var actions = document.cards().stream().filter(Card::actionable).toList();
var visible = new ArrayList<Card>();
var blank = new Card(EMPTY, "", List.of(), false);
visible.add(entries.get(index)); // The reading pane is drawn separately from the interactive tiles.
visible.add(blank);
visible.addAll(actions);
while (visible.size() < STANDARD_PAGE) visible.add(blank);
if (entries.size() > 1) {
String number = "Page " + (index + 1) + " / " + entries.size();
visible.add(new Card(PREVIOUS, "Previous", List.of(number), index > 0));
visible.add(new Card(NEXT, "Next", List.of(number), index + 1 < entries.size()));
}
return new Page(index, document.style(), List.copyOf(visible));
}
private static Page checkoutPage(Document document, int index) {
var controls = document.cards().stream()
.filter(card -> card.slot() != CHECKOUT_BACK && card.slot() != CHECKOUT_BUY)
@ -246,7 +268,7 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut
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 || (col == 5 && capacity(scene.page.style) == STANDARD_PAGE))) continue;
if (!initial && (row < 3 || row > 5 || col < 4 || col > 6 || (col == 5 && capacity(scene.page.style) == STANDARD_PAGE && scene.page.style != Style.ITEM_ARCHIVE))) continue;
var map = new MapId(FIRST_SCENE_MAP + row * COLS + col);
var image = art.getSubimage(col * 128, row * 128, 128, 128);
var card = cardAt(scene.page, row, col);
@ -317,6 +339,7 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut
private static Card cardAt(Page page, int row, int col) {
if (row < 3 || row > LAST_ROW || col < 4 || col > 6) return null;
if (page.style == Style.ITEM_ARCHIVE && row == 3) 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) :
@ -416,12 +439,13 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut
draw.setColor(palette.accent);
draw.setStroke(new BasicStroke(7));
draw.drawRect(445, 335, 518, 374);
draw.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 38));
draw.setFont(styledHeadingFont(scene.document.style()));
String heading = scene.roleplay != null ? scene.roleplay.heading :
scene.document.style() == Style.AUTO ? "YOUR DECISIONS" : styledTitle(scene.document);
int headlineWidth = draw.getFontMetrics().stringWidth(heading);
draw.drawString(heading, (image.getWidth() - headlineWidth) / 2, 372);
if (scene.roleplay != null) drawRoleplay(draw, scene);
else if (scene.document.style() == Style.ITEM_ARCHIVE) drawArchive(draw, scene, palette);
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);
@ -453,6 +477,7 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut
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, EXCHANGE_CHECKOUT -> new Palette(new Color(42, 28, 18), new Color(91, 62, 36), new Color(245, 208, 139));
case CODEX, ITEM_ARCHIVE -> new Palette(new Color(40, 33, 24), new Color(90, 63, 37), new Color(246, 221, 158));
case JOURNAL -> new Palette(new Color(30, 40, 31), new Color(61, 80, 51), new Color(235, 212, 154));
case HOUSE -> new Palette(new Color(34, 26, 39), new Color(72, 52, 79), new Color(244, 211, 152));
case AUTO -> scene.roleplay == null
@ -464,7 +489,7 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut
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));
graphics.setFont(styledHeadingFont(document.style()));
if (!wrap(graphics, styledTitle(document), 500, 1).complete) return false;
if (document.style() == Style.EXCHANGE_CHECKOUT) {
if (document.description().isBlank() || !hasCheckoutAction(document, CHECKOUT_BACK) ||
@ -473,15 +498,25 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut
var terms = checkoutTerms(graphics, document.description());
if (terms.isEmpty() || terms.size() > 9) return false;
}
if (document.style() == Style.ITEM_ARCHIVE) {
long actionCount = document.cards().stream().filter(Card::actionable).count();
if (actionCount < 1 || actionCount > 2 || actionCount == document.cards().size()) 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 (document.style() == Style.JOURNAL) {
if (!wrap(graphics, card.title(), 114, 2).complete) return false;
graphics.setFont(JOURNAL_LORE);
if (!journalLore(graphics, card).complete) return false;
if (document.style() == Style.ITEM_ARCHIVE && !card.actionable()) {
if (!wrap(graphics, card.title(), 368, 1).complete) return false;
graphics.setFont(ARCHIVE_LORE);
if (!archiveLore(graphics, card).complete) return false;
continue;
}
if (usesFullCardLore(document.style())) {
if (!fitsFullCardTitle(graphics, document.style(), card)) return false;
graphics.setFont(FULL_CARD_LORE);
if (!fullCardLore(graphics, card).complete) return false;
continue;
}
if (!wrap(graphics, card.title(), 114, seal ? 2 : 3).complete) return false;
@ -494,6 +529,43 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut
}
}
private static Font styledHeadingFont(Style style) {
return new Font(Font.SANS_SERIF, Font.BOLD, style == Style.ITEM_ARCHIVE ? 30 : 38);
}
private static boolean usesFullCardLore(Style style) {
return style == Style.JOURNAL || style == Style.CODEX || style == Style.ITEM_ARCHIVE;
}
private static boolean fitsFullCardTitle(java.awt.Graphics2D draw, Style style, Card card) {
boolean codex = style == Style.CODEX;
draw.setFont(codex ? CODEX_CARD_TITLE : CARD_TITLE);
return wrap(draw, card.title(), 114, codex ? 3 : 2).complete();
}
private static Wrapped archiveLore(java.awt.Graphics2D draw, Card card) {
var entries = card.lore().stream().filter(line -> !line.matches("─+")).toList();
return wrapLore(draw, entries, ARCHIVE_COLUMN_WIDTH, 2 * ARCHIVE_COLUMN_LINES);
}
private void drawArchive(java.awt.Graphics2D draw, Scene scene, Palette palette) {
var card = scene.page.cards.getFirst();
draw.setColor(palette.tile);
draw.fillRect(512, 386, 384, 123);
draw.setColor(Color.WHITE);
draw.setFont(CARD_TITLE);
draw.drawString(card.title(), 520, 404);
draw.setColor(palette.accent);
draw.drawLine(520, 407, 888, 407);
draw.setFont(ARCHIVE_LORE);
var lines = archiveLore(draw, card).lines();
for (int i = 0; i < lines.size(); i++) {
int x = 520 + i / ARCHIVE_COLUMN_LINES * 184;
int y = 416 + i % ARCHIVE_COLUMN_LINES * draw.getFontMetrics().getHeight();
draw.drawString(lines.get(i), x, y);
}
}
private static String styledTitle(Document document) {
return document.style() == Style.EXCHANGE_CHECKOUT ? "Exchange checkout" : document.title();
}
@ -512,10 +584,14 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut
return lines;
}
private static Wrapped journalLore(java.awt.Graphics2D draw, Card card) {
private static Wrapped fullCardLore(java.awt.Graphics2D draw, Card card) {
return wrapLore(draw, card.lore(), 114, FULL_CARD_LORE_LINES);
}
private static Wrapped wrapLore(java.awt.Graphics2D draw, List<String> entries, int width, int limit) {
var lines = new ArrayList<String>();
for (String entry : card.lore()) {
var wrapped = wrap(draw, entry, 114, JOURNAL_LORE_LINES - lines.size());
for (String entry : entries) {
var wrapped = wrap(draw, entry, width, limit - lines.size());
lines.addAll(wrapped.lines());
if (!wrapped.complete()) return new Wrapped(lines, false);
}
@ -553,7 +629,7 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut
draw.setColor(palette.background.darker());
draw.fillRect(644, 389, 120, 232);
switch (document.style()) {
case JOURNAL -> {
case JOURNAL, CODEX -> {
drawResource(draw, "/mcgui/dunerealms-season-logo-v2.png", 650, 449, 108, 96);
draw.setColor(palette.accent);
draw.drawLine(650, 446, 758, 446);
@ -590,15 +666,16 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut
if (style == Style.AUTO) return false;
String art = nativeArt(card.material());
draw.setColor(palette.accent);
if (style == Style.JOURNAL) {
if (usesFullCardLore(style)) {
draw.drawLine(x + 7, y + 48, x + 121, y + 48);
draw.setColor(Color.WHITE);
draw.setFont(CARD_TITLE);
writeWrapped(draw, card.title(), x + 7, y + 21, 114, 2);
boolean codex = style == Style.CODEX;
draw.setFont(codex ? CODEX_CARD_TITLE : CARD_TITLE);
writeWrapped(draw, card.title(), x + 7, y + (codex ? 15 : 21), 114, codex ? 3 : 2);
draw.setColor(palette.accent);
draw.setFont(JOURNAL_LORE);
draw.setFont(FULL_CARD_LORE);
int lineY = y + 64;
for (String line : journalLore(draw, card).lines()) {
for (String line : fullCardLore(draw, card).lines()) {
draw.drawString(line, x + 7, lineY);
lineY += draw.getFontMetrics().getHeight();
}