Skip to content

Commit 459a662

Browse files
author
Jannify
authored
Redesign player chat and NitroxUnity structure (#1024)
* Moving NitroxUnity from submodule to simple folder * Updated chat design and code * Added "special" functions * > Fixed dragging offset > Added fade to chat show/hide * Added chat key hint * Cleaned up the mess after failed rebase * Reimplemented #982 Reimplemented autofac registry entry * Added back meta files from unity * Changed method to removed chat pop in * > Optimized layout groups and content fitting > Added new line option with Shift + Enter > Dragging now works with offset > Optimized fonts * > Replaced `while return null` `with `WaitUntil` > Replaced `CoroutineWithData` `with `IEnumerator callback` * Optimizing sprites
1 parent db33aff commit 459a662

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+4054
-364
lines changed

.gitattributes

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
* text=auto
2+
3+
# Unity files
4+
*.meta -merge=unityamlmerge -text
5+
*.unity -merge=unityamlmerge -text
6+
*.asset -merge=unityamlmerge -text
7+
*.prefab -merge=unityamlmerge -text

.gitignore

+9-1
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ bld/
2727
[Oo]bj/
2828
[Ll]og/
2929

30-
# Visual Studio 2015 cache/options directory
30+
# Visual Studio cache/options directory
3131
.vs/
32+
3233
# Uncomment if you have tasks that create the project's static files in wwwroot
3334
#wwwroot/
3435

@@ -278,3 +279,10 @@ paket-files/
278279
/.sonarqube
279280
sonar.config.bat
280281
*.bak
282+
283+
# Unity3D: Generated meta files
284+
*.pidb.meta
285+
*.pdb.meta
286+
287+
# Unity3D: Generated File On Crash Reports
288+
sysinfo.txt

.gitmodules

-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
[submodule "NitroxUnity"]
2-
path = NitroxUnity
3-
url = https://github.com/SubnauticaNitrox/NitroxUnity

AssetBundles/chatkeyhint

217 KB
Binary file not shown.

AssetBundles/chatlog

168 KB
Binary file not shown.

Nitrox.sln.DotSettings

+1
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@
228228
</TypePattern>
229229
&lt;/Patterns&gt;</s:String>
230230
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAlwaysTreatStructAsNotReorderableMigration/@EntryIndexedValue">True</s:Boolean>
231+
<s:Boolean x:Key="/Default/UserDictionary/Words/=Coroutine/@EntryIndexedValue">True</s:Boolean>
231232
<s:Boolean x:Key="/Default/UserDictionary/Words/=Mathf/@EntryIndexedValue">True</s:Boolean>
232233
<s:Boolean x:Key="/Default/UserDictionary/Words/=Nitrox/@EntryIndexedValue">True</s:Boolean>
233234
<s:Boolean x:Key="/Default/UserDictionary/Words/=Startable/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

NitroxClient/ClientAutoFacRegistrar.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ private static void RegisterCoreDependencies(ContainerBuilder containerBuilder)
7575
containerBuilder.RegisterType<PlayerManager>().InstancePerLifetimeScope();
7676
containerBuilder.RegisterType<PlayerModelManager>().InstancePerLifetimeScope();
7777
containerBuilder.RegisterType<PlayerVitalsManager>().InstancePerLifetimeScope();
78-
containerBuilder.RegisterType<PlayerChat>().InstancePerLifetimeScope();
7978
containerBuilder.RegisterType<VisibleCells>().InstancePerLifetimeScope();
8079
containerBuilder.RegisterType<PacketReceiver>().InstancePerLifetimeScope();
8180
containerBuilder.RegisterType<AI>().InstancePerLifetimeScope();
8281
containerBuilder.RegisterType<Building>().InstancePerLifetimeScope();
82+
containerBuilder.RegisterType<PlayerChatManager>().InstancePerLifetimeScope();
8383
containerBuilder.RegisterType<Entities>().InstancePerLifetimeScope();
8484
containerBuilder.RegisterType<MedkitFabricator>().InstancePerLifetimeScope();
8585
containerBuilder.RegisterType<Item>().InstancePerLifetimeScope();

NitroxClient/Communication/Packets/Processors/ChatMessageProcessor.cs

+14-8
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,25 @@
33
using NitroxClient.Communication.Packets.Processors.Abstract;
44
using NitroxClient.GameLogic;
55
using NitroxClient.GameLogic.ChatUI;
6+
using NitroxModel.Core;
67
using NitroxModel.DataStructures.Util;
8+
using NitroxModel.Logger;
79
using NitroxModel.Packets;
10+
using UnityEngine;
811

912
namespace NitroxClient.Communication.Packets.Processors
1013
{
1114
class ChatMessageProcessor : ClientPacketProcessor<ChatMessage>
1215
{
1316
private readonly PlayerManager remotePlayerManager;
14-
private readonly PlayerChat playerChat;
17+
private readonly PlayerChatManager playerChatManager;
1518

16-
public ChatMessageProcessor(PlayerManager remotePlayerManager, PlayerChat playerChat)
19+
private readonly Color32 serverMessageColor = new Color32(0x8c, 0x00, 0xFF, 0xFF);
20+
21+
public ChatMessageProcessor(PlayerManager remotePlayerManager, PlayerChatManager playerChatManager)
1722
{
1823
this.remotePlayerManager = remotePlayerManager;
19-
this.playerChat = playerChat;
24+
this.playerChatManager = playerChatManager;
2025
}
2126

2227
public override void Process(ChatMessage message)
@@ -37,18 +42,19 @@ private void LogClientMessage(ChatMessage message)
3742
if (!remotePlayer.HasValue)
3843
{
3944
string playerTableFormatted = string.Join("\n", remotePlayerManager.GetAll().Select(ply => $"Name: '{ply.PlayerName}', Id: {ply.PlayerId}"));
45+
Log.Error($"Tried to add chat message for remote player that could not be found with id '${message.PlayerId}' and message: '{message.Text}'.\nAll remote players right now:\n{playerTableFormatted}");
4046
throw new Exception($"Tried to add chat message for remote player that could not be found with id '${message.PlayerId}' and message: '{message.Text}'.\nAll remote players right now:\n{playerTableFormatted}");
4147
}
42-
48+
4349
RemotePlayer remotePlayerInstance = remotePlayer.Value;
44-
playerChat.AddMessage(remotePlayerInstance.PlayerName, message.Text, remotePlayerInstance.PlayerSettings.PlayerColor);
45-
playerChat.ShowLog();
50+
playerChatManager.AddMessage(remotePlayerInstance.PlayerName, message.Text, remotePlayerInstance.PlayerSettings.PlayerColor);
51+
playerChatManager.ShowChat();
4652
}
4753

4854
private void LogServerMessage(ChatMessage message)
4955
{
50-
playerChat.AddMessage("Server", message.Text, new UnityEngine.Color32(0x8c, 0x00, 0xFF, 0xFF));
51-
playerChat.ShowLog();
56+
playerChatManager.AddMessage("Server", message.Text, serverMessageColor);
57+
playerChatManager.ShowChat();
5258
}
5359
}
5460
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using UnityEngine;
1+
using System;
2+
using UnityEngine;
23

34
namespace NitroxClient.GameLogic.ChatUI
45
{
@@ -7,12 +8,17 @@ public class ChatLogEntry
78
public string PlayerName { get; }
89
public string MessageText { get; set; }
910
public Color32 PlayerColor { get; }
11+
public string Time { get; set; }
12+
public GameObject EntryObject { get; set; }
1013

1114
public ChatLogEntry(string playerName, string messageText, Color32 playerColor)
1215
{
1316
PlayerName = playerName;
1417
MessageText = messageText;
1518
PlayerColor = playerColor;
19+
UpdateTime();
1620
}
21+
22+
public void UpdateTime() => Time = DateTime.Now.ToString("HH:mm");
1723
}
1824
}

