Skip to content

Commit

Permalink
Added Hud GUI and HUD fixes.
Browse files Browse the repository at this point in the history
The Hud GUI allows you to disable and enable Huds that will appear when even the ClickGUI is closed. It is not where I want it, but lets me use it to expand upon the HUD system.

There were also a lot of _OnChanged methods added to let a parent component know when it's children have moved, changed size, etc... This should not only help performance but will allow us to easily program modular components that can move or resize when a child element is modified.
  • Loading branch information
coltonk9043 committed Oct 26, 2023
1 parent 1a16a5b commit 8fa5ae4
Show file tree
Hide file tree
Showing 18 changed files with 438 additions and 226 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public Vector2Setting(String ID, String displayName, String description, Vector2
type = TYPE.VECTOR2;
}


public Vector2Setting(String ID, String description, Vector2 default_value, Consumer<Vector2> onUpdate) {
super(ID, description, default_value, onUpdate);
type = TYPE.VECTOR2;
Expand Down
52 changes: 35 additions & 17 deletions src/main/java/net/aoba/gui/HudManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,17 @@ public class HudManager implements LeftMouseDownListener, LeftMouseUpListener {
public static AbstractHud currentGrabbed = null;

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

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

private boolean wasTildaPressed = false;

// Navigation Bar and Pages
public NavigationBar clickGuiNavBar;

public Page modulesPane = new Page("Modules");
public Page toolsPane = new Page("Tools");
public Page hudPane = new Page("Hud");

// Global HUD Settings
public FloatSetting hue = new FloatSetting("color_hue", "Hue", 4, 0, 360, 1, null);
public FloatSetting effectSpeed = new FloatSetting("color_speed", "Effect Spd", 4, 1, 20, 0.1, null);
public BooleanSetting rainbow = new BooleanSetting("rainbow_mode", "Rainbow", false, null);
Expand All @@ -72,12 +78,7 @@ public HudManager() {
currentColor = color;
rainbowColor = new RainbowColor();
clickGuiNavBar = new NavigationBar();

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


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

ModuleSelectorHud moduleSelector = new ModuleSelectorHud();
Expand All @@ -87,16 +88,12 @@ public HudManager() {
RadarHud radarHud = new RadarHud(590, 500, 180, 180);
InfoHud infoHud = new InfoHud(100, 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(radarHud);
this.activeHuds.add(infoHud);
this.AddPinnableHud(armorHud);
this.AddPinnableHud(radarHud);
this.AddPinnableHud(infoHud);

hudPane.AddHud(moduleSelector);
hudPane.AddHud(armorHud);
hudPane.AddHud(radarHud);
hudPane.AddHud(infoHud);
hudPane.AddHud(new HudsTab(pinnableHuds));

//settingsPane.AddHud(new OptionsTab());

Expand All @@ -113,7 +110,7 @@ public HudManager() {
}
}
tab.addChild(stackPanel);

tab.setWidth(180);
modulesPane.AddHud(tab);
xOffset += tab.getWidth() + 10;
}
Expand Down Expand Up @@ -152,6 +149,27 @@ public void RemoveHud(AbstractHud hud, String pageName) {
}
}

/**
* Registers a HUD as Pinnable, which gives it a little more functionality.
*/
public void AddPinnableHud(AbstractHud hud) {
hudPane.AddHud(hud);
pinnableHuds.add(hud);
}

public List<AbstractHud> GetPinnableHuds(){
return this.pinnableHuds;
}

public void SetHudActive(AbstractHud hud, boolean state) {
if(state) {
this.activeHuds.add(hud);
}
else {
this.activeHuds.remove(hud);
}
}

/**
* Getter for the current color used by the GUI for text rendering.
* @return Current Color
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/net/aoba/gui/Page.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,20 @@ public void setVisible(boolean state) {
}

public void update() {
Iterator<AbstractHud> tabIterator = tabs.iterator();
while(tabIterator.hasNext()) {
tabIterator.next().update();
if(this.isVisible) {
Iterator<AbstractHud> tabIterator = tabs.iterator();
while(tabIterator.hasNext()) {
tabIterator.next().update();
}
}
}

public void render(DrawContext drawContext, float partialTicks, Color color) {
Iterator<AbstractHud> tabIterator = tabs.iterator();
while(tabIterator.hasNext()) {
tabIterator.next().draw(drawContext, partialTicks, color);
if(this.isVisible) {
Iterator<AbstractHud> tabIterator = tabs.iterator();
while(tabIterator.hasNext()) {
tabIterator.next().draw(drawContext, partialTicks, color);
}
}
}
}
31 changes: 23 additions & 8 deletions src/main/java/net/aoba/gui/hud/AbstractHud.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.aoba.gui.hud;

import java.util.ArrayList;
import java.util.function.Consumer;

import net.aoba.Aoba;
import net.aoba.core.settings.SettingManager;
Expand Down Expand Up @@ -42,14 +43,28 @@ public abstract class AbstractHud implements IHudElement, LeftMouseDownListener,

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

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

//TODO: I don't like this. It will use the setting to store position, but will only use this
// runnable when it needs to update from loading. Perhaps we could either forget about storing
// gui position OR we could find another way to do this.
this.position = new Vector2Setting(ID + "_position", "GUI POS", new Vector2(x, y), (Vector2 vec) -> UpdateAll(vec));
this.width = width;
this.height = height;

SettingManager.register_setting(position, Aoba.getInstance().settingManager.hidden_category);
}

public void UpdateAll(Vector2 vec) {
for(Component component : this.children) {
component.OnParentXChanged();
component.OnParentYChanged();
}
}

public String getID() {
return ID;
}

@Override
public float getHeight() {
return this.height;
Expand All @@ -73,18 +88,18 @@ public float getWidth() {
@Override
public void setX(float x) {
if(this.position.getValue().x != x) {
position.setX(x);
position.silentSetX(x);
for(Component component : this.children) {
component.onParentMoved();
component.OnParentXChanged();
}
}
}

public void setY(float y) {
if(this.position.getValue().y != y) {
position.setY(y);
position.silentSetY(y);
for(Component component : this.children) {
component.onParentMoved();
component.OnParentYChanged();
}
}
}
Expand All @@ -93,7 +108,7 @@ public void setWidth(float width) {
if(this.width != width) {
this.width = width;
for(Component component : this.children) {
component.onParentMoved();
component.OnParentWidthChanged();
}
}
}
Expand All @@ -102,7 +117,7 @@ public void setHeight(float height) {
if(this.height != height) {
this.height = height;
for(Component component : this.children) {
component.onParentMoved();
component.OnParentHeightChanged();
}
}
}
Expand Down
31 changes: 23 additions & 8 deletions src/main/java/net/aoba/gui/hud/ArmorHud.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@

package net.aoba.gui.hud;

import net.aoba.Aoba;
import net.aoba.core.utils.types.Vector2;
import net.aoba.event.events.LeftMouseDownEvent;
import net.aoba.gui.Color;
import net.aoba.gui.HudManager;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
Expand All @@ -33,6 +36,7 @@ public class ArmorHud extends AbstractHud{

public ArmorHud(int x, int y, int width, int height) {
super("ArmorHud", x,y,width,height);
this.setVisible(false);
this.width = 64;
this.height = 256;
}
Expand All @@ -44,14 +48,25 @@ 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)pos.x, (int)(pos.y + this.height - yOff));
yOff += 16;
if(this.visible) {
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)pos.x, (int)(pos.y + this.height - yOff));
yOff += 16;
}
}
}

@Override
public void OnLeftMouseDown(LeftMouseDownEvent event) {
super.OnLeftMouseDown(event);

if(this.isMouseOver) {
HudManager.currentGrabbed = this;
}
}
}
25 changes: 14 additions & 11 deletions src/main/java/net/aoba/gui/hud/InfoHud.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class InfoHud extends AbstractHud {
//
public InfoHud(int x, int y) {
super("InfoHud", x, y, 190, 60);
this.setVisible(false);
}

@Override
Expand Down Expand Up @@ -54,16 +55,18 @@ public void update() {

@Override
public void draw(DrawContext drawContext, float partialTicks, Color color) {
MatrixStack matrixStack = drawContext.getMatrices();
// Draws background depending on components width and height

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);
if(this.visible) {
MatrixStack matrixStack = drawContext.getMatrices();
// Draws background depending on components width and height

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);
}
}
}
Loading

0 comments on commit 8fa5ae4

Please sign in to comment.