Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main/java/net/aoba/command/commands/CmdClickgui.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.aoba.Aoba;
import net.aoba.command.Command;
import net.aoba.command.InvalidSyntaxException;
import net.aoba.utils.input.Keybind;

public class CmdClickgui extends Command {

Expand All @@ -26,7 +27,7 @@ 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().guiManager.clickGuiButton.setValue(InputConstants.Type.KEYBOARD.getOrCreate((int) keybind));
Aoba.getInstance().guiManager.clickGuiButton.setValue(Keybind.from(InputConstants.Type.KEYBOARD.getOrCreate((int) keybind)));
break;
case "open":
Aoba.getInstance().guiManager.setClickGuiOpen(true);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/aoba/command/commands/CmdHelp.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void runCommand(String[] parameters) {
CommandManager.sendChatMessage(title);
CommandManager.sendChatMessage("Name: " + ChatFormatting.LIGHT_PURPLE + module.getName() + ChatFormatting.RESET);
CommandManager.sendChatMessage("Description: " + ChatFormatting.LIGHT_PURPLE + module.getDescription() + ChatFormatting.RESET);
CommandManager.sendChatMessage("Keybind: " + ChatFormatting.LIGHT_PURPLE + module.getBind().getValue().getName() + ChatFormatting.RESET);
CommandManager.sendChatMessage("Keybind: " + ChatFormatting.LIGHT_PURPLE + module.getBind().getValue().getKey().getName() + ChatFormatting.RESET);
CommandManager.sendChatMessage("-".repeat(unformatted_title.length() - 2)); // mc font characters are not the same width but eh..
}
}
Expand Down
29 changes: 22 additions & 7 deletions src/main/java/net/aoba/gui/GuiManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

import com.google.common.collect.Lists;
import com.mojang.blaze3d.platform.InputConstants;
import com.mojang.blaze3d.platform.InputConstants.Key;

import net.aoba.Aoba;
import net.aoba.AobaClient;
import net.aoba.event.events.KeyDownEvent;
Expand Down Expand Up @@ -83,6 +85,7 @@
import net.aoba.settings.types.KeybindSetting;
import net.aoba.utils.input.CursorStyle;
import net.aoba.utils.input.Input;
import net.aoba.utils.input.Keybind;
import net.aoba.rendering.Renderer2D;
import net.aoba.rendering.shaders.Shader;
import net.minecraft.client.KeyMapping;
Expand All @@ -95,7 +98,7 @@ public class GuiManager implements KeyDownListener, TickListener, Render2DListen
private static final Minecraft MC = Minecraft.getInstance();

public KeybindSetting clickGuiButton = KeybindSetting.builder().id("key.clickgui").displayName("ClickGUI Key")
.defaultValue(InputConstants.Type.KEYBOARD.getOrCreate(InputConstants.KEY_RSHIFT)).build();
.defaultValue(Keybind.from(InputConstants.KEY_RSHIFT)).build();

private static CursorStyle currentCursor = CursorStyle.Default;
private static String tooltip = null;
Expand Down Expand Up @@ -141,10 +144,18 @@ public class GuiManager implements KeyDownListener, TickListener, Render2DListen
.displayName("UI Panel Border Color").description("Accent color of the background.")
.defaultValue(Shader.solid(new Color(100, 100, 100, 100))).build();

public static ShaderSetting componentBackgroundColor = ShaderSetting.builder().id("ui_component_background_color")
.displayName("UI Component Background Color").description("Background colors of components (i.e TextBox).")
.defaultValue(Shader.solid(new Color(20, 20, 20, 95))).build();

public static ShaderSetting componentHoveredBackgroundColor = ShaderSetting.builder().id("ui_component_hover_background_color")
.displayName("UI Component Hovered Background Color").description("Background colors of components (i.e TextBox) when hovered.")
.defaultValue(Shader.solid(new Color(50, 50, 50, 150))).build();

public static ShaderSetting componentBorderColor = ShaderSetting.builder().id("ui_component_border_color")
.displayName("UI Component Border Color").description("Background colors of components (i.e TextBox).")
.defaultValue(Shader.solid(new Color(115, 115, 115, 200))).build();

public static ShaderSetting windowBackgroundColor = ShaderSetting.builder().id("ui_window_background_color")
.displayName("UI Background Color").description("Color of the background.")
.defaultValue(Shader.blur(new Color(55, 55, 55, 255), 60f, 5f)).build();
Expand All @@ -153,10 +164,6 @@ public class GuiManager implements KeyDownListener, TickListener, Render2DListen
.displayName("UI Panel Background Color").description("Accent color of the background.")
.defaultValue(Shader.solid(new Color(90, 90, 90, 60))).build();

public static ShaderSetting componentBackgroundColor = ShaderSetting.builder().id("ui_component_background_color")
.displayName("UI Component Background Color").description("Background colors of components (i.e TextBox).")
.defaultValue(Shader.solid(new Color(20, 20, 20, 95))).build();

