57 lines
2.0 KiB
C#
57 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using CSNetwork.GPDataType;
|
|
using UnityEngine;
|
|
|
|
namespace BrewMonster.Scripts.ChatUI
|
|
{
|
|
[Serializable]
|
|
public struct ChannelIconMapping
|
|
{
|
|
public ChatChannel channel;
|
|
public string iconName;
|
|
public Sprite icon;
|
|
public string prefix;
|
|
}
|
|
|
|
[CreateAssetMenu(fileName = "ChatSystemSO", menuName = "Scriptable Objects/Chat/ChatSystemSO")]
|
|
public class ChatSystemSO : ScriptableObject
|
|
{
|
|
[Header("Button States")]
|
|
public Sprite selectedSprite;
|
|
public Sprite unselectedSprite;
|
|
|
|
[Header("Channel Icons")]
|
|
public List<ChannelIconMapping> channelIcons = new List<ChannelIconMapping>();
|
|
|
|
[Header("Message Limits")]
|
|
[Tooltip("Giới hạn số ký tự thô cho một tin nhắn. <= 0 nghĩa là không giới hạn. " +
|
|
"TMP tag như <sprite ...> cũng được tính theo đúng số ký tự của tag.")]
|
|
public int maxRawCharactersPerMessage = 60;
|
|
|
|
/// <summary>
|
|
/// Đếm số ký tự thô (raw) của nội dung đang nhập.
|
|
/// Count raw characters from current input text.
|
|
/// </summary>
|
|
public int CountRawCharacters(string rawText)
|
|
{
|
|
if (string.IsNullOrEmpty(rawText))
|
|
return 0;
|
|
return rawText.Length;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Kiểm tra có thể dùng thêm reserveChars mà vẫn không vượt giới hạn ký tự thô.
|
|
/// Check whether reserveChars can be added without exceeding raw character limit.
|
|
/// </summary>
|
|
public bool CanUseRawCharacters(string rawText, int reserveChars, out int usedChars, out int limitChars)
|
|
{
|
|
limitChars = maxRawCharactersPerMessage;
|
|
usedChars = CountRawCharacters(rawText) + Mathf.Max(0, reserveChars);
|
|
if (limitChars <= 0)
|
|
return true;
|
|
return usedChars <= limitChars;
|
|
}
|
|
}
|
|
}
|