From 3f3d8bff506698d1b62274c2619f23935e4cd761 Mon Sep 17 00:00:00 2001 From: Stephen Fasciani Date: Tue, 8 Sep 2026 04:57:12 -0400 Subject: [PATCH] Capture with tooltip line and rebindable add key. Hover stays on the item. Tooltip shows the bound key. Default is the =/+ key under Controls > Satistaskory. No click-off-the-slot button. --- docs/05-Experience/πŸ–₯️ Experience.md | 4 +- docs/05-Experience/πŸ–ΌοΈ Wireframes.md | 13 +-- .../satistaskory/SatistaskoryClient.java | 13 +-- .../infrastructure/client/CaptureHook.java | 110 ++++++++---------- .../assets/satistaskory/lang/en_us.json | 6 +- 5 files changed, 66 insertions(+), 80 deletions(-) diff --git a/docs/05-Experience/πŸ–₯️ Experience.md b/docs/05-Experience/πŸ–₯️ Experience.md index a0287db..984f713 100644 --- a/docs/05-Experience/πŸ–₯️ Experience.md +++ b/docs/05-Experience/πŸ–₯️ Experience.md @@ -34,8 +34,8 @@ Places: Interaction: 1. Hover the item -2. `+ Add to Crafting Goals` appears -3. That is [[▢️ Create Goal]] β€” quantity **1**, or **+1** if that item is already a goal +2. Tooltip includes `[+] Add to Crafting Goals` (bound key) +3. Press that key β€” [[▢️ Create Goal]] β€” quantity **1**, or **+1** if that item is already a goal 4. Player closes the view and is back in the world 5. The item is a row on the overlay’s goal list diff --git a/docs/05-Experience/πŸ–ΌοΈ Wireframes.md b/docs/05-Experience/πŸ–ΌοΈ Wireframes.md index bca6a1a..e714683 100644 --- a/docs/05-Experience/πŸ–ΌοΈ Wireframes.md +++ b/docs/05-Experience/πŸ–ΌοΈ Wireframes.md @@ -14,21 +14,20 @@ Screen 2 is the player’s concept art, finished with the domain: goals on top; The player is already in inventory, the crafting bench craft pane, or the craft book. -Satistaskory draws only the hover control. +Satistaskory draws only a tooltip line. The mouse stays on the item. ```text (host view we do not own) [ item ] - - β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” - β”‚ + Add to Crafting Goals β”‚ - β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ + Tooltip + … + [+] Add to Crafting Goals ``` -**Primary action:** Add β†’ [[▢️ Create Goal]] (quantity 1, or +1 if present) β†’ player closes the host view β†’ the item appears in Screen 2’s goal list. +**Primary action:** hover the item, press the Add key (default `=`, rebindable in Controls) β†’ [[▢️ Create Goal]] (quantity 1, or +1 if present) β†’ close the host view β†’ the item is a row on Screen 2. -Same button in all three hosts. We do not restyle the inventory, the bench, or the book. +Same control in inventory, crafting pane, and craft book. We do not restyle those views. We do not draw a click target you have to leave the item to hit. Target Quantity is not drawn here. First quantity is 1. Further edits are `[+]` / `[-]` on Screen 2. diff --git a/src/main/java/com/sufficient/satistaskory/SatistaskoryClient.java b/src/main/java/com/sufficient/satistaskory/SatistaskoryClient.java index 29c0809..caf4901 100644 --- a/src/main/java/com/sufficient/satistaskory/SatistaskoryClient.java +++ b/src/main/java/com/sufficient/satistaskory/SatistaskoryClient.java @@ -20,12 +20,14 @@ import net.neoforged.neoforge.client.event.RegisterClientCommandsEvent; import net.neoforged.neoforge.client.event.RegisterGuiLayersEvent; import net.neoforged.neoforge.client.event.ScreenEvent; import net.neoforged.neoforge.client.gui.VanillaGuiLayers; +import net.neoforged.neoforge.event.entity.player.ItemTooltipEvent; @Mod(value = Satistaskory.MODID, dist = Dist.CLIENT) public class SatistaskoryClient { public SatistaskoryClient(IEventBus modEventBus, ModContainer container) { PlannerSession.bootstrap(); modEventBus.addListener(SatistaskoryClient::registerGuiLayers); + modEventBus.addListener(CaptureHook::registerKeys); } private static void registerGuiLayers(RegisterGuiLayersEvent event) { @@ -63,16 +65,13 @@ public class SatistaskoryClient { } @SubscribeEvent - public static void onScreenRender(ScreenEvent.Render.Post event) { - CaptureHook.render(event.getScreen(), event.getGuiGraphics(), event.getMouseX(), event.getMouseY()); + public static void onTooltip(ItemTooltipEvent event) { + CaptureHook.onTooltip(event); } @SubscribeEvent - public static void onScreenClick(ScreenEvent.MouseButtonPressed.Pre event) { - if (event.getButton() != GLFW.GLFW_MOUSE_BUTTON_LEFT) { - return; - } - if (CaptureHook.click(event.getMouseX(), event.getMouseY())) { + public static void onScreenKey(ScreenEvent.KeyPressed.Pre event) { + if (CaptureHook.onKey(event.getScreen(), event.getKeyCode(), event.getScanCode())) { event.setCanceled(true); } } diff --git a/src/main/java/com/sufficient/satistaskory/infrastructure/client/CaptureHook.java b/src/main/java/com/sufficient/satistaskory/infrastructure/client/CaptureHook.java index 84d42d0..73540dd 100644 --- a/src/main/java/com/sufficient/satistaskory/infrastructure/client/CaptureHook.java +++ b/src/main/java/com/sufficient/satistaskory/infrastructure/client/CaptureHook.java @@ -2,11 +2,15 @@ package com.sufficient.satistaskory.infrastructure.client; import java.lang.reflect.Field; +import org.lwjgl.glfw.GLFW; + +import com.mojang.blaze3d.platform.InputConstants; import com.sufficient.satistaskory.domain.ItemId; +import net.minecraft.ChatFormatting; +import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Font; -import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.components.EditBox; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.client.gui.screens.recipebook.RecipeBookComponent; @@ -19,15 +23,20 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvents; import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; +import net.neoforged.neoforge.client.event.RegisterKeyMappingsEvent; +import net.neoforged.neoforge.client.settings.KeyConflictContext; +import net.neoforged.neoforge.event.entity.player.ItemTooltipEvent; /** - * Screen 1: a button on host views we do not own. - * Inventory slots, crafting grid, and the craft book. + * Screen 1: tooltip line + rebindable key. Stay on the item; do not chase a button. */ public final class CaptureHook { - private static final String LABEL = "+ Add to Crafting Goals"; - private static final int PAD_X = 6; - private static final int PAD_Y = 4; + public static final KeyMapping ADD_GOAL = new KeyMapping( + "key.satistaskory.add_goal", + KeyConflictContext.GUI, + InputConstants.Type.KEYSYM, + GLFW.GLFW_KEY_EQUAL, + "key.categories.satistaskory"); private static final Field RECIPE_PAGE; private static final Field HOVERED_BUTTON; @@ -38,8 +47,7 @@ public final class CaptureHook { try { page = RecipeBookComponent.class.getDeclaredField("recipeBookPage"); page.setAccessible(true); - Class pageClass = page.getType(); - hovered = pageClass.getDeclaredField("hoveredButton"); + hovered = page.getType().getDeclaredField("hoveredButton"); hovered.setAccessible(true); } catch (ReflectiveOperationException ignored) { // Slot hover still works if craft-book fields move. @@ -48,71 +56,47 @@ public final class CaptureHook { HOVERED_BUTTON = hovered; } - private static int buttonX; - private static int buttonY; - private static int buttonW; - private static int buttonH; - private static ItemId hoveredItem; - private CaptureHook() {} - public static void render(Screen screen, GuiGraphics graphics, int mouseX, int mouseY) { - hoveredItem = null; - Minecraft minecraft = Minecraft.getInstance(); - if (minecraft.player == null) { - return; - } - - ItemStack stack = hoveredStack(screen); - if (stack.isEmpty()) { - return; - } - - ResourceLocation key = BuiltInRegistries.ITEM.getKey(stack.getItem()); - hoveredItem = ItemId.parse(key.toString()); - - Font font = minecraft.font; - buttonW = font.width(LABEL) + PAD_X * 2; - buttonH = font.lineHeight + PAD_Y * 2; - buttonX = mouseX + 12; - buttonY = mouseY + 20; - if (buttonX + buttonW > screen.width - 4) { - buttonX = screen.width - 4 - buttonW; - } - if (buttonY + buttonH > screen.height - 4) { - buttonY = mouseY - buttonH - 8; - } - if (buttonX < 4) { - buttonX = 4; - } - if (buttonY < 4) { - buttonY = 4; - } - - graphics.fill(buttonX, buttonY, buttonX + buttonW, buttonY + buttonH, 0xE0101010); - graphics.fill(buttonX + 1, buttonY + 1, buttonX + buttonW - 1, buttonY + buttonH - 1, 0xE0282828); - graphics.drawString(font, LABEL, buttonX + PAD_X, buttonY + PAD_Y, 0xFFFFFF, false); + public static void registerKeys(RegisterKeyMappingsEvent event) { + event.register(ADD_GOAL); } - public static boolean click(double mouseX, double mouseY) { - if (hoveredItem == null || !contains(mouseX, mouseY)) { + public static void onTooltip(ItemTooltipEvent event) { + if (event.getEntity() == null || event.getItemStack().isEmpty()) { + return; + } + Minecraft minecraft = Minecraft.getInstance(); + if (!(minecraft.screen instanceof AbstractContainerScreen)) { + return; + } + event.getToolTip() + .add(Component.translatable("satistaskory.tooltip.add", ADD_GOAL.getTranslatedKeyMessage()) + .withStyle(ChatFormatting.DARK_GRAY)); + } + + public static boolean onKey(Screen screen, int keyCode, int scanCode) { + if (!ADD_GOAL.matches(keyCode, scanCode)) { return false; } - PlannerSession.get().create(hoveredItem); + if (screen.getFocused() instanceof EditBox) { + return false; + } + ItemStack stack = hoveredStack(screen); + if (stack.isEmpty()) { + return false; + } + ResourceLocation key = BuiltInRegistries.ITEM.getKey(stack.getItem()); + PlannerSession.get().create(ItemId.parse(key.toString())); Minecraft minecraft = Minecraft.getInstance(); minecraft.getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F)); - minecraft.player.displayClientMessage(Component.literal("Added " + hoveredItem), false); + if (minecraft.player != null) { + minecraft.player.displayClientMessage( + Component.translatable("satistaskory.message.added", stack.getHoverName()), false); + } return true; } - private static boolean contains(double mouseX, double mouseY) { - return hoveredItem != null - && mouseX >= buttonX - && mouseX < buttonX + buttonW - && mouseY >= buttonY - && mouseY < buttonY + buttonH; - } - private static ItemStack hoveredStack(Screen screen) { if (screen instanceof AbstractContainerScreen container) { Slot slot = container.getSlotUnderMouse(); diff --git a/src/main/resources/assets/satistaskory/lang/en_us.json b/src/main/resources/assets/satistaskory/lang/en_us.json index 83b8249..5ca2f23 100644 --- a/src/main/resources/assets/satistaskory/lang/en_us.json +++ b/src/main/resources/assets/satistaskory/lang/en_us.json @@ -1,4 +1,8 @@ { "satistaskory.overlay.title": "SATISTASKORY", - "satistaskory.overlay.clear": "X Clear Items" + "satistaskory.overlay.clear": "X Clear Items", + "key.categories.satistaskory": "Satistaskory", + "key.satistaskory.add_goal": "Add to Crafting Goals", + "satistaskory.tooltip.add": "[%s] Add to Crafting Goals", + "satistaskory.message.added": "Added %s to crafting goals" }