aboutsummaryrefslogtreecommitdiff
path: root/GuiTest/src/main/java/io
diff options
context:
space:
mode:
authorFalkreon <falkreon@gmail.com>2019-08-24 21:17:24 -0500
committerFalkreon <falkreon@gmail.com>2019-08-24 21:17:24 -0500
commit2ae4c11c84ad90031b0fd32e011c49849352bcc5 (patch)
tree303da79f8304110029c32148fd02453e0cc02059 /GuiTest/src/main/java/io
parentd17ec9d9299b7dae2964d7314a60502b56f7e12b (diff)
downloadLibGui-2ae4c11c84ad90031b0fd32e011c49849352bcc5.tar.gz
LibGui-2ae4c11c84ad90031b0fd32e011c49849352bcc5.tar.bz2
LibGui-2ae4c11c84ad90031b0fd32e011c49849352bcc5.zip
Add test project, fix readme, work on list widget
Diffstat (limited to 'GuiTest/src/main/java/io')
-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
4 files changed, 101 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);
+ }
+
+}