(965c31410a) Unstable v0.10.4.0

This commit is contained in:
Juan Pablo Arce
2020-07-21 08:57:50 -03:00
parent 4f8bd39789
commit 33d3a41104
546 changed files with 45952 additions and 25762 deletions
@@ -0,0 +1,365 @@
using Barotrauma.Networking;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Barotrauma.Extensions;
using Microsoft.Xna.Framework.Graphics;
namespace Barotrauma
{
partial class ConversationAction : EventAction
{
private GUIMessageBox dialogBox;
private static ConversationAction lastActiveAction;
private static GUIMessageBox lastMessageBox;
public static bool IsDialogOpen
{
get
{
return GUIMessageBox.MessageBoxes.Any(mb =>
mb.UserData as string == "ConversationAction" ||
(mb.UserData is Pair<string, UInt16> pair && pair.First == "ConversationAction"));
}
}
public static bool FadeScreenToBlack
{
get { return IsDialogOpen && shouldFadeToBlack; }
}
private static bool shouldFadeToBlack;
private bool IsBlockedByAnotherConversation(IEnumerable<Entity> _)
{
return
lastActiveAction != null &&
lastActiveAction.ParentEvent != ParentEvent &&
Timing.TotalTime < lastActiveAction.lastActiveTime + BlockOtherConversationsDuration;
}
partial void ShowDialog(Character speaker, Character targetCharacter)
{
CreateDialog(Text, speaker, Options.Select(opt => opt.Text), GetEndingOptions(), actionInstance: this, spriteIdentifier: EventSprite, fadeToBlack: FadeToBlack, dialogType: DialogType, continueConversation: ContinueConversation);
}
public static void CreateDialog(string text, Character speaker, IEnumerable<string> options, int[] closingOptions, string eventSprite, UInt16 actionId, bool fadeToBlack, DialogTypes dialogType, bool continueConversation = false)
{
CreateDialog(text, speaker, options, closingOptions, actionInstance: null, actionId: actionId, spriteIdentifier: eventSprite, fadeToBlack: fadeToBlack, dialogType: dialogType, continueConversation: continueConversation);
}
private static void CreateDialog(string text, Character speaker, IEnumerable<string> options, int[] closingOptions, string spriteIdentifier = null,
ConversationAction actionInstance = null, UInt16? actionId = null, bool fadeToBlack = false, DialogTypes dialogType = DialogTypes.Regular, bool continueConversation = false)
{
Debug.Assert(actionInstance == null || actionId == null);
shouldFadeToBlack = fadeToBlack;
if (lastMessageBox != null && !lastMessageBox.Closed && GUIMessageBox.MessageBoxes.Contains(lastMessageBox))
{
if (actionId != null && lastMessageBox.UserData is Pair<string, ushort> userData)
{
if (userData.Second == actionId) { return; }
lastMessageBox.UserData = new Pair<string, ushort>("ConversationAction", actionId.Value);
}
GUIListBox conversationList = lastMessageBox.FindChild("conversationlist", true) as GUIListBox;
Debug.Assert(conversationList != null);
// gray out the last text block
if (conversationList.Content.Children.LastOrDefault() is GUILayoutGroup lastElement)
{
if (lastElement.FindChild("text", true) is GUITextBlock textLayout)
{
textLayout.OverrideTextColor(Color.DarkGray * 0.8f);
}
}
List<GUIButton> extraButtons = CreateConversation(conversationList, text, speaker, options, string.IsNullOrWhiteSpace(spriteIdentifier));
AssignActionsToButtons(extraButtons, lastMessageBox);
RecalculateLastMessage(conversationList, true);
conversationList.ScrollToEnd(0.5f);
lastMessageBox.SetBackgroundIcon(EventSet.GetEventSprite(spriteIdentifier));
return;
}
var (relative, min) = GetSizes(dialogType);
GUIMessageBox messageBox = new GUIMessageBox(string.Empty, string.Empty, new string[0],
relativeSize: relative, minSize: min,
type: GUIMessageBox.Type.InGame, backgroundIcon: EventSet.GetEventSprite(spriteIdentifier))
{
UserData = "ConversationAction"
};
lastMessageBox = messageBox;
messageBox.InnerFrame.ClearChildren();
messageBox.AutoClose = false;
GUI.Style.Apply(messageBox.InnerFrame, "DialogBox");
if (actionInstance != null)
{
lastActiveAction = actionInstance;
actionInstance.dialogBox = messageBox;
}
else
{
messageBox.UserData = new Pair<string, UInt16>("ConversationAction", actionId.Value);
}
int padding = GUI.IntScale(16);
GUIListBox listBox = new GUIListBox(new RectTransform(messageBox.InnerFrame.Rect.Size - new Point(padding * 2), messageBox.InnerFrame.RectTransform, Anchor.Center), style: null)
{
KeepSpaceForScrollBar = true,
HoverCursor = CursorState.Default,
UserData = "conversationlist"
};
List<GUIButton> buttons = CreateConversation(listBox, text, speaker, options, string.IsNullOrWhiteSpace(spriteIdentifier));
AssignActionsToButtons(buttons, messageBox);
RecalculateLastMessage(listBox, false);
messageBox.InnerFrame.RectTransform.MinSize = new Point(0, Math.Max(listBox.RectTransform.MinSize.Y + padding * 2, (int)(100 * GUI.yScale)));
var shadow = new GUIFrame(new RectTransform(messageBox.InnerFrame.Rect.Size + new Point(padding * 4), messageBox.InnerFrame.RectTransform, Anchor.Center), style: "OuterGlow")
{
Color = Color.Black * 0.7f
};
shadow.SetAsFirstChild();
void RecalculateLastMessage(GUIListBox conversationList, bool append)
{
if (conversationList.Content.Children.LastOrDefault() is GUILayoutGroup lastElement)
{
GUILayoutGroup textLayout = lastElement.GetChild<GUILayoutGroup>();
if (lastElement.Rect.Size.Y < textLayout.Rect.Size.Y && !append)
{
lastElement.RectTransform.MinSize = textLayout.Rect.Size;
}
if (textLayout != null)
{
int textHeight = textLayout.Children.Sum(c => c.Rect.Height);
textLayout.RectTransform.MaxSize = new Point(lastElement.RectTransform.MaxSize.X, textHeight);
textLayout.Recalculate();
}
int sumHeight = lastElement.Children.Sum(c => c.Rect.Height);
lastElement.RectTransform.MaxSize = new Point(lastElement.RectTransform.MaxSize.X, sumHeight);
lastElement.Recalculate();
conversationList.RecalculateChildren();
if (!append || textLayout == null) { return; }
foreach (GUIComponent child in textLayout.Children)
{
conversationList.UpdateScrollBarSize();
float wait = conversationList.BarSize < 1.0f ? 0.5f : 0.0f;
if (child is GUITextBlock) { child.FadeIn(wait, 0.5f); }
if (child is GUIButton btn)
{
btn.FadeIn(wait, 1.0f);
btn.TextBlock.FadeIn(wait, 0.5f);
}
}
}
}
void AssignActionsToButtons(List<GUIButton> optionButtons, GUIMessageBox target)
{
if (!options.Any())
{
GUIButton closeButton = new GUIButton(new RectTransform(Vector2.One, target.InnerFrame.RectTransform, Anchor.BottomRight, scaleBasis: ScaleBasis.Smallest)
{
MaxSize = new Point(GUI.IntScale(24)),
MinSize = new Point(24),
AbsoluteOffset = new Point(GUI.IntScale(48), GUI.IntScale(16))
}, style: "GUIButtonVerticalArrow")
{
UserData = "ContinueButton",
IgnoreLayoutGroups = true,
Bounce = true,
OnClicked = (btn, userdata) =>
{
if (actionInstance != null)
{
actionInstance.selectedOption = 0;
}
else if (actionId.HasValue)
{
SendResponse(actionId.Value, 0);
}
if (!continueConversation)
{
target.Close();
}
else
{
btn.Frame.FadeOut(0.33f, true);
}
return true;
}
};
closeButton.Children.ForEach(child => child.SpriteEffects = SpriteEffects.FlipVertically);
closeButton.Frame.FadeIn(0.5f, 0.5f);
closeButton.SlideIn(0.5f, 0.33f, 16, SlideDirection.Down);
}
for (int i = 0; i < optionButtons.Count; i++)
{
optionButtons[i].UserData = i;
optionButtons[i].OnClicked += (btn, userdata) =>
{
int selectedOption = (userdata as int?) ?? 0;
if (actionInstance != null)
{
actionInstance.selectedOption = selectedOption;
foreach (GUIButton otherButton in optionButtons)
{
otherButton.CanBeFocused = false;
if (otherButton != btn)
{
otherButton.TextBlock.OverrideTextColor(Color.DarkGray * 0.8f);
}
}
btn.ExternalHighlight = true;
return true;
}
if (actionId.HasValue)
{
SendResponse(actionId.Value, selectedOption);
btn.CanBeFocused = false;
btn.ExternalHighlight = true;
foreach (GUIButton otherButton in optionButtons)
{
otherButton.CanBeFocused = false;
if (otherButton != btn)
{
otherButton.TextBlock.OverrideTextColor(Color.DarkGray * 0.8f);
}
}
return true;
}
//should not happen
return false;
};
if (closingOptions.Contains(i)) { optionButtons[i].OnClicked += target.Close; }
}
}
}
private static Tuple<Vector2, Point> GetSizes(DialogTypes dialogTypes)
{
return dialogTypes switch
{
DialogTypes.Regular => Tuple.Create(new Vector2(0.3f, 0.2f), new Point(512, 256)),
_ => Tuple.Create(new Vector2(0.3f, 0.15f), new Point(512, 128))
};
}
private static List<GUIButton> CreateConversation(GUIListBox parentBox, string text, Character speaker, IEnumerable<string> options, bool drawChathead = true)
{
var content = new GUILayoutGroup(new RectTransform(Vector2.One, parentBox.Content.RectTransform), childAnchor: Anchor.CenterLeft, isHorizontal: true)
{
Stretch = true,
CanBeFocused = true,
AlwaysOverrideCursor = true
};
string translatedText = TextManager.Get(text, returnNull: true) ?? text;
if (speaker?.Info != null && drawChathead)
{
// chathead
new GUICustomComponent(new RectTransform(new Vector2(0.15f, 0.8f), content.RectTransform), onDraw: (sb, customComponent) =>
{
speaker.Info.DrawIcon(sb, customComponent.Rect.Center.ToVector2(), customComponent.Rect.Size.ToVector2());
});
}
var textContent = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 1.0f), content.RectTransform), childAnchor: Anchor.TopCenter)
{
AbsoluteSpacing = GUI.IntScale(5)
};
var textBlock = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), textContent.RectTransform), translatedText, wrap: true)
{
AlwaysOverrideCursor = true,
UserData = "text"
};
List<GUIButton> buttons = new List<GUIButton>();
if (options.Any())
{
foreach (string option in options)
{
var btn = new GUIButton(new RectTransform(new Vector2(0.9f, 0.01f), textContent.RectTransform), TextManager.Get(option, returnNull: true) ?? option, style: "ListBoxElement");
btn.TextBlock.TextAlignment = Alignment.CenterLeft;
btn.TextColor = btn.HoverTextColor = GUI.Style.Green;
btn.TextBlock.Wrap = true;
buttons.Add(btn);
}
}
content.Recalculate();
textContent.Recalculate();
textBlock.CalculateHeightFromText();
textBlock.RectTransform.MinSize = new Point(0, (int)(textBlock.Rect.Height * 1.2f));
foreach (GUIButton btn in buttons)
{
btn.TextBlock.SetTextPos();
btn.TextBlock.CalculateHeightFromText();
btn.RectTransform.MinSize = new Point(0, (int)(btn.TextBlock.Rect.Height * 1.2f));
}
textContent.RectTransform.MinSize = new Point(0, textContent.Children.Sum(c => c.Rect.Height + textContent.AbsoluteSpacing) + GUI.IntScale(16));
// content.RectTransform.MinSize = new Point(0, textContent.Rect.Height);
return buttons;
}
private static void SendResponse(UInt16 actionId, int selectedOption)
{
IWriteMessage outmsg = new WriteOnlyMessage();
outmsg.Write((byte)ClientPacketHeader.EVENTMANAGER_RESPONSE);
outmsg.Write(actionId);
outmsg.Write((byte)selectedOption);
GameMain.Client?.ClientPeer?.Send(outmsg, DeliveryMethod.Reliable);
}
// Too broken, left it here if I ever want to come back to it
private static List<RichTextData> GetQuoteHighlights(string text, Color color)
{
char[] quotes = { '“', '”', '\"', '\'', '「', '」'};
List<RichTextData> textColors = new List<RichTextData> { new RichTextData { StartIndex = 0 } };
bool start = true;
for (int i = 0; i < text.Length; i++)
{
char c = text[i];
if (quotes.Contains(c))
{
textColors.Last().EndIndex = i - 1;
textColors.Add(new RichTextData { StartIndex = i, Color = start ? color : (Color?) null });
start = !start;
}
}
if (textColors.LastOrDefault() is { } last && last.EndIndex == 0)
{
last.EndIndex = text.Length;
}
return textColors;
}
}
}
@@ -1,6 +1,12 @@
using Microsoft.Xna.Framework;
#nullable enable
using Barotrauma.Extensions;
using Barotrauma.Networking;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
namespace Barotrauma
{
@@ -11,34 +17,43 @@ namespace Barotrauma
private float intensityGraphUpdateInterval;
private float lastIntensityUpdate;
private Event? pinnedEvent;
private Vector2 pinnedPosition = new Vector2(256, 128);
private bool isDragging;
public void DebugDraw(SpriteBatch spriteBatch)
{
foreach (ScriptedEvent ev in activeEvents)
foreach (Event ev in activeEvents)
{
Vector2 drawPos = ev.DebugDrawPos;
drawPos.Y = -drawPos.Y;
var textOffset = new Vector2(-150, 0);
ShapeExtensions.DrawCircle(spriteBatch, drawPos, 600, 6, Color.White, thickness: 20);
spriteBatch.DrawCircle(drawPos, 600, 6, Color.White, thickness: 20);
GUI.DrawString(spriteBatch, drawPos + textOffset, ev.ToString(), Color.White, Color.Black, 0, GUI.LargeFont);
}
}
public void DebugDrawHUD(SpriteBatch spriteBatch, int y)
{
foreach (ScriptedEvent scriptedEvent in activeEvents.Where(ev => !ev.IsFinished && ev is ScriptedEvent).Cast<ScriptedEvent>())
{
DrawEventTargetTags(spriteBatch, scriptedEvent);
}
GUI.DrawString(spriteBatch, new Vector2(10, y), "EventManager", Color.White, Color.Black * 0.6f, 0, GUI.SmallFont);
GUI.DrawString(spriteBatch, new Vector2(15, y + 20), "Event cooldown: " + eventCoolDown, Color.White, Color.Black * 0.6f, 0, GUI.SmallFont);
GUI.DrawString(spriteBatch, new Vector2(15, y + 35), "Current intensity: " + (int)Math.Round(currentIntensity * 100), Color.Lerp(Color.White, GUI.Style.Red, currentIntensity), Color.Black * 0.6f, 0, GUI.SmallFont);
GUI.DrawString(spriteBatch, new Vector2(15, y + 50), "Target intensity: " + (int)Math.Round(targetIntensity * 100), Color.Lerp(Color.White, GUI.Style.Red, targetIntensity), Color.Black * 0.6f, 0, GUI.SmallFont);
GUI.DrawString(spriteBatch, new Vector2(15, y + 35), "Current intensity: " + (int) Math.Round(currentIntensity * 100), Color.Lerp(Color.White, GUI.Style.Red, currentIntensity), Color.Black * 0.6f, 0, GUI.SmallFont);
GUI.DrawString(spriteBatch, new Vector2(15, y + 50), "Target intensity: " + (int) Math.Round(targetIntensity * 100), Color.Lerp(Color.White, GUI.Style.Red, targetIntensity), Color.Black * 0.6f, 0, GUI.SmallFont);
GUI.DrawString(spriteBatch, new Vector2(15, y + 65), "AvgHealth: " + (int)Math.Round(avgCrewHealth * 100), Color.Lerp(GUI.Style.Red, GUI.Style.Green, avgCrewHealth), Color.Black * 0.6f, 0, GUI.SmallFont);
GUI.DrawString(spriteBatch, new Vector2(15, y + 80), "AvgHullIntegrity: " + (int)Math.Round(avgHullIntegrity * 100), Color.Lerp(GUI.Style.Red, GUI.Style.Green, avgHullIntegrity), Color.Black * 0.6f, 0, GUI.SmallFont);
GUI.DrawString(spriteBatch, new Vector2(15, y + 95), "FloodingAmount: " + (int)Math.Round(floodingAmount * 100), Color.Lerp(GUI.Style.Green, GUI.Style.Red, floodingAmount), Color.Black * 0.6f, 0, GUI.SmallFont);
GUI.DrawString(spriteBatch, new Vector2(15, y + 110), "FireAmount: " + (int)Math.Round(fireAmount * 100), Color.Lerp(GUI.Style.Green, GUI.Style.Red, fireAmount), Color.Black * 0.6f, 0, GUI.SmallFont);
GUI.DrawString(spriteBatch, new Vector2(15, y + 125), "EnemyDanger: " + (int)Math.Round(enemyDanger * 100), Color.Lerp(GUI.Style.Green, GUI.Style.Red, enemyDanger), Color.Black * 0.6f, 0, GUI.SmallFont);
GUI.DrawString(spriteBatch, new Vector2(15, y + 65), "AvgHealth: " + (int) Math.Round(avgCrewHealth * 100), Color.Lerp(GUI.Style.Red, GUI.Style.Green, avgCrewHealth), Color.Black * 0.6f, 0, GUI.SmallFont);
GUI.DrawString(spriteBatch, new Vector2(15, y + 80), "AvgHullIntegrity: " + (int) Math.Round(avgHullIntegrity * 100), Color.Lerp(GUI.Style.Red, GUI.Style.Green, avgHullIntegrity), Color.Black * 0.6f, 0, GUI.SmallFont);
GUI.DrawString(spriteBatch, new Vector2(15, y + 95), "FloodingAmount: " + (int) Math.Round(floodingAmount * 100), Color.Lerp(GUI.Style.Green, GUI.Style.Red, floodingAmount), Color.Black * 0.6f, 0, GUI.SmallFont);
GUI.DrawString(spriteBatch, new Vector2(15, y + 110), "FireAmount: " + (int) Math.Round(fireAmount * 100), Color.Lerp(GUI.Style.Green, GUI.Style.Red, fireAmount), Color.Black * 0.6f, 0, GUI.SmallFont);
GUI.DrawString(spriteBatch, new Vector2(15, y + 125), "EnemyDanger: " + (int) Math.Round(enemyDanger * 100), Color.Lerp(GUI.Style.Green, GUI.Style.Red, enemyDanger), Color.Black * 0.6f, 0, GUI.SmallFont);
#if DEBUG
if (PlayerInput.KeyDown(Microsoft.Xna.Framework.Input.Keys.LeftAlt) &&
if (PlayerInput.KeyDown(Microsoft.Xna.Framework.Input.Keys.LeftAlt) &&
PlayerInput.KeyHit(Microsoft.Xna.Framework.Input.Keys.T))
{
eventCoolDown = 1.0f;
@@ -56,7 +71,7 @@ namespace Barotrauma
{
intensityGraph.Update(currentIntensity);
targetIntensityGraph.Update(targetIntensity);
lastIntensityUpdate = (float)Timing.TotalTime;
lastIntensityUpdate = (float) Timing.TotalTime;
}
Rectangle graphRect = new Rectangle(15, y + 150, 150, 50);
@@ -72,20 +87,19 @@ namespace Barotrauma
y = graphRect.Bottom + 20;
if (eventCoolDown > 0.0f)
{
GUI.DrawString(spriteBatch, new Vector2(graphRect.X, y), "Event cooldown active: " + (int)eventCoolDown, Color.LightGreen * 0.8f, null, 0, GUI.SmallFont);
GUI.DrawString(spriteBatch, new Vector2(graphRect.X, y), "Event cooldown active: " + (int) eventCoolDown, Color.LightGreen * 0.8f, null, 0, GUI.SmallFont);
y += 15;
}
else if (currentIntensity > eventThreshold)
{
GUI.DrawString(spriteBatch, new Vector2(graphRect.X, y),
"Intensity too high for new events: " + (int)(currentIntensity * 100) + "%/" + (int)(eventThreshold * 100) + "%", Color.LightGreen * 0.8f, null, 0, GUI.SmallFont);
"Intensity too high for new events: " + (int) (currentIntensity * 100) + "%/" + (int) (eventThreshold * 100) + "%", Color.LightGreen * 0.8f, null, 0, GUI.SmallFont);
y += 15;
}
foreach (ScriptedEventSet eventSet in pendingEventSets)
foreach (EventSet eventSet in pendingEventSets)
{
float distanceTraveled = MathHelper.Clamp(
(Submarine.MainSub.WorldPosition.X - level.StartPosition.X) / (level.EndPosition.X - level.StartPosition.X),
0.0f, 1.0f);
if (Submarine.MainSub == null) { break; }
GUI.DrawString(spriteBatch, new Vector2(graphRect.X, y), "New event (ID " + eventSet.DebugIdentifier + ") after: ", Color.Orange * 0.8f, null, 0, GUI.SmallFont);
y += 12;
@@ -94,36 +108,421 @@ namespace Barotrauma
roundDuration < eventSet.MinMissionTime)
{
GUI.DrawString(spriteBatch, new Vector2(graphRect.X, y),
" " + (int)(eventSet.MinDistanceTraveled * 100.0f) + "% travelled (current: " + (int)(distanceTraveled * 100.0f) + " %)",
" " + (int) (eventSet.MinDistanceTraveled * 100.0f) + "% travelled (current: " + (int) (distanceTraveled * 100.0f) + " %)",
Color.Orange * 0.8f, null, 0, GUI.SmallFont);
y += 12;
}
if (CurrentIntensity < eventSet.MinIntensity || CurrentIntensity > eventSet.MaxIntensity)
{
GUI.DrawString(spriteBatch, new Vector2(graphRect.X, y),
" intensity between " + ((int)eventSet.MinIntensity) + " and " + ((int)eventSet.MaxIntensity),
" intensity between " + ((int) eventSet.MinIntensity) + " and " + ((int) eventSet.MaxIntensity),
Color.Orange * 0.8f, null, 0, GUI.SmallFont);
y += 12;
}
if (roundDuration < eventSet.MinMissionTime)
{
GUI.DrawString(spriteBatch, new Vector2(graphRect.X, y),
" " + (int)(eventSet.MinMissionTime - roundDuration) + " s",
" " + (int) (eventSet.MinMissionTime - roundDuration) + " s",
Color.Orange * 0.8f, null, 0, GUI.SmallFont);
}
y += 15;
}
GUI.DrawString(spriteBatch, new Vector2(graphRect.X, y), "Current events: ", Color.White * 0.9f, null, 0, GUI.SmallFont);
y += 12;
foreach (ScriptedEvent scriptedEvent in activeEvents)
y += 15;
foreach (Event ev in activeEvents.Where(ev => !ev.IsFinished || PlayerInput.IsShiftDown()))
{
if (scriptedEvent.IsFinished) { continue; }
GUI.DrawString(spriteBatch, new Vector2(graphRect.X + 5, y), scriptedEvent.ToString(), Color.White * 0.8f, null, 0, GUI.SmallFont);
y += 12;
GUI.DrawString(spriteBatch, new Vector2(graphRect.X + 5, y), ev.ToString(), (!ev.IsFinished ? Color.White : Color.Red) * 0.8f, null, 0, GUI.SmallFont);
Rectangle rect = new Rectangle(new Point(graphRect.X + 5, y), GUI.SmallFont.MeasureString(ev.ToString()).ToPoint());
Rectangle outlineRect = new Rectangle(rect.Location, rect.Size);
outlineRect.Inflate(4, 4);
if (pinnedEvent == ev) { GUI.DrawRectangle(spriteBatch, outlineRect, Color.White); }
if (rect.Contains(PlayerInput.MousePosition))
{
GUI.MouseCursor = CursorState.Hand;
GUI.DrawRectangle(spriteBatch, outlineRect, Color.White);
if (ev != pinnedEvent)
{
DrawEvent(spriteBatch, ev, rect);
}
else if (PlayerInput.SecondaryMouseButtonHeld() || PlayerInput.SecondaryMouseButtonDown())
{
pinnedEvent = null;
}
if (PlayerInput.PrimaryMouseButtonHeld() || PlayerInput.PrimaryMouseButtonDown())
{
pinnedEvent = ev;
}
}
y += 18;
}
}
public void DrawPinnedEvent(SpriteBatch spriteBatch)
{
if (pinnedEvent != null)
{
Rectangle rect = DrawEvent(spriteBatch, pinnedEvent, null);
if (rect != Rectangle.Empty)
{
if (rect.Contains(PlayerInput.MousePosition) && !isDragging)
{
GUI.MouseCursor = CursorState.Move;
if (PlayerInput.PrimaryMouseButtonDown() || PlayerInput.PrimaryMouseButtonHeld())
{
isDragging = true;
}
if (PlayerInput.SecondaryMouseButtonClicked() || PlayerInput.SecondaryMouseButtonHeld())
{
pinnedEvent = null;
isDragging = false;
}
}
}
if (isDragging)
{
GUI.MouseCursor = CursorState.Dragging;
pinnedPosition = PlayerInput.MousePosition - (new Vector2(rect.Width / 2.0f, -24));
if (!PlayerInput.PrimaryMouseButtonHeld())
{
isDragging = false;
}
}
}
}
private static void DrawEventTargetTags(SpriteBatch spriteBatch, ScriptedEvent scriptedEvent)
{
if (Screen.Selected is GameScreen screen)
{
Camera cam = screen.Cam;
Dictionary<Entity, List<string>> tagsDictionary = new Dictionary<Entity, List<string>>();
foreach ((string key, List<Entity> value) in scriptedEvent.Targets)
{
foreach (Entity entity in value)
{
if (tagsDictionary.ContainsKey(entity))
{
tagsDictionary[entity].Add(key);
}
else
{
tagsDictionary.Add(entity, new List<string> { key });
}
}
}
string identifier = scriptedEvent.Prefab.Identifier;
foreach ((Entity entity, List<string> tags) in tagsDictionary)
{
if (entity.Removed) { continue; }
string text = tags.Aggregate("Tags:\n", (current, tag) => current + $" {tag.ColorizeObject()}\n").TrimEnd('\r', '\n');
if (!string.IsNullOrWhiteSpace(identifier)) { text = $"Event: {identifier.ColorizeObject()}\n{text}"; }
List<RichTextData> richTextData = RichTextData.GetRichTextData(text, out text);
Vector2 entityPos = cam.WorldToScreen(entity.WorldPosition);
Vector2 infoSize = GUI.SmallFont.MeasureString(text);
Vector2 infoPos = entityPos + new Vector2(128 * cam.Zoom, -(128 * cam.Zoom));
infoPos.Y -= infoSize.Y / 2;
Rectangle infoRect = new Rectangle(infoPos.ToPoint(), infoSize.ToPoint());
infoRect.Inflate(4, 4);
GUI.DrawRectangle(spriteBatch, infoRect, Color.Black * 0.8f, isFilled: true);
GUI.DrawRectangle(spriteBatch, infoRect, Color.White, isFilled: false);
GUI.DrawStringWithColors(spriteBatch, infoPos, text, Color.White, richTextData, font: GUI.SmallFont);
GUI.DrawLine(spriteBatch, entityPos, new Vector2(infoRect.Location.X, infoRect.Location.Y + infoRect.Height / 2), Color.White);
}
}
}
private readonly struct DebugLine
{
public readonly Vector2 Position;
public readonly Color Color;
public DebugLine(Vector2 position, Color color)
{
Position = position;
Color = color;
}
}
private Rectangle DrawEvent(SpriteBatch spriteBatch, Event ev, Rectangle? parentRect = null)
{
return ev switch
{
ScriptedEvent scriptedEvent => DrawScriptedEvent(spriteBatch, scriptedEvent, parentRect),
ArtifactEvent artifactEvent => DrawArtifactEvent(spriteBatch, artifactEvent, parentRect),
MonsterEvent monsterEvent => DrawMonsterEvent(spriteBatch, monsterEvent, parentRect),
_ => Rectangle.Empty
};
}
private Rectangle DrawScriptedEvent(SpriteBatch spriteBatch, ScriptedEvent scriptedEvent, Rectangle? parentRect = null)
{
EventAction? currentEvent = !scriptedEvent.IsFinished ? scriptedEvent.Actions[scriptedEvent.CurrentActionIndex] : null;
List<DebugLine> positions = new List<DebugLine>();
string text = $"Finished: {scriptedEvent.IsFinished.ColorizeObject()}\n" +
$"Action index: {scriptedEvent.CurrentActionIndex.ColorizeObject()}\n" +
$"Current action: {currentEvent?.ToDebugString() ?? ToolBox.ColorizeObject(null)}\n";
text += "All actions:\n";
text += FindActions(scriptedEvent).Aggregate(string.Empty, (current, action) => current + $"{new string(' ', action.Item1 * 6)}{action.Item2.ToDebugString()}\n");
text += "Targets:\n";
foreach (var (key, value) in scriptedEvent.Targets)
{
text += $" {key.ColorizeObject()}: {value.Aggregate(string.Empty, (current, entity) => current + $"{entity.ColorizeObject()} ")}\n";
}
if (scriptedEvent.Targets != null)
{
foreach ((_, List<Entity> entities) in scriptedEvent.Targets)
{
if (entities == null || !entities.Any()) { continue; }
foreach (var entity in entities)
{
positions.Add(new DebugLine(entity.WorldPosition, Color.White));
}
}
}
return DrawInfoRectangle(spriteBatch, scriptedEvent, text, parentRect, positions);
}
private Rectangle DrawArtifactEvent(SpriteBatch spriteBatch, ArtifactEvent artifactEvent, Rectangle? parentRect = null)
{
List<DebugLine> positions = new List<DebugLine>();
string text = $"Finished: {artifactEvent.IsFinished.ColorizeObject()}\n" +
$"Item: {artifactEvent.Item.ColorizeObject()}\n" +
$"Spawn pending: {artifactEvent.SpawnPending.ColorizeObject()}\n" +
$"Spawn position: {artifactEvent.SpawnPos.ColorizeObject()}\n";
if (artifactEvent.Item != null)
{
Vector2 pos = artifactEvent.Item.WorldPosition;
positions.Add(new DebugLine(pos, Color.White));
}
return DrawInfoRectangle(spriteBatch, artifactEvent, text, parentRect, positions);
}
private Rectangle DrawMonsterEvent(SpriteBatch spriteBatch, MonsterEvent monsterEvent, Rectangle? parentRect = null)
{
List<DebugLine> positions = new List<DebugLine>();
string text = $"Finished: {monsterEvent.IsFinished.ColorizeObject()}\n" +
$"Amount: {monsterEvent.MinAmount.ColorizeObject()} - {monsterEvent.MaxAmount.ColorizeObject()}\n" +
$"Spawn pending: {monsterEvent.SpawnPending.ColorizeObject()}\n" +
$"Spawn position: {monsterEvent.SpawnPos.ColorizeObject()}\n";
if (monsterEvent.SpawnPos != null && Submarine.MainSub != null)
{
Vector2 pos = monsterEvent.SpawnPos.Value;
text += $"Distance from submarine: {Vector2.Distance(pos, Submarine.MainSub.WorldPosition).ColorizeObject()}\n";
positions.Add(new DebugLine(pos, Color.White));
}
if (monsterEvent.Monsters != null)
{
text += !monsterEvent.Monsters.Any() ? $"Monsters: {"None".ColorizeObject()}" : "Monsters:\n";
foreach (Character monster in monsterEvent.Monsters)
{
text += $" {monster.ColorizeObject()} -> (Dead: {monster.IsDead.ColorizeObject()}, Health: {monster.HealthPercentage.ColorizeObject()}%, AIState: {(monster.AIController?.State).ColorizeObject()})\n";
positions.Add(new DebugLine(monster.WorldPosition, Color.Red));
}
}
return DrawInfoRectangle(spriteBatch, monsterEvent, text, parentRect, positions);
}
private Rectangle DrawInfoRectangle(SpriteBatch spriteBatch, Event @event, string text, Rectangle? parentRect = null, List<DebugLine>? drawPoints = null)
{
text = text.TrimEnd('\r', '\n');
string identifier = @event.Prefab.Identifier;
if (!string.IsNullOrWhiteSpace(identifier))
{
text = $"Identifier: {identifier.ColorizeObject()}\n{text}";
}
List<RichTextData> richTextData = RichTextData.GetRichTextData(text, out text);
Vector2 size = GUI.SmallFont.MeasureString(text);
Vector2 pos = pinnedPosition;
Rectangle infoRect;
Rectangle? infoBarRect = null;
if (parentRect != null)
{
Rectangle rect = parentRect.Value;
pos = new Vector2(350, GameMain.GraphicsHeight / 2.0f - size.Y / 2);
infoRect = new Rectangle(pos.ToPoint(), size.ToPoint());
infoRect.Inflate(8, 8);
GUI.DrawLine(spriteBatch, new Vector2(rect.Right, rect.Y + rect.Height / 2), new Vector2(infoRect.X, infoRect.Y + infoRect.Height / 2), Color.White);
}
else
{
infoRect = new Rectangle(pos.ToPoint(), size.ToPoint());
infoRect.Inflate(8, 8);
Rectangle barRect = new Rectangle(infoRect.Left, infoRect.Top - 32, infoRect.Width, 32);
const string titleHeader = "Pinned event";
GUI.DrawRectangle(spriteBatch, barRect, Color.DarkGray * 0.8f, isFilled: true);
GUI.DrawString(spriteBatch, barRect.Location.ToVector2() + barRect.Size.ToVector2() / 2 - GUI.SubHeadingFont.MeasureString(titleHeader) / 2, titleHeader, Color.White);
GUI.DrawRectangle(spriteBatch, barRect, Color.White);
infoBarRect = barRect;
}
if (drawPoints != null && drawPoints.Any() && Screen.Selected?.Cam != null)
{
foreach (DebugLine line in drawPoints)
{
if (line.Position != Vector2.Zero)
{
float xPos = infoRect.Right;
if (parentRect == null && pinnedPosition.X + infoRect.Width / 2.0f > GameMain.GraphicsWidth / 2.0f)
{
xPos = infoRect.Left;
}
GUI.DrawLine(spriteBatch, new Vector2(xPos, infoRect.Top + infoRect.Height / 2), Screen.Selected.Cam.WorldToScreen(line.Position), line.Color);
}
}
}
GUI.DrawRectangle(spriteBatch, infoRect, Color.Black * 0.8f, isFilled: true);
GUI.DrawRectangle(spriteBatch, infoRect, Color.White);
GUI.DrawStringWithColors(spriteBatch, pos, text, Color.White, richTextData, null, 0, GUI.SmallFont);
richTextData.Clear();
return infoBarRect ?? infoRect;
}
public void ClientRead(IReadMessage msg)
{
NetworkEventType eventType = (NetworkEventType)msg.ReadByte();
switch (eventType)
{
case NetworkEventType.STATUSEFFECT:
string eventIdentifier = msg.ReadString();
UInt16 actionIndex = msg.ReadUInt16();
UInt16 targetCount = msg.ReadUInt16();
List<Entity> targets = new List<Entity>();
for (int i = 0; i < targetCount; i++)
{
UInt16 targetID = msg.ReadUInt16();
Entity target = Entity.FindEntityByID(targetID);
if (target != null) { targets.Add(target); }
}
var eventPrefab = EventSet.GetEventPrefab(eventIdentifier);
if (eventPrefab == null) { return; }
int j = 0;
foreach (XElement element in eventPrefab.ConfigElement.Descendants())
{
if (j != actionIndex)
{
j++;
continue;
}
foreach (XElement subElement in element.Elements())
{
if (!subElement.Name.ToString().Equals("statuseffect", StringComparison.OrdinalIgnoreCase)) { continue; }
StatusEffect effect = StatusEffect.Load(subElement, $"EventManager.ClientRead ({eventIdentifier})");
foreach (Entity target in targets)
{
effect.Apply(effect.type, 1.0f, target, target as ISerializableEntity);
}
}
break;
}
break;
case NetworkEventType.CONVERSATION:
UInt16 identifier = msg.ReadUInt16();
string eventSprite = msg.ReadString();
byte dialogType = msg.ReadByte();
bool continueConversation = msg.ReadBoolean();
UInt16 speakerId = msg.ReadUInt16();
string text = msg.ReadString();
bool fadeToBlack = msg.ReadBoolean();
byte optionCount = msg.ReadByte();
List<string> options = new List<string>();
for (int i = 0; i < optionCount; i++)
{
options.Add(msg.ReadString());
}
byte endCount = msg.ReadByte();
int[] endings = new int[endCount];
for (int i = 0; i < endCount; i++)
{
endings[i] = msg.ReadByte();
}
if (string.IsNullOrEmpty(text) && optionCount == 0)
{
GUIMessageBox.MessageBoxes.ForEachMod(mb =>
{
if (mb.UserData is Pair<string, UInt16> pair && pair.First == "ConversationAction" && pair.Second == identifier)
{
(mb as GUIMessageBox)?.Close();
}
});
}
else
{
ConversationAction.CreateDialog(text, Entity.FindEntityByID(speakerId) as Character, options, endings, eventSprite, identifier, fadeToBlack, (ConversationAction.DialogTypes)dialogType, continueConversation);
}
if (Entity.FindEntityByID(speakerId) is Character speaker)
{
speaker.CampaignInteractionType = CampaignMode.InteractionType.None;
speaker.SetCustomInteract(null, null);
}
break;
case NetworkEventType.MISSION:
string missionIdentifier = msg.ReadString();
MissionPrefab? prefab = MissionPrefab.List.Find(mp => mp.Identifier.Equals(missionIdentifier, StringComparison.OrdinalIgnoreCase));
if (prefab != null)
{
new GUIMessageBox(string.Empty, TextManager.GetWithVariable("missionunlocked", "[missionname]", prefab.Name),
new string[0], type: GUIMessageBox.Type.InGame, icon: prefab.Icon, relativeSize: new Vector2(0.3f, 0.15f), minSize: new Point(512, 128))
{
IconColor = prefab.IconColor
};
}
break;
}
}
}
}
}
@@ -6,6 +6,7 @@ namespace Barotrauma
{
public override void ClientReadInitial(IReadMessage msg)
{
items.Clear();
ushort itemCount = msg.ReadUInt16();
for (int i = 0; i < itemCount; i++)
{
@@ -17,7 +18,7 @@ namespace Barotrauma
}
if (items.Count != itemCount)
{
throw new System.Exception("Error in CargoMission.ClientReadInitial: item count does not match the server count (" + itemCount + " != " + items.Count + "mission: " + Prefab.Identifier + ")");
throw new System.Exception("Error in CargoMission.ClientReadInitial: item count does not match the server count (" + itemCount + " != " + items.Count + ", mission: " + Prefab.Identifier + ")");
}
if (requiredDeliveryAmount == 0) { requiredDeliveryAmount = items.Count; }
}
@@ -1,4 +1,5 @@
using Barotrauma.Networking;
using System.Collections.Generic;
namespace Barotrauma
{
@@ -13,10 +14,20 @@ namespace Barotrauma
string header = messageIndex < Headers.Count ? Headers[messageIndex] : "";
string message = messageIndex < Messages.Count ? Messages[messageIndex] : "";
CoroutineManager.StartCoroutine(ShowMessageBoxAfterRoundSummary(header, message));
}
private IEnumerable<object> ShowMessageBoxAfterRoundSummary(string header, string message)
{
while (GUIMessageBox.VisibleBox?.UserData is RoundSummary)
{
yield return new WaitForSeconds(1.0f);
}
new GUIMessageBox(header, message, buttons: new string[0], type: GUIMessageBox.Type.InGame, icon: Prefab.Icon)
{
IconColor = Prefab.IconColor
};
yield return CoroutineStatus.Success;
}
public void ClientRead(IReadMessage msg)