aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorFalkreon <falkreon@gmail.com>2019-07-22 23:19:29 -0500
committerFalkreon <falkreon@gmail.com>2019-07-22 23:19:29 -0500
commitfc939bb66aa486daa6aee036dc4a91e702a79a77 (patch)
tree6e8747f0131b06956286c0d16869dc839d2eefd6 /src/main/java
parent3608eeab247977e969c37c8942270e0ff2639675 (diff)
downloadLibGui-fc939bb66aa486daa6aee036dc4a91e702a79a77.tar.gz
LibGui-fc939bb66aa486daa6aee036dc4a91e702a79a77.tar.bz2
LibGui-fc939bb66aa486daa6aee036dc4a91e702a79a77.zip
Hastily add buttons and finish config gui
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/ClientCottonScreen.java11
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java6
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ConfigGui.java13
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ModMenuSupport.java2
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java83
5 files changed, 110 insertions, 5 deletions
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
index bf71991..5916c3a 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/client/ClientCottonScreen.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/client/ClientCottonScreen.java
@@ -60,10 +60,17 @@ public class ClientCottonScreen extends Screen {
}
@Override
- public void render(int int_1, int int_2, float float_1) {
+ public void render(int mouseX, int mouseY, float partialTicks) {
renderBackground();
- super.render(int_1, int_2, float_1);
+ super.render(mouseX, mouseY, partialTicks);
+
+ if (description!=null) {
+ WPanel root = description.getRootPanel();
+ if (root!=null) {
+ root.paintForeground(left, top, mouseX, mouseY);
+ }
+ }
}
@Override
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java b/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java
index 0e6df04..dd55eea 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java
@@ -5,6 +5,7 @@ import org.lwjgl.opengl.GL11;
import com.mojang.blaze3d.platform.GlStateManager;
import net.minecraft.client.MinecraftClient;
+import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexFormats;
@@ -199,6 +200,11 @@ public class ScreenDrawing {
public static void drawString(String s, int x, int y, int color) {
MinecraftClient.getInstance().getFontManager().getTextRenderer(MinecraftClient.DEFAULT_TEXT_RENDERER_ID).draw(s, x, y, color);
}
+
+ public static void drawCenteredWithShadow(String s, int x, int y, int color) {
+ TextRenderer render = MinecraftClient.getInstance().getFontManager().getTextRenderer(MinecraftClient.DEFAULT_TEXT_RENDERER_ID);
+ render.drawWithShadow(s, (float)(x - render.getStringWidth(s) / 2), (float)y, color);
+ }
public static void drawTooltip(String s, int x, int y) {
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
index b4202dc..4edf03d 100644
--- 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
@@ -3,13 +3,16 @@ package io.github.cottonmc.cotton.gui.client.modmenu;
import io.github.cottonmc.cotton.gui.client.BackgroundPainter;
import io.github.cottonmc.cotton.gui.client.LibGuiClient;
import io.github.cottonmc.cotton.gui.client.LightweightGuiDescription;
+import io.github.cottonmc.cotton.gui.widget.WButton;
import io.github.cottonmc.cotton.gui.widget.WGridPanel;
import io.github.cottonmc.cotton.gui.widget.WToggleButton;
+import net.minecraft.client.MinecraftClient;
+import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.TranslatableText;
public class ConfigGui extends LightweightGuiDescription {
- public ConfigGui() {
+ public ConfigGui(Screen previous) {
WGridPanel root = new WGridPanel();
setRootPanel(root);
@@ -23,7 +26,13 @@ public class ConfigGui extends LightweightGuiDescription {
darkmodeButton.setToggle(LibGuiClient.config.darkMode);
root.add(darkmodeButton, 0, 2, 6, 1);
- root.add(new WKirbSprite(), 4, 4);
+ root.add(new WKirbSprite(), 5, 4);
+
+ WButton doneButton = new WButton(new TranslatableText("option.libgui.done"));
+ doneButton.setOnClick(()->{
+ MinecraftClient.getInstance().openScreen(previous);
+ });
+ root.add(doneButton, 0, 5, 3, 1);
root.setBackgroundPainter(BackgroundPainter.VANILLA);
root.setSize(7*18, 6*18);
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
index 327ee02..335c093 100644
--- 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
@@ -17,7 +17,7 @@ public class ModMenuSupport implements ModMenuApi {
@Override
public Function<Screen, ? extends Screen> getConfigScreenFactory() {
- return screen -> new ClientCottonScreen(new TranslatableText("options.libgui.libgui_settings"), new ConfigGui()) {
+ return screen -> new ClientCottonScreen(new TranslatableText("options.libgui.libgui_settings"), new ConfigGui(screen)) {
public void onClose() {
this.minecraft.openScreen(screen);
}
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java
new file mode 100644
index 0000000..acb126c
--- /dev/null
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java
@@ -0,0 +1,83 @@
+package io.github.cottonmc.cotton.gui.widget;
+
+import io.github.cottonmc.cotton.gui.client.BackgroundPainter;
+import io.github.cottonmc.cotton.gui.client.LibGuiClient;
+import io.github.cottonmc.cotton.gui.client.ScreenDrawing;
+import net.fabricmc.api.EnvType;
+import net.fabricmc.api.Environment;
+import net.minecraft.client.MinecraftClient;
+import net.minecraft.client.gui.widget.AbstractButtonWidget;
+import net.minecraft.client.sound.PositionedSoundInstance;
+import net.minecraft.sound.SoundEvents;
+import net.minecraft.text.Text;
+
+public class WButton extends WWidget {
+ private Text label;
+ protected int color = WLabel.DEFAULT_TEXT_COLOR;
+ protected int darkmodeColor = WLabel.DEFAULT_TEXT_COLOR;
+
+ private Runnable onClick;
+
+ public WButton() {
+
+ }
+
+ public WButton(Text text) {
+ this.label = text;
+ }
+
+ @Override
+ public boolean canResize() {
+ return true;
+ }
+
+
+ @Override
+ public void paintForeground(int x, int y, int mouseX, int mouseY) {
+ boolean hovered = (mouseX>=x && mouseY>=y && mouseX<x+getWidth() && mouseY<y+getHeight());
+ int int_3 = 1; //1=regular. 2=hovered. 0=disabled.
+ if (hovered) int_3 = 2;
+
+ float px = 1/256f;
+ float buttonLeft = 0 * px;
+ float buttonTop = (46 + (int_3*20)) * px;
+ int halfWidth = getWidth()/2;
+ if (halfWidth>198) halfWidth=198;
+ float buttonWidth = halfWidth*px;
+ float buttonHeight = 20*px;
+
+ float buttonEndLeft = (200-(getWidth()/2)) * px;
+
+ ScreenDrawing.rect(AbstractButtonWidget.WIDGETS_LOCATION, x, y, getWidth()/2, 20, buttonLeft, buttonTop, buttonLeft+buttonWidth, buttonTop+buttonHeight, 0xFFFFFFFF);
+ ScreenDrawing.rect(AbstractButtonWidget.WIDGETS_LOCATION, x+(getWidth()/2), y, getWidth()/2, 20, buttonEndLeft, buttonTop, 200*px, buttonTop+buttonHeight, 0xFFFFFFFF);
+
+ if (label!=null) {
+ boolean active = true;
+ int color = 14737632;
+ if (!active) {
+ color = 10526880;
+ } else if (hovered) {
+ color = 16777120;
+ }
+
+ ScreenDrawing.drawCenteredWithShadow(label.asFormattedString(), x+(getWidth()/2), y+4, color); //LibGuiClient.config.darkMode ? darkmodeColor : color);
+ }
+
+
+ super.paintForeground(x, y, mouseX, mouseY);
+ }
+
+
+ @Override
+ public void onClick(int x, int y, int button) {
+ super.onClick(x, y, button);
+
+ MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F));
+
+ if (onClick!=null) onClick.run();
+ }
+
+ public void setOnClick(Runnable r) {
+ this.onClick = r;
+ }
+}