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
|
package de.hysky.skyblocker.skyblock.waypoint;
import de.hysky.skyblocker.utils.waypoint.NamedWaypoint;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ConfirmScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.GridWidget;
import net.minecraft.client.gui.widget.SimplePositioningWidget;
import net.minecraft.screen.ScreenTexts;
import net.minecraft.text.Text;
public class WaypointsScreen extends AbstractWaypointsScreen<Screen> {
private ButtonWidget buttonNew;
private ButtonWidget buttonDone;
public WaypointsScreen(Screen parent) {
super(Text.translatable("skyblocker.waypoints.config"), parent, Waypoints.waypointsDeepCopy());
}
@Override
protected void init() {
super.init();
GridWidget gridWidget = new GridWidget();
gridWidget.getMainPositioner().marginX(5).marginY(2);
GridWidget.Adder adder = gridWidget.createAdder(2);
adder.add(ButtonWidget.builder(Text.translatable("skyblocker.waypoints.share"), buttonShare -> client.setScreen(new WaypointsShareScreen(this, waypoints))).build());
buttonNew = adder.add(ButtonWidget.builder(Text.translatable("skyblocker.waypoints.newCategory"), buttonNew -> waypointsListWidget.addWaypointCategoryAfterSelected()).build());
adder.add(ButtonWidget.builder(ScreenTexts.CANCEL, button -> close()).build());
buttonDone = adder.add(ButtonWidget.builder(ScreenTexts.DONE, button -> {
saveWaypoints();
close();
}).build());
gridWidget.refreshPositions();
SimplePositioningWidget.setPos(gridWidget, 0, this.height - 64, this.width, 64);
gridWidget.forEachChild(this::addDrawableChild);
updateButtons();
}
@Override
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
super.render(context, mouseX, mouseY, delta);
context.drawCenteredTextWithShadow(this.textRenderer, this.title, this.width / 2, 16, 0xFFFFFF);
}
@Override
protected boolean isEnabled(NamedWaypoint waypoint) {
return waypoint.shouldRender();
}
@Override
protected void enabledChanged(NamedWaypoint waypoint, boolean enabled) {
waypoint.setShouldRender(enabled);
}
private void saveWaypoints() {
Waypoints.waypoints.clear();
Waypoints.waypoints.putAll(waypoints);
Waypoints.saveWaypoints(client);
}
@Override
public void close() {
assert client != null;
if (!waypoints.equals(Waypoints.waypoints)) {
client.setScreen(new ConfirmScreen(confirmedAction -> client.setScreen(confirmedAction ? parent : this),
Text.translatable("text.skyblocker.quit_config"),
Text.translatable("text.skyblocker.quit_config_sure"),
Text.translatable("text.skyblocker.quit_discard"),
ScreenTexts.CANCEL
));
} else {
client.setScreen(parent);
}
}
}
|