Skip to content

Commit

Permalink
changes:
Browse files Browse the repository at this point in the history
- fixed Watermark texture disrupting other overlay elements (health bar)
- fixed returning wrong data for getCombo
- added find method in Config
- added startY to NotificationManager (avoid overlapping with watermark)
- added more chaining constructors
- made separate events with predefined types
- refactored position utils into own packages
  • Loading branch information
dxxxxy committed Oct 12, 2022
1 parent 565abee commit 36cc982
Show file tree
Hide file tree
Showing 18 changed files with 104 additions and 112 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/studio/dreamys/icarus/component/Page.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -51,7 +51,6 @@ public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
if (hovered(mouseX, mouseY) && mouseButton == 0) {
runnable.run();
held = true;
fireChange();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
69 changes: 20 additions & 49 deletions src/main/java/studio/dreamys/icarus/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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<String, Boolean> 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<String, Boolean> 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<? extends Component> 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;
}
}
30 changes: 18 additions & 12 deletions src/main/java/studio/dreamys/icarus/event/ComponentEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Boolean> 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();
}
}
Expand Down
27 changes: 18 additions & 9 deletions src/main/java/studio/dreamys/icarus/extra/Watermark.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class Notification {
private ArrayList<String> 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) {
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.util.ArrayList;

public class NotificationManager {
public static double startY;

public static ArrayList<Notification> notifications = new ArrayList<>();

public static void send(Notification notification) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Loading

0 comments on commit 36cc982

Please sign in to comment.