This commit is contained in:
2026-10-10 08:59:44 +08:00
parent 2bbabb70b4
commit b5881a6cc4
7 changed files with 130 additions and 39 deletions
@@ -71,6 +71,9 @@ public class UIHome_BY_BackPackPanel : SubUIBase
// 大喇叭
if (DaLaBaPanel != null)
DaLaBaPanel.SetActive(false);
// 大喇叭正文限长:后端整条广播≤20字,标识占1字,输入框直接限制19字
if (tMPText_DaLaBaLabel != null)
tMPText_DaLaBaLabel.characterLimit = APIRequestList.BroadcastMaxContentLength;
if (btn_FaSong != null)
{
// ⭐ 先清再绑:防止面板重复 Show 叠加监听器(点一次发 N 次 = 多扣 N 个大喇叭)
@@ -170,16 +173,20 @@ public class UIHome_BY_BackPackPanel : SubUIBase
UIManager.Instance.ShowBoardError("请输入广播内容");
return;
}
// ⭐ 后端整条广播限制20字,标识字符占1字,正文最多19字
if (content.Length > APIRequestList.BroadcastMaxContentLength)
{
UIManager.Instance.ShowBoardError($"广播内容不能超过{APIRequestList.BroadcastMaxContentLength}个字");
return;
}
_isSendingFaSong = true;
// ⭐ 超时兜底:后端拒绝(字数超限等)时没有回调,靠超时复位防重入标志
if (_faSongTimeoutRoutine != null) StopCoroutine(_faSongTimeoutRoutine);
_faSongTimeoutRoutine = StartCoroutine(ResetFaSongFlagAfterTimeout());
// ⭐ 显示格式:"<sprite index=0>【小*鱼】:内容"(前面加喇叭图标 TMP 标签;名字打码与游戏内大喇叭同格式)
var userName = GameManager.Instance.user?.BaseInfo?.userName;
if (string.IsNullOrEmpty(userName)) userName = "玩家";
APIRequestList.SendBroadcast($"<sprite index=0>【{MaskBroadcastName(userName)}】:{content}", (result) =>
// ⭐ 只发"标识字符+正文":喇叭图标与打码昵称由接收端(LoginBroadcast)统一补上
APIRequestList.SendBroadcast(APIRequestList.BroadcastMarker + content, (result) =>
{
// 成功:停掉超时协程并复位标志
if (_faSongTimeoutRoutine != null)
@@ -207,18 +214,6 @@ public class UIHome_BY_BackPackPanel : SubUIBase
_faSongTimeoutRoutine = null;
}
/// <summary>
/// 玩家名打码(广播格式):保留首尾字符、中间一个 *("小金鱼"→"小*鱼")。
/// 与 GameMainPanel_FishBase.MaskBroadcastName 同格式(背包面板独立副本)。
/// </summary>
private static string MaskBroadcastName(string name)
{
if (string.IsNullOrEmpty(name)) return name;
name = name.Trim();
if (name.Length <= 1) return name;
return name[0] + "*" + name[name.Length - 1];
}
private void OnClickConfirmChangeName()
{
string newName = tMPText_NewName?.text?.Trim();