diff --git a/src/client/java/jesse/keeblarcraft/gui/FactionBlockGUI/FactionBlockScreen.java b/src/client/java/jesse/keeblarcraft/gui/FactionBlockGUI/FactionBlockScreen.java index f885394..417899a 100644 --- a/src/client/java/jesse/keeblarcraft/gui/FactionBlockGUI/FactionBlockScreen.java +++ b/src/client/java/jesse/keeblarcraft/gui/FactionBlockGUI/FactionBlockScreen.java @@ -25,18 +25,23 @@ public class FactionBlockScreen extends HandledScreen super.init(); titleY = 1000; //begone from screen playerInventoryTitleY = 1000; //begone from screen + + this.backgroundWidth = 256; + this.backgroundHeight = 256; + this.x = (width - backgroundWidth) / 2; + this.y = (height - backgroundHeight) / 2; } @Override protected void drawBackground(DrawContext context, float delta, int mouseX, int mouseY) { - RenderSystem.setShader(GameRenderer::getPositionTexProgram); - RenderSystem.setShaderColor(1f, 1f, 1f, 1f); - RenderSystem.setShaderTexture(0, TEXTURE); +// RenderSystem.setShader(GameRenderer::getPositionTexProgram); +// RenderSystem.setShaderColor(1f, 1f, 1f, 1f); +// RenderSystem.setShaderTexture(0, TEXTURE); + + context.drawTexture(TEXTURE, this.x, this.y, 0, 0, this.backgroundWidth, this.backgroundHeight, this.backgroundWidth, this.backgroundHeight); this.backgroundHeight = 256; this.backgroundWidth = 256; - - } @Override diff --git a/src/client/java/jesse/keeblarcraft/gui/Generics/ClickableLayer.java b/src/client/java/jesse/keeblarcraft/gui/Generics/ClickableLayer.java index 7fcbb12..41fea1d 100644 --- a/src/client/java/jesse/keeblarcraft/gui/Generics/ClickableLayer.java +++ b/src/client/java/jesse/keeblarcraft/gui/Generics/ClickableLayer.java @@ -27,6 +27,16 @@ abstract public class ClickableLayer extends ClickableWidget { this.layerName = layerName; } + protected void ResizeLayer(int width, int height) { + this.setWidth(width); + this.setHeight(height); + } + + protected void MoveLayer(int startX, int startY) { + this.setX(startX); + this.setY(startY); + } + protected void AddSubLayer(ClickableLayer newLayer) { subLayers.add(newLayer); } @@ -59,7 +69,6 @@ abstract public class ClickableLayer extends ClickableWidget { @Override public void renderButton(DrawContext context, int mouseX, int mouseY, float delta) { context.drawTexture(this.GetTexture(), this.getX(), this.getY(), 0, 0, this.getWidth(), this.getHeight(), this.getWidth(), this.getHeight()); - } public Identifier GetTexture() { diff --git a/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/DrawableStoreItem.java b/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/DrawableStoreItem.java new file mode 100644 index 0000000..bf0990b --- /dev/null +++ b/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/DrawableStoreItem.java @@ -0,0 +1,48 @@ +package jesse.keeblarcraft.gui.ShopKeeperGUI; + +import jesse.keeblarcraft.Keeblarcraft; +import jesse.keeblarcraft.gui.Generics.ClickableLayer; +import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; +import net.minecraft.text.Text; +import net.minecraft.util.Identifier; + +// All the custom content that a store item will have. Handled by @see MerchandiseScroller.java +public class DrawableStoreItem extends ClickableLayer { + private static final Identifier ITEM_ICON = new Identifier(Keeblarcraft.MOD_ID, "textures/gui/shopkeeper_item_slot.png"); + private Integer itemCost; + private String itemName; + private Integer amountSelected = 0; + + public DrawableStoreItem(String itemName, Integer itemCost) { + this(itemName, itemCost, Text.of(""), 0, 0, 0, 0); + + } + + public DrawableStoreItem(String itemName, Integer itemCost, Text layerName, int width, int height, int startX, int startY) { + super(ITEM_ICON, layerName, width, height, startX, startY); + this.itemCost = itemCost; + this.itemName = itemName; + } + + public void Add() { + ++this.amountSelected; + System.out.println("Current buy amount: " + this.amountSelected); + } + + public void Subtract() { + --this.amountSelected; + System.out.println("Current buy amount: " + this.amountSelected); + } + + public Integer GetTotal() { + return this.amountSelected * itemCost; + } + + @Override + public void onClick(double x, double y) { + System.out.println("User clicked the following coordinates: [" + x + ", " + y + "]"); + } + + @Override + protected void appendClickableNarrations(NarrationMessageBuilder builder) {} +} diff --git a/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/MerchandiseScroller.java b/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/MerchandiseScroller.java new file mode 100644 index 0000000..5487179 --- /dev/null +++ b/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/MerchandiseScroller.java @@ -0,0 +1,40 @@ +package jesse.keeblarcraft.gui.ShopKeeperGUI; + +import jesse.keeblarcraft.GuiMgr.ShopKeeper.ShopKeeperInventory; +import jesse.keeblarcraft.GuiMgr.ShopKeeper.StoreItem; +import jesse.keeblarcraft.gui.Generics.ClickableLayer; +import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; +import net.minecraft.text.Text; +import net.minecraft.util.Identifier; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +// This is the main section in the GUI that will display the stores "merchandise" -- all the items on sale. +public class MerchandiseScroller { + private final ShopKeeperInventory storeInventory; + + // Key = item name + // Value = the drawable slot for it + // The KVP keeps it so duplicate items don't take up more than 1 store slot + private final HashMap drawableInventory; + + public MerchandiseScroller(ShopKeeperInventory storeInventory) { + this.storeInventory = storeInventory; + drawableInventory = new HashMap<>(); + } + + public Integer Size() { + return storeInventory.Size(); + } + + public void Add(StoreItem item) { + storeInventory.Add(item); + drawableInventory.put(item.GetUPC(), new DrawableStoreItem(item.GetName(), item.GetCost())); + } + + public void Remove(String upc) { + storeInventory.Remove(upc); + } +} diff --git a/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/NewItemButton.java b/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/NewItemButton.java index 61c82a8..b345d44 100644 --- a/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/NewItemButton.java +++ b/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/NewItemButton.java @@ -7,7 +7,7 @@ import net.minecraft.text.Text; import net.minecraft.util.Identifier; public class NewItemButton extends ClickableLayer { - private static final Identifier NEW_ITEM_MENU = new Identifier(Keeblarcraft.MOD_ID, "textures/gui/shopkeeper_item_slot.jpeg"); + private static final Identifier NEW_ITEM_MENU = new Identifier(Keeblarcraft.MOD_ID, "textures/gui/shopkeeper_item_slot.jpeg"); /// TODO: Does not exist private static NewItemMenu newItemMenu; public NewItemButton(Identifier texture, Text layerName, int width, int height, int startX, int startY) { diff --git a/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/NewItemMenu.java b/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/NewItemMenu.java index 0acca22..158a713 100644 --- a/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/NewItemMenu.java +++ b/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/NewItemMenu.java @@ -25,6 +25,10 @@ public class NewItemMenu extends ClickableLayer { this.AddDrawableSlotByName("add_item_slot", true); } + public void AddItem() { + + } + public boolean IsOpen() { return this.isOpen; } diff --git a/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/Scrollbar.java b/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/Scrollbar.java new file mode 100644 index 0000000..9bdc3b2 --- /dev/null +++ b/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/Scrollbar.java @@ -0,0 +1,77 @@ +package jesse.keeblarcraft.gui.ShopKeeperGUI; + +import jesse.keeblarcraft.gui.Generics.ClickableLayer; +import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; + +import net.minecraft.text.Text; +import net.minecraft.util.Identifier; + +public class Scrollbar extends ClickableLayer { + private boolean isDragging = false; + private int scrollbarStart = 0; + private int scrollbarEnd = 0; + + public Scrollbar(Identifier texture, Text layerName, int width, int height, int startX, int startY, int scrollbarStart, int scrollbarMaxLength) { + super(texture, layerName, width, height, startX, startY); + this.scrollbarStart = scrollbarStart; + this.scrollbarEnd = startY + scrollbarMaxLength; + } + + @Override + protected void onDrag(double mX, double mY, double dX, double dY) { + // We only want to enable dragging if this feature is being toggled + if (dY > 0) { + dY = 1.0; + } else { + dY = -1.0; + } + + if (isDragging && mY >= this.scrollbarStart && mY <= this.scrollbarEnd) { + this.MoveLayer(this.getX(), (int)mY - (this.getHeight() / 2)); + } + } + + @Override + public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { + // We intentionally switch the scroll direction since it is backwards + // The number set to is the speed of scrolling + if (verticalAmount > 0) { + verticalAmount = -3; + } else { + verticalAmount = 3; + } + + + int newY = this.getY() + (int) verticalAmount; + System.out.println("Mouse move. newY: " + newY + " -> this.getY()=" + this.getY()); + if (newY >= this.scrollbarStart-12 && newY <= this.scrollbarEnd-9) { + this.MoveLayer(this.getX(), newY); + } + + return true; + } + + @Override + public boolean mouseClicked(double mouseX, double mouseY, int button) { + SetDragging(true); + return true; + } + + @Override + public boolean mouseReleased(double mouseX, double mouseY, int button) { + SetDragging(false); + return true; + } + + public Boolean IsDragging() { + return this.isDragging; + } + + public void SetDragging(boolean b) { + System.out.println("Toggling dragging mode on scrollbar"); + this.isDragging = b; + } + + @Override + protected void appendClickableNarrations(NarrationMessageBuilder builder) {} +} diff --git a/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/ShopKeeperMenu.java b/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/ShopKeeperMenu.java index 83cafc0..8d36015 100644 --- a/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/ShopKeeperMenu.java +++ b/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/ShopKeeperMenu.java @@ -1,12 +1,16 @@ package jesse.keeblarcraft.gui.ShopKeeperGUI; +import jesse.keeblarcraft.Entities.ShopKeeper; import jesse.keeblarcraft.GuiMgr.ShopKeeper.ShopKeeperHandler; +import jesse.keeblarcraft.GuiMgr.ShopKeeper.ShopKeeperInventory; import jesse.keeblarcraft.Keeblarcraft; import jesse.keeblarcraft.ClientHelpers.Helper; import jesse.keeblarcraft.gui.Generics.ClickableLayer; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; import net.minecraft.text.Text; import net.minecraft.util.Identifier; @@ -15,12 +19,15 @@ import java.util.List; import java.util.Map; public class ShopKeeperMenu extends HandledScreen { - private static final Identifier MENU_TEXTURE = new Identifier(Keeblarcraft.MOD_ID, "textures/gui/shopkeeper_gui.jpeg"); - private static final Identifier ADD_BUTTON = new Identifier(Keeblarcraft.MOD_ID, "textures/gui/shopkeeper_add_icon.jpeg"); - private static final Identifier NEW_ITEM_MENU = new Identifier(Keeblarcraft.MOD_ID, "textures/gui/shopkeeper_item_slot.jpeg"); + private static final Identifier MENU_TEXTURE = new Identifier(Keeblarcraft.MOD_ID, "textures/gui/shopkeeper_gui.png"); + private static final Identifier ADD_BUTTON = new Identifier(Keeblarcraft.MOD_ID, "textures/gui/plus.png"); + private static final Identifier SCROLLBAR = new Identifier(Keeblarcraft.MOD_ID, "textures/gui/scrollbar.png"); private int x = 0; private int y = 0; private final List layers = new ArrayList<>(); + private MerchandiseScroller catalogue; + private ShopKeeperInventory serverInventory; + Scrollbar scrollbar; public ShopKeeperMenu(ShopKeeperHandler handler, PlayerInventory inventory, Text title) { super(handler, inventory, title); @@ -37,9 +44,14 @@ public class ShopKeeperMenu extends HandledScreen { this.backgroundHeight = 256; this.x = (width - backgroundWidth) / 2; this.y = (height - backgroundHeight) / 2; + scrollbar = new Scrollbar(SCROLLBAR, Text.of("scrollbar"), 15, 28, x+243, y+40, y+50, 163); // Add all layers below - AddNewButton(ADD_BUTTON, Text.of("ADD ITEM BUTTON"), x, y, 64, 64); + AddNewButton(ADD_BUTTON, Text.of("ADD ITEM BUTTON"), x+20, y+20, 8, 8); + AddNewLayer(scrollbar); + + catalogue = new MerchandiseScroller(this.getScreenHandler().GetInventory()); + System.out.println("This store catalogue has size " + catalogue.Size()); } @Override @@ -50,17 +62,25 @@ public class ShopKeeperMenu extends HandledScreen { // context.drawTexture(NEW_ITEM_MENU, this.x, this.y, 0, 0, 32, 24); // context.drawTexture(NEW_ITEM_MENU, this.x, this.y, 0, 0, 32, 24, 32, 24); -// this.getScreenHandler().showSlot("new_item", "add_item_slot"); + this.getScreenHandler().showSlot("add_item_menu", "add_item_slot"); + // TODO: Temporary to just prove a point that we can draw item icons in the menu + ItemStack tempStack = Items.ACACIA_DOOR.getDefaultStack(); + + + // Draws primary layers first for (ClickableLayer layer : layers) { layer.renderButton(context, mouseX, mouseY, delta); ToggleSlots(layer.GetLayerName().getString(), layer.GetDrawableSlots()); + // If a primary layer happens to want sub-layers in itself; we draw those here for (ClickableLayer subLayer : layer.GetSubLayers()) { subLayer.renderButton(context, mouseX, mouseY, delta); ToggleSlots(subLayer.GetLayerName().getString(), subLayer.GetDrawableSlots()); } + // TODO: HACK to see if this works + context.drawItem(tempStack, this.x, this.y); // TODO: REMOVE // We only notify the parent to update sub layers. It must manage its own sub layers layer.UpdateSubLayers(); } @@ -69,10 +89,10 @@ public class ShopKeeperMenu extends HandledScreen { private void ToggleSlots(String menuName, Map slotNames) { for (Map.Entry slot : slotNames.entrySet()) { if (slot.getValue()) { - System.out.println("Attempting to turn slot " + slot.getKey() + " to value " + slot.getValue()); +// System.out.println("Attempting to turn slot " + slot.getKey() + " to value " + slot.getValue()); this.getScreenHandler().showSlot(menuName, slot.getKey()); } else { - System.out.println("Attempting to turn slot " + slot.getKey() + " to value " + slot.getValue()); +// System.out.println("Attempting to turn slot " + slot.getKey() + " to value " + slot.getValue()); this.getScreenHandler().hideSlot(menuName, slot.getKey()); } } @@ -83,6 +103,10 @@ public class ShopKeeperMenu extends HandledScreen { layers.add(new NewItemButton(iconId, layerName, imgWidth, imgHeight, drawX, drawY)); } + private void AddNewLayer(ClickableLayer layer) { + layers.add(layer); + } + @Override public void drawForeground(DrawContext context, int mouseX, int mouseY) { // We override this function to intentionally do nothing @@ -108,6 +132,69 @@ public class ShopKeeperMenu extends HandledScreen { return true; } + @Override + public boolean mouseReleased(double mouseX, double mouseY, int button) { + scrollbar.SetDragging(false); + + for (ClickableLayer layer : layers) { + // Scrollbar gets special handling above this. Ignore in loop + if (layer.GetLayerName().getString().equals("scrollbar")) { + continue; + } + // Check main layer first + if (Helper.WithinBounds(layer.getX(), layer.getY(), layer.getWidth(), layer.getHeight(), mouseX, mouseY)) { + layer.mouseReleased(mouseX, mouseY, button); + } + + for (ClickableLayer subLayer : layer.GetSubLayers()) { + + if (subLayer.visible && Helper.WithinBounds(subLayer.getX(), subLayer.getY(), subLayer.getWidth(), subLayer.getHeight(), mouseX, mouseY)) { + subLayer.mouseReleased(mouseX, mouseY, button); + } + } + } + + return true; + } + + @Override + public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { + System.out.println("Mouse scrolled. Vert amount is: " + verticalAmount); + scrollbar.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount); + return true; + } + + + + @Override + public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) { +// super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY); + if (scrollbar.IsDragging()) { + scrollbar.mouseDragged(mouseX, mouseY, button, deltaX, deltaY); + } + + for (ClickableLayer layer : layers) { + // Scrollbar layer gets special handling above this for loop. Skip here + if (layer.GetLayerName().getString().equals("scrollbar")) { + continue; + } + + // Check main layer first + if (Helper.WithinBounds(layer.getX(), layer.getY(), layer.getWidth(), layer.getHeight(), mouseX, mouseY)) { + layer.mouseDragged(mouseX, mouseY, button, deltaX, deltaY); + } + + for (ClickableLayer subLayer : layer.GetSubLayers()) { + + if (subLayer.visible && Helper.WithinBounds(subLayer.getX(), subLayer.getY(), subLayer.getWidth(), subLayer.getHeight(), mouseX, mouseY)) { + subLayer.mouseDragged(mouseX, mouseY, button, deltaX, deltaY); + } + } + } + + return true; + } + // Check if a click point is within the context of a square (square = x, y, w, h) // public static boolean WithinBounds(double x, double y, double w, double h, double clickX, double clickY) { //// System.out.println("Mouse click X Y: " + clickX + " " + clickY); diff --git a/src/main/java/jesse/keeblarcraft/Entities/ShopKeeper.java b/src/main/java/jesse/keeblarcraft/Entities/ShopKeeper.java index 6308ef4..c22f206 100644 --- a/src/main/java/jesse/keeblarcraft/Entities/ShopKeeper.java +++ b/src/main/java/jesse/keeblarcraft/Entities/ShopKeeper.java @@ -26,6 +26,7 @@ public class ShopKeeper extends VillagerEntity { } private void BeginTrades(PlayerEntity player) { + System.out.println("Beginning trades with player"); super.setCustomer(player); this.sendOffers(player, this.getDisplayName(), this.getVillagerData().getLevel()); } diff --git a/src/main/java/jesse/keeblarcraft/GuiMgr/Factions/FactionBlockScreenHandler.java b/src/main/java/jesse/keeblarcraft/GuiMgr/Factions/FactionBlockScreenHandler.java index ea85711..20a9156 100644 --- a/src/main/java/jesse/keeblarcraft/GuiMgr/Factions/FactionBlockScreenHandler.java +++ b/src/main/java/jesse/keeblarcraft/GuiMgr/Factions/FactionBlockScreenHandler.java @@ -79,7 +79,6 @@ public class FactionBlockScreenHandler extends ScreenHandler { return newStack; } - // From Kaupenjoe video private void addPlayerInventory(PlayerInventory playerInventory) { int spacing = -8; for (int i = 0; i < 3; ++i) { // Rows @@ -92,7 +91,6 @@ public class FactionBlockScreenHandler extends ScreenHandler { } } - // From Kaupenjoe video private void addPlayerHotbar(PlayerInventory playerInventory) { int spacing = -8; for (int i = 0; i < 9; ++i) { diff --git a/src/main/java/jesse/keeblarcraft/GuiMgr/ShopKeeper/ShopKeeperHandler.java b/src/main/java/jesse/keeblarcraft/GuiMgr/ShopKeeper/ShopKeeperHandler.java index 66516b4..5d14895 100644 --- a/src/main/java/jesse/keeblarcraft/GuiMgr/ShopKeeper/ShopKeeperHandler.java +++ b/src/main/java/jesse/keeblarcraft/GuiMgr/ShopKeeper/ShopKeeperHandler.java @@ -1,5 +1,6 @@ package jesse.keeblarcraft.GuiMgr.ShopKeeper; +import jesse.keeblarcraft.ConfigMgr.ConfigManager; import jesse.keeblarcraft.GuiMgr.ScreenHandlerRegistration; import jesse.keeblarcraft.Utils.CustomSlot; import net.minecraft.entity.player.PlayerEntity; @@ -18,12 +19,18 @@ import java.util.Map; public class ShopKeeperHandler extends ScreenHandler { private Merchant merchant; + private ShopKeeperInventory shopKeeperInventory; private MerchantInventory merchantInventory; + ConfigManager config = new ConfigManager(); + String shopName; + // 0 size is default to prevent null. Inventory expanded later + +// private final DefaultedList merchantInventory = DefaultedList.ofSize(0, ItemStack.EMPTY); private boolean canRefreshTrades = false; private boolean isLeveledMerchant = false; private int levelAmount = 0; private int merchantExperience = 0; - private Map slotIdByName = new HashMap<>(); + private Map slotIdByName = new HashMap<>(); ///TODO: Is this deprecated? Seems unused ShopKeeperSlots allSlots = new ShopKeeperSlots(); public ShopKeeperHandler(int syncId, PlayerInventory playerInventory) { @@ -32,12 +39,26 @@ public class ShopKeeperHandler extends ScreenHandler { public ShopKeeperHandler(int syncId, PlayerInventory playerInventory, Merchant merchant) { super(ScreenHandlerRegistration.SHOP_KEEPER_HANDLER_SCREEN_HANDLER_TYPE, syncId); + this.shopName = playerInventory.player.getEntityName(); ///TODO: Needs to be pulled from a shop manager this.merchant = merchant; this.merchantInventory = new MerchantInventory(merchant); + merchantInventory.onOpen(playerInventory.player); // not sure if this is doing anything + this.shopKeeperInventory = new ShopKeeperInventory(merchantInventory); + addPlayerHotbar(playerInventory); RegisterSlots(); - // Add slots below -// this.addSlot(new Slot(this.merchantInventory, 0, 136, 37)); -// this.addSlot(new CustomSlot(this.merchantInventory, 0, 136, 37), Text.of("test")); + } + + public ShopKeeperInventory GetInventory() { + String name = "shops/" + shopName; + if (config.DoesFileExist(name)) { + /// TODO: Add system to pull json shop stuff + System.out.println("Shop exists."); + } else { + System.out.println("[NOWARN]: ShopKeep inventory not found for this shop. Creating one..."); + config.CreateFile(name); + } + + return this.shopKeeperInventory; } public void RegisterSlots() { @@ -90,14 +111,47 @@ public class ShopKeeperHandler extends ScreenHandler { this.canRefreshTrades = isRefreshable; } + // This is just for SHIFT+CLICK moving @Override - public ItemStack quickMove(PlayerEntity player, int slot) { - return null; + public ItemStack quickMove(PlayerEntity player, int invSlot) { + System.out.println("Is client: " + player.getWorld().isClient()); + ItemStack newStack = ItemStack.EMPTY; + Slot slot = this.slots.get(invSlot); + if (slot.hasStack()) { + ItemStack originalStack = slot.getStack(); + newStack = originalStack.copy(); + + // TODO: This is from the YT video and it looks atrocious. Refactor this later + if ((invSlot < this.merchantInventory.size() && !this.insertItem(originalStack, this.merchantInventory.size(), this.slots.size(), true)) || + (!this.insertItem(originalStack, 0, this.merchantInventory.size(), false))) { + return ItemStack.EMPTY; + } + + if (originalStack.isEmpty()) { + slot.setStack(ItemStack.EMPTY); + } else { + slot.markDirty();; + } + } + return newStack; + } + + private void addPlayerHotbar(PlayerInventory playerInventory) { + int spacing = -8; + for (int i = 0; i < 9; ++i) { + // int x = (8 + i * 18) + spacing; // Texture draw position + int x = i * 22 + spacing; // Texture draw position + int y = 162; // Texture draw position + this.addSlot(new Slot(playerInventory, i, x, y)); + } } // Called every tick @Override public boolean canUse(PlayerEntity player) { +// System.out.println("canUse called on screen handler"); +// System.out.println("Can player use? " + this.merchantInventory.canPlayerUse(player)); +// System.out.println("Current customer is : " + this.merchantInventory.); return true; } } diff --git a/src/main/java/jesse/keeblarcraft/GuiMgr/ShopKeeper/ShopKeeperInventory.java b/src/main/java/jesse/keeblarcraft/GuiMgr/ShopKeeper/ShopKeeperInventory.java new file mode 100644 index 0000000..1e9bfd0 --- /dev/null +++ b/src/main/java/jesse/keeblarcraft/GuiMgr/ShopKeeper/ShopKeeperInventory.java @@ -0,0 +1,35 @@ +package jesse.keeblarcraft.GuiMgr.ShopKeeper; + +import net.minecraft.village.MerchantInventory; + +import java.util.ArrayList; +import java.util.List; + +public class ShopKeeperInventory { + private final List items; + private final MerchantInventory merchantInventory; + + public ShopKeeperInventory(MerchantInventory merchantInventory) { + items = new ArrayList(); + // This is temporary to see if this stuff works client->server->client etc + items.add(new StoreItem("Among Us Statue", "$$$$$$$$$$", 10000)); + this.merchantInventory = merchantInventory; + } + + public List GetItems() { + return this.items; + } + + public Integer Size() { + System.out.println("Size called..."); + return this.items.size(); + } + + public void Add(StoreItem item) { + this.items.add(item); + } + + public void Remove(String upc) { + this.items.removeIf(item -> item.equals(upc)); + } +} diff --git a/src/main/java/jesse/keeblarcraft/GuiMgr/ShopKeeper/ShopKeeperSlots.java b/src/main/java/jesse/keeblarcraft/GuiMgr/ShopKeeper/ShopKeeperSlots.java index 399e18c..f4dca16 100644 --- a/src/main/java/jesse/keeblarcraft/GuiMgr/ShopKeeper/ShopKeeperSlots.java +++ b/src/main/java/jesse/keeblarcraft/GuiMgr/ShopKeeper/ShopKeeperSlots.java @@ -3,13 +3,14 @@ package jesse.keeblarcraft.GuiMgr.ShopKeeper; import jesse.keeblarcraft.Utils.CustomSlot; import java.util.HashMap; -import java.util.List; import java.util.Map; // Until I find the will and way to mixin slots to be able to be removed (i.e: not backed by an Inventory) I am patching // slots in its own registration class (like ShopKeeperSlots). The time to do the mixin stuff far exceeds what is worth // it for the time being. public class ShopKeeperSlots { + // Key = The GUI menu the slot belongs to. Helpful in parsing + // Value = Map Key = Name of slot; Value = Slot itself. Name of slot is helpful for parsing if set private final Map> shopKeeperSlots = new HashMap<>(); public ShopKeeperSlots() {} diff --git a/src/main/java/jesse/keeblarcraft/GuiMgr/ShopKeeper/StoreItem.java b/src/main/java/jesse/keeblarcraft/GuiMgr/ShopKeeper/StoreItem.java new file mode 100644 index 0000000..2467e81 --- /dev/null +++ b/src/main/java/jesse/keeblarcraft/GuiMgr/ShopKeeper/StoreItem.java @@ -0,0 +1,30 @@ +package jesse.keeblarcraft.GuiMgr.ShopKeeper; + +// All the custom content that a store item will have. Handled by @see MerchandiseScroller.java +public class StoreItem { + private Integer itemCost; + private String itemName; + private String upc; + + public StoreItem(String itemName, String upc, Integer cost) { + this.itemName = itemName; + this.upc = upc; + this.itemCost = cost; + } + + public String GetName() { + return itemName; + } + + public String GetUPC() { + return this.upc; + } + + public Integer GetCost() { + return this.itemCost; + } + + public boolean equals(String other) { + return upc.equals(other); + } +} diff --git a/src/main/resources/assets/keeblarcraft/textures/gui/minus.png b/src/main/resources/assets/keeblarcraft/textures/gui/minus.png new file mode 100644 index 0000000..46b1943 Binary files /dev/null and b/src/main/resources/assets/keeblarcraft/textures/gui/minus.png differ diff --git a/src/main/resources/assets/keeblarcraft/textures/gui/plus.png b/src/main/resources/assets/keeblarcraft/textures/gui/plus.png new file mode 100644 index 0000000..1616bc7 Binary files /dev/null and b/src/main/resources/assets/keeblarcraft/textures/gui/plus.png differ diff --git a/src/main/resources/assets/keeblarcraft/textures/gui/scrollbar.png b/src/main/resources/assets/keeblarcraft/textures/gui/scrollbar.png new file mode 100644 index 0000000..0a82783 Binary files /dev/null and b/src/main/resources/assets/keeblarcraft/textures/gui/scrollbar.png differ diff --git a/src/main/resources/assets/keeblarcraft/textures/gui/shopkeeper_add_icon.jpeg b/src/main/resources/assets/keeblarcraft/textures/gui/shopkeeper_add_icon.jpeg deleted file mode 100644 index 6319a82..0000000 Binary files a/src/main/resources/assets/keeblarcraft/textures/gui/shopkeeper_add_icon.jpeg and /dev/null differ diff --git a/src/main/resources/assets/keeblarcraft/textures/gui/shopkeeper_gui.jpeg b/src/main/resources/assets/keeblarcraft/textures/gui/shopkeeper_gui.jpeg deleted file mode 100644 index 41b5794..0000000 Binary files a/src/main/resources/assets/keeblarcraft/textures/gui/shopkeeper_gui.jpeg and /dev/null differ diff --git a/src/main/resources/assets/keeblarcraft/textures/gui/shopkeeper_gui.png b/src/main/resources/assets/keeblarcraft/textures/gui/shopkeeper_gui.png new file mode 100644 index 0000000..70d827b Binary files /dev/null and b/src/main/resources/assets/keeblarcraft/textures/gui/shopkeeper_gui.png differ diff --git a/src/main/resources/assets/keeblarcraft/textures/gui/shopkeeper_item_slot.jpeg b/src/main/resources/assets/keeblarcraft/textures/gui/shopkeeper_item_slot.jpeg deleted file mode 100644 index 8e051c3..0000000 Binary files a/src/main/resources/assets/keeblarcraft/textures/gui/shopkeeper_item_slot.jpeg and /dev/null differ diff --git a/src/main/resources/assets/keeblarcraft/textures/gui/shopkeeper_item_slot.png b/src/main/resources/assets/keeblarcraft/textures/gui/shopkeeper_item_slot.png new file mode 100644 index 0000000..0100593 Binary files /dev/null and b/src/main/resources/assets/keeblarcraft/textures/gui/shopkeeper_item_slot.png differ diff --git a/src/main/resources/assets/keeblarcraft/textures/gui/shopkeeper_scrollbar.jpeg b/src/main/resources/assets/keeblarcraft/textures/gui/shopkeeper_scrollbar.jpeg deleted file mode 100644 index 0c46d57..0000000 Binary files a/src/main/resources/assets/keeblarcraft/textures/gui/shopkeeper_scrollbar.jpeg and /dev/null differ diff --git a/src/main/resources/assets/keeblarcraft/textures/gui/shopkeeper_subtract.png b/src/main/resources/assets/keeblarcraft/textures/gui/shopkeeper_subtract.png deleted file mode 100644 index 4d3baae..0000000 Binary files a/src/main/resources/assets/keeblarcraft/textures/gui/shopkeeper_subtract.png and /dev/null differ