Skip to content

Commit

Permalink
Ticker/Charges HUD
Browse files Browse the repository at this point in the history
  • Loading branch information
MisterCheezeCake committed Sep 15, 2024
1 parent e1ef5d0 commit ec395e5
Show file tree
Hide file tree
Showing 13 changed files with 281 additions and 21 deletions.
14 changes: 7 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@ base {

repositories {
maven {
name 'Xander Maven'
url 'https://maven.isxander.dev/releases'
name = "Xander Maven"
url = "https://maven.isxander.dev/releases"
}
maven {
name = "Terraformers"
url = "https://maven.terraformersmc.com/"
}
exclusiveContent {
forRepository {
maven { url "https://maven.azureaaron.net/releases" }
maven {
url = "https://maven.azureaaron.net/releases"
}
}

filter {
includeGroup "net.azureaaron"
}
Expand All @@ -35,9 +36,9 @@ dependencies {
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
modImplementation 'dev.isxander:yet-another-config-lib:3.5.0+1.21-fabric'
modImplementation "dev.isxander:yet-another-config-lib:${project.yacl_version}"
modImplementation("com.terraformersmc:modmenu:${project.modmenu_version}")
include modImplementation("net.azureaaron:hm-api:1.0.0+1.21")
include modImplementation("net.azureaaron:hm-api:${project.hmapi_version}")


}
Expand All @@ -56,7 +57,6 @@ tasks.withType(JavaCompile).configureEach {

java {
withSourcesJar()

sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}
Expand Down
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ archives_base_name=SkyblockTweaks

# Dependencies
fabric_version=0.100.6+1.21
modmenu_version=11.0.1
modmenu_version=11.0.1
yacl_version=3.5.0+1.21-fabric
hmapi_version=1.0.0+1.21
3 changes: 3 additions & 0 deletions src/main/java/wtf/cheeze/sbt/SkyblockTweaks.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ public void onInitialize() {
HUDS.add(new RealTimeHUD());
HUDS.add(new FpsHUD());

HUDS.add(new TickerHUD());


HudRenderCallback.EVENT.register((context, tickCounter) -> {
HUDS.forEach(hud -> hud.render(context, false));
});
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/wtf/cheeze/sbt/config/categories/Huds.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ public class Huds {
@SerialEntry
public SkillHUD.Config skills = new SkillHUD.Config();

@SerialEntry
public TickerHUD.Config ticker = new TickerHUD.Config();

public static ConfigCategory getCategory(ConfigImpl defaults, ConfigImpl config) {
return ConfigCategory.createBuilder()
.name(Text.literal("HUDs"))
Expand All @@ -91,6 +94,7 @@ public static ConfigCategory getCategory(ConfigImpl defaults, ConfigImpl config)
.group(CoordinatesHUD.Config.getGroup(defaults, config))
.group(RealTimeHUD.Config.getGroup(defaults, config))
.group(FpsHUD.Config.getGroup(defaults, config))
.group(TickerHUD.Config.getGroup(defaults, config))
.build();
}
}
112 changes: 112 additions & 0 deletions src/main/java/wtf/cheeze/sbt/features/huds/TickerHUD.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package wtf.cheeze.sbt.features.huds;

import dev.isxander.yacl3.api.Option;
import dev.isxander.yacl3.api.OptionDescription;
import dev.isxander.yacl3.api.OptionGroup;
import dev.isxander.yacl3.config.v2.api.SerialEntry;
import net.minecraft.text.Text;
import wtf.cheeze.sbt.SkyblockTweaks;
import wtf.cheeze.sbt.config.ConfigImpl;
import wtf.cheeze.sbt.config.SkyblockTweaksConfig;
import wtf.cheeze.sbt.utils.TextUtils;
import wtf.cheeze.sbt.utils.hud.AbstractTickerHUD;
import wtf.cheeze.sbt.utils.hud.HudInformation;

public class TickerHUD extends AbstractTickerHUD {

public TickerHUD() {
INFO = new HudInformation(
() -> SkyblockTweaks.CONFIG.config.huds.ticker.x,
() -> SkyblockTweaks.CONFIG.config.huds.ticker.y,
() -> SkyblockTweaks.CONFIG.config.huds.ticker.scale,
() -> SkyblockTweaks.CONFIG.config.huds.ticker.anchor,
x -> SkyblockTweaks.CONFIG.config.huds.ticker.x = x,
y -> SkyblockTweaks.CONFIG.config.huds.ticker.y = y,
scale -> SkyblockTweaks.CONFIG.config.huds.ticker.scale = scale,
anchor -> SkyblockTweaks.CONFIG.config.huds.ticker.anchor = anchor
);
}


@Override
public String getName() {
return TextUtils.SECTION + "eTicker/Charges Hud";
}

@Override
public boolean shouldRender(boolean fromHudScreen) {
if (!super.shouldRender(fromHudScreen)) return false;
if ((SkyblockTweaks.DATA.inSB && SkyblockTweaks.CONFIG.config.huds.ticker.enabled && SkyblockTweaks.DATA.tickerActive) || fromHudScreen) return true;
return false;
}


@Override
public int getMax(boolean fromHudScreen) {
if (!fromHudScreen) return SkyblockTweaks.DATA.maxTickers;
if (SkyblockTweaks.DATA.tickerActive) return SkyblockTweaks.DATA.maxTickers;
return 5;
}

@Override
public int getUsable(boolean fromHudScreen) {
if (!fromHudScreen) return SkyblockTweaks.DATA.tickers;
if (SkyblockTweaks.DATA.tickerActive) return SkyblockTweaks.DATA.tickers;
return 5;

}

@Override
public int getMax() {
return getMax(false);
}

public static class Config {
@SerialEntry
public boolean enabled = false;

@SerialEntry // Not handled by YACL Gui
public float x = 0;

@SerialEntry // Not handled by YACL Gui
public float y = 0.9f;

@SerialEntry
public float scale = 1.0f;

@SerialEntry
public AnchorPoint anchor = AnchorPoint.LEFT;

public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) {
var enabled = Option.<Boolean>createBuilder()
.name(Text.literal("Enable Ticker HUD"))
.description(OptionDescription.of(Text.literal("Enables the Ticker/Charges HUD")))
.controller(SkyblockTweaksConfig::generateBooleanController)
.binding(
defaults.huds.ticker.enabled,
() -> config.huds.ticker.enabled,
value -> config.huds.ticker.enabled = (Boolean) value
)
.build();
var scale = Option.<Float>createBuilder()
.name(Text.literal("Ticker HUD Scale"))
.description(OptionDescription.of(Text.literal("The scale of the Mana Bar")))
.controller(SkyblockTweaksConfig::generateScaleController)
.binding(
defaults.huds.ticker.scale,
() -> config.huds.ticker.scale,
value -> config.huds.ticker.scale = value
)
.build();

return OptionGroup.createBuilder()
.name(Text.literal("Ticker/Charges HUD"))
.description(OptionDescription.of(Text.literal("Settings for the Ticker/Charges HUD")))
.option(enabled)
.option(scale)
.collapsed(true)
.build();
}
}

}
13 changes: 8 additions & 5 deletions src/main/java/wtf/cheeze/sbt/utils/actionbar/ActionBarData.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@
/**
* Represents the data that can be extracted from the action bar, and also contains the transformed text.
* Not all fields are always present, and the mod does not use or parse the following fields:
* - Tickers
* - Race Fields
* - Location Alert Fields
*/
public class ActionBarData {
public String transformedText;


@Nullable
public Float maxHealth;
@Nullable
Expand Down Expand Up @@ -61,11 +59,16 @@ public class ActionBarData {
@Nullable
public String abilityName;
@Nullable
public int abilityManaCost;
public Integer abilityManaCost;
@Nullable
public Integer secretsFound;
@Nullable
public int secretsFound;
public Integer secretsTotal;
@Nullable
public int secretsTotal;
public Integer maxTickers;
@Nullable
public Integer currentTickers;


public String toJson() {
return SkyblockTweaks.GSON.toJson(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,27 @@ public static ActionBarData extractDataAndRunTransformation(String actionBarText
} else if (segment.contains("second") || segment.contains("DPS")) {
// Trial of Fire
newText += SEPERATOR3 + unpadded;
} else if (segment.contains("ⓩ") || segment.contains("Ⓞ")){
// Ornate/Florid: §e§lⓩⓩⓩ§6§lⓄⓄ
// Regular: §a§lⓩ§2§lⓄⓄⓄ
// Foil: §e§lⓄⓄ§7§lⓄⓄ
data.maxTickers = segment.length();
if (unpadded.contains("§6§l")) {
var split = unpadded.split("§6§l") ;
data.currentTickers = TextUtils.removeColorCodes(split[0]).length();
} else if (unpadded.contains("§2§l")) {
var split = unpadded.split("§2§l") ;
data.currentTickers = TextUtils.removeColorCodes(split[0]).length();
}
else if (unpadded.contains("§7§l")) {
var split = unpadded.split("§7§l") ;
data.currentTickers = TextUtils.removeColorCodes(split[0]).length();
}

if (!SkyblockTweaks.CONFIG.config.actionBarFilters.hideTickers) {
newText += SEPERATOR4 + unpadded;
}

} else {
newText += SEPERATOR5 + unpadded;
}
Expand All @@ -186,7 +207,7 @@ public static void registerEvents() {
if (!overlay) return message;
//SkyblockTweaks.LOGGER.info("Old: " + message.getString());
var data = ActionBarTransformer.extractDataAndRunTransformation(message.getString());
//SkyBlockTweaks.LOGGER.info("New: " + data.transformedText);
//SkyblockTweaks.LOGGER.info("New: " + data.transformedText);
SkyblockTweaks.DATA.update(data);
return Text.of(data.transformedText);

Expand Down Expand Up @@ -215,6 +236,10 @@ public static class Config {

@SerialEntry
public boolean hideSecrets = false;

@SerialEntry
public boolean hideTickers = false;

public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) {
var health = Option.<Boolean>createBuilder()
.name(Text.literal("Hide Health in Action Bar"))
Expand Down Expand Up @@ -286,6 +311,16 @@ public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) {
value -> config.actionBarFilters.hideSecrets = (Boolean) value
)
.build();
var tickers = Option.<Boolean>createBuilder()
.name(Text.literal("Hide Tickers/Charges in Action Bar"))
.description(OptionDescription.of(Text.literal("Hides the tickers/charges in the action bar")))
.controller(SkyblockTweaksConfig::generateBooleanController)
.binding(
defaults.actionBarFilters.hideTickers,
() -> config.actionBarFilters.hideTickers,
value -> config.actionBarFilters.hideTickers = (Boolean) value
)
.build();
return OptionGroup.createBuilder()
.name(Text.literal("Action Bar Filters"))
.description(OptionDescription.of(Text.literal("Filters out certain information from the action bar")))
Expand All @@ -296,7 +331,7 @@ public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) {
.option(skill)
.option(drill)
.option(secrets)
.collapsed(true)
.option(tickers)
.build();
}
}
Expand Down
91 changes: 91 additions & 0 deletions src/main/java/wtf/cheeze/sbt/utils/hud/AbstractTickerHUD.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package wtf.cheeze.sbt.utils.hud;

import net.minecraft.client.gui.DrawContext;
import net.minecraft.util.Identifier;
import wtf.cheeze.sbt.SkyblockTweaks;
import wtf.cheeze.sbt.utils.render.RenderUtils;

/**
* The abstract representation of the ticker HUD, for the implementation, see {@link wtf.cheeze.sbt.features.huds.TickerHUD}
*/
public abstract class AbstractTickerHUD extends HUD{
private static final Identifier FULL = Identifier.of("skyblocktweaks", "ticker_full.png");
private static final Identifier BLANK = Identifier.of("skyblocktweaks", "ticker_blank.png");
private static final int DIMENSION = 9;

public abstract int getMax(boolean fromHudScreen);
public abstract int getUsable(boolean fromHudScreen);
public abstract int getMax();


@Override
public void render(DrawContext context, boolean fromHudScreen, boolean hovered) {
if (!shouldRender(fromHudScreen)) return;
var bounds = getCurrentBounds();
if (fromHudScreen) {
drawBackground(context, hovered ? BACKGROUND_HOVERED : BACKGROUND_NOT_HOVERED);
}
if (bounds.scale != 1.0f) {
RenderUtils.beginScale(context, bounds.scale);
}
var x2 = drawTickers(context, getUsable(fromHudScreen), bounds.x, bounds.y, bounds.scale, true);
drawTickers(context, getMax(fromHudScreen) - getUsable(fromHudScreen), x2, bounds.y, bounds.scale, false);
if (bounds.scale != 1.0f) {
RenderUtils.endScale(context);
}

}

private float drawTickers(DrawContext context, int number, float x, int y, float scale, boolean filled) {
float drawX = x;
for (int i = 0; i < number; i++) {
context.drawTexture(filled ? FULL : BLANK, (int) (drawX / scale), (int) (y / scale), 0, 0, DIMENSION, DIMENSION, DIMENSION , DIMENSION);
drawX = (2 + drawX + (DIMENSION * scale));
}
return drawX;
}

private int getWidth() {
return DIMENSION * getMax() + 2 * getMax();
}

private int getRelativeWidth() {
return getWidth() / SkyblockTweaks.mc.getWindow().getWidth();
}

@Override
public Bounds getCurrentBounds() {
var scale = (float) INFO.getScale.get();
switch (INFO.getAnchorPoint.get()) {
case LEFT -> {
return new Bounds(getActualX((float) INFO.getX.get()), getActualY((float) INFO.getY.get()), getWidth() * scale, DIMENSION * scale, scale);
}
case RIGHT -> {
return new Bounds((int) (getActualX((float) INFO.getX.get()) - getWidth() * scale), getActualY((float) INFO.getY.get()), getWidth() * scale, DIMENSION * scale, scale);
}
case CENTER -> {
return new Bounds((int) (getActualX((float) INFO.getX.get()) - getWidth() * scale / 2), getActualY((float) INFO.getY.get()), getWidth() * scale, DIMENSION * scale, scale);
}
default -> throw new IllegalStateException("Unexpected value: " + INFO.getAnchorPoint.get());
}
}
@Override
public BoundsRelative getCurrentBoundsRelative() {
var scale = (float) INFO.getScale.get();
switch (INFO.getAnchorPoint.get()) {
case LEFT -> {
return new BoundsRelative((float) INFO.getX.get(), (float) INFO.getY.get(), getWidth() * scale, DIMENSION * scale, scale);
}
case RIGHT -> {
return new BoundsRelative((float) INFO.getX.get() - getRelativeWidth() * scale, (float) INFO.getY.get(), getWidth() * scale, DIMENSION * scale, scale);
}
case CENTER -> {
return new BoundsRelative((float) INFO.getX.get() - getRelativeWidth() * scale / 2, (float) INFO.getY.get(), getWidth() * scale, DIMENSION * scale, scale);
}
default -> throw new IllegalStateException("Unexpected value: " + INFO.getAnchorPoint.get());
}
}



}
Loading

0 comments on commit ec395e5

Please sign in to comment.