diff options
author | Falkreon <falkreon@gmail.com> | 2019-08-28 17:57:00 -0500 |
---|---|---|
committer | Falkreon <falkreon@gmail.com> | 2019-08-28 17:57:00 -0500 |
commit | 40059d3145ac938e3e14eb011a07a405d99e5ffc (patch) | |
tree | ea27df65965d6ebad148bb267ca52e6d07e9b1c4 /GuiTest/src/main/java | |
parent | a9f2dd347f4da78c3740d9e0dddac9739f42d78c (diff) | |
download | LibGui-40059d3145ac938e3e14eb011a07a405d99e5ffc.tar.gz LibGui-40059d3145ac938e3e14eb011a07a405d99e5ffc.tar.bz2 LibGui-40059d3145ac938e3e14eb011a07a405d99e5ffc.zip |
Test gui demo leading to list fixes
Diffstat (limited to 'GuiTest/src/main/java')
-rw-r--r-- | GuiTest/src/main/java/io/github/cottonmc/test/client/TestClientGui.java | 72 |
1 files changed, 62 insertions, 10 deletions
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 index 9bbd1fc..90beffd 100644 --- a/GuiTest/src/main/java/io/github/cottonmc/test/client/TestClientGui.java +++ b/GuiTest/src/main/java/io/github/cottonmc/test/client/TestClientGui.java @@ -3,38 +3,90 @@ package io.github.cottonmc.test.client; import java.util.ArrayList; import java.util.function.BiConsumer; +import io.github.cottonmc.cotton.gui.client.BackgroundPainter; import io.github.cottonmc.cotton.gui.client.LightweightGuiDescription; +import io.github.cottonmc.cotton.gui.client.ScreenDrawing; +import io.github.cottonmc.cotton.gui.widget.WButton; 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.WPlainPanel; +import io.github.cottonmc.cotton.gui.widget.WSprite; import io.github.cottonmc.cotton.gui.widget.WTextField; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.minecraft.text.LiteralText; +import net.minecraft.util.Identifier; public class TestClientGui extends LightweightGuiDescription { + @Environment(EnvType.CLIENT) + public static final BackgroundPainter PANEL = (x, y, panel)->{ + ScreenDrawing.drawBeveledPanel(x, y, panel.getWidth(), panel.getHeight()); + }; + + private static final Identifier PORTAL1 = new Identifier("libgui-test:portal.png"); + private static final Identifier PORTAL2 = new Identifier("libgui-test:portal2.png"); + public TestClientGui() { - WGridPanel root = new WGridPanel(24); + WGridPanel root = new WGridPanel(22); this.setRootPanel(root); WLabel title = new WLabel(new LiteralText("Client Test Gui"), WLabel.DEFAULT_TEXT_COLOR); root.add(title, 0, 0); WTextField text = new WTextField(); - text.setSuggestion("Test Suggestion"); + text.setSuggestion("Search"); root.add(text, 0, 1, 8, 1); - text.setSize(8*18, 20); + text.setSize(7*18, 20); ArrayList<String> data = new ArrayList<>(); - for(int i=0; i<100; i++) { - data.add(""+i); - } + data.add("Wolfram Alpha"); + data.add("Strange Home"); + data.add("Nether Base"); + data.add("Death"); + data.add("Cake"); + data.add("Mushroom Island"); + data.add("A List Item"); + data.add("Notes"); + data.add("Slime Island"); - BiConsumer<String, WLabel> configurator = (String s, WLabel label) -> { - label.setText(new LiteralText(s)); + BiConsumer<String, PortalDestination> configurator = (String s, PortalDestination destination) -> { + destination.label.setText(new LiteralText(s)); + + int hash = s.hashCode(); + Identifier sprite = ((hash & 0x01) == 0) ? PORTAL1 : PORTAL2; + destination.sprite.setImage(sprite); + + int cost = (hash >> 1) & 0x2FF; + destination.cost.setText(new LiteralText(""+cost+" XP")); }; - WListPanel<String, WLabel> list = new WListPanel<String, WLabel>(data, WLabel.class, ()->new WLabel(""), configurator); - root.add(list, 0, 2, 7, 5); + WListPanel<String, PortalDestination> list = new WListPanel<String, PortalDestination>(data, PortalDestination.class, PortalDestination::new, configurator); + list.setListItemHeight(2*18); + root.add(list, 0, 2, 7, 6); + + root.add(new WButton(new LiteralText("Teleport")), 3,8,4,1); root.validate(this); } + + public static class PortalDestination extends WPlainPanel { + WSprite sprite; + WLabel label; + WLabel cost; + + public PortalDestination() { + sprite = new WSprite(new Identifier("libgui-test:portal")); + this.add(sprite, 2, 2, 18, 18); + label = new WLabel("Foo"); + this.add(label, 18+ 4, 2, 5*18, 18); + cost = new WLabel("1000 Xp"); + this.add(cost, 2, 20, 6*18, 18); + + this.setSize(7*18, 2*18); + + this.setBackgroundPainter(PANEL); //Would fail on a serverside gui + } + } } + |