Skip to content

Commit

Permalink
Several UI fixed.
Browse files Browse the repository at this point in the history
Fixed Tabs not pinning properly.
Fixed Module Component not clicking.
  • Loading branch information
coltonk9043 committed Sep 16, 2023
1 parent aa1f65c commit 8e5b3cc
Show file tree
Hide file tree
Showing 18 changed files with 167 additions and 291 deletions.
14 changes: 7 additions & 7 deletions src/main/java/net/aoba/event/events/MouseLeftClickEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@

public class MouseLeftClickEvent extends AbstractEvent{

int mouseX;
int mouseY;
double mouseX;
double mouseY;

public MouseLeftClickEvent(int mouseX, int mouseY) {
public MouseLeftClickEvent(double mouseX2, double mouseY2) {
super();
this.mouseX = mouseX;
this.mouseY = mouseY;
this.mouseX = mouseX2;
this.mouseY = mouseY2;
}

public int GetMouseX() {
public double GetMouseX() {
return mouseX;
}

public int GetMouseY() {
public double GetMouseY() {
return mouseY;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/aoba/gui/NavigationBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public void OnMouseLeftClick(MouseLeftClickEvent event) {
AobaClient aoba = Aoba.getInstance();
Window window = mc.getWindow();

int mouseX = event.GetMouseX();
int mouseY = event.GetMouseY();
double mouseX = event.GetMouseX();
double mouseY = event.GetMouseY();
int width = 100 * options.size();
int centerX = (window.getWidth() / 2);
int x = centerX - (width / 2);
Expand Down
59 changes: 21 additions & 38 deletions src/main/java/net/aoba/gui/hud/AbstractHud.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,75 +14,58 @@
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;

import java.util.function.Consumer;

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 Vector2Setting position;
protected float width;
protected float height;

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;
protected double lastMouseX;
protected double lastMouseY;

public AbstractHud(String ID, int x, int y, int width, int height) {
this.ID = ID;
this.x = x;
this.y = y;

this.position = new Vector2Setting(ID + "_position", "GUI POS", new Vector2(x, y));
this.width = width;
this.height = height;

position_setting_update = new Consumer<Vector2>() {
@Override
public void accept(Vector2 vector2) {
setX(vector2.x);
setY(vector2.y);
}
};

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

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

public float getX() {
return this.x;
public float getHeight() {
return this.height;
}

public float getY() {
return this.y;
public float getX(){
return position.getValue().x;
}

public float getHeight() {
return this.height;
public float getY(){
return position.getValue().y;
}

public float getWidth() {
return this.width;
}

public void setX(float x) {
this.x = x;
position_setting.silentSetX(x);
position.setX(x);
}

public void setY(float y) {
this.y = y;
position_setting.silentSetY(y);
position.setY(y);
}

public void setWidth(float width) {
Expand All @@ -99,15 +82,15 @@ public void setHeight(float height) {

@Override
public void OnMouseLeftClick(MouseLeftClickEvent event) {
int mouseX = event.GetMouseX();
int mouseY = event.GetMouseY();
double mouseX = event.GetMouseX();
double mouseY = event.GetMouseY();

Vector2 pos = position.getValue();

if (Aoba.getInstance().hudManager.isClickGuiOpen()) {
if (HudManager.currentGrabbed == null) {
if (mouseX >= x && mouseX <= (x + width)) {
if (mouseY >= y && mouseY <= (y + height)) {
System.out.println(ID + " was clicked!");
//HudManager.currentGrabbed = this;
if (mouseX >= pos.x && mouseX <= (pos.x + width)) {
if (mouseY >= pos.y && mouseY <= (pos.y + height)) {
lastMouseX = mouseX;
lastMouseY = mouseY;
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/net/aoba/gui/hud/ArmorHud.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@

package net.aoba.gui.hud;

import net.aoba.core.utils.types.Vector2;
import net.aoba.gui.Color;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.render.item.ItemRenderer;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.collection.DefaultedList;
Expand All @@ -33,8 +33,6 @@ public class ArmorHud extends AbstractHud{

public ArmorHud(int x, int y, int width, int height) {
super("ArmorHud", x,y,width,height);
this.x = 300;
this.y = 300;
this.width = 64;
this.height = 256;
}
Expand All @@ -47,10 +45,12 @@ public void update() {
@Override
public void draw(DrawContext drawContext, float partialTicks, Color color) {
DefaultedList<ItemStack> armors = mc.player.getInventory().armor;

Vector2 pos = position.getValue();
int yOff = 16;
for(ItemStack armor : armors) {
if(armor.getItem() == Items.AIR) continue;
drawContext.drawItem(armor, (int)this.x, (int)(this.y + this.height - yOff));
drawContext.drawItem(armor, (int)pos.x, (int)(pos.y + this.height - yOff));
yOff += 16;
}
}
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/net/aoba/gui/hud/InfoHud.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.aoba.gui.hud;

import net.aoba.core.utils.types.Vector2;
import net.aoba.gui.Color;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
Expand Down Expand Up @@ -55,11 +56,14 @@ public void update() {
public void draw(DrawContext drawContext, float partialTicks, Color color) {
MatrixStack matrixStack = drawContext.getMatrices();
// Draws background depending on components width and height
renderUtils.drawRoundedBox(matrixStack, x, y, width, height, 6, new Color(30,30,30), 0.4f);
renderUtils.drawRoundedOutline(matrixStack, x, y, width, height, 6, new Color(0,0,0), 0.8f);

renderUtils.drawString(drawContext, positionText, x + 5, y + 4, color);
renderUtils.drawString(drawContext, timeText, x + 5, y + 24, color);
renderUtils.drawString(drawContext, fpsText, x + 5, y + 44, color);
Vector2 pos = position.getValue();

renderUtils.drawRoundedBox(matrixStack, pos.x, pos.y, width, height, 6, new Color(30,30,30), 0.4f);
renderUtils.drawRoundedOutline(matrixStack, pos.x, pos.y, width, height, 6, new Color(0,0,0), 0.8f);

renderUtils.drawString(drawContext, positionText, pos.x + 5, pos.y + 4, color);
renderUtils.drawString(drawContext, timeText, pos.x + 5, pos.y + 24, color);
renderUtils.drawString(drawContext, fpsText, pos.x + 5, pos.y + 44, color);
}
}
27 changes: 15 additions & 12 deletions src/main/java/net/aoba/gui/hud/ModuleSelectorHud.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.lwjgl.glfw.GLFW;
import net.aoba.Aoba;
import net.aoba.AobaClient;
import net.aoba.core.utils.types.Vector2;
import net.aoba.gui.Color;
import net.aoba.module.Module;
import net.aoba.module.Module.Category;
Expand Down Expand Up @@ -66,7 +67,7 @@ public void update() {
}
this.keybindDown.setPressed(false);
} else if (this.keybindRight.isPressed()) {
if (!isCategoryMenuOpen && x != -width) {
if (!isCategoryMenuOpen) {
isCategoryMenuOpen = !isCategoryMenuOpen;
if (modules.isEmpty()) {
for (Module module : aoba.moduleManager.modules) {
Expand Down Expand Up @@ -98,39 +99,41 @@ public void draw(DrawContext drawContext, float partialTicks, Color color) {
MatrixStack matrixStack = drawContext.getMatrices();
Window window = mc.getWindow();

Vector2 pos = position.getValue();

// Draws the top bar including "Aoba x.x"
renderUtils.drawString(drawContext, "Aoba " + AobaClient.VERSION, 8, 8, color);

// Draws the table including all of the categories.
renderUtils.drawRoundedBox(matrixStack, x, y, width, height * this.categories.length, 6f, new Color(30,30,30), 0.4f);
renderUtils.drawRoundedOutline(matrixStack, x, y, width, height * this.categories.length, 6f, new Color(0,0,0), 0.8f);
renderUtils.drawRoundedBox(matrixStack, pos.x, pos.y, width, height * this.categories.length, 6f, new Color(30,30,30), 0.4f);
renderUtils.drawRoundedOutline(matrixStack, pos.x, pos.y, width, height * this.categories.length, 6f, new Color(0,0,0), 0.8f);

// For every category, draw a cell for it.
for (int i = 0; i < this.categories.length; i++) {
renderUtils.drawString(drawContext, ">>", x + width - 24, y + (height * i) + 8, color);
renderUtils.drawString(drawContext, ">>", pos.x + width - 24, pos.y + (height * i) + 8, color);
// Draws the name of the category dependent on whether it is selected.
if (this.index == i) {
renderUtils.drawString(drawContext, "> " + this.categories[i].name(), x + 8, y + (height * i) + 8, color);
renderUtils.drawString(drawContext, "> " + this.categories[i].name(), pos.x + 8, pos.y + (height * i) + 8, color);
} else {
renderUtils.drawString(drawContext, this.categories[i].name(), x + 8, y + (height * i) + 8, 0xFFFFFF);
renderUtils.drawString(drawContext, this.categories[i].name(), pos.x + 8, pos.y + (height * i) + 8, 0xFFFFFF);
}
}

// If any particular category menu is open.
if (isCategoryMenuOpen) {
// Draw the table underneath
renderUtils.drawRoundedBox(matrixStack, x + width, y + (height * this.index), 165, height * modules.size(), 6f, new Color(30,30,30), 0.4f);
renderUtils.drawRoundedOutline(matrixStack, x + width, y + (height * this.index), 165, height * modules.size(), 6f, new Color(0,0,0), 0.8f);
renderUtils.drawRoundedBox(matrixStack, pos.x + width, pos.y + (height * this.index), 165, height * modules.size(), 6f, new Color(30,30,30), 0.4f);
renderUtils.drawRoundedOutline(matrixStack, pos.x + width, pos.y + (height * this.index), 165, height * modules.size(), 6f, new Color(0,0,0), 0.8f);

// For every mod, draw a cell for it.
for (int i = 0; i < modules.size(); i++) {
if (this.indexMods == i) {
renderUtils.drawString(drawContext, "> " + modules.get(i).getName(), x + width + 5,
y + (i * height) + (this.index * height) + 8,
renderUtils.drawString(drawContext, "> " + modules.get(i).getName(), pos.x + width + 5,
pos.y + (i * height) + (this.index * height) + 8,
modules.get(i).getState() ? 0x00FF00 : color.getColorAsInt());
} else {
renderUtils.drawString(drawContext, modules.get(i).getName(), x + width + 5,
y + (i * height) + (this.index * height) + 8,
renderUtils.drawString(drawContext, modules.get(i).getName(), pos.x + width + 5,
pos.y + (i * height) + (this.index * height) + 8,
modules.get(i).getState() ? 0x00FF00 : 0xFFFFFF);
}
}
Expand Down
32 changes: 18 additions & 14 deletions src/main/java/net/aoba/gui/hud/RadarHud.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.aoba.gui.hud;

import net.aoba.Aoba;
import net.aoba.core.utils.types.Vector2;
import net.aoba.gui.Color;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.network.AbstractClientPlayerEntity;
Expand All @@ -21,20 +22,23 @@ public RadarHud( int x, int y, int width, int height) {
@Override
public void draw(DrawContext drawContext, float partialTicks, Color color) {
MatrixStack matrixStack = drawContext.getMatrices();

Vector2 pos = position.getValue();

// Draws background depending on components width and height
renderUtils.drawRoundedBox(matrixStack, x, y, width, height, 6, new Color(30,30,30), 0.4f);
renderUtils.drawRoundedOutline(matrixStack, x, y, width, height, 6, new Color(0,0,0), 0.8f);
renderUtils.drawRoundedBox(matrixStack, pos.x, pos.y, width, height, 6, new Color(30,30,30), 0.4f);
renderUtils.drawRoundedOutline(matrixStack, pos.x, pos.y, width, height, 6, new Color(0,0,0), 0.8f);

// Draw the 'Radar'
renderUtils.drawBox(matrixStack, x , y + (height / 2), width - 1, 1, new Color(128,128,128), 1.0f);
renderUtils.drawBox(matrixStack, x + (width / 2), y, 1, height, new Color(128,128,128), 1.0f);
renderUtils.drawBox(matrixStack, x + (width / 2) - 2, y + (height / 2) - 2, 5, 5, Aoba.getInstance().hudManager.getColor(), 1.0f);
renderUtils.drawBox(matrixStack, pos.x , pos.y + (height / 2), width - 1, 1, new Color(128,128,128), 1.0f);
renderUtils.drawBox(matrixStack, pos.x + (width / 2), pos.y, 1, height, new Color(128,128,128), 1.0f);
renderUtils.drawBox(matrixStack, pos.x + (width / 2) - 2, pos.y + (height / 2) - 2, 5, 5, Aoba.getInstance().hudManager.getColor(), 1.0f);

float sin_theta = (float) Math.sin(Math.toRadians(-mc.player.getRotationClient().y));
float cos_theta = (float) Math.cos(Math.toRadians(-mc.player.getRotationClient().y));

float center_x = x + (width / 2);
float center_y = y - 2 + (height / 2);
float center_x = pos.x + (width / 2);
float center_y = pos.y - 2 + (height / 2);

// Render Entities
for (Entity entity : mc.world.getEntities()) {
Expand All @@ -54,13 +58,13 @@ public void draw(DrawContext drawContext, float partialTicks, Color color) {
float ratio_x = (float)((entity.getX() - mc.player.getX())) / (distance);
float ratio_y = (float)((entity.getZ() - mc.player.getZ())) / (distance);

float fake_x = (x + (width / 2) - (width * ratio_x / 2));
float fake_y = (y - 2 + (height / 2) - (width * ratio_y / 2));
float fake_x = (pos.x + (width / 2) - (width * ratio_x / 2));
float fake_y = (pos.y - 2 + (height / 2) - (width * ratio_y / 2));

float radius_x = (float)((cos_theta * (fake_x - center_x)) - (sin_theta * (fake_y - center_y))) + center_x;
float radius_y = (float)((sin_theta * (fake_x - center_x)) + (cos_theta * (fake_y - center_y))) + center_y;

renderUtils.drawBox(matrixStack, (int)(Math.min(x + width - 5, Math.max(x, radius_x))) , (int)(Math.min(y - 5 + height, Math.max(y, radius_y))), 3, 3, c, 1.0f);
renderUtils.drawBox(matrixStack, (int)(Math.min(pos.x + width - 5, Math.max(pos.x, radius_x))) , (int)(Math.min(pos.y - 5 + height, Math.max(pos.y, radius_y))), 3, 3, c, 1.0f);
}

// Render Players
Expand All @@ -69,14 +73,14 @@ public void draw(DrawContext drawContext, float partialTicks, Color color) {
float ratio_x = (float)((entity.getX() - mc.player.getX())) / (distance);
float ratio_y = (float)((entity.getZ() - mc.player.getZ())) / (distance);

float fake_x = (x + (width / 2) - (width * ratio_x / 2));
float fake_y = (y + 28 + (height / 2) - (width * ratio_y / 2));
float fake_x = (pos.x + (width / 2) - (width * ratio_x / 2));
float fake_y = (pos.y + 28 + (height / 2) - (width * ratio_y / 2));

float radius_x = (float)((cos_theta * (fake_x - center_x)) - (sin_theta * (fake_y - center_y))) + center_x;
float radius_y = (float)((sin_theta * (fake_x - center_x)) + (cos_theta * (fake_y - center_y))) + center_y;

renderUtils.drawBox(matrixStack, (int)(Math.min(x + width - 5, Math.max(x, radius_x))), (int)(Math.min(y + 25 + height, Math.max(y, radius_y))), 3, 3, new Color(255, 255, 255), 1.0f);
renderUtils.drawStringWithScale(drawContext, entity.getName().getString(), (int)(Math.min(x + width - 5, Math.max(x, radius_x))) - (mc.textRenderer.getWidth(entity.getName()) * 0.5f), (int)(Math.min(y + 25 + height, Math.max(y, radius_y))) - 10, color, 1.0f);
renderUtils.drawBox(matrixStack, (int)(Math.min(pos.x + width - 5, Math.max(pos.x, radius_x))), (int)(Math.min(pos.y + 25 + height, Math.max(pos.y, radius_y))), 3, 3, new Color(255, 255, 255), 1.0f);
renderUtils.drawStringWithScale(drawContext, entity.getName().getString(), (int)(Math.min(pos.x + width - 5, Math.max(pos.x, radius_x))) - (mc.textRenderer.getWidth(entity.getName()) * 0.5f), (int)(Math.min(pos.y + 25 + height, Math.max(pos.y, radius_y))) - 10, color, 1.0f);
}
}
}
Expand Down
Loading

0 comments on commit 8e5b3cc

Please sign in to comment.