Updated launcher to allow for character selection

This commit is contained in:
François Autin 2021-06-23 16:12:09 +02:00
parent f9043d6deb
commit 9757634881
6 changed files with 96 additions and 16 deletions

View File

@ -16,6 +16,9 @@ import javafx.collections.ObservableList;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.ChoiceBox;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.VBox;
import javafx.scene.control.CheckBox;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
@ -23,6 +26,7 @@ import javafx.fxml.*;
import java.util.HashMap;
import java.util.Map;
@SuppressWarnings("unchecked")
public class Launcher extends Application {
public static Launcher pointer;
@ -45,7 +49,6 @@ public class Launcher extends Application {
* Start method is used by Launcher as an implementation of the Application class to create a JavaFX thread to display the GUI window
*/
@SuppressWarnings("unchecked")
public void start(Stage primaryStage) throws Exception {
FXMLLoader loader = new FXMLLoader(getClass().getResource("launcher.fxml"));
@ -72,7 +75,21 @@ public class Launcher extends Application {
fs.setSelected(false);
}
VBox v1 = (VBox) namespace.get("p1");
ChoiceBox<String> b1 = (ChoiceBox<String>) v1.getChildren().get(1);
VBox v2 = (VBox) namespace.get("p2");
ChoiceBox<String> b2 = (ChoiceBox<String>) v2.getChildren().get(1);
ObservableList<String> availablechar = FXCollections.observableArrayList("Blue");
b1.setItems(availablechar);
b2.setItems(availablechar);
if(setter.getChar1().equals("blue")) {
b1.setValue("Blue");
}
if(setter.getChar2().equals("blue")) {
b2.setValue("Blue");
}
primaryStage.initStyle(StageStyle.UNDECORATED);
primaryStage.setTitle("Boulevard Combattant");
@ -81,7 +98,6 @@ public class Launcher extends Application {
}
@SuppressWarnings("unchecked")
@FXML
public void runGame() {
try {
@ -126,8 +142,15 @@ public class Launcher extends Application {
CheckBox fs = (CheckBox) namespace.get("fullscreen");
pointer.arraysettings.put("fullscreen", fs.isSelected());
pointer.arraysettings.put("rounds", 3);
pointer.arraysettings.put("character1", "default");
pointer.arraysettings.put("character2", "default");
VBox vp1 = (VBox) namespace.get("p1");
ChoiceBox<String> p1 = (ChoiceBox<String>) vp1.getChildren().get(1);
pointer.arraysettings.put("character1", p1.getValue().toLowerCase());
VBox vp2 = (VBox) namespace.get("p2");
ChoiceBox<String> p2 = (ChoiceBox<String>) vp2.getChildren().get(1);
pointer.arraysettings.put("character2", p2.getValue().toLowerCase());
pointer.arraysettings.put("stage", "default");
setter.setSettings();
match.main(null);
@ -153,6 +176,36 @@ public class Launcher extends Application {
getHostServices().showDocument("https://gitlab.istic.univ-rennes1.fr/fautin/jeu-de-combat");
}
@FXML
public void chp1() {
VBox v1 = (VBox) namespace.get("p1");
ImageView iv1 = (ImageView) v1.getChildren().get(0);
ChoiceBox<String> b1 = (ChoiceBox<String>) v1.getChildren().get(1);
switch (b1.getValue()) {
case "Blue":
iv1.setImage(new Image("/launcher/charfaces/blue.png"));
break;
default:
iv1.setImage(new Image("/launcher/default.png"));
break;
}
}
@FXML
public void chp2() {
VBox v1 = (VBox) namespace.get("p2");
ImageView iv1 = (ImageView) v1.getChildren().get(0);
ChoiceBox<String> b1 = (ChoiceBox<String>) v1.getChildren().get(1);
switch (b1.getValue()) {
case "Blue":
iv1.setImage(new Image("/launcher/charfaces/blue.png"));
break;
default:
iv1.setImage(new Image("/launcher/default.png"));
break;
}
}
public HashMap<String, Object> getArraysettings() {
return arraysettings;
}

View File

@ -27,7 +27,7 @@ public class Settings {
String stage = (String) set.get("stage");
config.write(width, height, rounds, fullscreen, character1, character2, stage);
} catch (Exception e) {
config.write(800, 600, 3, false, "default", "default", "default");
config.write(800, 600, 3, false, "blue", "blue", "default");
System.out.println("Incorrect config file");
}
}
@ -40,4 +40,12 @@ public class Settings {
return config.fullscreen;
}
public String getChar1() {
return config.p1;
}
public String getChar2() {
return config.p2;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
src/launcher/default.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 212 KiB

View File

@ -19,7 +19,7 @@
<children>
<VBox fx:id="sidepanel"
prefWidth="200" prefHeight="1280">
minWidth="280" prefHeight="1280">
<children>
<ImageView fx:id="logo" fitHeight="120" fitWidth="120">
@ -61,18 +61,24 @@
<HBox fx:id="picker">
<children>
<VBox fx:id="p1" styleClass="pane_p">
<VBox fx:id="p1" styleClass="pane_p" prefWidth="500" prefHeight="720">
<children>
<ImageView/>
<ChoiceBox styleClass="char_box" />
<ChoiceBox styleClass="contr_box" />
<ImageView styleClass="char_img" fitHeight="400" fitWidth="400">
<image>
<Image url="/launcher/default.png"/>
</image>
</ImageView>
<ChoiceBox styleClass="char_box" onAction="#chp1"/>
</children>
</VBox>
<VBox fx:id="p2" styleClass="pane_p">
<VBox fx:id="p2" styleClass="pane_p" prefWidth="500" prefHeight="720">
<children>
<ImageView/>
<ChoiceBox styleClass="char_box" />
<ChoiceBox styleClass="contr_box" />
<ImageView styleClass="char_img" fx:id="char_p2" fitHeight="400" fitWidth="400">
<image>
<Image url="/launcher/default.png"/>
</image>
</ImageView>
<ChoiceBox styleClass="char_box" onAction="#chp2"/>
</children>
</VBox>
</children>

View File

@ -1,5 +1,6 @@
#window {
-fx-background-color: #131320;
-fx-font-size: 1.25em;
}
Text, Label {
@ -19,7 +20,7 @@ Text, Label {
/* Logo */
.title {
-fx-font-weight: bold;
-fx-font-size: 1.35em;
-fx-font-size: 1.5em;
-fx-padding: 1;
}
@ -47,7 +48,7 @@ Text, Label {
/* Settings */
.res_box Label {
ChoiceBox Label {
-fx-fill: #000000;
-fx-text-fill: #000000;
}
@ -66,3 +67,15 @@ Text, Label {
Hyperlink:visited {
-fx-text-fill: #0095c8;
}
/**********/
/* Picker */
/**********/
#picker {
-fx-alignment: top-center;
}
#picker VBox {
-fx-alignment: top-center;
}