wip settings

This commit is contained in:
Bixilon 2020-09-07 19:27:37 +02:00
parent b5fecc3742
commit 652e0c3058
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
6 changed files with 102 additions and 1 deletions

View File

@ -14,18 +14,21 @@
package de.bixilon.minosoft.gui.main;
import de.bixilon.minosoft.game.datatypes.objectLoader.versions.Version;
import de.bixilon.minosoft.logging.LogLevels;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.ComboBox;
import javafx.scene.image.Image;
import java.io.ByteArrayInputStream;
import java.util.Arrays;
import java.util.Base64;
public class GUITools {
public final static Image logo = new Image(GUITools.class.getResourceAsStream("/icons/windowIcon.png"));
public final static ObservableList<Version> versions = FXCollections.observableArrayList();
public final static ComboBox<Version> versionList = new ComboBox<>(GUITools.versions);
public final static ObservableList<LogLevels> logLevels = FXCollections.observableList(Arrays.asList(LogLevels.values().clone()));
public static Image getImageFromBase64(String base64) {
if (base64 == null) {

View File

@ -147,4 +147,17 @@ public class MainWindow implements Initializable {
public void manageAccounts(ActionEvent actionEvent) {
manageAccounts();
}
public void openSettings() {
try {
Parent parent = FXMLLoader.load(MainWindow.class.getResource("/layout/settings.fxml"));
Stage stage = new Stage();
stage.initModality(Modality.APPLICATION_MODAL);
stage.setTitle("Settings - Minosoft");
stage.setScene(new Scene(parent));
stage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,49 @@
/*
* Codename Minosoft
* Copyright (C) 2020 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.gui.main;
import de.bixilon.minosoft.Config;
import de.bixilon.minosoft.Minosoft;
import de.bixilon.minosoft.config.GameConfiguration;
import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.logging.LogLevels;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ComboBox;
import javafx.scene.layout.GridPane;
import java.net.URL;
import java.util.ResourceBundle;
public class SettingsWindow implements Initializable {
@FXML
public GridPane tabGeneral;
@FXML
public ComboBox<LogLevels> generalLogLevel;
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
generalLogLevel.setItems(GUITools.logLevels);
generalLogLevel.getSelectionModel().select(Log.getLevel());
generalLogLevel.setOnAction((actionEvent -> {
LogLevels newLevel = generalLogLevel.getValue();
if (Log.getLevel() == newLevel) {
return;
}
Log.setLevel(newLevel);
Minosoft.getConfig().putString(GameConfiguration.GENERAL_LOG_LEVEL, newLevel.name());
Minosoft.getConfig().saveToFile(Config.configFileName);
}));
}
}

View File

@ -145,6 +145,7 @@ public class Log {
}
public static void setLevel(LogLevels level) {
Log.info(String.format("Log level changed from %s to %s", Log.level, level));
Log.level = level;
}
}

View File

@ -7,7 +7,7 @@
fx:controller="de.bixilon.minosoft.gui.main.MainWindow">
<MenuBar VBox.vgrow="NEVER">
<Menu mnemonicParsing="false" text="_File">
<MenuItem mnemonicParsing="false" disable="true" text="Preferences…"/>
<MenuItem mnemonicParsing="false" onAction="#openSettings" text="Preferences"/>
<SeparatorMenuItem mnemonicParsing="false"/>
<MenuItem mnemonicParsing="false" onAction="#quit" text="Quit"/>
</Menu>

View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<VBox xmlns:fx="http://javafx.com/fxml/1" prefHeight="400.0" prefWidth="640.0" xmlns="http://javafx.com/javafx/11.0.1"
fx:controller="de.bixilon.minosoft.gui.main.SettingsWindow">
<TabPane prefHeight="200.0" prefWidth="200.0" tabClosingPolicy="UNAVAILABLE">
<Tab text="General">
<GridPane fx:id="tabGeneral" hgap="10" minHeight="0.0" minWidth="0.0" prefHeight="429.0" prefWidth="640.0"
vgap="10">
<padding>
<Insets bottom="10" left="10" right="300" top="10"/>
</padding>
<columnConstraints>
<ColumnConstraints/>
<ColumnConstraints/>
</columnConstraints>
<rowConstraints>
<RowConstraints/>
<RowConstraints/>
</rowConstraints>
<Label text="Log level"/>
<ComboBox fx:id="generalLogLevel" prefWidth="150.0" GridPane.columnIndex="1"/>
</GridPane>
</Tab>
<Tab disable="true" text="Download">
<GridPane hgap="10" minHeight="0.0" minWidth="0.0" prefHeight="429.0" prefWidth="640.0" vgap="10">
<padding>
<Insets bottom="10" left="10" right="300" top="10"/>
</padding>
</GridPane>
</Tab>
</TabPane>
</VBox>