aboutsummaryrefslogtreecommitdiff
path: root/GuiTest/src
diff options
context:
space:
mode:
Diffstat (limited to 'GuiTest/src')
-rw-r--r--GuiTest/src/main/java/io/github/cottonmc/test/GuiItem.java30
-rw-r--r--GuiTest/src/main/java/io/github/cottonmc/test/LibGuiTest.java17
-rw-r--r--GuiTest/src/main/java/io/github/cottonmc/test/client/LibGuiTestClient.java12
-rw-r--r--GuiTest/src/main/java/io/github/cottonmc/test/client/TestClientGui.java42
-rw-r--r--GuiTest/src/main/resources/assets/libgui-test/icon.pngbin0 -> 5016 bytes
-rw-r--r--GuiTest/src/main/resources/fabric.mod.json29
6 files changed, 130 insertions, 0 deletions
diff --git a/GuiTest/src/main/java/io/github/cottonmc/test/GuiItem.java b/GuiTest/src/main/java/io/github/cottonmc/test/GuiItem.java
new file mode 100644
index 0000000..906ad82
--- /dev/null
+++ b/GuiTest/src/main/java/io/github/cottonmc/test/GuiItem.java
@@ -0,0 +1,30 @@
+package io.github.cottonmc.test;
+
+import io.github.cottonmc.cotton.gui.client.ClientCottonScreen;
+import io.github.cottonmc.test.client.TestClientGui;
+import net.minecraft.client.MinecraftClient;
+import net.minecraft.entity.player.PlayerEntity;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemGroup;
+import net.minecraft.item.ItemStack;
+import net.minecraft.util.ActionResult;
+import net.minecraft.util.Hand;
+import net.minecraft.util.Rarity;
+import net.minecraft.util.TypedActionResult;
+import net.minecraft.world.World;
+
+public class GuiItem extends Item {
+
+ public GuiItem() {
+ super(new Item.Settings().group(ItemGroup.TOOLS).rarity(Rarity.EPIC));
+ }
+
+ @Override
+ public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
+ if (world.isClient) {
+ MinecraftClient.getInstance().openScreen(new ClientCottonScreen(new TestClientGui()));
+ }
+
+ return new TypedActionResult<ItemStack>(ActionResult.SUCCESS, (hand==Hand.MAIN_HAND) ? player.getMainHandStack() : player.getOffHandStack());
+ }
+}
diff --git a/GuiTest/src/main/java/io/github/cottonmc/test/LibGuiTest.java b/GuiTest/src/main/java/io/github/cottonmc/test/LibGuiTest.java
new file mode 100644
index 0000000..e2431c8
--- /dev/null
+++ b/GuiTest/src/main/java/io/github/cottonmc/test/LibGuiTest.java
@@ -0,0 +1,17 @@
+package io.github.cottonmc.test;
+
+import net.fabricmc.api.ModInitializer;
+import net.minecraft.util.Identifier;
+import net.minecraft.util.registry.Registry;
+
+public class LibGuiTest implements ModInitializer {
+ public static final String MODID = "libgui-test";
+
+ @Override
+ public void onInitialize() {
+ //TODO: Register an item that spawns a clientside gui, and a block that spawns a serverside one
+
+ Registry.register(Registry.ITEM, new Identifier(MODID, "client_gui"), new GuiItem());
+ }
+
+}
diff --git a/GuiTest/src/main/java/io/github/cottonmc/test/client/LibGuiTestClient.java b/GuiTest/src/main/java/io/github/cottonmc/test/client/LibGuiTestClient.java
new file mode 100644
index 0000000..42b4b42
--- /dev/null
+++ b/GuiTest/src/main/java/io/github/cottonmc/test/client/LibGuiTestClient.java
@@ -0,0 +1,12 @@
+package io.github.cottonmc.test.client;
+
+import net.fabricmc.api.ClientModInitializer;
+
+public class LibGuiTestClient implements ClientModInitializer {
+
+ @Override
+ public void onInitializeClient() {
+
+ }
+
+}
diff --git a/GuiTest/src/main/java/io/github/cottonmc/test/client/TestClientGui.java b/GuiTest/src/main/java/io/github/cottonmc/test/client/TestClientGui.java
new file mode 100644
index 0000000..73f23b4
--- /dev/null
+++ b/GuiTest/src/main/java/io/github/cottonmc/test/client/TestClientGui.java
@@ -0,0 +1,42 @@
+package io.github.cottonmc.test.client;
+
+import java.util.ArrayList;
+import java.util.function.BiConsumer;
+
+import io.github.cottonmc.cotton.gui.client.LightweightGuiDescription;
+import io.github.cottonmc.cotton.gui.widget.WGridPanel;
+import io.github.cottonmc.cotton.gui.widget.WLabel;
+import io.github.cottonmc.cotton.gui.widget.WListPanel;
+import io.github.cottonmc.cotton.gui.widget.WTextField;
+import net.minecraft.text.LiteralText;
+
+public class TestClientGui extends LightweightGuiDescription {
+
+ public TestClientGui() {
+ WGridPanel root = new WGridPanel();
+ this.setRootPanel(root);
+
+ WTextField text = new WTextField();
+ text.setSuggestion("Test Suggestion");
+ root.add(text, 0, 1, 8, 1);
+
+ ArrayList<String> data = new ArrayList<>();
+ data.add("This");
+ data.add("is");
+ data.add("a");
+ data.add("test");
+ data.add("of the");
+ data.add("new");
+ data.add("recycler-style");
+ data.add("list");
+ data.add("widget");
+ BiConsumer<String, WLabel> configurator = (String s, WLabel label) -> {
+ label.setText(new LiteralText(s));
+ };
+ WListPanel<String, WLabel> list = new WListPanel<String, WLabel>(data, WLabel.class, ()->new WLabel(""), configurator);
+ root.add(list, 0, 2, 8, 8);
+
+ root.validate(this);
+ }
+
+}
diff --git a/GuiTest/src/main/resources/assets/libgui-test/icon.png b/GuiTest/src/main/resources/assets/libgui-test/icon.png
new file mode 100644
index 0000000..4286522
--- /dev/null
+++ b/GuiTest/src/main/resources/assets/libgui-test/icon.png
Binary files differ
diff --git a/GuiTest/src/main/resources/fabric.mod.json b/GuiTest/src/main/resources/fabric.mod.json
new file mode 100644
index 0000000..df68f07
--- /dev/null
+++ b/GuiTest/src/main/resources/fabric.mod.json
@@ -0,0 +1,29 @@
+{
+ "schemaVersion": 1,
+ "id": "libgui-test",
+ "version": "${version}",
+
+ "name": "LibGui Test",
+ "description": "Some example Guis to shake out errors",
+ "authors": [
+ "Falkreon"
+ ],
+ "contact": {
+ "sources": "https://github.com/CottonMC/LibGUI"
+ },
+
+ "license": "MIT",
+ "icon": "assets/libgui-test/icon.png",
+
+ "environment": "*",
+ "entrypoints": {
+ "main": [ "io.github.cottonmc.test.LibGuiTest"],
+ "client": [ "io.github.cottonmc.test.client.LibGuiTestClient" ]
+ },
+ "depends": {
+ "fabricloader": ">=0.4.0",
+ "libgui": "*",
+ "jankson": "1.0.x",
+ "fabric": "*"
+ }
+}