2 using System.Collections.Generic;
5 using Microsoft.Xna.Framework;
11 public readonly
string Text;
33 private const int MaxMessages = 60;
35 private readonly List<TerminalMessage> messageHistory =
new List<TerminalMessage>(MaxMessages);
43 private string welcomeMessage;
44 [
InGameEditable,
Serialize(
"",
IsPropertySaveable.Yes,
"Message to be displayed on the terminal display when it is first opened.", translationTextTag:
"terminalwelcomemsg.", alwaysUseInstanceValues:
true)]
47 get {
return welcomeMessage; }
50 if (welcomeMessage == value) {
return; }
51 welcomeMessage = value;
61 get {
return messageHistory.Count == 0 ?
string.Empty : messageHistory.Last().Text; }
64 if (
string.IsNullOrEmpty(value)) {
return; }
65 ShowOnDisplay(value, addToHistory:
true,
TextColor, isWelcomeMessage:
false);
78 private Color textColor = Color.LimeGreen;
88 if (inputBox is { } input)
90 input.TextColor = value;
105 private string OutputValue {
get;
set; }
107 private string prevColorSignal;
110 : base(
item, element)
113 InitProjSpecific(element);
116 partial
void InitProjSpecific(XElement element);
118 partial
void ShowOnDisplay(
string input,
bool addToHistory, Color color,
bool isWelcomeMessage);
122 switch (connection.
Name)
126 if (
string.IsNullOrEmpty(signal.
value)) {
return; }
127 if (signal.
value.Length > MaxMessageLength)
129 signal.
value = signal.
value.Substring(0, MaxMessageLength);
131 string inputSignal = signal.
value.Replace(
"\\n",
"\n");
132 ShowOnDisplay(inputSignal, addToHistory:
true,
TextColor, isWelcomeMessage:
false);
134 case "set_text_color":
135 if (signal.
value != prevColorSignal)
138 prevColorSignal = signal.
value;
141 case "clear_text" when signal.
value !=
"0":
142 messageHistory.Clear();
144 if (historyBox?.Content is { } history)
146 history.ClearChildren();
157 bool isSubEditor =
false;
175 public override XElement
Save(XElement parentElement)
177 var componentElement = base.Save(parentElement);
178 for (
int i = 0; i < messageHistory.Count; i++)
180 var msg = messageHistory[i];
181 componentElement.Add(
new XAttribute(
"msg" + i, msg.Text));
182 componentElement.Add(
new XAttribute(
"color" + i, msg.Color.ToStringHex()));
183 if (msg.IsWelcomeMessage)
185 componentElement.Add(
new XAttribute(
"welcomemessage" + i,
true));
188 return componentElement;
193 base.Load(componentElement, usePrefabValues, idRemap, isItemSwap);
194 for (
int i = 0; i < MaxMessages; i++)
197 if (msg is
null) {
break; }
199 bool isWelcomeMessage = componentElement.
GetAttributeBool(
"welcomemessage" + i,
false);
200 ShowOnDisplay(msg, addToHistory:
true, color, isWelcomeMessage);
string? GetAttributeString(string key, string? def)
Color GetAttributeColor(string key, in Color def)
bool GetAttributeBool(string key, bool def)
static GameSession?? GameSession
static SubEditorScreen SubEditorScreen
The base class for components holding the different functionalities of the item
override XElement Save(XElement parentElement)
LocalizedString DisplayedWelcomeMessage
override void OnItemLoaded()
Called when all the components of the item have been loaded. Use to initialize connections between co...
override void ReceiveSignal(Signal signal, Connection connection)
string? ShowMessage
Can be used to display messages on the terminal via status effects
override void Load(ContentXElement componentElement, bool usePrefabValues, IdRemap idRemap, bool isItemSwap)
bool WelcomeMessageDisplayed
Terminal(Item item, ContentXElement element)
LocalizedString Fallback(LocalizedString fallback, bool useDefaultLanguageIfFound=true)
Use this text instead if the original text cannot be found.
TerminalMessage(string text, Color color, bool isWelcomeMessage)
void Deconstruct(out string text, out Color color)
readonly bool IsWelcomeMessage