From 8eeec924cfcfaef68a1c6ec30d5a0e9bb9c6dfe9 Mon Sep 17 00:00:00 2001 From: Paul Schifferer Date: Mon, 25 Nov 2024 08:02:36 -0800 Subject: [PATCH] Change logging levels --- CHANGELOG/1.18/current.md | 1 + .../client/event/ClientEventHandler.java | 25 +++++++++++++------ .../client/overlay/CraftQueueOverlay.java | 6 ++--- .../crafttracker/common/lib/Constants.java | 1 + .../crafttracker/common/util/KeyUtil.java | 14 +++++++++++ 5 files changed, 36 insertions(+), 11 deletions(-) create mode 100644 src/main/java/com/sweetrpg/crafttracker/common/util/KeyUtil.java diff --git a/CHANGELOG/1.18/current.md b/CHANGELOG/1.18/current.md index 0d8fcf2..d26235c 100644 --- a/CHANGELOG/1.18/current.md +++ b/CHANGELOG/1.18/current.md @@ -1 +1,2 @@ - `[FIX]` Remove lingering widgets when deleting a recipe from the queue +- `[NEW]` Enabled key bindings to manage display of craft list and shopping list 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 df6171e..5a663b9 100644 --- a/src/main/java/com/sweetrpg/crafttracker/client/event/ClientEventHandler.java +++ b/src/main/java/com/sweetrpg/crafttracker/client/event/ClientEventHandler.java @@ -7,6 +7,7 @@ import com.sweetrpg.crafttracker.common.lib.Constants; import com.sweetrpg.crafttracker.common.manager.CraftingQueueManager; import com.sweetrpg.crafttracker.common.registry.ModKeyBindings; +import com.sweetrpg.crafttracker.common.util.KeyUtil; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.inventory.CreativeModeInventoryScreen; @@ -19,8 +20,6 @@ import net.minecraftforge.client.event.ScreenEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; -import java.util.UUID; - public class ClientEventHandler { // static boolean craftListDisplayed = true; @@ -62,44 +61,54 @@ public static void onKeyInput(final InputEvent.KeyInputEvent event) { handleAddToQueue(); } - else if(ModKeyBindings.TOGGLE_CRAFT_LIST_MAPPING.matches(event.getKey(), event.getScanCode())) { + else if(KeyUtil.isKeyDown(event.getKey()) && + ModKeyBindings.TOGGLE_CRAFT_LIST_MAPPING.matches(event.getKey(), event.getScanCode())) { CraftTracker.LOGGER.debug("#onKeyInput: TOGGLE_CRAFT_LIST_MAPPING"); handleToggleCraftList(); } - else if(ModKeyBindings.TOGGLE_SHOPPING_LIST_MAPPING.matches(event.getKey(), event.getScanCode())) { + else if(KeyUtil.isKeyDown(event.getKey()) && + ModKeyBindings.TOGGLE_SHOPPING_LIST_MAPPING.matches(event.getKey(), event.getScanCode())) { CraftTracker.LOGGER.debug("#onKeyInput: TOGGLE_SHOPPING_LIST_MAPPING"); handleToggleShoppingList(); } - else if(ModKeyBindings.OPEN_QUEUE_MANAGER_MAPPING.matches(event.getKey(), event.getScanCode())) { + else if(KeyUtil.isKeyDown(event.getKey()) && + ModKeyBindings.OPEN_QUEUE_MANAGER_MAPPING.matches(event.getKey(), event.getScanCode())) { CraftTracker.LOGGER.debug("#onKeyInput: OPEN_QUEUE_MANAGER_MAPPING"); QueueManagementScreen.open(); } + else if(KeyUtil.isKeyDown(event.getKey()) && + ModKeyBindings.POPULATE_SHOPPING_LIST_MAPPING.matches(event.getKey(), event.getScanCode())) { + CraftTracker.LOGGER.debug("#onKeyInput: POPULATE_SHOPPING_LIST_MAPPING"); + + // TODO + } } private static void handleToggleCraftList() { CraftTracker.LOGGER.debug("#handleToggleCraftList"); + var player = Minecraft.getInstance().player; TranslatableComponent msg; switch(CTRuntime.INSTANCE.queueOverlayRequestedState) { case SHOW: CTRuntime.INSTANCE.queueOverlayRequestedState = CTRuntime.OverlayState.HIDE; msg = new TranslatableComponent(Constants.TRANSLATION_KEY_GUI_MSG_QUEUE_OVERLAY_MODE_HIDE); - Minecraft.getInstance().player.sendMessage(msg, UUID.randomUUID()); + player.displayClientMessage(msg, true); break; case HIDE: CTRuntime.INSTANCE.queueOverlayRequestedState = CTRuntime.OverlayState.DYNAMIC; msg = new TranslatableComponent(Constants.TRANSLATION_KEY_GUI_MSG_QUEUE_OVERLAY_MODE_DYNAMIC); - Minecraft.getInstance().player.sendMessage(msg, UUID.randomUUID()); + player.displayClientMessage(msg, true); break; case DYNAMIC: CTRuntime.INSTANCE.queueOverlayRequestedState = CTRuntime.OverlayState.SHOW; msg = new TranslatableComponent(Constants.TRANSLATION_KEY_GUI_MSG_QUEUE_OVERLAY_MODE_SHOW); - Minecraft.getInstance().player.sendMessage(msg, UUID.randomUUID()); + player.displayClientMessage(msg, true); break; } } 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 96f0538..db5f327 100644 --- a/src/main/java/com/sweetrpg/crafttracker/client/overlay/CraftQueueOverlay.java +++ b/src/main/java/com/sweetrpg/crafttracker/client/overlay/CraftQueueOverlay.java @@ -157,7 +157,7 @@ public class CraftQueueOverlay { var text = String.format("%s [%s]", item.getDescription().getString(MAX_STRING_LENGTH - countText.length() - 3), countText); - CraftTracker.LOGGER.debug("text: {}", text); + CraftTracker.LOGGER.trace("text: {}", text); GuiComponent.drawString(poseStack, gui.getFont(), text, x + ITEM_NAME_X_OFFSET, lambdaYpos + 4, TEXT_COLOR); } else { @@ -215,7 +215,7 @@ public class CraftQueueOverlay { var text = String.format("%s [%s]", item.getDescription().getString(MAX_STRING_LENGTH - countText.length() - 3), countText); - CraftTracker.LOGGER.debug("text: {}", text); + CraftTracker.LOGGER.trace("text: {}", text); GuiComponent.drawString(poseStack, gui.getFont(), text, x + ITEM_NAME_X_OFFSET, lambdaYpos + 4, TEXT_COLOR); } else { @@ -273,7 +273,7 @@ public class CraftQueueOverlay { var text = String.format("%s [%s]", item.getDescription().getString(MAX_STRING_LENGTH - countText.length() - 3), countText); - CraftTracker.LOGGER.debug("text: {}", text); + CraftTracker.LOGGER.trace("text: {}", text); GuiComponent.drawString(poseStack, gui.getFont(), text, x + ITEM_NAME_X_OFFSET, lambdaYpos + 4, TEXT_COLOR); } else { 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 4ff6001..a381b52 100644 --- a/src/main/java/com/sweetrpg/crafttracker/common/lib/Constants.java +++ b/src/main/java/com/sweetrpg/crafttracker/common/lib/Constants.java @@ -45,6 +45,7 @@ public class Constants { 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"; + public static final String TRANSLATION_KEY_BINDINGS_POPULATE_SHOPPING_LIST_TITLE = "key.populateShoppingList"; public static final String TRANSLATION_KEY_GUI_MSG_QUEUE_OVERLAY_MODE_HIDE = "crafttracker.msg.queue_overlay_mode.hide"; public static final String TRANSLATION_KEY_GUI_MSG_QUEUE_OVERLAY_MODE_SHOW = "crafttracker.msg.queue_overlay_mode.show"; public static final String TRANSLATION_KEY_GUI_MSG_QUEUE_OVERLAY_MODE_DYNAMIC = "crafttracker.msg.queue_overlay_mode.dynamic"; diff --git a/src/main/java/com/sweetrpg/crafttracker/common/util/KeyUtil.java b/src/main/java/com/sweetrpg/crafttracker/common/util/KeyUtil.java new file mode 100644 index 0000000..81c3643 --- /dev/null +++ b/src/main/java/com/sweetrpg/crafttracker/common/util/KeyUtil.java @@ -0,0 +1,14 @@ +package com.sweetrpg.crafttracker.common.util; + +import com.mojang.blaze3d.platform.InputConstants; +import net.minecraft.client.Minecraft; + +public class KeyUtil { + + public static boolean isKeyDown(int key) { + return InputConstants.isKeyDown(Minecraft.getInstance() + .getWindow() + .getWindow(), key); + } + +}