diff options
7 files changed, 85 insertions, 3 deletions
diff --git a/build.gradle b/build.gradle index f56ea43..61fbdb2 100644 --- a/build.gradle +++ b/build.gradle @@ -24,6 +24,10 @@ group = project.maven_group minecraft { } +repositories { + maven { url "http://server.bbkr.space:8081/artifactory/libs-release" } +} + dependencies { //to change the versions see the gradle.properties file minecraft "com.mojang:minecraft:${project.minecraft_version}" @@ -32,6 +36,8 @@ dependencies { // Fabric API. This is technically optional, but you probably want it anyway. modCompile "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + modCompile "io.github.cottonmc:Jankson:${project.jankson_version}" + include "io.github.cottonmc:Jankson:${project.jankson_version}" compileOnly ("com.google.code.findbugs:jsr305:3.0.2") { transitive = false } // PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs. diff --git a/gradle.properties b/gradle.properties index dc1c461..64feb90 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,3 +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.0+build.187 + jankson_version=1.0.0+j1.1.2 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 b95cdfc..360e85e 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 @@ -20,13 +20,13 @@ public interface BackgroundPainter { public static BackgroundPainter SLOT = (left, top, panel) -> { if (!(panel instanceof WItemSlot)) { - ScreenDrawing.drawBeveledPanel(left-1, top-1, panel.getWidth(), panel.getHeight(), 0xFF373737, 0xFF8B8B8B, 0xFFFFFFFF); + ScreenDrawing.drawBeveledPanel(left-1, top-1, panel.getWidth(), panel.getHeight(), 0xFF373737, 0x4C000000, 0xFFFFFFFF); } else { WItemSlot slot = (WItemSlot)panel; for(int x = 0; x < slot.getWidth()/18; ++x) { for(int y = 0; y < slot.getHeight()/18; ++y) { int lo = 0xFF373737; - int bg = 0xFF8B8B8B; + int bg = 0x4C000000; int hi = 0xFFFFFFFF; if (slot.isBigSlot()) { ScreenDrawing.drawBeveledPanel((x * 18) + left - 4, (y * 18) + top - 4, 24, 24, 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 new file mode 100644 index 0000000..ea24bf4 --- /dev/null +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/LibGuiClient.java @@ -0,0 +1,61 @@ +package io.github.cottonmc.cotton.gui.client; + +import blue.endless.jankson.Jankson; +import blue.endless.jankson.JsonElement; +import blue.endless.jankson.JsonObject; +import io.github.cottonmc.jankson.JanksonFactory; +import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.loader.api.FabricLoader; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.io.File; +import java.io.FileOutputStream; + +public class LibGuiClient implements ClientModInitializer { + public static final Logger logger = LogManager.getLogger(); + + public static LibGuiConfig config; + + public static final Jankson jankson = JanksonFactory.createJankson(); + + @Override + public void onInitializeClient() { + config = loadConfig(); + } + + public LibGuiConfig loadConfig() { + try { + File file = FabricLoader.getInstance().getConfigDirectory().toPath().resolve("libgui.json5").toFile(); + if (!file.exists()) saveConfig(new LibGuiConfig()); + JsonObject json = jankson.load(file); + LibGuiConfig result = 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){ + saveConfig(result); + } + } + } catch (Exception e) { + logger.error("[LibGui] Error loading config: {}", e.getMessage()); + } + return new LibGuiConfig(); + } + + public void saveConfig(LibGuiConfig config) { + try { + File file = FabricLoader.getInstance().getConfigDirectory().toPath().resolve("libgui.json5").toFile(); + JsonElement json = jankson.toJson(config); + String result = json.toJson(true, true); + if (!file.exists()) file.createNewFile(); + FileOutputStream out = new FileOutputStream(file,false); + out.write(result.getBytes()); + out.flush(); + out.close(); + } 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 new file mode 100644 index 0000000..b971e31 --- /dev/null +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/LibGuiConfig.java @@ -0,0 +1,8 @@ +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/ScreenDrawing.java b/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java index 5592e5d..0e6df04 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 @@ -131,7 +131,8 @@ public class ScreenDrawing { * Draws a beveled, round rectangle that is substantially similar to default Minecraft UI panels. */ public static void drawGuiPanel(int x, int y, int width, int height) { - drawGuiPanel(x, y, width, height, 0xFF555555, 0xFFC6C6C6, 0xFFFFFFFF, 0xFF000000); + if (LibGuiClient.config.darkMode) drawGuiPanel(x, y, width, height, 0xFF0B0B0B, 0xFF2F2F2F, 0xFF414141, 0xFF000000); + else drawGuiPanel(x, y, width, height, 0xFF555555, 0xFFC6C6C6, 0xFFFFFFFF, 0xFF000000); } public static void drawGuiPanel(int x, int y, int width, int height, int panelColor) { diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index d803a84..4e658e7 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -16,6 +16,11 @@ "icon": "assets/libgui/icon.png", "environment": "*", + "entrypoints": { + "client": [ + "io.github.cottonmc.libgui.client.LibGuiClient" + ] + }, "depends": { "fabricloader": ">=0.4.0", "fabric": "*" |