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

2
jGui

Submodule jGui updated: 6b16892d64...424959c6d6

View File

@@ -245,18 +245,10 @@ public class Utils {
logger.trace("Opening crash report popup GUI"); logger.trace("Opening crash report popup GUI");
GuiCrashReportPopup popup = new GuiCrashReportPopup(container, crashReportStr); GuiCrashReportPopup popup = new GuiCrashReportPopup(container, crashReportStr);
Futures.addCallback(popup.getFuture(), new FutureCallback<Void>() { popup.onClosed(() -> {
@Override logger.trace("Crash report popup closed");
public void onSuccess(@Nullable Void result) { if (onClose != null) {
logger.trace("Crash report popup closed"); onClose.run();
if (onClose != null) {
onClose.run();
}
}
@Override
public void onFailure(Throwable t) {
logger.error("During error popup:", t);
} }
}); });
return popup; return popup;
@@ -329,18 +321,10 @@ public class Utils {
LOGGER.trace("Minimal mode active, denying action, opening popup"); LOGGER.trace("Minimal mode active, denying action, opening popup");
MinimalModeUnsupportedPopup popup = new MinimalModeUnsupportedPopup(container); MinimalModeUnsupportedPopup popup = new MinimalModeUnsupportedPopup(container);
Futures.addCallback(popup.getFuture(), new FutureCallback<Void>() { popup.onClosed(() -> {
@Override LOGGER.trace("Minimal mode popup closed");
public void onSuccess(@Nullable Void result) { if (onPopupClosed != null) {
LOGGER.trace("Minimal mode popup closed"); onPopupClosed.run();
if (onPopupClosed != null) {
onPopupClosed.run();
}
}
@Override
public void onFailure(Throwable t) {
LOGGER.error("During minimal mode popup:", t);
} }
}); });
return false; return false;

View File

@@ -53,13 +53,13 @@ public class PlayerOverviewGui extends GuiScreen implements Closeable {
public final GuiCheckbox checkAll = new GuiCheckbox(contentPanel){ public final GuiCheckbox checkAll = new GuiCheckbox(contentPanel){
@Override @Override
public void onClick() { public void onClick() {
playersScrollable.forEach(IGuiCheckbox.class).setChecked(true); playersScrollable.invokeAll(IGuiCheckbox.class, e -> e.setChecked(true));
} }
}.setLabel("").setChecked(true).setTooltip(new GuiTooltip().setI18nText("replaymod.gui.playeroverview.showall")); }.setLabel("").setChecked(true).setTooltip(new GuiTooltip().setI18nText("replaymod.gui.playeroverview.showall"));
public final GuiCheckbox uncheckAll = new GuiCheckbox(contentPanel){ public final GuiCheckbox uncheckAll = new GuiCheckbox(contentPanel){
@Override @Override
public void onClick() { public void onClick() {
playersScrollable.forEach(IGuiCheckbox.class).setChecked(false); playersScrollable.invokeAll(IGuiCheckbox.class, e -> e.setChecked(false));
} }
}.setLabel("").setChecked(false).setTooltip(new GuiTooltip().setI18nText("replaymod.gui.playeroverview.hideall")); }.setLabel("").setChecked(false).setTooltip(new GuiTooltip().setI18nText("replaymod.gui.playeroverview.hideall"));

View File

@@ -31,7 +31,6 @@ import net.minecraft.util.Util;
//$$ import org.lwjgl.Sys; //$$ import org.lwjgl.Sys;
//#endif //#endif
import javax.annotation.Nullable;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import javax.imageio.ImageReader; import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream; import javax.imageio.stream.ImageInputStream;
@@ -116,36 +115,27 @@ public class GuiYoutubeUpload extends GuiScreen {
public final GuiButton thumbnailButton = new GuiButton().onClick(new Runnable() { public final GuiButton thumbnailButton = new GuiButton().onClick(new Runnable() {
@Override @Override
public void run() { public void run() {
Futures.addCallback( GuiFileChooserPopup.openLoadGui(
GuiFileChooserPopup.openLoadGui(GuiYoutubeUpload.this, "replaymod.gui.load", GuiYoutubeUpload.this,
ImageIO.getReaderFileSuffixes()).getFuture(), "replaymod.gui.load",
new FutureCallback<File>() { ImageIO.getReaderFileSuffixes()
@Override ).onAccept(file -> {
public void onSuccess(@Nullable File result) { thumbnailButton.setLabel(file.getName());
if (result != null) { Image image;
thumbnailButton.setLabel(result.getName()); try {
Image image; thumbnailImage = IOUtils.toByteArray(new FileInputStream(file));
try { ImageInputStream in = ImageIO.createImageInputStream(new ByteArrayInputStream(thumbnailImage));
thumbnailImage = IOUtils.toByteArray(new FileInputStream(result)); ImageReader reader = ImageIO.getImageReaders(in).next();
ImageInputStream in = ImageIO.createImageInputStream(new ByteArrayInputStream(thumbnailImage)); thumbnailFormat = reader.getFormatName().toLowerCase();
ImageReader reader = ImageIO.getImageReaders(in).next(); image = Image.read(new ByteArrayInputStream(thumbnailImage));
thumbnailFormat = reader.getFormatName().toLowerCase(); } catch (Throwable t) {
image = Image.read(new ByteArrayInputStream(thumbnailImage)); t.printStackTrace();
} catch (Throwable t) { thumbnailImage = null;
t.printStackTrace(); image = null;
thumbnailImage = null; }
image = null; thumbnail.setTexture(image);
} inputValidation.run();
thumbnail.setTexture(image); });
inputValidation.run();
}
}
@Override
public void onFailure(Throwable t) {
throw new RuntimeException(t);
}
});
} }
}).setSize(200, 20).setI18nLabel("replaymod.gui.videothumbnail"); }).setSize(200, 20).setI18nLabel("replaymod.gui.videothumbnail");
@@ -191,7 +181,7 @@ public class GuiYoutubeUpload extends GuiScreen {
} }
private void setState(boolean uploading) { private void setState(boolean uploading) {
forEach(GuiElement.class).setEnabled(!uploading); invokeAll(GuiElement.class, e -> e.setEnabled(!uploading));
uploadButton.setEnabled(); uploadButton.setEnabled();
if (uploading) { if (uploading) {
uploadButton.onClick(() -> { uploadButton.onClick(() -> {

View File

@@ -65,18 +65,15 @@ public class GuiKeyframeRepository extends GuiScreen implements Closeable, Typea
public final GuiButton overwriteButton = new GuiButton().onClick(new Runnable() { public final GuiButton overwriteButton = new GuiButton().onClick(new Runnable() {
@Override @Override
public void run() { public void run() {
GuiYesNoPopup popup = GuiYesNoPopup.open(GuiKeyframeRepository.this, GuiYesNoPopup.open(GuiKeyframeRepository.this,
new GuiLabel().setI18nText("replaymod.gui.keyframerepo.overwrite").setColor(Colors.BLACK) new GuiLabel().setI18nText("replaymod.gui.keyframerepo.overwrite").setColor(Colors.BLACK)
).setYesI18nLabel("gui.yes").setNoI18nLabel("gui.no"); ).setYesI18nLabel("gui.yes").setNoI18nLabel("gui.no").onAccept(() -> {
Utils.addCallback(popup.getFuture(), doIt -> { for (Entry entry : selectedEntries) {
if (doIt) { timelines.put(entry.name, currentTimeline);
for (Entry entry : selectedEntries) {
timelines.put(entry.name, currentTimeline);
}
overwriteButton.setDisabled();
save();
} }
}, Throwable::printStackTrace); overwriteButton.setDisabled();
save();
});
} }
}).setSize(75, 20).setI18nLabel("replaymod.gui.overwrite").setDisabled(); }).setSize(75, 20).setI18nLabel("replaymod.gui.overwrite").setDisabled();
public final GuiButton saveAsButton = new GuiButton().onClick(new Runnable() { public final GuiButton saveAsButton = new GuiButton().onClick(new Runnable() {
@@ -103,21 +100,11 @@ public class GuiKeyframeRepository extends GuiScreen implements Closeable, Typea
&& !timelines.containsKey(nameField.getText())); && !timelines.containsKey(nameField.getText()));
} }
}); });
Futures.addCallback(popup.getFuture(), new FutureCallback<Boolean>() { popup.onAccept(() -> {
@Override String name = nameField.getText();
public void onSuccess(Boolean save) { timelines.put(name, currentTimeline);
if (save) { list.getListPanel().addElements(null, new Entry(name));
String name = nameField.getText(); save();
timelines.put(name, currentTimeline);
list.getListPanel().addElements(null, new Entry(name));
save();
}
}
@Override
public void onFailure(Throwable t) {
t.printStackTrace();
}
}); });
} }
}).setSize(75, 20).setI18nLabel("replaymod.gui.saveas"); }).setSize(75, 20).setI18nLabel("replaymod.gui.saveas");
@@ -161,50 +148,29 @@ public class GuiKeyframeRepository extends GuiScreen implements Closeable, Typea
&& !timelines.containsKey(nameField.getText())); && !timelines.containsKey(nameField.getText()));
} }
}); });
Futures.addCallback(popup.getFuture(), new FutureCallback<Boolean>() { popup.onAccept(() -> {
@Override String name = nameField.getText();
public void onSuccess(Boolean save) { timelines.put(name, timelines.remove(selectedEntry.name));
if (save) { selectedEntry.name = name;
String name = nameField.getText(); selectedEntry.label.setText(name);
timelines.put(name, timelines.remove(selectedEntry.name)); save();
selectedEntry.name = name;
selectedEntry.label.setText(name);
save();
}
}
@Override
public void onFailure(Throwable t) {
t.printStackTrace();
}
}); });
} }
}).setSize(75, 20).setI18nLabel("replaymod.gui.rename").setDisabled(); }).setSize(75, 20).setI18nLabel("replaymod.gui.rename").setDisabled();
public final GuiButton removeButton = new GuiButton().onClick(new Runnable() { public final GuiButton removeButton = new GuiButton().onClick(new Runnable() {
@Override @Override
public void run() { public void run() {
GuiYesNoPopup popup = GuiYesNoPopup.open(GuiKeyframeRepository.this, GuiYesNoPopup.open(GuiKeyframeRepository.this,
new GuiLabel().setI18nText("replaymod.gui.keyframerepo.delete").setColor(Colors.BLACK) new GuiLabel().setI18nText("replaymod.gui.keyframerepo.delete").setColor(Colors.BLACK)
).setYesI18nLabel("replaymod.gui.delete").setNoI18nLabel("replaymod.gui.cancel"); ).setYesI18nLabel("replaymod.gui.delete").setNoI18nLabel("replaymod.gui.cancel").onAccept(() -> {
Futures.addCallback(popup.getFuture(), new FutureCallback<Boolean>() { for (Entry entry : selectedEntries) {
@Override timelines.remove(entry.name);
public void onSuccess(Boolean delete) { list.getListPanel().removeElement(entry);
if (delete) {
for (Entry entry : selectedEntries) {
timelines.remove(entry.name);
list.getListPanel().removeElement(entry);
}
selectedEntries.clear();
updateButtons();
save();
}
} }
@Override selectedEntries.clear();
public void onFailure(Throwable t) { updateButtons();
t.printStackTrace(); save();
}
}); });
} }
}).setSize(75, 20).setI18nLabel("replaymod.gui.remove").setDisabled(); }).setSize(75, 20).setI18nLabel("replaymod.gui.remove").setDisabled();

