Skip to content

Commit

Permalink
2nd iteration of the UI overhaul.
Browse files Browse the repository at this point in the history
- Added Navigation Bar on the top of the the ClickGUI that allows you to change which Tab (Pane) is currently visible.
- Added AbstractHud that represents any element that can be rendered onto the Ingame GUI.
- Restructed Tabs and added Huds in place of tabs such as Radar, InfoTab, etc...

Still more work to do, but it's coming together.
  • Loading branch information
coltonk9043 committed Jul 23, 2023
1 parent 127da72 commit eb3224e
Show file tree
Hide file tree
Showing 30 changed files with 481 additions and 318 deletions.
187 changes: 120 additions & 67 deletions src/main/java/net/aoba/gui/HudManager.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package net.aoba.gui;

import java.util.Hashtable;
import java.util.ArrayList;
import java.util.List;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.opengl.GL11;
import net.aoba.module.Module;
import net.aoba.Aoba;
import net.aoba.gui.elements.ModuleComponent;
import net.aoba.gui.hud.AbstractHud;
import net.aoba.gui.hud.ArmorHud;
import net.aoba.gui.hud.InfoHud;
import net.aoba.gui.hud.ModuleSelectorHud;
import net.aoba.gui.hud.RadarHud;
import net.aoba.gui.tabs.*;
import net.aoba.gui.tabs.components.ModuleComponent;
import net.aoba.misc.RainbowColor;
import net.aoba.misc.RenderUtils;
import net.aoba.module.Module.Category;
Expand All @@ -19,77 +25,102 @@

