Prepare the dedicated Smuggler Navigator screens
This commit is contained in:
parent
297429cabb
commit
af33fc87b9
2 changed files with 130 additions and 0 deletions
|
|
@ -71,6 +71,64 @@ final class OrganisationMenus implements Listener {
|
|||
boolean war=row.has("wars")&&!row.getAsJsonArray("wars").isEmpty();put(panel,43,"War Transport",war?"Deploy for an active war\nShared Imperial boarding windows":"Unavailable · no active clan war",war?Material.CROSSBOW:Material.GRAY_DYE,()->{if(war)wars(p,data,kind,row);else organisation(p,data,kind,row);});
|
||||
put(panel,45,"Back","Your organisations",Material.ARROW,()->start(p,data));close(panel,p);show(p,panel);
|
||||
}
|
||||
void smugglerNavigator(Player player, List<SmugglerDestinations.Destination> destinations,
|
||||
int pageNumber, Consumer<SmugglerDestinations.Destination> select, Runnable back) {
|
||||
var screen = panel(player, "Smuggler Navigator", false);
|
||||
var page = SmugglerDestinations.page(destinations, pageNumber);
|
||||
int index = 0;
|
||||
for (var destination : page.destinations()) {
|
||||
String kind = switch (destination.kind()) {
|
||||
case CLAN -> "Clan";
|
||||
case COMPANY -> "Company";
|
||||
case WORLD -> "World";
|
||||
};
|
||||
String location = destination.world() == null ? "No registered Home Block" : destination.world();
|
||||
String details = kind + " · " + location;
|
||||
Material icon = switch (destination.kind()) {
|
||||
case CLAN -> Material.GREEN_BANNER;
|
||||
case COMPANY -> Material.CYAN_BANNER;
|
||||
case WORLD -> Material.COMPASS;
|
||||
};
|
||||
if (destination.available()) {
|
||||
put(screen, SmugglerDestinations.slot(index++), destination.name(), details + "\nView fare", icon,
|
||||
() -> select.accept(destination));
|
||||
} else {
|
||||
put(screen, SmugglerDestinations.slot(index++), destination.name(), details + "\n" + destination.unavailableReason(),
|
||||
Material.GRAY_DYE, () -> {
|
||||
player.sendMessage(destination.unavailableReason());
|
||||
smugglerNavigator(player, destinations, pageNumber, select, back);
|
||||
});
|
||||
}
|
||||
}
|
||||
if (page.destinations().isEmpty()) {
|
||||
put(screen, 22, "No destinations", "There are no destinations to display.", Material.MAP,
|
||||
() -> smugglerNavigator(player, destinations, pageNumber, select, back));
|
||||
}
|
||||
if (page.hasPrevious()) put(screen, 47, "Previous page", "Earlier destinations", Material.ARROW,
|
||||
() -> smugglerNavigator(player, destinations, pageNumber - 1, select, back));
|
||||
if (page.hasNext()) put(screen, 51, "Next page", "More destinations", Material.ARROW,
|
||||
() -> smugglerNavigator(player, destinations, pageNumber + 1, select, back));
|
||||
put(screen, 45, "Back", "Return to the contact", Material.ARROW, back);
|
||||
close(screen, player);
|
||||
show(player, screen);
|
||||
}
|
||||
void confirmSmugglerPassage(Player player, SmugglerDestinations.Quote quote, Runnable board, Runnable back) {
|
||||
var screen = panel(player, "Confirm smuggler passage", false);
|
||||
var destination = quote.destination();
|
||||
put(screen, 22, destination.name(), destination.world() + "\nSmuggler fare: " + quote.fare(), Material.COMPASS, back);
|
||||
if (quote.canBoard()) {
|
||||
put(screen, 31, "Confirm paid passage", "Reserve the quoted fare. Payment settles on arrival.", Material.LIME_DYE, board);
|
||||
} else {
|
||||
put(screen, 31, "Passage unavailable", quote.unavailableReason(), Material.GRAY_DYE,
|
||||
() -> {
|
||||
player.sendMessage(quote.unavailableReason());
|
||||
confirmSmugglerPassage(player, quote, board, back);
|
||||
});
|
||||
}
|
||||
put(screen, 45, "Back", "Smuggler Navigator", Material.ARROW, back);
|
||||
close(screen, player);
|
||||
show(player, screen);
|
||||
}
|
||||
private void warStatus(Player p,Runnable back){
|
||||
var screen=panel(p,"War report",false);JsonObject result;
|
||||
try{result=bridge.warReport(p.getUniqueId());}catch(Exception unavailable){p.sendMessage("War reports are temporarily unavailable.");return;}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
package com.dunerealms.gui;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/** Display data from the travel authority. Availability is never inferred by the menu. */
|
||||
final class SmugglerDestinations {
|
||||
private static final int COLUMNS = 7;
|
||||
private static final int PAGE_SIZE = 4 * COLUMNS;
|
||||
|
||||
enum Kind { CLAN, COMPANY, WORLD }
|
||||
|
||||
record Destination(String id, Kind kind, String name, String world, String unavailableReason) {
|
||||
boolean available() { return unavailableReason == null; }
|
||||
}
|
||||
|
||||
record Page(List<Destination> destinations, boolean hasPrevious, boolean hasNext) {}
|
||||
|
||||
record Quote(Destination destination, long fareMinor, String unavailableReason) {
|
||||
String fare() { return BigDecimal.valueOf(fareMinor, 2).toPlainString() + " DM"; }
|
||||
boolean canBoard() { return unavailableReason == null; }
|
||||
}
|
||||
|
||||
static Page page(List<Destination> destinations, int requestedPage) {
|
||||
int lastPage = Math.max(0, (destinations.size() - 1) / PAGE_SIZE);
|
||||
int page = Math.max(0, Math.min(requestedPage, lastPage));
|
||||
int start = page * PAGE_SIZE;
|
||||
return new Page(List.copyOf(destinations.subList(start, Math.min(start + PAGE_SIZE, destinations.size()))),
|
||||
page > 0, page < lastPage);
|
||||
}
|
||||
|
||||
static int slot(int index) {
|
||||
return 10 + index / COLUMNS * 9 + index % COLUMNS;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue

Staff