[Changes] Converted Screens to new Layout Engine

This commit is contained in:
Frank 2022-07-21 22:42:42 +02:00
parent 96bfdc5afa
commit 2d997c53ce
31 changed files with 475 additions and 375 deletions

View file

@ -10,6 +10,7 @@ import net.fabricmc.api.Environment;
import java.util.List;
import java.util.function.Function;
@Deprecated(forRemoval = true)
@Environment(EnvType.CLIENT)
class GridCell extends GridCellDefinition {
public final float height;

View file

@ -8,6 +8,7 @@ import net.fabricmc.api.Environment;
import java.util.function.Consumer;
@Deprecated(forRemoval = true)
@Environment(EnvType.CLIENT)
class SignalingCheckBox extends Checkbox {
private final Consumer<Boolean> onChange;
@ -35,6 +36,7 @@ class SignalingCheckBox extends Checkbox {
}
}
@Deprecated(forRemoval = true)
@Environment(EnvType.CLIENT)
public class GridCheckboxCell extends GridCell implements GridWidgetWithEnabledState {
private boolean checked;

View file

@ -5,6 +5,10 @@ import net.fabricmc.api.Environment;
import java.util.List;
/**
* @deprecated Please use {@link org.betterx.ui.layout.components.VerticalStack} instead
*/
@Deprecated(forRemoval = true)
@Environment(EnvType.CLIENT)
public class GridColumn extends GridContainer {
GridColumn(double width) {

View file

@ -8,6 +8,7 @@ import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
@Deprecated(forRemoval = true)
@Environment(EnvType.CLIENT)
public abstract class GridCustomRenderCell extends GridCell {
protected GridCustomRenderCell(double width, GridValueType widthType, double height) {

View file

@ -9,6 +9,7 @@ import net.minecraft.resources.ResourceLocation;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
@Deprecated(forRemoval = true)
@Environment(EnvType.CLIENT)
public class GridImageCell extends GridCell {
GridImageCell(

View file

@ -15,6 +15,7 @@ import java.util.List;
import java.util.function.Function;
@Deprecated(forRemoval = true)
@Environment(EnvType.CLIENT)
abstract class GridCellDefinition {
public final float width;
@ -57,6 +58,7 @@ abstract class GridCellDefinition {
abstract protected GridElement buildElementAt(int left, int top, int width, final List<GridElement> collector);
}
@Deprecated(forRemoval = true)
@Environment(EnvType.CLIENT)
class GridElement extends GridTransform {
final Function<GridTransform, Object> componentPlacer;
@ -85,6 +87,7 @@ class GridElement extends GridTransform {
}
}
@Deprecated(forRemoval = true)
@Environment(EnvType.CLIENT)
abstract class GridContainer extends GridCellDefinition {
protected List<GridCellDefinition> cells;
@ -99,6 +102,11 @@ abstract class GridContainer extends GridCellDefinition {
}
}
/**
* @deprecated Please use {@link org.betterx.ui.layout.components.Panel} instead
*/
@Deprecated(forRemoval = true)
@Environment(EnvType.CLIENT)
public class GridLayout extends GridColumn {
public static final int COLOR_WHITE = 0xFFFFFFFF;

View file

@ -9,6 +9,7 @@ import net.fabricmc.api.Environment;
import java.util.List;
@Deprecated(forRemoval = true)
@Environment(EnvType.CLIENT)
public class GridMessageCell extends GridCell {
private final Font font;

View file

@ -15,6 +15,10 @@ import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;
/**
* @deprecated Please use {@link org.betterx.ui.layout.components.HorizontalStack} instead
*/
@Deprecated(forRemoval = true)
@Environment(EnvType.CLIENT)
public class GridRow extends GridContainer {
public final GridLayout.VerticalAlignment alignment;

View file

@ -16,7 +16,10 @@ import net.fabricmc.api.Environment;
import org.jetbrains.annotations.Nullable;
/**
* @deprecated Use {@link org.betterx.ui.vanilla.LayoutScreen} or {@link org.betterx.ui.vanilla.LayoutScreenWithIcon} instead
*/
@Deprecated(forRemoval = true)
@Environment(EnvType.CLIENT)
public abstract class GridScreen extends Screen {
protected GridLayout grid = null;

View file

@ -6,6 +6,7 @@ import net.minecraft.network.chat.Component;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
@Deprecated(forRemoval = true)
@Environment(EnvType.CLIENT)
public class GridStringCell extends GridCell {
private Component text;

View file

@ -3,6 +3,7 @@ package org.betterx.bclib.client.gui.gridlayout;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
@Deprecated(forRemoval = true)
@Environment(EnvType.CLIENT)
public class GridTransform {
public final int left;

View file

@ -1,5 +1,6 @@
package org.betterx.bclib.client.gui.gridlayout;
@Deprecated(forRemoval = true)
public interface GridWidgetWithEnabledState {
boolean isEnabled();
void setEnabled(boolean enabled);

View file

@ -10,7 +10,6 @@ import org.betterx.ui.layout.components.Checkbox;
import org.betterx.ui.layout.components.HorizontalStack;
import org.betterx.ui.layout.components.LayoutComponent;
import org.betterx.ui.layout.components.VerticalStack;
import org.betterx.ui.layout.values.Value;
import org.betterx.ui.vanilla.LayoutScreenWithIcon;
import net.minecraft.client.gui.screens.Screen;
@ -59,7 +58,7 @@ public class MainScreen extends LayoutScreenWithIcon {
row.addSpacer(option.leftPadding);
}
Checkbox cb = row.addCheckbox(
Value.fit(), Value.fit(),
fit(), fit(),
getComponent(config, option, "title"),
config.getRaw(option.token)
).onChange(
@ -84,7 +83,7 @@ public class MainScreen extends LayoutScreenWithIcon {
@Override
protected LayoutComponent initContent() {
VerticalStack content = new VerticalStack(Value.fit(), Value.fit()).setDebugName("content");
VerticalStack content = new VerticalStack(fit(), fit()).setDebugName("content");
Configs.GENERATOR_CONFIG.getAllOptions()
.stream()
@ -102,10 +101,10 @@ public class MainScreen extends LayoutScreenWithIcon {
.forEach(o -> addRow(content, Configs.CLIENT_CONFIG, o));
VerticalStack grid = new VerticalStack(Value.fill(), Value.fill()).setDebugName("main grid");
VerticalStack grid = new VerticalStack(fill(), fill()).setDebugName("main grid");
grid.addScrollable(content);
grid.addSpacer(8);
grid.addButton(Value.fit(), Value.fit(), CommonComponents.GUI_DONE).onPress((button) -> {
grid.addButton(fit(), fit(), CommonComponents.GUI_DONE).onPress((button) -> {
Configs.CLIENT_CONFIG.saveChanges();
Configs.GENERATOR_CONFIG.saveChanges();
Configs.MAIN_CONFIG.saveChanges();

View file

@ -4,7 +4,6 @@ import org.betterx.bclib.BCLib;
import org.betterx.ui.ColorUtil;
import org.betterx.ui.layout.components.*;
import org.betterx.ui.layout.values.Size;
import org.betterx.ui.layout.values.Value;
import org.betterx.ui.vanilla.LayoutScreen;
import net.minecraft.client.gui.screens.Screen;
@ -25,51 +24,51 @@ public class TestScreen extends LayoutScreen {
@Override
protected LayoutComponent<?, ?> initContent() {
VerticalStack page1 = new VerticalStack(Value.fill(), Value.fit());
page1.addText(Value.fit(), Value.fit(), Component.literal("Page 1")).alignLeft().centerVertical();
page1.addButton(Value.fit(), Value.fit(), Component.literal("A1")).onPress((bt) -> System.out.println("A1"))
VerticalStack page1 = new VerticalStack(fill(), fit());
page1.addText(fit(), fit(), Component.literal("Page 1")).alignLeft().centerVertical();
page1.addButton(fit(), fit(), Component.literal("A1")).onPress((bt) -> System.out.println("A1"))
.centerHorizontal();
page1.addButton(Value.fit(), Value.fit(), Component.literal("A2")).onPress((bt) -> System.out.println("A2"))
page1.addButton(fit(), fit(), Component.literal("A2")).onPress((bt) -> System.out.println("A2"))
.centerHorizontal();
page1.addButton(Value.fit(), Value.fit(), Component.literal("A3")).onPress((bt) -> System.out.println("A3"))
page1.addButton(fit(), fit(), Component.literal("A3")).onPress((bt) -> System.out.println("A3"))
.centerHorizontal();
page1.addButton(Value.fit(), Value.fit(), Component.literal("A4")).onPress((bt) -> System.out.println("A4"))
page1.addButton(fit(), fit(), Component.literal("A4")).onPress((bt) -> System.out.println("A4"))
.centerHorizontal();
page1.addRange(Value.fixed(100), Value.fit(), Component.literal("N1"), 0, 10, 5);
page1.addRange(fixed(100), fit(), Component.literal("N1"), 0, 10, 5);
VerticalStack page2 = new VerticalStack(Value.fill(), Value.fit());
page2.addText(Value.fit(), Value.fit(), Component.literal("Page 2")).alignRight().centerVertical();
page2.addButton(Value.fit(), Value.fit(), Component.literal("B1")).onPress((bt) -> System.out.println("B1"))
VerticalStack page2 = new VerticalStack(fill(), fit());
page2.addText(fit(), fit(), Component.literal("Page 2")).alignRight().centerVertical();
page2.addButton(fit(), fit(), Component.literal("B1")).onPress((bt) -> System.out.println("B1"))
.centerHorizontal();
page2.addButton(Value.fit(), Value.fit(), Component.literal("B2")).onPress((bt) -> System.out.println("B2"))
page2.addButton(fit(), fit(), Component.literal("B2")).onPress((bt) -> System.out.println("B2"))
.centerHorizontal();
page2.addButton(Value.fit(), Value.fit(), Component.literal("B3")).onPress((bt) -> System.out.println("B3"))
page2.addButton(fit(), fit(), Component.literal("B3")).onPress((bt) -> System.out.println("B3"))
.centerHorizontal();
page2.addButton(Value.fit(), Value.fit(), Component.literal("B4")).onPress((bt) -> System.out.println("B4"))
page2.addButton(fit(), fit(), Component.literal("B4")).onPress((bt) -> System.out.println("B4"))
.centerHorizontal();
page2.addRange(Value.fixed(100), Value.fit(), Component.literal("N2"), 0, 10, 5);
page2.addRange(fixed(100), fit(), Component.literal("N2"), 0, 10, 5);
Container c = new Container(Value.fill(), Value.fixed(40));
c.addChild(new Button(Value.fit(), Value.fit(), Component.literal("Containerd")).onPress(bt -> {
Container c = new Container(fill(), fixed(40));
c.addChild(new Button(fit(), fit(), Component.literal("Containerd")).onPress(bt -> {
System.out.println("Containerd");
}).centerHorizontal().centerVertical());
c.setBackgroundColor(0x77000000);
VerticalStack rows = new VerticalStack(Value.fit(), Value.fitOrFill());
VerticalStack rows = new VerticalStack(fit(), fitOrFill());
rows.addFiller();
rows.add(new Text(
Value.fitOrFill(), Value.fixed(20),
fitOrFill(), fixed(20),
Component.literal("Some Text")
).alignRight()
);
rows.add(new Text(
Value.fitOrFill(), Value.fixed(20),
fitOrFill(), fixed(20),
Component.literal("Some other, longer Text")
).centerHorizontal()
);
rows.addHorizontalSeparator(16).alignTop();
rows.add(new Tabs(Value.fixed(300), Value.fixed(80)).addPage(
rows.add(new Tabs(fixed(300), fixed(80)).addPage(
Component.literal("PAGE 1"),
VerticalScroll.create(page1)
)
@ -77,24 +76,24 @@ public class TestScreen extends LayoutScreen {
Component.literal("PAGE 2"),
VerticalScroll.create(page2)
));
rows.add(new Input(Value.fitOrFill(), Value.fit(), Component.literal("Input"), "0xff00ff"));
rows.add(new ColorSwatch(Value.fit(), Value.fit(), ColorUtil.LIGHT_PURPLE).centerHorizontal());
rows.add(new Input(fitOrFill(), fit(), Component.literal("Input"), "0xff00ff"));
rows.add(new ColorSwatch(fit(), fit(), ColorUtil.LIGHT_PURPLE).centerHorizontal());
rows.add(new ColorPicker(
Value.fill(),
Value.fit(),
fill(),
fit(),
Component.literal("Color"),
ColorUtil.GREEN
).centerHorizontal());
rows.add(new Text(
Value.fitOrFill(), Value.fixed(20),
fitOrFill(), fixed(20),
Component.literal("Some blue text")
).centerHorizontal().setColor(ColorUtil.BLUE)
);
rows.addHLine(Value.fixed(32), Value.fixed(16));
rows.addHLine(fixed(32), fixed(16));
rows.add(c);
rows.addCheckbox(
Value.fitOrFill(),
Value.fit(),
fitOrFill(),
fit(),
Component.literal("Hide"),
false
).onChange(
@ -102,13 +101,13 @@ public class TestScreen extends LayoutScreen {
);
rows.addSpacer(16);
rows.add(new Image(
Value.fixed(24), Value.fixed(24),
fixed(24), fixed(24),
BCLib.makeID("icon.png"),
new Size(512, 512)
).centerHorizontal()
);
rows.add(new MultiLineText(
Value.fill(), Value.fit(),
fill(), fit(),
Component.literal(
"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.")
).setColor(ColorUtil.LIGHT_PURPLE).centerHorizontal()
@ -116,7 +115,7 @@ public class TestScreen extends LayoutScreen {
rows.addHorizontalLine(16);
rows.add(new Range<>(
Value.fill(), Value.fit(),
fill(), fit(),
Component.literal("Integer"),
10, 90, 20
).onChange(
@ -126,7 +125,7 @@ public class TestScreen extends LayoutScreen {
));
rows.addSpacer(8);
rows.add(new Range<>(
Value.fill(), Value.fit(),
fill(), fit(),
Component.literal("Float"),
10f, 90f, 20f
).onChange(
@ -136,7 +135,7 @@ public class TestScreen extends LayoutScreen {
));
rows.addSpacer(16);
Checkbox cb1 = new Checkbox(
Value.fit(), Value.fit(),
fit(), fit(),
Component.literal("Some Sub-State"),
false, true
).onChange(
@ -145,7 +144,7 @@ public class TestScreen extends LayoutScreen {
}
);
rows.add(new Checkbox(
Value.fit(), Value.fit(),
fit(), fit(),
Component.literal("Some Selectable State"),
false, true
).onChange(
@ -157,7 +156,7 @@ public class TestScreen extends LayoutScreen {
rows.add(cb1);
rows.addSpacer(16);
rows.add(new Button(
Value.fit(), Value.fit(),
fit(), fit(),
Component.literal("test")
).onPress(
(bt) -> {
@ -167,7 +166,7 @@ public class TestScreen extends LayoutScreen {
);
rows.addSpacer(8);
rows.add(new Button(
Value.fit(), Value.fit(),
fit(), fit(),
Component.literal("Hello World")
).onPress(
(bt) -> {
@ -177,6 +176,6 @@ public class TestScreen extends LayoutScreen {
);
rows.addFiller();
return HorizontalStack.centered(VerticalScroll.create(Value.fit(), Value.relative(1), rows));
return HorizontalStack.centered(VerticalScroll.create(fit(), relative(1), rows));
}
}

View file

@ -0,0 +1,37 @@
package org.betterx.bclib.client.gui.screens;
import org.betterx.bclib.BCLib;
import org.betterx.ui.vanilla.LayoutScreenWithIcon;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.Nullable;
public abstract class BCLibLayoutScreen extends LayoutScreenWithIcon {
static final ResourceLocation BCLIB_LOGO_LOCATION = new ResourceLocation(BCLib.MOD_ID, "icon.png");
public BCLibLayoutScreen(
Component component
) {
super(BCLIB_LOGO_LOCATION, component);
}
public BCLibLayoutScreen(
@Nullable Screen parent,
Component component
) {
super(parent, BCLIB_LOGO_LOCATION, component);
}
public BCLibLayoutScreen(
@Nullable Screen parent,
Component component,
int topPadding,
int bottomPadding,
int sidePadding
) {
super(parent, BCLIB_LOGO_LOCATION, component, topPadding, bottomPadding, sidePadding);
}
}

View file

@ -1,61 +0,0 @@
package org.betterx.bclib.client.gui.screens;
import org.betterx.bclib.BCLib;
import org.betterx.bclib.client.gui.gridlayout.GridLayout;
import org.betterx.bclib.client.gui.gridlayout.GridRow;
import org.betterx.bclib.client.gui.gridlayout.GridScreen;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import org.jetbrains.annotations.Nullable;
@Environment(EnvType.CLIENT)
abstract class BCLibScreen extends GridScreen {
static final ResourceLocation BCLIB_LOGO_LOCATION = new ResourceLocation(BCLib.MOD_ID, "icon.png");
public BCLibScreen(Component title) {
super(title);
}
public BCLibScreen(@Nullable Screen parent, Component title) {
super(parent, title);
}
public BCLibScreen(Component title, int topPadding, boolean centerVertically) {
super(title, topPadding, 20, centerVertically);
}
public BCLibScreen(@Nullable Screen parent, Component title, int topPadding, boolean centerVertically) {
super(parent, title, topPadding, centerVertically);
}
public BCLibScreen(Component title, int topPadding, int sidePadding, boolean centerVertically) {
super(title, topPadding, sidePadding, centerVertically);
}
public BCLibScreen(
@Nullable Screen parent,
Component title,
int topPadding,
int sidePadding,
boolean centerVertically
) {
super(parent, title, topPadding, sidePadding, centerVertically);
}
protected void addTitle() {
GridRow row = grid.addRow(GridLayout.VerticalAlignment.CENTER);
row.addFiller();
row.addImage(BCLIB_LOGO_LOCATION, 24, GridLayout.GridValueType.CONSTANT, 24, 512, 512);
row.addSpacer(4);
row.addString(this.title, this);
row.addFiller();
grid.addSpacerRow(15);
}
}

View file

@ -1,9 +1,10 @@
package org.betterx.bclib.client.gui.screens;
import org.betterx.bclib.client.gui.gridlayout.GridCheckboxCell;
import org.betterx.bclib.client.gui.gridlayout.GridLayout;
import org.betterx.bclib.client.gui.gridlayout.GridRow;
import org.betterx.ui.layout.components.Checkbox;
import org.betterx.ui.layout.components.HorizontalStack;
import org.betterx.ui.layout.components.LayoutComponent;
import org.betterx.ui.layout.components.VerticalStack;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.CommonComponents;
@ -15,7 +16,7 @@ import net.fabricmc.api.Environment;
import org.jetbrains.annotations.Nullable;
@Environment(EnvType.CLIENT)
public class ConfirmFixScreen extends BCLibScreen {
public class ConfirmFixScreen extends BCLibLayoutScreen {
protected final ConfirmFixScreen.Listener listener;
private final Component description;
protected int id;
@ -27,48 +28,38 @@ public class ConfirmFixScreen extends BCLibScreen {
this.description = Component.translatable("bclib.datafixer.backupWarning.message");
}
protected void initLayout() {
final int BUTTON_HEIGHT = 20;
grid.addRow().addMessage(this.description, this.font, GridLayout.Alignment.CENTER);
grid.addSpacerRow();
GridRow row = grid.addRow();
GridCheckboxCell backup = row.addCheckbox(
Component.translatable("bclib.datafixer.backupWarning.backup"),
true,
BUTTON_HEIGHT,
this.font
);
grid.addSpacerRow(10);
row = grid.addRow();
GridCheckboxCell fix = row.addCheckbox(
Component.translatable("bclib.datafixer.backupWarning.fix"),
true,
BUTTON_HEIGHT,
this.font
);
grid.addSpacerRow(20);
row = grid.addRow();
row.addFiller();
row.addButton(CommonComponents.GUI_CANCEL, BUTTON_HEIGHT, this.font, (button) -> {
onClose();
});
row.addSpacer();
row.addButton(CommonComponents.GUI_PROCEED, BUTTON_HEIGHT, this.font, (button) -> {
this.listener.proceed(backup.isChecked(), fix.isChecked());
});
row.addFiller();
}
public boolean shouldCloseOnEsc() {
return true;
}
@Override
protected LayoutComponent<?, ?> initContent() {
VerticalStack grid = new VerticalStack(fill(), fill());
grid.addFiller();
grid.addMultilineText(fill(), fit(), this.description).centerHorizontal();
grid.addSpacer(8);
Checkbox backup = grid.addCheckbox(
fit(), fit(),
Component.translatable("bclib.datafixer.backupWarning.backup"),
true
);
grid.addSpacer(4);
Checkbox fix = grid.addCheckbox(
fit(), fit(),
Component.translatable("bclib.datafixer.backupWarning.fix"),
true
);
grid.addSpacer(20);
HorizontalStack row = grid.addRow().centerHorizontal();
row.addButton(fit(), fit(), CommonComponents.GUI_CANCEL).onPress((button) -> onClose());
row.addSpacer(4);
row.addButton(fit(), fit(), CommonComponents.GUI_PROCEED)
.onPress((button) -> this.listener.proceed(backup.isChecked(), fix.isChecked()));
return grid;
}
@Environment(EnvType.CLIENT)
public interface Listener {
void proceed(boolean createBackup, boolean applyPatches);

View file

@ -1,7 +1,7 @@
package org.betterx.bclib.client.gui.screens;
import org.betterx.bclib.client.gui.gridlayout.GridLayout;
import org.betterx.bclib.client.gui.gridlayout.GridRow;
import org.betterx.ui.layout.components.LayoutComponent;
import org.betterx.ui.layout.components.VerticalStack;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
@ -11,7 +11,7 @@ import net.fabricmc.api.Environment;
@Environment(EnvType.CLIENT)
public class ConfirmRestartScreen extends BCLibScreen {
public class ConfirmRestartScreen extends BCLibLayoutScreen {
private final Component description;
private final ConfirmRestartScreen.Listener listener;
@ -26,25 +26,24 @@ public class ConfirmRestartScreen extends BCLibScreen {
this.listener = listener;
}
protected void initLayout() {
final int BUTTON_HEIGHT = 20;
grid.addRow().addMessage(this.description, this.font, GridLayout.Alignment.CENTER);
grid.addSpacerRow();
GridRow row = grid.addRow();
row.addFiller();
row.addButton(CommonComponents.GUI_PROCEED, BUTTON_HEIGHT, font, (button) -> {
listener.proceed();
});
row.addFiller();
}
public boolean shouldCloseOnEsc() {
return false;
}
@Override
protected LayoutComponent<?, ?> initContent() {
VerticalStack grid = new VerticalStack(fill(), fill());
grid.addFiller();
grid.addMultilineText(fill(), fit(), this.description).centerHorizontal();
grid.addSpacer(10);
grid.addButton(fit(), fit(), CommonComponents.GUI_PROCEED)
.onPress((button) -> listener.proceed())
.centerHorizontal();
grid.addFiller();
return grid;
}
@Environment(EnvType.CLIENT)
public interface Listener {
void proceed();

View file

@ -1,8 +1,9 @@
package org.betterx.bclib.client.gui.screens;
import org.betterx.bclib.client.gui.gridlayout.GridColumn;
import org.betterx.bclib.client.gui.gridlayout.GridLayout;
import org.betterx.bclib.client.gui.gridlayout.GridRow;
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 net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.CommonComponents;
@ -12,47 +13,58 @@ import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
@Environment(EnvType.CLIENT)
public class LevelFixErrorScreen extends BCLibScreen {
public class LevelFixErrorScreen extends BCLibLayoutScreen {
private final String[] errors;
final Listener onContinue;
public LevelFixErrorScreen(Screen parent, String[] errors, Listener onContinue) {
super(parent, Component.translatable("title.bclib.datafixer.error"), 10, true);
super(parent, Component.translatable("title.bclib.datafixer.error"), 10, 10, 10);
this.errors = errors;
this.onContinue = onContinue;
}
@Override
protected void initLayout() {
grid.addSpacerRow();
grid.addRow()
.addMessage(Component.translatable("message.bclib.datafixer.error"), font, GridLayout.Alignment.CENTER);
grid.addSpacerRow(8);
GridRow row = grid.addRow();
@Override
protected LayoutComponent<?, ?> initContent() {
VerticalStack grid = new VerticalStack(fill(), fill());
grid.addSpacer(4);
grid.addMultilineText(fill(), fit(), Component.translatable("message.bclib.datafixer.error"))
.centerHorizontal();
grid.addSpacer(8);
HorizontalStack row = new HorizontalStack(fill(), fit());
row.addSpacer(10);
GridColumn col = row.addColumn(300, GridLayout.GridValueType.CONSTANT);
VerticalStack col = row.addColumn(fixed(300), fit());
grid.addScrollable(row);
for (String error : errors) {
Component dash = Component.literal("-");
row = col.addRow();
row.addString(dash, this);
row.addText(fit(), fit(), dash);
row.addSpacer(4);
row.addString(Component.literal(error), this);
row.addText(fit(), fit(), Component.literal(error)).setColor(ColorUtil.RED);
}
grid.addSpacer(8);
grid.addSpacerRow(8);
row = grid.addRow();
row.addFiller();
row.addButton(Component.translatable("title.bclib.datafixer.error.continue"), 0.5f, 20, font, (n) -> {
row = grid.addRow().centerHorizontal();
row.addButton(
fit(), fit(),
Component.translatable("title.bclib.datafixer.error.continue")
).setAlpha(0.5f).onPress((n) -> {
onClose();
onContinue.doContinue(true);
});
row.addSpacer();
row.addButton(CommonComponents.GUI_CANCEL, 20, font, (n) -> {
row.addSpacer(4);
row.addButton(
fit(), fit(),
CommonComponents.GUI_CANCEL
).onPress((n) -> {
this.minecraft.setScreen(null);
});
row.addFiller();
return grid;
}
@Environment(EnvType.CLIENT)

View file

@ -1,11 +1,12 @@
package org.betterx.bclib.client.gui.screens;
import org.betterx.bclib.api.v2.dataexchange.handler.autosync.HelloClient;
import org.betterx.bclib.client.gui.gridlayout.GridColumn;
import org.betterx.bclib.client.gui.gridlayout.GridLayout;
import org.betterx.bclib.client.gui.gridlayout.GridRow;
import org.betterx.bclib.client.gui.gridlayout.GridScreen;
import org.betterx.bclib.util.Triple;
import org.betterx.ui.layout.components.HorizontalStack;
import org.betterx.ui.layout.components.LayoutComponent;
import org.betterx.ui.layout.components.Text;
import org.betterx.ui.layout.components.VerticalStack;
import org.betterx.worlds.together.util.ModUtil;
import org.betterx.worlds.together.util.PathUtil;
@ -21,8 +22,7 @@ import java.util.*;
import java.util.stream.Collectors;
@Environment(EnvType.CLIENT)
public class ModListScreen extends BCLibScreen {
public class ModListScreen extends BCLibLayoutScreen {
private final List<ModUtil.ModInfo> mods;
private final HelloClient.IServerModMap serverInfo;
private final Component description;
@ -73,7 +73,7 @@ public class ModListScreen extends BCLibScreen {
List<ModUtil.ModInfo> mods,
HelloClient.IServerModMap serverInfo
) {
super(parent, title, 10, true);
super(parent, title);
this.mods = mods;
this.serverInfo = serverInfo;
this.description = description;
@ -105,10 +105,9 @@ public class ModListScreen extends BCLibScreen {
public static void addModDesc(
GridColumn grid,
VerticalStack grid,
java.util.List<ModUtil.ModInfo> mods,
HelloClient.IServerModMap serverInfo,
GridScreen parent
HelloClient.IServerModMap serverInfo
) {
final int STATE_OK = 6;
final int STATE_SERVER_MISSING_CLIENT_MOD = 5;
@ -190,6 +189,7 @@ public class ModListScreen extends BCLibScreen {
});
items.stream()
.filter(t -> t.second != STATE_SERVER_MISSING)
.sorted(Comparator.comparing(a -> a.second + a.first.toLowerCase(Locale.ROOT)))
.forEach(t -> {
final String name = t.first;
@ -223,46 +223,46 @@ public class ModListScreen extends BCLibScreen {
}
Component dash = Component.literal("-");
Component typeTextComponent = Component.literal(typeText);
GridRow row = grid.addRow();
HorizontalStack row = grid.addRow();
row.addString(dash, parent);
Text dashText = row.addText(fit(), fit(), dash);
row.addSpacer(4);
row.addString(Component.literal(name), parent);
row.addText(fit(), fit(), Component.literal(name));
row.addSpacer(4);
row.addString(typeTextComponent, color, parent);
row.addText(fit(), fit(), typeTextComponent).setColor(color);
if (!stateString.isEmpty()) {
row = grid.addRow();
row.addSpacer(4 + parent.getWidth(dash));
row.addString(Component.literal(stateString), GridLayout.COLOR_GRAY, parent);
row.addSpacer(4 + dashText.getContentWidth());
row.addText(fit(), fit(), Component.literal(stateString))
.setColor(GridLayout.COLOR_GRAY);
}
grid.addSpacerRow();
grid.addSpacer(4);
});
}
@Override
protected void initLayout() {
protected LayoutComponent<?, ?> initContent() {
VerticalStack grid = new VerticalStack(fill(), fill());
if (description != null) {
grid.addSpacerRow();
grid.addRow().addMessage(description, font, GridLayout.Alignment.CENTER);
grid.addSpacerRow(8);
grid.addSpacer(4);
grid.addMultilineText(fill(), fit(), description).centerHorizontal();
grid.addSpacer(8);
}
GridRow row = grid.addRow();
HorizontalStack row = new HorizontalStack(fill(), fit());
row.addSpacer(10);
GridColumn col = row.addColumn(200, GridLayout.GridValueType.CONSTANT);
addModDesc(col, mods, serverInfo, this);
VerticalStack col = row.addColumn(fixed(200), fit());
addModDesc(col, mods, serverInfo);
grid.addScrollable(row);
grid.addSpacerRow(8);
row = grid.addRow();
row.addFiller();
row.addButton(buttonTitle, 20, font, (n) -> {
onClose();
});
row.addFiller();
}
grid.addSpacer(8);
grid.addButton(fit(), fit(), buttonTitle).onPress((n) -> onClose()).centerHorizontal();
return grid;
}
}

View file

@ -1,7 +1,11 @@
package org.betterx.bclib.client.gui.screens;
import org.betterx.bclib.BCLib;
import org.betterx.bclib.client.gui.gridlayout.*;
import org.betterx.ui.ColorUtil;
import org.betterx.ui.layout.components.*;
import org.betterx.ui.layout.values.Rectangle;
import org.betterx.ui.layout.values.Value;
import org.betterx.ui.vanilla.LayoutScreen;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
@ -16,7 +20,7 @@ import net.minecraft.util.ProgressListener;
import java.util.concurrent.atomic.AtomicInteger;
import org.jetbrains.annotations.Nullable;
class ProgressLogoRender extends GridCustomRenderCell {
class ProgressLogoRender extends CustomRenderComponent<ProgressLogoRender> {
public static final int SIZE = 64;
public static final int LOGO_SIZE = 512;
public static final int PIXELATED_SIZE = 512;
@ -24,19 +28,38 @@ class ProgressLogoRender extends GridCustomRenderCell {
double time = 0;
protected ProgressLogoRender() {
super(SIZE, GridLayout.GridValueType.CONSTANT, SIZE);
super(Value.fixed(SIZE), Value.fixed(SIZE));
}
@Override
public void onRender(PoseStack poseStack, GridTransform transform, Object context) {
time += 0.03;
public int getContentWidth() {
return SIZE;
}
@Override
public int getContentHeight() {
return SIZE;
}
@Override
protected void customRender(
PoseStack poseStack,
int x,
int y,
float deltaTicks,
Rectangle transform,
Rectangle clipRect
) {
//time += 0.03;
time += deltaTicks * 0.1;
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.enableBlend();
RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0f);
final int yBarLocal = (int) (transform.height * percentage);
final int yBar = transform.top + yBarLocal;
final int yBar = yBarLocal;
final float fScale = (float) (0.3 * ((Math.sin(time) + 1.0) * 0.5) + 0.7);
int height = (int) (transform.height * fScale);
@ -53,10 +76,10 @@ class ProgressLogoRender extends GridCustomRenderCell {
if (yBarImage > 0) {
final int uvTopLogo = (int) (relativeY * LOGO_SIZE);
RenderSystem.setShaderTexture(0, BCLibScreen.BCLIB_LOGO_LOCATION);
RenderSystem.setShaderTexture(0, BCLibLayoutScreen.BCLIB_LOGO_LOCATION);
GuiComponent.blit(poseStack,
xOffset + transform.left,
yOffset + transform.top,
xOffset,
yOffset,
width,
yBarImage,
0, 0, LOGO_SIZE, uvTopLogo,
@ -68,8 +91,8 @@ class ProgressLogoRender extends GridCustomRenderCell {
final int uvTopPixelated = (int) (relativeY * PIXELATED_SIZE);
RenderSystem.setShaderTexture(0, ProgressScreen.BCLIB_LOGO_PIXELATED_LOCATION);
GuiComponent.blit(poseStack,
xOffset + transform.left,
yOffset + transform.top + yBarImage,
xOffset,
yOffset + yBarImage,
width,
height - yBarImage,
0, uvTopPixelated, PIXELATED_SIZE, PIXELATED_SIZE - uvTopPixelated,
@ -80,9 +103,9 @@ class ProgressLogoRender extends GridCustomRenderCell {
if (percentage > 0 && percentage < 1.0) {
GuiComponent.fill(
poseStack,
transform.left,
0,
yBar,
transform.left + transform.width,
transform.width,
yBar + 1,
0x3FFFFFFF
);
@ -90,7 +113,7 @@ class ProgressLogoRender extends GridCustomRenderCell {
}
}
public class ProgressScreen extends GridScreen implements ProgressListener, AtomicProgressListener {
public class ProgressScreen extends LayoutScreen implements ProgressListener, AtomicProgressListener {
static final ResourceLocation BCLIB_LOGO_PIXELATED_LOCATION = new ResourceLocation(
BCLib.MOD_ID,
@ -98,15 +121,16 @@ public class ProgressScreen extends GridScreen implements ProgressListener, Atom
);
public ProgressScreen(@Nullable Screen parent, Component title, Component description) {
super(parent, title, 20, true);
super(parent, title);
this.description = description;
}
Component description;
private Component stageComponent;
private GridMessageCell stage;
private GridStringCell progress;
private MultiLineText stage;
private HorizontalStack stageRow;
private Text progress;
private ProgressLogoRender progressImage;
private int currentProgress = 0;
private AtomicInteger atomicCounter;
@ -136,34 +160,6 @@ public class ProgressScreen extends GridScreen implements ProgressListener, Atom
return Component.translatable("title.bclib.progress").append(": " + pg + "%");
}
@Override
protected void initLayout() {
grid.addSpacerRow();
GridRow row = grid.addRow(GridLayout.VerticalAlignment.CENTER);
row.addFiller();
progressImage = new ProgressLogoRender();
progressImage.percentage = currentProgress / 100.0f;
row.addCustomRender(progressImage);
row.addSpacer();
int textWidth = Math.max(getWidth(description), getWidth(getProgressComponent(100)));
GridColumn textCol = row.addColumn(0, GridLayout.GridValueType.INHERIT);
textCol.addRow().addString(description, this);
textCol.addSpacerRow();
progress = textCol.addRow()
.addString(getProgressComponent(), GridLayout.COLOR_GRAY, GridLayout.Alignment.LEFT, this);
row.addFiller();
grid.addSpacerRow(20);
row = grid.addRow();
stage = row.addMessage(
stageComponent != null ? stageComponent : Component.literal(""),
font,
GridLayout.Alignment.CENTER
);
}
@Override
public void progressStartNoAbort(Component text) {
@ -180,6 +176,7 @@ public class ProgressScreen extends GridScreen implements ProgressListener, Atom
public void progressStage(Component text) {
stageComponent = text;
if (stage != null) stage.setText(text);
if (stageRow != null) stageRow.reCalculateLayout();
}
@Override
@ -195,4 +192,42 @@ public class ProgressScreen extends GridScreen implements ProgressListener, Atom
public void stop() {
}
@Override
protected LayoutComponent<?, ?> addTitle(LayoutComponent<?, ?> content) {
return content;
}
@Override
protected LayoutComponent<?, ?> initContent() {
VerticalStack grid = new VerticalStack(fill(), fill()).setDebugName("grid");
grid.addFiller();
grid.add(buildTitle());
grid.addSpacer(4);
HorizontalStack contentRow = grid.addRow(fit(), fit())
.centerHorizontal()
.setDebugName("contentRow");
progressImage = new ProgressLogoRender();
progressImage.percentage = currentProgress / 100.0f;
contentRow.add(progressImage);
contentRow.addSpacer(8);
VerticalStack textCol = contentRow.addColumn(fit(), fit()).setDebugName("textCol").centerVertical();
textCol.addText(fit(), fit(), description);
textCol.addSpacer(4);
progress = textCol.addText(fit(), fit(), getProgressComponent()).setColor(ColorUtil.GRAY);
grid.addSpacer(20);
stageRow = grid.addRow(fill(), fit());
stage = stageRow.addMultilineText(
fill(), fit(),
stageComponent != null ? stageComponent : Component.literal("")
).centerHorizontal();
grid.addFiller();
return grid;
}
}

View file

@ -1,9 +1,10 @@
package org.betterx.bclib.client.gui.screens;
import org.betterx.bclib.api.v2.dataexchange.handler.autosync.HelloClient;
import org.betterx.bclib.client.gui.gridlayout.GridCheckboxCell;
import org.betterx.bclib.client.gui.gridlayout.GridLayout;
import org.betterx.bclib.client.gui.gridlayout.GridRow;
import org.betterx.ui.layout.components.Checkbox;
import org.betterx.ui.layout.components.HorizontalStack;
import org.betterx.ui.layout.components.LayoutComponent;
import org.betterx.ui.layout.components.VerticalStack;
import org.betterx.worlds.together.util.ModUtil;
import net.minecraft.client.Minecraft;
@ -14,7 +15,7 @@ import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
@Environment(EnvType.CLIENT)
public class SyncFilesScreen extends BCLibScreen {
public class SyncFilesScreen extends BCLibLayoutScreen {
private final Component description;
private final SyncFilesScreen.Listener listener;
private final boolean hasConfigFiles;
@ -44,29 +45,36 @@ public class SyncFilesScreen extends BCLibScreen {
this.shouldDelete = deleteFiles > 0;
}
protected void initLayout() {
public boolean shouldCloseOnEsc() {
return false;
}
@Override
protected LayoutComponent<?, ?> initContent() {
VerticalStack grid = new VerticalStack(fill(), fill());
final int BUTTON_HEIGHT = 20;
grid.addRow()
.addMessage(this.description, this.font, GridLayout.Alignment.CENTER);
grid.addMultilineText(fill(), fit(), this.description).centerHorizontal();
grid.addSpacerRow(10);
grid.addSpacer(10);
GridRow row;
HorizontalStack row;
final GridCheckboxCell mods;
final Checkbox mods;
row = grid.addRow();
mods = row.addCheckbox(
fit(), fit(),
Component.translatable("message.bclib.syncfiles.mods"),
hasMods,
BUTTON_HEIGHT,
this.font
hasMods
);
mods.setEnabled(hasMods);
row.addSpacer();
row.addButton(Component.translatable("title.bclib.syncfiles.modInfo"), 20, font, (button) -> {
row.addSpacer(4);
row.addButton(
fit(), fit(),
Component.translatable("title.bclib.syncfiles.modInfo")
).onPress((button) -> {
ModListScreen scr = new ModListScreen(
this,
Component.translatable("title.bclib.syncfiles.modlist"),
@ -77,51 +85,47 @@ public class SyncFilesScreen extends BCLibScreen {
Minecraft.getInstance().setScreen(scr);
});
grid.addSpacerRow();
grid.addSpacer(4);
final GridCheckboxCell configs;
final Checkbox configs;
row = grid.addRow();
configs = row.addCheckbox(
fit(), fit(),
Component.translatable("message.bclib.syncfiles.configs"),
hasConfigFiles,
BUTTON_HEIGHT,
this.font
hasConfigFiles
);
configs.setEnabled(hasConfigFiles);
grid.addSpacerRow();
grid.addSpacer(4);
row = grid.addRow();
final GridCheckboxCell folder;
final Checkbox folder;
folder = row.addCheckbox(
fit(), fit(),
Component.translatable("message.bclib.syncfiles.folders"),
hasFiles,
BUTTON_HEIGHT,
this.font
hasFiles
);
folder.setEnabled(hasFiles);
row.addSpacer();
row.addSpacer(4);
GridCheckboxCell delete;
Checkbox delete;
delete = row.addCheckbox(
fit(), fit(),
Component.translatable("message.bclib.syncfiles.delete"),
shouldDelete,
BUTTON_HEIGHT,
this.font
shouldDelete
);
delete.setEnabled(shouldDelete);
grid.addSpacerRow(30);
row = grid.addRow();
row.addFiller();
row.addButton(CommonComponents.GUI_NO, BUTTON_HEIGHT, this.font, (button) -> {
grid.addSpacer(30);
row = grid.addRow().centerHorizontal();
row.addButton(fit(), fit(), CommonComponents.GUI_NO).onPress((button) -> {
listener.proceed(false, false, false, false);
});
row.addSpacer();
row.addButton(CommonComponents.GUI_YES, BUTTON_HEIGHT, this.font, (button) -> {
row.addSpacer(4);
row.addButton(fit(), fit(), CommonComponents.GUI_YES).onPress((button) -> {
listener.proceed(
mods.isChecked(),
configs.isChecked(),
@ -129,11 +133,8 @@ public class SyncFilesScreen extends BCLibScreen {
delete.isChecked()
);
});
row.addFiller();
}
public boolean shouldCloseOnEsc() {
return false;
return grid;
}
@Environment(EnvType.CLIENT)

View file

@ -1,7 +1,8 @@
package org.betterx.bclib.client.gui.screens;
import org.betterx.bclib.client.gui.gridlayout.GridLayout;
import org.betterx.bclib.client.gui.gridlayout.GridRow;
import org.betterx.ui.layout.components.HorizontalStack;
import org.betterx.ui.layout.components.LayoutComponent;
import org.betterx.ui.layout.components.VerticalStack;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
@ -10,7 +11,7 @@ import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
@Environment(EnvType.CLIENT)
public class WarnBCLibVersionMismatch extends BCLibScreen {
public class WarnBCLibVersionMismatch extends BCLibLayoutScreen {
private final Component description;
private final Listener listener;
@ -21,27 +22,26 @@ public class WarnBCLibVersionMismatch extends BCLibScreen {
this.listener = listener;
}
protected void initLayout() {
final int BUTTON_HEIGHT = 20;
grid.addRow().addMessage(this.description, this.font, GridLayout.Alignment.CENTER);
grid.addSpacerRow(20);
GridRow row = grid.addRow();
row.addFiller();
row.addButton(CommonComponents.GUI_NO, BUTTON_HEIGHT, this.font, (button) -> {
listener.proceed(false);
});
row.addSpacer();
row.addButton(CommonComponents.GUI_YES, BUTTON_HEIGHT, this.font, (button) -> {
listener.proceed(true);
});
row.addFiller();
}
public boolean shouldCloseOnEsc() {
return false;
}
@Override
protected LayoutComponent<?, ?> initContent() {
VerticalStack grid = new VerticalStack(fill(), fill());
grid.addFiller();
grid.addMultilineText(fill(), fit(), this.description).centerHorizontal();
grid.addSpacer(20);
HorizontalStack row = grid.addRow().centerHorizontal();
row.addButton(fit(), fit(), CommonComponents.GUI_NO).onPress((button) -> listener.proceed(false));
row.addSpacer(4);
row.addButton(fit(), fit(), CommonComponents.GUI_YES).onPress((button) -> listener.proceed(true));
grid.addFiller();
return grid;
}
@Environment(EnvType.CLIENT)
public interface Listener {
void proceed(boolean download);

View file

@ -1,6 +1,5 @@
package org.betterx.bclib.client.gui.screens;
import org.betterx.bclib.BCLib;
import org.betterx.bclib.api.v2.generator.BCLibEndBiomeSource;
import org.betterx.bclib.api.v2.generator.BCLibNetherBiomeSource;
import org.betterx.bclib.api.v2.generator.config.BCLEndBiomeSourceConfig;
@ -9,7 +8,6 @@ import org.betterx.bclib.api.v2.levelgen.LevelGenUtil;
import org.betterx.bclib.registry.PresetsRegistry;
import org.betterx.ui.layout.components.*;
import org.betterx.ui.layout.values.Size;
import org.betterx.ui.layout.values.Value;
import org.betterx.ui.vanilla.LayoutScreen;
import org.betterx.worlds.together.worldPreset.TogetherWorldPreset;
import org.betterx.worlds.together.worldPreset.WorldGenSettingsComponentAccessor;
@ -20,7 +18,6 @@ import net.minecraft.core.Holder;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.dimension.BuiltinDimensionTypes;
import net.minecraft.world.level.dimension.DimensionType;
@ -36,8 +33,6 @@ import org.jetbrains.annotations.Nullable;
@Environment(EnvType.CLIENT)
public class WorldSetupScreen extends LayoutScreen {
static final ResourceLocation BCLIB_LOGO_LOCATION = new ResourceLocation(BCLib.MOD_ID, "icon.png");
private final WorldCreationContext context;
private final CreateWorldScreen createWorldScreen;
private Range<Integer> landBiomeSize;
@ -61,17 +56,17 @@ public class WorldSetupScreen extends LayoutScreen {
Checkbox netherLegacy;
public LayoutComponent<?, ?> netherPage(BCLNetherBiomeSourceConfig netherConfig) {
VerticalStack content = new VerticalStack(Value.fill(), Value.fit()).centerHorizontal();
VerticalStack content = new VerticalStack(fill(), fit()).centerHorizontal();
content.addSpacer(8);
bclibNether = content.addCheckbox(
Value.fit(), Value.fit(),
fit(), fit(),
Component.translatable("title.screen.bclib.worldgen.custom_biome_source"),
netherConfig.mapVersion != BCLNetherBiomeSourceConfig.NetherBiomeMapType.VANILLA
);
netherLegacy = content.indent(20).addCheckbox(
Value.fit(), Value.fit(),
fit(), fit(),
Component.translatable("title.screen.bclib.worldgen.legacy_square"),
netherConfig.mapVersion == BCLNetherBiomeSourceConfig.NetherBiomeMapType.SQUARE
);
@ -86,40 +81,40 @@ public class WorldSetupScreen extends LayoutScreen {
}
public LayoutComponent<?, ?> endPage(BCLEndBiomeSourceConfig endConfig) {
VerticalStack content = new VerticalStack(Value.fill(), Value.fit()).centerHorizontal();
VerticalStack content = new VerticalStack(fill(), fit()).centerHorizontal();
content.addSpacer(8);
bclibEnd = content.addCheckbox(
Value.fit(), Value.fit(),
fit(), fit(),
Component.translatable("title.screen.bclib.worldgen.custom_biome_source"),
endConfig.mapVersion != BCLEndBiomeSourceConfig.EndBiomeMapType.VANILLA
);
endLegacy = content.indent(20).addCheckbox(
Value.fit(), Value.fit(),
fit(), fit(),
Component.translatable("title.screen.bclib.worldgen.legacy_square"),
endConfig.mapVersion == BCLEndBiomeSourceConfig.EndBiomeMapType.SQUARE
);
endCustomTerrain = content.indent(20).addCheckbox(
Value.fit(), Value.fit(),
fit(), fit(),
Component.translatable("title.screen.bclib.worldgen.custom_end_terrain"),
endConfig.generatorVersion != BCLEndBiomeSourceConfig.EndBiomeGeneratorType.VANILLA
);
generateEndVoid = content.indent(20).addCheckbox(
Value.fit(), Value.fit(),
fit(), fit(),
Component.translatable("title.screen.bclib.worldgen.end_void"),
endConfig.withVoidBiomes
);
content.addSpacer(12);
content.addText(Value.fit(), Value.fit(), Component.translatable("title.screen.bclib.worldgen.avg_biome_size"))
content.addText(fit(), fit(), Component.translatable("title.screen.bclib.worldgen.avg_biome_size"))
.centerHorizontal();
content.addHorizontalSeparator(8).alignTop();
landBiomeSize = content.addRange(
Value.fixed(200),
Value.fit(),
fixed(200),
fit(),
Component.translatable("title.screen.bclib.worldgen.land_biome_size"),
1,
512,
@ -127,8 +122,8 @@ public class WorldSetupScreen extends LayoutScreen {
);
voidBiomeSize = content.addRange(
Value.fixed(200),
Value.fit(),
fixed(200),
fit(),
Component.translatable("title.screen.bclib.worldgen.void_biome_size"),
1,
512,
@ -136,8 +131,8 @@ public class WorldSetupScreen extends LayoutScreen {
);
centerBiomeSize = content.addRange(
Value.fixed(200),
Value.fit(),
fixed(200),
fit(),
Component.translatable("title.screen.bclib.worldgen.center_biome_size"),
1,
512,
@ -145,8 +140,8 @@ public class WorldSetupScreen extends LayoutScreen {
);
barrensBiomeSize = content.addRange(
Value.fixed(200),
Value.fit(),
fixed(200),
fit(),
Component.translatable("title.screen.bclib.worldgen.barrens_biome_size"),
1,
512,
@ -154,13 +149,13 @@ public class WorldSetupScreen extends LayoutScreen {
);
content.addSpacer(12);
content.addText(Value.fit(), Value.fit(), Component.translatable("title.screen.bclib.worldgen.other"))
content.addText(fit(), fit(), Component.translatable("title.screen.bclib.worldgen.other"))
.centerHorizontal();
content.addHorizontalSeparator(8).alignTop();
innerRadius = content.addRange(
Value.fixed(200),
Value.fit(),
fixed(200),
fit(),
Component.translatable("title.screen.bclib.worldgen.central_radius"),
1,
512,
@ -282,7 +277,7 @@ public class WorldSetupScreen extends LayoutScreen {
@Override
protected LayoutComponent<?, ?> addTitle(LayoutComponent<?, ?> content) {
VerticalStack rows = new VerticalStack(Value.fill(), Value.fill()).setDebugName("title stack");
VerticalStack rows = new VerticalStack(fill(), fill()).setDebugName("title stack");
if (topPadding > 0) rows.addSpacer(topPadding);
rows.add(content);
@ -290,7 +285,7 @@ public class WorldSetupScreen extends LayoutScreen {
if (sidePadding <= 0) return rows;
HorizontalStack cols = new HorizontalStack(Value.fill(), Value.fill()).setDebugName("padded side");
HorizontalStack cols = new HorizontalStack(fill(), fill()).setDebugName("padded side");
cols.addSpacer(sidePadding);
cols.add(rows);
cols.addSpacer(sidePadding);
@ -320,12 +315,12 @@ public class WorldSetupScreen extends LayoutScreen {
var netherPage = netherPage(netherConfig);
var endPage = endPage(endConfig);
Tabs main = new Tabs(Value.fill(), Value.fill()).setPadding(8, 0, 0, 0);
Tabs main = new Tabs(fill(), 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));
HorizontalStack title = new HorizontalStack(Value.fit(), Value.fit()).setDebugName("title bar");
title.addIcon(BCLIB_LOGO_LOCATION, Size.of(512)).setDebugName("icon");
HorizontalStack title = new HorizontalStack(fit(), fit()).setDebugName("title bar");
title.addIcon(BCLibLayoutScreen.BCLIB_LOGO_LOCATION, Size.of(512)).setDebugName("icon");
title.addSpacer(4);
title.add(super.buildTitle());
@ -333,10 +328,10 @@ public class WorldSetupScreen extends LayoutScreen {
main.addComponent(title);
VerticalStack rows = new VerticalStack(Value.fill(), Value.fill());
VerticalStack rows = new VerticalStack(fill(), fill());
rows.add(main);
rows.addSpacer(4);
rows.addButton(Value.fit(), Value.fit(), CommonComponents.GUI_DONE).onPress((bt) -> {
rows.addButton(fit(), fit(), CommonComponents.GUI_DONE).onPress((bt) -> {
updateSettings();
onClose();
}).alignRight();

View file

@ -42,7 +42,7 @@ public class ColorUtil {
public static final int LIGHT_PURPLE = ChatFormatting.LIGHT_PURPLE.getColor() | 0xFF000000;
public static final int YELLOW = ChatFormatting.YELLOW.getColor() | 0xFF000000;
public static final int WHITE = ChatFormatting.WHITE.getColor() | 0xFF000000;
public static final int DEFAULT_TEXT = 0xFFA0A0A0;
public static final int DEFAULT_TEXT = WHITE;
private static final float[] FLOAT_BUFFER = new float[4];
private static final int ALPHA = 255 << 24;

View file

@ -29,6 +29,12 @@ public abstract class LayoutComponent<R extends ComponentRenderer, L extends Lay
this.renderer = renderer;
}
public void reCalculateLayout() {
updateContainerWidth(relativeBounds.width);
updateContainerHeight(relativeBounds.height);
setRelativeBounds(relativeBounds.left, relativeBounds.top);
}
protected int updateContainerWidth(int containerWidth) {
return width.setCalculatedSize(containerWidth);
}

View file

@ -9,11 +9,13 @@ import org.betterx.ui.layout.values.Value;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.gui.components.MultiLineLabel;
import net.minecraft.network.chat.Component;
public class MultiLineText extends LayoutComponent<MultiLineText.MultiLineTextRenderer, MultiLineText> {
final net.minecraft.network.chat.Component text;
net.minecraft.network.chat.Component text;
int color = ColorUtil.DEFAULT_TEXT;
protected MultiLineLabel multiLineLabel;
int bufferedContentWidth = 0;
public MultiLineText(
Value width,
@ -23,6 +25,7 @@ public class MultiLineText extends LayoutComponent<MultiLineText.MultiLineTextRe
super(width, height, new MultiLineTextRenderer());
renderer.linkedComponent = this;
this.text = text;
updatedContentWidth();
}
public MultiLineText setColor(int cl) {
@ -30,6 +33,17 @@ public class MultiLineText extends LayoutComponent<MultiLineText.MultiLineTextRe
return this;
}
public MultiLineText setText(Component text) {
this.text = text;
this.updatedContentWidth();
if (multiLineLabel != null) {
multiLineLabel = createVanillaComponent();
}
return this;
}
protected MultiLineLabel createVanillaComponent() {
return MultiLineLabel.create(
renderer.getFont(),
@ -38,6 +52,19 @@ public class MultiLineText extends LayoutComponent<MultiLineText.MultiLineTextRe
);
}
protected void updatedContentWidth() {
String[] lines = text.getString().split("\n");
if (lines.length == 0) bufferedContentWidth = 0;
else {
String line = lines[0];
for (int i = 1; i < lines.length; i++)
if (lines[i].length() > line.length())
line = lines[i];
bufferedContentWidth = renderer.getWidth(Component.literal(line));
}
}
@Override
void setRelativeBounds(int left, int top) {
super.setRelativeBounds(left, top);
@ -46,7 +73,7 @@ public class MultiLineText extends LayoutComponent<MultiLineText.MultiLineTextRe
@Override
public int getContentWidth() {
return renderer.getWidth(text);
return bufferedContentWidth;
}
@Override
@ -57,6 +84,11 @@ public class MultiLineText extends LayoutComponent<MultiLineText.MultiLineTextRe
protected static class MultiLineTextRenderer implements ComponentRenderer, TextProvider {
MultiLineText linkedComponent;
@Override
public int getWidth(Component c) {
return getFont().width(c.getVisualOrderText());
}
@Override
public int getHeight(net.minecraft.network.chat.Component c) {
if (linkedComponent == null) return 20;

View file

@ -99,4 +99,6 @@ public class Panel implements ComponentWithBounds, RelativeContainerEventHandler
child.render(poseStack, mouseX - bounds.left, mouseY - bounds.top, deltaTicks, bounds, bounds);
}
}
}

View file

@ -9,9 +9,10 @@ import org.betterx.ui.layout.values.Value;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.gui.GuiComponent;
import net.minecraft.network.chat.Component;
public class Text extends LayoutComponent<Text.TextRenderer, Text> {
final net.minecraft.network.chat.Component text;
net.minecraft.network.chat.Component text;
int color = ColorUtil.DEFAULT_TEXT;
public Text(
@ -30,6 +31,11 @@ public class Text extends LayoutComponent<Text.TextRenderer, Text> {
return this;
}
public Text setText(Component text) {
this.text = text;
return this;
}
@Override
public int getContentWidth() {
return renderer.getWidth(text);

View file

@ -74,14 +74,14 @@ public abstract class LayoutScreen extends Screen {
}
protected LayoutComponent<?, ?> buildTitle() {
var text = new Text(Value.fit(), Value.fit(), title).centerHorizontal()
var text = new Text(fit(), fit(), title).centerHorizontal()
.setColor(ColorUtil.WHITE)
.setDebugName("title");
return text;
}
protected LayoutComponent<?, ?> addTitle(LayoutComponent<?, ?> content) {
VerticalStack rows = new VerticalStack(Value.fill(), Value.fill()).setDebugName("title stack");
VerticalStack rows = new VerticalStack(fill(), fill()).setDebugName("title stack");
if (topPadding > 0) rows.addSpacer(topPadding);
rows.add(buildTitle());
@ -91,7 +91,7 @@ public abstract class LayoutScreen extends Screen {
if (sidePadding <= 0) return rows;
HorizontalStack cols = new HorizontalStack(Value.fill(), Value.fill()).setDebugName("padded side");
HorizontalStack cols = new HorizontalStack(fill(), fill()).setDebugName("padded side");
cols.addSpacer(sidePadding);
cols.add(rows);
cols.addSpacer(sidePadding);
@ -118,4 +118,24 @@ public abstract class LayoutScreen extends Screen {
public boolean isPauseScreen() {
return true;
}
public static Value fit() {
return Value.fit();
}
public static Value fitOrFill() {
return Value.fitOrFill();
}
public static Value fill() {
return Value.fill();
}
public static Value fixed(int size) {
return Value.fixed(size);
}
public static Value relative(double percentage) {
return Value.relative(percentage);
}
}

View file

@ -3,7 +3,6 @@ package org.betterx.ui.vanilla;
import org.betterx.ui.layout.components.HorizontalStack;
import org.betterx.ui.layout.components.LayoutComponent;
import org.betterx.ui.layout.values.Size;
import org.betterx.ui.layout.values.Value;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
@ -41,7 +40,7 @@ public abstract class LayoutScreenWithIcon extends LayoutScreen {
@Override
protected LayoutComponent<?, ?> buildTitle() {
LayoutComponent<?, ?> title = super.buildTitle();
HorizontalStack row = new HorizontalStack(Value.fill(), Value.fit()).setDebugName("title bar");
HorizontalStack row = new HorizontalStack(fill(), fit()).setDebugName("title bar");
row.addFiller();
row.addIcon(icon, Size.of(512)).setDebugName("icon");
row.addSpacer(4);