Skip to content

Commit

Permalink
Changelog since pre9:
Browse files Browse the repository at this point in the history
= Pests Destroyer - Small fix
= Movrec fixes
+ Bug fixes
= Status HUD - Centering issues fixed :yawn: Some more styling
  • Loading branch information
May2Beez committed Jan 6, 2024
1 parent c45a2de commit be423cb
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 45 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ mcVersion=1.8.9
modid=farmhelperv2
modName=FarmHelper
version=2.4.0-pre11
shouldRelease=false
shouldRelease=true
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ public boolean isFarming() {

public String getStatusString() {
if (FarmHelperConfig.enableScheduler) {
return EnumChatFormatting.BOLD + (schedulerState == SchedulerState.FARMING ? (EnumChatFormatting.GREEN + "Farming") : (EnumChatFormatting.DARK_AQUA + "Break")) + EnumChatFormatting.RESET + " for " +
EnumChatFormatting.BOLD + EnumChatFormatting.GOLD + LogUtils.formatTime(Math.max(schedulerClock.getRemainingTime(), 0)) + EnumChatFormatting.RESET + (schedulerClock.isPaused() ? " (Paused)" : "");
return (schedulerState == SchedulerState.FARMING ? (EnumChatFormatting.GREEN + "Farming") : (EnumChatFormatting.DARK_AQUA + "Break")) + EnumChatFormatting.RESET + " for " +
EnumChatFormatting.GOLD + LogUtils.formatTime(Math.max(schedulerClock.getRemainingTime(), 0)) + EnumChatFormatting.RESET + (schedulerClock.isPaused() ? " (Paused)" : "");
} else {
return "Farming";
}
Expand Down
74 changes: 32 additions & 42 deletions src/main/java/com/jelly/farmhelperv2/hud/StatusHUD.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
import com.jelly.farmhelperv2.util.LogUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StringUtils;
import net.minecraftforge.fml.common.Loader;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import static cc.polyfrost.oneconfig.libs.universal.UGraphics.getCharWidth;

public class StatusHUD extends TextHud {

private final boolean jdaDependencyPresent = Loader.isModLoaded("farmhelperjdadependency");
Expand All @@ -30,64 +31,53 @@ public StatusHUD() {

@Override
protected void getLines(List<String> lines, boolean example) {
if (example) {
lines.add("Break for 25m 35s");
lines.add("Staff bans in the last 15 minutes: 999");
lines.add("Bans in the last 15 minutes");
lines.add("detected by FarmHelper: 0");
lines.set(0, centerText(lines.get(0), scale));
} else {
List<String> tempLines = new ArrayList<>();
tempLines.add(getStatusString());

if (PestsDestroyer.getInstance().getTotalPests() > 0) {
tempLines.add(EnumChatFormatting.UNDERLINE + "Pests in Garden:" + EnumChatFormatting.RESET + " " + EnumChatFormatting.BOLD + EnumChatFormatting.RED + PestsDestroyer.getInstance().getTotalPests());
}
List<String> tempLines = new ArrayList<>();
tempLines.add(getStatusString());

if (BanInfoWS.getInstance().isRunning() && FarmHelperConfig.banwaveCheckerEnabled && BanInfoWS.getInstance().isConnected()) {
tempLines.add("Ban stats from the last " + BanInfoWS.getInstance().getMinutes() + " minutes");
tempLines.add("Staff bans: " + BanInfoWS.getInstance().getStaffBans());
tempLines.add("Detected by FarmHelper: " + BanInfoWS.getInstance().getBansByMod());
} else if (!BanInfoWS.getInstance().isConnected() && FarmHelperConfig.banwaveCheckerEnabled) {
tempLines.add("Connecting to the analytics server...");
}
if (LeaveTimer.getInstance().isRunning())
tempLines.add("Leaving in " + LogUtils.formatTime(Math.max(LeaveTimer.leaveClock.getRemainingTime(), 0)));
if (PestsDestroyer.getInstance().getTotalPests() > 0) {
tempLines.add(EnumChatFormatting.UNDERLINE + "Pests in Garden:" + EnumChatFormatting.RESET + " " + EnumChatFormatting.RED + PestsDestroyer.getInstance().getTotalPests());
}

if (FarmHelperConfig.enableRemoteControl && jdaDependencyPresent) {
if (!Objects.equals(DiscordBotHandler.getInstance().getConnectingState(), "")) {
tempLines.add("");
tempLines.add(DiscordBotHandler.getInstance().getConnectingState());
}
}
if (BanInfoWS.getInstance().isRunning() && FarmHelperConfig.banwaveCheckerEnabled && BanInfoWS.getInstance().isConnected()) {
tempLines.add("Ban stats from the last " + BanInfoWS.getInstance().getMinutes() + " minutes");
tempLines.add("Staff bans: " + BanInfoWS.getInstance().getStaffBans());
tempLines.add("Detected by FarmHelper: " + BanInfoWS.getInstance().getBansByMod());
} else if (!BanInfoWS.getInstance().isConnected() && FarmHelperConfig.banwaveCheckerEnabled) {
tempLines.add("Connecting to the analytics server...");
}
if (LeaveTimer.getInstance().isRunning())
tempLines.add("Leaving in " + LogUtils.formatTime(Math.max(LeaveTimer.leaveClock.getRemainingTime(), 0)));

for (String line : tempLines) {
lines.add(centerText(line, scale, tempLines));
if (FarmHelperConfig.enableRemoteControl && jdaDependencyPresent) {
if (!Objects.equals(DiscordBotHandler.getInstance().getConnectingState(), "")) {
tempLines.add("");
tempLines.add(DiscordBotHandler.getInstance().getConnectingState());
}
}
}

private String centerText(String text, float scale) {
return centerText(text, scale, lines);
float maxWidth = getWidth(tempLines);

for (String line : tempLines) {
lines.add(centerText(line, maxWidth));
}
}

private String centerText(String text, float scale, List<String> lines) {
if (lines == null || lines.isEmpty()) return text;
float width = getWidth(scale, lines);
float lineWidth = getLineWidth(text, scale);
int spaces = (int) ((width - lineWidth) / (scale * 4));
private String centerText(String text, float maxWidth) {
float lineWidth = getLineWidth(EnumChatFormatting.getTextWithoutFormattingCodes(text).trim(), scale);
float charWidth = getCharWidth(' ');
int spaces = (int) ((maxWidth - lineWidth) / charWidth);
StringBuilder builder = new StringBuilder();
for (int i = 0; i < spaces / 2; i++) {
builder.append(" ");
}
return builder + text + builder;
return builder + text;
}

protected float getWidth(float scale, List<String> lines) {
protected float getWidth(List<String> lines) {
if (lines == null) return 0;
float width = 0;
for (String line : lines) {
width = Math.max(width, getLineWidth(StringUtils.stripControlCodes(line), scale));
width = Math.max(width, getLineWidth(EnumChatFormatting.getTextWithoutFormattingCodes(line).trim(), scale));
}
return width;
}
Expand Down

0 comments on commit be423cb

Please sign in to comment.