From 81227cf388fd37d89c6405ae528a8a0e323e34a3 Mon Sep 17 00:00:00 2001 From: Jkibbels Date: Fri, 28 Mar 2025 17:47:09 -0400 Subject: [PATCH] #3 Added rendered cart price and arrows in item now work and correctly increase and decrease item amount --- .../gui/Generics/ClickableLayer.java | 13 ++ .../gui/ShopKeeperGUI/DrawableStoreItem.java | 169 +++++++++++++++--- .../ShopKeeperGUI/MerchandiseScroller.java | 86 ++++----- .../gui/ShopKeeperGUI/Scrollbar.java | 5 +- .../gui/ShopKeeperGUI/ShopKeeperMenu.java | 65 ++++--- .../ShopKeeper/ShopKeeperInventory.java | 2 +- .../GuiMgr/ShopKeeper/StoreItem.java | 6 +- 7 files changed, 246 insertions(+), 100 deletions(-) diff --git a/src/client/java/jesse/keeblarcraft/gui/Generics/ClickableLayer.java b/src/client/java/jesse/keeblarcraft/gui/Generics/ClickableLayer.java index fc54f66..f1a2ecb 100644 --- a/src/client/java/jesse/keeblarcraft/gui/Generics/ClickableLayer.java +++ b/src/client/java/jesse/keeblarcraft/gui/Generics/ClickableLayer.java @@ -44,6 +44,19 @@ abstract public class ClickableLayer extends ClickableWidget { this.setY(startY); } + // Helpful for debugging an image coordinates very fast. + // Algorithm: + // - Subtracts down the mX and mY by the this.getX() and this.getY() values as if it was normalized on 0 + // + This helps see where a coordinate legitimately is on a layer/image + protected void PrintMouseClick(double mX, double mY) { + System.out.println("Normalized mX mY: " + (mX - this.getX()) + " " + (mY - this.getY())); + } + + // Only call this function if the value being passed in are not correctly being 0,0 in the top left of the layer + protected Pair NormalizeCoordinates(double rawMX, double rawMY) { + return new Pair<>(rawMX - this.getX(), rawMY - this.getY()); + } + protected void AddSubLayer(ClickableLayer newLayer) { subLayers.add(newLayer); } diff --git a/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/DrawableStoreItem.java b/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/DrawableStoreItem.java index 4e2c465..fa44db5 100644 --- a/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/DrawableStoreItem.java +++ b/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/DrawableStoreItem.java @@ -1,7 +1,9 @@ package jesse.keeblarcraft.gui.ShopKeeperGUI; import jesse.keeblarcraft.Keeblarcraft; +import jesse.keeblarcraft.Utils.CommonStructures.Pair; import jesse.keeblarcraft.gui.Generics.ClickableLayer; +import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; import net.minecraft.item.ItemStack; @@ -12,24 +14,127 @@ import net.minecraft.util.Identifier; public class DrawableStoreItem extends ClickableLayer { // Names are hard. ITEM_ICON is the actual SLOT icon itself; not the in-game item!!!! private static final Identifier ITEM_ICON = new Identifier(Keeblarcraft.MOD_ID, "textures/gui/shopkeeper_item_slot.png"); - private Integer itemCost; - private String itemName; + private double itemCost = 0.0; + private String itemName = ""; private Integer amountSelected = 0; ItemStack itemTextureId; - public DrawableStoreItem(String itemName, Integer itemCost, ItemStack itemTextureId) { + // Increment counter + private static class UpSelectionArrow { + // Please use this parent class (ClickableLayer) debug print to find these coordinates if they move (func: PrintMouseClick()) + // X Y Pair + public static Pair top = new Pair<>(64.0, 12.0); + public static Pair bottomLeft = new Pair<>(47.0, 21.0); + public static Pair bottomRight = new Pair<>(82.0, 21.0); + } + + // Decrement counter + private static class DownSelectionArrow { + // Please use this parent class (ClickableLayer) debug print to find these coordinates if they move (func: PrintMouseClick()) + // X Y Pair + public static Pair topLeft = new Pair<>(47.0, 39.0); + public static Pair topRight = new Pair<>(82.0, 39.0); + public static Pair bottom = new Pair<>(64.0, 48.0); + } + + private static class TextPosition { + public static Pair UNIT_PRICE = new Pair<>(44.0, 1.0); // Area on widget that displays price per unit + public static Pair FINAL_PRICE = new Pair<>(0.0, 0.0); // TODO: TBD + public static Pair BUY_AMOUNT = new Pair<>(48.0, 26.0); // TODO: TBD + } + + private enum CLICKED_SELECTION_ARROW { + NONE, + TOP, + DOWN + } + + // Helper function to calculate area of a triangle + private static double CalculateTriangleArea(int x1, int y1, int x2, int y2, int x3, int y3) + { + return Math.abs((x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 2.0); + } + + // Algorithm explained: + // Let's call the points of the triangle ABC, we first calculate the area of this triangle with the following: + // Eq: AREA = [x1(y2-y3) + x2(y3 - y1) + x3(y1 - y2)] / 2 + // + // Now let's make 3 more areas; but instead of using ABC we will introduce point P and replace it with each letter + // and calculate that area. That means we have the entire triangle area (ABC), then area 1 (ABP), then + // area 2 (APC), then finally area 3 (PBC). The summation of these 3 areas should be equal to the global area we + // originally calculated + // + // Note: Pair is a pair with the first being an X coordinate and second being Y (Pair) + private Boolean TriangleBoundsCheck(Pair POINT_A, + Pair POINT_B, + Pair POINT_C, + Pair point) { + Boolean inBounds = false; + double totalArea = CalculateTriangleArea((int)Math.floor(POINT_A.GetKey()), (int)Math.floor(POINT_A.GetValue()), + (int)Math.floor(POINT_B.GetKey()), (int)Math.floor(POINT_B.GetValue()), + (int)Math.floor(POINT_C.GetKey()), (int)Math.floor(POINT_C.GetValue())); + + double areaOne = CalculateTriangleArea((int)Math.floor(POINT_A.GetKey()), (int)Math.floor(POINT_A.GetValue()), + (int)Math.floor(POINT_B.GetKey()), (int)Math.floor(POINT_B.GetValue()), + (int)Math.floor(point.GetKey()), (int)Math.floor(point.GetValue())); + + double areaTwo = CalculateTriangleArea((int)Math.floor(POINT_A.GetKey()), (int)Math.floor(POINT_A.GetValue()), + (int)Math.floor(point.GetKey()), (int)Math.floor(point.GetValue()), + (int)Math.floor(POINT_C.GetKey()), (int)Math.floor(POINT_C.GetValue())); + + double areaThree = CalculateTriangleArea((int)Math.floor(point.GetKey()), (int)Math.floor(point.GetValue()), + (int)Math.floor(POINT_B.GetKey()), (int)Math.floor(POINT_B.GetValue()), + (int)Math.floor(POINT_C.GetKey()), (int)Math.floor(POINT_C.GetValue())); + +// System.out.println("Area one: " + areaOne); +// System.out.println("Area two: " + areaTwo); +// System.out.println("Area three: " + areaThree); +// System.out.println("MX MY: " + point.GetKey() + " " + point.GetValue()); +// double addedArea = areaOne + areaTwo + areaThree; +// System.out.println("Total area: " + totalArea); +// System.out.println("Added areas: " + addedArea); +// System.out.println("Triangle selected? " + (totalArea == (areaOne + areaTwo + areaThree))); + + return totalArea == (areaOne + areaTwo + areaThree); + } + + // This function solves two things at once; if a selection point is within the bounds of a selection arrow + // and determines which arrow it is if either. + private CLICKED_SELECTION_ARROW InArrowBounds(double mX, double mY) { + CLICKED_SELECTION_ARROW inBounds = CLICKED_SELECTION_ARROW.NONE; + boolean isTopArrow = false; + boolean isBottomArrow = false; + + // Check if click is the top triangle then bottom triangle (if it's not bottom triangle obvs) + isTopArrow = TriangleBoundsCheck(UpSelectionArrow.bottomLeft, UpSelectionArrow.top, UpSelectionArrow.bottomRight, new Pair<>(mX, mY)); + + if (!isTopArrow) { + isBottomArrow = TriangleBoundsCheck(DownSelectionArrow.topLeft, DownSelectionArrow.topRight, DownSelectionArrow.bottom, new Pair<>(mX, mY)); + } + + if (isTopArrow) { + inBounds = CLICKED_SELECTION_ARROW.TOP; + } else if (isBottomArrow) { + inBounds = CLICKED_SELECTION_ARROW.DOWN; + } + + return inBounds; + } + + public DrawableStoreItem(String itemName, Double itemCost, ItemStack itemTextureId) { this(itemName, itemCost, Text.of(""), 85, 50); this.itemTextureId = itemTextureId; } - public DrawableStoreItem(String itemName, Integer itemCost, Text layerName, int width, int height) { + public DrawableStoreItem(String itemName, Double itemCost, Text layerName, int width, int height) { super(ITEM_ICON, layerName, width, height, 0, 0); this.itemCost = itemCost; this.itemName = itemName; } - public Integer GetPrice() { - return this.itemCost; + + public Double GetPrice() { + return this.itemCost * this.amountSelected; } public String GetName() { @@ -37,8 +142,32 @@ public class DrawableStoreItem extends ClickableLayer { } public void Add() { - ++this.amountSelected; - System.out.println("Current buy amount: " + this.amountSelected); + if (this.amountSelected < 99) { + ++this.amountSelected; + } + } + + public void Subtract() { + if (this.amountSelected > 0) { + --this.amountSelected; + } + } + + @Override + public boolean mouseClicked(double mX, double mY, int button) { +// PrintMouseClick(mX, mY); + // Normalize the mouse selection + Pair normalizedClick = NormalizeCoordinates(mX, mY); + CLICKED_SELECTION_ARROW arrowPressed = InArrowBounds(normalizedClick.GetKey(), normalizedClick.GetValue()); + + if (arrowPressed == CLICKED_SELECTION_ARROW.TOP) { + Add(); + } + else if (arrowPressed == CLICKED_SELECTION_ARROW.DOWN) { + Subtract(); + } + + return true; } @Override @@ -47,26 +176,22 @@ public class DrawableStoreItem extends ClickableLayer { // Now we want to draw the item icon in the icon slot if (this.itemTextureId != null) { + // I have no idea if it really ever CAN be null in practicality + if (MinecraftClient.getInstance() != null) { + int unitPriceXPos = this.getX() + TextPosition.UNIT_PRICE.GetKey().intValue(); + int unitPriceYPos = this.getY() + TextPosition.UNIT_PRICE.GetValue().intValue(); + context.drawText(MinecraftClient.getInstance().textRenderer, Text.of(Double.toString(this.itemCost)), unitPriceXPos, unitPriceYPos, 4, false); + + int buyAmountXPos = this.getX() + TextPosition.BUY_AMOUNT.GetKey().intValue(); + int buyAmountYPos = this.getY() + TextPosition.BUY_AMOUNT.GetValue().intValue(); + context.drawText(MinecraftClient.getInstance().textRenderer, Text.of(this.amountSelected.toString()), buyAmountXPos, buyAmountYPos, 100, false); + } context.drawItem(this.itemTextureId, this.getX() + 13, this.getY() + 22); // TODO: Need to correct offest to draw } else { // TODO: Add default icon to draw if no texture is set or could be found for item } } - 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 index 69e7de1..599d4f7 100644 --- a/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/MerchandiseScroller.java +++ b/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/MerchandiseScroller.java @@ -18,7 +18,7 @@ public class MerchandiseScroller extends ClickableLayer { private final ShopKeeperInventory storeInventory; private int scrollAmount = 0; // Indicator for how many tickets the scrollbar is down private final int maxDisplayItems = 6; - + private boolean resetDrawLayers = true; // Key = item name // Value = the drawable slot for it @@ -33,63 +33,67 @@ public class MerchandiseScroller extends ClickableLayer { } public void UpdateScrollAmount(double amount) { - + ClearSubLayers(); + resetDrawLayers = true; this.scrollAmount = (int) Math.floor(amount * 100); -// System.out.println("Scroll amount is: " + scrollAmount + " from " + amount); } @Override public void renderButton(DrawContext context, int mouseX, int mouseY, float delta) { - // scrollAmount is our indicator for where to start in the list to draw going +6 past it - int drawX = this.getX()+10; - int drawY = this.getY()+5; - int xScalar = 0; - int yScalar = 0; - int oscillator = 0; + // We only re-render buttons when the catalogue has been scrolled or accessed in some other way + if (resetDrawLayers) { + int drawX = this.getX() + 10; + int drawY = this.getY() + 5; + int xScalar = 0; + int yScalar = 0; + int oscillator = 0; -// System.out.println("[Merch]: Store size = " + storeInventory.Size()); -// System.out.println("[Merch]: Draw list size: " + drawList.size()); - for (int i = scrollAmount; i < scrollAmount + maxDisplayItems; i++) { - // Make sure we are within the bounds of the size - if (i < drawList.size()) { - DrawableStoreItem storeItem = drawList.get(i); -// System.out.println("[Merch]: Item found. Name of item: " + storeItem.GetName() + ". Price: " + storeItem.GetPrice()); -// System.out.println("DRAWX DRAWY WIDTH HEIGHT: " + drawX + " " + drawY + " " + storeItem.getWidth() + " " + storeItem.getHeight()); - // uv values can be changed for smooth scrolling in the future; but for now with jar-scrolling we will be - // scrolling at least 1 height value of the store stuff - storeItem.ResetLayer(drawX, drawY, storeItem.getWidth(), storeItem.getHeight()); - storeItem.renderButton(context, mouseX, mouseY, delta); // The draw item will draw out its contents like item icons, menu info, etc + for (int i = scrollAmount; i < scrollAmount + maxDisplayItems; i++) { + // Make sure we are within the bounds of the size + if (i < drawList.size()) { + DrawableStoreItem storeItem = drawList.get(i); + // uv values can be changed for smooth scrolling in the future; but for now with jar-scrolling we will be + // scrolling at least 1 height value of the store stuff + storeItem.ResetLayer(drawX, drawY, storeItem.getWidth(), storeItem.getHeight()); + AddSubLayer(storeItem); + if (oscillator % 2 == 0) { + // Even implies we are going to odd; which means this is xScalar + 1 + xScalar++; + oscillator++; + } else { + yScalar++; + xScalar--; + oscillator--; + } - if (oscillator % 2 == 0) { - // Even implies we are going to odd; which means this is xScalar+1 - xScalar++; -// yScalar--; - oscillator++; - } else { - yScalar++; - xScalar--; - oscillator--; + // drawX and drawY must start in top left of grid -> then add a scalar. + // this.getX() + 10 means the MINIMUM spacer is 10 off the X axis + // - width + 15 means spacer is 15 pix * xScalar (first or second in row) + // this.getY() + 5 means the MINIMUM spacer is 5 off the Y axi + // - height + 5 mean 5 pixels between each row + drawX = this.getX() + 10 + ((storeItem.getWidth() + 15) * xScalar); + drawY = this.getY() + 5 + ((storeItem.getHeight() + 5) * yScalar); } - - // drawX and drawY must start in top left of grid -> then add a scalar. - // this.getX() + 10 means the MINIMUM spacer is 10 off the X axis - // - width + 15 means spacer is 15 pix * xScalar (first or second in row) - // this.getY() + 5 means the MINIMUM spacer is 5 off the Y axi - // - height + 5 mean 5 pixels between each row -// System.out.println("X Scalar: " + xScalar); -// System.out.println("Y scalar: " + yScalar); - drawX = this.getX() + 10 + ((storeItem.getWidth() + 15) * xScalar); - drawY = this.getY() + 5 + ((storeItem.getHeight() + 5) * yScalar); } + resetDrawLayers = false; } } + public Double GetCartTotal() { + Double finalPrice = 0.0; + for (Map.Entry storeItem : this.drawableInventory.entrySet()) { + finalPrice += storeItem.getValue().GetPrice(); + } + return finalPrice; + } + public Integer Size() { return storeInventory.Size(); } public void Add(StoreItem item) { storeInventory.Add(item); + System.out.println("Item cost is " + item.GetCost()); drawableInventory.put(item.GetUPC(), new DrawableStoreItem(item.GetName(), item.GetCost(), item.GetItem())); ResizeDrawlist(); } @@ -104,8 +108,6 @@ public class MerchandiseScroller extends ClickableLayer { for (Map.Entry entry : drawableInventory.entrySet()) { drawList.add(entry.getValue()); } - - System.out.println("Resized draw list. Size is now " + drawList.size()); } @Override diff --git a/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/Scrollbar.java b/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/Scrollbar.java index 1c30890..c500aa6 100644 --- a/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/Scrollbar.java +++ b/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/Scrollbar.java @@ -72,11 +72,11 @@ public class Scrollbar extends ClickableLayer { int newY = this.getY() + (int) verticalAmount; - System.out.println("Mouse move. newY: " + newY + " -> this.getY()=" + this.getY()); +// System.out.println("Mouse move. newY: " + newY + " -> this.getY()=" + this.getY()); // For the time being these values are going to stick and feel the best with the scrollbar // Probably should be fixed in the future so no magic numbers need to exist here. Oh well. - if (newY >= this.scrollbarStart-12 && newY <= this.scrollbarEnd-9 && !isLocked) { + if (newY >= this.scrollbarStart - 12 && newY <= this.scrollbarEnd-9 && !isLocked) { this.MoveLayer(this.getX(), newY); UpdateScrollDistance(newY); } @@ -101,7 +101,6 @@ public class Scrollbar extends ClickableLayer { } public void SetDragging(boolean b) { - System.out.println("Toggling dragging mode on scrollbar"); this.isDragging = b; } diff --git a/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/ShopKeeperMenu.java b/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/ShopKeeperMenu.java index 17442a0..99697d8 100644 --- a/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/ShopKeeperMenu.java +++ b/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/ShopKeeperMenu.java @@ -1,16 +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.GuiMgr.ShopKeeper.StoreItem; import jesse.keeblarcraft.Keeblarcraft; import jesse.keeblarcraft.ClientHelpers.Helper; +import jesse.keeblarcraft.Utils.CommonStructures.Pair; import jesse.keeblarcraft.gui.Generics.ClickableLayer; +import net.minecraft.client.MinecraftClient; 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; @@ -28,7 +28,11 @@ public class ShopKeeperMenu extends HandledScreen { private final List layers = new ArrayList<>(); private MerchandiseScroller catalogue; private ShopKeeperInventory serverInventory; - Scrollbar scrollbar; + private Scrollbar scrollbar; + + private static class TextPosition { + public static Pair CHECKOUT_PRICE = new Pair<>(100.0, 230.0); // TODO: Probably needs to be tested + } public ShopKeeperMenu(ShopKeeperHandler handler, PlayerInventory inventory, Text title) { super(handler, inventory, title); @@ -60,24 +64,24 @@ public class ShopKeeperMenu extends HandledScreen { // This is for temporary testing - StoreItem newMerch = new StoreItem("Dirt block", "minecraft:dirt_block", 10000000, Items.DIRT.getDefaultStack()); - StoreItem newMerch2 = new StoreItem("Dirt block2", "minecraft:dirt_block2", 10000000, Items.DIRT.getDefaultStack()); - StoreItem newMerch3 = new StoreItem("Dirt block3", "minecraft:dirt_block3", 10000000, Items.DIRT.getDefaultStack()); - StoreItem newMerch4 = new StoreItem("Dirt block4", "minecraft:dirt_block4", 10000000, Items.DIRT.getDefaultStack()); - StoreItem newMerch5 = new StoreItem("Dirt block5", "minecraft:dirt_block5", 10000000, Items.DIRT.getDefaultStack()); - StoreItem newMerch6 = new StoreItem("Dirt block6", "minecraft:dirt_block6", 10000000, Items.DIRT.getDefaultStack()); - StoreItem newMerch7 = new StoreItem("Dirt block7", "minecraft:dirt_block7", 10000000, Items.DIRT.getDefaultStack()); - StoreItem newMerch8 = new StoreItem("Dirt block8", "minecraft:dirt_block8", 10000000, Items.DIRT.getDefaultStack()); - StoreItem newMerch9 = new StoreItem("Dirt block9", "minecraft:dirt_block9", 10000000, Items.DIRT.getDefaultStack()); - StoreItem newMerch10 = new StoreItem("Dirt block10", "minecraft:dirt_block10", 10000000, Items.DIRT.getDefaultStack()); - StoreItem newMerch11 = new StoreItem("Dirt block11", "minecraft:dirt_block11", 10000000, Items.DIRT.getDefaultStack()); - StoreItem newMerch12 = new StoreItem("Dirt block711", "minecraft:dirt_block12", 10000000, Items.DIRT.getDefaultStack()); - StoreItem newMerch13 = new StoreItem("Dirt block711", "minecraft:dirt_block13", 10000000, Items.DIRT.getDefaultStack()); - StoreItem newMerch14 = new StoreItem("Dirt block711", "minecraft:dirt_block14", 10000000, Items.DIRT.getDefaultStack()); - StoreItem newMerch15 = new StoreItem("Dirt block71", "minecraft:dirt_block15", 10000000, Items.DIRT.getDefaultStack()); - StoreItem newMerch16 = new StoreItem("Dirt block711111", "minecraft:dirt_block16", 10000000, Items.DIRT.getDefaultStack()); - StoreItem newMerch17 = new StoreItem("Dirt block711", "minecraft:dirt_block17", 10000000, Items.DIRT.getDefaultStack()); - StoreItem newMerch18 = new StoreItem("Dirt block711", "minecraft:dirt_block18", 10000000, Items.DIRT.getDefaultStack()); + StoreItem newMerch = new StoreItem("Dirt block", "minecraft:dirt_block", 500.0, Items.DIRT.getDefaultStack()); + StoreItem newMerch2 = new StoreItem("Dirt block2", "minecraft:dirt_block2", 500.0, Items.DIRT.getDefaultStack()); + StoreItem newMerch3 = new StoreItem("Dirt block3", "minecraft:dirt_block3", 500.0, Items.DIRT.getDefaultStack()); + StoreItem newMerch4 = new StoreItem("Dirt block4", "minecraft:dirt_block4", 500.0, Items.DIRT.getDefaultStack()); + StoreItem newMerch5 = new StoreItem("Dirt block5", "minecraft:dirt_block5", 500.0, Items.DIRT.getDefaultStack()); + StoreItem newMerch6 = new StoreItem("Dirt block6", "minecraft:dirt_block6", 500.0, Items.DIRT.getDefaultStack()); + StoreItem newMerch7 = new StoreItem("Dirt block7", "minecraft:dirt_block7", 500.0, Items.DIRT.getDefaultStack()); + StoreItem newMerch8 = new StoreItem("Dirt block8", "minecraft:dirt_block8", 500.0, Items.DIRT.getDefaultStack()); + StoreItem newMerch9 = new StoreItem("Dirt block9", "minecraft:dirt_block9", 500.0, Items.DIRT.getDefaultStack()); + StoreItem newMerch10 = new StoreItem("Dirt block10", "minecraft:dirt_block10", 500.0, Items.DIRT.getDefaultStack()); + StoreItem newMerch11 = new StoreItem("Dirt block11", "minecraft:dirt_block11", 500.0, Items.DIRT.getDefaultStack()); + StoreItem newMerch12 = new StoreItem("Dirt block711", "minecraft:dirt_block12", 500.0, Items.DIRT.getDefaultStack()); + StoreItem newMerch13 = new StoreItem("Dirt block711", "minecraft:dirt_block13", 500.0, Items.DIRT.getDefaultStack()); + StoreItem newMerch14 = new StoreItem("Dirt block711", "minecraft:dirt_block14", 500.0, Items.DIRT.getDefaultStack()); + StoreItem newMerch15 = new StoreItem("Dirt block71", "minecraft:dirt_block15", 500.0, Items.DIRT.getDefaultStack()); + StoreItem newMerch16 = new StoreItem("Dirt block711111", "minecraft:dirt_block16", 500.0, Items.DIRT.getDefaultStack()); + StoreItem newMerch17 = new StoreItem("Dirt block711", "minecraft:dirt_block17", 500.0, Items.DIRT.getDefaultStack()); + StoreItem newMerch18 = new StoreItem("Dirt block711", "minecraft:dirt_block18", 500.0, Items.DIRT.getDefaultStack()); catalogue.Add(newMerch); @@ -100,6 +104,9 @@ public class ShopKeeperMenu extends HandledScreen { catalogue.Add(newMerch18); + AddNewLayer(catalogue); + + @@ -114,16 +121,17 @@ public class ShopKeeperMenu extends HandledScreen { @Override protected void drawBackground(DrawContext context, float delta, int mouseX, int mouseY) { // Draw the menu texture first -// context.drawTexture(MENU_TEXTURE, this.x, this.y, 0, 0, this.backgroundWidth, this.backgroundHeight); context.drawTexture(MENU_TEXTURE, this.x, this.y, 0, 0, this.backgroundWidth, this.backgroundHeight, this.backgroundWidth, this.backgroundHeight); -// 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("add_item_menu", "add_item_slot"); catalogue.UpdateScrollAmount(scrollbar.GetScrollDistance()); - catalogue.renderButton(context, mouseX, mouseY, delta); - + if (MinecraftClient.getInstance() != null) { + // Draw the cart total + int cartTotalPosX = this.x + TextPosition.CHECKOUT_PRICE.GetKey().intValue(); + int cartTotalPosY = this.y + TextPosition.CHECKOUT_PRICE.GetValue().intValue(); + context.drawText(MinecraftClient.getInstance().textRenderer, Text.of("$" + catalogue.GetCartTotal().toString()), cartTotalPosX, cartTotalPosY, 4, false); + } // Draws primary layers first for (ClickableLayer layer : layers) { @@ -144,10 +152,8 @@ 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()); this.getScreenHandler().showSlot(menuName, slot.getKey()); } else { -// System.out.println("Attempting to turn slot " + slot.getKey() + " to value " + slot.getValue()); this.getScreenHandler().hideSlot(menuName, slot.getKey()); } } @@ -170,6 +176,7 @@ public class ShopKeeperMenu extends HandledScreen { @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { + System.out.println("ShopKeeperMenu MX MY: " + mouseX + " " + mouseY); for (ClickableLayer layer : layers) { // Check main layer first if (Helper.WithinBounds(layer.getX(), layer.getY(), layer.getWidth(), layer.getHeight(), mouseX, mouseY)) { @@ -214,7 +221,7 @@ public class ShopKeeperMenu extends HandledScreen { @Override public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { - System.out.println("Mouse scrolled. Vert amount is: " + verticalAmount); +// System.out.println("Mouse scrolled. Vert amount is: " + verticalAmount); scrollbar.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount); return true; } diff --git a/src/main/java/jesse/keeblarcraft/GuiMgr/ShopKeeper/ShopKeeperInventory.java b/src/main/java/jesse/keeblarcraft/GuiMgr/ShopKeeper/ShopKeeperInventory.java index 4aa19e4..e279845 100644 --- a/src/main/java/jesse/keeblarcraft/GuiMgr/ShopKeeper/ShopKeeperInventory.java +++ b/src/main/java/jesse/keeblarcraft/GuiMgr/ShopKeeper/ShopKeeperInventory.java @@ -14,7 +14,7 @@ public class ShopKeeperInventory { items = new ArrayList(); // This is temporary to see if this stuff works client->server->client etc // Also default item for now is a dirt block because why not! - items.add(new StoreItem("Among Us Statue", "$$$$$$$$$$", 10000, Items.DIRT.getDefaultStack())); + items.add(new StoreItem("Among Us Statue", "$$$$$$$$$$", 10000.0, Items.DIRT.getDefaultStack())); this.merchantInventory = merchantInventory; } diff --git a/src/main/java/jesse/keeblarcraft/GuiMgr/ShopKeeper/StoreItem.java b/src/main/java/jesse/keeblarcraft/GuiMgr/ShopKeeper/StoreItem.java index 1d75462..93a5474 100644 --- a/src/main/java/jesse/keeblarcraft/GuiMgr/ShopKeeper/StoreItem.java +++ b/src/main/java/jesse/keeblarcraft/GuiMgr/ShopKeeper/StoreItem.java @@ -4,12 +4,12 @@ import net.minecraft.item.ItemStack; // All the custom content that a store item will have. Handled by @see MerchandiseScroller.java public class StoreItem { - private Integer itemCost; + private Double itemCost = 0.0; private String itemName; private String upc; private ItemStack storeItem; - public StoreItem(String itemName, String upc, Integer cost, ItemStack storeItem) { + public StoreItem(String itemName, String upc, Double cost, ItemStack storeItem) { this.itemName = itemName; this.upc = upc; this.itemCost = cost; @@ -28,7 +28,7 @@ public class StoreItem { return this.upc; } - public Integer GetCost() { + public Double GetCost() { return this.itemCost; }