Skip to content

Commit

Permalink
Some more changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
tanishisherewithhh committed Jul 10, 2024
1 parent e04bcf6 commit 174a9eb
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/main/java/dev/heliosclient/hud/HudElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ public void saveSettingsToMap(Map<String, Object> MAP){

@Override
public void loadFromFile(Map<String, Object> MAP) {
//Hope it saves as double and not any other.
List<Double> obj = (List<Double>) MAP.get("dimensions");
this.x = MathUtils.d2iSafe(obj.get(0));
this.y = MathUtils.d2iSafe(obj.get(1));
Expand Down
52 changes: 35 additions & 17 deletions src/main/java/dev/heliosclient/hud/hudelements/ModuleList.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ public class ModuleList extends HudElement implements Listener {

public static HudElementData<ModuleList> DATA = new HudElementData<>("Module List", "Shows enabled modules", ModuleList::new);

//Managing a structure of sorted Modules to prevent resorting them every time unless the enabled modules change.
private List<Module_> sortedModules = new ArrayList<>();

public SettingGroup sgSettings = new SettingGroup("Settings");
private final CycleSetting sort = sgSettings.add(new CycleSetting.Builder()
.name("Sort")
Expand All @@ -49,6 +46,13 @@ public class ModuleList extends HudElement implements Listener {
.defaultValue(true)
.build()
);
public RGBASetting moduleInfoColor = sgSettings.add(new RGBASetting.Builder()
.name("ModuleInfo Color")
.description("Color of the ModuleInfo text")
.defaultValue(Color.DARK_GRAY)
.onSettingChange(this)
.shouldRender(() -> moduleInfo.value)
.build());
private final BooleanSetting background = sgSettings.add(new BooleanSetting.Builder()
.name("Render Module Background")
.description("Renders a background behind the module name and info")
Expand Down Expand Up @@ -168,6 +172,10 @@ public class ModuleList extends HudElement implements Listener {
.build()
);
private ArrayList<Module_> enabledModules = ModuleManager.getEnabledModules();

//Managing a structure of sorted Modules to prevent resorting them every time unless the enabled modules change.
private List<Module_> sortedModules = new ArrayList<>();

private Color rainbow = new Color(255, 255, 255);
private double rainbowHue1;
private double rainbowHue2;
Expand All @@ -179,24 +187,23 @@ public ModuleList() {
this.width = 50;
EventManager.register(this);
addSettingGroup(sgSettings);

}

@Override
public void onLoad() {
}

@Override
public void renderElement(DrawContext drawContext, TextRenderer textRenderer) {
int maxWidth = 0;

// Calculate the maximum width of the module names for enabled modules only
for (Module_ m : enabledModules) {
if (!m.showInModulesList.value) continue;
String name = moduleInfo.value ? m.getNameWithInfo() : m.name;
int nameWidth = Math.round(Renderer2D.getStringWidth(name));
maxWidth = Math.max(maxWidth, nameWidth);
}
this.width = maxWidth + (sideLines.value ? 4 : 0);
}

@Override
public void renderElement(DrawContext drawContext, TextRenderer textRenderer) {
if (colorMode.getOption() == METEOR) {
rainbowHue1 += rainbowSpeed.value * mc.getTickDelta();
if (rainbowHue1 > 1) rainbowHue1 -= 1;
Expand All @@ -206,15 +213,14 @@ public void renderElement(DrawContext drawContext, TextRenderer textRenderer) {
}

// Render each module with a different color
this.width = maxWidth + (sideLines.value ? 4 : 0);
int yOffset = this.y; // Start rendering from this.y

for (Module_ m : enabledModules) {
if (!m.showInModulesList.value) continue;

String info = m.getInfoString();

float nameWidth = Renderer2D.getStringWidth(m.name) + ((info.isEmpty() || !moduleInfo.value) ? 0 : Renderer2D.getStringWidth(" [" + info + "]"));
float nameWidth = Renderer2D.getStringWidth(m.name) + getInfoStringWidth(info);
if (colorMode.getOption() == METEOR) {
rainbowHue2 += rainbowSpread.value;
rainbow = new Color(Color.HSBtoRGB((float) rainbowHue2, (float) rainbowSaturation.value, (float) rainbowBrightness.value));
Expand Down Expand Up @@ -253,7 +259,7 @@ public void renderElement(DrawContext drawContext, TextRenderer textRenderer) {
if (moduleInfo.value && !info.isEmpty()) {
Renderer2D.drawString(drawContext.getMatrices(), "[" + info + "]",
textX + Renderer2D.getStringWidth(m.name + " "), 1 + yOffset,
Color.DARK_GRAY.getRGB());
moduleInfoColor.getColor().getRGB());
}


Expand All @@ -263,21 +269,36 @@ public void renderElement(DrawContext drawContext, TextRenderer textRenderer) {
}
private Comparator<Module_> getComparator() {
return (m1, m2) -> {
float name1Width = Renderer2D.getStringWidth(m1.name) + ((m1.getInfoString().isEmpty() || !moduleInfo.value) ? 0 : Renderer2D.getStringWidth(" [" + m1.getInfoString() + "]"));
float name2Width = Renderer2D.getStringWidth(m2.name) + ((m2.getInfoString().isEmpty() || !moduleInfo.value) ? 0 : Renderer2D.getStringWidth(" [" + m2.getInfoString() + "]"));
float name1Width = Renderer2D.getStringWidth(m1.name) + getInfoStringWidth(m1.getInfoString());
float name2Width = Renderer2D.getStringWidth(m2.name) + getInfoStringWidth(m2.getInfoString());
return switch ((Sort) sort.getOption()) {
case Alphabetical -> m1.name.compareTo(m2.name);
case Biggest -> Float.compare(name2Width, name1Width);
case Smallest -> Float.compare(name1Width, name2Width);
};
};
}

private float getInfoStringWidth(String infoString){
return (infoString.isEmpty() || !moduleInfo.value) ? 0 : Renderer2D.getStringWidth(" [" + infoString + "]");
}

@SubscribeEvent
public void update(TickEvent.CLIENT event) {
enabledModules = ModuleManager.getEnabledModules();
if (!enabledModules.equals(sortedModules)) {
enabledModules.sort(getComparator());
sortedModules = new ArrayList<>(enabledModules);

int maxWidth = 0;
// Calculate the maximum width of the module names for enabled modules only
for (Module_ m : enabledModules) {
if (!m.showInModulesList.value) continue;
String name = moduleInfo.value ? m.getNameWithInfo() : m.name;
int nameWidth = Math.round(Renderer2D.getStringWidth(name));
maxWidth = Math.max(maxWidth, nameWidth);
}
this.width = maxWidth + (sideLines.value ? 4 : 0);
}
}

Expand All @@ -295,7 +316,4 @@ public enum GlowMode {
LOW_BG_ALPHA,
NORMAL
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public void render(DrawContext drawContext, int mouseX, int mouseY, float delta)

if (HeliosClient.CLICKGUI.ScreenHelp.value) {
float fontHeight = Renderer2D.getCustomStringHeight(FontRenderers.Super_Small_fxfontRenderer);
FontRenderers.Super_Small_fxfontRenderer.drawString(drawContext.getMatrices(), "Ctrl- C/V - To Copy/Paste HudElement properties", 2, drawContext.getScaledWindowHeight() - (5 * fontHeight) - 5 * 2, -1);
FontRenderers.Super_Small_fxfontRenderer.drawString(drawContext.getMatrices(), "Left Click - Select Element", 2, drawContext.getScaledWindowHeight() - (4 * fontHeight) - 4 * 2, -1);
FontRenderers.Super_Small_fxfontRenderer.drawString(drawContext.getMatrices(), "Right Click - Open Settings", 2, drawContext.getScaledWindowHeight() - (3 * fontHeight) - 3 * 2, -1);
FontRenderers.Super_Small_fxfontRenderer.drawString(drawContext.getMatrices(), "Delete / Backspace - Remove Element", 2, drawContext.getScaledWindowHeight() - (2 * fontHeight) - 2 * 2, -1);
Expand Down

0 comments on commit 174a9eb

Please sign in to comment.