forked from unimatrix/web
Render roleplay quest screens in the opt-in fullscreen view
This commit is contained in:
parent
5d80713483
commit
e8452c887f
4 changed files with 148 additions and 26 deletions
|
|
@ -1,7 +1,7 @@
|
|||
# Optional Paper fullscreen Decisions provider
|
||||
# Optional Paper fullscreen roleplay provider
|
||||
|
||||
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. Keep the allowlist empty on live servers. The existing menu path handles unsupported clients, unavailable providers and documents with invalid slots or outside the 54-card inventory limit.
|
||||
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.
|
||||
|
||||
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.
|
||||
|
|
|
|||
|
|
@ -45,12 +45,14 @@ 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 Roleplay(String heading, String contact, Card portrait, Card world, Card summary) {}
|
||||
|
||||
private static final class Scene {
|
||||
final Player viewer;
|
||||
final Location original;
|
||||
final boolean gravity;
|
||||
final Document document;
|
||||
final Roleplay roleplay;
|
||||
final IntConsumer select;
|
||||
final Runnable dismiss;
|
||||
final List<Entity> entities = new ArrayList<>();
|
||||
|
|
@ -62,14 +64,15 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut
|
|||
volatile boolean closed;
|
||||
boolean positioning;
|
||||
|
||||
Scene(Player viewer, Document document, IntConsumer select, Runnable dismiss) {
|
||||
Scene(Player viewer, Document document, Roleplay roleplay, IntConsumer select, Runnable dismiss) {
|
||||
this.viewer = viewer;
|
||||
this.document = document;
|
||||
this.roleplay = roleplay;
|
||||
this.select = select;
|
||||
this.dismiss = dismiss;
|
||||
original = viewer.getLocation();
|
||||
gravity = viewer.hasGravity();
|
||||
page = page(document, 0);
|
||||
page = page(this.document, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -84,7 +87,10 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut
|
|||
var pipeline = player.getHandle().connection.connection.channel.pipeline();
|
||||
if (pipeline.get("packet_handler") == null || pipeline.get(INPUT) != null) return false;
|
||||
|
||||
Scene scene = new Scene(viewer, document, select, dismiss);
|
||||
Roleplay roleplay = roleplay(document);
|
||||
Document visibleDocument = presentable(document, roleplay);
|
||||
if (roleplay != null && !fitsRoleplay(visibleDocument, roleplay)) 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,
|
||||
origin.getBlockZ() + .5, 0, 0);
|
||||
|
|
@ -202,7 +208,7 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut
|
|||
|
||||
private void paint(Scene scene, boolean initial) {
|
||||
var cards = scene.page.cards;
|
||||
BufferedImage art = artwork(cards);
|
||||
BufferedImage art = artwork(scene, cards);
|
||||
scene.buttons.clear();
|
||||
scene.focus = null;
|
||||
for (int row = 0; row < ROWS; row++) {
|
||||
|
|
@ -360,30 +366,36 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut
|
|||
}
|
||||
}
|
||||
|
||||
private BufferedImage artwork(List<Card> cards) {
|
||||
private BufferedImage artwork(Scene scene, List<Card> cards) {
|
||||
var image = new BufferedImage(COLS * 128, ROWS * 128, BufferedImage.TYPE_INT_RGB);
|
||||
var draw = image.createGraphics();
|
||||
try {
|
||||
draw.setColor(new Color(25, 40, 46));
|
||||
draw.setColor(scene.roleplay == null ? new Color(25, 40, 46) : new Color(9, 33, 24));
|
||||
draw.fillRect(0, 0, image.getWidth(), image.getHeight());
|
||||
draw.setColor(new Color(237, 199, 105));
|
||||
draw.setStroke(new BasicStroke(7));
|
||||
draw.drawRect(445, 335, 518, 455);
|
||||
draw.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 38));
|
||||
draw.drawString("YOUR DECISIONS", 523, 372);
|
||||
String heading = scene.roleplay == null ? "YOUR DECISIONS" : scene.roleplay.heading;
|
||||
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() ? new Color(52, 93, 107) : new Color(55, 63, 66));
|
||||
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);
|
||||
draw.setColor(Color.WHITE);
|
||||
draw.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 14));
|
||||
writeWrapped(draw, card.title(), x + 7, y + 25, 114, 3);
|
||||
if (!card.lore().isEmpty()) {
|
||||
String lore = displayLore(scene.roleplay, card);
|
||||
if (!lore.isBlank()) {
|
||||
draw.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
|
||||
writeWrapped(draw, card.lore().getFirst(), x + 7, y + 76, 114, 3);
|
||||
writeWrapped(draw, lore, x + 7, y + (card.slot() < 0 ? 45 : 76), 114, 3);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
|
|
@ -392,20 +404,117 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut
|
|||
return image;
|
||||
}
|
||||
|
||||
private static Roleplay roleplay(Document document) {
|
||||
String[] title = document.title().split(" · ", 2);
|
||||
if (title.length != 2) return null;
|
||||
String heading = switch (title[0]) {
|
||||
case "NPC dashboard" -> "YOUR MISSIONS";
|
||||
case "NPC next quest" -> "YOUR NEXT MISSION";
|
||||
case "NPC turn-in" -> document.cards().stream().anyMatch(card ->
|
||||
card.actionable() && (card.title().equals("Claim verified reward") || card.title().equals("Next quest")))
|
||||
? "MISSION COMPLETE" : "MISSION TURN-IN";
|
||||
default -> null;
|
||||
};
|
||||
if (heading == null) return null;
|
||||
var portrait = document.cards().stream().filter(card -> card.material().matches("npc_avatar_[0-7]")).findFirst().orElse(null);
|
||||
var world = document.cards().stream().filter(card -> card.material().matches("npc_world_[a-z_]+")).findFirst().orElse(null);
|
||||
var summary = document.description().isBlank() ? document.cards().stream()
|
||||
.filter(card -> card.material().equals("npc_summary")).findFirst().orElse(null) : null;
|
||||
return new Roleplay(heading, portrait == null ? title[1] : portrait.title(), portrait, world, summary);
|
||||
}
|
||||
|
||||
private static Document presentable(Document document, Roleplay roleplay) {
|
||||
if (roleplay == null) return document;
|
||||
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);
|
||||
}
|
||||
|
||||
private static String displayLore(Roleplay roleplay, Card card) {
|
||||
if (card.lore().isEmpty()) return "";
|
||||
if (roleplay == null || card.slot() < 0) return card.lore().getFirst();
|
||||
if (!card.actionable()) return String.join(" ", card.lore());
|
||||
return roleplay.heading.equals("YOUR MISSIONS") && card.slot() >= 9 && card.slot() < 45
|
||||
? card.lore().getFirst() : "";
|
||||
}
|
||||
|
||||
private static boolean fitsRoleplay(Document document, Roleplay roleplay) {
|
||||
var graphics = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB).createGraphics();
|
||||
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));
|
||||
String summary = roleplay.summary == null ? document.description() : String.join(" ", roleplay.summary.lore());
|
||||
return wrap(graphics, summary, 112, 8).complete;
|
||||
} finally {
|
||||
graphics.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private void drawRoleplay(java.awt.Graphics2D draw, Scene scene) {
|
||||
var role = scene.roleplay;
|
||||
draw.setColor(new Color(23, 56, 40));
|
||||
draw.fillRect(644, 389, 120, 232);
|
||||
String asset = role.portrait == null ? "npc_avatar_7" : role.portrait.material();
|
||||
drawSceneArt(draw, asset, 650, 395, 108, 83);
|
||||
draw.setColor(new Color(250, 226, 169));
|
||||
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));
|
||||
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);
|
||||
}
|
||||
|
||||
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")) {
|
||||
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);
|
||||
} catch (java.io.IOException error) {
|
||||
plugin.getLogger().warning("Could not render quest artwork: " + asset);
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
int lineHeight = draw.getFontMetrics().getHeight();
|
||||
for (String line : wrap(draw, text, width, lines).lines()) {
|
||||
draw.drawString(line, x, y);
|
||||
y += lineHeight;
|
||||
}
|
||||
}
|
||||
|
||||
private static Wrapped wrap(java.awt.Graphics2D draw, String text, int width, int lines) {
|
||||
var metrics = draw.getFontMetrics();
|
||||
String remaining = text.strip();
|
||||
for (int line = 0; line < lines && !remaining.isEmpty(); line++) {
|
||||
var result = new ArrayList<String>();
|
||||
String remaining = text.strip().replaceAll("\\s+", " ");
|
||||
while (result.size() < lines && !remaining.isEmpty()) {
|
||||
int end = remaining.length();
|
||||
while (end > 1 && metrics.stringWidth(remaining.substring(0, end)) > width) end--;
|
||||
if (end < remaining.length()) {
|
||||
int wordBreak = remaining.lastIndexOf(' ', end);
|
||||
if (wordBreak > 0) end = wordBreak;
|
||||
}
|
||||
draw.drawString(remaining.substring(0, end), x, y + line * metrics.getHeight());
|
||||
result.add(remaining.substring(0, end));
|
||||
remaining = remaining.substring(end).stripLeading();
|
||||
}
|
||||
return new Wrapped(List.copyOf(result), remaining.isEmpty());
|
||||
}
|
||||
|
||||
private BufferedImage focused(BufferedImage normal) {
|
||||
var image = new BufferedImage(128, 128, BufferedImage.TYPE_INT_RGB);
|
||||
var draw = image.createGraphics();
|
||||
|
|
|
|||
|
|
@ -5,11 +5,15 @@ import java.util.function.IntConsumer;
|
|||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Bukkit service for an optional Java fullscreen provider. The provider owns its
|
||||
* Bukkit service for an optional Java fullscreen roleplay provider. It owns its
|
||||
* runtime-specific packet support and closes its scene before returning input.
|
||||
*/
|
||||
public interface DecisionsViewTransport {
|
||||
record Card(int slot, String title, List<String> lore, boolean actionable) {
|
||||
record Card(int slot, String title, List<String> lore, boolean actionable, String material) {
|
||||
public Card(int slot, String title, List<String> lore, boolean actionable) {
|
||||
this(slot, title, lore, actionable, "");
|
||||
}
|
||||
|
||||
public Card {
|
||||
lore = List.copyOf(lore);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ final class QuestMenus implements Listener {
|
|||
private final Map<UUID,UUID> pending=new HashMap<>();
|
||||
private final Map<UUID,PolQuestNpc.Role> roleScope=new HashMap<>();
|
||||
private static final class Panel implements DuneMenuInventory {
|
||||
final UUID owner;final GuiSession gate;final Map<Integer,Runnable> actions=new HashMap<>();final List<BedrockForms.Choice> choices=new ArrayList<>();final Inventory inventory;final String title;String description="Your current J.A.R.V.I.S. mission journal";
|
||||
final UUID owner;final GuiSession gate;final Map<Integer,Runnable> actions=new HashMap<>();final List<BedrockForms.Choice> choices=new ArrayList<>();final List<String> descriptionNotes=new ArrayList<>();final Inventory inventory;final String title;String description="Your current J.A.R.V.I.S. mission journal";
|
||||
Panel(Player p,String title){owner=p.getUniqueId();gate=new GuiSession(owner);this.title=title;inventory=Bukkit.createInventory(this,54,Component.text(title,NamedTextColor.GOLD));}
|
||||
public Inventory getInventory(){return inventory;}
|
||||
}
|
||||
|
|
@ -33,10 +33,10 @@ final class QuestMenus implements Listener {
|
|||
private Panel panel(Player p,String title){var screen=new Panel(p,title);var filler=new ItemStack(Material.GRAY_STAINED_GLASS_PANE);var meta=filler.getItemMeta();meta.displayName(Component.empty());filler.setItemMeta(meta);for(int i=0;i<54;i++)screen.inventory.setItem(i,filler);return screen;}
|
||||
private void put(Panel panel,int slot,String title,String description,Material material,Runnable action){
|
||||
var item=new ItemStack(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());item.setItemMeta(meta);panel.inventory.setItem(slot,item);
|
||||
if(action==null)panel.description+="\n\n"+title+"\n"+description;
|
||||
if(action==null){String note="\n\n"+title+"\n"+description;panel.description+=note;panel.descriptionNotes.add(note);}
|
||||
if(action!=null){panel.actions.put(slot,action);panel.choices.add(new BedrockForms.Choice(title,description,action));}
|
||||
}
|
||||
private void show(Player p,Panel screen){if(BedrockForms.isBedrock(p)){BedrockForms.show(plugin,p,screen.title,screen.description,List.copyOf(screen.choices));return;}if(MCGUIMenus.show(p,screen.title,screen.description,screen.inventory,screen.actions,screen.gate))return;p.openInventory(screen.inventory);Bukkit.getScheduler().runTaskLater(plugin,screen.gate::expire,2400L);}
|
||||
private void show(Player p,Panel screen){if(BedrockForms.isBedrock(p)){BedrockForms.show(plugin,p,screen.title,screen.description,List.copyOf(screen.choices));return;}if(showDevelopmentRoleplay(p,screen))return;if(MCGUIMenus.show(p,screen.title,screen.description,screen.inventory,screen.actions,screen.gate))return;p.openInventory(screen.inventory);Bukkit.getScheduler().runTaskLater(plugin,screen.gate::expire,2400L);}
|
||||
void close(){pending.clear();for(Player p:Bukkit.getOnlinePlayers())if(p.getOpenInventory().getTopInventory().getHolder() instanceof Panel)p.closeInventory();}
|
||||
private record RefitQuote(JsonObject input,UUID world,long expires){}
|
||||
private final Map<UUID,RefitQuote> refitQuotes=new HashMap<>();
|
||||
|
|
@ -293,18 +293,27 @@ final class QuestMenus implements Listener {
|
|||
if(current<last)put(screen,53,"Next page","More decisions",Material.ARROW,()->openDecisions(p,current+1));
|
||||
put(screen,48,"Back","Mission journal",Material.ARROW,()->open(p));
|
||||
put(screen,49,"Website","Decision definitions and history",Material.MAP,()->decisionWebsite(p));
|
||||
if(!showDevelopmentDecisions(p,screen))show(p,screen);
|
||||
show(p,screen);
|
||||
},true);
|
||||
}
|
||||
private boolean showDevelopmentDecisions(Player player,Panel screen){
|
||||
if(!plugin.getConfig().getStringList("development.fullscreen-decisions-viewers")
|
||||
.contains(player.getUniqueId().toString())||BedrockForms.isBedrock(player))return false;
|
||||
private boolean showDevelopmentRoleplay(Player player,Panel screen){
|
||||
boolean decisions=screen.title.startsWith("NPC dashboard decision · ");
|
||||
boolean quests=screen.title.startsWith("NPC dashboard · ")||screen.title.startsWith("NPC turn-in · ")||
|
||||
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()))
|
||||
.map(card->new DecisionsViewTransport.Card(card.slot(),card.title(),card.lore(),card.action(),card.material()))
|
||||
.toList();
|
||||
var document=new DecisionsViewTransport.Document(screen.title,screen.description,cards);
|
||||
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<Integer,Runnable> visibleActions=new HashMap<>();
|
||||
for(var card:cards)if(card.actionable())visibleActions.put(card.slot(),screen.actions.get(card.slot()));
|
||||
var callbacks=Map.copyOf(visibleActions);
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff