11var duration_seconds := 2.5
12var position := Vector2(18, 18)
14var _active_notifications := []
17func configure(layout, settings = null, options:Dictionary = {}) -> void:
18 layout_manager = layout
19 settings_manager = settings
20 duration_seconds = float(options.get(
"duration", duration_seconds))
21 position = options.get(
"position", position)
25func dispose() -> void:
29 for notification
in _active_notifications:
30 if is_instance_valid(notification):
31 notification.queue_free()
32 _active_notifications.clear()
36func show(parent:Node, stats_manager, ids:Array) -> void:
37 if parent == null
or stats_manager == null
or ids.is_empty():
39 var achievements = stats_manager.get_achievements()
41 queue.append(achievements.get(id, {
"id": id}))
43 _process_queue(parent)
46func _process_queue(parent:Node) -> void:
47 if parent == null
or layout_manager == null:
53 while run_id == _run_id
and not queue.is_empty()
and is_instance_valid(parent):
54 var achievement = queue.pop_front()
55 var notification = layout_manager.create_achievement_notification(achievement)
56 notification.position = position
57 parent.add_child(notification)
58 _active_notifications.append(notification)
59 layout_manager.apply_theme(notification, str(_settings_value(
"theme",
"dark")))
60 if settings_manager != null
and settings_manager.has_method(
"apply_text_size"):
61 settings_manager.apply_text_size(notification)
62 var tree := parent.get_tree()
65 await tree.create_timer(duration_seconds).timeout
68 if is_instance_valid(notification):
69 notification.queue_free()
70 _active_notifications.erase(notification)
74func _settings_value(key:String, default_value):
75 if settings_manager != null
and settings_manager.has_method(
"get_settings"):
76 return settings_manager.get_settings().get(key, default_value)