forked from unimatrix/web
Offer native Exchange checkout with the original purchase actions
This commit is contained in:
parent
c7638d5f94
commit
a7448814de
1 changed files with 95 additions and 8 deletions
|
|
@ -36,7 +36,9 @@ 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 Font CHECKOUT_TERMS = new Font(Font.SANS_SERIF, Font.BOLD, 15);
|
||||
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<>();
|
||||
private final JavaPlugin plugin;
|
||||
// This range is private to each connection and reused on reopen to bound the client map cache.
|
||||
|
|
@ -198,6 +200,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);
|
||||
var cards = document.cards();
|
||||
int capacity = capacity(document.style());
|
||||
if (cards.size() <= capacity) return new Page(0, document.style(), cards);
|
||||
|
|
@ -211,6 +214,30 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut
|
|||
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)
|
||||
.sorted(Comparator.comparingInt(card -> switch (card.slot()) {
|
||||
case 30 -> 0;
|
||||
case 32 -> 1;
|
||||
case 31 -> 2;
|
||||
default -> 3;
|
||||
})).toList();
|
||||
int start = index * CHECKOUT_CONTROLS;
|
||||
int end = Math.min(start + CHECKOUT_CONTROLS, controls.size());
|
||||
var visible = new ArrayList<>(controls.subList(start, end));
|
||||
while (visible.size() < CHECKOUT_CONTROLS) visible.add(new Card(EMPTY, "", List.of(), false));
|
||||
for (int slot : new int[]{CHECKOUT_BACK,CHECKOUT_BUY}) {
|
||||
visible.add(document.cards().stream().filter(card -> card.slot() == slot).findFirst().orElseThrow());
|
||||
}
|
||||
if (controls.size() > CHECKOUT_CONTROLS) {
|
||||
String number = "Page " + (index + 1) + " / " + ((controls.size() + CHECKOUT_CONTROLS - 1) / CHECKOUT_CONTROLS);
|
||||
visible.add(new Card(PREVIOUS, "Previous", List.of(number), index > 0));
|
||||
visible.add(new Card(NEXT, "Next", List.of(number), end < controls.size()));
|
||||
}
|
||||
return new Page(index, document.style(), List.copyOf(visible));
|
||||
}
|
||||
|
||||
private void paint(Scene scene, boolean initial) {
|
||||
BufferedImage art = artwork(scene);
|
||||
scene.buttons.clear();
|
||||
|
|
@ -389,7 +416,7 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut
|
|||
draw.drawRect(445, 335, 518, 374);
|
||||
draw.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 38));
|
||||
String heading = scene.roleplay != null ? scene.roleplay.heading :
|
||||
scene.document.style() == Style.AUTO ? "YOUR DECISIONS" : scene.document.title();
|
||||
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);
|
||||
|
|
@ -423,7 +450,7 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut
|
|||
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 EXCHANGE, EXCHANGE_CHECKOUT -> 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))
|
||||
|
|
@ -435,7 +462,14 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut
|
|||
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;
|
||||
if (!wrap(graphics, styledTitle(document), 500, 1).complete) return false;
|
||||
if (document.style() == Style.EXCHANGE_CHECKOUT) {
|
||||
if (document.description().isBlank() || !hasCheckoutAction(document, CHECKOUT_BACK) ||
|
||||
!hasCheckoutAction(document, CHECKOUT_BUY)) return false;
|
||||
graphics.setFont(CHECKOUT_TERMS);
|
||||
var terms = checkoutTerms(graphics, document.description());
|
||||
if (terms.isEmpty() || terms.size() > 9) 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()) {
|
||||
|
|
@ -451,11 +485,30 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut
|
|||
}
|
||||
}
|
||||
|
||||
private static String styledTitle(Document document) {
|
||||
return document.style() == Style.EXCHANGE_CHECKOUT ? "Exchange checkout" : document.title();
|
||||
}
|
||||
|
||||
private static boolean hasCheckoutAction(Document document, int slot) {
|
||||
return document.cards().stream().anyMatch(card -> card.slot() == slot && card.actionable());
|
||||
}
|
||||
|
||||
private static List<String> checkoutTerms(java.awt.Graphics2D graphics, String description) {
|
||||
var lines = new ArrayList<String>();
|
||||
for (String term : description.lines().toList()) {
|
||||
var wrapped = wrap(graphics, term, 106, 9);
|
||||
if (!wrapped.complete) return List.of();
|
||||
lines.addAll(wrapped.lines);
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
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) {
|
||||
if (style == Style.EXCHANGE_CHECKOUT && !card.actionable()) return String.join(" ", card.lore());
|
||||
if (style == Style.EXCHANGE || style == Style.EXCHANGE_CHECKOUT) {
|
||||
// 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);
|
||||
|
|
@ -481,6 +534,15 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut
|
|||
draw.setColor(palette.background.darker());
|
||||
draw.fillRect(644, 389, 120, 232);
|
||||
switch (document.style()) {
|
||||
case EXCHANGE_CHECKOUT -> {
|
||||
draw.setColor(Color.WHITE);
|
||||
draw.setFont(CHECKOUT_TERMS);
|
||||
int y = 420;
|
||||
for (String line : checkoutTerms(draw, document.description())) {
|
||||
draw.drawString(line, 651, y);
|
||||
y += draw.getFontMetrics().getHeight();
|
||||
}
|
||||
}
|
||||
case ORGANISATION -> {
|
||||
if (identity != null) {
|
||||
BufferedImage mark = organisationLogo(identity.logo());
|
||||
|
|
@ -506,7 +568,7 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut
|
|||
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) {
|
||||
} else if (style == Style.EXCHANGE || style == Style.EXCHANGE_CHECKOUT) {
|
||||
draw.fillRect(x, y + 70, 128, 5);
|
||||
draw.fillRect(x, y + 120, 128, 5);
|
||||
} else if (art != null) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff