plugins/DuneRealmsGUI/src/main/java/com/dunerealms/gui/SmugglerDestinations.java
2026-11-29 23:18:58 +01:00

35 lines
1.3 KiB
Java

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;
}
}