1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
| package Vue;
// many imports
public class PanelBatiment extends JComponent {
private JRadioButton radioPickThisBat;
private JLabel lblNomBatiment;
private JLabel lblCapMax;
private JLabel lblNbJoueur;
private JLabel lblNbZombie;
private boolean drawImageFlag = false;
private boolean isCurrent;
public PanelBatiment(int idLieu, String modeDeJeu, boolean isCurrent) {
this.isCurrent = isCurrent;
this.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
initGridBag(gbc);
if (!isCurrent) {
lblNomBatiment = new JLabel(); //à modifier avec le controleur
JLabel lblTxtCapacite = new JLabel("Capacité maximale d'accueil :");
lblCapMax = new JLabel();
JLabel lblTxtNbJoueurCurrent = new JLabel("Nombre de joueurs présent : ");
lblNbJoueur = new JLabel();
JLabel lblTxtNbZombieCurrent = new JLabel("Nombre de zombies présent : ");
lblNbZombie = new JLabel();
JLabel labelPickThisBat = new JLabel("Se déplacer dans ce bâtiment :");
radioPickThisBat = new JRadioButton();
int dangerBatiment = getDangerBatiment();
JLabel imgBatiment = getImageFromNumber(idLieu, dangerBatiment);
this.add(imgBatiment, gbc);
gbc.gridy++;
this.add(lblNomBatiment, gbc);
gbc.gridy++;
this.add(lblTxtCapacite, gbc);
gbc.gridx++;
this.add(lblCapMax, gbc);
gbc.gridx = 0;
gbc.gridy++;
if (!modeDeJeu.equals("Difficile")) {
this.add(lblTxtNbJoueurCurrent, gbc);
gbc.gridx++;
this.add(lblNbJoueur, gbc);
gbc.gridx = 0;
gbc.gridy++;
this.add(lblTxtNbZombieCurrent, gbc);
gbc.gridx++;
this.add(lblNbZombie, gbc);
gbc.gridx = 0;
gbc.gridy++;
}
this.add(labelPickThisBat, gbc);
gbc.gridx++;
this.add(radioPickThisBat, gbc);
} else {
//JPanel panelCurrentBatiment = new JPanel();
//panelCurrentBatiment.setLayout(new GridBagLayout());
JPanel panelImageBatimentCurrent = new JPanel();
panelImageBatimentCurrent.setLayout(new GridBagLayout());
JPanel panelInfoCurrentBatiment = new JPanel();
panelInfoCurrentBatiment.setLayout(new GridBagLayout());
JPanel panelListeJoueurPresent = new JPanel();
panelListeJoueurPresent.setLayout(new GridBagLayout());
//GridBagConstraints gbcPanelCurrentBat = new GridBagConstraints(); // Ce panel contient les trois panels suivants
GridBagConstraints gbcPanelImageCurrentBat = new GridBagConstraints();
GridBagConstraints gbcPanelInfoCurrentBatiment = new GridBagConstraints();
GridBagConstraints gbcPanelListeJoueursPresent = new GridBagConstraints();
// Initialisation des contraintes du gbcImageCurrent
initGridBag(gbcPanelImageCurrentBat);
// Initialisation des contraintes du gbcInfoCurrentBatiment
initGridBag(gbcPanelInfoCurrentBatiment);
// Initialisation des contraintes du gbcListeJoueursPresent
initGridBag(gbcPanelListeJoueursPresent);
// Création de l'image du bâtiment actuel
JLabel imageCurrentBat = this.getImageFromNumber(1, 2);
lblNomBatiment = new JLabel("Nom bâtiment");
// Placement de l'image du bâtiment actuel dans son panel
panelImageBatimentCurrent.add(imageCurrentBat, gbcPanelImageCurrentBat);
gbcPanelImageCurrentBat.gridy++;
gbcPanelImageCurrentBat.insets = new Insets(10, 0, 0, 0); // Permet d'écarter le nom du bâtiment de l'image
panelImageBatimentCurrent.add(lblNomBatiment, gbcPanelImageCurrentBat);
// Rajout du panel de l'image dans le panel d'image + infos
this.add(panelImageBatimentCurrent, gbc);
gbc.gridx++;
// Création des différents label d'informations du bâtiment
JLabel labelCapaciteCurrent = new JLabel("Capacité d'accueil : ");
lblCapMax = new JLabel();
JLabel labelNbreJoueurCurrent = new JLabel("Nombre de joueurs présent : ");
lblNbJoueur = new JLabel();
JLabel labelNbreZombieCurrent = new JLabel("Nombre de zombies présent : ");
lblNbZombie = new JLabel();
panelInfoCurrentBatiment.add(labelCapaciteCurrent, gbcPanelInfoCurrentBatiment);
gbcPanelInfoCurrentBatiment.gridx++;
panelInfoCurrentBatiment.add(lblCapMax, gbcPanelInfoCurrentBatiment);
gbcPanelInfoCurrentBatiment.gridy++;
gbcPanelInfoCurrentBatiment.gridx = 0;
panelInfoCurrentBatiment.add(labelNbreJoueurCurrent, gbcPanelInfoCurrentBatiment);
gbcPanelInfoCurrentBatiment.gridx++;
panelInfoCurrentBatiment.add(lblNbJoueur, gbcPanelInfoCurrentBatiment);
gbcPanelInfoCurrentBatiment.gridy++;
gbcPanelInfoCurrentBatiment.gridx = 0;
panelInfoCurrentBatiment.add(labelNbreZombieCurrent, gbcPanelInfoCurrentBatiment);
gbcPanelInfoCurrentBatiment.gridx++;
panelInfoCurrentBatiment.add(lblNbZombie, gbcPanelInfoCurrentBatiment);
// Création des labels sur la liste des joueurs présent dans le bâtiment
JLabel labelListeJoueur = new JLabel("Liste des joueurs présent dans le bâtiment : ");
panelListeJoueurPresent.add(labelListeJoueur, gbcPanelListeJoueursPresent);
gbcPanelListeJoueursPresent.gridy++;
this.add(panelInfoCurrentBatiment, gbc);
gbc.gridx++;
this.add(panelListeJoueurPresent, gbc);
}
}
/**
* Méthode permettant de récupérer le JRadioButton de choix du bâtiment
*
* @return JRadioButton à renvoyer.
*/
public JRadioButton getRadioPickThisBat() {
return this.radioPickThisBat;
}
@Override
protected void paintChildren(Graphics g) {
Rectangle lesDimensions = this.getBounds();
Graphics2D graphic2D = (Graphics2D) this.getParent().getGraphics();
graphic2D.clearRect(lesDimensions.x - 20, lesDimensions.y - 20, 240, 270);
super.paintChildren(g);
if (drawImageFlag) {
this.dessinerContourPanel();
}
}
/**
* Méthode permettant de mettre à jour le booléen du dessin de l'image
*
* @param drawImageFlag Booléen de dessin du contour ou non
*/
public void setDrawImage(boolean drawImageFlag) {
this.drawImageFlag = drawImageFlag;
repaint();
}
/**
* Méthode permettant de redessiné tous les éléments sauf le contour.
*/
public void cacherContourPanel() {
setDrawImage(false);
}
/**
* Méthode permettant de dessiner un contour autour d'un JPanel
*
* @param leJPanel Le JPanel dont on veut dessiner le contour.
*/
public void dessinerContourPanel() {
Rectangle lesDimensions = this.getBounds();
Graphics2D graphic2D = (Graphics2D) this.getParent().getGraphics();
graphic2D.setColor(Color.ORANGE);
graphic2D.setStroke(new BasicStroke(2));
//graphic2D.drawRect(lesDimensions.x, lesDimensions.y, 210 ,260);
ImageIcon bloodStrokeIcon = new ImageIcon(Fenetre_Lancement.pathDossierImages + "/bloodStroke.png");
Image bloodStroke = bloodStrokeIcon.getImage();
graphic2D.drawImage(bloodStroke, lesDimensions.x - 15, lesDimensions.y - 15, 235, 270, null);
}
public JLabel getLblNbJoueur() {
return lblNbJoueur;
}
public JLabel getLblNomBatiment() {
return lblNomBatiment;
}
public void setLblNomBatiment(JLabel lblNomBatiment) {
this.lblNomBatiment = lblNomBatiment;
}
public JLabel getLblCapMax() {
return lblCapMax;
}
public void setLblCapMax(JLabel lblCapMax) {
this.lblCapMax = lblCapMax;
}
public JLabel getLblNbZombie() {
return lblNbZombie;
}
public void setLblNbZombie(JLabel lblNbZombie) {
this.lblNbZombie = lblNbZombie;
}
/**
* Méthode permettant de créer une image à partir du numéro sachant que les
* images s'appellent "bat+numéro"
*
* @param numeroDeImage Numéro de l'image (de 0 à 6)
* @return Retourne l'image en JLabel
*/
private JLabel getImageFromNumber(int numeroDeImage, int danger) {
ImageIcon currentBat;
if (Fenetre_Partie.modeJeu.equals("Facile")) {
currentBat = new ImageIcon(System.getProperty("user.dir") + "/images/bat" + numeroDeImage + "/bat" + numeroDeImage + "_" + danger + ".png");
} else {
currentBat = new ImageIcon(System.getProperty("user.dir") + "/images/bat" + numeroDeImage + "/bat" + numeroDeImage + ".png");
}
JLabel imageCurrentBat = new JLabel(currentBat);
return imageCurrentBat;
}
/**
* Méthode permettant de récupérer le risque encouru par le joueur pour le
* bâtiment donné
*
* @return Un indice entre 1 et 3 , 1 pour calme, et 3 pour risqué.
*/
private int getDangerBatiment() {
return 3;
}
/**
* Méthode permettant d'intialiser les valeurs de contraintes du GBC
*
* @param leGBC Le GridBagConstraints dont nous voulons initialiser les
* valeurs
*/
private void initGridBag(GridBagConstraints leGBC) {
leGBC.weightx = 1;
leGBC.weighty = 1;
leGBC.gridx = 0;
leGBC.gridy = 0;
}
/**
* @param isCurrent the isCurrent to set
*/
public void setIsCurrent(boolean isCurrent) {
this.isCurrent = isCurrent;
}
} |
Partager