Add preview for valid targets
This commit is contained in:
@@ -10,6 +10,10 @@ import java.util.prefs.Preferences;
|
||||
* Holds the game's options and is responsible for saving and loading them.
|
||||
*/
|
||||
public class Options {
|
||||
/**
|
||||
* Whether valid targets for quests/products should be highlighted
|
||||
*/
|
||||
private boolean previewValidTargets;
|
||||
/**
|
||||
* Whether quest should get automatically added when fulfilled
|
||||
*/
|
||||
@@ -71,6 +75,14 @@ public class Options {
|
||||
this.soundEnabled = soundEnabled;
|
||||
}
|
||||
|
||||
public boolean getPreviewValidTargets() {
|
||||
return previewValidTargets;
|
||||
}
|
||||
|
||||
public void setPreviewValidTargets(boolean previewValidTargets) {
|
||||
this.previewValidTargets = previewValidTargets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a reference to the preferences object used for session independent storage.
|
||||
* @return The preferences object
|
||||
@@ -84,6 +96,7 @@ public class Options {
|
||||
*/
|
||||
public void load() {
|
||||
Preferences preferences = getPreferences();
|
||||
previewValidTargets = preferences.getBoolean("preview-valid-targets", true);
|
||||
autoRefillQuests = preferences.getBoolean("auto-refill-quests", false);
|
||||
allowQuestResolving = preferences.getBoolean("allow-quest-resolving", true);
|
||||
soundEnabled = preferences.getBoolean("sound-enabled", false);
|
||||
@@ -97,6 +110,7 @@ public class Options {
|
||||
*/
|
||||
public void save() {
|
||||
Preferences preferences = getPreferences();
|
||||
preferences.putBoolean("preview-valid-targets", previewValidTargets);
|
||||
preferences.putBoolean("auto-refill-quests", autoRefillQuests);
|
||||
preferences.putBoolean("allow-quest-resolving", allowQuestResolving);
|
||||
preferences.putBoolean("sound-enabled", soundEnabled);
|
||||
|
||||
@@ -44,6 +44,7 @@ public class JFXVisual extends Application implements Visual {
|
||||
private static GameController gameController;
|
||||
private static JFXStorageSlot[][] storageSlots;
|
||||
private static int width, height, depth;
|
||||
private static int currentQuestPreview = -1;
|
||||
|
||||
private static Scene optionsScene;
|
||||
private static OptionsController optionsController;
|
||||
@@ -370,4 +371,50 @@ public class JFXVisual extends Application implements Visual {
|
||||
slot.getImages()[dz].setTooltip(null);
|
||||
GridPane.setConstraints(slot.getImages()[dz], GridPane.getColumnIndex(slot.getImages()[dz]), dz, 1, 1);
|
||||
}
|
||||
|
||||
public static void previewQuestSources(int questIndex) {
|
||||
WhatAStorage instance = WhatAStorage.getInstance();
|
||||
|
||||
if (currentQuestPreview == questIndex) {
|
||||
clearPreviews();
|
||||
} else {
|
||||
for (int x = 0; x < storageSlots.length; x++) {
|
||||
for (int y = 0; y < storageSlots.length; y++) {
|
||||
JFXUtil.setStyleClass(storageSlots[y][x].getGrid(), "preview", instance.canDeliverProduct(questIndex, x, y));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void previewQuestTargets(int questIndex) {
|
||||
WhatAStorage instance = WhatAStorage.getInstance();
|
||||
|
||||
if (instance.getOptions().getPreviewValidTargets()) {
|
||||
for (int x = 0; x < storageSlots.length; x++) {
|
||||
for (int y = 0; y < storageSlots.length; y++) {
|
||||
JFXUtil.setStyleClass(storageSlots[y][x].getGrid(), "preview", instance.canStoreProduct(questIndex, x, y));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void previewStorageTargets(int sx, int sy) {
|
||||
WhatAStorage instance = WhatAStorage.getInstance();
|
||||
|
||||
if (instance.getOptions().getPreviewValidTargets()) {
|
||||
for (int x = 0; x < storageSlots.length; x++) {
|
||||
for (int y = 0; y < storageSlots.length; y++) {
|
||||
JFXUtil.setStyleClass(storageSlots[y][x].getGrid(), "preview", instance.canMoveProduct(sx, sy, x, y));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void clearPreviews() {
|
||||
for (int x = 0; x < storageSlots.length; x++) {
|
||||
for (JFXStorageSlot[] storageSlot : storageSlots) {
|
||||
JFXUtil.setStyleClass(storageSlot[x].getGrid(), "preview", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package de.siphalor.was.visual.jfx.controller;
|
||||
|
||||
import de.siphalor.was.WhatAStorage;
|
||||
import de.siphalor.was.assets.AssetsManager;
|
||||
import de.siphalor.was.visual.JFXVisual;
|
||||
import de.siphalor.was.visual.jfx.util.DraggedProduct;
|
||||
import de.siphalor.was.visual.jfx.util.JFXUtil;
|
||||
import javafx.animation.FadeTransition;
|
||||
@@ -90,6 +91,7 @@ public class GameController {
|
||||
dragEvent.consume();
|
||||
|
||||
JFXUtil.playAudio("destroy");
|
||||
JFXVisual.clearPreviews();
|
||||
return;
|
||||
} else if (origin instanceof DraggedProduct.Slot) {
|
||||
was.userDestroyProduct(((DraggedProduct.Slot) origin).x, ((DraggedProduct.Slot) origin).y);
|
||||
@@ -97,6 +99,7 @@ public class GameController {
|
||||
dragEvent.setDropCompleted(true);
|
||||
dragEvent.consume();
|
||||
JFXUtil.playAudio("destroy");
|
||||
JFXVisual.clearPreviews();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ public class OptionsController {
|
||||
public ToggleButton soundsEnabledToggle;
|
||||
public ToggleButton allowQuestResolvingToggle;
|
||||
public ToggleButton autoQuestRefillToggle;
|
||||
public ToggleButton previewValidTargetsToggle;
|
||||
|
||||
public void beforeOpen(@NotNull Runnable exitRunnable) {
|
||||
Options options = WhatAStorage.getInstance().getOptions();
|
||||
@@ -39,6 +40,7 @@ public class OptionsController {
|
||||
soundsEnabledToggle.setSelected(options.getSoundEnabled());
|
||||
allowQuestResolvingToggle.setSelected(options.getAllowQuestResolving());
|
||||
autoQuestRefillToggle.setSelected(options.getAutoRefillQuests());
|
||||
previewValidTargetsToggle.setSelected(options.getPreviewValidTargets());
|
||||
}
|
||||
|
||||
@FXML
|
||||
@@ -50,6 +52,7 @@ public class OptionsController {
|
||||
options.setSoundEnabled(soundsEnabledToggle.isSelected());
|
||||
options.setAllowQuestResolving(allowQuestResolvingToggle.isSelected());
|
||||
options.setAutoRefillQuests(autoQuestRefillToggle.isSelected());
|
||||
options.setPreviewValidTargets(previewValidTargetsToggle.isSelected());
|
||||
|
||||
options.save();
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package de.siphalor.was.visual.jfx.controller;
|
||||
|
||||
import de.siphalor.was.WhatAStorage;
|
||||
import de.siphalor.was.content.quest.Quest;
|
||||
import de.siphalor.was.visual.JFXVisual;
|
||||
import de.siphalor.was.visual.jfx.util.DraggedProduct;
|
||||
import de.siphalor.was.visual.jfx.util.JFXUtil;
|
||||
import javafx.fxml.FXML;
|
||||
@@ -32,6 +33,11 @@ public class QuestController {
|
||||
WhatAStorage.getInstance().userAbandonQuest(getIndex());
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void onPreviewRequest() {
|
||||
JFXVisual.previewQuestSources(getIndex());
|
||||
}
|
||||
|
||||
private boolean canDropHere(DragEvent dragEvent) {
|
||||
if (type != Quest.Type.OUT) {
|
||||
return false;
|
||||
@@ -60,6 +66,8 @@ public class QuestController {
|
||||
ClipboardContent content = new ClipboardContent();
|
||||
content.put(DraggedProduct.FORMAT, new DraggedProduct.Quest(getIndex()));
|
||||
dragboard.setContent(content);
|
||||
|
||||
JFXVisual.previewQuestTargets(getIndex());
|
||||
}
|
||||
|
||||
event.consume();
|
||||
@@ -93,6 +101,7 @@ public class QuestController {
|
||||
if (WhatAStorage.getInstance().userDeliverProduct(getIndex(), slot.x, slot.y)) {
|
||||
dragEvent.setDropCompleted(true);
|
||||
dragEvent.consume();
|
||||
JFXVisual.clearPreviews();
|
||||
return;
|
||||
}
|
||||
} else if (product instanceof DraggedProduct.Quest) {
|
||||
@@ -100,6 +109,7 @@ public class QuestController {
|
||||
if (WhatAStorage.getInstance().userResolveQuests(quest.index, getIndex())) {
|
||||
dragEvent.setDropCompleted(true);
|
||||
dragEvent.consume();
|
||||
JFXVisual.clearPreviews();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package de.siphalor.was.visual.jfx.util;
|
||||
|
||||
import de.siphalor.was.WhatAStorage;
|
||||
import de.siphalor.was.content.lang.I18n;
|
||||
import de.siphalor.was.visual.JFXVisual;
|
||||
import de.siphalor.was.visual.jfx.component.ScalingImagePane;
|
||||
import javafx.geometry.HPos;
|
||||
import javafx.geometry.VPos;
|
||||
@@ -115,6 +116,8 @@ public class JFXStorageSlot {
|
||||
content.put(DraggedProduct.FORMAT, new DraggedProduct.Slot(x, y));
|
||||
dragboard.setContent(content);
|
||||
|
||||
JFXVisual.previewStorageTargets(x, y);
|
||||
|
||||
event.consume();
|
||||
}
|
||||
|
||||
@@ -140,12 +143,14 @@ public class JFXStorageSlot {
|
||||
WhatAStorage.getInstance().userStoreProduct(((DraggedProduct.Quest) origin).index, x, y);
|
||||
dragEvent.setDropCompleted(true);
|
||||
JFXUtil.playAudio("place");
|
||||
JFXVisual.clearPreviews();
|
||||
return;
|
||||
} else if (origin instanceof DraggedProduct.Slot) {
|
||||
DraggedProduct.Slot slot = (DraggedProduct.Slot) origin;
|
||||
WhatAStorage.getInstance().userMoveProduct(slot.x, slot.y, x, y);
|
||||
dragEvent.setDropCompleted(true);
|
||||
JFXUtil.playAudio("place");
|
||||
JFXVisual.clearPreviews();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,8 +132,13 @@ Label.green {
|
||||
-fx-background-color: #dddddd;
|
||||
}
|
||||
|
||||
#storage-grid > .preview {
|
||||
-fx-border-color: #aaaaaa;
|
||||
-fx-background-insets: 1;
|
||||
-fx-padding: -1;
|
||||
}
|
||||
#storage-grid > .drop-hover {
|
||||
-fx-background-color: #eeeeee;
|
||||
-fx-background-color: #dddddd;
|
||||
}
|
||||
.storage-slot-item-title {
|
||||
-fx-padding: 0 0 0 5;
|
||||
|
||||
@@ -1,18 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.ChoiceBox?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.ScrollPane?>
|
||||
<?import javafx.scene.control.ToggleButton?>
|
||||
<?import javafx.scene.control.ToolBar?>
|
||||
<?import javafx.scene.layout.ColumnConstraints?>
|
||||
<?import javafx.scene.layout.GridPane?>
|
||||
<?import javafx.scene.layout.RowConstraints?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<?import javafx.geometry.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="500.0" prefWidth="850.0" xmlns="http://javafx.com/javafx/9.0.1" xmlns:fx="http://javafx.com/fxml/1">
|
||||
<VBox 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>
|
||||
<ToolBar prefHeight="40.0" prefWidth="200.0">
|
||||
<items>
|
||||
@@ -34,6 +26,7 @@
|
||||
<RowConstraints minHeight="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" />
|
||||
@@ -47,12 +40,14 @@
|
||||
<ToggleButton fx:id="allowQuestResolvingToggle" mnemonicParsing="false" GridPane.columnIndex="1" 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="5" />
|
||||
<Label styleClass="heading" text="%menu.options.imprint" GridPane.rowIndex="6" />
|
||||
<Label styleClass="heading" text="%menu.options.imprint" GridPane.rowIndex="7" />
|
||||
<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" 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" />
|
||||
<Label alignment="TOP_LEFT" minHeight="-Infinity" text="%menu.options.imprint.developer" wrapText="true" GridPane.rowIndex="8" />
|
||||
<Label minHeight="-Infinity" text="%menu.options.imprint.assets" wrapText="true" GridPane.rowIndex="9" />
|
||||
<Label minHeight="-Infinity" text="%menu.options.imprint.javafx" wrapText="true" GridPane.rowIndex="10" />
|
||||
<Label text="%menu.options.gameplay.preview-valid-targets" GridPane.rowIndex="6" />
|
||||
<ToggleButton fx:id="previewValidTargetsToggle" mnemonicParsing="false" GridPane.columnIndex="1" GridPane.rowIndex="6" />
|
||||
</children>
|
||||
<padding>
|
||||
<Insets left="20.0" right="20.0" />
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.image.ImageView?>
|
||||
<?import javafx.geometry.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.image.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
<GridPane fx:id="questContainer" maxHeight="-Infinity" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="250.0" onDragDetected="#onDragDetected" onDragDropped="#onDragDropped" onDragEntered="#onDragEntered" onDragExited="#onDragExited" onDragOver="#onDragOver" prefHeight="80.0" styleClass="quest-container" xmlns="http://javafx.com/javafx/9.0.1" xmlns:fx="http://javafx.com/fxml/1">
|
||||
<?import javafx.scene.text.*?>
|
||||
|
||||
<GridPane fx:id="questContainer" maxHeight="-Infinity" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="250.0" onContextMenuRequested="#onPreviewRequest" onDragDetected="#onDragDetected" onDragDropped="#onDragDropped" onDragEntered="#onDragEntered" onDragExited="#onDragExited" onDragOver="#onDragOver" prefHeight="80.0" styleClass="quest-container" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="-Infinity" minWidth="-Infinity" prefWidth="80.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" />
|
||||
|
||||
@@ -7,6 +7,7 @@ menu.options.back = Anwenden und zur\u00fcck
|
||||
menu.options.general = Allgemein
|
||||
menu.options.general.sounds = Geräusche
|
||||
menu.options.gameplay = Spielmechanik
|
||||
menu.options.gameplay.preview-valid-targets = G\u00fcltige Ablageorte anzeigen (Sieht ein bisschen h\u00e4sslich aus)
|
||||
menu.options.gameplay.quest-resolving = Erlauben Auftr\u00e4ge gegeneinander aufzul\u00f6sen
|
||||
menu.options.gameplay.auto-quest-refill = Automatisch neue Auftr\u00e4ge akzeptieren
|
||||
menu.options.imprint = Impressum
|
||||
|
||||
@@ -10,6 +10,7 @@ menu.options.back = Apply & Leave
|
||||
menu.options.general = General
|
||||
menu.options.general.sounds = Sounds
|
||||
menu.options.gameplay = Gameplay
|
||||
menu.options.gameplay.preview-valid-targets = Preview valid targets (It's a bit ugly)
|
||||
menu.options.gameplay.quest-resolving = Allow quest resolving
|
||||
menu.options.gameplay.auto-quest-refill = Automatically refill quests
|
||||
menu.options.imprint = Imprint
|
||||
|
||||
Reference in New Issue
Block a user