RAGECOOP-V/Client/Interface.cs

90 lines
2.4 KiB
C#
Raw Normal View History

2021-09-28 16:51:16 +02:00
using System;
using System.ComponentModel;
using Lidgren.Network;
namespace CoopClient
{
public static class Interface
{
2021-09-27 19:10:51 +02:00
#region DELEGATES
public delegate void ConnectEvent(bool connected, string reason = null);
public delegate void MessageEvent(NetIncomingMessage message);
public delegate void ChatMessage(string from, string message, CancelEventArgs args);
2021-09-27 19:10:51 +02:00
#endregion
#region EVENTS
public static event ConnectEvent OnConnection;
public static event MessageEvent OnMessage;
public static event ChatMessage OnChatMessage;
internal static void Connected()
{
OnConnection?.Invoke(true);
}
internal static void Disconnected(string reason)
{
OnConnection?.Invoke(false, reason);
}
internal static void MessageReceived(NetIncomingMessage message)
{
2021-09-27 19:10:51 +02:00
OnMessage?.Invoke(message);
}
internal static bool ChatMessageReceived(string from, string message)
{
CancelEventArgs args = new CancelEventArgs(false);
OnChatMessage?.Invoke(from, message, args);
return args.Cancel;
}
2021-09-27 19:10:51 +02:00
#endregion
public static void SendChatMessage(string from, string message)
{
Main.MainChat.AddMessage(from, message);
}
2021-09-27 19:10:51 +02:00
public static void Connect(string serverAddress)
{
2021-09-27 19:10:51 +02:00
Main.MainNetworking.DisConnectFromServer(serverAddress);
}
public static bool IsOnServer()
{
return Main.MainNetworking.IsOnServer();
}
2021-09-28 16:51:16 +02:00
public static bool IsMenuVisible()
{
return Main.MainMenu.MenuPool.AreAnyVisible;
}
public static bool IsChatFocused()
{
return Main.MainChat.Focused;
}
public static bool IsPlayerListVisible()
{
return Environment.TickCount - PlayerList.Pressed < 5000;
}
public static string GetCurrentVersion()
{
return Main.CurrentVersion;
}
2021-09-27 19:10:51 +02:00
public static void Configure(string playerName, bool shareNpcsWithPlayers, int streamedNpcs, bool debug = false)
{
2021-09-27 19:10:51 +02:00
Main.MainSettings.Username = playerName;
Main.ShareNpcsWithPlayers = shareNpcsWithPlayers;
Main.MainSettings.StreamedNpc = streamedNpcs;
#if DEBUG
Main.UseDebug = debug;
#endif
}
}
}