Unstable 0.17.6.0

This commit is contained in:
Markus Isberg
2022-04-04 16:46:08 +09:00
parent 44ded0225a
commit 95764d1fa8
78 changed files with 1265 additions and 703 deletions
@@ -1048,7 +1048,7 @@ namespace Barotrauma
box.Content.ChildAnchor = Anchor.TopCenter;
box.Content.AbsoluteSpacing = 20;
int elementSize = 30;
var listBox = new GUIListBox(new RectTransform(new Vector2(1, 0.9f), box.Content.RectTransform));
var listBox = new GUIListBox(new RectTransform(new Vector2(1, 0.75f), box.Content.RectTransform));
new GUITextBlock(new RectTransform(new Point(listBox.Content.Rect.Width, elementSize), listBox.Content.RectTransform),
TextManager.Get("leveleditor.levelobjname")) { CanBeFocused = false };
@@ -1059,13 +1059,13 @@ namespace Barotrauma
var texturePathBox = new GUITextBox(new RectTransform(new Point(listBox.Content.Rect.Width, elementSize), listBox.Content.RectTransform));
foreach (LevelObjectPrefab prefab in LevelObjectPrefab.Prefabs)
{
if (prefab.Sprites.FirstOrDefault() == null) continue;
if (prefab.Sprites.FirstOrDefault() == null) { continue; }
texturePathBox.Text = Path.GetDirectoryName(prefab.Sprites.FirstOrDefault().FilePath.Value);
break;
}
//this is nasty :(
newPrefab = new LevelObjectPrefab(null, null, Identifier.Empty);
newPrefab = new LevelObjectPrefab(null, null, new Identifier("No identifier"));
new SerializableEntityEditor(listBox.Content.RectTransform, newPrefab, false, false);
@@ -828,7 +828,6 @@ namespace Barotrauma
" -playstyle " + ((PlayStyle)playstyleBanner.UserData).ToString() +
" -banafterwrongpassword " + wrongPasswordBanBox.Selected.ToString() +
" -karmaenabled " + (!karmaBox.Selected).ToString() +
" -karmapreset default" +
" -maxplayers " + maxPlayersBox.Text;
if (!string.IsNullOrWhiteSpace(passwordBox.Text))
@@ -5,6 +5,7 @@ using System.Linq;
using Barotrauma.Extensions;
using Barotrauma.IO;
using Barotrauma.Networking;
using Barotrauma.Steam;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Steamworks.Data;
@@ -94,7 +95,7 @@ namespace Barotrauma
}
GUIMessageBox msgBox = new GUIMessageBox(
TextManager.Get("WorkshopItemDownloadTitle"),
TextManager.Get("ModDownloadTitle"),
"",
Array.Empty<LocalizedString>(),
relativeSize: (0.5f, 0.75f));
@@ -122,8 +123,6 @@ namespace Barotrauma
return tb;
}
var title = textBlock(TextManager.Get("ModDownloadTitle"), GUIStyle.SubHeadingFont, Alignment.Center);
innerLayoutSpacing(0.05f);
var header = textBlock(TextManager.Get("ModDownloadHeader"), GUIStyle.Font);
innerLayoutSpacing(0.05f);
@@ -138,8 +137,8 @@ namespace Barotrauma
void buttonContainerSpacing(float width)
=> new GUIFrame(new RectTransform((width, 1.0f), buttonContainer.RectTransform), style: null);
void button(LocalizedString text, Action action)
=> new GUIButton(new RectTransform((0.3f, 1.0f), buttonContainer.RectTransform), text)
void button(LocalizedString text, Action action, float width = 0.3f)
=> new GUIButton(new RectTransform((width, 1.0f), buttonContainer.RectTransform), text)
{
OnClicked = (_, __) =>
{
@@ -159,6 +158,28 @@ namespace Barotrauma
});
buttonContainerSpacing(0.1f);
var missingIds = missingPackages.Where(
mp => mp.WorkshopId != 0
&& ContentPackageManager.WorkshopPackages.All(wp
=> wp.SteamWorkshopId != mp.WorkshopId))
.Select(mp => mp.WorkshopId)
.ToArray();
if (missingIds.Any())
{
buttonContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.1f), innerLayout.RectTransform), isHorizontal: true);
buttonContainerSpacing(0.15f);
button(TextManager.Get("SubscribeToAllOnWorkshop"), () =>
{
BulkDownloader.SubscribeToServerMods(missingIds,
rejoinEndpoint: GameMain.Client.ClientPeer.ServerConnection.EndPointString,
rejoinLobby: SteamManager.CurrentLobbyID,
rejoinServerName: GameMain.NetLobbyScreen.ServerName.Text);
GameMain.Client.Disconnect();
GameMain.MainMenuScreen.Select();
}, width: 0.7f);
buttonContainerSpacing(0.15f);
}
foreach (var p in missingPackages)
{
pendingDownloads.Enqueue(p);
@@ -218,9 +218,6 @@ namespace Barotrauma
public MultiPlayerCampaignSetupUI CampaignSetupUI;
// Passed onto the gamesession when created
public List<SubmarineInfo> ServerOwnedSubmarines = new List<SubmarineInfo>();
public bool UsingShuttle
{
get { return shuttleTickBox.Selected; }
@@ -2007,7 +2004,7 @@ namespace Barotrauma
SelectedTextColor = Color.Black,
UserData = client
};
var soundIcon = new GUIImage(new RectTransform(new Point((int)(textBlock.Rect.Height * 0.8f)), textBlock.RectTransform, Anchor.CenterRight) { AbsoluteOffset = new Point(5, 0) },
var soundIcon = new GUIImage(new RectTransform(Vector2.One * 0.8f, textBlock.RectTransform, Anchor.CenterRight, scaleBasis: ScaleBasis.BothHeight) { AbsoluteOffset = new Point(5, 0) },
sprite: GUIStyle.GetComponentStyle("GUISoundIcon").GetDefaultSprite(), scaleToFit: true)
{
UserData = new Pair<string, float>("soundicon", 0.0f),
@@ -2017,7 +2014,7 @@ namespace Barotrauma
HoverColor = Color.White
};
new GUIImage(new RectTransform(new Point((int)(textBlock.Rect.Height * 0.8f)), textBlock.RectTransform, Anchor.CenterRight) { AbsoluteOffset = new Point(5, 0) },
var soundIconDisabled = new GUIImage(new RectTransform(Vector2.One * 0.8f, textBlock.RectTransform, Anchor.CenterRight, scaleBasis: ScaleBasis.BothHeight) { AbsoluteOffset = new Point(5, 0) },
"GUISoundIconDisabled")
{
UserData = "soundicondisabled",
@@ -2026,15 +2023,55 @@ namespace Barotrauma
OverrideState = GUIComponent.ComponentState.None,
HoverColor = Color.White
};
new GUIFrame(new RectTransform(new Vector2(0.6f, 0.6f), textBlock.RectTransform, Anchor.CenterRight, scaleBasis: ScaleBasis.BothHeight) { AbsoluteOffset = new Point(10 + soundIcon.Rect.Width, 0) }, style: "GUIReadyToStart")
var readyTick = new GUIFrame(new RectTransform(new Vector2(0.6f, 0.6f), textBlock.RectTransform, Anchor.CenterRight, scaleBasis: ScaleBasis.BothHeight) { AbsoluteOffset = new Point(10 + soundIcon.Rect.Width, 0) }, style: "GUIReadyToStart")
{
Visible = false,
CanBeFocused = false,
ToolTip = TextManager.Get("ReadyToStartTickBox"),
UserData = "clientready"
};
var downloadingThrobber = new GUICustomComponent(
new RectTransform(Vector2.One, textBlock.RectTransform, scaleBasis: ScaleBasis.BothHeight),
onUpdate: null,
onDraw: DrawDownloadThrobber(client, soundIcon, soundIconDisabled, readyTick));
}
private Action<SpriteBatch, GUICustomComponent> DrawDownloadThrobber(Client client, params GUIComponent[] otherComponents)
=> (sb, c) => DrawDownloadThrobber(client, otherComponents, sb, c); //poor man's currying
private void DrawDownloadThrobber(Client client, GUIComponent[] otherComponents, SpriteBatch spriteBatch, GUICustomComponent component)
{
if (!client.IsDownloading)
{
component.ToolTip = "";
return;
}
component.HideElementsOutsideFrame = false;
int drawRectX = otherComponents.Where(c => c.Visible)
.Select(c => c.Rect)
.Concat(new Rectangle(component.Parent.Rect.Right, component.Parent.Rect.Y, 0, component.Parent.Rect.Height).ToEnumerable())
.Min(r => r.X) - component.Parent.Rect.Height - 10;
Rectangle drawRect
= new Rectangle(drawRectX, component.Rect.Y, component.Parent.Rect.Height, component.Parent.Rect.Height);
component.RectTransform.AbsoluteOffset = drawRect.Location - component.Parent.Rect.Location;
component.RectTransform.NonScaledSize = drawRect.Size;
var sheet = GUIStyle.GenericThrobber;
sheet.Draw(
spriteBatch,
pos: drawRect.Location.ToVector2(),
spriteIndex: (int)Math.Floor(Timing.TotalTime * 24.0f) % sheet.FrameCount,
color: Color.White,
origin: Vector2.Zero, rotate: 0.0f,
scale: Vector2.One * component.Parent.Rect.Height / sheet.FrameSize.ToVector2());
if (component.ToolTip.IsNullOrEmpty())
{
component.ToolTip = TextManager.Get("PlayerIsDownloadingFiles");
}
}
public void SetPlayerNameAndJobPreference(Client client)
{
var playerFrame = (GUITextBlock)PlayerList.Content.FindChild(client);
@@ -2160,17 +2197,16 @@ namespace Barotrauma
Steamworks.SteamFriends.OpenWebOverlay($"https://steamcommunity.com/profiles/{client.SteamID}");
}));
options.Add(new ContextMenuOption("ModerationMenu.UserDetails", isEnabled: true, onSelected: delegate
options.Add(new ContextMenuOption("ModerationMenu.ManagePlayer", isEnabled: true, onSelected: delegate
{
GameMain.NetLobbyScreen?.SelectPlayer(client);
}));
// Creates sub context menu options for all the ranks
List<ContextMenuOption> permissionOptions = new List<ContextMenuOption>();
List<ContextMenuOption> rankOptions = new List<ContextMenuOption>();
foreach (PermissionPreset rank in PermissionPreset.List)
{
permissionOptions.Add(new ContextMenuOption(rank.Name, isEnabled: true, onSelected: () =>
rankOptions.Add(new ContextMenuOption(rank.Name, isEnabled: true, onSelected: () =>
{
LocalizedString label = TextManager.GetWithVariables(rank.Permissions == ClientPermissions.None ? "clearrankprompt" : "giverankprompt", ("[user]", client.Name), ("[rank]", rank.Name));
GUIMessageBox msgBox = new GUIMessageBox(string.Empty, label, new[] { TextManager.Get("Yes"), TextManager.Get("Cancel") });
@@ -2190,7 +2226,7 @@ namespace Barotrauma
}) { Tooltip = rank.Description });
}
options.Add(new ContextMenuOption("Permissions", isEnabled: canPromo, options: permissionOptions.ToArray()));
options.Add(new ContextMenuOption("Rank", isEnabled: canPromo, options: rankOptions.ToArray()));
Color clientColor = client.Character?.Info?.Job.Prefab.UIColor ?? Color.White;
@@ -3554,12 +3590,6 @@ namespace Barotrauma
("[serverhash]", Md5Hash.GetShortHash(md5Hash))) + " ";
}
//already showing a message about the same sub
if (GUIMessageBox.MessageBoxes.Any(mb => mb.UserData as string == "request" + subName))
{
return false;
}
if (GameMain.Client.ServerSettings.AllowFileTransfers)
{
GameMain.Client?.RequestFile(FileTransferType.Submarine, subName, md5Hash);
@@ -793,7 +793,7 @@ namespace Barotrauma
showEntitiesPanel.RectTransform.NonScaledSize =
new Point(
(int)(paddedShowEntitiesPanel.RectTransform.Children.Max(c => (int)((c.GUIComponent as GUITickBox)?.TextBlock.TextSize.X ?? 0)) / paddedShowEntitiesPanel.RectTransform.RelativeSize.X),
(int)Math.Max(showEntitiesPanel.RectTransform.NonScaledSize.X, paddedShowEntitiesPanel.RectTransform.Children.Max(c => (int)((c.GUIComponent as GUITickBox)?.TextBlock.TextSize.X ?? 0)) / paddedShowEntitiesPanel.RectTransform.RelativeSize.X),
(int)(paddedShowEntitiesPanel.RectTransform.Children.Sum(c => c.MinSize.Y) / paddedShowEntitiesPanel.RectTransform.RelativeSize.Y));
GUITextBlock.AutoScaleAndNormalize(paddedShowEntitiesPanel.Children.Where(c => c is GUITickBox).Select(c => ((GUITickBox)c).TextBlock));
@@ -1700,44 +1700,13 @@ namespace Barotrauma
return false;
}
string specialSavePath = "";
if (MainSub.Info.Type != SubmarineType.Player)
{
Identifier typeIdentifier = MainSub.Info.Type.ToString().ToIdentifier();
Type contentType = ContentFile.Types.FirstOrDefault(t
=> !t.Type.IsAbstract
&& t.Type.IsSubclassOf(typeof(BaseSubFile))
&& t.Names.Contains(typeIdentifier))
?.Type ??
typeof(SubmarineFile);
if (MainSub.Info.Type == SubmarineType.OutpostModule &&
MainSub.Info.OutpostModuleInfo != null)
{
contentType = typeof(OutpostModuleFile);
MainSub.Info.PreviewImage = null;
}
if (contentType != typeof(SubmarineFile))
{
#if DEBUG
var existingFiles = GameMain.VanillaContent.GetFiles(contentType);
if (contentType == typeof(OutpostModuleFile))
{
existingFiles = existingFiles.Where(f => f.Path.Value.Contains("Ruin") == MainSub.Info.OutpostModuleInfo.ModuleFlags.Contains("ruin".ToIdentifier()));
}
#else
var existingFiles = ContentPackageManager.EnabledPackages.All
.Where(c => c != GameMain.VanillaContent)
.SelectMany(c => c.GetFiles(contentType));
#endif
specialSavePath = existingFiles.FirstOrDefault(f =>
ContentPackage.PathAllowedAsLocalModFile(f.Path.Value))?.Path.Value;
if (!string.IsNullOrEmpty(specialSavePath))
{
specialSavePath = Path.GetDirectoryName(specialSavePath);
}
}
}
else if (MainSub.Info.SubmarineClass == SubmarineClass.Undefined && !MainSub.Info.HasTag(SubmarineTag.Shuttle))
{
@@ -1758,35 +1727,7 @@ namespace Barotrauma
return true;
}
if (!string.IsNullOrEmpty(specialSavePath) &&
(string.IsNullOrEmpty(MainSub?.Info.FilePath) || Path.GetFileNameWithoutExtension(MainSub.Info.Name) != nameBox.Text || Path.GetDirectoryName(MainSub?.Info.FilePath) != specialSavePath))
{
string submarineTypeTag = $"SubmarineType.{MainSub.Info.Type}";
if (MainSub.Info.Type == SubmarineType.EnemySubmarine && !TextManager.ContainsTag(submarineTypeTag))
{
submarineTypeTag = "MissionType.Pirate";
}
var msgBox = new GUIMessageBox("", TextManager.GetWithVariables("savesubtospecialfolderprompt",
("[type]", TextManager.Get(submarineTypeTag)), ("[outpostpath]", specialSavePath)),
new LocalizedString[] { TextManager.Get("yes"), TextManager.Get("no") });
msgBox.Buttons[0].OnClicked = (bt, userdata) =>
{
SaveSubToFile(nameBox.Text, specialSavePath);
saveFrame = null;
msgBox.Close();
return true;
};
msgBox.Buttons[1].OnClicked = (bt, userdata) =>
{
SaveSubToFile(nameBox.Text);
saveFrame = null;
msgBox.Close();
return true;
};
return true;
}
var result = SaveSubToFile(nameBox.Text, specialSavePath);
var result = SaveSubToFile(nameBox.Text);
saveFrame = null;
return result;
}
@@ -1798,13 +1739,9 @@ namespace Barotrauma
if (p is null) { return; }
if (!packageReloadQueue.Contains(p)) { packageReloadQueue.Enqueue(p); }
}
private bool SaveSubToFile(string name, string specialSavePath = null)
{
bool canModifyPackage(ContentPackage p)
=> p != null && ContentPackageManager.LocalPackages.Contains(p) && p != ContentPackageManager.VanillaCorePackage;
Type subFileType = MainSub?.Info.Type switch
public static Type DetermineSubFileType(SubmarineType type)
=> type switch
{
SubmarineType.Outpost => typeof(OutpostFile),
SubmarineType.OutpostModule => typeof(OutpostModuleFile),
@@ -1812,8 +1749,16 @@ namespace Barotrauma
SubmarineType.Wreck => typeof(WreckFile),
SubmarineType.BeaconStation => typeof(BeaconStationFile),
SubmarineType.EnemySubmarine => typeof(EnemySubmarineFile),
SubmarineType.Player => typeof(SubmarineFile)
SubmarineType.Player => typeof(SubmarineFile),
_ => null
};
private bool SaveSubToFile(string name)
{
bool canModifyPackage(ContentPackage p)
=> p != null && ContentPackageManager.LocalPackages.Contains(p) && p != ContentPackageManager.VanillaCorePackage;
Type subFileType = DetermineSubFileType(MainSub?.Info.Type ?? SubmarineType.Player);
void addSubAndSaveModProject(ModProject modProject, string filePath, string packagePath)
{
@@ -1858,11 +1803,13 @@ namespace Barotrauma
foreach (var illegalChar in Path.GetInvalidFileNameChars())
{
if (!name.Contains(illegalChar)) continue;
if (!name.Contains(illegalChar)) { continue; }
GUI.AddMessage(TextManager.GetWithVariable("SubNameIllegalCharsWarning", "[illegalchar]", illegalChar.ToString()), GUIStyle.Red);
return false;
}
name = name.Trim();
string newLocalModDir = $"{ContentPackage.LocalModsDir}/{name}";
var vanilla = GameMain.VanillaContent;
@@ -1871,33 +1818,7 @@ namespace Barotrauma
string savePath = name + ".sub";
string prevSavePath = null;
if (!string.IsNullOrEmpty(specialSavePath))
{
string directoryName = specialSavePath;
savePath = Path.Combine(directoryName, savePath);
ContentPackage contentPackage = ContentPackageManager.EnabledPackages.All.FirstOrDefault(cp => cp.Files.Any(f => Path.GetDirectoryName(f.Path.Value) == directoryName));
if (!contentPackage.Files.Any(f => f.Path == savePath) && canModifyPackage(contentPackage))
{
var msgBox = new GUIMessageBox("", TextManager.GetWithVariable("addtocontentpackageprompt", "[packagename]", contentPackage.Name),
new LocalizedString[] { TextManager.Get("yes"), TextManager.Get("no") });
msgBox.Buttons[0].OnClicked = (bt, userdata) =>
{
ModProject modProject = new ModProject(contentPackage);
addSubAndSaveModProject(modProject, savePath, contentPackage.Path);
EnqueueForReload(contentPackage);
msgBox.Close();
return true;
};
msgBox.Buttons[1].OnClicked = (bt, userdata) =>
{
msgBox.Close();
return true;
};
}
}
else if (!string.IsNullOrEmpty(MainSub?.Info.FilePath) &&
if (!string.IsNullOrEmpty(MainSub?.Info.FilePath) &&
MainSub.Info.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase))
{
prevSavePath = MainSub.Info.FilePath.CleanUpPath();
@@ -2515,7 +2436,7 @@ namespace Barotrauma
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), rightColumn.RectTransform), TextManager.Get("SubPreviewImage"), font: GUIStyle.SubHeadingFont);
var previewImageHolder = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.5f), rightColumn.RectTransform), style: null) { Color = Color.Black, CanBeFocused = false };
var previewImageHolder = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.4f), rightColumn.RectTransform), style: null) { Color = Color.Black, CanBeFocused = false };
previewImage = new GUIImage(new RectTransform(Vector2.One, previewImageHolder.RectTransform), MainSub?.Info.PreviewImage, scaleToFit: true);
previewImageButtonHolder = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.05f), rightColumn.RectTransform), isHorizontal: true) { Stretch = true, RelativeSpacing = 0.05f };
@@ -2567,7 +2488,7 @@ namespace Barotrauma
previewImageButtonHolder.RectTransform.MinSize = new Point(0, previewImageButtonHolder.RectTransform.Children.Max(c => c.MinSize.Y));
var horizontalArea = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.35f), rightColumn.RectTransform), style: null);
var horizontalArea = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.45f), rightColumn.RectTransform), style: null);
var settingsLabel = new GUITextBlock(new RectTransform(new Vector2(0.5f, 0.0f), horizontalArea.RectTransform),
TextManager.Get("SaveSubDialogSettings"), wrap: true, font: GUIStyle.SmallFont);
@@ -2613,11 +2534,30 @@ namespace Barotrauma
};
}
var contentPackagesLabel = new GUITextBlock(new RectTransform(new Vector2(0.5f, 0.0f), horizontalArea.RectTransform, Anchor.TopRight),
var contentPackagesLayout = new GUILayoutGroup(new RectTransform(new Vector2(0.5f, 1.0f),
horizontalArea.RectTransform, Anchor.BottomRight))
{
Stretch = true
};
var contentPackagesLabel = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), contentPackagesLayout.RectTransform),
TextManager.Get("RequiredContentPackages"), wrap: true, font: GUIStyle.SmallFont);
contentPackagesLabel.RectTransform.MinSize
= GUIStyle.SmallFont.MeasureString(contentPackagesLabel.WrappedText).ToPoint();
var contentPackList = new GUIListBox(new RectTransform(new Vector2(0.5f, 1.0f - contentPackagesLabel.RectTransform.RelativeSize.Y),
horizontalArea.RectTransform, Anchor.BottomRight));
var contentPackList = new GUIListBox(new RectTransform(new Vector2(1.0f, 1.0f),
contentPackagesLayout.RectTransform));
var contentPackFilter
= new GUITextBox(new RectTransform(new Vector2(1.0f, 0.0f), contentPackagesLayout.RectTransform),
createClearButton: true);
contentPackFilter.OnTextChanged += (box, text) =>
{
contentPackList.Content.Children.ForEach(c
=> c.Visible = !(c is GUITickBox tb &&
!tb.Text.Contains(text, StringComparison.OrdinalIgnoreCase)));
return true;
};
if (MainSub != null)
{