diff options
| author | polo <ordipolo@gmx.fr> | 2026-07-02 00:14:17 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2026-07-02 00:14:17 +0200 |
| commit | 0c2c3ee5a55f36d270171f2f67938542e251fdc5 (patch) | |
| tree | 8ea4d6a7ad09a5b1389b829980a7a5476982e754 /src/main/java/vue/simulation/AfficheSimulation.java | |
| download | ppe_javafx-0c2c3ee5a55f36d270171f2f67938542e251fdc5.tar.gz ppe_javafx-0c2c3ee5a55f36d270171f2f67938542e251fdc5.tar.bz2 ppe_javafx-0c2c3ee5a55f36d270171f2f67938542e251fdc5.zip | |
fork utilisant maven
Diffstat (limited to 'src/main/java/vue/simulation/AfficheSimulation.java')
| -rw-r--r-- | src/main/java/vue/simulation/AfficheSimulation.java | 201 |
1 files changed, 201 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 | } | ||
