diff options
Diffstat (limited to 'src/main/java/vue/simulation')
| -rw-r--r-- | src/main/java/vue/simulation/AfficheSimulation.java | 201 | ||||
| -rw-r--r-- | src/main/java/vue/simulation/SimAptAndWeaponsVBox.java | 130 | ||||
| -rw-r--r-- | src/main/java/vue/simulation/SimFigurinesVBox.java | 139 | ||||
| -rw-r--r-- | src/main/java/vue/simulation/SimHistogramme.java | 101 | ||||
| -rw-r--r-- | src/main/java/vue/simulation/SimUnitsVBox.java | 65 |
5 files changed, 636 insertions, 0 deletions
diff --git a/src/main/java/vue/simulation/AfficheSimulation.java b/src/main/java/vue/simulation/AfficheSimulation.java new file mode 100644 index 0000000..bb658a3 --- /dev/null +++ b/src/main/java/vue/simulation/AfficheSimulation.java | |||
| @@ -0,0 +1,201 @@ | |||
| 1 | package vue.simulation; | ||
| 2 | |||
| 3 | |||
| 4 | import vue.AfficheTopMenu; | ||
| 5 | |||
| 6 | import java.util.ArrayList; | ||
| 7 | |||
| 8 | import application.Battle; | ||
| 9 | import controlleur.ControlleurSimu; | ||
| 10 | import javafx.geometry.Insets; | ||
| 11 | import javafx.geometry.Pos; | ||
| 12 | import javafx.scene.Scene; | ||
| 13 | import javafx.scene.control.Button; | ||
| 14 | import javafx.scene.control.ChoiceBox; | ||
| 15 | import javafx.scene.control.ScrollPane; | ||
| 16 | import javafx.scene.image.Image; | ||
| 17 | import javafx.scene.image.ImageView; | ||
| 18 | import javafx.scene.layout.HBox; | ||
| 19 | import javafx.scene.layout.Pane; | ||
| 20 | import javafx.scene.layout.VBox; | ||
| 21 | import javafx.stage.Stage; | ||
| 22 | import modele.ArmeeListe; | ||
| 23 | |||
| 24 | import modele.User; | ||
| 25 | |||
| 26 | public class AfficheSimulation | ||
| 27 | { | ||
| 28 | private static SimAptAndWeaponsVBox weapons_aptitudes_menu = new SimAptAndWeaponsVBox(); | ||
| 29 | public static boolean inversion = false; // pour le bouton inversion | ||
| 30 | |||
| 31 | public static void refreshWeaponAndAptitude(SimAptAndWeaponsVBox wap) | ||
| 32 | { | ||
| 33 | weapons_aptitudes_menu.getChildren().clear(); | ||
| 34 | weapons_aptitudes_menu.getChildren().addAll(wap.getChildren()); // copie profonde | ||
| 35 | //weapons_aptitudes_menu.setStyle("-fx-border-width: 1; -fx-border-color: black; -fx-border-radius: 2; -fx-padding: 3px;"); | ||
| 36 | weapons_aptitudes_menu.setStyle("-fx-background-color: rgb(210, 210, 210); -fx-padding: 4px; -fx-border-color: black; -fx-border-radius: 4;"); | ||
| 37 | } | ||
| 38 | |||
| 39 | public static SimAptAndWeaponsVBox getWeaponsAtitudesMenu() { | ||
| 40 | return weapons_aptitudes_menu; | ||
| 41 | } | ||
| 42 | public static void cleanWeaponsAtitudesMenu() { | ||
| 43 | weapons_aptitudes_menu = new SimAptAndWeaponsVBox(); | ||
| 44 | } | ||
| 45 | |||
| 46 | public static void affiche(Stage primaryStage, User session) | ||
| 47 | { | ||
| 48 | // listes d'armées | ||
| 49 | ArrayList<ArmeeListe> lists_of_lists = session.getListes(); // listes d'objets ArmeeListe | ||
| 50 | String[] list_names = session.getListNames(); // tableau des noms des listes | ||
| 51 | |||
| 52 | System.out.print(session.getListes() + "wawa" + session.getListNames() + "wiwi"); | ||
| 53 | VBox root_box = new VBox(); | ||
| 54 | |||
| 55 | AfficheTopMenu menu = new AfficheTopMenu(primaryStage, session); // menu du haut de l'écran | ||
| 56 | |||
| 57 | HBox main = new HBox(); // partie principale de la fenêtre | ||
| 58 | |||
| 59 | |||
| 60 | /* -- colonne de gauche -- */ | ||
| 61 | VBox column1_box = new VBox(); | ||
| 62 | column1_box.prefWidthProperty().bind(main.widthProperty().multiply(0.3)); | ||
| 63 | |||
| 64 | ScrollPane column1_scrollpane = new ScrollPane(); // conteneur avec barres de défilement | ||
| 65 | column1_scrollpane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); // pas de barre horizontale | ||
| 66 | |||
| 67 | VBox column1 = new VBox(); | ||
| 68 | column1.prefWidthProperty().bind(column1_scrollpane.widthProperty()); | ||
| 69 | |||
| 70 | |||
| 71 | // menu choix armée | ||
| 72 | HBox col1_first_row = new HBox(); // menu déroulant + logo faction | ||
| 73 | ChoiceBox<String> list1_drop_down = new ChoiceBox<>(); | ||
| 74 | list1_drop_down.setStyle("-fx-font-size: 15;"); | ||
| 75 | list1_drop_down.prefWidthProperty().bind(column1_scrollpane.widthProperty()); | ||
| 76 | for(int i = 0; i < list_names.length; i++) | ||
| 77 | { | ||
| 78 | list1_drop_down.getItems().add(list_names[i]); | ||
| 79 | } | ||
| 80 | col1_first_row.getChildren().add(list1_drop_down); | ||
| 81 | column1.getChildren().add(col1_first_row); | ||
| 82 | |||
| 83 | // unités colonne 1 (par défaut) | ||
| 84 | SimUnitsVBox units_list1 = new SimUnitsVBox(1); | ||
| 85 | column1.getChildren().add(units_list1); | ||
| 86 | column1_scrollpane.setContent(column1); | ||
| 87 | |||
| 88 | VBox.setMargin(weapons_aptitudes_menu, new Insets(5,2,2,2)); | ||
| 89 | column1_box.getChildren().addAll(column1_scrollpane, weapons_aptitudes_menu); | ||
| 90 | |||
| 91 | |||
| 92 | /* -- colonne centrale -- */ | ||
| 93 | VBox column2 = new VBox(); | ||
| 94 | column2.prefWidthProperty().bind(main.widthProperty().multiply(0.4)); | ||
| 95 | column2.setAlignment(Pos.TOP_CENTER); | ||
| 96 | |||
| 97 | // boutons inverser et simuler | ||
| 98 | Button btn_simulate = new Button("Action !!"); | ||
| 99 | btn_simulate.setStyle("-fx-font-size: 15;"); | ||
| 100 | |||
| 101 | Image icons_inversion = new Image("/images/inversion_icons.png"); | ||
| 102 | ImageView icons_inversion_box = new ImageView(icons_inversion); | ||
| 103 | Button btn_reverse_armies = new Button(); | ||
| 104 | btn_reverse_armies.setGraphic(icons_inversion_box); | ||
| 105 | |||
| 106 | // grande image | ||
| 107 | Image image_col2 = new Image("/images/wip.jpg"); | ||
| 108 | ImageView image_box = new ImageView(); | ||
| 109 | image_box.setPreserveRatio(true); | ||
| 110 | image_box.fitWidthProperty().bind(column2.widthProperty()); | ||
| 111 | image_box.setImage(image_col2); | ||
| 112 | |||
| 113 | // contrairement aux VBox, ce conteneur ne s'adapte pas à la taille des ses enfants, c'est l'image qui s'adapte | ||
| 114 | Pane big_image_pane = new Pane(); | ||
| 115 | big_image_pane.getChildren().add(image_box); | ||
| 116 | |||
| 117 | // assemblage | ||
| 118 | column2.getChildren().addAll(btn_simulate, big_image_pane, btn_reverse_armies); | ||
| 119 | |||
| 120 | |||
| 121 | /* -- colonne de droite -- */ | ||
| 122 | ScrollPane column3_box = new ScrollPane(); // conteneur avec barres de défilement | ||
| 123 | column3_box.prefWidthProperty().bind(main.widthProperty().multiply(0.3)); | ||
| 124 | column3_box.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); // pas de barre horizontale | ||
| 125 | |||
| 126 | VBox column3 = new VBox(); | ||
| 127 | column3.prefWidthProperty().bind(column3_box.widthProperty()); | ||
| 128 | |||
| 129 | HBox col3_first_row = new HBox(); // menu déroulant + logo faction | ||
| 130 | ChoiceBox<String> list2_drop_down = new ChoiceBox<>(); | ||
| 131 | list2_drop_down.setStyle("-fx-font-size: 15;"); | ||
| 132 | list2_drop_down.prefWidthProperty().bind(column1_scrollpane.widthProperty()); | ||
| 133 | for(int i = 0; i < list_names.length; i++) | ||
| 134 | { | ||
| 135 | list2_drop_down.getItems().add(list_names[i]); | ||
| 136 | } | ||
| 137 | col3_first_row.getChildren().add(list2_drop_down); | ||
| 138 | column3.getChildren().add(col3_first_row); | ||
| 139 | |||
| 140 | // unités colonne 3 | ||
| 141 | SimUnitsVBox units_list2 = new SimUnitsVBox(2); | ||
| 142 | column3.getChildren().add(units_list2); | ||
| 143 | column3_box.setContent(column3); | ||
| 144 | |||
| 145 | |||
| 146 | /* -- assemblage -- */ | ||
| 147 | main.getChildren().addAll(column1_box, column2, column3_box); | ||
| 148 | root_box.getChildren().addAll(menu, main); | ||
| 149 | |||
| 150 | |||
| 151 | /* ACTION !! */ | ||
| 152 | btn_simulate.setOnAction(e -> { | ||
| 153 | if(Battle.getSelectedList(1) != null && Battle.getSelectedList(2) != null | ||
| 154 | && Battle.getSelectedUnitIndex(1) >= 0 && Battle.getSelectedUnitIndex(2) >= 0) | ||
| 155 | { | ||
| 156 | ControlleurSimu.afficheSimu(big_image_pane, Battle.getSelectedUnit(1), Battle.getSelectedUnit(2)); | ||
| 157 | } | ||
| 158 | else { | ||
| 159 | System.out.println("conditions non remplies pour faire une simulation"); | ||
| 160 | } | ||
| 161 | }); | ||
| 162 | |||
| 163 | |||
| 164 | Scene scene = new Scene(root_box,800,600); | ||
| 165 | primaryStage.setTitle("Simulation"); | ||
| 166 | primaryStage.setScene(scene); | ||
| 167 | primaryStage.show(); | ||
| 168 | |||
| 169 | |||
| 170 | // choix des listes d'armées | ||
| 171 | ArrayList<SimUnitsVBox> unit_lists = new ArrayList<SimUnitsVBox>(); | ||
| 172 | unit_lists.add(units_list1); | ||
| 173 | unit_lists.add(units_list2); | ||
| 174 | ArrayList<ChoiceBox<String>> lists_drop_down = new ArrayList<ChoiceBox<String>>(); | ||
| 175 | lists_drop_down.add(list1_drop_down); | ||
| 176 | lists_drop_down.add(list2_drop_down);; | ||
| 177 | ArrayList<HBox> first_rows = new ArrayList<HBox>(); | ||
| 178 | first_rows.add(col1_first_row); | ||
| 179 | first_rows.add(col3_first_row); | ||
| 180 | for(int i = 0; i < 2; i++) | ||
| 181 | { | ||
| 182 | final int j = i; | ||
| 183 | lists_drop_down.get(i).getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> { | ||
| 184 | if(!inversion) { | ||
| 185 | ControlleurSimu.selectAList(j + 1, lists_of_lists, newValue); | ||
| 186 | } | ||
| 187 | ControlleurSimu.PullDownUnits(j + 1, first_rows.get(j), unit_lists.get(j)); | ||
| 188 | }); | ||
| 189 | } | ||
| 190 | |||
| 191 | // inversion de l'attaquant et du défenseur | ||
| 192 | btn_reverse_armies.setOnAction(e -> { | ||
| 193 | if(Battle.getSelectedList(1) != null && Battle.getSelectedList(2) != null) { | ||
| 194 | ControlleurSimu.reverseArmies(lists_drop_down); | ||
| 195 | } | ||
| 196 | else { | ||
| 197 | System.out.println("conditions non remplies pour inverser listes"); | ||
| 198 | } | ||
| 199 | }); | ||
| 200 | } | ||
| 201 | } | ||
diff --git a/src/main/java/vue/simulation/SimAptAndWeaponsVBox.java b/src/main/java/vue/simulation/SimAptAndWeaponsVBox.java new file mode 100644 index 0000000..5014b59 --- /dev/null +++ b/src/main/java/vue/simulation/SimAptAndWeaponsVBox.java | |||
| @@ -0,0 +1,130 @@ | |||
| 1 | package vue.simulation; | ||
| 2 | |||
| 3 | import java.util.ArrayList; | ||
| 4 | |||
| 5 | import application.Battle; | ||
| 6 | import controlleur.ControlleurSimu; | ||
| 7 | import javafx.geometry.Insets; | ||
| 8 | import javafx.geometry.Pos; | ||
| 9 | import javafx.scene.control.CheckBox; | ||
| 10 | import javafx.scene.control.ChoiceBox; | ||
| 11 | import javafx.scene.control.Label; | ||
| 12 | import javafx.scene.control.Slider; | ||
| 13 | import javafx.scene.layout.HBox; | ||
| 14 | import javafx.scene.layout.FlowPane; | ||
| 15 | import javafx.scene.layout.VBox; | ||
| 16 | import modele.Aptitude; | ||
| 17 | import modele.Arme; | ||
| 18 | import modele.Figurine; | ||
| 19 | |||
| 20 | public class SimAptAndWeaponsVBox extends VBox | ||
| 21 | { | ||
| 22 | private int group_number; | ||
| 23 | private String group_name; | ||
| 24 | int group_size; | ||
| 25 | String[] weapon_names; | ||
| 26 | String[] aptitude_names; | ||
| 27 | |||
| 28 | //public SimAptAndWeaponsVBox(){} | ||
| 29 | |||
| 30 | // setters | ||
| 31 | public void setFigGroup(int fig_group_number, String fig_group_name, int fig_group_size){ | ||
| 32 | group_number = fig_group_number; | ||
| 33 | group_name = fig_group_name; | ||
| 34 | group_size = fig_group_size; | ||
| 35 | } | ||
| 36 | public void setArmes(ArrayList<Arme> weapon_list){ | ||
| 37 | weapon_names = new String[weapon_list.size()]; | ||
| 38 | for(int i = 0; i < weapon_list.size(); i++) { | ||
| 39 | weapon_names[i] = weapon_list.get(i).getNom(); | ||
| 40 | } | ||
| 41 | } | ||
| 42 | public void setAptitudes(ArrayList<Aptitude> aptitude_list){ | ||
| 43 | aptitude_names = new String[aptitude_list.size()]; | ||
| 44 | for(int i = 0; i < aptitude_list.size(); i++) { | ||
| 45 | aptitude_names[i] = aptitude_list.get(i).getName(); | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | public void setAptAndWeapons(ArrayList<Figurine> fig_group) | ||
| 50 | { | ||
| 51 | /* -- ligne 1: numéro du group et nom figurine -- */ | ||
| 52 | HBox first_row = new HBox(); | ||
| 53 | |||
| 54 | // numéro du group de figurines identiques | ||
| 55 | Label number = new Label(Integer.toString(group_number)); | ||
| 56 | number.setAlignment(Pos.CENTER); | ||
| 57 | number.setMinHeight(25); | ||
| 58 | number.setMinWidth(25); | ||
| 59 | number.setStyle("-fx-text-fill: white; -fx-background-color: black; -fx-background-radius: 4;"); | ||
| 60 | HBox.setMargin(number, new Insets(0, 2, 2, 0)); | ||
| 61 | |||
| 62 | Label figurine_name = new Label(group_name); | ||
| 63 | first_row.getChildren().addAll(number, figurine_name); | ||
| 64 | |||
| 65 | |||
| 66 | /* -- ligne 2: menu déroulant choix de l'arme -- */ | ||
| 67 | ChoiceBox<String> select_weapon = new ChoiceBox<String>(); | ||
| 68 | |||
| 69 | // sécurité | ||
| 70 | for(int i = 0; i < weapon_names.length; i++) | ||
| 71 | { | ||
| 72 | select_weapon.getItems().add(weapon_names[i]); | ||
| 73 | } | ||
| 74 | |||
| 75 | // valeur initiale menu déroulante | ||
| 76 | Arme weapon = Battle.getSeletedWeapon(1, group_name); | ||
| 77 | if(weapon != null) { | ||
| 78 | select_weapon.setValue(weapon.getNom()); | ||
| 79 | } | ||
| 80 | else { | ||
| 81 | select_weapon.setValue(weapon_names[0]); | ||
| 82 | } | ||
| 83 | // caractéristiques | ||
| 84 | FlowPane weapon_stats = new FlowPane(); | ||
| 85 | setWeaponStats(weapon, weapon_stats); | ||
| 86 | |||
| 87 | select_weapon.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> { | ||
| 88 | ControlleurSimu.selectAWeapon(this, newValue, fig_group, weapon_stats); | ||
| 89 | }); | ||
| 90 | |||
| 91 | // choix du nombre d'attaquants (= nombre d'armes) | ||
| 92 | Slider nb_of_attackers = new Slider(0, group_size, Battle.getSelectedUnit(1).getAliveFigsOfAGroup(group_name)); | ||
| 93 | nb_of_attackers.setMajorTickUnit(1); | ||
| 94 | nb_of_attackers.setMinorTickCount(0); | ||
| 95 | nb_of_attackers.setSnapToTicks(true); | ||
| 96 | //nb_of_attackers.setShowTickMarks(true); | ||
| 97 | nb_of_attackers.setShowTickLabels(true); | ||
| 98 | //nb_of_attackers.setBlockIncrement(1); | ||
| 99 | |||
| 100 | nb_of_attackers.valueProperty().addListener((observable, oldValue, newValue) -> { | ||
| 101 | ControlleurSimu.AliveFigsChoice(1, newValue.intValue(), group_name); | ||
| 102 | }); | ||
| 103 | |||
| 104 | // checkbox | ||
| 105 | FlowPane aptitudes = new FlowPane(); | ||
| 106 | for(int i = 0; i < aptitude_names.length; i++) | ||
| 107 | { | ||
| 108 | CheckBox one_aptitude = new CheckBox(aptitude_names[i]); | ||
| 109 | one_aptitude.setStyle("-fx-padding: 2px;"); | ||
| 110 | aptitudes.getChildren().add(one_aptitude); | ||
| 111 | |||
| 112 | one_aptitude.setOnAction(e -> { | ||
| 113 | ControlleurSimu.checkOrUncheckAnAptitude(one_aptitude.isSelected(), one_aptitude.getText(), fig_group); | ||
| 114 | }); | ||
| 115 | } | ||
| 116 | |||
| 117 | this.getChildren().addAll(first_row, select_weapon, weapon_stats, nb_of_attackers, aptitudes); | ||
| 118 | } | ||
| 119 | |||
| 120 | public void setWeaponStats(Arme weapon, FlowPane weapon_stats) { | ||
| 121 | weapon_stats.setStyle("-fx-padding: 3px;"); | ||
| 122 | Label A = new Label("A " + weapon.getA() + " | "); | ||
| 123 | Label F = new Label("F " + weapon.getF() + " | "); | ||
| 124 | Label PA = new Label("PA " + weapon.getPA() + " | "); | ||
| 125 | Label D = new Label("D " + weapon.getD() + " | "); | ||
| 126 | Label portee = new Label("portée " + weapon.getPortee()); | ||
| 127 | weapon_stats.getChildren().addAll(A, F, PA, D, portee); | ||
| 128 | } | ||
| 129 | } | ||
| 130 | |||
diff --git a/src/main/java/vue/simulation/SimFigurinesVBox.java b/src/main/java/vue/simulation/SimFigurinesVBox.java new file mode 100644 index 0000000..4940917 --- /dev/null +++ b/src/main/java/vue/simulation/SimFigurinesVBox.java | |||
| @@ -0,0 +1,139 @@ | |||
| 1 | package vue.simulation; | ||
| 2 | |||
| 3 | import java.util.ArrayList; | ||
| 4 | import java.util.HashMap; | ||
| 5 | |||
| 6 | import application.Battle; | ||
| 7 | import controlleur.ControlleurSimu; | ||
| 8 | import javafx.geometry.Insets; | ||
| 9 | import javafx.geometry.Pos; | ||
| 10 | import javafx.scene.control.Button; | ||
| 11 | import javafx.scene.control.Label; | ||
| 12 | import javafx.scene.control.Slider; | ||
| 13 | import javafx.scene.control.Spinner; | ||
| 14 | import javafx.scene.image.Image; | ||
| 15 | import javafx.scene.image.ImageView; | ||
| 16 | import javafx.scene.layout.HBox; | ||
| 17 | import javafx.scene.layout.FlowPane; | ||
| 18 | import javafx.scene.layout.VBox; | ||
| 19 | import modele.Figurine; | ||
| 20 | import modele.Unit; | ||
| 21 | |||
| 22 | public class SimFigurinesVBox extends VBox | ||
| 23 | { | ||
| 24 | private Unit unit; | ||
| 25 | private int column; | ||
| 26 | private ArrayList<SimAptAndWeaponsVBox> weapons_aptitudes_menu_view = new ArrayList<SimAptAndWeaponsVBox>(); | ||
| 27 | private boolean open = false; // les figurines sont cachées par défaut | ||
| 28 | |||
| 29 | public SimFigurinesVBox(int col, Unit unit){ | ||
| 30 | column = col; | ||
| 31 | this.unit = unit; | ||
| 32 | this.setStyle("-fx-padding: 2px;"); | ||
| 33 | } | ||
| 34 | |||
| 35 | public boolean isOpen(){ | ||
| 36 | return open; | ||
| 37 | } | ||
| 38 | public void changeState(){ | ||
| 39 | open ^= true; // inversion de bouléen avec un masque 00000001 | ||
| 40 | } | ||
| 41 | |||
| 42 | public void setFigurines() | ||
| 43 | { | ||
| 44 | /* -- boucle sur les groupes de figuriones -- */ | ||
| 45 | int i = 0; // valeurs des boutons numérotés | ||
| 46 | for(HashMap.Entry<String, ArrayList<Figurine>> entry : unit.getIdenticalFigsGroups().entrySet()) | ||
| 47 | { | ||
| 48 | FlowPane fig_group = new FlowPane(); | ||
| 49 | //fig_group.setStyle("-fx-background-color: rgb(220, 220, 220);"); | ||
| 50 | String fig_name = entry.getKey(); | ||
| 51 | ArrayList<Figurine> fig_list = entry.getValue(); | ||
| 52 | i++; | ||
| 53 | if(column == 1) | ||
| 54 | { | ||
| 55 | // boutons numérotés des groupes de figurines | ||
| 56 | Button number = new Button(Integer.toString(i)); | ||
| 57 | number.setAlignment(Pos.CENTER); | ||
| 58 | number.setMinHeight(25); | ||
| 59 | number.setMinWidth(25); | ||
| 60 | number.setStyle("-fx-text-fill: white; -fx-background-color: black;"); | ||
| 61 | fig_group.getChildren().add(number); | ||
| 62 | |||
| 63 | // zone des armes et aptitudes | ||
| 64 | SimAptAndWeaponsVBox weapons_aptitudes_menu = new SimAptAndWeaponsVBox(); | ||
| 65 | weapons_aptitudes_menu.setFigGroup(i, fig_name, fig_list.size()); | ||
| 66 | weapons_aptitudes_menu_view.add(weapons_aptitudes_menu); | ||
| 67 | |||
| 68 | number.setOnAction(e -> | ||
| 69 | { | ||
| 70 | ControlleurSimu.makeWeaponsAndAptitudeZone(fig_list, weapons_aptitudes_menu); | ||
| 71 | }); | ||
| 72 | } | ||
| 73 | else { | ||
| 74 | Label fig_name_label = new Label(fig_name); | ||
| 75 | fig_name_label.setStyle("-fx-padding: 0 5px 0 0"); | ||
| 76 | fig_group.getChildren().add(fig_name_label); | ||
| 77 | |||
| 78 | Slider nb_of_defenders = new Slider(0, fig_list.size(), | ||
| 79 | Battle.getSelectedUnit(2).getAliveFigsOfAGroup(fig_name)); | ||
| 80 | nb_of_defenders.setMajorTickUnit(1); | ||
| 81 | nb_of_defenders.setMinorTickCount(0); | ||
| 82 | nb_of_defenders.setSnapToTicks(true); | ||
| 83 | //nb_of_attackers.setShowTickMarks(true); | ||
| 84 | nb_of_defenders.setShowTickLabels(true); | ||
| 85 | //nb_of_attackers.setBlockIncrement(1); | ||
| 86 | |||
| 87 | fig_group.getChildren().add(nb_of_defenders); | ||
| 88 | |||
| 89 | nb_of_defenders.valueProperty().addListener((observable, oldValue, newValue) -> { | ||
| 90 | ControlleurSimu.AliveFigsChoice(2, newValue.intValue(), fig_name); | ||
| 91 | }); | ||
| 92 | } | ||
| 93 | |||
| 94 | |||
| 95 | /* -- figurines d'un groupe -- */ | ||
| 96 | for(Figurine fig : fig_list) | ||
| 97 | { | ||
| 98 | HBox one_fig_box = new HBox(); | ||
| 99 | Image one_image; | ||
| 100 | if(fig.getHP() > 0) { | ||
| 101 | one_image = new Image("/images/android-fill.png"); | ||
| 102 | } | ||
| 103 | else { | ||
| 104 | one_image = new Image("/images/android-line.png"); | ||
| 105 | } | ||
| 106 | ImageView one_image_box = new ImageView(); | ||
| 107 | one_image_box.setPreserveRatio(true); | ||
| 108 | //one_image_box.setFitHeight(24); // appeler une des deux méthodes de dimensionnement | ||
| 109 | one_image_box.setFitWidth(24); | ||
| 110 | one_image_box.setImage(one_image); | ||
| 111 | one_fig_box.getChildren().add(one_image_box); | ||
| 112 | |||
| 113 | if(column == 1) { | ||
| 114 | Label hp_label = new Label(fig.getHP() + " PV "); | ||
| 115 | one_fig_box.getChildren().add(hp_label); | ||
| 116 | } | ||
| 117 | else { | ||
| 118 | Label hp_label = new Label("PV:"); | ||
| 119 | Spinner<Integer> spinner = new Spinner<>(0, fig.getHPMax(), fig.getHP()); | ||
| 120 | spinner.setMaxWidth(55); | ||
| 121 | one_fig_box.getChildren().add(hp_label); | ||
| 122 | one_fig_box.getChildren().add(spinner); | ||
| 123 | one_fig_box.setStyle("-fx-padding: 0 3px 0 0;"); | ||
| 124 | |||
| 125 | spinner.valueProperty().addListener((obs, oldValue, newValue) -> { | ||
| 126 | ControlleurSimu.hpUpdate(newValue, fig, one_image_box); | ||
| 127 | }); | ||
| 128 | } | ||
| 129 | |||
| 130 | SimFigurinesVBox.setMargin(one_fig_box, new Insets(5)); | ||
| 131 | fig_group.getChildren().add(one_fig_box); | ||
| 132 | } | ||
| 133 | SimFigurinesVBox.setMargin(fig_group, new Insets(3)); | ||
| 134 | |||
| 135 | this.getChildren().add(fig_group); | ||
| 136 | } | ||
| 137 | } | ||
| 138 | } | ||
| 139 | |||
diff --git a/src/main/java/vue/simulation/SimHistogramme.java b/src/main/java/vue/simulation/SimHistogramme.java new file mode 100644 index 0000000..519c90b --- /dev/null +++ b/src/main/java/vue/simulation/SimHistogramme.java | |||
| @@ -0,0 +1,101 @@ | |||
| 1 | package vue.simulation; | ||
| 2 | import javafx.application.Application; | ||
| 3 | import javafx.scene.Scene; | ||
| 4 | import javafx.scene.chart.Axis; | ||
| 5 | import javafx.scene.chart.BarChart; | ||
| 6 | import javafx.scene.chart.CategoryAxis; | ||
| 7 | import javafx.scene.chart.NumberAxis; | ||
| 8 | import javafx.scene.chart.XYChart; | ||
| 9 | import javafx.scene.layout.Pane; | ||
| 10 | import javafx.scene.layout.Priority; | ||
| 11 | import javafx.scene.layout.VBox; | ||
| 12 | import javafx.stage.Stage; | ||
| 13 | |||
| 14 | public class SimHistogramme extends Pane{ | ||
| 15 | private Pane p; | ||
| 16 | |||
| 17 | |||
| 18 | |||
| 19 | // public SimHistogramme() { | ||
| 20 | // super(); | ||
| 21 | // } | ||
| 22 | |||
| 23 | public static void setHist(int[] tabdegat ,int[] tabmort, float degat_moyen ,float mort_moyen,Pane p) { | ||
| 24 | Axis<String> xAxis = new CategoryAxis(); | ||
| 25 | xAxis.setLabel("nbr mort"); | ||
| 26 | |||
| 27 | NumberAxis yAxis = new NumberAxis(); | ||
| 28 | yAxis.setLabel("pourcentage"); | ||
| 29 | |||
| 30 | Axis<String> xAxis2 = new CategoryAxis(); | ||
| 31 | xAxis2.setLabel("nbr degat"); | ||
| 32 | |||
| 33 | javafx.scene.chart.NumberAxis yAxis2 = new NumberAxis(); | ||
| 34 | yAxis2.setLabel("pourcentage"); | ||
| 35 | |||
| 36 | // Create a BarChart | ||
| 37 | BarChart<String, Number> barChart = new BarChart<String, Number>(xAxis, yAxis); | ||
| 38 | BarChart<String, Number> barChart2 = new BarChart<String, Number>(xAxis2, yAxis2); | ||
| 39 | |||
| 40 | // Series 1 - Data of 2014 | ||
| 41 | XYChart.Series<String, Number> dataSeries1 = new XYChart.Series<String, Number>(); | ||
| 42 | //dataSeries1.setName("mort moyen : "+mort_moyen); | ||
| 43 | for(int i=0;i<tabmort.length;i++) { | ||
| 44 | if(tabmort[i]!=0) { | ||
| 45 | dataSeries1.getData().add(new XYChart.Data<String, Number>(""+i , tabmort[i]/100)); | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | //barChart.getData().add(dataSeries1); | ||
| 50 | |||
| 51 | |||
| 52 | // Series 1 - Data of 2014 | ||
| 53 | XYChart.Series<String, Number> dataSeries2 = new XYChart.Series<String, Number>(); | ||
| 54 | //dataSeries2.setName("degat moyen : "+degat_moyen); | ||
| 55 | for(int i=0;i<tabdegat.length;i++) { | ||
| 56 | if(tabdegat[i]!=0) { | ||
| 57 | dataSeries2.getData().add(new XYChart.Data<String, Number>(""+i , tabdegat[i]/100)); | ||
| 58 | } | ||
| 59 | } | ||
| 60 | |||
| 61 | barChart.getData().add(dataSeries1); | ||
| 62 | barChart2.getData().add(dataSeries2); | ||
| 63 | |||
| 64 | |||
| 65 | |||
| 66 | VBox vbox = new VBox(); | ||
| 67 | vbox.getChildren().add(barChart); | ||
| 68 | vbox.getChildren().add(barChart2); | ||
| 69 | barChart.maxWidthProperty().bind(p.widthProperty()); | ||
| 70 | barChart2.maxWidthProperty().bind(p.widthProperty()); | ||
| 71 | barChart2.prefHeight(150); | ||
| 72 | barChart.prefHeight(150); | ||
| 73 | barChart.lookupAll(".default-color0.chart-bar") | ||
| 74 | .forEach(n -> n.setStyle("-fx-bar-fill: red;")); | ||
| 75 | barChart2.lookupAll(".default-color0.chart-bar") | ||
| 76 | .forEach(n -> n.setStyle("-fx-bar-fill: green;")); | ||
| 77 | |||
| 78 | |||
| 79 | barChart.setMaxHeight(220); | ||
| 80 | barChart2.setMaxHeight(220); | ||
| 81 | barChart.prefHeight(200); | ||
| 82 | barChart.setLegendVisible(false); | ||
| 83 | barChart2.setLegendVisible(false); | ||
| 84 | barChart.setTitle("nbr mort moyen : "+mort_moyen); | ||
| 85 | barChart2.setTitle("nbr degat moyen : "+degat_moyen); | ||
| 86 | barChart2.prefHeight(200); | ||
| 87 | VBox.setVgrow(barChart, Priority.ALWAYS); | ||
| 88 | VBox.setVgrow(barChart2, Priority.ALWAYS); | ||
| 89 | //vbox.setSpacing(10); | ||
| 90 | |||
| 91 | |||
| 92 | p.getChildren().add(vbox); | ||
| 93 | } | ||
| 94 | |||
| 95 | |||
| 96 | |||
| 97 | |||
| 98 | //BarChart<String, Number> barChart = new BarChart<String, Number>(xAxis, yAxis); | ||
| 99 | |||
| 100 | } | ||
| 101 | |||
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 | } | ||
