130 lines
5.6 KiB
C#
130 lines
5.6 KiB
C#
using System.Runtime.InteropServices;
|
|
|
|
namespace VRC_Console;
|
|
|
|
public partial class OSCCollar
|
|
{
|
|
private const byte CoordinateSystemSize = 16;
|
|
private const int MinWindowHeight = 10;
|
|
private const int MinWindowWidth = 60;
|
|
|
|
private void CheckConsoleMinSize()
|
|
{
|
|
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
return;
|
|
if (Console.WindowHeight < MinWindowHeight)
|
|
Console.WindowHeight = MinWindowHeight;
|
|
if (Console.WindowWidth < MinWindowWidth)
|
|
Console.WindowWidth = MinWindowWidth;
|
|
}
|
|
|
|
private void PrintConsole()
|
|
{
|
|
Console.Clear();
|
|
CheckConsoleMinSize();
|
|
ValueTuple<string, string>[] configValues = new[]
|
|
{
|
|
new ValueTuple<string, string>("IP", Config.Ip),
|
|
new ValueTuple<string, string>("Send-Osc-Port", Config.PortSend.ToString()),
|
|
new ValueTuple<string, string>("Receive-Osc-Port", this._osc.OSCPort.ToString()),
|
|
new ValueTuple<string, string>("Calibration Values", $"{this._calibrationAverage.Count}/{Config.CalibrationValues}"),
|
|
new ValueTuple<string, string>("Stretch Parameter", Config.LeashStretchParameter),
|
|
new ValueTuple<string, string>("Toggle Parameter", Config.LeashToggleParameter),
|
|
new ValueTuple<string, string>("AvatarId", _avatarId.Length < 1 ? "Reset Avatar to show." : _avatarId),
|
|
};
|
|
|
|
ValueTuple<string, string>[] variableValues = new[]
|
|
{
|
|
new ValueTuple<string, string>("Status", $"{(_allowMoving ? Resources.OSCCollar_ConsoleOutput_StatusEnabled : Resources.OSCCollar_ConsoleOutput_StatusDisabled)}"),
|
|
new ValueTuple<string, string>("GPS 1", $"{refPos1.Distance: 0.00000}"),
|
|
new ValueTuple<string, string>("GPS 2", $"{refPos2.Distance: 0.00000}"),
|
|
new ValueTuple<string, string>("GPS 3", $"{refPos3.Distance: 0.00000}"),
|
|
new ValueTuple<string, string>(Resources.OSCCollar_ConsoleOutput_PositionVector, _unitVectorLeash.ToString()),
|
|
new ValueTuple<string, string>(Resources.OSCCollar_ConsoleOutput_LeashStretch, _leashStretch.ToString(" 0.00000")),
|
|
new ValueTuple<string, string>(Resources.OSCCollar_ConsoleOutput_MovementVector, _movementVector.ToString()),
|
|
new ValueTuple<string, string>("CalibrationX", $"{GetCalibrationValues().Item1: 00.00000;-00.00000}"),
|
|
new ValueTuple<string, string>("CalibrationY", $"{GetCalibrationValues().Item2: 00.00000;-00.00000}")
|
|
};
|
|
|
|
Console.Write(GetCoordinateSystem());
|
|
|
|
int coordOffset = CoordinateSystemSize + 5;
|
|
|
|
int valueOffset = configValues.MaxBy(item => item.Item1.Length).Item1.Length + 3;
|
|
for (int i = 0; i < configValues.Length; i++)
|
|
{
|
|
Console.SetCursorPosition(coordOffset, i);
|
|
Console.Write($"{configValues[i].Item1}:");
|
|
Console.Write(new string('.', valueOffset - configValues[i].Item1.Length));
|
|
Console.SetCursorPosition(coordOffset + valueOffset, i);
|
|
Console.Write(configValues[i].Item2);
|
|
}
|
|
ValueTuple<string, string> x = configValues.MaxBy(item => item.Item1.Length + item.Item2.Length);
|
|
|
|
int varOffset = coordOffset + x.Item1.Length + x.Item2.Length + 10;
|
|
valueOffset = variableValues.MaxBy(item => item.Item1.Length).Item1.Length + 3;
|
|
for (int i = 0; i < variableValues.Length; i++)
|
|
{
|
|
Console.SetCursorPosition(varOffset, i);
|
|
Console.Write($"{variableValues[i].Item1}:");
|
|
Console.Write(new string('.', valueOffset - variableValues[i].Item1.Length));
|
|
Console.SetCursorPosition(varOffset + valueOffset, i);
|
|
Console.Write(variableValues[i].Item2);
|
|
}
|
|
|
|
Console.SetCursorPosition(0, Console.WindowHeight - 2);
|
|
Console.Write($"Last Hand Reset: {DateTime.Now.Subtract(_lastNilMessageSent):ss\\.fff}\tLast Message Received: {(_lastMessageReceived == DateTime.UnixEpoch ? "never" : DateTime.Now.Subtract(_lastMessageReceived)):ss\\.fff} {_lastMessageReceivedParameter}\tRuntime: {DateTime.Now.Subtract(_programStarted):hh\\:mm\\:ss\\.fff}");
|
|
}
|
|
|
|
private String GetCoordinateSystem()
|
|
{
|
|
string system = "";
|
|
byte width = CoordinateSystemSize;
|
|
byte height = CoordinateSystemSize / 2;
|
|
|
|
int positionX = Convert.ToInt32(Math.Floor(_unitVectorLeash.X * (width / 2.0))) + (width / 2);
|
|
int positionY = Convert.ToInt32(-Math.Floor(_unitVectorLeash.Y * (height / 2.0))) + (height / 2);
|
|
|
|
int movementX = Convert.ToInt32(Math.Floor(_movementVector.X * (width / 2.0))) + (width / 2);
|
|
int movementY = Convert.ToInt32(-Math.Floor(_movementVector.Y * (height / 2.0))) + (height / 2);
|
|
|
|
for (int y = 0; y <= height; y++)
|
|
{
|
|
for (int x = 0; x <= width; x++)
|
|
{
|
|
|
|
if (x == movementX && y == movementY)
|
|
{
|
|
system += "x";
|
|
continue;
|
|
}
|
|
|
|
if (x == positionX && y == positionY)
|
|
{
|
|
system += "x";
|
|
continue;
|
|
}
|
|
|
|
if (y == height / 2)
|
|
{
|
|
if (x == width / 2)
|
|
system += "+";
|
|
else
|
|
system += "-";
|
|
}
|
|
else
|
|
{
|
|
if (x == width / 2)
|
|
system += "|";
|
|
else
|
|
system += " ";
|
|
}
|
|
}
|
|
|
|
if (y != height)
|
|
system += "\n";
|
|
}
|
|
|
|
return system;
|
|
}
|
|
} |