diff options
Diffstat (limited to 'src/main/java/vue/simulation/SimUnitsVBox.java')
| -rw-r--r-- | src/main/java/vue/simulation/SimUnitsVBox.java | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/main/java/vue/simulation/SimUnitsVBox.java b/src/main/java/vue/simulation/SimUnitsVBox.java new file mode 100644 index 0000000..df02f82 --- /dev/null +++ b/src/main/java/vue/simulation/SimUnitsVBox.java | |||
| @@ -0,0 +1,65 @@ | |||
| 1 | package vue.simulation; | ||
| 2 | |||
| 3 | import java.util.ArrayList; | ||
| 4 | |||
| 5 | import application.Battle; | ||
| 6 | import controlleur.ControlleurSimu; | ||
| 7 | import javafx.scene.control.Button; | ||
| 8 | import javafx.scene.layout.VBox; | ||
| 9 | import modele.Unit; | ||
| 10 | |||
| 11 | public class SimUnitsVBox extends VBox | ||
| 12 | { | ||
| 13 | private ArrayList<Button> buttons = new ArrayList<Button>(); | ||
| 14 | private ArrayList<SimFigurinesVBox> fig_boxes = new ArrayList<SimFigurinesVBox>(); | ||
| 15 | private int column; // = 1 ou 2 | ||
| 16 | |||
| 17 | public SimUnitsVBox(int col){ | ||
| 18 | column = col; | ||
| 19 | this.setStyle("-fx-padding: 2px;"); | ||
| 20 | } | ||
| 21 | |||
| 22 | // getters | ||
| 23 | public ArrayList<Button> getButtons(){ | ||
| 24 | return buttons; | ||
| 25 | } | ||
| 26 | public ArrayList<SimFigurinesVBox> getFigBoxes(){ | ||
| 27 | return fig_boxes; | ||
| 28 | } | ||
| 29 | |||
| 30 | // afficher les unités de la liste déroulée | ||
| 31 | public void setList(int num_list) | ||
| 32 | { | ||
| 33 | ArrayList<Unit> units = Battle.getSelectedList(num_list).getUnits(); | ||
| 34 | for(int i = 0; i < units.size(); i++) | ||
| 35 | { | ||
| 36 | VBox one_unit = new VBox(); | ||
| 37 | |||
| 38 | // chaque unité est un bouton pour dérouler des figurines | ||
| 39 | Button tmp_button = new Button(units.get(i).getName()); | ||
| 40 | tmp_button.setMaxWidth(Double.MAX_VALUE); | ||
| 41 | one_unit.getChildren().add(tmp_button); | ||
| 42 | buttons.add(tmp_button); | ||
| 43 | |||
| 44 | // créer une zone de figurines par unité | ||
| 45 | SimFigurinesVBox one_fig_box = new SimFigurinesVBox(column, units.get(i)); | ||
| 46 | one_unit.getChildren().add(one_fig_box); | ||
| 47 | fig_boxes.add(one_fig_box); | ||
| 48 | |||
| 49 | this.getChildren().add(one_unit); | ||
| 50 | } | ||
| 51 | |||
| 52 | /* -- activation des boutons pour dérouler les unités --*/ | ||
| 53 | for(int i = 0; i < buttons.size(); i++) | ||
| 54 | { | ||
| 55 | final int j = i; // merci chatgpt pour le trick! | ||
| 56 | // java interdit à i et c d'être paramètres de la fonction lambda parce qu'ils changent à chaque itération | ||
| 57 | // on garantit que col et j seront constants (final) dans la méthode setOnAction | ||
| 58 | |||
| 59 | buttons.get(i).setOnAction(e -> | ||
| 60 | { | ||
| 61 | ControlleurSimu.selectAnUnit(this, column, j); | ||
| 62 | }); | ||
| 63 | } | ||
| 64 | } | ||
| 65 | } | ||