NitroxClient/GameLogic/ChatUI/PlayerChat.cs

-72
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using System.Collections;
2+
using NitroxClient.Communication.Abstract;
3+
using NitroxClient.MonoBehaviours.Gui.Chat;
4+
using NitroxClient.Unity.Helper;
5+
using NitroxModel.Packets;
6+
using UnityEngine;
7+
8+
namespace NitroxClient.GameLogic.ChatUI
9+
{
10+
public class PlayerChatManager
11+
{
12+
public PlayerChatManager(IMultiplayerSession multiplayerSession)
13+
{
14+
this.multiplayerSession = multiplayerSession;
15+
Player.main.StartCoroutine(LoadChatLogAsset());
16+
}
17+
18+
private PlayerChat playerChat;
19+
public Transform PlayerChaTransform => playerChat.transform;
20+
private readonly IMultiplayerSession multiplayerSession;
21+
22+
public void ShowChat() => Player.main.StartCoroutine(ShowChatAsync());
23+
private IEnumerator ShowChatAsync()
24+
{
25+
yield return new WaitUntil(() => PlayerChat.IsReady);
26+
playerChat.Show();
27+
}
28+
29+
public void HideChat() => Player.main.StartCoroutine(HideChatAsync());
30+
private IEnumerator HideChatAsync()
31+
{
32+
yield return new WaitUntil(() => PlayerChat.IsReady);
33+
playerChat.Deselect();
34+
playerChat.Hide();
35+
}
36+
37+
public void SelectChat() => Player.main.StartCoroutine(SelectChatAsync());
38+
private IEnumerator SelectChatAsync()
39+
{
40+
yield return new WaitUntil(() => PlayerChat.IsReady);
41+
playerChat.Show();
42+
playerChat.Select();
43+
}
44+
45+
public void AddMessage(string playerName, string message, Color color) => Player.main.StartCoroutine(AddMessageAsync(playerName, message, color));
46+
private IEnumerator AddMessageAsync(string playerName, string message, Color color)
47+
{
48+
yield return new WaitUntil(() => PlayerChat.IsReady);
49+
playerChat.WriteLogEntry(playerName, message, color);
50+
}
51+
52+
public void SendMessage()
53+
{
54+
if (playerChat.inputText.Trim() != "")
55+
{
56+
multiplayerSession.Send(new ChatMessage(multiplayerSession.Reservation.PlayerId, playerChat.inputText));
57+
playerChat.WriteLogEntry(multiplayerSession.AuthenticationContext.Username, playerChat.inputText, multiplayerSession.PlayerSettings.PlayerColor);
58+
playerChat.inputText = "";
59+
}
60+
playerChat.Select();
61+
}
62+
63+
private IEnumerator LoadChatLogAsset()
64+
{
65+
yield return AssetBundleLoader.LoadUIAsset("chatlog", "PlayerChatCanvas", true, playerChatGameObject =>
66+
{
67+
playerChat = playerChatGameObject.AddComponent<PlayerChat>();
68+
});
69+
70+
yield return playerChat.SetupChatComponents();
71+
}
72+
73+
public static void LoadChatKeyHint() => Player.main.StartCoroutine(AssetBundleLoader.LoadUIAsset("chatkeyhint", "ChatKeyCanvas"));
74+
}
75+
}

0 commit comments

Comments
 (0)