diff options
author | Juuxel <6596629+Juuxel@users.noreply.github.com> | 2021-02-27 15:54:45 +0200 |
---|---|---|
committer | Juuxel <6596629+Juuxel@users.noreply.github.com> | 2021-02-27 15:54:45 +0200 |
commit | 554a5877fb12bbfccdbfec2903406675ffc71c31 (patch) | |
tree | 32b589980168b9edc468598c3eaf90065c0ca7a2 | |
parent | 7e1b68e49bcbeb151fd77e9193377e9a360bb7f0 (diff) | |
download | LibGui-554a5877fb12bbfccdbfec2903406675ffc71c31.tar.gz LibGui-554a5877fb12bbfccdbfec2903406675ffc71c31.tar.bz2 LibGui-554a5877fb12bbfccdbfec2903406675ffc71c31.zip |
Replace LibGuiClient.config.darkMode with LibGui.isDarkMode()
15 files changed, 50 insertions, 25 deletions
diff --git a/.editorconfig b/.editorconfig index e8cdad1..7db2d7c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,3 +8,4 @@ insert_final_newline = true [*.java] ij_java_imports_layout = com.mojang.**,net.fabricmc.**,net.minecraft.**,|,*,|,javax.**,java.**,|,$* +ij_java_class_count_to_use_import_on_demand = 1000 diff --git a/src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java b/src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java index b275983..b4d6f94 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java @@ -26,7 +26,7 @@ import net.minecraft.server.world.ServerWorld; import net.minecraft.world.World; import io.github.cottonmc.cotton.gui.client.BackgroundPainter; -import io.github.cottonmc.cotton.gui.client.LibGuiClient; +import io.github.cottonmc.cotton.gui.client.LibGui; import io.github.cottonmc.cotton.gui.networking.NetworkSide; import io.github.cottonmc.cotton.gui.widget.WGridPanel; import io.github.cottonmc.cotton.gui.widget.WLabel; @@ -80,7 +80,7 @@ public class SyncedGuiDescription extends ScreenHandler implements GuiDescriptio } public int getTitleColor() { - return (world.isClient && LibGuiClient.config.darkMode) ? darkTitleColor : titleColor; + return (world.isClient && LibGui.isDarkMode()) ? darkTitleColor : titleColor; } public SyncedGuiDescription setRootPanel(WPanel panel) { diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/BackgroundPainter.java b/src/main/java/io/github/cottonmc/cotton/gui/client/BackgroundPainter.java index f00bf80..8878a60 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/BackgroundPainter.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/BackgroundPainter.java @@ -147,7 +147,7 @@ public interface BackgroundPainter { */ public static BackgroundPainter createLightDarkVariants(BackgroundPainter light, BackgroundPainter dark) { return (left, top, panel) -> { - if (LibGuiClient.config.darkMode) dark.paintBackground(left, top, panel); + if (LibGui.isDarkMode()) dark.paintBackground(left, top, panel); else light.paintBackground(left, top, panel); }; } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/LibGui.java b/src/main/java/io/github/cottonmc/cotton/gui/client/LibGui.java new file mode 100644 index 0000000..4be9c29 --- /dev/null +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/LibGui.java @@ -0,0 +1,20 @@ +package io.github.cottonmc.cotton.gui.client; + +/** + * This class provides access to LibGui configuration and other global data. + * + * @since 3.4.0 + */ +public final class LibGui { + private LibGui() { + } + + /** + * Returns whether LibGui is running in dark mode and widgets should use dark theming. + * + * @return true if widgets should use dark theming, false otherwise + */ + public static boolean isDarkMode() { + return LibGuiClient.config.darkMode; + } +} diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/LibGuiClient.java b/src/main/java/io/github/cottonmc/cotton/gui/client/LibGuiClient.java index 80fa414..3c1f72f 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/LibGuiClient.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/LibGuiClient.java @@ -13,14 +13,18 @@ import io.github.cottonmc.cotton.gui.impl.ScreenNetworkingImpl; import io.github.cottonmc.jankson.JanksonFactory; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.jetbrains.annotations.ApiStatus; import java.io.File; import java.io.FileOutputStream; import java.nio.charset.StandardCharsets; +@ApiStatus.Internal public class LibGuiClient implements ClientModInitializer { public static final Logger logger = LogManager.getLogger(); public static final String MODID = "libgui"; + /** @deprecated Replaced with {@link LibGui} */ + @Deprecated public static volatile LibGuiConfig config; public static final Jankson jankson = JanksonFactory.createJankson(); diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/LightweightGuiDescription.java b/src/main/java/io/github/cottonmc/cotton/gui/client/LightweightGuiDescription.java index 41b8d49..54ae02f 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/LightweightGuiDescription.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/LightweightGuiDescription.java @@ -32,7 +32,7 @@ public class LightweightGuiDescription implements GuiDescription { @Override public int getTitleColor() { - return (LibGuiClient.config.darkMode) ? darkmodeTitleColor : titleColor; + return (LibGui.isDarkMode()) ? darkmodeTitleColor : titleColor; } @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 f31a046..410840d 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 @@ -262,7 +262,7 @@ public class ScreenDrawing { * @param height the height of the panel */ public static void drawGuiPanel(int x, int y, int width, int height) { - if (LibGuiClient.config.darkMode) drawGuiPanel(x, y, width, height, 0xFF0B0B0B, 0xFF2F2F2F, 0xFF414141, 0xFF000000); + if (LibGui.isDarkMode()) drawGuiPanel(x, y, width, height, 0xFF0B0B0B, 0xFF2F2F2F, 0xFF414141, 0xFF000000); else drawGuiPanel(x, y, width, height, 0xFF555555, 0xFFC6C6C6, 0xFFFFFFFF, 0xFF000000); } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/WKirbSprite.java b/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/WKirbSprite.java index 74d5357..f0300b1 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/WKirbSprite.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/WKirbSprite.java @@ -5,7 +5,7 @@ import net.fabricmc.api.Environment; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.Identifier; -import io.github.cottonmc.cotton.gui.client.LibGuiClient; +import io.github.cottonmc.cotton.gui.client.LibGui; import io.github.cottonmc.cotton.gui.client.ScreenDrawing; import io.github.cottonmc.cotton.gui.widget.WWidget; @@ -30,7 +30,7 @@ public class WKirbSprite extends WWidget { private long lastFrame; public WKirbSprite() { - state = (LibGuiClient.config.darkMode) ? State.ASLEEP : State.AWAKE; + state = (LibGui.isDarkMode()) ? State.ASLEEP : State.AWAKE; } public void schedule(int[] frames) { @@ -60,7 +60,7 @@ public class WKirbSprite extends WWidget { if (pendingFrames.isEmpty()) { - if (LibGuiClient.config.darkMode) { + if (LibGui.isDarkMode()) { switch(state) { case AWAKE: state = State.FALLING_ASLEEP; diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WDynamicLabel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WDynamicLabel.java index 0412b83..6099022 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WDynamicLabel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WDynamicLabel.java @@ -4,7 +4,7 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.util.math.MatrixStack; -import io.github.cottonmc.cotton.gui.client.LibGuiClient; +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; @@ -40,7 +40,7 @@ public class WDynamicLabel extends WWidget { @Override public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { String tr = text.get(); - ScreenDrawing.drawString(matrices, tr, alignment, x, y, this.getWidth(), LibGuiClient.config.darkMode ? darkmodeColor : color); + ScreenDrawing.drawString(matrices, tr, alignment, x, y, this.getWidth(), LibGui.isDarkMode() ? darkmodeColor : color); } @Override diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java index 0bdf81a..1fc6018 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java @@ -10,7 +10,7 @@ import net.minecraft.text.LiteralText; import net.minecraft.text.Style; import net.minecraft.text.Text; -import io.github.cottonmc.cotton.gui.client.LibGuiClient; +import io.github.cottonmc.cotton.gui.client.LibGui; import io.github.cottonmc.cotton.gui.client.ScreenDrawing; import io.github.cottonmc.cotton.gui.client.TextHoverRendererScreen; import io.github.cottonmc.cotton.gui.widget.data.HorizontalAlignment; @@ -98,7 +98,7 @@ public class WLabel extends WWidget { break; } - ScreenDrawing.drawString(matrices, text.asOrderedText(), horizontalAlignment, x, y + yOffset, this.getWidth(), LibGuiClient.config.darkMode ? darkmodeColor : color); + ScreenDrawing.drawString(matrices, text.asOrderedText(), horizontalAlignment, x, y + yOffset, this.getWidth(), LibGui.isDarkMode() ? darkmodeColor : color); Style hoveredTextStyle = getTextStyleAt(mouseX, mouseY); if (hoveredTextStyle != null) { diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java index 500f312..812b5fe 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java @@ -4,7 +4,7 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.util.math.MatrixStack; -import io.github.cottonmc.cotton.gui.client.LibGuiClient; +import io.github.cottonmc.cotton.gui.client.LibGui; import io.github.cottonmc.cotton.gui.client.ScreenDrawing; import io.github.cottonmc.cotton.gui.widget.data.Axis; @@ -36,7 +36,7 @@ public class WScrollBar extends WWidget { @Environment(EnvType.CLIENT) @Override public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { - if (LibGuiClient.config.darkMode) { + if (LibGui.isDarkMode()) { ScreenDrawing.drawBeveledPanel(x, y, width, height, 0xFF_212121, 0xFF_2F2F2F, 0xFF_5D5D5D); } else { ScreenDrawing.drawBeveledPanel(x, y, width, height, 0xFF_373737, 0xFF_8B8B8B, 0xFF_FFFFFF); @@ -47,7 +47,7 @@ public class WScrollBar extends WWidget { int top, middle, bottom; if (sliding) { - if (LibGuiClient.config.darkMode) { + if (LibGui.isDarkMode()) { top = 0xFF_6C6C6C; middle = 0xFF_2F2F2F; bottom = 0xFF_212121; @@ -57,7 +57,7 @@ public class WScrollBar extends WWidget { bottom = 0xFF_555555; } } else if (isWithinBounds(mouseX, mouseY)) { - if (LibGuiClient.config.darkMode) { + if (LibGui.isDarkMode()) { top = 0xFF_5F6A9D; middle = 0xFF_323F6E; bottom = 0xFF_0B204A; @@ -67,7 +67,7 @@ public class WScrollBar extends WWidget { bottom = 0xFF_343E75; } } else { - if (LibGuiClient.config.darkMode) { + if (LibGui.isDarkMode()) { top = 0xFF_6C6C6C; middle = 0xFF_414141; bottom = 0xFF_212121; diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WSlider.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WSlider.java index 0e78333..6638fb7 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WSlider.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WSlider.java @@ -6,7 +6,7 @@ import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.Identifier; import io.github.cottonmc.cotton.gui.client.BackgroundPainter; -import io.github.cottonmc.cotton.gui.client.LibGuiClient; +import io.github.cottonmc.cotton.gui.client.LibGui; import io.github.cottonmc.cotton.gui.client.ScreenDrawing; import io.github.cottonmc.cotton.gui.widget.data.Axis; import org.jetbrains.annotations.Nullable; @@ -57,7 +57,7 @@ public class WSlider extends WAbstractSlider { int thumbX, thumbY; // thumbXOffset: thumb texture x offset in pixels int thumbXOffset; - Identifier texture = LibGuiClient.config.darkMode ? DARK_TEXTURE : LIGHT_TEXTURE; + Identifier texture = LibGui.isDarkMode() ? DARK_TEXTURE : LIGHT_TEXTURE; if (axis == Axis.VERTICAL) { int trackX = x + width / 2 - TRACK_WIDTH / 2; diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WTabPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WTabPanel.java index efb71d5..bc3a742 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WTabPanel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WTabPanel.java @@ -11,7 +11,7 @@ import net.minecraft.text.Text; import net.minecraft.util.Identifier; import io.github.cottonmc.cotton.gui.client.BackgroundPainter; -import io.github.cottonmc.cotton.gui.client.LibGuiClient; +import io.github.cottonmc.cotton.gui.client.LibGui; import io.github.cottonmc.cotton.gui.client.ScreenDrawing; import io.github.cottonmc.cotton.gui.widget.data.Axis; import io.github.cottonmc.cotton.gui.widget.data.HorizontalAlignment; @@ -338,7 +338,7 @@ public class WTabPanel extends WPanel { HorizontalAlignment align = (icon != null) ? HorizontalAlignment.LEFT : HorizontalAlignment.CENTER; int color; - if (LibGuiClient.config.darkMode) { + if (LibGui.isDarkMode()) { color = WLabel.DEFAULT_DARKMODE_TEXT_COLOR; } else { color = selected ? WLabel.DEFAULT_TEXT_COLOR : 0xEEEEEE; diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WText.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WText.java index 953f995..4ce4440 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WText.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WText.java @@ -10,7 +10,7 @@ import net.minecraft.text.OrderedText; import net.minecraft.text.Style; import net.minecraft.text.Text; -import io.github.cottonmc.cotton.gui.client.LibGuiClient; +import io.github.cottonmc.cotton.gui.client.LibGui; import io.github.cottonmc.cotton.gui.client.ScreenDrawing; import io.github.cottonmc.cotton.gui.client.TextHoverRendererScreen; import io.github.cottonmc.cotton.gui.widget.data.HorizontalAlignment; @@ -109,7 +109,7 @@ public class WText extends WWidget { for (int i = 0; i < wrappedLines.size(); i++) { OrderedText line = wrappedLines.get(i); - int c = LibGuiClient.config.darkMode ? darkmodeColor : color; + int c = LibGui.isDarkMode() ? darkmodeColor : color; ScreenDrawing.drawString(matrices, line, horizontalAlignment, x, y + yOffset + i * font.fontHeight, width, c); } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WToggleButton.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WToggleButton.java index 1142928..1a88ece 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WToggleButton.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WToggleButton.java @@ -9,7 +9,7 @@ import net.minecraft.sound.SoundEvents; import net.minecraft.text.Text; import net.minecraft.util.Identifier; -import io.github.cottonmc.cotton.gui.client.LibGuiClient; +import io.github.cottonmc.cotton.gui.client.LibGui; import io.github.cottonmc.cotton.gui.client.ScreenDrawing; import io.github.cottonmc.cotton.gui.widget.data.Texture; import org.jetbrains.annotations.Nullable; @@ -107,7 +107,7 @@ public class WToggleButton extends WWidget { } if (label!=null) { - ScreenDrawing.drawString(matrices, label.asOrderedText(), x + 22, y+6, LibGuiClient.config.darkMode ? darkmodeColor : color); + ScreenDrawing.drawString(matrices, label.asOrderedText(), x + 22, y+6, LibGui.isDarkMode() ? darkmodeColor : color); } } |