From f5dddcafa5aae57bc9972b851ab2277eb97d8c00 Mon Sep 17 00:00:00 2001 From: Zalgo-Dev <29240471+Zalgo-Dev@users.noreply.github.com> Date: Sun, 26 Jan 2025 04:28:56 +0100 Subject: [PATCH 1/2] Add new theme, add theme selection button and adjust titlescreen buttons positions --- .../paradiseclientfabric/ConfigManager.java | 53 +++++++++++++++ .../paradiseclientfabric/WallPaper.java | 67 +++++++++++++++++++ .../mixin/inject/gui/screen/ScreenMixin.java | 2 +- .../inject/gui/screen/TitleScreenMixin.java | 33 +++++++-- 4 files changed, 150 insertions(+), 5 deletions(-) create mode 100644 src/main/java/io/github/spigotrce/paradiseclientfabric/ConfigManager.java diff --git a/src/main/java/io/github/spigotrce/paradiseclientfabric/ConfigManager.java b/src/main/java/io/github/spigotrce/paradiseclientfabric/ConfigManager.java new file mode 100644 index 0000000..6d81354 --- /dev/null +++ b/src/main/java/io/github/spigotrce/paradiseclientfabric/ConfigManager.java @@ -0,0 +1,53 @@ +package io.github.spigotrce.paradiseclientfabric; + +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; + +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +public class ConfigManager { + private static final File CONFIG_FILE = new File("config/paradiseclient.json"); + private static JsonObject config; + + static { + loadConfig(); + } + + // Charger la configuration depuis le fichier + private static void loadConfig() { + try { + if (CONFIG_FILE.exists()) { + FileReader reader = new FileReader(CONFIG_FILE); + config = JsonParser.parseReader(reader).getAsJsonObject(); + reader.close(); + } else { + config = new JsonObject(); + saveConfig(); + } + } catch (IOException e) { + config = new JsonObject(); + } + } + + // Sauvegarder la configuration dans le fichier + private static void saveConfig() { + try (FileWriter writer = new FileWriter(CONFIG_FILE)) { + writer.write(config.toString()); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static String getTheme() { + return config.has("theme") ? config.get("theme").getAsString() : "ParadiseHack"; // ParadiseHack par défaut + } + + public static void setTheme(String theme) { + config.addProperty("theme", theme); // Mise à jour + saveConfig(); // Sauvegarde immédiate + } + +} diff --git a/src/main/java/io/github/spigotrce/paradiseclientfabric/WallPaper.java b/src/main/java/io/github/spigotrce/paradiseclientfabric/WallPaper.java index 5fcb5ab..0260ddc 100644 --- a/src/main/java/io/github/spigotrce/paradiseclientfabric/WallPaper.java +++ b/src/main/java/io/github/spigotrce/paradiseclientfabric/WallPaper.java @@ -8,7 +8,36 @@ public class WallPaper { private static final Random random = new Random(); private static final int[] drops = new int[300]; + private static final Particle[] particles = new Particle[100]; + static { + for (int i = 0; i < particles.length; i++) { + particles[i] = new Particle(); + } + } + + public static String getTheme() { + return ConfigManager.getTheme(); + } + + public static void setTheme(String theme) { + ConfigManager.setTheme(theme); + } + + /** + * Rend l'arrière-plan selon le thème actuel. + */ + public static void render(DrawContext context, int width, int height) { + String theme = getTheme(); // Récupérer le thème à partir de la configuration + switch (theme) { + case "ParadiseHack" -> renderMatrix(context, width, height); + case "ParadiseParticle" -> renderElegantBackground(context, width, height); + default -> renderMatrix(context, width, height); // Hack par défaut + } + } + + + // Thème Hack (style Matrix) public static void renderMatrix(DrawContext context, int width, int height) { context.fillGradient(0, 0, width, height, 0xCC000000, 0xCC000000); for (int i = 0; i < drops.length; i++) { @@ -20,4 +49,42 @@ public static void renderMatrix(DrawContext context, int width, int height) { drops[i]++; } } + + // Thème Particle (particules dynamiques) + public static void renderElegantBackground(DrawContext context, int width, int height) { + context.fillGradient(0, 0, width, height, 0xFF1A237E, 0xFF882dbd); // Bleu -> Violet + for (Particle particle : particles) { + particle.update(width, height); + context.fill(particle.x, particle.y, particle.x + 2, particle.y + 2, particle.color); + } + } + + private static class Particle { + int x, y, speedX, speedY, color; + + public Particle() { + reset(800, 600); + } + + public void update(int width, int height) { + x += speedX; + y += speedY; + + if (x < 0 || x > width || y < 0 || y > height) { + reset(width, height); + } + } + + public void reset(int width, int height) { + x = random.nextInt(width); + y = random.nextInt(height); + + do { + speedX = -1 + random.nextInt(3); // Vitesse entre -1 et 1 + speedY = -1 + random.nextInt(3); + } while (speedX == 0 && speedY == 0); + + color = 0xFFFFFFFF; // Blanc + } + } } diff --git a/src/main/java/io/github/spigotrce/paradiseclientfabric/mixin/inject/gui/screen/ScreenMixin.java b/src/main/java/io/github/spigotrce/paradiseclientfabric/mixin/inject/gui/screen/ScreenMixin.java index 2d9f2ea..ebd3115 100644 --- a/src/main/java/io/github/spigotrce/paradiseclientfabric/mixin/inject/gui/screen/ScreenMixin.java +++ b/src/main/java/io/github/spigotrce/paradiseclientfabric/mixin/inject/gui/screen/ScreenMixin.java @@ -35,7 +35,7 @@ public abstract class ScreenMixin { */ @Inject(method = "renderBackground", at = @At(value = "HEAD"), cancellable = true) private void renderBackground(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) { - WallPaper.renderMatrix(context, width, height); + WallPaper.render(context, width, height); ci.cancel(); } } diff --git a/src/main/java/io/github/spigotrce/paradiseclientfabric/mixin/inject/gui/screen/TitleScreenMixin.java b/src/main/java/io/github/spigotrce/paradiseclientfabric/mixin/inject/gui/screen/TitleScreenMixin.java index f1c42c9..1279f8d 100644 --- a/src/main/java/io/github/spigotrce/paradiseclientfabric/mixin/inject/gui/screen/TitleScreenMixin.java +++ b/src/main/java/io/github/spigotrce/paradiseclientfabric/mixin/inject/gui/screen/TitleScreenMixin.java @@ -4,6 +4,7 @@ import io.github.spigotrce.paradiseclientfabric.Constants; import io.github.spigotrce.paradiseclientfabric.Helper; import io.github.spigotrce.paradiseclientfabric.ParadiseClient_Fabric; +import io.github.spigotrce.paradiseclientfabric.WallPaper; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; @@ -32,10 +33,10 @@ * This class modifies the Title Screen to include a custom button recommending * the installation of "ViaFabricPlus" and customizes the background fade effect. * It also displays additional information about the client and game version. + *

* * @author SpigotRCE * @since 2.9 - *

*/ @SuppressWarnings("unused") @Mixin(TitleScreen.class) @@ -108,7 +109,7 @@ public void init(CallbackInfo ci) { MinecraftClient.getInstance().setScreen(new TitleScreen()); }) .width(this.textRenderer.getWidth(VIAFABRICPLUS_REMINDER) + 5) - .position((this.width / 2) - ((this.textRenderer.getWidth(VIAFABRICPLUS_REMINDER) + 5) / 2), this.height / 4 + 48 + 72 + 12 + 35) + .position((this.width / 2) - ((this.textRenderer.getWidth(VIAFABRICPLUS_REMINDER) + 5) / 2), this.height / 4 + 200) .build() ); } @@ -121,6 +122,29 @@ public void init(CallbackInfo ci) { MinecraftClient.getInstance().setScreen(new TitleScreen()); }, this.textRenderer)); } + + // Adding a button to switch themes dynamically + // This button toggles between "hack" and "particle" themes + String currentTheme = WallPaper.getTheme(); + this.addDrawableChild(ButtonWidget.builder(Text.literal("Theme: " + WallPaper.getTheme()), + onPress -> { + // Basculer entre les thèmes disponibles + String newTheme = switch (WallPaper.getTheme()) { + case "ParadiseHack" -> "ParadiseParticle"; + default -> "ParadiseHack"; + }; + + // Mettre à jour le thème dans ConfigManager et l'interface + WallPaper.setTheme(newTheme); + + // Mettre à jour le texte du bouton + onPress.setMessage(Text.literal("Theme: " + newTheme)); + }) + .width(150) + .position(this.width / 2 - 75, this.height / 4 + 160) + .build() + ); + } /** @@ -160,6 +184,8 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta, Cal this.backgroundFadeStart = Util.getMeasuringTimeMs(); } + WallPaper.render(context, this.width, this.height); + float f = 1.0F; if (this.doBackgroundFade) { float g = (float) (Util.getMeasuringTimeMs() - this.backgroundFadeStart) / 2000.0F; @@ -175,7 +201,6 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta, Cal this.setWidgetAlpha(f); } - this.renderPanoramaBackground(context, delta); int i = MathHelper.ceil(f * 255.0F) << 24; if ((i & -67108864) != 0) { super.render(context, mouseX, mouseY, delta); @@ -193,7 +218,7 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta, Cal this.realmsNotificationGui.render(context, mouseX, mouseY, delta); } } - + super.render(context, mouseX, mouseY, delta); ci.cancel(); } } From fea6b2dc77b4414f40c17731e5ec7123caad013e Mon Sep 17 00:00:00 2001 From: ZalgoDev <29240471+Zalgo-Dev@users.noreply.github.com> Date: Sun, 26 Jan 2025 05:36:20 +0100 Subject: [PATCH 2/2] Update TitleScreenMixin.java --- .../mixin/inject/gui/screen/TitleScreenMixin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/spigotrce/paradiseclientfabric/mixin/inject/gui/screen/TitleScreenMixin.java b/src/main/java/io/github/spigotrce/paradiseclientfabric/mixin/inject/gui/screen/TitleScreenMixin.java index 1279f8d..ab335be 100644 --- a/src/main/java/io/github/spigotrce/paradiseclientfabric/mixin/inject/gui/screen/TitleScreenMixin.java +++ b/src/main/java/io/github/spigotrce/paradiseclientfabric/mixin/inject/gui/screen/TitleScreenMixin.java @@ -109,7 +109,7 @@ public void init(CallbackInfo ci) { MinecraftClient.getInstance().setScreen(new TitleScreen()); }) .width(this.textRenderer.getWidth(VIAFABRICPLUS_REMINDER) + 5) - .position((this.width / 2) - ((this.textRenderer.getWidth(VIAFABRICPLUS_REMINDER) + 5) / 2), this.height / 4 + 200) + .position((this.width / 2) - ((this.textRenderer.getWidth(VIAFABRICPLUS_REMINDER) + 5) / 2), this.height / 4 + 48 + 72 + 12 + 35 + 33) .build() ); }