forked from unimatrix/web
Render roleplay quest screens in the opt-in fullscreen view
This commit is contained in:
parent
5d80713483
commit
e8452c887f
2 changed files with 148 additions and 26 deletions
|
|
@ -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