Made quest usable
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user