Add main menu
This commit is contained in:
@@ -179,6 +179,7 @@ public class WhatAStorage {
|
||||
questManager.clear();
|
||||
productManager.reload(contentManager);
|
||||
questManager.reload(contentManager, productManager);
|
||||
questManager.register("random", new RandomQuestGenerator());
|
||||
|
||||
Util.LOGGER.log(Level.INFO, "Reloaded game content");
|
||||
}
|
||||
@@ -203,9 +204,8 @@ public class WhatAStorage {
|
||||
/**
|
||||
* Start a new game.
|
||||
*/
|
||||
public void startGame() {
|
||||
//questGenerator = questManager.get("example.test");
|
||||
questGenerator = new RandomQuestGenerator();
|
||||
public void startGame(String questGen) {
|
||||
questGenerator = questManager.get(questGen);
|
||||
quests.clear();
|
||||
storage = new Storage(GRID_SIZE, GRID_SIZE, GRID_SIZE);
|
||||
balance = new Balance();
|
||||
|
||||
@@ -56,6 +56,11 @@ public class ProductManager implements ResourceManager<ProductType<?>> {
|
||||
return productTypes.get(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(String id, ProductType<?> value) {
|
||||
productTypes.put(id, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all loaded product types.
|
||||
* @return All loaded product types
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* This class handles the loading and access of quest generators.
|
||||
@@ -55,4 +56,17 @@ public class QuestManager implements ResourceManager<QuestGenerator> {
|
||||
public QuestGenerator get(String id) {
|
||||
return questGenerators.get(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(String id, QuestGenerator value) {
|
||||
questGenerators.put(id, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all of the quest ids.
|
||||
* @return The quest ids
|
||||
*/
|
||||
public Set<String> ids() {
|
||||
return questGenerators.keySet();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,4 +16,11 @@ public interface ResourceManager<T> {
|
||||
* @return The associated resource
|
||||
*/
|
||||
T get(String id);
|
||||
|
||||
/**
|
||||
* Registers a new resource.
|
||||
* @param id The resource's id
|
||||
* @param value The resource
|
||||
*/
|
||||
void register(String id, T value);
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public class ConsoleVisual implements Visual {
|
||||
break;
|
||||
}
|
||||
case "start":
|
||||
was.startGame();
|
||||
was.startGame("random");
|
||||
break;
|
||||
case "exit":
|
||||
was.scheduleStop();
|
||||
|
||||
@@ -9,10 +9,7 @@ import de.siphalor.was.content.quest.Quest;
|
||||
import de.siphalor.was.content.resource.Resource;
|
||||
import de.siphalor.was.game.Transaction;
|
||||
import de.siphalor.was.util.Util;
|
||||
import de.siphalor.was.visual.jfx.controller.BalanceController;
|
||||
import de.siphalor.was.visual.jfx.controller.GameController;
|
||||
import de.siphalor.was.visual.jfx.controller.OptionsController;
|
||||
import de.siphalor.was.visual.jfx.controller.QuestController;
|
||||
import de.siphalor.was.visual.jfx.controller.*;
|
||||
import de.siphalor.was.visual.jfx.util.JFXUtil;
|
||||
import de.siphalor.was.visual.jfx.util.JFXStorageSlot;
|
||||
import javafx.animation.FadeTransition;
|
||||
@@ -40,6 +37,9 @@ public class JFXVisual extends Application implements Visual {
|
||||
private static boolean i18nInvalidated = false;
|
||||
private static Stage primaryStage;
|
||||
|
||||
private static Scene mainMenuScene;
|
||||
private static MainMenuController mainMenuController;
|
||||
|
||||
private static Scene gameScene;
|
||||
private static GameController gameController;
|
||||
private static JFXStorageSlot[][] storageSlots;
|
||||
@@ -86,6 +86,7 @@ public class JFXVisual extends Application implements Visual {
|
||||
primaryStage.setMinHeight(500);
|
||||
primaryStage.getIcons().add(JFXUtil.getIcon());
|
||||
|
||||
loadMainMenuScene();
|
||||
loadOptionsScene();
|
||||
|
||||
primaryStage.setOnCloseRequest(event -> {
|
||||
@@ -93,7 +94,7 @@ public class JFXVisual extends Application implements Visual {
|
||||
balanceStage.hide();
|
||||
});
|
||||
|
||||
WhatAStorage.getInstance().startGame();
|
||||
changeScene(mainMenuScene);
|
||||
}
|
||||
|
||||
private void changeScene(Scene nextScene) {
|
||||
@@ -102,7 +103,25 @@ public class JFXVisual extends Application implements Visual {
|
||||
primaryStage.show();
|
||||
}
|
||||
|
||||
public void loadGameScene() {
|
||||
private void loadMainMenuScene() {
|
||||
mainMenuController = new MainMenuController();
|
||||
|
||||
mainMenuScene = JFXUtil.loadScene("main_menu", mainMenuController, I18n.getInstance());
|
||||
|
||||
mainMenuController.optionsButton.setOnAction(event -> {
|
||||
optionsController.beforeOpen(() -> {
|
||||
if (i18nInvalidated) {
|
||||
loadOptionsScene();
|
||||
loadMainMenuScene();
|
||||
i18nInvalidated = false;
|
||||
}
|
||||
changeScene(mainMenuScene);
|
||||
});
|
||||
changeScene(optionsScene);
|
||||
});
|
||||
}
|
||||
|
||||
private void loadGameScene() {
|
||||
gameController = new GameController(WhatAStorage.getInstance());
|
||||
|
||||
gameScene = JFXUtil.loadScene("game", gameController, I18n.getInstance());
|
||||
@@ -129,6 +148,14 @@ public class JFXVisual extends Application implements Visual {
|
||||
});
|
||||
|
||||
gameController.optionsButton.setOnAction(event -> openOptionsScene());
|
||||
|
||||
gameController.quitButton.setOnAction(event -> {
|
||||
changeScene(mainMenuScene);
|
||||
if (balanceStage != null) {
|
||||
balanceStage.close();
|
||||
balanceStage = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void loadOptionsScene() {
|
||||
@@ -162,6 +189,7 @@ public class JFXVisual extends Application implements Visual {
|
||||
WhatAStorage.getInstance().resendVisualGameData();
|
||||
changeScene(gameScene);
|
||||
loadOptionsScene();
|
||||
loadMainMenuScene();
|
||||
setupBalanceStage();
|
||||
i18nInvalidated = false;
|
||||
} else {
|
||||
|
||||
@@ -25,6 +25,7 @@ public class GameController {
|
||||
public Label budgetChangeLabel;
|
||||
public Button balanceButton;
|
||||
public Button optionsButton;
|
||||
public Button quitButton;
|
||||
|
||||
public Pane storagePane;
|
||||
|
||||
@@ -48,11 +49,6 @@ public class GameController {
|
||||
budgetChangeTransition.setInterpolator(Interpolator.EASE_BOTH);
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void scheduleStop() {
|
||||
was.scheduleStop();
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void nextQuest() {
|
||||
was.userRequestQuest();
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package de.siphalor.was.visual.jfx.controller;
|
||||
|
||||
import de.siphalor.was.WhatAStorage;
|
||||
import de.siphalor.was.content.lang.I18n;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.ListCell;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.scene.control.SelectionMode;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class MainMenuController {
|
||||
public ListView<String> questSelection;
|
||||
public Button optionsButton;
|
||||
|
||||
@FXML
|
||||
private void initialize() {
|
||||
I18n i18n = I18n.getInstance();
|
||||
questSelection.setCellFactory(param -> new ListCell<>(){
|
||||
@Override
|
||||
protected void updateItem(String item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
if (empty) {
|
||||
setText(null);
|
||||
} else {
|
||||
setText(i18n.getString("quests." + item) + " (" + i18n.getString("quests." + item + ".description") + ")");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
ObservableList<String> items = questSelection.getItems();
|
||||
items.clear();
|
||||
items.addAll(WhatAStorage.getInstance().getQuestManager().ids().stream().sorted().collect(Collectors.toList()));
|
||||
questSelection.getSelectionModel().selectIndices(0);
|
||||
questSelection.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void startGame() {
|
||||
String selectedItem = questSelection.getSelectionModel().getSelectedItem();
|
||||
WhatAStorage.getInstance().startGame(selectedItem);
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,7 @@
|
||||
<Insets right="10.0" />
|
||||
</HBox.margin>
|
||||
</Button>
|
||||
<Button alignment="CENTER" mnemonicParsing="false" onMouseClicked="#scheduleStop" styleClass="red" text="%game.quit" textFill="WHITE" />
|
||||
<Button fx:id="quitButton" alignment="CENTER" mnemonicParsing="false" styleClass="red" text="%game.quit" textFill="WHITE" />
|
||||
</children>
|
||||
</HBox>
|
||||
</children>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
Button.green {
|
||||
-fx-background-color: #56893b;
|
||||
-fx-text-fill: white;
|
||||
}
|
||||
Button.green:hover {
|
||||
-fx-background-color: #72a157;
|
||||
@@ -9,6 +10,7 @@ Button.green:pressed {
|
||||
}
|
||||
Button.red {
|
||||
-fx-background-color: #ff4848;
|
||||
-fx-text-fill: white;
|
||||
}
|
||||
Button.red:hover {
|
||||
-fx-background-color: #ff5e5e;
|
||||
@@ -31,6 +33,14 @@ Button.red:pressed {
|
||||
-fx-background-color: linear-gradient(to right, #1695e8, #1279bb 60%, white 60%);
|
||||
}
|
||||
|
||||
ListView {
|
||||
-fx-border-width: 1 0 1 0;
|
||||
-fx-border-color: #aaaaaa;
|
||||
-fx-background-insets: 0;
|
||||
-fx-border-insets: 0;
|
||||
-fx-padding: 0;
|
||||
}
|
||||
|
||||
ScrollPane {
|
||||
-fx-background-insets: 0;
|
||||
-fx-border-insets: 0;
|
||||
|
||||
47
src/main/resources/assets/jfx/main_menu.fxml
Normal file
47
src/main/resources/assets/jfx/main_menu.fxml
Normal file
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.geometry.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.image.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.text.*?>
|
||||
|
||||
<VBox alignment="TOP_CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="500.0" prefWidth="850.0" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1">
|
||||
<children>
|
||||
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0">
|
||||
<children>
|
||||
<ImageView fitHeight="150.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true">
|
||||
<image>
|
||||
<Image url="@/assets/textures/icon.png" />
|
||||
</image>
|
||||
</ImageView>
|
||||
<Label text="What A Storage!">
|
||||
<font>
|
||||
<Font name="System Bold" size="42.0" />
|
||||
</font>
|
||||
<HBox.margin>
|
||||
<Insets left="20.0" />
|
||||
</HBox.margin>
|
||||
</Label>
|
||||
</children>
|
||||
<VBox.margin>
|
||||
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
|
||||
</VBox.margin>
|
||||
</HBox>
|
||||
<ListView fx:id="questSelection" editable="true" prefHeight="200.0" prefWidth="200.0">
|
||||
<VBox.margin>
|
||||
<Insets bottom="10.0" top="10.0" />
|
||||
</VBox.margin>
|
||||
</ListView>
|
||||
<Button mnemonicParsing="false" onAction="#startGame" styleClass="green" text="%menu.start-game">
|
||||
<font>
|
||||
<Font size="23.0" />
|
||||
</font>
|
||||
</Button>
|
||||
<Button fx:id="optionsButton" mnemonicParsing="false" text="%menu.options">
|
||||
<VBox.margin>
|
||||
<Insets top="20.0" />
|
||||
</VBox.margin>
|
||||
</Button>
|
||||
</children>
|
||||
</VBox>
|
||||
@@ -50,9 +50,9 @@
|
||||
<Label styleClass="heading" text="%menu.options.imprint" GridPane.rowIndex="6" />
|
||||
<Label minHeight="-Infinity" text="%menu.options.general.sounds" wrapText="true" GridPane.rowIndex="2" />
|
||||
<ToggleButton fx:id="soundsEnabledToggle" mnemonicParsing="false" GridPane.columnIndex="1" GridPane.rowIndex="2" />
|
||||
<Label alignment="TOP_LEFT" minHeight="-Infinity" text="%menu.options.imprint.developer" textAlignment="JUSTIFY" wrapText="true" GridPane.rowIndex="7" />
|
||||
<Label minHeight="-Infinity" text="%menu.options.imprint.assets" textAlignment="JUSTIFY" wrapText="true" GridPane.rowIndex="8" />
|
||||
<Label minHeight="-Infinity" text="%menu.options.imprint.javafx" textAlignment="JUSTIFY" wrapText="true" GridPane.rowIndex="9" />
|
||||
<Label alignment="TOP_LEFT" minHeight="-Infinity" text="%menu.options.imprint.developer" wrapText="true" GridPane.rowIndex="7" />
|
||||
<Label minHeight="-Infinity" text="%menu.options.imprint.assets" wrapText="true" GridPane.rowIndex="8" />
|
||||
<Label minHeight="-Infinity" text="%menu.options.imprint.javafx" wrapText="true" GridPane.rowIndex="9" />
|
||||
</children>
|
||||
<padding>
|
||||
<Insets left="20.0" right="20.0" />
|
||||
|
||||
@@ -48,6 +48,9 @@ game.balance.total-income = Gesamteinahmen: %d\u20ac
|
||||
game.balance.total-loss = Gesamtverluste: %d\u20ac
|
||||
|
||||
quests.normal = Normal
|
||||
quests.normal.description = Die Standard-Auftr\u00e4ge
|
||||
quests.random = Reiner Zufall
|
||||
quests.random.description = V\u00f6llig zuf\u00e4llige Generierung von Auftr\u00efgen
|
||||
|
||||
products.paper = Papier
|
||||
products.paper.color = Farbe
|
||||
|
||||
@@ -51,6 +51,9 @@ game.balance.total-income = Total Income: %d$
|
||||
game.balance.total-loss = Total Loss: %d$
|
||||
|
||||
quests.normal = Normal
|
||||
quests.normal.description = The legacy quests
|
||||
quests.random = Completely Random
|
||||
quests.random.description = Quests will get generated completely random
|
||||
|
||||
products.paper = Paper
|
||||
products.paper.color = Color
|
||||
|
||||
Reference in New Issue
Block a user