fix: polish lobby chat and joystick

This commit is contained in:
ud18010
2026-07-28 17:23:11 +08:00
parent 48aed26725
commit 053a95b4fb
11 changed files with 176 additions and 9 deletions
@@ -0,0 +1,88 @@
using System;
using System.Reflection;
using NUnit.Framework;
using TMPro;
using UnityEditor;
using UnityEngine;
using XGame;
using XWorld.Framework.Protocol;
public sealed class WorldChatModuleTests
{
private GameObject view;
private GameObject host;
[TearDown]
public void TearDown()
{
if (view != null)
{
UnityEngine.Object.DestroyImmediate(view);
}
if (host != null)
{
UnityEngine.Object.DestroyImmediate(host);
}
}
[Test]
public void EndEditingInput_SubmitsTrimmedWorldChat()
{
WorldChatModule module = CreateBoundModule();
TMP_InputField input = view.transform.FindTransform("InputHitArea").GetComponent<TMP_InputField>();
string sent = null;
module.OnSendWorldChat = text => sent = text;
input.text = " hello world ";
input.onEndEdit.Invoke(input.text);
Assert.That(sent, Is.EqualTo("hello world"));
Assert.That(input.text, Is.Empty);
}
[Test]
public void ReceivedMessage_UpdatesCollapsedPreview()
{
WorldChatModule module = CreateBoundModule();
TMP_Text collapsedText = view.transform.FindTransform("Txt_CollapsedPlaceholder").GetComponent<TMP_Text>();
module.HandleWorldChatMessage(new WorldChatMessageMsg
{
PlayerId = 2,
PlayerName = "Bob",
Text = "hello world"
});
Assert.That(collapsedText.text, Is.EqualTo("Bob: hello world"));
}
private WorldChatModule CreateBoundModule()
{
GameObject prefab = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/Game/Art/UI/Prefab/UI_CommonChat.prefab");
Assert.That(prefab, Is.Not.Null);
view = UnityEngine.Object.Instantiate(prefab);
host = new GameObject("WorldChatModuleTestHost");
WorldChatModule module = host.AddComponent<WorldChatModule>();
module.Initialize(1, _ => { });
SetPrivateField(module, "view", view);
InvokePrivate(module, "CacheControls");
InvokePrivate(module, "BindEvents");
return module;
}
private static void SetPrivateField(object target, string name, object value)
{
FieldInfo field = target.GetType().GetField(name, BindingFlags.Instance | BindingFlags.NonPublic);
Assert.That(field, Is.Not.Null);
field.SetValue(target, value);
}
private static void InvokePrivate(object target, string name)
{
MethodInfo method = target.GetType().GetMethod(name, BindingFlags.Instance | BindingFlags.NonPublic);
Assert.That(method, Is.Not.Null);
method.Invoke(target, Array.Empty<object>());
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f953f6437b2d4314b8c8c77d531223e0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -3,6 +3,7 @@
"rootNamespace": "",
"references": [
"XWorld.Link",
"XWorld.Framework.Shared",
"Unity.TextMeshPro",
"GUID:119d45324677fde49923efc4ea54b313"
],