Skip to content

Commit 349944c

Browse files
authored
Merge pull request #278 from FTBTeam/1.20.1/dev
1.20.1/dev
2 parents 6b790ca + d47cdb0 commit 349944c

File tree

11 files changed

+246
-99
lines changed

11 files changed

+246
-99
lines changed

Diff for: CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [2001.3.0]
8+
9+
### Changed
10+
* Significant GUI overhaul and cleanup in several places (backported improvements from 1.20.4)
11+
* FTB Library 2001.2.0 is a requirement
12+
713
## [2001.2.7]
814

915
### Fixed

Diff for: common/src/main/java/dev/ftb/mods/ftbchunks/client/FTBChunksClient.java

+51-15
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
import dev.ftb.mods.ftbchunks.FTBChunks;
1919
import dev.ftb.mods.ftbchunks.FTBChunksWorldConfig;
2020
import dev.ftb.mods.ftbchunks.api.FTBChunksAPI;
21-
import dev.ftb.mods.ftbchunks.api.client.FTBChunksClientAPI;
2221
import dev.ftb.mods.ftbchunks.api.client.event.MapIconEvent;
2322
import dev.ftb.mods.ftbchunks.api.client.icon.MapIcon;
2423
import dev.ftb.mods.ftbchunks.api.client.icon.MapType;
2524
import dev.ftb.mods.ftbchunks.api.client.icon.WaypointIcon;
2625
import dev.ftb.mods.ftbchunks.api.client.waypoint.Waypoint;
26+
import dev.ftb.mods.ftbchunks.client.gui.AddWaypointOverlay;
2727
import dev.ftb.mods.ftbchunks.client.gui.ChunkScreen;
2828
import dev.ftb.mods.ftbchunks.client.gui.LargeMapScreen;
2929
import dev.ftb.mods.ftbchunks.client.gui.WaypointEditorScreen;
@@ -32,16 +32,20 @@
3232
import dev.ftb.mods.ftbchunks.client.mapicon.*;
3333
import dev.ftb.mods.ftbchunks.net.PartialPackets;
3434
import dev.ftb.mods.ftbchunks.net.SendGeneralDataPacket.GeneralChunkData;
35+
import dev.ftb.mods.ftblibrary.config.ColorConfig;
3536
import dev.ftb.mods.ftblibrary.config.StringConfig;
3637
import dev.ftb.mods.ftblibrary.config.ui.EditConfigFromStringScreen;
38+
import dev.ftb.mods.ftblibrary.config.ui.EditStringConfigOverlay;
3739
import dev.ftb.mods.ftblibrary.icon.Color4I;
3840
import dev.ftb.mods.ftblibrary.icon.FaceIcon;
3941
import dev.ftb.mods.ftblibrary.icon.Icon;
4042
import dev.ftb.mods.ftblibrary.math.MathUtils;
4143
import dev.ftb.mods.ftblibrary.math.XZ;
4244
import dev.ftb.mods.ftblibrary.snbt.SNBTCompoundTag;
45+
import dev.ftb.mods.ftblibrary.ui.BaseScreen;
4346
import dev.ftb.mods.ftblibrary.ui.CustomClickEvent;
4447
import dev.ftb.mods.ftblibrary.ui.GuiHelper;
48+
import dev.ftb.mods.ftblibrary.ui.Theme;
4549
import dev.ftb.mods.ftblibrary.ui.input.Key;
4650
import dev.ftb.mods.ftblibrary.util.StringUtils;
4751
import dev.ftb.mods.ftblibrary.util.client.ClientUtils;
@@ -363,7 +367,7 @@ public EventResult keyPressed(Minecraft client, int keyCode, int scanCode, int a
363367
public EventResult keyPressed(Minecraft client, Screen screen, int keyCode, int scanCode, int modifiers) {
364368
if (doesKeybindMatch(openMapKey, keyCode, scanCode, modifiers)) {
365369
LargeMapScreen gui = ClientUtils.getCurrentGuiAs(LargeMapScreen.class);
366-
if (gui != null) {
370+
if (gui != null && !gui.anyModalPanelOpen()) {
367371
gui.closeGui(false);
368372
return EventResult.interruptTrue();
369373
}
@@ -378,16 +382,9 @@ private EventResult addQuickWaypoint() {
378382
if (player == null) return EventResult.pass();
379383

380384
return MapManager.getInstance().map(manager -> {
381-
new EditConfigFromStringScreen<>(name, set -> {
382-
if (set && !name.getValue().isEmpty()) {
383-
MapDimension mapDimension = manager.getDimension(player.level().dimension());
384-
WaypointImpl waypoint = new WaypointImpl(WaypointType.DEFAULT, mapDimension, player.blockPosition())
385-
.setName(name.getValue())
386-
.setColor(Color4I.hsb(MathUtils.RAND.nextFloat(), 1F, 1F).rgba());
387-
mapDimension.getWaypointManager().add(waypoint);
388-
}
389-
openGui();
390-
}).openGuiLater(); // later needed to prevent keypress being passed into gui
385+
BaseScreen screen = new WaypointAddScreen(name, player);
386+
screen.openGuiLater();
387+
// later needed to prevent keypress being passed into gui
391388
return EventResult.interruptTrue();
392389
}).orElse(EventResult.pass());
393390
}
@@ -1163,10 +1160,49 @@ public int getMinimapTextureId() {
11631160
return minimapTextureId;
11641161
}
11651162

1166-
public static void addWaypoint(Player player, String name, BlockPos position, int color) {
1167-
FTBChunksAPI.clientApi().getWaypointManager(player.level().dimension()).ifPresent(mgr -> {
1163+
public static Waypoint addWaypoint(Player player, String name, BlockPos position, int color) {
1164+
return FTBChunksAPI.clientApi().getWaypointManager(player.level().dimension()).map(mgr -> {
11681165
Waypoint wp = mgr.addWaypointAt(position, name);
11691166
wp.setColor(color);
1170-
});
1167+
return wp;
1168+
}).orElse(null);
1169+
}
1170+
1171+
private static class WaypointAddScreen extends BaseScreen {
1172+
private final StringConfig name;
1173+
private final Player player;
1174+
1175+
public WaypointAddScreen(StringConfig name, Player player) {
1176+
super();
1177+
this.name = name;
1178+
this.player = player;
1179+
this.setHeight(35);
1180+
}
1181+
1182+
@Override
1183+
public void drawBackground(GuiGraphics graphics, Theme theme, int x, int y, int w, int h) {
1184+
}
1185+
1186+
@Override
1187+
public void addWidgets() {
1188+
ColorConfig col = new ColorConfig();
1189+
col.setValue(Color4I.hsb(MathUtils.RAND.nextFloat(), 1F, 1F));
1190+
AddWaypointOverlay overlay = new AddWaypointOverlay(this, name, col, set -> {
1191+
if (set && !name.getValue().isEmpty()) {
1192+
Waypoint wp = addWaypoint(player, name.getValue(), player.blockPosition(), col.getValue().rgba());
1193+
Minecraft.getInstance().player.displayClientMessage(
1194+
Component.translatable("ftbchunks.waypoint_added",
1195+
Component.literal(wp.getName()).withStyle(ChatFormatting.YELLOW)
1196+
), true);
1197+
}
1198+
}) {
1199+
@Override
1200+
public void onClosed() {
1201+
closeGui();
1202+
}
1203+
};
1204+
overlay.setWidth(this.width);
1205+
pushModalPanel(overlay);
1206+
}
11711207
}
11721208
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package dev.ftb.mods.ftbchunks.client.gui;
2+
3+
import dev.ftb.mods.ftblibrary.config.ColorConfig;
4+
import dev.ftb.mods.ftblibrary.config.ConfigCallback;
5+
import dev.ftb.mods.ftblibrary.config.ConfigFromString;
6+
import dev.ftb.mods.ftblibrary.config.ui.EditStringConfigOverlay;
7+
import dev.ftb.mods.ftblibrary.icon.Color4I;
8+
import dev.ftb.mods.ftblibrary.icon.Icon;
9+
import dev.ftb.mods.ftblibrary.ui.*;
10+
import net.minecraft.client.gui.GuiGraphics;
11+
import net.minecraft.network.chat.Component;
12+
13+
public class AddWaypointOverlay extends EditStringConfigOverlay<String> {
14+
private final ColorButton colorButton;
15+
16+
public AddWaypointOverlay(Panel panel, ConfigFromString<String> config, ColorConfig colorConfig, ConfigCallback callback) {
17+
super(panel, config, callback, Component.translatable("ftbchunks.gui.add_waypoint"));
18+
19+
colorButton = new ColorButton(colorConfig.getValue(), (btn, mb) -> {
20+
ColorSelectorPanel.popupAtMouse(getGui(), colorConfig, accepted -> {
21+
if (accepted) {
22+
btn.setIcon(colorConfig.getValue());
23+
} else {
24+
colorConfig.setValue(((ColorButton) btn).getIcon());
25+
}
26+
});
27+
});
28+
}
29+
30+
@Override
31+
public void addWidgets() {
32+
super.addWidgets();
33+
add(colorButton);
34+
}
35+
36+
@Override
37+
public void alignWidgets() {
38+
super.alignWidgets();
39+
colorButton.setPosAndSize(width - 11, 1, 10, 10);
40+
}
41+
42+
private class ColorButton extends SimpleButton {
43+
public ColorButton(Icon icon, Callback c) {
44+
super(AddWaypointOverlay.this, Component.empty(), icon, c);
45+
}
46+
47+
Color4I getIcon() {
48+
return icon instanceof Color4I c ? c : Color4I.empty();
49+
}
50+
51+
@Override
52+
public void draw(GuiGraphics graphics, Theme theme, int x, int y, int w, int h) {
53+
icon.draw(graphics, x, y, w, h);
54+
Color4I shade = getIcon().addBrightness(-0.15f);
55+
GuiHelper.drawHollowRect(graphics, x, y, w, h, shade, false);
56+
}
57+
}
58+
}

Diff for: common/src/main/java/dev/ftb/mods/ftbchunks/client/gui/ChunkScreen.java

+41-18
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import dev.ftb.mods.ftblibrary.ui.*;
2323
import dev.ftb.mods.ftblibrary.ui.input.Key;
2424
import dev.ftb.mods.ftblibrary.ui.input.MouseButton;
25+
import dev.ftb.mods.ftblibrary.ui.misc.KeyReferenceScreen;
2526
import dev.ftb.mods.ftblibrary.util.TimeUtils;
2627
import dev.ftb.mods.ftblibrary.util.TooltipList;
2728
import dev.ftb.mods.ftbteams.api.property.TeamProperties;
@@ -92,6 +93,7 @@ public void addWidgets() {
9293
int startX = chunkPos.x - FTBChunks.TILE_OFFSET;
9394
int startZ = chunkPos.z - FTBChunks.TILE_OFFSET;
9495

96+
chunkButtons.clear();
9597
for (int z = 0; z < FTBChunks.TILES; z++) {
9698
for (int x = 0; x < FTBChunks.TILES; x++) {
9799
ChunkButton button = new ChunkButton(this, XZ.of(startX + x, startZ + z));
@@ -104,9 +106,14 @@ public void addWidgets() {
104106
new RequestMapDataPacket(chunkPos.x - FTBChunks.TILE_OFFSET, chunkPos.z - FTBChunks.TILE_OFFSET,
105107
chunkPos.x + FTBChunks.TILE_OFFSET, chunkPos.z + FTBChunks.TILE_OFFSET
106108
).sendToServer();
109+
107110
add(new SimpleButton(this, Component.translatable("ftbchunks.gui.large_map"), Icons.MAP,
108111
(simpleButton, mouseButton) -> LargeMapScreen.openMap()
109112
).setPosAndSize(1, 1, 16, 16));
113+
114+
add(new SimpleButton(this, Component.translatable("ftbchunks.gui.chunk_info"), Icons.INFO,
115+
(btn, mb) -> new ChunkMouseReferenceScreen().openGui()
116+
).setPosAndSize(1, 19, 16, 16));
110117
}
111118

112119
@Override
@@ -170,6 +177,17 @@ public void drawBackground(GuiGraphics graphics, Theme theme, int x, int y, int
170177
}
171178
}
172179

180+
private static class ChunkMouseReferenceScreen extends KeyReferenceScreen {
181+
public ChunkMouseReferenceScreen() {
182+
super("ftbchunks.gui.chunk_info.text");
183+
}
184+
185+
@Override
186+
public Component getTitle() {
187+
return Component.translatable("ftbchunks.gui.chunk_info");
188+
}
189+
}
190+
173191
private class ChunkButton extends Button {
174192
private final XZ chunkPos;
175193
private final MapChunk chunk;
@@ -258,24 +276,7 @@ public boolean mouseScrolled(double scroll) {
258276
int dir = (int) Math.signum(scroll);
259277
long now = System.currentTimeMillis();
260278
Date expiry = chunk.getForceLoadExpiryDate().orElse(new Date(now));
261-
long offset = (expiry.getTime() - now) / 1000L;
262-
if (dir == 1) {
263-
if (offset < 86400L) {
264-
offset = offset + 3600L; // hour
265-
} else if (offset < 604800L) {
266-
offset = offset + 86400L; // day
267-
} else {
268-
offset = offset + 604800L; // week
269-
}
270-
} else if (dir == -1) {
271-
if (offset <= 86400L) {
272-
offset = Math.max(0L, offset - 3600L);
273-
} else if (offset <= 604800L) {
274-
offset = Math.max(86400L, offset - 86400L);
275-
} else {
276-
offset = Math.max(604800L, offset - 604800L);
277-
}
278-
}
279+
long offset = calcOffset(expiry, now, dir);
279280
chunk.updateForceLoadExpiryDate(now, offset * 1000L);
280281
lastAdjust = now;
281282
return true;
@@ -284,6 +285,28 @@ public boolean mouseScrolled(double scroll) {
284285
}).orElse(super.mouseScrolled(scroll));
285286
}
286287

288+
private static long calcOffset(Date expiry, long now, int dir) {
289+
long offset = (expiry.getTime() - now) / 1000L;
290+
if (dir == 1) {
291+
if (offset < 86400L) {
292+
offset = offset + 3600L; // hour
293+
} else if (offset < 604800L) {
294+
offset = offset + 86400L; // day
295+
} else {
296+
offset = offset + 604800L; // week
297+
}
298+
} else if (dir == -1) {
299+
if (offset <= 86400L) {
300+
offset = Math.max(0L, offset - 3600L);
301+
} else if (offset <= 604800L) {
302+
offset = Math.max(86400L, offset - 86400L);
303+
} else {
304+
offset = Math.max(604800L, offset - 604800L);
305+
}
306+
}
307+
return offset;
308+
}
309+
287310
@Override
288311
public void tick() {
289312
super.tick();

0 commit comments

Comments
 (0)