Add some hover effects
This commit is contained in:
@@ -9,10 +9,7 @@ import de.siphalor.was.content.quest.Quest;
|
||||
import de.siphalor.was.content.resource.Resource;
|
||||
import de.siphalor.was.game.Balance;
|
||||
import de.siphalor.was.util.PersistentInputStream;
|
||||
import de.siphalor.was.visual.jfx.BalanceEntry;
|
||||
import de.siphalor.was.visual.jfx.MainController;
|
||||
import de.siphalor.was.visual.jfx.QuestController;
|
||||
import de.siphalor.was.visual.jfx.StorageSlotController;
|
||||
import de.siphalor.was.visual.jfx.*;
|
||||
import javafx.animation.FadeTransition;
|
||||
import javafx.animation.Interpolator;
|
||||
import javafx.application.Application;
|
||||
@@ -83,13 +80,7 @@ public class JFXVisual extends Application implements Visual {
|
||||
I18n i18n = I18n.getInstance();
|
||||
|
||||
controller.budgetLabel.setText(i18n.format("game.budget", budget));
|
||||
if (budget < 0) {
|
||||
if (!controller.budgetLabel.getStyleClass().contains("red")) {
|
||||
controller.budgetLabel.getStyleClass().add("red");
|
||||
}
|
||||
} else {
|
||||
controller.budgetLabel.getStyleClass().remove("red");
|
||||
}
|
||||
JFXUtil.setStyleClass(controller.budgetLabel, "red", budget < 0);
|
||||
|
||||
controller.totalIncomeLabel.setText(i18n.format("game.balance.total-income", totalIncome));
|
||||
controller.totalLossLabel.setText(i18n.format("game.balance.total-loss", totalLoss));
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.siphalor.was.visual.jfx;
|
||||
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.PixelReader;
|
||||
import javafx.scene.image.PixelWriter;
|
||||
@@ -22,4 +23,14 @@ public class JFXUtil {
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public static void setStyleClass(Node node, String clazz, boolean active) {
|
||||
if (active) {
|
||||
if (!node.getStyleClass().contains(clazz)) {
|
||||
node.getStyleClass().add(clazz);
|
||||
}
|
||||
} else {
|
||||
node.getStyleClass().remove(clazz);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,23 @@ public class QuestController {
|
||||
WhatAStorage.getInstance().abandonQuest(getIndex());
|
||||
}
|
||||
|
||||
private boolean canDropHere(DragEvent dragEvent) {
|
||||
if (type != Quest.Type.OUT) {
|
||||
return false;
|
||||
}
|
||||
if (dragEvent.getDragboard().hasContent(DraggedProduct.FORMAT)) {
|
||||
DraggedProduct product = (DraggedProduct) dragEvent.getDragboard().getContent(DraggedProduct.FORMAT);
|
||||
if (product instanceof DraggedProduct.Quest) {
|
||||
DraggedProduct.Quest quest = (DraggedProduct.Quest) product;
|
||||
return WhatAStorage.getInstance().canQuestsResolve(quest.index, getIndex());
|
||||
} else if (product instanceof DraggedProduct.Slot) {
|
||||
DraggedProduct.Slot slot = (DraggedProduct.Slot) product;
|
||||
return WhatAStorage.getInstance().canDeliverProduct(getIndex(), slot.x, slot.y);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void onDragDetected(MouseEvent event) {
|
||||
if (type == Quest.Type.IN) {
|
||||
@@ -44,24 +61,21 @@ public class QuestController {
|
||||
event.consume();
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void onDragEntered(DragEvent dragEvent) {
|
||||
JFXUtil.setStyleClass(questContainer, "drop-hover", canDropHere(dragEvent));
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void onDragExited(DragEvent dragEvent) {
|
||||
JFXUtil.setStyleClass(questContainer, "drop-hover", false);
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void onDragOver(DragEvent dragEvent) {
|
||||
Dragboard dragboard = dragEvent.getDragboard();
|
||||
if (dragboard.hasContent(DraggedProduct.FORMAT)) {
|
||||
DraggedProduct product = (DraggedProduct) dragboard.getContent(DraggedProduct.FORMAT);
|
||||
if (product instanceof DraggedProduct.Slot) {
|
||||
DraggedProduct.Slot slot = (DraggedProduct.Slot) product;
|
||||
if (WhatAStorage.getInstance().canDeliverProduct(getIndex(), slot.x, slot.y)) {
|
||||
dragEvent.acceptTransferModes(TransferMode.MOVE);
|
||||
dragEvent.consume();
|
||||
}
|
||||
} else if (product instanceof DraggedProduct.Quest) {
|
||||
DraggedProduct.Quest quest = (DraggedProduct.Quest) product;
|
||||
if ((WhatAStorage.getInstance().canQuestsResolve(quest.index, getIndex()))) {
|
||||
dragEvent.acceptTransferModes(TransferMode.MOVE);
|
||||
dragEvent.consume();
|
||||
}
|
||||
}
|
||||
if (canDropHere(dragEvent)) {
|
||||
dragEvent.acceptTransferModes(TransferMode.MOVE);
|
||||
dragEvent.consume();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,18 @@ public class StorageSlotController {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
private boolean canDropHere(DragEvent dragEvent) {
|
||||
if (dragEvent.getGestureSource() != slot && dragEvent.getDragboard().hasContent(DraggedProduct.FORMAT)) {
|
||||
DraggedProduct origin = (DraggedProduct) dragEvent.getDragboard().getContent(DraggedProduct.FORMAT);
|
||||
if (origin instanceof DraggedProduct.Quest) {
|
||||
return WhatAStorage.getInstance().canStoreProduct(((DraggedProduct.Quest) origin).index, x, y);
|
||||
} else if (origin instanceof DraggedProduct.Slot){
|
||||
return WhatAStorage.getInstance().canMoveProduct(((DraggedProduct.Slot) origin).x, ((DraggedProduct.Slot) origin).y, x, y);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void onDragDetected(MouseEvent event) {
|
||||
int index;
|
||||
@@ -54,19 +66,20 @@ public class StorageSlotController {
|
||||
event.consume();
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void onDragEntered(DragEvent dragEvent) {
|
||||
JFXUtil.setStyleClass(slot, "drop-hover", canDropHere(dragEvent));
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void onDragExited(DragEvent dragEvent) {
|
||||
JFXUtil.setStyleClass(slot, "drop-hover", false);
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void onDragOver(DragEvent dragEvent) {
|
||||
if (dragEvent.getGestureSource() != slot && dragEvent.getDragboard().hasContent(DraggedProduct.FORMAT)) {
|
||||
DraggedProduct origin = (DraggedProduct) dragEvent.getDragboard().getContent(DraggedProduct.FORMAT);
|
||||
if (origin instanceof DraggedProduct.Quest) {
|
||||
if (WhatAStorage.getInstance().canStoreProduct(((DraggedProduct.Quest) origin).index, x, y)) {
|
||||
dragEvent.acceptTransferModes(TransferMode.MOVE);
|
||||
}
|
||||
} else if (origin instanceof DraggedProduct.Slot){
|
||||
if (WhatAStorage.getInstance().canMoveProduct(((DraggedProduct.Slot) origin).x, ((DraggedProduct.Slot) origin).y, x, y)) {
|
||||
dragEvent.acceptTransferModes(TransferMode.MOVE);
|
||||
}
|
||||
}
|
||||
if (canDropHere(dragEvent)) {
|
||||
dragEvent.acceptTransferModes(TransferMode.MOVE);
|
||||
}
|
||||
dragEvent.consume();
|
||||
}
|
||||
|
||||
@@ -37,10 +37,16 @@ Label.green {
|
||||
.quest-container {
|
||||
-fx-border-width: 0 0 1 0;
|
||||
-fx-border-color: #aaaaaa;
|
||||
-fx-background-color: #eeeeee;
|
||||
-fx-background-color: #ffffff;
|
||||
}
|
||||
.quest-container.quest-out {
|
||||
-fx-background-color: #dddddd;
|
||||
}
|
||||
.quest-container.quest-out ImageView {
|
||||
-fx-blend-mode: hard-light;
|
||||
#-fx-blend-mode: lighten;
|
||||
}
|
||||
.quest-container.quest-out.drop-hover {
|
||||
-fx-background-color: #eeeeee;
|
||||
}
|
||||
.quest-reward {
|
||||
-fx-text-fill: #457229;
|
||||
@@ -76,8 +82,10 @@ Label.green {
|
||||
}
|
||||
|
||||
#storage-grid > * {
|
||||
-fx-border-color: #dddddd;
|
||||
-fx-border-width: 1;
|
||||
-fx-background-color: #ffffff;
|
||||
}
|
||||
#storage-grid > .drop-hover {
|
||||
-fx-background-color: #eeeeee;
|
||||
}
|
||||
.storage-slot-item-title {
|
||||
-fx-end-margin: 10;
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
|
||||
<GridPane fx:id="questContainer" maxHeight="-Infinity" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="250.0" onDragDetected="#onDragDetected" onDragDropped="#onDragDropped" onDragOver="#onDragOver" prefHeight="80.0" styleClass="quest-container" xmlns="http://javafx.com/javafx/9.0.1" xmlns:fx="http://javafx.com/fxml/1">
|
||||
<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">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="-Infinity" minWidth="-Infinity" prefWidth="80.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" />
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
|
||||
<VBox fx:id="slot" fillWidth="false" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" onDragDetected="#onDragDetected" onDragDropped="#onDragDropped" onDragOver="#onDragOver" GridPane.valignment="CENTER" xmlns="http://javafx.com/javafx/9.0.1" xmlns:fx="http://javafx.com/fxml/1">
|
||||
<VBox fx:id="slot" fillWidth="false" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" onDragDetected="#onDragDetected" onDragDropped="#onDragDropped" onDragEntered="#onDragEntered" onDragExited="#onDragExited" onDragOver="#onDragOver" GridPane.valignment="CENTER" xmlns="http://javafx.com/javafx/9.0.1" xmlns:fx="http://javafx.com/fxml/1">
|
||||
<children>
|
||||
<GridPane alignment="CENTER_LEFT" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308">
|
||||
<columnConstraints>
|
||||
@@ -36,7 +36,6 @@
|
||||
<Font name="System Bold" size="12.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Label fx:id="slot0Description" textOverrun="CLIP" />
|
||||
</children>
|
||||
</HBox>
|
||||
<HBox alignment="CENTER_LEFT" prefHeight="100.0" GridPane.columnIndex="3" GridPane.columnSpan="2147483647" GridPane.rowIndex="2">
|
||||
@@ -46,7 +45,6 @@
|
||||
<Font name="System Bold" size="12.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Label fx:id="slot1Description" />
|
||||
</children>
|
||||
</HBox>
|
||||
<HBox alignment="CENTER_LEFT" prefHeight="100.0" GridPane.columnIndex="2" GridPane.columnSpan="2147483647" GridPane.rowIndex="3">
|
||||
@@ -56,7 +54,6 @@
|
||||
<Font name="System Bold" size="12.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Label fx:id="slot2Description" />
|
||||
</children>
|
||||
</HBox>
|
||||
</children>
|
||||
|
||||
@@ -494,7 +494,7 @@
|
||||
inkscape:current-layer="layer4"
|
||||
inkscape:document-units="mm"
|
||||
inkscape:cy="240.10718"
|
||||
inkscape:cx="145.00338"
|
||||
inkscape:cx="85.404383"
|
||||
inkscape:zoom="0.98994949"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:pageopacity="0.0"
|
||||
@@ -522,7 +522,7 @@
|
||||
</metadata>
|
||||
<g
|
||||
transform="translate(-1.0191821,-12.666652)"
|
||||
style="display:inline;opacity:1"
|
||||
style="display:none;opacity:1"
|
||||
inkscape:label="lid_open"
|
||||
id="layer3"
|
||||
inkscape:groupmode="layer">
|
||||
|
||||
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 26 KiB |
Reference in New Issue
Block a user