18
18
import dev .ftb .mods .ftbchunks .FTBChunks ;
19
19
import dev .ftb .mods .ftbchunks .FTBChunksWorldConfig ;
20
20
import dev .ftb .mods .ftbchunks .api .FTBChunksAPI ;
21
- import dev .ftb .mods .ftbchunks .api .client .FTBChunksClientAPI ;
22
21
import dev .ftb .mods .ftbchunks .api .client .event .MapIconEvent ;
23
22
import dev .ftb .mods .ftbchunks .api .client .icon .MapIcon ;
24
23
import dev .ftb .mods .ftbchunks .api .client .icon .MapType ;
25
24
import dev .ftb .mods .ftbchunks .api .client .icon .WaypointIcon ;
26
25
import dev .ftb .mods .ftbchunks .api .client .waypoint .Waypoint ;
26
+ import dev .ftb .mods .ftbchunks .client .gui .AddWaypointOverlay ;
27
27
import dev .ftb .mods .ftbchunks .client .gui .ChunkScreen ;
28
28
import dev .ftb .mods .ftbchunks .client .gui .LargeMapScreen ;
29
29
import dev .ftb .mods .ftbchunks .client .gui .WaypointEditorScreen ;
32
32
import dev .ftb .mods .ftbchunks .client .mapicon .*;
33
33
import dev .ftb .mods .ftbchunks .net .PartialPackets ;
34
34
import dev .ftb .mods .ftbchunks .net .SendGeneralDataPacket .GeneralChunkData ;
35
+ import dev .ftb .mods .ftblibrary .config .ColorConfig ;
35
36
import dev .ftb .mods .ftblibrary .config .StringConfig ;
36
37
import dev .ftb .mods .ftblibrary .config .ui .EditConfigFromStringScreen ;
38
+ import dev .ftb .mods .ftblibrary .config .ui .EditStringConfigOverlay ;
37
39
import dev .ftb .mods .ftblibrary .icon .Color4I ;
38
40
import dev .ftb .mods .ftblibrary .icon .FaceIcon ;
39
41
import dev .ftb .mods .ftblibrary .icon .Icon ;
40
42
import dev .ftb .mods .ftblibrary .math .MathUtils ;
41
43
import dev .ftb .mods .ftblibrary .math .XZ ;
42
44
import dev .ftb .mods .ftblibrary .snbt .SNBTCompoundTag ;
45
+ import dev .ftb .mods .ftblibrary .ui .BaseScreen ;
43
46
import dev .ftb .mods .ftblibrary .ui .CustomClickEvent ;
44
47
import dev .ftb .mods .ftblibrary .ui .GuiHelper ;
48
+ import dev .ftb .mods .ftblibrary .ui .Theme ;
45
49
import dev .ftb .mods .ftblibrary .ui .input .Key ;
46
50
import dev .ftb .mods .ftblibrary .util .StringUtils ;
47
51
import dev .ftb .mods .ftblibrary .util .client .ClientUtils ;
@@ -363,7 +367,7 @@ public EventResult keyPressed(Minecraft client, int keyCode, int scanCode, int a
363
367
public EventResult keyPressed (Minecraft client , Screen screen , int keyCode , int scanCode , int modifiers ) {
364
368
if (doesKeybindMatch (openMapKey , keyCode , scanCode , modifiers )) {
365
369
LargeMapScreen gui = ClientUtils .getCurrentGuiAs (LargeMapScreen .class );
366
- if (gui != null ) {
370
+ if (gui != null && ! gui . anyModalPanelOpen () ) {
367
371
gui .closeGui (false );
368
372
return EventResult .interruptTrue ();
369
373
}
@@ -378,16 +382,9 @@ private EventResult addQuickWaypoint() {
378
382
if (player == null ) return EventResult .pass ();
379
383
380
384
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
391
388
return EventResult .interruptTrue ();
392
389
}).orElse (EventResult .pass ());
393
390
}
@@ -1163,10 +1160,49 @@ public int getMinimapTextureId() {
1163
1160
return minimapTextureId ;
1164
1161
}
1165
1162
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 -> {
1168
1165
Waypoint wp = mgr .addWaypointAt (position , name );
1169
1166
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
+ }
1171
1207
}
1172
1208
}
0 commit comments