ajout de l'afficheur du tableau des scores
This commit is contained in:
@@ -44,7 +44,7 @@ class Equipe {
|
|||||||
this.score = score;
|
this.score = score;
|
||||||
this.update();
|
this.update();
|
||||||
Scoreboard.applyScore(this.id, this.score);
|
Scoreboard.applyScore(this.id, this.score);
|
||||||
drawPionsAround(oldScore);
|
drawAround(oldScore);
|
||||||
drawPionsAround(this.score);
|
drawAround(this.score);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
10
Plateau.pde
10
Plateau.pde
@@ -47,8 +47,8 @@ void setup() {
|
|||||||
Scoreboard.applyScores();
|
Scoreboard.applyScores();
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawPionsAround(int score) {
|
void drawAround(int score) {
|
||||||
println("draw around", score);
|
//println("draw around", score);
|
||||||
for (int i=0; i<positionTable.getRowCount(); i++) {
|
for (int i=0; i<positionTable.getRowCount(); i++) {
|
||||||
if (score>0 && score!=i) continue;
|
if (score>0 && score!=i) continue;
|
||||||
// récupération des pions par score
|
// récupération des pions par score
|
||||||
@@ -127,6 +127,10 @@ void mousePressed() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Scoreboard.mouseHover()) {
|
||||||
|
Scoreboard.toggleDisplay();
|
||||||
|
}
|
||||||
|
|
||||||
if (!EDITING) return;
|
if (!EDITING) return;
|
||||||
for (int i = 0 ; i < positions.length; i++) {
|
for (int i = 0 ; i < positions.length; i++) {
|
||||||
Position p = positions[i];
|
Position p = positions[i];
|
||||||
@@ -252,6 +256,8 @@ void draw() {
|
|||||||
timer = millis();
|
timer = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Scoreboard.draw();
|
||||||
|
|
||||||
if (!EDITING) return;
|
if (!EDITING) return;
|
||||||
for (int i = 0 ; i < positions.length; i++) {
|
for (int i = 0 ; i < positions.length; i++) {
|
||||||
positions[i].draw();
|
positions[i].draw();
|
||||||
|
|||||||
@@ -1,16 +1,26 @@
|
|||||||
class Scoreboard {
|
class Scoreboard {
|
||||||
|
|
||||||
String dataSource;
|
String dataSource; // nom du fichier csv
|
||||||
Table table;
|
Table table;
|
||||||
boolean autoload = true;
|
boolean autoload = true; // chargement et rechargement automatique
|
||||||
|
boolean display = true;
|
||||||
|
float posX, posY, width, height; // position et dimensions de l'afficheur
|
||||||
|
|
||||||
Scoreboard() {
|
Scoreboard() {
|
||||||
this.dataSource = "scoreboard.csv";
|
this.dataSource = "scoreboard.csv";
|
||||||
if (autoload) this.load();
|
this.setup();
|
||||||
}
|
}
|
||||||
Scoreboard(String dataSource) {
|
Scoreboard(String dataSource) {
|
||||||
this.dataSource = dataSource;
|
this.dataSource = dataSource;
|
||||||
|
this.setup();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup() {
|
||||||
if (autoload) this.load();
|
if (autoload) this.load();
|
||||||
|
this.posX = 348;
|
||||||
|
this.posY = 59;
|
||||||
|
this.width = 1239;
|
||||||
|
this.height = 158;
|
||||||
}
|
}
|
||||||
|
|
||||||
// charge ou génère le tableau des scores
|
// charge ou génère le tableau des scores
|
||||||
@@ -28,6 +38,9 @@ class Scoreboard {
|
|||||||
scoreEquipe.setInt("score", 0);
|
scoreEquipe.setInt("score", 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// typage forcé pour que .sort() fonctionne sur la colonne score
|
||||||
|
this.table.setColumnType("score", "int");
|
||||||
}
|
}
|
||||||
|
|
||||||
// écrit le tableau des scores dans un .csv
|
// écrit le tableau des scores dans un .csv
|
||||||
@@ -71,4 +84,67 @@ class Scoreboard {
|
|||||||
Iterable <TableRow> findRows(String value, String name) {
|
Iterable <TableRow> findRows(String value, String name) {
|
||||||
return this.table.findRows(value, name);
|
return this.table.findRows(value, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Iterable <TableRow> findEquipesByScore(int value) {
|
||||||
|
return this.table.findRows(str(value), "score");
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean mouseHover() {
|
||||||
|
if (mouseX > this.posX && mouseX < this.posX + this.width && mouseY > this.posY && mouseY < this.posY + height) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void toggleDisplay() {
|
||||||
|
this.display = !this.display;
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw() {
|
||||||
|
if (!this.display) return;
|
||||||
|
//int count = 1;
|
||||||
|
int podium = 3;
|
||||||
|
int margin = 60;
|
||||||
|
float offsetX = this.posX+this.width;
|
||||||
|
float offsetY = this.posY;
|
||||||
|
rectMode(CORNER);
|
||||||
|
noStroke();
|
||||||
|
fill(color(250, 150, 50));
|
||||||
|
rect(this.posX, this.posY, this.width, this.height);
|
||||||
|
|
||||||
|
// pour chaque score de 50 à 1
|
||||||
|
for (int i=50; i>0; i--) {
|
||||||
|
// récupération des équipes à ce score
|
||||||
|
Iterable<TableRow> rowsIterable = this.findEquipesByScore(i);
|
||||||
|
ArrayList<String> teams = new ArrayList<String>();
|
||||||
|
for (TableRow row : rowsIterable) { teams.add(row.getString("equipe")); }
|
||||||
|
|
||||||
|
// arrêter la boucle si on est hors du cadre d'affichage
|
||||||
|
if (offsetX<=this.posX-margin) break;
|
||||||
|
// passer cette itération si aucune équipe à afficher
|
||||||
|
if (teams.size()==0) continue;
|
||||||
|
|
||||||
|
//println(i, teams);
|
||||||
|
|
||||||
|
// affichage du score
|
||||||
|
fill(color(0, 0, 0));
|
||||||
|
stroke(color(0, 0, 0));
|
||||||
|
strokeWeight(1);
|
||||||
|
textFont(quicksandFont, 40);
|
||||||
|
text(i, offsetX-margin, offsetY+margin);
|
||||||
|
|
||||||
|
|
||||||
|
// affichage des équipes
|
||||||
|
for(int j=0; j<teams.size(); j++) {
|
||||||
|
fill(color(255, 255,255));
|
||||||
|
textFont(quicksandFont, 40);
|
||||||
|
text(teams.get(j), offsetX-(margin*(j+1)), offsetY+(margin*2));
|
||||||
|
}
|
||||||
|
|
||||||
|
line(offsetX-(margin*teams.size())-10, offsetY, offsetX-(margin*teams.size())-10, offsetY+this.height);
|
||||||
|
|
||||||
|
//count += teams.size();
|
||||||
|
offsetX -= margin*teams.size();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user