diff --git a/src/client/java/jesse/keeblarcraft/gui/FactionBlockGUI/FactionBlockScreen.java b/src/client/java/jesse/keeblarcraft/gui/FactionBlockGUI/FactionBlockScreen.java index a54f95f..f885394 100644 --- a/src/client/java/jesse/keeblarcraft/gui/FactionBlockGUI/FactionBlockScreen.java +++ b/src/client/java/jesse/keeblarcraft/gui/FactionBlockGUI/FactionBlockScreen.java @@ -4,7 +4,7 @@ package jesse.keeblarcraft.gui.FactionBlockGUI; import com.mojang.blaze3d.systems.RenderSystem; import jesse.keeblarcraft.Keeblarcraft; -import jesse.keeblarcraft.GuiMgr.FactionBlockScreenHandler; +import jesse.keeblarcraft.GuiMgr.Factions.FactionBlockScreenHandler; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.client.render.GameRenderer; diff --git a/src/client/java/jesse/keeblarcraft/gui/Generics/ClickableLayer.java b/src/client/java/jesse/keeblarcraft/gui/Generics/ClickableLayer.java index 91395b2..7fcbb12 100644 --- a/src/client/java/jesse/keeblarcraft/gui/Generics/ClickableLayer.java +++ b/src/client/java/jesse/keeblarcraft/gui/Generics/ClickableLayer.java @@ -1,5 +1,6 @@ package jesse.keeblarcraft.gui.Generics; +import jesse.keeblarcraft.Utils.CommonStructures.Pair; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; import net.minecraft.client.gui.widget.ClickableWidget; @@ -8,12 +9,15 @@ import net.minecraft.text.Text; import net.minecraft.util.Identifier; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; abstract public class ClickableLayer extends ClickableWidget { private final Identifier texture; private final Text layerName; private final List subLayers = new ArrayList<>(); + private final Map drawSlots = new HashMap<>(); // layerName is used as menu name for the screen handler protected abstract void appendClickableNarrations(NarrationMessageBuilder builder); @@ -28,17 +32,29 @@ abstract public class ClickableLayer extends ClickableWidget { } protected void ClearSubLayers() { - subLayers.clear(); + this.subLayers.clear(); } public List GetSubLayers() { - return subLayers; + return this.subLayers; + } + + public Map GetDrawableSlots() { + return this.drawSlots; + } + + public void AddDrawableSlotByName(String slotName, boolean toggled) { + this.drawSlots.put(slotName, toggled); + } + + public void ClearDrawableSlots() { + for (Map.Entry entry : this.drawSlots.entrySet()) { + entry.setValue(false); + } } // This will be called every draw frame - public void UpdateSubLayers() { - - } + public void UpdateSubLayers() {} @Override public void renderButton(DrawContext context, int mouseX, int mouseY, float delta) { diff --git a/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/NewItemButton.java b/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/NewItemButton.java index 6980261..61c82a8 100644 --- a/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/NewItemButton.java +++ b/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/NewItemButton.java @@ -14,7 +14,7 @@ public class NewItemButton extends ClickableLayer { super(texture, layerName, width, height, startX, startY); // These values may be temporary - newItemMenu = new NewItemMenu(NEW_ITEM_MENU, Text.of("Add Item"), 32, 24, this.getX() + 20, this.getY() + 20); + newItemMenu = new NewItemMenu(NEW_ITEM_MENU, Text.of("add_item_menu"), 32, 24, this.getX() + 20, this.getY() + 20); } @Override diff --git a/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/NewItemMenu.java b/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/NewItemMenu.java index bc79b13..0acca22 100644 --- a/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/NewItemMenu.java +++ b/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/NewItemMenu.java @@ -10,17 +10,19 @@ public class NewItemMenu extends ClickableLayer { private boolean isOpen = false; public NewItemMenu(Identifier texture, Text layerName, int width, int height, int startX, int startY) { super(texture, layerName, width, height, startX, startY); - System.out.println("Item menu created at coordinates X Y: " + this.getX() + " " + this.getY()); +// System.out.println("Item menu created at coordinates X Y: " + this.getX() + " " + this.getY()); } public void CloseMenu() { this.isOpen = false; this.visible = false; + this.ClearDrawableSlots(); } public void OpenMenu() { this.visible = true; this.isOpen = true; + this.AddDrawableSlotByName("add_item_slot", true); } public boolean IsOpen() { @@ -34,7 +36,8 @@ public class NewItemMenu extends ClickableLayer { // TODO: top right of the image with a 5 pixel buffer if (this.visible && Helper.WithinBounds((this.getX() + this.getWidth() - 5), this.getY(), 5, 5, x, y)) { System.out.println("User clicked fake 'X' button"); - this.isOpen = false; +// this.isOpen = false; + this.CloseMenu(); } } diff --git a/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/ShopKeeperMenu.java b/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/ShopKeeperMenu.java index 6ab3086..83cafc0 100644 --- a/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/ShopKeeperMenu.java +++ b/src/client/java/jesse/keeblarcraft/gui/ShopKeeperGUI/ShopKeeperMenu.java @@ -1,9 +1,8 @@ package jesse.keeblarcraft.gui.ShopKeeperGUI; -import jesse.keeblarcraft.GuiMgr.ShopKeeperHandler; +import jesse.keeblarcraft.GuiMgr.ShopKeeper.ShopKeeperHandler; import jesse.keeblarcraft.Keeblarcraft; import jesse.keeblarcraft.ClientHelpers.Helper; -import jesse.keeblarcraft.Utils.CustomSlot; import jesse.keeblarcraft.gui.Generics.ClickableLayer; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.ingame.HandledScreen; @@ -13,6 +12,7 @@ import net.minecraft.util.Identifier; import java.util.ArrayList; 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"); @@ -50,13 +50,15 @@ 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(Text.of("test")); +// this.getScreenHandler().showSlot("new_item", "add_item_slot"); for (ClickableLayer layer : layers) { layer.renderButton(context, mouseX, mouseY, delta); + ToggleSlots(layer.GetLayerName().getString(), layer.GetDrawableSlots()); for (ClickableLayer subLayer : layer.GetSubLayers()) { subLayer.renderButton(context, mouseX, mouseY, delta); + ToggleSlots(subLayer.GetLayerName().getString(), subLayer.GetDrawableSlots()); } // We only notify the parent to update sub layers. It must manage its own sub layers @@ -64,6 +66,18 @@ 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()); + } + } + } + // Takes an image and adds it to the background draw list and saves coordinates to return to a callback if it is clicked private void AddNewButton(Identifier iconId, Text layerName, int drawX, int drawY, int imgWidth, int imgHeight) { layers.add(new NewItemButton(iconId, layerName, imgWidth, imgHeight, drawX, drawY)); diff --git a/src/client/java/jesse/keeblarcraft/mixin/ClientPlayNetworkHandlerMixin.java b/src/client/java/jesse/keeblarcraft/mixin/ClientPlayNetworkHandlerMixin.java index e04d07f..d442baf 100644 --- a/src/client/java/jesse/keeblarcraft/mixin/ClientPlayNetworkHandlerMixin.java +++ b/src/client/java/jesse/keeblarcraft/mixin/ClientPlayNetworkHandlerMixin.java @@ -1,8 +1,7 @@ package jesse.keeblarcraft.mixin; import com.llamalad7.mixinextras.sugar.Local; -import com.llamalad7.mixinextras.sugar.ref.LocalRef; -import jesse.keeblarcraft.GuiMgr.ShopKeeperHandler; +import jesse.keeblarcraft.GuiMgr.ShopKeeper.ShopKeeperHandler; import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.network.packet.s2c.play.SetTradeOffersS2CPacket; import net.minecraft.screen.ScreenHandler; diff --git a/src/main/java/jesse/keeblarcraft/CustomBlocks/BlockEntities/FactionBlockEntity.java b/src/main/java/jesse/keeblarcraft/CustomBlocks/BlockEntities/FactionBlockEntity.java index dd95324..e7ac380 100644 --- a/src/main/java/jesse/keeblarcraft/CustomBlocks/BlockEntities/FactionBlockEntity.java +++ b/src/main/java/jesse/keeblarcraft/CustomBlocks/BlockEntities/FactionBlockEntity.java @@ -11,7 +11,7 @@ import jesse.keeblarcraft.FactionMgr.Callbacks.PlayerEnteredBaseCallback; import jesse.keeblarcraft.FactionMgr.Callbacks.PlayerExitedBaseCallback; import jesse.keeblarcraft.FactionMgr.Callbacks.PlayerInBaseCallback; import jesse.keeblarcraft.FactionMgr.FactionTier.FactionTierEnum; -import jesse.keeblarcraft.GuiMgr.FactionBlockScreenHandler; +import jesse.keeblarcraft.GuiMgr.Factions.FactionBlockScreenHandler; import jesse.keeblarcraft.Utils.CommonStructures.Position3d; import jesse.keeblarcraft.world.ImplementedInventory; import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory; diff --git a/src/main/java/jesse/keeblarcraft/Entities/ShopKeeper.java b/src/main/java/jesse/keeblarcraft/Entities/ShopKeeper.java index c9ae6aa..6308ef4 100644 --- a/src/main/java/jesse/keeblarcraft/Entities/ShopKeeper.java +++ b/src/main/java/jesse/keeblarcraft/Entities/ShopKeeper.java @@ -1,6 +1,6 @@ package jesse.keeblarcraft.Entities; -import jesse.keeblarcraft.GuiMgr.ShopKeeperHandler; +import jesse.keeblarcraft.GuiMgr.ShopKeeper.ShopKeeperHandler; import net.minecraft.entity.EntityType; import net.minecraft.entity.passive.VillagerEntity; import net.minecraft.entity.player.PlayerEntity; diff --git a/src/main/java/jesse/keeblarcraft/GuiMgr/FactionBlockScreenHandler.java b/src/main/java/jesse/keeblarcraft/GuiMgr/Factions/FactionBlockScreenHandler.java similarity index 97% rename from src/main/java/jesse/keeblarcraft/GuiMgr/FactionBlockScreenHandler.java rename to src/main/java/jesse/keeblarcraft/GuiMgr/Factions/FactionBlockScreenHandler.java index 2c63081..ea85711 100644 --- a/src/main/java/jesse/keeblarcraft/GuiMgr/FactionBlockScreenHandler.java +++ b/src/main/java/jesse/keeblarcraft/GuiMgr/Factions/FactionBlockScreenHandler.java @@ -1,6 +1,7 @@ -package jesse.keeblarcraft.GuiMgr; +package jesse.keeblarcraft.GuiMgr.Factions; import jesse.keeblarcraft.CustomBlocks.BlockEntities.FactionBlockEntity; +import jesse.keeblarcraft.GuiMgr.ScreenHandlerRegistration; import net.minecraft.block.entity.BlockEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; diff --git a/src/main/java/jesse/keeblarcraft/GuiMgr/ScreenHandlerRegistration.java b/src/main/java/jesse/keeblarcraft/GuiMgr/ScreenHandlerRegistration.java index cf3e61e..c4c26dd 100644 --- a/src/main/java/jesse/keeblarcraft/GuiMgr/ScreenHandlerRegistration.java +++ b/src/main/java/jesse/keeblarcraft/GuiMgr/ScreenHandlerRegistration.java @@ -1,5 +1,7 @@ package jesse.keeblarcraft.GuiMgr; +import jesse.keeblarcraft.GuiMgr.Factions.FactionBlockScreenHandler; +import jesse.keeblarcraft.GuiMgr.ShopKeeper.ShopKeeperHandler; import jesse.keeblarcraft.Keeblarcraft; import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerType; import net.minecraft.registry.Registries; diff --git a/src/main/java/jesse/keeblarcraft/GuiMgr/ShopKeeperHandler.java b/src/main/java/jesse/keeblarcraft/GuiMgr/ShopKeeper/ShopKeeperHandler.java similarity index 72% rename from src/main/java/jesse/keeblarcraft/GuiMgr/ShopKeeperHandler.java rename to src/main/java/jesse/keeblarcraft/GuiMgr/ShopKeeper/ShopKeeperHandler.java index 5100a96..66516b4 100644 --- a/src/main/java/jesse/keeblarcraft/GuiMgr/ShopKeeperHandler.java +++ b/src/main/java/jesse/keeblarcraft/GuiMgr/ShopKeeper/ShopKeeperHandler.java @@ -1,5 +1,6 @@ -package jesse.keeblarcraft.GuiMgr; +package jesse.keeblarcraft.GuiMgr.ShopKeeper; +import jesse.keeblarcraft.GuiMgr.ScreenHandlerRegistration; import jesse.keeblarcraft.Utils.CustomSlot; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; @@ -18,11 +19,12 @@ import java.util.Map; public class ShopKeeperHandler extends ScreenHandler { private Merchant merchant; private MerchantInventory merchantInventory; - boolean canRefreshTrades = false; - boolean isLeveledMerchant = false; - int levelAmount = 0; - int merchantExperience = 0; - Map slotIdByName = new HashMap<>(); + private boolean canRefreshTrades = false; + private boolean isLeveledMerchant = false; + private int levelAmount = 0; + private int merchantExperience = 0; + private Map slotIdByName = new HashMap<>(); + ShopKeeperSlots allSlots = new ShopKeeperSlots(); public ShopKeeperHandler(int syncId, PlayerInventory playerInventory) { this(syncId, playerInventory, new SimpleMerchant(playerInventory.player)); @@ -32,26 +34,29 @@ public class ShopKeeperHandler extends ScreenHandler { super(ScreenHandlerRegistration.SHOP_KEEPER_HANDLER_SCREEN_HANDLER_TYPE, syncId); this.merchant = merchant; this.merchantInventory = new MerchantInventory(merchant); + RegisterSlots(); // Add slots below // this.addSlot(new Slot(this.merchantInventory, 0, 136, 37)); - this.addSlot(new CustomSlot(this.merchantInventory, 0, Text.of("test"), 136, 37), Text.of("test")); +// this.addSlot(new CustomSlot(this.merchantInventory, 0, 136, 37), Text.of("test")); } - public void HideSlot(Text slotName) { - this.getSlot(Text.of("test")).setEnabled(false); + public void RegisterSlots() { + CustomSlot slotOne = new CustomSlot(this.merchantInventory, 0, 136, 37); + + + allSlots.AddSlot("add_item_menu", "add_item_slot", slotOne); + this.addSlot(slotOne); } - public void ShowSlot(Text slotName) { - this.getSlot(Text.of("test")).setEnabled(true); + public void showSlot(String menuName, String slotName) { + allSlots.ShowSlot(menuName, slotName); } - protected void addSlot(CustomSlot slot, Text name) { - super.addSlot(slot); - slotIdByName.put(name, slot.id); + public void hideSlot(String menuName, String slotName) { + allSlots.HideSlot(menuName, slotName); } public CustomSlot getSlot(Text name) { - System.out.println("Printing slot map"); for (Slot slot : super.slots) { System.out.println("Found slot with id: " + slot.id); diff --git a/src/main/java/jesse/keeblarcraft/GuiMgr/ShopKeeper/ShopKeeperSlots.java b/src/main/java/jesse/keeblarcraft/GuiMgr/ShopKeeper/ShopKeeperSlots.java new file mode 100644 index 0000000..399e18c --- /dev/null +++ b/src/main/java/jesse/keeblarcraft/GuiMgr/ShopKeeper/ShopKeeperSlots.java @@ -0,0 +1,57 @@ +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 { + private final Map> shopKeeperSlots = new HashMap<>(); + + public ShopKeeperSlots() {} + + public void AddSlot(String menuName, String slotName, CustomSlot newSlot) { + if (!shopKeeperSlots.containsKey(slotName)) { + shopKeeperSlots.put(menuName, new HashMap<>()); + shopKeeperSlots.get(menuName).put(slotName, newSlot); + } else { + shopKeeperSlots.get(menuName).put(slotName, newSlot); + } + } + + public HashMap GetSlotsByMenu(String menu) { + return this.shopKeeperSlots.get(menu); + } + + public void HideSlot(String menuName, String slotName) { + for (Map.Entry> entry : shopKeeperSlots.entrySet()) { + if (entry.getKey().equals(menuName)) { + for (Map.Entry menuSlots : entry.getValue().entrySet()) { + if (menuSlots.getKey().equals(slotName)) { + menuSlots.getValue().setEnabled(false); + } + } + break; + } + } + } + + public void ShowSlot(String menuName, String slotName) { + for (Map.Entry> entry : shopKeeperSlots.entrySet()) { +// System.out.println("Menu name: " + entry.getKey()); + if (entry.getKey().equals(menuName)) { + for (Map.Entry menuSlots : entry.getValue().entrySet()) { +// System.out.println("Slot name: " + menuSlots.getKey()); + if (menuSlots.getKey().equals(slotName)) { + menuSlots.getValue().setEnabled(true); + } + } + break; + } + } + } +} diff --git a/src/main/java/jesse/keeblarcraft/GuiMgr/TreeHandler.java b/src/main/java/jesse/keeblarcraft/GuiMgr/SkillTree/TreeHandler.java similarity index 98% rename from src/main/java/jesse/keeblarcraft/GuiMgr/TreeHandler.java rename to src/main/java/jesse/keeblarcraft/GuiMgr/SkillTree/TreeHandler.java index 6e86cf5..09cd22c 100644 --- a/src/main/java/jesse/keeblarcraft/GuiMgr/TreeHandler.java +++ b/src/main/java/jesse/keeblarcraft/GuiMgr/SkillTree/TreeHandler.java @@ -1,4 +1,4 @@ -package jesse.keeblarcraft.GuiMgr; +package jesse.keeblarcraft.GuiMgr.SkillTree; import jesse.keeblarcraft.Keeblarcraft; import net.minecraft.entity.player.PlayerEntity; diff --git a/src/main/java/jesse/keeblarcraft/Keeblarcraft.java b/src/main/java/jesse/keeblarcraft/Keeblarcraft.java index da8192e..ebd0fe1 100644 --- a/src/main/java/jesse/keeblarcraft/Keeblarcraft.java +++ b/src/main/java/jesse/keeblarcraft/Keeblarcraft.java @@ -38,7 +38,7 @@ import jesse.keeblarcraft.EventMgr.DimensionLoadingEvent; import jesse.keeblarcraft.EventMgr.PlayerJoinListener; import jesse.keeblarcraft.EventMgr.ServerTickListener; import jesse.keeblarcraft.GuiMgr.ScreenHandlerRegistration; -import jesse.keeblarcraft.GuiMgr.TreeHandler; +import jesse.keeblarcraft.GuiMgr.SkillTree.TreeHandler; import jesse.keeblarcraft.Utils.CustomExceptions.SETUP_FAILED_EXCEPTION; import jesse.keeblarcraft.Utils.Setup; diff --git a/src/main/java/jesse/keeblarcraft/Utils/CommonStructures/Pair.java b/src/main/java/jesse/keeblarcraft/Utils/CommonStructures/Pair.java index cf7d0b8..75f58a5 100644 --- a/src/main/java/jesse/keeblarcraft/Utils/CommonStructures/Pair.java +++ b/src/main/java/jesse/keeblarcraft/Utils/CommonStructures/Pair.java @@ -3,6 +3,7 @@ package jesse.keeblarcraft.Utils.CommonStructures; public class Pair { KEY key; VALUE value; + public Pair(KEY key, VALUE val) { this.key = key; this.value = val; diff --git a/src/main/java/jesse/keeblarcraft/Utils/CustomSlot.java b/src/main/java/jesse/keeblarcraft/Utils/CustomSlot.java index 40a979e..190fac7 100644 --- a/src/main/java/jesse/keeblarcraft/Utils/CustomSlot.java +++ b/src/main/java/jesse/keeblarcraft/Utils/CustomSlot.java @@ -2,15 +2,9 @@ package jesse.keeblarcraft.Utils; import net.minecraft.inventory.Inventory; import net.minecraft.screen.slot.Slot; -import net.minecraft.text.Text; public class CustomSlot extends Slot { private boolean slotIsEnabled = false; - private Text slotId; - - public CustomSlot(Inventory inventory, int index, Text slotName, int x, int y) { - super(inventory, index, x, y); - } public CustomSlot(Inventory inventory, int index, int x, int y) { super(inventory, index, x, y);