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.Parent;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.control.ChoiceBox; 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.scene.control.CheckBox;
import javafx.stage.Stage; import javafx.stage.Stage;
import javafx.stage.StageStyle; import javafx.stage.StageStyle;
@ -23,6 +26,7 @@ import javafx.fxml.*;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@SuppressWarnings("unchecked")
public class Launcher extends Application { public class Launcher extends Application {
public static Launcher pointer; 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 * 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 { public void start(Stage primaryStage) throws Exception {
FXMLLoader loader = new FXMLLoader(getClass().getResource("launcher.fxml")); FXMLLoader loader = new FXMLLoader(getClass().getResource("launcher.fxml"));
@ -72,7 +75,21 @@ public class Launcher extends Application {
fs.setSelected(false); 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.initStyle(StageStyle.UNDECORATED);
primaryStage.setTitle("Boulevard Combattant"); primaryStage.setTitle("Boulevard Combattant");
@ -81,7 +98,6 @@ public class Launcher extends Application {
} }
@SuppressWarnings("unchecked")
@FXML @FXML
public void runGame() { public void runGame() {
try { try {
@ -126,8 +142,15 @@ public class Launcher extends Application {
CheckBox fs = (CheckBox) namespace.get("fullscreen"); CheckBox fs = (CheckBox) namespace.get("fullscreen");
pointer.arraysettings.put("fullscreen", fs.isSelected()); pointer.arraysettings.put("fullscreen", fs.isSelected());
pointer.arraysettings.put("rounds", 3); 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"); pointer.arraysettings.put("stage", "default");
setter.setSettings(); setter.setSettings();
match.main(null); match.main(null);
@ -152,6 +175,36 @@ public class Launcher extends Application {
public void website() { public void website() {
getHostServices().showDocument("https://gitlab.istic.univ-rennes1.fr/fautin/jeu-de-combat"); 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() { public HashMap<String, Object> getArraysettings() {
return arraysettings; return arraysettings;

View File

@ -27,7 +27,7 @@ public class Settings {
String stage = (String) set.get("stage"); String stage = (String) set.get("stage");
config.write(width, height, rounds, fullscreen, character1, character2, stage); config.write(width, height, rounds, fullscreen, character1, character2, stage);
} catch (Exception e) { } 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"); System.out.println("Incorrect config file");
} }
} }
@ -39,5 +39,13 @@ public class Settings {
public boolean getFullscreen() { public boolean getFullscreen() {
return config.fullscreen; 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> <children>
<VBox fx:id="sidepanel" <VBox fx:id="sidepanel"
prefWidth="200" prefHeight="1280"> minWidth="280" prefHeight="1280">
<children> <children>
<ImageView fx:id="logo" fitHeight="120" fitWidth="120"> <ImageView fx:id="logo" fitHeight="120" fitWidth="120">
@ -61,18 +61,24 @@
<HBox fx:id="picker"> <HBox fx:id="picker">
<children> <children>
<VBox fx:id="p1" styleClass="pane_p"> <VBox fx:id="p1" styleClass="pane_p" prefWidth="500" prefHeight="720">
<children> <children>
<ImageView/> <ImageView styleClass="char_img" fitHeight="400" fitWidth="400">
<ChoiceBox styleClass="char_box" /> <image>
<ChoiceBox styleClass="contr_box" /> <Image url="/launcher/default.png"/>
</image>
</ImageView>
<ChoiceBox styleClass="char_box" onAction="#chp1"/>
</children> </children>
</VBox> </VBox>
<VBox fx:id="p2" styleClass="pane_p"> <VBox fx:id="p2" styleClass="pane_p" prefWidth="500" prefHeight="720">
<children> <children>
<ImageView/> <ImageView styleClass="char_img" fx:id="char_p2" fitHeight="400" fitWidth="400">
<ChoiceBox styleClass="char_box" /> <image>
<ChoiceBox styleClass="contr_box" /> <Image url="/launcher/default.png"/>
</image>
</ImageView>
<ChoiceBox styleClass="char_box" onAction="#chp2"/>
</children> </children>
</VBox> </VBox>
</children> </children>

View File

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