+62
-10
lines changedFilter options
+62
-10
lines changed Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
9
9
import com.almasb.fxgl.app.GameApplication;
10
10
import com.almasb.fxgl.app.GameSettings;
11
11
import com.almasb.fxgl.notification.NotificationService;
12
+
import javafx.scene.Node;
12
13
import javafx.scene.input.KeyCode;
13
14
import javafx.scene.paint.Color;
14
15
@@ -37,6 +38,11 @@ public void pushNotification(String message) {
37
38
System.out.println("Notify: " + message);
38
39
}
39
40
41
+
@Override
42
+
public void pushNotification(String message, Node icon) {
43
+
44
+
}
45
+
40
46
@Override
41
47
public void setTextColor(Color textColor) {
42
48
Original file line number Diff line number Diff line change
@@ -13,17 +13,23 @@
13
13
import static com.almasb.fxgl.dsl.FXGL.*;
14
14
15
15
/**
16
+
* Shows how to use the notification service.
16
17
*
17
18
* @author Almas Baimagambetov (AlmasB) (almaslvl@gmail.com)
18
19
*/
19
20
public class NotificationSample extends GameApplication {
20
21
21
22
@Override
22
-
protected void initSettings(GameSettings settings) { }
23
+
protected void initSettings(GameSettings settings) {
24
+
settings.setWidth(1280);
25
+
settings.setHeight(720);
26
+
}
23
27
24
28
@Override
25
29
protected void initInput() {
26
-
onKeyDown(KeyCode.F, "Notify", () -> getNotificationService().pushNotification("Hello! " + random(1, 10000)));
30
+
onKeyDown(KeyCode.F, () -> getNotificationService().pushNotification("Hello! " + random(1, 10000)));
31
+
32
+
onKeyDown(KeyCode.G, () -> getNotificationService().pushNotification("Hello! " + random(1, 10000), texture("brick.png", 32, 32)));
27
33
}
28
34
29
35
public static void main(String[] args) {
Original file line number Diff line number Diff line change
@@ -6,9 +6,14 @@
6
6
7
7
package com.almasb.fxgl.notification
8
8
9
+
import javafx.scene.Node
10
+
9
11
/**
10
12
* Represents a notification message.
11
13
*
12
14
* @author Almas Baimagambetov (AlmasB) (almaslvl@gmail.com)
13
15
*/
14
-
class Notification internal constructor(val message: String)
16
+
class Notification internal constructor(
17
+
val message: String,
18
+
val icon: Node
19
+
)
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
7
7
package com.almasb.fxgl.notification
8
8
9
9
import com.almasb.fxgl.core.EngineService
10
+
import javafx.scene.Node
10
11
import javafx.scene.paint.Color
11
12
12
13
/**
@@ -30,4 +31,9 @@ abstract class NotificationService : EngineService() {
30
31
* Push a notification with given [message].
31
32
*/
32
33
abstract fun pushNotification(message: String)
34
+
35
+
/**
36
+
* Push a notification with given [message] and [icon].
37
+
*/
38
+
abstract fun pushNotification(message: String, icon: Node)
33
39
}
Original file line number Diff line number Diff line change
@@ -12,6 +12,8 @@ import com.almasb.fxgl.notification.Notification
12
12
import com.almasb.fxgl.notification.NotificationService
13
13
import com.almasb.fxgl.notification.view.NotificationView
14
14
import com.almasb.fxgl.scene.SceneService
15
+
import javafx.scene.Group
16
+
import javafx.scene.Node
15
17
import javafx.scene.paint.Color
16
18
import javafx.util.Duration
17
19
import java.util.*
@@ -63,7 +65,11 @@ class NotificationServiceProvider : NotificationService() {
63
65
* @param message the text to show
64
66
*/
65
67
override fun pushNotification(message: String) {
66
-
val notification = Notification(message)
68
+
pushNotification(message, Group())
69
+
}
70
+
71
+
override fun pushNotification(message: String, icon: Node) {
72
+
val notification = Notification(message, icon)
67
73
68
74
queue.add(notification)
69
75
Original file line number Diff line number Diff line change
@@ -10,6 +10,8 @@ import com.almasb.fxgl.animation.Animation
10
10
import com.almasb.fxgl.animation.AnimationBuilder
11
11
import com.almasb.fxgl.notification.Notification
12
12
import javafx.geometry.Point2D
13
+
import javafx.scene.Group
14
+
import javafx.scene.Node
13
15
import javafx.scene.shape.Circle
14
16
import javafx.scene.shape.Rectangle
15
17
import javafx.scene.text.Font
@@ -28,6 +30,8 @@ class XboxNotificationView : NotificationView() {
28
30
*/
29
31
private val circle = Circle(30.0, 30.0, 30.0)
30
32
33
+
private val iconViewHolder = Group()
34
+
31
35
private val bg = Rectangle(400.0, 57.0)
32
36
private val bgClip = Rectangle(bg.width + 15.0, bg.height)
33
37
@@ -70,13 +74,13 @@ class XboxNotificationView : NotificationView() {
70
74
translateX = appWidth / 2 - bg.width / 2 + 200
71
75
translateY = 50.0
72
76
73
-
centerTextX(text1, 65.0, 395.0)
77
+
centerNodeX(text1, 65.0, 395.0)
74
78
75
79
scaleX = 0.0
76
80
scaleY = 0.0
77
81
78
82
// make sure we only have circle for proper centering during the first animation
79
-
children.setAll(circle)
83
+
children.setAll(circle, iconViewHolder)
80
84
81
85
// move the whole view to left
82
86
translateThis = AnimationBuilder()
@@ -125,13 +129,24 @@ class XboxNotificationView : NotificationView() {
125
129
private var animText2: Animation<*>? = null
126
130
private var animText1: Animation<*>? = null
127
131
132
+
private var iconViewFadeIn: Animation<*>? = null
133
+
128
134
override fun push(notification: Notification) {
129
135
text2.text = notification.message
130
136
text2.translateY = -35.0
131
137
138
+
iconViewHolder.children.setAll(notification.icon)
139
+
centerNodeX(iconViewHolder, 0.0, 60.0)
140
+
centerNodeY(iconViewHolder, 0.0, 60.0)
141
+
142
+
iconViewFadeIn = AnimationBuilder()
143
+
.duration(Duration.seconds(1.33))
144
+
.fadeIn(iconViewHolder)
145
+
.build()
146
+
132
147
children.add(text2)
133
148
134
-
centerTextX(text2, 65.0, 395.0)
149
+
centerNodeX(text2, 65.0, 395.0)
135
150
136
151
// move text 2 to replace text 1
137
152
animText2 = AnimationBuilder()
@@ -159,6 +174,7 @@ class XboxNotificationView : NotificationView() {
159
174
160
175
animText2!!.start()
161
176
animText1!!.start()
177
+
iconViewFadeIn!!.start()
162
178
}
163
179
164
180
override fun playOutAnimation() {
@@ -169,9 +185,10 @@ class XboxNotificationView : NotificationView() {
169
185
170
186
translateBG?.onFinished = Runnable {
171
187
172
-
children.setAll(circle)
188
+
children.setAll(circle, iconViewHolder)
173
189
174
190
scale = AnimationBuilder()
191
+
.onFinished { iconViewHolder.children.clear() }
175
192
.duration(Duration.seconds(0.3))
176
193
.scale(this)
177
194
.from(Point2D(1.0, 1.0))
@@ -192,9 +209,15 @@ class XboxNotificationView : NotificationView() {
192
209
193
210
animText2?.onUpdate(tpf)
194
211
animText1?.onUpdate(tpf)
212
+
213
+
iconViewFadeIn?.onUpdate(tpf)
214
+
}
215
+
216
+
private fun centerNodeX(node: Node, minX: Double, maxX: Double) {
217
+
node.translateX = (minX + maxX) / 2 - node.layoutBounds.width / 2
195
218
}
196
219
197
-
private fun centerTextX(text: Text, minX: Double, maxX: Double) {
198
-
text.translateX = (minX + maxX) / 2 - text.layoutBounds.width / 2
220
+
private fun centerNodeY(node: Node, minY: Double, maxY: Double) {
221
+
node.translateY = (minY + maxY) / 2 - node.layoutBounds.height / 2
199
222
}
200
223
}
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4