Public Release

This commit is contained in:
Moulberry committed 2024-08-24 04:41:01 +08:00
1 parent 666398e480
commit 61bb497a22
126 files changed
+8435 -1240

No files matched your search

@@ -7,11 +7,18 @@ import net.minecraft.network.chat.Component;
public class BottomTextWidget extends AbstractStringWidget {
public float horizontalAlignment = 0.5f;
public BottomTextWidget(int width, int height, Component component, Font font) {
super(0, 0, width, height, component, font);
this.active = false;
}
public BottomTextWidget alignLeft() {
this.horizontalAlignment = 0.0f;
return this;
}
public void renderWidget(GuiGraphics guiGraphics, int i, int j, float f) {
Component component = this.getMessage();
@@ -19,7 +26,7 @@ public class BottomTextWidget extends AbstractStringWidget {
int width = this.getWidth();
int textWidth = font.width(component);
int x = this.getX() + Math.round((width - textWidth)/2.0f);
int x = this.getX() + Math.round((width - textWidth) * this.horizontalAlignment);
int y = this.getY() + this.getHeight() - this.getFont().lineHeight + 1;
guiGraphics.drawString(font, component.getVisualOrderText(), x, y, this.getColor());
@@ -1,11 +1,15 @@
package com.moulberry.flashback.screen;
import com.moulberry.flashback.Flashback;
import com.moulberry.flashback.configuration.FlashbackConfig;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.options.OptionsSubScreen;
import net.minecraft.network.chat.Component;
import java.nio.file.Path;
public class ConfigScreen extends OptionsSubScreen {
public ConfigScreen(Screen previous) {
@@ -14,11 +18,13 @@ public class ConfigScreen extends OptionsSubScreen {
protected void addOptions() {
if (this.list != null) {
this.list.addSmall(FlashbackConfig.createOptionInstances());
this.list.addSmall(Flashback.getConfig().createOptionInstances());
}
}
public void removed() {
Path configFolder = FabricLoader.getInstance().getConfigDir().resolve("flashback");
Flashback.getConfig().saveToFolder(configFolder);
}
}
@@ -0,0 +1,53 @@
package com.moulberry.flashback.screen;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Button;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
public class FlashbackButton extends Button {
public FlashbackButton(int x, int y, int width, int height, Component component, OnPress onPress) {
super(x, y, width, height, component, onPress, DEFAULT_NARRATION);
}
@Override
protected void renderWidget(GuiGraphics guiGraphics, int i, int j, float f) {
super.renderWidget(guiGraphics, i, j, f);
final int size = 14;
int paddingX = (this.getWidth() - size) / 2;
int paddingY = (this.getHeight() - size) / 2;
int x = this.getX() + paddingX;
int y = this.getY() + paddingY;
double guiScale = Minecraft.getInstance().getWindow().getGuiScale();
int realSize = (int)(size * guiScale);
ResourceLocation icon;
if (realSize == 14) {
icon = ResourceLocation.parse("flashback:icon_14x.png");
} else if (realSize == 28) {
icon = ResourceLocation.parse("flashback:icon_28x.png");
} else if (realSize == 42) {
icon = ResourceLocation.parse("flashback:icon_42x.png");
} else if (realSize == 56) {
icon = ResourceLocation.parse("flashback:icon_56x.png");
} else {
icon = ResourceLocation.parse("flashback:icon.png");
}
guiGraphics.blit(icon, x, y, 0f, 0f, size, size, size, size);
}
@Override
public void renderString(GuiGraphics guiGraphics, Font font, int i) {
}
}
@@ -5,13 +5,16 @@ package com.moulberry.flashback.screen;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.mojang.blaze3d.platform.NativeImage;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.logging.LogUtils;
import com.moulberry.flashback.Flashback;
import com.moulberry.flashback.FlashbackGson;
import com.moulberry.flashback.SneakyThrow;
import com.moulberry.flashback.record.FlashbackMeta;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.SharedConstants;
import net.minecraft.Util;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
@@ -48,6 +51,8 @@ public class ReplaySelectionList extends ObjectSelectionList<ReplaySelectionList
private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT).withZone(ZoneId.systemDefault());
private static final ResourceLocation ERROR_HIGHLIGHTED_SPRITE = ResourceLocation.withDefaultNamespace("world_list/error_highlighted");
private static final ResourceLocation ERROR_SPRITE = ResourceLocation.withDefaultNamespace("world_list/error");
private static final ResourceLocation WARNING_HIGHLIGHTED_SPRITE = ResourceLocation.withDefaultNamespace("world_list/warning_highlighted");
static private final ResourceLocation WARNING_SPRITE = ResourceLocation.withDefaultNamespace("world_list/warning");
private static final ResourceLocation JOIN_HIGHLIGHTED_SPRITE = ResourceLocation.withDefaultNamespace("world_list/join_highlighted");
private static final ResourceLocation JOIN_SPRITE = ResourceLocation.withDefaultNamespace("world_list/join");
private static final Logger LOGGER = LogUtils.getLogger();
@@ -58,6 +63,8 @@ public class ReplaySelectionList extends ObjectSelectionList<ReplaySelectionList
private String filter;
private final LoadingHeader loadingHeader;
private Map<UUID, Long> lastOpenTimes = null;
public ReplaySelectionList(SelectReplayScreen selectReplayScreen, Minecraft minecraft, int i, int j, int k, int l, String string, @Nullable ReplaySelectionList replaySelectionList) {
super(minecraft, i, j, k, l);
this.screen = selectReplayScreen;
@@ -125,8 +132,49 @@ public class ReplaySelectionList extends ObjectSelectionList<ReplaySelectionList
this.filter = string;
}
// private Path getOpenTimeCachePath() {
// Path flashbackDir = Flashback.getDataDirectory();
// Path replayDir = flashbackDir.resolve("replays");
// return replayDir.resolve(".lastopened.json");
// }
//
// private synchronized long getOpenTime(UUID uuid) {
// if (this.lastOpenTimes == null) {
// Path path = getOpenTimeCachePath();
//
// if (Files.exists(path)) {
// try {
// String serialized = Files.readString(path);
// TypeToken<Map<UUID, Long>> typeToken = (TypeToken<Map<UUID, Long>>) TypeToken.getParameterized(Map.class, UUID.class, Long.class);
// this.lastOpenTimes = FlashbackGson.PRETTY.fromJson(serialized, typeToken);
// return this.lastOpenTimes.getOrDefault(uuid, 0L);
// } catch (IOException e) {
// Flashback.LOGGER.error("Unable to read last opened cache", e);
// }
// }
//
// this.lastOpenTimes = new HashMap<>();
// }
//
// return this.lastOpenTimes.getOrDefault(uuid, 0L);
// }
//
// private synchronized void setOpenTime(UUID uuid, long time) {
// this.lastOpenTimes.put(uuid, time);
// }
//
// private synchronized void saveOpenTimeCache() {
// String serialized = FlashbackGson.PRETTY.toJson(this.lastOpenTimes);
// try {
// Files.writeString(getOpenTimeCachePath(), serialized, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING,
// StandardOpenOption.CREATE);
// } catch (IOException e) {
// Flashback.LOGGER.error("Unable to write last opened cache", e);
// }
// }
private CompletableFuture<List<ReplaySummary>> loadReplays() {
Path flashbackDir = FabricLoader.getInstance().getGameDir().resolve("flashback");
Path flashbackDir = Flashback.getDataDirectory();
Path replayDir = flashbackDir.resolve("replays");
if (!Files.exists(replayDir) || !Files.isDirectory(replayDir)) {
@@ -148,14 +196,12 @@ public class ReplaySelectionList extends ObjectSelectionList<ReplaySelectionList
BasicFileAttributeView attributeView = Files.getFileAttributeView(path, BasicFileAttributeView.class);
BasicFileAttributes basicFileAttributes = attributeView.readAttributes();
long lastOpened = Math.max(basicFileAttributes.creationTime().toMillis(),
Math.max(basicFileAttributes.lastAccessTime().toMillis(), basicFileAttributes.lastModifiedTime().toMillis()));
long lastModified = Math.max(basicFileAttributes.creationTime().toMillis(), basicFileAttributes.lastModifiedTime().toMillis());
byte[] iconBytes = null;
String metadataString = null;
try (FileSystem fs = FileSystems.newFileSystem(path)) {
Path iconPath = fs.getPath("/icon.png");
if (Files.exists(iconPath)) {
iconBytes = Files.readAllBytes(iconPath);
@@ -176,10 +222,10 @@ public class ReplaySelectionList extends ObjectSelectionList<ReplaySelectionList
JsonObject metadataJson = new Gson().fromJson(metadataString, JsonObject.class);
FlashbackMeta metadata = FlashbackMeta.fromJson(metadataJson);
if (metadata != null) {
return new ReplaySummary(path, metadata, fileName, lastOpened, iconBytes);
return new ReplaySummary(path, metadata, fileName, lastModified, iconBytes);
}
} catch (IOException e) {
SneakyThrow.sneakyThrow(e);
Flashback.LOGGER.error("Failed to load replay", e);
}
return null;
}, Util.backgroundExecutor()));
@@ -300,7 +346,7 @@ public class ReplaySelectionList extends ObjectSelectionList<ReplaySelectionList
@Override
public Component getNarration() {
MutableComponent component = Component.translatable("narrator.select.world_info", this.summary.getReplayName(),
Component.translationArg(new Date(this.summary.getLastPlayed())),
Component.translationArg(new Date(this.summary.getLastModified())),
this.summary.getInfo());
return Component.translatable("narrator.select", component);
}
@@ -309,7 +355,7 @@ public class ReplaySelectionList extends ObjectSelectionList<ReplaySelectionList
public void render(GuiGraphics guiGraphics, int i, int j, int k, int l, int m, int n, int o, boolean bl, float f) {
String title = this.summary.getReplayName();
String fileAndTime = this.summary.getReplayId();
long p = this.summary.getLastPlayed();
long p = this.summary.getLastModified();
if (p != -1L) {
fileAndTime = fileAndTime + " (" + DATE_FORMAT.format(Instant.ofEpochMilli(p)) + ")";
}
@@ -318,7 +364,14 @@ public class ReplaySelectionList extends ObjectSelectionList<ReplaySelectionList
}
Component info = this.summary.getInfo();
guiGraphics.drawString(this.minecraft.font, title, k + ICON_WIDTH + 3, j + 1, 0xFFFFFF, false);
int titleColour = 0xFFFFFF;
if (!this.summary.canOpen()) {
titleColour = 0xFF5555;
} else if (this.summary.hasWarning()) {
titleColour = 0xFFAA55;
}
guiGraphics.drawString(this.minecraft.font, title, k + ICON_WIDTH + 3, j + 1, titleColour, false);
guiGraphics.drawString(this.minecraft.font, fileAndTime, k + ICON_WIDTH + 3, j + this.minecraft.font.lineHeight + 3, 0xFF808080, false);
guiGraphics.drawString(this.minecraft.font, info, k + ICON_WIDTH + 3, j + this.minecraft.font.lineHeight + this.minecraft.font.lineHeight + 3, 0xFF808080, false);
@@ -329,15 +382,21 @@ public class ReplaySelectionList extends ObjectSelectionList<ReplaySelectionList
if (this.minecraft.options.touchscreen().get() || bl) {
guiGraphics.fill(k, j, k + ICON_WIDTH, j + ICON_HEIGHT, -1601138544);
int q = n - k;
boolean bl2 = q < 32;
boolean hoveredIcon = q < 32;
if (!this.summary.canOpen()) {
ResourceLocation resourceLocation3 = bl2 ? ERROR_HIGHLIGHTED_SPRITE : ERROR_SPRITE;
guiGraphics.blitSprite(resourceLocation3, k, j, ICON_WIDTH, ICON_HEIGHT);
} else {
ResourceLocation resourceLocation = bl2 ? JOIN_HIGHLIGHTED_SPRITE : JOIN_SPRITE;
guiGraphics.blitSprite(resourceLocation, k, j, ICON_WIDTH, ICON_HEIGHT);
if (bl && this.summary.getHoverInfo() != null) {
guiGraphics.renderTooltip(this.minecraft.font, this.minecraft.font.split(this.summary.getHoverInfo(), 240), n, o);
}
ResourceLocation iconOverlay;
if (!this.summary.canOpen()) {
iconOverlay = hoveredIcon ? ERROR_HIGHLIGHTED_SPRITE : ERROR_SPRITE;
} else if (this.summary.hasWarning()) {
iconOverlay = hoveredIcon ? WARNING_HIGHLIGHTED_SPRITE : WARNING_SPRITE;
} else {
iconOverlay = hoveredIcon ? JOIN_HIGHLIGHTED_SPRITE : JOIN_SPRITE;
}
guiGraphics.blitSprite(iconOverlay, k, j, ICON_WIDTH, ICON_HEIGHT);
}
}
@@ -366,6 +425,9 @@ public class ReplaySelectionList extends ObjectSelectionList<ReplaySelectionList
if (this.summary.canOpen()) {
this.minecraft.forceSetScreen(new GenericMessageScreen(Component.translatable("flashback.select_replay.data_read")));
Flashback.openReplayWorld(this.summary.getPath());
// setOpenTime(this.summary.getReplayMetadata().replayIdentifier, System.currentTimeMillis());
// saveOpenTimeCache();
}
}
@@ -398,7 +460,7 @@ public class ReplaySelectionList extends ObjectSelectionList<ReplaySelectionList
public void editReplay() {
SystemToast.add(this.minecraft.getToasts(), new SystemToast.SystemToastId(3000),
Component.literal("Sorry"), Component.literal("Editing replay data hasn't been implemented yet"));
// todo:
// todo: implement editing replay data
// EditWorldScreen editWorldScreen;
// ReplayStorageSource.ReplayStorageAccess levelStorageAccess;
// this.queueLoadScreen();
@@ -3,28 +3,56 @@
*/
package com.moulberry.flashback.screen;
import com.moulberry.flashback.editor.ui.windows.TimelineWindow;
import com.moulberry.flashback.record.FlashbackMeta;
import net.minecraft.SharedConstants;
import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.util.FormattedCharSequence;
import org.jetbrains.annotations.Nullable;
import java.nio.file.Path;
import java.util.List;
public class ReplaySummary implements Comparable<ReplaySummary> {
private final Path path;
private final FlashbackMeta metadata;
private final String replayId;
private final long lastOpened;
private final long lastModified;
private final byte[] iconBytes;
private Component info = null;
private Component hoverInfo = null;
private boolean canOpen = true;
private boolean hasWarning = false;
public ReplaySummary(Path path, FlashbackMeta metadata, String replayId, long lastOpened, @Nullable byte[] iconBytes) {
public ReplaySummary(Path path, FlashbackMeta metadata, String replayId, long lastModified, @Nullable byte[] iconBytes) {
this.path = path;
this.metadata = metadata;
this.replayId = replayId;
this.lastOpened = lastOpened;
this.lastModified = lastModified;
this.iconBytes = iconBytes;
if (metadata.protocolVersion != 0 && metadata.protocolVersion != SharedConstants.getProtocolVersion()) {
this.canOpen = false;
if (metadata.versionString != null && !metadata.versionString.equals(SharedConstants.VERSION_STRING)) {
this.hoverInfo = Component.literal("Unable to open replay\nReplay was created in " + metadata.versionString +
" and is incompatible with " + SharedConstants.VERSION_STRING);
} else {
this.hoverInfo = Component.literal("Unable to open replay\nReplay was created with protocol version " + metadata.protocolVersion +
" and is incompatible with " + SharedConstants.getProtocolVersion());
}
} else if (metadata.dataVersion != 0 && metadata.dataVersion != SharedConstants.getCurrentVersion().getDataVersion().getVersion()) {
this.hasWarning = true;
if (metadata.versionString != null && !metadata.versionString.equals(SharedConstants.VERSION_STRING)) {
this.hoverInfo = Component.literal("Important Warning\nReplay was created in " + metadata.versionString +
" and may fail to load in " + SharedConstants.VERSION_STRING);
} else {
this.hoverInfo = Component.literal("Important Warning\nReplay was created with data version " + metadata.dataVersion +
" and may fail to load with " + SharedConstants.getCurrentVersion().getDataVersion().getVersion());
}
}
}
public Path getPath() {
@@ -35,12 +63,16 @@ public class ReplaySummary implements Comparable<ReplaySummary> {
return this.replayId;
}
public FlashbackMeta getReplayMetadata() {
return this.metadata;
}
public String getReplayName() {
return this.metadata.name.isEmpty() ? this.replayId : this.metadata.name;
}
public long getLastPlayed() {
return this.lastOpened;
public long getLastModified() {
return this.lastModified;
}
public Component getInfo() {
@@ -68,6 +100,9 @@ public class ReplaySummary implements Comparable<ReplaySummary> {
}
builder.append(seconds).append('s');
}
if (builder.isEmpty()) {
builder.append("0s");
}
mutable.append(Component.translatable("flashback.select_replay.duration", builder));
}
@@ -81,16 +116,24 @@ public class ReplaySummary implements Comparable<ReplaySummary> {
return this.iconBytes;
}
public Component getHoverInfo() {
return this.hoverInfo;
}
public boolean hasWarning() {
return this.hasWarning;
}
public boolean canOpen() {
return true;
return this.canOpen;
}
@Override
public int compareTo(ReplaySummary levelSummary) {
if (this.getLastPlayed() < levelSummary.getLastPlayed()) {
if (this.getLastModified() < levelSummary.getLastModified()) {
return 1;
}
if (this.getLastPlayed() > levelSummary.getLastPlayed()) {
if (this.getLastModified() > levelSummary.getLastModified()) {
return -1;
}
return this.replayId.compareTo(levelSummary.replayId);
@@ -0,0 +1,164 @@
package com.moulberry.flashback.screen;
import com.moulberry.flashback.Flashback;
import com.moulberry.flashback.exporting.AsyncFileDialogs;
import com.moulberry.flashback.record.ReplayExporter;
import net.minecraft.FileUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.EditBox;
import net.minecraft.client.gui.components.StringWidget;
import net.minecraft.client.gui.layouts.FrameLayout;
import net.minecraft.client.gui.layouts.GridLayout;
import net.minecraft.client.gui.screens.AlertScreen;
import net.minecraft.client.gui.screens.ConfirmScreen;
import net.minecraft.client.gui.screens.PauseScreen;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import org.apache.commons.io.FileUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
public class SaveReplayScreen extends Screen {
private Path recordFolder;
private String replayName;
private Path savePath = null;
private boolean generateFileFromReplayName = true;
private Button filePathButton;
private Screen previousScreen;
public SaveReplayScreen(Screen previousScreen, Path recordFolder, String replayName) {
super(Component.literal("Save Replay"));
this.recordFolder = recordFolder;
this.setReplayName(replayName);
if (this.savePath == null) {
this.savePath = Flashback.getReplayFolder().resolve(UUID.randomUUID() + ".zip");
}
if (!(previousScreen instanceof SaveReplayScreen)) {
this.previousScreen = previousScreen;
}
}
@Override
protected void init() {
super.init();
GridLayout gridLayout = new GridLayout();
gridLayout.defaultCellSetting().padding(4, 4, 4, 0);
GridLayout.RowHelper rowHelper = gridLayout.createRowHelper(2);
rowHelper.addChild(new StringWidget(204, 20, Component.literal("Save Replay"), this.font), 2);
rowHelper.addChild(new BottomTextWidget(204, 10, Component.literal("Replay Name"), this.font).alignLeft(), 2);
EditBox replayNameEditBox = new EditBox(this.font, 0, 0, 204, 20, Component.literal(this.replayName));
replayNameEditBox.setValue(this.replayName);
replayNameEditBox.setResponder(this::setReplayName);
rowHelper.addChild(replayNameEditBox, 2);
rowHelper.addChild(new BottomTextWidget(204, 10, Component.literal("Filename"), this.font).alignLeft(), 2);
this.filePathButton = Button.builder(Component.literal(this.savePath.getFileName().toString()), button -> {
CompletableFuture<String> future = AsyncFileDialogs.saveFileDialog(this.savePath.getParent().toString(), this.savePath.getFileName().toString(),
"Replay Archive", "zip");
future.thenAccept(pathStr -> {
if (pathStr != null) {
this.savePath = Path.of(pathStr);
this.generateFileFromReplayName = false;
}
});
}).width(204).build();
rowHelper.addChild(this.filePathButton, 2);
rowHelper.addChild(new BottomTextWidget(204, 10, Component.literal(""), this.font), 2);
rowHelper.addChild(Button.builder(Component.literal("Save Replay"), button -> {
this.saveReplay();
Minecraft.getInstance().setScreen(this.previousScreen);
}).width(98).build(), 1);
rowHelper.addChild(Button.builder(Component.literal("Delete Replay"), button -> {
Minecraft.getInstance().setScreen(new ConfirmScreen(value -> {
if (value) {
this.deleteReplay();
Minecraft.getInstance().setScreen(this.previousScreen);
} else {
Minecraft.getInstance().setScreen(SaveReplayScreen.this);
}
}, Component.literal("Confirm Delete Recording"),
Component.literal("Are you sure you want to delete the recording? You won't be able to recover it")));
}).width(98).build(), 1);
gridLayout.arrangeElements();
FrameLayout.alignInRectangle(gridLayout, 0, 0, this.width, this.height, 0.5f, 0.5f);
gridLayout.visitWidgets(this::addRenderableWidget);
}
@Override
public boolean shouldCloseOnEsc() {
return false;
}
@Override
public void tick() {
super.tick();
if (!Files.exists(this.recordFolder)) {
Minecraft.getInstance().setScreen(new AlertScreen(() -> Minecraft.getInstance().setScreen(this.previousScreen),
Component.literal("Error Saving Replay"), Component.literal("Recording folder seems to be missing. Did you delete it?")));
}
}
private void saveReplay() {
if (!Files.exists(this.recordFolder)) {
Minecraft.getInstance().setScreen(new AlertScreen(() -> Minecraft.getInstance().setScreen(this.previousScreen),
Component.literal("Error Saving Replay"), Component.literal("Recording folder seems to be missing. Did you delete it?")));
return;
}
ReplayExporter.export(this.recordFolder, this.savePath, this.replayName);
Flashback.removePendingReplaySave(this.recordFolder);
}
private void deleteReplay() {
try {
FileUtils.deleteDirectory(this.recordFolder.toFile());
} catch (Exception e) {
Flashback.LOGGER.error("Exception deleting record folder", e);
}
Flashback.removePendingReplaySave(this.recordFolder);
}
private void setReplayName(String replayName) {
this.replayName = replayName;
if (!this.replayName.isEmpty() && (this.savePath == null || this.generateFileFromReplayName)) {
Path replayDir = Flashback.getReplayFolder();
String filename;
try {
filename = FileUtil.findAvailableName(replayDir, this.replayName.replace(' ', '_'), ".zip");
} catch (IOException e) {
Flashback.LOGGER.error("Error while trying to determine filename", e);
filename = UUID.randomUUID() + ".zip";
}
this.savePath = replayDir.resolve(filename);
if (this.filePathButton != null) {
this.filePathButton.setMessage(Component.literal(this.savePath.getFileName().toString()));
}
}
}
}
@@ -4,15 +4,16 @@ import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.EditBox;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import org.jetbrains.annotations.Nullable;
public class SelectReplayScreen extends Screen {
protected final Screen lastScreen;
private Button deleteButton;
private Button selectButton;
private Button editButton;
private Button deleteButton;
protected EditBox searchBox;
private ReplaySelectionList list;
@@ -26,14 +27,16 @@ public class SelectReplayScreen extends Screen {
this.searchBox = new EditBox(this.font, this.width / 2 - 100, 22, 200, 20, this.searchBox, Component.translatable("selectWorld.search"));
this.searchBox.setResponder(string -> this.list.updateFilter(string));
this.addWidget(this.searchBox);
this.list = this.addRenderableWidget(new ReplaySelectionList(this, this.minecraft,
this.list = this.addRenderableWidget(new ReplaySelectionList(this, this.minecraft,
this.width, this.height - 112, 48, 36, this.searchBox.getValue(), this.list));
this.selectButton = this.addRenderableWidget(Button.builder(Component.translatable("flashback.select_replay.open"), this::tryOpenReplay)
.bounds(this.width / 2 - 150, this.height - 52, 300, 20).build());
.bounds(this.width / 2 - 154, this.height - 52, 308, 20).build());
this.editButton = this.addRenderableWidget(Button.builder(Component.translatable("selectWorld.edit"), this::tryEditReplay)
.bounds(this.width / 2 - 150, this.height - 28, 146, 20).build());
.bounds(this.width / 2 - 154, this.height - 28, 150, 20).build());
this.deleteButton = this.addRenderableWidget(Button.builder(Component.translatable("selectWorld.delete"), this::tryDeleteReplay)
.bounds(this.width / 2 + 4, this.height - 28, 146, 20).build());
.bounds(this.width / 2 + 4, this.height - 28, 72, 20).build());
this.addRenderableWidget(Button.builder(CommonComponents.GUI_BACK, button -> this.minecraft.setScreen(this.lastScreen))
.bounds(this.width / 2 + 82, this.height - 28, 72, 20).build());
this.updateButtonStatus(null);
}