Unstable 0.15.15.0 (and the one before it I forgor)
This commit is contained in:
@@ -2,16 +2,35 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace Barotrauma.Items.Components
|
||||
{
|
||||
readonly struct TerminalMessage
|
||||
{
|
||||
public readonly string Text;
|
||||
public readonly Color Color;
|
||||
|
||||
public TerminalMessage(string text, Color color)
|
||||
{
|
||||
Text = text;
|
||||
Color = color;
|
||||
}
|
||||
|
||||
public void Deconstruct(out string text, out Color color)
|
||||
{
|
||||
text = Text;
|
||||
color = Color;
|
||||
}
|
||||
}
|
||||
|
||||
partial class Terminal : ItemComponent
|
||||
{
|
||||
private const int MaxMessageLength = ChatMessage.MaxLength;
|
||||
|
||||
private const int MaxMessages = 60;
|
||||
|
||||
private List<string> messageHistory = new List<string>(MaxMessages);
|
||||
private List<TerminalMessage> messageHistory = new List<TerminalMessage>(MaxMessages);
|
||||
|
||||
public string DisplayedWelcomeMessage
|
||||
{
|
||||
@@ -37,19 +56,39 @@ namespace Barotrauma.Items.Components
|
||||
/// </summary>
|
||||
public string ShowMessage
|
||||
{
|
||||
get { return messageHistory.Count == 0 ? string.Empty : messageHistory.Last(); }
|
||||
get { return messageHistory.Count == 0 ? string.Empty : messageHistory.Last().Text; }
|
||||
set
|
||||
{
|
||||
if (string.IsNullOrEmpty(value)) { return; }
|
||||
ShowOnDisplay(value, addToHistory: true);
|
||||
ShowOnDisplay(value, addToHistory: true, TextColor);
|
||||
}
|
||||
}
|
||||
|
||||
[Editable, Serialize(false, true, description: "The terminal will use a monospace font if this box is ticked.", alwaysUseInstanceValues: true)]
|
||||
public bool UseMonospaceFont { get; set; }
|
||||
|
||||
private Color textColor = Color.LimeGreen;
|
||||
|
||||
[Editable, Serialize("50,205,50,255", true, description: "Color of the terminal text.", alwaysUseInstanceValues: true)]
|
||||
public Color TextColor
|
||||
{
|
||||
get => textColor;
|
||||
set
|
||||
{
|
||||
textColor = value;
|
||||
#if CLIENT
|
||||
if (inputBox is { } input)
|
||||
{
|
||||
input.TextColor = value;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
private string OutputValue { get; set; }
|
||||
|
||||
private string prevColorSignal;
|
||||
|
||||
public Terminal(Item item, XElement element)
|
||||
: base(item, element)
|
||||
{
|
||||
@@ -59,18 +98,39 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
partial void InitProjSpecific(XElement element);
|
||||
|
||||
partial void ShowOnDisplay(string input, bool addToHistory);
|
||||
partial void ShowOnDisplay(string input, bool addToHistory, Color color);
|
||||
|
||||
public override void ReceiveSignal(Signal signal, Connection connection)
|
||||
{
|
||||
if (connection.Name != "signal_in") { return; }
|
||||
if (signal.value.Length > MaxMessageLength)
|
||||
switch (connection.Name)
|
||||
{
|
||||
signal.value = signal.value.Substring(0, MaxMessageLength);
|
||||
}
|
||||
case "set_text":
|
||||
|
||||
string inputSignal = signal.value.Replace("\\n", "\n");
|
||||
ShowOnDisplay(inputSignal, addToHistory: true);
|
||||
if (signal.value.Length > MaxMessageLength)
|
||||
{
|
||||
signal.value = signal.value.Substring(0, MaxMessageLength);
|
||||
}
|
||||
|
||||
string inputSignal = signal.value.Replace("\\n", "\n");
|
||||
ShowOnDisplay(inputSignal, addToHistory: true, TextColor);
|
||||
break;
|
||||
case "set_text_color":
|
||||
if (signal.value != prevColorSignal)
|
||||
{
|
||||
TextColor = XMLExtensions.ParseColor(signal.value, false);
|
||||
prevColorSignal = signal.value;
|
||||
}
|
||||
break;
|
||||
case "clear_text" when signal.value != "0":
|
||||
messageHistory.Clear();
|
||||
#if CLIENT
|
||||
if (historyBox?.Content is { } history)
|
||||
{
|
||||
history.ClearChildren();
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnItemLoaded()
|
||||
@@ -83,7 +143,7 @@ namespace Barotrauma.Items.Components
|
||||
base.OnItemLoaded();
|
||||
if (!string.IsNullOrEmpty(DisplayedWelcomeMessage))
|
||||
{
|
||||
ShowOnDisplay(DisplayedWelcomeMessage, addToHistory: !isSubEditor);
|
||||
ShowOnDisplay(DisplayedWelcomeMessage, addToHistory: !isSubEditor, TextColor);
|
||||
DisplayedWelcomeMessage = "";
|
||||
//remove welcome message if a game session is running so it doesn't reappear on successive rounds
|
||||
if (GameMain.GameSession != null && !isSubEditor)
|
||||
@@ -98,7 +158,8 @@ namespace Barotrauma.Items.Components
|
||||
var componentElement = base.Save(parentElement);
|
||||
for (int i = 0; i < messageHistory.Count; i++)
|
||||
{
|
||||
componentElement.Add(new XAttribute("msg" + i, messageHistory[i]));
|
||||
componentElement.Add(new XAttribute("msg" + i, messageHistory[i].Text));
|
||||
componentElement.Add(new XAttribute("color" + i, messageHistory[i].Color.ToStringHex()));
|
||||
}
|
||||
return componentElement;
|
||||
}
|
||||
@@ -109,8 +170,9 @@ namespace Barotrauma.Items.Components
|
||||
for (int i = 0; i < MaxMessages; i++)
|
||||
{
|
||||
string msg = componentElement.GetAttributeString("msg" + i, null);
|
||||
if (msg == null) { break; }
|
||||
ShowOnDisplay(msg, addToHistory: true);
|
||||
if (msg is null) { break; }
|
||||
Color color = componentElement.GetAttributeColor("color" + i, TextColor);
|
||||
ShowOnDisplay(msg, addToHistory: true, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user