diff --git a/src/main/java/net/aoba/gui/HudManager.java b/src/main/java/net/aoba/gui/HudManager.java index 7034d031..eac34f1a 100644 --- a/src/main/java/net/aoba/gui/HudManager.java +++ b/src/main/java/net/aoba/gui/HudManager.java @@ -50,9 +50,7 @@ public class HudManager implements LeftMouseDownListener, LeftMouseUpListener { public static AbstractHud currentGrabbed = null; private List activeHuds = new ArrayList(); - - - + private boolean wasTildaPressed = false; public NavigationBar clickGuiNavBar; @@ -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"); @@ -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); @@ -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) { @@ -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(); @@ -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); } diff --git a/src/main/java/net/aoba/gui/IHudElement.java b/src/main/java/net/aoba/gui/IHudElement.java index f747d84b..f2d7ea86 100644 --- a/src/main/java/net/aoba/gui/IHudElement.java +++ b/src/main/java/net/aoba/gui/IHudElement.java @@ -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); } diff --git a/src/main/java/net/aoba/gui/NavigationBar.java b/src/main/java/net/aoba/gui/NavigationBar.java index 4f38e6f8..660e12c0 100644 --- a/src/main/java/net/aoba/gui/NavigationBar.java +++ b/src/main/java/net/aoba/gui/NavigationBar.java @@ -23,6 +23,7 @@ public class NavigationBar implements LeftMouseDownListener { public NavigationBar() { options = new ArrayList(); renderUtils = new RenderUtils(); + Aoba.getInstance().eventManager.AddListener(LeftMouseDownListener.class, this); } public void addPane(Page pane) { @@ -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(); @@ -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 @@ -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); } } } diff --git a/src/main/java/net/aoba/gui/Page.java b/src/main/java/net/aoba/gui/Page.java index 2e62a18a..7086a228 100644 --- a/src/main/java/net/aoba/gui/Page.java +++ b/src/main/java/net/aoba/gui/Page.java @@ -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; @@ -9,8 +10,8 @@ public class Page { protected String title; protected List tabs = new ArrayList(); - - private List tabsToAdd = new ArrayList(); + + private boolean isVisible; public Page(String title) { this.title = title; @@ -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 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 tabIterator = tabs.iterator(); + while(tabIterator.hasNext()) { + tabIterator.next().draw(drawContext, partialTicks, color); } } } diff --git a/src/main/java/net/aoba/gui/hud/AbstractHud.java b/src/main/java/net/aoba/gui/hud/AbstractHud.java index 0ad1405d..0e0dac79 100644 --- a/src/main/java/net/aoba/gui/hud/AbstractHud.java +++ b/src/main/java/net/aoba/gui/hud/AbstractHud.java @@ -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; @@ -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 @@ -59,7 +58,6 @@ public float getHeight() { @Override public float getX() { return position.getValue().x; - } @Override @@ -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(); @@ -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(); @@ -151,6 +185,13 @@ public void OnMouseMove(MouseMoveEvent event) { isMouseOver = true; } } + }else { + isMouseOver = false; } } + + @Override + public void OnChildChanged(IHudElement child) { + + } } diff --git a/src/main/java/net/aoba/gui/tabs/components/ButtonComponent.java b/src/main/java/net/aoba/gui/tabs/components/ButtonComponent.java index 15da2f3d..dfa723ea 100644 --- a/src/main/java/net/aoba/gui/tabs/components/ButtonComponent.java +++ b/src/main/java/net/aoba/gui/tabs/components/ButtonComponent.java @@ -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); } /** @@ -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); + } } } diff --git a/src/main/java/net/aoba/gui/tabs/components/CheckboxComponent.java b/src/main/java/net/aoba/gui/tabs/components/CheckboxComponent.java index 43793d3f..30d8b002 100644 --- a/src/main/java/net/aoba/gui/tabs/components/CheckboxComponent.java +++ b/src/main/java/net/aoba/gui/tabs/components/CheckboxComponent.java @@ -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()) { @@ -50,6 +52,7 @@ public void draw(DrawContext drawContext, float partialTicks, Color color) { */ @Override public void update() { + super.update(); } /** diff --git a/src/main/java/net/aoba/gui/tabs/components/Component.java b/src/main/java/net/aoba/gui/tabs/components/Component.java index 96b0eeb2..f71a6034 100644 --- a/src/main/java/net/aoba/gui/tabs/components/Component.java +++ b/src/main/java/net/aoba/gui/tabs/components/Component.java @@ -1,12 +1,10 @@ package net.aoba.gui.tabs.components; import java.util.ArrayList; - import net.aoba.Aoba; import net.aoba.event.events.MouseMoveEvent; import net.aoba.event.listeners.MouseMoveListener; import net.aoba.gui.Color; -import net.aoba.gui.HudManager; import net.aoba.gui.IHudElement; import net.aoba.misc.RenderUtils; import net.minecraft.client.gui.DrawContext; @@ -16,7 +14,7 @@ public abstract class Component implements IHudElement, MouseMoveListener { private static boolean DEBUG = true; - private boolean visible = true; + private boolean visible = false; protected boolean hovered = false; // NEW ui variables. @@ -57,7 +55,6 @@ public Component(IHudElement parent) { if(renderUtils == null) { renderUtils = Aoba.getInstance().renderUtils; } - Aoba.getInstance().eventManager.AddListener(MouseMoveListener.class, this); } /** @@ -117,6 +114,7 @@ public void setX(float x) { this.x = x; this.actualX = this.parent.getX() + x; updateChildrenPosition(); + this.parent.OnChildChanged(this); } } @@ -125,6 +123,7 @@ public void setY(float y) { this.y = y; this.actualY = this.parent.getY() + y; updateChildrenPosition(); + this.parent.OnChildChanged(this); } } @@ -133,6 +132,7 @@ public void setWidth(float width) { this.width = width; this.actualWidth = width; updateChildrenPosition(); + this.parent.OnChildChanged(this); } } @@ -147,6 +147,7 @@ public void setHeight(float height) this.height = height; this.actualHeight = height; updateChildrenPosition(); + this.parent.OnChildChanged(this); } } @@ -164,6 +165,7 @@ public void setTop(float top) { actualHeight = height; } updateChildrenPosition(); + this.parent.OnChildChanged(this); } } @@ -176,6 +178,7 @@ public void setBottom(float bottom) { actualHeight = height; } updateChildrenPosition(); + this.parent.OnChildChanged(this); } } @@ -194,6 +197,7 @@ public void setLeft(float left) { actualWidth = width; } updateChildrenPosition(); + this.parent.OnChildChanged(this); } } @@ -206,11 +210,13 @@ public void setRight(float right) { actualWidth = width; } updateChildrenPosition(); + this.parent.OnChildChanged(this); } } public void addChild(Component component) { this.children.add(component); + this.OnChildAdded(component); } protected void updateChildrenPosition() { @@ -264,14 +270,24 @@ public IHudElement getParent() * @param bool State to set visibility to. */ public void setVisible(boolean bool) { + if(this.visible == bool) return; + this.visible = bool; + this.hovered = false; + for(Component child : this.children) { + child.setVisible(true); + } + + this.parent.OnChildChanged(this); // Register and Unregister event listener according to state. if(bool) { Aoba.getInstance().eventManager.AddListener(MouseMoveListener.class, this); }else { Aoba.getInstance().eventManager.RemoveListener(MouseMoveListener.class, this); } + + this.OnVisibilityChanged(); } /** @@ -302,13 +318,15 @@ public void update() { * @param color Color of the UI. */ public void draw(DrawContext drawContext, float partialTicks, Color color) { - if(this.hovered && DEBUG) { - renderUtils.drawOutline(drawContext.getMatrices(), this.actualX, this.actualY, this.actualWidth, this.actualHeight); - } + if(this.visible) { + if(this.hovered && DEBUG) { + renderUtils.drawOutline(drawContext.getMatrices(), this.actualX, this.actualY, this.actualWidth, this.actualHeight); + } - for(Component child : children) { - if(child.visible) { - child.draw(drawContext, partialTicks, color); + for(Component child : children) { + if(child.visible) { + child.draw(drawContext, partialTicks, color); + } } } } @@ -319,7 +337,7 @@ public void draw(DrawContext drawContext, float partialTicks, Color color) { */ @Override public void OnMouseMove(MouseMoveEvent mouseMoveEvent) { - if (HudManager.currentGrabbed != null || !visible) { + if (!visible) { this.hovered = false; }else { double mouseX = mouseMoveEvent.GetHorizontal(); @@ -328,4 +346,17 @@ public void OnMouseMove(MouseMoveEvent mouseMoveEvent) { this.hovered = ((mouseX >= actualX && mouseX <= (actualX + actualWidth)) && (mouseY >= (actualY) && mouseY <= (actualY + actualHeight))); } } + + public void OnChildAdded(IHudElement child) { + + } + + @Override + public void OnChildChanged(IHudElement child) { + + } + + public void OnVisibilityChanged() { + + } } diff --git a/src/main/java/net/aoba/gui/tabs/components/KeybindComponent.java b/src/main/java/net/aoba/gui/tabs/components/KeybindComponent.java index 93d98478..45a0217d 100644 --- a/src/main/java/net/aoba/gui/tabs/components/KeybindComponent.java +++ b/src/main/java/net/aoba/gui/tabs/components/KeybindComponent.java @@ -24,7 +24,9 @@ public KeybindComponent(IHudElement parent, KeybindSetting keyBind) { } @Override - public void update() {} + public void update() { + super.update(); + } @Override public void draw(DrawContext drawContext, float partialTicks, Color color) { diff --git a/src/main/java/net/aoba/gui/tabs/components/ListComponent.java b/src/main/java/net/aoba/gui/tabs/components/ListComponent.java index 50b05854..d36b0a16 100644 --- a/src/main/java/net/aoba/gui/tabs/components/ListComponent.java +++ b/src/main/java/net/aoba/gui/tabs/components/ListComponent.java @@ -73,7 +73,6 @@ public void OnLeftMouseDown(LeftMouseDownEvent event) { @Override public void update() { - // TODO Auto-generated method stub - + super.update(); } } diff --git a/src/main/java/net/aoba/gui/tabs/components/ModuleComponent.java b/src/main/java/net/aoba/gui/tabs/components/ModuleComponent.java index d5a3018d..40a6ba54 100644 --- a/src/main/java/net/aoba/gui/tabs/components/ModuleComponent.java +++ b/src/main/java/net/aoba/gui/tabs/components/ModuleComponent.java @@ -18,30 +18,26 @@ public class ModuleComponent extends Component implements LeftMouseDownListener { private String text; private Module module; - private boolean popped = false; - - private int expandedHeight = 30; - private Color hoverColor = new Color(90, 90, 90); private Color color = new Color(128, 128, 128); private Color backgroundColor = color; + private ModuleSettingsTab lastSettingsTab = null; + public ModuleComponent(String text, IHudElement parent, Module module) { super(parent); this.text = text; this.module = module; - this.setHeight(30); this.setLeft(2); this.setRight(2); - - Aoba.getInstance().eventManager.AddListener(LeftMouseDownListener.class, this); + this.setHeight(30); } @Override public void update() { - + super.update(); } @Override @@ -50,20 +46,10 @@ public void draw(DrawContext drawContext, float partialTicks, Color color) { renderUtils.drawString(drawContext, this.text, actualX + 8, actualY + 8, module.getState() ? 0x00FF00 : 0xFFFFFF); if (module.hasSettings()) { - renderUtils.drawString(drawContext, this.popped ? "<<" : ">>", actualX + actualWidth - 30, + renderUtils.drawString(drawContext, ">>", actualX + actualWidth - 30, actualY + 8, color.getColorAsInt()); } } - - public void setPopped(boolean state) { - this.popped = state; - for(Component child : children) { - child.setVisible(state); - } - } - - - @Override public void OnLeftMouseDown(LeftMouseDownEvent event) { @@ -73,15 +59,14 @@ public void OnLeftMouseDown(LeftMouseDownEvent event) { if(mouseY >= actualY && mouseY <= actualY + 30){ boolean isOnOptionsButton = (mouseX >= (actualX + actualWidth - 34) && mouseX <= (actualX + actualWidth)); if (isOnOptionsButton) { -// setPopped(!this.popped); -// -// if (this.popped) { -// this.setHeight(expandedHeight); -// } else { -// this.setHeight(30); -// } - - Aoba.getInstance().hudManager.AddHud(new ModuleSettingsTab(this.module.getName(), this.actualX + this.width + 1, this.y, this.module), "Modules"); + if(lastSettingsTab == null) { + lastSettingsTab = new ModuleSettingsTab(this.module.getName(), this.actualX + this.width + 1, this.y, this.module); + lastSettingsTab.setVisible(true); + Aoba.getInstance().hudManager.AddHud(lastSettingsTab, "Modules"); + }else { + Aoba.getInstance().hudManager.RemoveHud(lastSettingsTab, "Modules"); + lastSettingsTab = null; + } } else { module.toggle(); return; @@ -89,4 +74,13 @@ public void OnLeftMouseDown(LeftMouseDownEvent event) { } } } + + @Override + public void OnVisibilityChanged() { + if(this.isVisible()) { + Aoba.getInstance().eventManager.AddListener(LeftMouseDownListener.class, this); + }else { + Aoba.getInstance().eventManager.RemoveListener(LeftMouseDownListener.class, this); + } + } } diff --git a/src/main/java/net/aoba/gui/tabs/components/SliderComponent.java b/src/main/java/net/aoba/gui/tabs/components/SliderComponent.java index d2d3a390..02bb29d3 100644 --- a/src/main/java/net/aoba/gui/tabs/components/SliderComponent.java +++ b/src/main/java/net/aoba/gui/tabs/components/SliderComponent.java @@ -100,7 +100,7 @@ public void OnMouseMove(MouseMoveEvent event) { @Override public void update() { - + super.update(); } @Override diff --git a/src/main/java/net/aoba/gui/tabs/components/StackPanelComponent.java b/src/main/java/net/aoba/gui/tabs/components/StackPanelComponent.java index c1da7736..05f4ea34 100644 --- a/src/main/java/net/aoba/gui/tabs/components/StackPanelComponent.java +++ b/src/main/java/net/aoba/gui/tabs/components/StackPanelComponent.java @@ -15,13 +15,27 @@ public StackPanelComponent(IHudElement parent) { @Override public void update() { + super.update(); + } + + @Override + public void OnChildAdded(IHudElement child) { + this.RecalculateHeight(); + } + + @Override + public void OnChildChanged(IHudElement child) { + this.RecalculateHeight(); + } + + public void RecalculateHeight() { int height = 0; for(int i = 0; i < children.size(); i++) { - Component child = children.get(i); + Component iChild = children.get(i); // If the child is visible, increase the height of the StackPanel. - if (child.isVisible()) { - height += child.getHeight(); + if (iChild.isVisible()) { + height += iChild.getHeight(); } // Move the Top of the child below to the top + height of the previous element. diff --git a/src/main/java/net/aoba/gui/tabs/components/StringComponent.java b/src/main/java/net/aoba/gui/tabs/components/StringComponent.java index 1d7985ea..02583069 100644 --- a/src/main/java/net/aoba/gui/tabs/components/StringComponent.java +++ b/src/main/java/net/aoba/gui/tabs/components/StringComponent.java @@ -66,7 +66,6 @@ public void draw(DrawContext drawContext, float partialTicks, Color color) { actualY + 8 + i, 0xFFFFFF); i += 30; } - } /**