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
// );
}
}

View file

@ -23,6 +23,13 @@ public class ClientConfig extends NamedPathConfig {
"showUpdateInfo",
"ui"
);
@ConfigUI(hide = true)
public static final ConfigToken<Boolean> FORCE_BETTERX_PRESET = ConfigToken.Boolean(
true,
"forceBetterXPreset",
"ui"
);
public static final ConfigToken<Boolean> SUPPRESS_EXPERIMENTAL_DIALOG = ConfigToken.Boolean(
false,
"suppressExperimentalDialogOnLoad",
@ -134,6 +141,10 @@ public class ClientConfig extends NamedPathConfig {
return get(SUPPRESS_EXPERIMENTAL_DIALOG);
}
public void setSuppressExperimentalDialog(boolean newValue) {
set(ClientConfig.SUPPRESS_EXPERIMENTAL_DIALOG, newValue);
}
public boolean netherThickFog() {
return get(NETHER_THICK_FOG);
}
@ -170,4 +181,12 @@ public class ClientConfig extends NamedPathConfig {
public void setDidShowWelcomeScreen() {
set(ClientConfig.DID_SHOW_WELCOME, true);
}
public boolean forceBetterXPreset() {
return get(FORCE_BETTERX_PRESET);
}
public void setForceBetterXPreset(boolean v) {
set(FORCE_BETTERX_PRESET, v);
}
}

View file

@ -4,6 +4,7 @@ import org.betterx.bclib.BCLib;
import org.betterx.bclib.api.v2.generator.config.BCLEndBiomeSourceConfig;
import org.betterx.bclib.api.v2.generator.config.BCLNetherBiomeSourceConfig;
import org.betterx.bclib.api.v2.levelgen.LevelGenUtil;
import org.betterx.bclib.config.Configs;
import org.betterx.worlds.together.entrypoints.WorldPresetBootstrap;
import org.betterx.worlds.together.levelgen.WorldGenUtil;
import org.betterx.worlds.together.worldPreset.TogetherWorldPreset;
@ -45,7 +46,10 @@ public class PresetsRegistry implements WorldPresetBootstrap {
false
);
WorldPresets.setDEFAULT(BCL_WORLD);
if (Configs.CLIENT_CONFIG.forceBetterXPreset())
WorldPresets.setDEFAULT(BCL_WORLD);
else
WorldPresets.setDEFAULT(net.minecraft.world.level.levelgen.presets.WorldPresets.NORMAL);
}
public static TogetherWorldPreset buildPreset(

View file

@ -255,4 +255,14 @@ public class Container extends LayoutComponent<Container.ContainerRenderer, Cont
}
return false;
}
public static Container create(LayoutComponent<?, ?> content) {
return create(Value.fit(), Value.fit(), content);
}
public static Container create(Value width, Value height, LayoutComponent<?, ?> content) {
Container c = new Container(width, height);
c.addChild(content);
return c;
}
}

View file

@ -1,14 +1,11 @@
package org.betterx.ui.layout.components;
import org.betterx.ui.layout.components.render.RenderHelper;
import org.betterx.ui.layout.values.Rectangle;
import org.betterx.ui.layout.values.Size;
import org.betterx.ui.layout.values.Value;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.gui.GuiComponent;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.resources.ResourceLocation;
import net.fabricmc.api.EnvType;
@ -82,35 +79,7 @@ public class Image extends CustomRenderComponent {
Rectangle bounds,
Rectangle clipRect
) {
renderImage(stack, bounds, location, uvRect, resourceSize, alpha);
}
protected static void renderImage(
PoseStack stack,
Rectangle bounds,
ResourceLocation location,
Rectangle uvRect,
Size size,
float alpha
) {
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderTexture(0, location);
RenderSystem.enableBlend();
RenderSystem.blendFunc(
GlStateManager.SourceFactor.SRC_ALPHA,
GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA
);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, alpha);
GuiComponent.blit(
stack,
0, 0, bounds.width, bounds.height,
uvRect.left,
uvRect.top,
uvRect.width,
uvRect.height,
size.width(),
size.height()
);
RenderHelper.renderImage(stack, bounds.width, bounds.height, location, uvRect, resourceSize, alpha);
}
@Override

View file

@ -28,11 +28,14 @@ public class VerticalScroll<RS extends ScrollerRenderer> extends LayoutComponent
protected int travel;
protected int topOffset;
protected int scrollerPadding;
protected boolean keepSpaceForScrollbar = true;
public VerticalScroll(Value width, Value height, RS scrollerRenderer) {
super(width, height, new NullRenderer());
this.scrollerRenderer = scrollerRenderer;
this.scrollerPadding = scrollerRenderer.scrollerPadding();
}
public static VerticalScroll<VanillaScrollerRenderer> create(LayoutComponent<?, ?> c) {
@ -61,6 +64,11 @@ public class VerticalScroll<RS extends ScrollerRenderer> extends LayoutComponent
return this;
}
public VerticalScroll<RS> setScrollerPadding(int pad) {
this.scrollerPadding = pad;
return this;
}
public VerticalScroll<RS> setKeepSpaceForScrollbar(boolean value) {
keepSpaceForScrollbar = value;
return this;
@ -87,7 +95,7 @@ public class VerticalScroll<RS extends ScrollerRenderer> extends LayoutComponent
}
protected int scrollerWidth() {
return scrollerRenderer.scrollerWidth() + scrollerRenderer.scrollerPadding();
return scrollerRenderer.scrollerWidth() + scrollerPadding;
}
@Override

View file

@ -1,11 +1,16 @@
package org.betterx.ui.layout.components.render;
import org.betterx.ui.ColorUtil;
import org.betterx.ui.layout.values.Rectangle;
import org.betterx.ui.layout.values.Size;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.*;
import com.mojang.math.Matrix4f;
import net.minecraft.client.gui.GuiComponent;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.resources.ResourceLocation;
public class RenderHelper {
public static void outline(PoseStack poseStack, int x0, int y0, int x1, int y1, int color) {
@ -79,4 +84,32 @@ public class RenderHelper {
RenderSystem.enableTexture();
RenderSystem.disableBlend();
}
public static void renderImage(
PoseStack stack,
int width, int height,
ResourceLocation location,
Rectangle uvRect,
Size resourceSize,
float alpha
) {
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderTexture(0, location);
RenderSystem.enableBlend();
RenderSystem.blendFunc(
GlStateManager.SourceFactor.SRC_ALPHA,
GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA
);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, alpha);
GuiComponent.blit(
stack,
0, 0, width, height,
uvRect.left,
uvRect.top,
uvRect.width,
uvRect.height,
resourceSize.width(),
resourceSize.height()
);
}
}

View file

@ -18,6 +18,26 @@ public class Rectangle {
this.height = height;
}
public float aspect() {
return (float) width / height;
}
public Size sizeFromWidth(int width) {
return new Size(width, (int) (width / aspect()));
}
public Size sizeFromHeight(int height) {
return new Size((int) (height * aspect()), height);
}
public Size size(float scale) {
return new Size((int) (width * scale), (int) (height * scale));
}
public Size size() {
return new Size(width, height);
}
public int right() {
return left + width;
}