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