diff --git a/src/generated/resources/assets/crafttracker/lang/de_de.json b/src/generated/resources/assets/crafttracker/lang/de_de.json index 5cbaef0..b150bb3 100644 --- a/src/generated/resources/assets/crafttracker/lang/de_de.json +++ b/src/generated/resources/assets/crafttracker/lang/de_de.json @@ -6,6 +6,11 @@ "crafttracker.screen.craft_list.section.materials": "Materialien", "crafttracker.screen.craft_list.section.products": "Produkte", "crafttracker.screen.craft_list.title": "Bastelliste", + "crafttracker.screen.queuemgr.button.clear": "Alle l\u00F6schen", + "crafttracker.screen.queuemgr.button.dec.tooltip": "Reduzieren Sie die Menge an hergestellten", + "crafttracker.screen.queuemgr.button.del.tooltip": "Dieses Element aus der Warteschlange l\u00F6schen", + "crafttracker.screen.queuemgr.button.inc.tooltip": "Erh\u00F6hen Sie die Menge an hergestellten", + "crafttracker.screen.queuemgr.title": "Warteschlangenmanager", "crafttracker.screen.shopping_list.title": "Einkaufsliste", "key.addToQueue": "Zur Warteschlange hinzuf\u00FCgen", "key.categories.crafttracker": "Handwerks-Tracker", diff --git a/src/generated/resources/assets/crafttracker/lang/en_gb.json b/src/generated/resources/assets/crafttracker/lang/en_gb.json index dcecd78..5a7a537 100644 --- a/src/generated/resources/assets/crafttracker/lang/en_gb.json +++ b/src/generated/resources/assets/crafttracker/lang/en_gb.json @@ -6,6 +6,11 @@ "crafttracker.screen.craft_list.section.materials": "Materials", "crafttracker.screen.craft_list.section.products": "Products", "crafttracker.screen.craft_list.title": "Craft List", + "crafttracker.screen.queuemgr.button.clear": "Clear", + "crafttracker.screen.queuemgr.button.dec.tooltip": "Decrease the amount crafted", + "crafttracker.screen.queuemgr.button.del.tooltip": "Delete this item from the queue", + "crafttracker.screen.queuemgr.button.inc.tooltip": "Increase the amount crafted", + "crafttracker.screen.queuemgr.title": "Queue Manager", "crafttracker.screen.shopping_list.title": "Shopping List", "key.addToQueue": "Add to Queue", "key.categories.crafttracker": "Craft Tracker", diff --git a/src/generated/resources/assets/crafttracker/lang/en_us.json b/src/generated/resources/assets/crafttracker/lang/en_us.json index dcecd78..49a558c 100644 --- a/src/generated/resources/assets/crafttracker/lang/en_us.json +++ b/src/generated/resources/assets/crafttracker/lang/en_us.json @@ -1,11 +1,17 @@ { "crafttracker.screen.craft_list.empty_message": "The queue is empty.", "crafttracker.screen.craft_list.have": "have %d", + "crafttracker.screen.craft_list.help_message": "To manage the queue:", "crafttracker.screen.craft_list.section.fuel": "Fuel", "crafttracker.screen.craft_list.section.intermediates": "Intermediates", "crafttracker.screen.craft_list.section.materials": "Materials", "crafttracker.screen.craft_list.section.products": "Products", "crafttracker.screen.craft_list.title": "Craft List", + "crafttracker.screen.queuemgr.button.clear": "Clear", + "crafttracker.screen.queuemgr.button.dec.tooltip": "Decrease the amount crafted", + "crafttracker.screen.queuemgr.button.del.tooltip": "Delete this item from the queue", + "crafttracker.screen.queuemgr.button.inc.tooltip": "Increase the amount crafted", + "crafttracker.screen.queuemgr.title": "Queue Manager", "crafttracker.screen.shopping_list.title": "Shopping List", "key.addToQueue": "Add to Queue", "key.categories.crafttracker": "Craft Tracker", diff --git a/src/main/java/com/sweetrpg/crafttracker/client/event/ClientEventHandler.java b/src/main/java/com/sweetrpg/crafttracker/client/event/ClientEventHandler.java index 8ebf326..1f652bc 100644 --- a/src/main/java/com/sweetrpg/crafttracker/client/event/ClientEventHandler.java +++ b/src/main/java/com/sweetrpg/crafttracker/client/event/ClientEventHandler.java @@ -4,6 +4,7 @@ import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.*; import com.sweetrpg.crafttracker.CraftTracker; +import com.sweetrpg.crafttracker.client.screen.QueueManagementScreen; import com.sweetrpg.crafttracker.common.addon.jei.CTPlugin; import com.sweetrpg.crafttracker.common.manager.CraftingQueueManager; import com.sweetrpg.crafttracker.common.registry.ModKeyBindings; @@ -78,21 +79,21 @@ public static void onKeyInput(final InputEvent.KeyInputEvent event) { } -// else if(ModKeyBindings.TOGGLE_CRAFT_LIST_MAPPING.matches(event.getKey(), event.getScanCode())) { -// CraftTracker.LOGGER.debug("#onKeyInput: TOGGLE_CRAFT_LIST_MAPPING"); -//// craftListDisplayed = !craftListDisplayed; -//// PacketHandler.sendToServer(new ToggleCraftListData()); -// } -// else if(ModKeyBindings.TOGGLE_SHOPPING_LIST_MAPPING.matches(event.getKey(), event.getScanCode())) { -// CraftTracker.LOGGER.debug("#onKeyInput: TOGGLE_SHOPPING_LIST_MAPPING"); -//// shoppingListDisplayed = !shoppingListDisplayed; -//// PacketHandler.sendToServer(new ToggleShoppingListData()); -// } -// else if(ModKeyBindings.OPEN_QUEUE_MANAGER_MAPPING.matches(event.getKey(), event.getScanCode())) { -// CraftTracker.LOGGER.debug("#onKeyInput: OPEN_QUEUE_MANAGER_MAPPING"); -// -// QueueManagementScreen.open(); -// } + else if(ModKeyBindings.TOGGLE_CRAFT_LIST_MAPPING.matches(event.getKey(), event.getScanCode())) { + CraftTracker.LOGGER.debug("#onKeyInput: TOGGLE_CRAFT_LIST_MAPPING"); +// craftListDisplayed = !craftListDisplayed; +// PacketHandler.sendToServer(new ToggleCraftListData()); + } + else if(ModKeyBindings.TOGGLE_SHOPPING_LIST_MAPPING.matches(event.getKey(), event.getScanCode())) { + CraftTracker.LOGGER.debug("#onKeyInput: TOGGLE_SHOPPING_LIST_MAPPING"); +// shoppingListDisplayed = !shoppingListDisplayed; +// PacketHandler.sendToServer(new ToggleShoppingListData()); + } + else if(ModKeyBindings.OPEN_QUEUE_MANAGER_MAPPING.matches(event.getKey(), event.getScanCode())) { + CraftTracker.LOGGER.debug("#onKeyInput: OPEN_QUEUE_MANAGER_MAPPING"); + + QueueManagementScreen.open(); + } } @SubscribeEvent diff --git a/src/main/java/com/sweetrpg/crafttracker/client/overlay/CraftQueueOverlay.java b/src/main/java/com/sweetrpg/crafttracker/client/overlay/CraftQueueOverlay.java index ae0bec7..3a3ef5a 100644 --- a/src/main/java/com/sweetrpg/crafttracker/client/overlay/CraftQueueOverlay.java +++ b/src/main/java/com/sweetrpg/crafttracker/client/overlay/CraftQueueOverlay.java @@ -3,11 +3,14 @@ import com.sweetrpg.crafttracker.CraftTracker; import com.sweetrpg.crafttracker.common.addon.jei.CTPlugin; import com.sweetrpg.crafttracker.common.config.ConfigHandler; +import com.sweetrpg.crafttracker.common.lib.CTRuntime; import com.sweetrpg.crafttracker.common.lib.Constants; import com.sweetrpg.crafttracker.common.manager.CraftingQueueManager; +import com.sweetrpg.crafttracker.common.registry.ModKeyBindings; import mezz.jei.api.constants.VanillaTypes; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiComponent; +import net.minecraft.client.resources.language.I18n; import net.minecraft.network.chat.TranslatableComponent; import net.minecraftforge.client.gui.IIngameOverlay; import net.minecraftforge.registries.ForgeRegistries; @@ -15,6 +18,7 @@ public class CraftQueueOverlay { static int TITLE_COLOR = 0x99999999; + static int HELP_COLOR = 0x77777777; static int SECTION_COLOR = 0xcccccccc; static int TEXT_COLOR = 0xffffffff; static int MESSAGE_COLOR = 0x66666666; @@ -28,8 +32,24 @@ public class CraftQueueOverlay { public static final IIngameOverlay CRAFT_QUEUE = (gui, poseStack, partialTicks, width, height) -> { CraftTracker.LOGGER.trace("CRAFT_QUEUE"); - if(ConfigHandler.CLIENT.CRAFT_QUEUE_OVERLAY_HIDE_EMPTY.get() /* TODO: || user wants it to display */) { - return; + var mgr = CraftingQueueManager.INSTANCE; + var products = mgr.getEndProducts(); + + switch(CTRuntime.INSTANCE.queueOverlayRequestedState) { + case SHOW: + // + break; + + case HIDE: + case SUPPRESS: + return; + + case DO_NOT_CARE: + if(ConfigHandler.CLIENT.CRAFT_QUEUE_OVERLAY_HIDE_EMPTY.get() && + products.isEmpty()) { + return; + } + break; } var x = ConfigHandler.CLIENT.CRAFT_QUEUE_OVERLAY_X.get(); @@ -46,9 +66,6 @@ public class CraftQueueOverlay { new TranslatableComponent(Constants.TRANSLATION_KEY_GUI_CRAFTLIST_TITLE), (x + olWidth - 8) / 2, y + 6, TITLE_COLOR); - var mgr = CraftingQueueManager.INSTANCE; - var products = mgr.getEndProducts(); - // if products list is empty, display "empty" message if(products.isEmpty()) { GuiComponent.drawCenteredString(poseStack, gui.getFont(), @@ -57,6 +74,12 @@ public class CraftQueueOverlay { return; } + var helpText = String.format("%s [%s]", + I18n.get(Constants.TRANSLATION_KEY_GUI_CRAFTLIST_HELP), + ModKeyBindings.OPEN_QUEUE_MANAGER_MAPPING.getTranslatedKeyMessage().getString()); + GuiComponent.drawCenteredString(poseStack, gui.getFont(), helpText, + (x + olWidth - 8) / 2, olHeight - TEXT_HEIGHT, HELP_COLOR); + int yPos = y + SECTION_TITLE_Y_OFFSET; CraftTracker.LOGGER.trace("yPos (initial): {}", yPos); @@ -88,6 +111,7 @@ public class CraftQueueOverlay { } // SECTION: intermediates + if(!mgr.getIntermediates().isEmpty()) { yPos += (TEXT_HEIGHT * 1.5); CraftTracker.LOGGER.trace("yPos (before intermediates title): {}", yPos); @@ -117,6 +141,7 @@ public class CraftQueueOverlay { } // SECTION: raw materials + if(!mgr.getRawMaterials().isEmpty()) { yPos += (TEXT_HEIGHT * 1.5); CraftTracker.LOGGER.trace("yPos (before materials title): {}", yPos); @@ -148,9 +173,10 @@ public class CraftQueueOverlay { .map(inv -> inv.getCount()) .findFirst() .ifPresent(count -> { - var text = String.format("%s [%d]", + var countText = I18n.get(Constants.TRANSLATION_KEY_GUI_CRAFTLIST_HAVE, count); + var text = String.format("%s [%s]", item.getDescription().getString(MAX_STRING_LENGTH), - count); + countText); CraftTracker.LOGGER.debug("text: {}", text); GuiComponent.drawString(poseStack, gui.getFont(), text, x + ITEM_NAME_X_OFFSET, lambdaYpos + 4, TEXT_COLOR); }); diff --git a/src/main/java/com/sweetrpg/crafttracker/client/screen/QueueManagementScreen.java b/src/main/java/com/sweetrpg/crafttracker/client/screen/QueueManagementScreen.java index 708c809..e181161 100644 --- a/src/main/java/com/sweetrpg/crafttracker/client/screen/QueueManagementScreen.java +++ b/src/main/java/com/sweetrpg/crafttracker/client/screen/QueueManagementScreen.java @@ -1,19 +1,52 @@ package com.sweetrpg.crafttracker.client.screen; import com.mojang.blaze3d.vertex.PoseStack; +import com.sweetrpg.crafttracker.CraftTracker; +import com.sweetrpg.crafttracker.common.addon.jei.CTPlugin; +import com.sweetrpg.crafttracker.common.lib.CTRuntime; import com.sweetrpg.crafttracker.common.lib.Constants; +import com.sweetrpg.crafttracker.common.manager.CraftingQueueManager; +import mezz.jei.api.constants.VanillaTypes; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiComponent; +import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.resources.language.I18n; +import net.minecraft.network.chat.TextComponent; import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.world.entity.player.Player; +import net.minecraftforge.registries.ForgeRegistries; + +import java.util.List; + +import static com.sweetrpg.crafttracker.common.lib.CTRuntime.OverlayState.DO_NOT_CARE; +import static com.sweetrpg.crafttracker.common.lib.CTRuntime.OverlayState.SUPPRESS; public class QueueManagementScreen extends Screen { public final Player player; + public static final int TITLE_COLOR = 0xbbbbbbbb; + public static final int TITLE_HEIGHT = 20; + public static final int ITEM_COLOR = 0xffffffff; + public static final int ITEM_HEIGHT = 18; + public static final int BUTTON_SIZE = ITEM_HEIGHT - 2; + public static final int BACKGROUND_COLOR = 0x66666666; + public static final int ITEM_X_ICON_OFFSET = 2; + public static final int ITEM_X_TEXT_OFFSET = 20; + public static final int ITEM_X_DELETE_BUTTON_OFFSET = -(2 + BUTTON_SIZE); + public static final int ITEM_X_UP_BUTTON_OFFSET = ITEM_X_DELETE_BUTTON_OFFSET - BUTTON_SIZE - 2; + public static final int ITEM_X_QTY_WIDTH = 30; + public static final int ITEM_X_QTY_OFFSET = ITEM_X_UP_BUTTON_OFFSET - (ITEM_X_QTY_WIDTH / 2); + public static final int ITEM_X_DOWN_BUTTON_OFFSET = ITEM_X_QTY_OFFSET - (int) (BUTTON_SIZE * 2) - 2; + + final private List productItems; + public QueueManagementScreen(Player player) { super(new TranslatableComponent(Constants.TRANSLATION_KEY_GUI_QUEUEMGR_TITLE)); this.player = player; + + this.productItems = CraftingQueueManager.INSTANCE.getEndProducts(); } public static void open() { @@ -30,22 +63,129 @@ public void init() { int topX = this.width / 2; int topY = this.height / 2; - // TODO: hide queue overlay and shopping list - - + // hide queue overlay and shopping list + CTRuntime.INSTANCE.queueOverlayRequestedState = SUPPRESS; + CTRuntime.INSTANCE.shoppingOverlayRequestedState = SUPPRESS; } @Override - public void render(PoseStack stack, int mouseX, int mouseY, float partialTicks) { - //Background - int topX = this.width / 2; - int topY = this.height / 2; - - this.renderBackground(stack); - - + public void render(PoseStack poseStack, int mouseX, int mouseY, float partialTicks) { + + int width = Math.max(200, this.width / 3); + int height = this.height - 100; + int topX = (this.width / 2) - (width / 2); + int topY = 20; // (this.height / 2) - (height / 2); + + this.renderBackground(poseStack); + +// GuiComponent.fill(poseStack, topX, topY, width, height, BACKGROUND_COLOR); + + // title + GuiComponent.drawCenteredString(poseStack, this.font, I18n.get(Constants.TRANSLATION_KEY_GUI_QUEUEMGR_TITLE), this.width / 2, topY + 2, TITLE_COLOR); + + // products + for(int i = 0; i < this.productItems.size(); i++) { + var pItem = this.productItems.get(i); + final var itemIndex = i; + + var item = ForgeRegistries.ITEMS.getValue(pItem.getItemId()); + var itemStack = item.getDefaultInstance(); + var y = topY + TITLE_HEIGHT + (i * (ITEM_HEIGHT + 4)); + + if(y + ITEM_HEIGHT > height) { + CraftTracker.LOGGER.debug("too many items for display (stopping at item {}, y {}", i, y); + break; + } + + // background + GuiComponent.fill(poseStack, topX, y, topX + width, y + ITEM_HEIGHT + 2, BACKGROUND_COLOR); + + // icon + var drawable = CTPlugin.jeiRuntime.getJeiHelpers().getGuiHelper() + .createDrawableIngredient(VanillaTypes.ITEM_STACK, itemStack); + drawable.draw(poseStack, topX + ITEM_X_ICON_OFFSET, y + 2); + + // name + this.font.draw(poseStack, item.getDescription(), topX + ITEM_X_TEXT_OFFSET, y + 6, ITEM_COLOR); + + // quantity and adjustment buttons + { + Button button = new Button(topX + width + ITEM_X_DOWN_BUTTON_OFFSET, y + 2, BUTTON_SIZE, BUTTON_SIZE - 2, new TextComponent("-"), btn -> { + this.productItems.set(itemIndex, new CraftingQueueManager.ProductItem(pItem.getItemId(), pItem.getQuantity() - 1, pItem.getCategories())); + CraftingQueueManager.INSTANCE.adjustProduct(player, pItem.getItemId(), -1); + }) { + @Override + public void renderToolTip(PoseStack pPoseStack, int pMouseX, int pMouseY) { + QueueManagementScreen.this.renderTooltip(poseStack, new TranslatableComponent(Constants.TRANSLATION_KEY_GUI_QUEUEMGR_DEC_BUTTON_TOOLTIP), mouseX, mouseY); + } + }; + button.active = pItem.getQuantity() > 0; + this.addRenderableWidget(button); + } + { + var text = String.format("%d", pItem.getQuantity()); +// this.font.draw(poseStack, text, topX + width + ITEM_X_QTY_OFFSET, y + 6, ITEM_COLOR); + GuiComponent.drawCenteredString(poseStack, this.font, text, topX + width + ITEM_X_QTY_OFFSET, y + 6, ITEM_COLOR); + } + { + Button button = new Button(topX + width + ITEM_X_UP_BUTTON_OFFSET, y + 2, BUTTON_SIZE, BUTTON_SIZE - 2, new TextComponent("+"), btn -> { + this.productItems.set(itemIndex, new CraftingQueueManager.ProductItem(pItem.getItemId(), pItem.getQuantity() + 1, pItem.getCategories())); + CraftingQueueManager.INSTANCE.adjustProduct(player, pItem.getItemId(), 1); + }) { + @Override + public void renderToolTip(PoseStack pPoseStack, int pMouseX, int pMouseY) { + QueueManagementScreen.this.renderTooltip(poseStack, new TranslatableComponent(Constants.TRANSLATION_KEY_GUI_QUEUEMGR_INC_BUTTON_TOOLTIP), mouseX, mouseY); + } + }; + this.addRenderableWidget(button); + } + + // variations + // TODO + + // delete button + { + Button button = new Button(topX + width + ITEM_X_DELETE_BUTTON_OFFSET, y + 2, BUTTON_SIZE, BUTTON_SIZE - 2, new TextComponent("x"), btn -> { + this.productItems.remove(itemIndex); + CraftingQueueManager.INSTANCE.removeProduct(player, pItem.getItemId()); + }) { + @Override + public void renderToolTip(PoseStack pPoseStack, int pMouseX, int pMouseY) { + QueueManagementScreen.this.renderTooltip(poseStack, new TranslatableComponent(Constants.TRANSLATION_KEY_GUI_QUEUEMGR_DEL_BUTTON_TOOLTIP), mouseX, mouseY); + } + }; + this.addRenderableWidget(button); + } + } + + // clear all button + { + Button button = new Button(topX + (width / 2) - 50, topY + height - BUTTON_SIZE - 4, 100, BUTTON_SIZE + 2, + new TranslatableComponent(Constants.TRANSLATION_KEY_GUI_QUEUEMGR_CLEAR_BUTTON), + btn -> { + CraftingQueueManager.INSTANCE.removeAll(); + }) { + @Override + public void renderToolTip(PoseStack pPoseStack, int pMouseX, int pMouseY) { + QueueManagementScreen.this.renderTooltip(poseStack, new TranslatableComponent(Constants.TRANSLATION_KEY_GUI_QUEUEMGR_CLEAR_BUTTON_TOOLTIP), mouseX, mouseY); + } + }; + this.addRenderableWidget(button); + } + + // buttons + + super.render(poseStack, mouseX, mouseY, partialTicks); + //RenderHelper.disableStandardItemLighting(); // 1.14 enableGUIStandardItemLighting + +// for(Widget widget : this.renderables) { +// if(widget instanceof AbstractWidget w && w.isHoveredOrFocused()) { +// w.renderToolTip(poseStack, mouseX, mouseY); +// break; +// } +// } } @Override @@ -54,7 +194,9 @@ public void removed() { this.minecraft.keyboardHandler.setSendRepeatsToGui(false); - // TODO: restore queue overlay and shopping list + // restore queue overlay and shopping list + CTRuntime.INSTANCE.queueOverlayRequestedState = DO_NOT_CARE; + CTRuntime.INSTANCE.shoppingOverlayRequestedState = DO_NOT_CARE; } @Override diff --git a/src/main/java/com/sweetrpg/crafttracker/common/lib/CTRuntime.java b/src/main/java/com/sweetrpg/crafttracker/common/lib/CTRuntime.java new file mode 100644 index 0000000..a871898 --- /dev/null +++ b/src/main/java/com/sweetrpg/crafttracker/common/lib/CTRuntime.java @@ -0,0 +1,27 @@ +package com.sweetrpg.crafttracker.common.lib; + +import com.sweetrpg.crafttracker.common.config.ConfigHandler; + +public class CTRuntime { + + public static CTRuntime INSTANCE = new CTRuntime(); + + public enum OverlayState { + SHOW, + HIDE, + SUPPRESS, + DO_NOT_CARE, + } + + public OverlayState queueOverlayRequestedState; + public OverlayState shoppingOverlayRequestedState; + + public CTRuntime() { + init(); + } + + private void init() { + this.queueOverlayRequestedState = OverlayState.DO_NOT_CARE; + this.shoppingOverlayRequestedState = OverlayState.DO_NOT_CARE; + } +} diff --git a/src/main/java/com/sweetrpg/crafttracker/common/lib/Constants.java b/src/main/java/com/sweetrpg/crafttracker/common/lib/Constants.java index 62f1ba5..35918fc 100644 --- a/src/main/java/com/sweetrpg/crafttracker/common/lib/Constants.java +++ b/src/main/java/com/sweetrpg/crafttracker/common/lib/Constants.java @@ -27,6 +27,7 @@ public class Constants { // Translation keys public static final String TRANSLATION_KEY_GUI_CRAFTLIST_TITLE = "crafttracker.screen.craft_list.title"; public static final String TRANSLATION_KEY_GUI_CRAFTLIST_EMPTY = "crafttracker.screen.craft_list.empty_message"; + public static final String TRANSLATION_KEY_GUI_CRAFTLIST_HELP = "crafttracker.screen.craft_list.help_message"; public static final String TRANSLATION_KEY_GUI_CRAFTLIST_SECTION_PRODUCTS = "crafttracker.screen.craft_list.section.products"; public static final String TRANSLATION_KEY_GUI_CRAFTLIST_SECTION_INTERMEDIATES = "crafttracker.screen.craft_list.section.intermediates"; public static final String TRANSLATION_KEY_GUI_CRAFTLIST_SECTION_MATERIALS = "crafttracker.screen.craft_list.section.materials"; @@ -34,10 +35,16 @@ public class Constants { public static final String TRANSLATION_KEY_GUI_CRAFTLIST_HAVE = "crafttracker.screen.craft_list.have"; public static final String TRANSLATION_KEY_GUI_SHOPPINGLIST_TITLE = "crafttracker.screen.shopping_list.title"; public static final String TRANSLATION_KEY_GUI_QUEUEMGR_TITLE = "crafttracker.screen.queuemgr.title"; + public static final String TRANSLATION_KEY_GUI_QUEUEMGR_CLEAR_BUTTON = "crafttracker.screen.queuemgr.button.clear"; + public static final String TRANSLATION_KEY_GUI_QUEUEMGR_CLEAR_BUTTON_TOOLTIP = "crafttracker.screen.queuemgr.button.clear.tooltip"; + public static final String TRANSLATION_KEY_GUI_QUEUEMGR_DEC_BUTTON_TOOLTIP = "crafttracker.screen.queuemgr.button.dec.tooltip"; + public static final String TRANSLATION_KEY_GUI_QUEUEMGR_INC_BUTTON_TOOLTIP = "crafttracker.screen.queuemgr.button.inc.tooltip"; + public static final String TRANSLATION_KEY_GUI_QUEUEMGR_DEL_BUTTON_TOOLTIP = "crafttracker.screen.queuemgr.button.del.tooltip"; public static final String TRANSLATION_KEY_BINDINGS_CATEGORY_TITLE = "key.categories.crafttracker"; public static final String TRANSLATION_KEY_BINDINGS_ADDTOQUEUE_TITLE = "key.addToQueue"; public static final String TRANSLATION_KEY_BINDINGS_TOGGLE_CRAFTLIST_TITLE = "key.toggleCraftList"; public static final String TRANSLATION_KEY_BINDINGS_TOGGLE_SHOPPINGLIST_TITLE = "key.toggleShoppingList"; + public static final String TRANSLATION_KEY_BINDINGS_OPEN_QMGR_TITLE = "key.openQueueManager"; // Advancements public static final String TRANSLATION_KEY_ADVANCEMENT_MAKE_LIST_TITLE = "advancements.crafttracker.main.make_list.title"; diff --git a/src/main/java/com/sweetrpg/crafttracker/common/manager/CraftingQueueManager.java b/src/main/java/com/sweetrpg/crafttracker/common/manager/CraftingQueueManager.java index 049cdf5..7623f72 100644 --- a/src/main/java/com/sweetrpg/crafttracker/common/manager/CraftingQueueManager.java +++ b/src/main/java/com/sweetrpg/crafttracker/common/manager/CraftingQueueManager.java @@ -152,6 +152,8 @@ public List getFuel() { public void addProduct(Player player, ResourceLocation itemId, int quantity) { CraftTracker.LOGGER.debug("CraftingQueueManager#addProduct: {}, quantity: {}", itemId, quantity); + if(quantity < 1) return; + var recipes = RecipeUtil.getRecipesFor(itemId); if(recipes.size() > 0) { @@ -174,9 +176,34 @@ public void addProduct(Player player, ResourceLocation itemId, int quantity) { this.save(player); } + /** + * A convenience method to adjust the quantity of a product. + * This will call the appropriate add* or remove* method. + * + * @param player + * @param itemId + * @param quantity + */ + public void adjustProduct(Player player, ResourceLocation itemId, int quantity) { + CraftTracker.LOGGER.debug("CraftingQueueManager#adjustProduct: {}, quantity: {}", itemId, quantity); + + if(quantity < 0) + removeProduct(player, itemId, -quantity); + else if(quantity > 0) + addProduct(player, itemId, quantity); + } + + public void removeProduct(Player player, ResourceLocation itemId) { + CraftTracker.LOGGER.debug("CraftingQueueManager#removeProduct: {}", itemId); + + this.endProducts.remove(itemId); + } + public void removeProduct(Player player, ResourceLocation itemId, int quantity) { CraftTracker.LOGGER.debug("CraftingQueueManager#removeProduct: {}, quantity: {}", itemId, quantity); + if(quantity < 1) return; + var product = this.endProducts.get(itemId); if(product == null) { CraftTracker.LOGGER.info("No product found in queue for {}", itemId); @@ -187,7 +214,7 @@ public void removeProduct(Player player, ResourceLocation itemId, int quantity) int newQuantity = product.getQuantity() - quantity; if(newQuantity < 1) { CraftTracker.LOGGER.info("Removing item from queue storage: {}", itemId); - this.endProducts.remove(itemId); + this.removeProduct(player, itemId); } else { CraftTracker.LOGGER.info("Adjusting quantity of item in queue storage to {}: {}", quantity, itemId); @@ -202,6 +229,15 @@ public void removeProduct(Player player, ResourceLocation itemId, int quantity) this.save(player); } + public void removeAll() { + CraftTracker.LOGGER.debug("CraftingQueueManager#removeAll"); + + this.endProducts.clear(); + this.intermediateProducts.clear(); + this.rawMaterials.clear(); + this.fuel.clear(); + } + /** * Compute all the intermediate items, raw materials, and fuel needed to make the recipes */ diff --git a/src/main/java/com/sweetrpg/crafttracker/data/CTLangProvider.java b/src/main/java/com/sweetrpg/crafttracker/data/CTLangProvider.java index 7e51dfd..451c392 100644 --- a/src/main/java/com/sweetrpg/crafttracker/data/CTLangProvider.java +++ b/src/main/java/com/sweetrpg/crafttracker/data/CTLangProvider.java @@ -32,6 +32,7 @@ private void processENUS() { add(Constants.TRANSLATION_KEY_GUI_CRAFTLIST_TITLE, "Craft List"); add(Constants.TRANSLATION_KEY_GUI_CRAFTLIST_EMPTY, "The queue is empty."); + add(Constants.TRANSLATION_KEY_GUI_CRAFTLIST_HELP, "To manage the queue:"); add(Constants.TRANSLATION_KEY_GUI_CRAFTLIST_SECTION_PRODUCTS, "Products"); add(Constants.TRANSLATION_KEY_GUI_CRAFTLIST_SECTION_INTERMEDIATES, "Intermediates"); add(Constants.TRANSLATION_KEY_GUI_CRAFTLIST_SECTION_MATERIALS, "Materials"); @@ -39,10 +40,15 @@ private void processENUS() { add(Constants.TRANSLATION_KEY_GUI_CRAFTLIST_HAVE, "have %d"); add(Constants.TRANSLATION_KEY_GUI_SHOPPINGLIST_TITLE, "Shopping List"); add(Constants.TRANSLATION_KEY_GUI_QUEUEMGR_TITLE, "Queue Manager"); + add(Constants.TRANSLATION_KEY_GUI_QUEUEMGR_CLEAR_BUTTON, "Clear"); + add(Constants.TRANSLATION_KEY_GUI_QUEUEMGR_DEC_BUTTON_TOOLTIP, "Decrease the amount crafted"); + add(Constants.TRANSLATION_KEY_GUI_QUEUEMGR_INC_BUTTON_TOOLTIP, "Increase the amount crafted"); + add(Constants.TRANSLATION_KEY_GUI_QUEUEMGR_DEL_BUTTON_TOOLTIP, "Delete this item from the queue"); add(Constants.TRANSLATION_KEY_BINDINGS_CATEGORY_TITLE, "Craft Tracker"); add(Constants.TRANSLATION_KEY_BINDINGS_ADDTOQUEUE_TITLE, "Add to Queue"); add(Constants.TRANSLATION_KEY_BINDINGS_TOGGLE_CRAFTLIST_TITLE, "Toggle Craft List"); add(Constants.TRANSLATION_KEY_BINDINGS_TOGGLE_SHOPPINGLIST_TITLE, "Toggle Shopping List"); + add(Constants.TRANSLATION_KEY_BINDINGS_OPEN_QMGR_TITLE, "Open Queue Manager"); } private void processENGB() { @@ -50,6 +56,7 @@ private void processENGB() { add(Constants.TRANSLATION_KEY_GUI_CRAFTLIST_TITLE, "Craft List"); add(Constants.TRANSLATION_KEY_GUI_CRAFTLIST_EMPTY, "The queue is empty."); + add(Constants.TRANSLATION_KEY_GUI_CRAFTLIST_HELP, "To manage the queue:"); add(Constants.TRANSLATION_KEY_GUI_CRAFTLIST_SECTION_PRODUCTS, "Products"); add(Constants.TRANSLATION_KEY_GUI_CRAFTLIST_SECTION_INTERMEDIATES, "Intermediates"); add(Constants.TRANSLATION_KEY_GUI_CRAFTLIST_SECTION_MATERIALS, "Materials"); @@ -57,10 +64,15 @@ private void processENGB() { add(Constants.TRANSLATION_KEY_GUI_CRAFTLIST_HAVE, "have %d"); add(Constants.TRANSLATION_KEY_GUI_SHOPPINGLIST_TITLE, "Shopping List"); add(Constants.TRANSLATION_KEY_GUI_QUEUEMGR_TITLE, "Queue Manager"); + add(Constants.TRANSLATION_KEY_GUI_QUEUEMGR_CLEAR_BUTTON, "Clear"); + add(Constants.TRANSLATION_KEY_GUI_QUEUEMGR_DEC_BUTTON_TOOLTIP, "Decrease the amount crafted"); + add(Constants.TRANSLATION_KEY_GUI_QUEUEMGR_INC_BUTTON_TOOLTIP, "Increase the amount crafted"); + add(Constants.TRANSLATION_KEY_GUI_QUEUEMGR_DEL_BUTTON_TOOLTIP, "Delete this item from the queue"); add(Constants.TRANSLATION_KEY_BINDINGS_CATEGORY_TITLE, "Craft Tracker"); add(Constants.TRANSLATION_KEY_BINDINGS_ADDTOQUEUE_TITLE, "Add to Queue"); add(Constants.TRANSLATION_KEY_BINDINGS_TOGGLE_CRAFTLIST_TITLE, "Toggle Craft List"); add(Constants.TRANSLATION_KEY_BINDINGS_TOGGLE_SHOPPINGLIST_TITLE, "Toggle Shopping List"); + add(Constants.TRANSLATION_KEY_BINDINGS_OPEN_QMGR_TITLE, "Open Queue Manager"); } private void processDEDE() { @@ -68,6 +80,7 @@ private void processDEDE() { add(Constants.TRANSLATION_KEY_GUI_CRAFTLIST_TITLE, "Bastelliste"); add(Constants.TRANSLATION_KEY_GUI_CRAFTLIST_EMPTY, "Die Warteschlange ist leer."); + add(Constants.TRANSLATION_KEY_GUI_CRAFTLIST_HELP, "Die Warteschlange verwalten:"); add(Constants.TRANSLATION_KEY_GUI_CRAFTLIST_SECTION_PRODUCTS, "Produkte"); add(Constants.TRANSLATION_KEY_GUI_CRAFTLIST_SECTION_INTERMEDIATES, "Zwischenprodukte"); add(Constants.TRANSLATION_KEY_GUI_CRAFTLIST_SECTION_MATERIALS, "Materialien"); @@ -75,9 +88,14 @@ private void processDEDE() { add(Constants.TRANSLATION_KEY_GUI_CRAFTLIST_HAVE, "habe %d"); add(Constants.TRANSLATION_KEY_GUI_SHOPPINGLIST_TITLE, "Einkaufsliste"); add(Constants.TRANSLATION_KEY_GUI_QUEUEMGR_TITLE, "Warteschlangenmanager"); + add(Constants.TRANSLATION_KEY_GUI_QUEUEMGR_CLEAR_BUTTON, "Alle löschen"); + add(Constants.TRANSLATION_KEY_GUI_QUEUEMGR_DEC_BUTTON_TOOLTIP, "Reduzieren Sie die Menge an hergestellten"); + add(Constants.TRANSLATION_KEY_GUI_QUEUEMGR_INC_BUTTON_TOOLTIP, "Erhöhen Sie die Menge an hergestellten"); + add(Constants.TRANSLATION_KEY_GUI_QUEUEMGR_DEL_BUTTON_TOOLTIP, "Dieses Element aus der Warteschlange löschen"); add(Constants.TRANSLATION_KEY_BINDINGS_CATEGORY_TITLE, "Handwerks-Tracker"); add(Constants.TRANSLATION_KEY_BINDINGS_ADDTOQUEUE_TITLE, "Zur Warteschlange hinzufügen"); add(Constants.TRANSLATION_KEY_BINDINGS_TOGGLE_CRAFTLIST_TITLE, "Handwerksliste umschalten"); add(Constants.TRANSLATION_KEY_BINDINGS_TOGGLE_SHOPPINGLIST_TITLE, "Einkaufsliste umschalten"); + add(Constants.TRANSLATION_KEY_BINDINGS_OPEN_QMGR_TITLE, "Warteschlangenmanager öffnen"); } }