Skip to content

Commit

Permalink
WIP implementation of shop item copying using shift click
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed May 7, 2023
1 parent 55bda3a commit fa9b99a
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions main/src/main/java/net/citizensnpcs/trait/ShopTrait.java
Expand Up @@ -176,6 +176,7 @@ public void setPermission(String permission) {

@Menu(title = "NPC Shop Contents Editor", type = InventoryType.CHEST, dimensions = { 5, 9 })
public static class NPCShopContentsEditor extends InventoryMenuPage {
private NPCShopItem copying;
private MenuContext ctx;
private int page = 0;
private final NPCShop shop;
Expand All @@ -191,23 +192,36 @@ public void changePage(int newPage) {
for (int i = 0; i < ctx.getInventory().getSize(); i++) {
InventoryMenuSlot slot = ctx.getSlot(i);
slot.clear();
NPCShopItem item = shopPage.getItem(i);

if (item != null) {
slot.setItemStack(item.getDisplayItem(null));
if (shopPage.getItem(i) != null) {
slot.setItemStack(shopPage.getItem(i).getDisplayItem(null));
}

final int idx = i;
slot.setClickHandler(evt -> {
ctx.clearSlots();
NPCShopItem display = item;
NPCShopItem display = shopPage.getItem(idx);
if (display != null && evt.isShiftClick() && evt.getCursorNonNull().getType() == Material.AIR
&& display.display != null) {
copying = display.clone();
evt.setCursor(display.getDisplayItem(null));
evt.setCancelled(true);
return;
}
if (display == null) {
if (copying != null && evt.getCursorNonNull().getType() != Material.AIR
&& evt.getCursorNonNull().equals(copying.getDisplayItem(null))) {
shopPage.setItem(idx, copying);
copying = null;
return;
}

display = new NPCShopItem();
if (evt.getCursor() != null) {
display.display = evt.getCursor().clone();
}
}

ctx.clearSlots();
ctx.getMenu().transition(new NPCShopItemEditor(display, modified -> {
if (modified == null) {
shopPage.removeItem(idx);
Expand Down

0 comments on commit fa9b99a

Please sign in to comment.