Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit 3c3b29a

Browse files
authored
Merge pull request #23 from Zalgo-Dev/main
Add new theme, add theme selection button and adjust titlescreen buttons positions
2 parents 9e49833 + fea6b2d commit 3c3b29a

File tree

4 files changed

+150
-5
lines changed

4 files changed

+150
-5
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package io.github.spigotrce.paradiseclientfabric;
2+
3+
import com.google.gson.JsonObject;
4+
import com.google.gson.JsonParser;
5+
6+
import java.io.File;
7+
import java.io.FileReader;
8+
import java.io.FileWriter;
9+
import java.io.IOException;
10+
11+
public class ConfigManager {
12+
private static final File CONFIG_FILE = new File("config/paradiseclient.json");
13+
private static JsonObject config;
14+
15+
static {
16+
loadConfig();
17+
}
18+
19+
// Charger la configuration depuis le fichier
20+
private static void loadConfig() {
21+
try {
22+
if (CONFIG_FILE.exists()) {
23+
FileReader reader = new FileReader(CONFIG_FILE);
24+
config = JsonParser.parseReader(reader).getAsJsonObject();
25+
reader.close();
26+
} else {
27+
config = new JsonObject();
28+
saveConfig();
29+
}
30+
} catch (IOException e) {
31+
config = new JsonObject();
32+
}
33+
}
34+
35+
// Sauvegarder la configuration dans le fichier
36+
private static void saveConfig() {
37+
try (FileWriter writer = new FileWriter(CONFIG_FILE)) {
38+
writer.write(config.toString());
39+
} catch (IOException e) {
40+
e.printStackTrace();
41+
}
42+
}
43+
44+
public static String getTheme() {
45+
return config.has("theme") ? config.get("theme").getAsString() : "ParadiseHack"; // ParadiseHack par défaut
46+
}
47+
48+
public static void setTheme(String theme) {
49+
config.addProperty("theme", theme); // Mise à jour
50+
saveConfig(); // Sauvegarde immédiate
51+
}
52+
53+
}

