From 38e7c947fdc412d34babbdd54c5b66af3e844ae9 Mon Sep 17 00:00:00 2001 From: syeyoung Date: Mon, 27 Feb 2023 01:53:35 +0900 Subject: - Disable autoupdate button if remote branch is not available Signed-off-by: syeyoung --- .../java/kr/syeyoung/dungeonsguide/mod/VersionInfo.java | 15 ++++++++++++--- .../kr/syeyoung/dungeonsguide/mod/WidgetUpdateLog.java | 6 +++++- 2 files changed, 17 insertions(+), 4 deletions(-) (limited to 'mod/src/main/java/kr') diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/VersionInfo.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/VersionInfo.java index f0c30c7b..37b6c212 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/VersionInfo.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/VersionInfo.java @@ -36,6 +36,7 @@ import org.apache.logging.log4j.Logger; import javax.swing.*; import java.io.IOException; +import java.util.List; import java.util.Optional; import java.util.Properties; @@ -82,13 +83,14 @@ public class VersionInfo { Scaler scaler = new Scaler(); scaler.scale.setValue((double) new ScaledResolution(Minecraft.getMinecraft()).getScaleFactor()); scaler.child.setValue(new WidgetUpdateLog( - latestUpdate.getName(), latestUpdate.getUpdateLog() + latestUpdate.getName(), latestUpdate.getUpdateLog(), true )); GuiDisplayer.INSTANCE.displayGui(new GuiScreenAdapter(scaler)); logger.info("Update Required!!"); } else if (VersionInfo.getCurrentLoader() instanceof JarLoader || VersionInfo.getCurrentLoader() instanceof LocalLoader) { - UpdateBranch requiredUpdateBranch = UpdateRetrieverUtil.getUpdateBranches().stream().filter(a -> + List availableBranches = UpdateRetrieverUtil.getUpdateBranches(); + UpdateBranch requiredUpdateBranch = availableBranches.stream().filter(a -> Optional.ofNullable(a.getMetadata()) .filter(b -> b.has("additionalMeta")) .map(b -> b.getJSONObject("additionalMeta")) @@ -96,6 +98,13 @@ public class VersionInfo { .map(b -> b.getString("type")) .filter(b -> b.equals("update-alarm-github")) .isPresent()).findFirst().orElse(null); + boolean autoupdate = availableBranches.stream().anyMatch(a -> + Optional.ofNullable(a.getMetadata()) + .filter(b -> b.has("additionalMeta")) + .map(b -> b.getJSONObject("additionalMeta")) + .filter(b -> b.has("type")) + .map(b -> b.getString("type")) + .filter(b -> b.equals("mod")).isPresent()); if (requiredUpdateBranch == null) { logger.error("No update branch found: ???"); return; @@ -117,7 +126,7 @@ public class VersionInfo { Scaler scaler = new Scaler(); scaler.scale.setValue((double) new ScaledResolution(Minecraft.getMinecraft()).getScaleFactor()); scaler.child.setValue(new WidgetUpdateLog( - latestUpdate.getName(), latestUpdate.getUpdateLog() + latestUpdate.getName(), latestUpdate.getUpdateLog(), autoupdate )); GuiDisplayer.INSTANCE.displayGui(new GuiScreenAdapter(scaler)); } else { diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/WidgetUpdateLog.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/WidgetUpdateLog.java index cb7903e3..1345a140 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/WidgetUpdateLog.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/WidgetUpdateLog.java @@ -32,10 +32,14 @@ public class WidgetUpdateLog extends AnnotatedImportOnlyWidget { @Bind(variableName = "version") public final BindableAttribute version = new BindableAttribute<>(String.class); - public WidgetUpdateLog(String version, String updateLog) { + @Bind(variableName = "disabled") + public final BindableAttribute disabled = new BindableAttribute<>(Boolean.class, false); + + public WidgetUpdateLog(String version, String updateLog, boolean autoupdate) { super(new ResourceLocation("dungeonsguide:gui/update.gui")); this.version.setValue(version); this.updateLog.setValue(updateLog); + this.disabled.setValue(!autoupdate); } @On(functionName = "continue") -- cgit