[Feature] Updater Icons from Entrypoints
This commit is contained in:
parent
bcd64b87b7
commit
dca9817c17
9 changed files with 86 additions and 11 deletions
|
@ -1,11 +1,16 @@
|
|||
package org.betterx.bclib.client.gui.screens;
|
||||
|
||||
import org.betterx.bclib.BCLib;
|
||||
import org.betterx.bclib.config.Configs;
|
||||
import org.betterx.bclib.entrypoints.EntrypointUtil;
|
||||
import org.betterx.bclib.networking.VersionCheckEntryPoint;
|
||||
import org.betterx.bclib.networking.VersionChecker;
|
||||
import org.betterx.ui.ColorUtil;
|
||||
import org.betterx.ui.layout.components.HorizontalStack;
|
||||
import org.betterx.ui.layout.components.LayoutComponent;
|
||||
import org.betterx.ui.layout.components.VerticalStack;
|
||||
import org.betterx.ui.layout.values.Size;
|
||||
import org.betterx.ui.layout.values.Value;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.gui.GuiComponent;
|
||||
|
@ -13,6 +18,7 @@ import net.minecraft.client.gui.screens.Screen;
|
|||
import net.minecraft.network.chat.CommonComponents;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
@ -27,6 +33,18 @@ public class UpdatesScreen extends BCLibLayoutScreen {
|
|||
super(parent, Component.translatable("bclib.updates.title"), 10, 10, 10);
|
||||
}
|
||||
|
||||
public ResourceLocation getUpdaterIcon(String modID) {
|
||||
if (modID.equals(BCLib.MOD_ID)) {
|
||||
return BCLibLayoutScreen.BCLIB_LOGO_LOCATION;
|
||||
}
|
||||
return EntrypointUtil.getCommon(VersionCheckEntryPoint.class)
|
||||
.stream()
|
||||
.map(vc -> vc.updaterIcon(modID))
|
||||
.filter(r -> r != null)
|
||||
.findAny()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LayoutComponent<?, ?> initContent() {
|
||||
VerticalStack rows = new VerticalStack(relative(1), fit()).centerHorizontal();
|
||||
|
@ -37,8 +55,14 @@ public class UpdatesScreen extends BCLibLayoutScreen {
|
|||
|
||||
VersionChecker.forEachUpdate((mod, cur, updated) -> {
|
||||
ModContainer nfo = FabricLoader.getInstance().getModContainer(mod).orElse(null);
|
||||
|
||||
HorizontalStack row = rows.addRow(relative(0.8), fit()).centerHorizontal();
|
||||
ResourceLocation icon = getUpdaterIcon(mod);
|
||||
HorizontalStack row = rows.addRow(fixed(320), fit()).centerHorizontal();
|
||||
if (icon != null) {
|
||||
row.addImage(Value.fit(), Value.fit(), icon, Size.of(32));
|
||||
row.addSpacer(4);
|
||||
} else {
|
||||
row.addSpacer(36);
|
||||
}
|
||||
if (nfo != null) {
|
||||
row.addText(fit(), fit(), Component.literal(nfo.getMetadata().getName()))
|
||||
.setColor(ColorUtil.WHITE);
|
||||
|
@ -54,7 +78,7 @@ public class UpdatesScreen extends BCLibLayoutScreen {
|
|||
row.addButton(fit(), fit(), Component.translatable("bclib.updates.curseforge_link"))
|
||||
.onPress((bt) -> {
|
||||
this.openLink(nfo.getMetadata().getContact().get("homepage").get());
|
||||
});
|
||||
}).centerVertical();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -72,7 +72,7 @@ public class WelcomeScreen extends BCLibLayoutScreen {
|
|||
Checkbox check = innerContent.addCheckbox(
|
||||
fit(),
|
||||
fit(),
|
||||
translatable("title.config.bclib.client.ui.check"),
|
||||
translatable("title.config.bclib.client.version.check"),
|
||||
Configs.CLIENT_CONFIG.checkVersions()
|
||||
)
|
||||
.onChange((cb, state) -> {
|
||||
|
@ -80,7 +80,7 @@ public class WelcomeScreen extends BCLibLayoutScreen {
|
|||
});
|
||||
innerContent.addSpacer(2);
|
||||
HorizontalStack dscBox = innerContent.indent(24);
|
||||
dscBox.addMultilineText(fill(), fit(), translatable("description.config.bclib.client.ui.check"))
|
||||
dscBox.addMultilineText(fill(), fit(), translatable("description.config.bclib.client.version.check"))
|
||||
.setColor(ColorUtil.GRAY);
|
||||
dscBox.addSpacer(8);
|
||||
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
package org.betterx.bclib.entrypoints;
|
||||
|
||||
public interface BCLibEntryPoint {
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package org.betterx.bclib.entrypoints;
|
||||
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
|
||||
import java.util.List;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public class EntrypointUtil {
|
||||
private static <T extends BCLibEntryPoint> List<T> getEntryPoints(boolean client, Class<T> select) {
|
||||
return FabricLoader.getInstance()
|
||||
.getEntrypoints(
|
||||
client ? "bclib_client" : "bclib",
|
||||
BCLibEntryPoint.class
|
||||
)
|
||||
.stream()
|
||||
.filter(o -> select.isAssignableFrom(o.getClass()))
|
||||
.map(e -> (T) e)
|
||||
.toList();
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static <T extends BCLibEntryPoint> List<T> getCommon(Class<T> select) {
|
||||
return getEntryPoints(false, select);
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static <T extends BCLibEntryPoint> List<T> getClient(Class<T> select) {
|
||||
return getEntryPoints(true, select);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package org.betterx.bclib.networking;
|
||||
|
||||
import org.betterx.bclib.entrypoints.BCLibEntryPoint;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
public interface VersionCheckEntryPoint extends BCLibEntryPoint {
|
||||
ResourceLocation updaterIcon(String modID);
|
||||
}
|
|
@ -4,6 +4,8 @@ import org.betterx.bclib.BCLib;
|
|||
import org.betterx.bclib.config.Configs;
|
||||
import org.betterx.worlds.together.util.ModUtil;
|
||||
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -123,6 +125,10 @@ public class VersionChecker implements Runnable {
|
|||
BCLib.LOGGER.info("Received Version Info for minecraft=" + json.mc + ", loader=" + json.loader);
|
||||
if (json.mods != null) {
|
||||
for (ModVersion mod : json.mods) {
|
||||
if (!KNOWN_MODS.contains(mod.n)) {
|
||||
if (FabricLoader.getInstance().getModContainer(mod.n).isPresent())
|
||||
registerMod(mod.n);
|
||||
}
|
||||
if (mod.n != null && mod.v != null && KNOWN_MODS.contains(mod.n)) {
|
||||
boolean isNew = ModUtil.isLargerVersion(mod.v, ModUtil.getModVersion(mod.n));
|
||||
BCLib.LOGGER.info(" - " + mod.n + ":" + mod.v + (isNew ? " (update available)" : ""));
|
||||
|
|
|
@ -19,10 +19,12 @@ public class EntrypointUtil {
|
|||
.toList();
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static <T extends WorldsTogetherEntrypoint> List<T> getCommon(Class<T> select) {
|
||||
return getEntryPoints(false, select);
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static <T extends WorldsTogetherEntrypoint> List<T> getClient(Class<T> select) {
|
||||
return getEntryPoints(true, select);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue