Skip to content

Commit

Permalink
Fix Fire Sales Widget (#461)
Browse files Browse the repository at this point in the history
  • Loading branch information
AzureAaron authored Dec 31, 2023
1 parent 30b2c26 commit 3f0a9ad
Showing 1 changed file with 6 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package de.hysky.skyblocker.skyblock.tabhud.widget;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import de.hysky.skyblocker.skyblock.tabhud.util.Colors;
import de.hysky.skyblocker.skyblock.tabhud.util.Ico;
import de.hysky.skyblocker.skyblock.tabhud.util.PlayerListMgr;
import de.hysky.skyblocker.skyblock.tabhud.widget.component.IcoTextComponent;
import de.hysky.skyblocker.skyblock.tabhud.widget.component.PlainTextComponent;
import de.hysky.skyblocker.skyblock.tabhud.widget.component.ProgressComponent;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
Expand All @@ -17,47 +13,25 @@

public class FireSaleWidget extends Widget {

private static final MutableText TITLE = Text.literal("Fire Sale").formatted(Formatting.DARK_AQUA,
private static final MutableText TITLE = Text.literal("Fire Sales").formatted(Formatting.DARK_AQUA,
Formatting.BOLD);

// matches a fire sale item
// group 1: item name
// group 2: # items available
// group 3: # items available in total (1 digit + "k")
private static final Pattern FIRE_PATTERN = Pattern.compile("(?<item>.*): (?<avail>\\d*)/(?<total>[0-9.]*)k");

public FireSaleWidget() {
super(TITLE, Formatting.DARK_AQUA.getColorValue());
}

@Override
public void updateContent() {
String event = PlayerListMgr.strAt(46);
Text event = PlayerListMgr.textAt(46);

if (event == null) {
this.addComponent(new PlainTextComponent(Text.literal("No Fire Sale!").formatted(Formatting.GRAY)));
this.addComponent(new PlainTextComponent(Text.literal("No Fire Sales!").formatted(Formatting.GRAY)));
return;
}

if (event.contains("Starts In")) {
this.addSimpleIcoText(Ico.CLOCK, "Starts in:", Formatting.DARK_AQUA, 46);
if (event.getString().contains("starting in")) {
this.addComponent(new IcoTextComponent(Ico.CLOCK, event));
return;
}

for (int i = 46;; i++) {
Matcher m = PlayerListMgr.regexAt( i, FIRE_PATTERN);
if (m == null) {
break;
}
String avail = m.group("avail");
Text itemTxt = Text.literal(m.group("item"));
float total = Float.parseFloat(m.group("total")) * 1000;
Text prgressTxt = Text.literal(String.format("%s/%.0f", avail, total));
float pcnt = (Float.parseFloat(avail) / (total)) * 100f;
ProgressComponent pc = new ProgressComponent(Ico.GOLD, itemTxt, prgressTxt, pcnt, Colors.pcntToCol(pcnt));
this.addComponent(pc);
}

}

}

0 comments on commit 3f0a9ad

Please sign in to comment.