Modification des optionsActivity
This commit is contained in:
@@ -1,18 +1,24 @@
|
|||||||
package sae.chuzzle;
|
package sae.chuzzle;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
|
|
||||||
public class OptionsActivity extends Activity
|
public class OptionsActivity extends Activity
|
||||||
implements CompoundButton.OnCheckedChangeListener {
|
implements CompoundButton.OnCheckedChangeListener, View.OnClickListener {
|
||||||
|
|
||||||
private SharedPreferences prefs;
|
private SharedPreferences prefs;
|
||||||
private CheckBox checkDaltonien;
|
private CheckBox checkDaltonien;
|
||||||
private CheckBox checkHard;
|
private CheckBox checkHard;
|
||||||
|
|
||||||
|
private Button btnRetour;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@@ -20,14 +26,16 @@ public class OptionsActivity extends Activity
|
|||||||
|
|
||||||
prefs = getSharedPreferences("chuzzle_prefs", MODE_PRIVATE);
|
prefs = getSharedPreferences("chuzzle_prefs", MODE_PRIVATE);
|
||||||
|
|
||||||
checkDaltonien = findViewById(R.id.switchDaltonien);
|
checkDaltonien = findViewById(R.id.checkDaltonien);
|
||||||
checkHard = findViewById(R.id.switchHard);
|
checkHard = findViewById(R.id.checkHard);
|
||||||
|
btnRetour = findViewById(R.id.btnBack);
|
||||||
|
|
||||||
checkDaltonien.setChecked(prefs.getBoolean("daltonien", false));
|
checkDaltonien.setChecked(prefs.getBoolean("daltonien", false));
|
||||||
checkHard.setChecked(prefs.getBoolean("hard_mode", false));
|
checkHard.setChecked(prefs.getBoolean("hard_mode", false));
|
||||||
|
|
||||||
checkDaltonien.setOnCheckedChangeListener(this);
|
checkDaltonien.setOnCheckedChangeListener(this);
|
||||||
checkHard.setOnCheckedChangeListener(this);
|
checkHard.setOnCheckedChangeListener(this);
|
||||||
|
btnRetour.setOnClickListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -38,4 +46,13 @@ public class OptionsActivity extends Activity
|
|||||||
prefs.edit().putBoolean("hard_mode", estCoche).apply();
|
prefs.edit().putBoolean("hard_mode", estCoche).apply();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (v == btnRetour) {
|
||||||
|
Intent intent = new Intent(this, MenuActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user