diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Controller/IntroController.java b/src/main/java/de/hdm_stuttgart/battlearena/Controller/IntroController.java index 2c4472104e35751cedb56601d0b5f6b13f72e278..a18c1cb60b5cbe6bcd1371ff7e4951b09dc32da2 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Controller/IntroController.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Controller/IntroController.java @@ -1,6 +1,9 @@ package de.hdm_stuttgart.battlearena.Controller; import de.hdm_stuttgart.battlearena.Controller.Utilities.CreateMediaPlayer; +import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Exceptions.DatabaseException; +import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Persistence; +import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.StartupThread; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.fxml.Initializable; @@ -8,6 +11,8 @@ import javafx.scene.Cursor; import javafx.scene.layout.BorderPane; import javafx.scene.media.MediaPlayer; import javafx.scene.media.MediaView; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.io.File; import java.io.IOException; @@ -27,12 +32,15 @@ public class IntroController implements Initializable { private File file = new File(fileName + videos[0]); private int counter = 0; private MediaPlayer mediaPlayer; + private Persistence playerAccountSingleton = Persistence.getInstance(); + private static final Logger log = LogManager.getLogger(Persistence.class); @Override public void initialize(URL url, ResourceBundle resourceBundle) { introParent.setStyle("-fx-background-color: black;"); introParent.setCursor(Cursor.NONE); createMediaPlayer(); + new StartupThread().run(); } private void createMediaPlayer() { @@ -42,7 +50,11 @@ public class IntroController implements Initializable { mediaPlayer.setOnEndOfMedia(() -> { if (counter == videos.length - 1) { - videoEnd(); + try { + videoEnd(); + } catch (IOException e) { + throw new RuntimeException(e); + } } else { nextVideo(); } @@ -51,21 +63,42 @@ public class IntroController implements Initializable { // TODO: make any button pressed work introParent.setOnMouseClicked((mouseEvent) -> { if (counter == videos.length - 1) { - videoEnd(); + try { + videoEnd(); + } catch (IOException e) { + throw new RuntimeException(e); + } } else { nextVideo(); } }); } - private void videoEnd() { -// TODO: check if player exists - try { - mediaPlayer.dispose(); - introParent.getScene().setRoot(FXMLLoader.load(Objects.requireNonNull(getClass().getResource("/fxml/PlayerCreateScene.fxml")))); - } catch (IOException e) { - throw new RuntimeException(); + private void videoEnd() throws IOException { + boolean isStartUp = true, noAccount = false, statsLoaded = false; + while (isStartUp) { + try { + playerAccountSingleton.loadPlayerAccount(); + playerAccountSingleton.verifyPlayerAccount(); + mediaPlayer.dispose(); + isStartUp = false; + } catch (DatabaseException e) { + noAccount = true; +// TODO: reset player account if account fails to load in loadPlayerAccount() + } + if (noAccount) { + introParent.getScene().setRoot(FXMLLoader.load(Objects.requireNonNull(getClass().getResource("/fxml/PlayerCreateScene.fxml")))); + } + } + while (!statsLoaded) { // while loop because Martin said so + try { + playerAccountSingleton.loadPlayerStatistics(); + statsLoaded = true; + } catch (DatabaseException e) { + log.error(e); + } } + introParent.getScene().setRoot(FXMLLoader.load(Objects.requireNonNull(getClass().getResource("/fxml/MenuBorderPane.fxml")))); } private void nextVideo() { diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Controller/MapForgeController.java b/src/main/java/de/hdm_stuttgart/battlearena/Controller/MapForgeController.java index 7f57a6dd566a493f12e2c9ffdea4772df823f130..70564607f62c80a0ef9a5e90cc7823244eac2fa9 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Controller/MapForgeController.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Controller/MapForgeController.java @@ -2,6 +2,8 @@ package de.hdm_stuttgart.battlearena.Controller; import de.hdm_stuttgart.battlearena.Controller.Utilities.MusicPlayerSingleton; import de.hdm_stuttgart.battlearena.Controller.Utilities.SceneLoader; +import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Exceptions.DatabaseException; +import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Persistence; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.scene.layout.VBox; @@ -13,6 +15,7 @@ public class MapForgeController { @FXML private VBox parent; SceneLoader sceneLoader = new SceneLoader(); + private Persistence updateMaps = Persistence.getInstance(); @FXML private void mapEditorScene() { @@ -30,13 +33,9 @@ public class MapForgeController { } @FXML - private void updateMapScene() { - try { - parent.getScene().setRoot(FXMLLoader.load(Objects.requireNonNull(getClass().getResource("/fxml/PlayerCreateScene.fxml")))); - MusicPlayerSingleton.getInstance().getMediaPlayer().dispose(); - } catch (IOException e) { - throw new RuntimeException(); - } + private void updateMapScene() throws DatabaseException { + updateMaps.updateCoreMaps(); +// TODO: set message label if update was successful or not } @FXML diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Controller/MapSelectionController.java b/src/main/java/de/hdm_stuttgart/battlearena/Controller/MapSelectionController.java new file mode 100644 index 0000000000000000000000000000000000000000..e0d68e3308c3ac8971e8ac225259ef27c6667d18 --- /dev/null +++ b/src/main/java/de/hdm_stuttgart/battlearena/Controller/MapSelectionController.java @@ -0,0 +1,70 @@ +package de.hdm_stuttgart.battlearena.Controller; + +import de.hdm_stuttgart.battlearena.Controller.Utilities.MusicPlayerSingleton; +import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.MapData; +import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Persistence; +import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.RuntimeInfo; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.fxml.Initializable; +import javafx.scene.control.ToggleButton; +import javafx.scene.control.ToggleGroup; +import javafx.scene.layout.VBox; + +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Objects; +import java.util.ResourceBundle; + +public class MapSelectionController implements Initializable { + @FXML + private VBox boxBox, parent; + + private int selectedMap; + + private final ArrayList<MapData> coreMaps = Persistence.getInstance().getCoreMaps(); + + @Override + public void initialize(URL url, ResourceBundle resourceBundle) { + ToggleGroup group = new ToggleGroup(); + + for (int i = 0; i < coreMaps.size(); i++) { + ToggleButton toggleButton = new ToggleButton(coreMaps.get(i).getMapName()); + toggleButton.setToggleGroup(group); + boxBox.getChildren().add(toggleButton); + } + + group.selectedToggleProperty().addListener((observableValue, oldToggle, newToggle) -> { + if (group.getSelectedToggle() != null) { + ToggleButton selected = (ToggleButton) group.getSelectedToggle(); + selectedMap = boxBox.getChildren().indexOf(selected); + System.out.println(selectedMap); + String value = selected.getText(); + System.out.println(value); + } + }); + } + +// private void switchScene(String name) { +// parent.getChildren().clear(); +// parent.getChildren().add(sceneLoader.loadScene(name)); +// } +// + + @FXML + private void gameScene() { + try { +// RuntimeInfo.getInstance().setGameMap(selectedMap, true); + MusicPlayerSingleton.getInstance().getMediaPlayer().dispose(); + parent.getScene().setRoot(FXMLLoader.load(Objects.requireNonNull(getClass().getResource("/fxml/GameScene.fxml")))); + } catch (IOException e) { + throw new RuntimeException(); + } + } + + @FXML + private void backButton() { + + } +} diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Controller/MenuBorderPaneController.java b/src/main/java/de/hdm_stuttgart/battlearena/Controller/MenuBorderPaneController.java index 0216502d4c8e9a4ac9c629d0cd2dd8171f899758..ec0c36049f6ed621d0462207161905c58961b609 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Controller/MenuBorderPaneController.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Controller/MenuBorderPaneController.java @@ -3,6 +3,7 @@ package de.hdm_stuttgart.battlearena.Controller; import de.hdm_stuttgart.battlearena.Controller.Utilities.CreateMediaPlayer; import de.hdm_stuttgart.battlearena.Controller.Utilities.MusicPlayerSingleton; import de.hdm_stuttgart.battlearena.Controller.Utilities.SceneLoader; +import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Persistence; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.geometry.Rectangle2D; @@ -40,6 +41,7 @@ public class MenuBorderPaneController implements Initializable { List<String> shuffledVideos = Arrays.asList(videoFiles); Rectangle2D screen = Screen.getPrimary().getVisualBounds(); + @Override public void initialize(URL url, ResourceBundle resourceBundle) { center.getChildren().add(sceneLoader.loadScene("MainMenu")); @@ -107,6 +109,7 @@ public class MenuBorderPaneController implements Initializable { private void backgroundMusic(String file) { Media media = new Media(new File("src/main/resources/sound/music/" + file).toURI().toString()); musicPlayer = new MediaPlayer(media); + musicPlayer.setVolume((double) Persistence.getInstance().getSettings().getMusicVolume() / 100); musicPlayer.setCycleCount(MediaPlayer.INDEFINITE); musicPlayer.play(); MusicPlayerSingleton.getInstance().setMediaPlayer(musicPlayer); diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Controller/SettingsController.java b/src/main/java/de/hdm_stuttgart/battlearena/Controller/SettingsController.java index a3c7526665111d073af465d5c74599952442b63b..d37bbcfdeb7b6056883a63eefae77c0eab1c5697 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Controller/SettingsController.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Controller/SettingsController.java @@ -2,6 +2,7 @@ package de.hdm_stuttgart.battlearena.Controller; import de.hdm_stuttgart.battlearena.Controller.Utilities.MusicPlayerSingleton; import de.hdm_stuttgart.battlearena.Controller.Utilities.SceneLoader; +import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Persistence; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.fxml.Initializable; @@ -19,8 +20,9 @@ public class SettingsController implements Initializable { @FXML private Slider musicVolume, sfxVolume; SceneLoader sceneLoader = new SceneLoader(); - public double music; + public int music; MusicPlayerSingleton musicPlayer = MusicPlayerSingleton.getInstance(); + Persistence volume = Persistence.getInstance(); @Override public void initialize(URL url, ResourceBundle resourceBundle) { @@ -41,6 +43,7 @@ public class SettingsController implements Initializable { private void setMusicVolume() { // need a runtime database to save volume + musicVolume.setValue(volume.getSettings().getMusicVolume()); musicVolume.valueProperty().addListener((observableValue, oldValue, newValue) -> { setMusic(musicVolume); System.out.println(music); @@ -49,8 +52,9 @@ public class SettingsController implements Initializable { private void setMusic(Slider slider) { slider.valueProperty().addListener(((observableValue, oldValue, newValue) -> { - music = newValue.doubleValue() / 100; - musicPlayer.getMediaPlayer().setVolume(music); + music = newValue.intValue(); + volume.getSettings().setMusicVolume(music); + musicPlayer.getMediaPlayer().setVolume((double) music / 100); })); } } diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Controller/SkinSelectionController.java b/src/main/java/de/hdm_stuttgart/battlearena/Controller/SkinSelectionController.java index 6015655a06d8dad0530362087a84c6e87e646f57..9e27cab1e0a87b52e01a1ea63b84ba6cf6b46006 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Controller/SkinSelectionController.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Controller/SkinSelectionController.java @@ -54,11 +54,9 @@ public class SkinSelectionController implements Initializable { @FXML private void gameScene() { - try { - MusicPlayerSingleton.getInstance().getMediaPlayer().dispose(); - parent.getScene().setRoot(FXMLLoader.load(Objects.requireNonNull(getClass().getResource("/fxml/GameScene.fxml")))); - } catch (IOException e) { - throw new RuntimeException(); - } + + + parent.getChildren().clear(); + parent.getChildren().add(new SceneLoader().loadScene("MapSelection")); } } diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Controller/StatisticsController.java b/src/main/java/de/hdm_stuttgart/battlearena/Controller/StatisticsController.java index 009c8a94b5f4a68c3c1b21ddcf194621be698a9c..ee8ccd517fc9c48f3178e792d136dba3f20783e8 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Controller/StatisticsController.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Controller/StatisticsController.java @@ -1,6 +1,7 @@ package de.hdm_stuttgart.battlearena.Controller; import de.hdm_stuttgart.battlearena.Controller.Utilities.SceneLoader; +import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Persistence; import javafx.beans.binding.Bindings; import javafx.collections.FXCollections; import javafx.collections.ObservableList; @@ -23,6 +24,8 @@ public class StatisticsController implements Initializable { private PieChart kd, wl; SceneLoader sceneLoader = new SceneLoader(); + Persistence persistence = Persistence.getInstance(); + public void mainMenuScene() { parent.getChildren().clear(); parent.getChildren().add(sceneLoader.loadScene("MainMenu")); @@ -30,17 +33,27 @@ public class StatisticsController implements Initializable { @Override public void initialize(URL url, ResourceBundle resourceBundle) { - iniPieChartkd(); - iniPieChartwl(); + iniPieChartKD(); + iniPieChartWL(); kd.setLegendVisible(false); wl.setLegendVisible(false); + setLabels(); + } + + private void setLabels() { + kills.setText(String.valueOf(persistence.getStatistics().getKills())); + gamesWon.setText(Integer.toString(persistence.getStatistics().getGamesWon())); + gamesLost.setText(String.valueOf(persistence.getStatistics().getGamesLost())); + gameTime.setText(Integer.toString(persistence.getStatistics().getGameTimeInHours())); + deaths.setText(String.valueOf(persistence.getStatistics().getDeaths())); + blocks.setText(Integer.toString(persistence.getStatistics().getBlocksDestroyed())); } - public void iniPieChartkd() { + public void iniPieChartKD() { ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList( - new PieChart.Data("Kills", 20), - new PieChart.Data("Deaths", 12)); + new PieChart.Data("Kills", persistence.getStatistics().getKills()), + new PieChart.Data("Deaths", persistence.getStatistics().getDeaths())); pieChartData.forEach(data -> data.nameProperty().bind( @@ -52,11 +65,11 @@ public class StatisticsController implements Initializable { kd.getData().addAll(pieChartData); } - public void iniPieChartwl() { + public void iniPieChartWL() { ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList( - new PieChart.Data("Wins", 3), - new PieChart.Data("Losses", 5)); + new PieChart.Data("Wins", persistence.getStatistics().getGamesWon()), + new PieChart.Data("Losses", persistence.getStatistics().getGamesLost())); pieChartData.forEach(data -> data.nameProperty().bind( diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Persistence.java b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Persistence.java index 821e550fa965efefc270d13d7c332146c6cfc208..3e24e0eb7201fd59a20b9913e926f3c2029b0ff0 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Persistence.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Persistence.java @@ -60,7 +60,7 @@ public class Persistence { public void loadPlayerAccount() throws DatabaseException { try { - gsonHandler.loadAccount(); + account = gsonHandler.loadAccount(); log.info("Player account successfully loaded!"); } catch(Exception e){ diff --git a/src/main/resources/fxml/MapSelection.fxml b/src/main/resources/fxml/MapSelection.fxml new file mode 100644 index 0000000000000000000000000000000000000000..821692cedce41686c10c25f68feab9ada55f8cf1 --- /dev/null +++ b/src/main/resources/fxml/MapSelection.fxml @@ -0,0 +1,107 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<?import javafx.geometry.Insets?> +<?import javafx.scene.control.Accordion?> +<?import javafx.scene.control.Button?> +<?import javafx.scene.control.RadioButton?> +<?import javafx.scene.control.ScrollPane?> +<?import javafx.scene.control.TitledPane?> +<?import javafx.scene.control.ToggleGroup?> +<?import javafx.scene.layout.AnchorPane?> +<?import javafx.scene.layout.HBox?> +<?import javafx.scene.layout.Pane?> +<?import javafx.scene.layout.VBox?> +<?import javafx.scene.text.Text?> + +<VBox fx:id="parent" alignment="CENTER" prefHeight="400.0" prefWidth="600.0" spacing="20.0" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.hdm_stuttgart.battlearena.Controller.MapSelectionController"> + <children> + <Pane VBox.vgrow="ALWAYS" /> + <HBox alignment="TOP_CENTER" spacing="20.0"> + <children> + <Text strokeType="OUTSIDE" strokeWidth="0.0" text="Rounds:" /> + <Accordion> + <panes> + <TitledPane fx:id="roundsTitledPane" text="Select"> + <content> + <ScrollPane minViewportHeight="40.0"> + <content> + <VBox fx:id="boxBox" /> + </content> + </ScrollPane> + </content> + </TitledPane> + </panes> + </Accordion> + </children> + <VBox.margin> + <Insets /> + </VBox.margin> + </HBox> + <HBox alignment="TOP_CENTER" maxWidth="-Infinity" minWidth="-Infinity" prefHeight="25.0" prefWidth="213.0" spacing="20.0"> + <children> + <Text strokeType="OUTSIDE" strokeWidth="0.0" text="Time:" /> + <Accordion> + <panes> + <TitledPane animated="false" text="Select"> + <content> + <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" /> + </content> + </TitledPane> + </panes> + </Accordion> + </children> + </HBox> + <HBox alignment="TOP_CENTER" spacing="10.0"> + <children> + <Text strokeType="OUTSIDE" strokeWidth="0.0" text="Players:" /> + <RadioButton mnemonicParsing="false" selected="true" text="2"> + <toggleGroup> + <ToggleGroup fx:id="group31" /> + </toggleGroup> + </RadioButton> + <RadioButton mnemonicParsing="false" text="3" toggleGroup="$group31" /> + <RadioButton mnemonicParsing="false" text="4" toggleGroup="$group31" /> + </children> + </HBox> + <HBox alignment="TOP_CENTER" spacing="10.0"> + <children> + <Text strokeType="OUTSIDE" strokeWidth="0.0" text="Text:" /> + <RadioButton mnemonicParsing="false" text="Yes"> + <toggleGroup> + <ToggleGroup fx:id="group1" /> + </toggleGroup> + </RadioButton> + <RadioButton mnemonicParsing="false" selected="true" text="No" toggleGroup="$group1" /> + </children> + </HBox> + <HBox alignment="TOP_CENTER" spacing="10.0"> + <children> + <Text strokeType="OUTSIDE" strokeWidth="0.0" text="Text:" /> + <RadioButton mnemonicParsing="false" text="Yes"> + <toggleGroup> + <ToggleGroup fx:id="group2" /> + </toggleGroup> + </RadioButton> + <RadioButton mnemonicParsing="false" selected="true" text="No" toggleGroup="$group2" /> + </children> + </HBox> + <HBox alignment="TOP_CENTER" spacing="10.0"> + <children> + <Text strokeType="OUTSIDE" strokeWidth="0.0" text="Text:" /> + <RadioButton mnemonicParsing="false" text="Yes"> + <toggleGroup> + <ToggleGroup fx:id="group3" /> + </toggleGroup> + </RadioButton> + <RadioButton mnemonicParsing="false" selected="true" text="No" toggleGroup="$group3" /> + </children> + </HBox> + <Button mnemonicParsing="false" onAction="#gameScene" text="Start" /> + <Button mnemonicParsing="false" onAction="#backButton" text="Back"> + <VBox.margin> + <Insets bottom="50.0" /> + </VBox.margin> + </Button> + <Pane VBox.vgrow="ALWAYS" /> + </children> +</VBox> diff --git a/src/main/resources/player/appSettings.json b/src/main/resources/player/appSettings.json index ac6b7e58fa58ee25e2070c5cdfb9b8324bdddc6b..ec5bc62a909f2065d81be4cfd6c494b9e10715fb 100644 --- a/src/main/resources/player/appSettings.json +++ b/src/main/resources/player/appSettings.json @@ -1,4 +1,4 @@ { "sfxVolume": 50, - "musicVolume": 50 + "musicVolume": 0 } \ No newline at end of file diff --git a/src/main/resources/player/playerAccount.json b/src/main/resources/player/playerAccount.json index 1cecf8373c050f15e816dae79f50e4b326d4f090..60070b6ed6a4c8153907eaf7e737e2e997fb3377 100644 --- a/src/main/resources/player/playerAccount.json +++ b/src/main/resources/player/playerAccount.json @@ -1,5 +1,5 @@ { "playerName": "Player1", - "accountPassword": "7c4a8d09ca3762af61e59520943dc26494f8941b", - "accountType": "ONLINE" + "accountPassword": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8", + "accountType": "LOCAL" } \ No newline at end of file diff --git a/src/main/resources/player/playerStatsLocal.json b/src/main/resources/player/playerStatsLocal.json index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..e51de779c74b6c93fe347b5bf263508c23fff2c9 100644 --- a/src/main/resources/player/playerStatsLocal.json +++ b/src/main/resources/player/playerStatsLocal.json @@ -0,0 +1,8 @@ +{ + "gamesLost": 5, + "gamesWon": 9, + "kills": 30, + "deaths": 20, + "blocksDestroyed": 200, + "gameTime": 3966480 +} \ No newline at end of file