Skip to content

Commit

Permalink
Added basic Keybind setting and Module setting tab.
Browse files Browse the repository at this point in the history
The new Binding system saves the Binds to the new Settings file. This means that any changes made to bindings will persist across game sessions, similar to other module settings. There is now a Module Settings Tab instead of a dropdown in the Module Component. This is likely to change in the future but it's a good placeholder.
  • Loading branch information
coltonk9043 committed Oct 11, 2023
1 parent 25db625 commit 4fb7f0c
Show file tree
Hide file tree
Showing 74 changed files with 483 additions and 221 deletions.
2 changes: 1 addition & 1 deletion src/main/java/net/aoba/cmd/commands/CmdHelp.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void runCommand(String[] parameters) {
CommandManager.sendChatMessage(title);
CommandManager.sendChatMessage("Name: " + Formatting.LIGHT_PURPLE + module.getName() + Formatting.RESET);
CommandManager.sendChatMessage("Description: " + Formatting.LIGHT_PURPLE + module.getDescription() + Formatting.RESET);
CommandManager.sendChatMessage("Keybind: " + Formatting.LIGHT_PURPLE + module.getBind().getTranslationKey() + Formatting.RESET);
CommandManager.sendChatMessage("Keybind: " + Formatting.LIGHT_PURPLE + module.getBind().getValue().getTranslationKey() + Formatting.RESET);
CommandManager.sendChatMessage("-".repeat(unformatted_title.length() - 2)); // mc font characters are not the same width but eh..
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/aoba/core/settings/Setting.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public abstract class Setting<T> {

public enum TYPE {
BOOLEAN, DOUBLE, STRING, INTEGER, STRINGLIST, INDEXEDSTRINGLIST, VECTOR2
BOOLEAN, DOUBLE, STRING, INTEGER, STRINGLIST, INDEXEDSTRINGLIST, VECTOR2, KEYBIND
}

public final String ID;
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/net/aoba/core/settings/SettingManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import net.aoba.core.settings.types.IntegerSetting;
import net.aoba.core.utils.types.Vector2;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.client.util.InputUtil.Key;

import java.io.File;
import java.io.FileInputStream;
Expand Down Expand Up @@ -55,12 +58,15 @@ public static void saveSettings(String name, List<Setting> setting_list) {
case DOUBLE, INTEGER, BOOLEAN, STRING -> {
config.setProperty(setting.ID, String.valueOf(setting.getValue()));
}
case KEYBIND -> {
Key key = InputUtil.fromTranslationKey(((KeyBinding)setting.getValue()).getBoundKeyTranslationKey());
config.setProperty(setting.ID, String.valueOf(key.getCode()));
}
case VECTOR2 -> {
config.setProperty(setting.ID + "_x", String.valueOf(((Vector2)setting.getValue()).x));
config.setProperty(setting.ID + "_y", String.valueOf(((Vector2)setting.getValue()).y));
}
}
// config.setProperty(setting.ID, String.valueOf(setting.getValue()));
}
config.storeToXML(new FileOutputStream(configFile), null);
} catch (Exception ignored) {}
Expand Down Expand Up @@ -99,7 +105,10 @@ public static void loadSettings(String name, List<Setting> setting_list) {
}
}
}

