[Feature] Update Checker
This commit is contained in:
parent
2ef9e51ef1
commit
69d472d107
21 changed files with 633 additions and 22 deletions
|
@ -0,0 +1,103 @@
|
|||
package org.betterx.bclib.client.gui.screens;
|
||||
|
||||
import org.betterx.bclib.config.Configs;
|
||||
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 com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.gui.GuiComponent;
|
||||
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.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.fabricmc.loader.api.ModContainer;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class UpdatesScreen extends BCLibLayoutScreen {
|
||||
|
||||
public static final String DONATION_URL = "https://www.paypal.com/donate/?hosted_button_id=7VTXYRXBHZQZJ&item_name=BetterX%20Mods&cmd=_s-xclick";
|
||||
|
||||
public UpdatesScreen(Screen parent) {
|
||||
super(parent, Component.translatable("bclib.updates.title"), 10, 10, 10);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LayoutComponent<?, ?> initContent() {
|
||||
VerticalStack rows = new VerticalStack(relative(1), fit()).centerHorizontal();
|
||||
rows.addMultilineText(fill(), fit(), Component.translatable("bclib.updates.description"))
|
||||
.centerHorizontal();
|
||||
|
||||
rows.addSpacer(16);
|
||||
|
||||
VersionChecker.forEachUpdate((mod, cur, updated) -> {
|
||||
ModContainer nfo = FabricLoader.getInstance().getModContainer(mod).orElse(null);
|
||||
|
||||
HorizontalStack row = rows.addRow(relative(0.8), fit()).centerHorizontal();
|
||||
if (nfo != null) {
|
||||
row.addText(fit(), fit(), Component.literal(nfo.getMetadata().getName()))
|
||||
.setColor(ColorUtil.WHITE);
|
||||
} else {
|
||||
row.addText(fit(), fit(), Component.literal(mod)).setColor(ColorUtil.WHITE);
|
||||
}
|
||||
row.addSpacer(4);
|
||||
row.addText(fit(), fit(), Component.literal(cur));
|
||||
row.addText(fit(), fit(), Component.literal(" -> "));
|
||||
row.addText(fit(), fit(), Component.literal(updated)).setColor(ColorUtil.GREEN);
|
||||
row.addFiller();
|
||||
if (nfo != null && nfo.getMetadata().getContact().get("homepage").isPresent()) {
|
||||
row.addButton(fit(), fit(), Component.translatable("bclib.updates.curseforge_link"))
|
||||
.onPress((bt) -> {
|
||||
this.openLink(nfo.getMetadata().getContact().get("homepage").get());
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
VerticalStack layout = new VerticalStack(relative(1), fill()).centerHorizontal();
|
||||
layout.addSpacer(8);
|
||||
layout.addScrollable(rows);
|
||||
layout.addSpacer(8);
|
||||
|
||||
|
||||
HorizontalStack footer = layout.addRow(fill(), fit());
|
||||
if (Configs.CLIENT_CONFIG.isDonor()) {
|
||||
footer.addButton(
|
||||
fit(),
|
||||
fit(),
|
||||
Component.translatable("bclib.updates.donate").setStyle(Style.EMPTY.withColor(ColorUtil.YELLOW))
|
||||
)
|
||||
.onPress((bt) -> openLink(DONATION_URL));
|
||||
footer.addSpacer(2);
|
||||
footer.addMultilineText(fit(), fit(), Component.translatable("bclib.updates.donate_pre"))
|
||||
.alignBottom();
|
||||
}
|
||||
|
||||
footer.addFiller();
|
||||
footer.addCheckbox(
|
||||
fit(),
|
||||
fit(),
|
||||
Component.translatable("Disable Check"),
|
||||
!Configs.MAIN_CONFIG.checkVersions()
|
||||
)
|
||||
.onChange((cb, state) -> {
|
||||
Configs.MAIN_CONFIG.setCheckVersions(!state);
|
||||
Configs.MAIN_CONFIG.saveChanges();
|
||||
});
|
||||
footer.addSpacer(4);
|
||||
footer.addButton(fit(), fit(), CommonComponents.GUI_DONE).onPress((bt -> {
|
||||
onClose();
|
||||
}));
|
||||
return layout;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderBackground(PoseStack poseStack, int i, int j, float f) {
|
||||
GuiComponent.fill(poseStack, 0, 0, width, height, 0xBD343444);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package org.betterx.bclib.client.gui.screens;
|
||||
|
||||
import org.betterx.bclib.config.Configs;
|
||||
import org.betterx.ui.ColorUtil;
|
||||
import org.betterx.ui.layout.components.*;
|
||||
|
||||
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;
|
||||
|
||||
public class WelcomeScreen extends BCLibLayoutScreen {
|
||||
public WelcomeScreen(Screen parent) {
|
||||
super(parent, translatable("bclib.welcome.title"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LayoutComponent<?, ?> initContent() {
|
||||
VerticalStack content = new VerticalStack(fill(), fit()).setDebugName("content");
|
||||
content.addMultilineText(fill(), fit(), MultiLineText.parse(translatable("bclib.welcome.description")))
|
||||
.centerHorizontal();
|
||||
if (Configs.CLIENT_CONFIG.isDonor()) {
|
||||
content.addHorizontalSeparator(48);
|
||||
HorizontalStack donationRow = content.addRow(relative(0.9), fit())
|
||||
.setDebugName("donationRow")
|
||||
.centerHorizontal();
|
||||
|
||||
donationRow.addMultilineText(fill(), fit(), translatable("bclib.welcome.donation"))
|
||||
.alignLeft()
|
||||
.alignRight();
|
||||
donationRow.addSpacer(4);
|
||||
donationRow.addButton(
|
||||
fit(), fit(),
|
||||
Component.translatable("bclib.updates.donate").setStyle(Style.EMPTY.withColor(ColorUtil.YELLOW))
|
||||
)
|
||||
.onPress((bt) -> openLink(UpdatesScreen.DONATION_URL)).centerVertical();
|
||||
}
|
||||
|
||||
content.addHorizontalSeparator(48);
|
||||
content.addCheckbox(fit(), fit(), translatable("bclib.welcome.updater.title"), true)
|
||||
.onChange((cb, state) -> Configs.MAIN_CONFIG.setCheckVersions(state));
|
||||
content.addSpacer(2);
|
||||
content.indent(24)
|
||||
.addMultilineText(fill(), fit(), translatable("bclib.welcome.updater.description"))
|
||||
.setColor(ColorUtil.GRAY);
|
||||
|
||||
content.addSpacer(16);
|
||||
content.addButton(fit(), fit(), CommonComponents.GUI_PROCEED).onPress((bt) -> {
|
||||
Configs.MAIN_CONFIG.setDidShowWelcomeScreen();
|
||||
onClose();
|
||||
}).alignRight();
|
||||
|
||||
return VerticalScroll.create(fill(), fill(), content);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue