Skip to content

Commit

Permalink
Several changed pertaining to UI and the new event system. (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
coltonk9043 committed Sep 3, 2023
1 parent 2a70420 commit 5cecfc1
Show file tree
Hide file tree
Showing 29 changed files with 711 additions and 285 deletions.
7 changes: 4 additions & 3 deletions src/main/java/net/aoba/AobaClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/net/aoba/event/events/AbstractEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ public boolean IsCancelled() {
return isCancelled;
}

public void SetCancelled(boolean state) {
this.isCancelled = state;
}

public abstract void Fire(ArrayList<? extends AbstractListener> listeners);
public abstract <T extends AbstractListener> Class<T> GetListenerClassType();
}
57 changes: 57 additions & 0 deletions src/main/java/net/aoba/event/events/KeyDownEvent.java
Original file line number Diff line number Diff line change
@@ -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<? extends AbstractListener> listeners) {
for(AbstractListener listener : listeners) {
KeyDownListener keyDownListener = (KeyDownListener) listener;
keyDownListener.OnKeyDown(this);
}
}

@SuppressWarnings("unchecked")
@Override
public Class<KeyDownListener> GetListenerClassType() {
return KeyDownListener.class;
}
}
39 changes: 39 additions & 0 deletions src/main/java/net/aoba/event/events/MouseLeftClickEvent.java
Original file line number Diff line number Diff line change
@@ -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<? extends AbstractListener> listeners) {
for(AbstractListener listener : listeners) {
MouseLeftClickListener mouseLeftClickListener = (MouseLeftClickListener) listener;
mouseLeftClickListener.OnMouseLeftClick(this);
}
}

@SuppressWarnings("unchecked")
@Override
public Class<MouseLeftClickListener> GetListenerClassType() {
return MouseLeftClickListener.class;
}
}
40 changes: 40 additions & 0 deletions src/main/java/net/aoba/event/events/MouseMoveEvent.java
Original file line number Diff line number Diff line change
@@ -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<? extends AbstractListener> listeners) {
for(AbstractListener listener : listeners) {
MouseMoveListener mouseMoveListener = (MouseMoveListener) listener;
mouseMoveListener.OnMouseMove(this);
}
}

@SuppressWarnings("unchecked")
@Override
public Class<MouseScrollListener> GetListenerClassType() {
return MouseScrollListener.class;
}
}
7 changes: 7 additions & 0 deletions src/main/java/net/aoba/event/listeners/KeyDownListener.java
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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);
}
7 changes: 7 additions & 0 deletions src/main/java/net/aoba/event/listeners/MouseMoveListener.java
Original file line number Diff line number Diff line change
@@ -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);
}
50 changes: 26 additions & 24 deletions src/main/java/net/aoba/gui/HudManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -45,8 +47,6 @@ public class HudManager {

private int lastMouseX = 0;
private int lastMouseY = 0;
private int mouseX;
private int mouseY;

private List<AbstractHud> activeHuds = new ArrayList<AbstractHud>();

Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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();
}


Expand Down Expand Up @@ -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;
}
}
}
47 changes: 27 additions & 20 deletions src/main/java/net/aoba/gui/NavigationBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<NavigationPane> options;
Expand All @@ -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();
}
}

Expand All @@ -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;
}
}
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/net/aoba/gui/NavigationPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
Loading

0 comments on commit 5cecfc1

Please sign in to comment.