Hover stays on the item. Tooltip shows the bound key. Default is the =/+ key under Controls > Satistaskory. No click-off-the-slot button.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,69 +56,45 @@ 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;
|
||||
public static void registerKeys(RegisterKeyMappingsEvent event) {
|
||||
event.register(ADD_GOAL);
|
||||
}
|
||||
|
||||
public static void onTooltip(ItemTooltipEvent event) {
|
||||
if (event.getEntity() == null || event.getItemStack().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Minecraft minecraft = Minecraft.getInstance();
|
||||
if (minecraft.player == null) {
|
||||
if (!(minecraft.screen instanceof AbstractContainerScreen<?>)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack stack = hoveredStack(screen);
|
||||
if (stack.isEmpty()) {
|
||||
return;
|
||||
event.getToolTip()
|
||||
.add(Component.translatable("satistaskory.tooltip.add", ADD_GOAL.getTranslatedKeyMessage())
|
||||
.withStyle(ChatFormatting.DARK_GRAY));
|
||||
}
|
||||
|
||||
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 boolean click(double mouseX, double mouseY) {
|
||||
if (hoveredItem == null || !contains(mouseX, mouseY)) {
|
||||
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);
|
||||
return true;
|
||||
if (minecraft.player != null) {
|
||||
minecraft.player.displayClientMessage(
|
||||
Component.translatable("satistaskory.message.added", stack.getHoverName()), false);
|
||||
}
|
||||
|
||||
private static boolean contains(double mouseX, double mouseY) {
|
||||
return hoveredItem != null
|
||||
&& mouseX >= buttonX
|
||||
&& mouseX < buttonX + buttonW
|
||||
&& mouseY >= buttonY
|
||||
&& mouseY < buttonY + buttonH;
|
||||
return true;
|
||||
}
|
||||
|
||||
private static ItemStack hoveredStack(Screen screen) {
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user