diff --git a/README.md b/README.md index 5878573..b3556dc 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,20 @@ # GastinelClient -Mod **côté client** pour NeoForge 1.21.1 (testé avec NeoForge 21.1.234). Il remplace l'écran d'accueil et le menu pause de Minecraft par des écrans aux couleurs de Gastinel. NeoForge n'est pas modifié : le mod écoute `ScreenEvent.Opening` et ouvre ses propres écrans à la place de `TitleScreen` et de `PauseScreen`. +Mod **côté client** pour NeoForge 1.21.1 (testé avec NeoForge 21.1.234). Branche `design/style-c` : proposition C « vanilla épurée ». Les menus restent ceux de Minecraft (disposition, police pixel) ; le mod change leur style par ses ressources et y ajoute seulement ce qui sert à Gastinel. Le serveur n'a pas besoin du mod (`displayTest="IGNORE_ALL_VERSION"`), et un joueur sans le mod peut se connecter. -## Écrans +## Ce que fait le mod -| Écran | Contenu | +| Écran | Changement | |---|---| -| Accueil | Solo · **Serveur Gastinel** (un clic, avec l'état en direct : « En ligne · 0/20 joueur · 15 ms ») · Autres serveurs · Options · Quitter. En pied de page : versions, lien « Mods ». | -| Autres serveurs | Une case d'adresse (Rejoindre / Enregistrer, Entrée = rejoindre), la liste des serveurs enregistrés (un clic pour rejoindre, avec des pages s'il y en a beaucoup) et un lien vers la liste complète de Minecraft pour modifier ou supprimer. Le serveur Gastinel n'y figure pas, puisqu'il est déjà sur l'accueil. | -| Options | Deux colonnes avec des boutons − / + : distance d'affichage, champ de vision, luminosité, taille de l'interface, plein écran, synchro verticale, volumes (général, musique, blocs), sensibilité de la souris. Un lien mène à toutes les options de Minecraft. | -| Pause | Un panneau papier à gauche, le monde visible à droite (sans flou) : Reprendre (avec le nom du monde ou du serveur), Options, Progrès, Statistiques, Ouvrir en réseau local (en solo), Mods, Sauvegarder et quitter / Se déconnecter (retour à l'accueil Gastinel). | +| Tous | Boutons et curseurs en aplats sombres translucides à filet clair, sans arrondi (sprites `widget/button*` et `widget/slider*` dans `assets/minecraft/`, prioritaires sur ceux de Minecraft). Aucun code. | +| Accueil | Le logo devient le mot « GASTINEL » en police Minecraft ; phrases d'accueil Gastinel (`texts/splashes.txt`) ; Realms retiré ; bouton **Serveur Gastinel** en tête, filet orange, état en direct (« ■ 3/20 · 15 ms » ou « hors ligne »). | +| Multijoueur | Au premier lancement, le serveur Gastinel est ajouté à la liste ; il est ensuite toujours remis en tête, avec un filet orange. S'il est supprimé, il n'est pas rajouté. | +| Options | Écran de Minecraft, plus un bouton « Réglages essentiels… » (distance, champ de vision, luminosité, sensibilité, plein écran, synchro, volumes) avec les curseurs de Minecraft. | +| Pause | Écran de Minecraft sans « Donner son avis » ni « Signaler un bug », avec un bouton « Serveur Gastinel » (sauvegarde le monde puis rejoint le serveur ; absent si on y est déjà) et « GASTINEL » discret en bas à droite. | -Les captures sont dans `livrable/captures/`. - -## Charte (proposition A « sobre », branche `design/propositions`) - -- Fond blanc `#FFFFFF` (alterné `#F4F4F4`), encre `#111111`, gris `#6B6B6B`, filets `#D9D9D9` (fort : 2 px d'encre au-dessus des listes). Valeurs de la charte relevée (Mind, météo, Hub). -- Police Inter (TTF fournie dans le mod, licence OFL : `LICENCE-INTER-OFL.txt`). Grands titres en Inter SemiBold suréchantillonnée ; étiquettes en capitales espacées. -- Aucun arrondi, aucune texture vanilla, plus d'image de fond. Les menus sont des listes numérotées séparées par des filets ; l'action principale est une ligne pleine à l'encre. -- La couleur ne sert que de signal, toujours avec un texte : succès `#1A5C2A` sur `#F0F7F0`, alerte `#8A1C1C` sur `#FDF2F2`. -- Accueil : à droite, l'état du serveur en grands chiffres (joueurs, latence, version, adresse), masqué si l'écran est étroit. -- Les deux autres propositions (B, C) et les maquettes sont dans `propositions/`. +Captures en jeu : `propositions/C/en-jeu/`. ## Configuration @@ -31,8 +23,9 @@ Les captures sont dans `livrable/captures/`. ```toml serveurNom = "Serveur Gastinel" serveurAdresse = "gastinel.me:25565" -remplacerAccueil = true -remplacerPause = true +habillerAccueil = true +habillerPause = true +serveurAjoute = false ``` Si l'adresse figure déjà dans la liste multijoueur, l'accueil reprend cette entrée, ce qui conserve le choix fait pour le pack de ressources. @@ -49,10 +42,13 @@ Sur cornafserver : `sh outils/client-xvfb.sh`. Le script lance le client de dév ``` src/main/java/com/gastinelclient/ - GastinelClient.java @Mod(dist = CLIENT), remplacement des écrans - Config.java config client - core/Libelles.java textes et calculs purs (testés) - ui/Charte.java couleurs, polices, fond, filets - ui/Bouton.java bouton plat (MENU, PRIMAIRE, CADRE, LIEN) - ecrans/ Accueil, Serveurs, OptionsSimples, PauseGastinel, base EcranGastinel + GastinelClient.java @Mod(dist = CLIENT), branche les événements d'écran + Config.java config client + core/Libelles.java textes et calculs purs (testés) + ecrans/Habillage.java ajouts sur l'accueil, la pause, les options, la liste multijoueur + ecrans/BoutonServeur.java bouton « Serveur Gastinel » avec ping + ecrans/Gastinel.java entrée du serveur, épinglage, connexion + ecrans/OptionsSimplesScreen réglages essentiels (OptionsSubScreen de Minecraft) +src/main/resources/assets/minecraft/ sprites et textes qui remplacent ceux de Minecraft +outils/sprites-c.py régénère les sprites (Python, sans dépendance) ``` diff --git a/gradle.properties b/gradle.properties index da0522a..582e77f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ org.gradle.jvmargs=-Xmx2G org.gradle.parallel=true -mod_version=0.2.0 +mod_version=0.3.0-c mod_group_id=com.gastinelclient mod_id=gastinelclient diff --git a/outils/client-xvfb.sh b/outils/client-xvfb.sh index e0e077a..b457155 100644 --- a/outils/client-xvfb.sh +++ b/outils/client-xvfb.sh @@ -1,5 +1,5 @@ #!/bin/sh -# Lance le client de dev dans un conteneur jetable « gc-test », SANS carte graphique +# Lance le client de dev dans un conteneur jetable « gc-test » (autre nom : NOM=… sh outils/client-xvfb.sh), SANS carte graphique # (Xvfb + Mesa llvmpipe : rendu 100 % CPU). Le conteneur reste en vie pour piloter le jeu : # docker exec gc-test sh -c 'DISPLAY=:99 import -window root /src/captures/x.png' # docker exec gc-test sh -c 'DISPLAY=:99 xdotool mousemove 200 500 click 1' @@ -7,8 +7,8 @@ set -e cd "$(dirname "$0")/.." mkdir -p captures "$HOME/.cache/gastinelclient-gradle" -docker rm -f gc-test >/dev/null 2>&1 || true -docker run -d --name gc-test --memory 8g --cpus 4 --cpu-shares 256 \ +docker rm -f "${NOM:-gc-test}" >/dev/null 2>&1 || true +docker run -d --name "${NOM:-gc-test}" --memory 8g --cpus 4 --cpu-shares 256 \ -e GRADLE_USER_HOME=/gradle-home -e U="$(id -u)" -e G="$(id -g)" \ -v "$HOME/.cache/gastinelclient-gradle:/gradle-home" \ -v "$(pwd):/src" -w /src \ @@ -22,4 +22,4 @@ echo pret > /tmp/x11 setpriv --reuid=$U --regid=$G --clear-groups env HOME=/tmp sh ./gradlew --no-daemon runClient > captures/run.log 2>&1 echo arrete >> captures/run.log sleep 100000' -echo "conteneur gc-test lancé" +echo "conteneur ${NOM:-gc-test} lancé" diff --git a/outils/sprites-c.py b/outils/sprites-c.py new file mode 100644 index 0000000..f12d0ba --- /dev/null +++ b/outils/sprites-c.py @@ -0,0 +1,40 @@ +"""Génère les sprites de la proposition C (boutons et curseurs plats, logo vide) sans dépendance. +Usage : python outils/sprites-c.py (écrit dans src/main/resources/assets/minecraft/textures/gui)""" +import json, os, struct, zlib + +RACINE = os.path.join(os.path.dirname(__file__), "..", "src", "main", "resources", "assets", "minecraft", "textures", "gui") + +def png(chemin, l, h, pixel): + brut = b"".join(b"\x00" + b"".join(bytes(pixel(x, y)) for x in range(l)) for y in range(h)) + def bloc(t, d): + return struct.pack(">I", len(d)) + t + d + struct.pack(">I", zlib.crc32(t + d) & 0xFFFFFFFF) + os.makedirs(os.path.dirname(chemin), exist_ok=True) + with open(chemin, "wb") as f: + f.write(b"\x89PNG\r\n\x1a\n" + bloc(b"IHDR", struct.pack(">IIBBBBB", l, h, 8, 6, 0, 0, 0)) + + bloc(b"IDAT", zlib.compress(brut, 9)) + bloc(b"IEND", b"")) + +def aplat(fond, filet): + def p(l, h): + return lambda x, y: filet if x in (0, l - 1) or y in (0, h - 1) else fond + return p + +def sprite(nom, l, h, fabrique): + chemin = os.path.join(RACINE, "sprites", "widget", nom + ".png") + png(chemin, l, h, fabrique(l, h)) + with open(chemin + ".mcmeta", "w") as f: + json.dump({"gui": {"scaling": {"type": "nine_slice", "width": l, "height": h, "border": 1}}}, f) + +NOIR = lambda a: (0, 0, 0, a) +BLANC = lambda a: (255, 255, 255, a) +# Boutons : aplat noir translucide + filet clair de 1 px de texture (3 à 4 px à l'écran), aucun arrondi. +sprite("button", 200, 20, aplat(NOIR(140), BLANC(60))) +sprite("button_highlighted", 200, 20, aplat(NOIR(170), BLANC(255))) +sprite("button_disabled", 200, 20, aplat(NOIR(90), BLANC(25))) +# Curseurs : même piste que les boutons, poignée claire pleine. +sprite("slider", 200, 20, aplat(NOIR(140), BLANC(60))) +sprite("slider_highlighted", 200, 20, aplat(NOIR(170), BLANC(160))) +sprite("slider_handle", 8, 20, aplat(BLANC(200), BLANC(255))) +sprite("slider_handle_highlighted", 8, 20, aplat(BLANC(255), BLANC(255))) +# Logo Minecraft et « Java Edition » vides : le mot GASTINEL est écrit par le mod en police Minecraft. +for nom, l, h in (("minecraft", 256, 64), ("minceraft", 256, 64), ("edition", 128, 16)): + png(os.path.join(RACINE, "title", nom + ".png"), l, h, lambda x, y: (0, 0, 0, 0)) diff --git a/propositions/C/en-jeu/c-01-accueil.png b/propositions/C/en-jeu/c-01-accueil.png new file mode 100644 index 0000000..69cc8ff Binary files /dev/null and b/propositions/C/en-jeu/c-01-accueil.png differ diff --git a/propositions/C/en-jeu/c-02-accueil-survol.png b/propositions/C/en-jeu/c-02-accueil-survol.png new file mode 100644 index 0000000..ae3a249 Binary files /dev/null and b/propositions/C/en-jeu/c-02-accueil-survol.png differ diff --git a/propositions/C/en-jeu/c-03-solo.png b/propositions/C/en-jeu/c-03-solo.png new file mode 100644 index 0000000..9067acc Binary files /dev/null and b/propositions/C/en-jeu/c-03-solo.png differ diff --git a/propositions/C/en-jeu/c-04-multijoueur.png b/propositions/C/en-jeu/c-04-multijoueur.png new file mode 100644 index 0000000..3030763 Binary files /dev/null and b/propositions/C/en-jeu/c-04-multijoueur.png differ diff --git a/propositions/C/en-jeu/c-05-options.png b/propositions/C/en-jeu/c-05-options.png new file mode 100644 index 0000000..32bec9e Binary files /dev/null and b/propositions/C/en-jeu/c-05-options.png differ diff --git a/propositions/C/en-jeu/c-06-reglages-essentiels.png b/propositions/C/en-jeu/c-06-reglages-essentiels.png new file mode 100644 index 0000000..2107930 Binary files /dev/null and b/propositions/C/en-jeu/c-06-reglages-essentiels.png differ diff --git a/propositions/C/en-jeu/c-07-pause.png b/propositions/C/en-jeu/c-07-pause.png new file mode 100644 index 0000000..6075452 Binary files /dev/null and b/propositions/C/en-jeu/c-07-pause.png differ diff --git a/propositions/C/en-jeu/c-08-pause-survol.png b/propositions/C/en-jeu/c-08-pause-survol.png new file mode 100644 index 0000000..21d202d Binary files /dev/null and b/propositions/C/en-jeu/c-08-pause-survol.png differ diff --git a/src/main/java/com/gastinelclient/Config.java b/src/main/java/com/gastinelclient/Config.java index 5cbe2f5..8737b41 100644 --- a/src/main/java/com/gastinelclient/Config.java +++ b/src/main/java/com/gastinelclient/Config.java @@ -10,14 +10,17 @@ public final class Config { .comment("Nom affiché pour le serveur principal") .define("serveurNom", "Serveur Gastinel"); public static final ModConfigSpec.ConfigValue SERVEUR_ADRESSE = B - .comment("Adresse du serveur principal (bouton « Serveur Gastinel » de l'accueil)") + .comment("Adresse du serveur principal (bouton « Serveur Gastinel »)") .define("serveurAdresse", "gastinel.me:25565"); public static final ModConfigSpec.BooleanValue ACCUEIL = B - .comment("Remplacer l'écran d'accueil de Minecraft") - .define("remplacerAccueil", true); + .comment("Ajouts Gastinel sur l'écran d'accueil de Minecraft (bouton serveur, titre, sans Realms)") + .define("habillerAccueil", true); public static final ModConfigSpec.BooleanValue PAUSE = B - .comment("Remplacer le menu pause de Minecraft") - .define("remplacerPause", true); + .comment("Ajouts Gastinel sur le menu pause de Minecraft") + .define("habillerPause", true); + public static final ModConfigSpec.BooleanValue AJOUTE = B + .comment("Le serveur Gastinel a déjà été ajouté à la liste multijoueur (on ne le rajoute pas s'il a été supprimé)") + .define("serveurAjoute", false); public static final ModConfigSpec SPEC = B.build(); @@ -28,4 +31,9 @@ public final class Config { public static String adresse() { try { return SERVEUR_ADRESSE.get(); } catch (IllegalStateException e) { return SERVEUR_ADRESSE.getDefault(); } } public static boolean accueil() { try { return ACCUEIL.get(); } catch (IllegalStateException e) { return true; } } public static boolean pause() { try { return PAUSE.get(); } catch (IllegalStateException e) { return true; } } + public static boolean ajoute() { try { return AJOUTE.get(); } catch (IllegalStateException e) { return true; } } + + public static void marquerAjoute() { + try { AJOUTE.set(true); SPEC.save(); } catch (IllegalStateException ignore) { /* config pas encore chargée */ } + } } diff --git a/src/main/java/com/gastinelclient/GastinelClient.java b/src/main/java/com/gastinelclient/GastinelClient.java index e01a13e..10aff9f 100644 --- a/src/main/java/com/gastinelclient/GastinelClient.java +++ b/src/main/java/com/gastinelclient/GastinelClient.java @@ -1,22 +1,17 @@ package com.gastinelclient; -import com.gastinelclient.ecrans.AccueilScreen; -import com.gastinelclient.ecrans.PauseGastinel; -import net.minecraft.client.gui.screens.PauseScreen; -import net.minecraft.client.gui.screens.Screen; -import net.minecraft.client.gui.screens.TitleScreen; +import com.gastinelclient.ecrans.Habillage; import net.neoforged.api.distmarker.Dist; import net.neoforged.bus.api.IEventBus; import net.neoforged.fml.ModContainer; import net.neoforged.fml.common.Mod; import net.neoforged.fml.config.ModConfig; -import net.neoforged.neoforge.client.event.ScreenEvent; import net.neoforged.neoforge.common.NeoForge; /** - * GastinelClient : remplace l'écran d'accueil et le menu pause par les écrans Gastinel. - * On ne modifie pas NeoForge : on intercepte simplement l'ouverture des écrans vanilla - * (ScreenEvent.Opening) et on en ouvre un autre à la place. + * GastinelClient, proposition C « vanilla épurée » : les écrans restent ceux de Minecraft. + * Le style (boutons sombres plats, logo) vient des ressources du mod, qui passent devant celles de Minecraft ; + * le code ajoute seulement le bouton « Serveur Gastinel », retire Realms et épingle le serveur dans la liste. */ @Mod(value = GastinelClient.MODID, dist = Dist.CLIENT) public final class GastinelClient { @@ -24,18 +19,9 @@ public final class GastinelClient { public GastinelClient(IEventBus modBus, ModContainer container) { container.registerConfig(ModConfig.Type.CLIENT, Config.SPEC); - NeoForge.EVENT_BUS.addListener(GastinelClient::avantOuverture); - } - - private static void avantOuverture(ScreenEvent.Opening e) { - Screen s = e.getNewScreen(); - if (s == null) return; - // Classe exacte : on ne remplace pas un écran d'un autre mod qui hériterait de TitleScreen. - if (s.getClass() == TitleScreen.class && Config.accueil()) { - e.setNewScreen(new AccueilScreen()); - } else if (s.getClass() == PauseScreen.class && ((PauseScreen) s).showsPauseMenu() && Config.pause()) { - // showsPauseMenu() == false : pause « silencieuse » (F3+Échap), on la laisse telle quelle. - e.setNewScreen(new PauseGastinel()); - } + NeoForge.EVENT_BUS.addListener(Habillage::avantOuverture); + NeoForge.EVENT_BUS.addListener(Habillage::apresInit); + NeoForge.EVENT_BUS.addListener(Habillage::apresRendu); + NeoForge.EVENT_BUS.addListener(Habillage::fermeture); } } diff --git a/src/main/java/com/gastinelclient/core/Libelles.java b/src/main/java/com/gastinelclient/core/Libelles.java index 6fa4947..8b3f0f8 100644 --- a/src/main/java/com/gastinelclient/core/Libelles.java +++ b/src/main/java/com/gastinelclient/core/Libelles.java @@ -6,12 +6,10 @@ import java.util.Locale; public final class Libelles { private Libelles() {} - /** « En ligne · 3/20 joueurs · 12 ms » ; singulier pour 0 ou 1 joueur. */ - public static String enLigne(int joueurs, int max, long pingMs) { - String j = joueurs <= 1 ? "joueur" : "joueurs"; - StringBuilder sb = new StringBuilder("En ligne · ").append(joueurs); + /** État court pour le bouton « Serveur Gastinel » : « 3/20 · 12 ms ». */ + public static String etatCourt(int joueurs, int max, long pingMs) { + StringBuilder sb = new StringBuilder().append(joueurs); if (max > 0) sb.append('/').append(max); - sb.append(' ').append(j); if (pingMs >= 0) sb.append(" · ").append(pingMs).append(" ms"); return sb.toString(); } @@ -31,24 +29,16 @@ public final class Libelles { return s.endsWith(":25565") ? s.substring(0, s.length() - 6) : s; } - /** Pourcentage arrondi : 0.456 → « 46 % » (espace insécable fine à la française). */ - public static String pourcent(double v) { - return Math.round(Math.max(0, Math.min(1, v)) * 100) + " %"; + /** Même serveur, port par défaut ou non, sans tenir compte de la casse. */ + public static boolean memeServeur(String a, String b) { + return adresseCourte(a).equalsIgnoreCase(adresseCourte(b)) && !adresseCourte(a).isEmpty(); } - /** Ajoute un pas à une valeur dans [0, 1] en évitant les 0.30000000000000004. */ - public static double pas01(double v, double pas) { - double r = Math.round((v + pas) * 100.0) / 100.0; - return Math.max(0, Math.min(1, r)); - } - - public static int borne(int v, int min, int max) { - return Math.max(min, Math.min(max, v)); - } - - /** Position de v entre min et max, ramenée dans [0, 1] (pour une jauge). */ - public static double fraction(int v, int min, int max) { - if (max <= min) return 0; - return Math.max(0, Math.min(1, (v - min) / (double) (max - min))); + /** Nouvelle position des éléments d'une liste après avoir amené l'élément « i » en tête (ordre des autres conservé). */ + public static int[] ordreEpingle(int taille, int i) { + int[] r = new int[taille]; + r[0] = i; + for (int k = 0, j = 1; k < taille; k++) if (k != i) r[j++] = k; + return r; } } diff --git a/src/main/java/com/gastinelclient/ecrans/AccueilScreen.java b/src/main/java/com/gastinelclient/ecrans/AccueilScreen.java deleted file mode 100644 index 3e829a8..0000000 --- a/src/main/java/com/gastinelclient/ecrans/AccueilScreen.java +++ /dev/null @@ -1,188 +0,0 @@ -package com.gastinelclient.ecrans; - -import com.gastinelclient.Config; -import com.gastinelclient.core.Libelles; -import com.gastinelclient.ui.Bouton; -import com.gastinelclient.ui.Charte; -import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.gui.screens.ConnectScreen; -import net.minecraft.client.gui.screens.Screen; -import net.minecraft.client.gui.screens.worldselection.SelectWorldScreen; -import net.minecraft.client.multiplayer.ServerData; -import net.minecraft.client.multiplayer.ServerList; -import net.minecraft.client.multiplayer.ServerStatusPinger; -import net.minecraft.client.multiplayer.resolver.ServerAddress; -import net.neoforged.neoforge.client.gui.ModListScreen; - -import java.net.UnknownHostException; - -/** - * Écran d'accueil Gastinel : Solo, Serveur Gastinel (un clic), Autres serveurs, Options, Quitter. - * Le bouton du serveur affiche son état en direct (ping comme la liste multijoueur vanilla) ; - * sur un écran assez large, un panneau à droite le détaille en grands chiffres (proposition A). - */ -public class AccueilScreen extends EcranGastinel { - private final ServerStatusPinger pinger = new ServerStatusPinger(); - private ServerData gastinel; - private volatile String etat = "Recherche du serveur…"; - private volatile int couleurEtat = Charte.DOUX; - - public AccueilScreen() { - super("Accueil", null); - } - - private int hautBloc() { - return Math.max(34, (this.height - 24 - 168) / 2 + 12); - } - - @Override - protected void init() { - this.gastinel = serveurGastinel(); - int m = marge(), l = colonne(); - int y = hautBloc() + 58; - - addRenderableWidget(new Bouton(m, y, l, 30, Config.nom(), Bouton.Genre.PRIMAIRE, this::rejoindreGastinel) - .numero(1).sousTitre(this::sousTitreServeur, () -> Charte.CLAIR).pastille(() -> enLigne() ? Charte.PASTILLE : null)); - y += 30; - addRenderableWidget(new Bouton(m, y, l, 20, "Solo", Bouton.Genre.MENU, - () -> this.minecraft.setScreen(new SelectWorldScreen(this))).numero(2)); - y += 20; - addRenderableWidget(new Bouton(m, y, l, 20, "Autres serveurs", Bouton.Genre.MENU, - () -> this.minecraft.setScreen(new ServeursScreen(this))).numero(3)); - y += 20; - addRenderableWidget(new Bouton(m, y, l, 20, "Options", Bouton.Genre.MENU, - () -> this.minecraft.setScreen(new OptionsSimplesScreen(this))).numero(4)); - y += 20; - addRenderableWidget(new Bouton(m, y, l, 20, "Quitter", Bouton.Genre.MENU, () -> this.minecraft.stop()).numero(5)); - - String mods = "Mods"; - lien(this.width - m - this.font.width(Charte.txt(mods)), this.height - 16, mods, - () -> this.minecraft.setScreen(new ModListScreen(this))); - - // Relancé à chaque retour sur l'accueil : l'état affiché reste frais. - etat = "Recherche du serveur…"; - couleurEtat = Charte.DOUX; - lancerPing(); - } - - private boolean enLigne() { - ServerData d = this.gastinel; - return d != null && d.players != null; - } - - /** Reprend l'entrée de la liste multijoueur si elle existe (garde le choix du pack de ressources). */ - private ServerData serveurGastinel() { - String adr = Libelles.nettoyerAdresse(Config.adresse()); - ServerList liste = new ServerList(this.minecraft); - liste.load(); - for (int i = 0; i < liste.size(); i++) { - ServerData d = liste.get(i); - if (Libelles.nettoyerAdresse(d.ip).equalsIgnoreCase(adr) - || Libelles.adresseCourte(d.ip).equalsIgnoreCase(Libelles.adresseCourte(adr))) { - return d; - } - } - return new ServerData(Config.nom(), adr, ServerData.Type.OTHER); - } - - private void lancerPing() { - ServerData d = this.gastinel; - Thread t = new Thread(() -> { - try { - pinger.pingServer(d, () -> {}, () -> { etat = "Hors ligne pour le moment"; couleurEtat = Charte.ALERTE; }); - } catch (UnknownHostException e) { - etat = "Adresse introuvable"; - couleurEtat = Charte.ALERTE; - } catch (Exception e) { - etat = "Hors ligne pour le moment"; - couleurEtat = Charte.ALERTE; - } - }, "GastinelClient ping"); - t.setDaemon(true); - t.start(); - } - - private String sousTitreServeur() { - ServerData d = this.gastinel; - if (d != null && d.players != null) { - couleurEtat = Charte.SUCCES; - return Libelles.enLigne(d.players.online(), d.players.max(), d.ping); - } - return etat; - } - - private void rejoindreGastinel() { - ServerData d = this.gastinel; - ConnectScreen.startConnecting(this, this.minecraft, ServerAddress.parseString(d.ip), d, false, null); - } - - @Override - public void tick() { - pinger.tick(); - } - - @Override - public void removed() { - pinger.removeAll(); - } - - @Override - public boolean shouldCloseOnEsc() { - return false; - } - - @Override - public void render(GuiGraphics g, int mx, int my, float pt) { - super.render(g, mx, my, pt); - int m = marge(), l = colonne(); - int y = hautBloc(); - barre(g, m, this.width, null); - Charte.etiquette(g, this.font, "Serveur Minecraft", m, y, Charte.DOUX); - Charte.grandTitre(g, this.font, "Gastinel", m - 2, y + 12, 4f, Charte.ENCRE); - Charte.filet(g, m, m + l, y + 57, Charte.ENCRE); - Charte.filet(g, m, m + l, y + 56, Charte.ENCRE); // filet fort de 2 px au-dessus de la liste - panneauEtat(g, m, l, y); - piedDePage(g); - } - - /** Panneau de droite : état du serveur en grands chiffres. Masqué si l'écran est trop étroit. */ - private void panneauEtat(GuiGraphics g, int m, int l, int y) { - int xs = m + l + m; - int x = xs + m, larg = this.width - m - x; - if (larg < 150) return; - g.fill(xs, 25, xs + 1, this.height - 22, Charte.FILET); - Charte.etiquette(g, this.font, "État du serveur · en direct", x, y, Charte.DOUX); - ServerData d = this.gastinel; - boolean ok = enLigne(); - String grand = ok ? String.valueOf(d.players.online()) : "—"; - Charte.grandTitre(g, this.font, grand, x - 2, y + 16, 6f, Charte.ENCRE); - int lg = (int) (this.font.width(Charte.titre(grand)) * 6f); - if (ok) { - Charte.texte(g, this.font, Charte.gras("/ " + d.players.max() + (d.players.max() > 1 ? " joueurs" : " joueur")), - x + lg + 6, y + 56, Charte.ENCRE); - } - // Signal : texte coloré sur fond pâle, jamais la couleur seule. - String sig = ok ? "En ligne" : etat; - int ls = this.font.width(Charte.gras(sig)) + 10, sy = y + 76; - g.fill(x, sy, x + ls, sy + 14, ok ? Charte.SUCCES_FOND : (couleurEtat == Charte.ALERTE ? Charte.ALERTE_FOND : Charte.ALTERNE)); - Charte.texte(g, this.font, Charte.gras(sig), x + 5, sy + 3, ok ? Charte.SUCCES : couleurEtat); - // Trois cases séparées par des filets - int cy = sy + 30, lc = Math.min(90, larg * 2 / 7); // la 3e case (adresse) prend le reste - Charte.filet(g, x, x + larg, cy, Charte.FILET); - String[][] cases = { - {"Latence", ok && d.ping >= 0 ? d.ping + " ms" : "—"}, - {"Version", d != null && d.version != null && ok ? d.version.getString() : "1.21.1"}, - {"Adresse", Libelles.adresseCourte(d != null ? d.ip : Config.adresse())}}; - for (int i = 0; i < 3; i++) { - int cx = x + i * lc; - if (i > 0) g.fill(cx - 8, cy, cx - 7, cy + 40, Charte.FILET); - Charte.etiquette(g, this.font, cases[i][0], cx, cy + 10, Charte.DOUX); - String v = cases[i][1]; - // Valeur venue du serveur (ping) : bornée avant la boucle, sinon une chaîne énorme la rend coûteuse à chaque image. - if (v.length() > 32) v = v.substring(0, 32); - int lv = i < 2 ? lc - 12 : larg - 2 * lc; - while (v.length() > 1 && this.font.width(Charte.titre(v)) * 1.5f > lv) v = v.substring(0, v.length() - 1); - Charte.grandTitre(g, this.font, v, cx, cy + 24, 1.5f, Charte.ENCRE); - } - } -} diff --git a/src/main/java/com/gastinelclient/ecrans/BoutonServeur.java b/src/main/java/com/gastinelclient/ecrans/BoutonServeur.java new file mode 100644 index 0000000..2bec74b --- /dev/null +++ b/src/main/java/com/gastinelclient/ecrans/BoutonServeur.java @@ -0,0 +1,81 @@ +package com.gastinelclient.ecrans; + +import com.gastinelclient.Config; +import com.gastinelclient.core.Libelles; +import com.mojang.blaze3d.systems.RenderSystem; +import net.minecraft.ChatFormatting; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.components.Button; +import net.minecraft.client.multiplayer.ServerData; +import net.minecraft.client.multiplayer.ServerStatusPinger; +import net.minecraft.network.chat.Component; +import net.minecraft.util.Mth; + +/** + * Bouton « Serveur Gastinel » de l'accueil : bouton vanilla (donc restylé par le pack intégré) + * avec un filet orange et l'état du serveur en direct (ping comme la liste multijoueur). + */ +public class BoutonServeur extends Button { + /** Un seul ping à la fois, gardé tant que l'accueil reste ouvert (même après un redimensionnement). */ + private static Etat etat; + + public BoutonServeur(int x, int y, int l, int h) { + super(x, y, l, h, Component.literal(Config.nom()), b -> Gastinel.rejoindre(Minecraft.getInstance(), Minecraft.getInstance().screen), + DEFAULT_NARRATION); + if (etat == null) etat = new Etat(Gastinel.serveur(Minecraft.getInstance())); + } + + public static void fermer() { + if (etat != null) etat.pinger.removeAll(); + etat = null; + } + + @Override + protected void renderWidget(GuiGraphics g, int mx, int my, float pt) { + if (etat != null) { + etat.pinger.tick(); + setMessage(Component.literal(Config.nom() + " ").append(etat.libelle())); + } + g.setColor(1f, 1f, 1f, this.alpha); + RenderSystem.enableBlend(); + RenderSystem.enableDepthTest(); + g.blitSprite(SPRITES.get(this.active, this.isHoveredOrFocused()), getX(), getY(), getWidth(), getHeight()); + g.setColor(1f, 1f, 1f, 1f); + int a = Mth.ceil(this.alpha * 255f) << 24; + g.fill(getX() + 1, getY() + 1, getRight() - 1, getBottom() - 1, (Gastinel.ORANGE & 0xFFFFFF) | (Mth.ceil(this.alpha * 0x30) << 24)); + g.renderOutline(getX(), getY(), getWidth(), getHeight(), (Gastinel.ORANGE & 0xFFFFFF) | a); + renderString(g, Minecraft.getInstance().font, 0xFFFFFF | a); + } + + private static final class Etat { + final ServerStatusPinger pinger = new ServerStatusPinger(); + final ServerData d; + volatile Component repli = Component.literal("…").withStyle(ChatFormatting.GRAY); + + Etat(ServerData d) { + this.d = d; + Thread t = new Thread(() -> { + try { + pinger.pingServer(d, () -> {}, () -> repli = horsLigne()); + } catch (Exception e) { + repli = horsLigne(); + } + }, "GastinelClient ping"); + t.setDaemon(true); + t.start(); + } + + static Component horsLigne() { + return Component.literal("hors ligne").withStyle(ChatFormatting.GRAY); + } + + Component libelle() { + if (d.players != null) { + return Component.literal("■ ").withStyle(ChatFormatting.GREEN) + .append(Component.literal(Libelles.etatCourt(d.players.online(), d.players.max(), d.ping)).withStyle(ChatFormatting.GRAY)); + } + return repli; + } + } +} diff --git a/src/main/java/com/gastinelclient/ecrans/EcranGastinel.java b/src/main/java/com/gastinelclient/ecrans/EcranGastinel.java deleted file mode 100644 index 8f77aab..0000000 --- a/src/main/java/com/gastinelclient/ecrans/EcranGastinel.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.gastinelclient.ecrans; - -import com.gastinelclient.ui.Bouton; -import com.gastinelclient.ui.Charte; -import net.minecraft.SharedConstants; -import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.gui.screens.Screen; -import net.minecraft.network.chat.Component; -import net.neoforged.fml.ModList; -import org.jetbrains.annotations.Nullable; - -/** Base des écrans Gastinel : fond blanc, barre du haut, en-tête, pied de page. */ -public abstract class EcranGastinel extends Screen { - @Nullable protected final Screen parent; - - protected EcranGastinel(String titre, @Nullable Screen parent) { - super(Component.literal(titre)); - this.parent = parent; - } - - protected int marge() { return Math.max(16, this.width / 16); } - - protected int colonne() { return Math.min(240, Math.max(170, (int) (this.width * 0.36f))); } - - protected Bouton lien(int x, int y, String texte, Runnable action) { - int l = this.font.width(Charte.txt(texte)); - return this.addRenderableWidget(new Bouton(x, y, l, 12, texte, Bouton.Genre.LIEN, action)); - } - - @Override - public void renderBackground(GuiGraphics g, int mx, int my, float pt) { - if (this.minecraft != null && this.minecraft.level != null) { - // En partie : voile blanc presque opaque (pas de flou), le monde reste deviné derrière. - g.fill(0, 0, this.width, this.height, 0xF5FFFFFF); - } else { - Charte.fond(g, this.width, this.height); - } - } - - /** Barre du haut : « GASTINEL / Rubrique » à gauche, filet sur toute la largeur. */ - protected void barre(GuiGraphics g, int x, int largeur, String rubrique) { - int l = Charte.etiquette(g, this.font, "Gastinel", x, 9, Charte.ENCRE); - if (rubrique != null && !rubrique.isEmpty()) { - Charte.etiquette(g, this.font, "/ " + rubrique, x + l + 4, 9, Charte.DOUX); - } - Charte.filet(g, 0, largeur, 24, Charte.FILET); - } - - /** En-tête : barre du haut + grand titre. Renvoie le y sous l'en-tête (y + 46, comme avant). */ - protected int entete(GuiGraphics g, int x, int y, String rubrique, String titre) { - barre(g, x, this.width, rubrique); - Charte.grandTitre(g, this.font, titre, x - 1, y + 18, 2f, Charte.ENCRE); - return y + 46; - } - - protected void piedDePage(GuiGraphics g) { - int m = marge(), y = this.height - 14; - Charte.filet(g, m, this.width - m, y - 8, Charte.FILET); - String v = ModList.get().getModContainerById("gastinelclient") - .map(c -> c.getModInfo().getVersion().toString()).orElse("?"); - Charte.texte(g, this.font, Charte.txt("Minecraft " + SharedConstants.getCurrentVersion().getName() - + " · GastinelClient " + v), m, y, Charte.DOUX); - } - - @Override - public void onClose() { - this.minecraft.setScreen(this.parent); - } -} diff --git a/src/main/java/com/gastinelclient/ecrans/Gastinel.java b/src/main/java/com/gastinelclient/ecrans/Gastinel.java new file mode 100644 index 0000000..fa09538 --- /dev/null +++ b/src/main/java/com/gastinelclient/ecrans/Gastinel.java @@ -0,0 +1,73 @@ +package com.gastinelclient.ecrans; + +import com.gastinelclient.Config; +import com.gastinelclient.core.Libelles; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.screens.ConnectScreen; +import net.minecraft.client.gui.screens.GenericMessageScreen; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.screens.TitleScreen; +import net.minecraft.client.multiplayer.ServerData; +import net.minecraft.client.multiplayer.ServerList; +import net.minecraft.client.multiplayer.resolver.ServerAddress; +import net.minecraft.network.chat.Component; + +/** Le serveur Gastinel : retrouver son entrée, l'épingler en tête de la liste multijoueur, le rejoindre. */ +public final class Gastinel { + public static final int ORANGE = 0xFFE8650A; + + private Gastinel() {} + + public static boolean est(String ip) { + return Libelles.memeServeur(ip, Config.adresse()); + } + + /** Reprend l'entrée de la liste multijoueur si elle existe (garde le choix du pack de ressources). */ + public static ServerData serveur(Minecraft mc) { + ServerList liste = new ServerList(mc); + liste.load(); + for (int i = 0; i < liste.size(); i++) { + if (est(liste.get(i).ip)) return liste.get(i); + } + return new ServerData(Config.nom(), Libelles.nettoyerAdresse(Config.adresse()), ServerData.Type.OTHER); + } + + /** + * Avant l'ouverture de la liste multijoueur : ajoute le serveur Gastinel au premier lancement, + * puis le garde en tête. S'il a été supprimé par le joueur, on ne le remet pas. + */ + public static void epingler(Minecraft mc) { + ServerList liste = new ServerList(mc); + liste.load(); + int i = -1; + for (int k = 0; k < liste.size(); k++) if (est(liste.get(k).ip)) { i = k; break; } + if (i < 0) { + if (Config.ajoute()) return; + liste.add(new ServerData(Config.nom(), Libelles.nettoyerAdresse(Config.adresse()), ServerData.Type.OTHER), false); + i = liste.size() - 1; + Config.marquerAjoute(); + } else if (i == 0) { + if (!Config.ajoute()) Config.marquerAjoute(); + return; + } + ServerData[] avant = new ServerData[liste.size()]; + for (int k = 0; k < avant.length; k++) avant[k] = liste.get(k); + int[] ordre = Libelles.ordreEpingle(avant.length, i); + for (int k = 0; k < avant.length; k++) liste.replace(k, avant[ordre[k]]); + liste.save(); + } + + /** Quitte la partie en cours (sauvegarde en solo, comme le menu pause vanilla) puis rejoint le serveur Gastinel. */ + public static void quitterEtRejoindre(Minecraft mc) { + boolean local = mc.isLocalServer(); + if (mc.level != null) mc.level.disconnect(); + if (local) mc.disconnect(new GenericMessageScreen(Component.translatable("menu.savingLevel"))); + else mc.disconnect(); + rejoindre(mc, new TitleScreen()); + } + + public static void rejoindre(Minecraft mc, Screen parent) { + ServerData d = serveur(mc); + ConnectScreen.startConnecting(parent, mc, ServerAddress.parseString(d.ip), d, false, null); + } +} diff --git a/src/main/java/com/gastinelclient/ecrans/Habillage.java b/src/main/java/com/gastinelclient/ecrans/Habillage.java new file mode 100644 index 0000000..99e1cd3 --- /dev/null +++ b/src/main/java/com/gastinelclient/ecrans/Habillage.java @@ -0,0 +1,192 @@ +package com.gastinelclient.ecrans; + +import com.gastinelclient.Config; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.components.AbstractWidget; +import net.minecraft.client.gui.components.Button; +import net.minecraft.client.gui.components.events.GuiEventListener; +import net.minecraft.client.gui.screens.PauseScreen; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.screens.TitleScreen; +import net.minecraft.client.gui.screens.multiplayer.JoinMultiplayerScreen; +import net.minecraft.client.gui.screens.multiplayer.ServerSelectionList; +import net.minecraft.client.gui.screens.options.OptionsScreen; +import net.minecraft.client.multiplayer.ServerData; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.contents.TranslatableContents; +import net.neoforged.neoforge.client.event.ScreenEvent; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.Map; + +/** + * Proposition C : on garde les écrans de Minecraft (restylés par les ressources du mod) + * et on y ajoute seulement ce qui sert à Gastinel. Classe exacte partout : on ne touche pas + * aux écrans d'un autre mod qui hériteraient de ceux de Minecraft. + */ +public final class Habillage { + private Habillage() {} + + // ---------------------------------------------------------------- ouverture, fermeture + + public static void avantOuverture(ScreenEvent.Opening e) { + if (e.getNewScreen() != null && e.getNewScreen().getClass() == JoinMultiplayerScreen.class) { + Gastinel.epingler(Minecraft.getInstance()); + } + } + + public static void fermeture(ScreenEvent.Closing e) { + if (e.getScreen().getClass() == TitleScreen.class) BoutonServeur.fermer(); + } + + // ---------------------------------------------------------------- init + + public static void apresInit(ScreenEvent.Init.Post e) { + Screen s = e.getScreen(); + if (s.getClass() == TitleScreen.class && Config.accueil()) accueil(e, s); + else if (s.getClass() == PauseScreen.class && ((PauseScreen) s).showsPauseMenu() && Config.pause()) pause(e, s); + else if (s.getClass() == OptionsScreen.class) options(e, s); + } + + /** Accueil : sans Realms ; « Serveur Gastinel » en tête, Solo et Multijoueur décalés d'une ligne (Mods prend la place de Realms). */ + private static void accueil(ScreenEvent.Init.Post e, Screen s) { + AbstractWidget solo = null, multi = null, realms = null; + for (GuiEventListener l : e.getListenersList()) { + if (!(l instanceof AbstractWidget w)) continue; + switch (cle(w)) { + case "menu.singleplayer" -> solo = w; + case "menu.multiplayer" -> multi = w; + case "menu.online" -> realms = w; + default -> {} + } + } + if (solo == null || multi == null) return; // mode démo ou écran modifié par un autre mod : on n'y touche pas + int y = solo.getY(); + if (realms != null) { + e.removeListener(realms); + solo.setY(y + 24); + multi.setY(y + 48); + e.addListener(new BoutonServeur(s.width / 2 - 100, y, 200, 20)); + } else { + // Pas de place libérée : le bouton se met au-dessus de Solo. + e.addListener(new BoutonServeur(s.width / 2 - 100, y - 24, 200, 20)); + } + } + + /** Ordre des demi-boutons du menu pause (les autres viennent après, dans leur ordre d'origine). */ + private static final Map ORDRE_PAUSE = Map.of( + "gui.advancements", 0, "gui.stats", 1, "fml.menu.mods", 2, + "menu.shareToLan", 3, "menu.playerReporting", 3, "menu.options", 4, "gastinel", 5); + + /** + * Pause : on retire « Donner son avis » et « Signaler un bug », on ajoute « Serveur Gastinel » + * (si on n'y est pas déjà) et on range : Retour au jeu, paires de demi-boutons, Sauvegarder et quitter. + */ + private static void pause(ScreenEvent.Init.Post e, Screen s) { + Minecraft mc = Minecraft.getInstance(); + List boutons = new ArrayList<>(); + for (GuiEventListener l : List.copyOf(e.getListenersList())) { + if (!(l instanceof Button b)) continue; + String c = cle(b); + if (c.equals("menu.sendFeedback") || c.equals("menu.reportBugs")) e.removeListener(b); + else boutons.add(b); + } + if (boutons.size() < 3) return; + boutons.sort(Comparator.comparingInt(AbstractWidget::getY).thenComparingInt(AbstractWidget::getX)); + AbstractWidget retour = boutons.remove(0), quitter = boutons.remove(boutons.size() - 1); + ServerData actuel = mc.getCurrentServer(); + Button gastinel = null; + if (actuel == null || !Gastinel.est(actuel.ip)) { + gastinel = Button.builder(Component.literal(Config.nom()), b -> Gastinel.quitterEtRejoindre(mc)).width(98).build(); + e.addListener(gastinel); + boutons.add(gastinel); + } + final Button g = gastinel; + boutons.sort(Comparator.comparingInt(w -> ORDRE_PAUSE.getOrDefault(w == g ? "gastinel" : cle(w), 9))); + + int x = s.width / 2 - 102, y = retour.getY(); + place(retour, x, y, 204); + y += 24; + for (int i = 0; i < boutons.size(); i += 2) { + if (i + 1 < boutons.size()) { + place(boutons.get(i), x, y, 98); + place(boutons.get(i + 1), x + 106, y, 98); + } else { + place(boutons.get(i), x, y, 204); + } + y += 24; + } + place(quitter, x, y + 12, 204); + } + + private static void place(AbstractWidget w, int x, int y, int l) { + w.setX(x); + w.setY(y); + w.setWidth(l); + } + + /** Options vanilla : « Terminé » passe à droite, « Réglages essentiels… » (écran simple) à gauche. */ + private static void options(ScreenEvent.Init.Post e, Screen s) { + for (GuiEventListener l : e.getListenersList()) { + if (l instanceof Button b && cle(b).equals("gui.done")) { + int y = b.getY(); + b.setWidth(150); + b.setX(s.width / 2 + 5); + e.addListener(Button.builder(Component.literal("Réglages essentiels…"), + x -> Minecraft.getInstance().setScreen(new OptionsSimplesScreen(s))) + .bounds(s.width / 2 - 155, y, 150, 20).build()); + return; + } + } + } + + // ---------------------------------------------------------------- rendu + + public static void apresRendu(ScreenEvent.Render.Post e) { + Screen s = e.getScreen(); + GuiGraphics g = e.getGuiGraphics(); + Font f = Minecraft.getInstance().font; + if (s.getClass() == TitleScreen.class && Config.accueil()) { + // Le logo vanilla est remplacé par une image vide (ressources du mod) ; le mot GASTINEL en police Minecraft x4. + String t = "GASTINEL"; + int l = f.width(t) * 4; + g.pose().pushPose(); + g.pose().translate(s.width / 2f - l / 2f, 34, 0); + g.pose().scale(4f, 4f, 1f); + g.drawString(f, t, 0, 0, 0xFFFFFFFF, true); + g.pose().popPose(); + } else if (s.getClass() == PauseScreen.class && ((PauseScreen) s).showsPauseMenu() && Config.pause()) { + String t = "GASTINEL"; + g.drawString(f, t, s.width - f.width(t) - 6, s.height - 14, 0xB0FFFFFF, true); + } else if (s.getClass() == JoinMultiplayerScreen.class) { + cadreGastinel(g, s); + } + } + + /** Filet orange autour de l'entrée du serveur Gastinel dans la liste multijoueur. */ + private static void cadreGastinel(GuiGraphics g, Screen s) { + for (GuiEventListener l : s.children()) { + if (!(l instanceof ServerSelectionList liste)) continue; + List entrees = liste.children(); + for (int i = 0; i < entrees.size(); i++) { + if (entrees.get(i) instanceof ServerSelectionList.OnlineServerEntry o && Gastinel.est(o.getServerData().ip)) { + // Même calcul que AbstractSelectionList#getRowTop (protégé) ; 36 = hauteur d'une ligne de la liste multijoueur. + int haut = liste.getY() + 4 - (int) liste.getScrollAmount() + i * 36; + int gauche = liste.getX() + (liste.getWidth() - liste.getRowWidth()) / 2; + g.enableScissor(liste.getX(), liste.getY(), liste.getRight(), liste.getBottom()); + g.renderOutline(gauche, haut - 2, liste.getRowWidth(), 36, Gastinel.ORANGE); + g.disableScissor(); + return; + } + } + } + } + + private static String cle(AbstractWidget w) { + return w.getMessage().getContents() instanceof TranslatableContents t ? t.getKey() : ""; + } +} diff --git a/src/main/java/com/gastinelclient/ecrans/OptionsSimplesScreen.java b/src/main/java/com/gastinelclient/ecrans/OptionsSimplesScreen.java index 9ae2c19..af604f4 100644 --- a/src/main/java/com/gastinelclient/ecrans/OptionsSimplesScreen.java +++ b/src/main/java/com/gastinelclient/ecrans/OptionsSimplesScreen.java @@ -1,153 +1,27 @@ package com.gastinelclient.ecrans; -import com.gastinelclient.core.Libelles; -import com.gastinelclient.ui.Bouton; -import com.gastinelclient.ui.Charte; -import net.minecraft.client.OptionInstance; -import net.minecraft.client.Options; -import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.Screen; -import net.minecraft.client.gui.screens.options.OptionsScreen; +import net.minecraft.client.gui.screens.options.OptionsSubScreen; import net.minecraft.network.chat.Component; import net.minecraft.sounds.SoundSource; -import java.util.ArrayList; -import java.util.List; -import java.util.function.DoubleSupplier; -import java.util.function.IntFunction; -import java.util.function.Supplier; - /** - * Options essentielles sur un seul écran (image, son, souris), avec des pas − / + au lieu - * des curseurs vanilla. « Toutes les options » ouvre l'écran complet de Minecraft. + * Les réglages essentiels sur un seul écran, avec les curseurs de Minecraft (restylés par les ressources du mod). + * La taille de l'interface reste dans « Graphismes » : elle demande un redimensionnement géré par cet écran-là. */ -public class OptionsSimplesScreen extends EcranGastinel { - private record Ligne(String nom, Supplier valeur, int x, int y, int l, DoubleSupplier part) {} - private record Rubrique(String nom, int x, int y) {} - - private final List lignes = new ArrayList<>(); - private final List rubriques = new ArrayList<>(); - +public class OptionsSimplesScreen extends OptionsSubScreen { public OptionsSimplesScreen(Screen parent) { - super("Options", parent); - } - - private Options o() { return this.minecraft.options; } - - @Override - protected void init() { - lignes.clear(); - rubriques.clear(); - int m = marge(); - int l = Math.min(colonne(), (this.width - 2 * m - 24) / 2); - int x1 = m, x2 = m + l + 24; - int y0 = 16 + 46; - - int y = rubrique("Image", x1, y0); - y = pas(x1, y, l, "Distance d'affichage", o().renderDistance(), 1, v -> v + " tronçons"); - y = pas(x1, y, l, "Champ de vision", o().fov(), 5, v -> v + "°"); - y = pasDouble(x1, y, l, "Luminosité", o().gamma(), 0.1); - y = pas(x1, y, l, "Taille de l'interface", o().guiScale(), 1, v -> v == 0 ? "Auto" : "×" + v); - y = bascule(x1, y, l, "Plein écran", o().fullscreen()); - bascule(x1, y, l, "Synchro verticale", o().enableVsync()); - - y = rubrique("Son et souris", x2, y0); - y = pasDouble(x2, y, l, "Volume général", o().getSoundSourceOptionInstance(SoundSource.MASTER), 0.05); - y = pasDouble(x2, y, l, "Musique", o().getSoundSourceOptionInstance(SoundSource.MUSIC), 0.05); - y = pasDouble(x2, y, l, "Blocs et ambiance", o().getSoundSourceOptionInstance(SoundSource.BLOCKS), 0.05); - pasDouble(x2, y, l, "Sensibilité de la souris", o().sensitivity(), 0.05); - - lien(m, this.height - 16, "← Retour", this::onClose); - String tout = "Toutes les options de Minecraft"; - lien(this.width - m - this.font.width(Charte.txt(tout)), this.height - 16, tout, - () -> this.minecraft.setScreen(new OptionsScreen(this, o()))); - } - - private int rubrique(String nom, int x, int y) { - rubriques.add(new Rubrique(nom, x, y)); - return y + 14; - } - - /** Pas entier, borné sur les limites de l'option (une valeur hors bornes serait remise par défaut). */ - private int pas(int x, int y, int l, String nom, OptionInstance opt, int pas, IntFunction format) { - Runnable apres = opt == o().guiScale() ? () -> this.minecraft.resizeDisplay() : () -> {}; - ajouterPas(x, y, l, nom, () -> format.apply(opt.get()), fraction(opt), - () -> { opt.set(borner(opt, opt.get() - pas)); apres.run(); }, - () -> { opt.set(borner(opt, opt.get() + pas)); apres.run(); }); - return y + 20; - } - - /** Position dans les bornes de l'option, pour la jauge ; null si les bornes sont inconnues (ex. taille de l'interface). */ - private DoubleSupplier fraction(OptionInstance opt) { - if (opt == o().guiScale()) return null; - int min, max; - if (opt.values() instanceof OptionInstance.IntRange r) { min = r.minInclusive(); max = r.maxInclusive(); } - else if (opt.values() instanceof OptionInstance.ClampingLazyMaxIntRange r) { min = r.minInclusive(); max = r.maxInclusive(); } - else return null; - return () -> Libelles.fraction(opt.get(), min, max); - } - - private static int borner(OptionInstance opt, int v) { - if (opt.values() instanceof OptionInstance.IntRange r) return Libelles.borne(v, r.minInclusive(), r.maxInclusive()); - if (opt.values() instanceof OptionInstance.ClampingLazyMaxIntRange r) return Libelles.borne(v, r.minInclusive(), r.maxInclusive()); - return v; - } - - private int pasDouble(int x, int y, int l, String nom, OptionInstance opt, double pas) { - ajouterPas(x, y, l, nom, () -> Libelles.pourcent(opt.get()), opt::get, - () -> opt.set(Libelles.pas01(opt.get(), -pas)), - () -> opt.set(Libelles.pas01(opt.get(), pas))); - return y + 20; - } - - private void ajouterPas(int x, int y, int l, String nom, Supplier valeur, DoubleSupplier part, Runnable moins, Runnable plus) { - lignes.add(new Ligne(nom, valeur, x, y, l - 42, part)); - addRenderableWidget(new Bouton(x + l - 38, y + 2, 17, 15, "−", Bouton.Genre.CADRE, moins)); - addRenderableWidget(new Bouton(x + l - 17, y + 2, 17, 15, "+", Bouton.Genre.CADRE, plus)); - } - - private int bascule(int x, int y, int l, String nom, OptionInstance opt) { - lignes.add(new Ligne(nom, () -> "", x, y, l - 42, null)); - Bouton[] b = new Bouton[1]; - b[0] = addRenderableWidget(new Bouton(x + l - 38, y + 2, 38, 15, opt.get() ? "Oui" : "Non", Bouton.Genre.CADRE, () -> { - opt.set(!opt.get()); - b[0].setMessage(Component.literal(opt.get() ? "Oui" : "Non")); - })); - return y + 20; + super(parent, Minecraft.getInstance().options, Component.literal("Réglages essentiels")); } @Override - public void render(GuiGraphics g, int mx, int my, float pt) { - super.render(g, mx, my, pt); - entete(g, marge(), 16, "Options", "Options"); - int m = marge(); - int l = Math.min(colonne(), (this.width - 2 * m - 24) / 2); - for (Rubrique r : rubriques) { - Charte.etiquette(g, this.font, r.nom(), r.x(), r.y(), Charte.DOUX); - Charte.filet(g, r.x(), r.x() + l, r.y() + 11, Charte.ENCRE); - Charte.filet(g, r.x(), r.x() + l, r.y() + 12, Charte.ENCRE); - } - for (Ligne li : lignes) { - Charte.texte(g, this.font, Charte.txt(li.nom()), li.x(), li.y() + 6, Charte.ENCRE); - String v = li.valeur().get(); - int vx = li.x() + li.l(); - if (!v.isEmpty()) { - vx -= this.font.width(Charte.gras(v)); - Charte.texte(g, this.font, Charte.gras(v), vx, li.y() + 6, Charte.ENCRE); - } - if (li.part() != null) { - // Jauge entre le nom et la valeur, seulement s'il y a la place. - int debut = li.x() + this.font.width(Charte.txt(li.nom())) + 8, fin = vx - 8; - int lj = Math.min(60, fin - debut); - if (lj >= 20) Charte.jauge(g, fin - lj, li.y() + 9, lj, li.part().getAsDouble()); - } - Charte.filet(g, li.x(), li.x() + li.l() + 42, li.y() + 19, Charte.FILET); - } - Charte.filet(g, m, this.width - m, this.height - 22, Charte.FILET); - } - - @Override - public void removed() { - this.minecraft.options.save(); + protected void addOptions() { + this.list.addSmall( + this.options.renderDistance(), this.options.fov(), + this.options.gamma(), this.options.sensitivity(), + this.options.fullscreen(), this.options.enableVsync(), + this.options.getSoundSourceOptionInstance(SoundSource.MASTER), this.options.getSoundSourceOptionInstance(SoundSource.MUSIC), + this.options.getSoundSourceOptionInstance(SoundSource.BLOCKS), this.options.getSoundSourceOptionInstance(SoundSource.AMBIENT)); } } diff --git a/src/main/java/com/gastinelclient/ecrans/PauseGastinel.java b/src/main/java/com/gastinelclient/ecrans/PauseGastinel.java deleted file mode 100644 index 6e22b0b..0000000 --- a/src/main/java/com/gastinelclient/ecrans/PauseGastinel.java +++ /dev/null @@ -1,117 +0,0 @@ -package com.gastinelclient.ecrans; - -import com.gastinelclient.ui.Bouton; -import com.gastinelclient.ui.Charte; -import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.gui.screens.GenericMessageScreen; -import net.minecraft.client.gui.screens.ShareToLanScreen; -import net.minecraft.client.gui.screens.achievement.StatsScreen; -import net.minecraft.client.gui.screens.advancements.AdvancementsScreen; -import net.minecraft.client.multiplayer.ServerData; -import net.minecraft.network.chat.Component; -import net.neoforged.neoforge.client.gui.ModListScreen; - -/** - * Menu pause simplifié : un panneau blanc à gauche, le monde visible à droite (sans flou). - * Reprendre, Options, Progrès, Statistiques, (Ouvrir en réseau local), Mods, Quitter. - */ -public class PauseGastinel extends EcranGastinel { - private static final Component SAUVEGARDE = Component.translatable("menu.savingLevel"); - - public PauseGastinel() { - super("Pause", null); - } - - private int panneau() { return Math.min(this.width, colonne() + 2 * marge()); } - - private int haut() { - int n = 5 + (lanPossible() ? 1 : 0); - return Math.max(14, (this.height - (58 + 30 + n * 20 + 14 + 20)) / 2 + 8); - } - - @Override - protected void init() { - int m = marge(), l = colonne(); - boolean solo = this.minecraft.isLocalServer(); - int y = haut() + 58; - int n = 1; - - addRenderableWidget(new Bouton(m, y, l, 30, "Reprendre", Bouton.Genre.PRIMAIRE, this::reprendre) - .numero(n++).sousTitre(this::lieu, () -> Charte.CLAIR)); - y += 30; - addRenderableWidget(new Bouton(m, y, l, 20, "Options", Bouton.Genre.MENU, - () -> this.minecraft.setScreen(new OptionsSimplesScreen(this))).numero(n++)); - y += 20; - addRenderableWidget(new Bouton(m, y, l, 20, "Progrès", Bouton.Genre.MENU, - () -> this.minecraft.setScreen(new AdvancementsScreen(this.minecraft.player.connection.getAdvancements(), this))).numero(n++)); - y += 20; - addRenderableWidget(new Bouton(m, y, l, 20, "Statistiques", Bouton.Genre.MENU, - () -> this.minecraft.setScreen(new StatsScreen(this, this.minecraft.player.getStats()))).numero(n++)); - y += 20; - if (lanPossible()) { - addRenderableWidget(new Bouton(m, y, l, 20, "Ouvrir en réseau local", Bouton.Genre.MENU, - () -> this.minecraft.setScreen(new ShareToLanScreen(this))).numero(n++)); - y += 20; - } - addRenderableWidget(new Bouton(m, y, l, 20, "Mods", Bouton.Genre.MENU, - () -> this.minecraft.setScreen(new ModListScreen(this))).numero(n++)); - y += 20 + 14; - addRenderableWidget(new Bouton(m, y, l, 20, solo ? "Sauvegarder et quitter" : "Se déconnecter", - Bouton.Genre.ALERTE, this::quitter)); - } - - private boolean lanPossible() { - return this.minecraft.hasSingleplayerServer() && !this.minecraft.getSingleplayerServer().isPublished(); - } - - private String lieu() { - if (this.minecraft.hasSingleplayerServer()) { - return "Monde : " + this.minecraft.getSingleplayerServer().getWorldData().getLevelName(); - } - ServerData d = this.minecraft.getCurrentServer(); - return d != null ? d.name : "Multijoueur"; - } - - private void reprendre() { - this.minecraft.setScreen(null); - this.minecraft.mouseHandler.grabMouse(); - } - - /** Même suite que PauseScreen#onDisconnect, puis retour à l'accueil Gastinel. */ - private void quitter() { - boolean local = this.minecraft.isLocalServer(); - this.minecraft.level.disconnect(); - if (local) { - this.minecraft.disconnect(new GenericMessageScreen(SAUVEGARDE)); - } else { - this.minecraft.disconnect(); - } - this.minecraft.setScreen(new AccueilScreen()); - } - - @Override - public void onClose() { - reprendre(); - } - - @Override - public void renderBackground(GuiGraphics g, int mx, int my, float pt) { - int p = panneau(); - g.fill(0, 0, this.width, this.height, 0x2E000000); // monde légèrement assombri, sans flou - g.fill(0, 0, p, this.height, Charte.FOND); - g.fill(p, 0, p + 1, this.height, Charte.ENCRE); - } - - @Override - public void render(GuiGraphics g, int mx, int my, float pt) { - super.render(g, mx, my, pt); - int m = marge(), l = colonne(), y = haut(); - Charte.etiquette(g, this.font, "Gastinel", m, 9, Charte.ENCRE); - String echap = "Échap : reprendre"; - Charte.etiquette(g, this.font, echap, m + l - Charte.largeurEtiquette(this.font, echap), 9, Charte.DOUX); - Charte.filet(g, 0, panneau(), 24, Charte.FILET); - Charte.grandTitre(g, this.font, "Pause", m - 2, y, 4f, Charte.ENCRE); - Charte.filet(g, m, m + l, y + 56, Charte.ENCRE); - Charte.filet(g, m, m + l, y + 57, Charte.ENCRE); - } -} diff --git a/src/main/java/com/gastinelclient/ecrans/ServeursScreen.java b/src/main/java/com/gastinelclient/ecrans/ServeursScreen.java deleted file mode 100644 index 04d1dcf..0000000 --- a/src/main/java/com/gastinelclient/ecrans/ServeursScreen.java +++ /dev/null @@ -1,162 +0,0 @@ -package com.gastinelclient.ecrans; - -import com.gastinelclient.Config; -import com.gastinelclient.core.Libelles; -import com.gastinelclient.ui.Bouton; -import com.gastinelclient.ui.Charte; -import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.gui.components.EditBox; -import net.minecraft.client.gui.screens.ConnectScreen; -import net.minecraft.client.gui.screens.Screen; -import net.minecraft.client.gui.screens.multiplayer.JoinMultiplayerScreen; -import net.minecraft.client.multiplayer.ServerData; -import net.minecraft.client.multiplayer.ServerList; -import net.minecraft.client.multiplayer.resolver.ServerAddress; -import net.minecraft.network.chat.Component; -import net.minecraft.util.FormattedCharSequence; - -import java.util.ArrayList; -import java.util.List; - -/** - * « Autres serveurs », version simple : une case d'adresse (Rejoindre / Enregistrer) et la liste - * des serveurs enregistrés, un clic pour rejoindre. La liste vanilla complète reste accessible. - */ -public class ServeursScreen extends EcranGastinel { - private EditBox adresse; - private String saisie = ""; - private String message = ""; - private int page = 0; - - public ServeursScreen(Screen parent) { - super("Autres serveurs", parent); - } - - @Override - protected void init() { - int m = marge(), l = colonne(); - int y = 16 + 46; - - adresse = new EditBox(this.font, m + 5, y + 7, l - 10, 12, Component.literal("Adresse")); - adresse.setBordered(false); - adresse.setTextShadow(false); - adresse.setTextColor(Charte.ENCRE); - adresse.setMaxLength(255); - adresse.setHint(Charte.txt("Adresse, ex. play.exemple.fr").withColor(Charte.DOUX)); - adresse.setFormatter((s, i) -> FormattedCharSequence.forward(s, Charte.txt("").getStyle())); - adresse.setValue(saisie); - adresse.setResponder(s -> saisie = s); - addRenderableWidget(adresse); - setInitialFocus(adresse); - y += 26; - - int lb = (l - 6) / 2; - addRenderableWidget(new Bouton(m, y, lb, 18, "Rejoindre", Bouton.Genre.CADRE, this::rejoindreSaisie)); - addRenderableWidget(new Bouton(m + lb + 6, y, l - lb - 6, 18, "Enregistrer", Bouton.Genre.CADRE, this::enregistrer)); - y += 30; - - // Liste enregistrée (sans le serveur Gastinel, déjà sur l'accueil) - List serveurs = new ArrayList<>(); - ServerList liste = new ServerList(this.minecraft); - liste.load(); - String gastinel = Libelles.adresseCourte(Config.adresse()); - for (int i = 0; i < liste.size(); i++) { - ServerData d = liste.get(i); - if (!Libelles.adresseCourte(d.ip).equalsIgnoreCase(gastinel)) serveurs.add(d); - } - int bas = this.height - 46; - int parPage = Math.max(1, (bas - y - 14) / 20); - int pages = Math.max(1, (serveurs.size() + parPage - 1) / parPage); - page = Math.min(page, pages - 1); - int ligneY = y + 14; - if (serveurs.isEmpty()) { - message = message.isEmpty() ? "Aucun serveur enregistré pour l'instant." : message; - } - for (int i = page * parPage; i < Math.min(serveurs.size(), (page + 1) * parPage); i++) { - ServerData d = serveurs.get(i); - addRenderableWidget(new Bouton(m, ligneY, l, 20, d.name, Bouton.Genre.MENU, () -> rejoindre(d)) - .droite(Libelles.adresseCourte(d.ip))); - ligneY += 20; - } - if (pages > 1) { - if (page > 0) lien(m, bas, "← Précédents", () -> { page--; rebuildWidgets(); }); - if (page < pages - 1) { - String s = "Suivants →"; - lien(m + l - this.font.width(Charte.txt(s)), bas, s, () -> { page++; rebuildWidgets(); }); - } - } - - lien(m, this.height - 16, "← Retour", this::onClose); - String complet = "Liste complète de Minecraft (modifier, supprimer)"; - lien(this.width - m - this.font.width(Charte.txt(complet)), this.height - 16, complet, - () -> this.minecraft.setScreen(new JoinMultiplayerScreen(this))); - } - - private void rejoindreSaisie() { - String a = Libelles.nettoyerAdresse(saisie); - if (!ServerAddress.isValidAddress(a)) { - message = "Adresse invalide."; - return; - } - rejoindre(new ServerData(a, a, ServerData.Type.OTHER)); - } - - private void enregistrer() { - String a = Libelles.nettoyerAdresse(saisie); - if (!ServerAddress.isValidAddress(a)) { - message = "Adresse invalide."; - return; - } - ServerList liste = new ServerList(this.minecraft); - liste.load(); - if (liste.get(a) == null) { - liste.add(new ServerData(a, a, ServerData.Type.OTHER), false); - liste.save(); - message = "Enregistré : " + a; - } else { - message = "Déjà dans la liste."; - } - saisie = ""; - rebuildWidgets(); - } - - private void rejoindre(ServerData d) { - ConnectScreen.startConnecting(this, this.minecraft, ServerAddress.parseString(d.ip), d, false, null); - } - - @Override - public boolean keyPressed(int key, int scan, int mods) { - if ((key == 257 || key == 335) && adresse != null && adresse.isFocused()) { // Entrée - rejoindreSaisie(); - return true; - } - return super.keyPressed(key, scan, mods); - } - - @Override - public void render(GuiGraphics g, int mx, int my, float pt) { - super.render(g, mx, my, pt); - int m = marge(), l = colonne(); - int y = entete(g, m, 16, "Multijoueur", "Autres serveurs"); - // Case d'adresse : cadre fin dessiné par nous (pas de bordure vanilla) - // Case d'adresse : simple trait de 2 px dessous (à l'encre quand elle a le focus). - int c = adresse != null && adresse.isFocused() ? Charte.ENCRE : Charte.FILET_FORT; - g.fill(m, y + 20, m + l, y + 22, c); - int ly = y + 26 + 30; - int le = Charte.etiquette(g, this.font, "Enregistrés", m, ly, Charte.DOUX), fin = m + l; - if (!message.isEmpty()) { - Charte.texte(g, this.font, Charte.txt(message), m + le + 10, ly, Charte.DOUX); - fin = Math.max(fin, m + le + 10 + this.font.width(Charte.txt(message))); - } - Charte.filet(g, m, fin, ly + 11, Charte.ENCRE); - Charte.filet(g, m, fin, ly + 12, Charte.ENCRE); - Charte.filet(g, m, this.width - m, this.height - 22, Charte.FILET); - } - - @Override - public void renderBackground(GuiGraphics g, int mx, int my, float pt) { - super.renderBackground(g, mx, my, pt); - int m = marge(), l = colonne(); - g.fill(m, 16 + 46, m + l, 16 + 46 + 20, Charte.ALTERNE); - } -} diff --git a/src/main/java/com/gastinelclient/ui/Bouton.java b/src/main/java/com/gastinelclient/ui/Bouton.java deleted file mode 100644 index 85a4ac5..0000000 --- a/src/main/java/com/gastinelclient/ui/Bouton.java +++ /dev/null @@ -1,119 +0,0 @@ -package com.gastinelclient.ui; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Font; -import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.gui.components.AbstractButton; -import net.minecraft.client.gui.narration.NarrationElementOutput; -import net.minecraft.network.chat.Component; - -import java.util.function.Supplier; - -/** - * Bouton plat de la charte : angles droits, filets de 1 px, pas de texture. - * MENU : ligne de liste (numéro gris, texte, filet dessous ; survol = fond alterné + barre d'encre + flèche). - * PRIMAIRE : ligne pleine à l'encre, texte blanc, sous-titre gris clair. - * ALERTE : ligne au texte rouge sombre entre deux filets rouges (quitter). - * CADRE : bouton encadré 1 px, plein à l'encre au survol. LIEN : texte seul souligné au survol. - */ -public class Bouton extends AbstractButton { - public enum Genre { MENU, PRIMAIRE, ALERTE, CADRE, LIEN } - - private final Genre genre; - private final Runnable action; - private Supplier sousTitre = null; - private Supplier couleurSousTitre = () -> Charte.DOUX; - private Supplier pastille = null; - private String droite = null; - private int numero = 0; - - public Bouton(int x, int y, int l, int h, String texte, Genre genre, Runnable action) { - super(x, y, l, h, Component.literal(texte)); - this.genre = genre; - this.action = action; - } - - public Bouton sousTitre(Supplier s, Supplier couleur) { - this.sousTitre = s; - this.couleurSousTitre = couleur; - return this; - } - - /** Petit carré de couleur devant le sous-titre (état du serveur) ; null = pas de carré. */ - public Bouton pastille(Supplier c) { this.pastille = c; return this; } - - /** Numéro gris « 01 » en tête de ligne (0 = aucun). */ - public Bouton numero(int n) { this.numero = n; return this; } - - /** Petit texte gris aligné à droite (ex. adresse d'un serveur). */ - public Bouton droite(String s) { this.droite = s; return this; } - - @Override - public void onPress() { action.run(); } - - @Override - protected void renderWidget(GuiGraphics g, int mx, int my, float pt) { - Font f = Minecraft.getInstance().font; - boolean s = this.active && this.isHoveredOrFocused(); - int x = getX(), y = getY(), l = getWidth(), h = getHeight(); - String t = getMessage().getString(); - int ty = y + (h - 8) / 2; - switch (genre) { - case MENU, PRIMAIRE -> { - boolean prim = genre == Genre.PRIMAIRE; - int encre = prim ? Charte.FOND : (this.active ? Charte.ENCRE : Charte.FILET_FORT); - if (prim) g.fill(x, y, x + l, y + h, Charte.ENCRE); - else if (s) { - g.fill(x, y, x + l, y + h, Charte.ALTERNE); - g.fill(x, y, x + 1, y + h, Charte.ENCRE); - } - int tx = x + 8; - if (numero > 0) { - Charte.texte(g, f, Charte.gras(String.format("%02d", numero)), tx, ty, prim ? Charte.FILET_FORT : Charte.DOUX); - tx += 22; - } - if (sousTitre != null) { - Charte.texte(g, f, Charte.txt(t), tx, y + h / 2 - 10, encre); - int sx = tx; - if (pastille != null && pastille.get() != null) { - Charte.carre(g, sx, y + h / 2 + 4, 5, pastille.get()); - sx += 9; - } - Charte.texte(g, f, Charte.txt(sousTitre.get()), sx, y + h / 2 + 2, couleurSousTitre.get()); - } else { - Charte.texte(g, f, Charte.txt(t), tx, ty, encre); - } - if (droite != null) { - Component d = Charte.txt(droite); - Charte.texte(g, f, d, x + l - 22 - f.width(d), ty, Charte.DOUX); - } - if (s || prim) Charte.texte(g, f, Charte.txt("→"), x + l - 14, ty, encre); - if (!prim) Charte.filet(g, x, x + l, y + h - 1, Charte.FILET); - } - case ALERTE -> { - if (s) g.fill(x, y, x + l, y + h, Charte.ALERTE_FOND); - Charte.filet(g, x, x + l, y, Charte.ALERTE); - Charte.filet(g, x, x + l, y + h - 1, Charte.ALERTE); - Charte.texte(g, f, Charte.gras(t), x + 8, ty, Charte.ALERTE); - if (s) Charte.texte(g, f, Charte.txt("→"), x + l - 14, ty, Charte.ALERTE); - } - case CADRE -> { - int encre = this.active ? Charte.ENCRE : Charte.FILET_FORT; - g.fill(x, y, x + l, y + h, s ? Charte.ENCRE : Charte.FOND); - g.renderOutline(x, y, l, h, this.active ? Charte.ENCRE : Charte.FILET); - Component c = Charte.txt(t); - Charte.texte(g, f, c, x + (l - f.width(c)) / 2, ty, s ? Charte.FOND : encre); - } - case LIEN -> { - Component c = Charte.txt(t); - Charte.texte(g, f, c, x, ty, s ? Charte.ENCRE : Charte.DOUX); - if (s) Charte.filet(g, x, x + f.width(c), ty + 9, Charte.ENCRE); - } - } - } - - @Override - protected void updateWidgetNarration(NarrationElementOutput out) { - this.defaultButtonNarrationText(out); - } -} diff --git a/src/main/java/com/gastinelclient/ui/Charte.java b/src/main/java/com/gastinelclient/ui/Charte.java deleted file mode 100644 index 729ecd9..0000000 --- a/src/main/java/com/gastinelclient/ui/Charte.java +++ /dev/null @@ -1,104 +0,0 @@ -package com.gastinelclient.ui; - -import com.gastinelclient.GastinelClient; -import net.minecraft.client.gui.Font; -import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.MutableComponent; -import net.minecraft.resources.ResourceLocation; - -/** - * Charte Gastinel (proposition A, « sobre ») : fond blanc, encre #111, gris #6b6b6b, filets #d9d9d9, - * police Inter, aucun arrondi, filets de 1 px. La couleur ne sert que de signal (en ligne, hors ligne). - * Valeurs reprises de la charte relevée (Mind, météo, Hub). - */ -public final class Charte { - private Charte() {} - - // Couleurs (ARGB) - public static final int FOND = 0xFFFFFFFF; - public static final int ALTERNE = 0xFFF4F4F4; - public static final int ENCRE = 0xFF111111; - public static final int DOUX = 0xFF6B6B6B; - public static final int CLAIR = 0xFFBDBDBD; // texte secondaire sur fond encre - public static final int FILET = 0xFFD9D9D9; - public static final int FILET_FORT = 0xFF8C8C8C; - // Signaux (jamais seuls : toujours avec un texte) - public static final int SUCCES = 0xFF1A5C2A; - public static final int SUCCES_FOND = 0xFFF0F7F0; - public static final int ALERTE = 0xFF8A1C1C; - public static final int ALERTE_FOND = 0xFFFDF2F2; - public static final int PASTILLE = 0xFF3FBF5F; // carré « en ligne » sur fond encre - - public static final ResourceLocation INTER = rl("inter"); - public static final ResourceLocation INTER_GRAS = rl("inter_gras"); - public static final ResourceLocation INTER_TITRE = rl("inter_titre"); - - private static ResourceLocation rl(String p) { - return ResourceLocation.fromNamespaceAndPath(GastinelClient.MODID, p); - } - - public static MutableComponent txt(String s) { - return Component.literal(s).withStyle(st -> st.withFont(INTER)); - } - - public static MutableComponent gras(String s) { - return Component.literal(s).withStyle(st -> st.withFont(INTER_GRAS)); - } - - public static MutableComponent titre(String s) { - return Component.literal(s).withStyle(st -> st.withFont(INTER_TITRE)); - } - - /** Texte sans ombre (l'ombre vanilla salit un fond clair). */ - public static void texte(GuiGraphics g, Font f, Component c, int x, int y, int couleur) { - g.drawString(f, c, x, y, couleur, false); - } - - /** Grand titre : police Inter suréchantillonnée, agrandie d'un facteur {@code echelle}. */ - public static void grandTitre(GuiGraphics g, Font f, String s, int x, int y, float echelle, int couleur) { - g.pose().pushPose(); - g.pose().translate(x, y, 0); - g.pose().scale(echelle, echelle, 1f); - g.drawString(f, titre(s), 0, 0, couleur, false); - g.pose().popPose(); - } - - /** Arrière-plan : blanc uni. */ - public static void fond(GuiGraphics g, int w, int h) { - g.fill(0, 0, w, h, FOND); - } - - /** Étiquette en capitales, lettrage espacé (« GASTINEL », « ÉTAT DU SERVEUR »). Renvoie la largeur. */ - public static int etiquette(GuiGraphics g, Font f, String s, int x, int y, int couleur) { - int cx = x; - for (char ch : s.toUpperCase().toCharArray()) { - Component c = gras(String.valueOf(ch)); - g.drawString(f, c, cx, y, couleur, false); - cx += f.width(c) + 1; - } - return cx - x; - } - - public static int largeurEtiquette(Font f, String s) { - int l = 0; - for (char ch : s.toUpperCase().toCharArray()) l += f.width(gras(String.valueOf(ch))) + 1; - return l; - } - - /** Pastille carrée (aucun arrondi). */ - public static void carre(GuiGraphics g, int x, int y, int c, int couleur) { - g.fill(x, y, x + c, y + c, couleur); - } - - /** Jauge fine : piste grise, partie remplie à l'encre. */ - public static void jauge(GuiGraphics g, int x, int y, int l, double part) { - g.fill(x, y, x + l, y + 2, FILET); - g.fill(x, y, x + (int) Math.round(l * Math.max(0, Math.min(1, part))), y + 2, ENCRE); - } - - /** Filet horizontal fin. */ - public static void filet(GuiGraphics g, int x1, int x2, int y, int couleur) { - g.fill(x1, y, x2, y + 1, couleur); - } -} diff --git a/src/main/resources/LICENCE-INTER-OFL.txt b/src/main/resources/LICENCE-INTER-OFL.txt deleted file mode 100644 index 9b2ca37..0000000 --- a/src/main/resources/LICENCE-INTER-OFL.txt +++ /dev/null @@ -1,92 +0,0 @@ -Copyright (c) 2016 The Inter Project Authors (https://github.com/rsms/inter) - -This Font Software is licensed under the SIL Open Font License, Version 1.1. -This license is copied below, and is also available with a FAQ at: -http://scripts.sil.org/OFL - ------------------------------------------------------------ -SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 ------------------------------------------------------------ - -PREAMBLE -The goals of the Open Font License (OFL) are to stimulate worldwide -development of collaborative font projects, to support the font creation -efforts of academic and linguistic communities, and to provide a free and -open framework in which fonts may be shared and improved in partnership -with others. - -The OFL allows the licensed fonts to be used, studied, modified and -redistributed freely as long as they are not sold by themselves. The -fonts, including any derivative works, can be bundled, embedded, -redistributed and/or sold with any software provided that any reserved -names are not used by derivative works. The fonts and derivatives, -however, cannot be released under any other type of license. The -requirement for fonts to remain under this license does not apply -to any document created using the fonts or their derivatives. - -DEFINITIONS -"Font Software" refers to the set of files released by the Copyright -Holder(s) under this license and clearly marked as such. This may -include source files, build scripts and documentation. - -"Reserved Font Name" refers to any names specified as such after the -copyright statement(s). - -"Original Version" refers to the collection of Font Software components as -distributed by the Copyright Holder(s). - -"Modified Version" refers to any derivative made by adding to, deleting, -or substituting -- in part or in whole -- any of the components of the -Original Version, by changing formats or by porting the Font Software to a -new environment. - -"Author" refers to any designer, engineer, programmer, technical -writer or other person who contributed to the Font Software. - -PERMISSION AND CONDITIONS -Permission is hereby granted, free of charge, to any person obtaining -a copy of the Font Software, to use, study, copy, merge, embed, modify, -redistribute, and sell modified and unmodified copies of the Font -Software, subject to the following conditions: - -1) Neither the Font Software nor any of its individual components, -in Original or Modified Versions, may be sold by itself. - -2) Original or Modified Versions of the Font Software may be bundled, -redistributed and/or sold with any software, provided that each copy -contains the above copyright notice and this license. These can be -included either as stand-alone text files, human-readable headers or -in the appropriate machine-readable metadata fields within text or -binary files as long as those fields can be easily viewed by the user. - -3) No Modified Version of the Font Software may use the Reserved Font -Name(s) unless explicit written permission is granted by the corresponding -Copyright Holder. This restriction only applies to the primary font name as -presented to the users. - -4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font -Software shall not be used to promote, endorse or advertise any -Modified Version, except to acknowledge the contribution(s) of the -Copyright Holder(s) and the Author(s) or with their explicit written -permission. - -5) The Font Software, modified or unmodified, in part or in whole, -must be distributed entirely under this license, and must not be -distributed under any other license. The requirement for fonts to -remain under this license does not apply to any document created -using the Font Software. - -TERMINATION -This license becomes null and void if any of the above conditions are -not met. - -DISCLAIMER -THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT -OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE -COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL -DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM -OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/src/main/resources/META-INF/neoforge.mods.toml b/src/main/resources/META-INF/neoforge.mods.toml index 7deda73..f169f9c 100644 --- a/src/main/resources/META-INF/neoforge.mods.toml +++ b/src/main/resources/META-INF/neoforge.mods.toml @@ -1,13 +1,13 @@ modLoader="javafml" loaderVersion="[1,)" -license="MIT (code) ; police Inter : SIL OFL 1.1" +license="MIT" [[mods]] modId="gastinelclient" -version="0.1.0" +version="0.3.0-c" displayName="GastinelClient" authors="Théo Gastinel" -description='''Interface Gastinel : nouvel écran d'accueil (Solo, Serveur Gastinel en un clic, autres serveurs, options, quitter) et menus simplifiés. Mod côté client uniquement.''' +description='''Interface Gastinel, style « vanilla épurée » : les menus de Minecraft avec des boutons sombres plats, le bouton « Serveur Gastinel » sur l'accueil et le serveur épinglé en tête de la liste multijoueur. Mod côté client uniquement.''' # Le serveur n'a pas besoin du mod (et un client sans le mod peut se connecter). displayTest="IGNORE_ALL_VERSION" diff --git a/src/main/resources/assets/gastinelclient/font/inter-regular.ttf b/src/main/resources/assets/gastinelclient/font/inter-regular.ttf deleted file mode 100644 index b7aaca8..0000000 Binary files a/src/main/resources/assets/gastinelclient/font/inter-regular.ttf and /dev/null differ diff --git a/src/main/resources/assets/gastinelclient/font/inter-semibold.ttf b/src/main/resources/assets/gastinelclient/font/inter-semibold.ttf deleted file mode 100644 index 47f8ab1..0000000 Binary files a/src/main/resources/assets/gastinelclient/font/inter-semibold.ttf and /dev/null differ diff --git a/src/main/resources/assets/gastinelclient/font/inter.json b/src/main/resources/assets/gastinelclient/font/inter.json deleted file mode 100644 index d12980f..0000000 --- a/src/main/resources/assets/gastinelclient/font/inter.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "providers": [ - { "type": "ttf", "file": "gastinelclient:inter-regular.ttf", "size": 9.0, "oversample": 4.0, "shift": [0.0, 1.0] }, - { "type": "reference", "id": "minecraft:default" } - ] -} diff --git a/src/main/resources/assets/gastinelclient/font/inter_gras.json b/src/main/resources/assets/gastinelclient/font/inter_gras.json deleted file mode 100644 index de11813..0000000 --- a/src/main/resources/assets/gastinelclient/font/inter_gras.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "providers": [ - { "type": "ttf", "file": "gastinelclient:inter-semibold.ttf", "size": 9.0, "oversample": 4.0, "shift": [0.0, 1.0] }, - { "type": "reference", "id": "minecraft:default" } - ] -} diff --git a/src/main/resources/assets/gastinelclient/font/inter_titre.json b/src/main/resources/assets/gastinelclient/font/inter_titre.json deleted file mode 100644 index e6d5872..0000000 --- a/src/main/resources/assets/gastinelclient/font/inter_titre.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "providers": [ - { "type": "ttf", "file": "gastinelclient:inter-semibold.ttf", "size": 9.0, "oversample": 12.0, "shift": [0.0, 1.0] }, - { "type": "reference", "id": "minecraft:default" } - ] -} diff --git a/src/main/resources/assets/minecraft/texts/splashes.txt b/src/main/resources/assets/minecraft/texts/splashes.txt new file mode 100644 index 0000000..7b32cb8 --- /dev/null +++ b/src/main/resources/assets/minecraft/texts/splashes.txt @@ -0,0 +1,4 @@ +Bienvenue dans le Vercors ! +Bienvenue sur Gastinel ! +Vu depuis le Vercors ! +Serveur Gastinel, un clic ! diff --git a/src/main/resources/assets/minecraft/textures/gui/sprites/widget/button.png b/src/main/resources/assets/minecraft/textures/gui/sprites/widget/button.png new file mode 100644 index 0000000..c640ca6 Binary files /dev/null and b/src/main/resources/assets/minecraft/textures/gui/sprites/widget/button.png differ diff --git a/src/main/resources/assets/minecraft/textures/gui/sprites/widget/button.png.mcmeta b/src/main/resources/assets/minecraft/textures/gui/sprites/widget/button.png.mcmeta new file mode 100644 index 0000000..5162a00 --- /dev/null +++ b/src/main/resources/assets/minecraft/textures/gui/sprites/widget/button.png.mcmeta @@ -0,0 +1 @@ +{"gui": {"scaling": {"type": "nine_slice", "width": 200, "height": 20, "border": 1}}} \ No newline at end of file diff --git a/src/main/resources/assets/minecraft/textures/gui/sprites/widget/button_disabled.png b/src/main/resources/assets/minecraft/textures/gui/sprites/widget/button_disabled.png new file mode 100644 index 0000000..16c0e4e Binary files /dev/null and b/src/main/resources/assets/minecraft/textures/gui/sprites/widget/button_disabled.png differ diff --git a/src/main/resources/assets/minecraft/textures/gui/sprites/widget/button_disabled.png.mcmeta b/src/main/resources/assets/minecraft/textures/gui/sprites/widget/button_disabled.png.mcmeta new file mode 100644 index 0000000..5162a00 --- /dev/null +++ b/src/main/resources/assets/minecraft/textures/gui/sprites/widget/button_disabled.png.mcmeta @@ -0,0 +1 @@ +{"gui": {"scaling": {"type": "nine_slice", "width": 200, "height": 20, "border": 1}}} \ No newline at end of file diff --git a/src/main/resources/assets/minecraft/textures/gui/sprites/widget/button_highlighted.png b/src/main/resources/assets/minecraft/textures/gui/sprites/widget/button_highlighted.png new file mode 100644 index 0000000..08d2ca3 Binary files /dev/null and b/src/main/resources/assets/minecraft/textures/gui/sprites/widget/button_highlighted.png differ diff --git a/src/main/resources/assets/minecraft/textures/gui/sprites/widget/button_highlighted.png.mcmeta b/src/main/resources/assets/minecraft/textures/gui/sprites/widget/button_highlighted.png.mcmeta new file mode 100644 index 0000000..5162a00 --- /dev/null +++ b/src/main/resources/assets/minecraft/textures/gui/sprites/widget/button_highlighted.png.mcmeta @@ -0,0 +1 @@ +{"gui": {"scaling": {"type": "nine_slice", "width": 200, "height": 20, "border": 1}}} \ No newline at end of file diff --git a/src/main/resources/assets/minecraft/textures/gui/sprites/widget/slider.png b/src/main/resources/assets/minecraft/textures/gui/sprites/widget/slider.png new file mode 100644 index 0000000..c640ca6 Binary files /dev/null and b/src/main/resources/assets/minecraft/textures/gui/sprites/widget/slider.png differ diff --git a/src/main/resources/assets/minecraft/textures/gui/sprites/widget/slider.png.mcmeta b/src/main/resources/assets/minecraft/textures/gui/sprites/widget/slider.png.mcmeta new file mode 100644 index 0000000..5162a00 --- /dev/null +++ b/src/main/resources/assets/minecraft/textures/gui/sprites/widget/slider.png.mcmeta @@ -0,0 +1 @@ +{"gui": {"scaling": {"type": "nine_slice", "width": 200, "height": 20, "border": 1}}} \ No newline at end of file diff --git a/src/main/resources/assets/minecraft/textures/gui/sprites/widget/slider_handle.png b/src/main/resources/assets/minecraft/textures/gui/sprites/widget/slider_handle.png new file mode 100644 index 0000000..7adc0e2 Binary files /dev/null and b/src/main/resources/assets/minecraft/textures/gui/sprites/widget/slider_handle.png differ diff --git a/src/main/resources/assets/minecraft/textures/gui/sprites/widget/slider_handle.png.mcmeta b/src/main/resources/assets/minecraft/textures/gui/sprites/widget/slider_handle.png.mcmeta new file mode 100644 index 0000000..036856b --- /dev/null +++ b/src/main/resources/assets/minecraft/textures/gui/sprites/widget/slider_handle.png.mcmeta @@ -0,0 +1 @@ +{"gui": {"scaling": {"type": "nine_slice", "width": 8, "height": 20, "border": 1}}} \ No newline at end of file diff --git a/src/main/resources/assets/minecraft/textures/gui/sprites/widget/slider_handle_highlighted.png b/src/main/resources/assets/minecraft/textures/gui/sprites/widget/slider_handle_highlighted.png new file mode 100644 index 0000000..1f7539f Binary files /dev/null and b/src/main/resources/assets/minecraft/textures/gui/sprites/widget/slider_handle_highlighted.png differ diff --git a/src/main/resources/assets/minecraft/textures/gui/sprites/widget/slider_handle_highlighted.png.mcmeta b/src/main/resources/assets/minecraft/textures/gui/sprites/widget/slider_handle_highlighted.png.mcmeta new file mode 100644 index 0000000..036856b --- /dev/null +++ b/src/main/resources/assets/minecraft/textures/gui/sprites/widget/slider_handle_highlighted.png.mcmeta @@ -0,0 +1 @@ +{"gui": {"scaling": {"type": "nine_slice", "width": 8, "height": 20, "border": 1}}} \ No newline at end of file diff --git a/src/main/resources/assets/minecraft/textures/gui/sprites/widget/slider_highlighted.png b/src/main/resources/assets/minecraft/textures/gui/sprites/widget/slider_highlighted.png new file mode 100644 index 0000000..5f5bef8 Binary files /dev/null and b/src/main/resources/assets/minecraft/textures/gui/sprites/widget/slider_highlighted.png differ diff --git a/src/main/resources/assets/minecraft/textures/gui/sprites/widget/slider_highlighted.png.mcmeta b/src/main/resources/assets/minecraft/textures/gui/sprites/widget/slider_highlighted.png.mcmeta new file mode 100644 index 0000000..5162a00 --- /dev/null +++ b/src/main/resources/assets/minecraft/textures/gui/sprites/widget/slider_highlighted.png.mcmeta @@ -0,0 +1 @@ +{"gui": {"scaling": {"type": "nine_slice", "width": 200, "height": 20, "border": 1}}} \ No newline at end of file diff --git a/src/main/resources/assets/minecraft/textures/gui/title/edition.png b/src/main/resources/assets/minecraft/textures/gui/title/edition.png new file mode 100644 index 0000000..d171a5e Binary files /dev/null and b/src/main/resources/assets/minecraft/textures/gui/title/edition.png differ diff --git a/src/main/resources/assets/minecraft/textures/gui/title/minceraft.png b/src/main/resources/assets/minecraft/textures/gui/title/minceraft.png new file mode 100644 index 0000000..4cc76eb Binary files /dev/null and b/src/main/resources/assets/minecraft/textures/gui/title/minceraft.png differ diff --git a/src/main/resources/assets/minecraft/textures/gui/title/minecraft.png b/src/main/resources/assets/minecraft/textures/gui/title/minecraft.png new file mode 100644 index 0000000..4cc76eb Binary files /dev/null and b/src/main/resources/assets/minecraft/textures/gui/title/minecraft.png differ diff --git a/src/test/java/com/gastinelclient/core/LibellesTest.java b/src/test/java/com/gastinelclient/core/LibellesTest.java index 1790ad1..a026840 100644 --- a/src/test/java/com/gastinelclient/core/LibellesTest.java +++ b/src/test/java/com/gastinelclient/core/LibellesTest.java @@ -1,14 +1,16 @@ package com.gastinelclient.core; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.Test; class LibellesTest { - @Test void enLigne() { - assertEquals("En ligne · 3/20 joueurs · 12 ms", Libelles.enLigne(3, 20, 12)); - assertEquals("En ligne · 1/20 joueur · 9 ms", Libelles.enLigne(1, 20, 9)); - assertEquals("En ligne · 0 joueur", Libelles.enLigne(0, 0, -1)); + @Test void etatCourt() { + assertEquals("3/20 · 12 ms", Libelles.etatCourt(3, 20, 12)); + assertEquals("0", Libelles.etatCourt(0, 0, -1)); } @Test void adresses() { @@ -17,17 +19,13 @@ class LibellesTest { assertEquals("", Libelles.nettoyerAdresse(null)); assertEquals("gastinel.me", Libelles.adresseCourte("gastinel.me:25565")); assertEquals("gastinel.me:25570", Libelles.adresseCourte("gastinel.me:25570")); + assertTrue(Libelles.memeServeur("Gastinel.me", "gastinel.me:25565")); + assertFalse(Libelles.memeServeur("gastinel.me:25570", "gastinel.me")); + assertFalse(Libelles.memeServeur("", "")); } - @Test void nombres() { - assertEquals("46 %", Libelles.pourcent(0.456)); - assertEquals("100 %", Libelles.pourcent(1.4)); - assertEquals(0.3, Libelles.pas01(0.2, 0.1)); - assertEquals(1.0, Libelles.pas01(0.98, 0.05)); - assertEquals(0.0, Libelles.pas01(0.02, -0.05)); - assertEquals(32, Libelles.borne(40, 2, 32)); - assertEquals(0.5, Libelles.fraction(17, 2, 32)); - assertEquals(1.0, Libelles.fraction(40, 2, 32)); - assertEquals(0.0, Libelles.fraction(5, 5, 5)); + @Test void epingle() { + assertArrayEquals(new int[] {2, 0, 1, 3}, Libelles.ordreEpingle(4, 2)); + assertArrayEquals(new int[] {0, 1}, Libelles.ordreEpingle(2, 0)); } }