diff --git a/WunderLib b/WunderLib index 4638cbf4..782c5a63 160000 --- a/WunderLib +++ b/WunderLib @@ -1 +1 @@ -Subproject commit 4638cbf4cab6a900cf9969eb353d51b33236eaee +Subproject commit 782c5a63e67cb7eb9d31f63a2ddec77b044d2541 diff --git a/src/main/java/org/betterx/bclib/client/gui/modmenu/MainScreen.java b/src/main/java/org/betterx/bclib/client/gui/modmenu/MainScreen.java index 44bf419b..367383ab 100644 --- a/src/main/java/org/betterx/bclib/client/gui/modmenu/MainScreen.java +++ b/src/main/java/org/betterx/bclib/client/gui/modmenu/MainScreen.java @@ -6,14 +6,15 @@ import org.betterx.bclib.config.Configs; import org.betterx.bclib.config.NamedPathConfig; import org.betterx.bclib.config.NamedPathConfig.ConfigTokenDescription; import org.betterx.bclib.config.NamedPathConfig.DependendConfigToken; -import org.betterx.ui.layout.components.*; -import org.betterx.ui.vanilla.LayoutScreenWithIcon; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.CommonComponents; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; +import org.wunder.lib.ui.layout.components.*; +import org.wunder.lib.ui.vanilla.LayoutScreenWithIcon; + import java.util.HashMap; import java.util.Map; import java.util.function.Supplier; diff --git a/src/main/java/org/betterx/bclib/client/gui/modmenu/TestScreen.java b/src/main/java/org/betterx/bclib/client/gui/modmenu/TestScreen.java index 11d23aae..5b140772 100644 --- a/src/main/java/org/betterx/bclib/client/gui/modmenu/TestScreen.java +++ b/src/main/java/org/betterx/bclib/client/gui/modmenu/TestScreen.java @@ -1,10 +1,6 @@ package org.betterx.bclib.client.gui.modmenu; 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.vanilla.LayoutScreen; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.Component; @@ -12,6 +8,11 @@ import net.minecraft.network.chat.Component; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import org.wunder.lib.ui.ColorHelper; +import org.wunder.lib.ui.layout.components.*; +import org.wunder.lib.ui.layout.values.Size; +import org.wunder.lib.ui.vanilla.LayoutScreen; + @Environment(EnvType.CLIENT) public class TestScreen extends LayoutScreen { public TestScreen(Component component) { @@ -77,17 +78,17 @@ public class TestScreen extends LayoutScreen { VerticalScroll.create(page2) )); rows.add(new Input(fitOrFill(), fit(), Component.literal("Input"), "0xff00ff")); - rows.add(new ColorSwatch(fit(), fit(), ColorUtil.LIGHT_PURPLE).centerHorizontal()); + rows.add(new ColorSwatch(fit(), fit(), ColorHelper.LIGHT_PURPLE).centerHorizontal()); rows.add(new ColorPicker( fill(), fit(), Component.literal("Color"), - ColorUtil.GREEN + ColorHelper.GREEN ).centerHorizontal()); rows.add(new Text( fitOrFill(), fixed(20), Component.literal("Some blue text") - ).centerHorizontal().setColor(ColorUtil.BLUE) + ).centerHorizontal().setColor(ColorHelper.BLUE) ); rows.addHLine(fixed(32), fixed(16)); rows.add(c); @@ -110,7 +111,7 @@ public class TestScreen extends LayoutScreen { 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() + ).setColor(ColorHelper.LIGHT_PURPLE).centerHorizontal() ); rows.addHorizontalLine(16); diff --git a/src/main/java/org/betterx/bclib/client/gui/screens/BCLibLayoutScreen.java b/src/main/java/org/betterx/bclib/client/gui/screens/BCLibLayoutScreen.java index ecf28cf9..f91a9690 100644 --- a/src/main/java/org/betterx/bclib/client/gui/screens/BCLibLayoutScreen.java +++ b/src/main/java/org/betterx/bclib/client/gui/screens/BCLibLayoutScreen.java @@ -1,12 +1,13 @@ 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.wunder.lib.ui.vanilla.LayoutScreenWithIcon; + import org.jetbrains.annotations.Nullable; public abstract class BCLibLayoutScreen extends LayoutScreenWithIcon { diff --git a/src/main/java/org/betterx/bclib/client/gui/screens/ConfirmFixScreen.java b/src/main/java/org/betterx/bclib/client/gui/screens/ConfirmFixScreen.java index cfd74fd3..46ac25d9 100644 --- a/src/main/java/org/betterx/bclib/client/gui/screens/ConfirmFixScreen.java +++ b/src/main/java/org/betterx/bclib/client/gui/screens/ConfirmFixScreen.java @@ -1,11 +1,6 @@ package org.betterx.bclib.client.gui.screens; -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; import net.minecraft.network.chat.Component; @@ -13,6 +8,11 @@ import net.minecraft.network.chat.Component; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import org.wunder.lib.ui.layout.components.Checkbox; +import org.wunder.lib.ui.layout.components.HorizontalStack; +import org.wunder.lib.ui.layout.components.LayoutComponent; +import org.wunder.lib.ui.layout.components.VerticalStack; + import org.jetbrains.annotations.Nullable; @Environment(EnvType.CLIENT) diff --git a/src/main/java/org/betterx/bclib/client/gui/screens/ConfirmRestartScreen.java b/src/main/java/org/betterx/bclib/client/gui/screens/ConfirmRestartScreen.java index 04cc6777..6ce67c8a 100644 --- a/src/main/java/org/betterx/bclib/client/gui/screens/ConfirmRestartScreen.java +++ b/src/main/java/org/betterx/bclib/client/gui/screens/ConfirmRestartScreen.java @@ -1,15 +1,15 @@ package org.betterx.bclib.client.gui.screens; -import org.betterx.ui.layout.components.LayoutComponent; -import org.betterx.ui.layout.components.VerticalStack; -import org.betterx.ui.layout.values.Value; - import net.minecraft.network.chat.CommonComponents; import net.minecraft.network.chat.Component; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import org.wunder.lib.ui.layout.components.LayoutComponent; +import org.wunder.lib.ui.layout.components.VerticalStack; +import org.wunder.lib.ui.layout.values.Value; + @Environment(EnvType.CLIENT) public class ConfirmRestartScreen extends BCLibLayoutScreen { diff --git a/src/main/java/org/betterx/bclib/client/gui/screens/LevelFixErrorScreen.java b/src/main/java/org/betterx/bclib/client/gui/screens/LevelFixErrorScreen.java index 3235c9cc..e4f89df5 100644 --- a/src/main/java/org/betterx/bclib/client/gui/screens/LevelFixErrorScreen.java +++ b/src/main/java/org/betterx/bclib/client/gui/screens/LevelFixErrorScreen.java @@ -1,10 +1,5 @@ package org.betterx.bclib.client.gui.screens; -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; import net.minecraft.network.chat.Component; @@ -12,6 +7,11 @@ import net.minecraft.network.chat.Component; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import org.wunder.lib.ui.ColorHelper; +import org.wunder.lib.ui.layout.components.HorizontalStack; +import org.wunder.lib.ui.layout.components.LayoutComponent; +import org.wunder.lib.ui.layout.components.VerticalStack; + @Environment(EnvType.CLIENT) public class LevelFixErrorScreen extends BCLibLayoutScreen { private final String[] errors; @@ -43,7 +43,7 @@ public class LevelFixErrorScreen extends BCLibLayoutScreen { row.addText(fit(), fit(), dash); row.addSpacer(4); - row.addText(fit(), fit(), Component.literal(error)).setColor(ColorUtil.RED); + row.addText(fit(), fit(), Component.literal(error)).setColor(ColorHelper.RED); } grid.addSpacer(8); diff --git a/src/main/java/org/betterx/bclib/client/gui/screens/ModListScreen.java b/src/main/java/org/betterx/bclib/client/gui/screens/ModListScreen.java index 149d4a9d..93945d2e 100644 --- a/src/main/java/org/betterx/bclib/client/gui/screens/ModListScreen.java +++ b/src/main/java/org/betterx/bclib/client/gui/screens/ModListScreen.java @@ -2,11 +2,6 @@ package org.betterx.bclib.client.gui.screens; import org.betterx.bclib.api.v2.dataexchange.handler.autosync.HelloClient; import org.betterx.bclib.util.Triple; -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.Text; -import org.betterx.ui.layout.components.VerticalStack; import org.betterx.worlds.together.util.ModUtil; import org.betterx.worlds.together.util.PathUtil; @@ -18,6 +13,12 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.loader.api.metadata.ModEnvironment; +import org.wunder.lib.ui.ColorHelper; +import org.wunder.lib.ui.layout.components.HorizontalStack; +import org.wunder.lib.ui.layout.components.LayoutComponent; +import org.wunder.lib.ui.layout.components.Text; +import org.wunder.lib.ui.layout.components.VerticalStack; + import java.util.*; import java.util.stream.Collectors; @@ -196,29 +197,29 @@ public class ModListScreen extends BCLibLayoutScreen { final int state = t.second; final String stateString = t.third; - int color = ColorUtil.RED; + int color = ColorHelper.RED; final String typeText; if (state == STATE_VERSION || state == STATE_VERSION_NOT_OFFERED || state == STATE_VERSION_CLIENT_ONLY) { typeText = "[VERSION]"; if (state == STATE_VERSION_NOT_OFFERED) { - color = ColorUtil.YELLOW; + color = ColorHelper.YELLOW; } else if (state == STATE_VERSION_CLIENT_ONLY) { - color = ColorUtil.DARK_GREEN; + color = ColorHelper.DARK_GREEN; } } else if (state == STATE_MISSING || state == STATE_MISSING_NOT_OFFERED) { typeText = "[MISSING]"; if (state == STATE_MISSING_NOT_OFFERED) { - color = ColorUtil.YELLOW; + color = ColorHelper.YELLOW; } } else if (state == STATE_SERVER_MISSING || state == STATE_SERVER_MISSING_CLIENT_MOD) { if (state == STATE_SERVER_MISSING_CLIENT_MOD) { - color = ColorUtil.AQUA; + color = ColorHelper.AQUA; typeText = "[OK]"; } else { typeText = "[NOT ON SERVER]"; } } else { - color = ColorUtil.DARK_GREEN; + color = ColorHelper.DARK_GREEN; typeText = "[OK]"; } Component dash = Component.literal("-"); @@ -237,7 +238,7 @@ public class ModListScreen extends BCLibLayoutScreen { row = grid.addRow(); row.addSpacer(4 + dashText.getContentWidth()); row.addText(fit(), fit(), Component.literal(stateString)) - .setColor(ColorUtil.GRAY); + .setColor(ColorHelper.GRAY); } grid.addSpacer(4); diff --git a/src/main/java/org/betterx/bclib/client/gui/screens/ProgressScreen.java b/src/main/java/org/betterx/bclib/client/gui/screens/ProgressScreen.java index 9da0a397..e24ae5f4 100644 --- a/src/main/java/org/betterx/bclib/client/gui/screens/ProgressScreen.java +++ b/src/main/java/org/betterx/bclib/client/gui/screens/ProgressScreen.java @@ -1,11 +1,6 @@ package org.betterx.bclib.client.gui.screens; import org.betterx.bclib.BCLib; -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; @@ -17,6 +12,12 @@ import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.ProgressListener; +import org.wunder.lib.ui.ColorHelper; +import org.wunder.lib.ui.layout.components.*; +import org.wunder.lib.ui.layout.values.Rectangle; +import org.wunder.lib.ui.layout.values.Value; +import org.wunder.lib.ui.vanilla.LayoutScreen; + import java.util.concurrent.atomic.AtomicInteger; import org.jetbrains.annotations.Nullable; @@ -217,7 +218,7 @@ public class ProgressScreen extends LayoutScreen implements ProgressListener, At 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); + progress = textCol.addText(fit(), fit(), getProgressComponent()).setColor(ColorHelper.GRAY); grid.addSpacer(20); diff --git a/src/main/java/org/betterx/bclib/client/gui/screens/SyncFilesScreen.java b/src/main/java/org/betterx/bclib/client/gui/screens/SyncFilesScreen.java index 64dd76ea..571fa07b 100644 --- a/src/main/java/org/betterx/bclib/client/gui/screens/SyncFilesScreen.java +++ b/src/main/java/org/betterx/bclib/client/gui/screens/SyncFilesScreen.java @@ -1,10 +1,6 @@ package org.betterx.bclib.client.gui.screens; import org.betterx.bclib.api.v2.dataexchange.handler.autosync.HelloClient; -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,6 +10,11 @@ import net.minecraft.network.chat.Component; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import org.wunder.lib.ui.layout.components.Checkbox; +import org.wunder.lib.ui.layout.components.HorizontalStack; +import org.wunder.lib.ui.layout.components.LayoutComponent; +import org.wunder.lib.ui.layout.components.VerticalStack; + @Environment(EnvType.CLIENT) public class SyncFilesScreen extends BCLibLayoutScreen { private final Component description; diff --git a/src/main/java/org/betterx/bclib/client/gui/screens/UpdatesScreen.java b/src/main/java/org/betterx/bclib/client/gui/screens/UpdatesScreen.java index b4130ebc..ed2e4d03 100644 --- a/src/main/java/org/betterx/bclib/client/gui/screens/UpdatesScreen.java +++ b/src/main/java/org/betterx/bclib/client/gui/screens/UpdatesScreen.java @@ -3,12 +3,6 @@ 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.ui.ColorUtil; -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.Size; -import org.betterx.ui.layout.values.Value; import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.gui.GuiComponent; @@ -24,6 +18,13 @@ import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.ModContainer; import net.fabricmc.loader.api.metadata.CustomValue; +import org.wunder.lib.ui.ColorHelper; +import org.wunder.lib.ui.layout.components.HorizontalStack; +import org.wunder.lib.ui.layout.components.LayoutComponent; +import org.wunder.lib.ui.layout.components.VerticalStack; +import org.wunder.lib.ui.layout.values.Size; +import org.wunder.lib.ui.layout.values.Value; + @Environment(EnvType.CLIENT) public class UpdatesScreen extends BCLibLayoutScreen { public static final String DONATION_URL = "https://www.buymeacoffee.com/quiqueck"; @@ -71,14 +72,14 @@ public class UpdatesScreen extends BCLibLayoutScreen { } if (nfo != null) { row.addText(fit(), fit(), Component.literal(nfo.getMetadata().getName())) - .setColor(ColorUtil.WHITE); + .setColor(ColorHelper.WHITE); } else { - row.addText(fit(), fit(), Component.literal(mod)).setColor(ColorUtil.WHITE); + row.addText(fit(), fit(), Component.literal(mod)).setColor(ColorHelper.WHITE); } row.addSpacer(4); row.addText(fit(), fit(), Component.literal(cur)); row.addText(fit(), fit(), Component.literal(" -> ")); - row.addText(fit(), fit(), Component.literal(updated)).setColor(ColorUtil.GREEN); + row.addText(fit(), fit(), Component.literal(updated)).setColor(ColorHelper.GREEN); row.addFiller(); if (nfo != null && nfo.getMetadata().getContact().get("homepage").isPresent()) { row.addButton(fit(), fit(), Component.translatable("bclib.updates.curseforge_link")) @@ -99,7 +100,7 @@ public class UpdatesScreen extends BCLibLayoutScreen { footer.addButton( fit(), fit(), - Component.translatable("bclib.updates.donate").setStyle(Style.EMPTY.withColor(ColorUtil.YELLOW)) + Component.translatable("bclib.updates.donate").setStyle(Style.EMPTY.withColor(ColorHelper.YELLOW)) ) .onPress((bt) -> openLink(DONATION_URL)); footer.addSpacer(2); diff --git a/src/main/java/org/betterx/bclib/client/gui/screens/WarnBCLibVersionMismatch.java b/src/main/java/org/betterx/bclib/client/gui/screens/WarnBCLibVersionMismatch.java index 1127a24d..2e68ee9b 100644 --- a/src/main/java/org/betterx/bclib/client/gui/screens/WarnBCLibVersionMismatch.java +++ b/src/main/java/org/betterx/bclib/client/gui/screens/WarnBCLibVersionMismatch.java @@ -1,15 +1,15 @@ package org.betterx.bclib.client.gui.screens; -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; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import org.wunder.lib.ui.layout.components.HorizontalStack; +import org.wunder.lib.ui.layout.components.LayoutComponent; +import org.wunder.lib.ui.layout.components.VerticalStack; + @Environment(EnvType.CLIENT) public class WarnBCLibVersionMismatch extends BCLibLayoutScreen { private final Component description; diff --git a/src/main/java/org/betterx/bclib/client/gui/screens/WelcomeScreen.java b/src/main/java/org/betterx/bclib/client/gui/screens/WelcomeScreen.java index b840e28a..2d70c852 100644 --- a/src/main/java/org/betterx/bclib/client/gui/screens/WelcomeScreen.java +++ b/src/main/java/org/betterx/bclib/client/gui/screens/WelcomeScreen.java @@ -4,9 +4,6 @@ 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; @@ -18,6 +15,10 @@ import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Style; import net.minecraft.resources.ResourceLocation; +import org.wunder.lib.ui.ColorHelper; +import org.wunder.lib.ui.layout.components.*; +import org.wunder.lib.ui.layout.values.Size; + 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"); @@ -33,12 +34,12 @@ public class WelcomeScreen extends BCLibLayoutScreen { VerticalStack content = new VerticalStack(fill(), fit()).setDebugName("content"); content.addImage(fill(), fit(), BACKGROUND, new Size(427, 100)); - content.addHorizontalLine(1).setColor(ColorUtil.BLACK); + content.addHorizontalLine(1).setColor(ColorHelper.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.addText(fit(), fit(), title).centerHorizontal().setColor(ColorHelper.WHITE).setDebugName("title"); headerRow.addImage(fixed(178 / 2), fixed(40 / 2), BETTERX_LOCATION, Size.of(178, 40)).setDebugName("betterx"); content.addSpacer(16); @@ -61,7 +62,7 @@ public class WelcomeScreen extends BCLibLayoutScreen { donationRow.addSpacer(4); donationRow.addButton( fit(), fit(), - Component.translatable("bclib.updates.donate").setStyle(Style.EMPTY.withColor(ColorUtil.YELLOW)) + Component.translatable("bclib.updates.donate").setStyle(Style.EMPTY.withColor(ColorHelper.YELLOW)) ) .onPress((bt) -> openLink(UpdatesScreen.DONATION_URL)).centerVertical(); } @@ -81,7 +82,7 @@ public class WelcomeScreen extends BCLibLayoutScreen { innerContent.addSpacer(2); HorizontalStack dscBox = innerContent.indent(24); dscBox.addMultilineText(fill(), fit(), translatable("description.config.bclib.client.version.check")) - .setColor(ColorUtil.GRAY); + .setColor(ColorHelper.GRAY); dscBox.addSpacer(8); // Hide Experimental Dialog @@ -102,7 +103,7 @@ public class WelcomeScreen extends BCLibLayoutScreen { fit(), translatable("description.config.bclib.client.ui.suppressExperimentalDialogOnLoad") ) - .setColor(ColorUtil.GRAY); + .setColor(ColorHelper.GRAY); dscBox.addSpacer(8); // Use BetterX WorldType @@ -123,16 +124,16 @@ public class WelcomeScreen extends BCLibLayoutScreen { translatable("warning.config.bclib.client.ui.forceBetterXPreset") .setStyle(Style.EMPTY .withBold(true) - .withColor(ColorUtil.RED) + .withColor(ColorHelper.RED) ) .append(translatable( "description.config.bclib.client.ui.forceBetterXPreset").setStyle( Style.EMPTY .withBold(false) - .withColor(ColorUtil.GRAY)) + .withColor(ColorHelper.GRAY)) ) ) - .setColor(ColorUtil.GRAY); + .setColor(ColorHelper.GRAY); dscBox.addSpacer(8); innerContent.addSpacer(16); diff --git a/src/main/java/org/betterx/bclib/client/gui/screens/WorldSetupScreen.java b/src/main/java/org/betterx/bclib/client/gui/screens/WorldSetupScreen.java index 4305e791..f0ce64b6 100644 --- a/src/main/java/org/betterx/bclib/client/gui/screens/WorldSetupScreen.java +++ b/src/main/java/org/betterx/bclib/client/gui/screens/WorldSetupScreen.java @@ -6,11 +6,6 @@ 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.registry.PresetsRegistry; -import 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.vanilla.LayoutScreen; import org.betterx.worlds.together.worldPreset.TogetherWorldPreset; import org.betterx.worlds.together.worldPreset.WorldGenSettingsComponentAccessor; @@ -32,6 +27,12 @@ import net.minecraft.world.level.levelgen.presets.WorldPresets; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import org.wunder.lib.ui.layout.components.*; +import org.wunder.lib.ui.layout.components.render.RenderHelper; +import org.wunder.lib.ui.layout.values.Rectangle; +import org.wunder.lib.ui.layout.values.Size; +import org.wunder.lib.ui.vanilla.LayoutScreen; + import java.util.Map; import java.util.Optional; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/org/betterx/bclib/util/ColorExtractor.java b/src/main/java/org/betterx/bclib/util/ColorExtractor.java index 9c1d0132..593e9444 100644 --- a/src/main/java/org/betterx/bclib/util/ColorExtractor.java +++ b/src/main/java/org/betterx/bclib/util/ColorExtractor.java @@ -1,5 +1,6 @@ package org.betterx.bclib.util; + import org.betterx.ui.ColorUtil; import java.util.ArrayList; diff --git a/src/main/java/org/betterx/ui/ColorUtil.java b/src/main/java/org/betterx/ui/ColorUtil.java index e218412b..81c09d24 100644 --- a/src/main/java/org/betterx/ui/ColorUtil.java +++ b/src/main/java/org/betterx/ui/ColorUtil.java @@ -5,7 +5,6 @@ import org.betterx.bclib.util.ColorExtractor; import org.betterx.bclib.util.MHelper; import com.mojang.blaze3d.platform.NativeImage; -import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; import net.minecraft.core.Registry; import net.minecraft.resources.ResourceLocation; @@ -18,6 +17,7 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import com.google.common.collect.Maps; +import org.wunder.lib.ui.ColorHelper; import java.io.IOException; import java.util.ArrayList; @@ -25,23 +25,23 @@ import java.util.List; import java.util.Map; public class ColorUtil { - public static final int BLACK = ChatFormatting.BLACK.getColor() | 0xFF000000; - public static final int DARK_BLUE = ChatFormatting.DARK_BLUE.getColor() | 0xFF000000; - public static final int DARK_GREEN = ChatFormatting.DARK_GREEN.getColor() | 0xFF000000; - public static final int DARK_AQUA = ChatFormatting.DARK_AQUA.getColor() | 0xFF000000; - public static final int DARK_RED = ChatFormatting.DARK_RED.getColor() | 0xFF000000; - public static final int DARK_PURPLE = ChatFormatting.DARK_PURPLE.getColor() | 0xFF000000; - public static final int GOLD = ChatFormatting.GOLD.getColor() | 0xFF000000; - public static final int GRAY = ChatFormatting.GRAY.getColor() | 0xFF000000; - public static final int DARK_GRAY = ChatFormatting.DARK_GRAY.getColor() | 0xFF000000; - public static final int BLUE = ChatFormatting.BLUE.getColor() | 0xFF000000; - public static final int GREEN = ChatFormatting.GREEN.getColor() | 0xFF000000; - public static final int AQUA = ChatFormatting.AQUA.getColor() | 0xFF000000; - public static final int RED = ChatFormatting.RED.getColor() | 0xFF000000; - 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 = WHITE; + public static final int BLACK = ColorHelper.BLACK; + public static final int DARK_BLUE = ColorHelper.DARK_BLUE; + public static final int DARK_GREEN = ColorHelper.DARK_GREEN; + public static final int DARK_AQUA = ColorHelper.DARK_AQUA; + public static final int DARK_RED = ColorHelper.DARK_RED; + public static final int DARK_PURPLE = ColorHelper.DARK_PURPLE; + public static final int GOLD = ColorHelper.GOLD; + public static final int GRAY = ColorHelper.GRAY; + public static final int DARK_GRAY = ColorHelper.DARK_GRAY; + public static final int BLUE = ColorHelper.BLUE; + public static final int GREEN = ColorHelper.GREEN; + public static final int AQUA = ColorHelper.AQUA; + public static final int RED = ColorHelper.RED; + public static final int LIGHT_PURPLE = ColorHelper.LIGHT_PURPLE; + public static final int YELLOW = ColorHelper.YELLOW; + public static final int WHITE = ColorHelper.WHITE; + public static final int DEFAULT_TEXT = ColorHelper.WHITE; private static final float[] FLOAT_BUFFER = new float[4]; private static final int ALPHA = 255 << 24; diff --git a/src/main/java/org/betterx/ui/layout/components/AbstractHorizontalStack.java b/src/main/java/org/betterx/ui/layout/components/AbstractHorizontalStack.java deleted file mode 100644 index a7a4debf..00000000 --- a/src/main/java/org/betterx/ui/layout/components/AbstractHorizontalStack.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.betterx.ui.layout.components; - -import org.betterx.ui.layout.components.input.RelativeContainerEventHandler; -import org.betterx.ui.layout.components.render.NullRenderer; -import org.betterx.ui.layout.values.Alignment; -import org.betterx.ui.layout.values.Value; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; - -@Environment(EnvType.CLIENT) -public class AbstractHorizontalStack> extends AbstractStack implements RelativeContainerEventHandler { - public AbstractHorizontalStack(Value width, Value height) { - super(width, height); - } - - @Override - public int updateContainerWidth(int containerWidth) { - int myWidth = width.calculateOrFill(containerWidth); - int fixedWidth = components.stream().map(c -> c.width.calculate(myWidth)).reduce(0, Integer::sum); - - int freeWidth = Math.max(0, myWidth - fixedWidth); - fillWidth(myWidth, freeWidth); - - for (LayoutComponent c : components) { - c.updateContainerWidth(c.width.calculatedSize()); - } - - return myWidth; - } - - @Override - protected int updateContainerHeight(int containerHeight) { - int myHeight = height.calculateOrFill(containerHeight); - components.stream().forEach(c -> c.height.calculateOrFill(myHeight)); - for (LayoutComponent c : components) { - c.updateContainerHeight(c.height.calculatedSize()); - } - return myHeight; - } - - - @Override - void setRelativeBounds(int left, int top) { - super.setRelativeBounds(left, top); - - int offset = 0; - for (LayoutComponent c : components) { - int delta = relativeBounds.height - c.height.calculatedSize(); - if (c.vAlign == Alignment.MIN) delta = 0; - else if (c.vAlign == Alignment.CENTER) delta /= 2; - c.setRelativeBounds(offset, delta); - offset += c.relativeBounds.width; - } - } - - @Override - public int getContentWidth() { - int fixedWidth = components.stream().map(c -> c.width.calculateFixed()).reduce(0, Integer::sum); - double percentage = components.stream().map(c -> c.width.calculateRelative()).reduce(0.0, Double::sum); - - return (int) (fixedWidth / (1 - percentage)); - } - - @Override - public int getContentHeight() { - return components.stream().map(c -> c.height.calculateFixed()).reduce(0, Integer::max); - } - - - protected S addEmpty(Value size) { - this.components.add(new Empty(size, Value.fixed(0))); - return (S) this; - } - - protected VerticalStack addColumn(Value width, Value height) { - VerticalStack stack = new VerticalStack(width, height); - add(stack); - return stack; - } - - - protected VerticalStack addColumn() { - return addColumn(Value.fit(), Value.fit()); - } -} - diff --git a/src/main/java/org/betterx/ui/layout/components/AbstractStack.java b/src/main/java/org/betterx/ui/layout/components/AbstractStack.java deleted file mode 100644 index 980974b5..00000000 --- a/src/main/java/org/betterx/ui/layout/components/AbstractStack.java +++ /dev/null @@ -1,287 +0,0 @@ -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.values.Rectangle; -import org.betterx.ui.layout.values.Size; -import org.betterx.ui.layout.values.Value; -import org.betterx.ui.vanilla.VanillaScrollerRenderer; - -import com.mojang.blaze3d.vertex.PoseStack; -import net.minecraft.client.gui.components.events.GuiEventListener; -import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.ItemStack; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; - -import java.util.LinkedList; -import java.util.List; -import org.jetbrains.annotations.Nullable; - -@Environment(EnvType.CLIENT) -public abstract class AbstractStack> extends LayoutComponent implements RelativeContainerEventHandler { - protected final List> components = new LinkedList<>(); - - public AbstractStack(Value width, Value height) { - this(width, height, null); - } - - public AbstractStack(Value width, Value height, R renderer) { - super(width, height, renderer); - } - - @Override - public int fillWidth(int parentSize, int fillSize) { - double totalFillWeight = components.stream().map(c -> c.width.fillWeight()).reduce(0.0, Double::sum); - return components.stream() - .map(c -> c.width.fill(fillSize, totalFillWeight)) - .reduce(0, Integer::sum); - } - - @Override - public int fillHeight(int parentSize, int fillSize) { - double totalFillHeight = components.stream().map(c -> c.height.fillWeight()).reduce(0.0, Double::sum); - return components.stream() - .map(c -> c.height.fill(fillSize, totalFillHeight)) - .reduce(0, Integer::sum); - } - - @Override - public void updateScreenBounds(int worldX, int worldY) { - super.updateScreenBounds(worldX, worldY); - for (LayoutComponent c : components) { - c.updateScreenBounds(screenBounds.left, screenBounds.top); - } - } - - - @Override - protected void renderInBounds( - PoseStack poseStack, - int mouseX, - int mouseY, - float deltaTicks, - Rectangle renderBounds, - Rectangle clipRect - ) { - super.renderInBounds(poseStack, mouseX, mouseY, deltaTicks, renderBounds, clipRect); - for (LayoutComponent c : components) { - c.render(poseStack, mouseX, mouseY, deltaTicks, renderBounds, clipRect); - } - } - - @Override - public List children() { - return components; - } - - @Override - public Rectangle getInputBounds() { - return relativeBounds; - } - - boolean dragging; - - @Override - public boolean isDragging() { - return dragging; - } - - @Override - public void setDragging(boolean bl) { - dragging = bl; - } - - GuiEventListener focused; - - @Nullable - @Override - public GuiEventListener getFocused() { - return focused; - } - - @Override - public void setFocused(@Nullable GuiEventListener guiEventListener) { - focused = guiEventListener; - } - - public boolean isEmpty() { - return components.isEmpty(); - } - - protected abstract T addEmpty(Value size); - - protected T add(LayoutComponent c) { - this.components.add(c); - return (T) this; - } - - protected T addSpacer(int size) { - return addEmpty(Value.fixed(size)); - } - - protected T addSpacer(float percentage) { - return addEmpty(Value.relative(percentage)); - } - - protected T addFiller() { - return addEmpty(Value.fill()); - } - - - protected Image addIcon(ResourceLocation location, Size resourceSize) { - Image i = new Image(Value.fixed(24), Value.fixed(24), location, resourceSize); - add(i); - return i; - } - - protected Image addImage(Value width, Value height, ResourceLocation location, Size resourceSize) { - Image i = new Image(width, height, location, resourceSize); - add(i); - return i; - } - - protected Checkbox addCheckbox( - Value width, Value height, Component component, - boolean selected - ) { - Checkbox c = new Checkbox(width, height, component, selected, true); - add(c); - return c; - } - - protected Button addButton( - Value width, Value height, - Component component - ) { - Button b = new Button(width, height, component); - add(b); - return b; - } - - protected VerticalScroll addScrollable(LayoutComponent content) { - return addScrollable(Value.fill(), Value.fill(), content); - } - - protected VerticalScroll addScrollable( - Value width, - Value height, - LayoutComponent content - ) { - VerticalScroll s = VerticalScroll.create(width, height, content); - add(s); - return s; - } - - protected Text addText(Value width, Value height, net.minecraft.network.chat.Component text) { - Text t = new Text(width, height, text); - add(t); - return t; - } - - protected MultiLineText addMultilineText(Value width, Value height, net.minecraft.network.chat.Component text) { - MultiLineText t = new MultiLineText(width, height, text); - add(t); - return t; - } - - protected Range addRange( - Value width, Value height, - net.minecraft.network.chat.Component titleOrNull, - int minValue, int maxValue, int initialValue - ) { - Range r = new Range<>(width, height, titleOrNull, minValue, maxValue, initialValue); - add(r); - return r; - } - - protected Range addRange( - Value width, Value height, - net.minecraft.network.chat.Component titleOrNull, - float minValue, float maxValue, float initialValue - ) { - Range r = new Range<>(width, height, titleOrNull, minValue, maxValue, initialValue); - add(r); - return r; - } - - protected Range addRange( - Value width, Value height, - net.minecraft.network.chat.Component titleOrNull, - double minValue, double maxValue, double initialValue - ) { - Range r = new Range<>(width, height, titleOrNull, minValue, maxValue, initialValue); - add(r); - return r; - } - - protected Input addInput( - Value width, Value height, net.minecraft.network.chat.Component titleOrNull, String initialValue - ) { - Input i = new Input(width, height, titleOrNull, initialValue); - add(i); - return i; - } - - protected ColorSwatch addColorSwatch(Value width, Value height, int color) { - ColorSwatch c = new ColorSwatch(width, height, color); - add(c); - return c; - } - - protected ColorPicker addColorPicker( - Value width, - Value height, - net.minecraft.network.chat.Component titleOrNull, - int color - ) { - ColorPicker c = new ColorPicker(width, height, titleOrNull, color); - add(c); - return c; - } - - protected HLine addHorizontalSeparator(int height) { - return addHLine(Value.relative(1.0 / 1.618033988749894), Value.fixed(height)); - } - - protected HLine addHorizontalLine(int height) { - return addHLine(Value.fill(), Value.fixed(height)); - } - - protected HLine addHLine(Value width, Value height) { - HLine l = new HLine(width, height); - add(l); - return l; - } - - protected VLine addVerticalSeparator(int width) { - return addVLine(Value.fixed(width), Value.relative(1.0 / 1.618033988749894)); - } - - protected VLine addVerticalLine(int width) { - return addVLine(Value.fixed(width), Value.fill()); - } - - protected VLine addVLine(Value width, Value height) { - VLine l = new VLine(width, height); - add(l); - return l; - } - - protected Container addContainered(Value width, Value height, LayoutComponent content) { - Container c = new Container(width, height); - c.addChild(content); - add(c); - return c; - } - - protected Item addItem(ItemStack stack) { - Item i = new Item(Value.fit(), Value.fit()); - i.setItem(stack); - add(i); - return i; - } -} - diff --git a/src/main/java/org/betterx/ui/layout/components/AbstractVanillaComponent.java b/src/main/java/org/betterx/ui/layout/components/AbstractVanillaComponent.java deleted file mode 100644 index 59a4a7e0..00000000 --- a/src/main/java/org/betterx/ui/layout/components/AbstractVanillaComponent.java +++ /dev/null @@ -1,142 +0,0 @@ -package org.betterx.ui.layout.components; - -import org.betterx.ui.layout.values.Value; - -import net.minecraft.client.gui.components.AbstractWidget; - -public abstract class AbstractVanillaComponent> extends LayoutComponent, V> { - protected C vanillaComponent; - protected final net.minecraft.network.chat.Component component; - protected float alpha = 1.0f; - protected boolean enabled = true; - - public AbstractVanillaComponent( - Value width, - Value height, - AbstractVanillaComponentRenderer renderer, - net.minecraft.network.chat.Component component - ) { - super(width, height, renderer); - this.component = component; - renderer.linkedComponent = (V) this; - } - - protected abstract C createVanillaComponent(); - - @Override - protected void onBoundsChanged() { - vanillaComponent = createVanillaComponent(); - vanillaComponent.setAlpha(this.alpha); - } - - protected net.minecraft.network.chat.Component contentComponent() { - return component; - } - - @Override - public int getContentWidth() { - return renderer.getWidth(contentComponent()); - } - - @Override - public int getContentHeight() { - return renderer.getHeight(contentComponent()); - } - - public float getAlpha() { - return alpha; - } - - public V setAlpha(float alpha) { - this.alpha = alpha; - if (vanillaComponent != null) { - vanillaComponent.setAlpha(alpha); - } - return (V) this; - } - - public boolean isEnabled() { - return enabled; - } - - public V setEnabled(boolean enabled) { - this.enabled = enabled; - return (V) this; - } - - @Override - public void mouseMoved(double x, double y) { - if (vanillaComponent != null && enabled) - vanillaComponent.mouseMoved(x - relativeBounds.left, y - relativeBounds.top); - } - - @Override - public boolean mouseClicked(double x, double y, int button) { - if (vanillaComponent != null && enabled) - return vanillaComponent.mouseClicked(x - relativeBounds.left, y - relativeBounds.top, button); - return false; - } - - @Override - public boolean mouseReleased(double x, double y, int button) { - if (vanillaComponent != null && enabled) - return vanillaComponent.mouseReleased(x - relativeBounds.left, y - relativeBounds.top, button); - return false; - } - - @Override - public boolean mouseDragged(double x, double y, int button, double x2, double y2) { - if (vanillaComponent != null && enabled) - return vanillaComponent.mouseDragged( - x - relativeBounds.left, - y - relativeBounds.top, - button, - x2 - relativeBounds.left, - y2 - relativeBounds.top - ); - return false; - } - - @Override - public boolean mouseScrolled(double x, double y, double f) { - if (vanillaComponent != null && enabled) - return vanillaComponent.mouseScrolled(x - relativeBounds.left, y - relativeBounds.top, f); - return false; - } - - @Override - public boolean keyPressed(int i, int j, int k) { - if (vanillaComponent != null && enabled) - return vanillaComponent.keyPressed(i, j, k); - return false; - } - - @Override - public boolean keyReleased(int i, int j, int k) { - if (vanillaComponent != null && enabled) - return vanillaComponent.keyReleased(i, j, k); - return false; - } - - @Override - public boolean charTyped(char c, int i) { - if (vanillaComponent != null && enabled) - return vanillaComponent.charTyped(c, i); - return false; - } - - @Override - public boolean changeFocus(boolean bl) { - if (vanillaComponent != null && enabled) - return vanillaComponent.changeFocus(bl); - return false; - } - - @Override - public boolean isMouseOver(double x, double y) { - if (vanillaComponent != null && enabled) - return vanillaComponent.isMouseOver(x - relativeBounds.left, y - relativeBounds.top); - return false; - } - -} diff --git a/src/main/java/org/betterx/ui/layout/components/AbstractVanillaComponentRenderer.java b/src/main/java/org/betterx/ui/layout/components/AbstractVanillaComponentRenderer.java deleted file mode 100644 index 822798b2..00000000 --- a/src/main/java/org/betterx/ui/layout/components/AbstractVanillaComponentRenderer.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.betterx.ui.layout.components; - -import org.betterx.ui.layout.components.render.ComponentRenderer; -import org.betterx.ui.layout.components.render.TextProvider; -import org.betterx.ui.layout.values.Rectangle; - -import com.mojang.blaze3d.vertex.PoseStack; -import net.minecraft.client.gui.components.AbstractWidget; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; - -@Environment(EnvType.CLIENT) -public class AbstractVanillaComponentRenderer> implements ComponentRenderer, TextProvider { - V linkedComponent; - - protected V getLinkedComponent() { - return linkedComponent; - } - - @Override - public void renderInBounds( - PoseStack poseStack, - int mouseX, - int mouseY, - float deltaTicks, - Rectangle bounds, - Rectangle clipRect - ) { - if (linkedComponent != null) { - if (linkedComponent.vanillaComponent != null) { - if (!linkedComponent.enabled) { - linkedComponent.vanillaComponent.setAlpha(linkedComponent.alpha / 2); - } - linkedComponent.vanillaComponent.render(poseStack, mouseX, mouseY, deltaTicks); - if (!linkedComponent.enabled) { - linkedComponent.vanillaComponent.setAlpha(linkedComponent.alpha); - } - } - - } - } -} diff --git a/src/main/java/org/betterx/ui/layout/components/AbstractVerticalStack.java b/src/main/java/org/betterx/ui/layout/components/AbstractVerticalStack.java deleted file mode 100644 index a42b69d7..00000000 --- a/src/main/java/org/betterx/ui/layout/components/AbstractVerticalStack.java +++ /dev/null @@ -1,83 +0,0 @@ -package org.betterx.ui.layout.components; - -import org.betterx.ui.layout.components.input.RelativeContainerEventHandler; -import org.betterx.ui.layout.components.render.NullRenderer; -import org.betterx.ui.layout.values.Alignment; -import org.betterx.ui.layout.values.Value; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; - -@Environment(EnvType.CLIENT) -public class AbstractVerticalStack> extends AbstractStack implements RelativeContainerEventHandler { - public AbstractVerticalStack(Value width, Value height) { - super(width, height); - } - - @Override - protected int updateContainerWidth(int containerWidth) { - int myWidth = width.calculateOrFill(containerWidth); - components.stream().forEach(c -> c.width.calculateOrFill(myWidth)); - for (LayoutComponent c : components) { - c.updateContainerWidth(c.width.calculatedSize()); - } - return myWidth; - } - - @Override - public int updateContainerHeight(int containerHeight) { - int myHeight = height.calculateOrFill(containerHeight); - int fixedHeight = components.stream().map(c -> c.height.calculate(myHeight)).reduce(0, Integer::sum); - - int freeHeight = Math.max(0, myHeight - fixedHeight); - fillHeight(myHeight, freeHeight); - - for (LayoutComponent c : components) { - c.updateContainerHeight(c.height.calculatedSize()); - } - - return myHeight; - } - - @Override - void setRelativeBounds(int left, int top) { - super.setRelativeBounds(left, top); - - int offset = 0; - for (LayoutComponent c : components) { - int delta = relativeBounds.width - c.width.calculatedSize(); - if (c.hAlign == Alignment.MIN) delta = 0; - else if (c.hAlign == Alignment.CENTER) delta /= 2; - c.setRelativeBounds(delta, offset); - offset += c.relativeBounds.height; - } - } - - @Override - public int getContentWidth() { - return components.stream().map(c -> c.width.calculateFixed()).reduce(0, Integer::max); - } - - @Override - public int getContentHeight() { - int fixedHeight = components.stream().map(c -> c.height.calculateFixed()).reduce(0, Integer::sum); - double percentage = components.stream().map(c -> c.height.calculateRelative()).reduce(0.0, Double::sum); - - return (int) (fixedHeight / (1 - percentage)); - } - - protected S addEmpty(Value size) { - this.components.add(new Empty(Value.fixed(0), size)); - return (S) this; - } - - protected HorizontalStack addRow(Value width, Value height) { - HorizontalStack stack = new HorizontalStack(width, height); - add(stack); - return stack; - } - - protected HorizontalStack addRow() { - return addRow(Value.fit(), Value.fit()); - } -} \ No newline at end of file diff --git a/src/main/java/org/betterx/ui/layout/components/Button.java b/src/main/java/org/betterx/ui/layout/components/Button.java deleted file mode 100644 index 50109162..00000000 --- a/src/main/java/org/betterx/ui/layout/components/Button.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.betterx.ui.layout.components; - -import org.betterx.ui.layout.components.render.ButtonRenderer; -import org.betterx.ui.layout.values.Value; - -import com.mojang.blaze3d.vertex.PoseStack; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; - -@Environment(EnvType.CLIENT) -public class Button extends AbstractVanillaComponent { - public static final OnTooltip NO_TOOLTIP = (button, poseStack, i, j) -> { - }; - public static final OnPress NO_ACTION = (button) -> { - }; - - @Environment(EnvType.CLIENT) - public interface OnTooltip { - void onTooltip(Button button, PoseStack poseStack, int mouseX, int mouseY); - } - - @Environment(EnvType.CLIENT) - public interface OnPress { - void onPress(Button button); - } - - OnPress onPress; - OnTooltip onTooltip; - - boolean glow = false; - - public Button( - Value width, - Value height, - net.minecraft.network.chat.Component component - ) { - super(width, height, new ButtonRenderer(), component); - this.onPress = NO_ACTION; - this.onTooltip = NO_TOOLTIP; - } - - public Button onPress(OnPress onPress) { - this.onPress = onPress; - return this; - } - - public Button onToolTip(OnTooltip onTooltip) { - this.onTooltip = onTooltip; - return this; - } - - @Override - protected net.minecraft.client.gui.components.Button createVanillaComponent() { - Button self = this; - return net.minecraft.client.gui.components.Button - .builder(component, (bt) -> onPress.onPress(self)) - .bounds(0, 0, relativeBounds.width, relativeBounds.height) - .tooltip((bt, stack, x, y) -> onTooltip.onTooltip(self, stack, x, y)) - .build(); - - } - - public boolean isGlowing() { - return glow; - } -} diff --git a/src/main/java/org/betterx/ui/layout/components/Checkbox.java b/src/main/java/org/betterx/ui/layout/components/Checkbox.java deleted file mode 100644 index 0bcdad2c..00000000 --- a/src/main/java/org/betterx/ui/layout/components/Checkbox.java +++ /dev/null @@ -1,68 +0,0 @@ -package org.betterx.ui.layout.components; - -import org.betterx.ui.layout.components.render.CheckboxRenderer; -import org.betterx.ui.layout.values.Value; - -import net.minecraft.network.chat.Component; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; - -@Environment(EnvType.CLIENT) -public class Checkbox extends AbstractVanillaComponent { - public static SelectionChanged IGNORE_CHANGE = (a, b) -> { - }; - - @FunctionalInterface - public interface SelectionChanged { - void now(Checkbox checkBox, boolean selected); - } - - private final boolean selected; - private final boolean showLabel; - - private SelectionChanged onSelectionChange; - - public Checkbox( - Value width, - Value height, - Component component, - boolean selected, boolean showLabel - ) { - super(width, height, new CheckboxRenderer(), component); - onSelectionChange = IGNORE_CHANGE; - this.selected = selected; - this.showLabel = showLabel; - } - - public Checkbox onChange(SelectionChanged onSelectionChange) { - this.onSelectionChange = onSelectionChange; - return this; - } - - public boolean isChecked() { - if (vanillaComponent != null) return vanillaComponent.selected(); - return selected; - } - - @Override - protected net.minecraft.client.gui.components.Checkbox createVanillaComponent() { - Checkbox self = this; - net.minecraft.client.gui.components.Checkbox cb = new net.minecraft.client.gui.components.Checkbox( - 0, 0, - relativeBounds.width, relativeBounds.height, - component, - selected, - showLabel - ) { - @Override - public void onPress() { - super.onPress(); - onSelectionChange.now(self, this.selected()); - } - }; - - onSelectionChange.now(this, cb.selected()); - return cb; - } -} diff --git a/src/main/java/org/betterx/ui/layout/components/ColorPicker.java b/src/main/java/org/betterx/ui/layout/components/ColorPicker.java deleted file mode 100644 index 45b7bffd..00000000 --- a/src/main/java/org/betterx/ui/layout/components/ColorPicker.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.betterx.ui.layout.components; - -import org.betterx.ui.ColorUtil; -import org.betterx.ui.layout.values.Value; - -import net.minecraft.network.chat.Component; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; - -@Environment(EnvType.CLIENT) -public class ColorPicker extends AbstractHorizontalStack { - ColorSwatch swatch; - Input input; - - public ColorPicker(Value width, Value height, Component title, int color) { - super(width, height); - swatch = addColorSwatch(Value.fixed(20), Value.fixed(20), color); - input = addInput(Value.fill(), Value.fit(), title, ColorUtil.toRGBHex(color)); - - //input.setFilter(ColorUtil::validHexColor); - input.setResponder(this::inputResponder); - } - - private void inputResponder(String value) { - if (ColorUtil.validHexColor(value)) { - int color = ColorUtil.parseHex(value); - swatch.setColor(color); - swatch.setOffsetInner(false); - swatch.setBorderColor(ColorUtil.BLACK); - } else { - swatch.setOffsetInner(true); - swatch.setBorderColor(ColorUtil.RED); - } - } -} diff --git a/src/main/java/org/betterx/ui/layout/components/ColorSwatch.java b/src/main/java/org/betterx/ui/layout/components/ColorSwatch.java deleted file mode 100644 index ce30ad0c..00000000 --- a/src/main/java/org/betterx/ui/layout/components/ColorSwatch.java +++ /dev/null @@ -1,68 +0,0 @@ -package org.betterx.ui.layout.components; - -import org.betterx.ui.ColorUtil; -import org.betterx.ui.layout.components.render.RenderHelper; -import org.betterx.ui.layout.values.Rectangle; -import org.betterx.ui.layout.values.Value; - -import com.mojang.blaze3d.vertex.PoseStack; -import net.minecraft.client.gui.GuiComponent; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; - -@Environment(EnvType.CLIENT) -public class ColorSwatch extends CustomRenderComponent { - private int color; - private int borderColor = ColorUtil.BLACK; - private boolean offsetInner = false; - - public ColorSwatch(Value width, Value height, int color) { - super(width, height); - this.color = color; - } - - @Override - protected void customRender(PoseStack stack, int x, int y, float deltaTicks, Rectangle bounds, Rectangle clipRect) { - int o = offsetInner ? 2 : 1; - RenderHelper.outline(stack, 0, 0, bounds.width, bounds.height, borderColor); - GuiComponent.fill(stack, o, o, bounds.width - o, bounds.height - o, color); - } - - public int getColor() { - return color; - } - - public ColorSwatch setColor(int color) { - this.color = color; - return this; - } - - public int getBorderColor() { - return borderColor; - } - - public ColorSwatch setBorderColor(int color) { - this.borderColor = color; - return this; - } - - public boolean getOffsetInner() { - return offsetInner; - } - - public ColorSwatch setOffsetInner(boolean val) { - this.offsetInner = val; - return this; - } - - @Override - public int getContentWidth() { - return 20; - } - - @Override - public int getContentHeight() { - return 20; - } -} diff --git a/src/main/java/org/betterx/ui/layout/components/ComponentWithBounds.java b/src/main/java/org/betterx/ui/layout/components/ComponentWithBounds.java deleted file mode 100644 index af9ed645..00000000 --- a/src/main/java/org/betterx/ui/layout/components/ComponentWithBounds.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.betterx.ui.layout.components; - -import org.betterx.ui.layout.values.Rectangle; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; - -@Environment(EnvType.CLIENT) -public interface ComponentWithBounds { - Rectangle getRelativeBounds(); -} diff --git a/src/main/java/org/betterx/ui/layout/components/Container.java b/src/main/java/org/betterx/ui/layout/components/Container.java deleted file mode 100644 index 40d25a0f..00000000 --- a/src/main/java/org/betterx/ui/layout/components/Container.java +++ /dev/null @@ -1,291 +0,0 @@ -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.RenderHelper; -import org.betterx.ui.layout.values.Alignment; -import org.betterx.ui.layout.values.Rectangle; -import org.betterx.ui.layout.values.Value; - -import com.mojang.blaze3d.vertex.PoseStack; -import net.minecraft.client.gui.GuiComponent; -import net.minecraft.client.gui.components.events.GuiEventListener; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; - -import java.util.LinkedList; -import java.util.List; -import org.jetbrains.annotations.Nullable; - -@Environment(EnvType.CLIENT) -public class Container extends LayoutComponent implements RelativeContainerEventHandler { - public static class ContainerRenderer implements ComponentRenderer { - Container linkedContainer; - - @Override - public void renderInBounds( - PoseStack stack, - int mouseX, - int mouseY, - float deltaTicks, - Rectangle bounds, - Rectangle clipRect - ) { - if (linkedContainer != null) { - if ((linkedContainer.backgroundColor & 0xFF000000) != 0) - GuiComponent.fill(stack, 0, 0, bounds.width, bounds.height, linkedContainer.backgroundColor); - - if ((linkedContainer.outlineColor & 0xFF000000) != 0) - RenderHelper.outline(stack, 0, 0, bounds.width, bounds.height, linkedContainer.outlineColor); - } - } - } - - record Positional(int left, int top, LayoutComponent component) { - public int getMaxX() { - return left + component().getContentWidth(); - } - - public int getMaxY() { - return top + component().getContentHeight(); - } - } - - private final List children = new LinkedList<>(); - boolean dragging = false; - GuiEventListener focused = null; - boolean visible = true; - - int paddingLeft, paddingTop, paddingRight, paddingBottom; - - int backgroundColor = 0; - int outlineColor = 0; - - public Container( - Value width, - Value height - ) { - super(width, height, new ContainerRenderer()); - renderer.linkedContainer = this; - } - - public Container addChild(LayoutComponent child) { - children.add(new Positional(0, 0, child)); - return this; - } - - public Container addChild(int left, int top, LayoutComponent child) { - children.add(new Positional(left, top, child)); - return this; - } - - public Container setVisible(boolean v) { - this.visible = v; - return this; - } - - public boolean getVisible() { - return this.visible; - } - - public Container setBackgroundColor(int color) { - this.backgroundColor = color; - return this; - } - - public int getBackgroundColor() { - return backgroundColor; - } - - public Container setOutlineColor(int color) { - this.outlineColor = color; - return this; - } - - public int getOutlineColor() { - return outlineColor; - } - - public Container setPadding(int padding) { - return setPadding(padding, padding, padding, 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(Positional::getMaxX) - .reduce(0, Math::max) + paddingLeft + paddingRight; - } - - @Override - public int getContentHeight() { - return children.stream() - .map(Positional::getMaxY) - .reduce(0, Math::max) + paddingTop + paddingBottom; - } - - @Override - public Rectangle getInputBounds() { - return relativeBounds; - } - - @Override - public List children() { - return children.stream().map(p -> p.component).toList(); - } - - @Override - public boolean isDragging() { - return dragging; - } - - @Override - public void setDragging(boolean bl) { - dragging = bl; - } - - @Nullable - @Override - public GuiEventListener getFocused() { - return focused; - } - - @Override - public void setFocused(@Nullable GuiEventListener guiEventListener) { - focused = guiEventListener; - } - - @Override - protected int updateContainerWidth(int containerWidth) { - int myWidth = width.calculateOrFill(containerWidth); - for (var child : children) { - child.component.width.calculateOrFill(myWidth - (paddingLeft + paddingRight)); - child.component.updateContainerWidth(child.component.width.calculatedSize()); - } - return myWidth; - } - - @Override - protected int updateContainerHeight(int containerHeight) { - int myHeight = height.calculateOrFill(containerHeight); - for (var child : children) { - child.component.height.calculateOrFill(myHeight - (paddingTop + paddingBottom)); - child.component.updateContainerHeight(child.component.height.calculatedSize()); - } - return myHeight; - } - - @Override - protected void renderInBounds( - PoseStack poseStack, - int mouseX, - int mouseY, - float deltaTicks, - Rectangle renderBounds, - Rectangle clipRect - ) { - if (visible) { - super.renderInBounds(poseStack, mouseX, mouseY, deltaTicks, renderBounds, clipRect); - - setClippingRect(clipRect); - for (var child : children) { - child.component.render( - poseStack, mouseX, mouseY, deltaTicks, - renderBounds, clipRect - ); - } - setClippingRect(null); - } - } - - @Override - void setRelativeBounds(int left, int top) { - super.setRelativeBounds(left, top); - - for (var child : children) { - int childLeft = (relativeBounds.width - (paddingLeft + paddingRight)) - child.component.width.calculatedSize(); - if (child.component.hAlign == Alignment.MIN) childLeft = 0; - else if (child.component.hAlign == Alignment.CENTER) childLeft /= 2; - - int childTop = (relativeBounds.height - (paddingTop + paddingBottom)) - child.component.height.calculatedSize(); - if (child.component.vAlign == Alignment.MIN) childTop = 0; - else if (child.component.vAlign == Alignment.CENTER) childTop /= 2; - - child.component.setRelativeBounds(child.left + paddingLeft + childLeft, child.top + paddingTop + childTop); - } - } - - @Override - public void updateScreenBounds(int worldX, int worldY) { - super.updateScreenBounds(worldX, worldY); - for (Positional p : children) { - p.component.updateScreenBounds(p.left + screenBounds.left, p.top + screenBounds.top); - } - } - - @Override - public void mouseMoved(double d, double e) { - if (visible) - RelativeContainerEventHandler.super.mouseMoved(d, e); - } - - @Override - public boolean mouseClicked(double d, double e, int i) { - if (visible) - return RelativeContainerEventHandler.super.mouseClicked(d, e, i); - return false; - } - - @Override - public boolean mouseReleased(double d, double e, int i) { - if (visible) - return RelativeContainerEventHandler.super.mouseReleased(d, e, i); - return false; - } - - @Override - public boolean mouseScrolled(double d, double e, double f) { - if (visible) - return RelativeContainerEventHandler.super.mouseScrolled(d, e, f); - return false; - } - - @Override - public boolean mouseDragged(double d, double e, int i, double f, double g) { - if (visible) - return RelativeContainerEventHandler.super.mouseDragged(d, e, i, f, g); - return false; - } - - @Override - public boolean isMouseOver(double x, double y) { - if (visible) { - boolean res = false; - for (var child : children) { - res |= child.component.isMouseOver(x, y); - } - - return res || relativeBounds.contains(x, y); - } - 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; - } -} diff --git a/src/main/java/org/betterx/ui/layout/components/CustomRenderComponent.java b/src/main/java/org/betterx/ui/layout/components/CustomRenderComponent.java deleted file mode 100644 index d7a234f3..00000000 --- a/src/main/java/org/betterx/ui/layout/components/CustomRenderComponent.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.betterx.ui.layout.components; - -import org.betterx.ui.layout.components.render.ComponentRenderer; -import org.betterx.ui.layout.values.Rectangle; -import org.betterx.ui.layout.values.Value; - -import com.mojang.blaze3d.vertex.PoseStack; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; - -@Environment(EnvType.CLIENT) -public abstract class CustomRenderComponent> extends LayoutComponent, C> { - public CustomRenderComponent( - Value width, - Value height - ) { - super(width, height, new CustomRenderRenderer<>()); - renderer.linkedComponent = (C) this; - } - - protected abstract void customRender( - PoseStack stack, - int x, - int y, - float deltaTicks, - Rectangle bounds, - Rectangle clipRect - ); - - protected static class CustomRenderRenderer> implements ComponentRenderer { - C linkedComponent; - - @Override - public void renderInBounds( - PoseStack stack, - int mouseX, - int mouseY, - float deltaTicks, - Rectangle bounds, - Rectangle clipRect - ) { - if (linkedComponent != null) { - linkedComponent.customRender(stack, mouseX, mouseY, deltaTicks, bounds, clipRect); - } - } - } -} diff --git a/src/main/java/org/betterx/ui/layout/components/Empty.java b/src/main/java/org/betterx/ui/layout/components/Empty.java deleted file mode 100644 index fca87bfd..00000000 --- a/src/main/java/org/betterx/ui/layout/components/Empty.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.betterx.ui.layout.components; - -import org.betterx.ui.layout.components.render.NullRenderer; -import org.betterx.ui.layout.values.Value; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; - -@Environment(EnvType.CLIENT) -public class Empty extends LayoutComponent { - public Empty( - Value width, - Value height - ) { - super(width, height, null); - } - - @Override - public int getContentWidth() { - return 0; - } - - @Override - public int getContentHeight() { - return 0; - } - - @Override - public boolean isMouseOver(double d, double e) { - return false; - } -} diff --git a/src/main/java/org/betterx/ui/layout/components/HLine.java b/src/main/java/org/betterx/ui/layout/components/HLine.java deleted file mode 100644 index fb2093ed..00000000 --- a/src/main/java/org/betterx/ui/layout/components/HLine.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.betterx.ui.layout.components; - -import org.betterx.ui.ColorUtil; -import org.betterx.ui.layout.components.render.RenderHelper; -import org.betterx.ui.layout.values.Alignment; -import org.betterx.ui.layout.values.Rectangle; -import org.betterx.ui.layout.values.Value; - -import com.mojang.blaze3d.vertex.PoseStack; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; - -@Environment(EnvType.CLIENT) -public class HLine extends CustomRenderComponent { - private int color = ColorUtil.DEFAULT_TEXT; - - public HLine(Value width, Value height) { - super(width, height); - this.vAlign = Alignment.CENTER; - this.hAlign = Alignment.CENTER; - } - - public HLine setColor(int color) { - this.color = color; - return this; - } - - @Override - protected void customRender(PoseStack stack, int x, int y, float deltaTicks, Rectangle bounds, Rectangle clipRect) { - int top = bounds.height - getContentHeight(); - if (vAlign == Alignment.CENTER) top /= 2; - else if (vAlign == Alignment.MIN) top = 0; - RenderHelper.hLine(stack, 0, bounds.width, top, color); - } - - @Override - public int getContentWidth() { - return 0; - } - - @Override - public int getContentHeight() { - return 1; - } -} diff --git a/src/main/java/org/betterx/ui/layout/components/HorizontalStack.java b/src/main/java/org/betterx/ui/layout/components/HorizontalStack.java deleted file mode 100644 index da3ca063..00000000 --- a/src/main/java/org/betterx/ui/layout/components/HorizontalStack.java +++ /dev/null @@ -1,205 +0,0 @@ -package org.betterx.ui.layout.components; - -import org.betterx.ui.layout.values.Size; -import org.betterx.ui.layout.values.Value; -import org.betterx.ui.vanilla.VanillaScrollerRenderer; - -import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.ItemStack; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; - -@Environment(EnvType.CLIENT) -public class HorizontalStack extends AbstractHorizontalStack { - public HorizontalStack(Value width, Value height) { - super(width, height); - } - - - public static HorizontalStack centered(LayoutComponent c) { - return new HorizontalStack(Value.fill(), Value.fill()).addFiller().add(c).addFiller(); - } - - public static HorizontalStack bottom(LayoutComponent c) { - return new HorizontalStack(Value.fill(), Value.fill()).add(c).addFiller(); - } - - protected HorizontalStack addEmpty(Value size) { - this.components.add(new Empty(size, Value.fixed(0))); - return this; - } - - @Override - public HorizontalStack add(LayoutComponent c) { - return super.add(c); - } - - public VerticalStack addColumn(Value width, Value height) { - return super.addColumn(width, height); - } - - public VerticalStack addColumn() { - return super.addColumn(); - } - - @Override - public HorizontalStack addSpacer(int size) { - return super.addSpacer(size); - } - - @Override - public HorizontalStack addSpacer(float percentage) { - return super.addSpacer(percentage); - } - - @Override - public HorizontalStack addFiller() { - return super.addFiller(); - } - - @Override - public Button addButton( - Value width, - Value height, - Component component - ) { - return super.addButton(width, height, component); - } - - @Override - public Checkbox addCheckbox( - Value width, - Value height, - Component component, - boolean selected - ) { - return super.addCheckbox(width, height, component, selected); - } - - @Override - public ColorPicker addColorPicker(Value width, Value height, Component titleOrNull, int color) { - return super.addColorPicker(width, height, titleOrNull, color); - } - - @Override - public ColorSwatch addColorSwatch(Value width, Value height, int color) { - return super.addColorSwatch(width, height, color); - } - - @Override - public Container addContainered(Value width, Value height, LayoutComponent content) { - return super.addContainered(width, height, content); - } - - @Override - public HLine addHLine(Value width, Value height) { - return super.addHLine(width, height); - } - - @Override - public HLine addHorizontalLine(int height) { - return super.addHorizontalLine(height); - } - - @Override - public HLine addHorizontalSeparator(int height) { - return super.addHorizontalSeparator(height); - } - - @Override - public Image addIcon(ResourceLocation location, Size resourceSize) { - return super.addIcon(location, resourceSize); - } - - @Override - public Image addImage(Value width, Value height, ResourceLocation location, Size resourceSize) { - return super.addImage(width, height, location, resourceSize); - } - - @Override - public Input addInput(Value width, Value height, Component titleOrNull, String initialValue) { - return super.addInput(width, height, titleOrNull, initialValue); - } - - @Override - public MultiLineText addMultilineText(Value width, Value height, Component text) { - return super.addMultilineText(width, height, text); - } - - @Override - public Range addRange( - Value width, - Value height, - Component titleOrNull, - double minValue, - double maxValue, - double initialValue - ) { - return super.addRange(width, height, titleOrNull, minValue, maxValue, initialValue); - } - - @Override - public Range addRange( - Value width, - Value height, - Component titleOrNull, - float minValue, - float maxValue, - float initialValue - ) { - return super.addRange(width, height, titleOrNull, minValue, maxValue, initialValue); - } - - @Override - public Range addRange( - Value width, - Value height, - Component titleOrNull, - int minValue, - int maxValue, - int initialValue - ) { - return super.addRange(width, height, titleOrNull, minValue, maxValue, initialValue); - } - - @Override - public Text addText(Value width, Value height, Component text) { - return super.addText(width, height, text); - } - - @Override - public VerticalScroll addScrollable(LayoutComponent content) { - return super.addScrollable(content); - } - - @Override - public VLine addVerticalLine(int width) { - return super.addVerticalLine(width); - } - - @Override - public VLine addVerticalSeparator(int width) { - return super.addVerticalSeparator(width); - } - - @Override - public VLine addVLine(Value width, Value height) { - return super.addVLine(width, height); - } - - @Override - public VerticalScroll addScrollable( - Value width, - Value height, - LayoutComponent content - ) { - return super.addScrollable(width, height, content); - } - - @Override - public Item addItem(ItemStack stack) { - return super.addItem(stack); - } -} diff --git a/src/main/java/org/betterx/ui/layout/components/Image.java b/src/main/java/org/betterx/ui/layout/components/Image.java deleted file mode 100644 index 74d9e279..00000000 --- a/src/main/java/org/betterx/ui/layout/components/Image.java +++ /dev/null @@ -1,98 +0,0 @@ -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.vertex.PoseStack; -import net.minecraft.resources.ResourceLocation; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; - -@Environment(EnvType.CLIENT) -public class Image extends CustomRenderComponent { - protected Rectangle uvRect; - public final ResourceLocation location; - protected float alpha; - protected Size resourceSize; - - public Image(Value width, Value height, ResourceLocation location) { - this(width, height, location, new Size(16, 16)); - } - - public Image(Value width, Value height, ResourceLocation location, Size resourceSize) { - super(width, height); - this.location = location; - this.uvRect = new Rectangle(0, 0, resourceSize.width(), resourceSize.height()); - this.resourceSize = resourceSize; - this.alpha = 1f; - } - - - public Image setAlpha(float a) { - alpha = a; - return this; - } - - public float getAlpha() { - return alpha; - } - - - public Image setUvRect(int left, int top, int width, int height) { - setUvRect(new Rectangle(left, top, width, height)); - return this; - } - - public Image setUvRect(Rectangle rect) { - uvRect = rect; - return this; - } - - public Rectangle getUvRect() { - return uvRect; - } - - public Image setResourceSize(int width, int height) { - return setResourceSize(new Size(width, height)); - } - - public Image setResourceSize(Size sz) { - resourceSize = sz; - return this; - } - - public Size getResourceSize() { - return resourceSize; - } - - @Override - public int getContentWidth() { - return uvRect.width; - } - - @Override - public int getContentHeight() { - return uvRect.height; - } - - - @Override - protected void customRender( - PoseStack stack, - int mouseX, - int mouseY, - float deltaTicks, - Rectangle bounds, - Rectangle clipRect - ) { - RenderHelper.renderImage(stack, 0, 0, bounds.width, bounds.height, location, resourceSize, uvRect, alpha); - } - - @Override - public boolean isMouseOver(double d, double e) { - return false; - } -} diff --git a/src/main/java/org/betterx/ui/layout/components/Input.java b/src/main/java/org/betterx/ui/layout/components/Input.java deleted file mode 100644 index ce07475a..00000000 --- a/src/main/java/org/betterx/ui/layout/components/Input.java +++ /dev/null @@ -1,96 +0,0 @@ -package org.betterx.ui.layout.components; - -import org.betterx.ui.layout.components.render.EditBoxRenderer; -import org.betterx.ui.layout.values.Value; - -import net.minecraft.client.gui.components.EditBox; -import net.minecraft.network.chat.Component; -import net.minecraft.util.FormattedCharSequence; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; - -import java.util.function.BiFunction; -import java.util.function.Consumer; -import java.util.function.Predicate; - -@Environment(EnvType.CLIENT) -public class Input extends AbstractVanillaComponent { - private Consumer responder; - private BiFunction formatter; - private Predicate filter; - private String initialValue = ""; - - public Input( - Value width, - Value height, - Component component, - String initialValue - ) { - super(width, height, new EditBoxRenderer(), component); - this.initialValue = initialValue; - } - - @Override - protected EditBox createVanillaComponent() { - EditBox eb = new EditBox(renderer.getFont(), - 0, 0, - relativeBounds.width, relativeBounds.height, - null, - component - ); - if (responder != null) eb.setResponder(responder); - if (filter != null) eb.setFilter(filter); - if (formatter != null) eb.setFormatter(formatter); - eb.setValue(initialValue); - eb.setBordered(true); - eb.setEditable(true); - - return eb; - } - - public Input setResponder(Consumer consumer) { - this.responder = consumer; - if (vanillaComponent != null) vanillaComponent.setResponder(responder); - return this; - } - - public Input setFormatter(BiFunction formatter) { - this.formatter = formatter; - if (vanillaComponent != null) vanillaComponent.setFormatter(formatter); - return this; - } - - public Input setFilter(Predicate filter) { - this.filter = filter; - if (vanillaComponent != null) vanillaComponent.setFilter(filter); - return this; - } - - public String getValue() { - if (vanillaComponent != null) return vanillaComponent.getValue(); - return ""; - } - - public Input setValue(String value) { - if (vanillaComponent != null) vanillaComponent.setValue(value); - else initialValue = value; - - return this; - } - - @Override - protected Component contentComponent() { - return Component.literal(initialValue + ".."); - } - - @Override - public boolean changeFocus(boolean bl) { - return super.changeFocus(bl); - } - - @Override - public boolean mouseClicked(double x, double y, int button) { - return super.mouseClicked(x, y, button); - } -} diff --git a/src/main/java/org/betterx/ui/layout/components/Item.java b/src/main/java/org/betterx/ui/layout/components/Item.java deleted file mode 100644 index 352cad48..00000000 --- a/src/main/java/org/betterx/ui/layout/components/Item.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.betterx.ui.layout.components; - - -import org.betterx.ui.layout.values.Rectangle; -import org.betterx.ui.layout.values.Value; - -import com.mojang.blaze3d.vertex.PoseStack; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.entity.ItemRenderer; -import net.minecraft.world.item.ItemStack; - -public class Item extends CustomRenderComponent { - private ItemStack itemStack; - - public Item(Value width, Value height) { - super(width, height); - } - - public Item setItem(ItemStack item) { - this.itemStack = item; - return this; - } - - @Override - protected void customRender(PoseStack stack, int x, int y, float deltaTicks, Rectangle bounds, Rectangle clipRect) { - final ItemRenderer itemRenderer = Minecraft.getInstance().getItemRenderer(); - itemRenderer.renderAndDecorateItem(Minecraft.getInstance().player, itemStack, bounds.left, bounds.top, 0); - itemRenderer.renderGuiItemDecorations( - Minecraft.getInstance().font, - itemStack, - bounds.left, - bounds.top, - "" + itemStack.getCount() - ); - } - - @Override - public int getContentWidth() { - return 16; - } - - @Override - public int getContentHeight() { - return 16; - } -} diff --git a/src/main/java/org/betterx/ui/layout/components/LayoutComponent.java b/src/main/java/org/betterx/ui/layout/components/LayoutComponent.java deleted file mode 100644 index 48e68ada..00000000 --- a/src/main/java/org/betterx/ui/layout/components/LayoutComponent.java +++ /dev/null @@ -1,184 +0,0 @@ -package org.betterx.ui.layout.components; - -import org.betterx.ui.layout.components.render.ComponentRenderer; -import org.betterx.ui.layout.values.Alignment; -import org.betterx.ui.layout.values.Rectangle; -import org.betterx.ui.layout.values.Value; - -import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.PoseStack; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.components.events.GuiEventListener; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; - -@Environment(EnvType.CLIENT) -public abstract class LayoutComponent> implements ComponentWithBounds, GuiEventListener { - protected final R renderer; - protected final Value width; - protected final Value height; - protected String debugName; - protected Rectangle relativeBounds; - protected Rectangle screenBounds; - protected Alignment vAlign = Alignment.MIN; - protected Alignment hAlign = Alignment.MIN; - - public LayoutComponent(Value width, Value height, R renderer) { - this.width = width.attachComponent(this::getContentWidth); - this.height = height.attachComponent(this::getContentHeight); - this.renderer = renderer; - } - - public void reCalculateLayout() { - updateContainerWidth(relativeBounds.width); - updateContainerHeight(relativeBounds.height); - setRelativeBounds(relativeBounds.left, relativeBounds.top); - updateScreenBounds(screenBounds.left, screenBounds.top); - } - - protected int updateContainerWidth(int containerWidth) { - return width.setCalculatedSize(containerWidth); - } - - protected int updateContainerHeight(int containerHeight) { - return height.setCalculatedSize(containerHeight); - } - - void setRelativeBounds(int left, int top) { - relativeBounds = new Rectangle(left, top, width.calculatedSize(), height.calculatedSize()); - onBoundsChanged(); - } - - public void updateScreenBounds(int worldX, int worldY) { - screenBounds = relativeBounds.movedBy(worldX, worldY); - } - - protected void onBoundsChanged() { - } - - public Rectangle getRelativeBounds() { - return relativeBounds; - } - - public Rectangle getScreenBounds() { - return screenBounds; - } - - public abstract int getContentWidth(); - public abstract int getContentHeight(); - - public int fillWidth(int parentSize, int fillSize) { - return width.fill(fillSize); - } - - public int fillHeight(int parentSize, int fillSize) { - return height.fill(fillSize); - } - - public int getWidth() { - return width.calculatedSize(); - } - - public int getHeight() { - return height.calculatedSize(); - } - - protected final void setClippingRect(Rectangle clippingRect) { - if (clippingRect == null) { - RenderSystem.disableScissor(); - return; - } - final double uiScale = Minecraft.getInstance().getWindow().getGuiScale(); - final int windowHeight = Minecraft.getInstance().getWindow().getHeight(); - RenderSystem.enableScissor( - (int) (clippingRect.left * uiScale), - (int) (windowHeight - (clippingRect.bottom()) * uiScale), - (int) (clippingRect.width * uiScale), - (int) ((clippingRect.height) * uiScale) - ); - } - - public void render( - PoseStack poseStack, - int mouseX, - int mouseY, - float deltaTicks, - Rectangle parentBounds, - Rectangle clipRect - ) { - Rectangle r = relativeBounds.movedBy(parentBounds.left, parentBounds.top); - Rectangle clip = r.intersect(clipRect); - poseStack.pushPose(); - poseStack.translate(relativeBounds.left, relativeBounds.top, 0); - //if (r.overlaps(clip)) - { - renderInBounds(poseStack, mouseX - relativeBounds.left, mouseY - relativeBounds.top, deltaTicks, r, clip); - } - poseStack.popPose(); - } - - protected void renderInBounds( - PoseStack poseStack, - int mouseX, - int mouseY, - float deltaTicks, - Rectangle renderBounds, - Rectangle clipRect - ) { - if (renderer != null) { - setClippingRect(clipRect); - renderer.renderInBounds(poseStack, mouseX, mouseY, deltaTicks, renderBounds, clipRect); - setClippingRect(null); - } - } - - @Override - public String toString() { - return super.toString() + "(" + - (debugName == null ? "" : debugName + " - ") + - relativeBounds + ", " + - width.calculatedSize() + "x" + height.calculatedSize() + - ")"; - } - - public L alignTop() { - vAlign = Alignment.MIN; - return (L) this; - } - - public L alignBottom() { - vAlign = Alignment.MAX; - return (L) this; - } - - public L centerVertical() { - vAlign = Alignment.CENTER; - return (L) this; - } - - public L alignLeft() { - hAlign = Alignment.MIN; - return (L) this; - } - - public L alignRight() { - hAlign = Alignment.MAX; - return (L) this; - } - - public L centerHorizontal() { - hAlign = Alignment.CENTER; - return (L) this; - } - - public L setDebugName(String d) { - debugName = d; - return (L) this; - } - - @Override - public boolean isMouseOver(double d, double e) { - return relativeBounds.contains(d, e); - } -} diff --git a/src/main/java/org/betterx/ui/layout/components/MultiLineText.java b/src/main/java/org/betterx/ui/layout/components/MultiLineText.java deleted file mode 100644 index 0f63d4d6..00000000 --- a/src/main/java/org/betterx/ui/layout/components/MultiLineText.java +++ /dev/null @@ -1,180 +0,0 @@ -package org.betterx.ui.layout.components; - -import org.betterx.ui.ColorUtil; -import org.betterx.ui.layout.components.render.ComponentRenderer; -import org.betterx.ui.layout.components.render.TextProvider; -import org.betterx.ui.layout.values.Alignment; -import org.betterx.ui.layout.values.Rectangle; -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; -import net.minecraft.network.chat.MutableComponent; -import net.minecraft.network.chat.Style; -import net.minecraft.util.FormattedCharSequence; - -import com.google.common.collect.ImmutableList; - -import java.util.Iterator; -import java.util.List; - -record LineWithWidth(FormattedCharSequence text, int width) { -} - -public class MultiLineText extends LayoutComponent { - net.minecraft.network.chat.Component text; - int color = ColorUtil.DEFAULT_TEXT; - protected MultiLineLabel multiLineLabel; - int bufferedContentWidth = 0; - List lines = List.of(); - - public MultiLineText( - Value width, - Value height, - final net.minecraft.network.chat.Component text - ) { - super(width, height, new MultiLineTextRenderer()); - renderer.linkedComponent = this; - this.text = text; - updatedContentWidth(); - } - - public MultiLineText setColor(int cl) { - this.color = cl; - return this; - } - - public static Component parse(Component text) { - String[] parts = text.getString().split("\\*\\*"); - if (parts.length > 0) { - boolean bold = false; - MutableComponent c = Component.literal(parts[0]); - - for (int i = 1; i < parts.length; i++) { - bold = !bold; - c.append(Component.literal(parts[i]).setStyle(Style.EMPTY.withBold(bold))); - } - return c; - } - return text; - } - - public MultiLineText setText(Component text) { - this.text = text; - this.updatedContentWidth(); - - if (multiLineLabel != null) { - multiLineLabel = createVanillaComponent(); - } - - return this; - } - - protected MultiLineLabel createVanillaComponent() { - final int wd = relativeBounds == null ? width.calculatedSize() : relativeBounds.width; - lines = renderer.getFont() - .split(text, wd) - .stream() - .map((component) -> new LineWithWidth(component, renderer.getFont().width(component))) - .collect(ImmutableList.toImmutableList()); - - return MultiLineLabel.create(renderer.getFont(), text, wd); - } - - 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 - protected void onBoundsChanged() { - super.onBoundsChanged(); - multiLineLabel = createVanillaComponent(); - } - - @Override - public int getContentWidth() { - return bufferedContentWidth; - } - - @Override - public int getContentHeight() { - return renderer.getHeight(text); - } - - 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; - MultiLineLabel ml; - if (linkedComponent.multiLineLabel != null) ml = linkedComponent.multiLineLabel; - else ml = linkedComponent.createVanillaComponent(); - return ml.getLineCount() * getLineHeight(c); - } - - @Override - public void renderInBounds( - PoseStack stack, - int mouseX, - int mouseY, - float deltaTicks, - Rectangle bounds, - Rectangle clipRect - ) { - if (linkedComponent != null && linkedComponent.multiLineLabel != null) { - int top = bounds.height - getHeight(linkedComponent.text); - if (linkedComponent.vAlign == Alignment.MIN) top = 0; - if (linkedComponent.vAlign == Alignment.CENTER) top /= 2; - - if (linkedComponent.hAlign == Alignment.CENTER) { - linkedComponent.multiLineLabel.renderCentered( - stack, bounds.width / 2, top, - getLineHeight(linkedComponent.text), - linkedComponent.color - ); - } else if (linkedComponent.hAlign == Alignment.MAX) { - int lineY = 0; - int lineHeight = getLineHeight(linkedComponent.text); - - for (Iterator iter = linkedComponent.lines.iterator(); iter.hasNext(); lineY += lineHeight) { - LineWithWidth textWithWidth = iter.next(); - getFont().drawShadow( - stack, - textWithWidth.text(), - linkedComponent.width.calculatedSize() - textWithWidth.width(), - lineY, - linkedComponent.color - ); - } - } else { - linkedComponent.multiLineLabel.renderLeftAligned( - stack, 0, top, - getLineHeight(linkedComponent.text), - linkedComponent.color - ); - } - } - } - } - - @Override - public boolean isMouseOver(double d, double e) { - return false; - } -} diff --git a/src/main/java/org/betterx/ui/layout/components/Panel.java b/src/main/java/org/betterx/ui/layout/components/Panel.java deleted file mode 100644 index f22c10fe..00000000 --- a/src/main/java/org/betterx/ui/layout/components/Panel.java +++ /dev/null @@ -1,108 +0,0 @@ -package org.betterx.ui.layout.components; - - -import org.betterx.ui.layout.components.input.RelativeContainerEventHandler; -import org.betterx.ui.layout.values.Rectangle; - -import com.mojang.blaze3d.vertex.PoseStack; -import net.minecraft.client.gui.components.Renderable; -import net.minecraft.client.gui.components.events.GuiEventListener; -import net.minecraft.client.gui.narration.NarratableEntry; -import net.minecraft.client.gui.narration.NarrationElementOutput; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; - -import java.util.List; -import org.jetbrains.annotations.Nullable; - -@Environment(EnvType.CLIENT) -public class Panel implements ComponentWithBounds, RelativeContainerEventHandler, NarratableEntry, Renderable { - protected LayoutComponent child; - List listeners = List.of(); - public final Rectangle bounds; - - public Panel(int width, int height) { - this(0, 0, width, height); - } - - public Panel(int left, int top, int width, int height) { - bounds = new Rectangle(left, top, width, height); - } - - public void setChild(LayoutComponent c) { - this.child = c; - listeners = List.of(c); - } - - public void calculateLayout() { - if (child != null) { - child.updateContainerWidth(bounds.width); - child.updateContainerHeight(bounds.height); - child.setRelativeBounds(0, 0); - child.updateScreenBounds(bounds.left, bounds.top); - } - } - - @Override - public Rectangle getRelativeBounds() { - return bounds; - } - - @Override - public List children() { - return listeners; - } - - @Override - public Rectangle getInputBounds() { - return bounds; - } - - boolean dragging = false; - - @Override - public boolean isDragging() { - return dragging; - } - - @Override - public void setDragging(boolean bl) { - dragging = bl; - } - - GuiEventListener focused; - - @Nullable - @Override - public GuiEventListener getFocused() { - return focused; - } - - @Override - public void setFocused(@Nullable GuiEventListener guiEventListener) { - focused = guiEventListener; - } - - @Override - public NarrationPriority narrationPriority() { - return NarrationPriority.NONE; - } - - @Override - public void updateNarration(NarrationElementOutput narrationElementOutput) { - - } - - @Override - public void render(PoseStack poseStack, int mouseX, int mouseY, float deltaTicks) { - if (child != null) { - poseStack.pushPose(); - poseStack.translate(bounds.left, bounds.top, 0); - child.render(poseStack, mouseX - bounds.left, mouseY - bounds.top, deltaTicks, bounds, bounds); - poseStack.popPose(); - } - } - - -} diff --git a/src/main/java/org/betterx/ui/layout/components/Range.java b/src/main/java/org/betterx/ui/layout/components/Range.java deleted file mode 100644 index c80d430b..00000000 --- a/src/main/java/org/betterx/ui/layout/components/Range.java +++ /dev/null @@ -1,92 +0,0 @@ -package org.betterx.ui.layout.components; - -import org.betterx.ui.layout.components.render.RangeRenderer; -import org.betterx.ui.layout.values.Value; -import org.betterx.ui.vanilla.Slider; - -import net.minecraft.network.chat.Component; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; - -@Environment(EnvType.CLIENT) -public class Range extends AbstractVanillaComponent, Range> { - @FunctionalInterface - public interface ValueChanged { - void now(Range range, N newValue); - } - - private ValueChanged onChange; - private final N minValue; - private final N maxValue; - private final N initialValue; - - public Range( - Value width, - Value height, - Component component, - N minValue, - N maxValue, - N initialValue - ) { - super(width, height, new RangeRenderer<>(), component); - this.onChange = (a, b) -> { - }; - this.minValue = minValue; - this.maxValue = maxValue; - this.initialValue = initialValue; - } - - public Range( - Value width, - Value height, - N minValue, - N maxValue, - N initialValue - ) { - this(width, height, null, minValue, maxValue, initialValue); - } - - public Range onChange(ValueChanged onChange) { - this.onChange = onChange; - return this; - } - - @Override - protected Slider createVanillaComponent() { - Range self = this; - return new Slider<>( - 0, - 0, - relativeBounds.width, - relativeBounds.height, - component, - minValue, - maxValue, - initialValue, - (s, v) -> onChange.now(self, v) - ); - } - - public N getValue() { - return vanillaComponent.currentValue(); - } - - - @Override - protected Component contentComponent() { - Slider dummy = new Slider<>( - 0, - 0, - 100, - 20, - component, - minValue, - maxValue, - initialValue, - (a, b) -> { - } - ); - return dummy.getValueComponent(maxValue); - } -} diff --git a/src/main/java/org/betterx/ui/layout/components/Tabs.java b/src/main/java/org/betterx/ui/layout/components/Tabs.java deleted file mode 100644 index ec5af1b0..00000000 --- a/src/main/java/org/betterx/ui/layout/components/Tabs.java +++ /dev/null @@ -1,158 +0,0 @@ -package org.betterx.ui.layout.components; - -import org.betterx.ui.layout.values.Value; - -import net.minecraft.network.chat.Component; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; - -import java.util.LinkedList; -import java.util.List; - -@Environment(EnvType.CLIENT) -public class Tabs extends AbstractVerticalStack { - @FunctionalInterface - public interface OnPageChange { - void now(Tabs tabs, int pageIndex); - } - - private final HorizontalStack buttons; - private final Container content; - - private final List pageList = new LinkedList<>(); - private final List