add sections, fix notification rendering being off by one
All checks were successful
/ Build BaseBand DSM & Broadway (push) Successful in 2m13s

This commit is contained in:
Daniella / Tove 2024-06-18 18:39:40 +02:00
parent 9f220acd74
commit 863568cd48
Signed by: TudbuT
GPG key ID: B3CF345217F202D3
6 changed files with 140 additions and 97 deletions

View file

@ -118,19 +118,29 @@ public abstract class Feature extends ToggleButton implements SetCommand {
subComponents.clear();
HashMap<String, ArrayList<Component>> sections = new HashMap<>();
ConfigHandle settings = config("Settings");
Field[] fields = getClass().getFields();
for (Field f : fields) {
Config config = f.getDeclaredAnnotation(Config.class);
KeyBound keyBound = f.getDeclaredAnnotation(KeyBound.class);
Description descriptionAnnotation = f.getDeclaredAnnotation(Description.class);
Section section = f.getDeclaredAnnotation(Section.class);
String path = "";
if(section != null && !sections.containsKey(section.value())) {
ArrayList<Component> comps = new ArrayList<>();
sections.put(section.value(), comps);
subComponents.add(new Component(section.value(), comps, true));
path = section.value() + "/";
}
String description = descriptionAnnotation == null ? null : descriptionAnnotation.value();
AnyGate gate = AnyGate.get(f, this);
if (config != null) {
Configuration.registerUpdater(settings.linkWith(this, f).name(config.value()));
Configuration.registerUpdater(settings.linkWith(this, f).name(path + config.value()));
if (f.getType() == boolean.class) {
Component btn = new ToggleButton(config.value(), settings, config.value()).gate(gate).hover(description);
subComponents.add(btn);
Component btn = new ToggleButton(config.value(), settings, path + config.value()).gate(gate).hover(description);
addComponent(sections, section, btn);
if(keyBound != null) {
String keyBindString = "Toggle ";
if(!keyBound.value().isEmpty())
@ -142,8 +152,9 @@ public abstract class Feature extends ToggleButton implements SetCommand {
btn.click(0, 0, 0);
BaseBand.notify("Toggled " + config.value() + " in " + this + " " + (btn.green ? "§aon" : "§coff"));
}, gate);
subComponents.add(new KeyButton(keyBindString, settings, keyBindConfig).gate(AnyGate.get(f, this, null, keyBound.allowChangeGate())).hover(description));
Configuration.registerUpdater(settings.linkWith(keyBind, KeyBind.KEY_FIELD).name(keyBindConfig));
Component kbtn = new KeyButton(keyBindString, settings, path + keyBindConfig).gate(AnyGate.get(f, this, null, keyBound.allowChangeGate())).hover(description);
addComponent(sections, section, kbtn);
Configuration.registerUpdater(settings.linkWith(keyBind, KeyBind.KEY_FIELD).name(path + keyBindConfig));
KeyManager.registerKeyBind(keyBind);
}
}
@ -155,7 +166,7 @@ public abstract class Feature extends ToggleButton implements SetCommand {
int min = Integer.parseInt(r[0]);
int max = Integer.parseInt(r[1]);
int step = rStep.length == 1 ? 1 : Integer.parseInt(rStep[1]);
subComponents.add(new IntSlider(config.value(), settings, config.value(), Object::toString, max - min, min, step).gate(gate).hover(description));
addComponent(sections, section, new IntSlider(config.value(), settings, path + config.value(), Object::toString, max - min, min, step).gate(gate).hover(description));
} else {
throw new RuntimeException("No range specified for slider");
}
@ -168,16 +179,16 @@ public abstract class Feature extends ToggleButton implements SetCommand {
float min = Float.parseFloat(r[0]);
float max = Float.parseFloat(r[1]);
float step = rStep.length == 1 ? 1f : Float.parseFloat(rStep[1]);
subComponents.add(new Slider(config.value(), settings, config.value(), n -> String.valueOf(Math.round(n * 100) / 100f), max - min, min, step).gate(gate).hover(description));
addComponent(sections, section, new Slider(config.value(), settings, path + config.value(), n -> String.valueOf(Math.round(n * 100) / 100f), max - min, min, step).gate(gate).hover(description));
} else {
throw new RuntimeException("No range specified for slider");
}
}
if (f.getType() == String.class) {
subComponents.add(new StringButton(config.value(), settings, config.value()).gate(gate).hover(description));
addComponent(sections, section, new StringButton(config.value(), settings, path + config.value()).gate(gate).hover(description));
}
if(f.getType().isEnum()) {
subComponents.add(new EnumButton((Class<? extends Enum<?>>) f.getType(), config.value(), settings, config.value()).gate(gate).hover(description));
addComponent(sections, section, new EnumButton((Class<? extends Enum<?>>) f.getType(), config.value(), settings, path + config.value()).gate(gate).hover(description));
}
}
}
@ -187,10 +198,18 @@ public abstract class Feature extends ToggleButton implements SetCommand {
KeyBound keyBound = m.getDeclaredAnnotation(KeyBound.class);
String keyBindString = null;
Description descriptionAnnotation = m.getDeclaredAnnotation(Description.class);
Section section = m.getDeclaredAnnotation(Section.class);
String path = "";
if(section != null && !sections.containsKey(section.value())) {
ArrayList<Component> comps = new ArrayList<>();
sections.put(section.value(), comps);
subComponents.add(new Component(section.value(), comps, true));
path = section.value() + "/";
}
String description = descriptionAnnotation == null ? null : descriptionAnnotation.value();
AnyGate gate = AnyGate.get(m, this);
if (trigger != null) {
subComponents.add(new Button(trigger.value(), btn -> {
addComponent(sections, section, new Button(trigger.value(), btn -> {
try {
m.invoke(this);
} catch (IllegalAccessException e) {
@ -218,8 +237,8 @@ public abstract class Feature extends ToggleButton implements SetCommand {
throw new RuntimeException(e);
}
}, gate);
subComponents.add(new KeyButton(keyBindString, settings, keyBindConfig).gate(AnyGate.get(m, this, null, keyBound.allowChangeGate())).hover(description));
Configuration.registerUpdater(settings.linkWith(keyBind, KeyBind.KEY_FIELD).name(keyBindConfig));
addComponent(sections, section, new KeyButton(keyBindString, settings, path + keyBindConfig).gate(AnyGate.get(m, this, null, keyBound.allowChangeGate())).hover(description));
Configuration.registerUpdater(settings.linkWith(keyBind, KeyBind.KEY_FIELD).name(path + keyBindConfig));
KeyManager.registerKeyBind(keyBind);
}
}
@ -235,6 +254,13 @@ public abstract class Feature extends ToggleButton implements SetCommand {
updateEnabled();
}
private void addComponent(HashMap<String, ArrayList<Component>> sections, Section section, Component btn) {
if(section == null)
subComponents.add(btn);
else
sections.get(section.value()).add(btn);
}
protected boolean notIngame() {
if (mc == null) {
throw new RuntimeException();

View file

@ -64,52 +64,7 @@ public class HUD extends Feature {
BottomRight,
}
@Config("Show information section")
@Description("Shows information about the player and server on the HUD.")
@Marker(1)
public boolean showInfo = true;
@Config("Show coordinates")
@Description("Shows the player's coordinates on the HUD.")
@Gate(1)
public boolean showCoords = true;
@Config("Show server ping")
@Description("Shows the server ping and player count on the HUD.")
@Gate(1)
public boolean showPing = true;
@Config("Show Spotify")
@Description("Shows the currently playing song of a locally running Spotify Instance.")
@Gate(1)
public boolean showSpotify = true;
@Config("Server Ping Jitter")
@Description("Makes your ping jitter up and down to make it seem more responsive.")
@Gate(1)
@Marker(2)
public boolean pingJitter = false;
@Config("Server Ping Jitter Amount")
@Description("See the above setting.")
@Gate(2)
@Range("0..10")
public int pingJitterAmount;
@Config("Show server TPS")
@Description("Shows the server TPS count on the HUD.")
@Gate(1)
public boolean showTPS = true;
@Config("Info location")
@Description("Where coordinates, ping, etc should be displayed")
@Gate(1)
public InfoLocation infoLoc = InfoLocation.BottomRight;
@Config("Match info text orientation")
@Description("If the Info location is on the right, makes the text right-bound.")
@Gate(1)
public boolean textMatchOrientation = true;
private final String C_INFO = "Information", C_NOTIF = "Notifications";
@Config("Include status in length")
@Description("By default, status (greyed out information tucked on the end of module names) is not factored into the sorting. This setting lets you change that.")
@ -131,37 +86,107 @@ public class HUD extends Feature {
@Config("Armor HUD")
public boolean armor = true;
@Config("Notification location")
@Section(C_INFO)
@Config("Show information section")
@Description("Shows information about the player and server on the HUD.")
@Marker(1)
public boolean showInfo = true;
@Section(C_INFO)
@Config("Show coordinates")
@Description("Shows the player's coordinates on the HUD.")
@Gate(1)
public boolean showCoords = true;
@Section(C_INFO)
@Config("Show server ping")
@Description("Shows the server ping and player count on the HUD.")
@Gate(1)
public boolean showPing = true;
@Section(C_INFO)
@Config("Server Ping Jitter")
@Description("Makes your ping jitter up and down to make it seem more responsive.")
@Gate(1)
@Marker(2)
public boolean pingJitter = false;
@Section(C_INFO)
@Config("Server Ping Jitter Amount")
@Description("See the above setting.")
@Gate(2)
@Range("0..10")
public int pingJitterAmount;
@Section(C_INFO)
@Config("Show server TPS")
@Description("Shows the server TPS count on the HUD.")
@Gate(1)
public boolean showTPS = true;
@Section(C_INFO)
@Config("Show Spotify")
@Description("Shows the currently playing song of a locally running Spotify Instance.")
@Gate(1)
public boolean showSpotify = true;
@Section(C_INFO)
@Config("Location")
@Description("Where coordinates, ping, etc should be displayed")
@Gate(1)
public InfoLocation infoLoc = InfoLocation.BottomRight;
@Section(C_INFO)
@Config("Match text orientation")
@Description("If the Info location is on the right, makes the text right-bound.")
@Gate(1)
public boolean textMatchOrientation = true;
@Section(C_NOTIF)
@Config("Location")
@Description("Where to display notifications. Left and Right display the most recent at the top, Center displays the most recent at the bottom.")
public NotificationRender.NotificationLocation nLocation = NotificationRender.NotificationLocation.Left;
@Config("Notifications like chat")
@Section(C_NOTIF)
@Config("Chat-like height")
@Description("Shows the notifications in the same way the chat is shown, with a given 'chat height'")
@Range("0..30")
public int chatLikeNotif = 0;
@Config("Notification size X")
@Section(C_NOTIF)
@Config("Size X")
@Description("How wide a notification should be. The width in pixels is this multiplied by 100.")
@Range("2..6")
public int nSize = 2;
@Config("Notification size Y")
@Section(C_NOTIF)
@Config("Size Y")
@Description("How much height a notification should have. This is auto-adjusted for multi-line notifications.\n" +
"1 is one line of text only, 2 is half a line of padding on both sides (for a total of 2 lines), 3 is one line of padding, etc.")
@Range("1..4")
public int nVSize = 1;
@Config("Notification spacing")
@Section(C_NOTIF)
@Config("Spacing")
@Description("How many pixels of space to leave between notifications.")
@Range("0..20")
public int nVSpace = 1;
@Section(C_NOTIF)
@Trigger("Test!")
@Description("Click to test your notification rendering settings.")
public void testBtn() {
notify("Test! " + System.currentTimeMillis());
}
@Section(C_NOTIF)
@Trigger("Test long!")
@Description("Click to test your notification rendering settings with a long notification.")
public void test2Btn() {
notify("Test2! a a a a a a a a a a a a a a a a a a a a a a a a a a a " + System.currentTimeMillis());
}
@Override
public String toString() {
return "HUD";
@ -340,13 +365,6 @@ public class HUD extends Feature {
return s;
}
@Override
protected void setup() {
if(Features.isFeaturePresent(ShowTPS.class)) {
subComponents.add(Features.getFeature(ShowTPS.class));
}
}
public int getColor(Feature feature, int featureIndex) {
switch (moduleColor) {
case Normal:
@ -361,6 +379,7 @@ public class HUD extends Feature {
}
}
// TODO: rewrite
private int getCuteColor(int index) {
int size = (int) Arrays.stream(Features.features).filter(m -> m.enabled && m.displayOnHUD()).count();
@ -387,23 +406,4 @@ public class HUD extends Feature {
return light_blue; //fail
}
@Render
public static class ShowTPS extends Feature {
@Override
public boolean displayOnClickGUI() {
return false;
}
@Override
public void onTick() {
meta = "TPS: " + (Math.round(ServerDataManager.tps * 100f) / 100f);
}
@Override
public String toString() {
return "ShowTPS";
}
}
}

View file

@ -4,8 +4,6 @@ public class Button extends Component {
private final ClickEvent event;
{green = true;}
public Button(String s, ClickEvent event) {
this.text = s;
this.event = event;

View file

@ -20,7 +20,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
public abstract class Component {
public class Component {
@Marker(Integer.MIN_VALUE)
static final boolean FALSE = false;
@ -32,10 +32,10 @@ public abstract class Component {
private AnyGate visibilityGate = null;
final FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer;
public final ArrayList<Component> subComponents = new ArrayList<>();
public final ArrayList<Component> subComponents;
public String text = "";
public String hover = null;
public boolean green = false;
public boolean green = true;
@Config("GUI/Expanded")
@Marker(M_GUI_EXPANDED)
@ -61,6 +61,16 @@ public abstract class Component {
}
}
public Component() {
this.subComponents = new ArrayList<>();
}
public Component(String name, ArrayList<Component> subComponents, boolean subComponentsShown) {
this.text = name;
this.subComponents = subComponents;
this.subComponentsShown = subComponentsShown;
}
public void render(int x, AtomicInteger y, int sub, boolean isLastInList) throws RenderException {
try {
loc = new Point(x + 8 + sub * 8, y.get());

View file

@ -0,0 +1,9 @@
package de.com.baseband.client.registry.annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
public @interface Section {
String value();
}

View file

@ -32,7 +32,7 @@ public class NotificationRender {
this.chatLikeSize = chatLikeSize;
this.textShadow = textShadow;
padding = (ySize / 2 - (mc.fontRenderer.FONT_HEIGHT / 2));
padding = (int) (ySize / 2f - (mc.fontRenderer.FONT_HEIGHT / 2f));
}
public void begin(int y) {
@ -55,7 +55,7 @@ public class NotificationRender {
throw new IllegalStateException("NotificationLocation " + nLocation.ordinal() + " not implemented");
}
this.startY = this.y;
this.y += (ySize + ySpace) * chatLikeSize;
this.y += (ySize + ySpace) * chatLikeSize + ySpace;
this.endY = this.y;
}
@ -67,7 +67,7 @@ public class NotificationRender {
String s = notif.text;
s = TextSplitter.breakText(s, xSize - padding * 2);
int ys = TextSplitter.getStringHeight(s) + padding * 2;
int ys = TextSplitter.getStringHeight(s) + 1 + padding * 2;
ys = notif.opacity(ys, 1);
if(chatLike) {