add limit char for chat

This commit is contained in:
CuongNV
2026-04-09 16:33:52 +07:00
parent 87e14a1d8a
commit b1fc46b50c
11 changed files with 84 additions and 7 deletions
@@ -23,5 +23,34 @@ namespace BrewMonster.Scripts.ChatUI
[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;
}
}
}