Modification des optionsActivity

This commit is contained in:
2026-03-19 10:12:17 +01:00
parent eb7ceec902
commit b3299977a2
2 changed files with 21 additions and 162 deletions
-158
View File
@@ -1,158 +0,0 @@
package sae.chuzzle;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;
import androidx.annotation.NonNull;
public class VueGrille extends View {
private boolean[][] verrous = new boolean[NB_LIGNES][NB_COLONNES];
private static final int NB_LIGNES = 6;
private static final int NB_COLONNES = 6;
private static final int NB_TYPES = 7;
// Symboles pour le mode daltonien, un par type
private static final String[] SYMBOLES = {"", "", "", "", "", "", ""};
// La VueGrille ne reçoit qu'un tableau int[][] brut, pas un EtatJeu
private int[][] grille = new int[NB_LIGNES][NB_COLONNES];
private boolean modeDaltonien = false;
private final Paint pinceauCase = new Paint();
private final Paint pinceauSymbole = new Paint();
// =========================================================
// CONSTRUCTEUR
// =========================================================
public VueGrille(Context contexte) {
super(contexte);
pinceauCase.setAntiAlias(true);
pinceauCase.setStyle(Paint.Style.FILL);
pinceauSymbole.setAntiAlias(true);
pinceauSymbole.setColor(0xFF000000);
pinceauSymbole.setTextAlign(Paint.Align.CENTER);
}
public VueGrille(Context context, AttributeSet attrs) {
super(context, attrs);
pinceauCase.setAntiAlias(true);
pinceauCase.setStyle(Paint.Style.FILL);
pinceauSymbole.setAntiAlias(true);
pinceauSymbole.setColor(0xFF000000);
pinceauSymbole.setTextAlign(Paint.Align.CENTER);
}
// API PUBLIQUE (appelée par MainActivity uniquement)
/**
* Reçoit une copie de la grille depuis MainActivity.
* VueGrille ne sait pas d'où viennent ces données,
* elle sait juste les dessiner.
*/
public void definirGrille(int[][] nouvelleGrille) {
for (int l = 0; l < NB_LIGNES; l++) {
System.arraycopy(nouvelleGrille[l], 0, grille[l], 0, NB_COLONNES);
}
invalidate();
}
public void definirModeDaltonien(boolean actif) {
this.modeDaltonien = actif;
invalidate();
}
// -
// DESSIN
@Override
protected void onDraw(@NonNull Canvas canvas) {
super.onDraw(canvas);
int largeur = getWidth();
int hauteur = getHeight();
float tailleCase = Math.min(
largeur / (float) NB_COLONNES,
hauteur / (float) NB_LIGNES
);
float margeGauche = (largeur - tailleCase * NB_COLONNES) / 2f;
float margeHaut = (hauteur - tailleCase * NB_LIGNES) / 2f;
pinceauSymbole.setTextSize(tailleCase * 0.4f);
for (int ligne = 0; ligne < NB_LIGNES; ligne++) {
for (int colonne = 0; colonne < NB_COLONNES; colonne++) {
int type = grille[ligne][colonne];
float x1 = margeGauche + colonne * tailleCase + 6;
float y1 = margeHaut + ligne * tailleCase + 6;
float x2 = margeGauche + (colonne + 1) * tailleCase - 6;
float y2 = margeHaut + (ligne + 1) * tailleCase - 6;
// Dessiner la case colorée
// Dessiner la case colorée
definirCouleur(type);
canvas.drawRoundRect(x1, y1, x2, y2, 20, 20, pinceauCase);
// Assombrir la case si elle est verrouillée
if (verrous[ligne][colonne]) {
pinceauCase.setARGB(120, 0, 0, 0);
canvas.drawRoundRect(x1, y1, x2, y2, 20, 20, pinceauCase);
}
// Dessiner le symbole daltonien
if (modeDaltonien) {
float cx = (x1 + x2) / 2f;
float cy = (y1 + y2) / 2f
- (pinceauSymbole.descent() + pinceauSymbole.ascent()) / 2f;
canvas.drawText(SYMBOLES[type % NB_TYPES], cx, cy, pinceauSymbole);
}
// Dessiner le cadenas par-dessus si verrouillée
if (verrous[ligne][colonne]) {
float cx = (x1 + x2) / 2f;
float cy = (y1 + y2) / 2f
- (pinceauSymbole.descent() + pinceauSymbole.ascent()) / 2f;
canvas.drawText("🔒", cx, cy, pinceauSymbole);
}
}
}
}
// -
// UTILITAIRE PRIVE
private void definirCouleur(int type) {
switch (type % NB_TYPES) {
case 0: pinceauCase.setARGB(255, 200, 200, 200); break;
case 1: pinceauCase.setARGB(255, 255, 105, 180); break;
case 2: pinceauCase.setARGB(255, 90, 230, 200); break;
case 3: pinceauCase.setARGB(255, 100, 170, 255); break;
case 4: pinceauCase.setARGB(255, 255, 220, 90); break;
case 5: pinceauCase.setARGB(255, 255, 140, 90); break;
case 6: pinceauCase.setARGB(255, 255, 90, 90); break;
}
}
public void definirVerrous(boolean[][] nouveauxVerrous) {
for (int l = 0; l < NB_LIGNES; l++) {
System.arraycopy(nouveauxVerrous[l], 0, verrous[l], 0, NB_COLONNES);
}
invalidate();
}
}