diff options
Diffstat (limited to 'src/main/java')
4 files changed, 73 insertions, 3 deletions
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) { |