Made quest usable
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using Babushka.scripts.CSharp.Common.Quest;
|
||||
|
||||
public partial class PopUpPostIt : Control
|
||||
{
|
||||
private Label Text => GetNode<Label>("Text");
|
||||
|
||||
private AnimationPlayer Animation => GetNode<AnimationPlayer>("AnimationPlayer");
|
||||
|
||||
QuestManager QM => QuestManager.Instance!;
|
||||
public override void _EnterTree()
|
||||
{
|
||||
QM.QuestBecomesActive += NewQuestPostIt;
|
||||
}
|
||||
|
||||
private void NewQuestPostIt(QuestResource questResource)
|
||||
{
|
||||
Text.Text = questResource.title;
|
||||
Animation.Play("NewPostit");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://byar6yqrlph6k
|
||||
@@ -12,7 +12,17 @@ public partial class QuestListItemUi : Control
|
||||
public void UpdateButton(QuestResource questResource)
|
||||
{
|
||||
_questResource = questResource;
|
||||
ShowName(questResource.title);
|
||||
var questStatus = QuestManager.Instance!.GetQuestStatus(_questResource);
|
||||
var name = questResource.title;
|
||||
|
||||
name += questStatus.status switch
|
||||
{
|
||||
QuestStatus.Status.Done => " \u2713", // Check
|
||||
QuestStatus.Status.Canceled => " \u2715", // X
|
||||
_ => ""
|
||||
};
|
||||
|
||||
ShowName(name);
|
||||
TitleButton.Pressed += ClickedTitleButton;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,12 @@ public partial class QuestListUi : VBoxContainer
|
||||
public override void _EnterTree()
|
||||
{
|
||||
UpdateList();
|
||||
QuestManager.Instance!.QuestsChanged += UpdateList;
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
QuestManager.Instance!.QuestsChanged -= UpdateList;
|
||||
}
|
||||
|
||||
public override void _Ready()
|
||||
@@ -27,8 +33,8 @@ public partial class QuestListUi : VBoxContainer
|
||||
}
|
||||
|
||||
// recreate children
|
||||
var activeQuests = QuestManager.Instance.GetActiveQuests();
|
||||
|
||||
var activeQuests = QuestManager.Instance.GetVisibleQuests();
|
||||
|
||||
foreach (var questPair in activeQuests)
|
||||
{
|
||||
var questResource = questPair.Key;
|
||||
|
||||
@@ -7,15 +7,21 @@ public partial class QuestLog : Control
|
||||
{
|
||||
[Signal]
|
||||
public delegate void DetailQuestChangedEventHandler(QuestLog questLog);
|
||||
|
||||
|
||||
public QuestResource? currentDetailQuest
|
||||
{
|
||||
get => _currentDetailQuestBacking;
|
||||
get => QuestManager.Instance!.GetFollowQuest();
|
||||
set
|
||||
{
|
||||
_currentDetailQuestBacking = value;
|
||||
QuestManager.Instance!.SetFollowQuest(value); // TODO: fix setup
|
||||
EmitSignalDetailQuestChanged(this);
|
||||
}
|
||||
}
|
||||
private QuestResource? _currentDetailQuestBacking;
|
||||
|
||||
public override void _EnterTree()
|
||||
{
|
||||
QuestManager.Instance!.QuestsChanged += () => EmitSignalDetailQuestChanged(this);
|
||||
}
|
||||
|
||||
//private QuestResource? _currentDetailQuestBacking;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,13 @@ namespace Babushka.scripts.CSharp.Common.Quest;
|
||||
using QuestPair = KeyValuePair<QuestResource, QuestStatus>;
|
||||
public partial class QuestManager : Node
|
||||
{
|
||||
public static QuestManager Instance { get; private set; }
|
||||
public static QuestManager? Instance { get; private set; }
|
||||
|
||||
[Signal]
|
||||
public delegate void QuestBecomesActiveEventHandler(QuestResource questResource);
|
||||
|
||||
[Signal]
|
||||
public delegate void QuestsChangedEventHandler();
|
||||
|
||||
public override void _EnterTree()
|
||||
{
|
||||
@@ -16,6 +22,8 @@ public partial class QuestManager : Node
|
||||
}
|
||||
|
||||
private Godot.Collections.Dictionary<QuestResource, QuestStatus> _questStatus = new();
|
||||
|
||||
private QuestResource? _followQuest;
|
||||
|
||||
|
||||
public void ChangeQuestStatus(QuestResource questResource, QuestStatus.Status newStatus)
|
||||
@@ -27,6 +35,13 @@ public partial class QuestManager : Node
|
||||
}
|
||||
|
||||
value.status = newStatus;
|
||||
|
||||
EmitSignalQuestsChanged();
|
||||
|
||||
if (newStatus == QuestStatus.Status.Active)
|
||||
{
|
||||
EmitSignalQuestBecomesActive(questResource);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<QuestPair> GetVisibleQuests()
|
||||
@@ -38,4 +53,24 @@ public partial class QuestManager : Node
|
||||
{
|
||||
return _questStatus.Where(qs => qs.Value.status == QuestStatus.Status.Active);
|
||||
}
|
||||
public QuestStatus GetQuestStatus(QuestResource questResource)
|
||||
{
|
||||
if (_questStatus.TryGetValue(questResource, out var status))
|
||||
return status;
|
||||
|
||||
status = new QuestStatus();
|
||||
_questStatus.Add(questResource, status);
|
||||
return status;
|
||||
}
|
||||
|
||||
public QuestResource? GetFollowQuest()
|
||||
{
|
||||
return _followQuest;
|
||||
}
|
||||
|
||||
public void SetFollowQuest(QuestResource? questResource)
|
||||
{
|
||||
_followQuest = questResource;
|
||||
EmitSignalQuestsChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://7wwid23tc8as
|
||||
@@ -5,13 +5,29 @@ using Babushka.scripts.CSharp.Common.Quest;
|
||||
public partial class QuestTrigger : Node
|
||||
{
|
||||
[Export]
|
||||
public QuestResource questResource;
|
||||
public QuestResource? questResource;
|
||||
|
||||
[Export]
|
||||
public QuestStatus.Status toStatus;
|
||||
|
||||
[Export]
|
||||
private bool makeCurrent = false;
|
||||
|
||||
public void Trigger()
|
||||
{
|
||||
GD.Print("trigger");
|
||||
|
||||
if(questResource== null)
|
||||
throw new Exception("QuestResource is not set on QuestTrigger node.");
|
||||
|
||||
if(QuestManager.Instance == null)
|
||||
throw new Exception("QuestManager instance is not available. Make sure it is initialized before calling Trigger.");
|
||||
|
||||
QuestManager.Instance.ChangeQuestStatus(questResource, toStatus);
|
||||
|
||||
if (makeCurrent)
|
||||
{
|
||||
QuestManager.Instance.SetFollowQuest(questResource);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user