blob: 53f84f7145eb2f7e9d02b5c330157661314d4870 (
plain)
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
|
package de.hysky.skyblocker.skyblock.tabhud.widget;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import de.hysky.skyblocker.skyblock.tabhud.widget.component.IcoTextComponent;
import de.hysky.skyblocker.skyblock.tabhud.util.Ico;
import de.hysky.skyblocker.skyblock.tabhud.util.PlayerListMgr;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
// this widget shows info about all puzzeles in the dungeon (name and status)
public class DungeonPuzzleWidget extends Widget {
private static final MutableText TITLE = Text.literal("Puzzles").formatted(Formatting.DARK_PURPLE,
Formatting.BOLD);
// match a puzzle entry
// group 1: name
// group 2: status
// " ?.*" to diescard the solver's name if present
// the teleport maze has a trailing whitespace that messes with the regex
private static final Pattern PUZZLE_PATTERN = Pattern.compile("(?<name>.*): \\[(?<status>.*)\\] ?.*");
public DungeonPuzzleWidget() {
super(TITLE, Formatting.DARK_PURPLE.getColorValue());
}
@Override
public void updateContent() {
int pos = 48;
while (pos < 60) {
Matcher m = PlayerListMgr.regexAt(pos, PUZZLE_PATTERN);
if (m == null) {
break;
}
Formatting statcol = switch (m.group("status")) {
case "✦" -> Formatting.GOLD; // Unsolved
case "✔" -> Formatting.GREEN; // Solved
case "✖" -> Formatting.RED; // Failed
default -> Formatting.WHITE; // Who knows if they'll add another puzzle state or not?
};
Text t = Text.literal(m.group("name") + ": ")
.append(Text.literal("[").formatted(Formatting.GRAY))
.append(Text.literal(m.group("status")).formatted(statcol, Formatting.BOLD))
.append(Text.literal("]").formatted(Formatting.GRAY));
IcoTextComponent itc = new IcoTextComponent(Ico.SIGN, t);
this.addComponent(itc);
pos++;
}
if (pos == 48) {
this.addComponent(
new IcoTextComponent(Ico.BARRIER, Text.literal("No puzzles!").formatted(Formatting.GRAY)));
}
}
}
|