-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e1ef5d0
commit ec395e5
Showing
13 changed files
with
281 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
src/main/java/wtf/cheeze/sbt/features/huds/TickerHUD.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
src/main/java/wtf/cheeze/sbt/utils/hud/AbstractTickerHUD.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
|
||
|
||
|
||
} |
Oops, something went wrong.