fix: polish lobby chat and joystick
This commit is contained in:
@@ -584,6 +584,7 @@ namespace XGame
|
||||
lobbyWorld?.HandleFrame(frame);
|
||||
break;
|
||||
case FrameworkOpcode.WorldChatMessage:
|
||||
Debug.Log("[CSharpClientApp] recv WorldChatMessage bytes=" + (frame.Payload?.Length ?? 0));
|
||||
worldChat?.HandleWorldChatMessage(WorldChatMessageMsg.Decode(frame.Payload));
|
||||
break;
|
||||
}
|
||||
@@ -701,13 +702,25 @@ namespace XGame
|
||||
private void SendWorldChat(string text)
|
||||
{
|
||||
text = (text ?? string.Empty).Trim();
|
||||
if (text.Length == 0 || lobbyNet == null)
|
||||
if (text.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (lobbyNet == null)
|
||||
{
|
||||
Debug.LogWarning("[CSharpClientApp] drop WorldChatSend: lobbyNet is null");
|
||||
return;
|
||||
}
|
||||
if (!lobbyNet.IsConnected)
|
||||
{
|
||||
Debug.LogWarning("[CSharpClientApp] drop WorldChatSend: lobbyNet is disconnected");
|
||||
return;
|
||||
}
|
||||
byte[] payload = new WorldChatSendMsg { Text = text }.Encode();
|
||||
Debug.Log("[CSharpClientApp] send WorldChatSend bytes=" + payload.Length);
|
||||
lobbyNet.SendFramework(
|
||||
FrameworkOpcode.WorldChatSend,
|
||||
new WorldChatSendMsg { Text = text }.Encode());
|
||||
payload);
|
||||
}
|
||||
|
||||
private void CloseWorldChat()
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace XGame
|
||||
private const float DirectionChangeDot = 0.98f;
|
||||
private const float JoystickRadius = 74f;
|
||||
private const float JoystickKnobRadius = 28f;
|
||||
private const float JoystickPadding = 34f;
|
||||
private const float JoystickPadding = 100.0f;
|
||||
private const float JoystickDeadZone = 0.18f;
|
||||
private const float JoystickAcquireRadiusMultiplier = 1.6f;
|
||||
private const float CameraMinDistance = 3.5f;
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6508ec0f8203b6d4e868b5a74194a926
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+42
@@ -24,10 +24,13 @@ namespace XGame
|
||||
private TMP_InputField inputField;
|
||||
private TMP_Text inputPlaceholder;
|
||||
private TMP_Text inputValue;
|
||||
private TMP_Text collapsedPreviewText;
|
||||
private ScrollRect scrollMessages;
|
||||
private bool opening;
|
||||
private int openVersion;
|
||||
private int localPlayerId;
|
||||
private string collapsedDefaultText;
|
||||
private string lastCollapsedPreview;
|
||||
private readonly Queue<GameObject> messageRows = new Queue<GameObject>();
|
||||
|
||||
public Action<string> OnSendWorldChat;
|
||||
@@ -89,7 +92,10 @@ namespace XGame
|
||||
inputField = null;
|
||||
inputPlaceholder = null;
|
||||
inputValue = null;
|
||||
collapsedPreviewText = null;
|
||||
scrollMessages = null;
|
||||
collapsedDefaultText = null;
|
||||
lastCollapsedPreview = null;
|
||||
opening = false;
|
||||
}
|
||||
|
||||
@@ -128,6 +134,12 @@ namespace XGame
|
||||
scrollMessages = FindComponent<ScrollRect>("Scroll_Messages");
|
||||
inputPlaceholder = FindComponent<TMP_Text>("Txt_InputPlaceholder");
|
||||
inputValue = FindComponent<TMP_Text>("Txt_InputValue");
|
||||
collapsedPreviewText = FindComponent<TMP_Text>("Txt_CollapsedPlaceholder");
|
||||
if (collapsedPreviewText != null && string.IsNullOrEmpty(collapsedDefaultText))
|
||||
{
|
||||
collapsedDefaultText = collapsedPreviewText.text;
|
||||
}
|
||||
RefreshCollapsedPreview();
|
||||
EnsureInputField();
|
||||
}
|
||||
|
||||
@@ -142,6 +154,8 @@ namespace XGame
|
||||
{
|
||||
inputField.onSubmit.RemoveListener(OnInputSubmitted);
|
||||
inputField.onSubmit.AddListener(OnInputSubmitted);
|
||||
inputField.onEndEdit.RemoveListener(OnInputEndEdit);
|
||||
inputField.onEndEdit.AddListener(OnInputEndEdit);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,6 +273,11 @@ namespace XGame
|
||||
SendCurrentInput();
|
||||
}
|
||||
|
||||
private void OnInputEndEdit(string text)
|
||||
{
|
||||
SendCurrentInput();
|
||||
}
|
||||
|
||||
private void SendCurrentInput()
|
||||
{
|
||||
string text = inputField == null ? string.Empty : inputField.text;
|
||||
@@ -271,6 +290,7 @@ namespace XGame
|
||||
{
|
||||
text = text.Substring(0, MaxInputLength);
|
||||
}
|
||||
Debug.Log("[WorldChatModule] send world chat length=" + text.Length);
|
||||
OnSendWorldChat?.Invoke(text);
|
||||
ClearInput();
|
||||
FocusInput();
|
||||
@@ -326,6 +346,28 @@ namespace XGame
|
||||
{
|
||||
StartCoroutine(ScrollToBottomNextFrame());
|
||||
}
|
||||
SetCollapsedPreview(message, isSelf);
|
||||
}
|
||||
|
||||
private void SetCollapsedPreview(WorldChatMessageMsg message, bool isSelf)
|
||||
{
|
||||
string name = isSelf ? "\u6211" : message.PlayerName;
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
{
|
||||
name = "\u73A9\u5BB6";
|
||||
}
|
||||
lastCollapsedPreview = name + ": " + (message.Text ?? string.Empty);
|
||||
RefreshCollapsedPreview();
|
||||
}
|
||||
|
||||
private void RefreshCollapsedPreview()
|
||||
{
|
||||
if (collapsedPreviewText != null)
|
||||
{
|
||||
collapsedPreviewText.text = string.IsNullOrEmpty(lastCollapsedPreview)
|
||||
? (collapsedDefaultText ?? string.Empty)
|
||||
: lastCollapsedPreview;
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator ScrollToBottomNextFrame()
|
||||
+3
-3
@@ -6,6 +6,6 @@ MonoImporter:
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user