Merge remote-tracking branch 'upstream/master' into develop

This commit is contained in:
EvilFactory
2024-06-18 12:19:13 -03:00
263 changed files with 7788 additions and 2849 deletions
@@ -781,7 +781,7 @@ namespace Barotrauma.CharacterEditor
// Lightmaps
if (GameMain.LightManager.LightingEnabled && Character.Controlled != null)
{
GameMain.LightManager.ObstructVision = Character.Controlled.ObstructVision;
GameMain.LightManager.ObstructVisionAmount = Character.Controlled.ObstructVisionAmount;
GameMain.LightManager.RenderLightMap(graphics, spriteBatch, cam);
GameMain.LightManager.UpdateObstructVision(graphics, spriteBatch, cam, Character.Controlled.CursorWorldPosition);
}
@@ -1,4 +1,4 @@
using Barotrauma.Extensions;
using Barotrauma.Extensions;
using Barotrauma.Lights;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
@@ -178,10 +178,15 @@ namespace Barotrauma
Stopwatch sw = new Stopwatch();
sw.Start();
GameMain.LightManager.ObstructVision =
Character.Controlled != null &&
Character.Controlled.ObstructVision &&
(Character.Controlled.ViewTarget == Character.Controlled || Character.Controlled.ViewTarget == null);
if (Character.Controlled != null &&
(Character.Controlled.ViewTarget == Character.Controlled || Character.Controlled.ViewTarget == null))
{
GameMain.LightManager.ObstructVisionAmount = Character.Controlled.ObstructVisionAmount;
}
else
{
GameMain.LightManager.ObstructVisionAmount = 0.0f;
}
GameMain.LightManager.UpdateObstructVision(graphics, spriteBatch, cam, Character.Controlled?.CursorWorldPosition ?? Vector2.Zero);
@@ -71,7 +71,7 @@ namespace Barotrauma
currentLevelData = LevelData.CreateRandom(seedBox.Text, generationParams: selectedParams);
editorContainer.ClearChildren();
SortLevelObjectsList(currentLevelData);
new SerializableEntityEditor(editorContainer.Content.RectTransform, selectedParams, false, true, elementHeight: 20);
new SerializableEntityEditor(editorContainer.Content.RectTransform, selectedParams, inGame: false, showName: true, elementHeight: 20, titleFont: GUIStyle.LargeFont);
return true;
};
@@ -996,7 +996,7 @@ namespace Barotrauma
{
foreach (Item item in Item.ItemList)
{
if (item == null || item.HiddenInGame) { continue; }
if (item == null || item.IsHidden) { continue; }
foreach (var light in item.GetComponents<Items.Components.LightComponent>())
{
light.Update((float)deltaTime, Cam);
@@ -63,6 +63,9 @@ namespace Barotrauma
private GUITickBox spectateBox;
public bool Spectating => spectateBox is { Selected: true, Visible: true };
public bool PermadeathMode => GameMain.Client?.ServerSettings?.RespawnMode == RespawnMode.Permadeath;
public bool PermanentlyDead => campaignCharacterInfo?.PermanentlyDead ?? false;
private GUILayoutGroup playerInfoContent;
private GUIComponent changesPendingText;
private bool createPendingChangesText = true;
@@ -87,7 +90,14 @@ namespace Barotrauma
private GUIFrame characterInfoFrame;
private GUIFrame appearanceFrame;
private readonly List<GUIComponent> respawnSettingsElements = new List<GUIComponent>();
private GUISelectionCarousel<RespawnMode> respawnModeSelection;
private GUITextBlock respawnModeLabel;
private GUIComponent respawnIntervalElement;
private readonly List<GUIComponent> midRoundRespawnSettings = new List<GUIComponent>();
private readonly List<GUIComponent> permadeathEnabledRespawnSettings = new List<GUIComponent>();
private readonly List<GUIComponent> permadeathDisabledRespawnSettings = new List<GUIComponent>();
private readonly List<GUIComponent> ironmanDisabledRespawnSettings = new List<GUIComponent>();
private readonly List<GUIComponent> campaignDisabledElements = new List<GUIComponent>();
public CharacterInfo.AppearanceCustomizationMenu CharacterAppearanceCustomizationMenu { get; set; }
@@ -191,7 +201,7 @@ namespace Barotrauma
public bool UsingShuttle
{
get { return shuttleTickBox.Selected; }
get { return shuttleTickBox.Selected && !PermadeathMode; }
set { shuttleTickBox.Selected = value; }
}
@@ -955,19 +965,17 @@ namespace Barotrauma
// ------------------------------------------------------------------
var respawnBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), settingsContent.RectTransform) { AbsoluteOffset = new Point((int)respawnSettingsHeader.Padding.X, 0) },
TextManager.Get("ServerSettingsAllowRespawning"))
var respawnModeHolder = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.1f), settingsContent.RectTransform), isHorizontal: true, childAnchor: Anchor.CenterLeft) { Stretch = true };
respawnModeLabel = new GUITextBlock(new RectTransform(new Vector2(0.4f, 0.0f), respawnModeHolder.RectTransform), TextManager.Get("RespawnMode"), wrap: true);
respawnModeSelection = new GUISelectionCarousel<RespawnMode>(new RectTransform(new Vector2(0.6f, 1.0f), respawnModeHolder.RectTransform));
foreach (var respawnMode in Enum.GetValues(typeof(RespawnMode)).Cast<RespawnMode>())
{
ToolTip = TextManager.Get("RespawnExplanation"),
OnSelected = (tickbox) =>
{
GameMain.Client?.ServerSettings.ClientAdminWrite(ServerSettings.NetFlags.Properties);
RefreshEnabledElements();
return true;
}
};
AssignComponentToServerSetting(respawnBox, nameof(ServerSettings.AllowRespawn));
clientDisabledElements.Add(respawnBox);
respawnModeSelection.AddElement(respawnMode, TextManager.Get($"respawnmode.{respawnMode}"), TextManager.Get($"respawnmode.{respawnMode}.tooltip"));
}
respawnModeSelection.ElementSelectionCondition += (value) => value != RespawnMode.Permadeath || SelectedMode == GameModePreset.MultiPlayerCampaign;
respawnModeSelection.OnValueChanged += (_) => GameMain.Client?.ServerSettings.ClientAdminWrite(ServerSettings.NetFlags.Properties);
AssignComponentToServerSetting(respawnModeSelection, nameof(ServerSettings.RespawnMode));
GUILayoutGroup shuttleHolder = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.05f), settingsContent.RectTransform), isHorizontal: true)
{
@@ -977,7 +985,7 @@ namespace Barotrauma
shuttleTickBox = new GUITickBox(new RectTransform(Vector2.One, shuttleHolder.RectTransform), TextManager.Get("RespawnShuttle"))
{
ToolTip = TextManager.Get("RespawnShuttleExplanation"),
Selected = true,
Selected = !PermadeathMode,
OnSelected = (GUITickBox box) =>
{
GameMain.Client?.ServerSettings.ClientAdminWrite(ServerSettings.NetFlags.Properties);
@@ -985,7 +993,7 @@ namespace Barotrauma
}
};
AssignComponentToServerSetting(shuttleTickBox, nameof(ServerSettings.UseRespawnShuttle));
respawnSettingsElements.Add(shuttleTickBox);
midRoundRespawnSettings.Add(shuttleTickBox);
shuttleTickBox.TextBlock.RectTransform.SizeChanged += () =>
{
@@ -1008,9 +1016,9 @@ namespace Barotrauma
};
ShuttleList.ListBox.RectTransform.MinSize = new Point(250, 0);
shuttleHolder.RectTransform.MinSize = new Point(0, ShuttleList.RectTransform.Children.Max(c => c.MinSize.Y));
respawnSettingsElements.Add(ShuttleList);
midRoundRespawnSettings.Add(ShuttleList);
var respawnIntervalElement = CreateLabeledSlider(settingsContent, "ServerSettingsRespawnInterval", "", "", out var respawnIntervalSlider, out var respawnIntervalSliderLabel,
respawnIntervalElement = CreateLabeledSlider(settingsContent, "ServerSettingsRespawnInterval", "", "", out var respawnIntervalSlider, out var respawnIntervalSliderLabel,
range: new Vector2(10.0f, 600.0f));
LocalizedString intervalLabel = respawnIntervalSliderLabel.Text;
respawnIntervalSlider.StepValue = 10.0f;
@@ -1026,7 +1034,6 @@ namespace Barotrauma
return true;
};
respawnIntervalSlider.OnMoved(respawnIntervalSlider, respawnIntervalSlider.BarScroll);
respawnSettingsElements.AddRange(respawnIntervalElement.GetAllChildren());
AssignComponentToServerSetting(respawnIntervalSlider, nameof(ServerSettings.RespawnInterval));
var minRespawnElement = CreateLabeledSlider(settingsContent, "ServerSettingsMinRespawn", "", "ServerSettingsMinRespawnToolTip", out var minRespawnSlider, out var minRespawnSliderLabel,
@@ -1043,7 +1050,7 @@ namespace Barotrauma
return true;
};
minRespawnSlider.OnMoved(minRespawnSlider, minRespawnSlider.BarScroll);
respawnSettingsElements.AddRange(minRespawnElement.GetAllChildren());
midRoundRespawnSettings.AddRange(minRespawnElement.GetAllChildren());
AssignComponentToServerSetting(minRespawnSlider, nameof(ServerSettings.MinRespawnRatio));
var respawnDurationElement = CreateLabeledSlider(settingsContent, "ServerSettingsRespawnDuration", "", "ServerSettingsRespawnDurationTooltip", out var respawnDurationSlider, out var respawnDurationSliderLabel,
@@ -1068,7 +1075,7 @@ namespace Barotrauma
return value <= 0.0f ? 1.0f : (value - scrollBar.Range.X) / (scrollBar.Range.Y - scrollBar.Range.X);
};
respawnDurationSlider.OnMoved(respawnDurationSlider, respawnDurationSlider.BarScroll);
respawnSettingsElements.AddRange(respawnDurationElement.GetAllChildren());
midRoundRespawnSettings.AddRange(respawnDurationElement.GetAllChildren());
AssignComponentToServerSetting(respawnDurationSlider, nameof(ServerSettings.MaxTransportTime));
var skillLossElement = CreateLabeledSlider(settingsContent, "ServerSettingsSkillLossPercentageOnDeath", "", "ServerSettingsSkillLossPercentageOnDeathToolTip",
@@ -1085,7 +1092,8 @@ namespace Barotrauma
GameMain.Client?.ServerSettings.ClientAdminWrite(ServerSettings.NetFlags.Properties);
return true;
};
respawnSettingsElements.AddRange(skillLossElement.GetAllChildren());
permadeathDisabledRespawnSettings.AddRange(skillLossElement.GetAllChildren());
clientDisabledElements.AddRange(skillLossElement.GetAllChildren());
AssignComponentToServerSetting(skillLossSlider, nameof(ServerSettings.SkillLossPercentageOnDeath));
skillLossSlider.OnMoved(skillLossSlider, skillLossSlider.BarScroll);
@@ -1103,11 +1111,41 @@ namespace Barotrauma
GameMain.Client?.ServerSettings.ClientAdminWrite(ServerSettings.NetFlags.Properties);
return true;
};
respawnSettingsElements.AddRange(skillLossImmediateRespawnElement.GetAllChildren());
midRoundRespawnSettings.AddRange(skillLossImmediateRespawnElement.GetAllChildren());
permadeathDisabledRespawnSettings.AddRange(skillLossImmediateRespawnElement.GetAllChildren());
AssignComponentToServerSetting(skillLossImmediateRespawnSlider, nameof(ServerSettings.SkillLossPercentageOnImmediateRespawn));
skillLossImmediateRespawnSlider.OnMoved(skillLossImmediateRespawnSlider, skillLossImmediateRespawnSlider.BarScroll);
foreach (var respawnElement in respawnSettingsElements)
var allowBotTakeoverTickbox = new GUITickBox(new RectTransform(Vector2.One, settingsContent.RectTransform), TextManager.Get("AllowBotTakeover"))
{
ToolTip = TextManager.Get("AllowBotTakeover.Tooltip"),
Selected = GameMain.Client != null && GameMain.Client.ServerSettings.AllowBotTakeoverOnPermadeath,
OnSelected = (GUITickBox box) =>
{
GameMain.Client?.ServerSettings.ClientAdminWrite(ServerSettings.NetFlags.Properties);
return true;
}
};
AssignComponentToServerSetting(allowBotTakeoverTickbox, nameof(ServerSettings.AllowBotTakeoverOnPermadeath));
permadeathEnabledRespawnSettings.Add(allowBotTakeoverTickbox);
ironmanDisabledRespawnSettings.Add(allowBotTakeoverTickbox);
clientDisabledElements.Add(allowBotTakeoverTickbox);
var ironmanTickbox = new GUITickBox(new RectTransform(Vector2.One, settingsContent.RectTransform), TextManager.Get("IronmanMode").ToUpper())
{
ToolTip = TextManager.Get("IronmanMode.Tooltip"),
Selected = GameMain.Client != null && GameMain.Client.ServerSettings.IronmanMode,
OnSelected = (GUITickBox box) =>
{
GameMain.Client?.ServerSettings.ClientAdminWrite(ServerSettings.NetFlags.Properties);
return true;
}
};
AssignComponentToServerSetting(ironmanTickbox, nameof(ServerSettings.IronmanMode));
permadeathEnabledRespawnSettings.Add(ironmanTickbox);
clientDisabledElements.Add(ironmanTickbox);
foreach (var respawnElement in midRoundRespawnSettings)
{
if (!clientDisabledElements.Contains(respawnElement))
{
@@ -1650,19 +1688,31 @@ namespace Barotrauma
bool campaignStarted = CampaignFrame.Visible;
bool gameStarted = client != null && client.GameStarted;
//disable elements the client doesn't have access to
// First, enable or disable elements based on client permissions
foreach (var element in clientDisabledElements)
{
element.Enabled = manageSettings;
}
// Then disable elements depending on other conditions
traitorElements.ForEach(e => e.Enabled &= settings.TraitorProbability > 0);
SetTraitorDangerIndicators(settings.TraitorDangerLevel);
respawnSettingsElements.ForEach(e => e.Enabled &= settings.AllowRespawn);
respawnModeSelection.Enabled = respawnModeLabel.Enabled = manageSettings && !gameStarted;
midRoundRespawnSettings.ForEach(e => e.Enabled &= settings.RespawnMode == RespawnMode.MidRound);
permadeathDisabledRespawnSettings.ForEach(e => e.Enabled &= settings.RespawnMode != RespawnMode.Permadeath);
permadeathEnabledRespawnSettings.ForEach(e => e.Enabled &= settings.RespawnMode == RespawnMode.Permadeath && !gameStarted);
ironmanDisabledRespawnSettings.ForEach(e => e.Enabled &= !settings.IronmanMode);
// The respawn interval is used even if the shuttle is not
respawnIntervalElement.GetAllChildren().ForEach(e => e.Enabled = settings.RespawnMode != RespawnMode.BetweenRounds && manageSettings);
//go through the individual elements that are only enabled in a specific context
shuttleTickBox.Enabled &= !gameStarted;
if (ShuttleList != null)
{
ShuttleList.Enabled = ShuttleList.ButtonEnabled = HasPermission(ClientPermissions.SelectSub) && !gameStarted && settings.AllowRespawn;
// Shuttle list depends on shuttle tickbox
ShuttleList.Enabled &= shuttleTickBox.Enabled && HasPermission(ClientPermissions.SelectSub);
ShuttleList.ButtonEnabled = ShuttleList.Enabled;
}
if (SubList != null)
{
@@ -1672,7 +1722,6 @@ namespace Barotrauma
{
ModeList.Enabled = !gameStarted && (settings.AllowModeVoting || HasPermission(ClientPermissions.SelectMode));
}
shuttleTickBox.Enabled &= !gameStarted;
RefreshStartButtonVisibility();
@@ -1750,6 +1799,10 @@ namespace Barotrauma
private void UpdatePlayerFrame(CharacterInfo characterInfo, bool allowEditing, GUIComponent parent, bool createPendingText = true)
{
if (GameMain.Client == null) { return; }
// When permanently dead and still characterless, spectating is the only option
spectateBox.Enabled = !PermanentlyDead;
createPendingChangesText = createPendingText;
if (characterInfo == null || CampaignCharacterDiscarded)
{
@@ -1780,41 +1833,57 @@ namespace Barotrauma
MaxTextLength = Client.MaxNameLength,
OverflowClip = true
};
CharacterNameBox.OnEnterPressed += (tb, text) => { CharacterNameBox.Deselect(); return true; };
CharacterNameBox.OnDeselected += (tb, key) =>
if (PermanentlyDead)
{
if (GameMain.Client == null) { return; }
string newName = Client.SanitizeName(tb.Text);
if (newName == GameMain.Client.Name) return;
if (string.IsNullOrWhiteSpace(newName))
CharacterNameBox.Readonly = true;
CharacterNameBox.Enabled = false;
}
else
{
CharacterNameBox.OnEnterPressed += (tb, text) =>
{
tb.Text = GameMain.Client.Name;
}
else
CharacterNameBox.Deselect();
return true;
};
CharacterNameBox.OnDeselected += (tb, key) =>
{
if (isGameRunning)
if (GameMain.Client == null)
{
GameMain.Client.PendingName = tb.Text;
TabMenu.PendingChanges = true;
if (createPendingText)
{
CreateChangesPendingText();
}
return;
}
string newName = Client.SanitizeName(tb.Text);
if (newName == GameMain.Client.Name) { return; }
if (string.IsNullOrWhiteSpace(newName))
{
tb.Text = GameMain.Client.Name;
}
else
{
ReadyToStartBox.Selected = false;
if (isGameRunning)
{
GameMain.Client.PendingName = tb.Text;
TabMenu.PendingChanges = true;
if (createPendingText)
{
CreateChangesPendingText();
}
}
else
{
ReadyToStartBox.Selected = false;
}
GameMain.Client.SetName(tb.Text);
}
GameMain.Client.SetName(tb.Text);
}
};
};
}
//spacing
new GUIFrame(new RectTransform(new Vector2(1.0f, 0.006f), parent.RectTransform), style: null);
if (allowEditing)
if (allowEditing && (!PermadeathMode || !isGameRunning))
{
GUILayoutGroup characterInfoTabs = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.07f), parent.RectTransform), isHorizontal: true)
{
@@ -1892,37 +1961,70 @@ namespace Barotrauma
{
characterInfo.CreateIcon(new RectTransform(new Vector2(1.0f, 0.16f), parent.RectTransform, Anchor.TopCenter));
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), parent.RectTransform), characterInfo.Job.Name, textAlignment: Alignment.Center, font: GUIStyle.SubHeadingFont, wrap: true)
if (PermanentlyDead)
{
HoverColor = Color.Transparent,
SelectedColor = Color.Transparent
};
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), parent.RectTransform), TextManager.Get("Skills"), font: GUIStyle.SubHeadingFont);
foreach (Skill skill in characterInfo.Job.GetSkills())
new GUITextBlock(
new RectTransform(new Vector2(1.0f, 0.0f), parent.RectTransform),
TextManager.Get("deceased"),
textAlignment: Alignment.Center, font: GUIStyle.LargeFont);
if (GameMain.Client?.ServerSettings is { IronmanMode: true })
{
new GUITextBlock(
new RectTransform(new Vector2(1.0f, 0.0f), parent.RectTransform),
TextManager.Get("lobby.ironmaninfo"),
textAlignment: Alignment.Center, wrap: true);
}
else
{
new GUITextBlock(
new RectTransform(new Vector2(1.0f, 0.0f), parent.RectTransform),
TextManager.Get("lobby.permadeathinfo"),
textAlignment: Alignment.Center, wrap: true);
new GUITextBlock(
new RectTransform(new Vector2(1.0f, 0.0f), parent.RectTransform),
TextManager.Get("lobby.permadeathoptionsexplanation"),
textAlignment: Alignment.Center, wrap: true);
}
}
else
{
Color textColor = Color.White * (0.5f + skill.Level / 200.0f);
var skillText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), parent.RectTransform),
" - " + TextManager.AddPunctuation(':', TextManager.Get("SkillName." + skill.Identifier), ((int)skill.Level).ToString()),
textColor,
font: GUIStyle.SmallFont);
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), parent.RectTransform), characterInfo.Job.Name, textAlignment: Alignment.Center, font: GUIStyle.SubHeadingFont, wrap: true)
{
HoverColor = Color.Transparent,
SelectedColor = Color.Transparent
};
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), parent.RectTransform), TextManager.Get("Skills"), font: GUIStyle.SubHeadingFont);
foreach (Skill skill in characterInfo.Job.GetSkills())
{
Color textColor = Color.White * (0.5f + skill.Level / 200.0f);
var skillText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), parent.RectTransform),
" - " + TextManager.AddPunctuation(':', TextManager.Get("SkillName." + skill.Identifier), ((int)skill.Level).ToString()),
textColor,
font: GUIStyle.SmallFont);
}
}
// Spacing
new GUIFrame(new RectTransform(new Vector2(1.0f, 0.15f), parent.RectTransform), style: null);
new GUIButton(new RectTransform(new Vector2(0.8f, 0.1f), parent.RectTransform, Anchor.BottomCenter), TextManager.Get("CreateNew"))
if (GameMain.Client?.ServerSettings?.RespawnMode != RespawnMode.Permadeath)
{
IgnoreLayoutGroups = true,
OnClicked = (btn, userdata) =>
// Button to create new character
new GUIButton(new RectTransform(new Vector2(0.8f, 0.1f), parent.RectTransform, Anchor.BottomCenter), TextManager.Get("CreateNew"))
{
TryDiscardCampaignCharacter(() =>
IgnoreLayoutGroups = true,
OnClicked = (btn, userdata) =>
{
UpdatePlayerFrame(null, true, parent);
});
return true;
}
};
TryDiscardCampaignCharacter(() =>
{
UpdatePlayerFrame(null, true, parent);
});
return true;
}
};
}
}
TeamPreferenceListBox = null;
@@ -2095,14 +2197,20 @@ namespace Barotrauma
{
if (GameMain.Client == null) { return; }
spectateBox.Selected = spectate;
if (spectate)
{
playerInfoContent.ClearChildren();
GameMain.Client.CharacterInfo?.Remove();
GameMain.Client.CharacterInfo = null;
GameMain.Client.Character?.Remove();
GameMain.Client.Character = null;
// TODO: The following lines are ancient, unexplained, and they cause a client spectating because of permadeath
// to get kicked from the server at round transition because the server expects to be in control of
// removing Characters and the client to still have one. Commenting these lines out for now, but
// if no side-effects occur, they can just be deleted.
//GameMain.Client.Character?.Remove();
//GameMain.Client.Character = null;
playerInfoContent.ClearChildren();
new GUITextBlock(new RectTransform(Vector2.One, playerInfoContent.RectTransform, Anchor.Center),
TextManager.Get("PlayingAsSpectator"),
textAlignment: Alignment.Center);
@@ -2118,6 +2226,10 @@ namespace Barotrauma
// Server owner is allowed to spectate regardless of the server settings
if (GameMain.Client != null && GameMain.Client.IsServerOwner) { return; }
// A client whose character has faced permadeath and hasn't chosen a new
// character yet has no choice but to spectate
if (campaignCharacterInfo != null && campaignCharacterInfo.PermanentlyDead) { return; }
// Show the player config menu if spectating is not allowed
if (spectateBox.Selected && !allowSpectating) { spectateBox.Selected = false; }
@@ -3609,6 +3721,7 @@ namespace Barotrauma
GameMain.GameSession = null;
}
respawnModeSelection.Refresh(); // not all respawn modes are compatible with all game modes
RefreshGameModeContent();
RefreshEnabledElements();
}
@@ -27,38 +27,8 @@ namespace Barotrauma
get => Submarine.MainSub;
set => Submarine.MainSub = value;
}
private enum LayerVisibility
{
Visible,
Invisible
}
private enum LayerLinkage
{
Unlinked,
Linked
}
private readonly struct LayerData
{
public readonly LayerVisibility Visible;
public readonly LayerLinkage Linkage;
public static readonly LayerData Default = new LayerData(LayerVisibility.Visible, LayerLinkage.Unlinked);
public LayerData(LayerVisibility visible, LayerLinkage linkage)
{
Visible = visible;
Linkage = linkage;
}
public void Deconstruct(out LayerVisibility isvisible, out LayerLinkage islinked)
{
isvisible = Visible;
islinked = Linkage;
}
}
private readonly record struct LayerData(bool IsVisible = true, bool IsGrouped = false);
public enum Mode
{
@@ -1105,12 +1075,22 @@ namespace Barotrauma
GameSession gameSession = new GameSession(backedUpSubInfo, "", GameModePreset.TestMode, CampaignSettings.Empty, null);
gameSession.StartRound(null, false);
(gameSession.GameMode as TestGameMode).OnRoundEnd = () =>
foreach ((string layerName, LayerData layerData) in Layers)
{
Submarine.Unload();
GameMain.SubEditorScreen.Select();
};
Identifier identifier = layerName.ToIdentifier();
bool enabled = layerData.IsVisible;
MainSub.SetLayerEnabled(identifier, enabled);
}
if (gameSession.GameMode is TestGameMode testGameMode)
{
testGameMode.OnRoundEnd = () =>
{
Submarine.Unload();
GameMain.SubEditorScreen.Select();
};
}
return true;
}
@@ -1472,6 +1452,7 @@ namespace Barotrauma
{
var subInfo = new SubmarineInfo();
MainSub = new Submarine(subInfo, showErrorMessages: false);
ReconstructLayers();
}
MainSub.UpdateTransform(interpolate: false);
@@ -1507,7 +1488,10 @@ namespace Barotrauma
}
ImageManager.OnEditorSelected();
ReconstructLayers();
if (Layers.None())
{
ReconstructLayers();
}
}
public override void OnFileDropped(string filePath, string extension)
@@ -1664,7 +1648,6 @@ namespace Barotrauma
});
ClearFilter();
ClearLayers();
}
private void CreateDummyCharacter()
@@ -2168,32 +2151,32 @@ namespace Barotrauma
if (Layers.Any())
{
var layerVisibilityGroup = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.01f), leftColumn.RectTransform), isHorizontal: true, childAnchor: Anchor.CenterLeft);
var visibleLayers = Layers.Where(l => !MainSub.Info.LayersHiddenByDefault.Contains(l.Key.ToIdentifier()));
LocalizedString visibleLayersString = LocalizedString.Join(", ", visibleLayers.Select(l => TextManager.Capitalize(l.Key)) ?? ((LocalizedString)"None").ToEnumerable());
new GUITextBlock(new RectTransform(new Vector2(0.5f, 1f), layerVisibilityGroup.RectTransform), TextManager.Get("editor.layer.visiblebydefault"), textAlignment: Alignment.CenterLeft);
var layerVisibilityDropDown = new GUIDropDown(new RectTransform(new Vector2(0.5f, 1f), layerVisibilityGroup.RectTransform),
text: LocalizedString.Join(", ", Layers.Where(l => !Submarine.MainSub?.Info?.LayersHiddenByDefault?.Contains(l.ToIdentifier()) ?? false).Select(lt => TextManager.Capitalize(lt.Key)) ?? ((LocalizedString)"None").ToEnumerable()), selectMultiple: true);
foreach (string layerName in Layers.Keys)
var layerVisibilityDropDown = new GUIDropDown(new RectTransform(new Vector2(0.5f, 1f), layerVisibilityGroup.RectTransform), text: visibleLayersString, selectMultiple: true);
foreach (var layer in Layers)
{
string layerName = layer.Key;
layerVisibilityDropDown.AddItem(TextManager.Capitalize(layerName), layerName);
if (MainSub?.Info == null) { continue; }
if (!MainSub.Info.LayersHiddenByDefault.Contains(layerName.ToIdentifier()))
if (visibleLayers.Contains(layer))
{
layerVisibilityDropDown.SelectItem(layerName);
}
}
layerVisibilityDropDown.OnSelected += (_, __) =>
layerVisibilityDropDown.OnSelected += (button, obj) =>
{
if (MainSub.Info == null) { return false; }
MainSub.Info.LayersHiddenByDefault.Clear();
foreach (string layerName in Layers.Keys)
string layerName = (string)obj;
bool isVisible = layerVisibilityDropDown.SelectedDataMultiple.Contains(obj);
if (isVisible)
{
//selected as visible = not hidden
if (layerVisibilityDropDown.SelectedDataMultiple.Any(o => o as string == layerName))
{
continue;
}
MainSub.Info.LayersHiddenByDefault.Add(layerName.ToIdentifier());
MainSub.Info.LayersHiddenByDefault.Remove(layerName.ToIdentifier());
}
else
{
MainSub.Info.LayersHiddenByDefault.Add(layerName.ToIdentifier());
}
UpdateLayerPanel();
layerVisibilityDropDown.Text = ToolBox.LimitString(layerVisibilityDropDown.Text.Value, layerVisibilityDropDown.Font, layerVisibilityDropDown.Rect.Width);
return true;
};
@@ -2511,6 +2494,15 @@ namespace Barotrauma
return true;
}
};
new GUITickBox(new RectTransform(new Vector2(1.0f, 0.25f), beaconSettingsContainer.RectTransform), TextManager.Get("allowdamageddevices"))
{
Selected = MainSub?.Info?.BeaconStationInfo?.AllowDamagedDevices ?? true,
OnSelected = (tb) =>
{
MainSub.Info.BeaconStationInfo.AllowDamagedDevices = tb.Selected;
return true;
}
};
new GUITickBox(new RectTransform(new Vector2(1.0f, 0.25f), beaconSettingsContainer.RectTransform), TextManager.Get("allowdisconnectedwires"))
{
Selected = MainSub?.Info?.BeaconStationInfo?.AllowDisconnectedWires ?? true,
@@ -3935,15 +3927,14 @@ namespace Barotrauma
MapEntity.HighlightedEntities.ToList() :
new List<MapEntity>(MapEntity.SelectedList);
Item target = null;
var single = targets.Count == 1 ? targets.Single() : null;
if (single is Item item && item.Components.Any(static ic => ic is not ConnectionPanel && ic is not Repairable && ic.GuiFrame != null))
{
// Do not offer the ability to open the inventory if the inventory should never be drawn
var containers = item.GetComponents<ItemContainer>();
if (containers.Any(static c => c.DrawInventory) || item.GetComponent<CircuitBox>() is not null) { target = item; }
}
bool allowOpening = false;
var targetItem = (targets.Count == 1 ? targets.Single() : null) as Item;
// Do not offer the ability to open the inventory if the inventory should never be drawn
allowOpening = targetItem is not null && targetItem.Components.Any(static ic =>
ic is not ConnectionPanel &&
ic is not Repairable &&
ic is not ItemContainer { DrawInventory: false } &&
ic.GuiFrame != null);
bool hasTargets = targets.Count > 0;
@@ -3987,7 +3978,6 @@ namespace Barotrauma
}
else
{
List<ContextMenuOption> availableLayers = new List<ContextMenuOption>
{
new ContextMenuOption("editor.layer.nolayer", true, onSelected: () => { MoveToLayer(null, targets); })
@@ -3995,7 +3985,8 @@ namespace Barotrauma
availableLayers.AddRange(Layers.Select(layer => new ContextMenuOption(layer.Key, true, onSelected: () => { MoveToLayer(layer.Key, targets); })));
List<ContextMenuOption> availableLayerOptions = new List<ContextMenuOption>
{ new ContextMenuOption("editor.layer.movetolayer", isEnabled: hasTargets, availableLayers.ToArray()),
{
new ContextMenuOption("editor.layer.movetolayer", isEnabled: hasTargets, availableLayers.ToArray()),
new ContextMenuOption("editor.layer.createlayer", isEnabled: hasTargets, onSelected: () => { CreateNewLayer(null, targets); }),
new ContextMenuOption("editor.layer.selectall", isEnabled: hasTargets, onSelected: () =>
{
@@ -4009,7 +4000,7 @@ namespace Barotrauma
availableLayerOptions.AddRange(Layers.Select(layer => new ContextMenuOption(layer.Key, true, onSelected: () => { MoveToLayer(layer.Key, targets); })));
GUIContextMenu.CreateContextMenu(
new ContextMenuOption("label.openlabel", isEnabled: target != null, onSelected: () => OpenItem(target)),
new ContextMenuOption("label.openlabel", isEnabled: allowOpening, onSelected: () => OpenItem(targetItem)),
new ContextMenuOption("editor.cut", isEnabled: hasTargets, onSelected: () => MapEntity.Cut(targets)),
new ContextMenuOption("editor.copytoclipboard", isEnabled: hasTargets, onSelected: () => MapEntity.Copy(targets)),
new ContextMenuOption("editor.paste", isEnabled: MapEntity.CopiedList.Any(), onSelected: () => MapEntity.Paste(cam.ScreenToWorld(PlayerInput.MousePosition))),
@@ -4064,13 +4055,13 @@ namespace Barotrauma
MoveToLayer(name, content);
}
Layers.Add(name, LayerData.Default);
Layers.Add(name, new LayerData());
UpdateLayerPanel();
}
private void RenameLayer(string original, string newName)
{
Layers.Remove(original);
Layers.Remove(original, out LayerData originalData);
foreach (MapEntity entity in MapEntity.MapEntityList.Where(entity => entity.Layer == original))
{
@@ -4079,7 +4070,7 @@ namespace Barotrauma
if (!string.IsNullOrWhiteSpace(newName))
{
Layers.TryAdd(newName, LayerData.Default);
Layers.TryAdd(newName, originalData);
}
UpdateLayerPanel();
}
@@ -4091,7 +4082,7 @@ namespace Barotrauma
{
if (!string.IsNullOrWhiteSpace(entity.Layer))
{
Layers.TryAdd(entity.Layer, LayerData.Default);
Layers.TryAdd(entity.Layer, new LayerData(!entity.IsLayerHidden));
}
}
UpdateLayerPanel();
@@ -4102,6 +4093,18 @@ namespace Barotrauma
Layers.Clear();
UpdateLayerPanel();
}
private static void SetLayerVisibility(string layerName, bool isVisible)
{
if (Layers.Remove(layerName, out LayerData layerData))
{
Layers.Add(layerName, layerData with { IsVisible = isVisible });
}
else
{
Layers.Add(layerName, new LayerData(isVisible));
}
}
private void PasteAssembly(string text = null, Vector2? pos = null)
{
@@ -4495,39 +4498,39 @@ namespace Barotrauma
}
/// <summary>
/// Tries to open an item container in the submarine editor using the dummy character
/// Tries to open an item in the submarine editor using the dummy character
/// </summary>
/// <param name="itemContainer">The item we want to open</param>
private void OpenItem(Item itemContainer)
/// <param name="item">The item we want to open</param>
private void OpenItem(Item item)
{
if (dummyCharacter == null || itemContainer == null) { return; }
if (dummyCharacter == null || item == null) { return; }
if ((itemContainer.GetComponent<Holdable>() is { Attached: false } || itemContainer.GetComponent<Wearable>() != null) && itemContainer.GetComponent<ItemContainer>() != null)
if ((item.GetComponent<Holdable>() is { Attached: false } || item.GetComponent<Wearable>() != null) && item.GetComponent<ItemContainer>() != null)
{
// We teleport our dummy character to the item so it appears as the entity stays still when in reality the dummy is holding it
oldItemPosition = itemContainer.SimPosition;
oldItemPosition = item.SimPosition;
TeleportDummyCharacter(oldItemPosition);
// Override this so we can be sure the container opens
var container = itemContainer.GetComponent<ItemContainer>();
var container = item.GetComponent<ItemContainer>();
if (container != null) { container.KeepOpenWhenEquipped = true; }
// We accept any slots except "Any" since that would take priority
List<InvSlotType> allowedSlots = new List<InvSlotType>();
itemContainer.AllowedSlots.ForEach(type =>
item.AllowedSlots.ForEach(type =>
{
if (type != InvSlotType.Any) { allowedSlots.Add(type); }
});
// Try to place the item in the dummy character's inventory
bool success = dummyCharacter.Inventory.TryPutItem(itemContainer, dummyCharacter, allowedSlots);
if (success) { OpenedItem = itemContainer; }
bool success = dummyCharacter.Inventory.TryPutItem(item, dummyCharacter, allowedSlots);
if (success) { OpenedItem = item; }
else { return; }
}
MapEntity.SelectedList.Clear();
MapEntity.FilteredSelectedList.Clear();
MapEntity.SelectEntity(itemContainer);
dummyCharacter.SelectedItem = itemContainer;
MapEntity.SelectEntity(item);
dummyCharacter.SelectedItem = item;
FilterEntities(entityFilterBox.Text);
MapEntity.StopSelection();
}
@@ -5179,7 +5182,7 @@ namespace Barotrauma
};
new GUIButton(new RectTransform(new Vector2(0.6f, 1f), buttonHeaders.RectTransform), TextManager.Get("name"), style: "GUIButtonSmallFreeScale") { ForceUpperCase = ForceUpperCase.Yes };
foreach (var (layer, (visibility, linkage)) in Layers)
foreach ((string layer, (bool isVisible, bool isGrouped)) in Layers)
{
GUIFrame parent = new GUIFrame(new RectTransform(new Vector2(1f, 0.1f), layerList.Content.RectTransform), style: "ListBoxElement")
{
@@ -5191,7 +5194,7 @@ namespace Barotrauma
GUILayoutGroup layerVisibilityLayout = new GUILayoutGroup(new RectTransform(new Vector2(0.25f, 1f), layerGroup.RectTransform), childAnchor: Anchor.Center);
GUITickBox layerVisibleButton = new GUITickBox(new RectTransform(Vector2.One, layerVisibilityLayout.RectTransform, scaleBasis: ScaleBasis.BothHeight), string.Empty)
{
Selected = visibility == LayerVisibility.Visible,
Selected = isVisible,
OnSelected = box =>
{
if (!Layers.TryGetValue(layer, out LayerData data))
@@ -5199,12 +5202,15 @@ namespace Barotrauma
UpdateLayerPanel();
return false;
}
//hiding a layer automatically deselects it (can't edit a hidden layer)
if (!box.Selected && layerList.SelectedData as string == layer)
{
layerList.Deselect();
//hiding a layer automatically deselects it (can't edit a hidden layer)
if (!box.Selected)
{
layerList.Deselect();
}
}
Layers[layer] = new LayerData(box.Selected ? LayerVisibility.Visible : LayerVisibility.Invisible, data.Linkage);
Layers[layer] = data with { IsVisible = box.Selected };
return true;
}
};
@@ -5212,7 +5218,7 @@ namespace Barotrauma
GUILayoutGroup layerChainLayout = new GUILayoutGroup(new RectTransform(new Vector2(0.15f, 1f), layerGroup.RectTransform), childAnchor: Anchor.Center);
GUITickBox layerChainButton = new GUITickBox(new RectTransform(Vector2.One, layerChainLayout.RectTransform, scaleBasis: ScaleBasis.BothHeight), string.Empty)
{
Selected = linkage == LayerLinkage.Linked,
Selected = isGrouped,
OnSelected = box =>
{
if (!Layers.TryGetValue(layer, out LayerData data))
@@ -5221,7 +5227,7 @@ namespace Barotrauma
return false;
}
Layers[layer] = new LayerData(data.Visible, box.Selected ? LayerLinkage.Linked : LayerLinkage.Unlinked);
Layers[layer] = data with { IsGrouped = box.Selected };
return true;
}
};
@@ -5252,7 +5258,6 @@ namespace Barotrauma
btn.ToolTip = originalBtnText;
}
}
}
public void UpdateUndoHistoryPanel()
@@ -6306,11 +6311,11 @@ namespace Barotrauma
if (!Layers.TryGetValue(entity.Layer, out LayerData data))
{
Layers.TryAdd(entity.Layer, LayerData.Default);
Layers.TryAdd(entity.Layer, new LayerData(!entity.IsLayerHidden));
return true;
}
return data.Visible == LayerVisibility.Visible;
return data.IsVisible;
}
public static bool IsLayerLinked(MapEntity entity)
@@ -6319,11 +6324,11 @@ namespace Barotrauma
if (!Layers.TryGetValue(entity.Layer, out LayerData data))
{
Layers.TryAdd(entity.Layer, LayerData.Default);
Layers.TryAdd(entity.Layer, new LayerData(!entity.IsLayerHidden));
return true;
}
return data.Linkage == LayerLinkage.Linked;
return data.IsGrouped;
}
public static ImmutableHashSet<MapEntity> GetEntitiesInSameLayer(MapEntity entity)