public class HudManager {

public MinecraftClient mc;
public Hashtable<String, ClickGuiTab> tabs = new Hashtable<String, ClickGuiTab>();
protected MinecraftClient mc = MinecraftClient.getInstance();
protected RenderUtils renderUtils = new RenderUtils();


private KeyBinding clickGuiButton = new KeyBinding("key.clickgui", GLFW.GLFW_KEY_GRAVE_ACCENT,
"key.categories.aoba");
private KeyBinding esc = new KeyBinding("key.esc", GLFW.GLFW_KEY_ESCAPE,
"key.categories.aoba");

private boolean clickGuiOpen = false;
private RenderUtils renderUtils;;

public IngameGUI hud;
public ArmorHUD armorHud;
public static Tab currentGrabbed = null;
public static IMoveable currentGrabbed = null;

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

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

private boolean wasTildaPressed = false;

public InfoTab infoTab;
public OptionsTab optionsTab;
public RadarTab radarTab;
public AuthCrackerTab authCrackerTab;


public NavigationBar clickGuiNavBar;

public SliderSetting hue = new SliderSetting("Hue", "color_hue", 4, 0, 360, 1);
public SliderSetting effectSpeed = new SliderSetting("Effect Spd", "color_speed", 4, 1, 20, 0.1);
public BooleanSetting rainbow = new BooleanSetting("Rainbow", "rainbow_mode");
public BooleanSetting ah = new BooleanSetting("ArmorHUD", "armorhud_toggle");

private Color currentColor;
private Color color;
private RainbowColor rainbowColor;

public HudManager() {
mc = MinecraftClient.getInstance();
hud = new IngameGUI();
armorHud = new ArmorHUD();

renderUtils = Aoba.getInstance().renderUtils;
color = new Color(hue.getValueFloat(), 1f, 1f);
currentColor = color;
rainbowColor = new RainbowColor();
rainbow.setValue(Settings.getSettingBoolean("rainbowUI"));

clickGuiNavBar = new NavigationBar();

NavigationPane modulesPane = new NavigationPane("Modules");
NavigationPane toolsPane = new NavigationPane("Tools");
NavigationPane hudPane = new NavigationPane("Hud");
NavigationPane settingsPane = new NavigationPane("Settings");

toolsPane.AddHud(new AuthCrackerTab("Auth Cracker", 810, 500));

ModuleSelectorHud moduleSelector = new ModuleSelectorHud();
ArmorHud armorHud = new ArmorHud(790, 500, 200, 50);
RadarHud radarHud = new RadarHud(590, 500, 180, 180);
InfoHud infoHud = new InfoHud(100, 500);

infoTab = new InfoTab("InfoTab", 100, 500);
optionsTab = new OptionsTab("Options", 370, 500, hue, rainbow, ah, effectSpeed);
radarTab = new RadarTab("Radar", 590, 500);
authCrackerTab = new AuthCrackerTab("Auth Cracker", 810, 500);
// TODO: Dumb workaround but I would like to be able to add HUDs through the pane found on the NavBar
this.activeHuds.add(moduleSelector);
this.activeHuds.add(armorHud);
this.activeHuds.add(infoHud);
this.activeHuds.add(infoHud);

hudPane.AddHud(moduleSelector);
hudPane.AddHud(armorHud);
hudPane.AddHud(infoHud);
hudPane.AddHud(infoHud);

settingsPane.AddHud(new OptionsTab("Options", 370, 500, hue, rainbow, ah, effectSpeed));

int xOffset = 335;
for (Category category : Module.Category.values()) {
ClickGuiTab tab = new ClickGuiTab(category.name(), xOffset, 1);
ClickGuiTab tab = new ClickGuiTab(category.name(), xOffset, 75, true);
for (Module module : Aoba.getInstance().moduleManager.modules) {
if (module.getCategory() == category) {
ModuleComponent button = new ModuleComponent(module.getName(), tab, module);
tab.addChild(button);
}
}
tabs.put(category.name(), tab);
modulesPane.AddHud(tab);
xOffset += tab.getWidth() + 10;
}
tabs.put(infoTab.getTitle(), infoTab);
tabs.put(optionsTab.getTitle(), optionsTab);
tabs.put(radarTab.getTitle(), radarTab);
tabs.put(authCrackerTab.getTitle(), authCrackerTab);

clickGuiNavBar.addPane(modulesPane);
clickGuiNavBar.addPane(toolsPane);
clickGuiNavBar.addPane(hudPane);
clickGuiNavBar.addPane(settingsPane);
}


/**
* Getter for the current color used by the GUI for text rendering.
* @return Current Color
*/
public Color getColor() {
return this.currentColor;
}


public Color getOriginalColor() {
return this.color;
Expand All @@ -99,13 +130,38 @@ public void update() {
boolean mouseClicked = mc.mouse.wasLeftButtonClicked();

if(!Aoba.getInstance().isGhosted()){
for (ClickGuiTab tab : tabs.values()) {
if (clickGuiOpen || tab.getPinned()) {
tab.preupdate();
tab.update(mouseX, mouseY, mouseClicked);
tab.postupdate();

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) {
int newX = Math.max(0, currentGrabbed.getX() - (lastMouseX - dx));
int newY = Math.max(0, currentGrabbed.getY() - (lastMouseY - dy));

currentGrabbed.setX(newX);
currentGrabbed.setY(newY);
}
this.lastMouseX = dx;
this.lastMouseY = dy;
}

/**
* Updates each of the Tab GUIs that are currently on the screen.
*/
for(AbstractHud hud : activeHuds) {
hud.update(lastMouseX, lastMouseY, mouseClicked);
}


if (this.clickGuiButton.isPressed() && !wasTildaPressed) {
wasTildaPressed = true;
Expand All @@ -120,6 +176,11 @@ public void update() {
this.toggleMouse();
}
}

/**
* Updates the Color.
* TODO: Remove this and move to event-based.
*/
if(this.rainbow.getValue()) {
rainbowColor.update(this.effectSpeed.getValueFloat());
this.currentColor = rainbowColor.getColor();
Expand All @@ -130,57 +191,49 @@ public void update() {
}

public void draw(DrawContext drawContext, float tickDelta) {
if (!Aoba.getInstance().isGhosted()) {
boolean mouseClicked = mc.mouse.wasLeftButtonClicked();
mouseX = (int) Math.ceil(mc.mouse.getX()) ;
mouseY = (int) Math.ceil(mc.mouse.getY()) ;
hud.update(mouseX, mouseY, mouseClicked);
if (this.clickGuiOpen) {
int dx = (int) Math.ceil(mouseX);
int dy = (int) Math.ceil(mouseY);
if (!mc.mouse.wasLeftButtonClicked())
currentGrabbed = null;
if (currentGrabbed != null)
currentGrabbed.moveWindow((lastMouseX - dx), (lastMouseY - dy));
this.lastMouseX = dx;
this.lastMouseY = dy;
}

}

GL11.glDisable(GL11.GL_CULL_FACE);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

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

Window window = mc.getWindow();

/**
* Render ClickGUI and Sidebar
*/
if (this.clickGuiOpen) {
renderUtils.drawBox(matrixStack, 0, 0, window.getWidth(), window.getHeight(), 0.1f, 0.1f, 0.1f, 0.4f);
}
this.hud.draw(drawContext, tickDelta, this.currentColor);
for (ClickGuiTab tab : tabs.values()) {
if (clickGuiOpen || tab.getPinned()) {
tab.draw(drawContext, tickDelta, this.currentColor);
clickGuiNavBar.draw(drawContext, tickDelta, this.currentColor);
}else {
for(AbstractHud hud : activeHuds) {
hud.draw(drawContext, tickDelta, this.currentColor);
}
}



matrixStack.pop();
GL11.glEnable(GL11.GL_CULL_FACE);
}

/**
* Gets whether or not the Click GUI is currently open.
* @return State of the Click GUI.
*/
public boolean isClickGuiOpen() {
return this.clickGuiOpen;
}

// TODO Toggle Mouse
public void toggleMouse() {
if(this.mc.mouse.isCursorLocked()) {
this.mc.mouse.unlockCursor();
}else {
this.mc.mouse.lockCursor();
}
}

/**
* Locks and unlocks the Mouse.
*/
public void toggleMouse() {
if(this.mc.mouse.isCursorLocked()) {
this.mc.mouse.unlockCursor();
}else {
this.mc.mouse.lockCursor();
}
}
}
12 changes: 12 additions & 0 deletions src/main/java/net/aoba/gui/IMoveable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package net.aoba.gui;

public interface IMoveable {
public int getX();
public int getY();
public int getHeight();
public int getWidth();
public void setX(int x);
public void setY(int y);
public void setWidth(int width);
public void setHeight(int height);
}
80 changes: 80 additions & 0 deletions src/main/java/net/aoba/gui/NavigationBar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package net.aoba.gui;

import java.util.ArrayList;
import java.util.List;
import net.aoba.Aoba;
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 {
MinecraftClient mc = MinecraftClient.getInstance();

private List<NavigationPane> options;

private int selectedIndex;
private RenderUtils renderUtils;

public NavigationBar() {
options = new ArrayList<NavigationPane>();
renderUtils = new RenderUtils();
}

public void addPane(NavigationPane pane) {
options.add(pane);
}

public int getSelectedIndex() {
return this.selectedIndex;
}

public void update(double mouseX, double mouseY, boolean mouseClicked) {

Window window = mc.getWindow();

int width = 100 * options.size();
int centerX = (window.getWidth() / 2);

int x = centerX - (width / 2);
if (Aoba.getInstance().hudManager.isClickGuiOpen()) {
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);
}
}

public void draw(DrawContext drawContext, float partialTicks, Color color) {
Window window = mc.getWindow();

int centerX = (window.getWidth() / 2);

MatrixStack matrixStack = drawContext.getMatrices();

int width = 100 * options.size();
renderUtils.drawRoundedBox(matrixStack, centerX - (width / 2), 25, width, 25, 6, new Color(30,30,30), 0.4f);
renderUtils.drawRoundedOutline(matrixStack, centerX - (width / 2), 25, width, 25, 6, new Color(0,0,0), 0.8f);

renderUtils.drawRoundedBox(drawContext.getMatrices(), centerX - (width / 2) + (100 * this.selectedIndex), 25, 100, 25, 5, new Color(150, 150, 150), 0.4f);

for(int i = 0; i < options.size(); i++) {
NavigationPane pane = options.get(i);
if(i == selectedIndex) {
pane.render(drawContext, partialTicks, color);
}
renderUtils.drawString(drawContext, pane.title, centerX - (width / 2) + 50 + (100 * i) - mc.textRenderer.getWidth(pane.title), 30, color);
}

}
}
Loading

1 comment on commit eb3224e

@OsakiTsukiko
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 🔥 🔥

Please sign in to comment.