src/main/java/io/github/spigotrce/paradiseclientfabric/WallPaper.java

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,36 @@
88
public class WallPaper {
99
private static final Random random = new Random();
1010
private static final int[] drops = new int[300];
11+
private static final Particle[] particles = new Particle[100];
1112

13+
static {
14+
for (int i = 0; i < particles.length; i++) {
15+
particles[i] = new Particle();
16+
}
17+
}
18+
19+
public static String getTheme() {
20+
return ConfigManager.getTheme();
21+
}
22+
23+
public static void setTheme(String theme) {
24+
ConfigManager.setTheme(theme);
25+
}
26+
27+
/**
28+
* Rend l'arrière-plan selon le thème actuel.
29+
*/
30+
public static void render(DrawContext context, int width, int height) {
31+
String theme = getTheme(); // Récupérer le thème à partir de la configuration
32+
switch (theme) {
33+
case "ParadiseHack" -> renderMatrix(context, width, height);
34+
case "ParadiseParticle" -> renderElegantBackground(context, width, height);
35+
default -> renderMatrix(context, width, height); // Hack par défaut
36+
}
37+
}
38+
39+
40+
// Thème Hack (style Matrix)
1241
public static void renderMatrix(DrawContext context, int width, int height) {
1342
context.fillGradient(0, 0, width, height, 0xCC000000, 0xCC000000);
1443
for (int i = 0; i < drops.length; i++) {
@@ -20,4 +49,42 @@ public static void renderMatrix(DrawContext context, int width, int height) {
2049
drops[i]++;
2150
}
2251
}
52+
53+
// Thème Particle (particules dynamiques)
54+
public static void renderElegantBackground(DrawContext context, int width, int height) {
55+
context.fillGradient(0, 0, width, height, 0xFF1A237E, 0xFF882dbd); // Bleu -> Violet
56+
for (Particle particle : particles) {
57+
particle.update(width, height);
58+
context.fill(particle.x, particle.y, particle.x + 2, particle.y + 2, particle.color);
59+
}
60+
}
61+
62+
private static class Particle {
63+
int x, y, speedX, speedY, color;
64+
65+
public Particle() {
66+
reset(800, 600);
67+
}
68+
69+
public void update(int width, int height) {
70+
x += speedX;
71+
y += speedY;
72+
73+
if (x < 0 || x > width || y < 0 || y > height) {
74+
reset(width, height);
75+
}
76+
}
77+
78+
public void reset(int width, int height) {
79+
x = random.nextInt(width);
80+
y = random.nextInt(height);
81+
82+
do {
83+
speedX = -1 + random.nextInt(3); // Vitesse entre -1 et 1
84+
speedY = -1 + random.nextInt(3);
85+
} while (speedX == 0 && speedY == 0);
86+
87+
color = 0xFFFFFFFF; // Blanc
88+
}
89+
}
2390
}

src/main/java/io/github/spigotrce/paradiseclientfabric/mixin/inject/gui/screen/ScreenMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public abstract class ScreenMixin {
3535
*/
3636
@Inject(method = "renderBackground", at = @At(value = "HEAD"), cancellable = true)
3737
private void renderBackground(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) {
38-
WallPaper.renderMatrix(context, width, height);
38+
WallPaper.render(context, width, height);
3939
ci.cancel();
4040
}
4141
}

src/main/java/io/github/spigotrce/paradiseclientfabric/mixin/inject/gui/screen/TitleScreenMixin.java

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import io.github.spigotrce.paradiseclientfabric.Constants;
55
import io.github.spigotrce.paradiseclientfabric.Helper;
66
import io.github.spigotrce.paradiseclientfabric.ParadiseClient_Fabric;
7+
import io.github.spigotrce.paradiseclientfabric.WallPaper;
78
import net.fabricmc.loader.api.FabricLoader;
89
import net.minecraft.client.MinecraftClient;
910
import net.minecraft.client.gui.DrawContext;
@@ -32,10 +33,10 @@
3233
* This class modifies the Title Screen to include a custom button recommending
3334
* the installation of "ViaFabricPlus" and customizes the background fade effect.
3435
* It also displays additional information about the client and game version.
36+
* </p>
3537
*
3638
* @author SpigotRCE
3739
* @since 2.9
38-
* </p>
3940
*/
4041
@SuppressWarnings("unused")
4142
@Mixin(TitleScreen.class)
@@ -108,7 +109,7 @@ public void init(CallbackInfo ci) {
108109
MinecraftClient.getInstance().setScreen(new TitleScreen());
109110
})
110111
.width(this.textRenderer.getWidth(VIAFABRICPLUS_REMINDER) + 5)
111-
.position((this.width / 2) - ((this.textRenderer.getWidth(VIAFABRICPLUS_REMINDER) + 5) / 2), this.height / 4 + 48 + 72 + 12 + 35)
112+
.position((this.width / 2) - ((this.textRenderer.getWidth(VIAFABRICPLUS_REMINDER) + 5) / 2), this.height / 4 + 48 + 72 + 12 + 35 + 33)
112113
.build()
113114
);
114115
}
@@ -121,6 +122,29 @@ public void init(CallbackInfo ci) {
121122
MinecraftClient.getInstance().setScreen(new TitleScreen());
122123
}, this.textRenderer));
123124
}
125+
126+
// Adding a button to switch themes dynamically
127+
// This button toggles between "hack" and "particle" themes
128+
String currentTheme = WallPaper.getTheme();
129+
this.addDrawableChild(ButtonWidget.builder(Text.literal("Theme: " + WallPaper.getTheme()),
130+
onPress -> {
131+
// Basculer entre les thèmes disponibles
132+
String newTheme = switch (WallPaper.getTheme()) {
133+
case "ParadiseHack" -> "ParadiseParticle";
134+
default -> "ParadiseHack";
135+
};
136+
137+
// Mettre à jour le thème dans ConfigManager et l'interface
138+
WallPaper.setTheme(newTheme);
139+
140+
// Mettre à jour le texte du bouton
141+
onPress.setMessage(Text.literal("Theme: " + newTheme));
142+
})
143+
.width(150)
144+
.position(this.width / 2 - 75, this.height / 4 + 160)
145+
.build()
146+
);
147+
124148
}
125149

126150
/**
@@ -160,6 +184,8 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta, Cal
160184
this.backgroundFadeStart = Util.getMeasuringTimeMs();
161185
}
162186

187+
WallPaper.render(context, this.width, this.height);
188+
163189
float f = 1.0F;
164190
if (this.doBackgroundFade) {
165191
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
175201
this.setWidgetAlpha(f);
176202
}
177203

178-
this.renderPanoramaBackground(context, delta);
179204
int i = MathHelper.ceil(f * 255.0F) << 24;
180205
if ((i & -67108864) != 0) {
181206
super.render(context, mouseX, mouseY, delta);
@@ -193,7 +218,7 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta, Cal
193218
this.realmsNotificationGui.render(context, mouseX, mouseY, delta);
194219
}
195220
}
196-
221+
super.render(context, mouseX, mouseY, delta);
197222
ci.cancel();
198223
}
199224
}

0 commit comments

Comments
 (0)