Merge pull request 'Connect DuneMenus fullscreen rendering and remove the chest fallback' (#616) from dev/MC:work/dunemenus-fullscreen-7b388da6 into main
This commit is contained in:
commit
cd2c30923a
4 changed files with 40 additions and 18 deletions
|
|
@ -21,6 +21,18 @@ public final class FullscreenProvider extends JavaPlugin {
|
|||
scenes = new PaperDecisionsScene(this);
|
||||
Bukkit.getPluginManager().registerEvents(scenes, this);
|
||||
Bukkit.getServicesManager().register(DecisionsViewTransport.class, scenes, this, ServicePriority.Normal);
|
||||
com.dunerealms.menus.FullscreenProvider menus = (viewer, screen, select, close) -> {
|
||||
var cards = new java.util.ArrayList<DecisionsViewTransport.Card>();
|
||||
for (var card : screen.cards()) {
|
||||
cards.add(new DecisionsViewTransport.Card(card.slot(), card.title(), card.lore(), true, card.material()));
|
||||
}
|
||||
int infoSlot = 54;
|
||||
for (String line : screen.info()) {
|
||||
cards.add(new DecisionsViewTransport.Card(infoSlot++, line, java.util.List.of(), false));
|
||||
}
|
||||
return scenes.open(viewer, new DecisionsViewTransport.Document(screen.title(), screen.subtitle(), cards), select, close);
|
||||
};
|
||||
Bukkit.getServicesManager().register(com.dunerealms.menus.FullscreenProvider.class, menus, this, ServicePriority.Normal);
|
||||
} catch (LinkageError unavailable) {
|
||||
getLogger().warning("Fullscreen Decisions runtime is unavailable: " + unavailable.getClass().getSimpleName());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -515,7 +515,7 @@ final class PaperDecisionsScene implements DecisionsViewTransport, Listener, Aut
|
|||
draw.drawRect(445, 335, 518, 374);
|
||||
|
||||
String heading = scene.roleplay != null ? scene.roleplay.heading :
|
||||
scene.document.style() == Style.AUTO ? "YOUR DECISIONS" : styledTitle(scene.document);
|
||||
scene.document.style() == Style.AUTO ? scene.document.title() : styledTitle(scene.document);
|
||||
setHeadingFont(draw, scene.document.style(), heading);
|
||||
int headlineWidth = draw.getFontMetrics().stringWidth(heading);
|
||||
draw.drawString(heading, (image.getWidth() - headlineWidth) / 2, 372);
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ public final class DuneMenusPlugin extends DuneServicesPlugin implements TabExec
|
|||
boolean itemCardPackLoaded(Player player) {
|
||||
String expected = getConfig().getString("resource-pack.item-card-sha1", "");
|
||||
return expected.matches("[a-f0-9]{40}") && expected.equals(loadedPacks.get(player))
|
||||
&& !Bedrock.is(player) && modeFor(player) == Menu.Mode.INVENTORY;
|
||||
&& !Bedrock.is(player);
|
||||
}
|
||||
|
||||
boolean hasOpenMenu(Player player) { return openMenus.containsKey(player.getUniqueId()); }
|
||||
|
|
@ -105,8 +105,7 @@ public final class DuneMenusPlugin extends DuneServicesPlugin implements TabExec
|
|||
|
||||
Menu.Mode modeFor(Player p) {
|
||||
if (getConfig().getBoolean("bedrock.forms", true) && Bedrock.is(p)) return Menu.Mode.BEDROCK;
|
||||
if (getConfig().getBoolean("fullscreen.enabled", false) && fullscreen() != null) return Menu.Mode.FULLSCREEN;
|
||||
return Menu.Mode.INVENTORY;
|
||||
return Menu.Mode.FULLSCREEN;
|
||||
}
|
||||
|
||||
/** Coloured title, optionally led by the DuneRealms logo glyph from the resource pack. */
|
||||
|
|
|
|||
|
|
@ -23,14 +23,14 @@ import org.bukkit.inventory.ItemStack;
|
|||
*/
|
||||
abstract class Menu implements InventoryHolder {
|
||||
interface Button { void click(ClickType type); }
|
||||
enum Mode { INVENTORY, BEDROCK, FULLSCREEN }
|
||||
enum Mode { BEDROCK, FULLSCREEN }
|
||||
|
||||
protected final DuneMenusPlugin plugin;
|
||||
protected final Player player;
|
||||
protected final Menu parent;
|
||||
private Inventory inv;
|
||||
private final Map<Integer, Button> buttons = new TreeMap<>();
|
||||
private Mode mode = Mode.INVENTORY;
|
||||
private Mode mode;
|
||||
private boolean active, redrawn;
|
||||
private int gen, pending;
|
||||
private long presentation;
|
||||
|
|
@ -55,12 +55,6 @@ abstract class Menu implements InventoryHolder {
|
|||
mode = plugin.modeFor(player);
|
||||
if (inv == null) inv = Bukkit.createInventory(this, rows() * 9, plugin.titleFor(this));
|
||||
redraw();
|
||||
if (mode == Mode.INVENTORY) showInventory();
|
||||
}
|
||||
|
||||
private void showInventory() {
|
||||
player.openInventory(inv);
|
||||
player.playSound(player.getLocation(), skin().open(), 0.6f, 1f);
|
||||
}
|
||||
|
||||
final void closed() {
|
||||
|
|
@ -93,7 +87,7 @@ abstract class Menu implements InventoryHolder {
|
|||
redrawn = true; gen++; pending = 0;
|
||||
inv.clear(); buttons.clear();
|
||||
draw();
|
||||
if (mode != Mode.INVENTORY && pending == 0) present();
|
||||
if (pending == 0) present();
|
||||
}
|
||||
|
||||
final void handle(int slot, ClickType type) {
|
||||
|
|
@ -102,7 +96,7 @@ abstract class Menu implements InventoryHolder {
|
|||
player.playSound(player.getLocation(), skin().click(), 0.5f, 1.2f);
|
||||
redrawn = false;
|
||||
b.click(type);
|
||||
if (mode != Mode.INVENTORY && active && !redrawn && pending == 0) present(); // keep forms/screens alive
|
||||
if (active && !redrawn && pending == 0) present(); // keep forms/screens alive
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- drawing helpers
|
||||
|
|
@ -125,7 +119,7 @@ abstract class Menu implements InventoryHolder {
|
|||
? "<red>This service isn't connected to the new menus yet."
|
||||
: "<red>Something went wrong. Please try again."));
|
||||
} else ok.accept(value);
|
||||
if (g == gen && mode != Mode.INVENTORY && pending == 0) present();
|
||||
if (g == gen && pending == 0) present();
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
@ -189,11 +183,28 @@ abstract class Menu implements InventoryHolder {
|
|||
new FullscreenProvider.Screen(id(), title(), subtitle(), cards, info),
|
||||
select, close);
|
||||
if (ok) return;
|
||||
presentation++;
|
||||
mode = Mode.INVENTORY; // provider declined: fall back to the chest menu
|
||||
showInventory();
|
||||
List<io.papermc.paper.registry.data.dialog.ActionButton> choices = new ArrayList<>();
|
||||
for (Card card : cards) {
|
||||
choices.add(dialogButton(card.title(), String.join("\n", card.lore()), () -> select.accept(card.slot())));
|
||||
}
|
||||
choices.add(dialogButton("Close", "", close));
|
||||
String content = java.util.stream.Stream.concat(java.util.stream.Stream.of(subtitle()), info.stream())
|
||||
.filter(line -> !line.isBlank()).collect(java.util.stream.Collectors.joining("\n"));
|
||||
player.showDialog(io.papermc.paper.dialog.Dialog.create(builder -> builder.empty()
|
||||
.base(io.papermc.paper.registry.data.dialog.DialogBase.builder(Component.text(title()))
|
||||
.body(List.of(io.papermc.paper.registry.data.dialog.body.DialogBody.plainMessage(Component.text(content)))).build())
|
||||
.type(io.papermc.paper.registry.data.dialog.type.DialogType.multiAction(choices).build())));
|
||||
return;
|
||||
}
|
||||
Bedrock.show(plugin, player, title(), subtitle(), info, cards, select, close);
|
||||
}
|
||||
private io.papermc.paper.registry.data.dialog.ActionButton dialogButton(String label, String hint, Runnable action) {
|
||||
return io.papermc.paper.registry.data.dialog.ActionButton.builder(Component.text(label))
|
||||
.tooltip(Component.text(hint))
|
||||
.action(io.papermc.paper.registry.data.dialog.action.DialogAction.customClick((view, viewer) -> {
|
||||
if (player.equals(viewer)) Bukkit.getScheduler().runTask(plugin, action);
|
||||
}, net.kyori.adventure.text.event.ClickCallback.Options.builder().uses(1)
|
||||
.lifetime(java.time.Duration.ofMinutes(5)).build())).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff