Skip to content

Commit

Permalink
ModuleList meteor rainbow. And some changes to settings
Browse files Browse the repository at this point in the history
  • Loading branch information
tanishisherewithhh committed Apr 27, 2024
1 parent affdfef commit 0653c53
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 14 deletions.
110 changes: 100 additions & 10 deletions src/main/java/dev/heliosclient/hud/hudelements/ModuleList.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,102 @@
import dev.heliosclient.managers.EventManager;
import dev.heliosclient.managers.ModuleManager;
import dev.heliosclient.module.Module_;
import dev.heliosclient.util.ColorUtils;
import dev.heliosclient.util.TimerUtils;
import dev.heliosclient.module.settings.CycleSetting;
import dev.heliosclient.module.settings.DoubleSetting;
import dev.heliosclient.module.settings.SettingGroup;
import dev.heliosclient.util.render.Renderer2D;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;

import java.awt.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import static dev.heliosclient.hud.hudelements.ModuleList.ColorMode.METEOR;
import static dev.heliosclient.hud.hudelements.ModuleList.Sort.*;

/**
* Color credits: <a href="https://github.com/MeteorDevelopment/meteor-client/">Meteor-Client</a>
*/
public class ModuleList extends HudElement implements Listener {

private ArrayList<Module_> enabledModules = ModuleManager.INSTANCE.getEnabledModules();
private Color rainbow = new Color(255, 255, 255);
private double rainbowHue1;
private double rainbowHue2;

public SettingGroup sgSettings = new SettingGroup("Settings");

private final CycleSetting sort = sgSettings.add(new CycleSetting.Builder()
.name("Sort")
.description("Sorting method used for displaying modules")
.value(List.of(Sort.values()))
.onSettingChange(this)
.defaultListOption(Biggest)
.build()
);
private final CycleSetting colorMode = sgSettings.add(new CycleSetting.Builder()
.name("Color Mode")
.description("Mode of the color displayed")
.value(List.of(ColorMode.values()))
.onSettingChange(this)
.defaultListOption(METEOR)
.build()
);

private final DoubleSetting rainbowSpeed = sgSettings.add(new DoubleSetting.Builder()
.name("Rainbow Speed")
.description("Speed of rainbow")
.onSettingChange(this)
.min(0.001d)
.max(0.2d)
.roundingPlace(3)
.value(0.05d)
.shouldRender(()-> (ColorMode) colorMode.getOption() == METEOR)
.build()
);
private final DoubleSetting rainbowSpread = sgSettings.add(new DoubleSetting.Builder()
.name("Rainbow Spread")
.description("Spread of rainbow")
.onSettingChange(this)
.min(0.001f)
.max(0.05f)
.roundingPlace(3)
.value(0.1d)
.shouldRender(()-> (ColorMode) colorMode.getOption() == METEOR)
.build()
);
private final DoubleSetting rainbowSaturation = sgSettings.add(new DoubleSetting.Builder()
.name("Rainbow Saturation")
.description("Saturation of rainbow")
.onSettingChange(this)
.min(0.0)
.max(1d)
.roundingPlace(2)
.value(1d)
.defaultValue(1d)
.shouldRender(()-> (ColorMode) colorMode.getOption() == METEOR)
.build()
);
private final DoubleSetting rainbowBrightness = sgSettings.add(new DoubleSetting.Builder()
.name("Rainbow Brightness")
.description("Brightness of rainbow")
.onSettingChange(this)
.min(0.0)
.max(1d)
.roundingPlace(2)
.value(1d)
.defaultValue(1d)
.shouldRender(()-> (ColorMode) colorMode.getOption() == METEOR)
.build()
);

public ModuleList() {
super(DATA);
this.width = 50;
EventManager.register(this);
addSettingGroup(sgSettings);
}

public static HudElementData<ModuleList> DATA = new HudElementData<>("Module List", "Shows enabled modules", ModuleList::new);
Expand All @@ -46,11 +119,13 @@ public void renderElement(DrawContext drawContext, TextRenderer textRenderer) {
int nameWidth = Math.round(Renderer2D.getStringWidth(m.name));
maxWidth = Math.max(maxWidth, nameWidth);
}
rainbowHue1 += 0.01f * mc.getTickDelta();
if (rainbowHue1 > 1) rainbowHue1 -= 1;
else if (rainbowHue1 < -1) rainbowHue1 += 1;
if(colorMode.getOption() == METEOR) {
rainbowHue1 += rainbowSpeed.value * mc.getTickDelta();
if (rainbowHue1 > 1) rainbowHue1 -= 1;
else if (rainbowHue1 < -1) rainbowHue1 += 1;

rainbowHue2 = rainbowHue1;
rainbowHue2 = rainbowHue1;
}

// Render each module with a different color
this.width = maxWidth + 5;
Expand All @@ -70,8 +145,10 @@ public void renderElement(DrawContext drawContext, TextRenderer textRenderer) {
x - 2 + width, yOffset, 2,
Math.round(Renderer2D.getStringHeight()) + 3, HeliosClient.uiColor);

rainbowHue2 += 2f;
rainbow = new Color(Color.HSBtoRGB((float) rainbowHue2, 1f, 1f));
if(colorMode.getOption() == METEOR) {
rainbowHue2 += rainbowSpread.value;
rainbow = new Color(Color.HSBtoRGB((float) rainbowHue2, (float) rainbowSaturation.value, (float) rainbowBrightness.value));
}
// Draw the module name
Renderer2D.drawString(drawContext.getMatrices(), m.name,
x - 4 + width - nameWidth, 1 + yOffset,
Expand All @@ -85,6 +162,19 @@ public void renderElement(DrawContext drawContext, TextRenderer textRenderer) {
@SubscribeEvent
public void update(TickEvent.CLIENT event) {
enabledModules = ModuleManager.INSTANCE.getEnabledModules();
enabledModules.sort(Comparator.comparing(module -> Renderer2D.getStringWidth(module.name), Comparator.reverseOrder()));
enabledModules.sort((mod1, mod2) -> switch ((Sort)sort.getOption()) {
case Alphabetical -> mod1.name.compareTo(mod2.name);
case Biggest -> Double.compare( Renderer2D.getStringWidth(mod2.name), Renderer2D.getStringWidth(mod1.name));
case Smallest -> Double.compare(Renderer2D.getStringWidth(mod1.name), Renderer2D.getStringWidth(mod2.name));
});
}

public enum Sort {
Alphabetical,
Biggest,
Smallest
}
public enum ColorMode {
METEOR
}
}
15 changes: 14 additions & 1 deletion src/main/java/dev/heliosclient/module/settings/CycleSetting.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ public void loadFromToml(Map<String, Object> MAP, Toml toml) {
return;
}
}
LOGGER.error("Option not found for: " + mapGet + ", " + name + " Setting during loading config: " + Config.MODULES);
LOGGER.error("Option not found for: {}, {} Setting during loading config: {}", mapGet, name, Config.MODULES);
}

public Object getOption() {
return options.get(value);
}

public static class Builder extends SettingBuilder<Builder, List<?>, CycleSetting> {
Expand All @@ -172,6 +176,15 @@ public Builder defaultListIndex(int defaultListIndex) {
this.defaultListIndex = defaultListIndex;
return this;
}
public Builder defaultListOption(Object o) {
if(value == null){
throw new NullPointerException("Option List is null, could not add default option");
}
if(value.contains(o)) {
this.defaultListIndex = value.indexOf(o);
}
return this;
}

/**
* Option order should be corresponding to value list order
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import dev.heliosclient.util.interfaces.ISettingChange;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.util.math.MathHelper;
import org.lwjgl.glfw.GLFW;

import java.awt.*;
Expand Down Expand Up @@ -44,17 +45,20 @@ public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY
int defaultColor = ColorManager.INSTANCE.defaultTextColor();

Renderer2D.drawFixedString(drawContext.getMatrices(), name, x + 2, y + 2, defaultColor);
//I dont understand these calculations.
double diff = Math.min(100, Math.max(0, (mouseX - x) / 1.9));

if (sliding) {
if (diff == 0) {
if (diff <= 0) {
value = min;
} else {
value = MathUtils.round(((diff / 100) * (max - min) + min), roundingPlace);
}
iSettingChange.onSettingChange(this);
}

value = MathHelper.clamp(value,min,max);

float valueWidth = Renderer2D.getFxStringWidth(value + ".00") + 3;

inputBox.render(drawContext, (x + 180) - Math.round(valueWidth), y + 2, mouseX, mouseY, textRenderer);
Expand Down Expand Up @@ -91,14 +95,14 @@ public void renderCompact(DrawContext drawContext, int x, int y, int mouseX, int
double diff = Math.min(moduleWidth - 10, Math.max(0, (mouseX - x)));

if (sliding) {
if (diff == 0) {
if (diff <= 0) {
value = min;
} else {
value = MathUtils.round(((diff / (moduleWidth - 10)) * (max - min) + min), roundingPlace);
}
iSettingChange.onSettingChange(this);
}

value = MathHelper.clamp(value,min,max);
String valueString = "" + MathUtils.round(value, roundingPlace);
FontRenderers.Small_fxfontRenderer.drawString(drawContext.getMatrices(), valueString, (x + moduleWidth - 10) - FontRenderers.Small_fxfontRenderer.getStringWidth(valueString), y + 2, ColorManager.INSTANCE.defaultTextColor());
Renderer2D.drawRoundedRectangle(drawContext.getMatrices().peek().getPositionMatrix(), x + 2, y + 16, moduleWidth - 8, 2, 1, 0xFFAAAAAA);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package dev.heliosclient.module.settings;

import com.google.common.base.Enums;
import com.moandjiezana.toml.Toml;
import de.javagl.obj.Obj;
import dev.heliosclient.managers.ColorManager;
import dev.heliosclient.ui.clickgui.ClickGUIScreen;
import dev.heliosclient.ui.clickgui.ListSettingScreen;
import dev.heliosclient.util.render.Renderer2D;
import it.unimi.dsi.fastutil.Arrays;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
Expand All @@ -15,6 +18,7 @@
import java.util.Map;
import java.util.function.BooleanSupplier;

@Deprecated
public class ListSetting extends Setting<ArrayList<String>> {
public ArrayList<String> options;
Screen parentScreen;
Expand Down Expand Up @@ -85,6 +89,7 @@ public Builder options(ArrayList<String> options) {
return this;
}


@Override
public ListSetting build() {
return new ListSetting(name, description, options, value, shouldRender, defaultValue);
Expand Down

0 comments on commit 0653c53

Please sign in to comment.