Notifications
Toast berichten, achievement popups, en alerts.
Notification Types
| Type | Gebruik | Duur |
|---|---|---|
| Toast | Korte info berichten | 3 sec |
| Achievement | Achievement unlocked | 5 sec |
| Quest | Quest updates | 4 sec |
| Level Up | Level omhoog | 5 sec |
| Error | Foutmeldingen | 4 sec |
Toast Notifications
┌──────────────────────────────────────┐
│ ✓ Item toegevoegd aan inventory! │
└──────────────────────────────────────┘
Notification Manager
# notification_manager.gd
extends CanvasLayer
const MAX_VISIBLE = 5
const TOAST_SCENE = preload("res://scenes/ui/toast.tscn")
@onready var container: VBoxContainer = $NotificationContainer
var _queue: Array = []
func toast(message: String, type: String = "info") -> void:
_queue.append({"message": message, "type": type, "kind": "toast"})
_process_queue()
func _process_queue() -> void:
while _queue.size() > 0 and container.get_child_count() < MAX_VISIBLE:
var data = _queue.pop_front()
_show_notification(data)
func _show_notification(data: Dictionary) -> void:
var toast = TOAST_SCENE.instantiate()
toast.setup(data.message, data.type)
container.add_child(toast)
# Animation
toast.modulate.a = 0
toast.position.x = 50
var tween = create_tween()
tween.set_parallel(true)
tween.tween_property(toast, "modulate:a", 1.0, 0.3)
tween.tween_property(toast, "position:x", 0, 0.3).set_ease(Tween.EASE_OUT)
# Auto remove
await get_tree().create_timer(3.0).timeout
_remove_notification(toast)
func _remove_notification(toast: Control) -> void:
var tween = create_tween()
tween.tween_property(toast, "modulate:a", 0.0, 0.3)
tween.tween_callback(func():
toast.queue_free()
_process_queue()
)
Toast Component
# toast.gd
extends PanelContainer
@onready var icon: TextureRect = $HBox/Icon
@onready var message_label: Label = $HBox/Message
const ICONS = {
"info": preload("res://assets/ui/icons/info.png"),
"success": preload("res://assets/ui/icons/check.png"),
"warning": preload("res://assets/ui/icons/warning.png"),
"error": preload("res://assets/ui/icons/error.png"),
}
const COLORS = {
"info": Color("#4a90d9"),
"success": Color("#5cb85c"),
"warning": Color("#f0ad4e"),
"error": Color("#d9534f"),
}
func setup(message: String, type: String) -> void:
message_label.text = message
icon.texture = ICONS.get(type, ICONS.info)
icon.modulate = COLORS.get(type, COLORS.info)
Achievement Popup
┌─────────────────────────────────────────────────────────────┐
│ │
│ 🏆 ACHIEVEMENT UNLOCKED! │
│ │
│ ┌─────┐ │
│ │ 🌻 │ Eerste Oogst │
│ └─────┘ "Oogst je eerste gewas" │
│ │
│ +50 XP • +10 Eikels │
│ │
└─────────────────────────────────────────────────────────────┘
Achievement Popup Script
# achievement_popup.gd
extends Control
@onready var icon: TextureRect = $Panel/Icon
@onready var title_label: Label = $Panel/Title
@onready var description_label: Label = $Panel/Description
@onready var rewards_label: Label = $Panel/Rewards
func show_achievement(achievement: Dictionary) -> void:
title_label.text = achievement.title
description_label.text = achievement.description
icon.texture = load(achievement.icon_path)
# Format rewards
var rewards = []
if achievement.reward_xp > 0:
rewards.append("+%d XP" % achievement.reward_xp)
if achievement.reward_eikels > 0:
rewards.append("+%d Eikels" % achievement.reward_eikels)
rewards_label.text = " • ".join(rewards)
# Animate in
_animate_in()
# Auto hide
await get_tree().create_timer(5.0).timeout
_animate_out()
func _animate_in() -> void:
visible = true
modulate.a = 0
scale = Vector2(0.8, 0.8)
var tween = create_tween()
tween.set_parallel(true)
tween.tween_property(self, "modulate:a", 1.0, 0.4)
tween.tween_property(self, "scale", Vector2.ONE, 0.4).set_ease(Tween.EASE_OUT).set_trans(Tween.TRANS_BACK)
# Particles or effects
_play_unlock_effect()
func _animate_out() -> void:
var tween = create_tween()
tween.tween_property(self, "modulate:a", 0.0, 0.3)
tween.tween_callback(func(): visible = false)
Quest Notification
┌────────────────────────────────────────┐
│ 📜 QUEST VOLTOOID │
│ "Dagelijkse Oogst" │
│ +10 Eikels, +15 XP │
└────────────────────────────────────────┘
Quest Update Types
func show_quest_update(quest: Dictionary, update_type: String) -> void:
var notification = QUEST_NOTIFICATION.instantiate()
match update_type:
"started":
notification.setup(
"NIEUWE QUEST",
quest.title,
"📜",
Color("#4a90d9")
)
"progress":
notification.setup(
"QUEST VOORTGANG",
quest.title + " - " + _format_progress(quest),
"📋",
Color("#f0ad4e")
)
"completed":
notification.setup(
"QUEST VOLTOOID",
quest.title + "\n" + _format_rewards(quest),
"✨",
Color("#5cb85c")
)
"failed":
notification.setup(
"QUEST MISLUKT",
quest.title,
"❌",
Color("#d9534f")
)
add_child(notification)
Level Up Notification
┌─────────────────────────────────────────────────────────────┐
│ │
│ ⭐ LEVEL UP! ⭐ │
│ │
│ Level 10 │
│ │
│ Nieuwe unlocks: │
│ • Gouden Schep │
│ • Recept: Appeltaart │
│ │
└─────────────────────────────────────────────────────────────┘
Level Up Script
# level_up_popup.gd
extends Control
func show_level_up(new_level: int, unlocks: Array) -> void:
$Panel/LevelLabel.text = "Level %d" % new_level
# Show unlocks
var unlock_container = $Panel/Unlocks
for child in unlock_container.get_children():
child.queue_free()
for unlock in unlocks:
var label = Label.new()
label.text = "• " + unlock.name
unlock_container.add_child(label)
_animate_in()
# Play fanfare
AudioManager.play_sound("level_up")
await get_tree().create_timer(5.0).timeout
_animate_out()
Screen Flash
# Voor belangrijke momenten
func flash_screen(color: Color = Color.WHITE, duration: float = 0.3) -> void:
var flash = ColorRect.new()
flash.color = color
flash.anchor_right = 1
flash.anchor_bottom = 1
add_child(flash)
var tween = create_tween()
tween.tween_property(flash, "modulate:a", 0.0, duration)
tween.tween_callback(flash.queue_free)
Usage Examples
# Ergens in game code
# Simple toast
NotificationManager.toast("Honing toegevoegd!", "success")
# Achievement
NotificationManager.show_achievement({
"title": "Eerste Oogst",
"description": "Oogst je eerste gewas",
"icon_path": "res://assets/achievements/first_harvest.png",
"reward_xp": 50,
"reward_eikels": 10
})
# Quest update
NotificationManager.show_quest_update(quest_data, "completed")
# Level up
NotificationManager.show_level_up(10, [
{"name": "Gouden Schep"},
{"name": "Recept: Appeltaart"}
])