Traveller/scripts/bubble/BubbleMarker.cs
Cold-Mint adee87429e
Add bubbles and scout areas.
加入气泡和侦察区域。
2024-07-07 23:10:25 +08:00

65 lines
1.7 KiB
C#

using System;
using System.Collections.Generic;
using ColdMint.scripts.utils;
using Godot;
namespace ColdMint.scripts.bubble;
/// <summary>
/// <para>BubbleMarker</para>
/// <para>气泡位置标记</para>
/// </summary>
public partial class BubbleMarker : Marker2D
{
private readonly Dictionary<int, Node2D> _bubbleDictionary = [];
/// <summary>
/// <para>Add bubbles</para>
/// <para>添加气泡</para>
/// </summary>
/// <param name="id"></param>
/// <param name="node"></param>
/// <returns></returns>
public bool AddBubble(int id, Node2D node)
{
if (!_bubbleDictionary.TryAdd(id, node))
{
return false;
}
node.Hide();
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))
{
return;
}
value.Show();
}
/// <summary>
/// <para>Hidden bubble</para>
/// <para>隐藏气泡</para>
/// </summary>
public void HideBubble(int id)
{
if (!_bubbleDictionary.TryGetValue(id, out var value))
{
return;
}
value.Hide();
}
}