aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorJuuxel <6596629+Juuxel@users.noreply.github.com>2021-02-02 18:55:17 +0200
committerJuuxel <6596629+Juuxel@users.noreply.github.com>2021-02-27 17:32:42 +0200
commit4580f57836642af7b0d2d99431923ccd6477e0ca (patch)
treeeb4a254043ec09aa5e2a6a800c1958de34ab7a14 /src/main
parent55797f31d267ed88b87621105b910406adc7507a (diff)
downloadLibGui-4580f57836642af7b0d2d99431923ccd6477e0ca.tar.gz
LibGui-4580f57836642af7b0d2d99431923ccd6477e0ca.tar.bz2
LibGui-4580f57836642af7b0d2d99431923ccd6477e0ca.zip
Add button dark mode
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java16
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java7
-rw-r--r--src/main/resources/assets/libgui/textures/widget/dark_widgets.pngbin0 -> 5798 bytes
3 files changed, 17 insertions, 6 deletions
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
index 3b5e4de..db1660b 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java
@@ -10,13 +10,17 @@ import net.minecraft.client.sound.PositionedSoundInstance;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
+import net.minecraft.util.Identifier;
+import io.github.cottonmc.cotton.gui.client.LibGui;
import io.github.cottonmc.cotton.gui.client.ScreenDrawing;
import io.github.cottonmc.cotton.gui.widget.data.HorizontalAlignment;
import io.github.cottonmc.cotton.gui.widget.icon.Icon;
import org.jetbrains.annotations.Nullable;
public class WButton extends WWidget {
+ private static final Identifier DARK_WIDGETS_LOCATION = new Identifier("libgui", "textures/widget/dark_widgets.png");
+
private Text label;
protected int color = WLabel.DEFAULT_TEXT_COLOR;
protected int darkmodeColor = WLabel.DEFAULT_TEXT_COLOR;
@@ -94,9 +98,10 @@ public class WButton extends WWidget {
float buttonHeight = 20*px;
float buttonEndLeft = (200-(getWidth()/2)) * px;
-
- ScreenDrawing.texturedRect(matrices, x, y, getWidth()/2, 20, AbstractButtonWidget.WIDGETS_LOCATION, buttonLeft, buttonTop, buttonLeft+buttonWidth, buttonTop+buttonHeight, 0xFFFFFFFF);
- ScreenDrawing.texturedRect(matrices, x+(getWidth()/2), y, getWidth()/2, 20, AbstractButtonWidget.WIDGETS_LOCATION, buttonEndLeft, buttonTop, 200*px, buttonTop+buttonHeight, 0xFFFFFFFF);
+
+ Identifier texture = getTexture();
+ ScreenDrawing.texturedRect(matrices, x, y, getWidth()/2, 20, texture, buttonLeft, buttonTop, buttonLeft+buttonWidth, buttonTop+buttonHeight, 0xFFFFFFFF);
+ ScreenDrawing.texturedRect(matrices, x+(getWidth()/2), y, getWidth()/2, 20, texture, buttonEndLeft, buttonTop, 200*px, buttonTop+buttonHeight, 0xFFFFFFFF);
if (icon != null) {
icon.paint(matrices, x + 1, y + 1, 16);
@@ -214,4 +219,9 @@ public class WButton extends WWidget {
this.icon = icon;
return this;
}
+
+ @Environment(EnvType.CLIENT)
+ static Identifier getTexture() {
+ return LibGui.isDarkMode() ? DARK_WIDGETS_LOCATION : AbstractButtonWidget.WIDGETS_LOCATION;
+ }
}
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java
index ba5edd4..5403bff 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java
@@ -2,10 +2,10 @@ package io.github.cottonmc.cotton.gui.widget;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
-import net.minecraft.client.gui.widget.AbstractButtonWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.util.math.Vector3f;
import net.minecraft.text.Text;
+import net.minecraft.util.Identifier;
import io.github.cottonmc.cotton.gui.client.ScreenDrawing;
import io.github.cottonmc.cotton.gui.widget.data.Axis;
@@ -207,8 +207,9 @@ public class WLabeledSlider extends WAbstractSlider {
float buttonHeight = 20 * px;
float buttonEndLeft = (200 - halfWidth) * px;
- ScreenDrawing.texturedRect(matrices, x, y, halfWidth, 20, AbstractButtonWidget.WIDGETS_LOCATION, buttonLeft, buttonTop, buttonLeft + buttonWidth, buttonTop + buttonHeight, 0xFFFFFFFF);
- ScreenDrawing.texturedRect(matrices, x + halfWidth, y, halfWidth, 20, AbstractButtonWidget.WIDGETS_LOCATION, buttonEndLeft, buttonTop, 200 * px, buttonTop + buttonHeight, 0xFFFFFFFF);
+ Identifier texture = WButton.getTexture();
+ ScreenDrawing.texturedRect(matrices, x, y, halfWidth, 20, texture, buttonLeft, buttonTop, buttonLeft + buttonWidth, buttonTop + buttonHeight, 0xFFFFFFFF);
+ ScreenDrawing.texturedRect(matrices, x + halfWidth, y, halfWidth, 20, texture, buttonEndLeft, buttonTop, 200 * px, buttonTop + buttonHeight, 0xFFFFFFFF);
}
/**
diff --git a/src/main/resources/assets/libgui/textures/widget/dark_widgets.png b/src/main/resources/assets/libgui/textures/widget/dark_widgets.png
new file mode 100644
index 0000000..8482d76
--- /dev/null
+++ b/src/main/resources/assets/libgui/textures/widget/dark_widgets.png
Binary files differ