Files
2024-10-16 00:03:41 +08:00

119 lines
3.3 KiB
C#

using Framework.Save;
using Framework.Timer;
using Framework.UI;
using Framework.Utils.SingletonTemplate;
using IcecreamView;
using Views;
namespace System.Guide
{
public class GuideMgr : MgrBase<GuideMgr>
{
protected override void OnCreateMge ()
{
}
private string _curGuideTable;
private GuideNode _curGuideNode;
private Action _callback;
public GuideNode CurGuideNode => this._curGuideNode;
public bool HasGuiding (string guideTable) => string.Equals (guideTable , this._curGuideTable);
public bool HasGuiding() => !string.IsNullOrEmpty(this._curGuideTable);
public bool HasGuide (string guideTable)
{
return Account.Instance.AccountSystemData.CompleteGuideTable.Contains (guideTable);
}
public void RemoveGuide (string guideTable)
{
Account.Instance.AccountSystemData.CompleteGuideTable.Remove (guideTable);
Account.Instance.Save(SaveData.System);
}
public void PlayGuide (GuideNode node , string guideTable , Action callback = null)
{
if (HasGuide(guideTable))
{
return;
}
this._callback = callback;
this._curGuideTable = guideTable;
node.StartNode ();
}
public void StopGuide (string guideTable)
{
if (!string.IsNullOrEmpty (guideTable) && HasGuide(guideTable))
{
return;
}
ResetData ();
}
public void StopGuide ()
{
if (UIManager.Instance.IsOpenedView (UIPanel.GuidePanel))
{
UIManager.Instance.CloseView (UIPanel.GuidePanel);
}
ResetData ();
}
/// <summary>
/// 直接完成当前任务引导,不管是否完成了所有节点
/// </summary>
public void CompleteGuide ()
{
Account.Instance.AccountSystemData.CompleteGuideTable.Add (this._curGuideTable);
Account.Instance.Save(SaveData.System);
var callback = this._callback;
ResetData ();
callback?.Invoke ();
}
private void ResetData ()
{
if (!ReferenceEquals (this._curGuideNode , default))
{
this._curGuideNode.OnGuidedLogic ();
}
this._curGuideNode = null;
this._callback = null;
this._curGuideTable = null;
}
internal void ShowGuideNode(GuideNode node)
{
this._curGuideNode = node;
this._curGuideNode.OnGuidingLogic ();
}
internal void NextNode (GuideNode node)
{
if (!ReferenceEquals (this._curGuideNode , default))
{
this._curGuideNode.OnGuidedLogic ();
}
if (node.nextNode != null)
{
node.nextNode.StartNode ();
}
else
{
CompleteGuide ();
}
}
public void NextCurNode ()
{
if (!ReferenceEquals (this._curGuideNode , default))
{
this._curGuideNode.NextNode ();
}
}
}
}