From 9568ea5118b9100b3375a6bd2153042506b0d5d1 Mon Sep 17 00:00:00 2001 From: sowgro Date: Sun, 14 May 2023 01:46:56 -0400 Subject: Finish css and menus --- src/assets/pico.png | Bin 0 -> 9072089 bytes src/gui/Driver.java | 18 +++++----- src/gui/Leaderboard.java | 26 ++++++++++----- src/gui/Level.java | 6 ---- src/gui/LevelSelector.java | 62 +++++++++++++++++++++++++++++++--- src/gui/MainMenu.java | 20 +++-------- src/gui/Settings.java | 29 ++++++++-------- src/gui/style.css | 78 ++++++++++++++++++++++++++++++++++++++++--- src/main/JFXaudioPlayer.java | 17 ++++++++-- src/main/focusTest.java | 46 +++++++++++++++++++++++++ 10 files changed, 238 insertions(+), 64 deletions(-) create mode 100644 src/assets/pico.png create mode 100644 src/main/focusTest.java (limited to 'src') diff --git a/src/assets/pico.png b/src/assets/pico.png new file mode 100644 index 0000000..002ad9e Binary files /dev/null and b/src/assets/pico.png differ diff --git a/src/gui/Driver.java b/src/gui/Driver.java index f9449cd..77fe0b0 100644 --- a/src/gui/Driver.java +++ b/src/gui/Driver.java @@ -38,25 +38,27 @@ public class Driver extends Application value.minHeightProperty().bind(primaryStage.heightProperty()); } - primaryPane.getChildren().add(menus.get("MainMenu")); - primaryPane.minWidthProperty().bind(primaryStage.widthProperty()); - primaryPane.minHeightProperty().bind(primaryStage.heightProperty()); - setBackground("assets/water.png"); - Scene primaryScene = new Scene(primaryPane, 800, 600); primaryScene.getStylesheets().add("gui/style.css"); primaryStage.setScene(primaryScene); primaryStage.setTitle("NPE Hero"); + + setMenu("MainMenu"); + setBackground("assets/water.png"); + primaryStage.show(); - primaryStage.setFullScreen(true); } - public static void switchMenu(String name) + public static void setMenu(String name) { - primaryPane.getChildren().remove(0); + if (! primaryPane.getChildren().isEmpty()) + { + primaryPane.getChildren().remove(0); + } primaryPane.getChildren().add(menus.get(name)); + primaryPane.requestFocus(); } public static void setBackground(String url) diff --git a/src/gui/Leaderboard.java b/src/gui/Leaderboard.java index 598b6aa..9580a5f 100644 --- a/src/gui/Leaderboard.java +++ b/src/gui/Leaderboard.java @@ -1,12 +1,12 @@ package gui; + import javafx.collections.FXCollections; import javafx.collections.ObservableList; -import javafx.event.ActionEvent; -import javafx.event.EventHandler; import javafx.geometry.Pos; import javafx.scene.control.Button; import javafx.scene.control.ListView; +import javafx.scene.layout.HBox; import javafx.scene.layout.Pane; import javafx.scene.layout.VBox; @@ -17,16 +17,24 @@ public class Leaderboard extends Pane ListView scores = new ListView(); ObservableList scoreList= FXCollections.observableArrayList ("Test Score 1", "Test Score 2", "Test Score 3", "Test Score 4"); scores.setItems(scoreList); + scores.minWidthProperty().bind(super.widthProperty().multiply(0.25)); + scores.minHeightProperty().bind(super.heightProperty().multiply(0.75)); Button exit = new Button(); exit.setText("Exit"); - exit.setOnAction(e -> Driver.switchMenu("MainMenu")); + exit.setOnAction(e -> Driver.setMenu("MainMenu")); + + VBox centerBox = new VBox(); + centerBox.setAlignment(Pos.CENTER); + centerBox.setSpacing(10); + centerBox.getChildren().addAll(scores,exit); + + HBox rootBox = new HBox(); + rootBox.minWidthProperty().bind(super.widthProperty()); + rootBox.minHeightProperty().bind(super.heightProperty()); + rootBox.getChildren().add(centerBox); + rootBox.setAlignment(Pos.CENTER); - VBox centerMenu3 = new VBox(); - centerMenu3.minWidthProperty().bind(super.widthProperty()); - centerMenu3.minHeightProperty().bind(super.heightProperty()); - centerMenu3.setAlignment(Pos.CENTER); - centerMenu3.getChildren().addAll(scores,exit); - super.getChildren().add(centerMenu3); + super.getChildren().add(rootBox); } } diff --git a/src/gui/Level.java b/src/gui/Level.java index 8f98903..ecb741d 100644 --- a/src/gui/Level.java +++ b/src/gui/Level.java @@ -8,19 +8,13 @@ import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.effect.BlurType; import javafx.scene.effect.DropShadow; -import javafx.scene.layout.AnchorPane; import javafx.scene.layout.Background; import javafx.scene.layout.BackgroundFill; import javafx.scene.layout.BorderPane; import javafx.scene.layout.CornerRadii; import javafx.scene.layout.GridPane; import javafx.scene.layout.Pane; -import javafx.scene.layout.StackPane; import javafx.scene.paint.Color; -import javafx.scene.shape.Rectangle; -import javafx.scene.text.Font; -import javafx.scene.text.FontWeight; -import javafx.scene.text.Text; import javafx.stage.Stage; // will eventually extend pane diff --git a/src/gui/LevelSelector.java b/src/gui/LevelSelector.java index a84444b..e0ad663 100644 --- a/src/gui/LevelSelector.java +++ b/src/gui/LevelSelector.java @@ -3,12 +3,16 @@ package gui; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.geometry.Pos; -import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.ListView; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; +import javafx.scene.layout.HBox; import javafx.scene.layout.Pane; import javafx.scene.layout.VBox; -import javafx.stage.Stage; +import javafx.scene.paint.Color; +import javafx.scene.text.Font; +import javafx.scene.text.Text; public class LevelSelector extends Pane { @@ -17,12 +21,60 @@ public class LevelSelector extends Pane ListView levels = new ListView(); ObservableList levelList= FXCollections.observableArrayList ("Test Level 1", "Test Level 2", "Test Level 3", "Test Level 4"); levels.setItems(levelList); - //super.setAlignment(Pos.CENTER); + levels.minWidthProperty().bind(super.widthProperty().multiply(0.25)); + levels.minHeightProperty().bind(super.heightProperty().multiply(0.75)); + Button exit = new Button(); exit.setText("Exit"); - exit.setOnAction(e -> Driver.switchMenu("MainMenu")); + exit.setOnAction(e -> Driver.setMenu("MainMenu")); + + VBox leftBox = new VBox(); + leftBox.setAlignment(Pos.CENTER_LEFT); + leftBox.setSpacing(10); + leftBox.getChildren().addAll(levels,exit); + + Text title = new Text(); + title.setText("Test level 1"); + title.setFill(Color.WHITE); + title.setFont(new Font(50)); + title.wrappingWidthProperty().bind(super.widthProperty().multiply(0.37)); + + Text desc = new Text(); + desc.setText("long description with lots of words. what we write does not actually need to be long i just wan t make sure it can word wrap"); + desc.setFill(Color.WHITE); + desc.wrappingWidthProperty().bind(super.widthProperty().multiply(0.37)); + + ImageView previewView = new ImageView(); + Image preview = new Image("assets/pico.png"); + previewView.setImage(preview); + //previewView.setFitHeight(100); + previewView.fitWidthProperty().bind(super.widthProperty().multiply(0.25)); + previewView.setPreserveRatio(true); + + VBox details = new VBox(); + details.minWidthProperty().bind(super.widthProperty().multiply(0.37)); + details.minHeightProperty().bind(super.heightProperty().multiply(0.75)); + details.maxWidthProperty().bind(super.widthProperty().multiply(0.37)); + details.maxHeightProperty().bind(super.heightProperty().multiply(0.75)); + details.getStyleClass().add("textBox"); + details.getChildren().addAll(title,desc,previewView); + + Button play = new Button(); + play.setText("Play"); + + VBox rightBox = new VBox(); + rightBox.setAlignment(Pos.CENTER_RIGHT); + rightBox.setSpacing(10); + rightBox.getChildren().addAll(details,play); + + HBox rootBox = new HBox(); + rootBox.minWidthProperty().bind(super.widthProperty()); + rootBox.minHeightProperty().bind(super.heightProperty()); + rootBox.getChildren().addAll(leftBox, rightBox); + rootBox.setAlignment(Pos.CENTER); + rootBox.setSpacing(10); - super.getChildren().addAll(levels,exit); + super.getChildren().add(rootBox); } } diff --git a/src/gui/MainMenu.java b/src/gui/MainMenu.java index 3ad91ad..d04408d 100644 --- a/src/gui/MainMenu.java +++ b/src/gui/MainMenu.java @@ -1,16 +1,9 @@ package gui; -import javafx.event.EventHandler; -import javafx.event.ActionEvent; import javafx.geometry.Pos; import javafx.scene.control.Button; import javafx.scene.effect.BlurType; import javafx.scene.effect.DropShadow; -import javafx.scene.layout.Border; -import javafx.scene.layout.BorderStroke; -import javafx.scene.layout.BorderStrokeStyle; -import javafx.scene.layout.BorderWidths; -import javafx.scene.layout.CornerRadii; import javafx.scene.layout.Pane; import javafx.scene.layout.VBox; import javafx.scene.paint.Color; @@ -21,7 +14,6 @@ public class MainMenu extends Pane { public MainMenu() { - DropShadow dropShadow = new DropShadow(); dropShadow.setRadius(50.0); dropShadow.setColor(Color.WHITE); @@ -35,36 +27,32 @@ public class MainMenu extends Pane Button play = new Button(); play.setText("Play"); - play.setOnAction(e -> Driver.switchMenu("LevelSelector")); + play.setOnAction(e -> Driver.setMenu("LevelSelector")); Button settings = new Button(); settings.setText("Settings"); - settings.setOnAction(e -> Driver.switchMenu("Settings")); + settings.setOnAction(e -> Driver.setMenu("Settings")); Button leaderboard = new Button(); leaderboard.setText("Leaderboard"); - leaderboard.setOnAction(e -> Driver.switchMenu("Leaderboard")); - - //Border border = new Border(new BorderStroke(Color.WHITE, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, BorderWidths.DEFAULT)); + leaderboard.setOnAction(e -> Driver.setMenu("Leaderboard")); VBox buttonBox = new VBox(); buttonBox.getChildren().addAll(play, settings, leaderboard); buttonBox.setAlignment(Pos.CENTER); buttonBox.setSpacing(10); - //buttonBox.setBorder(border); VBox centerBox = new VBox(); centerBox.setAlignment(Pos.CENTER); centerBox.getChildren().addAll(title, buttonBox); centerBox.setSpacing(10); - //centerBox.setBorder(border); VBox rootBox = new VBox(); rootBox.minWidthProperty().bind(super.widthProperty()); rootBox.minHeightProperty().bind(super.heightProperty()); rootBox.setAlignment(Pos.CENTER); rootBox.getChildren().add(centerBox); - //rootBox.setBorder(border); + super.getChildren().add(rootBox); } diff --git a/src/gui/Settings.java b/src/gui/Settings.java index 94c2a89..946be85 100644 --- a/src/gui/Settings.java +++ b/src/gui/Settings.java @@ -1,12 +1,12 @@ package gui; -import javafx.event.ActionEvent; -import javafx.event.EventHandler; import javafx.geometry.Pos; import javafx.scene.control.Button; import javafx.scene.control.Slider; +import javafx.scene.layout.HBox; import javafx.scene.layout.Pane; import javafx.scene.layout.VBox; +import javafx.scene.paint.Color; import javafx.scene.text.Text; public class Settings extends Pane @@ -15,6 +15,7 @@ public class Settings extends Pane { Text t1 = new Text(); t1.setText("Music Volume"); + t1.setFill(Color.WHITE); Slider musicVol = new Slider(); musicVol.setMax(100); @@ -22,6 +23,7 @@ public class Settings extends Pane Text t2 = new Text(); t2.setText("Sound Effects Volume"); + t2.setFill(Color.WHITE); Slider sfxVol = new Slider(); sfxVol.setMax(100); @@ -29,25 +31,26 @@ public class Settings extends Pane Button devMenu = new Button(); devMenu.setText("Debug Menu"); - devMenu.setOnAction(new EventHandler() - { - @Override - public void handle(ActionEvent event) - { - Driver.setBackground("assets/trees.png"); - } - }); + devMenu.setOnAction(e -> Driver.setBackground("assets/trees.png")); Button exit = new Button(); exit.setText("Exit"); - exit.setOnAction(e -> Driver.switchMenu("MainMenu")); + exit.setOnAction(e -> Driver.setMenu("MainMenu")); VBox options = new VBox(); + options.setSpacing(10); options.setAlignment(Pos.CENTER); options.getChildren().addAll(t1,musicVol,t2,sfxVol,devMenu,exit); - options.minWidthProperty().bind(super.widthProperty()); + options.minWidthProperty().bind(super.widthProperty().multiply(0.25)); options.minHeightProperty().bind(super.heightProperty()); - super.getChildren().add(options); + //options.getStyleClass().add("textBox"); + + HBox rootBox = new HBox(); + rootBox.minWidthProperty().bind(super.widthProperty()); + rootBox.minHeightProperty().bind(super.heightProperty()); + rootBox.getChildren().add(options); + rootBox.setAlignment(Pos.CENTER); + super.getChildren().add(rootBox); } } diff --git a/src/gui/style.css b/src/gui/style.css index 3e18f9d..7ca76be 100644 --- a/src/gui/style.css +++ b/src/gui/style.css @@ -1,14 +1,20 @@ +/* button */ + Button { -fx-background-color: rgba(0, 0, 0, 0.5); -fx-text-fill: white; -fx-padding: .5em; -fx-font-size: 25; - -fx-background-radius: 10; + -fx-background-radius: 5; } Button:hover { - -fx-background-color: rgb(255, 255, 255); - -fx-text-fill: rgb(0, 0, 0); + -fx-background-color: rgb(50, 50, 50, 0.5); +} + +Button:focused { + -fx-background-color: rgb(255, 255, 255); + -fx-text-fill: rgb(0, 0, 0); } Button:pressed { @@ -16,6 +22,68 @@ Button:pressed { -fx-text-fill: rgb(0, 0, 0); } -.pad { +/* list */ + +ListView { + -fx-background-color: rgba(0, 0, 0, 0.5); + -fx-background-radius: 5; +} + +.list-cell { + -fx-padding: .5em; + -fx-background-color: transparent; + -fx-text-fill: rgb(255, 255, 255); +} + +.list-cell:hover { + -fx-background-color: rgba(100, 100, 100, 0.5); + +} + +.list-cell:selected { + -fx-background-color: rgb(255, 255, 255); + -fx-text-fill: rgb(0, 0, 0); +} + +/* slider */ + +Slider { -fx-padding: 1em; -} \ No newline at end of file +} + +.track { + + -fx-padding: 3; + -fx-background-color: rgba(0, 0, 0, 0.5); + -fx-background-radius: 5; +} + +.thumb { + -fx-pref-height: 30; + -fx-prefer-width: 30; + -fx-background-color: rgba(0, 0, 0, 0.5); + -fx-size: 25; + -fx-border-radius: 5; + -fx-border-color: rgb(231, 231, 231); + -fx-border-width: 3; +} + +.thumb:hover { + -fx-background-color: rgb(50, 50, 50, 0.5); +} + +Slider:focused .thumb{ + -fx-background-color: rgb(255,255,255); + -fx-border-color: white; +} + +.thumb:pressed { + -fx-background-color: rgb(231, 231, 231); + -fx-border-color: rgb(231, 231, 231); +} + +.textBox { + -fx-background-radius: 5; + -fx-background-color: rgba(0, 0, 0, 0.5); + -fx-text-fill: white; +} diff --git a/src/main/JFXaudioPlayer.java b/src/main/JFXaudioPlayer.java index 0a2162d..9207c59 100644 --- a/src/main/JFXaudioPlayer.java +++ b/src/main/JFXaudioPlayer.java @@ -1,16 +1,29 @@ package main; import java.io.File; +import java.io.IOException; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; import javafx.scene.media.Media; import javafx.scene.media.MediaPlayer; +import javafx.stage.Stage; -public class JFXaudioPlayer { +public class JFXaudioPlayer extends Application{ + public static void main(String[] args) { + launch(args); + } + + @Override + public void start(Stage primaryStage) + { + // primaryStage.show(); String musicFile = "EXAMPLE.mp3"; // For example Media sound = new Media(new File(musicFile).toURI().toString()); MediaPlayer mediaPlayer = new MediaPlayer(sound); mediaPlayer.play(); - mediaPlayer.stop(); } } \ No newline at end of file diff --git a/src/main/focusTest.java b/src/main/focusTest.java new file mode 100644 index 0000000..28e61a3 --- /dev/null +++ b/src/main/focusTest.java @@ -0,0 +1,46 @@ +package main; + +import javafx.application.Application; +import javafx.geometry.Pos; +import javafx.scene.Scene; +import javafx.scene.control.ToggleButton; +import javafx.scene.layout.HBox; +import javafx.scene.layout.VBox; +import javafx.stage.Stage; + +public class focusTest extends Application { + + public static void main(String[] args) + { + launch(args); + } + + @Override + public void start(Stage primaryStage) throws Exception + { + VBox root = new VBox(); + root.setAlignment(Pos.CENTER); + root.setSpacing(20); + Scene sc = new Scene(root, 500, 500); + primaryStage.setScene(sc); + primaryStage.show(); + + + ToggleButton btn1 = new ToggleButton("Button 1"); + ToggleButton btn2 = new ToggleButton("Button 2"); + ToggleButton btn3 = new ToggleButton("Button 3"); + ToggleButton btn4 = new ToggleButton("Button 4"); + + HBox hb1 = new HBox(); + hb1.setAlignment(Pos.CENTER); + hb1.getChildren().addAll(btn1, btn2); + + HBox hb2 = new HBox(); + hb2.setAlignment(Pos.CENTER); + hb2.getChildren().addAll(btn3, btn4); + + root.getChildren().addAll(hb1, hb2); + + hb1.requestFocus(); + } +} -- cgit v1.2.3 From 4a1f4a98116b5c59efe0606375b833a722a0d281 Mon Sep 17 00:00:00 2001 From: sowgro Date: Sun, 14 May 2023 17:34:40 -0400 Subject: add levelselector gui, move some files around --- src/assets/levels/test level/background.png | Bin 0 -> 1009759 bytes src/assets/levels/test level/metadata.json | 0 src/assets/levels/test level/notes_easy.txt | 0 src/assets/levels/test level/notes_hard.txt | 0 src/assets/levels/test level/notes_medium.txt | 0 src/assets/levels/test level/preview.png | Bin 0 -> 9072089 bytes src/gui/LevelDetails.java | 71 +++++++++++++++++++ src/gui/LevelSelector.java | 49 +++++-------- src/gui/style.css | 4 +- src/main/JFXaudioPlayer.java | 29 -------- src/main/KeyDetection.java | 27 ------- src/main/Level.java | 25 +++++++ src/main/LevelController.java | 1 + src/main/NoteTest.java | 35 ---------- src/main/SettingsController.java | 7 ++ src/main/SongPlayer.java | 97 -------------------------- src/main/focusTest.java | 46 ------------ src/test/JFXaudioPlayer.java | 29 ++++++++ src/test/KeyDetection.java | 27 +++++++ src/test/NoteTest.java | 35 ++++++++++ src/test/SongPlayer.java | 97 ++++++++++++++++++++++++++ src/test/focusTest.java | 46 ++++++++++++ 22 files changed, 358 insertions(+), 267 deletions(-) create mode 100644 src/assets/levels/test level/background.png create mode 100644 src/assets/levels/test level/metadata.json create mode 100644 src/assets/levels/test level/notes_easy.txt create mode 100644 src/assets/levels/test level/notes_hard.txt create mode 100644 src/assets/levels/test level/notes_medium.txt create mode 100644 src/assets/levels/test level/preview.png create mode 100644 src/gui/LevelDetails.java delete mode 100644 src/main/JFXaudioPlayer.java delete mode 100644 src/main/KeyDetection.java create mode 100644 src/main/Level.java create mode 100644 src/main/LevelController.java delete mode 100644 src/main/NoteTest.java create mode 100644 src/main/SettingsController.java delete mode 100644 src/main/SongPlayer.java delete mode 100644 src/main/focusTest.java create mode 100644 src/test/JFXaudioPlayer.java create mode 100644 src/test/KeyDetection.java create mode 100644 src/test/NoteTest.java create mode 100644 src/test/SongPlayer.java create mode 100644 src/test/focusTest.java (limited to 'src') diff --git a/src/assets/levels/test level/background.png b/src/assets/levels/test level/background.png new file mode 100644 index 0000000..0113819 Binary files /dev/null and b/src/assets/levels/test level/background.png differ diff --git a/src/assets/levels/test level/metadata.json b/src/assets/levels/test level/metadata.json new file mode 100644 index 0000000..e69de29 diff --git a/src/assets/levels/test level/notes_easy.txt b/src/assets/levels/test level/notes_easy.txt new file mode 100644 index 0000000..e69de29 diff --git a/src/assets/levels/test level/notes_hard.txt b/src/assets/levels/test level/notes_hard.txt new file mode 100644 index 0000000..e69de29 diff --git a/src/assets/levels/test level/notes_medium.txt b/src/assets/levels/test level/notes_medium.txt new file mode 100644 index 0000000..e69de29 diff --git a/src/assets/levels/test level/preview.png b/src/assets/levels/test level/preview.png new file mode 100644 index 0000000..002ad9e Binary files /dev/null and b/src/assets/levels/test level/preview.png differ diff --git a/src/gui/LevelDetails.java b/src/gui/LevelDetails.java new file mode 100644 index 0000000..dee2f00 --- /dev/null +++ b/src/gui/LevelDetails.java @@ -0,0 +1,71 @@ +package gui; + +import javafx.geometry.Pos; +import javafx.scene.control.Button; +import javafx.scene.control.ListView; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; +import javafx.scene.layout.Pane; +import javafx.scene.layout.VBox; +import javafx.scene.paint.Color; +import javafx.scene.text.Font; +import javafx.scene.text.Text; +import javafx.scene.text.TextAlignment; + +public class LevelDetails extends VBox +{ + public LevelDetails(ListView list) + { + VBox details = new VBox(); + details.minWidthProperty().bind(super.widthProperty()); + details.minHeightProperty().bind(super.heightProperty().multiply(0.75)); + details.maxWidthProperty().bind(super.widthProperty()); + details.maxHeightProperty().bind(super.heightProperty().multiply(0.75)); + details.getStyleClass().add("textBox"); + + Button play = new Button(); + play.setText("Play"); + + if (list.getSelectionModel().getSelectedItem() == null) + { + Text desc = new Text(); + desc.setText("Select a level from the left pane"); + desc.setFill(Color.WHITE); + desc.wrappingWidthProperty().bind(super.widthProperty()); + desc.setTextAlignment(TextAlignment.CENTER); + details.setAlignment(Pos.CENTER); + details.getChildren().addAll(desc); + play.setDisable(true); + } + + else + { + Text title = new Text(); + title.setText("Test level 1"); + title.setFill(Color.WHITE); + title.setFont(new Font(50)); + title.wrappingWidthProperty().bind(super.widthProperty()); + + Text desc = new Text(); + desc.setText("long description with lots of words. what we write does not actually need to be long i just wan t make sure it can word wrap"); + desc.setFill(Color.WHITE); + desc.wrappingWidthProperty().bind(super.widthProperty()); + + ImageView previewView = new ImageView(); + Image preview = new Image("assets/pico.png"); + previewView.setImage(preview); + //previewView.setFitHeight(100); + previewView.fitWidthProperty().bind(super.widthProperty().multiply(0.5)); + previewView.setPreserveRatio(true); + details.getChildren().addAll(title,desc,previewView); + } + + VBox rightBox = new VBox(); + rightBox.setAlignment(Pos.CENTER_RIGHT); + rightBox.setSpacing(10); + rightBox.getChildren().addAll(details,play); + + super.setAlignment(Pos.CENTER_RIGHT); + super.getChildren().add(rightBox); + } +} diff --git a/src/gui/LevelSelector.java b/src/gui/LevelSelector.java index e0ad663..5600b07 100644 --- a/src/gui/LevelSelector.java +++ b/src/gui/LevelSelector.java @@ -33,39 +33,9 @@ public class LevelSelector extends Pane leftBox.setSpacing(10); leftBox.getChildren().addAll(levels,exit); - Text title = new Text(); - title.setText("Test level 1"); - title.setFill(Color.WHITE); - title.setFont(new Font(50)); - title.wrappingWidthProperty().bind(super.widthProperty().multiply(0.37)); + Pane rightBox = new Pane(); + addDetails(rightBox, levels); - Text desc = new Text(); - desc.setText("long description with lots of words. what we write does not actually need to be long i just wan t make sure it can word wrap"); - desc.setFill(Color.WHITE); - desc.wrappingWidthProperty().bind(super.widthProperty().multiply(0.37)); - - ImageView previewView = new ImageView(); - Image preview = new Image("assets/pico.png"); - previewView.setImage(preview); - //previewView.setFitHeight(100); - previewView.fitWidthProperty().bind(super.widthProperty().multiply(0.25)); - previewView.setPreserveRatio(true); - - VBox details = new VBox(); - details.minWidthProperty().bind(super.widthProperty().multiply(0.37)); - details.minHeightProperty().bind(super.heightProperty().multiply(0.75)); - details.maxWidthProperty().bind(super.widthProperty().multiply(0.37)); - details.maxHeightProperty().bind(super.heightProperty().multiply(0.75)); - details.getStyleClass().add("textBox"); - details.getChildren().addAll(title,desc,previewView); - - Button play = new Button(); - play.setText("Play"); - - VBox rightBox = new VBox(); - rightBox.setAlignment(Pos.CENTER_RIGHT); - rightBox.setSpacing(10); - rightBox.getChildren().addAll(details,play); HBox rootBox = new HBox(); rootBox.minWidthProperty().bind(super.widthProperty()); @@ -74,7 +44,22 @@ public class LevelSelector extends Pane rootBox.setAlignment(Pos.CENTER); rootBox.setSpacing(10); + levels.setOnMouseClicked(e -> addDetails(rightBox, levels)); super.getChildren().add(rootBox); } + private void addDetails(Pane rightBox, ListView levels) + { + VBox details = new LevelDetails(levels); + if (! rightBox.getChildren().isEmpty()) + { + rightBox.getChildren().remove(0); + } + rightBox.getChildren().add(details); + details.minWidthProperty().bind(super.widthProperty().multiply(0.37)); + details.minHeightProperty().bind(super.heightProperty()); + details.maxWidthProperty().bind(super.widthProperty().multiply(0.37)); + details.maxHeightProperty().bind(super.heightProperty()); + } + } diff --git a/src/gui/style.css b/src/gui/style.css index 7ca76be..16db327 100644 --- a/src/gui/style.css +++ b/src/gui/style.css @@ -82,8 +82,10 @@ Slider:focused .thumb{ -fx-border-color: rgb(231, 231, 231); } +/* text box */ + .textBox { -fx-background-radius: 5; -fx-background-color: rgba(0, 0, 0, 0.5); -fx-text-fill: white; -} +} \ No newline at end of file diff --git a/src/main/JFXaudioPlayer.java b/src/main/JFXaudioPlayer.java deleted file mode 100644 index 9207c59..0000000 --- a/src/main/JFXaudioPlayer.java +++ /dev/null @@ -1,29 +0,0 @@ -package main; - -import java.io.File; -import java.io.IOException; - -import javafx.application.Application; -import javafx.fxml.FXMLLoader; -import javafx.scene.Parent; -import javafx.scene.media.Media; -import javafx.scene.media.MediaPlayer; -import javafx.stage.Stage; - -public class JFXaudioPlayer extends Application{ - - public static void main(String[] args) - { - launch(args); - } - - @Override - public void start(Stage primaryStage) - { - // primaryStage.show(); - String musicFile = "EXAMPLE.mp3"; // For example - Media sound = new Media(new File(musicFile).toURI().toString()); - MediaPlayer mediaPlayer = new MediaPlayer(sound); - mediaPlayer.play(); - } -} \ No newline at end of file diff --git a/src/main/KeyDetection.java b/src/main/KeyDetection.java deleted file mode 100644 index 7887405..0000000 --- a/src/main/KeyDetection.java +++ /dev/null @@ -1,27 +0,0 @@ -/*Name: - *Date: - *Period: - *Teacher: - *Description: - */ -package main; - -import javax.swing.*; -import java.awt.event.ActionEvent; - -public class KeyDetection extends AbstractAction -{ - long timeStart = System.currentTimeMillis(); - private char key; - public KeyDetection(char ch){ - key = ch; - } - - public void actionPerformed(ActionEvent e) - { - // TODO Auto-generated method stub - int time = (int)((System.currentTimeMillis()-timeStart)); - System.out.println(key + ": " + time); - } - -} diff --git a/src/main/Level.java b/src/main/Level.java new file mode 100644 index 0000000..52047fd --- /dev/null +++ b/src/main/Level.java @@ -0,0 +1,25 @@ +package main; + +import java.io.File; +import java.util.ArrayList; + +import javafx.scene.image.Image; +import javafx.scene.paint.Color; + +public class Level +{ + private Color[] colors; + private Image background; + private Image preview; + private String text; + private String desc; + //private ArrayList(); + + //google "varargs" to see how this works + public void setColors(Color... newColors) + { + colors = newColors; + } + + //INCOMPLETE +} diff --git a/src/main/LevelController.java b/src/main/LevelController.java new file mode 100644 index 0000000..daf7ae3 --- /dev/null +++ b/src/main/LevelController.java @@ -0,0 +1 @@ +//coming soon \ No newline at end of file diff --git a/src/main/NoteTest.java b/src/main/NoteTest.java deleted file mode 100644 index 34d9c8c..0000000 --- a/src/main/NoteTest.java +++ /dev/null @@ -1,35 +0,0 @@ -/*Name: - *Date: - *Period: - *Teacher: - *Description: - */ -package main; -import java.awt.*; - -public class NoteTest -{ - private boolean failed = false; - private int lane; - private final int NOTESPEED = 1; - private int yPos = SongPlayer.HEIGHT; - - public void gameTick() { - if (!failed) { - if (yPos > 0) { - yPos -= NOTESPEED; - } - else { - failed = true; - } - } - } - - public boolean getFailed() { - return failed; - } - - public int getY() { - return yPos; - } -} diff --git a/src/main/SettingsController.java b/src/main/SettingsController.java new file mode 100644 index 0000000..79fb560 --- /dev/null +++ b/src/main/SettingsController.java @@ -0,0 +1,7 @@ +// coming soon +// needs to have getters and setters for: +// - sfx vol +// - music vol +// - full screen +// +// perhaps use public variables instead of getters and setters \ No newline at end of file diff --git a/src/main/SongPlayer.java b/src/main/SongPlayer.java deleted file mode 100644 index caf1ab7..0000000 --- a/src/main/SongPlayer.java +++ /dev/null @@ -1,97 +0,0 @@ -/*Name: - *Date: - *Period: - *Teacher: - *Description: - */ -package main; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; - - -public class SongPlayer -{ - public static final int HEIGHT = 650; - public static final int LENGTH = 400; - - - private final int BLENGTH = LENGTH/6; - private final int BHEIGHT = HEIGHT/20; - JFrame frame = new JFrame("Guitar Hero"); //creates the frame - - - JButton d = new JButton("D"); //creates the four button lanes - JButton f = new JButton("F"); - JButton h = new JButton("H"); - JButton j = new JButton("J"); - - - public void createAndShowGui() { - - d.setBounds(1*BLENGTH, (5*HEIGHT)/6, BLENGTH, BHEIGHT); //makes the button bounds for each button - f.setBounds(2*BLENGTH, (5*HEIGHT)/6, BLENGTH, BHEIGHT); - h.setBounds(3*BLENGTH, (5*HEIGHT)/6, BLENGTH, BHEIGHT); - j.setBounds(4*BLENGTH, (5*HEIGHT)/6, BLENGTH, BHEIGHT); - - - frame.add(d); //adds the buttons to the frame - frame.add(f); - frame.add(h); - frame.add(j); - - frame.setSize(LENGTH, HEIGHT); //sets the size of the frame - frame.setLayout(null); //??? - frame.setVisible(true); //makes the frame visible - - KeyDetection dAction = new KeyDetection('d'); //creates an action for each char - d.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke('d'), "dPress"); //Input map and Action map setting - d.getActionMap().put("dPress", dAction); - d.setFocusable(false); //makes it so you can't highlight the button - - KeyDetection fAction = new KeyDetection('f'); - f.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke('f'), "fPress"); - f.getActionMap().put("fPress", fAction); - f.setFocusable(false); - - KeyDetection hAction = new KeyDetection('h'); - h.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke('h'), "hPress"); - h.getActionMap().put("hPress", hAction); - h.setFocusable(false); - - KeyDetection jAction = new KeyDetection('j'); - j.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke('j'), "jPress"); - j.getActionMap().put("jPress", jAction); - j.setFocusable(false); - } - - public void loop() { - JButton note = new JButton(); - JButton test = new JButton(); - test.setBounds(200, 200, 100, 100); - note.setBounds(BLENGTH, 0, BLENGTH, BHEIGHT); - frame.add(note); - frame.add(test); - - NoteTest a = new NoteTest(); - while (!a.getFailed()) { - if (!a.getFailed()) { - a.gameTick(); - note.setBounds(BLENGTH, HEIGHT-a.getY(), BLENGTH, BHEIGHT); //moves the note down every frame - System.out.println(a.getFailed()); - //the computer runs too fast normally, force it to run at a certain fps - try { - Thread.sleep(2); - } catch (InterruptedException e) - { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - if (a.getFailed()) { - frame.remove(note); //removes the note once its off the screen - } - } - } -} diff --git a/src/main/focusTest.java b/src/main/focusTest.java deleted file mode 100644 index 28e61a3..0000000 --- a/src/main/focusTest.java +++ /dev/null @@ -1,46 +0,0 @@ -package main; - -import javafx.application.Application; -import javafx.geometry.Pos; -import javafx.scene.Scene; -import javafx.scene.control.ToggleButton; -import javafx.scene.layout.HBox; -import javafx.scene.layout.VBox; -import javafx.stage.Stage; - -public class focusTest extends Application { - - public static void main(String[] args) - { - launch(args); - } - - @Override - public void start(Stage primaryStage) throws Exception - { - VBox root = new VBox(); - root.setAlignment(Pos.CENTER); - root.setSpacing(20); - Scene sc = new Scene(root, 500, 500); - primaryStage.setScene(sc); - primaryStage.show(); - - - ToggleButton btn1 = new ToggleButton("Button 1"); - ToggleButton btn2 = new ToggleButton("Button 2"); - ToggleButton btn3 = new ToggleButton("Button 3"); - ToggleButton btn4 = new ToggleButton("Button 4"); - - HBox hb1 = new HBox(); - hb1.setAlignment(Pos.CENTER); - hb1.getChildren().addAll(btn1, btn2); - - HBox hb2 = new HBox(); - hb2.setAlignment(Pos.CENTER); - hb2.getChildren().addAll(btn3, btn4); - - root.getChildren().addAll(hb1, hb2); - - hb1.requestFocus(); - } -} diff --git a/src/test/JFXaudioPlayer.java b/src/test/JFXaudioPlayer.java new file mode 100644 index 0000000..2f12e20 --- /dev/null +++ b/src/test/JFXaudioPlayer.java @@ -0,0 +1,29 @@ +package test; + +import java.io.File; +import java.io.IOException; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.media.Media; +import javafx.scene.media.MediaPlayer; +import javafx.stage.Stage; + +public class JFXaudioPlayer extends Application{ + + public static void main(String[] args) + { + launch(args); + } + + @Override + public void start(Stage primaryStage) + { + // primaryStage.show(); + String musicFile = "EXAMPLE.mp3"; // For example + Media sound = new Media(new File(musicFile).toURI().toString()); + MediaPlayer mediaPlayer = new MediaPlayer(sound); + mediaPlayer.play(); + } +} \ No newline at end of file diff --git a/src/test/KeyDetection.java b/src/test/KeyDetection.java new file mode 100644 index 0000000..447b101 --- /dev/null +++ b/src/test/KeyDetection.java @@ -0,0 +1,27 @@ +/*Name: + *Date: + *Period: + *Teacher: + *Description: + */ +package test; + +import javax.swing.*; +import java.awt.event.ActionEvent; + +public class KeyDetection extends AbstractAction +{ + long timeStart = System.currentTimeMillis(); + private char key; + public KeyDetection(char ch){ + key = ch; + } + + public void actionPerformed(ActionEvent e) + { + // TODO Auto-generated method stub + int time = (int)((System.currentTimeMillis()-timeStart)); + System.out.println(key + ": " + time); + } + +} diff --git a/src/test/NoteTest.java b/src/test/NoteTest.java new file mode 100644 index 0000000..ce74d56 --- /dev/null +++ b/src/test/NoteTest.java @@ -0,0 +1,35 @@ +/*Name: + *Date: + *Period: + *Teacher: + *Description: + */ +package test; +import java.awt.*; + +public class NoteTest +{ + private boolean failed = false; + private int lane; + private final int NOTESPEED = 1; + private int yPos = SongPlayer.HEIGHT; + + public void gameTick() { + if (!failed) { + if (yPos > 0) { + yPos -= NOTESPEED; + } + else { + failed = true; + } + } + } + + public boolean getFailed() { + return failed; + } + + public int getY() { + return yPos; + } +} diff --git a/src/test/SongPlayer.java b/src/test/SongPlayer.java new file mode 100644 index 0000000..48f859d --- /dev/null +++ b/src/test/SongPlayer.java @@ -0,0 +1,97 @@ +/*Name: + *Date: + *Period: + *Teacher: + *Description: + */ +package test; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; + + +public class SongPlayer +{ + public static final int HEIGHT = 650; + public static final int LENGTH = 400; + + + private final int BLENGTH = LENGTH/6; + private final int BHEIGHT = HEIGHT/20; + JFrame frame = new JFrame("Guitar Hero"); //creates the frame + + + JButton d = new JButton("D"); //creates the four button lanes + JButton f = new JButton("F"); + JButton h = new JButton("H"); + JButton j = new JButton("J"); + + + public void createAndShowGui() { + + d.setBounds(1*BLENGTH, (5*HEIGHT)/6, BLENGTH, BHEIGHT); //makes the button bounds for each button + f.setBounds(2*BLENGTH, (5*HEIGHT)/6, BLENGTH, BHEIGHT); + h.setBounds(3*BLENGTH, (5*HEIGHT)/6, BLENGTH, BHEIGHT); + j.setBounds(4*BLENGTH, (5*HEIGHT)/6, BLENGTH, BHEIGHT); + + + frame.add(d); //adds the buttons to the frame + frame.add(f); + frame.add(h); + frame.add(j); + + frame.setSize(LENGTH, HEIGHT); //sets the size of the frame + frame.setLayout(null); //??? + frame.setVisible(true); //makes the frame visible + + KeyDetection dAction = new KeyDetection('d'); //creates an action for each char + d.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke('d'), "dPress"); //Input map and Action map setting + d.getActionMap().put("dPress", dAction); + d.setFocusable(false); //makes it so you can't highlight the button + + KeyDetection fAction = new KeyDetection('f'); + f.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke('f'), "fPress"); + f.getActionMap().put("fPress", fAction); + f.setFocusable(false); + + KeyDetection hAction = new KeyDetection('h'); + h.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke('h'), "hPress"); + h.getActionMap().put("hPress", hAction); + h.setFocusable(false); + + KeyDetection jAction = new KeyDetection('j'); + j.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke('j'), "jPress"); + j.getActionMap().put("jPress", jAction); + j.setFocusable(false); + } + + public void loop() { + JButton note = new JButton(); + JButton test = new JButton(); + test.setBounds(200, 200, 100, 100); + note.setBounds(BLENGTH, 0, BLENGTH, BHEIGHT); + frame.add(note); + frame.add(test); + + NoteTest a = new NoteTest(); + while (!a.getFailed()) { + if (!a.getFailed()) { + a.gameTick(); + note.setBounds(BLENGTH, HEIGHT-a.getY(), BLENGTH, BHEIGHT); //moves the note down every frame + System.out.println(a.getFailed()); + //the computer runs too fast normally, force it to run at a certain fps + try { + Thread.sleep(2); + } catch (InterruptedException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + if (a.getFailed()) { + frame.remove(note); //removes the note once its off the screen + } + } + } +} diff --git a/src/test/focusTest.java b/src/test/focusTest.java new file mode 100644 index 0000000..bc337da --- /dev/null +++ b/src/test/focusTest.java @@ -0,0 +1,46 @@ +package test; + +import javafx.application.Application; +import javafx.geometry.Pos; +import javafx.scene.Scene; +import javafx.scene.control.ToggleButton; +import javafx.scene.layout.HBox; +import javafx.scene.layout.VBox; +import javafx.stage.Stage; + +public class focusTest extends Application { + + public static void main(String[] args) + { + launch(args); + } + + @Override + public void start(Stage primaryStage) throws Exception + { + VBox root = new VBox(); + root.setAlignment(Pos.CENTER); + root.setSpacing(20); + Scene sc = new Scene(root, 500, 500); + primaryStage.setScene(sc); + primaryStage.show(); + + + ToggleButton btn1 = new ToggleButton("Button 1"); + ToggleButton btn2 = new ToggleButton("Button 2"); + ToggleButton btn3 = new ToggleButton("Button 3"); + ToggleButton btn4 = new ToggleButton("Button 4"); + + HBox hb1 = new HBox(); + hb1.setAlignment(Pos.CENTER); + hb1.getChildren().addAll(btn1, btn2); + + HBox hb2 = new HBox(); + hb2.setAlignment(Pos.CENTER); + hb2.getChildren().addAll(btn3, btn4); + + root.getChildren().addAll(hb1, hb2); + + hb1.requestFocus(); + } +} -- cgit v1.2.3 From 4c735b64005291173a324d555af6e8a9df8b939e Mon Sep 17 00:00:00 2001 From: Zach Jordan Date: Mon, 15 May 2023 08:52:44 -0400 Subject: The rabbithole continues, hopefully this doesnt take the whole week. --- src/assets/BookBetrayal.mp3 | Bin 0 -> 5624404 bytes src/gui/JsonReader.java | 5 +++++ src/gui/JsonStructure.java | 5 +++++ src/gui/JsonValue.java | 9 +++++++++ src/gui/JsonWriter.java | 5 +++++ src/gui/SettingsController.java | 5 +++++ 6 files changed, 29 insertions(+) create mode 100644 src/assets/BookBetrayal.mp3 create mode 100644 src/gui/JsonReader.java create mode 100644 src/gui/JsonStructure.java create mode 100644 src/gui/JsonValue.java create mode 100644 src/gui/JsonWriter.java create mode 100644 src/gui/SettingsController.java (limited to 'src') diff --git a/src/assets/BookBetrayal.mp3 b/src/assets/BookBetrayal.mp3 new file mode 100644 index 0000000..cf274a6 Binary files /dev/null and b/src/assets/BookBetrayal.mp3 differ diff --git a/src/gui/JsonReader.java b/src/gui/JsonReader.java new file mode 100644 index 0000000..b1da06f --- /dev/null +++ b/src/gui/JsonReader.java @@ -0,0 +1,5 @@ +package gui; + +public interface JsonReader { + +} diff --git a/src/gui/JsonStructure.java b/src/gui/JsonStructure.java new file mode 100644 index 0000000..1ea2fa1 --- /dev/null +++ b/src/gui/JsonStructure.java @@ -0,0 +1,5 @@ +package gui; + +public interface JsonStructure { + +} diff --git a/src/gui/JsonValue.java b/src/gui/JsonValue.java new file mode 100644 index 0000000..e91f45b --- /dev/null +++ b/src/gui/JsonValue.java @@ -0,0 +1,9 @@ +package gui; + +public interface JsonValue +{ + static JsonValue.ValueType getValueType() + { + return null; + } +} diff --git a/src/gui/JsonWriter.java b/src/gui/JsonWriter.java new file mode 100644 index 0000000..04fae8e --- /dev/null +++ b/src/gui/JsonWriter.java @@ -0,0 +1,5 @@ +package gui; + +public interface JsonWriter { + +} diff --git a/src/gui/SettingsController.java b/src/gui/SettingsController.java new file mode 100644 index 0000000..8898dc3 --- /dev/null +++ b/src/gui/SettingsController.java @@ -0,0 +1,5 @@ +package gui; + +public class SettingsController { + +} -- cgit v1.2.3 From 228091f5594c4c20e6c51682e487d8325a8a3230 Mon Sep 17 00:00:00 2001 From: sowgro Date: Tue, 16 May 2023 07:08:18 -0400 Subject: unfinnished commit --- src/fallTest/Hbox.java | 5 + src/gui/Driver.java | 16 +++- src/gui/LevelDetails.java | 9 +- src/gui/LevelSurround.java | 74 +++++++++++++++ src/gui/SongPlayer2.java | 232 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 332 insertions(+), 4 deletions(-) create mode 100644 src/fallTest/Hbox.java create mode 100644 src/gui/LevelSurround.java create mode 100644 src/gui/SongPlayer2.java (limited to 'src') diff --git a/src/fallTest/Hbox.java b/src/fallTest/Hbox.java new file mode 100644 index 0000000..a7a97a7 --- /dev/null +++ b/src/fallTest/Hbox.java @@ -0,0 +1,5 @@ +package fallTest; + +public class Hbox { + +} diff --git a/src/gui/Driver.java b/src/gui/Driver.java index 77fe0b0..59002c2 100644 --- a/src/gui/Driver.java +++ b/src/gui/Driver.java @@ -17,6 +17,7 @@ import javafx.stage.Stage; public class Driver extends Application { + static Stage primaryStage; static HashMap menus = new HashMap(); static Pane primaryPane = new Pane(); @@ -26,8 +27,9 @@ public class Driver extends Application } @Override - public void start(Stage primaryStage) + public void start(Stage newPrimaryStage) { + primaryStage = newPrimaryStage; menus.put("MainMenu", new MainMenu()); menus.put("LevelSelector", new LevelSelector()); menus.put("Settings", new Settings()); @@ -61,6 +63,18 @@ public class Driver extends Application primaryPane.requestFocus(); } + public static void setCustomMenu(Pane pane) + { + if (! primaryPane.getChildren().isEmpty()) + { + primaryPane.getChildren().remove(0); + } + pane.minWidthProperty().bind(primaryStage.widthProperty()); + pane.minHeightProperty().bind(primaryStage.heightProperty()); + primaryPane.getChildren().add(pane); + primaryPane.requestFocus(); + } + public static void setBackground(String url) { primaryPane.setBackground(new Background( diff --git a/src/gui/LevelDetails.java b/src/gui/LevelDetails.java index dee2f00..5623261 100644 --- a/src/gui/LevelDetails.java +++ b/src/gui/LevelDetails.java @@ -1,5 +1,6 @@ package gui; +import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.control.Button; import javafx.scene.control.ListView; @@ -22,6 +23,7 @@ public class LevelDetails extends VBox details.maxWidthProperty().bind(super.widthProperty()); details.maxHeightProperty().bind(super.heightProperty().multiply(0.75)); details.getStyleClass().add("textBox"); + details.setPadding(new Insets(10)); Button play = new Button(); play.setText("Play"); @@ -31,7 +33,7 @@ public class LevelDetails extends VBox Text desc = new Text(); desc.setText("Select a level from the left pane"); desc.setFill(Color.WHITE); - desc.wrappingWidthProperty().bind(super.widthProperty()); + desc.wrappingWidthProperty().bind(super.widthProperty().subtract(10)); desc.setTextAlignment(TextAlignment.CENTER); details.setAlignment(Pos.CENTER); details.getChildren().addAll(desc); @@ -44,12 +46,12 @@ public class LevelDetails extends VBox title.setText("Test level 1"); title.setFill(Color.WHITE); title.setFont(new Font(50)); - title.wrappingWidthProperty().bind(super.widthProperty()); + title.wrappingWidthProperty().bind(super.widthProperty().subtract(10)); Text desc = new Text(); desc.setText("long description with lots of words. what we write does not actually need to be long i just wan t make sure it can word wrap"); desc.setFill(Color.WHITE); - desc.wrappingWidthProperty().bind(super.widthProperty()); + desc.wrappingWidthProperty().bind(super.widthProperty().subtract(10)); ImageView previewView = new ImageView(); Image preview = new Image("assets/pico.png"); @@ -58,6 +60,7 @@ public class LevelDetails extends VBox previewView.fitWidthProperty().bind(super.widthProperty().multiply(0.5)); previewView.setPreserveRatio(true); details.getChildren().addAll(title,desc,previewView); + play.setOnAction(e -> Driver.setCustomMenu(new LevelSurround())); } VBox rightBox = new VBox(); diff --git a/src/gui/LevelSurround.java b/src/gui/LevelSurround.java new file mode 100644 index 0000000..22fcf97 --- /dev/null +++ b/src/gui/LevelSurround.java @@ -0,0 +1,74 @@ +package gui; + +import fallTest.Hbox; +import javafx.geometry.Insets; +import javafx.geometry.Pos; +import javafx.scene.control.Button; +import javafx.scene.layout.BorderPane; +import javafx.scene.layout.HBox; +import javafx.scene.layout.Pane; +import javafx.scene.layout.StackPane; +import javafx.scene.layout.VBox; +import javafx.scene.paint.Color; +import javafx.scene.text.Font; +import javafx.scene.text.Text; + +public class LevelSurround extends Pane +{ + //will have param (Level l) + public LevelSurround() + { + Button exit = new Button(); + exit.setText("Exit"); + exit.setOnAction(e -> Driver.setMenu("LevelSelector")); + + Button pause = new Button(); + pause.setText("Pause"); + + HBox buttonBox = new HBox(); + buttonBox.getChildren().addAll(exit,pause); + buttonBox.setAlignment(Pos.TOP_LEFT); + buttonBox.setSpacing(10); + + Text title = new Text(); + title.setText("Test level 1"); + title.setFill(Color.WHITE); + title.setFont(new Font(50)); + + Text diff = new Text(); + diff.setText("Easy"); + diff.setFill(Color.WHITE); + + VBox textBox = new VBox(); + textBox.setAlignment(Pos.TOP_RIGHT); + textBox.getChildren().addAll(title,diff); + + BorderPane topBar = new BorderPane(); + topBar.setLeft(buttonBox); + topBar.setRight(textBox); + topBar.setPadding(new Insets(10)); + + Text title = new Text(); + title.setText("Test level 1"); + title.setFill(Color.WHITE); + title.setFont(new Font(50)); + + Text diff = new Text(); + diff.setText("Easy"); + diff.setFill(Color.WHITE); + + VBox textBox = new VBox(); + textBox.setAlignment(Pos.TOP_RIGHT); + textBox.getChildren().addAll(title,diff); + + HBox centerBox = new HBox(); + centerBox.getStyleClass().add("textBox"); + + StackPane root = new StackPane(); + root.getChildren().addAll(topBar,centerBox); + + super.getChildren().add(root); + root.minWidthProperty().bind(super.minWidthProperty()); + root.minHeightProperty().bind(super.minHeightProperty()); + } +} \ No newline at end of file diff --git a/src/gui/SongPlayer2.java b/src/gui/SongPlayer2.java new file mode 100644 index 0000000..ed6476d --- /dev/null +++ b/src/gui/SongPlayer2.java @@ -0,0 +1,232 @@ +/*Name: Guitar Hero Project + *Description: Contains the main game loop for gameplay + */ +package gui; + +import javafx.scene.control.Button; +import javafx.scene.layout.HBox; +import javafx.scene.layout.Pane; + +import java.util.*; + +import fallTest.NoteField; +import fallTest.NoteInfo; +import fallTest.Score; +import fallTest.Timer; +//test +public class SongPlayer2 extends Pane +{ + Timer time = new Timer(); + + public static final int HEIGHT = 650; + public static final int LENGTH = 400; + + private final int BLENGTH = LENGTH/7; + private final int BHEIGHT = HEIGHT/20; + + Button d = new Button("D"); + Button f = new Button("F"); + Button space= new Button("..."); + Button j = new Button("J"); + Button k = new Button("K"); + + Queue dSends = new LinkedList(); //Queue that dictates when to send the notes + ArrayList dLane = new ArrayList(); //Array list containing all the notes currently on the field + ArrayList dVis = new ArrayList(); //Array list containing the visual representations of the notes in lanes + + Queue fSends = new LinkedList(); + ArrayList fLane = new ArrayList(); + ArrayList fVis = new ArrayList(); + + Queue spaceSends = new LinkedList(); + ArrayList spaceLane = new ArrayList(); + ArrayList spaceVis = new ArrayList(); + + Queue jSends = new LinkedList(); + ArrayList jLane = new ArrayList(); + ArrayList jVis = new ArrayList(); + + Queue kSends = new LinkedList(); + ArrayList kLane = new ArrayList(); + ArrayList kVis = new ArrayList(); + + Score score = new Score(); + + /** + * Establishes what the chart for the song is going to look like + */ + public void loadSong() { + dSends.add(new NoteInfo(4000)); + dSends.add(new NoteInfo(4333)); + dSends.add(new NoteInfo(4666)); + fSends.add(new NoteInfo(5000)); + kSends.add(new NoteInfo(5500)); + spaceSends.add(new NoteInfo(6000)); + jSends.add(new NoteInfo(6000)); + jSends.add(new NoteInfo(6250)); + dSends.add(new NoteInfo(6500)); + jSends.add(new NoteInfo(6750)); + spaceSends.add(new NoteInfo(7000)); + fSends.add(new NoteInfo(7500)); + jSends.add(new NoteInfo(7750)); + spaceSends.add(new NoteInfo(8000)); + fSends.add(new NoteInfo(8500)); + jSends.add(new NoteInfo(8500)); + dSends.add(new NoteInfo(9000)); + spaceSends.add(new NoteInfo(9000)); + kSends.add(new NoteInfo(9000)); + spaceSends.add(new NoteInfo(9500)); + + kSends.add(new NoteInfo(10000)); + dSends.add(new NoteInfo(10000)); + kSends.add(new NoteInfo(10333)); + fSends.add(new NoteInfo(10333)); + kSends.add(new NoteInfo(10666)); + spaceSends.add(new NoteInfo(10666)); + dSends.add(new NoteInfo(11000)); + spaceSends.add(new NoteInfo(11000)); + dSends.add(new NoteInfo(11333)); + jSends.add(new NoteInfo(11333)); + dSends.add(new NoteInfo(11666)); + kSends.add(new NoteInfo(11666)); + spaceSends.add(new NoteInfo(12000)); + } + + + /** + * Creates the GUI used to play the game + */ + public SongPlayer2() { + + // d.setBounds(1*BLENGTH, (5*HEIGHT)/6, BLENGTH, BHEIGHT); //makes the button bounds for each button + // f.setBounds(2*BLENGTH, (5*HEIGHT)/6, BLENGTH, BHEIGHT); + // space.setBounds(3*BLENGTH, (5*HEIGHT)/6, BLENGTH, BHEIGHT); + // j.setBounds(4*BLENGTH, (5*HEIGHT)/6, BLENGTH, BHEIGHT); + // k.setBounds(5*BLENGTH, (5*HEIGHT)/6, BLENGTH, BHEIGHT); + // d.setFocusable(false); //makes it so you can't focus on the button + // f.setFocusable(false); + // space.setFocusable(false); + // j.setFocusable(false); + // k.setFocusable(false); + + + HBox bottom = new HBox(); + bottom.getChildren().add(d); //adds the buttons to the frame + bottom.getChildren().add(f); + bottom.getChildren().add(space); + bottom.getChildren().add(j); + bottom.getChildren().add(k); + super.getChildren().add(bottom); + //frame.setSize(LENGTH, HEIGHT); //sets the size of the frame + //frame.setLayout(null); + //frame.setVisible(true); //makes the frame visible + + + //while (true) { //TRY TO FIND A BETTER SOLUTION FOR THIS?? maybe something like sends.size() > 0 || lanes.size() > 0 + + // update(d, dSends, dLane, dVis, 'd', "dPress", 1); //updates the provided lane + // update(f, fSends, fLane, fVis, 'f', "fPress", 2); + // update(space, spaceSends, spaceLane, spaceVis, ' ', "spacePress", 3); + // update(j, jSends, jLane, jVis, 'j', "jPress", 4); + // update(k, kSends, kLane, kVis, 'k', "kPress", 5); + + // frame.repaint(); //updates the visuals every frame + + // try { + // Thread.sleep(10); //THIS IS PROBABLY NOT THE BEST WAY TO DO THIS + // } catch (InterruptedException e) + // { + // e.printStackTrace(); + // } + //} + } + + /** + * Updates a lane. An update involves: + * Checking to see if a note needs to be sent down a lane + * Checking to see if the user hit the button + * Checking to see if any notes have moved past the lane + * @param sends The sending queue for the given lane + * @param lane The place where note information is stored for notes currently in that lane + * @param vis The place where the visual representation for a note is stored in that lane + * @param key The button on the keyboard corresponding to the button for the lane being updated + * @param id The id for the action map + * @param k The lane number + */ + /* + private void update(JButton button, Queue sends, ArrayList lane, ArrayList vis, char key, String id, int k) { + if (!sends.isEmpty() && sends.peek().getTime()-time.time()<3) { //checks if any notes in the queue need to be sent at this time + lane.add(new NoteField()); //adds that note's information to the lane list + + vis.add(new JButton()); //creates a visual representation of that note in the visualizer list + frame.add(vis.get(vis.size()-1)); + + sends.remove(); //removes the note just sent from the sending queue + } + + if (lane.size() > 0) { //if there are any notes in the lanes, tests for a button press + button.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(key), id); //Input map and Action map setting + button.getActionMap().put(id, new AbstractAction() { //Defines what happens when the proper button is pressed + public void actionPerformed(ActionEvent e) + { + if (lane.size() > 0) { + int i = getClosestNote(lane); + int dist = (int)Math.abs(lane.get(i).goalDistance()); + + lane.remove(i); //removes the notes and visual representation from the playing field when the button is pressed + frame.remove(vis.get(i)); + vis.remove(i); + + if (dist > 2*BHEIGHT) { //Determines what to add to the score depending on the proximity of the note + score.miss(); + } + else if (dist > BHEIGHT) { + score.combo(); + score.close(); + } + else { + score.combo(); + score.perfect(); + } + + System.out.println("Score: " + score.getScore() + " Combo: " + score.getCombo()); + } + } + }); + } + + for (int i=0; i 0 && lane.get(i).getFailed()) { //if the note has passed into the fail boundary, removes the note from the field + score.miss(); + System.out.println(score.getScore() + " Combo: " + score.getCombo()); + + + lane.remove(i); + frame.remove(vis.get(i)); + vis.remove(i); + + i--; + } + } + } + + /** + * Finds the note closest to the goal + * @return the location in the array list of the closest note + + private int getClosestNote(ArrayList searchLane) { + int pos = 0; + + for (int i=0; i