case KEYBIND -> {
int keyCode = Integer.parseInt(config.getProperty(setting.ID, null));
setting.setValue(new KeyBinding(setting.ID, keyCode, "key.categories.aoba"));
}
case VECTOR2 -> {
String value_x = config.getProperty(setting.ID + "_x", null);
String value_y = config.getProperty(setting.ID + "_y", null);
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/net/aoba/core/settings/types/KeybindSetting.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package net.aoba.core.settings.types;

import java.util.function.Consumer;
import net.aoba.core.settings.Setting;
import net.minecraft.client.option.KeyBinding;

public class KeybindSetting extends Setting<KeyBinding> {
public KeybindSetting(String ID, String description, KeyBinding default_value) {
super(ID, description, default_value);
type = TYPE.KEYBIND;
}

public KeybindSetting(String ID, String displayName, String description, KeyBinding default_value) {
super(ID, displayName, description, default_value);
type = TYPE.KEYBIND;
}

public KeybindSetting(String ID, String description, KeyBinding default_value, Consumer<KeyBinding> onUpdate) {
super(ID, description, default_value, onUpdate);
type = TYPE.KEYBIND;
}

/**
* Checks whether or not a value is with this setting's valid range.
*/
@Override
protected boolean isValueValid(KeyBinding value) {
return true;
}
}
5 changes: 4 additions & 1 deletion src/main/java/net/aoba/event/events/KeyDownEvent.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package net.aoba.event.events;

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

import net.aoba.event.listeners.AbstractListener;
import net.aoba.event.listeners.KeyDownListener;
import net.aoba.event.listeners.LeftMouseDownListener;

public class KeyDownEvent extends AbstractEvent{
private final long window;
Expand Down Expand Up @@ -43,7 +46,7 @@ public int GetModifiers() {

@Override
public void Fire(ArrayList<? extends AbstractListener> listeners) {
for(AbstractListener listener : listeners) {
for(AbstractListener listener : List.copyOf(listeners)) {
KeyDownListener keyDownListener = (KeyDownListener) listener;
keyDownListener.OnKeyDown(this);
}
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/net/aoba/event/events/LeftMouseDownEvent.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package net.aoba.event.events;

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

import net.aoba.event.listeners.AbstractListener;
import net.aoba.event.listeners.KeyDownListener;
import net.aoba.event.listeners.LeftMouseDownListener;

public class LeftMouseDownEvent extends AbstractEvent{
Expand All @@ -25,7 +30,7 @@ public double GetMouseY() {

@Override
public void Fire(ArrayList<? extends AbstractListener> listeners) {
for(AbstractListener listener : listeners) {
for(AbstractListener listener : List.copyOf(listeners)) {
LeftMouseDownListener mouseLeftClickListener = (LeftMouseDownListener) listener;
mouseLeftClickListener.OnLeftMouseDown(this);
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/net/aoba/event/events/LeftMouseUpEvent.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package net.aoba.event.events;

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

import net.aoba.event.listeners.AbstractListener;
import net.aoba.event.listeners.KeyDownListener;
import net.aoba.event.listeners.LeftMouseUpListener;

public class LeftMouseUpEvent extends AbstractEvent{
Expand All @@ -25,7 +28,7 @@ public double GetMouseY() {

@Override
public void Fire(ArrayList<? extends AbstractListener> listeners) {
for(AbstractListener listener : listeners) {
for(AbstractListener listener : List.copyOf(listeners)) {
LeftMouseUpListener mouseLeftClickListener = (LeftMouseUpListener) listener;
mouseLeftClickListener.OnLeftMouseUp(this);
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/net/aoba/event/events/MouseMoveEvent.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package net.aoba.event.events;

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

import net.aoba.event.listeners.AbstractListener;
import net.aoba.event.listeners.LeftMouseUpListener;
import net.aoba.event.listeners.MouseMoveListener;

public class MouseMoveEvent extends AbstractEvent{
Expand All @@ -24,7 +27,7 @@ public double GetHorizontal() {

@Override
public void Fire(ArrayList<? extends AbstractListener> listeners) {
for(AbstractListener listener : listeners) {
for(AbstractListener listener : List.copyOf(listeners)) {
MouseMoveListener mouseMoveListener = (MouseMoveListener) listener;
mouseMoveListener.OnMouseMove(this);
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/net/aoba/event/events/MouseScrollEvent.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package net.aoba.event.events;

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

import net.aoba.event.listeners.AbstractListener;
import net.aoba.event.listeners.MouseMoveListener;
import net.aoba.event.listeners.MouseScrollListener;

public class MouseScrollEvent extends AbstractEvent{
Expand All @@ -25,7 +27,7 @@ public float GetHorizontal() {

@Override
public void Fire(ArrayList<? extends AbstractListener> listeners) {
for(AbstractListener listener : listeners) {
for(AbstractListener listener : List.copyOf(listeners)) {
MouseScrollListener mouseScrollListener = (MouseScrollListener) listener;
mouseScrollListener.OnMouseScroll(this);
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/net/aoba/event/events/ReceivePacketEvent.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package net.aoba.event.events;

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

import net.aoba.event.listeners.AbstractListener;
import net.aoba.event.listeners.MouseScrollListener;
import net.aoba.event.listeners.ReceivePacketListener;
import net.minecraft.network.packet.Packet;

Expand All @@ -19,7 +22,7 @@ public ReceivePacketEvent(Packet<?> packet) {

@Override
public void Fire(ArrayList<? extends AbstractListener> listeners) {
for(AbstractListener listener : listeners) {
for(AbstractListener listener : List.copyOf(listeners)) {
ReceivePacketListener readPacketListener = (ReceivePacketListener) listener;
readPacketListener.OnReceivePacket(this);
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/net/aoba/event/events/RenderEvent.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package net.aoba.event.events;

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

import net.aoba.event.listeners.AbstractListener;
import net.aoba.event.listeners.ReceivePacketListener;
import net.aoba.event.listeners.RenderListener;
import net.minecraft.client.util.math.MatrixStack;

Expand All @@ -24,7 +26,7 @@ public RenderEvent(MatrixStack matrixStack, float partialTicks) {

@Override
public void Fire(ArrayList<? extends AbstractListener> listeners) {
for(AbstractListener listener : listeners) {
for(AbstractListener listener : List.copyOf(listeners)) {
RenderListener renderListener = (RenderListener) listener;
renderListener.OnRender(this);
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/net/aoba/event/events/SendPacketEvent.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package net.aoba.event.events;

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

import net.aoba.event.listeners.AbstractListener;
import net.aoba.event.listeners.RenderListener;
import net.aoba.event.listeners.SendPacketListener;
import net.minecraft.network.packet.Packet;

Expand All @@ -20,7 +22,7 @@ public Packet<?> GetPacket(){

@Override
public void Fire(ArrayList<? extends AbstractListener> listeners) {
for(AbstractListener listener : listeners) {
for(AbstractListener listener : List.copyOf(listeners)) {
SendPacketListener sendPacketListener = (SendPacketListener) listener;
sendPacketListener.OnSendPacket(this);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/aoba/event/events/TickEvent.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package net.aoba.event.events;

import java.util.ArrayList;

import java.util.List;
import net.aoba.event.listeners.AbstractListener;
import net.aoba.event.listeners.TickListener;

public class TickEvent extends AbstractEvent {
@Override
public void Fire(ArrayList<? extends AbstractListener> listeners) {
for(AbstractListener listener : listeners) {
for(AbstractListener listener : List.copyOf(listeners)) {
TickListener tickListener = (TickListener) listener;
tickListener.OnUpdate(this);
}
Expand Down
37 changes: 26 additions & 11 deletions src/main/java/net/aoba/gui/HudManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public class HudManager implements LeftMouseDownListener, LeftMouseUpListener {

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



private boolean wasTildaPressed = false;

public NavigationBar clickGuiNavBar;
Expand All @@ -76,9 +78,9 @@ public HudManager() {

clickGuiNavBar = new NavigationBar();

NavigationPane modulesPane = new NavigationPane("Modules");
NavigationPane toolsPane = new NavigationPane("Tools");
NavigationPane hudPane = new NavigationPane("Hud");
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));
Expand Down Expand Up @@ -110,8 +112,6 @@ public HudManager() {
for (Module module : Aoba.getInstance().moduleManager.modules) {
if (module.getCategory() == category) {
ModuleComponent button = new ModuleComponent(module.getName(), stackPanel, module);

//button.setHeight(30);
stackPanel.addChild(button);
}
}
Expand All @@ -135,22 +135,35 @@ public HudManager() {
Aoba.getInstance().eventManager.AddListener(LeftMouseUpListener.class, this);
}

public void AddHud(AbstractHud hud, String pageName) {
for(Page page : clickGuiNavBar.getPanes()) {
if(page.getTitle().equals(pageName)) {
page.tabs.add(hud);
break;
}
}
}

public void RemoveHud(AbstractHud hud, String pageName) {
for(Page page : clickGuiNavBar.getPanes()) {
if(page.getTitle().equals(pageName)) {
page.tabs.remove(hud);
break;
}
}
}

/**
* 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;
}

public void onMouseScroll(double horizontal, double vertical) {

}

public void update() {
if(!Aoba.getInstance().isGhosted()){
Expand Down Expand Up @@ -217,7 +230,9 @@ public void draw(DrawContext drawContext, float tickDelta) {
clickGuiNavBar.draw(drawContext, tickDelta, this.currentColor);
}else {
for(AbstractHud hud : activeHuds) {
hud.draw(drawContext, tickDelta, this.currentColor);
if(hud.visible) {
hud.draw(drawContext, tickDelta, this.currentColor);
}
}
}

Expand Down
12 changes: 8 additions & 4 deletions src/main/java/net/aoba/gui/NavigationBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,24 @@
public class NavigationBar implements LeftMouseDownListener {
MinecraftClient mc = MinecraftClient.getInstance();

private List<NavigationPane> options;
private List<Page> options;

private int selectedIndex;
private RenderUtils renderUtils;

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

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

public List<Page> getPanes(){
return this.options;
}

public int getSelectedIndex() {
return this.selectedIndex;
}
Expand All @@ -55,7 +59,7 @@ public void draw(DrawContext drawContext, float partialTicks, Color color) {
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);
Page pane = options.get(i);
if(i == selectedIndex) {
pane.render(drawContext, partialTicks, color);
}
Expand Down
Loading

0 comments on commit 4fb7f0c

Please sign in to comment.