public static ShaderSetting buttonBackgroundColor = ShaderSetting.builder().id("ui_button_background_color")
.displayName("UI Button Background Color").description("Background color of buttons.")
.defaultValue(Shader.gradient(new Color(180, 50, 220), new Color(100, 20, 160), 90f)).build();
Expand All @@ -165,6 +172,11 @@ public class GuiManager implements KeyDownListener, TickListener, Render2DListen
.id("ui_button_hover_background_color").displayName("UI Button Hover Background Color")
.description("Background color of buttons when hovered.")
.defaultValue(Shader.gradient(new Color(210, 80, 255), new Color(130, 40, 190), 90f)).build();

public static ShaderSetting buttonPressedBackgroundColor = ShaderSetting.builder()
.id("ui_button_pressed_background_color").displayName("UI Button Pressed Background Color")
.description("Background color of buttons when pressed.")
.defaultValue(Shader.gradient(new Color(150, 20, 195), new Color(70, 0, 130), 90f)).build();

public static ShaderSetting buttonBorderColor = ShaderSetting.builder().id("ui_button_border_color")
.displayName("UI Button Border Color").description("Border color of buttons.")
Expand Down Expand Up @@ -203,11 +215,13 @@ public GuiManager() {
SettingManager.registerGlobalSetting(panelBorderColor);
SettingManager.registerGlobalSetting(panelBackgroundColor);
SettingManager.registerGlobalSetting(componentBackgroundColor);
SettingManager.registerGlobalSetting(componentHoveredBackgroundColor);
SettingManager.registerGlobalSetting(foregroundColor);
SettingManager.registerGlobalSetting(foregroundHeaderColor);
SettingManager.registerGlobalSetting(foregroundAccentColor);
SettingManager.registerGlobalSetting(buttonBackgroundColor);
SettingManager.registerGlobalSetting(buttonHoverBackgroundColor);
SettingManager.registerGlobalSetting(buttonPressedBackgroundColor);
SettingManager.registerGlobalSetting(buttonBorderColor);
SettingManager.registerGlobalSetting(roundingRadius);
SettingManager.registerGlobalSetting(lineThickness);
Expand Down Expand Up @@ -403,7 +417,8 @@ public void removeWindow(Window hud, String pageName) {

@Override
public void onKeyDown(KeyDownEvent event) {
if (clickGuiButton.getValue().getValue() == event.GetKey() && MC.gui.screen() == null && !isKeyboardInputActive) {
Keybind clickguiKeybind = clickGuiButton.getValue();
if (clickguiKeybind.getKeyCode() == event.GetKey() && MC.gui.screen() == null && !isKeyboardInputActive) {
setClickGuiOpen(!clickGuiOpen);
toggleMouse();
}
Expand Down
23 changes: 18 additions & 5 deletions src/main/java/net/aoba/gui/components/ButtonComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

public class ButtonComponent extends Component {
private Runnable onClick;

private boolean isPressed = false;

/**
* Constructor for button component.
*
Expand All @@ -37,7 +38,8 @@ public ButtonComponent(Runnable onClick) {
@Override
public void draw(Renderer2D renderer, float partialTicks) {
boolean hovered = getProperty(UIElement.IsHoveredProperty);
Shader bgEffect = hovered ? GuiManager.buttonHoverBackgroundColor.getValue()

Shader bgEffect = isPressed ? GuiManager.buttonPressedBackgroundColor.getValue() : hovered ? GuiManager.buttonHoverBackgroundColor.getValue()
: getProperty(BackgroundProperty);
Shader bdEffect = getProperty(BorderProperty);
Float cornerRadius = getProperty(CornerRadiusProperty);
Expand Down Expand Up @@ -76,13 +78,24 @@ public void setOnClick(Runnable onClick) {
@Override
public void onMouseClick(MouseClickEvent event) {
super.onMouseClick(event);
if (event.button == MouseButton.LEFT && event.action == MouseAction.DOWN) {
if (event.button == MouseButton.LEFT) {
boolean hovered = getProperty(UIElement.IsHoveredProperty);
if (hovered) {
if (onClick != null)
onClick.run();

if(event.action == MouseAction.DOWN) {
isPressed = true;
}else if(event.action == MouseAction.UP) {
if (onClick != null) {
onClick.run();
}
isPressed = false;
}
event.cancel();
}else {
isPressed = false;
}
}else {
isPressed = false;
}
}
}
45 changes: 36 additions & 9 deletions src/main/java/net/aoba/gui/components/KeybindComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,29 @@
import net.aoba.gui.UIProperty;
import net.aoba.gui.types.GridDefinition;
import net.aoba.gui.types.HorizontalAlignment;
import net.aoba.gui.types.TextAlign;
import net.aoba.gui.types.TextWrapping;
import net.aoba.gui.types.Thickness;
import net.aoba.gui.types.VerticalAlignment;
import net.aoba.gui.types.GridDefinition.RelativeUnit;
import net.aoba.utils.input.CursorStyle;
import net.aoba.utils.types.MouseAction;
import net.aoba.utils.types.MouseButton;
import net.minecraft.client.gui.TextAlignment;
import net.aoba.utils.input.Keybind;

public class KeybindComponent extends Component implements KeyDownListener {
private boolean listeningForKey;
private final StringComponent label;
private final StringComponent keyTextComponent;
private final ToggleButtonComponent momentaryButton;

public static UIProperty<Key> SelectedKeyProperty = new UIProperty<>("SelectedKey", InputConstants.UNKNOWN, false, true, KeybindComponent::OnSelectedKeyPropertyChanged);
public static UIProperty<Keybind> SelectedKeyProperty = new UIProperty<>("SelectedKey", new Keybind(InputConstants.UNKNOWN, false), false, true, KeybindComponent::OnSelectedKeyPropertyChanged);
public static UIProperty<String> HeaderProperty = new UIProperty<>("Header", "", false, true, KeybindComponent::OnHeaderPropertyChanged);

private Consumer<Key> onChanged = null;
private static void OnSelectedKeyPropertyChanged(UIElement sender, Key oldValue, Key newValue) {
private Consumer<Keybind> onChanged = null;

private static void OnSelectedKeyPropertyChanged(UIElement sender, Keybind oldValue, Keybind newValue) {
if(sender instanceof KeybindComponent keybind) {
keybind.keyTextComponent.setProperty(StringComponent.TextProperty, keybind.getKeyDisplayText());

Expand All @@ -55,14 +60,35 @@ public KeybindComponent() {
setProperty(UIElement.CursorProperty, CursorStyle.Type);

GridComponent grid = new GridComponent();
grid.setProperty(GridComponent.HorizontalSpacingProperty, 4f);
grid.addColumnDefinition(new GridDefinition(1f, RelativeUnit.Relative));
grid.addColumnDefinition(new GridDefinition(RelativeUnit.Auto));
grid.addColumnDefinition(new GridDefinition(RelativeUnit.Auto));

// Label
label = new StringComponent();
label.setProperty(StringComponent.TextProperty, getProperty(KeybindComponent.HeaderProperty));
label.setProperty(UIElement.VerticalAlignmentProperty, VerticalAlignment.Center);
grid.addChild(label);

// Checkbox
momentaryButton = new ToggleButtonComponent();
momentaryButton.setProperty(Component.VerticalAlignmentProperty, VerticalAlignment.Center);
momentaryButton.setOnChanged(e -> {
Keybind keybind = this.getProperty(KeybindComponent.SelectedKeyProperty);
this.setProperty(KeybindComponent.SelectedKeyProperty, new Keybind(keybind.getKey(), e.booleanValue()));
});

momentaryButton.setProperty(UIElement.PaddingProperty, new Thickness(2f));

StringComponent momentaryButtonLabel = new StringComponent();
momentaryButtonLabel.setProperty(StringComponent.FontSizeProperty, 10f);
momentaryButtonLabel.setProperty(StringComponent.TextProperty, "Hold");
momentaryButtonLabel.setProperty(StringComponent.TextAlignmentProperty, TextAlign.Center);
momentaryButton.setContent(momentaryButtonLabel);
grid.addChild(momentaryButton);

// Key Button
RectangleComponent keyButton = new RectangleComponent();
keyButton.bindProperty(UIElement.BackgroundProperty, GuiManager.componentBackgroundColor);
keyButton.bindProperty(UIElement.BorderProperty, GuiManager.componentBorderColor);
Expand All @@ -89,10 +115,10 @@ public KeybindComponent() {
}

private String getKeyDisplayText() {
Key keybind = getProperty(SelectedKeyProperty);
if (keybind == null || keybind.equals(InputConstants.UNKNOWN))
Keybind keybind = getProperty(SelectedKeyProperty);
if (keybind == null || keybind.getKey() == InputConstants.UNKNOWN)
return "N/A";
return keybind.getDisplayName().getString();
return keybind.getKey().getDisplayName().getString();
}


Expand All @@ -103,12 +129,13 @@ public void onKeyDown(KeyDownEvent event) {
? InputConstants.UNKNOWN
: InputConstants.Type.KEYBOARD.getOrCreate(event.GetKey());

setProperty(SelectedKeyProperty, key);
boolean isMomentary = momentaryButton.getProperty(CheckboxComponent.IsCheckedProperty);
setProperty(SelectedKeyProperty, new Keybind(key, isMomentary));
setListeningForKey(false);
event.cancel();
}
}

private void setListeningForKey(boolean state) {
if (listeningForKey == state)
return;
Expand All @@ -131,7 +158,7 @@ protected void onLostFocus() {
}
}

public void setOnChanged(Consumer<Key> consumer) {
public void setOnChanged(Consumer<Keybind> consumer) {
this.onChanged = consumer;
}
}
Loading
Loading