Slight HUD refactor, allow modules to depend on each other more easily
Some checks failed
/ Build BaseBand DSM & Broadway (push) Has been cancelled
Some checks failed
/ Build BaseBand DSM & Broadway (push) Has been cancelled
This commit is contained in:
parent
b6b3ea61a1
commit
15852f0378
6 changed files with 139 additions and 60 deletions
|
@ -81,10 +81,7 @@ public class StaticEventHandler {
|
||||||
playerLastTick = mc.player;
|
playerLastTick = mc.player;
|
||||||
KeyManager.updateKeyBinds();
|
KeyManager.updateKeyBinds();
|
||||||
for(Feature feature : Features.features) {
|
for(Feature feature : Features.features) {
|
||||||
feature.onEveryTick();
|
feature.internalOnEveryTick();
|
||||||
if(feature.enabled) {
|
|
||||||
feature.onTick();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ import java.awt.*;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author TudbuT
|
* @author TudbuT
|
||||||
|
@ -37,6 +37,7 @@ public abstract class Feature extends ToggleButton implements SetCommand {
|
||||||
public static final int M_ENABLED = MARKER_PREFIX + 1;
|
public static final int M_ENABLED = MARKER_PREFIX + 1;
|
||||||
|
|
||||||
protected de.com.baseband.client.Setup Setup;
|
protected de.com.baseband.client.Setup Setup;
|
||||||
|
protected Set<Class<? extends Feature>> required = new HashSet<>();
|
||||||
protected Minecraft mc;
|
protected Minecraft mc;
|
||||||
|
|
||||||
public Category category;
|
public Category category;
|
||||||
|
@ -49,6 +50,9 @@ public abstract class Feature extends ToggleButton implements SetCommand {
|
||||||
public Feature() {
|
public Feature() {
|
||||||
super("Uninit", null, "Enabled");
|
super("Uninit", null, "Enabled");
|
||||||
this.setLambda(this::updateEnabled);
|
this.setLambda(this::updateEnabled);
|
||||||
|
Requires requiredAnnotation = getClass().getDeclaredAnnotation(Requires.class);
|
||||||
|
if(requiredAnnotation != null)
|
||||||
|
required.addAll(Arrays.asList(requiredAnnotation.value()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// feature methods
|
// feature methods
|
||||||
|
@ -268,6 +272,9 @@ public abstract class Feature extends ToggleButton implements SetCommand {
|
||||||
public void setEnabledSilent(boolean enable) {
|
public void setEnabledSilent(boolean enable) {
|
||||||
if(enabled == enable)
|
if(enabled == enable)
|
||||||
return;
|
return;
|
||||||
|
if(!enabled && !tryEnable()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
enabled = enable;
|
enabled = enable;
|
||||||
updateEnabled();
|
updateEnabled();
|
||||||
}
|
}
|
||||||
|
@ -279,11 +286,24 @@ public abstract class Feature extends ToggleButton implements SetCommand {
|
||||||
|
|
||||||
@KeyBound("Toggle")
|
@KeyBound("Toggle")
|
||||||
public void toggle() {
|
public void toggle() {
|
||||||
|
if(!enabled && !tryEnable()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
enabled = !enabled;
|
enabled = !enabled;
|
||||||
handle.poll("Enabled");
|
handle.poll("Enabled");
|
||||||
updateEnabled();
|
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) {
|
public boolean setWithString(String setting, String value) {
|
||||||
if(setting.equals("Enabled") && !value.equalsIgnoreCase(String.valueOf(enabled))) {
|
if(setting.equals("Enabled") && !value.equalsIgnoreCase(String.valueOf(enabled))) {
|
||||||
toggle();
|
toggle();
|
||||||
|
@ -293,6 +313,11 @@ public abstract class Feature extends ToggleButton implements SetCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canExist() {
|
public boolean canExist() {
|
||||||
|
for (Class<? extends Feature> feature : required) {
|
||||||
|
if(!Features.isFeaturePresent(feature)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -314,4 +339,13 @@ public abstract class Feature extends ToggleButton implements SetCommand {
|
||||||
return text + (meta != null ? ChatFormatting.GRAY + " [" + meta + "]" : "");
|
return text + (meta != null ? ChatFormatting.GRAY + " [" + meta + "]" : "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void internalOnEveryTick() {
|
||||||
|
if(enabled && !tryEnable())
|
||||||
|
toggle();
|
||||||
|
onEveryTick();
|
||||||
|
if(enabled) {
|
||||||
|
onTick();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.Config;
|
||||||
import de.com.baseband.client.registry.annotation.Gate;
|
import de.com.baseband.client.registry.annotation.Gate;
|
||||||
import de.com.baseband.client.registry.annotation.Range;
|
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.com.baseband.client.util.adapt.Marker;
|
||||||
import de.tudbut.parsing.TCN;
|
import de.tudbut.parsing.TCN;
|
||||||
import de.tudbut.tools.Lock;
|
import de.tudbut.tools.Lock;
|
||||||
|
@ -62,6 +63,12 @@ public class AutoKill extends Feature {
|
||||||
@Config("PacketHit")
|
@Config("PacketHit")
|
||||||
public boolean packetHit = false;
|
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> getAttackable() {
|
||||||
ArrayList<EntityLivingBase> allowed = new ArrayList<>();
|
ArrayList<EntityLivingBase> allowed = new ArrayList<>();
|
||||||
for (Entity entity : mc.world.loadedEntityList) {
|
for (Entity entity : mc.world.loadedEntityList) {
|
||||||
|
@ -182,6 +189,7 @@ public class AutoKill extends Feature {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Combat
|
@Combat
|
||||||
|
@Requires(AutoKill.class)
|
||||||
public class AutoHit extends Feature {
|
public class AutoHit extends Feature {
|
||||||
|
|
||||||
@Config("Speed (ms)")
|
@Config("Speed (ms)")
|
||||||
|
@ -193,8 +201,6 @@ public class AutoKill extends Feature {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTick() {
|
public void onTick() {
|
||||||
if(!AutoKill.this.enabled)
|
|
||||||
return;
|
|
||||||
if(notIngame())
|
if(notIngame())
|
||||||
return;
|
return;
|
||||||
if(threaded) {
|
if(threaded) {
|
||||||
|
@ -213,7 +219,7 @@ public class AutoKill extends Feature {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runThread() {
|
private void runThread() {
|
||||||
while (threaded) {
|
while (threaded && enabled) {
|
||||||
if(notIngame())
|
if(notIngame())
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -246,6 +252,7 @@ public class AutoKill extends Feature {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Combat
|
@Combat
|
||||||
|
@Requires(AutoKill.class)
|
||||||
public class AutoCrystal extends Feature {
|
public class AutoCrystal extends Feature {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -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.")
|
@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;
|
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")
|
@Config("Notification size X")
|
||||||
@Description("How wide a notification should be. The width in pixels is this multiplied by 100.")
|
@Description("How wide a notification should be. The width in pixels is this multiplied by 100.")
|
||||||
@Range("2..6")
|
@Range("2..6")
|
||||||
|
@ -242,40 +248,7 @@ public class HUD extends Feature {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(armor) {
|
if(armor) {
|
||||||
GlStateManager.enableTexture2D();
|
renderArmor();
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String initString = "§lBaseBand§r - \"" + BaseBand.buildString + "\" @ " + GitHash.GIT_HASH;
|
String initString = "§lBaseBand§r - \"" + BaseBand.buildString + "\" @ " + GitHash.GIT_HASH;
|
||||||
|
@ -301,6 +274,32 @@ public class HUD extends Feature {
|
||||||
y = y + mc.fontRenderer.FONT_HEIGHT;
|
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 dir = (nLocation == NotificationLocation.Center ? -1 : 1);
|
||||||
int isCenter = (nLocation == NotificationLocation.Center ? 1 : 0);
|
int isCenter = (nLocation == NotificationLocation.Center ? 1 : 0);
|
||||||
int xSize = this.nSize * 100;
|
int xSize = this.nSize * 100;
|
||||||
|
@ -312,7 +311,8 @@ public class HUD extends Feature {
|
||||||
y = sr.getScaledHeight() / 4;
|
y = sr.getScaledHeight() / 4;
|
||||||
} else {
|
} else {
|
||||||
if(nLocation == NotificationLocation.Right) {
|
if(nLocation == NotificationLocation.Right) {
|
||||||
y = -5;
|
if(!(showInfo && infoLoc == InfoLocation.TopRight))
|
||||||
|
y = -5;
|
||||||
x = sr.getScaledWidth() - x - xSize;
|
x = sr.getScaledWidth() - x - xSize;
|
||||||
}
|
}
|
||||||
y += 5;
|
y += 5;
|
||||||
|
@ -320,7 +320,12 @@ public class HUD extends Feature {
|
||||||
}
|
}
|
||||||
|
|
||||||
Notification[] notifs = HUD.notifs.toArray(new Notification[0]);
|
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];
|
Notification notif = notifs[i];
|
||||||
int localYSize = ySize;
|
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);
|
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();
|
GlStateManager.disableBlend();
|
||||||
y += (localYSize + nVSpace) * dir;
|
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) {
|
GlStateManager.enableDepth();
|
||||||
y = 3;
|
GlStateManager.disableLighting();
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int toHex(final int r, final int g, final int b) {
|
public static int toHex(final int r, final int g, final int b) {
|
||||||
|
|
|
@ -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
1
Website
Submodule
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit b3c3895b1349ba7bae90968970d8889195e8127e
|
Loading…
Add table
Reference in a new issue