diff options
author | msg-programs <msgdoesstuff@gmail.com> | 2023-09-08 09:54:36 +0200 |
---|---|---|
committer | msg-programs <msgdoesstuff@gmail.com> | 2023-09-08 09:54:36 +0200 |
commit | b153e75818b5058df9334953d5924c2c82598719 (patch) | |
tree | e3d89ebe428a443ead9a141340469f616e1ba761 /src/main/java/me/xmrvizzy/skyblocker/skyblock | |
parent | 2a0cfe9c7cd81b7e086f9902b0ee7a4affb3b89c (diff) | |
download | Skyblocker-b153e75818b5058df9334953d5924c2c82598719.tar.gz Skyblocker-b153e75818b5058df9334953d5924c2c82598719.tar.bz2 Skyblocker-b153e75818b5058df9334953d5924c2c82598719.zip |
Rewrite the RiftProgressWidget, hopefully it works correctly now.
Diffstat (limited to 'src/main/java/me/xmrvizzy/skyblocker/skyblock')
-rw-r--r-- | src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/rift/RiftProgressWidget.java | 135 |
1 files changed, 75 insertions, 60 deletions
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/rift/RiftProgressWidget.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/rift/RiftProgressWidget.java index bfd52131..ad43c9f4 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/rift/RiftProgressWidget.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/rift/RiftProgressWidget.java @@ -15,23 +15,24 @@ import net.minecraft.util.math.MathHelper; public class RiftProgressWidget extends Widget { - private static final MutableText TITLE = Text.literal("Rift Progress").formatted(Formatting.BLUE, Formatting.BOLD); + private static final MutableText TITLE = Text.literal("Rift Progress").formatted(Formatting.BLUE, Formatting.BOLD); - private static final Pattern TIMECHARMS_PATTERN = Pattern.compile("Timecharms: (?<current>[0-9]+)\\/(?<total>[0-9]+)"); - private static final Pattern ENIGMA_SOULS_PATTERN = Pattern.compile("Enigma Souls: (?<current>[0-9]+)\\/(?<total>[0-9]+)"); - private static final Pattern MONTEZUMA_PATTERN = Pattern.compile("Montezuma: (?<current>[0-9]+)\\/(?<total>[0-9]+)"); + private static final Pattern TIMECHARMS_PATTERN = Pattern.compile("Timecharms: (?<current>[0-9]+)\\/(?<total>[0-9]+)"); + private static final Pattern ENIGMA_SOULS_PATTERN = Pattern.compile("Enigma Souls: (?<current>[0-9]+)\\/(?<total>[0-9]+)"); + private static final Pattern MONTEZUMA_PATTERN = Pattern.compile("Montezuma: (?<current>[0-9]+)\\/(?<total>[0-9]+)"); - public RiftProgressWidget() { - super(TITLE, Formatting.BLUE.getColorValue()); + public RiftProgressWidget() { + super(TITLE, Formatting.BLUE.getColorValue()); } @Override public void updateContent() { - // After you progress further the tab adds more info so we need to be careful of - // that - // In beginning it only shows montezuma, then timecharms and enigma souls are - // added - String pos44 = PlayerListMgr.strAt(45); + // After you progress further, the tab adds more info so we need to be careful + // of that. + // In beginning it only shows montezuma, then timecharms and enigma souls are + // added. + + String pos44 = PlayerListMgr.strAt(44); // LHS short-circuits, so the RHS won't be evaluated on pos44 == null if (pos44 == null || !pos44.contains("Rift Progress")) { @@ -39,70 +40,84 @@ public class RiftProgressWidget extends Widget { return; } - String pos45 = PlayerListMgr.strAt(45); // Can be Montezuma or Timecharms - String pos46 = PlayerListMgr.strAt(46); // Can be Enigma Souls or Empty - String pos47 = PlayerListMgr.strAt(47); // Can be Montezuma or "Good to know" heading + // let's try to be clever by assuming what progress item may appear where and + // when to skip testing every slot for every thing. - boolean hasTimecharms = false; - boolean hasEnigmaSouls = false; - int montezumaPos; + // always non-null, as this holds the topmost item. + // if there is none, there shouldn't be a header. + String pos45 = PlayerListMgr.strAt(45); - // Check each position to see what is or isn't there so we don't try adding - // invalid components - if (pos45 != null && pos45.contains("Timecharms")) - hasTimecharms = true; - if (pos46 != null && pos46.contains("Enigma Souls")) - hasEnigmaSouls = true; + // Can be Montezuma, Enigma Souls or Timecharms. + // assume timecharms can only appear here and that they're the last thing to + // appear, so if this exists, we know the rest. + if (pos45.contains("Timecharms")) { + addTimecharmsComponent(45); + addEnigmaSoulsComponent(46); + addMontezumaComponent(47); + return; + } - // Small ternary to account for positions, defaults to -1 if it for some reason - // does not exist (which shouldn't be the case!) - montezumaPos = (pos47.contains("Montezuma")) ? 47 : (pos45.contains("Montezuma")) ? 45 : -1; + // timecharms didn't appear at the top, so there's two or one entries. + // assume that if there's two, souls is always top. + String pos46 = PlayerListMgr.strAt(46); + + if (pos45.contains("Enigma Souls")) { + addEnigmaSoulsComponent(45); + if (pos46 != null) { + // souls might appear alone. + // if there's a second entry, it has to be montezuma + addMontezumaComponent(46); + } + } else { + // first entry isn't souls, so it's just montezuma and nothing else. + addMontezumaComponent(45); + } - if (hasTimecharms) { - Matcher m = PlayerListMgr.regexAt(45, TIMECHARMS_PATTERN); + } - int current = Integer.parseInt(m.group("current")); - int total = Integer.parseInt(m.group("total")); - float pcnt = ((float) current / (float) total) * 100f; - Text progressText = Text.literal(current + "/" + total); + private static int pcntToCol(float pcnt) { + return MathHelper.hsvToRgb(pcnt / 300f, 0.9f, 0.9f); + } - ProgressComponent pc = new ProgressComponent(Ico.NETHER_STAR, Text.literal("Timecharms"), progressText, - pcnt, pcntToCol(pcnt)); + private void addTimecharmsComponent(int pos) { + Matcher m = PlayerListMgr.regexAt(pos, TIMECHARMS_PATTERN); - this.addComponent(pc); - } + int current = Integer.parseInt(m.group("current")); + int total = Integer.parseInt(m.group("total")); + float pcnt = ((float) current / (float) total) * 100f; + Text progressText = Text.literal(current + "/" + total); - if (hasEnigmaSouls) { - Matcher m = PlayerListMgr.regexAt(46, ENIGMA_SOULS_PATTERN); + ProgressComponent pc = new ProgressComponent(Ico.NETHER_STAR, Text.literal("Timecharms"), progressText, + pcnt, pcntToCol(pcnt)); - int current = Integer.parseInt(m.group("current")); - int total = Integer.parseInt(m.group("total")); - float pcnt = ((float) current / (float) total) * 100f; - Text progressText = Text.literal(current + "/" + total); + this.addComponent(pc); + } - ProgressComponent pc = new ProgressComponent(Ico.HEART_OF_THE_SEA, Text.literal("Enigma Souls"), - progressText, pcnt, pcntToCol(pcnt)); + private void addEnigmaSoulsComponent(int pos) { + Matcher m = PlayerListMgr.regexAt(pos, ENIGMA_SOULS_PATTERN); - this.addComponent(pc); - } + int current = Integer.parseInt(m.group("current")); + int total = Integer.parseInt(m.group("total")); + float pcnt = ((float) current / (float) total) * 100f; + Text progressText = Text.literal(current + "/" + total); - if (montezumaPos != -1) { - Matcher m = PlayerListMgr.regexAt(montezumaPos, MONTEZUMA_PATTERN); + ProgressComponent pc = new ProgressComponent(Ico.HEART_OF_THE_SEA, Text.literal("Enigma Souls"), + progressText, pcnt, pcntToCol(pcnt)); - int current = Integer.parseInt(m.group("current")); - int total = Integer.parseInt(m.group("total")); - float pcnt = ((float) current / (float) total) * 100f; - Text progressText = Text.literal(current + "/" + total); + this.addComponent(pc); + } - ProgressComponent pc = new ProgressComponent(Ico.BONE, Text.literal("Montezuma"), progressText, pcnt, - pcntToCol(pcnt)); + private void addMontezumaComponent(int pos) { + Matcher m = PlayerListMgr.regexAt(pos, MONTEZUMA_PATTERN); - this.addComponent(pc); - } + int current = Integer.parseInt(m.group("current")); + int total = Integer.parseInt(m.group("total")); + float pcnt = ((float) current / (float) total) * 100f; + Text progressText = Text.literal(current + "/" + total); - } + ProgressComponent pc = new ProgressComponent(Ico.BONE, Text.literal("Montezuma"), progressText, pcnt, + pcntToCol(pcnt)); - private static int pcntToCol(float pcnt) { - return MathHelper.hsvToRgb(pcnt / 300f, 0.9f, 0.9f); - } + this.addComponent(pc); + } } |