Skip to content

Commit

Permalink
Merge pull request #522 from kremnev8/Chat
Browse files Browse the repository at this point in the history
Add improved chat
  • Loading branch information
sp00ktober authored Feb 17, 2022
2 parents 250968a + 455e13f commit 4b7285e
Show file tree
Hide file tree
Showing 337 changed files with 576,107 additions and 8 deletions.
1 change: 0 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ insert_final_newline = false
# Organize usings
dotnet_separate_import_directive_groups = false
dotnet_sort_system_directives_first = false
file_header_template = unset

# this. and Me. preferences
dotnet_style_qualification_for_event = false
Expand Down
1 change: 1 addition & 0 deletions .github/scripts/thunderstore_bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ function generateManifest() {
BEPINEX_DEPENDENCY,
`nebula-${apiPluginInfo.name}-${apiPluginInfo.version}`,
"PhantomGamers-IlLine-1.0.0",
"CommonAPI-CommonAPI-1.2.2",
],
website_url: "https://github.com/hubastard/nebula"
};
Expand Down
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -374,4 +374,13 @@ FodyWeavers.xsd
nbgv.exe

# CI build indicator
.remoteBuild
.remoteBuild

# Assemblies copied into Unity project
NebulaUnity/Assets/Assemblies
# Generated assets
NebulaUnity/Assets/StreamingAssets/AssetBundles
NebulaUnity/Assets/Plugins/Editor/JetBrains
NebulaUnity/Assets/Plugins/Editor/JetBrains.meta
NebulaUnity/Assets/Plugins.meta
NebulaUnity/Assets/Plugins
4 changes: 3 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@
</ItemGroup>

<ItemGroup Label="Core">
<PackageReference Include="BepInEx.Analyzers" Version="1.*" PrivateAssets="all" />
<PackageReference Include="BepInEx.Core" Version="5.*" PrivateAssets="all" />
<PackageReference Include="UnityEngine.Modules" Version="2018.4.12" IncludeAssets="compile" PrivateAssets="all" />
<PackageReference Include="DysonSphereProgram.GameLibs" Version="*-*" IncludeAssets="compile" PrivateAssets="all" />
<PackageReference Include="DysonSphereProgram.Modding.CommonAPI" Version="1.4.1" IncludeAssets="compile" PrivateAssets="all"
Condition=" '$(MSBuildProjectName)' != 'NebulaAPI' " />

</ItemGroup>

<ItemGroup Condition="'$(TargetFramework.TrimEnd(`0123456789`))' == 'net'">
Expand Down
2 changes: 2 additions & 0 deletions NebulaAPI/GameState/IPlayerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public interface IPlayerManager

INebulaPlayer GetSyncingPlayer(INebulaConnection conn);

INebulaPlayer GetConnectedPlayerByUsername(string username);

void SendPacketToAllPlayers<T>(T packet) where T : class, new();

void SendPacketToLocalStar<T>(T packet) where T : class, new();
Expand Down
3 changes: 3 additions & 0 deletions NebulaModel/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ public static class Config
public static string ModVersion => ThisAssembly.AssemblyInformationalVersion;
public static MultiplayerOptions Options { get; set; }

public static Action OnConfigApplied;

private static ConfigFile configFile;


