Finished new End-Settings for WorldEdit Screen

This commit is contained in:
Frank 2022-07-20 01:23:47 +02:00
parent 7546efe097
commit cb1986a1fa
12 changed files with 106 additions and 67 deletions

View file

@ -40,6 +40,11 @@ public class WorldSetupScreen extends LayoutScreen {
private final WorldCreationContext context;
private final CreateWorldScreen createWorldScreen;
private Range<Integer> landBiomeSize;
private Range<Integer> voidBiomeSize;
private Range<Integer> centerBiomeSize;
private Range<Integer> barrensBiomeSize;
private Range<Integer> innerRadius;
public WorldSetupScreen(@Nullable CreateWorldScreen parent, WorldCreationContext context) {
super(parent, Component.translatable("title.screen.bclib.worldgen.main"), 10, 10, 10);
@ -57,7 +62,7 @@ public class WorldSetupScreen extends LayoutScreen {
public LayoutComponent<?, ?> netherPage(BCLNetherBiomeSourceConfig netherConfig) {
VerticalStack content = new VerticalStack(Value.fill(), Value.fit()).centerHorizontal();
content.addSpacer(4);
content.addSpacer(8);
bclibNether = content.addCheckbox(
Value.fit(), Value.fit(),
@ -75,12 +80,14 @@ public class WorldSetupScreen extends LayoutScreen {
bclibNether.onChange((cb, state) -> {
netherLegacy.setEnabled(state);
});
content.addSpacer(8);
return content.setDebugName("Nether page");
}
public LayoutComponent<?, ?> endPage(BCLEndBiomeSourceConfig endConfig) {
VerticalStack content = new VerticalStack(Value.fill(), Value.fit()).centerHorizontal();
content.addSpacer(4);
content.addSpacer(8);
bclibEnd = content.addCheckbox(
Value.fit(), Value.fit(),
Component.translatable("title.screen.bclib.worldgen.custom_biome_source"),
@ -106,55 +113,55 @@ public class WorldSetupScreen extends LayoutScreen {
);
content.addSpacer(12);
content.addText(Value.fit(), Value.fit(), Component.literal("Average Biome Size (in Chunks)"))
content.addText(Value.fit(), Value.fit(), Component.translatable("title.screen.bclib.worldgen.avg_biome_size"))
.centerHorizontal();
content.addHorizontalSeparator(8).alignTop();
Range<Integer> landBiomeSize = content.addRange(
landBiomeSize = content.addRange(
Value.fixed(200),
Value.fit(),
Component.literal("Land"),
Component.translatable("title.screen.bclib.worldgen.land_biome_size"),
1,
512,
endConfig.landBiomesSize / 16
);
Range<Integer> voidBiomeSize = content.addRange(
voidBiomeSize = content.addRange(
Value.fixed(200),
Value.fit(),
Component.literal("Void"),
Component.translatable("title.screen.bclib.worldgen.void_biome_size"),
1,
512,
endConfig.voidBiomesSize / 16
);
Range<Integer> centerBiomeSize = content.addRange(
centerBiomeSize = content.addRange(
Value.fixed(200),
Value.fit(),
Component.literal("Center"),
Component.translatable("title.screen.bclib.worldgen.center_biome_size"),
1,
512,
endConfig.centerBiomesSize / 16
);
Range<Integer> barrensBiomeSize = content.addRange(
barrensBiomeSize = content.addRange(
Value.fixed(200),
Value.fit(),
Component.literal("Barrens"),
Component.translatable("title.screen.bclib.worldgen.barrens_biome_size"),
1,
512,
endConfig.barrensBiomesSize / 16
);
content.addSpacer(12);
content.addText(Value.fit(), Value.fit(), Component.literal("Other Settings"))
content.addText(Value.fit(), Value.fit(), Component.translatable("title.screen.bclib.worldgen.other"))
.centerHorizontal();
content.addHorizontalSeparator(8).alignTop();
Range<Integer> innerRadius = content.addRange(
innerRadius = content.addRange(
Value.fixed(200),
Value.fit(),
Component.literal("Central Void Radius"),
Component.translatable("title.screen.bclib.worldgen.central_radius"),
1,
512,
(int) Math.sqrt(endConfig.innerVoidRadiusSquared) / 16
@ -167,17 +174,23 @@ public class WorldSetupScreen extends LayoutScreen {
generateEndVoid.setEnabled(state);
landBiomeSize.setEnabled(state && endCustomTerrain.isChecked());
voidBiomeSize.setEnabled(state && endCustomTerrain.isChecked());
voidBiomeSize.setEnabled(state && endCustomTerrain.isChecked() && generateEndVoid.isChecked());
centerBiomeSize.setEnabled(state && endCustomTerrain.isChecked());
barrensBiomeSize.setEnabled(state && endCustomTerrain.isChecked());
});
endCustomTerrain.onChange((cb, state) -> {
landBiomeSize.setEnabled(state);
voidBiomeSize.setEnabled(state);
voidBiomeSize.setEnabled(state && generateEndVoid.isChecked());
centerBiomeSize.setEnabled(state);
barrensBiomeSize.setEnabled(state);
});
generateEndVoid.onChange((cb, state) -> {
voidBiomeSize.setEnabled(state && endCustomTerrain.isChecked());
});
content.addSpacer(8);
return content.setDebugName("End Page");
}
@ -198,11 +211,11 @@ public class WorldSetupScreen extends LayoutScreen {
? BCLEndBiomeSourceConfig.EndBiomeGeneratorType.PAULEVS
: BCLEndBiomeSourceConfig.EndBiomeGeneratorType.VANILLA,
generateEndVoid.isChecked(),
BCLEndBiomeSourceConfig.DEFAULT.innerVoidRadiusSquared,
BCLEndBiomeSourceConfig.DEFAULT.centerBiomesSize,
BCLEndBiomeSourceConfig.DEFAULT.voidBiomesSize,
BCLEndBiomeSourceConfig.DEFAULT.landBiomesSize,
BCLEndBiomeSourceConfig.DEFAULT.barrensBiomesSize
(int) Math.pow(innerRadius.getValue() * 16, 2),
centerBiomeSize.getValue(),
voidBiomeSize.getValue(),
landBiomeSize.getValue(),
barrensBiomeSize.getValue()
);
ChunkGenerator endGenerator = betterxDimensions.get(LevelStem.END);
@ -307,7 +320,7 @@ public class WorldSetupScreen extends LayoutScreen {
var netherPage = netherPage(netherConfig);
var endPage = endPage(endConfig);
Tabs main = new Tabs(Value.fill(), Value.fill());
Tabs main = new Tabs(Value.fill(), Value.fill()).setPadding(8, 0, 0, 0);
main.addPage(Component.translatable("title.bclib.the_nether"), VerticalScroll.create(netherPage));
main.addPage(Component.translatable("title.bclib.the_end"), VerticalScroll.create(endPage));

View file

@ -1,6 +1,8 @@
package org.betterx.bclib.integration.modmenu;
import org.betterx.bclib.client.gui.modmenu.MainScreen;
import org.betterx.bclib.client.gui.modmenu.TestScreen;
import net.minecraft.network.chat.Component;
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.terraformersmc.modmenu.api.ModMenuApi;
@ -26,8 +28,8 @@ public class ModMenuEntryPoint implements ModMenuApi {
@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
//return (parent) -> new TestScreen(parent, Component.literal("Hello Test"));
return (parent) -> new MainScreen(parent);
return (parent) -> new TestScreen(parent, Component.literal("Hello Test"));
//return (parent) -> new MainScreen(parent);
}

View file

@ -2,7 +2,6 @@ package org.betterx.ui.layout.components;
import org.betterx.ui.layout.components.input.RelativeContainerEventHandler;
import org.betterx.ui.layout.components.render.ComponentRenderer;
import org.betterx.ui.layout.components.render.NullRenderer;
import org.betterx.ui.layout.values.Rectangle;
import org.betterx.ui.layout.values.Size;
import org.betterx.ui.layout.values.Value;
@ -152,16 +151,16 @@ public abstract class AbstractStack<R extends ComponentRenderer, T extends Abstr
return b;
}
protected VerticalScroll<NullRenderer, VanillaScrollerRenderer> addScrollable(LayoutComponent<?, ?> content) {
protected VerticalScroll<VanillaScrollerRenderer> addScrollable(LayoutComponent<?, ?> content) {
return addScrollable(Value.fill(), Value.fill(), content);
}
protected VerticalScroll<NullRenderer, VanillaScrollerRenderer> addScrollable(
protected VerticalScroll<VanillaScrollerRenderer> addScrollable(
Value width,
Value height,
LayoutComponent<?, ?> content
) {
VerticalScroll<NullRenderer, VanillaScrollerRenderer> s = VerticalScroll.create(width, height, content);
VerticalScroll<VanillaScrollerRenderer> s = VerticalScroll.create(width, height, content);
add(s);
return s;
}

View file

@ -47,7 +47,7 @@ public class Container extends LayoutComponent<Container.ContainerRenderer, Cont
GuiEventListener focused = null;
boolean visible = true;
int padding = 0;
int paddingLeft, paddingTop, paddingRight, paddingBottom;
int backgroundColor = 0;
int outlineColor = 0;
@ -93,22 +93,29 @@ public class Container extends LayoutComponent<Container.ContainerRenderer, Cont
}
public Container setPadding(int padding) {
this.padding = padding;
return this;
return setPadding(padding, padding, padding, padding);
}
public int getPadding() {
return padding;
public Container setPadding(int left, int top, int right, int bottom) {
this.paddingLeft = left;
this.paddingTop = top;
this.paddingRight = right;
this.paddingBottom = bottom;
return this;
}
@Override
public int getContentWidth() {
return children.stream().map(LayoutComponent::getContentWidth).reduce(0, Math::max) + 2 * padding;
return children.stream()
.map(LayoutComponent::getContentWidth)
.reduce(0, Math::max) + paddingLeft + paddingRight;
}
@Override
public int getContentHeight() {
return children.stream().map(LayoutComponent::getContentHeight).reduce(0, Math::max) + 2 * padding;
return children.stream()
.map(LayoutComponent::getContentHeight)
.reduce(0, Math::max) + paddingTop + paddingBottom;
}
@Override
@ -146,7 +153,7 @@ public class Container extends LayoutComponent<Container.ContainerRenderer, Cont
protected int updateContainerWidth(int containerWidth) {
int myWidth = width.calculateOrFill(containerWidth);
for (var child : children) {
child.width.calculateOrFill(myWidth - 2 * padding);
child.width.calculateOrFill(myWidth - (paddingLeft + paddingRight));
child.updateContainerWidth(child.width.calculatedSize());
}
return myWidth;
@ -156,7 +163,7 @@ public class Container extends LayoutComponent<Container.ContainerRenderer, Cont
protected int updateContainerHeight(int containerHeight) {
int myHeight = height.calculateOrFill(containerHeight);
for (var child : children) {
child.height.calculateOrFill(myHeight - 2 * padding);
child.height.calculateOrFill(myHeight - (paddingTop + paddingBottom));
child.updateContainerHeight(child.height.calculatedSize());
}
return myHeight;
@ -190,15 +197,15 @@ public class Container extends LayoutComponent<Container.ContainerRenderer, Cont
super.setRelativeBounds(left, top);
for (var child : children) {
int childLeft = (relativeBounds.width - 2 * padding) - child.width.calculatedSize();
int childLeft = (relativeBounds.width - (paddingLeft + paddingRight)) - child.width.calculatedSize();
if (child.hAlign == Alignment.MIN) childLeft = 0;
else if (child.hAlign == Alignment.CENTER) childLeft /= 2;
int childTop = (relativeBounds.height - 2 * padding) - child.height.calculatedSize();
int childTop = (relativeBounds.height - (paddingTop + paddingBottom)) - child.height.calculatedSize();
if (child.vAlign == Alignment.MIN) childTop = 0;
else if (child.vAlign == Alignment.CENTER) childTop /= 2;
child.setRelativeBounds(padding + childLeft, padding + childTop);
child.setRelativeBounds(paddingLeft + childLeft, paddingTop + childTop);
}
}

View file

@ -1,6 +1,5 @@
package org.betterx.ui.layout.components;
import org.betterx.ui.layout.components.render.NullRenderer;
import org.betterx.ui.layout.values.Size;
import org.betterx.ui.layout.values.Value;
import org.betterx.ui.vanilla.VanillaScrollerRenderer;
@ -170,7 +169,7 @@ public class HorizontalStack extends AbstractHorizontalStack<HorizontalStack> {
}
@Override
public VerticalScroll<NullRenderer, VanillaScrollerRenderer> addScrollable(LayoutComponent<?, ?> content) {
public VerticalScroll<VanillaScrollerRenderer> addScrollable(LayoutComponent<?, ?> content) {
return super.addScrollable(content);
}
@ -190,7 +189,7 @@ public class HorizontalStack extends AbstractHorizontalStack<HorizontalStack> {
}
@Override
public VerticalScroll<NullRenderer, VanillaScrollerRenderer> addScrollable(
public VerticalScroll<VanillaScrollerRenderer> addScrollable(
Value width,
Value height,
LayoutComponent<?, ?> content

View file

@ -68,6 +68,10 @@ public class Range<N extends Number> extends AbstractVanillaComponent<Slider<N>,
);
}
public N getValue() {
return vanillaComponent.currentValue();
}
@Override
protected Component contentComponent() {

View file

@ -79,8 +79,9 @@ public class Tabs extends AbstractVerticalStack<Tabs> {
return this;
}
public int getPadding() {
return content.getPadding();
public Tabs setPadding(int left, int top, int right, int bottom) {
content.setPadding(left, top, right, bottom);
return this;
}

View file

@ -1,6 +1,5 @@
package org.betterx.ui.layout.components;
import org.betterx.ui.layout.components.render.ComponentRenderer;
import org.betterx.ui.layout.components.render.NullRenderer;
import org.betterx.ui.layout.components.render.ScrollerRenderer;
import org.betterx.ui.layout.values.Alignment;
@ -19,10 +18,9 @@ import java.util.List;
import org.jetbrains.annotations.Nullable;
@Environment(EnvType.CLIENT)
public class VerticalScroll<R extends ComponentRenderer, RS extends ScrollerRenderer> extends LayoutComponent<R, VerticalScroll<R, RS>> implements ContainerEventHandler {
public class VerticalScroll<RS extends ScrollerRenderer> extends LayoutComponent<NullRenderer, VerticalScroll<RS>> implements ContainerEventHandler {
protected LayoutComponent<?, ?> child;
protected final RS scrollerRenderer;
protected Rectangle viewBounds;
protected int dist;
protected double scrollerY;
@ -30,29 +28,26 @@ public class VerticalScroll<R extends ComponentRenderer, RS extends ScrollerRend
protected int travel;
protected int topOffset;
public VerticalScroll(Value width, Value height, RS scrollerRenderer) {
this(width, height, scrollerRenderer, null);
}
protected boolean keepSpaceForScrollbar = true;
public VerticalScroll(Value width, Value height, RS scrollerRenderer, R renderer) {
super(width, height, renderer);
public VerticalScroll(Value width, Value height, RS scrollerRenderer) {
super(width, height, new NullRenderer());
this.scrollerRenderer = scrollerRenderer;
}
public static VerticalScroll<NullRenderer, VanillaScrollerRenderer> create(LayoutComponent<?, ?> c) {
public static VerticalScroll<VanillaScrollerRenderer> create(LayoutComponent<?, ?> c) {
return create(Value.relative(1), Value.relative(1), c);
}
public static VerticalScroll<NullRenderer, VanillaScrollerRenderer> create(
public static VerticalScroll<VanillaScrollerRenderer> create(
Value width,
Value height,
LayoutComponent<?, ?> c
) {
VerticalScroll<NullRenderer, VanillaScrollerRenderer> res = new VerticalScroll<>(
VerticalScroll<VanillaScrollerRenderer> res = new VerticalScroll<>(
width,
height,
VanillaScrollerRenderer.DEFAULT,
null
VanillaScrollerRenderer.DEFAULT
);
res.setChild(c);
return res;
@ -60,9 +55,15 @@ public class VerticalScroll<R extends ComponentRenderer, RS extends ScrollerRend
List<LayoutComponent<?, ?>> children = List.of();
public void setChild(LayoutComponent<?, ?> c) {
public VerticalScroll<RS> setChild(LayoutComponent<?, ?> c) {
this.child = c;
children = List.of(child);
return this;
}
public VerticalScroll<RS> setKeepSpaceForScrollbar(boolean value) {
keepSpaceForScrollbar = value;
return this;
}
@Override
@ -107,7 +108,7 @@ public class VerticalScroll<R extends ComponentRenderer, RS extends ScrollerRend
if (child != null) {
int width = relativeBounds.width;
boolean willNeedScrollBar = child.height.calculatedSize() > relativeBounds.height;
boolean willNeedScrollBar = keepSpaceForScrollbar || child.height.calculatedSize() > relativeBounds.height;
if (willNeedScrollBar) width -= scrollerWidth();
int childLeft = width - child.width.calculatedSize();
if (child.hAlign == Alignment.MIN) childLeft = 0;

View file

@ -1,7 +1,6 @@
package org.betterx.ui.layout.components;
import org.betterx.ui.layout.components.render.NullRenderer;
import org.betterx.ui.layout.values.Size;
import org.betterx.ui.layout.values.Value;
import org.betterx.ui.vanilla.VanillaScrollerRenderer;
@ -182,7 +181,7 @@ public class VerticalStack extends AbstractVerticalStack<VerticalStack> {
}
@Override
public VerticalScroll<NullRenderer, VanillaScrollerRenderer> addScrollable(LayoutComponent<?, ?> content) {
public VerticalScroll<VanillaScrollerRenderer> addScrollable(LayoutComponent<?, ?> content) {
return super.addScrollable(content);
}
@ -202,7 +201,7 @@ public class VerticalStack extends AbstractVerticalStack<VerticalStack> {
}
@Override
public VerticalScroll<NullRenderer, VanillaScrollerRenderer> addScrollable(
public VerticalScroll<VanillaScrollerRenderer> addScrollable(
Value width,
Value height,
LayoutComponent<?, ?> content

View file

@ -56,7 +56,7 @@ public class Slider<N extends Number> extends AbstractSliderButton {
this.updateMessage();
}
protected N currentValue() {
public N currentValue() {
Double res = value * (maxValue.doubleValue() - minValue.doubleValue()) + minValue.doubleValue();
if (minValue instanceof Integer) {
return (N) (Integer) res.intValue();

View file

@ -57,5 +57,12 @@
"title.screen.bclib.worldgen.custom_biome_source": "Benutzerdefinierte Biomquelle verwenden",
"title.screen.bclib.worldgen.legacy_square": "Legacy-Verteilung (1.17)",
"title.screen.bclib.worldgen.custom_end_terrain": "Angepasster End-Terrain-Generator",
"title.screen.bclib.worldgen.end_void": "Kleine End-Inseln erzeugen"
"title.screen.bclib.worldgen.end_void": "Kleine End-Inseln erzeugen",
"title.screen.bclib.worldgen.avg_biome_size": "Durchscnittl. Biome Größe (in Chunks)",
"title.screen.bclib.worldgen.other": "Sonstiges",
"title.screen.bclib.worldgen.land_biome_size": "Land-Biome",
"title.screen.bclib.worldgen.void_biome_size": "Kleine Inseln",
"title.screen.bclib.worldgen.center_biome_size": "Zentralbiome",
"title.screen.bclib.worldgen.barrens_biome_size": "Ödniss",
"title.screen.bclib.worldgen.central_radius": "Innerer Radius (in Chunks)"
}

View file

@ -58,5 +58,12 @@
"title.screen.bclib.worldgen.custom_biome_source": "Use Custom Biome Source",
"title.screen.bclib.worldgen.legacy_square": "Use Legacy Map (1.17)",
"title.screen.bclib.worldgen.custom_end_terrain": "Custom End Terrain Generator",
"title.screen.bclib.worldgen.end_void": "Generate small Islands"
"title.screen.bclib.worldgen.avg_biome_size": "Average Biome Size (in Chunks)",
"title.screen.bclib.worldgen.other": "Other Settings",
"title.screen.bclib.worldgen.land_biome_size": "Land Biomes",
"title.screen.bclib.worldgen.void_biome_size": "Small Island Biomes",
"title.screen.bclib.worldgen.center_biome_size": "Central Biomes",
"title.screen.bclib.worldgen.barrens_biome_size": "Barrens",
"title.screen.bclib.worldgen.central_radius": "Central Void Radius (in Chunks)",
"title.screen.bclib.worldgen.end_void": "Generate Small Islands"
}