This commit is contained in:
parent
ff407b1c74
commit
b78675db11
@ -1,5 +1,9 @@
|
||||
# Changelog
|
||||
|
||||
**1.1.4**
|
||||
* Add Refresh Button To GUI
|
||||
* Add ``/modupdater`` Command
|
||||
|
||||
**1.1.3**
|
||||
* Swap Buttons In GUI
|
||||
|
||||
|
@ -9,7 +9,7 @@ org.gradle.jvmargs = -Xmx1G
|
||||
fabric_loader_version = 0.8.8+build.202
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 1.1.3
|
||||
mod_version = 1.1.4
|
||||
maven_group = com.thebrokenrail
|
||||
|
||||
# Dependencies
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.thebrokenrail.modupdater;
|
||||
|
||||
import com.thebrokenrail.modupdater.command.ModUpdaterCommand;
|
||||
import com.thebrokenrail.modupdater.strategy.util.UpdateStrategyRunner;
|
||||
import com.thebrokenrail.modupdater.data.ModUpdate;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
@ -25,10 +26,11 @@ public class ModUpdater implements ModInitializer {
|
||||
getLogger().info(info);
|
||||
}
|
||||
|
||||
private static volatile ModUpdate[] updates;
|
||||
private static volatile ModUpdate[] updates = null;
|
||||
|
||||
public static void findUpdates() {
|
||||
updates = UpdateStrategyRunner.checkAllModsForUpdates();
|
||||
updates = null;
|
||||
new Thread(() -> updates = UpdateStrategyRunner.checkAllModsForUpdates()).start();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@ -38,7 +40,7 @@ public class ModUpdater implements ModInitializer {
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
Thread updateThread = new Thread(ModUpdater::findUpdates);
|
||||
updateThread.start();
|
||||
findUpdates();
|
||||
ModUpdaterCommand.register();
|
||||
}
|
||||
}
|
||||
|
@ -20,8 +20,11 @@ import java.util.Arrays;
|
||||
public class ModUpdateScreen extends Screen {
|
||||
public ModUpdateListWidget list;
|
||||
private ButtonWidget download;
|
||||
private ButtonWidget refresh;
|
||||
private final Screen parent;
|
||||
|
||||
private static final int BOTTOM_ROW = 60;
|
||||
|
||||
public ModUpdateScreen(Screen parent) {
|
||||
super(new TranslatableText("gui." + ModUpdater.NAMESPACE + ".title"));
|
||||
this.parent = parent;
|
||||
@ -31,25 +34,31 @@ public class ModUpdateScreen extends Screen {
|
||||
protected void init() {
|
||||
list = new ModUpdateListWidget(client, this);
|
||||
children.add(list);
|
||||
int buttonHeight = 20;
|
||||
int padding = 2;
|
||||
int actionRowY = height - BOTTOM_ROW / 2 - padding - buttonHeight;
|
||||
int doneY = height - BOTTOM_ROW / 2 + padding;
|
||||
int buttonWidth = 150;
|
||||
int paddingX = 5;
|
||||
int downloadX = width / 2 - buttonWidth - paddingX;
|
||||
int doneX = width / 2 + paddingX;
|
||||
addButton(new ButtonWidget(doneX, height - 30, buttonWidth, 20, ScreenTexts.DONE, buttonWidget -> {
|
||||
assert client != null;
|
||||
client.openScreen(parent);
|
||||
}));
|
||||
download = addButton(new ButtonWidget(downloadX, height - 30, buttonWidth, 20, new TranslatableText("gui." + ModUpdater.NAMESPACE + ".download"), buttonWidget -> {
|
||||
int refreshX = width / 2 - buttonWidth - padding;
|
||||
int downloadX = width / 2 + padding;
|
||||
int doneX = width / 2 - buttonWidth / 2;
|
||||
refresh = addButton(new ButtonWidget(refreshX, actionRowY, buttonWidth, buttonHeight, new TranslatableText("gui." + ModUpdater.NAMESPACE + ".refresh"), buttonWidget -> ModUpdater.findUpdates()));
|
||||
download = addButton(new ButtonWidget(downloadX, actionRowY, buttonWidth, buttonHeight, new TranslatableText("gui." + ModUpdater.NAMESPACE + ".download"), buttonWidget -> {
|
||||
if (list.getSelected() != null) {
|
||||
Util.getOperatingSystem().open(list.getSelected().update.downloadURL);
|
||||
}
|
||||
}));
|
||||
download.active = false;
|
||||
addButton(new ButtonWidget(doneX, doneY, buttonWidth, buttonHeight, ScreenTexts.DONE, buttonWidget -> {
|
||||
assert client != null;
|
||||
client.openScreen(parent);
|
||||
}));
|
||||
super.init();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
||||
refresh.active = ModUpdater.getUpdates() != null;
|
||||
download.active = list.getSelected() != null;
|
||||
list.render(matrices, mouseX, mouseY, delta);
|
||||
drawCenteredText(matrices, textRenderer, title, width / 2, 16, 16777215);
|
||||
super.render(matrices, mouseX, mouseY, delta);
|
||||
@ -61,7 +70,7 @@ public class ModUpdateScreen extends Screen {
|
||||
private ModUpdate[] updates = null;
|
||||
|
||||
private ModUpdateListWidget(MinecraftClient client, ModUpdateScreen screen) {
|
||||
super(client, screen.width, screen.height, 32, screen.height - 40, 18);
|
||||
super(client, screen.width, screen.height, 32, screen.height - BOTTOM_ROW, 18);
|
||||
this.screen = screen;
|
||||
|
||||
reload();
|
||||
@ -71,6 +80,7 @@ public class ModUpdateScreen extends Screen {
|
||||
ModUpdate[] newUpdates = ModUpdater.getUpdates();
|
||||
if (!Arrays.equals(updates, newUpdates)) {
|
||||
clearEntries();
|
||||
setSelected(null);
|
||||
if (newUpdates != null) {
|
||||
for (ModUpdate update : newUpdates) {
|
||||
addEntry(new ModUpdateEntry(update, screen, this));
|
||||
@ -99,9 +109,6 @@ public class ModUpdateScreen extends Screen {
|
||||
super.setSelected(entry);
|
||||
if (entry != null) {
|
||||
NarratorManager.INSTANCE.narrate(new TranslatableText("narrator.select", entry.update.text).asString());
|
||||
screen.download.active = true;
|
||||
} else {
|
||||
screen.download.active = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -120,7 +127,7 @@ public class ModUpdateScreen extends Screen {
|
||||
reload();
|
||||
super.render(matrices, mouseX, mouseY, delta);
|
||||
if (updates == null) {
|
||||
drawCenteredText(matrices, screen.textRenderer, new TranslatableText("gui.modupdater.loading"), width / 2, height / 2 - screen.textRenderer.fontHeight, 16777215);
|
||||
drawCenteredText(matrices, screen.textRenderer, new TranslatableText("gui.modupdater.loading"), width / 2, (bottom - top) / 2 - screen.textRenderer.fontHeight + top, 16777215);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,41 @@
|
||||
package com.thebrokenrail.modupdater.command;
|
||||
|
||||
import com.thebrokenrail.modupdater.ModUpdater;
|
||||
import com.thebrokenrail.modupdater.data.ModUpdate;
|
||||
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.server.command.CommandManager;
|
||||
import net.minecraft.text.ClickEvent;
|
||||
import net.minecraft.text.HoverEvent;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.Formatting;
|
||||
|
||||
public class ModUpdaterCommand {
|
||||
private static void checkLoaded() throws CommandException {
|
||||
if (ModUpdater.getUpdates() == null) {
|
||||
throw new CommandException(new TranslatableText("commands." + ModUpdater.NAMESPACE + ".not_loaded"));
|
||||
}
|
||||
}
|
||||
|
||||
public static void register() {
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, isDedicated) -> dispatcher.register(CommandManager.literal(ModUpdater.NAMESPACE)
|
||||
.then(CommandManager.literal("list").executes(context -> {
|
||||
checkLoaded();
|
||||
context.getSource().sendFeedback(new TranslatableText("commands." + ModUpdater.NAMESPACE + ".list_title").formatted(Formatting.YELLOW), false);
|
||||
ModUpdate[] updates = ModUpdater.getUpdates();
|
||||
assert updates != null;
|
||||
for (ModUpdate update : updates) {
|
||||
context.getSource().sendFeedback(new LiteralText(update.text).styled(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, update.downloadURL)).setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TranslatableText("commands." + ModUpdater.NAMESPACE + ".hover")))), false);
|
||||
}
|
||||
return updates.length;
|
||||
}))
|
||||
.then(CommandManager.literal("refresh").requires(source -> source.hasPermissionLevel(3)).executes(context -> {
|
||||
checkLoaded();
|
||||
ModUpdater.findUpdates();
|
||||
context.getSource().sendFeedback(new TranslatableText("commands." + ModUpdater.NAMESPACE + ".refresh_start"), true);
|
||||
return 1;
|
||||
}))
|
||||
));
|
||||
}
|
||||
}
|
@ -63,20 +63,24 @@ public class UpdateStrategyRunner {
|
||||
|
||||
for (ModContainer mod : FabricLoader.getInstance().getAllMods()) {
|
||||
Thread thread = new Thread(() -> {
|
||||
ModMetadata metadata = mod.getMetadata();
|
||||
try {
|
||||
ModMetadata metadata = mod.getMetadata();
|
||||
|
||||
ModUpdate update = checkModForUpdate(metadata);
|
||||
ModUpdate update = checkModForUpdate(metadata);
|
||||
|
||||
if (update != null) {
|
||||
ModUpdater.logInfo(update.text + " (" + update.downloadURL + ')');
|
||||
synchronized (updates) {
|
||||
updates.add(update);
|
||||
if (update != null) {
|
||||
ModUpdater.logInfo(update.text + " (" + update.downloadURL + ')');
|
||||
synchronized (updates) {
|
||||
updates.add(update);
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
synchronized (remaining) {
|
||||
remaining.decrementAndGet();
|
||||
remaining.notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
synchronized (remaining) {
|
||||
remaining.decrementAndGet();
|
||||
remaining.notifyAll();
|
||||
}
|
||||
});
|
||||
synchronized (remaining) {
|
||||
|
@ -1,5 +1,10 @@
|
||||
{
|
||||
"gui.modupdater.title": "Available Mod Updates",
|
||||
"gui.modupdater.download": "Download",
|
||||
"gui.modupdater.loading": "Loading..."
|
||||
"gui.modupdater.refresh": "Refresh",
|
||||
"gui.modupdater.loading": "Loading...",
|
||||
"commands.modupdater.not_loaded": "Unable To Perform Operation While Mod Updates Are Loading",
|
||||
"commands.modupdater.refresh_start": "Refreshing Mod Updates",
|
||||
"commands.modupdater.hover": "Click To Download",
|
||||
"commands.modupdater.list_title": "Available Mod Updates:"
|
||||
}
|
Reference in New Issue
Block a user