Add sound, imprint and icons

* Fix random quest generator putting out zero rewards
This commit is contained in:
2020-07-24 09:49:47 +02:00
parent 82c4eaad72
commit c77413acfe
16 changed files with 101 additions and 18 deletions

View File

@@ -40,7 +40,7 @@ public class RandomQuestGenerator implements QuestGenerator {
Product product = WhatAStorage.getInstance().getProductManager().randomProduct(RANDOM); Product product = WhatAStorage.getInstance().getProductManager().randomProduct(RANDOM);
return new Quest( return new Quest(
RANDOM.nextBoolean() ? Quest.Type.IN : Quest.Type.OUT, RANDOM.nextBoolean() ? Quest.Type.IN : Quest.Type.OUT,
RANDOM.nextInt(15) * 100 * product.getDepth(), (RANDOM.nextInt(14) + 1) * 100 * product.getDepth(),
product product
); );
} }

View File

@@ -18,6 +18,10 @@ public class Options {
* Allow resolving of two quests that target the same product. One asks to deposit it, the other to deliver it * Allow resolving of two quests that target the same product. One asks to deposit it, the other to deliver it
*/ */
private boolean allowQuestResolving; private boolean allowQuestResolving;
/**
* Whether the sound is enabled
*/
private boolean soundEnabled;
/** /**
* Gets whether quest resolving is enabled. * Gets whether quest resolving is enabled.
@@ -44,13 +48,29 @@ public class Options {
} }
/** /**
* Gets whether fulfilled quests should automatically be refilled. * Sets whether fulfilled quests should automatically be refilled.
* @param autoRefillQuests Whether fulfilled quests should automatically be refilled * @param autoRefillQuests Whether fulfilled quests should automatically be refilled
*/ */
public void setAutoRefillQuests(boolean autoRefillQuests) { public void setAutoRefillQuests(boolean autoRefillQuests) {
this.autoRefillQuests = autoRefillQuests; this.autoRefillQuests = autoRefillQuests;
} }
/**
* Gets whether the sound is enabled.
* @return Whether the sound is enabled
*/
public boolean getSoundEnabled() {
return soundEnabled;
}
/**
* Sets whether the sound should be enabled.
* @param soundEnabled Whether the sound should be enabled
*/
public void setSoundEnabled(boolean soundEnabled) {
this.soundEnabled = soundEnabled;
}
/** /**
* Gets a reference to the preferences object used for session independent storage. * Gets a reference to the preferences object used for session independent storage.
* @return The preferences object * @return The preferences object
@@ -66,6 +86,7 @@ public class Options {
Preferences preferences = getPreferences(); Preferences preferences = getPreferences();
autoRefillQuests = preferences.getBoolean("auto-refill-quests", false); autoRefillQuests = preferences.getBoolean("auto-refill-quests", false);
allowQuestResolving = preferences.getBoolean("allow-quest-resolving", true); allowQuestResolving = preferences.getBoolean("allow-quest-resolving", true);
soundEnabled = preferences.getBoolean("sound-enabled", false);
String lang = preferences.get("preferred-lang", Locale.getDefault().getLanguage() + "_" + Locale.getDefault().getCountry()); String lang = preferences.get("preferred-lang", Locale.getDefault().getLanguage() + "_" + Locale.getDefault().getCountry());
I18n.getInstance().setLang(lang, WhatAStorage.getInstance().getContentManager()); I18n.getInstance().setLang(lang, WhatAStorage.getInstance().getContentManager());
@@ -78,6 +99,7 @@ public class Options {
Preferences preferences = getPreferences(); Preferences preferences = getPreferences();
preferences.putBoolean("auto-refill-quests", autoRefillQuests); preferences.putBoolean("auto-refill-quests", autoRefillQuests);
preferences.putBoolean("allow-quest-resolving", allowQuestResolving); preferences.putBoolean("allow-quest-resolving", allowQuestResolving);
preferences.putBoolean("sound-enabled", soundEnabled);
preferences.put("preferred-lang", I18n.getInstance().getLang().getCode()); preferences.put("preferred-lang", I18n.getInstance().getLang().getCode());
} }
} }

View File

@@ -84,6 +84,7 @@ public class JFXVisual extends Application implements Visual {
primaryStage.setTitle(WhatAStorage.TITLE); primaryStage.setTitle(WhatAStorage.TITLE);
primaryStage.setMinWidth(850); primaryStage.setMinWidth(850);
primaryStage.setMinHeight(500); primaryStage.setMinHeight(500);
primaryStage.getIcons().add(JFXUtil.getIcon());
loadOptionsScene(); loadOptionsScene();
@@ -137,6 +138,8 @@ public class JFXVisual extends Application implements Visual {
private void setupBalanceStage() { private void setupBalanceStage() {
if (balanceStage != null) { if (balanceStage != null) {
balanceStage.getIcons().add(JFXUtil.getIcon());
balanceController = new BalanceController(); balanceController = new BalanceController();
Scene scene = JFXUtil.loadScene("balance", balanceController, I18n.getInstance()); Scene scene = JFXUtil.loadScene("balance", balanceController, I18n.getInstance());
@@ -270,9 +273,11 @@ public class JFXVisual extends Application implements Visual {
if (transaction.getChange() != 0) { if (transaction.getChange() != 0) {
gameController.budgetChangeLabel.getStyleClass().clear(); gameController.budgetChangeLabel.getStyleClass().clear();
if (transaction.getChange() > 0) { if (transaction.getChange() > 0) {
JFXUtil.playAudio("earn-money");
JFXUtil.setStyleClass(gameController.budgetChangeLabel, "green", true); JFXUtil.setStyleClass(gameController.budgetChangeLabel, "green", true);
gameController.budgetChangeLabel.setText(i18n.format("game.budget.change.income", transaction.getChange())); gameController.budgetChangeLabel.setText(i18n.format("game.budget.change.income", transaction.getChange()));
} else { } else {
JFXUtil.playAudio("lose-money");
JFXUtil.setStyleClass(gameController.budgetChangeLabel, "red", true); JFXUtil.setStyleClass(gameController.budgetChangeLabel, "red", true);
gameController.budgetChangeLabel.setText(i18n.format("game.budget.change.loss", transaction.getChange())); gameController.budgetChangeLabel.setText(i18n.format("game.budget.change.loss", transaction.getChange()));
} }

View File

@@ -3,6 +3,7 @@ package de.siphalor.was.visual.jfx.controller;
import de.siphalor.was.WhatAStorage; import de.siphalor.was.WhatAStorage;
import de.siphalor.was.assets.AssetsManager; import de.siphalor.was.assets.AssetsManager;
import de.siphalor.was.visual.jfx.util.DraggedProduct; import de.siphalor.was.visual.jfx.util.DraggedProduct;
import de.siphalor.was.visual.jfx.util.JFXUtil;
import javafx.animation.FadeTransition; import javafx.animation.FadeTransition;
import javafx.animation.Interpolator; import javafx.animation.Interpolator;
import javafx.fxml.FXML; import javafx.fxml.FXML;
@@ -91,12 +92,15 @@ public class GameController {
dragEvent.setDropCompleted(true); dragEvent.setDropCompleted(true);
dragEvent.consume(); dragEvent.consume();
JFXUtil.playAudio("destroy");
return; return;
} else if (origin instanceof DraggedProduct.Slot) { } else if (origin instanceof DraggedProduct.Slot) {
was.userDestroyProduct(((DraggedProduct.Slot) origin).x, ((DraggedProduct.Slot) origin).y); was.userDestroyProduct(((DraggedProduct.Slot) origin).x, ((DraggedProduct.Slot) origin).y);
dragEvent.setDropCompleted(true); dragEvent.setDropCompleted(true);
dragEvent.consume(); dragEvent.consume();
JFXUtil.playAudio("destroy");
return; return;
} }
} }

View File

@@ -14,6 +14,7 @@ public class OptionsController {
private Runnable exitRunnable; private Runnable exitRunnable;
public ChoiceBox<LangEntry> languageChoice; public ChoiceBox<LangEntry> languageChoice;
public ToggleButton soundsEnabledToggle;
public ToggleButton allowQuestResolvingToggle; public ToggleButton allowQuestResolvingToggle;
public ToggleButton autoQuestRefillToggle; public ToggleButton autoQuestRefillToggle;
@@ -35,6 +36,7 @@ public class OptionsController {
} }
} }
soundsEnabledToggle.setSelected(options.getSoundEnabled());
allowQuestResolvingToggle.setSelected(options.getAllowQuestResolving()); allowQuestResolvingToggle.setSelected(options.getAllowQuestResolving());
autoQuestRefillToggle.setSelected(options.getAutoRefillQuests()); autoQuestRefillToggle.setSelected(options.getAutoRefillQuests());
} }
@@ -45,6 +47,7 @@ public class OptionsController {
String oldLang = I18n.getInstance().getLang().getCode(); String oldLang = I18n.getInstance().getLang().getCode();
I18n.getInstance().setLang(languageChoice.getValue().getCode(), WhatAStorage.getInstance().getContentManager()); I18n.getInstance().setLang(languageChoice.getValue().getCode(), WhatAStorage.getInstance().getContentManager());
options.setSoundEnabled(soundsEnabledToggle.isSelected());
options.setAllowQuestResolving(allowQuestResolvingToggle.isSelected()); options.setAllowQuestResolving(allowQuestResolvingToggle.isSelected());
options.setAutoRefillQuests(autoQuestRefillToggle.isSelected()); options.setAutoRefillQuests(autoQuestRefillToggle.isSelected());

View File

@@ -139,11 +139,13 @@ public class JFXStorageSlot {
if (origin instanceof DraggedProduct.Quest) { if (origin instanceof DraggedProduct.Quest) {
WhatAStorage.getInstance().userStoreProduct(((DraggedProduct.Quest) origin).index, x, y); WhatAStorage.getInstance().userStoreProduct(((DraggedProduct.Quest) origin).index, x, y);
dragEvent.setDropCompleted(true); dragEvent.setDropCompleted(true);
JFXUtil.playAudio("place");
return; return;
} else if (origin instanceof DraggedProduct.Slot) { } else if (origin instanceof DraggedProduct.Slot) {
DraggedProduct.Slot slot = (DraggedProduct.Slot) origin; DraggedProduct.Slot slot = (DraggedProduct.Slot) origin;
WhatAStorage.getInstance().userMoveProduct(slot.x, slot.y, x, y); WhatAStorage.getInstance().userMoveProduct(slot.x, slot.y, x, y);
dragEvent.setDropCompleted(true); dragEvent.setDropCompleted(true);
JFXUtil.playAudio("place");
return; return;
} }
} }

View File

@@ -1,5 +1,6 @@
package de.siphalor.was.visual.jfx.util; package de.siphalor.was.visual.jfx.util;
import de.siphalor.was.WhatAStorage;
import de.siphalor.was.assets.AssetsManager; import de.siphalor.was.assets.AssetsManager;
import de.siphalor.was.content.lang.I18n; import de.siphalor.was.content.lang.I18n;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
@@ -11,9 +12,12 @@ import javafx.scene.image.PixelReader;
import javafx.scene.image.PixelWriter; import javafx.scene.image.PixelWriter;
import javafx.scene.image.WritableImage; import javafx.scene.image.WritableImage;
import javax.sound.sampled.*;
import java.io.IOException; import java.io.IOException;
public class JFXUtil { public class JFXUtil {
private static Image image;
public static Image scaleTo(Image image, int width) { public static Image scaleTo(Image image, int width) {
double scale = image.getWidth() / (double) width; double scale = image.getWidth() / (double) width;
int height = (int) (image.getHeight() / scale); int height = (int) (image.getHeight() / scale);
@@ -55,4 +59,26 @@ public class JFXUtil {
scene.getStylesheets().add("assets/jfx/main.css"); scene.getStylesheets().add("assets/jfx/main.css");
return scene; return scene;
} }
public static void playAudio(String sound) {
if (WhatAStorage.getInstance().getOptions().getSoundEnabled()) {
try {
AudioInputStream inputStream = AudioSystem.getAudioInputStream(AssetsManager.getStream("sound/" + sound + ".wav").orElseThrow());
AudioFormat format = inputStream.getFormat();
DataLine.Info info = new DataLine.Info(Clip.class, format);
Clip clip = (Clip) AudioSystem.getLine(info);
clip.open(inputStream);
clip.start();
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static Image getIcon() {
if (image == null) {
image = new Image(AssetsManager.getStream("textures/icon.png").orElseThrow());
}
return image;
}
} }

View File

@@ -54,11 +54,11 @@ Label.red {
Label.green { Label.green {
-fx-text-fill: #457229; -fx-text-fill: #457229;
} }
.options-menu > Label { .menu > Label {
-fx-font-size: 16; -fx-font-size: 16;
} }
.options-menu .heading { .menu > .heading {
-fx-padding: 10 0 0 0; -fx-padding: 8 0 0 0;
-fx-font-size: 20; -fx-font-size: 20;
-fx-font-weight: bold; -fx-font-weight: bold;
} }

View File

@@ -21,27 +21,38 @@
</ToolBar> </ToolBar>
<ScrollPane fitToWidth="true" VBox.vgrow="ALWAYS"> <ScrollPane fitToWidth="true" VBox.vgrow="ALWAYS">
<content> <content>
<GridPane styleClass="options-menu"> <GridPane styleClass="menu">
<columnConstraints> <columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" /> <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
<ColumnConstraints halignment="RIGHT" hgrow="SOMETIMES" minWidth="10.0" /> <ColumnConstraints halignment="RIGHT" hgrow="SOMETIMES" minWidth="10.0" />
</columnConstraints> </columnConstraints>
<rowConstraints> <rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="1.7976931348623157E308" minHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="1.7976931348623157E308" minHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="1.7976931348623157E308" minHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints> </rowConstraints>
<children> <children>
<Label styleClass="heading" text="%menu.options.general" GridPane.columnSpan="2147483647" /> <Label styleClass="heading" text="%menu.options.general" GridPane.columnSpan="2147483647" />
<Label text="Language" GridPane.rowIndex="1" /> <Label minHeight="-Infinity" text="Language" wrapText="true" GridPane.rowIndex="1" />
<ChoiceBox fx:id="languageChoice" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="1" /> <ChoiceBox fx:id="languageChoice" minWidth="-Infinity" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Label styleClass="heading" text="%menu.options.gameplay" GridPane.columnSpan="2147483647" GridPane.rowIndex="2" /> <Label styleClass="heading" text="%menu.options.gameplay" GridPane.columnSpan="2147483647" GridPane.rowIndex="3" />
<Label text="%menu.options.gameplay.quest-resolving" GridPane.rowIndex="3" /> <Label minHeight="-Infinity" text="%menu.options.gameplay.quest-resolving" wrapText="true" GridPane.rowIndex="4" />
<ToggleButton fx:id="allowQuestResolvingToggle" mnemonicParsing="false" GridPane.columnIndex="1" GridPane.rowIndex="3" /> <ToggleButton fx:id="allowQuestResolvingToggle" mnemonicParsing="false" GridPane.columnIndex="1" GridPane.rowIndex="4" />
<Label text="%menu.options.gameplay.auto-quest-refill" GridPane.rowIndex="4" /> <Label minHeight="-Infinity" text="%menu.options.gameplay.auto-quest-refill" wrapText="true" GridPane.rowIndex="5" />
<ToggleButton fx:id="autoQuestRefillToggle" mnemonicParsing="false" GridPane.columnIndex="1" GridPane.rowIndex="4" /> <ToggleButton fx:id="autoQuestRefillToggle" mnemonicParsing="false" GridPane.columnIndex="1" GridPane.rowIndex="5" />
<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" />
</children> </children>
<padding> <padding>
<Insets left="20.0" right="20.0" /> <Insets left="20.0" right="20.0" />

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

View File

@@ -5,9 +5,14 @@ menu.options = Optionen
menu.options.available = Verf\u00fcgbare Optionen: menu.options.available = Verf\u00fcgbare Optionen:
menu.options.back = Anwenden und zur\u00fcck menu.options.back = Anwenden und zur\u00fcck
menu.options.general = Allgemein menu.options.general = Allgemein
menu.options.general.sounds = Geräusche
menu.options.gameplay = Spielmechanik menu.options.gameplay = Spielmechanik
menu.options.gameplay.quest-resolving = Erlauben Auftr\u00e4ge gegeneinander aufzul\u00f6sen menu.options.gameplay.quest-resolving = Erlauben Auftr\u00e4ge gegeneinander aufzul\u00f6sen
menu.options.gameplay.auto-quest-refill = Automatisch neue Auftr\u00e4ge akzeptieren menu.options.gameplay.auto-quest-refill = Automatisch neue Auftr\u00e4ge akzeptieren
menu.options.imprint = Impressum
menu.options.imprint.developer = Entwickelt von Johannes Freitag.
menu.options.imprint.assets = Die Grafiken wurden von mir selbst erstellt. Die Audio-Dateien stammen von freesound.org und sind lizensiert als CC0.
menu.options.imprint.javafx = Die Benutzeroberfläche wurde mit JavaFX und dem Gluon Scene Builder erstellt.
general.invalid-input = Ung\u00fcltige Eingabe general.invalid-input = Ung\u00fcltige Eingabe

View File

@@ -8,9 +8,14 @@ menu.options = Options
menu.options.available = Available options: menu.options.available = Available options:
menu.options.back = Apply & Leave menu.options.back = Apply & Leave
menu.options.general = General menu.options.general = General
menu.options.general.sounds = Sounds
menu.options.gameplay = Gameplay menu.options.gameplay = Gameplay
menu.options.gameplay.quest-resolving = Allow quest resolving menu.options.gameplay.quest-resolving = Allow quest resolving
menu.options.gameplay.auto-quest-refill = Automatically refill quests menu.options.gameplay.auto-quest-refill = Automatically refill quests
menu.options.imprint = Imprint
menu.options.imprint.developer = Developed by Johannes Freitag.
menu.options.imprint.assets = Images are made by myself. Sounds are licensed as CC0 and taken from freesound.org.
menu.options.imprint.javafx = User Interface created with JavaFX and the Gluon Scene Builder.
general.invalid-input = Invalid input general.invalid-input = Invalid input