More Welcome Options

This commit is contained in:
Frank 2022-07-22 17:48:54 +02:00
parent a7efcd25ba
commit bcd64b87b7
15 changed files with 254 additions and 67 deletions

View file

@ -21,8 +21,7 @@ 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 static final String DONATION_URL = "https://www.paypal.com/donate/?hosted_button_id=7VTXYRXBHZQZJ";
public UpdatesScreen(Screen parent) {
super(parent, Component.translatable("bclib.updates.title"), 10, 10, 10);

View file

@ -1,9 +1,14 @@
package org.betterx.bclib.client.gui.screens;
import org.betterx.bclib.BCLib;
import org.betterx.bclib.config.Configs;
import org.betterx.bclib.networking.VersionChecker;
import org.betterx.bclib.registry.PresetsRegistry;
import org.betterx.ui.ColorUtil;
import org.betterx.ui.layout.components.*;
import org.betterx.ui.layout.values.Size;
import org.betterx.worlds.together.WorldsTogether;
import org.betterx.worlds.together.worldPreset.WorldPresets;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.gui.GuiComponent;
@ -11,8 +16,14 @@ 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;
public class WelcomeScreen extends BCLibLayoutScreen {
static final ResourceLocation BETTERX_LOCATION = new ResourceLocation(BCLib.MOD_ID, "betterx.png");
static final ResourceLocation BACKGROUND = new ResourceLocation(BCLib.MOD_ID, "header.jpg");
static final ResourceLocation ICON_BETTERNETHER = new ResourceLocation(BCLib.MOD_ID, "icon_betternether.png");
static final ResourceLocation ICON_BETTEREND = new ResourceLocation(BCLib.MOD_ID, "icon_betterend.png");
public WelcomeScreen(Screen parent) {
super(parent, translatable("bclib.welcome.title"));
}
@ -20,13 +31,29 @@ public class WelcomeScreen extends BCLibLayoutScreen {
@Override
protected LayoutComponent<?, ?> initContent() {
VerticalStack content = new VerticalStack(fill(), fit()).setDebugName("content");
content.addImage(fill(), fit(), BACKGROUND, new Size(427, 100));
content.addHorizontalLine(1).setColor(ColorUtil.BLACK);
content.addSpacer(16);
HorizontalStack headerRow = content.addRow(fit(), fit()).setDebugName("title bar").centerHorizontal();
headerRow.addIcon(icon, Size.of(512)).setDebugName("icon");
headerRow.addSpacer(4);
headerRow.addText(fit(), fit(), title).centerHorizontal().setColor(ColorUtil.WHITE).setDebugName("title");
headerRow.addImage(fixed(178 / 2), fixed(40 / 2), BETTERX_LOCATION, Size.of(178, 40)).setDebugName("betterx");
content.addSpacer(16);
content.addMultilineText(fill(), fit(), MultiLineText.parse(translatable("bclib.welcome.description")))
.centerHorizontal();
Container padContainer = new Container(fill(), fit()).setPadding(10, 0, 10, 10).setDebugName("padContainer");
VerticalStack innerContent = new VerticalStack(fill(), fit()).setDebugName("innerContent");
padContainer.addChild(innerContent);
content.add(padContainer);
if (Configs.CLIENT_CONFIG.isDonor()) {
content.addHorizontalSeparator(48);
HorizontalStack donationRow = content.addRow(relative(0.9), fit())
.setDebugName("donationRow")
.centerHorizontal();
addSeparator(innerContent, ICON_BETTEREND);
HorizontalStack donationRow = innerContent.addRow(relative(0.9), fit())
.setDebugName("donationRow")
.centerHorizontal();
donationRow.addMultilineText(fill(), fit(), translatable("bclib.welcome.donation"))
.alignLeft()
@ -39,36 +66,127 @@ public class WelcomeScreen extends BCLibLayoutScreen {
.onPress((bt) -> openLink(UpdatesScreen.DONATION_URL)).centerVertical();
}
content.addHorizontalSeparator(48);
Checkbox check = content.addCheckbox(
fit(),
fit(),
translatable("bclib.welcome.updater.title"),
Configs.CLIENT_CONFIG.checkVersions()
)
.onChange((cb, state) -> {
Configs.CLIENT_CONFIG.setCheckVersions(state);
});
content.addSpacer(2);
HorizontalStack dscBox = content.indent(24);
dscBox.addMultilineText(fill(), fit(), translatable("bclib.welcome.updater.description"))
addSeparator(innerContent, ICON_BETTERNETHER);
// Do Update Checks
Checkbox check = innerContent.addCheckbox(
fit(),
fit(),
translatable("title.config.bclib.client.ui.check"),
Configs.CLIENT_CONFIG.checkVersions()
)
.onChange((cb, state) -> {
Configs.CLIENT_CONFIG.setCheckVersions(state);
});
innerContent.addSpacer(2);
HorizontalStack dscBox = innerContent.indent(24);
dscBox.addMultilineText(fill(), fit(), translatable("description.config.bclib.client.ui.check"))
.setColor(ColorUtil.GRAY);
dscBox.addSpacer(8);
content.addSpacer(16);
content.addButton(fit(), fit(), CommonComponents.GUI_PROCEED).onPress((bt) -> {
// Hide Experimental Dialog
innerContent.addSpacer(8);
Checkbox experimental = innerContent.addCheckbox(
fit(),
fit(),
translatable("title.config.bclib.client.ui.suppressExperimentalDialogOnLoad"),
Configs.CLIENT_CONFIG.suppressExperimentalDialog()
)
.onChange((cb, state) -> {
Configs.CLIENT_CONFIG.setSuppressExperimentalDialog(state);
});
innerContent.addSpacer(2);
dscBox = innerContent.indent(24);
dscBox.addMultilineText(
fill(),
fit(),
translatable("description.config.bclib.client.ui.suppressExperimentalDialogOnLoad")
)
.setColor(ColorUtil.GRAY);
dscBox.addSpacer(8);
// Use BetterX WorldType
innerContent.addSpacer(8);
Checkbox betterx = innerContent.addCheckbox(
fit(),
fit(),
translatable("title.config.bclib.client.ui.forceBetterXPreset"),
Configs.CLIENT_CONFIG.forceBetterXPreset()
)
.onChange((cb, state) -> {
Configs.CLIENT_CONFIG.setForceBetterXPreset(state);
});
innerContent.addSpacer(2);
dscBox = innerContent.indent(24);
dscBox.addMultilineText(
fill(), fit(),
translatable("warning.config.bclib.client.ui.forceBetterXPreset")
.setStyle(Style.EMPTY
.withBold(true)
.withColor(ColorUtil.RED)
)
.append(translatable(
"description.config.bclib.client.ui.forceBetterXPreset").setStyle(
Style.EMPTY
.withBold(false)
.withColor(ColorUtil.GRAY))
)
)
.setColor(ColorUtil.GRAY);
dscBox.addSpacer(8);
innerContent.addSpacer(16);
innerContent.addButton(fit(), fit(), CommonComponents.GUI_PROCEED).onPress((bt) -> {
Configs.CLIENT_CONFIG.setDidShowWelcomeScreen();
Configs.CLIENT_CONFIG.setCheckVersions(check.isChecked());
Configs.CLIENT_CONFIG.setSuppressExperimentalDialog(experimental.isChecked());
Configs.CLIENT_CONFIG.setForceBetterXPreset(betterx.isChecked());
Configs.CLIENT_CONFIG.saveChanges();
WorldsTogether.SURPRESS_EXPERIMENTAL_DIALOG = Configs.CLIENT_CONFIG.suppressExperimentalDialog();
if (Configs.CLIENT_CONFIG.forceBetterXPreset())
WorldPresets.setDEFAULT(PresetsRegistry.BCL_WORLD);
else
WorldPresets.setDEFAULT(net.minecraft.world.level.levelgen.presets.WorldPresets.NORMAL);
VersionChecker.startCheck(true);
onClose();
}).alignRight();
return VerticalScroll.create(fill(), fill(), content);
return VerticalScroll.create(fill(), fill(), content).setScrollerPadding(0);
}
private void addSeparator(VerticalStack innerContent, ResourceLocation image) {
final int sepWidth = (int) (427 / 1.181) / 2;
HorizontalStack separator = new HorizontalStack(fit(), fit()).centerHorizontal();
separator.addHLine(fixed((sepWidth - 32) / 2), fixed(32)).centerVertical();
separator.addSpacer(1);
separator.addImage(fixed(32), fixed(32), image, Size.of(64)).alignBottom();
separator.addHLine(fixed((sepWidth - 32) / 2), fixed(32)).centerVertical();
innerContent.addSpacer(16);
innerContent.add(separator);
innerContent.addSpacer(4);
}
@Override
protected LayoutComponent<?, ?> addTitle(LayoutComponent<?, ?> content) {
return content;
}
@Override
protected void renderBackground(PoseStack poseStack, int i, int j, float f) {
GuiComponent.fill(poseStack, 0, 0, width, height, 0xBD343444);
// Rectangle BANNER_UV = new Rectangle(0, 0, 427, 100);
// Size BANNER_RESOURCE_SIZE = BANNER_UV.size();
// Size BANNER_SIZE = BANNER_UV.sizeFromWidth(this.width);
//
// RenderHelper.renderImage(
// poseStack,
// BANNER_SIZE.width(),
// BANNER_SIZE.height(),
// BACKGROUND,
// BANNER_UV,
// BANNER_RESOURCE_SIZE,
// 1.0f
// );
}
}