2021-07-07 13:36:25 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
using GTA;
|
|
|
|
|
using GTA.Native;
|
|
|
|
|
|
|
|
|
|
namespace CoopClient
|
|
|
|
|
{
|
2021-12-03 20:30:00 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Don't use it!
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class Chat
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
|
|
|
|
private readonly Scaleform MainScaleForm;
|
|
|
|
|
|
2021-12-03 20:30:00 +01:00
|
|
|
|
internal string CurrentInput { get; set; }
|
2021-07-07 13:36:25 +02:00
|
|
|
|
|
|
|
|
|
private bool CurrentFocused { get; set; }
|
2021-12-03 20:30:00 +01:00
|
|
|
|
internal bool Focused
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
|
|
|
|
get { return CurrentFocused; }
|
|
|
|
|
set
|
|
|
|
|
{
|
2021-07-12 20:28:26 -03:00
|
|
|
|
if (value && Hidden)
|
|
|
|
|
{
|
|
|
|
|
Hidden = false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-07 13:36:25 +02:00
|
|
|
|
MainScaleForm.CallFunction("SET_FOCUS", value ? 2 : 1, 2, "ALL");
|
|
|
|
|
|
|
|
|
|
CurrentFocused = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-19 22:08:15 +01:00
|
|
|
|
private ulong LastMessageTime { get; set; }
|
2021-07-12 20:28:26 -03:00
|
|
|
|
|
|
|
|
|
private bool CurrentHidden { get; set; }
|
|
|
|
|
private bool Hidden
|
|
|
|
|
{
|
|
|
|
|
get { return CurrentHidden; }
|
|
|
|
|
set
|
|
|
|
|
{
|
2021-08-26 17:01:32 +02:00
|
|
|
|
if (value)
|
2021-07-13 00:56:50 -03:00
|
|
|
|
{
|
2021-08-26 17:01:32 +02:00
|
|
|
|
if (!CurrentHidden)
|
|
|
|
|
{
|
|
|
|
|
MainScaleForm.CallFunction("hide");
|
|
|
|
|
}
|
2021-07-13 00:56:50 -03:00
|
|
|
|
}
|
2021-08-26 17:01:32 +02:00
|
|
|
|
else if (CurrentHidden)
|
2021-07-13 00:56:50 -03:00
|
|
|
|
{
|
|
|
|
|
MainScaleForm.CallFunction("showFeed");
|
|
|
|
|
}
|
2021-07-12 20:28:26 -03:00
|
|
|
|
|
|
|
|
|
CurrentHidden = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-03 20:30:00 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Don't use it!
|
|
|
|
|
/// </summary>
|
2021-07-07 13:36:25 +02:00
|
|
|
|
public Chat()
|
|
|
|
|
{
|
|
|
|
|
MainScaleForm = new Scaleform("multiplayer_chat");
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-03 20:30:00 +01:00
|
|
|
|
internal void Init()
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
|
|
|
|
MainScaleForm.CallFunction("SET_FOCUS", 2, 2, "ALL");
|
|
|
|
|
MainScaleForm.CallFunction("SET_FOCUS", 1, 2, "ALL");
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-03 20:30:00 +01:00
|
|
|
|
internal void Clear()
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
|
|
|
|
MainScaleForm.CallFunction("RESET");
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-03 20:30:00 +01:00
|
|
|
|
internal void Tick()
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
2021-11-19 22:08:15 +01:00
|
|
|
|
if ((Util.GetTickCount64() - LastMessageTime) > 15000 && !Focused && !Hidden)
|
2021-07-12 20:28:26 -03:00
|
|
|
|
{
|
|
|
|
|
Hidden = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!Hidden)
|
|
|
|
|
{
|
|
|
|
|
MainScaleForm.Render2D();
|
|
|
|
|
}
|
2021-07-07 13:36:25 +02:00
|
|
|
|
|
|
|
|
|
if (!CurrentFocused)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Function.Call(Hash.DISABLE_ALL_CONTROL_ACTIONS, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-03 20:30:00 +01:00
|
|
|
|
internal void AddMessage(string sender, string msg)
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
|
|
|
|
MainScaleForm.CallFunction("ADD_MESSAGE", sender + ":", msg);
|
2021-11-19 22:08:15 +01:00
|
|
|
|
LastMessageTime = Util.GetTickCount64();
|
2021-07-12 20:28:26 -03:00
|
|
|
|
Hidden = false;
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-03 20:30:00 +01:00
|
|
|
|
internal void OnKeyDown(Keys key)
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
|
|
|
|
if (key == Keys.Escape)
|
|
|
|
|
{
|
|
|
|
|
Focused = false;
|
|
|
|
|
CurrentInput = "";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (key == Keys.PageUp)
|
|
|
|
|
{
|
|
|
|
|
MainScaleForm.CallFunction("PAGE_UP");
|
|
|
|
|
}
|
|
|
|
|
else if (key == Keys.PageDown)
|
|
|
|
|
{
|
|
|
|
|
MainScaleForm.CallFunction("PAGE_DOWN");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string keyChar = GetCharFromKey(key, Game.IsKeyPressed(Keys.ShiftKey), false);
|
|
|
|
|
|
|
|
|
|
if (keyChar.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (keyChar[0])
|
|
|
|
|
{
|
|
|
|
|
case (char)8:
|
2021-12-23 22:03:01 +01:00
|
|
|
|
if (CurrentInput?.Length > 0)
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
2021-07-12 20:28:26 -03:00
|
|
|
|
CurrentInput = CurrentInput.Remove(CurrentInput.Length - 1);
|
|
|
|
|
MainScaleForm.CallFunction("DELETE_TEXT");
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
case (char)13:
|
|
|
|
|
MainScaleForm.CallFunction("ADD_TEXT", "ENTER");
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(CurrentInput))
|
|
|
|
|
{
|
|
|
|
|
Main.MainNetworking.SendChatMessage(CurrentInput);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Focused = false;
|
|
|
|
|
CurrentInput = "";
|
|
|
|
|
return;
|
|
|
|
|
default:
|
|
|
|
|
CurrentInput += keyChar;
|
|
|
|
|
MainScaleForm.CallFunction("ADD_TEXT", keyChar);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[DllImport("user32.dll")]
|
2021-12-03 20:30:00 +01:00
|
|
|
|
internal static extern int ToUnicodeEx(uint virtualKeyCode, uint scanCode, byte[] keyboardState,
|
2021-07-07 13:36:25 +02:00
|
|
|
|
[Out, MarshalAs(UnmanagedType.LPWStr, SizeConst = 64)]
|
|
|
|
|
StringBuilder receivingBuffer,
|
|
|
|
|
int bufferSize, uint flags, IntPtr kblayout);
|
|
|
|
|
|
2021-12-03 20:30:00 +01:00
|
|
|
|
internal static string GetCharFromKey(Keys key, bool shift, bool altGr)
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
|
|
|
|
StringBuilder buf = new StringBuilder(256);
|
|
|
|
|
byte[] keyboardState = new byte[256];
|
|
|
|
|
|
|
|
|
|
if (shift)
|
|
|
|
|
{
|
|
|
|
|
keyboardState[(int)Keys.ShiftKey] = 0xff;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (altGr)
|
|
|
|
|
{
|
|
|
|
|
keyboardState[(int)Keys.ControlKey] = 0xff;
|
|
|
|
|
keyboardState[(int)Keys.Menu] = 0xff;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ToUnicodeEx((uint)key, 0, keyboardState, buf, 256, 0, InputLanguage.CurrentInputLanguage.Handle);
|
|
|
|
|
return buf.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|