1 using Sandbox
.Game
.EntityComponents
;
2 using Sandbox
.ModAPI
.Ingame
;
3 using Sandbox
.ModAPI
.Interfaces
;
5 using SpaceEngineers
.Game
.ModAPI
.Ingame
;
8 using System
.Collections
;
9 using System
.Collections
.Generic
;
10 using System
.Collections
.Immutable
;
15 using VRage
.Collections
;
17 using VRage
.Game
.Components
;
18 using VRage
.Game
.GUI
.TextPanel
;
19 using VRage
.Game
.ModAPI
.Ingame
;
20 using VRage
.Game
.ModAPI
.Ingame
.Utilities
;
21 using VRage
.Game
.ObjectBuilders
.Definitions
;
25 namespace IngameScript
29 IList
<IMyTextSurface
> outputs
;
32 public Output(IList
<IMyTextSurface
> surfaces
, int maxNbLines
= 10)
34 foreach (var s
in surfaces
)
36 s
.ContentType
= ContentType
.TEXT_AND_IMAGE
;
40 this.outputs
= surfaces
;
41 this.maxNbLines
= maxNbLines
;
44 public Output(IMyCockpit cockpit
, int maxNbLines
= 10)
46 this.outputs
= new List
<IMyTextSurface
>();
47 for (int n
= 0; n
< cockpit
.SurfaceCount
; n
++)
49 var surface
= cockpit
.GetSurface(n
);
50 surface
.ContentType
= ContentType
.TEXT_AND_IMAGE
;
51 surface
.WriteText("");
52 this.outputs
.Add(surface
);
54 this.maxNbLines
= maxNbLines
;
57 public Output(IMyTextSurface surface
, int maxNbLines
= 10)
58 : this(new List
<IMyTextSurface
> { surface
}, maxNbLines
)
61 public void Print(string text
, int outputNumber
= 0)
63 if (this.outputs
.Count() <= outputNumber
)
65 throw new Exception($"Output number {outputNumber} doesn't exist (number of output: {this.outputs.Count()}");
69 var output
= this.outputs
[outputNumber
];
70 var currentText
= output
.GetText();
71 var lines
= currentText
.Split('\n');
72 if (lines
.Count() >= this.maxNbLines
)
74 output
.WriteText(lines
.Skip(lines
.Count() - this.maxNbLines
+ 1).Append(text
).Aggregate((a
, b
) => a
+ Environment
.NewLine
+ b
));
76 else if (lines
.Count() == 0)
78 output
.WriteText(text
);
82 output
.WriteText(Environment
.NewLine
+ text
, true);
87 public void PrintError(string text
, int outputNumber
= 0)
89 this.Print($"Error: {text}", outputNumber
);
93 public void Display(string text
, int outputNumber
= 0)
95 if (this.outputs
.Count() <= outputNumber
)
97 throw new Exception($"Output number {outputNumber} doesn't exist (number of output: {this.outputs.Count()}");
101 this.outputs
[outputNumber
].WriteText(text
);