Prepare the dedicated Smuggler Navigator screens
This commit is contained in:
parent
297429cabb
commit
af33fc87b9
1 changed files with 130 additions and 0 deletions
|
|
@ -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