Client LuaCsForBarotrauma
BarotraumaShared/SharedSource/Events/EventActions/EventLogAction.cs
1 #nullable enable
2 
3 using System;
4 using System.Xml.Linq;
5 
6 namespace Barotrauma
7 {
8 
12  partial class EventLogAction : EventAction
13  {
14  [Serialize("", IsPropertySaveable.Yes, description: "Identifier of the entry. If there's already an entry with the same id, it gets overwritten.")]
15  public Identifier Id { get; set; }
16 
17  [Serialize("", IsPropertySaveable.Yes, description: "Text to add to the event log. Can be the text as-is, or a tag referring to a line in a text file.")]
18  public string Text { get; set; }
19 
20  [Serialize("", IsPropertySaveable.Yes, description: "Tag of the character(s) who should see the entry. If empty, the entry is shown to everyone.")]
21  public Identifier TargetTag { get; set; }
22 
23  public bool ShowInServerLog { get; set; }
24 
25  private readonly XElement? textElement;
26 
27  public EventLogAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element)
28  {
29  if (Id == Identifier.Empty)
30  {
31  DebugConsole.ThrowError($"Error in event \"{parentEvent.Prefab.Identifier}\". {nameof(EventLogAction)} with no id.",
32  contentPackage: element.ContentPackage);
33  }
34  //append the target tag so logs targeted to different players don't interfere with each other even if they use the same Id
35  Id = (Id.ToString() + TargetTag).ToIdentifier();
36 
37  foreach (var elem in element.Elements())
38  {
39  if (elem.Name.LocalName.Equals("text", StringComparison.OrdinalIgnoreCase))
40  {
41  textElement = elem;
42  break;
43  }
44  }
45  Text ??= string.Empty;
46  if (textElement == null)
47  {
48  if (Text.IsNullOrEmpty())
49  {
50  DebugConsole.ThrowError($"Error in event \"{parentEvent.Prefab.Identifier}\". {nameof(EventLogAction)} with no text set ({element}).",
51  contentPackage: element.ContentPackage);
52  }
53  else
54  {
55  Text = TextManager.Get(Text).Fallback(Text).Value;
56  }
57  }
58  ShowInServerLog = element.GetAttributeBool(nameof(ShowInServerLog), ParentEvent is TraitorEvent);
59  }
60 
61  private bool isFinished;
62 
63  public override bool IsFinished(ref string goTo)
64  {
65  return isFinished;
66  }
67 
68  public override void Reset()
69  {
70  isFinished = false;
71  }
72 
73 
75  {
76  LocalizedString text = Text;
77  if (textElement != null)
78  {
79  LocalizedString tempDescription = string.Empty;
80  TextManager.ConstructDescription(ref tempDescription, textElement, ParentEvent.GetTextForReplacementElement);
81  text = tempDescription.Value;
82  }
84  }
85 
86  public override void Update(float deltaTime)
87  {
88  if (isFinished) { return; }
89  AddEntryProjSpecific(GameMain.GameSession?.EventManager?.EventLog, GetDisplayText().Value);
90  isFinished = true;
91  }
92 
93  partial void AddEntryProjSpecific(EventLog? eventLog, string displayText);
94 
95  public override string ToDebugString()
96  {
97  return $"{ToolBox.GetDebugSymbol(isFinished)} {nameof(EventLogAction)} -> (Id: {Id})";
98  }
99  }
100 }
ContentPackage? ContentPackage
readonly ScriptedEvent ParentEvent
Definition: EventAction.cs:102
Adds an entry to the "event log" displayed in the mission tab of the tab menu.
override bool IsFinished(ref string goTo)
Has the action finished.
EventLogAction(ScriptedEvent parentEvent, ContentXElement element)
override string ToDebugString()
Rich test to display in debugdraw
Used to store logs of scripted events (a sort of "quest log")
static GameSession?? GameSession
Definition: GameMain.cs:88
virtual LocalizedString ReplaceVariablesInEventText(LocalizedString str)
virtual string GetTextForReplacementElement(string tag)