public static bool LoadOptions()
{
Expand Down
69 changes: 69 additions & 0 deletions NebulaModel/DataStructures/Chat/ChatMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using NebulaModel.Packets.Players;
using NebulaModel.Utils;
using System;
using TMPro;
using UnityEngine;
using Object = UnityEngine.Object;

namespace NebulaModel.DataStructures
{
/// <summary>
/// This is what is rendered in the chat area (already sent chat messages)
/// </summary>
[Serializable]
public class ChatMessage
{
private string text;
private ChatMessageType messageType;

public TMP_Text textObject;
public TMP_Text notificationText;


public string Text
{
get => text;
set
{
textObject.text = value;
if (notificationText != null)
{
notificationText.text = value;
}

text = value;
}
}

public ChatMessageType MessageType
{
get => messageType;
set
{
textObject.color = ChatUtils.GetMessageColor(value);
if (notificationText != null)
{
notificationText.color = textObject.color;
}

messageType = value;
}
}

public ChatMessage(GameObject textObj, string message, ChatMessageType messageType)
{
textObject = textObj.GetComponent<TMP_Text>();
Text = message;
MessageType = messageType;
}

public void DestroyMessage()
{
Object.Destroy(textObject.gameObject);
if (notificationText != null)
{
Object.Destroy(notificationText.gameObject);
}
}
}
}
12 changes: 12 additions & 0 deletions NebulaModel/DataStructures/Chat/ChatMessageType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace NebulaModel.DataStructures
{
public enum ChatMessageType
{
PlayerMessage = 0,
SystemMessage = 1,
CommandUsageMessage = 2,
CommandOutputMessage = 3,
CommandErrorMessage = 4,
PlayerMessagePrivate = 5
}
}
17 changes: 17 additions & 0 deletions NebulaModel/DataStructures/Chat/ChatPosition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace NebulaModel.DataStructures
{
public enum ChatPosition
{
LeftMiddle = 0,
RightMiddle = 1,
LeftTop = 2,
RightTop = 3
}

public enum ChatSize
{
Small = 0,
Medium = 1,
Big = 2
}
}
13 changes: 13 additions & 0 deletions NebulaModel/MultiplayerOptions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using NebulaAPI;
using NebulaModel.Attributes;
using NebulaModel.DataStructures;
using System;
using System.ComponentModel;

Expand All @@ -21,10 +22,22 @@ public class MultiplayerOptions : ICloneable
[DisplayName("Show Lobby Hints")]
public bool ShowLobbyHints { get; set; } = true;

[DisplayName("Auto Open Chat")]
public bool AutoOpenChat { get; set; } = true;

public string LastIP { get; set; } = string.Empty;

[DisplayName("Sync Ups")]
public bool SyncUps { get; set; } = true;

[DisplayName("Streamer mode")]
public bool StreamerMode { get; set; } = false;

[DisplayName("Default chat position")]
public ChatPosition DefaultChatPosition { get; set; } = ChatPosition.LeftMiddle;

[DisplayName("Default chat size")]
public ChatSize DefaultChatSize { get; set; } = ChatSize.Medium;

[DisplayName("Sync Soil")]
public bool SyncSoil { get; set; } = false;
Expand Down
9 changes: 9 additions & 0 deletions NebulaModel/Networking/IClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Net;

namespace NebulaModel.Networking
{
public interface IClient
{
IPEndPoint ServerEndpoint { get; }
}
}
7 changes: 7 additions & 0 deletions NebulaModel/Networking/IServer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace NebulaModel.Networking
{
public interface IServer
{
int Port { get; }
}
}
18 changes: 18 additions & 0 deletions NebulaModel/Packets/Chat/ChatCommandWhisperPacket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace NebulaModel.Packets.Players
{
public class ChatCommandWhisperPacket
{
public string SenderUsername { get; set; }
public string RecipientUsername { get; set; }
public string Message { get; set; }

public ChatCommandWhisperPacket() { }

public ChatCommandWhisperPacket(string sender, string recipient, string message)
{
SenderUsername = sender;
RecipientUsername = recipient;
Message = message;
}
}
}
22 changes: 22 additions & 0 deletions NebulaModel/Packets/Chat/ChatCommandWhoPacket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace NebulaModel.Packets.Players
{
public class ChatCommandWhoPacket
{
public bool IsRequest { get; set; }
public string ResponsePayload { get; set; }

public ChatCommandWhoPacket() { }

public ChatCommandWhoPacket(bool isRequest, string responsePayload)
{
IsRequest = isRequest;
#if DEBUG
if (!isRequest)
{
Assert.False(string.IsNullOrEmpty(responsePayload));
}
#endif
ResponsePayload = responsePayload;
}
}
}
23 changes: 23 additions & 0 deletions NebulaModel/Packets/Chat/NewChatMessagePacket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using NebulaModel.DataStructures;
using System;

namespace NebulaModel.Packets.Players
{
public class NewChatMessagePacket
{
public ChatMessageType MessageType { get; set; }
public string MessageText { get; set; }
public long SentAt { get; set; }
public string UserName { get; set; }

public NewChatMessagePacket() { }

public NewChatMessagePacket(ChatMessageType messageType, string messageText, DateTime sentAt, string userName)
{
MessageType = messageType;
MessageText = messageText;
SentAt = sentAt.ToBinary();
UserName = userName;
}
}
}
Loading

0 comments on commit 4b7285e

Please sign in to comment.