forked from unimatrix/web
Import the supplied DuneMenus plugin and connect its first JARVIS actions
This commit is contained in:
parent
6aa77a3d65
commit
41ef8f4329
1 changed files with 1782 additions and 0 deletions
|
|
@ -0,0 +1,82 @@
|
|||
package com.dunerealms.menus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/** 6 rows. Vertical tabs on the left, a 7x4 shelf of goods, toolbar underneath. "Sell" is a price stall. */
|
||||
final class ExchangeMenu extends Menu {
|
||||
private static final List<Integer> SHELF = new ArrayList<>();
|
||||
static { for (int r = 1; r <= 4; r++) for (int c = 2; c <= 8; c++) SHELF.add(r * 9 + c); }
|
||||
|
||||
private String tab = "buy";
|
||||
private int page = 0;
|
||||
private long price = 10_000;
|
||||
|
||||
ExchangeMenu(DuneMenusPlugin plugin, Player p, Menu parent) { super(plugin, p, parent); }
|
||||
String id() { return "exchange"; }
|
||||
Skin skin() { return Skin.MARKET; }
|
||||
String title() { return "Exchange · Merchant Hall"; }
|
||||
String subtitle() { return "“Coin, cargo and rumour change hands here.”"; }
|
||||
int rows() { return 6; }
|
||||
|
||||
private void tabButton(int slot, Material m, String label, String key) {
|
||||
var item = Ui.item(m, (tab.equals(key) ? "<gold><b>" : "<gray>") + label);
|
||||
if (tab.equals(key)) Ui.glow(item);
|
||||
put(slot, item, t -> { tab = key; page = 0; redraw(); });
|
||||
}
|
||||
|
||||
void draw() {
|
||||
backdrop(Material.BROWN_STAINED_GLASS_PANE);
|
||||
tabButton(9, Material.EMERALD, "Goods", "buy");
|
||||
tabButton(18, Material.NETHERITE_CHESTPLATE, "Kits", "kits");
|
||||
tabButton(27, Material.ENDER_CHEST, "My listings", "mine");
|
||||
tabButton(36, Material.GOLD_NUGGET, "Sell", "sell");
|
||||
back(46);
|
||||
put(51, Ui.item(Material.CHEST, "<green>Collect purchases", "<gray>Move paid items to your inventory"),
|
||||
t -> act(backend().collectPurchases(player)));
|
||||
load(backend().balance(player), b -> put(47, Ui.item(Material.GOLD_INGOT, "<gold>Balance", "<white>" + Ui.dm(b))));
|
||||
if (tab.equals("sell")) drawStall(); else drawShelf();
|
||||
}
|
||||
|
||||
private void drawShelf() {
|
||||
load(backend().listings(player, tab, page), pg -> {
|
||||
boolean mine = tab.equals("mine");
|
||||
for (int i = 0; i < SHELF.size() && i < pg.items().size(); i++) {
|
||||
var l = pg.items().get(i);
|
||||
put(SHELF.get(i), Ui.item(l.icon(), l.quantity(), "<white>" + l.title() + " <gray>· <gold>" + Ui.dm(l.priceMinor()),
|
||||
"<gray>Seller: <white>" + l.seller(), "<gray>In stock: <white>" + l.quantity(), "",
|
||||
mine ? "<yellow>Click to withdraw this listing"
|
||||
: "<yellow>Click <gray>buy 1 <dark_gray>· <yellow>Shift-click <gray>buy " + Math.min(16, l.quantity())),
|
||||
t -> {
|
||||
if (mine) act(backend().withdraw(player, l));
|
||||
else if (l.purchasable()) act(backend().buy(player, l, t.isShiftClick() && l.kitVersion() == null ? Math.min(16, l.quantity()) : 1));
|
||||
});
|
||||
}
|
||||
put(49, Ui.item(Material.PAPER, "<gray>Page " + (page + 1)));
|
||||
if (page > 0) put(45, Ui.item(Material.ARROW, "<gray>◀ Previous"), t -> { page--; redraw(); });
|
||||
if (pg.hasNext()) put(53, Ui.item(Material.ARROW, "<gray>Next ▶"), t -> { page++; redraw(); });
|
||||
});
|
||||
}
|
||||
|
||||
private void chip(int slot, long delta) {
|
||||
boolean up = delta > 0;
|
||||
put(slot, Ui.item(up ? Material.LIME_DYE : Material.RED_DYE, (up ? "<green>+" : "<red>−") + Ui.dm(Math.abs(delta))),
|
||||
t -> { price = Math.max(100, price + delta); redraw(); });
|
||||
}
|
||||
|
||||
private void drawStall() {
|
||||
var held = player.getInventory().getItemInMainHand().clone();
|
||||
int heldSlot = player.getInventory().getHeldItemSlot();
|
||||
long shownPrice = price;
|
||||
boolean has = !held.getType().isAir();
|
||||
put(13, has ? held.clone() : Ui.item(Material.BARRIER, "<red>Nothing in your hand"));
|
||||
put(22, Ui.item(Material.OAK_SIGN, "<gray>Hold the item you want to sell", "<gray>in your main hand, set a price,", "<gray>then list it."));
|
||||
chip(28, -10_000); chip(29, -1_000); chip(30, -100);
|
||||
chip(32, 100); chip(33, 1_000); chip(34, 10_000);
|
||||
put(31, Ui.item(Material.GOLD_NUGGET, "<gold><b>" + Ui.dm(price), "<gray>Price per item"));
|
||||
put(40, Ui.glow(Ui.item(Material.EMERALD, "<green><b>List for " + Ui.dm(price))),
|
||||
t -> { if (!has) { player.sendMessage(Ui.text("<red>Hold an item first.")); return; } act(backend().sell(player, held, heldSlot, shownPrice)); });
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue

Staff