You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Babushka/scripts/CSharp/Common/Quest/QuestMessagePopup.cs

89 lines
2.1 KiB

using Godot;
using System;
using System.Net.Mime;
using Babushka.scripts.CSharp.Common.Quest;
public partial class QuestMessagePopup : Control
{
private Label Text => GetNode<Label>("Text");
private QuestResource? _currentlyShown;
private Tween? _activeTween = null;
[Export]
private Vector2 _showPosition;
[Export]
private Vector2 _hidePosition;
public override void _EnterTree()
{
QuestManager.Instance!.QuestsChanged += NewActiveQuest;
}
public override void _ExitTree()
{
QuestManager.Instance!.QuestsChanged -= NewActiveQuest;
}
private void NewActiveQuest()
{
GD.Print("NewActiveQuest");
var shownQuest = QuestManager.Instance!.GetFollowQuest();
if (_currentlyShown == shownQuest)
return;
if (_activeTween != null)
{
_activeTween.Kill();
}
if (shownQuest == null)
{
HideAnimate();
_currentlyShown = null;
return;
}
if (_currentlyShown == null)
{
Text.Text = shownQuest.title;
ShowAnimate();
_currentlyShown = shownQuest;
return;
}
// else (_currentlyShown != null)
_currentlyShown = shownQuest;
HideAnimate(() =>
{
Text.Text = shownQuest.title;
ShowAnimate();
});
}
private void HideAnimate(Action? then = null)
{
_activeTween = GetTree().CreateTween();
_activeTween.TweenProperty(this, "position", _hidePosition, 0.4)
.SetTrans(Tween.TransitionType.Cubic)
.SetEase(Tween.EaseType.Out);
if (then != null)
_activeTween.Finished += then;
}
private void ShowAnimate(Action? then = null)
{
_activeTween = GetTree().CreateTween();
_activeTween.TweenProperty(this, "position", _showPosition, 0.4)
.SetTrans(Tween.TransitionType.Cubic)
.SetEase(Tween.EaseType.Out);
if (then != null)
_activeTween.Finished += then;
}
}