Slight HUD refactor, allow modules to depend on each other more easily
Some checks failed
/ Build BaseBand DSM & Broadway (push) Has been cancelled

This commit is contained in:
Daniella / Tove 2024-06-18 00:00:29 +02:00
parent b6b3ea61a1
commit 15852f0378
Signed by: TudbuT
GPG key ID: B3CF345217F202D3
6 changed files with 139 additions and 60 deletions

View file

@ -81,10 +81,7 @@ public class StaticEventHandler {
playerLastTick = mc.player;
KeyManager.updateKeyBinds();
for(Feature feature : Features.features) {
feature.onEveryTick();
if(feature.enabled) {
feature.onTick();
}
feature.internalOnEveryTick();
}
}
}

View file

@ -24,7 +24,7 @@ import java.awt.*;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.*;
/**
* @author TudbuT
@ -37,6 +37,7 @@ public abstract class Feature extends ToggleButton implements SetCommand {
public static final int M_ENABLED = MARKER_PREFIX + 1;
protected de.com.baseband.client.Setup Setup;
protected Set<Class<? extends Feature>> required = new HashSet<>();
protected Minecraft mc;
public Category category;
@ -49,6 +50,9 @@ public abstract class Feature extends ToggleButton implements SetCommand {
public Feature() {
super("Uninit", null, "Enabled");
this.setLambda(this::updateEnabled);
Requires requiredAnnotation = getClass().getDeclaredAnnotation(Requires.class);
if(requiredAnnotation != null)
required.addAll(Arrays.asList(requiredAnnotation.value()));
}
// feature methods
@ -268,6 +272,9 @@ public abstract class Feature extends ToggleButton implements SetCommand {
public void setEnabledSilent(boolean enable) {
if(enabled == enable)
return;
if(!enabled && !tryEnable()) {
return;
}
enabled = enable;
updateEnabled();
}
@ -279,11 +286,24 @@ public abstract class Feature extends ToggleButton implements SetCommand {
@KeyBound("Toggle")
public void toggle() {
if(!enabled && !tryEnable()) {
return;
}
enabled = !enabled;
handle.poll("Enabled");
updateEnabled();
}
protected boolean tryEnable() {
for (Class<? extends Feature> feature : required) {
if(!Features.isFeatureEnabled(feature)) {
BaseBand.notify("§c" + this + " cannot work without " + feature + ".");
return false;
}
}
return true;
}
public boolean setWithString(String setting, String value) {
if(setting.equals("Enabled") && !value.equalsIgnoreCase(String.valueOf(enabled))) {
toggle();
@ -293,6 +313,11 @@ public abstract class Feature extends ToggleButton implements SetCommand {
}
public boolean canExist() {
for (Class<? extends Feature> feature : required) {
if(!Features.isFeaturePresent(feature)) {
return false;
}
}
return true;
}
@ -314,4 +339,13 @@ public abstract class Feature extends ToggleButton implements SetCommand {
return text + (meta != null ? ChatFormatting.GRAY + " [" + meta + "]" : "");
}
}
public void internalOnEveryTick() {
if(enabled && !tryEnable())
toggle();
onEveryTick();
if(enabled) {
onTick();
}
}
}

View file

@ -8,6 +8,7 @@ import de.com.baseband.client.registry.PlayerDB;
import de.com.baseband.client.registry.annotation.Config;
import de.com.baseband.client.registry.annotation.Gate;
import de.com.baseband.client.registry.annotation.Range;
import de.com.baseband.client.registry.annotation.Requires;
import de.com.baseband.client.util.adapt.Marker;
import de.tudbut.parsing.TCN;
import de.tudbut.tools.Lock;
@ -62,6 +63,12 @@ public class AutoKill extends Feature {
@Config("PacketHit")
public boolean packetHit = false;
@Override
public void onDisable() {
Features.ifFeatureEnabled(AutoHit.class, Feature::toggle);
Features.ifFeatureEnabled(AutoCrystal.class, Feature::toggle);
}
ArrayList<EntityLivingBase> getAttackable() {
ArrayList<EntityLivingBase> allowed = new ArrayList<>();
for (Entity entity : mc.world.loadedEntityList) {
@ -182,6 +189,7 @@ public class AutoKill extends Feature {
}
@Combat
@Requires(AutoKill.class)
public class AutoHit extends Feature {
@Config("Speed (ms)")
@ -193,8 +201,6 @@ public class AutoKill extends Feature {
@Override
public void onTick() {
if(!AutoKill.this.enabled)
return;
if(notIngame())
return;
if(threaded) {
@ -213,7 +219,7 @@ public class AutoKill extends Feature {
}
private void runThread() {
while (threaded) {
while (threaded && enabled) {
if(notIngame())
break;
@ -246,6 +252,7 @@ public class AutoKill extends Feature {
}
@Combat
@Requires(AutoKill.class)
public class AutoCrystal extends Feature {
@Override

View file

@ -170,6 +170,12 @@ public class HUD extends Feature {
@Description("Where to display notifications. Left and Right display the most recent at the top, Center displays the most recent at the bottom.")
public NotificationLocation nLocation = NotificationLocation.Left;
// TODO: finish implementation
@Marker(Integer.MIN_VALUE)
@Config("Notifications like chat")
@Description("Reverses the order in which notifications are shown and shows a fixed number of notifications, in case of Left and Right location.")
public boolean revNotif = false;
@Config("Notification size X")
@Description("How wide a notification should be. The width in pixels is this multiplied by 100.")
@Range("2..6")
@ -242,40 +248,7 @@ public class HUD extends Feature {
}
if(armor) {
GlStateManager.enableTexture2D();
ScaledResolution resolution = new ScaledResolution(mc);
int i = resolution.getScaledWidth() / 2;
int iteration = 0;
int y = resolution.getScaledHeight() - 55 - (mc.player.isInWater() ? 10 : 0);
for (ItemStack is : mc.player.inventory.armorInventory) {
iteration++;
if (is.isEmpty()) continue;
int x = i - 90 + (9 - iteration) * 20 + 2;
GlStateManager.enableDepth();
itemRender.zLevel = 200F;
itemRender.renderItemAndEffectIntoGUI(is, x, y);
itemRender.renderItemOverlayIntoGUI(mc.fontRenderer, is, x, y, "");
itemRender.zLevel = 0F;
GlStateManager.enableTexture2D();
GlStateManager.disableLighting();
GlStateManager.disableDepth();
String s = is.getCount() > 1 ? is.getCount() + "" : "";
mc.fontRenderer.drawStringWithShadow(s, x + 19 - 2 - mc.fontRenderer.getStringWidth(s), y + 9, 0xffffff);
float green = ((float) is.getMaxDamage() - (float) is.getItemDamage()) / (float) is.getMaxDamage();
float red = 1 - green;
int dmg = 100 - (int) (red * 100);
mc.fontRenderer.drawStringWithShadow(dmg + "", x + 8 - mc.fontRenderer.getStringWidth(dmg + "") / 2, y - 11, toHex((int) (red * 255), (int) (green * 255), 0));
}
GlStateManager.enableDepth();
GlStateManager.disableLighting();
renderArmor();
}
String initString = "§lBaseBand§r - \"" + BaseBand.buildString + "\" @ " + GitHash.GIT_HASH;
@ -301,6 +274,32 @@ public class HUD extends Feature {
y = y + mc.fontRenderer.FONT_HEIGHT;
}
if(infoLoc != InfoLocation.TopLeft) {
int x;
y = 3;
switch (infoLoc) {
case BottomRight:
y = sr.getScaledHeight() - 3 - TextSplitter.getStringHeight(infoString);
case TopRight:
x = sr.getScaledWidth() - 3 - TextSplitter.getStringWidth(infoString);
break;
default:
throw new IllegalStateException();
}
if(background) {
drawSizedBox(x - 1, y - 1, TextSplitter.getStringWidth(infoString) + 2, TextSplitter.getStringHeight(infoString) + 2, Pixels.mulTransparency(theme.getBackgroundColor(), 0.5f), false);
}
TextSplitter.drawString(infoString, x, y, theme.getGreenColor(), textShadow, textMatchOrientation);
y += TextSplitter.getStringHeight(infoString);
}
renderNotifications(sr, y);
}
// TODO: rewrite asap
private void renderNotifications(ScaledResolution sr, int y) {
int dir = (nLocation == NotificationLocation.Center ? -1 : 1);
int isCenter = (nLocation == NotificationLocation.Center ? 1 : 0);
int xSize = this.nSize * 100;
@ -312,7 +311,8 @@ public class HUD extends Feature {
y = sr.getScaledHeight() / 4;
} else {
if(nLocation == NotificationLocation.Right) {
y = -5;
if(!(showInfo && infoLoc == InfoLocation.TopRight))
y = -5;
x = sr.getScaledWidth() - x - xSize;
}
y += 5;
@ -320,7 +320,12 @@ public class HUD extends Feature {
}
Notification[] notifs = HUD.notifs.toArray(new Notification[0]);
for (int i = notifs.length - 1; i >= 0; i--) {
int i;
if(revNotif)
i = 0;
else
i = notifs.length - 1;
while (i >= 0 && i < notifs.length) {
Notification notif = notifs[i];
int localYSize = ySize;
@ -335,24 +340,45 @@ public class HUD extends Feature {
TextSplitter.drawString(text, x + textOffset, y + textOffset - isCenter * textboxYSize, 0xffffff + (Math.max(8, notif.opacity(0xff, 2)) << 24), notif.opacity(2) == 1.0 && textShadow, false);
GlStateManager.disableBlend();
y += (localYSize + nVSpace) * dir;
i += revNotif ? 1 : -1;
}
}
private void renderArmor() {
GlStateManager.enableTexture2D();
ScaledResolution resolution = new ScaledResolution(mc);
int i = resolution.getScaledWidth() / 2;
int iteration = 0;
int y = resolution.getScaledHeight() - 55 - (mc.player.isInWater() ? 10 : 0);
for (ItemStack is : mc.player.inventory.armorInventory) {
iteration++;
if (is.isEmpty()) continue;
int x = i - 90 + (9 - iteration) * 20 + 2;
GlStateManager.enableDepth();
itemRender.zLevel = 200F;
itemRender.renderItemAndEffectIntoGUI(is, x, y);
itemRender.renderItemOverlayIntoGUI(mc.fontRenderer, is, x, y, "");
itemRender.zLevel = 0F;
GlStateManager.enableTexture2D();
GlStateManager.disableLighting();
GlStateManager.disableDepth();
String s = is.getCount() > 1 ? is.getCount() + "" : "";
mc.fontRenderer.drawStringWithShadow(s, x + 19 - 2 - mc.fontRenderer.getStringWidth(s), y + 9, 0xffffff);
float green = ((float) is.getMaxDamage() - (float) is.getItemDamage()) / (float) is.getMaxDamage();
float red = 1 - green;
int dmg = 100 - (int) (red * 100);
mc.fontRenderer.drawStringWithShadow(dmg + "", x + 8 - (float) mc.fontRenderer.getStringWidth(String.valueOf(dmg)) / 2, y - 11, toHex((int) (red * 255), (int) (green * 255), 0));
}
if(infoLoc != InfoLocation.TopLeft) {
y = 3;
switch (infoLoc) {
case BottomRight:
y = sr.getScaledHeight() - 3 - TextSplitter.getStringHeight(infoString);
case TopRight:
x = sr.getScaledWidth() - 3 - TextSplitter.getStringWidth(infoString);
break;
}
if(background) {
drawSizedBox(x - 1, y - 1, TextSplitter.getStringWidth(infoString) + 2, TextSplitter.getStringHeight(infoString) + 2, Pixels.mulTransparency(theme.getBackgroundColor(), 0.5f), false);
}
TextSplitter.drawString(infoString, x, y, theme.getGreenColor(), textShadow, textMatchOrientation);
}
GlStateManager.enableDepth();
GlStateManager.disableLighting();
}
public static int toHex(final int r, final int g, final int b) {

View file

@ -0,0 +1,14 @@
package de.com.baseband.client.registry.annotation;
import de.com.baseband.client.feature.Feature;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Requires {
Class<? extends Feature>[] value();
}

1
Website Submodule

@ -0,0 +1 @@
Subproject commit b3c3895b1349ba7bae90968970d8889195e8127e