From 68e38117e60197e45963746c9b0fa44f696f420f Mon Sep 17 00:00:00 2001 From: Juuxel <6596629+Juuxel@users.noreply.github.com> Date: Thu, 26 Nov 2020 22:52:34 +0200 Subject: Move modmenu support, nine-patch internals and init code into impl package Also introduced a new LibGui class that provides API access to the dark mode setting now that the config is unavailable publically. --- .../cottonmc/cotton/gui/SyncedGuiDescription.java | 4 +- .../cotton/gui/client/BackgroundPainter.java | 2 +- .../github/cottonmc/cotton/gui/client/LibGui.java | 18 ++++ .../cottonmc/cotton/gui/client/LibGuiClient.java | 69 ------------ .../cottonmc/cotton/gui/client/LibGuiConfig.java | 8 -- .../gui/client/LightweightGuiDescription.java | 2 +- .../cottonmc/cotton/gui/client/NinePatch.java | 104 ++---------------- .../cottonmc/cotton/gui/client/ScreenDrawing.java | 2 +- .../cotton/gui/client/modmenu/ConfigGui.java | 62 ----------- .../cotton/gui/client/modmenu/ModMenuSupport.java | 18 ---- .../cotton/gui/client/modmenu/WKirbSprite.java | 117 --------------------- .../cotton/gui/client/modmenu/package-info.java | 4 - .../cotton/gui/impl/access/package-info.java | 3 + .../cotton/gui/impl/client/LibGuiClient.java | 70 ++++++++++++ .../cotton/gui/impl/client/LibGuiConfig.java | 8 ++ .../cotton/gui/impl/client/NinePatchInternals.java | 103 ++++++++++++++++++ .../cotton/gui/impl/client/modmenu/ConfigGui.java | 62 +++++++++++ .../gui/impl/client/modmenu/ModMenuSupport.java | 18 ++++ .../gui/impl/client/modmenu/WKirbSprite.java | 117 +++++++++++++++++++++ .../gui/impl/client/modmenu/package-info.java | 7 ++ .../cotton/gui/impl/client/package-info.java | 9 ++ .../cottonmc/cotton/gui/impl/package-info.java | 3 + .../cottonmc/cotton/gui/widget/WDynamicLabel.java | 4 +- .../github/cottonmc/cotton/gui/widget/WLabel.java | 6 +- .../cottonmc/cotton/gui/widget/WScrollBar.java | 10 +- .../github/cottonmc/cotton/gui/widget/WSlider.java | 4 +- .../cottonmc/cotton/gui/widget/WTabPanel.java | 4 +- .../github/cottonmc/cotton/gui/widget/WText.java | 4 +- .../cottonmc/cotton/gui/widget/WToggleButton.java | 4 +- src/main/resources/fabric.mod.json | 4 +- 30 files changed, 453 insertions(+), 397 deletions(-) create mode 100644 src/main/java/io/github/cottonmc/cotton/gui/client/LibGui.java delete mode 100644 src/main/java/io/github/cottonmc/cotton/gui/client/LibGuiClient.java delete mode 100644 src/main/java/io/github/cottonmc/cotton/gui/client/LibGuiConfig.java delete mode 100644 src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ConfigGui.java delete mode 100644 src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ModMenuSupport.java delete mode 100644 src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/WKirbSprite.java delete mode 100644 src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/package-info.java create mode 100644 src/main/java/io/github/cottonmc/cotton/gui/impl/client/LibGuiClient.java create mode 100644 src/main/java/io/github/cottonmc/cotton/gui/impl/client/LibGuiConfig.java create mode 100644 src/main/java/io/github/cottonmc/cotton/gui/impl/client/NinePatchInternals.java create mode 100644 src/main/java/io/github/cottonmc/cotton/gui/impl/client/modmenu/ConfigGui.java create mode 100644 src/main/java/io/github/cottonmc/cotton/gui/impl/client/modmenu/ModMenuSupport.java create mode 100644 src/main/java/io/github/cottonmc/cotton/gui/impl/client/modmenu/WKirbSprite.java create mode 100644 src/main/java/io/github/cottonmc/cotton/gui/impl/client/modmenu/package-info.java create mode 100644 src/main/java/io/github/cottonmc/cotton/gui/impl/client/package-info.java 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 293852d..83ae894 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java @@ -21,7 +21,7 @@ import net.minecraft.screen.slot.SlotActionType; 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.widget.WGridPanel; import io.github.cottonmc.cotton.gui.widget.WLabel; import io.github.cottonmc.cotton.gui.widget.WPanel; @@ -74,7 +74,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 4789271..c856761 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..8b1973a --- /dev/null +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/LibGui.java @@ -0,0 +1,18 @@ +package io.github.cottonmc.cotton.gui.client; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; + +import io.github.cottonmc.cotton.gui.impl.client.LibGuiClient; + +/** + * Provides access to global LibGui data such as the dark mode state. + * + * @since 4.0.0 + */ +@Environment(EnvType.CLIENT) +public final class LibGui { + 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 deleted file mode 100644 index a5fbb2d..0000000 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/LibGuiClient.java +++ /dev/null @@ -1,69 +0,0 @@ -package io.github.cottonmc.cotton.gui.client; - -import net.fabricmc.api.ClientModInitializer; -import net.fabricmc.fabric.api.resource.ResourceManagerHelper; -import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.resource.ResourceType; - -import blue.endless.jankson.Jankson; -import blue.endless.jankson.JsonElement; -import blue.endless.jankson.JsonObject; -import io.github.cottonmc.jankson.JanksonFactory; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import java.io.File; -import java.io.FileOutputStream; -import java.nio.charset.StandardCharsets; - -public class LibGuiClient implements ClientModInitializer { - public static final Logger logger = LogManager.getLogger(); - public static final String MODID = "libgui"; - public static volatile LibGuiConfig config; - - public static final Jankson jankson = JanksonFactory.createJankson(); - - @Override - public void onInitializeClient() { - config = loadConfig(); - - ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(NinePatch.MetadataLoader.INSTANCE); - } - - public static LibGuiConfig loadConfig() { - try { - File file = new File(FabricLoader.getInstance().getConfigDirectory(),"libgui.json5"); - - if (!file.exists()) saveConfig(new LibGuiConfig()); - - JsonObject json = jankson.load(file); - config = jankson.fromJson(json, LibGuiConfig.class); - - /* - JsonElement jsonElementNew = jankson.toJson(new LibGuiConfig()); - if(jsonElementNew instanceof JsonObject) { - JsonObject jsonNew = (JsonObject) jsonElementNew; - if(json.getDelta(jsonNew).size()>= 0) { //TODO: Insert new keys as defaults into `json` IR object instead of writing the config out, so comments are preserved - saveConfig(config); - } - }*/ - } catch (Exception e) { - logger.error("[LibGui] Error loading config: {}", e.getMessage()); - } - return config; - } - - public static void saveConfig(LibGuiConfig config) { - try { - File file = new File(FabricLoader.getInstance().getConfigDirectory(),"libgui.json5"); - - JsonElement json = jankson.toJson(config); - String result = json.toJson(true, true); - try (FileOutputStream out = new FileOutputStream(file, false)) { - out.write(result.getBytes(StandardCharsets.UTF_8)); - } - } catch (Exception e) { - logger.error("[LibGui] Error saving config: {}", e.getMessage()); - } - } -} diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/LibGuiConfig.java b/src/main/java/io/github/cottonmc/cotton/gui/client/LibGuiConfig.java deleted file mode 100644 index b971e31..0000000 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/LibGuiConfig.java +++ /dev/null @@ -1,8 +0,0 @@ -package io.github.cottonmc.cotton.gui.client; - -import blue.endless.jankson.Comment; - -public class LibGuiConfig { - @Comment("Whether dark mode should be enabled. Will only affect Vanilla-styled GUIs.") - public boolean darkMode = false; -} 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/NinePatch.java b/src/main/java/io/github/cottonmc/cotton/gui/client/NinePatch.java index 9057739..033f7cf 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/NinePatch.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/NinePatch.java @@ -2,24 +2,13 @@ package io.github.cottonmc.cotton.gui.client; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener; -import net.minecraft.resource.Resource; -import net.minecraft.resource.ResourceManager; -import net.minecraft.resource.SinglePreparationResourceReloadListener; import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; -import net.minecraft.util.profiler.Profiler; +import io.github.cottonmc.cotton.gui.impl.client.NinePatchInternals; import io.github.cottonmc.cotton.gui.widget.WWidget; import org.jetbrains.annotations.Nullable; -import java.io.InputStream; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; - /** * The nine-patch background painter paints rectangles using a nine-patch texture. * @@ -178,7 +167,7 @@ public class NinePatch implements BackgroundPainter { int y2 = top + height - cornerSize; float uv1 = cornerUv; float uv2 = 1.0f - cornerUv; - Mode mode = this.mode != null ? this.mode : MetadataLoader.INSTANCE.getProperties(texture).getMode(); + Mode mode = this.mode != null ? this.mode : NinePatchInternals.MetadataLoader.INSTANCE.getProperties(texture).getMode(); ScreenDrawing.texturedRect(left, top, cornerSize, cornerSize, texture, 0, 0, uv1, uv1, 0xFF_FFFFFF); ScreenDrawing.texturedRect(x2, top, cornerSize, cornerSize, texture, uv2, 0, 1, uv1, 0xFF_FFFFFF); @@ -239,8 +228,15 @@ public class NinePatch implements BackgroundPainter { */ TILING; + /** + * Deserializes a nine-patch mode from a string. + * + * @param str the mode string + * @return the mode, or null if the string is invalid + * @since 4.0.0 + */ @Nullable - static Mode fromString(String str) { + public static Mode fromString(String str) { if (str == null) return null; if (str.equalsIgnoreCase("stretching")) return STRETCHING; @@ -249,84 +245,4 @@ public class NinePatch implements BackgroundPainter { return null; } } - - public static class TextureProperties { - public static final TextureProperties DEFAULT = new TextureProperties(Mode.STRETCHING); - - private final Mode mode; - - public TextureProperties(Mode mode) { - this.mode = mode; - } - - public Mode getMode() { - return mode; - } - } - - public static class MetadataLoader extends SinglePreparationResourceReloadListener> implements IdentifiableResourceReloadListener { - public static final MetadataLoader INSTANCE = new MetadataLoader(); - - private static final Identifier ID = new Identifier("libgui", "9patch_metadata"); - private static final String SUFFIX = ".9patch"; - - private Map properties = Collections.emptyMap(); - - public TextureProperties getProperties(Identifier texture) { - return properties.getOrDefault(texture, TextureProperties.DEFAULT); - } - - @Override - public Identifier getFabricId() { - return ID; - } - - @Override - protected Map prepare(ResourceManager manager, Profiler profiler) { - Collection ids = manager.findResources("textures", s -> s.endsWith(SUFFIX)); - Map result = new HashMap<>(); - - for (Identifier input : ids) { - try (Resource resource = manager.getResource(input); - InputStream stream = resource.getInputStream()) { - Properties props = new Properties(); - props.load(stream); - Identifier textureId = new Identifier(input.getNamespace(), input.getPath().substring(0, input.getPath().length() - SUFFIX.length())); - result.put(textureId, props); - } catch (Exception e) { - LibGuiClient.logger.error("Error while loading metadata file {}, skipping...", input, e); - } - } - - return result; - } - - @Override - protected void apply(Map meta, ResourceManager manager, Profiler profiler) { - properties = new HashMap<>(); - for (Map.Entry entry : meta.entrySet()) { - Identifier id = entry.getKey(); - Properties props = entry.getValue(); - - Mode mode = TextureProperties.DEFAULT.getMode(); -// float cornerUv = TextureProperties.DEFAULT.getCornerUv(); - - if (props.containsKey("mode")) { - String modeStr = props.getProperty("mode"); - mode = Mode.fromString(modeStr); - if (mode == null) { - LibGuiClient.logger.error("Invalid mode '{}' in nine-patch metadata file for texture {}", modeStr, id); - continue; - } - } - -// if (props.containsKey("cornerUv")) { -// cornerUv = Float.parseFloat(props.getProperty("cornerUv")); -// } - - TextureProperties texProperties = new TextureProperties(mode); - properties.put(id, texProperties); - } - } - } } 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 daaaf2f..0781769 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 @@ -263,7 +263,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/ConfigGui.java b/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ConfigGui.java deleted file mode 100644 index cd3fe0a..0000000 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ConfigGui.java +++ /dev/null @@ -1,62 +0,0 @@ -package io.github.cottonmc.cotton.gui.client.modmenu; - -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.text.TranslatableText; - -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.WTextField; -import io.github.cottonmc.cotton.gui.widget.WToggleButton; - -public class ConfigGui extends LightweightGuiDescription { - - public ConfigGui(Screen previous) { - WGridPanel root = new WGridPanel(); - setRootPanel(root); - - WToggleButton darkmodeButton = new WToggleButton(new TranslatableText("option.libgui.darkmode")) { - @Override - public void onToggle(boolean on) { - LibGuiClient.config.darkMode = on; - LibGuiClient.saveConfig(LibGuiClient.config); - } - }; - darkmodeButton.setToggle(LibGuiClient.config.darkMode); - root.add(darkmodeButton, 0, 2, 6, 1); - - WTextField testField = new WTextField(); - testField.setSuggestion("test"); - root.add(testField, 0, 3, 4, 1); - - /* - WSlider verticalSlider = new WSlider(-100, 100, Axis.VERTICAL); - verticalSlider.setDraggingFinishedListener(() -> System.out.println("Mouse released")); - verticalSlider.setValueChangeListener(System.out::println); - - WLabeledSlider horizontalSlider = new WLabeledSlider(0, 500); - horizontalSlider.setLabelUpdater(value -> new LiteralText(value + "!")); - horizontalSlider.setDraggingFinishedListener(() -> System.out.println("Mouse released")); - horizontalSlider.setValue(250); - - root.add(verticalSlider, 6, 0, 1, 3); - root.add(horizontalSlider, 1, 4, 4, 1); - */ - - root.add(new WKirbSprite(), 5, 4); - - WButton doneButton = new WButton(new TranslatableText("gui.done")); - doneButton.setOnClick(()->{ - MinecraftClient.getInstance().openScreen(previous); - }); - root.add(doneButton, 0, 5, 3, 1); - - root.setBackgroundPainter(BackgroundPainter.VANILLA); - root.setSize(7*18, 6*18); - - root.validate(this); - } -} 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 deleted file mode 100644 index ccdff93..0000000 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ModMenuSupport.java +++ /dev/null @@ -1,18 +0,0 @@ -package io.github.cottonmc.cotton.gui.client.modmenu; - -import net.minecraft.text.TranslatableText; - -import io.github.cottonmc.cotton.gui.client.CottonClientScreen; -import io.github.prospector.modmenu.api.ConfigScreenFactory; -import io.github.prospector.modmenu.api.ModMenuApi; - -public class ModMenuSupport implements ModMenuApi { - @Override - public ConfigScreenFactory getModConfigScreenFactory() { - return screen -> new CottonClientScreen(new TranslatableText("options.libgui.libgui_settings"), new ConfigGui(screen)) { - public void onClose() { - this.client.openScreen(screen); - } - }; - } -} 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 deleted file mode 100644 index 74d5357..0000000 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/WKirbSprite.java +++ /dev/null @@ -1,117 +0,0 @@ -package io.github.cottonmc.cotton.gui.client.modmenu; - -import net.fabricmc.api.EnvType; -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.ScreenDrawing; -import io.github.cottonmc.cotton.gui.widget.WWidget; - -import java.util.ArrayList; - -public class WKirbSprite extends WWidget { - private static final Identifier KIRB = new Identifier("libgui:textures/widget/kirb.png"); - - private static final float PX = 1f/416f; - private static final float KIRB_WIDTH = 32*PX; - - private int currentFrame= 0; - private long currentFrameTime = 0; - private int[] toSleep = { 0, 0, 0, 1, 2, 1, 2, 0, 0, 0, 1, 2, 3 }; - private int[] asleep = { 4, 4, 4, 4, 5, 6, 7, 6, 5 }; - private int[] toAwake = { 3, 3, 8, 8, 8, 8, 8, 8, 8 }; - private int[] awake = { 9, 9, 9, 10, 11, 12 }; - private State state = State.ASLEEP; - private ArrayList pendingFrames = new ArrayList<>(); - - private int frameTime = 300; - private long lastFrame; - - public WKirbSprite() { - state = (LibGuiClient.config.darkMode) ? State.ASLEEP : State.AWAKE; - } - - public void schedule(int[] frames) { - for(int i : frames) pendingFrames.add(i); - } - - @Override - public boolean canResize() { - return false; - } - - @Override - public int getWidth() { - return 32; - } - - @Override - public int getHeight() { - return 32; - } - - @Environment(EnvType.CLIENT) - @Override - public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { - long now = System.nanoTime() / 1_000_000L; - - - if (pendingFrames.isEmpty()) { - - if (LibGuiClient.config.darkMode) { - switch(state) { - case AWAKE: - state = State.FALLING_ASLEEP; - break; - case FALLING_ASLEEP: - state = State.ASLEEP; - break; - default: - //zzzz - state = State.ASLEEP; - break; - } - } else { - switch(state) { - case ASLEEP: - state = State.WAKING_UP; - break; - case WAKING_UP: - state = State.AWAKE; - break; - default: - state = State.AWAKE; - break; - } - } - - switch (state) { - case ASLEEP: schedule(asleep); break; - case WAKING_UP: schedule(toAwake); break; - case AWAKE: schedule(awake); break; - case FALLING_ASLEEP: schedule(toSleep); break; - } - } - - float offset = KIRB_WIDTH * currentFrame; - ScreenDrawing.texturedRect(x, y+8, 32, 32, KIRB, offset, 0, offset+KIRB_WIDTH, 1, 0xFFFFFFFF); - - long elapsed = now - lastFrame; - currentFrameTime += elapsed; - if (currentFrameTime >= frameTime) { - if (!pendingFrames.isEmpty()) currentFrame = pendingFrames.remove(0); - currentFrameTime = 0; - } - - this.lastFrame = now; - } - - public static enum State { - AWAKE, - FALLING_ASLEEP, - ASLEEP, - WAKING_UP; - } -} diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/package-info.java b/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/package-info.java deleted file mode 100644 index ad040bf..0000000 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Mod Menu support for LibGui. - */ -package io.github.cottonmc.cotton.gui.client.modmenu; diff --git a/src/main/java/io/github/cottonmc/cotton/gui/impl/access/package-info.java b/src/main/java/io/github/cottonmc/cotton/gui/impl/access/package-info.java index 8f391fd..b98a6b8 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/impl/access/package-info.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/impl/access/package-info.java @@ -1,4 +1,7 @@ /** * Internal implementation classes. */ +@ApiStatus.Internal package io.github.cottonmc.cotton.gui.impl.access; + +import org.jetbrains.annotations.ApiStatus; diff --git a/src/main/java/io/github/cottonmc/cotton/gui/impl/client/LibGuiClient.java b/src/main/java/io/github/cottonmc/cotton/gui/impl/client/LibGuiClient.java new file mode 100644 index 0000000..5ebc2bb --- /dev/null +++ b/src/main/java/io/github/cottonmc/cotton/gui/impl/client/LibGuiClient.java @@ -0,0 +1,70 @@ +package io.github.cottonmc.cotton.gui.impl.client; + +import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.fabric.api.resource.ResourceManagerHelper; +import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.resource.ResourceType; + +import blue.endless.jankson.Jankson; +import blue.endless.jankson.JsonElement; +import blue.endless.jankson.JsonObject; +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; + +public class LibGuiClient implements ClientModInitializer { + public static final Logger logger = LogManager.getLogger(); + public static final String MODID = "libgui"; + public static volatile LibGuiConfig config; + + public static final Jankson jankson = JanksonFactory.createJankson(); + + @Override + public void onInitializeClient() { + config = loadConfig(); + + ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(NinePatchInternals.MetadataLoader.INSTANCE); + } + + public static LibGuiConfig loadConfig() { + try { + File file = new File(FabricLoader.getInstance().getConfigDirectory(),"libgui.json5"); + + if (!file.exists()) saveConfig(new LibGuiConfig()); + + JsonObject json = jankson.load(file); + config = jankson.fromJson(json, LibGuiConfig.class); + + /* + JsonElement jsonElementNew = jankson.toJson(new LibGuiConfig()); + if(jsonElementNew instanceof JsonObject) { + JsonObject jsonNew = (JsonObject) jsonElementNew; + if(json.getDelta(jsonNew).size()>= 0) { //TODO: Insert new keys as defaults into `json` IR object instead of writing the config out, so comments are preserved + saveConfig(config); + } + }*/ + } catch (Exception e) { + logger.error("[LibGui] Error loading config: {}", e.getMessage()); + } + return config; + } + + public static void saveConfig(LibGuiConfig config) { + try { + File file = new File(FabricLoader.getInstance().getConfigDirectory(),"libgui.json5"); + + JsonElement json = jankson.toJson(config); + String result = json.toJson(true, true); + try (FileOutputStream out = new FileOutputStream(file, false)) { + out.write(result.getBytes(StandardCharsets.UTF_8)); + } + } catch (Exception e) { + logger.error("[LibGui] Error saving config: {}", e.getMessage()); + } + } +} diff --git a/src/main/java/io/github/cottonmc/cotton/gui/impl/client/LibGuiConfig.java b/src/main/java/io/github/cottonmc/cotton/gui/impl/client/LibGuiConfig.java new file mode 100644 index 0000000..b1985af --- /dev/null +++ b/src/main/java/io/github/cottonmc/cotton/gui/impl/client/LibGuiConfig.java @@ -0,0 +1,8 @@ +package io.github.cottonmc.cotton.gui.impl.client; + +import blue.endless.jankson.Comment; + +public class LibGuiConfig { + @Comment("Whether dark mode should be enabled. Will only affect Vanilla-styled GUIs.") + public boolean darkMode = false; +} diff --git a/src/main/java/io/github/cottonmc/cotton/gui/impl/client/NinePatchInternals.java b/src/main/java/io/github/cottonmc/cotton/gui/impl/client/NinePatchInternals.java new file mode 100644 index 0000000..4113825 --- /dev/null +++ b/src/main/java/io/github/cottonmc/cotton/gui/impl/client/NinePatchInternals.java @@ -0,0 +1,103 @@ +package io.github.cottonmc.cotton.gui.impl.client; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener; +import net.minecraft.resource.Resource; +import net.minecraft.resource.ResourceManager; +import net.minecraft.resource.SinglePreparationResourceReloadListener; +import net.minecraft.util.Identifier; +import net.minecraft.util.profiler.Profiler; + +import io.github.cottonmc.cotton.gui.client.NinePatch; + +import java.io.InputStream; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + +@Environment(EnvType.CLIENT) +public final class NinePatchInternals { + @Environment(EnvType.CLIENT) + public static final class MetadataLoader extends SinglePreparationResourceReloadListener> implements IdentifiableResourceReloadListener { + public static final MetadataLoader INSTANCE = new MetadataLoader(); + + private static final Identifier ID = new Identifier("libgui", "9patch_metadata"); + private static final String SUFFIX = ".9patch"; + + private Map properties = Collections.emptyMap(); + + public TextureProperties getProperties(Identifier texture) { + return properties.getOrDefault(texture, TextureProperties.DEFAULT); + } + + @Override + public Identifier getFabricId() { + return ID; + } + + @Override + protected Map prepare(ResourceManager manager, Profiler profiler) { + Collection ids = manager.findResources("textures", s -> s.endsWith(SUFFIX)); + Map result = new HashMap<>(); + + for (Identifier input : ids) { + try (Resource resource = manager.getResource(input); + InputStream stream = resource.getInputStream()) { + Properties props = new Properties(); + props.load(stream); + Identifier textureId = new Identifier(input.getNamespace(), input.getPath().substring(0, input.getPath().length() - SUFFIX.length())); + result.put(textureId, props); + } catch (Exception e) { + LibGuiClient.logger.error("Error while loading metadata file {}, skipping...", input, e); + } + } + + return result; + } + + @Override + protected void apply(Map meta, ResourceManager manager, Profiler profiler) { + properties = new HashMap<>(); + for (Map.Entry entry : meta.entrySet()) { + Identifier id = entry.getKey(); + Properties props = entry.getValue(); + + NinePatch.Mode mode = TextureProperties.DEFAULT.getMode(); + // float cornerUv = TextureProperties.DEFAULT.getCornerUv(); + + if (props.containsKey("mode")) { + String modeStr = props.getProperty("mode"); + mode = NinePatch.Mode.fromString(modeStr); + if (mode == null) { + LibGuiClient.logger.error("Invalid mode '{}' in nine-patch metadata file for texture {}", modeStr, id); + continue; + } + } + + // if (props.containsKey("cornerUv")) { + // cornerUv = Float.parseFloat(props.getProperty("cornerUv")); + // } + + TextureProperties texProperties = new TextureProperties(mode); + properties.put(id, texProperties); + } + } + } + + public static class TextureProperties { + public static final TextureProperties DEFAULT = new TextureProperties(NinePatch.Mode.STRETCHING); + + private final NinePatch.Mode mode; + + public TextureProperties(NinePatch.Mode mode) { + this.mode = mode; + } + + public NinePatch.Mode getMode() { + return mode; + } + } +} diff --git a/src/main/java/io/github/cottonmc/cotton/gui/impl/client/modmenu/ConfigGui.java b/src/main/java/io/github/cottonmc/cotton/gui/impl/client/modmenu/ConfigGui.java new file mode 100644 index 0000000..5f3d4fa --- /dev/null +++ b/src/main/java/io/github/cottonmc/cotton/gui/impl/client/modmenu/ConfigGui.java @@ -0,0 +1,62 @@ +package io.github.cottonmc.cotton.gui.impl.client.modmenu; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.text.TranslatableText; + +import io.github.cottonmc.cotton.gui.client.BackgroundPainter; +import io.github.cottonmc.cotton.gui.client.LightweightGuiDescription; +import io.github.cottonmc.cotton.gui.impl.client.LibGuiClient; +import io.github.cottonmc.cotton.gui.widget.WButton; +import io.github.cottonmc.cotton.gui.widget.WGridPanel; +import io.github.cottonmc.cotton.gui.widget.WTextField; +import io.github.cottonmc.cotton.gui.widget.WToggleButton; + +public class ConfigGui extends LightweightGuiDescription { + + public ConfigGui(Screen previous) { + WGridPanel root = new WGridPanel(); + setRootPanel(root); + + WToggleButton darkmodeButton = new WToggleButton(new TranslatableText("option.libgui.darkmode")) { + @Override + public void onToggle(boolean on) { + LibGuiClient.config.darkMode = on; + LibGuiClient.saveConfig(LibGuiClient.config); + } + }; + darkmodeButton.setToggle(LibGuiClient.config.darkMode); + root.add(darkmodeButton, 0, 2, 6, 1); + + WTextField testField = new WTextField(); + testField.setSuggestion("test"); + root.add(testField, 0, 3, 4, 1); + + /* + WSlider verticalSlider = new WSlider(-100, 100, Axis.VERTICAL); + verticalSlider.setDraggingFinishedListener(() -> System.out.println("Mouse released")); + verticalSlider.setValueChangeListener(System.out::println); + + WLabeledSlider horizontalSlider = new WLabeledSlider(0, 500); + horizontalSlider.setLabelUpdater(value -> new LiteralText(value + "!")); + horizontalSlider.setDraggingFinishedListener(() -> System.out.println("Mouse released")); + horizontalSlider.setValue(250); + + root.add(verticalSlider, 6, 0, 1, 3); + root.add(horizontalSlider, 1, 4, 4, 1); + */ + + root.add(new WKirbSprite(), 5, 4); + + WButton doneButton = new WButton(new TranslatableText("gui.done")); + doneButton.setOnClick(()->{ + MinecraftClient.getInstance().openScreen(previous); + }); + root.add(doneButton, 0, 5, 3, 1); + + root.setBackgroundPainter(BackgroundPainter.VANILLA); + root.setSize(7*18, 6*18); + + root.validate(this); + } +} diff --git a/src/main/java/io/github/cottonmc/cotton/gui/impl/client/modmenu/ModMenuSupport.java b/src/main/java/io/github/cottonmc/cotton/gui/impl/client/modmenu/ModMenuSupport.java new file mode 100644 index 0000000..82fead4 --- /dev/null +++ b/src/main/java/io/github/cottonmc/cotton/gui/impl/client/modmenu/ModMenuSupport.java @@ -0,0 +1,18 @@ +package io.github.cottonmc.cotton.gui.impl.client.modmenu; + +import net.minecraft.text.TranslatableText; + +import io.github.cottonmc.cotton.gui.client.CottonClientScreen; +import io.github.prospector.modmenu.api.ConfigScreenFactory; +import io.github.prospector.modmenu.api.ModMenuApi; + +public class ModMenuSupport implements ModMenuApi { + @Override + public ConfigScreenFactory getModConfigScreenFactory() { + return screen -> new CottonClientScreen(new TranslatableText("options.libgui.libgui_settings"), new ConfigGui(screen)) { + public void onClose() { + this.client.openScreen(screen); + } + }; + } +} diff --git a/src/main/java/io/github/cottonmc/cotton/gui/impl/client/modmenu/WKirbSprite.java b/src/main/java/io/github/cottonmc/cotton/gui/impl/client/modmenu/WKirbSprite.java new file mode 100644 index 0000000..140819a --- /dev/null +++ b/src/main/java/io/github/cottonmc/cotton/gui/impl/client/modmenu/WKirbSprite.java @@ -0,0 +1,117 @@ +package io.github.cottonmc.cotton.gui.impl.client.modmenu; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.util.math.MatrixStack; +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.WWidget; + +import java.util.ArrayList; + +public class WKirbSprite extends WWidget { + private static final Identifier KIRB = new Identifier("libgui:textures/widget/kirb.png"); + + private static final float PX = 1f/416f; + private static final float KIRB_WIDTH = 32*PX; + + private int currentFrame= 0; + private long currentFrameTime = 0; + private int[] toSleep = { 0, 0, 0, 1, 2, 1, 2, 0, 0, 0, 1, 2, 3 }; + private int[] asleep = { 4, 4, 4, 4, 5, 6, 7, 6, 5 }; + private int[] toAwake = { 3, 3, 8, 8, 8, 8, 8, 8, 8 }; + private int[] awake = { 9, 9, 9, 10, 11, 12 }; + private State state = State.ASLEEP; + private ArrayList pendingFrames = new ArrayList<>(); + + private int frameTime = 300; + private long lastFrame; + + public WKirbSprite() { + state = (LibGui.isDarkMode()) ? State.ASLEEP : State.AWAKE; + } + + public void schedule(int[] frames) { + for(int i : frames) pendingFrames.add(i); + } + + @Override + public boolean canResize() { + return false; + } + + @Override + public int getWidth() { + return 32; + } + + @Override + public int getHeight() { + return 32; + } + + @Environment(EnvType.CLIENT) + @Override + public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { + long now = System.nanoTime() / 1_000_000L; + + + if (pendingFrames.isEmpty()) { + + if (LibGui.isDarkMode()) { + switch(state) { + case AWAKE: + state = State.FALLING_ASLEEP; + break; + case FALLING_ASLEEP: + state = State.ASLEEP; + break; + default: + //zzzz + state = State.ASLEEP; + break; + } + } else { + switch(state) { + case ASLEEP: + state = State.WAKING_UP; + break; + case WAKING_UP: + state = State.AWAKE; + break; + default: + state = State.AWAKE; + break; + } + } + + switch (state) { + case ASLEEP: schedule(asleep); break; + case WAKING_UP: schedule(toAwake); break; + case AWAKE: schedule(awake); break; + case FALLING_ASLEEP: schedule(toSleep); break; + } + } + + float offset = KIRB_WIDTH * currentFrame; + ScreenDrawing.texturedRect(x, y+8, 32, 32, KIRB, offset, 0, offset+KIRB_WIDTH, 1, 0xFFFFFFFF); + + long elapsed = now - lastFrame; + currentFrameTime += elapsed; + if (currentFrameTime >= frameTime) { + if (!pendingFrames.isEmpty()) currentFrame = pendingFrames.remove(0); + currentFrameTime = 0; + } + + this.lastFrame = now; + } + + public static enum State { + AWAKE, + FALLING_ASLEEP, + ASLEEP, + WAKING_UP; + } +} diff --git a/src/main/java/io/github/cottonmc/cotton/gui/impl/client/modmenu/package-info.java b/src/main/java/io/github/cottonmc/cotton/gui/impl/client/modmenu/package-info.java new file mode 100644 index 0000000..283aa50 --- /dev/null +++ b/src/main/java/io/github/cottonmc/cotton/gui/impl/client/modmenu/package-info.java @@ -0,0 +1,7 @@ +/** + * Mod Menu support for LibGui. + */ +@ApiStatus.Internal +package io.github.cottonmc.cotton.gui.impl.client.modmenu; + +import org.jetbrains.annotations.ApiStatus; diff --git a/src/main/java/io/github/cottonmc/cotton/gui/impl/client/package-info.java b/src/main/java/io/github/cottonmc/cotton/gui/impl/client/package-info.java new file mode 100644 index 0000000..c27d30e --- /dev/null +++ b/src/main/java/io/github/cottonmc/cotton/gui/impl/client/package-info.java @@ -0,0 +1,9 @@ +/** + * Internal implementation classes. + * + * @since 4.0.0 + */ +@ApiStatus.Internal // I hope this scares people off +package io.github.cottonmc.cotton.gui.impl.client; + +import org.jetbrains.annotations.ApiStatus; diff --git a/src/main/java/io/github/cottonmc/cotton/gui/impl/package-info.java b/src/main/java/io/github/cottonmc/cotton/gui/impl/package-info.java index 678ba6f..298c2fc 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/impl/package-info.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/impl/package-info.java @@ -3,4 +3,7 @@ * * @since 2.0.0 */ +@ApiStatus.Internal package io.github.cottonmc.cotton.gui.impl; + +import org.jetbrains.annotations.ApiStatus; 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..2583448 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; @@ -33,7 +33,7 @@ public class WLabel extends WWidget { public static final int DEFAULT_TEXT_COLOR = 0x404040; /** - * The default text color for {@linkplain io.github.cottonmc.cotton.gui.client.LibGuiConfig#darkMode dark mode} labels. + * The default text color for {@linkplain LibGui#isDarkMode() dark mode} labels. */ public static final int DEFAULT_DARKMODE_TEXT_COLOR = 0xbcbcbc; @@ -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 9e17d37..576588a 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; @@ -336,7 +336,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); } } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index df75753..c8f0ffe 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -18,8 +18,8 @@ "environment": "*", "entrypoints": { - "client": ["io.github.cottonmc.cotton.gui.client.LibGuiClient"], - "modmenu": ["io.github.cottonmc.cotton.gui.client.modmenu.ModMenuSupport"] + "client": ["io.github.cottonmc.cotton.gui.impl.client.LibGuiClient"], + "modmenu": ["io.github.cottonmc.cotton.gui.impl.client.modmenu.ModMenuSupport"] }, "mixins": [ "mixins.libgui.accessors.json" -- cgit