Skip to content

Commit

Permalink
Merge pull request #23 from Zalgo-Dev/main
Browse files Browse the repository at this point in the history
Add new theme, add theme selection button and adjust titlescreen buttons positions
  • Loading branch information
SpigotRCE authored Jan 26, 2025
2 parents 9e49833 + fea6b2d commit 3c3b29a
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand All @@ -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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
* </p>
*
* @author SpigotRCE
* @since 2.9
* </p>
*/
@SuppressWarnings("unused")
@Mixin(TitleScreen.class)
Expand Down Expand Up @@ -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 + 48 + 72 + 12 + 35 + 33)
.build()
);
}
Expand All @@ -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()
);

}

/**
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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();
}
}

0 comments on commit 3c3b29a

Please sign in to comment.