From 3f1d1d4e71f1ec3dc59e189e6aad4d99dcf75bd0 Mon Sep 17 00:00:00 2001 From: Falkreon Date: Fri, 27 Sep 2019 16:26:06 -0500 Subject: Implement HSL colors, update jankson --- GuiTest/build.gradle | 9 ++-- GuiTest/gradle.properties | 2 +- .../github/cottonmc/test/client/TestClientGui.java | 63 ++++++++++++++++++++-- GuiTest/src/main/resources/fabric.mod.json | 2 +- 4 files changed, 65 insertions(+), 11 deletions(-) (limited to 'GuiTest') diff --git a/GuiTest/build.gradle b/GuiTest/build.gradle index 1d08396..849cf3e 100644 --- a/GuiTest/build.gradle +++ b/GuiTest/build.gradle @@ -5,7 +5,7 @@ buildscript { } plugins { - id 'fabric-loom' version '0.2.4-SNAPSHOT' + id 'fabric-loom' version '0.2.5-SNAPSHOT' } sourceCompatibility = JavaVersion.VERSION_1_8 @@ -36,13 +36,14 @@ dependencies { mappings "net.fabricmc:yarn:${project.yarn_mappings}" modApi "net.fabricmc:fabric-loader:${project.loader_version}" modApi "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - modApi "io.github.cottonmc:Jankson:${project.jankson_version}" - include "io.github.cottonmc:Jankson:${project.jankson_version}" + modApi "io.github.cottonmc:Jankson-Fabric:${project.jankson_version}" + include "io.github.cottonmc:Jankson-Fabric:${project.jankson_version}" compileOnly ("com.google.code.findbugs:jsr305:3.0.2") { transitive = false } - modApi ("io.github.prospector:modmenu:1.7.10-unstable.19w35a+build.2")// { transitive = false } + //modApi ("io.github.prospector:modmenu:1.7.10-unstable.19w35a+build.2")// { transitive = false } + modCompileOnly "io.github.prospector:modmenu:1.7.10-unstable.19w35a+build.2" //modApi ("io.github.cottonmc:LibGui:1.3.1-SNAPSHOT") { changing = true } compile (project(":LibGUI")) { transitive = false }; runtime (project(":LibGUI")) { transitive = false }; diff --git a/GuiTest/gradle.properties b/GuiTest/gradle.properties index 9ae5f8f..921cf11 100644 --- a/GuiTest/gradle.properties +++ b/GuiTest/gradle.properties @@ -15,4 +15,4 @@ org.gradle.jvmargs=-Xmx1G # Dependencies # currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric fabric_version=0.3.2+build.230-1.15 - jankson_version=1.0.0+j1.1.2 + jankson_version=2.0.0+j1.2.0 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 4c16b81..e1e23d5 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 @@ -12,8 +12,12 @@ 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.WSlider; import io.github.cottonmc.cotton.gui.widget.WSprite; import io.github.cottonmc.cotton.gui.widget.WTextField; +import io.github.cottonmc.cotton.gui.widget.WWidget; +import io.github.cottonmc.cotton.gui.widget.data.Axis; +import io.github.cottonmc.cotton.gui.widget.data.Color; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.text.LiteralText; @@ -26,8 +30,12 @@ public class TestClientGui extends LightweightGuiDescription { ScreenDrawing.drawBeveledPanel(x-1, y-1, panel.getWidth()+2, panel.getHeight()+2); }; - private static final Identifier PORTAL1 = new Identifier("libgui-test:portal.png"); - private static final Identifier PORTAL2 = new Identifier("libgui-test:portal2.png"); + //private static final Identifier PORTAL1 = new Identifier("libgui-test:portal.png"); + //private static final Identifier PORTAL2 = new Identifier("libgui-test:portal2.png"); + + private int r = 0; + private int g = 0; + private int b = 0; public TestClientGui() { WGridPanel root = new WGridPanel(22); @@ -45,7 +53,7 @@ public class TestClientGui extends LightweightGuiDescription { text.setSuggestion("Search"); root.add(text, 0, 1, 8, 1); text.setSize(7*18, 20); - + /* ArrayList data = new ArrayList<>(); data.add("Wolfram Alpha"); data.add("Strange Home"); @@ -72,11 +80,35 @@ public class TestClientGui extends LightweightGuiDescription { list.setBackgroundPainter(PANEL); root.add(list, 0, 2, 7, 6); - root.add(new WButton(new LiteralText("Teleport")), 3,8,4,1); + root.add(new WButton(new LiteralText("Teleport")), 3,8,4,1);*/ + WColorBox col = new WColorBox(); + root.add(col, 3,2,1,3); + + WSlider r = new WSlider(0, 100, Axis.VERTICAL); + root.add(r, 0, 2, 1, 3); + r.setValueChangeListener((i)->{ + this.r = i; + updateCol(col); + System.out.println("h: "+this.r+" s: "+this.g+ " l: "+this.b); + System.out.println("col is now "+Integer.toHexString(col.color)); + }); + WSlider g = new WSlider(0, 100, Axis.VERTICAL); + root.add(g, 1, 2, 1, 3); + g.setValueChangeListener((i)->{ + this.g = i; + updateCol(col); + }); + WSlider b = new WSlider(0, 100, Axis.VERTICAL); + root.add(b, 2, 2, 1, 3); + b.setValueChangeListener((i)->{ + this.b = i; + updateCol(col); + }); + root.validate(this); } - + /* public static class PortalDestination extends WPlainPanel { WSprite sprite; WLabel label; @@ -94,6 +126,27 @@ public class TestClientGui extends LightweightGuiDescription { this.setBackgroundPainter(PANEL); //Would fail on a serverside gui } + }*/ + + private void updateCol(WColorBox col) { + Color.HSL hsl = new Color.HSL(r/100f, g/100f, b/100f); + col.setColor(hsl.toRgb()); + } + + public static class WColorBox extends WWidget { + protected int color = 0xFF_FFFFFF; + public WColorBox() {} + + public void setColor(int col) { + this.color = col; + } + + @Override + public void paintBackground(int x, int y, int mouseX, int mouseY) { + super.paintBackground(x, y, mouseX, mouseY); + + ScreenDrawing.coloredRect(x, y, this.getWidth(), this.getHeight(), color); + } } } diff --git a/GuiTest/src/main/resources/fabric.mod.json b/GuiTest/src/main/resources/fabric.mod.json index df68f07..b514f2b 100644 --- a/GuiTest/src/main/resources/fabric.mod.json +++ b/GuiTest/src/main/resources/fabric.mod.json @@ -23,7 +23,7 @@ "depends": { "fabricloader": ">=0.4.0", "libgui": "*", - "jankson": "1.0.x", + "jankson": "2.x.x", "fabric": "*" } } -- cgit