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,19 +245,11 @@ 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
public void onSuccess(@Nullable Void result) {
logger.trace("Crash report popup closed"); logger.trace("Crash report popup closed");
if (onClose != null) { if (onClose != null) {
onClose.run(); onClose.run();
} }
}
@Override
public void onFailure(Throwable t) {
logger.error("During error popup:", t);
}
}); });
return popup; return popup;
} }
@@ -329,19 +321,11 @@ 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
public void onSuccess(@Nullable Void result) {
LOGGER.trace("Minimal mode popup closed"); LOGGER.trace("Minimal mode popup closed");
if (onPopupClosed != null) { if (onPopupClosed != null) {
onPopupClosed.run(); 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,17 +115,15 @@ 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) {
thumbnailButton.setLabel(result.getName());
Image image; Image image;
try { try {
thumbnailImage = IOUtils.toByteArray(new FileInputStream(result)); thumbnailImage = IOUtils.toByteArray(new FileInputStream(file));
ImageInputStream in = ImageIO.createImageInputStream(new ByteArrayInputStream(thumbnailImage)); ImageInputStream in = ImageIO.createImageInputStream(new ByteArrayInputStream(thumbnailImage));
ImageReader reader = ImageIO.getImageReaders(in).next(); ImageReader reader = ImageIO.getImageReaders(in).next();
thumbnailFormat = reader.getFormatName().toLowerCase(); thumbnailFormat = reader.getFormatName().toLowerCase();
@@ -138,13 +135,6 @@ public class GuiYoutubeUpload extends GuiScreen {
} }
thumbnail.setTexture(image); thumbnail.setTexture(image);
inputValidation.run(); 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 -> {
if (doIt) {
for (Entry entry : selectedEntries) { for (Entry entry : selectedEntries) {
timelines.put(entry.name, currentTimeline); timelines.put(entry.name, currentTimeline);
} }
overwriteButton.setDisabled(); overwriteButton.setDisabled();
save(); save();
} });
}, Throwable::printStackTrace);
} }
}).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
public void onSuccess(Boolean save) {
if (save) {
String name = nameField.getText(); String name = nameField.getText();
timelines.put(name, currentTimeline); timelines.put(name, currentTimeline);
list.getListPanel().addElements(null, new Entry(name)); list.getListPanel().addElements(null, new Entry(name));
save(); save();
}
}
@Override
public void onFailure(Throwable t) {
t.printStackTrace();
}
}); });
} }
}).setSize(75, 20).setI18nLabel("replaymod.gui.saveas"); }).setSize(75, 20).setI18nLabel("replaymod.gui.saveas");
@@ -161,35 +148,21 @@ 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
public void onSuccess(Boolean save) {
if (save) {
String name = nameField.getText(); String name = nameField.getText();
timelines.put(name, timelines.remove(selectedEntry.name)); timelines.put(name, timelines.remove(selectedEntry.name));
selectedEntry.name = name; selectedEntry.name = name;
selectedEntry.label.setText(name); selectedEntry.label.setText(name);
save(); 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>() {
@Override
public void onSuccess(Boolean delete) {
if (delete) {
for (Entry entry : selectedEntries) { for (Entry entry : selectedEntries) {
timelines.remove(entry.name); timelines.remove(entry.name);
list.getListPanel().removeElement(entry); list.getListPanel().removeElement(entry);
@@ -198,13 +171,6 @@ public class GuiKeyframeRepository extends GuiScreen implements Closeable, Typea
selectedEntries.clear(); selectedEntries.clear();
updateButtons(); updateButtons();
save(); save();
}
}
@Override
public void onFailure(Throwable t) {
t.printStackTrace();
}
}); });
} }
}).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,24 +128,12 @@ 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>() {
@Override
public void onSuccess(@Nullable File result) {
if (result != null) {
if (!result.getName().equals(outputFile.getName())) {
userDefinedOutputFileName = true; userDefinedOutputFileName = true;
} }
outputFile = result; outputFile = file;
outputFileButton.setLabel(result.getName()); outputFileButton.setLabel(file.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,14 +149,11 @@ 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
public void onSuccess(Boolean delete) {
if (delete) {
// Sanitize their input // Sanitize their input
String name = nameField.getText().trim(); String newName = nameField.getText().trim();
// This file is what they want // This file is what they want
File targetFile = new File(file.getParentFile(), Utils.replayNameToFileName(name)); File targetFile = new File(file.getParentFile(), Utils.replayNameToFileName(newName));
try { try {
// Finally, try to move it // Finally, try to move it
FileUtils.moveFile(file, targetFile); FileUtils.moveFile(file, targetFile);
@@ -178,40 +173,22 @@ public class GuiReplayViewer extends GuiScreen {
return; return;
} }
list.load(); list.load();
}
}
@Override
public void onFailure(Throwable t) {
t.printStackTrace();
}
}); });
} }
}).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>() {
@Override
public void onSuccess(Boolean delete) {
if (delete) {
try { try {
FileUtils.forceDelete(entry.file); FileUtils.forceDelete(entry.file);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
list.load(); list.load();
}
}
@Override
public void onFailure(Throwable t) {
t.printStackTrace();
}
}); });
} }
}).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,24 +399,13 @@ 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>() {
@Override
public void onSuccess(Boolean delete) {
if (delete) {
mod.clearCurrentTimeline(); mod.clearCurrentTimeline();
if (entityTracker != null) { if (entityTracker != null) {
mod.getCurrentTimeline().setEntityTracker(entityTracker); mod.getCurrentTimeline().setEntityTracker(entityTracker);
} }
}
}
@Override
public void onFailure(Throwable t) {
t.printStackTrace();
}
}); });
} }