Improve JFXVisual and implement auto refill
This commit is contained in:
@@ -102,19 +102,26 @@ public class WhatAStorage {
|
|||||||
|
|
||||||
public void setup() {
|
public void setup() {
|
||||||
visual.setup(this);
|
visual.setup(this);
|
||||||
loadGame();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
visual.run();
|
visual.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadGame() {
|
public void startGame() {
|
||||||
questGenerator = questManager.get("example.test");
|
questGenerator = questManager.get("example.test");
|
||||||
//questGenerator = new RandomQuestGenerator();
|
//questGenerator = new RandomQuestGenerator();
|
||||||
quests.clear();
|
quests.clear();
|
||||||
storage = new Storage(GRID_SIZE, GRID_SIZE, GRID_SIZE);
|
storage = new Storage(GRID_SIZE, GRID_SIZE, GRID_SIZE);
|
||||||
balance = new Balance();
|
balance = new Balance();
|
||||||
|
|
||||||
|
visual.onGameStart();
|
||||||
|
|
||||||
|
if (options.getAutoRefillQuests()) {
|
||||||
|
for (int i = 0; i < MAX_QUESTS; i++) {
|
||||||
|
nextQuest();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void scheduleStop() {
|
public void scheduleStop() {
|
||||||
@@ -160,7 +167,7 @@ public class WhatAStorage {
|
|||||||
visual.onBalanceChanged(balance.getBudget(), new Transaction(Transaction.Type.NOOP, 0, ""), balance.getTotalIncome(), balance.getTotalLoss());
|
visual.onBalanceChanged(balance.getBudget(), new Transaction(Transaction.Type.NOOP, 0, ""), balance.getTotalIncome(), balance.getTotalLoss());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean userRequestQuest() {
|
private boolean nextQuest() {
|
||||||
if (quests.size() >= MAX_QUESTS) return false;
|
if (quests.size() >= MAX_QUESTS) return false;
|
||||||
|
|
||||||
if (!questGenerator.hasMoreElements()) {
|
if (!questGenerator.hasMoreElements()) {
|
||||||
@@ -174,6 +181,10 @@ public class WhatAStorage {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean userRequestQuest() {
|
||||||
|
return nextQuest();
|
||||||
|
}
|
||||||
|
|
||||||
public void userAbandonQuest(int index) {
|
public void userAbandonQuest(int index) {
|
||||||
if (index >= quests.size()) {
|
if (index >= quests.size()) {
|
||||||
Util.LOGGER.log(Level.SEVERE, "Attempted to abandon non-existent quest!");
|
Util.LOGGER.log(Level.SEVERE, "Attempted to abandon non-existent quest!");
|
||||||
@@ -184,6 +195,8 @@ public class WhatAStorage {
|
|||||||
addTransaction(Transaction.Type.ABANDON, -quest.getReward(), quest.getProduct());
|
addTransaction(Transaction.Type.ABANDON, -quest.getReward(), quest.getProduct());
|
||||||
|
|
||||||
visual.onQuestRemoved(index);
|
visual.onQuestRemoved(index);
|
||||||
|
|
||||||
|
if (options.getAutoRefillQuests()) nextQuest();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canStoreProduct(@Nullable Product product, int x, int y) {
|
public boolean canStoreProduct(@Nullable Product product, int x, int y) {
|
||||||
@@ -209,6 +222,8 @@ public class WhatAStorage {
|
|||||||
addTransaction(Transaction.Type.STORE, quest.getReward(), product);
|
addTransaction(Transaction.Type.STORE, quest.getReward(), product);
|
||||||
visual.onQuestRemoved(questIndex);
|
visual.onQuestRemoved(questIndex);
|
||||||
visual.onProductSet(x, y, z, quest.getProduct());
|
visual.onProductSet(x, y, z, quest.getProduct());
|
||||||
|
|
||||||
|
if (options.getAutoRefillQuests()) nextQuest();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -229,6 +244,8 @@ public class WhatAStorage {
|
|||||||
quests.remove(questIndex);
|
quests.remove(questIndex);
|
||||||
visual.onQuestRemoved(questIndex);
|
visual.onQuestRemoved(questIndex);
|
||||||
visual.onProductCleared(x, y, z, product);
|
visual.onProductCleared(x, y, z, product);
|
||||||
|
|
||||||
|
if (options.getAutoRefillQuests()) nextQuest();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -252,8 +269,7 @@ public class WhatAStorage {
|
|||||||
if (quests.get(in).getType() == Quest.Type.IN && quests.get(out).getType() == Quest.Type.OUT) {
|
if (quests.get(in).getType() == Quest.Type.IN && quests.get(out).getType() == Quest.Type.OUT) {
|
||||||
Product product = quests.get(in).getProduct();
|
Product product = quests.get(in).getProduct();
|
||||||
if (product.equals(quests.get(out).getProduct())) {
|
if (product.equals(quests.get(out).getProduct())) {
|
||||||
addTransaction(Transaction.Type.STORE, quests.get(in).getReward(), product);
|
addTransaction(Transaction.Type.RESOLVE, quests.get(in).getReward() + quests.get(out).getReward(), product);
|
||||||
addTransaction(Transaction.Type.DELIVER, quests.get(out).getReward(), product);
|
|
||||||
|
|
||||||
if (out > in) out--;
|
if (out > in) out--;
|
||||||
quests.remove(in);
|
quests.remove(in);
|
||||||
@@ -261,6 +277,11 @@ public class WhatAStorage {
|
|||||||
|
|
||||||
visual.onQuestRemoved(in);
|
visual.onQuestRemoved(in);
|
||||||
visual.onQuestRemoved(out);
|
visual.onQuestRemoved(out);
|
||||||
|
|
||||||
|
if (options.getAutoRefillQuests()) {
|
||||||
|
nextQuest();
|
||||||
|
nextQuest();
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public class Transaction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public enum Type {
|
public enum Type {
|
||||||
ABANDON, DESTROY, MOVE, NOOP, DELIVER, STORE;
|
ABANDON, DESTROY, MOVE, NOOP, DELIVER, STORE, RESOLVE;
|
||||||
|
|
||||||
public String getTranslationKey() {
|
public String getTranslationKey() {
|
||||||
return "game.balance.history.type." + name().toLowerCase(Locale.ENGLISH);
|
return "game.balance.history.type." + name().toLowerCase(Locale.ENGLISH);
|
||||||
|
|||||||
@@ -149,6 +149,11 @@ public class CanvasVisual implements Visual {
|
|||||||
frame.dispose();
|
frame.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGameStart() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onScheduleStop() {
|
public void onScheduleStop() {
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import de.siphalor.was.content.resource.Resource;
|
|||||||
import de.siphalor.was.game.Transaction;
|
import de.siphalor.was.game.Transaction;
|
||||||
import de.siphalor.was.util.Util;
|
import de.siphalor.was.util.Util;
|
||||||
import de.siphalor.was.visual.jfx.controller.BalanceController;
|
import de.siphalor.was.visual.jfx.controller.BalanceController;
|
||||||
import de.siphalor.was.visual.jfx.controller.MainController;
|
import de.siphalor.was.visual.jfx.controller.GameController;
|
||||||
import de.siphalor.was.visual.jfx.controller.OptionsController;
|
import de.siphalor.was.visual.jfx.controller.OptionsController;
|
||||||
import de.siphalor.was.visual.jfx.controller.QuestController;
|
import de.siphalor.was.visual.jfx.controller.QuestController;
|
||||||
import de.siphalor.was.visual.jfx.util.JFXUtil;
|
import de.siphalor.was.visual.jfx.util.JFXUtil;
|
||||||
@@ -41,7 +41,7 @@ public class JFXVisual extends Application implements Visual {
|
|||||||
private static Stage primaryStage;
|
private static Stage primaryStage;
|
||||||
|
|
||||||
private static Scene gameScene;
|
private static Scene gameScene;
|
||||||
private static MainController gameController;
|
private static GameController gameController;
|
||||||
private static GridPane storageGrid;
|
private static GridPane storageGrid;
|
||||||
private static JFXStorageSlot[][] storageSlots;
|
private static JFXStorageSlot[][] storageSlots;
|
||||||
|
|
||||||
@@ -78,6 +78,11 @@ public class JFXVisual extends Application implements Visual {
|
|||||||
launch();
|
launch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGameStart() {
|
||||||
|
changeScene(gameScene);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onScheduleStop() {
|
public void onScheduleStop() {
|
||||||
primaryStage.close();
|
primaryStage.close();
|
||||||
@@ -100,6 +105,19 @@ public class JFXVisual extends Application implements Visual {
|
|||||||
if (balanceController != null) {
|
if (balanceController != null) {
|
||||||
balanceController.onBalanceChanged(budget, transaction, totalIncome, totalLoss);
|
balanceController.onBalanceChanged(budget, transaction, totalIncome, totalLoss);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (transaction.getChange() != 0) {
|
||||||
|
gameController.budgetChangeLabel.getStyleClass().clear();
|
||||||
|
if (transaction.getChange() > 0) {
|
||||||
|
JFXUtil.setStyleClass(gameController.budgetChangeLabel, "green", true);
|
||||||
|
gameController.budgetChangeLabel.setText(i18n.format("game.budget.change.income", transaction.getChange()));
|
||||||
|
} else {
|
||||||
|
JFXUtil.setStyleClass(gameController.budgetChangeLabel, "red", true);
|
||||||
|
gameController.budgetChangeLabel.setText(i18n.format("game.budget.change.loss", transaction.getChange()));
|
||||||
|
}
|
||||||
|
gameController.budgetChangeLabel.setOpacity(1D);
|
||||||
|
gameController.budgetChangeTransition.playFromStart();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -117,7 +135,7 @@ public class JFXVisual extends Application implements Visual {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage primaryStage) throws Exception {
|
public void start(Stage primaryStage) {
|
||||||
JFXVisual.primaryStage = primaryStage;
|
JFXVisual.primaryStage = primaryStage;
|
||||||
primaryStage.setTitle(WhatAStorage.TITLE);
|
primaryStage.setTitle(WhatAStorage.TITLE);
|
||||||
primaryStage.setMinWidth(850);
|
primaryStage.setMinWidth(850);
|
||||||
@@ -131,17 +149,17 @@ public class JFXVisual extends Application implements Visual {
|
|||||||
balanceStage.hide();
|
balanceStage.hide();
|
||||||
});
|
});
|
||||||
|
|
||||||
changeScene(gameScene);
|
WhatAStorage.getInstance().startGame();
|
||||||
|
|
||||||
primaryStage.show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void changeScene(Scene nextScene) {
|
private void changeScene(Scene nextScene) {
|
||||||
primaryStage.setScene(nextScene);
|
primaryStage.setScene(nextScene);
|
||||||
|
if (!primaryStage.isShowing())
|
||||||
|
primaryStage.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadGameScene() {
|
public void loadGameScene() {
|
||||||
gameController = new MainController(WhatAStorage.getInstance());
|
gameController = new GameController(WhatAStorage.getInstance());
|
||||||
|
|
||||||
gameScene = JFXUtil.loadScene("game", gameController, I18n.getInstance());
|
gameScene = JFXUtil.loadScene("game", gameController, I18n.getInstance());
|
||||||
|
|
||||||
@@ -214,7 +232,7 @@ public class JFXVisual extends Application implements Visual {
|
|||||||
loader.setController(questController);
|
loader.setController(questController);
|
||||||
Parent parent = loader.load(is);
|
Parent parent = loader.load(is);
|
||||||
|
|
||||||
FadeTransition transition = new FadeTransition(Duration.millis(250), parent);
|
FadeTransition transition = new FadeTransition(Duration.millis(750), parent);
|
||||||
transition.setFromValue(0D);
|
transition.setFromValue(0D);
|
||||||
transition.setByValue(1D);
|
transition.setByValue(1D);
|
||||||
transition.setInterpolator(Interpolator.EASE_OUT);
|
transition.setInterpolator(Interpolator.EASE_OUT);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import de.siphalor.was.game.Transaction;
|
|||||||
public interface Visual {
|
public interface Visual {
|
||||||
void setup(WhatAStorage whatAStorage);
|
void setup(WhatAStorage whatAStorage);
|
||||||
void run();
|
void run();
|
||||||
|
void onGameStart();
|
||||||
void onScheduleStop();
|
void onScheduleStop();
|
||||||
|
|
||||||
void invalidateI18n();
|
void invalidateI18n();
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ 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 javafx.animation.FadeTransition;
|
||||||
|
import javafx.animation.Interpolator;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
@@ -12,12 +14,14 @@ import javafx.scene.input.DragEvent;
|
|||||||
import javafx.scene.input.TransferMode;
|
import javafx.scene.input.TransferMode;
|
||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
|
import javafx.util.Duration;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class MainController {
|
public class GameController {
|
||||||
private final WhatAStorage was;
|
private final WhatAStorage was;
|
||||||
|
|
||||||
public Label budgetLabel;
|
public Label budgetLabel;
|
||||||
|
public Label budgetChangeLabel;
|
||||||
public Button balanceButton;
|
public Button balanceButton;
|
||||||
public Button optionsButton;
|
public Button optionsButton;
|
||||||
|
|
||||||
@@ -28,10 +32,21 @@ public class MainController {
|
|||||||
public VBox questBox;
|
public VBox questBox;
|
||||||
public Button nextQuestButton;
|
public Button nextQuestButton;
|
||||||
|
|
||||||
public MainController(WhatAStorage was) {
|
public FadeTransition budgetChangeTransition;
|
||||||
|
|
||||||
|
public GameController(WhatAStorage was) {
|
||||||
this.was = was;
|
this.was = was;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void initialize() {
|
||||||
|
budgetChangeTransition = new FadeTransition(Duration.millis(1000), budgetChangeLabel);
|
||||||
|
budgetChangeTransition.setDelay(Duration.millis(250));
|
||||||
|
budgetChangeTransition.setFromValue(1D);
|
||||||
|
budgetChangeTransition.setByValue(-1D);
|
||||||
|
budgetChangeTransition.setInterpolator(Interpolator.EASE_BOTH);
|
||||||
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void scheduleStop() {
|
private void scheduleStop() {
|
||||||
was.scheduleStop();
|
was.scheduleStop();
|
||||||
@@ -30,6 +30,14 @@
|
|||||||
<Insets left="5.0" />
|
<Insets left="5.0" />
|
||||||
</padding>
|
</padding>
|
||||||
</Label>
|
</Label>
|
||||||
|
<Label fx:id="budgetChangeLabel">
|
||||||
|
<font>
|
||||||
|
<Font size="19.0" />
|
||||||
|
</font>
|
||||||
|
<padding>
|
||||||
|
<Insets left="5.0" />
|
||||||
|
</padding>
|
||||||
|
</Label>
|
||||||
</items>
|
</items>
|
||||||
</ToolBar>
|
</ToolBar>
|
||||||
<HBox layoutX="710.5" layoutY="7.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="7.0">
|
<HBox layoutX="710.5" layoutY="7.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="7.0">
|
||||||
|
|||||||
@@ -2,24 +2,27 @@ test.hello-world = Hallo Welt!
|
|||||||
|
|
||||||
menu.back = Zur\u00fcck
|
menu.back = Zur\u00fcck
|
||||||
menu.options = Optionen
|
menu.options = Optionen
|
||||||
|
menu.options.back = Anwenden und zur\u00fcck
|
||||||
menu.options.general = Allgemein
|
menu.options.general = Allgemein
|
||||||
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
|
||||||
|
|
||||||
game.budget = Budget: %d\u20ac
|
game.budget = Budget: %d\u20ac
|
||||||
|
game.budget.change.income = +%d\u20ac
|
||||||
|
game.budget.change.loss = %d\u20ac
|
||||||
game.quit = Spiel beenden
|
game.quit = Spiel beenden
|
||||||
game.quests = Auftr\u00e4ge
|
game.quests = Auftr\u00e4ge
|
||||||
game.quests.next = N\u00e4chster Auftrag
|
game.quests.next = N\u00e4chster Auftrag
|
||||||
game.quest.reward = %d\u20ac
|
game.quest.reward = %d\u20ac
|
||||||
game.trash = M\u00fclltonne
|
game.trash = M\u00fclltonne
|
||||||
game.trash.hover = Zerst\u00f6ren
|
game.trash.hover = Produkte zerst\u00f6ren oder Auftr\u00e4ge aufgeben
|
||||||
game.storage = Lager
|
game.storage = Lager
|
||||||
game.storage.empty = Leer
|
game.storage.empty = Leer
|
||||||
game.balance = Bilanz
|
game.balance = Bilanz
|
||||||
game.balance.history = Buchungen
|
game.balance.history = Buchungen
|
||||||
game.balance.history.no-data = Noch keine Buchungen
|
game.balance.history.no-data = Noch keine Buchungen
|
||||||
game.balance.history.index =
|
game.balance.history.index =
|
||||||
game.balance.history.change = Wert in \u20ac
|
game.balance.history.change = Wert in \u20ac
|
||||||
game.balance.history.type = Beschreibung
|
game.balance.history.type = Beschreibung
|
||||||
game.balance.history.type.abandon = Auftrag abgelehnt
|
game.balance.history.type.abandon = Auftrag abgelehnt
|
||||||
@@ -28,6 +31,7 @@ game.balance.history.type.move = Produkt bewegt
|
|||||||
game.balance.history.type.noop = NOOP
|
game.balance.history.type.noop = NOOP
|
||||||
game.balance.history.type.deliver = Produkt ausgelagert
|
game.balance.history.type.deliver = Produkt ausgelagert
|
||||||
game.balance.history.type.store = Produkt eingelagert
|
game.balance.history.type.store = Produkt eingelagert
|
||||||
|
game.balance.history.type.resolve = Zwei Auftr\u00e4ge miteinander aufgel\u00f6st
|
||||||
game.balance.history.product = Produkt
|
game.balance.history.product = Produkt
|
||||||
game.balance.chart = Bilanz
|
game.balance.chart = Bilanz
|
||||||
game.balance.chart.line = Budget
|
game.balance.chart.line = Budget
|
||||||
|
|||||||
@@ -11,12 +11,14 @@ 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
|
||||||
|
|
||||||
game.budget = Budget: %d$
|
game.budget = Budget: %d$
|
||||||
|
game.budget.change.income = +%d$
|
||||||
|
game.budget.change.loss = %d$
|
||||||
game.quit = Quit Game
|
game.quit = Quit Game
|
||||||
game.quests = Quests
|
game.quests = Quests
|
||||||
game.quests.next = Next Quest
|
game.quests.next = Next Quest
|
||||||
game.quest.reward = %d$
|
game.quest.reward = %d$
|
||||||
game.trash = Recycle Bin
|
game.trash = Recycle Bin
|
||||||
game.trash.hover = Destroy\n%d$
|
game.trash.hover = Destroy products or abandon quests
|
||||||
game.storage = Storage
|
game.storage = Storage
|
||||||
game.storage.empty = Empty
|
game.storage.empty = Empty
|
||||||
game.balance = Balance
|
game.balance = Balance
|
||||||
@@ -31,6 +33,7 @@ game.balance.history.type.move = Product moved
|
|||||||
game.balance.history.type.noop = NOOP
|
game.balance.history.type.noop = NOOP
|
||||||
game.balance.history.type.deliver = Product delivered
|
game.balance.history.type.deliver = Product delivered
|
||||||
game.balance.history.type.store = Product stored
|
game.balance.history.type.store = Product stored
|
||||||
|
game.balance.history.type.resolve = Resolved two quests against each other
|
||||||
game.balance.history.product = Product
|
game.balance.history.product = Product
|
||||||
game.balance.chart = Balance
|
game.balance.chart = Balance
|
||||||
game.balance.chart.line = Budget
|
game.balance.chart.line = Budget
|
||||||
|
|||||||
@@ -17,6 +17,11 @@ public class DummyVisual implements Visual {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGameStart() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onScheduleStop() {
|
public void onScheduleStop() {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user