aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/net/sowgro/npehero/gui/SettingsEditor.java
blob: e89dbc93b7cefcbf19b61753d45d23abd79dae9a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package net.sowgro.npehero.gui;

import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.*;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import net.sowgro.npehero.Driver;
import net.sowgro.npehero.main.ErrorDisplay;
import net.sowgro.npehero.main.Page;
import net.sowgro.npehero.main.Settings;
import net.sowgro.npehero.main.Sound;

import java.io.IOException;

public class SettingsEditor extends Page
{
    private final HBox content = new HBox();

    public SettingsEditor()
    {
        Text musicText = new Text();
        musicText.setText("Music Volume");
        musicText.getStyleClass().add("t3");

        Slider musicSlider = new Slider();
        musicSlider.valueProperty().bindBidirectional(Settings.musicVol);
        musicSlider.setMin(0.0);
        musicSlider.setMax(1.0);

        CheckBox enableMenuMusic = new CheckBox("Enable Menu Music");
        enableMenuMusic.selectedProperty().bindBidirectional(Settings.enableMenuMusic);

        VBox musicBox = new VBox();
        musicBox.getChildren().addAll(musicText, musicSlider, enableMenuMusic);
        musicBox.getStyleClass().add("box");
        musicBox.setPadding(new Insets(10));


        Text SFXText = new Text();
        SFXText.setText("Sound Effects Volume");
        SFXText.getStyleClass().add("t3");

        Slider SFXSlider = new Slider();
        SFXSlider.valueProperty().bindBidirectional(Settings.effectsVol);
        SFXSlider.setMin(0.0);
        SFXSlider.setMax(1.0);

        VBox SFXBox = new VBox();
        SFXBox.getChildren().addAll(SFXText, SFXSlider);
        SFXBox.getStyleClass().add("box");
        SFXBox.setPadding(new Insets(10));


        Text fullText = new Text();
        fullText.setText("Fullscreen mode");
        fullText.getStyleClass().add("t3");

        Button fullscreen = new Button();
        fullscreen.setText("Toggle (F11)");
        fullscreen.setOnAction(e -> {
            Sound.playSfx(Sound.FORWARD);
            Driver.primaryStage.setFullScreen(!Driver.primaryStage.isFullScreen());
        });

        VBox fullBox = new VBox();
        fullBox.getChildren().addAll(fullText,fullscreen);
        fullBox.getStyleClass().add("box");
        fullBox.setPadding(new Insets(10));


        Text controlsLabel = new Text("Key Bindings");
        controlsLabel.getStyleClass().add("t3");

        Button controlsButton = new Button();
        controlsButton.setText("Edit");
        controlsButton.setOnAction(_ -> {
            Sound.playSfx(Sound.FORWARD);
            Driver.setMenu(new ControlEditor());
        });

        VBox controlsBox = new VBox();
        controlsBox.getStyleClass().add("box");
        controlsBox.getChildren().addAll(controlsLabel, controlsButton);
        controlsBox.setPadding(new Insets(10));

        Label scaleLabel = new Label("UI Scale");

        ToggleButton[] scaleOptions = new ToggleButton[4];
        for (int i = 0; i < scaleOptions.length; i++) {
            var val = i * 0.5 + 0.5;
            ToggleButton tb = new ToggleButton((int)(val * 100) + "%");
            tb.setUserData(val);
            tb.getStyleClass().remove("radio-button");
            tb.getStyleClass().add("button");
            if (val == Settings.guiScale.get()) {
                tb.setSelected(true);
            }
            scaleOptions[i] = tb;
        }

        ToggleGroup tg = new ToggleGroup();
        tg.getToggles().addAll(scaleOptions);
        tg.selectedToggleProperty().addListener((_, _, newt) -> {
            Settings.guiScale.set((Double)newt.getUserData());
        });

        HBox scaleSlider = new HBox(scaleOptions);

        VBox scaleBox = new VBox(scaleLabel, scaleSlider);
        scaleBox.getStyleClass().add("box");
        scaleBox.setPadding(new Insets(10));

        Button exit = new Button();
        exit.setText("Back");
        exit.setOnAction(e -> {
            try {
                Settings.save();
            } catch (IOException ex) {
                Driver.setMenu(new ErrorDisplay("Failed to save settings", ex, this));
            }
            Sound.playSfx(Sound.BACKWARD);
            Driver.setMenu(new MainMenu());
        });

        BorderPane buttonBox = new BorderPane();
        buttonBox.setLeft(exit);

        VBox options = new VBox();
        options.setSpacing(10);
        options.setAlignment(Pos.CENTER);
        options.getChildren().addAll(musicBox,SFXBox,fullBox,controlsBox, scaleBox, buttonBox);
//        options.setPrefWidth(450);
        options.prefHeightProperty().bind(content.prefHeightProperty());

        content.getChildren().add(options);
        content.setAlignment(Pos.CENTER);
    }

    @Override
    public Pane getContent() {
        return content;
    }
}