1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
package de.hysky.skyblocker.skyblock.tabhud.widget.rift;
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.Widget;
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;
public class RiftProgressWidget extends Widget {
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]+)");
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(44);
// LHS short-circuits, so the RHS won't be evaluated on pos44 == null
if (pos44 == null || !pos44.contains("Rift Progress")) {
this.addComponent(new PlainTextComponent(Text.literal("No Progress").formatted(Formatting.GRAY)));
return;
}
// let's try to be clever by assuming what progress item may appear where and
// when to skip testing every slot for every thing.
// always non-null, as this holds the topmost item.
// if there is none, there shouldn't be a header.
String pos45 = PlayerListMgr.strAt(45);
// 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;
}
// 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);
}
}
private void addTimecharmsComponent(int pos) {
Matcher m = PlayerListMgr.regexAt(pos, 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);
ProgressComponent pc = new ProgressComponent(Ico.NETHER_STAR, Text.literal("Timecharms"), progressText,
pcnt, Colors.pcntToCol(pcnt));
this.addComponent(pc);
}
private void addEnigmaSoulsComponent(int pos) {
Matcher m = PlayerListMgr.regexAt(pos, ENIGMA_SOULS_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);
ProgressComponent pc = new ProgressComponent(Ico.HEART_OF_THE_SEA, Text.literal("Enigma Souls"),
progressText, pcnt, Colors.pcntToCol(pcnt));
this.addComponent(pc);
}
private void addMontezumaComponent(int pos) {
Matcher m = PlayerListMgr.regexAt(pos, MONTEZUMA_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);
ProgressComponent pc = new ProgressComponent(Ico.BONE, Text.literal("Montezuma"), progressText, pcnt,
Colors.pcntToCol(pcnt));
this.addComponent(pc);
}
}
|