Skip to content

Commit

Permalink
Renamed hudManager to guiManager. Added Text Alignment.
Browse files Browse the repository at this point in the history
  • Loading branch information
coltonk9043 committed Sep 17, 2024
1 parent 4c2fb05 commit cec27b1
Show file tree
Hide file tree
Showing 23 changed files with 166 additions and 75 deletions.
6 changes: 3 additions & 3 deletions src/main/java/net/aoba/AobaClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class AobaClient {
public CommandManager commandManager;
public AltManager altManager;
public ProxyManager proxyManager;
public GuiManager hudManager;
public GuiManager guiManager;
public FontManager fontManager;
public CombatManager combatManager;
public RPCManager rpcManager;
Expand Down Expand Up @@ -112,8 +112,8 @@ public void loadAssets() {
LogUtils.getLogger().info("[Aoba] Initializing Combat Manager");
combatManager = new CombatManager();
LogUtils.getLogger().info("[Aoba] Initializing GUI");
hudManager = new GuiManager();
hudManager.Initialize();
guiManager = new GuiManager();
guiManager.Initialize();
LogUtils.getLogger().info("[Aoba] Loading Alts");
altManager = new AltManager();
proxyManager = new ProxyManager();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/aoba/cmd/commands/CmdClickgui.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ public void runCommand(String[] parameters) throws InvalidSyntaxException {
if (parameters.length != 2)
throw new InvalidSyntaxException(this);
char keybind = Character.toUpperCase(parameters[1].charAt(0));
Aoba.getInstance().hudManager.clickGuiButton.setValue(InputUtil.fromKeyCode(keybind, 0));
Aoba.getInstance().guiManager.clickGuiButton.setValue(InputUtil.fromKeyCode(keybind, 0));
break;
case "open":
Aoba.getInstance().hudManager.setClickGuiOpen(true);
Aoba.getInstance().guiManager.setClickGuiOpen(true);
break;
default:
throw new InvalidSyntaxException(this);
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/net/aoba/gui/TextAlign.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package net.aoba.gui;

public enum TextAlign {
Left,
Center,
Right
}
2 changes: 1 addition & 1 deletion src/main/java/net/aoba/gui/components/BlocksComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void draw(DrawContext drawContext, float partialTicks) {

@Override
public void OnMouseScroll(MouseScrollEvent event) {
if (Aoba.getInstance().hudManager.isClickGuiOpen() && this.hovered) {
if (Aoba.getInstance().guiManager.isClickGuiOpen() && this.hovered) {
if (event.GetVertical() > 0 && scroll > 0) {
scroll--;
} else if (event.GetVertical() < 0 && (scroll + visibleRows) < (Registries.BLOCK.size() / visibleColumns)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void onMouseMove(MouseMoveEvent event) {

double mouseX = event.getX();
double mouseY = event.getY();
if (Aoba.getInstance().hudManager.isClickGuiOpen() && this.isSliding) {
if (Aoba.getInstance().guiManager.isClickGuiOpen() && this.isSliding) {
Color colorToModify = color.getValue();
float vertical = (float) Math.min(Math.max(1.0f - (((mouseY - (actualY + 59)) - 1) / (actualHeight - 63)), 0.0f), 1.0f);

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/aoba/gui/components/Component.java
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public void onMouseMove(MouseMoveEvent mouseMoveEvent) {
}

boolean wasHovered = hovered;
if (mouseMoveEvent.isCancelled() || !visible || !Aoba.getInstance().hudManager.isClickGuiOpen()) {
if (mouseMoveEvent.isCancelled() || !visible || !Aoba.getInstance().guiManager.isClickGuiOpen()) {
this.hovered = false;
if(wasHovered){
GuiManager.setTooltip(null);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/aoba/gui/components/HudComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void onMouseClick(MouseClickEvent event) {
if (event.button == MouseButton.LEFT && event.action == MouseAction.DOWN) {
if (this.hovered) {
boolean visibility = hud.activated.getValue();
Aoba.getInstance().hudManager.SetHudActive(hud, !visibility);
Aoba.getInstance().guiManager.SetHudActive(hud, !visibility);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/aoba/gui/components/ModuleComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ public void onMouseClick(MouseClickEvent event) {
lastSettingsTab.setOnClose(() -> {spinning = false;});

lastSettingsTab.setVisible(true);
Aoba.getInstance().hudManager.AddWindow(lastSettingsTab, "Modules");
Aoba.getInstance().guiManager.AddWindow(lastSettingsTab, "Modules");
spinning = true;
} else {
Aoba.getInstance().hudManager.RemoveWindow(lastSettingsTab, "Modules");
Aoba.getInstance().guiManager.RemoveWindow(lastSettingsTab, "Modules");
spinning = false;
lastSettingsTab = null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/aoba/gui/components/ScrollComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void RecalculateHeight() {

@Override
public void OnMouseScroll(MouseScrollEvent event) {
if (Aoba.getInstance().hudManager.isClickGuiOpen() && this.hovered) {
if (Aoba.getInstance().guiManager.isClickGuiOpen() && this.hovered) {
int childCount = children.size();
if (event.GetVertical() > 0 && scroll > 0) {
scroll--;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/aoba/gui/components/SliderComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void onMouseClick(MouseClickEvent event) {
public void onMouseMove(MouseMoveEvent event) {
super.onMouseMove(event);

if (Aoba.getInstance().hudManager.isClickGuiOpen() && this.isSliding) {
if (Aoba.getInstance().guiManager.isClickGuiOpen() && this.isSliding) {
double mouseX = event.getX();

float actualX = this.getActualSize().getX();
Expand Down
30 changes: 28 additions & 2 deletions src/main/java/net/aoba/gui/components/StringComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.aoba.event.listeners.FontChangedListener;
import net.aoba.gui.IGuiElement;
import net.aoba.gui.Margin;
import net.aoba.gui.TextAlign;
import net.aoba.gui.colors.Color;
import net.aoba.gui.colors.Colors;
import net.aoba.utils.render.Render2D;
Expand All @@ -33,6 +34,7 @@
import java.util.ArrayList;

public class StringComponent extends Component implements FontChangedListener {
private TextAlign textAlign = TextAlign.Left;
private String originalText;
private ArrayList<String> text = new ArrayList<String>();
private boolean bold;
Expand Down Expand Up @@ -69,16 +71,32 @@ public StringComponent(String text, IGuiElement parent, Color color, boolean bol
public void draw(DrawContext drawContext, float partialTicks) {
float actualX = this.getActualSize().getX();
float actualY = this.getActualSize().getY();
float actualWidth = this.getActualSize().getWidth();

int i = 5;

for (String str : text) {
if (bold)
str = Formatting.BOLD + str;
Render2D.drawString(drawContext, str, actualX, actualY + i, this.color.getColorAsInt());

switch(textAlign) {
case TextAlign.Left:
Render2D.drawString(drawContext, str, actualX, actualY + i, this.color.getColorAsInt());
break;
case TextAlign.Center:
float xPosCenter = actualX + (actualWidth / 2.0f) - Render2D.getStringWidth(str);
Render2D.drawString(drawContext, str, xPosCenter, actualY + i, this.color.getColorAsInt());
break;
case TextAlign.Right:
float xPosRight = actualX + actualWidth - (Render2D.getStringWidth(str) * 2);
Render2D.drawString(drawContext, str, xPosRight, actualY + i, this.color.getColorAsInt());
break;
}

i += 25;
}
}

/**
* Sets the text of the String Component.
*
Expand Down Expand Up @@ -133,6 +151,14 @@ public void setText(String text) {
}
}
}

public TextAlign getTextAlign() {
return this.textAlign;
}

public void setTextAlign(TextAlign textAlign) {
this.textAlign = textAlign;
}

/**
* Gets the text of the String Component.
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/net/aoba/gui/navigation/HudWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public HudWindow(String ID, float x, float y, float width, float height) {
}

private void onActivatedChanged(Boolean state) {
Aoba.getInstance().hudManager.SetHudActive(this, state.booleanValue());
Aoba.getInstance().guiManager.SetHudActive(this, state.booleanValue());
}

@Override
Expand All @@ -37,7 +37,10 @@ public boolean getVisible() {
// Override to do nothing.. We want it to be visible based off of whether it is activated.
@Override
public void setVisible(boolean state) {

if(!state) {
isMouseOver = false;
isMoving = false;
}
}

@Override
Expand All @@ -56,7 +59,7 @@ public void draw(DrawContext drawContext, float partialTicks) {
GuiManager.roundingRadius.getValue(), dragColor);
}
}
if(isMouseOver) {
if(Aoba.getInstance().guiManager.isClickGuiOpen() && isMouseOver) {
Render2D.drawRoundedBoxOutline(drawContext.getMatrices().peek().getPositionMatrix(), x, y, width, height,
GuiManager.roundingRadius.getValue(), hoverColor);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/aoba/gui/navigation/NavigationBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void OnMouseClick(MouseClickEvent event) {
int centerX = (window.getWidth() / 2);
int x = centerX - (width / 2);

if (aoba.hudManager.isClickGuiOpen()) {
if (aoba.guiManager.isClickGuiOpen()) {
if (mouseX >= (x) && mouseX <= (x + width)) {
if (mouseY >= (25) && mouseY <= (50)) {
int mouseXInt = (int) mouseX;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/aoba/gui/navigation/Page.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ public void moveToFront(Window window) {

@Override
public void OnMouseMove(MouseMoveEvent mouseMoveEvent) {
if(Aoba.getInstance().hudManager.isClickGuiOpen()) {
if(Aoba.getInstance().guiManager.isClickGuiOpen()) {
tabs.reversed().stream().collect(Collectors.toList()).forEach(s -> s.onMouseMove(mouseMoveEvent));
}
}

@Override
public void OnMouseClick(MouseClickEvent mouseClickEvent) {
if(Aoba.getInstance().hudManager.isClickGuiOpen()) {
if(Aoba.getInstance().guiManager.isClickGuiOpen()) {
tabs.reversed().stream().collect(Collectors.toList()).forEach(s -> s.OnMouseClick(mouseClickEvent));
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/net/aoba/gui/navigation/Window.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package net.aoba.gui.navigation;

import net.aoba.Aoba;
import net.aoba.AobaClient;
import net.aoba.event.events.MouseClickEvent;
import net.aoba.event.events.MouseMoveEvent;
import net.aoba.gui.Direction;
Expand All @@ -43,7 +44,8 @@

public class Window implements IGuiElement {
protected static MinecraftClient MC = MinecraftClient.getInstance();

protected static AobaClient AOBA = Aoba.getInstance();

protected String ID;
protected String title;
protected Page parent;
Expand Down
Loading

0 comments on commit cec27b1

Please sign in to comment.