diff --git a/build.gradle b/build.gradle index 232897d..81b430b 100644 --- a/build.gradle +++ b/build.gradle @@ -14,7 +14,7 @@ plugins { apply plugin: "net.minecraftforge.gradle.forge" -version = "1.4.1" +version = "1.4.2" group = "dreamys.studio" //http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "Icarus" //name of the output jar diff --git a/src/main/java/studio/dreamys/icarus/component/Component.java b/src/main/java/studio/dreamys/icarus/component/Component.java index db45c0f..1bd0a3c 100644 --- a/src/main/java/studio/dreamys/icarus/component/Component.java +++ b/src/main/java/studio/dreamys/icarus/component/Component.java @@ -4,7 +4,7 @@ import net.minecraftforge.fml.common.eventhandler.Event; import studio.dreamys.icarus.component.sub.*; import studio.dreamys.icarus.event.ComponentEvent; -import studio.dreamys.icarus.util.Bounds; +import studio.dreamys.icarus.util.position.Bounds; //keep this not abstract to avoid some useless empty methods public class Component { diff --git a/src/main/java/studio/dreamys/icarus/component/Page.java b/src/main/java/studio/dreamys/icarus/component/Page.java index 700d9b5..c34e113 100644 --- a/src/main/java/studio/dreamys/icarus/component/Page.java +++ b/src/main/java/studio/dreamys/icarus/component/Page.java @@ -1,6 +1,5 @@ package studio.dreamys.icarus.component; -import com.google.common.collect.Lists; import lombok.Getter; import lombok.Setter; import studio.dreamys.icarus.Icarus; diff --git a/src/main/java/studio/dreamys/icarus/component/sub/Button.java b/src/main/java/studio/dreamys/icarus/component/sub/Button.java index 88e5bde..1286734 100644 --- a/src/main/java/studio/dreamys/icarus/component/sub/Button.java +++ b/src/main/java/studio/dreamys/icarus/component/sub/Button.java @@ -4,8 +4,8 @@ import lombok.Setter; import studio.dreamys.icarus.component.Component; import studio.dreamys.icarus.component.Window; -import studio.dreamys.icarus.util.Bounds; import studio.dreamys.icarus.util.RenderUtils; +import studio.dreamys.icarus.util.position.Bounds; import java.awt.Color; @@ -51,7 +51,6 @@ public void mouseClicked(int mouseX, int mouseY, int mouseButton) { if (hovered(mouseX, mouseY) && mouseButton == 0) { runnable.run(); held = true; - fireChange(); } } diff --git a/src/main/java/studio/dreamys/icarus/component/sub/Checkbox.java b/src/main/java/studio/dreamys/icarus/component/sub/Checkbox.java index d3c7230..3d2fa01 100644 --- a/src/main/java/studio/dreamys/icarus/component/sub/Checkbox.java +++ b/src/main/java/studio/dreamys/icarus/component/sub/Checkbox.java @@ -4,7 +4,7 @@ import lombok.Setter; import studio.dreamys.icarus.component.Component; import studio.dreamys.icarus.component.Window; -import studio.dreamys.icarus.util.Bounds; +import studio.dreamys.icarus.util.position.Bounds; import studio.dreamys.icarus.util.RenderUtils; import java.awt.Color; diff --git a/src/main/java/studio/dreamys/icarus/component/sub/Choice.java b/src/main/java/studio/dreamys/icarus/component/sub/Choice.java index c71e108..7ac6eb3 100644 --- a/src/main/java/studio/dreamys/icarus/component/sub/Choice.java +++ b/src/main/java/studio/dreamys/icarus/component/sub/Choice.java @@ -4,7 +4,7 @@ import lombok.Setter; import studio.dreamys.icarus.component.Component; import studio.dreamys.icarus.component.Window; -import studio.dreamys.icarus.util.Bounds; +import studio.dreamys.icarus.util.position.Bounds; import studio.dreamys.icarus.util.RenderUtils; import java.awt.Color; diff --git a/src/main/java/studio/dreamys/icarus/component/sub/Combo.java b/src/main/java/studio/dreamys/icarus/component/sub/Combo.java index e3d8532..b917bb5 100644 --- a/src/main/java/studio/dreamys/icarus/component/sub/Combo.java +++ b/src/main/java/studio/dreamys/icarus/component/sub/Combo.java @@ -4,7 +4,7 @@ import lombok.Setter; import studio.dreamys.icarus.component.Component; import studio.dreamys.icarus.component.Window; -import studio.dreamys.icarus.util.Bounds; +import studio.dreamys.icarus.util.position.Bounds; import studio.dreamys.icarus.util.RenderUtils; import java.awt.Color; diff --git a/src/main/java/studio/dreamys/icarus/component/sub/Field.java b/src/main/java/studio/dreamys/icarus/component/sub/Field.java index 4157f3e..4aed003 100644 --- a/src/main/java/studio/dreamys/icarus/component/sub/Field.java +++ b/src/main/java/studio/dreamys/icarus/component/sub/Field.java @@ -5,7 +5,7 @@ import org.lwjgl.input.Keyboard; import studio.dreamys.icarus.component.Component; import studio.dreamys.icarus.component.Window; -import studio.dreamys.icarus.util.Bounds; +import studio.dreamys.icarus.util.position.Bounds; import studio.dreamys.icarus.util.RenderUtils; import java.awt.Color; diff --git a/src/main/java/studio/dreamys/icarus/component/sub/Slider.java b/src/main/java/studio/dreamys/icarus/component/sub/Slider.java index 84afbba..0df1675 100644 --- a/src/main/java/studio/dreamys/icarus/component/sub/Slider.java +++ b/src/main/java/studio/dreamys/icarus/component/sub/Slider.java @@ -4,7 +4,7 @@ import lombok.Setter; import studio.dreamys.icarus.component.Component; import studio.dreamys.icarus.component.Window; -import studio.dreamys.icarus.util.Bounds; +import studio.dreamys.icarus.util.position.Bounds; import studio.dreamys.icarus.util.RenderUtils; import java.awt.Color; diff --git a/src/main/java/studio/dreamys/icarus/config/Config.java b/src/main/java/studio/dreamys/icarus/config/Config.java index 1c7420b..d831a83 100644 --- a/src/main/java/studio/dreamys/icarus/config/Config.java +++ b/src/main/java/studio/dreamys/icarus/config/Config.java @@ -7,10 +7,12 @@ import java.io.*; import java.util.ArrayList; +import java.util.HashMap; @SuppressWarnings("unused") public class Config { public static File file; + private Component comp; @SuppressWarnings("ResultOfMethodCallIgnored") public Config(String modid) { @@ -114,87 +116,56 @@ public void load() { } public boolean getCheckbox(String group, String label) { - for (Component comp : Icarus.getWindow().all) { - if (comp.getLabel().equals(label) && comp.getGroup().getLabel().equals(group) && comp instanceof Checkbox) { - return ((Checkbox) comp).isToggled(); - } - } + if ((comp = find(group, label, Checkbox.class)) != null) return ((Checkbox) comp).isToggled(); return false; } public String getChoice(String group, String label) { - for (Component comp : Icarus.getWindow().all) { - if (comp.getLabel().equals(label) && comp.getGroup().getLabel().equals(group) && comp instanceof Choice) { - return ((Choice) comp).getSelected(); - } - } + if ((comp = find(group, label, Choice.class)) != null) return ((Choice) comp).getSelected(); return null; } - public String getCombo(String group, String label) { - for (Component comp : Icarus.getWindow().all) { - if (comp.getLabel().equals(label) && comp.getGroup().getLabel().equals(group) && comp instanceof Combo) { - return ((Combo) comp).getActiveOptions(); - } - } + public HashMap getCombo(String group, String label) { + if ((comp = find(group, label, Combo.class)) != null) return ((Combo) comp).getOptions(); return null; } public String getField(String group, String label) { - for (Component comp : Icarus.getWindow().all) { - if (comp.getLabel().equals(label) && comp.getGroup().getLabel().equals(group) && comp instanceof Field) { - return ((Field) comp).getText(); - } - } + if ((comp = find(group, label, Field.class)) != null) return ((Field) comp).getText(); return null; } public double getSlider(String group, String label) { - for (Component comp : Icarus.getWindow().all) { - if (comp.getLabel().equals(label) && comp.getGroup().getLabel().equals(group) && comp instanceof Slider) { - return ((Slider) comp).getValue(); - } - } + if ((comp = find(group, label, Slider.class)) != null) return ((Slider) comp).getValue(); return 0; } public void setCheckbox(String group, String label, boolean toggled) { - for (Component comp : Icarus.getWindow().all) { - if (comp.getLabel().equals(label) && comp.getGroup().getLabel().equals(group) && comp instanceof Checkbox) { - ((Checkbox) comp).setToggled(toggled); - } - } + if ((comp = find(group, label, Checkbox.class)) != null) ((Checkbox) comp).setToggled(toggled); } public void setChoice(String group, String label, String selected) { - for (Component comp : Icarus.getWindow().all) { - if (comp.getLabel().equals(label) && comp.getGroup().getLabel().equals(group) && comp instanceof Choice) { - ((Choice) comp).setSelected(selected); - } - } + if ((comp = find(group, label, Choice.class)) != null) ((Choice) comp).setSelected(selected); } - public void setCombo(String group, String label, String activeOptions) { - for (Component comp : Icarus.getWindow().all) { - if (comp.getLabel().equals(label) && comp.getGroup().getLabel().equals(group) && comp instanceof Combo) { - ((Combo) comp).setActiveOptions(activeOptions); - } - } + public void setCombo(String group, String label, HashMap options) { + if ((comp = find(group, label, Combo.class)) != null) ((Combo) comp).setOptions(options); } public void setField(String group, String label, String text) { - for (Component comp : Icarus.getWindow().all) { - if (comp.getLabel().equals(label) && comp.getGroup().getLabel().equals(group) && comp instanceof Field) { - ((Field) comp).setText(text); - } - } + if ((comp = find(group, label, Field.class)) != null) ((Field) comp).setText(text); } public void setSlider(String group, String label, double value) { + if ((comp = find(group, label, Slider.class)) != null) ((Slider) comp).setValue(value); + } + + public Component find(String group, String label, Class subType) { for (Component comp : Icarus.getWindow().all) { - if (comp.getLabel().equals(label) && comp.getGroup().getLabel().equals(group) && comp instanceof Slider) { - ((Slider) comp).setValue(value); + if (comp.getLabel().equals(label) && comp.getGroup().getLabel().equals(group) && subType.isInstance(comp)) { + return comp; } } + return null; } } diff --git a/src/main/java/studio/dreamys/icarus/event/ComponentEvent.java b/src/main/java/studio/dreamys/icarus/event/ComponentEvent.java index 6ec4626..d97e56b 100644 --- a/src/main/java/studio/dreamys/icarus/event/ComponentEvent.java +++ b/src/main/java/studio/dreamys/icarus/event/ComponentEvent.java @@ -13,56 +13,62 @@ public ComponentEvent(Component component) { this.component = component; } - public static class CheckboxEvent extends ComponentEvent { + public static class CheckboxEvent extends Event { + public Checkbox checkbox; public boolean toggled; public CheckboxEvent(Checkbox checkbox) { - super(checkbox); + this.checkbox = checkbox; toggled = checkbox.isToggled(); } } - public static class ChoiceEvent extends ComponentEvent { + public static class ChoiceEvent extends Event { + public Choice choice; public String selected; public ChoiceEvent(Choice choice) { - super(choice); + this.choice = choice; selected = choice.getSelected(); } } - public static class ComboEvent extends ComponentEvent { + public static class ComboEvent extends Event { + public Combo combo; public HashMap activeOptions; public ComboEvent(Combo combo) { - super(combo); + this.combo = combo; activeOptions = combo.getOptions(); } } - public static class FieldEvent extends ComponentEvent { + public static class FieldEvent extends Event { + public Field field; public String text; public FieldEvent(Field field) { - super(field); + this.field = field; text = field.getText(); } } - public static class KeybindEvent extends ComponentEvent { + public static class KeybindEvent extends Event { + public Keybind keybind; public int key; public KeybindEvent(Keybind keybind) { - super(keybind); + this.keybind = keybind; key = keybind.getKey(); } } - public static class SliderEvent extends ComponentEvent { + public static class SliderEvent extends Event { + public Slider slider; public double value; public SliderEvent(Slider slider) { - super(slider); + this.slider = slider; value = slider.getValue(); } } diff --git a/src/main/java/studio/dreamys/icarus/extra/Watermark.java b/src/main/java/studio/dreamys/icarus/extra/Watermark.java index 44a97ac..78f5241 100644 --- a/src/main/java/studio/dreamys/icarus/extra/Watermark.java +++ b/src/main/java/studio/dreamys/icarus/extra/Watermark.java @@ -7,7 +7,7 @@ import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import studio.dreamys.icarus.util.Placement; +import studio.dreamys.icarus.util.position.Position; import studio.dreamys.icarus.util.RenderUtils; import java.awt.*; @@ -16,26 +16,35 @@ @Setter public class Watermark { private String text; - private Placement placement; + private Position position; private double x, y, width, height = RenderUtils.getFontHeight() + 7.5; private Color textColor; - public Watermark(String text, Placement placement, Color textColor) { + public Watermark(String text) { + this(text, Position.TOP_RIGHT); + } + + public Watermark(String text, Position position) { + this(text, position, Color.WHITE); + } + + public Watermark(String text, Position position, Color textColor) { this.text = text; - this.placement = placement; + this.position = position; this.textColor = textColor; - - width = RenderUtils.getStringWidth(text) + 5; } @SubscribeEvent public void onGameOverlay(RenderGameOverlayEvent e) { + if (e.type != RenderGameOverlayEvent.ElementType.TEXT) return; + //update width in case text changes width = RenderUtils.getStringWidth(text) + 5; - placement.init(width, height); - x = placement.getX(); - y = placement.getY(); + //position + position.init(width, height); + x = position.getX(); + y = position.getY(); //draw our very professional skeet watermark Minecraft.getMinecraft().getTextureManager().bindTexture(new ResourceLocation("icarus", "watermark.png")); diff --git a/src/main/java/studio/dreamys/icarus/extra/notification/Notification.java b/src/main/java/studio/dreamys/icarus/extra/notification/Notification.java index b583fe3..8a14c00 100644 --- a/src/main/java/studio/dreamys/icarus/extra/notification/Notification.java +++ b/src/main/java/studio/dreamys/icarus/extra/notification/Notification.java @@ -22,7 +22,7 @@ public class Notification { private ArrayList lines; public Notification(String title, String message) { - this(title, message, 20, Color.BLACK, Color.WHITE, Color.WHITE, Color.PINK); + this(title, message, 20); } public Notification(String title, String message, int ticksToStay) { @@ -66,7 +66,7 @@ public Notification(String title, String message, int ticksToStay, Color backgro @SubscribeEvent public void onGameOverlay(RenderGameOverlayEvent e) { - y = 0; + y = NotificationManager.startY; //notification dynamic stacking for (Notification notification : NotificationManager.notifications) { diff --git a/src/main/java/studio/dreamys/icarus/extra/notification/NotificationManager.java b/src/main/java/studio/dreamys/icarus/extra/notification/NotificationManager.java index 6052bfd..d8291a3 100644 --- a/src/main/java/studio/dreamys/icarus/extra/notification/NotificationManager.java +++ b/src/main/java/studio/dreamys/icarus/extra/notification/NotificationManager.java @@ -5,6 +5,8 @@ import java.util.ArrayList; public class NotificationManager { + public static double startY; + public static ArrayList notifications = new ArrayList<>(); public static void send(Notification notification) { diff --git a/src/main/java/studio/dreamys/icarus/util/Bounds.java b/src/main/java/studio/dreamys/icarus/util/position/Bounds.java similarity index 75% rename from src/main/java/studio/dreamys/icarus/util/Bounds.java rename to src/main/java/studio/dreamys/icarus/util/position/Bounds.java index f1d7b0c..f4e799e 100644 --- a/src/main/java/studio/dreamys/icarus/util/Bounds.java +++ b/src/main/java/studio/dreamys/icarus/util/position/Bounds.java @@ -1,9 +1,10 @@ -package studio.dreamys.icarus.util; +package studio.dreamys.icarus.util.position; import lombok.Getter; +@Getter public class Bounds { - @Getter private double width, height, offsetY; + private double width, height, offsetY; public Bounds(double width, double height) { this(width, height, 0); diff --git a/src/main/java/studio/dreamys/icarus/util/Placement.java b/src/main/java/studio/dreamys/icarus/util/position/Position.java similarity index 94% rename from src/main/java/studio/dreamys/icarus/util/Placement.java rename to src/main/java/studio/dreamys/icarus/util/position/Position.java index 09ec9b0..2c88163 100644 --- a/src/main/java/studio/dreamys/icarus/util/Placement.java +++ b/src/main/java/studio/dreamys/icarus/util/position/Position.java @@ -1,8 +1,10 @@ -package studio.dreamys.icarus.util; +package studio.dreamys.icarus.util.position; +import lombok.Getter; import net.minecraft.client.Minecraft; -public enum Placement { +@Getter +public enum Position { TOP_LEFT, TOP_CENTER, TOP_RIGHT, diff --git a/src/main/java/studio/dreamys/test/TestMod.java b/src/main/java/studio/dreamys/test/TestMod.java index ac0a3bd..e6cd9e4 100644 --- a/src/main/java/studio/dreamys/test/TestMod.java +++ b/src/main/java/studio/dreamys/test/TestMod.java @@ -9,10 +9,9 @@ import org.lwjgl.input.Keyboard; import studio.dreamys.icarus.Icarus; import studio.dreamys.icarus.event.ComponentEvent; +import studio.dreamys.icarus.extra.Watermark; import studio.dreamys.icarus.extra.notification.Notification; import studio.dreamys.icarus.extra.notification.NotificationManager; -import studio.dreamys.icarus.extra.Watermark; -import studio.dreamys.icarus.util.Placement; import java.awt.*; @@ -25,57 +24,61 @@ public void preInit(FMLPreInitializationEvent e) { System.out.println(Icarus.getConfig().getCheckbox("Visuals", "haha")); System.out.println(Icarus.getConfig().getCheckbox("Visuals", "Another Checkbox")); System.out.println(Icarus.getConfig().getCheckbox("Visuals", "Checkbox")); - new Watermark("dxxxxyware | uid 001 (dxxxxy) | mc.hypixel.net | 23ms", Placement.TOP_RIGHT, Color.WHITE).enable(); + new Watermark("dxxxxyware | uid 001 (dxxxxy) | mc.hypixel.net | 23ms").enable(); + NotificationManager.startY = 20; //start below watermark //try all except top_right - new Watermark("testing123testing", Placement.TOP_LEFT, Color.WHITE).enable(); - new Watermark("testing123testing", Placement.TOP_CENTER, Color.WHITE).enable(); - new Watermark("testing123testing", Placement.CENTER_LEFT, Color.WHITE).enable(); - new Watermark("testing123testing", Placement.CENTER, Color.WHITE).enable(); - new Watermark("testing123testing", Placement.CENTER_RIGHT, Color.WHITE).enable(); - new Watermark("testing123testing", Placement.BOTTOM_LEFT, Color.WHITE).enable(); - new Watermark("testing123testing", Placement.BOTTOM_CENTER, Color.WHITE).enable(); - new Watermark("testing123testing", Placement.BOTTOM_RIGHT, Color.WHITE).enable(); +// new Watermark("testing123testing", Position.TOP_LEFT, Color.WHITE).enable(); +// new Watermark("testing123testing", Position.TOP_CENTER, Color.WHITE).enable(); +// new Watermark("testing123testing", Position.CENTER_LEFT, Color.WHITE).enable(); +// new Watermark("testing123testing", Position.CENTER, Color.WHITE).enable(); +// new Watermark("testing123testing", Position.CENTER_RIGHT, Color.WHITE).enable(); +// new Watermark("testing123testing", Position.BOTTOM_LEFT, Color.WHITE).enable(); +// new Watermark("testing123testing", Position.BOTTOM_CENTER, Color.WHITE).enable(); +// new Watermark("testing123testing", Position.BOTTOM_RIGHT, Color.WHITE).enable(); } @SubscribeEvent public void onComponentStateChange(ComponentEvent e) { System.out.println(e.component); + Icarus.getConfig().setSlider("AHSniper", "Sleep (ms)", 3000); } @SubscribeEvent public void onComponentStateChange(ComponentEvent.CheckboxEvent e) { - System.out.println(e.component); + System.out.println(e.checkbox); System.out.println(e.toggled); + Icarus.getConfig().setSlider("AHSniper", "Sleep (ms)", 3000); + } @SubscribeEvent public void onComponentStateChange(ComponentEvent.ChoiceEvent e) { - System.out.println(e.component); + System.out.println(e.choice); System.out.println(e.selected); } @SubscribeEvent public void onComponentStateChange(ComponentEvent.ComboEvent e) { - System.out.println(e.component); + System.out.println(e.combo); System.out.println(e.activeOptions); } @SubscribeEvent public void onComponentStateChange(ComponentEvent.FieldEvent e) { - System.out.println(e.component); + System.out.println(e.field); System.out.println(e.text); } @SubscribeEvent public void onComponentStateChange(ComponentEvent.KeybindEvent e) { - System.out.println(e.component); + System.out.println(e.keybind); System.out.println(e.key); } @SubscribeEvent public void onComponentStateChange(ComponentEvent.SliderEvent e) { - System.out.println(e.component); + System.out.println(e.slider); System.out.println(e.value); } diff --git a/src/main/java/studio/dreamys/test/TestWindow.java b/src/main/java/studio/dreamys/test/TestWindow.java index aa7db68..2a3c48e 100644 --- a/src/main/java/studio/dreamys/test/TestWindow.java +++ b/src/main/java/studio/dreamys/test/TestWindow.java @@ -51,15 +51,15 @@ public TestWindow() { addPage(new Page('s')) .addGroup(new Group("AHSniper", 47.5, 10)) - .addChild(new Checkbox("Enabled"), new Keybind()) - .addChild(new Slider("Sleep (ms)", 2000, 1, 5000, true)) - .addChild(new Slider("Minimum Profit (x)", 5, 2, 30, true)) - .addChild(new Choice("Lowest Bin Prices", new ArrayList<>(Arrays.asList("Moulberry", "Binmaster", "SkyHelper")))) - .addChild(new Button("Force Update Prices", () -> { - System.out.println("Force Update Prices"); - })) - .addChild(new Checkbox("Verbose Chat")) - .addChild(new Checkbox("Auto Buy")) + .addChild(new Checkbox("Enabled"), new Keybind()) + .addChild(new Slider("Sleep (ms)", 2000, 1, 5000, true)) + .addChild(new Slider("Minimum Profit (x)", 5, 2, 30, true)) + .addChild(new Choice("Lowest Bin Prices", new ArrayList<>(Arrays.asList("Moulberry", "Binmaster", "SkyHelper")))) + .addChild(new Button("Force Update Prices", () -> { + System.out.println("Force Update Prices"); + })) + .addChild(new Checkbox("Verbose Chat")) + .addChild(new Checkbox("Auto Buy")) ; /* ADDING COMPONENTS */