Update jGui

This commit is contained in:
Jonas Herzig
2020-11-07 13:18:10 +01:00
parent 6308b8a859
commit ec862f0596
10 changed files with 108 additions and 217 deletions

View File

@@ -93,7 +93,7 @@ public class GuiEditMarkerPopup extends AbstractGuiPopup<GuiEditMarkerPopup> imp
popup.setLayout(new VerticalLayout().setSpacing(5))
.addElements(new VerticalLayout.Data(0.5), title, inputs, buttons);
popup.forEach(IGuiLabel.class).setColor(Colors.BLACK);
popup.invokeAll(IGuiLabel.class, e -> e.setColor(Colors.BLACK));
nameField.setText(Strings.nullToEmpty(marker.getName()));
timeField.setValue(marker.getTime());

View File

@@ -1,8 +1,5 @@
package com.replaymod.replay.gui.screen;
import com.google.common.base.Supplier;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.SettableFuture;
import com.replaymod.render.gui.GuiRenderQueue;
import com.replaymod.render.rendering.VideoRenderer;
@@ -63,6 +60,7 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import static com.replaymod.replay.ReplayModReplay.LOGGER;
@@ -151,67 +149,46 @@ public class GuiReplayViewer extends GuiScreen {
popup.getYesButton().setEnabled(!nameField.getText().isEmpty()
&& !new File(file.getParentFile(), Utils.replayNameToFileName(nameField.getText())).exists());
});
Futures.addCallback(popup.getFuture(), new FutureCallback<Boolean>() {
@Override
public void onSuccess(Boolean delete) {
if (delete) {
// Sanitize their input
String name = nameField.getText().trim();
// This file is what they want
File targetFile = new File(file.getParentFile(), Utils.replayNameToFileName(name));
try {
// Finally, try to move it
FileUtils.moveFile(file, targetFile);
} catch (IOException e) {
// We failed (might also be their OS)
e.printStackTrace();
getMinecraft().openScreen(new NoticeScreen(
//#if MC>=11400
GuiReplayViewer.this::display,
new TranslatableText("replaymod.gui.viewer.delete.failed1"),
new TranslatableText("replaymod.gui.viewer.delete.failed2")
//#else
//$$ I18n.format("replaymod.gui.viewer.delete.failed1"),
//$$ I18n.format("replaymod.gui.viewer.delete.failed2")
//#endif
));
return;
}
list.load();
}
}
@Override
public void onFailure(Throwable t) {
t.printStackTrace();
popup.onAccept(() -> {
// Sanitize their input
String newName = nameField.getText().trim();
// This file is what they want
File targetFile = new File(file.getParentFile(), Utils.replayNameToFileName(newName));
try {
// Finally, try to move it
FileUtils.moveFile(file, targetFile);
} catch (IOException e) {
// We failed (might also be their OS)
e.printStackTrace();
getMinecraft().openScreen(new NoticeScreen(
//#if MC>=11400
GuiReplayViewer.this::display,
new TranslatableText("replaymod.gui.viewer.delete.failed1"),
new TranslatableText("replaymod.gui.viewer.delete.failed2")
//#else
//$$ I18n.format("replaymod.gui.viewer.delete.failed1"),
//$$ I18n.format("replaymod.gui.viewer.delete.failed2")
//#endif
));
return;
}
list.load();
});
}
}).setSize(73, 20).setI18nLabel("replaymod.gui.rename").setDisabled();
public final GuiButton deleteButton = new GuiButton().onClick(() -> {
for (GuiReplayEntry entry : list.getSelected()) {
String name = entry.name.getText();
GuiYesNoPopup popup = GuiYesNoPopup.open(GuiReplayViewer.this,
GuiYesNoPopup.open(GuiReplayViewer.this,
new GuiLabel().setI18nText("replaymod.gui.viewer.delete.linea").setColor(Colors.BLACK),
new GuiLabel().setI18nText("replaymod.gui.viewer.delete.lineb", name + Formatting.RESET).setColor(Colors.BLACK)
).setYesI18nLabel("replaymod.gui.delete").setNoI18nLabel("replaymod.gui.cancel");
Futures.addCallback(popup.getFuture(), new FutureCallback<Boolean>() {
@Override
public void onSuccess(Boolean delete) {
if (delete) {
try {
FileUtils.forceDelete(entry.file);
} catch (IOException e) {
e.printStackTrace();
}
list.load();
}
}
@Override
public void onFailure(Throwable t) {
t.printStackTrace();
).setYesI18nLabel("replaymod.gui.delete").setNoI18nLabel("replaymod.gui.cancel").onAccept(() -> {
try {
FileUtils.forceDelete(entry.file);
} catch (IOException e) {
e.printStackTrace();
}
list.load();
});
}
}).setSize(73, 20).setI18nLabel("replaymod.gui.delete").setDisabled();