Small fixes and improvements
* Tweaked random quest generator * Improved chart performance when it's not visible * Set a minimum height for the stage
This commit is contained in:
@@ -19,7 +19,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class WhatAStorage {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package de.siphalor.was.content.quest;
|
||||
|
||||
import de.siphalor.was.WhatAStorage;
|
||||
import de.siphalor.was.content.product.Product;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@@ -18,10 +19,11 @@ public class RandomQuestGenerator implements QuestGenerator {
|
||||
|
||||
@Override
|
||||
public Quest nextElement() {
|
||||
Product product = WhatAStorage.getInstance().getProductManager().randomProduct(RANDOM);
|
||||
return new Quest(
|
||||
RANDOM.nextBoolean() ? Quest.Type.IN : Quest.Type.OUT,
|
||||
RANDOM.nextInt(15) * 100,
|
||||
WhatAStorage.getInstance().getProductManager().randomProduct(RANDOM)
|
||||
RANDOM.nextInt(15) * 100 * product.getDepth(),
|
||||
product
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,9 +31,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.*;
|
||||
|
||||
public class JFXVisual extends Application implements Visual {
|
||||
private static Stage primaryStage;
|
||||
@@ -86,11 +84,16 @@ public class JFXVisual extends Application implements Visual {
|
||||
controller.totalLossLabel.setText(i18n.format("game.balance.total-loss", totalLoss));
|
||||
|
||||
ObservableList<XYChart.Data<Integer, Integer>> data = controller.budgetChartSeries.getData();
|
||||
int i = data.size();
|
||||
data.add(new XYChart.Data<>(data.size(), budget));
|
||||
|
||||
controller.chartQueue.add(budget);
|
||||
|
||||
if (controller.chartTab.isSelected()) {
|
||||
controller.updateChart();
|
||||
}
|
||||
|
||||
if (transaction != Balance.Transaction.NOOP) {
|
||||
controller.balanceHistoryTable.getItems().add(new BalanceEntry(i, change, i18n.getString(transaction.getTranslationKey())));
|
||||
ObservableList<BalanceEntry> items = controller.balanceHistoryTable.getItems();
|
||||
items.add(new BalanceEntry(items.size(), change, i18n.getString(transaction.getTranslationKey())));
|
||||
controller.balanceHistoryTable.sort();
|
||||
}
|
||||
}
|
||||
@@ -113,6 +116,7 @@ public class JFXVisual extends Application implements Visual {
|
||||
public void start(Stage primaryStage) throws Exception {
|
||||
JFXVisual.primaryStage = primaryStage;
|
||||
primaryStage.setMinWidth(850);
|
||||
primaryStage.setMinHeight(500);
|
||||
primaryStage.setTitle(WhatAStorage.TITLE);
|
||||
|
||||
loader.setResources(I18n.getInstance());
|
||||
|
||||
@@ -2,12 +2,14 @@ package de.siphalor.was.visual.jfx;
|
||||
|
||||
import de.siphalor.was.WhatAStorage;
|
||||
import de.siphalor.was.assets.AssetsManager;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.chart.LineChart;
|
||||
import javafx.scene.chart.NumberAxis;
|
||||
import javafx.scene.chart.XYChart;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.Tab;
|
||||
import javafx.scene.control.TableView;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
@@ -16,16 +18,21 @@ import javafx.scene.input.TransferMode;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class MainController {
|
||||
private final WhatAStorage was;
|
||||
|
||||
public Tab chartTab;
|
||||
public Label budgetLabel;
|
||||
public Label totalIncomeLabel;
|
||||
public Label totalLossLabel;
|
||||
public TableView<BalanceEntry> balanceHistoryTable;
|
||||
public LineChart<NumberAxis, NumberAxis> budgetChart;
|
||||
public XYChart.Series<Integer, Integer> budgetChartSeries = new XYChart.Series<>();
|
||||
public Queue<Integer> chartQueue = new LinkedList<>();
|
||||
|
||||
public ImageView trash;
|
||||
|
||||
@@ -94,4 +101,21 @@ public class MainController {
|
||||
}
|
||||
dragEvent.setDropCompleted(false);
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void onChartTabSelected() {
|
||||
updateChart();
|
||||
}
|
||||
|
||||
public void updateChart() {
|
||||
if (!chartQueue.isEmpty()) {
|
||||
ObservableList<XYChart.Data<Integer, Integer>> data = budgetChartSeries.getData();
|
||||
|
||||
for (Integer integer : chartQueue) {
|
||||
data.add(new XYChart.Data<>(data.size(), integer));
|
||||
}
|
||||
|
||||
chartQueue.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
|
||||
<VBox maxHeight="1.7976931348623157E308" prefWidth="800.0" xmlns="http://javafx.com/javafx/9.0.1" xmlns:fx="http://javafx.com/fxml/1">
|
||||
<VBox maxHeight="1.7976931348623157E308" minHeight="500.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/9.0.1" xmlns:fx="http://javafx.com/fxml/1">
|
||||
<children>
|
||||
<AnchorPane>
|
||||
<children>
|
||||
@@ -53,7 +53,7 @@
|
||||
<RowConstraints fillHeight="false" maxHeight="-Infinity" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<ScrollPane id="quest-pane" fitToWidth="true" hbarPolicy="NEVER" prefHeight="200.0" prefWidth="200.0" styleClass="border" GridPane.rowIndex="2">
|
||||
<ScrollPane id="quest-pane" fitToWidth="true" hbarPolicy="NEVER" prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="2">
|
||||
<content>
|
||||
<VBox fx:id="questBox" />
|
||||
</content>
|
||||
@@ -114,9 +114,9 @@
|
||||
<content>
|
||||
<TableView fx:id="balanceHistoryTable" prefHeight="200.0" prefWidth="200.0">
|
||||
<columns>
|
||||
<TableColumn prefWidth="50.666626400416135" sortable="false" styleClass="align-right" text="%game.balance.history.index" />
|
||||
<TableColumn maxWidth="500.0" prefWidth="100.0" sortable="false" styleClass="align-right" text="%game.balance.history.change" />
|
||||
<TableColumn maxWidth="1.7976931348623157E308" prefWidth="300.0" sortable="false" text="%game.balance.history.type" />
|
||||
<TableColumn prefWidth="50.666626400416135" styleClass="align-right" text="%game.balance.history.index" />
|
||||
<TableColumn editable="false" maxWidth="500.0" prefWidth="100.0" styleClass="align-right" text="%game.balance.history.change" />
|
||||
<TableColumn maxWidth="1.7976931348623157E308" prefWidth="300.0" text="%game.balance.history.type" />
|
||||
</columns>
|
||||
<placeholder>
|
||||
<Label text="%game.balance.history.no-data" />
|
||||
@@ -124,7 +124,7 @@
|
||||
</TableView>
|
||||
</content>
|
||||
</Tab>
|
||||
<Tab text="%game.balance.chart">
|
||||
<Tab fx:id="chartTab" onSelectionChanged="#onChartTabSelected" text="%game.balance.chart">
|
||||
<content>
|
||||
<VBox>
|
||||
<children>
|
||||
|
||||
Reference in New Issue
Block a user