View File

@@ -1,8 +1,6 @@
package com.replaymod.render.gui; package com.replaymod.render.gui;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.google.gson.InstanceCreator; import com.google.gson.InstanceCreator;
@@ -39,7 +37,6 @@ import net.minecraft.client.gui.screen.NoticeScreen;
import net.minecraft.client.resource.language.I18n; import net.minecraft.client.resource.language.I18n;
import net.minecraft.util.crash.CrashReport; import net.minecraft.util.crash.CrashReport;
import javax.annotation.Nullable;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
@@ -131,25 +128,13 @@ public class GuiRenderSettings extends AbstractGuiPopup<GuiRenderSettings> {
encodingPresetDropdown.getSelectedValue().getFileExtension()); encodingPresetDropdown.getSelectedValue().getFileExtension());
popup.setFolder(outputFile.getParentFile()); popup.setFolder(outputFile.getParentFile());
popup.setFileName(outputFile.getName()); popup.setFileName(outputFile.getName());
Futures.addCallback( popup.onAccept(file -> {
popup.getFuture(), if (!file.getName().equals(outputFile.getName())) {
new FutureCallback<File>() { userDefinedOutputFileName = true;
@Override }
public void onSuccess(@Nullable File result) { outputFile = file;
if (result != null) { outputFileButton.setLabel(file.getName());
if (!result.getName().equals(outputFile.getName())) { });
userDefinedOutputFileName = true;
}
outputFile = result;
outputFileButton.setLabel(result.getName());
}
}
@Override
public void onFailure(Throwable t) {
throw new RuntimeException(t);
}
});
} }
}); });
@@ -401,10 +386,10 @@ public class GuiRenderSettings extends AbstractGuiPopup<GuiRenderSettings> {
case CUBIC: case CUBIC:
case EQUIRECTANGULAR: case EQUIRECTANGULAR:
case ODS: case ODS:
stabilizePanel.forEach(IGuiCheckbox.class).setEnabled(); stabilizePanel.invokeAll(IGuiCheckbox.class, GuiElement::setEnabled);
break; break;
default: default:
stabilizePanel.forEach(IGuiCheckbox.class).setDisabled(); stabilizePanel.invokeAll(IGuiCheckbox.class, GuiElement::setDisabled);
} }
// Enable/Disable Spherical FOV slider // Enable/Disable Spherical FOV slider

