diff options
Diffstat (limited to 'src/main/java/io')
4 files changed, 54 insertions, 5 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java index ea388d1..91cf7b5 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java @@ -169,6 +169,19 @@ public class CottonClientScreen extends Screen { } @Override + public boolean mouseScrolled(double mouseX, double mouseY, double amount) { + if (description.getRootPanel()==null) return super.mouseScrolled(mouseX, mouseY, amount); + + WPanel root = description.getRootPanel(); + int containerX = (int)mouseX-left; + int containerY = (int)mouseY-top; + + WWidget child = root.hit(containerX, containerY); + child.onMouseScroll(containerX - child.getAbsoluteX(), containerY - child.getAbsoluteY(), amount); + return true; + } + + @Override public boolean charTyped(char ch, int keyCode) { if (description.getFocus()==null) return false; description.getFocus().onCharTyped(ch); diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java index ad00784..3a7f5c2 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java @@ -1,5 +1,7 @@ package io.github.cottonmc.cotton.gui.client; +import org.lwjgl.glfw.GLFW; + import io.github.cottonmc.cotton.gui.CottonCraftingController; import io.github.cottonmc.cotton.gui.widget.WPanel; import io.github.cottonmc.cotton.gui.widget.WWidget; @@ -78,10 +80,22 @@ public class CottonInventoryScreen<T extends CottonCraftingController> extends A @Override public boolean keyPressed(int ch, int keyCode, int modifiers) { - if (super.keyPressed(ch, keyCode, modifiers)) return true; - if (description.getFocus()==null) return false; - description.getFocus().onKeyPressed(ch, keyCode, modifiers); - return true; + if (keyCode==GLFW.GLFW_KEY_ESCAPE) { + this.minecraft.player.closeContainer(); + return true; + } else { + //if (super.keyPressed(ch, keyCode, modifiers)) return true; + if (description.getFocus()==null) { + if (MinecraftClient.getInstance().options.keyInventory.matchesKey(ch, keyCode)) { + this.minecraft.player.closeContainer(); + return true; + } + return false; + } else { + description.getFocus().onKeyPressed(ch, keyCode, modifiers); + return true; + } + } } @Override @@ -142,6 +156,19 @@ public class CottonInventoryScreen<T extends CottonCraftingController> extends A } @Override + public boolean mouseScrolled(double mouseX, double mouseY, double amount) { + if (description.getRootPanel()==null) return super.mouseScrolled(mouseX, mouseY, amount); + + WPanel root = description.getRootPanel(); + int containerX = (int)mouseX-left; + int containerY = (int)mouseY-top; + + WWidget child = root.hit(containerX, containerY); + child.onMouseScroll(containerX - child.getAbsoluteX(), containerY - child.getAbsoluteY(), amount); + return true; + } + + @Override protected void drawBackground(float partialTicks, int mouseX, int mouseY) {} //This is just an AbstractContainerScreen thing; most Screens don't work this way. public void paint(int mouseX, int mouseY) { diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WToggleButton.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WToggleButton.java index 82813ca..8935a95 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WToggleButton.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WToggleButton.java @@ -87,7 +87,7 @@ public class WToggleButton extends WWidget { @Override public void paintBackground(int x, int y) { - ScreenDrawing.texturedRect(x, y, 18, 18, isOn ? DEFAULT_ON_IMAGE : DEFAULT_OFF_IMAGE, 0xFFFFFFFF); + ScreenDrawing.texturedRect(x, y, 18, 18, isOn ? onImage : offImage, 0xFFFFFFFF); if (label!=null) { diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java index 1bbbf85..e4c5746 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java @@ -106,6 +106,15 @@ public class WWidget { } /** + * Notifies this widget that the mouse has been scrolled inside its bounds. + * @param x The X coordinate of the event, in widget-space (0 is the left edge of this widget) + * @param y The Y coordinate of the event, in widget-space (0 is the top edge of this widget) + * @param amount The scrolled amount. Positive values are up and negative values are down. + */ + public void onMouseScroll(int x, int y, double amount) { + } + + /** * Notifies this widget that a character has been typed. This method is subject to key repeat, * and may be called for characters that do not directly have a corresponding keyboard key. * @param ch the character typed |