diff --git a/src/main/java/com/hollingsworth/arsnouveau/client/gui/book/GuiSpellBook.java b/src/main/java/com/hollingsworth/arsnouveau/client/gui/book/GuiSpellBook.java index c6c9846e0e..11cff4954b 100644 --- a/src/main/java/com/hollingsworth/arsnouveau/client/gui/book/GuiSpellBook.java +++ b/src/main/java/com/hollingsworth/arsnouveau/client/gui/book/GuiSpellBook.java @@ -19,11 +19,13 @@ import com.hollingsworth.arsnouveau.common.network.PacketUpdateCaster; import com.hollingsworth.arsnouveau.common.spell.validation.CombinedSpellValidator; import com.hollingsworth.arsnouveau.common.spell.validation.GlyphMaxTierValidator; +import com.hollingsworth.arsnouveau.common.util.GuiUtils; import com.hollingsworth.arsnouveau.setup.ItemsRegistry; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.*; import net.minecraft.Util; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.components.AbstractWidget; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.EditBox; import net.minecraft.client.gui.components.Widget; @@ -79,7 +81,7 @@ public class GuiSpellBook extends BaseBook { public int maxManaCache = 0; int currentCostCache = 0; public boolean setFocusOnLoad = true; - + public Widget hoveredWidget = null; @Deprecated(forRemoval = true) // TODO: remove in 1.20 public GuiSpellBook(ItemStack bookStack, int tier, List unlockedSpells) { this(InteractionHand.MAIN_HAND); @@ -435,6 +437,25 @@ public void onSlotChange(Button button) { validate(); } + @Override + public boolean charTyped(char pCodePoint, int pModifiers) { + if(hoveredWidget instanceof GlyphButton glyphButton && glyphButton.validationErrors.isEmpty()){ + // check if char is a number + if(pCodePoint >= '0' && pCodePoint <= '9'){ + int num = Integer.parseInt(String.valueOf(pCodePoint)); + if(num == 0){ + num = 10; + } + num -= 1; + this.craftingCells.get(num).abstractSpellPart = glyphButton.abstractSpellPart; + this.craftingCells.get(num).spellTag = glyphButton.abstractSpellPart.getRegistryName(); + validate(); + return true; + } + } + return super.charTyped(pCodePoint, pModifiers); + } + public void updateCraftingSlots(int bookSlot) { //Crafting slots List recipe = CasterUtil.getCaster(bookStack).getSpell(bookSlot).recipe; @@ -630,9 +651,6 @@ private void validateGlyphButton(List recipe, GlyphButton gly recipe.remove(recipe.size() - 1); } - /** - * Draws the screen and all the components in it. - */ @Override public void render(PoseStack ms, int mouseX, int mouseY, float partialTicks) { super.render(ms, mouseX, mouseY, partialTicks); @@ -640,6 +658,13 @@ public void render(PoseStack ms, int mouseX, int mouseY, float partialTicks) { this.setFocusOnLoad = false; this.setInitialFocus(searchBar); } + hoveredWidget = null; + for(Widget widget : renderables){ + if(widget instanceof AbstractWidget abstractWidget && GuiUtils.isMouseInRelativeRange(mouseX, mouseY, abstractWidget)){ + hoveredWidget = widget; + break; + } + } spell_name.setSuggestion(spell_name.getValue().isEmpty() ? Component.translatable("ars_nouveau.spell_book_gui.spell_name").getString() : ""); } diff --git a/src/main/java/com/hollingsworth/arsnouveau/common/util/GuiUtils.java b/src/main/java/com/hollingsworth/arsnouveau/common/util/GuiUtils.java new file mode 100644 index 0000000000..f49f054f02 --- /dev/null +++ b/src/main/java/com/hollingsworth/arsnouveau/common/util/GuiUtils.java @@ -0,0 +1,14 @@ +package com.hollingsworth.arsnouveau.common.util; + +import net.minecraft.client.gui.components.AbstractWidget; + +public class GuiUtils { + + public static boolean isMouseInRelativeRange(int mouseX, int mouseY, AbstractWidget widget){ + return isMouseInRelativeRange(mouseX, mouseY, widget.x, widget.y, widget.getWidth(), widget.getHeight()); + } + + public static boolean isMouseInRelativeRange(int mouseX, int mouseY, int x, int y, int w, int h) { + return mouseX >= x && mouseX <= x + w && mouseY >= y && mouseY <= y + h; + } +}