diff options
3 files changed, 21 insertions, 8 deletions
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<UpdateBranch> 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<String> version = new BindableAttribute<>(String.class); - public WidgetUpdateLog(String version, String updateLog) { + @Bind(variableName = "disabled") + public final BindableAttribute<Boolean> 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") diff --git a/mod/src/main/resources/assets/dungeonsguide/gui/update.gui b/mod/src/main/resources/assets/dungeonsguide/gui/update.gui index db6a9843..c836349f 100644 --- a/mod/src/main/resources/assets/dungeonsguide/gui/update.gui +++ b/mod/src/main/resources/assets/dungeonsguide/gui/update.gui @@ -51,10 +51,10 @@ </flexible> <size width="0" height="15"/> <row mainAlign="CENTER"> - <size width="200" height="20"> - <RoundButton text="Unload DG and load new version" on:click="unload"/> - </size> - <size width="10" height="0"/> + <size width="200" height="20"> + <RoundButton text="Unload DG and load new version" bind:disabled="disabled" on:click="unload"/> + </size> + <size width="10" height="0"/> <size width="80" height="20"> <RoundButton text="Continue" on:click="continue"/> </size> |