Skip to content

Commit

Permalink
Removed IMoveable interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
coltonk9043 committed Sep 16, 2023
1 parent 93385f7 commit aa1f65c
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 60 deletions.
6 changes: 2 additions & 4 deletions src/main/java/net/aoba/event/events/MouseMoveEvent.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
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;
Expand Down Expand Up @@ -34,7 +32,7 @@ public void Fire(ArrayList<? extends AbstractListener> listeners) {

@SuppressWarnings("unchecked")
@Override
public Class<MouseScrollListener> GetListenerClassType() {
return MouseScrollListener.class;
public Class<MouseMoveListener> GetListenerClassType() {
return MouseMoveListener.class;
}
}
19 changes: 2 additions & 17 deletions src/main/java/net/aoba/gui/HudManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ public class HudManager implements MouseLeftClickListener {

private boolean clickGuiOpen = false;

public static IMoveable currentGrabbed = null;

private int lastMouseX = 0;
private int lastMouseY = 0;
public static AbstractHud currentGrabbed = null;

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

Expand Down Expand Up @@ -196,7 +193,7 @@ public void draw(DrawContext drawContext, float tickDelta) {

MatrixStack matrixStack = drawContext.getMatrices();
matrixStack.push();
matrixStack.scale(1.0f/mc.options.getGuiScale().getValue(), 1.0f/mc.options.getGuiScale().getValue(), 1.0f);
matrixStack.scale(1.0f / mc.options.getGuiScale().getValue(), 1.0f / mc.options.getGuiScale().getValue(), 1.0f);

Window window = mc.getWindow();

Expand Down Expand Up @@ -241,18 +238,6 @@ public void toggleMouse() {
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;
}
}
}
12 changes: 0 additions & 12 deletions src/main/java/net/aoba/gui/IMoveable.java

This file was deleted.

48 changes: 40 additions & 8 deletions src/main/java/net/aoba/gui/hud/AbstractHud.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,40 @@
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.IMoveable;
import net.aoba.misc.RenderUtils;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;

import java.util.function.Consumer;

public abstract class AbstractHud implements IMoveable, MouseLeftClickListener {
public abstract class AbstractHud implements MouseLeftClickListener, MouseMoveListener {
protected static RenderUtils renderUtils = new RenderUtils();
protected static MinecraftClient mc = MinecraftClient.getInstance();

protected String ID;
protected float x;
protected float y;
protected float width;
protected float height;

protected RenderUtils renderUtils = new RenderUtils();
protected MinecraftClient mc = MinecraftClient.getInstance();

protected boolean isMouseOver = false;
protected boolean moveable = true;

// Mouse Variables
protected float lastMouseX;
protected float lastMouseY;


private Vector2Setting position_setting;
private Consumer<Vector2> position_setting_update;

public AbstractHud(String ID, int x, int y, int width, int height) {
this.ID = ID;
this.x = x;
this.y = y;
this.width = width;
Expand All @@ -43,6 +54,9 @@ public void accept(Vector2 vector2) {

position_setting = new Vector2Setting(ID + "_position", "Position", new Vector2(x, y), position_setting_update);
SettingManager.register_setting(position_setting, Aoba.getInstance().settingManager.hidden_category);

Aoba.getInstance().eventManager.AddListener(MouseLeftClickListener.class, this);
Aoba.getInstance().eventManager.AddListener(MouseMoveListener.class, this);
}

public float getX() {
Expand Down Expand Up @@ -90,12 +104,30 @@ public void OnMouseLeftClick(MouseLeftClickEvent event) {

if (Aoba.getInstance().hudManager.isClickGuiOpen()) {
if (HudManager.currentGrabbed == null) {
if (mouseX >= (x) && mouseX <= (x + width)) {
if (mouseY >= (y) && mouseY <= (y + height)) {
HudManager.currentGrabbed = this;
if (mouseX >= x && mouseX <= (x + width)) {
if (mouseY >= y && mouseY <= (y + height)) {
System.out.println(ID + " was clicked!");
//HudManager.currentGrabbed = this;
lastMouseX = mouseX;
lastMouseY = mouseY;
}
}
}
}
}

@Override
public void OnMouseMove(MouseMoveEvent event) {
/*
* if(Aoba.getInstance().hudManager.isClickGuiOpen()) { float mouseX =
* (float)event.GetHorizontal(); float mouseY = (float)event.GetVertical();
*
* if(mouseX >= x && mouseX <= x + width) { if(mouseY >= y && mouseY <= y +
* height) { isMouseOver = true; if(HudManager.currentGrabbed == this &&
* this.moveable) { float deltaX = mouseX - lastMouseX; float deltaY = mouseY -
* lastMouseY;
*
* this.x = this.x + deltaX; this.y = this.y + deltaY; } } } }
*/
}
}
12 changes: 6 additions & 6 deletions src/main/java/net/aoba/gui/tabs/ClickGuiTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,23 +248,23 @@ public void OnMouseLeftClick(MouseLeftClickEvent event) {
}
} else {
if (!this.isPinned) {
HudManager.currentGrabbed = this;
//HudManager.currentGrabbed = this;
}
}
} else {
if (this.pinWasClicked) {
this.pinWasClicked = false;
}
if (!this.isPinned) {
HudManager.currentGrabbed = this;
//HudManager.currentGrabbed = this;
}
}
}
}
}
}

@Override
/*@Override
public void OnMouseMove(MouseMoveEvent mouseMoveEvent) {
double mouseX = mouseMoveEvent.GetHorizontal();
double mouseY = mouseMoveEvent.GetVertical();
Expand All @@ -288,18 +288,18 @@ public void OnMouseMove(MouseMoveEvent mouseMoveEvent) {
}
} else {
if (!this.isPinned) {
// TODO: HudManager.currentGrabbed = this;
HudManager.currentGrabbed = this;
}
}
} else {
if (this.pinWasClicked) {
this.pinWasClicked = false;
}
if (!this.isPinned) {
// TODO: HudManager.currentGrabbed = this;
HudManager.currentGrabbed = this;
}
}
}
}
}
}*/
}
19 changes: 10 additions & 9 deletions src/main/java/net/aoba/gui/tabs/components/Component.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,17 @@ public void update(int offset) {
public void OnMouseMove(MouseMoveEvent mouseMoveEvent) {
if (HudManager.currentGrabbed != null) {
this.hovered = false;
return;
}

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)));
if(this.parent != null) {
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)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,11 @@ public void OnMouseLeftClick(MouseLeftClickEvent event) {

int mouseX = event.GetMouseX();
int mouseY = event.GetMouseY();

if (hovered) {
backgroundColor = hoverColor;
System.out.println("X: " + mouseX + ", Y: " + mouseY);
System.out.println("Parent X: " + parentX + ", Parent Y: " + parentY );

boolean isOnOptionsButton = (mouseX >= (parentX + parentWidth - 34) && mouseX <= (parentX + parentWidth));
if (isOnOptionsButton) {
this.popped = !this.popped;
Expand All @@ -132,11 +134,10 @@ public void OnMouseLeftClick(MouseLeftClickEvent event) {
this.setHeight(30);
}
} else {
System.out.println(module.getName() + " TOGGLED! ");
module.toggle();
return;
}
} else {
backgroundColor = color;
}
}
}

0 comments on commit aa1f65c

Please sign in to comment.