Skip to content

Commit

Permalink
Merge pull request #278 from FTBTeam/1.20.1/dev
Browse files Browse the repository at this point in the history
1.20.1/dev
  • Loading branch information
desht authored Apr 16, 2024
2 parents 6b790ca + d47cdb0 commit 349944c
Show file tree
Hide file tree
Showing 11 changed files with 246 additions and 99 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2001.3.0]

### Changed
* Significant GUI overhaul and cleanup in several places (backported improvements from 1.20.4)
* FTB Library 2001.2.0 is a requirement

## [2001.2.7]

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
import dev.ftb.mods.ftbchunks.FTBChunks;
import dev.ftb.mods.ftbchunks.FTBChunksWorldConfig;
import dev.ftb.mods.ftbchunks.api.FTBChunksAPI;
import dev.ftb.mods.ftbchunks.api.client.FTBChunksClientAPI;
import dev.ftb.mods.ftbchunks.api.client.event.MapIconEvent;
import dev.ftb.mods.ftbchunks.api.client.icon.MapIcon;
import dev.ftb.mods.ftbchunks.api.client.icon.MapType;
import dev.ftb.mods.ftbchunks.api.client.icon.WaypointIcon;
import dev.ftb.mods.ftbchunks.api.client.waypoint.Waypoint;
import dev.ftb.mods.ftbchunks.client.gui.AddWaypointOverlay;
import dev.ftb.mods.ftbchunks.client.gui.ChunkScreen;
import dev.ftb.mods.ftbchunks.client.gui.LargeMapScreen;
import dev.ftb.mods.ftbchunks.client.gui.WaypointEditorScreen;
Expand All @@ -32,16 +32,20 @@
import dev.ftb.mods.ftbchunks.client.mapicon.*;
import dev.ftb.mods.ftbchunks.net.PartialPackets;
import dev.ftb.mods.ftbchunks.net.SendGeneralDataPacket.GeneralChunkData;
import dev.ftb.mods.ftblibrary.config.ColorConfig;
import dev.ftb.mods.ftblibrary.config.StringConfig;
import dev.ftb.mods.ftblibrary.config.ui.EditConfigFromStringScreen;
import dev.ftb.mods.ftblibrary.config.ui.EditStringConfigOverlay;
import dev.ftb.mods.ftblibrary.icon.Color4I;
import dev.ftb.mods.ftblibrary.icon.FaceIcon;
import dev.ftb.mods.ftblibrary.icon.Icon;
import dev.ftb.mods.ftblibrary.math.MathUtils;
import dev.ftb.mods.ftblibrary.math.XZ;
import dev.ftb.mods.ftblibrary.snbt.SNBTCompoundTag;
import dev.ftb.mods.ftblibrary.ui.BaseScreen;
import dev.ftb.mods.ftblibrary.ui.CustomClickEvent;
import dev.ftb.mods.ftblibrary.ui.GuiHelper;
import dev.ftb.mods.ftblibrary.ui.Theme;
import dev.ftb.mods.ftblibrary.ui.input.Key;
import dev.ftb.mods.ftblibrary.util.StringUtils;
import dev.ftb.mods.ftblibrary.util.client.ClientUtils;
Expand Down Expand Up @@ -363,7 +367,7 @@ public EventResult keyPressed(Minecraft client, int keyCode, int scanCode, int a
public EventResult keyPressed(Minecraft client, Screen screen, int keyCode, int scanCode, int modifiers) {
if (doesKeybindMatch(openMapKey, keyCode, scanCode, modifiers)) {
LargeMapScreen gui = ClientUtils.getCurrentGuiAs(LargeMapScreen.class);
if (gui != null) {
if (gui != null && !gui.anyModalPanelOpen()) {
gui.closeGui(false);
return EventResult.interruptTrue();
}
Expand All @@ -378,16 +382,9 @@ private EventResult addQuickWaypoint() {
if (player == null) return EventResult.pass();

return MapManager.getInstance().map(manager -> {
new EditConfigFromStringScreen<>(name, set -> {
if (set && !name.getValue().isEmpty()) {
MapDimension mapDimension = manager.getDimension(player.level().dimension());
WaypointImpl waypoint = new WaypointImpl(WaypointType.DEFAULT, mapDimension, player.blockPosition())
.setName(name.getValue())
.setColor(Color4I.hsb(MathUtils.RAND.nextFloat(), 1F, 1F).rgba());
mapDimension.getWaypointManager().add(waypoint);
}
openGui();
}).openGuiLater(); // later needed to prevent keypress being passed into gui
BaseScreen screen = new WaypointAddScreen(name, player);
screen.openGuiLater();
// later needed to prevent keypress being passed into gui
return EventResult.interruptTrue();
}).orElse(EventResult.pass());
}
Expand Down Expand Up @@ -1163,10 +1160,49 @@ public int getMinimapTextureId() {
return minimapTextureId;
}

public static void addWaypoint(Player player, String name, BlockPos position, int color) {
FTBChunksAPI.clientApi().getWaypointManager(player.level().dimension()).ifPresent(mgr -> {
public static Waypoint addWaypoint(Player player, String name, BlockPos position, int color) {
return FTBChunksAPI.clientApi().getWaypointManager(player.level().dimension()).map(mgr -> {
Waypoint wp = mgr.addWaypointAt(position, name);
wp.setColor(color);
});
return wp;
}).orElse(null);
}

private static class WaypointAddScreen extends BaseScreen {
private final StringConfig name;
private final Player player;

public WaypointAddScreen(StringConfig name, Player player) {
super();
this.name = name;
this.player = player;
this.setHeight(35);
}

@Override
public void drawBackground(GuiGraphics graphics, Theme theme, int x, int y, int w, int h) {
}

@Override
public void addWidgets() {
ColorConfig col = new ColorConfig();
col.setValue(Color4I.hsb(MathUtils.RAND.nextFloat(), 1F, 1F));
AddWaypointOverlay overlay = new AddWaypointOverlay(this, name, col, set -> {
if (set && !name.getValue().isEmpty()) {
Waypoint wp = addWaypoint(player, name.getValue(), player.blockPosition(), col.getValue().rgba());
Minecraft.getInstance().player.displayClientMessage(
Component.translatable("ftbchunks.waypoint_added",
Component.literal(wp.getName()).withStyle(ChatFormatting.YELLOW)
), true);
}
}) {
@Override
public void onClosed() {
closeGui();
}
};
overlay.setWidth(this.width);
pushModalPanel(overlay);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package dev.ftb.mods.ftbchunks.client.gui;

import dev.ftb.mods.ftblibrary.config.ColorConfig;
import dev.ftb.mods.ftblibrary.config.ConfigCallback;
import dev.ftb.mods.ftblibrary.config.ConfigFromString;
import dev.ftb.mods.ftblibrary.config.ui.EditStringConfigOverlay;
import dev.ftb.mods.ftblibrary.icon.Color4I;
import dev.ftb.mods.ftblibrary.icon.Icon;
import dev.ftb.mods.ftblibrary.ui.*;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component;

public class AddWaypointOverlay extends EditStringConfigOverlay<String> {
private final ColorButton colorButton;

public AddWaypointOverlay(Panel panel, ConfigFromString<String> config, ColorConfig colorConfig, ConfigCallback callback) {
super(panel, config, callback, Component.translatable("ftbchunks.gui.add_waypoint"));

colorButton = new ColorButton(colorConfig.getValue(), (btn, mb) -> {
ColorSelectorPanel.popupAtMouse(getGui(), colorConfig, accepted -> {
if (accepted) {
btn.setIcon(colorConfig.getValue());
} else {
colorConfig.setValue(((ColorButton) btn).getIcon());
}
});
});
}

@Override
public void addWidgets() {
super.addWidgets();
add(colorButton);
}

@Override
public void alignWidgets() {
super.alignWidgets();
colorButton.setPosAndSize(width - 11, 1, 10, 10);
}

private class ColorButton extends SimpleButton {
public ColorButton(Icon icon, Callback c) {
super(AddWaypointOverlay.this, Component.empty(), icon, c);
}

Color4I getIcon() {
return icon instanceof Color4I c ? c : Color4I.empty();
}

@Override
public void draw(GuiGraphics graphics, Theme theme, int x, int y, int w, int h) {
icon.draw(graphics, x, y, w, h);
Color4I shade = getIcon().addBrightness(-0.15f);
GuiHelper.drawHollowRect(graphics, x, y, w, h, shade, false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import dev.ftb.mods.ftblibrary.ui.*;
import dev.ftb.mods.ftblibrary.ui.input.Key;
import dev.ftb.mods.ftblibrary.ui.input.MouseButton;
import dev.ftb.mods.ftblibrary.ui.misc.KeyReferenceScreen;
import dev.ftb.mods.ftblibrary.util.TimeUtils;
import dev.ftb.mods.ftblibrary.util.TooltipList;
import dev.ftb.mods.ftbteams.api.property.TeamProperties;
Expand Down Expand Up @@ -92,6 +93,7 @@ public void addWidgets() {
int startX = chunkPos.x - FTBChunks.TILE_OFFSET;
int startZ = chunkPos.z - FTBChunks.TILE_OFFSET;

chunkButtons.clear();
for (int z = 0; z < FTBChunks.TILES; z++) {
for (int x = 0; x < FTBChunks.TILES; x++) {
ChunkButton button = new ChunkButton(this, XZ.of(startX + x, startZ + z));
Expand All @@ -104,9 +106,14 @@ public void addWidgets() {
new RequestMapDataPacket(chunkPos.x - FTBChunks.TILE_OFFSET, chunkPos.z - FTBChunks.TILE_OFFSET,
chunkPos.x + FTBChunks.TILE_OFFSET, chunkPos.z + FTBChunks.TILE_OFFSET
).sendToServer();

add(new SimpleButton(this, Component.translatable("ftbchunks.gui.large_map"), Icons.MAP,
(simpleButton, mouseButton) -> LargeMapScreen.openMap()
).setPosAndSize(1, 1, 16, 16));

add(new SimpleButton(this, Component.translatable("ftbchunks.gui.chunk_info"), Icons.INFO,
(btn, mb) -> new ChunkMouseReferenceScreen().openGui()
).setPosAndSize(1, 19, 16, 16));
}

@Override
Expand Down Expand Up @@ -170,6 +177,17 @@ public void drawBackground(GuiGraphics graphics, Theme theme, int x, int y, int
}
}

private static class ChunkMouseReferenceScreen extends KeyReferenceScreen {
public ChunkMouseReferenceScreen() {
super("ftbchunks.gui.chunk_info.text");
}

@Override
public Component getTitle() {
return Component.translatable("ftbchunks.gui.chunk_info");
}
}

private class ChunkButton extends Button {
private final XZ chunkPos;
private final MapChunk chunk;
Expand Down Expand Up @@ -258,24 +276,7 @@ public boolean mouseScrolled(double scroll) {
int dir = (int) Math.signum(scroll);
long now = System.currentTimeMillis();
Date expiry = chunk.getForceLoadExpiryDate().orElse(new Date(now));
long offset = (expiry.getTime() - now) / 1000L;
if (dir == 1) {
if (offset < 86400L) {
offset = offset + 3600L; // hour
} else if (offset < 604800L) {
offset = offset + 86400L; // day
} else {
offset = offset + 604800L; // week
}
} else if (dir == -1) {
if (offset <= 86400L) {
offset = Math.max(0L, offset - 3600L);
} else if (offset <= 604800L) {
offset = Math.max(86400L, offset - 86400L);
} else {
offset = Math.max(604800L, offset - 604800L);
}
}
long offset = calcOffset(expiry, now, dir);
chunk.updateForceLoadExpiryDate(now, offset * 1000L);
lastAdjust = now;
return true;
Expand All @@ -284,6 +285,28 @@ public boolean mouseScrolled(double scroll) {
}).orElse(super.mouseScrolled(scroll));
}

private static long calcOffset(Date expiry, long now, int dir) {
long offset = (expiry.getTime() - now) / 1000L;
if (dir == 1) {
if (offset < 86400L) {
offset = offset + 3600L; // hour
} else if (offset < 604800L) {
offset = offset + 86400L; // day
} else {
offset = offset + 604800L; // week
}
} else if (dir == -1) {
if (offset <= 86400L) {
offset = Math.max(0L, offset - 3600L);
} else if (offset <= 604800L) {
offset = Math.max(86400L, offset - 86400L);
} else {
offset = Math.max(604800L, offset - 604800L);
}
}
return offset;
}

@Override
public void tick() {
super.tick();
Expand Down
Loading

0 comments on commit 349944c

Please sign in to comment.