2024-07-10 15:23:04 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using ColdMint.scripts.debug;
|
2024-07-07 15:10:25 +00:00
|
|
|
|
using ColdMint.scripts.utils;
|
|
|
|
|
using Godot;
|
|
|
|
|
|
|
|
|
|
namespace ColdMint.scripts.bubble;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>BubbleMarker</para>
|
|
|
|
|
/// <para>气泡位置标记</para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class BubbleMarker : Marker2D
|
|
|
|
|
{
|
2024-07-10 15:23:04 +00:00
|
|
|
|
private readonly Dictionary<int, Node> _bubbleDictionary = [];
|
2024-07-07 15:10:25 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>Add bubbles</para>
|
|
|
|
|
/// <para>添加气泡</para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
/// <param name="node"></param>
|
|
|
|
|
/// <returns></returns>
|
2024-07-10 15:23:04 +00:00
|
|
|
|
public bool AddBubble(int id, Node node)
|
2024-07-07 15:10:25 +00:00
|
|
|
|
{
|
|
|
|
|
if (!_bubbleDictionary.TryAdd(id, node))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-10 15:23:04 +00:00
|
|
|
|
NodeUtils.HideNode(node);
|
2024-07-07 15:10:25 +00:00
|
|
|
|
NodeUtils.CallDeferredAddChild(this, node);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>DisplayBubble</para>
|
|
|
|
|
/// <para>显示气泡</para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
///<para>Display specific nodes above the creature as "bubbles", for example, question bubbles when an enemy finds the player.</para>
|
|
|
|
|
///<para>在生物头顶显示特定的节点作为“气泡”,例如:当敌人发现玩家后将显示疑问气泡。</para>
|
|
|
|
|
/// </remarks>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
public void ShowBubble(int id)
|
|
|
|
|
{
|
|
|
|
|
if (!_bubbleDictionary.TryGetValue(id, out var value))
|
|
|
|
|
{
|
2024-07-15 12:37:30 +00:00
|
|
|
|
LogCat.LogErrorWithFormat("bubble_not_found", LogCat.LogLabel.BubbleMarker, LogCat.UploadFormat,id);
|
2024-07-07 15:10:25 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2024-07-10 15:23:04 +00:00
|
|
|
|
|
|
|
|
|
NodeUtils.ShowNode(value);
|
2024-07-07 15:10:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>Hidden bubble</para>
|
|
|
|
|
/// <para>隐藏气泡</para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void HideBubble(int id)
|
|
|
|
|
{
|
|
|
|
|
if (!_bubbleDictionary.TryGetValue(id, out var value))
|
|
|
|
|
{
|
2024-07-15 12:37:30 +00:00
|
|
|
|
LogCat.LogErrorWithFormat("bubble_not_found", LogCat.LogLabel.BubbleMarker, LogCat.UploadFormat,id);
|
2024-07-07 15:10:25 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2024-07-10 15:23:04 +00:00
|
|
|
|
|
|
|
|
|
NodeUtils.HideNode(value);
|
2024-07-07 15:10:25 +00:00
|
|
|
|
}
|
|
|
|
|
}
|