11package com .dinosaur .dinosaurexploder .view ;
22
3- import static com .almasb .fxgl .dsl .FXGL .getLocalizationService ;
4- import static com .almasb .fxgl .dsl .FXGL .getSettings ;
5-
6- import java .util .Arrays ;
7- import java .util .Locale ;
83import com .almasb .fxgl .app .scene .FXGLMenu ;
94import com .almasb .fxgl .app .scene .MenuType ;
105import com .almasb .fxgl .dsl .FXGL ;
11- import com .almasb .fxgl .localization .Language ;
12- import com .almasb .fxgl .ui .FXGLChoiceBox ;
136import com .almasb .fxgl .ui .FontType ;
14- import com .dinosaur .dinosaurexploder .DinosaurApp ;
157import com .dinosaur .dinosaurexploder .model .GameConstants ;
16- import javafx .collections .FXCollections ;
17- import javafx .collections .ObservableList ;
188import javafx .scene .control .Button ;
9+ import javafx .scene .image .Image ;
10+ import javafx .scene .image .ImageView ;
1911import javafx .scene .media .Media ;
2012import javafx .scene .media .MediaPlayer ;
2113import javafx .scene .paint .Color ;
2214import javafx .scene .shape .Rectangle ;
23- import javafx .scene .text .Text ;
24- import javafx .util .StringConverter ;
15+
16+ import java .io .FileInputStream ;
17+ import java .io .FileNotFoundException ;
2518
2619public class DinosaurMenu extends FXGLMenu {
2720
@@ -35,62 +28,69 @@ public DinosaurMenu() {
3528
3629 var bg = new Rectangle (getAppWidth (), getAppHeight (), Color .BLACK );
3730
38- var title = FXGL .getUIFactoryService ().newText (GameConstants .GAME_NAME , Color .LIME , FontType .MONO , 35 );
39- title .setTranslateY (100 );
40- title .setTranslateX (getAppWidth () / 2 - 175 );
41-
42- DinosaurApp .initLanguages ();
43- drawControls (mainMenuSound , bg , title );
44- }
45-
46- private void drawControls (MediaPlayer mainMenuSound , Rectangle bg , Text title ) {
47- getContentRoot ().getChildren ().removeAll (getContentRoot ().getChildren ());
48-
49- var startButton = new Button (getLocalizationService ().getLocalizedString ("Menu.1" ));
50- var quitButton = new Button (getLocalizationService ().getLocalizedString ("Menu.2" ));
51- var chooseLanguage = new FXGLChoiceBox <Language >(FXCollections .observableArrayList (GameConstants .AVAILABLE_LANGUAGES ));
52-
53-
54- startButton .setMinSize (200 , 100 );
55- quitButton .setMinSize (200 , 100 );
56-
57- startButton .setTranslateY (350 );
58- startButton .setTranslateX (getAppWidth () / 2 - 100 );
59- startButton .setStyle ("-fx-font-size:20" );
60-
61- quitButton .setTranslateY (490 );
62- quitButton .setTranslateX (getAppWidth () / 2 - 100 );
63- quitButton .setStyle ("-fx-font-size:20" );
64-
65- chooseLanguage .setTranslateY (700 );
66- chooseLanguage .setTranslateX (getAppWidth () / 2 - 100 );
67- chooseLanguage .setValue (getLocalizationService ().getSelectedLanguage ());
68- quitButton .setStyle ("-fx-font-size:20" );
69- chooseLanguage .setConverter (new StringConverter <Language >() {
70-
71- @ Override
72- public String toString (Language language ) {
73- return getLocalizationService ().getLocalizedString (language .getName ());
74- }
75-
76- @ Override
77- public Language fromString (String text ) {
78- throw new UnsupportedOperationException ();
79- }
80- });
81-
82- startButton .setOnAction (event -> {
83- fireNewGame ();
84- mainMenuSound .stop ();
85- });
86-
87- quitButton .setOnAction (event -> fireExit ());
88-
89- chooseLanguage .setOnAction (event -> {
90- getLocalizationService ().setSelectedLanguage (chooseLanguage .getValue ());
91- drawControls (mainMenuSound , bg , title );
92- });
93-
94- getContentRoot ().getChildren ().addAll (bg , title , startButton , quitButton , chooseLanguage );
95- }
96- }
31+ var title = FXGL .getUIFactoryService ().newText (GameConstants .GAME_NAME , Color .LIME , FontType .MONO , 35 );
32+ var startButton = new Button ("Start Game" );
33+ var quitButton = new Button ("Quit" );
34+ try {
35+
36+
37+ FileInputStream fileInputStream = new FileInputStream ("../dinosaur-exploder/src/main/resources/assets/textures/dinomenu.png" );
38+ FileInputStream mutemusic_button = new FileInputStream ("../dinosaur-exploder/src/main/resources/assets/textures/silent.png" );
39+
40+ // image for dino in main menu
41+ Image image = new Image (fileInputStream );
42+ ImageView imageView = new ImageView (image );
43+ imageView .setFitHeight (250 );
44+ imageView .setFitWidth (200 );
45+ imageView .setX (200 );
46+ imageView .setY (190 );
47+ imageView .setPreserveRatio (true );
48+
49+ //adding image to manually mute music
50+
51+ Image mute = new Image (mutemusic_button );
52+ ImageView imageView_mute = new ImageView (mute );
53+ imageView_mute .setFitHeight (40 );
54+ imageView_mute .setFitWidth (50 );
55+ imageView_mute .setX (490 );
56+ imageView_mute .setY (20 );
57+ imageView_mute .setPreserveRatio (true );
58+
59+ startButton .setMinSize (50 , 50 );
60+ quitButton .setMinSize (140 , 50 );
61+
62+ title .setTranslateY (100 );
63+ title .setTranslateX (getAppWidth () / 2 - 145 );
64+
65+ startButton .setTranslateY (400 );
66+ startButton .setTranslateX (getAppWidth () / 2 - 50 );
67+ startButton .setStyle ("-fx-font-size:20" );
68+
69+ quitButton .setTranslateY (500 );
70+ quitButton .setTranslateX (getAppWidth () / 2 - 50 );
71+ quitButton .setStyle ("-fx-font-size:20" );
72+
73+ startButton .setOnAction (event -> {
74+ fireNewGame ();
75+ mainMenuSound .stop ();
76+ });
77+
78+ imageView_mute .setOnMouseClicked (mouseEvent -> {
79+ mainMenuSound .stop ();
80+ });
81+
82+ imageView_mute .setOnMousePressed (mouseEvent -> {
83+ mainMenuSound .stop ();
84+ });
85+ quitButton .setOnAction (event -> fireExit ());
86+
87+ getContentRoot ().getChildren ().addAll (
88+ bg , title , startButton , quitButton , imageView , imageView_mute
89+ );
90+ }
91+ catch (FileNotFoundException e ){
92+ System .out .println ("File not found" + e .getMessage ());
93+ }
94+ }
95+
96+ }
0 commit comments