diff --git a/src/main/java/net/aoba/AobaClient.java b/src/main/java/net/aoba/AobaClient.java index 33ca0d41..8e715421 100644 --- a/src/main/java/net/aoba/AobaClient.java +++ b/src/main/java/net/aoba/AobaClient.java @@ -21,8 +21,6 @@ */ package net.aoba; -import java.util.EventListener; - import net.aoba.altmanager.AltManager; import net.aoba.cmd.CommandManager; import net.aoba.core.settings.SettingManager; @@ -64,6 +62,9 @@ public void Initialize() { IMC = (IMinecraftClient)MC; System.out.println("[Aoba] Starting Client"); + + eventManager = new EventManager(); + renderUtils = new RenderUtils(); // System.out.println("[Aoba] Reading Settings"); // settings = new Settings(); @@ -79,7 +80,7 @@ public void Initialize() { altManager = new AltManager(); System.out.println("[Aoba] Aoba-chan initialized and ready to play!"); - eventManager = new EventManager(); + SettingManager.loadSettings("config_category", settingManager.config_category); diff --git a/src/main/java/net/aoba/event/events/AbstractEvent.java b/src/main/java/net/aoba/event/events/AbstractEvent.java index 151da5da..23e6eee2 100644 --- a/src/main/java/net/aoba/event/events/AbstractEvent.java +++ b/src/main/java/net/aoba/event/events/AbstractEvent.java @@ -15,6 +15,10 @@ public boolean IsCancelled() { return isCancelled; } + public void SetCancelled(boolean state) { + this.isCancelled = state; + } + public abstract void Fire(ArrayList listeners); public abstract Class GetListenerClassType(); } diff --git a/src/main/java/net/aoba/event/events/KeyDownEvent.java b/src/main/java/net/aoba/event/events/KeyDownEvent.java new file mode 100644 index 00000000..414d8fff --- /dev/null +++ b/src/main/java/net/aoba/event/events/KeyDownEvent.java @@ -0,0 +1,57 @@ +package net.aoba.event.events; + +import java.util.ArrayList; + +import net.aoba.event.listeners.AbstractListener; +import net.aoba.event.listeners.KeyDownListener; + +public class KeyDownEvent extends AbstractEvent{ + private final long window; + private final int key; + private final int scancode; + private final int action; + private final int modifiers; + + public KeyDownEvent(long window, int key, int scancode, int action, int modifiers) { + super(); + this.window = window; + this.key = key; + this.scancode = scancode; + this.action = action; + this.modifiers = modifiers; + } + + public long GetWindow() { + return window; + } + + public int GetKey() { + return key; + } + + public int GetScanCode() { + return scancode; + } + + public int GetAction() { + return action; + } + + public int GetModifiers() { + return modifiers; + } + + @Override + public void Fire(ArrayList listeners) { + for(AbstractListener listener : listeners) { + KeyDownListener keyDownListener = (KeyDownListener) listener; + keyDownListener.OnKeyDown(this); + } + } + + @SuppressWarnings("unchecked") + @Override + public Class GetListenerClassType() { + return KeyDownListener.class; + } +} \ No newline at end of file diff --git a/src/main/java/net/aoba/event/events/MouseLeftClickEvent.java b/src/main/java/net/aoba/event/events/MouseLeftClickEvent.java new file mode 100644 index 00000000..11fbda64 --- /dev/null +++ b/src/main/java/net/aoba/event/events/MouseLeftClickEvent.java @@ -0,0 +1,39 @@ +package net.aoba.event.events; + +import java.util.ArrayList; +import net.aoba.event.listeners.AbstractListener; +import net.aoba.event.listeners.MouseLeftClickListener; + +public class MouseLeftClickEvent extends AbstractEvent{ + + int mouseX; + int mouseY; + + public MouseLeftClickEvent(int mouseX, int mouseY) { + super(); + this.mouseX = mouseX; + this.mouseY = mouseY; + } + + public int GetMouseX() { + return mouseX; + } + + public int GetMouseY() { + return mouseY; + } + + @Override + public void Fire(ArrayList listeners) { + for(AbstractListener listener : listeners) { + MouseLeftClickListener mouseLeftClickListener = (MouseLeftClickListener) listener; + mouseLeftClickListener.OnMouseLeftClick(this); + } + } + + @SuppressWarnings("unchecked") + @Override + public Class GetListenerClassType() { + return MouseLeftClickListener.class; + } +} \ No newline at end of file diff --git a/src/main/java/net/aoba/event/events/MouseMoveEvent.java b/src/main/java/net/aoba/event/events/MouseMoveEvent.java new file mode 100644 index 00000000..8296db6a --- /dev/null +++ b/src/main/java/net/aoba/event/events/MouseMoveEvent.java @@ -0,0 +1,40 @@ +package net.aoba.event.events; + +import java.util.ArrayList; + +import net.aoba.event.listeners.AbstractListener; +import net.aoba.event.listeners.MouseMoveListener; +import net.aoba.event.listeners.MouseScrollListener; + +public class MouseMoveEvent extends AbstractEvent{ + private double horizontal; + private double vertical; + + public MouseMoveEvent(double x, double y) { + super(); + this.horizontal = x; + this.vertical = y; + } + + public double GetVertical() { + return vertical; + } + + public double GetHorizontal() { + return horizontal; + } + + @Override + public void Fire(ArrayList listeners) { + for(AbstractListener listener : listeners) { + MouseMoveListener mouseMoveListener = (MouseMoveListener) listener; + mouseMoveListener.OnMouseMove(this); + } + } + + @SuppressWarnings("unchecked") + @Override + public Class GetListenerClassType() { + return MouseScrollListener.class; + } +} \ No newline at end of file diff --git a/src/main/java/net/aoba/event/listeners/KeyDownListener.java b/src/main/java/net/aoba/event/listeners/KeyDownListener.java new file mode 100644 index 00000000..8ab06f25 --- /dev/null +++ b/src/main/java/net/aoba/event/listeners/KeyDownListener.java @@ -0,0 +1,7 @@ +package net.aoba.event.listeners; + +import net.aoba.event.events.KeyDownEvent; + +public interface KeyDownListener extends AbstractListener { + public abstract void OnKeyDown(KeyDownEvent event); +} diff --git a/src/main/java/net/aoba/event/listeners/MouseLeftClickListener.java b/src/main/java/net/aoba/event/listeners/MouseLeftClickListener.java new file mode 100644 index 00000000..dd0dab79 --- /dev/null +++ b/src/main/java/net/aoba/event/listeners/MouseLeftClickListener.java @@ -0,0 +1,7 @@ +package net.aoba.event.listeners; + +import net.aoba.event.events.MouseLeftClickEvent; + +public interface MouseLeftClickListener extends AbstractListener { + public abstract void OnMouseLeftClick(MouseLeftClickEvent event); +} diff --git a/src/main/java/net/aoba/event/listeners/MouseMoveListener.java b/src/main/java/net/aoba/event/listeners/MouseMoveListener.java new file mode 100644 index 00000000..e04f4a69 --- /dev/null +++ b/src/main/java/net/aoba/event/listeners/MouseMoveListener.java @@ -0,0 +1,7 @@ +package net.aoba.event.listeners; + +import net.aoba.event.events.MouseMoveEvent; + +public interface MouseMoveListener extends AbstractListener { + public abstract void OnMouseMove(MouseMoveEvent mouseMoveEvent); +} diff --git a/src/main/java/net/aoba/gui/HudManager.java b/src/main/java/net/aoba/gui/HudManager.java index 3d4a2fa0..3a767ab4 100644 --- a/src/main/java/net/aoba/gui/HudManager.java +++ b/src/main/java/net/aoba/gui/HudManager.java @@ -6,7 +6,9 @@ import net.aoba.core.settings.SettingManager; import net.aoba.core.settings.types.BooleanSetting; import net.aoba.core.settings.types.FloatSetting; +import net.aoba.event.events.MouseLeftClickEvent; import net.aoba.event.events.MouseScrollEvent; +import net.aoba.event.listeners.MouseLeftClickListener; import org.lwjgl.glfw.GLFW; import org.lwjgl.opengl.GL11; @@ -28,7 +30,7 @@ import net.minecraft.client.util.Window; import net.minecraft.client.util.math.MatrixStack; -public class HudManager { +public class HudManager implements MouseLeftClickListener { protected MinecraftClient mc = MinecraftClient.getInstance(); protected RenderUtils renderUtils = new RenderUtils(); @@ -45,8 +47,6 @@ public class HudManager { private int lastMouseX = 0; private int lastMouseY = 0; - private int mouseX; - private int mouseY; private List activeHuds = new ArrayList(); @@ -122,6 +122,8 @@ public HudManager() { SettingManager.register_setting(effectSpeed, Aoba.getInstance().settingManager.config_category); SettingManager.register_setting(rainbow, Aoba.getInstance().settingManager.config_category); SettingManager.register_setting(ah, Aoba.getInstance().settingManager.config_category); + + Aoba.getInstance().eventManager.AddListener(MouseLeftClickListener.class, this); } /** @@ -142,39 +144,20 @@ public void onMouseScroll(double horizontal, double vertical) { } public void update() { - boolean mouseClicked = mc.mouse.wasLeftButtonClicked(); - if(!Aoba.getInstance().isGhosted()){ - mouseX = (int) Math.ceil(mc.mouse.getX()); - mouseY = (int) Math.ceil(mc.mouse.getY()); - /** * Moves the selected Tab to where the user moves their mouse. */ if (this.clickGuiOpen) { - clickGuiNavBar.update(mouseX, mouseY, mouseClicked); - - int dx = (int) Math.ceil(mouseX); - int dy = (int) Math.ceil(mouseY); - if (!mouseClicked) - currentGrabbed = null; - else if (currentGrabbed != null) { - float newX = Math.max(0, currentGrabbed.getX() - (lastMouseX - dx)); - float newY = Math.max(0, currentGrabbed.getY() - (lastMouseY - dy)); - - currentGrabbed.setX(newX); - currentGrabbed.setY(newY); - } - this.lastMouseX = dx; - this.lastMouseY = dy; + clickGuiNavBar.update(); } /** * Updates each of the Tab GUIs that are currently on the screen. */ for(AbstractHud hud : activeHuds) { - hud.update(lastMouseX, lastMouseY, mouseClicked); + hud.update(); } @@ -253,4 +236,23 @@ public void toggleMouse() { this.mc.mouse.lockCursor(); } } + + @Override + public void OnMouseLeftClick(MouseLeftClickEvent event) { + if (this.clickGuiOpen) { + event.SetCancelled(true); + int dx = event.GetMouseX(); + int dy = event.GetMouseY(); + + if (currentGrabbed != null) { + float newX = Math.max(0, currentGrabbed.getX() - (lastMouseX - dx)); + float newY = Math.max(0, currentGrabbed.getY() - (lastMouseY - dy)); + + //currentGrabbed.setX(newX); + //currentGrabbed.setY(newY); + } + this.lastMouseX = dx; + this.lastMouseY = dy; + } + } } diff --git a/src/main/java/net/aoba/gui/NavigationBar.java b/src/main/java/net/aoba/gui/NavigationBar.java index b04c76e2..073e12ba 100644 --- a/src/main/java/net/aoba/gui/NavigationBar.java +++ b/src/main/java/net/aoba/gui/NavigationBar.java @@ -4,13 +4,15 @@ import java.util.List; import net.aoba.Aoba; import net.aoba.AobaClient; +import net.aoba.event.events.MouseLeftClickEvent; +import net.aoba.event.listeners.MouseLeftClickListener; import net.aoba.misc.RenderUtils; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.util.Window; import net.minecraft.client.util.math.MatrixStack; -public class NavigationBar { +public class NavigationBar implements MouseLeftClickListener { MinecraftClient mc = MinecraftClient.getInstance(); private List options; @@ -31,28 +33,11 @@ public int getSelectedIndex() { return this.selectedIndex; } - public void update(double mouseX, double mouseY, boolean mouseClicked) { - AobaClient aoba = Aoba.getInstance(); + public void update() { Window window = mc.getWindow(); - - int width = 100 * options.size(); - int centerX = (window.getWidth() / 2); - - int x = centerX - (width / 2); - if (aoba.hudManager.isClickGuiOpen() && HudManager.currentGrabbed == null) { - if (mouseX >= (x) && mouseX <= (x + width)) { - if (mouseY >= (25) && mouseY <= (50)) { - if (mouseClicked) { - int mouseXInt = (int) mouseX; - int selection = (mouseXInt - x) / 100; - this.selectedIndex = selection; - } - } - } - } if(options.size() > 0) { - options.get(selectedIndex).update(mouseX, mouseY, mouseClicked); + options.get(selectedIndex).update(); } } @@ -78,4 +63,26 @@ public void draw(DrawContext drawContext, float partialTicks, Color color) { } } + + @Override + public void OnMouseLeftClick(MouseLeftClickEvent event) { + AobaClient aoba = Aoba.getInstance(); + Window window = mc.getWindow(); + + int mouseX = event.GetMouseX(); + int mouseY = event.GetMouseY(); + int width = 100 * options.size(); + int centerX = (window.getWidth() / 2); + int x = centerX - (width / 2); + + if (aoba.hudManager.isClickGuiOpen() && HudManager.currentGrabbed == null) { + if (mouseX >= (x) && mouseX <= (x + width)) { + if (mouseY >= (25) && mouseY <= (50)) { + int mouseXInt = (int) mouseX; + int selection = (mouseXInt - x) / 100; + this.selectedIndex = selection; + } + } + } + } } \ No newline at end of file diff --git a/src/main/java/net/aoba/gui/NavigationPane.java b/src/main/java/net/aoba/gui/NavigationPane.java index e1a31dbe..6e90d756 100644 --- a/src/main/java/net/aoba/gui/NavigationPane.java +++ b/src/main/java/net/aoba/gui/NavigationPane.java @@ -18,9 +18,9 @@ public void AddHud(AbstractHud hud) { tabs.add(hud); } - public void update(double mouseX, double mouseY, boolean mouseClicked) { + public void update() { for(AbstractHud tab : tabs) { - tab.update(mouseX, mouseY, mouseClicked); + tab.update(); } } diff --git a/src/main/java/net/aoba/gui/hud/AbstractHud.java b/src/main/java/net/aoba/gui/hud/AbstractHud.java index d445d9f1..a7df5a3f 100644 --- a/src/main/java/net/aoba/gui/hud/AbstractHud.java +++ b/src/main/java/net/aoba/gui/hud/AbstractHud.java @@ -4,6 +4,8 @@ import net.aoba.core.settings.SettingManager; import net.aoba.core.settings.types.Vector2Setting; import net.aoba.core.utils.types.Vector2; +import net.aoba.event.events.MouseLeftClickEvent; +import net.aoba.event.listeners.MouseLeftClickListener; import net.aoba.gui.Color; import net.aoba.gui.HudManager; import net.aoba.gui.IMoveable; @@ -13,7 +15,7 @@ import java.util.function.Consumer; -public abstract class AbstractHud implements IMoveable { +public abstract class AbstractHud implements IMoveable, MouseLeftClickListener { protected float x; protected float y; protected float width; @@ -61,10 +63,12 @@ public float getWidth() { public void setX(float x) { this.x = x; + position_setting.silentSetX(x); } public void setY(float y) { this.y = y; + position_setting.silentSetY(y); } public void setWidth(float width) { @@ -75,22 +79,23 @@ public void setHeight(float height) { this.height = height; } - public void update(double mouseX, double mouseY, boolean mouseClicked) { + public abstract void update(); + + public abstract void draw(DrawContext drawContext, float partialTicks, Color color); + + @Override + public void OnMouseLeftClick(MouseLeftClickEvent event) { + int mouseX = event.GetMouseX(); + int mouseY = event.GetMouseY(); + if (Aoba.getInstance().hudManager.isClickGuiOpen()) { if (HudManager.currentGrabbed == null) { if (mouseX >= (x) && mouseX <= (x + width)) { if (mouseY >= (y) && mouseY <= (y + height)) { - if (mouseClicked) { - HudManager.currentGrabbed = this; - } + HudManager.currentGrabbed = this; } } } } - - position_setting.silentSetX(x); - position_setting.silentSetY(y); } - - public abstract void draw(DrawContext drawContext, float partialTicks, Color color); } diff --git a/src/main/java/net/aoba/gui/hud/ArmorHud.java b/src/main/java/net/aoba/gui/hud/ArmorHud.java index 3dedb526..49354034 100644 --- a/src/main/java/net/aoba/gui/hud/ArmorHud.java +++ b/src/main/java/net/aoba/gui/hud/ArmorHud.java @@ -39,6 +39,11 @@ public ArmorHud(int x, int y, int width, int height) { this.height = 256; } + @Override + public void update() { + + } + @Override public void draw(DrawContext drawContext, float partialTicks, Color color) { DefaultedList armors = mc.player.getInventory().armor; diff --git a/src/main/java/net/aoba/gui/hud/InfoHud.java b/src/main/java/net/aoba/gui/hud/InfoHud.java index be3215c6..47122da3 100644 --- a/src/main/java/net/aoba/gui/hud/InfoHud.java +++ b/src/main/java/net/aoba/gui/hud/InfoHud.java @@ -17,9 +17,7 @@ public InfoHud(int x, int y) { } @Override - public void update(double mouseX, double mouseY, boolean mouseClicked) { - super.update(mouseX, mouseY, mouseClicked); - + public void update() { MinecraftClient mc = MinecraftClient.getInstance(); int time = ((int)mc.world.getTime() + 6000)% 24000; diff --git a/src/main/java/net/aoba/gui/hud/ModuleSelectorHud.java b/src/main/java/net/aoba/gui/hud/ModuleSelectorHud.java index 726e5938..557fbea5 100644 --- a/src/main/java/net/aoba/gui/hud/ModuleSelectorHud.java +++ b/src/main/java/net/aoba/gui/hud/ModuleSelectorHud.java @@ -41,10 +41,7 @@ public ModuleSelectorHud() { } @Override - public void update(double mouseX, double mouseY, boolean mouseClicked) { - - super.update(mouseX, mouseY, mouseClicked); - + public void update() { if (!aoba.isGhosted()) { if (this.keybindUp.isPressed()) { if (!isCategoryMenuOpen) { diff --git a/src/main/java/net/aoba/gui/hud/RadarHud.java b/src/main/java/net/aoba/gui/hud/RadarHud.java index 0b78c32e..68878a2c 100644 --- a/src/main/java/net/aoba/gui/hud/RadarHud.java +++ b/src/main/java/net/aoba/gui/hud/RadarHud.java @@ -80,4 +80,9 @@ public void draw(DrawContext drawContext, float partialTicks, Color color) { } } } + + @Override + public void update() { + + } } \ No newline at end of file diff --git a/src/main/java/net/aoba/gui/tabs/ClickGuiTab.java b/src/main/java/net/aoba/gui/tabs/ClickGuiTab.java index e91f86b0..9305739b 100644 --- a/src/main/java/net/aoba/gui/tabs/ClickGuiTab.java +++ b/src/main/java/net/aoba/gui/tabs/ClickGuiTab.java @@ -30,6 +30,10 @@ import net.aoba.core.settings.types.BooleanSetting; import net.aoba.core.settings.types.Vector2Setting; import net.aoba.core.utils.types.Vector2; +import net.aoba.event.events.MouseLeftClickEvent; +import net.aoba.event.events.MouseMoveEvent; +import net.aoba.event.listeners.MouseLeftClickListener; +import net.aoba.event.listeners.MouseMoveListener; import net.aoba.gui.Color; import net.aoba.gui.HudManager; import net.aoba.gui.hud.AbstractHud; @@ -38,8 +42,7 @@ import net.minecraft.client.gui.DrawContext; import net.minecraft.client.util.math.MatrixStack; - -public class ClickGuiTab extends AbstractHud{ +public class ClickGuiTab extends AbstractHud implements MouseLeftClickListener, MouseMoveListener { protected String title; protected boolean pinnable = false; @@ -47,7 +50,7 @@ public class ClickGuiTab extends AbstractHud{ protected boolean pinWasClicked = false; protected boolean drawBorder = true; protected boolean inheritHeightFromChildren = true; - + protected ArrayList children = new ArrayList<>(); private Consumer update_pos; @@ -67,8 +70,8 @@ public ClickGuiTab(String title, int x, int y, boolean pinnable) { update_pos = new Consumer() { @Override public void accept(Vector2 vector2) { - setX((int)vector2.x); - setY((int)vector2.y); + setX((int) vector2.x); + setY((int) vector2.y); } }; @@ -83,9 +86,11 @@ public void accept(Boolean aBoolean) { pinned_setting = new BooleanSetting(title + "_pinned", "IS PINNED", false, update_pinned); SettingManager.register_setting(position, Aoba.getInstance().settingManager.hidden_category); SettingManager.register_setting(pinned_setting, Aoba.getInstance().settingManager.hidden_category); + + Aoba.getInstance().eventManager.AddListener(MouseLeftClickListener.class, this); + Aoba.getInstance().eventManager.AddListener(MouseMoveListener.class, this); } - public final String getTitle() { return title; } @@ -156,50 +161,20 @@ public final void addChild(Component component) { } @Override - public void update(double mouseX, double mouseY, boolean mouseClicked) { - if(this.inheritHeightFromChildren) { + public void update() { + if (this.inheritHeightFromChildren) { int tempHeight = 1; for (Component child : children) { tempHeight += (child.getHeight()); } this.height = tempHeight; } - + if (Aoba.getInstance().hudManager.isClickGuiOpen()) { - if (HudManager.currentGrabbed == null) { - if (mouseX >= (x) && mouseX <= (x + width)) { - if (mouseY >= (y) && mouseY <= (y + 28)) { - if (mouseClicked) { - boolean isInsidePinButton = false; - if(this.pinnable) { - if (mouseX >= (x + width - 24) && mouseX <= (x + width - 2)) { - if (mouseY >= (y + 4) && mouseY <= (y + 20)) { - isInsidePinButton = true; - } - } - } - if (isInsidePinButton) { - if (!this.pinWasClicked) { - this.isPinned = !this.isPinned; - this.pinWasClicked = true; - return; - } - } else { - if (!this.isPinned) HudManager.currentGrabbed = this; - } - } else { - if (this.pinWasClicked) { - this.pinWasClicked = false; - } - if (!this.isPinned) HudManager.currentGrabbed = this; - } - } - } - } int i = 30; for (Component child : this.children) { - child.update(i, mouseX, mouseY, mouseClicked); + child.update(i); i += child.getHeight(); } } @@ -218,20 +193,24 @@ public void postupdate() { @Override public void draw(DrawContext drawContext, float partialTicks, Color color) { MatrixStack matrixStack = drawContext.getMatrices(); - if(drawBorder) { + if (drawBorder) { // Draws background depending on components width and height - renderUtils.drawRoundedBox(matrixStack, x, y, width, height + 30, 6, new Color(30,30,30), 0.4f); - renderUtils.drawRoundedOutline(matrixStack, x, y, width, height + 30, 6, new Color(0,0,0), 0.8f); + renderUtils.drawRoundedBox(matrixStack, x, y, width, height + 30, 6, new Color(30, 30, 30), 0.4f); + renderUtils.drawRoundedOutline(matrixStack, x, y, width, height + 30, 6, new Color(0, 0, 0), 0.8f); renderUtils.drawString(drawContext, this.title, x + 8, y + 8, Aoba.getInstance().hudManager.getColor()); - renderUtils.drawLine(matrixStack, x, y + 30, x + width, y + 30, new Color(0,0,0), 0.4f); + renderUtils.drawLine(matrixStack, x, y + 30, x + width, y + 30, new Color(0, 0, 0), 0.4f); - if(this.pinnable) { + if (this.pinnable) { if (this.isPinned) { - renderUtils.drawRoundedBox(matrixStack, x + width - 23, y + 8, 15, 15, 6f, new Color(154,0,0), 0.8f); - renderUtils.drawRoundedOutline(matrixStack, x + width - 23, y + 8, 15, 15, 6f, new Color(0,0,0), 0.8f); + renderUtils.drawRoundedBox(matrixStack, x + width - 23, y + 8, 15, 15, 6f, new Color(154, 0, 0), + 0.8f); + renderUtils.drawRoundedOutline(matrixStack, x + width - 23, y + 8, 15, 15, 6f, new Color(0, 0, 0), + 0.8f); } else { - renderUtils.drawRoundedBox(matrixStack, x + width - 23, y + 8, 15, 15, 6f, new Color(128,128,128), 0.2f); - renderUtils.drawRoundedOutline(matrixStack, x + width - 23, y + 8, 15, 15, 6f, new Color(0,0,0), 0.2f); + renderUtils.drawRoundedBox(matrixStack, x + width - 23, y + 8, 15, 15, 6f, new Color(128, 128, 128), + 0.2f); + renderUtils.drawRoundedOutline(matrixStack, x + width - 23, y + 8, 15, 15, 6f, new Color(0, 0, 0), + 0.2f); } } } @@ -241,4 +220,86 @@ public void draw(DrawContext drawContext, float partialTicks, Color color) { i += child.getHeight(); } } + + @Override + public void OnMouseLeftClick(MouseLeftClickEvent event) { + super.OnMouseLeftClick(event); + + int mouseX = (int) Math.ceil(mc.mouse.getX()); + int mouseY = (int) Math.ceil(mc.mouse.getY()); + + if (Aoba.getInstance().hudManager.isClickGuiOpen()) { + if (HudManager.currentGrabbed == null) { + if (mouseX >= (x) && mouseX <= (x + width)) { + if (mouseY >= (y) && mouseY <= (y + 28)) { + boolean isInsidePinButton = false; + if (this.pinnable) { + if (mouseX >= (x + width - 24) && mouseX <= (x + width - 2)) { + if (mouseY >= (y + 4) && mouseY <= (y + 20)) { + isInsidePinButton = true; + } + } + } + if (isInsidePinButton) { + if (!this.pinWasClicked) { + this.isPinned = !this.isPinned; + this.pinWasClicked = true; + return; + } + } else { + if (!this.isPinned) { + HudManager.currentGrabbed = this; + } + } + } else { + if (this.pinWasClicked) { + this.pinWasClicked = false; + } + if (!this.isPinned) { + HudManager.currentGrabbed = this; + } + } + } + } + } + } + + @Override + public void OnMouseMove(MouseMoveEvent mouseMoveEvent) { + double mouseX = mouseMoveEvent.GetHorizontal(); + double mouseY = mouseMoveEvent.GetVertical(); + + if (HudManager.currentGrabbed == null) { + if (mouseX >= (x) && mouseX <= (x + width)) { + if (mouseY >= (y) && mouseY <= (y + 28)) { + boolean isInsidePinButton = false; + if (this.pinnable) { + if (mouseX >= (x + width - 24) && mouseX <= (x + width - 2)) { + if (mouseY >= (y + 4) && mouseY <= (y + 20)) { + isInsidePinButton = true; + } + } + } + if (isInsidePinButton) { + if (!this.pinWasClicked) { + this.isPinned = !this.isPinned; + this.pinWasClicked = true; + return; + } + } else { + if (!this.isPinned) { + // TODO: HudManager.currentGrabbed = this; + } + } + } else { + if (this.pinWasClicked) { + this.pinWasClicked = false; + } + if (!this.isPinned) { + // TODO: HudManager.currentGrabbed = this; + } + } + } + } + } } diff --git a/src/main/java/net/aoba/gui/tabs/OptionsTab.java b/src/main/java/net/aoba/gui/tabs/OptionsTab.java index 342c7949..23316904 100644 --- a/src/main/java/net/aoba/gui/tabs/OptionsTab.java +++ b/src/main/java/net/aoba/gui/tabs/OptionsTab.java @@ -21,7 +21,7 @@ public OptionsTab() { } @Override - public void update(double mouseX, double mouseY, boolean mouseClicked) { + public void update() { Window window = mc.getWindow(); this.setWidth(window.getWidth() - 240); this.setHeight(window.getHeight() - 240); diff --git a/src/main/java/net/aoba/gui/tabs/components/ButtonComponent.java b/src/main/java/net/aoba/gui/tabs/components/ButtonComponent.java index 99b6472b..97ddb592 100644 --- a/src/main/java/net/aoba/gui/tabs/components/ButtonComponent.java +++ b/src/main/java/net/aoba/gui/tabs/components/ButtonComponent.java @@ -1,12 +1,15 @@ package net.aoba.gui.tabs.components; +import net.aoba.Aoba; +import net.aoba.event.events.MouseLeftClickEvent; +import net.aoba.event.listeners.MouseLeftClickListener; import net.aoba.gui.Color; import net.aoba.gui.HudManager; import net.aoba.gui.tabs.ClickGuiTab; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.util.math.MatrixStack; -public class ButtonComponent extends Component { +public class ButtonComponent extends Component implements MouseLeftClickListener { private String text; private ClickGuiTab parent; @@ -18,42 +21,15 @@ public class ButtonComponent extends Component { private Color color = new Color(128, 128, 128); private Color backgroundColor = color; + private boolean focused = false; public ButtonComponent(ClickGuiTab parent, String text, Runnable onClick) { super(); this.text = text; this.parent = parent; this.onClick = onClick; - } - - public void update(int offset, double mouseX, double mouseY, boolean mouseClicked) { - float parentX = parent.getX(); - float parentY = parent.getY(); - float parentWidth = parent.getWidth(); - if (HudManager.currentGrabbed == null) { - if (mouseClicked) { - // Enable Module - if((mouseX >= ((parentX + 2)) && mouseX <= (((parentX + 2)) + parentWidth - 34)) && - (mouseY >= parentY + offset && mouseY <= (parentY + offset + 28))) { - backgroundColor = hoverColor; - hovered = true; - if (!this.wasClicked) { - try { - onClick.run(); - } catch (Exception e) { - e.printStackTrace(); - } - this.wasClicked = true; - return; - } - }else { - this.backgroundColor = color; - this.hovered = false; - this.wasClicked = false; - } - } - } + Aoba.getInstance().eventManager.AddListener(MouseLeftClickListener.class, this); } public void setText(String text) { @@ -75,4 +51,31 @@ public void draw(int offset, DrawContext drawContext, float partialTicks, Color renderUtils.drawString(drawContext, this.text, parentX + 8, parentY + 8 + offset, 0xFFFFFF); } -} \ No newline at end of file + + @Override + public void OnMouseLeftClick(MouseLeftClickEvent event) { + float parentX = parent.getX(); + float parentY = parent.getY(); + float parentWidth = parent.getWidth(); + + int mouseX = event.GetMouseX(); + int mouseY = event.GetMouseY(); + + if (HudManager.currentGrabbed == null) { + // Enable Module + if ((mouseX >= ((parentX + 2)) && mouseX <= (((parentX + 2)) + parentWidth - 34)) + && (mouseY >= parentY + offset && mouseY <= (parentY + offset + 28))) { + backgroundColor = hoverColor; + hovered = true; + if (!this.wasClicked) { + focused = true; + } + } else { + this.backgroundColor = color; + this.hovered = false; + this.wasClicked = false; + focused = true; + } + } + } +} diff --git a/src/main/java/net/aoba/gui/tabs/components/CheckboxComponent.java b/src/main/java/net/aoba/gui/tabs/components/CheckboxComponent.java index 62b87a37..48e80803 100644 --- a/src/main/java/net/aoba/gui/tabs/components/CheckboxComponent.java +++ b/src/main/java/net/aoba/gui/tabs/components/CheckboxComponent.java @@ -1,13 +1,16 @@ package net.aoba.gui.tabs.components; +import net.aoba.Aoba; import net.aoba.core.settings.types.BooleanSetting; +import net.aoba.event.events.MouseLeftClickEvent; +import net.aoba.event.listeners.MouseLeftClickListener; import net.aoba.gui.Color; import net.aoba.gui.HudManager; import net.aoba.gui.tabs.ClickGuiTab; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.util.math.MatrixStack; -public class CheckboxComponent extends Component { +public class CheckboxComponent extends Component implements MouseLeftClickListener { private String text; private boolean wasClicked = false; @@ -18,15 +21,42 @@ public CheckboxComponent(ClickGuiTab parent, BooleanSetting checkbox) { this.text = checkbox.displayName; this.parent = parent; this.checkbox = checkbox; + + Aoba.getInstance().eventManager.AddListener(MouseLeftClickListener.class, this); } @Override - public void update(int offset, double mouseX, double mouseY, boolean mouseClicked) { + public void draw(int offset, DrawContext drawContext, float partialTicks, Color color) { + float parentX = parent.getX(); + float parentY = parent.getY(); + float parentWidth = parent.getWidth(); + MatrixStack matrixStack = drawContext.getMatrices(); + renderUtils.drawString(drawContext, this.text, parentX + 10, + parentY + offset + 8, 0xFFFFFF); + if(this.checkbox.getValue()) { + renderUtils.drawOutlinedBox(matrixStack, parentX + parentWidth - 24, parentY + 1 + offset, 20, 20, new Color(0,154,0), 0.8f); + }else { + renderUtils.drawOutlinedBox(matrixStack, parentX + parentWidth - 24, parentY + 1 + offset, 20, 20, new Color(154,0,0), 0.8f); + } + } + + @Override + public void update(int offset) { + // TODO Auto-generated method stub + + } + + @Override + public void OnMouseLeftClick(MouseLeftClickEvent event) { float parentX = parent.getX(); float parentY = parent.getY(); float parentWidth = parent.getWidth(); + + int mouseX = event.GetMouseX(); + int mouseY = event.GetMouseY(); + if (HudManager.currentGrabbed == null) { - if (mouseClicked) { + if (!this.wasClicked) { if (mouseX >= ((parentX + parent.getWidth() - 28)) && mouseX <= ((parentX + parentWidth - 8))) { if (mouseY >= (((parentY + offset + 2))) @@ -34,30 +64,10 @@ public void update(int offset, double mouseX, double mouseY, boolean mouseClicke if (!this.wasClicked) { checkbox.toggle(); this.wasClicked = true; - return; } } } - } else { - if (this.wasClicked) { - this.wasClicked = false; - } } } } - - @Override - public void draw(int offset, DrawContext drawContext, float partialTicks, Color color) { - float parentX = parent.getX(); - float parentY = parent.getY(); - float parentWidth = parent.getWidth(); - MatrixStack matrixStack = drawContext.getMatrices(); - renderUtils.drawString(drawContext, this.text, parentX + 10, - parentY + offset + 8, 0xFFFFFF); - if(this.checkbox.getValue()) { - renderUtils.drawOutlinedBox(matrixStack, parentX + parentWidth - 24, parentY + 1 + offset, 20, 20, new Color(0,154,0), 0.8f); - }else { - renderUtils.drawOutlinedBox(matrixStack, parentX + parentWidth - 24, parentY + 1 + offset, 20, 20, new Color(154,0,0), 0.8f); - } - } } diff --git a/src/main/java/net/aoba/gui/tabs/components/Component.java b/src/main/java/net/aoba/gui/tabs/components/Component.java index 0a33e988..9ae98b96 100644 --- a/src/main/java/net/aoba/gui/tabs/components/Component.java +++ b/src/main/java/net/aoba/gui/tabs/components/Component.java @@ -1,23 +1,33 @@ package net.aoba.gui.tabs.components; import net.aoba.Aoba; +import net.aoba.event.events.MouseMoveEvent; +import net.aoba.event.listeners.MouseMoveListener; import net.aoba.gui.Color; import net.aoba.gui.tabs.ClickGuiTab; import net.aoba.misc.RenderUtils; import net.minecraft.client.gui.DrawContext; -public abstract class Component { +public abstract class Component implements MouseMoveListener { protected RenderUtils renderUtils; protected ClickGuiTab parent; private int height = 30; private boolean visible = true; + protected int offset; + protected boolean hovered = false; public Component() { this.renderUtils = Aoba.getInstance().renderUtils; + Aoba.getInstance().eventManager.AddListener(MouseMoveListener.class, this); } public void setVisible(boolean bool) { this.visible = bool; + if(bool) { + Aoba.getInstance().eventManager.AddListener(MouseMoveListener.class, this); + }else { + Aoba.getInstance().eventManager.RemoveListener(MouseMoveListener.class, this); + } } public boolean isVisible() { @@ -44,6 +54,22 @@ public void setParent(ClickGuiTab parent) this.parent = parent; } - public abstract void update(int offset, double mouseX, double mouseY, boolean mouseClicked); + public void update(int offset) { + this.offset = offset; + } + public abstract void draw(int offset, DrawContext drawContext, float partialTicks, Color color); + + @Override + public void OnMouseMove(MouseMoveEvent mouseMoveEvent) { + System.out.println("Mouse Move Component"); + float parentX = parent.getX(); + float parentY = parent.getY(); + float parentWidth = parent.getWidth(); + + double mouseX = mouseMoveEvent.GetHorizontal(); + double mouseY = mouseMoveEvent.GetVertical(); + + this.hovered = ((mouseX >= parentX && mouseX <= (parentX + parentWidth)) && (mouseY >= parentY + offset && mouseY <= (parentY + offset + 28))); + } } diff --git a/src/main/java/net/aoba/gui/tabs/components/KeybindComponent.java b/src/main/java/net/aoba/gui/tabs/components/KeybindComponent.java new file mode 100644 index 00000000..4b0b3c0f --- /dev/null +++ b/src/main/java/net/aoba/gui/tabs/components/KeybindComponent.java @@ -0,0 +1,86 @@ +package net.aoba.gui.tabs.components; + +import net.aoba.Aoba; +import net.aoba.event.events.MouseLeftClickEvent; +import net.aoba.event.listeners.MouseLeftClickListener; +import net.aoba.gui.Color; +import net.aoba.gui.HudManager; +import net.aoba.gui.tabs.ClickGuiTab; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.util.math.MatrixStack; + +public class KeybindComponent extends Component implements MouseLeftClickListener { + + private String text; + private ClickGuiTab parent; + private boolean wasClicked = false; + private boolean hovered = false; + private Runnable onClick; + + private Color hoverColor = new Color(90, 90, 90); + private Color color = new Color(128, 128, 128); + + private Color backgroundColor = color; + + public KeybindComponent(ClickGuiTab parent, String text, Runnable onClick) { + super(); + this.text = text; + this.parent = parent; + this.onClick = onClick; + + Aoba.getInstance().eventManager.AddListener(MouseLeftClickListener.class, this); + } + + public void setText(String text) { + this.text = text; + } + + public void setOnClick(Runnable onClick) { + this.onClick = onClick; + } + + @Override + public void draw(int offset, DrawContext drawContext, float partialTicks, Color color) { + float parentX = parent.getX(); + float parentY = parent.getY(); + float parentWidth = parent.getWidth(); + MatrixStack matrixStack = drawContext.getMatrices(); + renderUtils.drawOutlinedBox(matrixStack, parentX + 2, parentY + offset, parentWidth - 4, this.getHeight() - 2, + backgroundColor, 0.2f); + + renderUtils.drawString(drawContext, this.text, parentX + 8, parentY + 8 + offset, 0xFFFFFF); + } + + @Override + public void OnMouseLeftClick(MouseLeftClickEvent event) { + float parentX = parent.getX(); + float parentY = parent.getY(); + float parentWidth = parent.getWidth(); + + int mouseX = event.GetMouseX(); + int mouseY = event.GetMouseY(); + + if (HudManager.currentGrabbed == null) { + if (!this.wasClicked) { + // Enable Module + if((mouseX >= ((parentX + 2)) && mouseX <= (((parentX + 2)) + parentWidth - 34)) && + (mouseY >= parentY + offset && mouseY <= (parentY + offset + 28))) { + backgroundColor = hoverColor; + hovered = true; + if (!this.wasClicked) { + try { + onClick.run(); + } catch (Exception e) { + e.printStackTrace(); + } + this.wasClicked = true; + } + }else { + this.backgroundColor = color; + this.hovered = false; + this.wasClicked = false; + } + } + } + } +} \ No newline at end of file diff --git a/src/main/java/net/aoba/gui/tabs/components/ListComponent.java b/src/main/java/net/aoba/gui/tabs/components/ListComponent.java index b955860a..7e69c67a 100644 --- a/src/main/java/net/aoba/gui/tabs/components/ListComponent.java +++ b/src/main/java/net/aoba/gui/tabs/components/ListComponent.java @@ -3,7 +3,10 @@ import java.util.ArrayList; import java.util.List; +import net.aoba.Aoba; import net.aoba.core.settings.types.IndexedStringListSetting; +import net.aoba.event.events.MouseLeftClickEvent; +import net.aoba.event.listeners.MouseLeftClickListener; import net.aoba.gui.Color; import net.aoba.gui.HudManager; import net.aoba.gui.tabs.ClickGuiTab; @@ -11,7 +14,7 @@ import net.minecraft.client.gui.DrawContext; import net.minecraft.client.util.math.MatrixStack; -public class ListComponent extends Component { +public class ListComponent extends Component implements MouseLeftClickListener { private String text; private boolean wasClicked = false; @@ -22,6 +25,8 @@ public ListComponent(String text, ClickGuiTab parent) { super(); this.text = text; this.parent = parent; + + Aoba.getInstance().eventManager.AddListener(MouseLeftClickListener.class, this); } public ListComponent(ClickGuiTab parent, IndexedStringListSetting list) { @@ -29,15 +34,35 @@ public ListComponent(ClickGuiTab parent, IndexedStringListSetting list) { this.text = list.displayName; this.parent = parent; this.list = list; + + Aoba.getInstance().eventManager.AddListener(MouseLeftClickListener.class, this); } @Override - public void update(int offset, double mouseX, double mouseY, boolean mouseClicked) { + public void draw(int offset, DrawContext drawContext, float partialTicks, Color color) { float parentX = parent.getX(); float parentY = parent.getY(); float parentWidth = parent.getWidth(); + int length = MinecraftClient.getInstance().textRenderer.getWidth(list.getIndexValue()); + MatrixStack matrixStack = drawContext.getMatrices(); + renderUtils.drawOutlinedBox(matrixStack, parentX + 4, parentY + offset, parentWidth - 8, 22, new Color(25,25,25), + 0.3f); + renderUtils.drawString(drawContext, list.getIndexValue(), (parentX + (parentWidth / 2)) - length , parentY + offset + 4, 0xFFFFFF); + renderUtils.drawString(drawContext,"<<", parentX + 8, parentY + offset + 4, 0xFFFFFF); + renderUtils.drawString(drawContext,">>", parentX + 8 + (parentWidth - 34), parentY + offset + 4, 0xFFFFFF); + } + + @Override + public void OnMouseLeftClick(MouseLeftClickEvent event) { + float parentX = parent.getX(); + float parentY = parent.getY(); + float parentWidth = parent.getWidth(); + + int mouseX = event.GetMouseX(); + int mouseY = event.GetMouseY(); + if (HudManager.currentGrabbed == null) { - if (mouseClicked) { + if (!wasClicked) { if (mouseY >= (((parentY + offset + 4))) && mouseY <= (parentY + offset + 22)) { // If Left arrow clicked. if (mouseX >= ((parentX + 4)) && mouseX <= ((parentX + 64))) { @@ -56,25 +81,7 @@ public void update(int offset, double mouseX, double mouseY, boolean mouseClicke } } } - } else { - if (this.wasClicked) { - this.wasClicked = false; - } } } } - - @Override - public void draw(int offset, DrawContext drawContext, float partialTicks, Color color) { - float parentX = parent.getX(); - float parentY = parent.getY(); - float parentWidth = parent.getWidth(); - int length = MinecraftClient.getInstance().textRenderer.getWidth(list.getIndexValue()); - MatrixStack matrixStack = drawContext.getMatrices(); - renderUtils.drawOutlinedBox(matrixStack, parentX + 4, parentY + offset, parentWidth - 8, 22, new Color(25,25,25), - 0.3f); - renderUtils.drawString(drawContext, list.getIndexValue(), (parentX + (parentWidth / 2)) - length , parentY + offset + 4, 0xFFFFFF); - renderUtils.drawString(drawContext,"<<", parentX + 8, parentY + offset + 4, 0xFFFFFF); - renderUtils.drawString(drawContext,">>", parentX + 8 + (parentWidth - 34), parentY + offset + 4, 0xFFFFFF); - } } diff --git a/src/main/java/net/aoba/gui/tabs/components/ModuleComponent.java b/src/main/java/net/aoba/gui/tabs/components/ModuleComponent.java index c4c6ef1a..c9ce2a68 100644 --- a/src/main/java/net/aoba/gui/tabs/components/ModuleComponent.java +++ b/src/main/java/net/aoba/gui/tabs/components/ModuleComponent.java @@ -3,11 +3,14 @@ import java.util.ArrayList; import java.util.List; +import net.aoba.Aoba; import net.aoba.core.settings.Setting; import net.aoba.core.settings.types.BooleanSetting; import net.aoba.core.settings.types.FloatSetting; import net.aoba.core.settings.types.IndexedStringListSetting; import net.aoba.core.settings.types.StringListSetting; +import net.aoba.event.events.MouseLeftClickEvent; +import net.aoba.event.listeners.MouseLeftClickListener; import net.aoba.module.Module; import net.aoba.gui.Color; import net.aoba.gui.HudManager; @@ -15,17 +18,17 @@ import net.minecraft.client.gui.DrawContext; import net.minecraft.client.util.math.MatrixStack; -public class ModuleComponent extends Component { +public class ModuleComponent extends Component implements MouseLeftClickListener { private String text; private Module module; private ClickGuiTab parent; private boolean wasClicked = false; private boolean popped = false; - private boolean hovered = false; + private int expandedHeight = 30; - + private Color hoverColor = new Color(90, 90, 90); private Color color = new Color(128, 128, 128); @@ -51,67 +54,25 @@ public ModuleComponent(String text, ClickGuiTab parent, Module module) { } settingsList.add(c); } - + RecalculateExpandedHeight(); + + Aoba.getInstance().eventManager.AddListener(MouseLeftClickListener.class, this); } - - - public void update(int offset, double mouseX, double mouseY, boolean mouseClicked) { - float parentX = parent.getX(); - float parentY = parent.getY(); - float parentWidth = parent.getWidth(); - + @Override + public void update(int offset) { + super.update(offset); + // If the Module options are popped, display all of the options. if (this.popped) { - // Updates all of the options. + // Updates all of the options. int i = offset + 30; for (Component children : this.settingsList) { - children.update(i, mouseX, mouseY, mouseClicked); + children.update(i); i += children.getHeight(); } } - - // As long as no other Component is being grabbed. - if (HudManager.currentGrabbed == null) { - - // Check if the current Module Component is currently hovered over. - hovered = ((mouseX >= parentX && mouseX <= (parentX + parentWidth)) && (mouseY >= parentY + offset && mouseY <= (parentY + offset + 28))); - if(hovered) { - backgroundColor = hoverColor; - boolean isOnOptionsButton = (mouseX >= (parentX + parentWidth - 34) && mouseX <= (parentX + parentWidth)); - if(isOnOptionsButton) { - if (mouseClicked) { - if (!this.wasClicked) { - this.popped = !this.popped; - - if(this.popped) { - this.setHeight(expandedHeight); - }else { - this.setHeight(30); - } - this.wasClicked = true; - return; - } - } - }else { - if (mouseClicked) { - if (!this.wasClicked) { - module.toggle(); - this.wasClicked = true; - return; - } - } - } - - this.wasClicked = (mouseClicked && this.wasClicked); - }else { - backgroundColor = color; - this.wasClicked = false; - } - }else { - backgroundColor = hoverColor; - } } @Override @@ -120,7 +81,8 @@ public void draw(int offset, DrawContext drawContext, float partialTicks, Color float parentY = parent.getY(); float parentWidth = parent.getWidth(); MatrixStack matrixStack = drawContext.getMatrices(); - //renderUtils.drawOutlinedBox(matrixStack, parentX + 2, parentY + offset, parentWidth - 4, this.getHeight() - 2, backgroundColor, 0.2f); + // renderUtils.drawOutlinedBox(matrixStack, parentX + 2, parentY + offset, + // parentWidth - 4, this.getHeight() - 2, backgroundColor, 0.2f); if (this.popped) { int i = offset + 30; @@ -139,7 +101,7 @@ public void draw(int offset, DrawContext drawContext, float partialTicks, Color parentY + 8 + offset, color.getColorAsInt()); } } - + public void RecalculateExpandedHeight() { int height = 30; for (Component children : this.settingsList) { @@ -149,4 +111,33 @@ public void RecalculateExpandedHeight() { } expandedHeight = height; } + + @Override + public void OnMouseLeftClick(MouseLeftClickEvent event) { + float parentX = parent.getX(); + float parentY = parent.getY(); + float parentWidth = parent.getWidth(); + + int mouseX = event.GetMouseX(); + int mouseY = event.GetMouseY(); + + if (hovered) { + backgroundColor = hoverColor; + boolean isOnOptionsButton = (mouseX >= (parentX + parentWidth - 34) && mouseX <= (parentX + parentWidth)); + if (isOnOptionsButton) { + this.popped = !this.popped; + + if (this.popped) { + this.setHeight(expandedHeight); + } else { + this.setHeight(30); + } + } else { + module.toggle(); + return; + } + } else { + backgroundColor = color; + } + } } diff --git a/src/main/java/net/aoba/gui/tabs/components/SliderComponent.java b/src/main/java/net/aoba/gui/tabs/components/SliderComponent.java index 784cab1c..a6e2c92c 100644 --- a/src/main/java/net/aoba/gui/tabs/components/SliderComponent.java +++ b/src/main/java/net/aoba/gui/tabs/components/SliderComponent.java @@ -1,13 +1,16 @@ package net.aoba.gui.tabs.components; +import net.aoba.Aoba; import net.aoba.core.settings.types.FloatSetting; +import net.aoba.event.events.MouseLeftClickEvent; +import net.aoba.event.listeners.MouseLeftClickListener; import net.aoba.gui.Color; import net.aoba.gui.HudManager; import net.aoba.gui.tabs.ClickGuiTab; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.util.math.MatrixStack; -public class SliderComponent extends Component { +public class SliderComponent extends Component implements MouseLeftClickListener { private String text; private ClickGuiTab parent; @@ -15,7 +18,7 @@ public class SliderComponent extends Component { float r; float g; float b; - + FloatSetting slider; public SliderComponent(String text, ClickGuiTab parent) { @@ -23,6 +26,8 @@ public SliderComponent(String text, ClickGuiTab parent) { this.text = text; this.parent = parent; this.slider = null; + + Aoba.getInstance().eventManager.AddListener(MouseLeftClickListener.class, this); } public SliderComponent(ClickGuiTab parent, FloatSetting slider) { @@ -30,26 +35,8 @@ public SliderComponent(ClickGuiTab parent, FloatSetting slider) { this.text = slider.displayName; this.parent = parent; this.slider = slider; - this.currentSliderPosition = (float) ((slider.getValue() - slider.min_value) / (slider.max_value - slider.min_value)); - } - - @Override - public void update(int offset, double mouseX, double mouseY, boolean mouseClicked) { - float parentX = parent.getX(); - float parentY = parent.getY(); - float parentWidth = parent.getWidth(); - if (HudManager.currentGrabbed == null) { - if (mouseClicked) { - if (mouseX >= ((parentX + 2)) && mouseX <= (((parentX)) + parentWidth - 2)) { - if (mouseY >= (((parentY + offset))) - && mouseY <= ((parentY + offset) + 24)) { - this.currentSliderPosition = (float) Math.min((((mouseX - ((parentX + 4))) - 1) / ((parentWidth - 12))), 1f); - this.currentSliderPosition = (float) Math.max(0f,this.currentSliderPosition); - this.slider.setValue((this.currentSliderPosition * (slider.max_value - slider.min_value)) + slider.min_value); - } - } - } - } + this.currentSliderPosition = (float) ((slider.getValue() - slider.min_value) + / (slider.max_value - slider.min_value)); } @Override @@ -58,15 +45,18 @@ public void draw(int offset, DrawContext drawContext, float partialTicks, Color float parentY = parent.getY(); float parentWidth = parent.getWidth(); MatrixStack matrixStack = drawContext.getMatrices(); - renderUtils.drawBox(matrixStack, parentX + 3, parentY + offset, parentWidth - 6, 24, 0.5f, 0.5f, 0.5f, - 0.3f); + renderUtils.drawBox(matrixStack, parentX + 3, parentY + offset, parentWidth - 6, 24, 0.5f, 0.5f, 0.5f, 0.3f); renderUtils.drawBox(matrixStack, parentX + 3, parentY + offset, - (int) Math.floor((parentWidth - 6) * (float) ((slider.getValue() - slider.min_value) / (slider.max_value - slider.min_value))), 24, color, 1f); + (int) Math.floor((parentWidth - 6) + * (float) ((slider.getValue() - slider.min_value) / (slider.max_value - slider.min_value))), + 24, color, 1f); renderUtils.drawOutline(matrixStack, parentX + 3, parentY + offset, parentWidth - 6, 24); - if(this.slider == null) return; - // TODO: Slow but it works. Perhaps we can modify a STORED string using our new Consumer delegates? - renderUtils.drawString(drawContext, this.text + ": " + String.format("%.02f", this.slider.getValue()), parentX + 10, - parentY + 6 + offset, 0xFFFFFF); + if (this.slider == null) + return; + // TODO: Slow but it works. Perhaps we can modify a STORED string using our new + // Consumer delegates? + renderUtils.drawString(drawContext, this.text + ": " + String.format("%.02f", this.slider.getValue()), + parentX + 10, parentY + 6 + offset, 0xFFFFFF); } public float getSliderPosition() { @@ -91,4 +81,26 @@ public void setColor(float r, float g, float b) { this.b = b; } + @Override + public void OnMouseLeftClick(MouseLeftClickEvent event) { + float parentX = parent.getX(); + float parentY = parent.getY(); + + int mouseX = event.GetMouseX(); + int mouseY = event.GetMouseY(); + + float parentWidth = parent.getWidth(); + if (HudManager.currentGrabbed == null) { + if (mouseX >= ((parentX + 2)) && mouseX <= (((parentX)) + parentWidth - 2)) { + if (mouseY >= (((parentY + offset))) && mouseY <= ((parentY + offset) + 24)) { + this.currentSliderPosition = (float) Math + .min((((mouseX - ((parentX + 4))) - 1) / ((parentWidth - 12))), 1f); + this.currentSliderPosition = (float) Math.max(0f, this.currentSliderPosition); + this.slider.setValue( + (this.currentSliderPosition * (slider.max_value - slider.min_value)) + slider.min_value); + } + } + } + } + } diff --git a/src/main/java/net/aoba/gui/tabs/components/StringComponent.java b/src/main/java/net/aoba/gui/tabs/components/StringComponent.java index 9b3bac14..cbc0c44b 100644 --- a/src/main/java/net/aoba/gui/tabs/components/StringComponent.java +++ b/src/main/java/net/aoba/gui/tabs/components/StringComponent.java @@ -63,10 +63,6 @@ public StringComponent(String text, ClickGuiTab parent, boolean bold) { this.parent = parent; } - public void update(int offset, double mouseX, double mouseY, boolean mouseClicked) { - - } - @Override public void draw(int offset, DrawContext drawContext, float partialTicks, Color color) { float parentX = this.parent.getX(); diff --git a/src/main/java/net/aoba/mixin/KeyboardMixin.java b/src/main/java/net/aoba/mixin/KeyboardMixin.java new file mode 100644 index 00000000..c2077c84 --- /dev/null +++ b/src/main/java/net/aoba/mixin/KeyboardMixin.java @@ -0,0 +1,25 @@ +package net.aoba.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.aoba.Aoba; +import net.aoba.event.events.KeyDownEvent; +import net.minecraft.client.Keyboard; + +@Mixin(Keyboard.class) +public class KeyboardMixin { + + @Inject(at = {@At("HEAD")}, method = {"onKey(JIIII)V" }) + private void OnKeyDown(long window, int key, int scancode, + int action, int modifiers, CallbackInfo ci) { + KeyDownEvent event = new KeyDownEvent(window, key, scancode, action, modifiers); + Aoba.getInstance().eventManager.Fire(event); + + if(event.IsCancelled()) { + ci.cancel(); + } + } +} diff --git a/src/main/java/net/aoba/mixin/MinecraftClientMixin.java b/src/main/java/net/aoba/mixin/MinecraftClientMixin.java index e3946062..a492126d 100644 --- a/src/main/java/net/aoba/mixin/MinecraftClientMixin.java +++ b/src/main/java/net/aoba/mixin/MinecraftClientMixin.java @@ -1,9 +1,11 @@ package net.aoba.mixin; import net.aoba.Aoba; +import net.aoba.event.events.MouseLeftClickEvent; import net.aoba.event.events.TickEvent; import net.aoba.interfaces.IMinecraftClient; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.Mouse; import net.minecraft.client.util.Session; import net.minecraft.client.world.ClientWorld; import net.minecraft.util.thread.ReentrantThreadExecutor; @@ -25,9 +27,15 @@ public abstract class MinecraftClientMixin extends ReentrantThreadExecutor cir) { - if (Aoba.getInstance().hudManager.isClickGuiOpen()) { + int mouseX = (int) Math.ceil(mouse.getX()); + int mouseY = (int) Math.ceil(mouse.getY()); + + MouseLeftClickEvent event = new MouseLeftClickEvent(mouseX, mouseY); + + Aoba.getInstance().eventManager.Fire(event); + + if(event.IsCancelled()) { cir.setReturnValue(false); cir.cancel(); } diff --git a/src/main/java/net/aoba/mixin/MouseMixin.java b/src/main/java/net/aoba/mixin/MouseMixin.java index c091b91e..48e03b42 100644 --- a/src/main/java/net/aoba/mixin/MouseMixin.java +++ b/src/main/java/net/aoba/mixin/MouseMixin.java @@ -5,6 +5,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import net.aoba.Aoba; +import net.aoba.event.events.MouseMoveEvent; import net.minecraft.client.Mouse; @Mixin(Mouse.class) @@ -13,6 +14,18 @@ public class MouseMixin @Inject(at = {@At("HEAD")}, method = {"lockCursor()V"}, cancellable = true) private void onLockCursor(CallbackInfo ci) { - if(Aoba.getInstance().hudManager.isClickGuiOpen()) ci.cancel(); + if(Aoba.getInstance().hudManager.isClickGuiOpen()) + ci.cancel(); + } + + @Inject(at = {@At(value = "INVOKE", target = "Lnet/minecraft/client/Mouse;updateMouse()V") }, method = {"onCursorPos(JDD)V" }, cancellable = true) + private void onCursorPos(long window, double x, double y, CallbackInfo ci) { + if(Aoba.getInstance().hudManager.isClickGuiOpen()) { + MouseMoveEvent event = new MouseMoveEvent(x, y); + Aoba.getInstance().eventManager.Fire(event); + + if(event.IsCancelled()) + ci.cancel(); + } } } \ No newline at end of file