(6eeea9b7c) v0.9.10.0.0

This commit is contained in:
Joonas Rikkonen
2020-06-04 16:41:07 +03:00
parent ce4ccd99ac
commit eeac247a8e
366 changed files with 7772 additions and 3692 deletions
@@ -2,7 +2,7 @@
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.IO;
using Barotrauma.IO;
using System.Linq;
using System.Xml.Linq;
@@ -2,13 +2,17 @@
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using Barotrauma.Extensions;
using FarseerPhysics;
using FarseerPhysics.Dynamics;
#if DEBUG
using System.IO;
#else
using Barotrauma.IO;
#endif
namespace Barotrauma.CharacterEditor
{
@@ -278,7 +282,7 @@ namespace Barotrauma.CharacterEditor
return TextManager.Get(screenTextTag + tag);
}
#region Main methods
#region Main methods
public override void AddToGUIUpdateList()
{
rightArea.AddToGUIUpdateList();
@@ -662,9 +666,6 @@ namespace Barotrauma.CharacterEditor
}
if (!isFrozen)
{
Submarine.MainSub.SetPrevTransform(Submarine.MainSub.Position);
Submarine.MainSub.Update((float)deltaTime);
foreach (PhysicsBody body in PhysicsBody.List)
{
body.SetPrevTransform(body.SimPosition, body.Rotation);
@@ -991,9 +992,9 @@ namespace Barotrauma.CharacterEditor
}
spriteBatch.End();
}
#endregion
#endregion
#region Ragdoll Manipulation
#region Ragdoll Manipulation
private void UpdateJointCreation()
{
if (jointCreationMode == JointCreationMode.None)
@@ -1320,9 +1321,9 @@ namespace Barotrauma.CharacterEditor
}
RecreateRagdoll();
}
#endregion
#endregion
#region Endless runner
#region Endless runner
private int min;
private int max;
private void CalculateMovementLimits()
@@ -1425,9 +1426,9 @@ namespace Barotrauma.CharacterEditor
AllWalls.ForEach(w => w.SetCollisionCategory(collisionCategory));
GameMain.World.ProcessChanges();
}
#endregion
#endregion
#region Character spawning
#region Character spawning
private int characterIndex = -1;
private string currentCharacterConfig;
private string selectedJob = null;
@@ -1749,7 +1750,11 @@ namespace Barotrauma.CharacterEditor
{
Directory.CreateDirectory(mainFolder);
}
#if DEBUG
doc.Save(configFilePath);
#else
doc.SaveSafe(configFilePath);
#endif
// Add to the selected content package
contentPackage.AddFile(configFilePath, ContentType.Character);
contentPackage.Save(contentPackage.Path);
@@ -1830,9 +1835,9 @@ namespace Barotrauma.CharacterEditor
{
character.Inventory?.Items.ForEachMod(i => i?.Unequip(character));
}
#endregion
#endregion
#region GUI
#region GUI
private static Vector2 innerScale = new Vector2(0.95f, 0.95f);
private GUILayoutGroup rightArea, leftArea;
@@ -3147,9 +3152,9 @@ namespace Barotrauma.CharacterEditor
fileEditPanel.RectTransform.MinSize = new Point(0, (int)(layoutGroup.RectTransform.Children.Sum(c => c.MinSize.Y + layoutGroup.AbsoluteSpacing) * 1.2f));
}
#endregion
#endregion
#region ToggleButtons
#region ToggleButtons
private enum Direction
{
Left,
@@ -3211,9 +3216,9 @@ namespace Barotrauma.CharacterEditor
}
}
#endregion
#endregion
#region Params
#region Params
private CharacterParams CharacterParams => character.Params;
private List<AnimationParams> AnimParams => character.AnimController.AllAnimParams;
private AnimationParams CurrentAnimation => character.AnimController.CurrentAnimationParams;
@@ -3464,9 +3469,9 @@ namespace Barotrauma.CharacterEditor
}
}
}
#endregion
#endregion
#region Helpers
#region Helpers
private Vector2 ScreenToSim(float x, float y) => ScreenToSim(new Vector2(x, y));
private Vector2 ScreenToSim(Vector2 p) => ConvertUnits.ToSimUnits(Cam.ScreenToWorld(p)) + Submarine.MainSub.SimPosition;
private Vector2 SimToScreen(float x, float y) => SimToScreen(new Vector2(x, y));
@@ -3707,9 +3712,9 @@ namespace Barotrauma.CharacterEditor
SetToggle(spritesheetToggle, true);
}
}
#endregion
#endregion
#region Animation Controls
#region Animation Controls
private void DrawAnimationControls(SpriteBatch spriteBatch, float deltaTime)
{
var collider = character.AnimController.Collider;
@@ -4302,9 +4307,9 @@ namespace Barotrauma.CharacterEditor
}
}
}
#endregion
#endregion
#region Ragdoll
#region Ragdoll
private Vector2[] corners = new Vector2[4];
private Vector2[] GetLimbPhysicRect(Limb limb)
{
@@ -4626,9 +4631,9 @@ namespace Barotrauma.CharacterEditor
}
return otherLimbs;
}
#endregion
#endregion
#region Spritesheet
#region Spritesheet
private List<Texture2D> textures;
private List<Texture2D> Textures
{
@@ -5223,9 +5228,9 @@ namespace Barotrauma.CharacterEditor
CalculateSpritesheetZoom();
spriteSheetZoomBar.BarScroll = MathHelper.Lerp(0, 1, MathUtils.InverseLerp(spriteSheetMinZoom, spriteSheetMaxZoom, spriteSheetZoom));
}
#endregion
#endregion
#region Widgets as methods
#region Widgets as methods
private void DrawRadialWidget(SpriteBatch spriteBatch, Vector2 drawPos, float value, string toolTip, Color color, Action<float> onClick,
float circleRadius = 30, int widgetSize = 10, float rotationOffset = 0, bool clockWise = true, bool displayAngle = true, bool? autoFreeze = null, bool wrapAnglePi = false, bool holdPosition = false, int rounding = 1)
{
@@ -5334,9 +5339,9 @@ namespace Barotrauma.CharacterEditor
}
}
}
#endregion
#endregion
#region Widgets as classes
#region Widgets as classes
private Dictionary<string, Widget> animationWidgets = new Dictionary<string, Widget>();
private Dictionary<string, Widget> jointSelectionWidgets = new Dictionary<string, Widget>();
private Dictionary<string, Widget> limbEditWidgets = new Dictionary<string, Widget>();
@@ -5490,6 +5495,6 @@ namespace Barotrauma.CharacterEditor
return w;
}
}
#endregion
#endregion
}
}
@@ -1,6 +1,6 @@
using Microsoft.Xna.Framework;
using System;
using System.IO;
using Barotrauma.IO;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
@@ -151,7 +151,10 @@ namespace Barotrauma
GameMain.ParticleManager.UpdateTransforms();
GameMain.LightManager.ObstructVision = Character.Controlled != null && Character.Controlled.ObstructVision;
GameMain.LightManager.ObstructVision =
Character.Controlled != null &&
Character.Controlled.ObstructVision &&
(Character.Controlled.ViewTarget == Character.Controlled || Character.Controlled.ViewTarget == null);
if (Character.Controlled != null)
{
@@ -261,7 +264,7 @@ namespace Barotrauma
graphics.SetRenderTarget(renderTargetFinal);
WaterRenderer.Instance.ResetBuffers();
Hull.UpdateVertices(graphics, cam, WaterRenderer.Instance);
Hull.UpdateVertices(cam, WaterRenderer.Instance);
WaterRenderer.Instance.RenderWater(spriteBatch, renderTargetWater, cam);
WaterRenderer.Instance.RenderAir(graphics, cam, renderTarget, Cam.ShaderTransform);
graphics.DepthStencilState = DepthStencilState.None;
@@ -3,10 +3,14 @@ using Barotrauma.RuinGeneration;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.IO;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
#if DEBUG
using System.IO;
using System.Xml;
#else
using Barotrauma.IO;
#endif
namespace Barotrauma
{
@@ -459,7 +463,7 @@ namespace Barotrauma
Submarine.Draw(spriteBatch, false);
Submarine.DrawFront(spriteBatch);
Submarine.DrawDamageable(spriteBatch, null);
GUI.DrawRectangle(spriteBatch, new Rectangle(new Point(0, -Level.Loaded.Size.Y), Level.Loaded.Size), Color.White, thickness: (int)(1.0f / cam.Zoom));
GUI.DrawRectangle(spriteBatch, new Rectangle(new Point(0, -Level.Loaded.Size.Y), Level.Loaded.Size), Color.Gray, thickness: (int)(1.0f / cam.Zoom));
spriteBatch.End();
if (lightingEnabled.Selected)
@@ -497,7 +501,7 @@ namespace Barotrauma
private void SerializeAll()
{
XmlWriterSettings settings = new XmlWriterSettings
System.Xml.XmlWriterSettings settings = new System.Xml.XmlWriterSettings
{
Indent = true,
NewLineOnAttributes = true
@@ -578,7 +582,7 @@ namespace Barotrauma
if (elementFound)
{
XmlWriterSettings settings = new XmlWriterSettings
System.Xml.XmlWriterSettings settings = new System.Xml.XmlWriterSettings
{
Indent = true,
NewLineOnAttributes = true
@@ -595,7 +599,7 @@ namespace Barotrauma
}
#region LevelObject Wizard
#region LevelObject Wizard
private class Wizard
{
private LevelObjectPrefab newPrefab;
@@ -676,8 +680,8 @@ namespace Barotrauma
}
newPrefab.Name = nameBox.Text;
XmlWriterSettings settings = new XmlWriterSettings { Indent = true };
System.Xml.XmlWriterSettings settings = new System.Xml.XmlWriterSettings { Indent = true };
foreach (ContentFile configFile in GameMain.Instance.GetFilesOfType(ContentType.LevelObjectPrefabs))
{
XDocument doc = XMLExtensions.TryLoadXml(configFile.Path);
@@ -710,6 +714,6 @@ namespace Barotrauma
}
}
#endregion
#endregion
}
}
@@ -10,7 +10,7 @@ using RestSharp;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using Barotrauma.IO;
using System.Linq;
using System.Net;
using System.Threading;
@@ -409,10 +409,9 @@ namespace Barotrauma
this.game = game;
menuTabs[(int)Tab.Credits] = new GUIFrame(new RectTransform(Vector2.One, GUI.Canvas), style: null, color: Color.Black * 0.5f)
{
CanBeFocused = false
};
menuTabs[(int)Tab.Credits] = new GUIFrame(new RectTransform(Vector2.One, GUI.Canvas, Anchor.Center), style: null);
new GUIFrame(new RectTransform(GUI.Canvas.RelativeSize, menuTabs[(int)Tab.Credits].RectTransform, Anchor.Center), style: "GUIBackgroundBlocker");
var creditsContainer = new GUIFrame(new RectTransform(new Vector2(0.75f, 1.5f), menuTabs[(int)Tab.Credits].RectTransform, Anchor.CenterRight), style: "OuterGlow", color: Color.Black * 0.8f);
creditsPlayer = new CreditsPlayer(new RectTransform(Vector2.One, creditsContainer.RectTransform), "Content/Texts/Credits.xml");
@@ -1010,11 +1009,12 @@ namespace Barotrauma
GUI.Draw(Cam, spriteBatch);
#if !UNSTABLE
GUI.Font.DrawString(spriteBatch, "Barotrauma v" + GameMain.Version + " (" + AssemblyInfo.GetBuildString() + ", branch " + AssemblyInfo.GetGitBranch() + ", revision " + AssemblyInfo.GetGitRevision() + ")", new Vector2(10, GameMain.GraphicsHeight - 20), Color.White * 0.7f);
string versionString = "Barotrauma v" + GameMain.Version + " (" + AssemblyInfo.GetBuildString() + ", branch " + AssemblyInfo.GetGitBranch() + ", revision " + AssemblyInfo.GetGitRevision() + ")";
GUI.SmallFont.DrawString(spriteBatch, versionString, new Vector2(HUDLayoutSettings.Padding, GameMain.GraphicsHeight - GUI.SmallFont.MeasureString(versionString).Y - HUDLayoutSettings.Padding * 0.75f), Color.White * 0.7f);
#endif
if (selectedTab != Tab.Credits)
{
Vector2 textPos = new Vector2(GameMain.GraphicsWidth - 10, GameMain.GraphicsHeight - 10);
Vector2 textPos = new Vector2(GameMain.GraphicsWidth - HUDLayoutSettings.Padding, GameMain.GraphicsHeight - HUDLayoutSettings.Padding * 0.75f);
for (int i = legalCrap.Length - 1; i >= 0; i--)
{
Vector2 textSize = GUI.SmallFont.MeasureString(legalCrap[i]);
@@ -1069,7 +1069,7 @@ namespace Barotrauma
{
File.Copy(selectedSub.FilePath, Path.Combine(SaveUtil.TempPath, selectedSub.Name + ".sub"), true);
}
catch (IOException e)
catch (System.IO.IOException e)
{
DebugConsole.ThrowError("Copying the file \"" + selectedSub.FilePath + "\" failed. The file may have been deleted or in use by another process. Try again or select another submarine.", e);
GameAnalyticsManager.AddErrorEventOnce(
@@ -4,7 +4,7 @@ using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.IO;
using Barotrauma.IO;
using System.Linq;
using System.Xml.Linq;
@@ -668,7 +668,7 @@ namespace Barotrauma
OnClicked = (btn, obj) =>
{
GameMain.Client.RequestStartRound();
CoroutineManager.StartCoroutine(WaitForStartRound(StartButton, allowCancel: false), "WaitForStartRound");
CoroutineManager.StartCoroutine(WaitForStartRound(StartButton), "WaitForStartRound");
return true;
}
};
@@ -786,6 +786,26 @@ namespace Barotrauma
};
var subLabel = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.055f), subHolder.RectTransform) { MinSize = new Point(0, 25) }, TextManager.Get("Submarine"), font: GUI.SubHeadingFont);
var filterContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.05f), subHolder.RectTransform), isHorizontal: true)
{
Stretch = true
};
var searchTitle = new GUITextBlock(new RectTransform(new Vector2(0.001f, 1.0f), filterContainer.RectTransform), TextManager.Get("serverlog.filter"), textAlignment: Alignment.CenterLeft, font: GUI.Font);
var searchBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 1.0f), filterContainer.RectTransform, Anchor.CenterRight), font: GUI.Font, createClearButton: true);
filterContainer.RectTransform.MinSize = searchBox.RectTransform.MinSize;
searchBox.OnSelected += (sender, userdata) => { searchTitle.Visible = false; };
searchBox.OnDeselected += (sender, userdata) => { searchTitle.Visible = true; };
searchBox.OnTextChanged += (textBox, text) =>
{
foreach (GUIComponent child in subList.Content.Children)
{
if (!(child.UserData is SubmarineInfo sub)) { continue; }
child.Visible = string.IsNullOrEmpty(text) ? true : sub.DisplayName.ToLower().Contains(text.ToLower());
}
return true;
};
subList = new GUIListBox(new RectTransform(Vector2.One, subHolder.RectTransform))
{
OnSelected = VotableClicked
@@ -1173,25 +1193,11 @@ namespace Barotrauma
GUI.ClearCursorWait();
}
public IEnumerable<object> WaitForStartRound(GUIButton startButton, bool allowCancel)
public IEnumerable<object> WaitForStartRound(GUIButton startButton)
{
GUI.SetCursorWaiting();
string headerText = TextManager.Get("RoundStartingPleaseWait");
var msgBox = new GUIMessageBox(headerText, TextManager.Get("RoundStarting"),
allowCancel ? new string[] { TextManager.Get("Cancel") } : new string[0]);
if (allowCancel)
{
msgBox.Buttons[0].OnClicked = (btn, userdata) =>
{
startButton.Enabled = true;
GameMain.Client.RequestRoundEnd();
CoroutineManager.StopCoroutines("WaitForStartRound");
GUI.ClearCursorWait();
return true;
};
msgBox.Buttons[0].OnClicked += msgBox.Close;
}
var msgBox = new GUIMessageBox(headerText, TextManager.Get("RoundStarting"), new string[0]);
if (startButton != null)
{
@@ -1939,13 +1945,15 @@ namespace Barotrauma
public bool SelectPlayer(Client selectedClient)
{
bool myClient = selectedClient.ID == GameMain.Client.ID;
bool hasManagePermissions = GameMain.Client.HasPermission(ClientPermissions.ManagePermissions);
PlayerFrame = new GUIButton(new RectTransform(Vector2.One, GUI.Canvas), style: "GUIBackgroundBlocker")
PlayerFrame = new GUIButton(new RectTransform(Vector2.One, GUI.Canvas, Anchor.Center), style: null)
{
OnClicked = (btn, userdata) => { if (GUI.MouseOn == btn || GUI.MouseOn == btn.TextBlock) ClosePlayerFrame(btn, userdata); return true; }
};
Vector2 frameSize = GameMain.Client.HasPermission(ClientPermissions.ManagePermissions) ? new Vector2(.28f, .5f) : new Vector2(.28f, .24f);
new GUIFrame(new RectTransform(GUI.Canvas.RelativeSize, PlayerFrame.RectTransform, Anchor.Center), style: "GUIBackgroundBlocker");
Vector2 frameSize = hasManagePermissions ? new Vector2(.28f, .5f) : new Vector2(.28f, .15f);
var playerFrameInner = new GUIFrame(new RectTransform(frameSize, PlayerFrame.RectTransform, Anchor.Center) { MinSize = new Point(550, 0) });
var paddedPlayerFrame = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.88f), playerFrameInner.RectTransform, Anchor.Center))
@@ -1954,31 +1962,16 @@ namespace Barotrauma
RelativeSpacing = 0.03f
};
var headerContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.1f), paddedPlayerFrame.RectTransform), isHorizontal: true, childAnchor: Anchor.CenterLeft)
var headerContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, hasManagePermissions ? 0.1f : 0.25f), paddedPlayerFrame.RectTransform), isHorizontal: true, childAnchor: Anchor.CenterLeft)
{
Stretch = true
};
var nameText = new GUITextBlock(new RectTransform(new Vector2(0.6f, 1.0f), headerContainer.RectTransform),
var nameText = new GUITextBlock(new RectTransform(new Vector2(0.5f, 1.0f), headerContainer.RectTransform),
text: selectedClient.Name, font: GUI.LargeFont);
nameText.Text = ToolBox.LimitString(nameText.Text, nameText.Font, nameText.Rect.Width);
nameText.Text = ToolBox.LimitString(nameText.Text, nameText.Font, (int)(nameText.Rect.Width * 0.95f));
if (selectedClient.SteamID != 0 && Steam.SteamManager.IsInitialized)
{
var viewSteamProfileButton = new GUIButton(new RectTransform(new Vector2(0.4f, 1.0f), headerContainer.RectTransform, Anchor.TopCenter) { MaxSize = new Point(int.MaxValue, (int)(40 * GUI.Scale)) },
TextManager.Get("ViewSteamProfile"))
{
UserData = selectedClient
};
viewSteamProfileButton.TextBlock.AutoScaleHorizontal = true;
viewSteamProfileButton.OnClicked = (bt, userdata) =>
{
Steamworks.SteamFriends.OpenWebOverlay("https://steamcommunity.com/profiles/" + selectedClient.SteamID.ToString());
return true;
};
}
if (GameMain.Client.HasPermission(ClientPermissions.ManagePermissions))
if (hasManagePermissions)
{
PlayerFrame.UserData = selectedClient;
@@ -2166,7 +2159,7 @@ namespace Barotrauma
}
var buttonAreaTop = myClient ? null : new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.08f), paddedPlayerFrame.RectTransform), isHorizontal: true);
var buttonAreaLower = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.08f), paddedPlayerFrame.RectTransform), isHorizontal: true);
var buttonAreaLower = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.08f), paddedPlayerFrame.RectTransform), isHorizontal: true, childAnchor: Anchor.CenterLeft);
if (!myClient)
{
@@ -2214,32 +2207,66 @@ namespace Barotrauma
kickButton.OnClicked += ClosePlayerFrame;
}
GUITextBlock.AutoScaleAndNormalize(
buttonAreaTop.Children.Select(c => ((GUIButton)c).TextBlock).Concat(buttonAreaLower.Children.Select(c => ((GUIButton)c).TextBlock)));
if (buttonAreaTop.CountChildren > 0)
{
GUITextBlock.AutoScaleAndNormalize(buttonAreaTop.Children.Select(c => ((GUIButton)c).TextBlock).Concat(buttonAreaLower.Children.Select(c => ((GUIButton)c).TextBlock)));
}
new GUITickBox(new RectTransform(new Vector2(0.25f, 1.0f), buttonAreaTop.RectTransform, Anchor.TopRight),
new GUITickBox(new RectTransform(new Vector2(0.175f, 1.0f), headerContainer.RectTransform, Anchor.TopRight),
TextManager.Get("Mute"))
{
IgnoreLayoutGroups = true,
Selected = selectedClient.MutedLocally,
OnSelected = (tickBox) => { selectedClient.MutedLocally = tickBox.Selected; return true; }
};
}
var closeButton = new GUIButton(new RectTransform(new Vector2(0.3f, 1.0f), buttonAreaLower.RectTransform, Anchor.TopRight),
if (selectedClient.SteamID != 0 && Steam.SteamManager.IsInitialized)
{
var viewSteamProfileButton = new GUIButton(new RectTransform(new Vector2(0.3f, 1.0f), headerContainer.RectTransform, Anchor.TopCenter) { MaxSize = new Point(int.MaxValue, (int)(40 * GUI.Scale)) },
TextManager.Get("ViewSteamProfile"))
{
UserData = selectedClient
};
viewSteamProfileButton.TextBlock.AutoScaleHorizontal = true;
viewSteamProfileButton.OnClicked = (bt, userdata) =>
{
Steamworks.SteamFriends.OpenWebOverlay("https://steamcommunity.com/profiles/" + selectedClient.SteamID.ToString());
return true;
};
}
var closeButton = new GUIButton(new RectTransform(new Vector2(0f, 1.0f), buttonAreaLower.RectTransform, Anchor.CenterRight),
TextManager.Get("Close"))
{
IgnoreLayoutGroups = true,
OnClicked = ClosePlayerFrame
};
float xSize = 1f / buttonAreaLower.CountChildren;
for (int i = 0; i < buttonAreaLower.CountChildren; i++)
{
buttonAreaLower.GetChild(i).RectTransform.RelativeSize = new Vector2(xSize, 1f);
}
buttonAreaLower.RectTransform.NonScaledSize = new Point(buttonAreaLower.Rect.Width, buttonAreaLower.RectTransform.Children.Max(c => c.NonScaledSize.Y));
if (buttonAreaTop != null)
{
buttonAreaTop.RectTransform.NonScaledSize =
buttonAreaLower.RectTransform.NonScaledSize =
new Point(buttonAreaLower.Rect.Width, Math.Max(buttonAreaLower.RectTransform.NonScaledSize.Y, buttonAreaTop.RectTransform.Children.Max(c => c.NonScaledSize.Y)));
if (buttonAreaTop.CountChildren == 0)
{
paddedPlayerFrame.RemoveChild(buttonAreaTop);
}
else
{
for (int i = 0; i < buttonAreaTop.CountChildren; i++)
{
buttonAreaTop.GetChild(i).RectTransform.RelativeSize = new Vector2(1f / 3f, 1f);
}
buttonAreaTop.RectTransform.NonScaledSize =
buttonAreaLower.RectTransform.NonScaledSize =
new Point(buttonAreaLower.Rect.Width, Math.Max(buttonAreaLower.RectTransform.NonScaledSize.Y, buttonAreaTop.RectTransform.Children.Max(c => c.NonScaledSize.Y)));
}
}
return false;
@@ -3086,7 +3113,7 @@ namespace Barotrauma
StartRound = () =>
{
GameMain.Client.RequestStartRound();
CoroutineManager.StartCoroutine(WaitForStartRound(campaignUI.StartButton, allowCancel: true), "WaitForStartRound");
CoroutineManager.StartCoroutine(WaitForStartRound(campaignUI.StartButton), "WaitForStartRound");
}
};
@@ -3145,8 +3172,8 @@ namespace Barotrauma
{
if (!(button.UserData is Pair<JobPrefab, int> jobPrefab)) { return false; }
JobInfoFrame = jobPrefab.First.CreateInfoFrame(jobPrefab.Second);
GUIButton closeButton = new GUIButton(new RectTransform(new Vector2(0.25f, 0.05f), JobInfoFrame.GetChild(2).GetChild(0).RectTransform, Anchor.BottomRight),
JobInfoFrame = jobPrefab.First.CreateInfoFrame(out GUIComponent buttonContainer);
GUIButton closeButton = new GUIButton(new RectTransform(new Vector2(0.25f, 0.05f), buttonContainer.RectTransform, Anchor.BottomRight),
TextManager.Get("Close"))
{
OnClicked = CloseJobInfo
@@ -3304,7 +3331,8 @@ namespace Barotrauma
{
CreateSubPreview(sub);
}
if (subList.SelectedData is SubmarineInfo selectedSub && selectedSub.MD5Hash?.Hash == md5Hash && System.IO.File.Exists(sub.FilePath))
if (subList.SelectedData is SubmarineInfo selectedSub && selectedSub.MD5Hash?.Hash == md5Hash && Barotrauma.IO.File.Exists(sub.FilePath))
{
return true;
}
@@ -4,9 +4,14 @@ using Barotrauma.Particles;
using System;
using System.Collections.Generic;
using System.Xml.Linq;
using System.Xml;
using System.Text;
using Barotrauma.Extensions;
#if DEBUG
using System.IO;
using System.Xml;
#else
using Barotrauma.IO;
#endif
namespace Barotrauma
{
@@ -242,7 +247,7 @@ namespace Barotrauma
}
}
XmlWriterSettings settings = new XmlWriterSettings
System.Xml.XmlWriterSettings settings = new System.Xml.XmlWriterSettings
{
Indent = true,
OmitXmlDeclaration = true,
@@ -262,7 +267,7 @@ namespace Barotrauma
#if WINDOWS
if (prefab == null) { return; }
XmlWriterSettings settings = new XmlWriterSettings
System.Xml.XmlWriterSettings settings = new System.Xml.XmlWriterSettings
{
Indent = true,
OmitXmlDeclaration = true,
@@ -295,7 +300,7 @@ namespace Barotrauma
}
StringBuilder sb = new StringBuilder();
using (var writer = XmlWriter.Create(sb, settings))
using (var writer = System.Xml.XmlWriter.Create(sb, settings))
{
originalElement.WriteTo(writer);
writer.Flush();
@@ -14,10 +14,11 @@ namespace Barotrauma
{
if (frame == null)
{
frame = new GUIFrame(new RectTransform(Vector2.One, GUICanvas.Instance), style: null)
frame = new GUIFrame(new RectTransform(GUICanvas.Instance.RelativeSize, GUICanvas.Instance), style: null)
{
CanBeFocused = false
};
}
return frame;
}
@@ -6,7 +6,7 @@ using Microsoft.Xna.Framework.Graphics;
using RestSharp;
using System;
using System.Collections.Generic;
using System.IO;
using Barotrauma.IO;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
@@ -683,7 +683,21 @@ namespace Barotrauma
if (!File.Exists(file)) { return; }
XDocument doc = XMLExtensions.TryLoadXml(file);
if (doc == null) { return; }
if (doc == null)
{
DebugConsole.NewMessage("Failed to load file \"" + file + "\". Attempting to recreate the file...");
try
{
doc = new XDocument(new XElement("servers"));
doc.Save(file);
DebugConsole.NewMessage("Recreated \"" + file + "\".");
}
catch (Exception e)
{
DebugConsole.ThrowError("Failed to recreate the file \"" + file + "\".", e);
}
return;
}
foreach (XElement element in doc.Root.Elements())
{
@@ -705,7 +719,7 @@ namespace Barotrauma
rootElement.Add(info.ToXElement());
}
doc.Save(file);
doc.SaveSafe(file);
}
public ServerInfo UpdateServerInfoWithServerSettings(object endpoint, ServerSettings serverSettings)
@@ -1670,7 +1684,7 @@ namespace Barotrauma
{
CanBeFocused = false,
Selected =
serverInfo.GameVersion == GameMain.Version.ToString() &&
(NetworkMember.IsCompatible(GameMain.Version.ToString(), serverInfo.GameVersion) ?? true) &&
serverInfo.ContentPackagesMatch(GameMain.SelectedPackages),
UserData = "compatible"
};
@@ -1696,6 +1710,14 @@ namespace Barotrauma
serverName.Text = ToolBox.LimitString(serverName.Text, serverName.Font, serverName.Rect.Width);
};
if (serverInfo.ContentPackageNames.Any())
{
if (serverInfo.ContentPackageNames.Any(cp => !cp.Equals(GameMain.VanillaContent.Name, StringComparison.OrdinalIgnoreCase)))
{
serverName.TextColor = new Color(219, 125, 217);
}
}
new GUITickBox(new RectTransform(new Vector2(columnRelativeWidth[3], 0.9f), serverContent.RectTransform, Anchor.Center), label: "")
{
ToolTip = TextManager.Get((serverInfo.GameStarted) ? "ServerListRoundStarted" : "ServerListRoundNotStarted"),
@@ -3,10 +3,14 @@ using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml.Linq;
using Barotrauma.Extensions;
#if DEBUG
using System.IO;
#else
using Barotrauma.IO;
#endif
namespace Barotrauma
{
@@ -415,7 +419,11 @@ namespace Barotrauma
{
string xmlPath = doc.ParseContentPathFromUri();
xmlPathText.Text += "\n" + xmlPath;
#if DEBUG
doc.Save(xmlPath);
#else
doc.SaveSafe(xmlPath);
#endif
}
xmlPathText.TextColor = GUI.Style.Green;
return true;
@@ -4,7 +4,7 @@ using Microsoft.Xna.Framework.Graphics;
using RestSharp;
using System;
using System.Collections.Generic;
using System.IO;
using Barotrauma.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -15,6 +15,7 @@ namespace Barotrauma
{
private GUIFrame menu;
private GUIListBox subscribedItemList, topItemList;
private GUITextBox subscribedItemFilter, topItemFilter;
private GUIListBox publishedItemList, myItemList;
@@ -26,7 +27,7 @@ namespace Barotrauma
//listbox that shows the files included in the item being created
private GUIListBox createItemFileList;
private FileSystemWatcher createItemWatcher;
private System.IO.FileSystemWatcher createItemWatcher;
private readonly List<GUIButton> tabButtons = new List<GUIButton>();
@@ -135,6 +136,8 @@ namespace Barotrauma
}
};
subscribedItemFilter = CreateFilterBox(modsContainer, subscribedItemList);
modsPreviewFrame = new GUIFrame(new RectTransform(new Vector2(0.6f, 1.0f), tabs[(int)Tab.Mods].RectTransform, Anchor.TopRight), style: null);
//-------------------------------------------------------------------------------
@@ -163,6 +166,8 @@ namespace Barotrauma
}
};
topItemFilter = CreateFilterBox(listContainer, topItemList);
new GUIButton(new RectTransform(new Vector2(1.0f, 0.02f), listContainer.RectTransform), TextManager.Get("FindModsButton"), style: "GUIButtonSmall")
{
OnClicked = (btn, userdata) =>
@@ -235,6 +240,31 @@ namespace Barotrauma
subscribedCoroutine = CoroutineManager.StartCoroutine(PollSubscribedItems());
}
private GUITextBox CreateFilterBox(GUIComponent parent, GUIListBox listbox)
{
var filterContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.05f), parent.RectTransform), isHorizontal: true)
{
Stretch = true
};
filterContainer.RectTransform.SetAsFirstChild();
var searchTitle = new GUITextBlock(new RectTransform(new Vector2(0.001f, 1.0f), filterContainer.RectTransform), TextManager.Get("serverlog.filter"), textAlignment: Alignment.CenterLeft, font: GUI.Font);
var searchBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 1.0f), filterContainer.RectTransform, Anchor.CenterRight), font: GUI.Font, createClearButton: true);
filterContainer.RectTransform.MinSize = searchBox.RectTransform.MinSize;
searchBox.OnSelected += (sender, userdata) => { searchTitle.Visible = false; };
searchBox.OnDeselected += (sender, userdata) => { searchTitle.Visible = true; };
searchBox.OnTextChanged += (textBox, text) =>
{
foreach (GUIComponent child in listbox.Content.Children)
{
if (!(child.UserData is Steamworks.Ugc.Item item)) { continue; }
child.Visible = string.IsNullOrEmpty(text) ? true : (item.Title?.ToLower().Contains(text.ToLower()) ?? false);
}
return true;
};
return searchBox;
}
public override void Select()
{
base.Select();
@@ -448,6 +478,18 @@ namespace Barotrauma
return;
}
string text = string.Empty;
if (listBox == subscribedItemList)
{
text = subscribedItemFilter.Text;
}
else if (listBox == topItemList)
{
text = topItemFilter.Text;
}
bool visible = string.IsNullOrEmpty(text) ? true : (item?.Title?.ToLower().Contains(text.ToLower()) ?? false);
int prevIndex = -1;
var existingFrame = listBox.Content.FindChild((component) => { return (component.UserData is Steamworks.Ugc.Item?) && (component.UserData as Steamworks.Ugc.Item?)?.Id == item?.Id; });
if (existingFrame != null)
@@ -459,7 +501,8 @@ namespace Barotrauma
var itemFrame = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.1f), listBox.Content.RectTransform, minSize: new Point(0, 80)),
style: "ListBoxElement")
{
UserData = item
UserData = item,
Visible = visible
};
if (prevIndex > -1)
{
@@ -583,7 +626,7 @@ namespace Barotrauma
}
else
{
installed = SteamManager.EnableWorkShopItem(item, true, out string errorMsg, Selected == this);
installed = SteamManager.EnableWorkShopItem(item, out string errorMsg, Selected == this);
if (!installed)
{
DebugConsole.NewMessage(errorMsg, Color.Red);
@@ -643,7 +686,7 @@ namespace Barotrauma
{
bool reselect = GameMain.Config.SelectedContentPackages.Any(cp => !string.IsNullOrWhiteSpace(cp.SteamWorkshopUrl) && cp.SteamWorkshopUrl == item?.Url);
if (!SteamManager.DisableWorkShopItem(item, false, out string errorMsg) ||
!SteamManager.EnableWorkShopItem(item, true, out errorMsg, reselect, true))
!SteamManager.EnableWorkShopItem(item, out errorMsg, reselect, true))
{
DebugConsole.ThrowError($"Failed to reinstall \"{item?.Title}\": {errorMsg}", null, true);
elem.Flash(GUI.Style.Red);
@@ -837,7 +880,7 @@ namespace Barotrauma
item?.Download(onInstalled: () =>
{
if (SteamManager.EnableWorkShopItem(item, false, out _))
if (SteamManager.EnableWorkShopItem(item, out _))
{
textBlock.Text = TextManager.Get("workshopiteminstalled");
frame.Flash(GUI.Style.Green);
@@ -1038,7 +1081,7 @@ namespace Barotrauma
string previewImagePath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(itemContentPackage.Path), SteamManager.PreviewImageName));
try
{
using (Stream s = File.Create(previewImagePath))
using (System.IO.Stream s = File.Create(previewImagePath))
{
sub.PreviewImage.Texture.SaveAsPng(s, (int)sub.PreviewImage.size.X, (int)sub.PreviewImage.size.Y);
itemEditor = itemEditor?.WithPreviewFile(previewImagePath);
@@ -1290,10 +1333,10 @@ namespace Barotrauma
};
createItemFileList = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.35f), createItemContent.RectTransform));
createItemWatcher?.Dispose();
createItemWatcher = new FileSystemWatcher(Path.GetDirectoryName(itemContentPackage.Path))
createItemWatcher = new System.IO.FileSystemWatcher(Path.GetDirectoryName(itemContentPackage.Path))
{
Filter = "*",
NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName
NotifyFilter = System.IO.NotifyFilters.LastWrite | System.IO.NotifyFilters.FileName | System.IO.NotifyFilters.DirectoryName
};
createItemWatcher.Created += OnFileSystemChanges;
createItemWatcher.Deleted += OnFileSystemChanges;
@@ -1551,7 +1594,7 @@ namespace Barotrauma
volatile bool refreshFileList = false;
private void OnFileSystemChanges(object sender, FileSystemEventArgs e)
private void OnFileSystemChanges(object sender, System.IO.FileSystemEventArgs e)
{
refreshFileList = true;
}
@@ -1564,14 +1607,26 @@ namespace Barotrauma
List<ContentFile> files = itemContentPackage.Files.ToList();
foreach (ContentFile contentFile in files)
for (int i = files.Count - 1; i >= 0; i--)
{
ContentFile contentFile = files[i];
bool fileExists = File.Exists(contentFile.Path);
if (!fileExists) { itemContentPackage.Files.Remove(contentFile); continue; }
if (contentFile.Type == ContentType.Executable ||
contentFile.Type == ContentType.ServerExecutable)
{
fileExists |= File.Exists(contentFile.Path + ".dll");
}
if (!fileExists)
{
itemContentPackage.Files.Remove(contentFile);
files.RemoveAt(i);
}
}
List<ContentFile> allFiles = Directory.GetFiles(Path.GetDirectoryName(itemContentPackage.Path), "*", SearchOption.AllDirectories)
List<ContentFile> allFiles = Directory.GetFiles(Path.GetDirectoryName(itemContentPackage.Path), "*", System.IO.SearchOption.AllDirectories)
.Select(f => new ContentFile(f, ContentType.None))
.Where(file => Path.GetFileName(file.Path) != SteamManager.MetadataFileName &&
Path.GetFileName(file.Path) != SteamManager.PreviewImageName)
@@ -1579,22 +1634,31 @@ namespace Barotrauma
for (int i=0;i<allFiles.Count;i++)
{
ContentFile file = allFiles[i];
ContentFile otherFile = itemContentPackage.Files.Find(f => string.Equals(Path.GetFullPath(f.Path).CleanUpPath(),
Path.GetFullPath(file.Path).CleanUpPath(),
StringComparison.InvariantCultureIgnoreCase));
ContentFile otherFile = files.Find(f => string.Equals(Path.GetFullPath(f.Path).CleanUpPath(),
Path.GetFullPath(file.Path).CleanUpPath(),
StringComparison.InvariantCultureIgnoreCase));
if (otherFile != null)
{
//replace the generated ContentFile object with the one that's present in the
//content package to determine which tickboxes should already be checked
allFiles[i] = otherFile;
files.Remove(otherFile);
}
}
allFiles.AddRange(files);
foreach (ContentFile contentFile in allFiles)
{
bool illegalPath = !ContentPackage.IsModFilePathAllowed(contentFile);
bool fileExists = File.Exists(contentFile.Path);
if (contentFile.Type == ContentType.Executable ||
contentFile.Type == ContentType.ServerExecutable)
{
fileExists |= File.Exists(contentFile.Path + ".dll");
}
var fileFrame = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.12f), createItemFileList.Content.RectTransform) { MinSize = new Point(0, 20) },
style: "ListBoxElement")
{
@@ -1662,36 +1726,39 @@ namespace Barotrauma
return true;
};
new GUIButton(new RectTransform(new Vector2(0.2f, 1.0f), content.RectTransform), TextManager.Get("Delete"), style: "GUIButtonSmall")
if (!files.Contains(contentFile)) //this prevents deletion of files not contained in the mod's path (i.e. vanilla content)
{
OnClicked = (btn, userdata) =>
new GUIButton(new RectTransform(new Vector2(0.2f, 1.0f), content.RectTransform), TextManager.Get("Delete"), style: "GUIButtonSmall")
{
var msgBox = new GUIMessageBox(TextManager.Get("ConfirmFileDeletionHeader"),
TextManager.GetWithVariable("ConfirmFileDeletion", "[file]", contentFile.Path),
new string[] { TextManager.Get("Yes"), TextManager.Get("Cancel") })
OnClicked = (btn, userdata) =>
{
UserData = "verificationprompt"
};
msgBox.Buttons[0].OnClicked = (applyButton, obj) =>
{
try
var msgBox = new GUIMessageBox(TextManager.Get("ConfirmFileDeletionHeader"),
TextManager.GetWithVariable("ConfirmFileDeletion", "[file]", contentFile.Path),
new string[] { TextManager.Get("Yes"), TextManager.Get("Cancel") })
{
File.Delete(contentFile.Path);
if (contentFile.Type == ContentType.Submarine) { SubmarineInfo.RefreshSavedSub(contentFile.Path); }
}
catch (Exception e)
UserData = "verificationprompt"
};
msgBox.Buttons[0].OnClicked = (applyButton, obj) =>
{
DebugConsole.ThrowError($"Failed to delete \"${contentFile.Path}\".", e);
}
//RefreshCreateItemFileList();
RefreshMyItemList();
try
{
File.Delete(contentFile.Path);
if (contentFile.Type == ContentType.Submarine) { SubmarineInfo.RefreshSavedSub(contentFile.Path); }
}
catch (Exception e)
{
DebugConsole.ThrowError($"Failed to delete \"${contentFile.Path}\".", e);
}
//RefreshCreateItemFileList();
RefreshMyItemList();
return true;
};
msgBox.Buttons[0].OnClicked += msgBox.Close;
msgBox.Buttons[1].OnClicked = msgBox.Close;
return true;
};
msgBox.Buttons[0].OnClicked += msgBox.Close;
msgBox.Buttons[1].OnClicked = msgBox.Close;
return true;
}
};
}
};
}
content.Recalculate();
fileFrame.RectTransform.MinSize =
@@ -1714,7 +1781,7 @@ namespace Barotrauma
var workshopPublishStatus = SteamManager.StartPublishItem(itemContentPackage, itemEditor);
if (workshopPublishStatus != null)
{
if (!itemEditor.Value.Tags.Contains("unstable")) { itemEditor.Value.Tags.Add("unstable"); }
if (!(itemEditor?.HasTag("unstable") ?? false)) { itemEditor = itemEditor?.WithTag("unstable"); }
CoroutineManager.StartCoroutine(WaitForPublish(workshopPublishStatus), "WaitForPublish");
}
msgBox.Close();
@@ -4,11 +4,15 @@ using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Xml.Linq;
using Microsoft.Xna.Framework.Input;
#if DEBUG
using System.IO;
#else
using Barotrauma.IO;
#endif
// ReSharper disable AccessToModifiedClosure, PossibleLossOfFraction, RedundantLambdaParameterType, UnusedVariable
@@ -50,7 +54,7 @@ namespace Barotrauma
private GUITextBlock subNameLabel;
private bool showThalamus = true;
public bool ShowThalamus { get; private set; } = true;
private bool entityMenuOpen = true;
private float entityMenuOpenState = 1.0f;
@@ -183,7 +187,7 @@ namespace Barotrauma
private void CreateUI()
{
TopPanel = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.01f), GUI.Canvas) { MinSize = new Point(0, 35) }, "GUIFrameTop");
TopPanel = new GUIFrame(new RectTransform(new Vector2(GUI.Canvas.RelativeSize.X, 0.01f), GUI.Canvas) { MinSize = new Point(0, 35) }, "GUIFrameTop");
GUILayoutGroup paddedTopPanel = new GUILayoutGroup(new RectTransform(new Vector2(0.98f, 0.8f), TopPanel.RectTransform, Anchor.Center),
isHorizontal: true, childAnchor: Anchor.CenterLeft)
@@ -480,8 +484,8 @@ namespace Barotrauma
new GUITickBox(new RectTransform(new Vector2(1.0f, 0.1f), paddedShowEntitiesPanel.RectTransform), TextManager.Get("mapentitycategory.thalamus"))
{
UserData = "thalamus",
Selected = showThalamus,
OnSelected = (GUITickBox obj) => { showThalamus = obj.Selected; return true; },
Selected = ShowThalamus,
OnSelected = (GUITickBox obj) => { ShowThalamus = obj.Selected; return true; },
};
showEntitiesTickBoxes.AddRange(paddedShowEntitiesPanel.Children.Select(c => c as GUITickBox));
@@ -747,10 +751,15 @@ namespace Barotrauma
frame.RectTransform.MinSize = new Point(0, frame.Rect.Width);
frame.RectTransform.MaxSize = new Point(int.MaxValue, frame.Rect.Width);
string name = legacy ? ep.Name + " (legacy)" : ep.Name;
string name = legacy ? TextManager.GetWithVariable("legacyitemformat", "[name]", ep.Name) : ep.Name;
frame.ToolTip = string.IsNullOrEmpty(ep.Description) ? name : name + '\n' + ep.Description;
if (ep.HideInMenus)
{
frame.Color = Color.Red;
name = "[HIDDEN] " + name;
}
GUILayoutGroup paddedFrame = new GUILayoutGroup(new RectTransform(new Vector2(0.8f, 0.8f), frame.RectTransform, Anchor.Center), childAnchor: Anchor.TopCenter)
{
Stretch = true,
@@ -787,7 +796,11 @@ namespace Barotrauma
if (ep is ItemAssemblyPrefab itemAssemblyPrefab)
{
new GUICustomComponent(new RectTransform(new Vector2(1.0f, 0.75f),
paddedFrame.RectTransform, Anchor.TopCenter), onDraw: itemAssemblyPrefab.DrawIcon)
paddedFrame.RectTransform, Anchor.TopCenter), onDraw: (sb, customComponent) =>
{
if (GUIImage.LoadingTextures) { return; }
itemAssemblyPrefab.DrawIcon(sb, customComponent);
})
{
HideElementsOutsideFrame = true,
ToolTip = frame.RawToolTip
@@ -795,7 +808,7 @@ namespace Barotrauma
}
GUITextBlock textBlock = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), paddedFrame.RectTransform, Anchor.BottomCenter),
text: ep.Name, textAlignment: Alignment.Center, font: GUI.SmallFont)
text: name, textAlignment: Alignment.Center, font: GUI.SmallFont)
{
CanBeFocused = false
};
@@ -1169,7 +1182,7 @@ namespace Barotrauma
if (!Directory.Exists(filePath))
{
var e = Directory.CreateDirectory(filePath);
e.Attributes = FileAttributes.Directory | FileAttributes.Hidden;
e.Attributes = System.IO.FileAttributes.Directory | System.IO.FileAttributes.Hidden;
if (!e.Exists) { return; }
}
@@ -1221,15 +1234,33 @@ namespace Barotrauma
return false;
}
Submarine.MainSub.Info.Name = name;
string savePath = name + ".sub";
string prevSavePath = null;
if (!string.IsNullOrEmpty(Submarine.MainSub?.Info.FilePath) &&
Submarine.MainSub.Info.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase))
{
prevSavePath = Submarine.MainSub.Info.FilePath.CleanUpPath();
savePath = Path.Combine(Path.GetDirectoryName(Submarine.MainSub.Info.FilePath), savePath).CleanUpPath();
string prevDir = Path.GetDirectoryName(Submarine.MainSub.Info.FilePath).CleanUpPath();
string[] subDirs = prevDir.Split('/');
bool forceToSubFolder = Steam.SteamManager.IsInitialized;
bool isInSubFolder = subDirs.Length > 0 && subDirs[0].Equals("Submarines", StringComparison.InvariantCultureIgnoreCase);
if (forceToSubFolder && subDirs.Length > 1 && subDirs[0].Equals("Mods", StringComparison.InvariantCultureIgnoreCase))
{
string modName = subDirs[1];
ContentPackage contentPackage = ContentPackage.List.Find(p => p.Name.Equals(modName, StringComparison.InvariantCultureIgnoreCase));
if (contentPackage != null)
{
Steamworks.Data.PublishedFileId packageId = Steam.SteamManager.GetWorkshopItemIDFromUrl(contentPackage.SteamWorkshopUrl);
Steamworks.Ugc.Item? item = Steamworks.Ugc.Item.GetAsync(packageId).Result;
if (item?.Owner.Id == Steam.SteamManager.GetSteamID())
{
forceToSubFolder = false;
contentPackage.Files.Add(new ContentFile(Path.Combine(prevDir, savePath).CleanUpPath(), ContentType.Submarine));
contentPackage.Save(contentPackage.Path);
}
}
}
savePath = Path.Combine(forceToSubFolder && !isInSubFolder ? SubmarineInfo.SavePath : prevDir, savePath).CleanUpPath();
}
else
{
@@ -1255,7 +1286,7 @@ namespace Barotrauma
if (previewImage?.Sprite?.Texture != null)
{
bool savePreviewImage = true;
using MemoryStream imgStream = new MemoryStream();
using System.IO.MemoryStream imgStream = new System.IO.MemoryStream();
try
{
previewImage.Sprite.Texture.SaveAsPng(imgStream, previewImage.Sprite.Texture.Width, previewImage.Sprite.Texture.Height);
@@ -1298,11 +1329,13 @@ namespace Barotrauma
SetMode(Mode.Default);
}
saveFrame = new GUIButton(new RectTransform(Vector2.One, GUI.Canvas), style: "GUIBackgroundBlocker")
saveFrame = new GUIButton(new RectTransform(Vector2.One, GUI.Canvas, Anchor.Center), style: null)
{
OnClicked = (btn, userdata) => { if (GUI.MouseOn == btn || GUI.MouseOn == btn.TextBlock) saveFrame = null; return true; }
};
new GUIFrame(new RectTransform(GUI.Canvas.RelativeSize, saveFrame.RectTransform, Anchor.Center), style: "GUIBackgroundBlocker");
var innerFrame = new GUIFrame(new RectTransform(new Vector2(0.4f, 0.5f), saveFrame.RectTransform, Anchor.Center) { MinSize = new Point(750, 400) });
var paddedSaveFrame = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.9f), innerFrame.RectTransform, Anchor.Center)) { Stretch = true, RelativeSpacing = 0.02f };
@@ -1465,10 +1498,10 @@ namespace Barotrauma
{
OnClicked = (btn, userdata) =>
{
using (MemoryStream imgStream = new MemoryStream())
using (System.IO.MemoryStream imgStream = new System.IO.MemoryStream())
{
CreateImage(defaultPreviewImageSize.X, defaultPreviewImageSize.Y, imgStream);
previewImage.Sprite = new Sprite(TextureLoader.FromStream(imgStream), null, null);
previewImage.Sprite = new Sprite(TextureLoader.FromStream(imgStream, compress: false), null, null);
if (Submarine.MainSub != null)
{
Submarine.MainSub.Info.PreviewImage = previewImage.Sprite;
@@ -1611,11 +1644,13 @@ namespace Barotrauma
{
SetMode(Mode.Default);
saveFrame = new GUIButton(new RectTransform(Vector2.One, GUI.Canvas), style: "GUIBackgroundBlocker")
saveFrame = new GUIButton(new RectTransform(Vector2.One, GUI.Canvas, Anchor.Center), style: null)
{
OnClicked = (btn, userdata) => { if (GUI.MouseOn == btn || GUI.MouseOn == btn.TextBlock) saveFrame = null; return true; }
};
new GUIFrame(new RectTransform(GUI.Canvas.RelativeSize, saveFrame.RectTransform, Anchor.Center), style: "GUIBackgroundBlocker");
var innerFrame = new GUIFrame(new RectTransform(new Vector2(0.25f, 0.3f), saveFrame.RectTransform, Anchor.Center) { MinSize = new Point(400, 300) });
GUILayoutGroup paddedSaveFrame = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.9f), innerFrame.RectTransform, Anchor.Center))
{
@@ -1703,10 +1738,24 @@ namespace Barotrauma
}
}
var hideInMenusTickBox = nameBox.Parent.GetChildByUserData("hideinmenus") as GUITickBox;
bool hideInMenus = hideInMenusTickBox == null ? false : hideInMenusTickBox.Selected;
string saveFolder = Path.Combine("Content", "Items", "Assemblies");
bool hideInMenus = !(nameBox.Parent.GetChildByUserData("hideinmenus") is GUITickBox hideInMenusTickBox) ? false : hideInMenusTickBox.Selected;
#if DEBUG
string saveFolder = ItemAssemblyPrefab.VanillaSaveFolder;
#else
string saveFolder = ItemAssemblyPrefab.SaveFolder;
if (!Directory.Exists(saveFolder))
{
try
{
Directory.CreateDirectory(saveFolder);
}
catch (Exception e)
{
DebugConsole.ThrowError("Failed to create a directory for the item assmebly.", e);
return false;
}
}
#endif
string filePath = Path.Combine(saveFolder, nameBox.Text + ".xml");
if (File.Exists(filePath))
@@ -1729,8 +1778,11 @@ namespace Barotrauma
void Save()
{
XDocument doc = new XDocument(ItemAssemblyPrefab.Save(MapEntity.SelectedList, nameBox.Text, descriptionBox.Text, hideInMenus));
#if DEBUG
doc.Save(filePath);
#else
doc.SaveSafe(filePath);
#endif
new ItemAssemblyPrefab(filePath);
UpdateEntityList();
}
@@ -1744,11 +1796,13 @@ namespace Barotrauma
CloseItem();
SetMode(Mode.Default);
loadFrame = new GUIButton(new RectTransform(Vector2.One, GUI.Canvas), style: "GUIBackgroundBlocker")
loadFrame = new GUIButton(new RectTransform(Vector2.One, GUI.Canvas, Anchor.Center), style: null)
{
OnClicked = (btn, userdata) => { if (GUI.MouseOn == btn || GUI.MouseOn == btn.TextBlock) loadFrame = null; return true; },
};
new GUIFrame(new RectTransform(GUI.Canvas.RelativeSize, loadFrame.RectTransform, Anchor.Center), style: "GUIBackgroundBlocker");
var innerFrame = new GUIFrame(new RectTransform(new Vector2(0.3f, 0.5f), loadFrame.RectTransform, Anchor.Center) { MinSize = new Point(350, 500) });
var paddedLoadFrame = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.9f), innerFrame.RectTransform, Anchor.Center)) { Stretch = true, RelativeSpacing = 0.02f };
@@ -3025,6 +3079,7 @@ namespace Barotrauma
}
hullVolumeFrame.Visible = MapEntity.SelectedList.Any(s => s is Hull);
hullVolumeFrame.RectTransform.AbsoluteOffset = new Point(Math.Max(showEntitiesPanel.Rect.Right, previouslyUsedPanel.Rect.Right), 0);
saveAssemblyFrame.Visible = MapEntity.SelectedList.Count > 0;
var offset = cam.WorldView.Top - cam.ScreenToWorld(new Vector2(0, GameMain.GraphicsHeight - EntityMenu.Rect.Top)).Y;
@@ -3547,7 +3602,7 @@ namespace Barotrauma
}
Submarine.DrawBack(spriteBatch, true, e =>
e is Structure s &&
(showThalamus || !s.prefab.Category.HasFlag(MapEntityCategory.Thalamus)) &&
(ShowThalamus || !s.prefab.Category.HasFlag(MapEntityCategory.Thalamus)) &&
(e.SpriteDepth >= 0.9f || s.Prefab.BackgroundSprite != null));
spriteBatch.End();
@@ -3567,15 +3622,15 @@ namespace Barotrauma
Submarine.DrawBack(spriteBatch, true, e =>
(!(e is Structure) || e.SpriteDepth < 0.9f) &&
(showThalamus || !e.prefab.Category.HasFlag(MapEntityCategory.Thalamus)));
(ShowThalamus || !e.prefab.Category.HasFlag(MapEntityCategory.Thalamus)));
spriteBatch.End();
spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.NonPremultiplied, transformMatrix: cam.Transform);
Submarine.DrawDamageable(spriteBatch, null, editing: true, e => showThalamus || !(e.prefab?.Category.HasFlag(MapEntityCategory.Thalamus) ?? false));
Submarine.DrawDamageable(spriteBatch, null, editing: true, e => ShowThalamus || !(e.prefab?.Category.HasFlag(MapEntityCategory.Thalamus) ?? false));
spriteBatch.End();
spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.NonPremultiplied, transformMatrix: cam.Transform);
Submarine.DrawFront(spriteBatch, editing: true, e => showThalamus || !(e.prefab?.Category.HasFlag(MapEntityCategory.Thalamus) ?? false));
Submarine.DrawFront(spriteBatch, editing: true, e => ShowThalamus || !(e.prefab?.Category.HasFlag(MapEntityCategory.Thalamus) ?? false));
if (!WiringMode && !IsMouseOnEditorGUI())
{
MapEntityPrefab.Selected?.DrawPlacing(spriteBatch, cam);
@@ -3636,7 +3691,7 @@ namespace Barotrauma
spriteBatch.End();
}
private void CreateImage(int width, int height, Stream stream)
private void CreateImage(int width, int height, System.IO.Stream stream)
{
MapEntity.SelectedList.Clear();
@@ -3688,7 +3743,7 @@ namespace Barotrauma
public void SaveScreenShot(int width, int height, string filePath)
{
Stream stream = File.OpenWrite(filePath);
System.IO.Stream stream = File.OpenWrite(filePath);
CreateImage(width, height, stream);
stream.Dispose();
}