Skip to content

Commit

Permalink
Fixed several UI issues pertaining to HUD Visibility and Click logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
coltonk9043 committed Oct 22, 2023
1 parent 7ee0cf9 commit 1a16a5b
Show file tree
Hide file tree
Showing 14 changed files with 185 additions and 83 deletions.
20 changes: 9 additions & 11 deletions src/main/java/net/aoba/gui/HudManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ public class HudManager implements LeftMouseDownListener, LeftMouseUpListener {
public static AbstractHud currentGrabbed = null;

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




private boolean wasTildaPressed = false;

public NavigationBar clickGuiNavBar;
Expand All @@ -73,9 +71,6 @@ public HudManager() {
color = new Color(hue.getValue().floatValue(), 1f, 1f);
currentColor = color;
rainbowColor = new RainbowColor();
// rainbow.setValue(Settings.getSettingBoolean("rainbowUI"));
// TODO: ^^^^^^^^^^^^^^

clickGuiNavBar = new NavigationBar();

Page modulesPane = new Page("Modules");
Expand All @@ -86,6 +81,8 @@ public HudManager() {
toolsPane.AddHud(new AuthCrackerTab("Auth Cracker", 810, 500));

ModuleSelectorHud moduleSelector = new ModuleSelectorHud();
moduleSelector.setAlwaysVisible(true);

ArmorHud armorHud = new ArmorHud(790, 500, 200, 50);
RadarHud radarHud = new RadarHud(590, 500, 180, 180);
InfoHud infoHud = new InfoHud(100, 500);
Expand Down Expand Up @@ -133,6 +130,8 @@ public HudManager() {

Aoba.getInstance().eventManager.AddListener(LeftMouseDownListener.class, this);
Aoba.getInstance().eventManager.AddListener(LeftMouseUpListener.class, this);

clickGuiNavBar.setSelectedIndex(0);
}

public void AddHud(AbstractHud hud, String pageName) {
Expand Down Expand Up @@ -218,7 +217,9 @@ 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);

int guiScale = mc.getWindow().calculateScaleFactor(mc.options.getGuiScale().getValue(), mc.forcesUnicodeFont());
matrixStack.scale(1.0f / guiScale, 1.0f / guiScale, 1.0f);

Window window = mc.getWindow();

Expand All @@ -230,14 +231,11 @@ public void draw(DrawContext drawContext, float tickDelta) {
clickGuiNavBar.draw(drawContext, tickDelta, this.currentColor);
}else {
for(AbstractHud hud : activeHuds) {
if(hud.visible) {
if(hud.getVisible()) {
hud.draw(drawContext, tickDelta, this.currentColor);
}
}
}



matrixStack.pop();
GL11.glEnable(GL11.GL_CULL_FACE);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/aoba/gui/IHudElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public interface IHudElement {
public void setY(float y);
public void setWidth(float width);
public void setHeight(float height);

public void OnChildChanged(IHudElement child);
}
12 changes: 10 additions & 2 deletions src/main/java/net/aoba/gui/NavigationBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class NavigationBar implements LeftMouseDownListener {
public NavigationBar() {
options = new ArrayList<Page>();
renderUtils = new RenderUtils();
Aoba.getInstance().eventManager.AddListener(LeftMouseDownListener.class, this);
}

public void addPane(Page pane) {
Expand All @@ -37,6 +38,14 @@ public int getSelectedIndex() {
return this.selectedIndex;
}

public void setSelectedIndex(int index) {
if(index <= this.options.size()) {
this.options.get(selectedIndex).setVisible(false);
this.selectedIndex = index;
this.options.get(selectedIndex).setVisible(true);
}
}

public void update() {
Window window = mc.getWindow();

Expand Down Expand Up @@ -65,7 +74,6 @@ public void draw(DrawContext drawContext, float partialTicks, Color color) {
}
renderUtils.drawString(drawContext, pane.title, centerX - (width / 2) + 50 + (100 * i) - mc.textRenderer.getWidth(pane.title), 30, color);
}

}

@Override
Expand All @@ -84,7 +92,7 @@ public void OnLeftMouseDown(LeftMouseDownEvent event) {
if (mouseY >= (25) && mouseY <= (50)) {
int mouseXInt = (int) mouseX;
int selection = (mouseXInt - x) / 100;
this.selectedIndex = selection;
this.setSelectedIndex(selection);
}
}
}
Expand Down
29 changes: 17 additions & 12 deletions src/main/java/net/aoba/gui/Page.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.aoba.gui;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import net.aoba.gui.hud.AbstractHud;
Expand All @@ -9,8 +10,8 @@
public class Page {
protected String title;
protected List<AbstractHud> tabs = new ArrayList<AbstractHud>();
private List<AbstractHud> tabsToAdd = new ArrayList<AbstractHud>();

private boolean isVisible;

public Page(String title) {
this.title = title;
Expand All @@ -21,23 +22,27 @@ public String getTitle() {
}

public void AddHud(AbstractHud hud) {
tabsToAdd.add(hud);
tabs.add(hud);
}

public void update() {
for(AbstractHud tabToAdd : tabsToAdd) {
tabs.add(tabToAdd);
public void setVisible(boolean state) {
this.isVisible = state;
for(AbstractHud hud : tabs){
hud.setVisible(state);
}
tabsToAdd.clear();

for(AbstractHud tab : tabs) {
tab.update();
}

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

public void render(DrawContext drawContext, float partialTicks, Color color) {
for(AbstractHud tab : tabs) {
tab.draw(drawContext, partialTicks, color);
Iterator<AbstractHud> tabIterator = tabs.iterator();
while(tabIterator.hasNext()) {
tabIterator.next().draw(drawContext, partialTicks, color);
}
}
}
55 changes: 48 additions & 7 deletions src/main/java/net/aoba/gui/hud/AbstractHud.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public abstract class AbstractHud implements IHudElement, LeftMouseDownListener,

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

protected boolean alwaysVisible = false;
protected boolean visible = false;

// Mouse Variables
protected double lastClickOffsetX;
Expand All @@ -46,9 +48,6 @@ public AbstractHud(String ID, float x, float y, float width, float height) {
this.height = height;

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

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

@Override
Expand All @@ -59,7 +58,6 @@ public float getHeight() {
@Override
public float getX() {
return position.getValue().x;

}

@Override
Expand Down Expand Up @@ -108,6 +106,43 @@ public void setHeight(float height) {
}
}
}

public boolean getVisible() {
return this.visible;
}

public void setVisible(boolean state) {
if(this.visible == state || alwaysVisible) return;

this.visible = state;

for(Component component : children){
component.setVisible(state);
}

// Binds/Unbinds respective listeners depending on whether it is visible.
if(state) {
Aoba.instance.eventManager.AddListener(LeftMouseDownListener.class, this);
Aoba.instance.eventManager.AddListener(MouseMoveListener.class, this);
}else {
Aoba.instance.eventManager.RemoveListener(LeftMouseDownListener.class, this);
Aoba.instance.eventManager.RemoveListener(MouseMoveListener.class, this);
}
}

public void setAlwaysVisible(boolean state) {
this.alwaysVisible = state;
if(this.alwaysVisible) {
this.visible = true;

for(Component component : children){
component.setVisible(true);
}

Aoba.instance.eventManager.AddListener(LeftMouseDownListener.class, this);
Aoba.instance.eventManager.AddListener(MouseMoveListener.class, this);
}
}

public abstract void update();

Expand All @@ -134,8 +169,7 @@ public void OnLeftMouseDown(LeftMouseDownEvent event) {

@Override
public void OnMouseMove(MouseMoveEvent event) {

if (Aoba.getInstance().hudManager.isClickGuiOpen()) {
if (this.visible && Aoba.getInstance().hudManager.isClickGuiOpen()) {
double mouseX = event.GetHorizontal();
double mouseY = event.GetVertical();

Expand All @@ -151,6 +185,13 @@ public void OnMouseMove(MouseMoveEvent event) {
isMouseOver = true;
}
}
}else {
isMouseOver = false;
}
}

@Override
public void OnChildChanged(IHudElement child) {

}
}
14 changes: 10 additions & 4 deletions src/main/java/net/aoba/gui/tabs/components/ButtonComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public ButtonComponent(ClickGuiTab parent, String text, Runnable onClick) {
super(parent);
this.text = text;
this.onClick = onClick;

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

/**
Expand Down Expand Up @@ -86,7 +84,15 @@ public void OnLeftMouseDown(LeftMouseDownEvent event) {

@Override
public void update() {
// TODO Auto-generated method stub

super.update();
}

@Override
public void OnVisibilityChanged() {
if(this.isVisible()) {
Aoba.getInstance().eventManager.AddListener(LeftMouseDownListener.class, this);
}else {
Aoba.getInstance().eventManager.RemoveListener(LeftMouseDownListener.class, this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public CheckboxComponent(IHudElement parent, BooleanSetting checkbox) {
*/
@Override
public void draw(DrawContext drawContext, float partialTicks, Color color) {
super.draw(drawContext, partialTicks, color);

MatrixStack matrixStack = drawContext.getMatrices();
renderUtils.drawString(drawContext, this.text, actualX + 10, actualY + 8, 0xFFFFFF);
if (this.checkbox.getValue()) {
Expand All @@ -50,6 +52,7 @@ public void draw(DrawContext drawContext, float partialTicks, Color color) {
*/
@Override
public void update() {
super.update();
}

/**
Expand Down
Loading

0 comments on commit 1a16a5b

Please sign in to comment.