Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Fire Sales Widget #461

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}

}

}