Permalink
Browse files

finished quests can now be closed from UI

  • Loading branch information...
1 parent 62f68bd commit 5d8430ea73981c62ea224e5cc97efa3aa3e7d5c1 @AlmasB committed Dec 24, 2016
@@ -53,6 +53,7 @@
import javafx.util.Duration;
import java.util.Arrays;
+import java.util.List;
/**
* @author Almas Baimagambetov (almaslvl@gmail.com)
@@ -144,6 +145,7 @@ protected void initAssets() {}
protected void initGame() {
shotArrows = new SimpleIntegerProperty(0);
jumps = new SimpleIntegerProperty(0);
+ enemiesKilled = new SimpleIntegerProperty(0);
TextLevelParser parser = new TextLevelParser(factory);
Level level = parser.parse("towerfall_level.txt");
@@ -181,6 +183,8 @@ protected void onCollisionBegin(Entity arrow, Entity enemy) {
arrow.removeFromWorld();
enemy.removeFromWorld();
+ enemiesKilled.set(enemiesKilled.get() + 1);
+
getGameWorld().addEntity(factory.newEnemy(27, 6));
}
});
@@ -190,14 +194,19 @@ protected void onCollisionBegin(Entity arrow, Entity enemy) {
private IntegerProperty shotArrows;
private IntegerProperty jumps;
+ private IntegerProperty enemiesKilled;
@Override
protected void initUI() {
panel = new InGamePanel();
-
getGameScene().addUINode(panel);
- QuestPane questPane = new QuestPane(350, 450,
+ QuestPane questPane = new QuestPane(350, 450);
+ QuestWindow window = new QuestWindow(questPane);
+
+ getGameScene().addUINode(window);
+
+ List<Quest> quests = Arrays.asList(
new Quest("Test Quest", Arrays.asList(
new QuestObjective("Shoot Arrows", shotArrows, 15),
new QuestObjective("Jump", jumps)
@@ -208,7 +217,7 @@ protected void initUI() {
)),
new Quest("Test Quest 2", Arrays.asList(
- new QuestObjective("Shoot Arrows", shotArrows, 25)
+ new QuestObjective("Kill an enemy", enemiesKilled)
)),
new Quest("Test Quest 2", Arrays.asList(
@@ -220,15 +229,7 @@ protected void initUI() {
))
);
-// InGameWindow window = new InGameWindow("Quests", InGameWindow.WindowDecor.MINIMIZE);
-//// window.prefWidthProperty().bind(questPane.widthProperty());
-//// window.prefHeightProperty().bind(questPane.heightProperty());
-// window.setContentPane(questPane);
-// window.setResizableWindow(true);
-
- QuestWindow window = new QuestWindow(questPane);
-
- getGameScene().addUINode(window);
+ quests.forEach(getQuestManager()::addQuest);
}
@Override
@@ -27,12 +27,17 @@
package com.almasb.fxgl.gameplay.rpg.quest
import com.almasb.fxgl.app.FXGL
+import com.almasb.fxgl.devtools.DeveloperTools
+import javafx.animation.ScaleTransition
import javafx.geometry.Pos
+import javafx.scene.control.Button
import javafx.scene.control.TitledPane
import javafx.scene.layout.HBox
import javafx.scene.layout.Priority
import javafx.scene.layout.VBox
import javafx.scene.paint.Color
+import javafx.scene.text.Font
+import javafx.util.Duration
/**
* View for a quest in the form of a titled pane.
@@ -54,10 +59,29 @@ class QuestView(val quest: Quest, width: Double) : TitledPane() {
HBox.setHgrow(hbox, Priority.ALWAYS)
- val hboxRoot = HBox(10.0, FXGL.getUIFactory().newText(quest.name, Color.BLACK, 18.0), hbox)
+ val closeBtn = Button("X")
+ closeBtn.font = Font.font(11.0)
+ closeBtn.setPrefSize(15.0, 9.0)
+ closeBtn.visibleProperty().bind(mainCheckBox.stateProperty().isNotEqualTo(QuestState.ACTIVE))
+ closeBtn.setOnAction { close() }
+
+ VBox.setVgrow(closeBtn, Priority.NEVER)
+
+ val hboxRoot = HBox(10.0, FXGL.getUIFactory().newText(quest.name, Color.BLACK, 18.0), closeBtn, hbox)
hboxRoot.prefWidth = width - mainCheckBox.width*3 + 2
content = vbox
graphic = hboxRoot
}
+
+ private fun close() {
+ with(ScaleTransition(Duration.seconds(0.33), this)) {
+ fromX = 1.0
+ toX = 0.0
+ fromY = 1.0
+ toY = 0.0
+ setOnFinished { DeveloperTools.removeFromParent(this@QuestView) }
+ play()
+ }
+ }
}

0 comments on commit 5d8430e

Please sign in to comment.