126 lines
No EOL
3.7 KiB
C#
126 lines
No EOL
3.7 KiB
C#
using Sandbox.Game.EntityComponents;
|
|
using Sandbox.ModAPI.Ingame;
|
|
using Sandbox.ModAPI.Interfaces;
|
|
|
|
using SpaceEngineers.Game.ModAPI.Ingame;
|
|
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Immutable;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
using VRage;
|
|
using VRage.Collections;
|
|
using VRage.Game;
|
|
using VRage.Game.Components;
|
|
using VRage.Game.GUI.TextPanel;
|
|
using VRage.Game.ModAPI.Ingame;
|
|
using VRage.Game.ModAPI.Ingame.Utilities;
|
|
using VRage.Game.ObjectBuilders.Definitions;
|
|
|
|
using VRageMath;
|
|
|
|
namespace IngameScript
|
|
{
|
|
class Output
|
|
{
|
|
readonly IList<IMyTextSurface> outputs;
|
|
readonly int maxNbLines;
|
|
|
|
public Output(IList<IMyTextSurface> surfaces, int maxNbLines = 10)
|
|
{
|
|
foreach (var s in surfaces)
|
|
{
|
|
s.ContentType = ContentType.TEXT_AND_IMAGE;
|
|
s.WriteText("");
|
|
}
|
|
|
|
this.outputs = surfaces;
|
|
this.maxNbLines = maxNbLines;
|
|
}
|
|
|
|
public Output(IMyCockpit cockpit, int maxNbLines = 10)
|
|
{
|
|
this.outputs = new List<IMyTextSurface>();
|
|
for (int n = 0; n < cockpit.SurfaceCount; n++)
|
|
{
|
|
var surface = cockpit.GetSurface(n);
|
|
surface.ContentType = ContentType.TEXT_AND_IMAGE;
|
|
surface.WriteText("");
|
|
this.outputs.Add(surface);
|
|
}
|
|
this.maxNbLines = maxNbLines;
|
|
}
|
|
|
|
public Output(IMyTextSurface surface, int maxNbLines = 10)
|
|
: this(new List<IMyTextSurface> { surface }, maxNbLines)
|
|
{ }
|
|
|
|
public void Print(string text, int outputNumber = -1)
|
|
{
|
|
if (outputNumber >= 0 && this.outputs.Count() <= outputNumber)
|
|
{
|
|
throw new Exception($"Output number {outputNumber} doesn't exist (number of output: {this.outputs.Count()}");
|
|
}
|
|
else
|
|
{
|
|
if (outputNumber == -1)
|
|
{
|
|
foreach (var output in this.outputs)
|
|
this.Print(text, output);
|
|
}
|
|
else
|
|
{
|
|
this.Print(text, this.outputs[outputNumber]);
|
|
}
|
|
}
|
|
}
|
|
|
|
void Print(string text, IMyTextSurface surface)
|
|
{
|
|
var currentText = surface.GetText();
|
|
var lines = currentText.Split('\n');
|
|
if (lines.Count() >= this.maxNbLines)
|
|
{
|
|
surface.WriteText(lines.Skip(lines.Count() - this.maxNbLines + 1).Append(text).Aggregate((a, b) => a + Environment.NewLine + b));
|
|
}
|
|
else if (lines.Count() == 0)
|
|
{
|
|
surface.WriteText(text);
|
|
}
|
|
else
|
|
{
|
|
surface.WriteText(Environment.NewLine + text, true);
|
|
}
|
|
}
|
|
|
|
public void PrintError(string text, int outputNumber = 0)
|
|
{
|
|
this.Print($"Error: {text}", outputNumber);
|
|
}
|
|
|
|
|
|
public void Display(string text, int outputNumber = -1)
|
|
{
|
|
if (outputNumber >= 0 && this.outputs.Count() <= outputNumber)
|
|
{
|
|
throw new Exception($"Output number {outputNumber} doesn't exist (number of output: {this.outputs.Count()}");
|
|
}
|
|
else
|
|
{
|
|
if (outputNumber == -1)
|
|
{
|
|
foreach (var output in this.outputs)
|
|
output.WriteText(text);
|
|
}
|
|
else
|
|
{
|
|
this.outputs[outputNumber].WriteText(text);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
} |