diff options
author | Falkreon <falkreon@gmail.com> | 2019-07-21 23:41:58 -0500 |
---|---|---|
committer | Falkreon <falkreon@gmail.com> | 2019-07-21 23:41:58 -0500 |
commit | a012d6ead79afa2eda1c8ad9dd1c22bf8d40aa40 (patch) | |
tree | acd4da8fa2f0cd29d42e6c201202147fa2b94920 /src | |
parent | 82a62cf0c992bb0390814a1d12569fa7f05dfcd9 (diff) | |
download | LibGui-a012d6ead79afa2eda1c8ad9dd1c22bf8d40aa40.tar.gz LibGui-a012d6ead79afa2eda1c8ad9dd1c22bf8d40aa40.tar.bz2 LibGui-a012d6ead79afa2eda1c8ad9dd1c22bf8d40aa40.zip |
Get clientside guis running, stub out config gui
Diffstat (limited to 'src')
7 files changed, 221 insertions, 4 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/GuiDescription.java b/src/main/java/io/github/cottonmc/cotton/gui/GuiDescription.java new file mode 100644 index 0000000..642e329 --- /dev/null +++ b/src/main/java/io/github/cottonmc/cotton/gui/GuiDescription.java @@ -0,0 +1,28 @@ +package io.github.cottonmc.cotton.gui; + +import javax.annotation.Nullable; + +import io.github.cottonmc.cotton.gui.widget.WPanel; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.container.PropertyDelegate; + +public interface GuiDescription { + public WPanel getRootPanel(); + public int getTitleColor(); + + public GuiDescription setRootPanel(WPanel panel); + public GuiDescription setTitleColor(int color); + public GuiDescription setPropertyDelegate(PropertyDelegate delegate); + public void addSlotPeer(ValidatedSlot slot); + + @Environment(EnvType.CLIENT) + public void addPainters(); + + + + + @Nullable + public PropertyDelegate getPropertyDelegate(); + +} diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/ClientCottonScreen.java b/src/main/java/io/github/cottonmc/cotton/gui/client/ClientCottonScreen.java new file mode 100644 index 0000000..b47f8db --- /dev/null +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/ClientCottonScreen.java @@ -0,0 +1,83 @@ +package io.github.cottonmc.cotton.gui.client; + +import io.github.cottonmc.cotton.gui.GuiDescription; +import io.github.cottonmc.cotton.gui.widget.WPanel; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.text.LiteralText; +import net.minecraft.text.Text; + +public class ClientCottonScreen extends Screen { + protected GuiDescription description; + protected int left = 0; + protected int top = 0; + protected int containerWidth = 0; + protected int containerHeight = 0; + + public ClientCottonScreen(GuiDescription description) { + super(new LiteralText("")); + this.description = description; + } + + public ClientCottonScreen(Text title, GuiDescription description) { + super(title); + this.description = description; + } + + public GuiDescription getDescription() { + return description; + } + + + @Override + public void init(MinecraftClient client, int screenWidth, int screenHeight) { + + super.init(client, screenWidth, screenHeight); + + + reposition(screenWidth, screenHeight); + } + + @Override + public void resize(MinecraftClient client, int screenWidth, int screenHeight) { + reposition(screenWidth, screenHeight); + } + + public void reposition(int screenWidth, int screenHeight) { + if (description!=null) { + WPanel root = description.getRootPanel(); + if (root!=null) { + this.containerWidth = root.getWidth(); + this.containerHeight = root.getHeight(); + + this.left = (screenWidth - root.getWidth()) / 2; + this.top = (screenHeight - root.getHeight()) / 2; + } + } + } + + @Override + public void render(int int_1, int int_2, float float_1) { + renderBackground(); + + super.render(int_1, int_2, float_1); + } + + @Override + public void renderBackground() { + super.renderBackground(); + + if (description!=null) { + WPanel root = description.getRootPanel(); + if (root!=null) { + root.paintBackground(left, top); + } + } + } + + + @Override + public void tick() { + super.tick(); + } +} diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/LibGuiClient.java b/src/main/java/io/github/cottonmc/cotton/gui/client/LibGuiClient.java index ea24bf4..8666832 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/LibGuiClient.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/LibGuiClient.java @@ -14,7 +14,7 @@ import java.io.FileOutputStream; public class LibGuiClient implements ClientModInitializer { public static final Logger logger = LogManager.getLogger(); - + public static final String MODID = "libgui"; public static LibGuiConfig config; public static final Jankson jankson = JanksonFactory.createJankson(); diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/LightweightGuiDescription.java b/src/main/java/io/github/cottonmc/cotton/gui/client/LightweightGuiDescription.java new file mode 100644 index 0000000..c253cf1 --- /dev/null +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/LightweightGuiDescription.java @@ -0,0 +1,67 @@ +package io.github.cottonmc.cotton.gui.client; + +import javax.annotation.Nullable; + +import io.github.cottonmc.cotton.gui.GuiDescription; +import io.github.cottonmc.cotton.gui.ValidatedSlot; +import io.github.cottonmc.cotton.gui.widget.WGridPanel; +import io.github.cottonmc.cotton.gui.widget.WLabel; +import io.github.cottonmc.cotton.gui.widget.WPanel; +import net.minecraft.container.PropertyDelegate; + +/** + * A GuiDescription without any associated Minecraft classes + */ +public class LightweightGuiDescription implements GuiDescription { + protected WPanel rootPanel = new WGridPanel(); + protected int titleColor = WLabel.DEFAULT_TEXT_COLOR; + protected int darkmodeTitleColor = WLabel.DEFAULT_DARKMODE_TEXT_COLOR; + protected PropertyDelegate propertyDelegate; + + @Override + public WPanel getRootPanel() { + return rootPanel; + } + + @Override + public int getTitleColor() { + return titleColor; + } + + @Override + public GuiDescription setRootPanel(WPanel panel) { + this.rootPanel = panel; + return this; + } + + @Override + public GuiDescription setTitleColor(int color) { + this.titleColor = color; + return this; + } + + @Override + public void addPainters() { + if (this.rootPanel!=null) { + this.rootPanel.setBackgroundPainter(BackgroundPainter.VANILLA); + } + } + + @Override + public void addSlotPeer(ValidatedSlot slot) { + //NO-OP + } + + @Override + @Nullable + public PropertyDelegate getPropertyDelegate() { + return propertyDelegate; + } + + @Override + public GuiDescription setPropertyDelegate(PropertyDelegate delegate) { + this.propertyDelegate = delegate; + return this; + } + +} diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ConfigGui.java b/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ConfigGui.java new file mode 100644 index 0000000..cb130eb --- /dev/null +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ConfigGui.java @@ -0,0 +1,19 @@ +package io.github.cottonmc.cotton.gui.client.modmenu; + +import io.github.cottonmc.cotton.gui.client.BackgroundPainter; +import io.github.cottonmc.cotton.gui.client.LightweightGuiDescription; +import io.github.cottonmc.cotton.gui.widget.WGridPanel; +import io.github.cottonmc.cotton.gui.widget.WSprite; +import net.minecraft.util.Identifier; + +public class ConfigGui extends LightweightGuiDescription { + + public ConfigGui() { + WGridPanel root = new WGridPanel(); + setRootPanel(root); + + root.add(new WSprite(new Identifier("libgui:icon.png")), 0, 0, 2, 2); + root.setBackgroundPainter(BackgroundPainter.VANILLA); + root.setSize(64, 64); + } +} diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ModMenuSupport.java b/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ModMenuSupport.java new file mode 100644 index 0000000..e7d4590 --- /dev/null +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ModMenuSupport.java @@ -0,0 +1,21 @@ +package io.github.cottonmc.cotton.gui.client.modmenu; + +import java.util.function.Function; + +import io.github.cottonmc.cotton.gui.client.ClientCottonScreen; +import io.github.cottonmc.cotton.gui.client.LibGuiClient; +import io.github.prospector.modmenu.api.ModMenuApi; +import net.minecraft.client.gui.screen.Screen; + +public class ModMenuSupport implements ModMenuApi { + + @Override + public String getModId() { + return LibGuiClient.MODID; + } + + @Override + public Function<Screen, ? extends Screen> getConfigScreenFactory() { + return screen -> new ClientCottonScreen(new ConfigGui()); + } +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 05faf69..1fccb86 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -17,9 +17,8 @@ "environment": "*", "entrypoints": { - "client": [ - "io.github.cottonmc.cotton.gui.client.LibGuiClient" - ] + "client": [ "io.github.cottonmc.cotton.gui.client.LibGuiClient" ], + "modmenu": [ "io.github.cottonmc.cotton.gui.client.modmenu.ModMenuSupport" ] }, "depends": { "fabricloader": ">=0.4.0", |