View File

@@ -93,7 +93,7 @@ public class GuiEditMarkerPopup extends AbstractGuiPopup<GuiEditMarkerPopup> imp
popup.setLayout(new VerticalLayout().setSpacing(5)) popup.setLayout(new VerticalLayout().setSpacing(5))
.addElements(new VerticalLayout.Data(0.5), title, inputs, buttons); .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())); nameField.setText(Strings.nullToEmpty(marker.getName()));
timeField.setValue(marker.getTime()); timeField.setValue(marker.getTime());

View File

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

View File

@@ -155,7 +155,7 @@ public abstract class GuiEditKeyframe<T extends GuiEditKeyframe<T>> extends Abst
link(timeMinField, timeSecField, timeMSecField); link(timeMinField, timeSecField, timeMSecField);
popup.forEach(IGuiLabel.class).setColor(Colors.BLACK); popup.invokeAll(IGuiLabel.class, e -> e.setColor(Colors.BLACK));
} }
@Override @Override
@@ -194,7 +194,7 @@ public abstract class GuiEditKeyframe<T extends GuiEditKeyframe<T>> extends Abst
link(timestampMinField, timestampSecField, timestampMSecField, timeMinField, timeSecField, timeMSecField); link(timestampMinField, timestampSecField, timestampMSecField, timeMinField, timeSecField, timeMSecField);
popup.forEach(IGuiLabel.class).setColor(Colors.BLACK); popup.invokeAll(IGuiLabel.class, e -> e.setColor(Colors.BLACK));
} }
@Override @Override
@@ -252,7 +252,7 @@ public abstract class GuiEditKeyframe<T extends GuiEditKeyframe<T>> extends Abst
link(xField, yField, zField, yawField, pitchField, rollField, timeMinField, timeSecField, timeMSecField); link(xField, yField, zField, yawField, pitchField, rollField, timeMinField, timeSecField, timeMSecField);
popup.forEach(IGuiLabel.class).setColor(Colors.BLACK); popup.invokeAll(IGuiLabel.class, e -> e.setColor(Colors.BLACK));
} }
@Override @Override

View File

@@ -399,23 +399,12 @@ public class GuiPathing {
} }
public void clearKeyframesButtonPressed() { public void clearKeyframesButtonPressed() {
GuiYesNoPopup popup = GuiYesNoPopup.open(replayHandler.getOverlay(), GuiYesNoPopup.open(replayHandler.getOverlay(),
new GuiLabel().setI18nText("replaymod.gui.clearcallback.title").setColor(Colors.BLACK) new GuiLabel().setI18nText("replaymod.gui.clearcallback.title").setColor(Colors.BLACK)
).setYesI18nLabel("gui.yes").setNoI18nLabel("gui.no"); ).setYesI18nLabel("gui.yes").setNoI18nLabel("gui.no").onAccept(() -> {
Futures.addCallback(popup.getFuture(), new FutureCallback<Boolean>() { mod.clearCurrentTimeline();
@Override if (entityTracker != null) {
public void onSuccess(Boolean delete) { mod.getCurrentTimeline().setEntityTracker(entityTracker);
if (delete) {
mod.clearCurrentTimeline();
if (entityTracker != null) {
mod.getCurrentTimeline().setEntityTracker(entityTracker);
}
}
}
@Override
public void onFailure(Throwable t) {
t.printStackTrace();
} }
}); });
} }