(a00338777) v0.9.2.1

This commit is contained in:
Joonas Rikkonen
2019-08-26 19:58:19 +03:00
parent 0f63da27b2
commit 80698b58b0
311 changed files with 11763 additions and 4507 deletions
@@ -599,7 +599,8 @@ namespace Barotrauma
if (!tb.Selected) { return false; }
RefreshMissionTab(tb.UserData as Mission);
Campaign.Map.OnMissionSelected?.Invoke(connection, mission);
if (GameMain.Client != null && GameMain.Client.HasPermission(Networking.ClientPermissions.ManageCampaign))
if ((Campaign is MultiPlayerCampaign multiPlayerCampaign) && !multiPlayerCampaign.SuppressStateSending &&
GameMain.Client != null && GameMain.Client.HasPermission(Networking.ClientPermissions.ManageCampaign))
{
GameMain.Client?.SendCampaignState();
}
@@ -97,7 +97,7 @@ namespace Barotrauma
SoundPlayer.OverrideMusicType = "none";
SoundPlayer.OverrideMusicDuration = null;
GameMain.SoundManager.SetCategoryGainMultiplier("waterambience", 0.0f);
GameMain.SoundManager.SetCategoryGainMultiplier("waterambience", 0.0f, 0);
GUI.ForceMouseOn(null);
CalculateSpritesheetPosition();
@@ -195,7 +195,7 @@ namespace Barotrauma
base.Deselect();
SoundPlayer.OverrideMusicType = null;
GameMain.SoundManager.SetCategoryGainMultiplier("waterambience", GameMain.Config.SoundVolume);
GameMain.SoundManager.SetCategoryGainMultiplier("waterambience", GameMain.Config.SoundVolume, 0);
GUI.ForceMouseOn(null);
if (isEndlessRunner)
@@ -1467,6 +1467,7 @@ namespace Barotrauma
private void ShowWearables()
{
if (character.Inventory == null) { return; }
foreach (var item in character.Inventory.Items)
{
if (item == null) { continue; }
@@ -1478,7 +1479,7 @@ namespace Barotrauma
private void HideWearables()
{
character.Inventory.Items.ForEachMod(i => i?.Unequip(character));
character.Inventory?.Items.ForEachMod(i => i?.Unequip(character));
}
#endregion
@@ -23,8 +23,8 @@ namespace Barotrauma
private CampaignSetupUI campaignSetupUI;
private GUITextBox serverNameBox, portBox, queryPortBox, passwordBox, maxPlayersBox;
private GUITickBox isPublicBox, useUpnpBox;
private GUITextBox serverNameBox, /*portBox, queryPortBox,*/ passwordBox, maxPlayersBox;
private GUITickBox isPublicBox/*, useUpnpBox*/;
private GUIButton joinServerButton, hostServerButton, steamWorkshopButton;
@@ -203,10 +203,6 @@ namespace Barotrauma
UserData = Tab.SteamWorkshop,
OnClicked = SelectTab
};
/*#if OSX && !DEBUG
steamWorkshopButton.Text += " (Not yet available on MacOS)";
#endif*/
}
new GUIButton(new RectTransform(new Vector2(1.0f, 1.0f), customizeList.RectTransform), TextManager.Get("SubEditorButton"), textAlignment: Alignment.Left, style: "MainMenuGUIButton")
@@ -256,7 +252,7 @@ namespace Barotrauma
UserData = Tab.Settings,
OnClicked = SelectTab
};
//TODO: translate
new GUIButton(new RectTransform(new Vector2(1.0f, 1.0f), optionList.RectTransform), TextManager.Get("CreditsButton"), textAlignment: Alignment.Left, style: "MainMenuGUIButton")
{
ForceUpperCase = true,
@@ -323,7 +319,7 @@ namespace Barotrauma
StartNewGame = StartGame
};
var hostServerScale = new Vector2(0.7f, 1.0f);
var hostServerScale = new Vector2(0.7f, 0.6f);
menuTabs[(int)Tab.HostServer] = new GUIFrame(new RectTransform(
Vector2.Multiply(relativeSize, hostServerScale), GUI.Canvas, anchor, pivot, minSize.Multiply(hostServerScale), maxSize.Multiply(hostServerScale)) { RelativeOffset = relativeSpacing });
@@ -703,7 +699,7 @@ namespace Barotrauma
return false;
}
if (!int.TryParse(portBox.Text, out int port) || port < 0 || port > 65535)
/*if (!int.TryParse(portBox.Text, out int port) || port < 0 || port > 65535)
{
portBox.Text = NetConfig.DefaultPort.ToString();
portBox.Flash();
@@ -720,7 +716,7 @@ namespace Barotrauma
portBox.Flash();
return false;
}
}
}*/
GameMain.NetLobbyScreen = new NetLobbyScreen();
try
@@ -732,16 +728,22 @@ namespace Barotrauma
exeName = "DedicatedServer.exe";
}
int ownerKey = Math.Max(CryptoRandom.Instance.Next(), 1);
string arguments = "-name \"" + name.Replace("\\", "\\\\").Replace("\"", "\\\"") + "\"" +
" -port " + port.ToString() +
" -queryport " + queryPort.ToString() +
" -public " + isPublicBox.Selected.ToString() +
" -password \"" + passwordBox.Text.Replace("\\", "\\\\").Replace("\"", "\\\"") + "\"" +
" -upnp " + useUpnpBox.Selected +
" -maxplayers " + maxPlayersBox.Text +
" -ownerkey " + ownerKey.ToString();
" -maxplayers " + maxPlayersBox.Text;
int ownerKey = 0;
if (Steam.SteamManager.GetSteamID()!=0)
{
arguments += " -steamid " + Steam.SteamManager.GetSteamID();
}
else
{
ownerKey = Math.Max(CryptoRandom.Instance.Next(), 1);
arguments += " -ownerkey " + ownerKey;
}
string filename = exeName;
#if LINUX || OSX
@@ -752,13 +754,15 @@ namespace Barotrauma
FileName = filename,
Arguments = arguments,
#if !DEBUG
CreateNoWindow = true,
UseShellExecute = false,
WindowStyle = ProcessWindowStyle.Hidden
#endif
};
GameMain.ServerChildProcess = Process.Start(processInfo);
Thread.Sleep(1000); //wait until the server is ready before connecting
GameMain.Client = new GameClient(name, "127.0.0.1:" + port.ToString(), name, ownerKey);
GameMain.Client = new GameClient(name, System.Net.IPAddress.Loopback.ToString(), Steam.SteamManager.GetSteamID(), name, ownerKey, true);
}
catch (Exception e)
{
@@ -798,7 +802,10 @@ namespace Barotrauma
#else
joinServerButton.Enabled = true;
hostServerButton.Enabled = true;
steamWorkshopButton.Enabled = true;
if (Steam.SteamManager.USE_STEAM)
{
steamWorkshopButton.Enabled = true;
}
#endif
}
@@ -976,6 +983,7 @@ namespace Barotrauma
OverflowClip = true
};
/* TODO: allow lidgren servers from client?
label = new GUITextBlock(new RectTransform(textLabelSize, parent.RectTransform), TextManager.Get("ServerPort"), textAlignment: textAlignment);
portBox = new GUITextBox(new RectTransform(textFieldSize, label.RectTransform, Anchor.CenterRight), textAlignment: textAlignment)
{
@@ -991,7 +999,7 @@ namespace Barotrauma
Text = queryPort.ToString(),
ToolTip = TextManager.Get("ServerQueryPortToolTip")
};
}
}*/
var maxPlayersLabel = new GUITextBlock(new RectTransform(textLabelSize, parent.RectTransform), TextManager.Get("MaxPlayers"), textAlignment: textAlignment);
var buttonContainer = new GUILayoutGroup(new RectTransform(textFieldSize, maxPlayersLabel.RectTransform, Anchor.CenterRight), isHorizontal: true)
@@ -1027,10 +1035,11 @@ namespace Barotrauma
ToolTip = TextManager.Get("PublicServerToolTip")
};
/* TODO: remove UPnP altogether?
useUpnpBox = new GUITickBox(new RectTransform(tickBoxSize, parent.RectTransform), TextManager.Get("AttemptUPnP"))
{
ToolTip = TextManager.Get("AttemptUPnPToolTip")
};
};*/
new GUIButton(new RectTransform(new Vector2(0.4f, 0.1f), menuTabs[(int)Tab.HostServer].RectTransform, Anchor.BottomRight)
{
@@ -1383,7 +1383,7 @@ namespace Barotrauma
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(.24f, .34f) : new Vector2(.24f, .14f);
Vector2 frameSize = GameMain.Client.HasPermission(ClientPermissions.ManagePermissions) ? new Vector2(.24f, .44f) : new Vector2(.24f, .24f);
var playerFrameInner = new GUIFrame(new RectTransform(frameSize, playerFrame.RectTransform, Anchor.Center));
var paddedPlayerFrame = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.85f), playerFrameInner.RectTransform, Anchor.Center))
@@ -1530,13 +1530,29 @@ namespace Barotrauma
}
var buttonAreaUpper = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.1f), paddedPlayerFrame.RectTransform), isHorizontal: true);
var buttonAreaMiddle = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.1f), paddedPlayerFrame.RectTransform), isHorizontal: true);
var buttonAreaLower = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.1f), paddedPlayerFrame.RectTransform), isHorizontal: true);
if (selectedClient.SteamID != 0 && Steam.SteamManager.IsInitialized)
{
var viewSteamProfileButton = new GUIButton(new RectTransform(new Vector2(0.8f, 1.0f), buttonAreaUpper.RectTransform, Anchor.TopCenter),
TextManager.Get("ViewSteamProfile"))
{
UserData = selectedClient
};
viewSteamProfileButton.OnClicked = (bt, userdata) =>
{
Steam.SteamManager.Instance.Overlay.OpenUrl("https://steamcommunity.com/profiles/" + selectedClient.SteamID.ToString());
return true;
};
}
if (!myClient)
{
if (GameMain.Client.HasPermission(ClientPermissions.Ban))
{
var banButton = new GUIButton(new RectTransform(new Vector2(0.3f, 1.0f), buttonAreaUpper.RectTransform),
var banButton = new GUIButton(new RectTransform(new Vector2(0.3f, 1.0f), buttonAreaMiddle.RectTransform),
TextManager.Get("Ban"))
{
UserData = selectedClient
@@ -1544,7 +1560,7 @@ namespace Barotrauma
banButton.OnClicked = (bt, userdata) => { BanPlayer(selectedClient); return true; };
banButton.OnClicked += ClosePlayerFrame;
var rangebanButton = new GUIButton(new RectTransform(new Vector2(0.3f, 1.0f), buttonAreaUpper.RectTransform),
var rangebanButton = new GUIButton(new RectTransform(new Vector2(0.3f, 1.0f), buttonAreaMiddle.RectTransform),
TextManager.Get("BanRange"))
{
UserData = selectedClient
@@ -1578,7 +1594,7 @@ namespace Barotrauma
kickButton.OnClicked += ClosePlayerFrame;
}
new GUITickBox(new RectTransform(new Vector2(0.25f, 1.0f), buttonAreaUpper.RectTransform, Anchor.TopRight),
new GUITickBox(new RectTransform(new Vector2(0.25f, 1.0f), buttonAreaMiddle.RectTransform, Anchor.TopRight),
TextManager.Get("Mute"))
{
IgnoreLayoutGroups = true,
@@ -10,6 +10,7 @@ using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Text;
using System.Threading;
namespace Barotrauma
@@ -45,7 +46,7 @@ namespace Barotrauma
private readonly GUITickBox filterEmpty;
private string sortedBy;
private readonly GUIButton serverPreviewToggleButton;
//a timer for preventing the client from spamming the refresh button faster than AllowedRefreshInterval
@@ -332,7 +333,14 @@ namespace Barotrauma
{
if (ipBox.UserData is ServerInfo selectedServer)
{
JoinServer(selectedServer.IP + ":" + selectedServer.Port, selectedServer.ServerName);
if (selectedServer.LobbyID == 0)
{
JoinServer(selectedServer.IP + ":" + selectedServer.Port, selectedServer.ServerName);
}
else
{
Steam.SteamManager.JoinLobby(selectedServer.LobbyID, true);
}
}
else if (!string.IsNullOrEmpty(ipBox.Text))
{
@@ -474,6 +482,15 @@ namespace Barotrauma
RefreshServers();
}
public override void Deselect()
{
base.Deselect();
if (SteamManager.IsInitialized && SteamManager.Instance.LobbyList != null)
{
SteamManager.Instance.LobbyList.OnLobbiesUpdated = null;
}
}
private void FilterServers()
{
serverList.Content.RemoveChild(serverList.Content.FindChild("noresults"));
@@ -671,16 +688,24 @@ namespace Barotrauma
private void AddToServerList(ServerInfo serverInfo)
{
var serverFrame = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.06f), serverList.Content.RectTransform) { MinSize = new Point(0, 35) },
var serverFrame = serverList.Content.FindChild(d => (d.UserData is ServerInfo info) &&
(info.LobbyID==serverInfo.LobbyID && info.IP==serverInfo.IP && info.Port==serverInfo.Port));
if (serverFrame == null)
{
serverFrame = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.06f), serverList.Content.RectTransform) { MinSize = new Point(0, 35) },
style: "InnerFrame", color: Color.White * 0.5f)
{
UserData = serverInfo
};
new GUILayoutGroup(new RectTransform(new Vector2(0.98f, 1.0f), serverFrame.RectTransform, Anchor.Center), isHorizontal: true, childAnchor: Anchor.CenterLeft)
{
Stretch = true,
//RelativeSpacing = 0.02f
};
{
UserData = serverInfo
};
new GUILayoutGroup(new RectTransform(new Vector2(0.98f, 1.0f), serverFrame.RectTransform, Anchor.Center), isHorizontal: true, childAnchor: Anchor.CenterLeft)
{
Stretch = true,
//RelativeSpacing = 0.02f
};
}
serverFrame.UserData = serverInfo;
UpdateServerInfo(serverInfo);
SortList(sortedBy, toggle: false);
@@ -901,13 +926,17 @@ namespace Barotrauma
return true;
}
private IEnumerable<object> ConnectToServer(string ip, string serverName)
private IEnumerable<object> ConnectToServer(string endpoint, string serverName)
{
string serverIP = null;
UInt64 serverSteamID = SteamManager.SteamIDStringToUInt64(endpoint);
if (serverSteamID == 0) { serverIP = endpoint; }
#if !DEBUG
try
{
#endif
GameMain.Client = new GameClient(clientNameBox.Text, ip, serverName);
GameMain.Client = new GameClient(clientNameBox.Text, serverIP, serverSteamID, serverName);
#if !DEBUG
}
catch (Exception e)
@@ -961,7 +990,7 @@ namespace Barotrauma
public void PingServer(ServerInfo serverInfo, int timeOut)
{
if (serverInfo?.IP == null)
if (string.IsNullOrWhiteSpace(serverInfo?.IP))
{
serverInfo.PingChecked = true;
serverInfo.Ping = -1;
@@ -969,7 +998,8 @@ namespace Barotrauma
}
long rtt = -1;
IPAddress address = IPAddress.Parse(serverInfo.IP);
IPAddress address = null;
IPAddress.TryParse(serverInfo.IP, out address);
if (address != null)
{
//don't attempt to ping if the address is IPv6 and it's not supported
@@ -159,6 +159,7 @@ namespace Barotrauma
OnSelected = (component, userdata) =>
{
if (GUI.MouseOn is GUIButton || GUI.MouseOn?.Parent is GUIButton) { return false; }
if (GUI.MouseOn is GUITickBox || GUI.MouseOn?.Parent is GUITickBox) { return false; }
myItemList.Deselect();
if (userdata is Facepunch.Steamworks.Workshop.Item item)
{
@@ -190,16 +191,6 @@ namespace Barotrauma
}
};
new GUIButton(new RectTransform(new Vector2(0.5f, 0.05f), leftColumn.RectTransform), TextManager.Get("CreateWorkshopItem"))
{
OnClicked = (btn, userData) =>
{
CreateWorkshopItem();
ShowCreateItemFrame();
return true;
}
};
createItemFrame = new GUIFrame(new RectTransform(new Vector2(0.58f, 1.0f), tabs[(int)Tab.Publish].RectTransform, Anchor.TopRight), style: "InnerFrame");
buttonContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.08f), container.RectTransform), childAnchor: Anchor.CenterLeft);
@@ -269,7 +260,11 @@ namespace Barotrauma
});
SteamManager.GetPopularWorkshopItems((items) => { OnItemsReceived(items, topItemList); }, 20);
SteamManager.GetPublishedWorkshopItems((items) => { OnItemsReceived(items, publishedItemList); });
RefreshMyItemList();
}
private void RefreshMyItemList()
{
myItemList.ClearChildren();
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.2f), myItemList.Content.RectTransform), TextManager.Get("WorkshopLabelSubmarines"), textAlignment: Alignment.Center, font: GUI.LargeFont)
{
@@ -278,12 +273,28 @@ namespace Barotrauma
foreach (Submarine sub in Submarine.SavedSubmarines)
{
if (sub.HasTag(SubmarineTag.HideInMenus)) { continue; }
//ignore subs that are part of some content package
string subPath = Path.GetFullPath(sub.FilePath);
if (ContentPackage.List.Any(cp => cp.Files.Any(f => f.Type == ContentType.Submarine && Path.GetFullPath(f.Path) == subPath)))
//ignore subs that are part of the vanilla content package
if (GameMain.VanillaContent != null &&
GameMain.VanillaContent.GetFilesOfType(ContentType.Submarine).Any(s => Path.GetFullPath(s) == subPath))
{
continue;
}
//ignore subs that are part of a workshop content package
if (ContentPackage.List.Any(cp => !string.IsNullOrEmpty(cp.SteamWorkshopUrl) &&
cp.Files.Any(f => f.Type == ContentType.Submarine && Path.GetFullPath(f.Path) == subPath)))
{
continue;
}
//ignore subs that are defined in a content package with more files than just the sub
//(these will be listed in the "content packages" section)
if (ContentPackage.List.Any(cp => cp.Files.Count > 1 &&
cp.Files.Any(f => f.Type == ContentType.Submarine && Path.GetFullPath(f.Path) == subPath)))
{
continue;
}
CreateMyItemFrame(sub, myItemList);
}
@@ -294,6 +305,8 @@ namespace Barotrauma
foreach (ContentPackage contentPackage in ContentPackage.List)
{
if (!string.IsNullOrEmpty(contentPackage.SteamWorkshopUrl) || contentPackage.HideInWorkshopMenu) { continue; }
//don't list content packages that only define one sub (they're visible in the "Submarines" section)
if (contentPackage.Files.Count == 1 && contentPackage.Files[0].Type == ContentType.Submarine) { continue; }
CreateMyItemFrame(contentPackage, myItemList);
}
}
@@ -459,6 +472,7 @@ namespace Barotrauma
OnClicked = (btn, userdata) =>
{
item.UnSubscribe();
subscribedItemList.RemoveChild(subscribedItemList.Content.GetChildByUserData(item));
return true;
}
};
@@ -787,34 +801,40 @@ namespace Barotrauma
new GUITextBlock(new RectTransform(new Vector2(0.5f, 0.0f), modificationDate.RectTransform, Anchor.CenterRight), item.Modified.ToString("dd.MM.yyyy"), textAlignment: Alignment.TopRight);
}
private void CreateWorkshopItem()
/*private void CreateWorkshopItem()
{
SteamManager.CreateWorkshopItemStaging(new List<ContentFile>(), out itemEditor, out itemContentPackage);
}
SteamManager.CreateWorkshopItemStaging("ModName", out itemEditor, out itemContentPackage);
}*/
private void CreateWorkshopItem(Submarine sub)
{
SteamManager.CreateWorkshopItemStaging(new List<ContentFile>(), out itemEditor, out itemContentPackage);
string destinationFolder = Path.Combine("Mods", sub.Name);
itemContentPackage = ContentPackage.CreatePackage(sub.Name, Path.Combine(destinationFolder, SteamManager.MetadataFileName), corePackage: false);
SteamManager.CreateWorkshopItemStaging(itemContentPackage, out itemEditor);
string destinationPath = Path.Combine(SteamManager.WorkshopItemStagingFolder, "Submarines", Path.GetFileName(sub.FilePath));
try
string submarineDir = Path.GetDirectoryName(sub.FilePath);
if (submarineDir != Path.GetDirectoryName(destinationFolder))
{
File.Copy(sub.FilePath, destinationPath);
string destinationPath = Path.Combine(destinationFolder, Path.GetFileName(sub.FilePath));
if (!File.Exists(destinationPath))
{
File.Move(sub.FilePath, destinationPath);
}
sub.FilePath = destinationPath;
}
catch (Exception e)
{
DebugConsole.ThrowError("Failed to copy submarine file \"" + sub.FilePath + "\" to the Workshop item staging folder.", e);
return;
}
itemContentPackage.AddFile(Path.Combine("Submarines", Path.GetFileName(sub.FilePath)), ContentType.Submarine);
itemContentPackage.AddFile(sub.FilePath, ContentType.Submarine);
itemContentPackage.Name = sub.Name;
itemContentPackage.Save(itemContentPackage.Path);
ContentPackage.List.Add(itemContentPackage);
GameMain.Config.SelectedContentPackages.Add(itemContentPackage);
itemEditor.Title = sub.Name;
itemEditor.Tags.Add("Submarine");
itemEditor.Description = sub.Description;
if (sub.PreviewImage != null)
{
string previewImagePath = Path.GetFullPath(Path.Combine(SteamManager.WorkshopItemStagingFolder, SteamManager.PreviewImageName));
string previewImagePath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(itemContentPackage.Path), SteamManager.PreviewImageName));
try
{
using (Stream s = File.Create(previewImagePath))
@@ -837,8 +857,13 @@ namespace Barotrauma
}
private void CreateWorkshopItem(ContentPackage contentPackage)
{
SteamManager.CreateWorkshopItemStaging(new List<ContentFile>(), out itemEditor, out itemContentPackage);
string modDirectory = "";
//SteamManager.CreateWorkshopItemStaging(new List<ContentFile>(), out itemEditor, out itemContentPackage);
itemContentPackage = contentPackage;
SteamManager.CreateWorkshopItemStaging(itemContentPackage, out itemEditor);
itemEditor.Title = contentPackage.Name;
/*string modDirectory = "";
foreach (ContentFile file in contentPackage.Files)
{
itemContentPackage.AddFile(file.Path, file.Type);
@@ -858,12 +883,8 @@ namespace Barotrauma
if (!string.IsNullOrEmpty(modDirectory))
{
SaveUtil.CopyFolder(Path.Combine("Mods", modDirectory), Path.Combine(SteamManager.WorkshopItemStagingFolder, "Mods", modDirectory), copySubDirs: true);
}
}*/
itemContentPackage.CorePackage = contentPackage.CorePackage;
itemContentPackage.Name = contentPackage.Name;
itemContentPackage.Save(itemContentPackage.Path);
itemEditor.Title = contentPackage.Name;
}
private void CreateWorkshopItem(Facepunch.Steamworks.Workshop.Item item)
{
@@ -879,8 +900,16 @@ namespace Barotrauma
private void ShowCreateItemFrame()
{
createItemFrame.ClearChildren();
if (itemEditor == null) { return; }
if (itemEditor == null) return;
if (itemContentPackage == null)
{
string errorMsg = "Failed to edit workshop item (content package null)\n" + Environment.StackTrace;
DebugConsole.ThrowError(errorMsg);
GameAnalyticsManager.AddErrorEventOnce("SteamWorkshopScreen.ShowCreateItemFrame:ContentPackageNull", GameAnalyticsSDK.Net.EGAErrorSeverity.Error, errorMsg);
return;
}
var createItemContent = new GUILayoutGroup(new RectTransform(new Vector2(0.92f, 0.92f), createItemFrame.RectTransform, Anchor.Center))
{
@@ -987,7 +1016,7 @@ namespace Barotrauma
Barotrauma.OpenFileDialog ofd = new Barotrauma.OpenFileDialog()
{
Multiselect = true,
InitialDirectory = Path.GetFullPath(SteamManager.WorkshopItemStagingFolder),
InitialDirectory = Path.GetFullPath(Path.GetDirectoryName(itemContentPackage.Path)),
Filter = TextManager.Get("WorkshopItemPreviewImage") + "|*.png",
Title = TextManager.Get("WorkshopItemPreviewImageDialogTitle")
};
@@ -1018,9 +1047,19 @@ namespace Barotrauma
return true;
}
};
//if preview image has not been set, but there's a PreviewImage file inside the mod folder, use that by default
if (string.IsNullOrEmpty(itemEditor.PreviewImage))
{
string previewImagePath = Path.Combine(Path.GetDirectoryName(itemContentPackage.Path), SteamManager.PreviewImageName);
if (File.Exists(previewImagePath))
{
itemEditor.PreviewImage = Path.GetFullPath(previewImagePath);
}
}
if (!string.IsNullOrEmpty(itemEditor.PreviewImage))
{
itemEditor.PreviewImage = Path.GetFullPath(itemEditor.PreviewImage);
if (itemPreviewSprites.ContainsKey(itemEditor.PreviewImage))
{
itemPreviewSprites[itemEditor.PreviewImage].Remove();
@@ -1068,7 +1107,7 @@ namespace Barotrauma
new GUIButton(new RectTransform(new Vector2(0.3f, 1.0f), fileListTitle.RectTransform, Anchor.CenterRight), TextManager.Get("WorkshopItemShowFolder"))
{
IgnoreLayoutGroups = true,
OnClicked = (btn, userdata) => { System.Diagnostics.Process.Start(Path.GetFullPath(SteamManager.WorkshopItemStagingFolder)); return true; }
OnClicked = (btn, userdata) => { System.Diagnostics.Process.Start(Path.GetFullPath(Path.GetDirectoryName(itemContentPackage.Path))); return true; }
};
createItemFileList = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.35f), createItemContent.RectTransform));
RefreshCreateItemFileList();
@@ -1077,11 +1116,11 @@ namespace Barotrauma
{
RelativeSpacing = 0.05f
};
new GUIButton(new RectTransform(new Vector2(0.4f, 1.0f), buttonContainer.RectTransform, Anchor.TopRight), TextManager.Get("WorkshopItemRefreshFileList"))
{
ToolTip = TextManager.Get("WorkshopItemRefreshFileListTooltip"),
OnClicked = (btn, userdata) =>
OnClicked = (btn, userdata) =>
{
itemContentPackage = new ContentPackage(itemContentPackage.Path);
RefreshCreateItemFileList();
@@ -1096,26 +1135,27 @@ namespace Barotrauma
{
Barotrauma.OpenFileDialog ofd = new Barotrauma.OpenFileDialog()
{
InitialDirectory = Path.GetFullPath(SteamManager.WorkshopItemStagingFolder),
InitialDirectory = Path.GetFullPath(Path.GetDirectoryName(itemContentPackage.Path)),
Title = TextManager.Get("workshopitemaddfiles"),
Multiselect = true
};
if (ofd.ShowDialog() == DialogResult.OK)
{
OnAddFilesSelected(ofd.FileNames);
RefreshMyItemList();
}
}
catch
{
//use a custom prompt if OpenFileDialog fails (Linux/Mac)
var msgBox = new GUIMessageBox(TextManager.Get("workshopitemaddfiles"), "", relativeSize: new Vector2(0.4f, 0.2f),
buttons: new string[] { TextManager.Get("Cancel"), TextManager.Get("OK") });
buttons: new string[] { TextManager.Get("Cancel"), TextManager.Get("OK") });
var pathBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 0.5f), msgBox.Content.RectTransform, Anchor.Center) { MinSize = new Point(0, 25) });
msgBox.Buttons[0].OnClicked += msgBox.Close;
msgBox.Buttons[1].OnClicked += msgBox.Close;
msgBox.Buttons[1].OnClicked += (btn2, userdata2) =>
msgBox.Buttons[1].OnClicked += (btn2, userdata2) =>
{
if (string.IsNullOrEmpty(pathBox?.Text)) { return true; }
string[] filePaths = pathBox.Text.Split(',');
@@ -1131,6 +1171,7 @@ namespace Barotrauma
}
};
//the item has been already published if it has a non-zero ID -> allow adding a changenote
if (itemEditor.Id > 0)
{
@@ -1181,6 +1222,9 @@ namespace Barotrauma
itemEditor = null;
SelectTab(Tab.Browse);
deleteVerification.Close();
createItemFrame.ClearChildren();
itemContentPackage.SteamWorkshopUrl = "";
itemContentPackage.Save(itemContentPackage.Path);
return true;
};
deleteVerification.Buttons[1].OnClicked = deleteVerification.Close;
@@ -1221,7 +1265,7 @@ namespace Barotrauma
private void OnPreviewImageSelected(GUIImage previewImageElement, string filePath)
{
string previewImagePath = Path.GetFullPath(Path.Combine(SteamManager.WorkshopItemStagingFolder, SteamManager.PreviewImageName));
string previewImagePath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(itemContentPackage.Path), SteamManager.PreviewImageName));
if (new FileInfo(filePath).Length > 1024 * 1024)
{
new GUIMessageBox(TextManager.Get("Error"), TextManager.Get("WorkshopItemPreviewImageTooLarge"));
@@ -1248,33 +1292,36 @@ namespace Barotrauma
if (fileNames == null) { return; }
for (int i = 0; i < fileNames.Length; i++)
{
string file = fileNames[i];
if (string.IsNullOrEmpty(file)) { continue; }
file = file.Trim();
if (!File.Exists(file)) { continue; }
string file = fileNames[i]?.Trim();
if (string.IsNullOrEmpty(file) || !File.Exists(file)) { continue; }
string filePathRelativeToStagingFolder = UpdaterUtil.GetRelativePath(file, Path.Combine(Environment.CurrentDirectory, SteamManager.WorkshopItemStagingFolder));
string filePathRelativeToBaseFolder = UpdaterUtil.GetRelativePath(file, Environment.CurrentDirectory);
//file is not inside the staging folder
if (filePathRelativeToStagingFolder.StartsWith(".."))
string modFolder = Path.GetDirectoryName(itemContentPackage.Path);
string filePathRelativeToModFolder = UpdaterUtil.GetRelativePath(file, Path.Combine(Environment.CurrentDirectory, modFolder));
string destinationPath = Path.Combine(modFolder, Path.GetFileName(file));
//file is not inside the mod folder, we need to move it
if (filePathRelativeToModFolder.StartsWith("..") ||
Path.GetPathRoot(Environment.CurrentDirectory) != Path.GetPathRoot(file))
{
//submarines can be included in the content package directly
string basePath = Path.GetDirectoryName(filePathRelativeToBaseFolder.Replace("..", ""));
if (basePath == "Submarines")
string tryPath = destinationPath;
//add a number to the filename if a file with the same name already exists
i = 2;
while (File.Exists(destinationPath))
{
destinationPath = Path.Combine(modFolder, $"{Path.GetFileNameWithoutExtension(file)} ({i}){Path.GetExtension(file)}");
i++;
}
try
{
string destinationPath = Path.Combine(SteamManager.WorkshopItemStagingFolder, "Submarines", Path.GetFileName(file));
File.Copy(file, destinationPath);
itemContentPackage.AddFile(filePathRelativeToBaseFolder, ContentType.Submarine);
}
else
catch (Exception e)
{
itemContentPackage.AddFile(filePathRelativeToBaseFolder, ContentType.None);
DebugConsole.ThrowError("Copying the file \""+file+"\" to the mod folder failed.", e);
return;
}
}
else
{
itemContentPackage.AddFile(filePathRelativeToStagingFolder, ContentType.None);
}
itemContentPackage.AddFile(destinationPath, ContentType.None);
}
itemContentPackage.Save(itemContentPackage.Path);
RefreshCreateItemFileList();
@@ -1289,9 +1336,9 @@ namespace Barotrauma
foreach (ContentFile contentFile in itemContentPackage.Files)
{
bool illegalPath = !ContentPackage.IsModFilePathAllowed(contentFile);
string pathInStagingFolder = Path.Combine(SteamManager.WorkshopItemStagingFolder, contentFile.Path);
bool fileInStagingFolder = File.Exists(pathInStagingFolder);
bool fileExists = illegalPath ? File.Exists(contentFile.Path) : fileInStagingFolder;
//string pathInStagingFolder = Path.Combine(SteamManager.WorkshopItemStagingFolder, contentFile.Path);
//bool fileInStagingFolder = File.Exists(pathInStagingFolder);
bool fileExists = File.Exists(contentFile.Path);
var fileFrame = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.12f), createItemFileList.Content.RectTransform) { MinSize = new Point(0, 20) },
style: "ListBoxElement")
@@ -1309,7 +1356,7 @@ namespace Barotrauma
{
Selected = fileExists && !illegalPath,
Enabled = false,
ToolTip = TextManager.Get(fileInStagingFolder ? "WorkshopItemFileIncluded" : "WorkshopItemFileNotIncluded")
ToolTip = TextManager.Get(illegalPath ? "WorkshopItemFileNotIncluded" : "WorkshopItemFileIncluded")
};
var nameText = new GUITextBlock(new RectTransform(new Vector2(0.6f, 1.0f), content.RectTransform, Anchor.CenterLeft), contentFile.Path, font: GUI.SmallFont)
@@ -1352,6 +1399,7 @@ namespace Barotrauma
itemContentPackage.RemoveFile(contentFile);
itemContentPackage.Save(itemContentPackage.Path);
RefreshCreateItemFileList();
RefreshMyItemList();
return true;
}
};
@@ -1408,8 +1456,8 @@ namespace Barotrauma
if (errorMsg == null)
{
new GUIMessageBox(
TextManager.Get("Error"),
TextManager.GetWithVariable("WorkshopItemPublishFailed", "[itemname]", TextManager.EnsureUTF8(item.Title)) + item.Error);
TextManager.Get("Error"),
TextManager.GetWithVariable("WorkshopItemPublishFailed", "[itemname]", TextManager.EnsureUTF8(item.Title)) + " " + item.Error);
}
else
{
@@ -1418,6 +1466,7 @@ namespace Barotrauma
}
createItemFrame.ClearChildren();
RefreshItemLists();
SelectTab(Tab.Browse);
}
@@ -646,8 +646,8 @@ namespace Barotrauma
SoundPlayer.OverrideMusicType = "none";
SoundPlayer.OverrideMusicDuration = null;
GameMain.SoundManager.SetCategoryGainMultiplier("default", 0.0f);
GameMain.SoundManager.SetCategoryGainMultiplier("waterambience", 0.0f);
GameMain.SoundManager.SetCategoryGainMultiplier("default", 0.0f, 0);
GameMain.SoundManager.SetCategoryGainMultiplier("waterambience", 0.0f, 0);
linkedSubBox.ClearChildren();
foreach (Submarine sub in Submarine.SavedSubmarines)
@@ -688,8 +688,8 @@ namespace Barotrauma
if (WiringMode) SetWiringMode(false);
SoundPlayer.OverrideMusicType = null;
GameMain.SoundManager.SetCategoryGainMultiplier("default", GameMain.Config.SoundVolume);
GameMain.SoundManager.SetCategoryGainMultiplier("waterambience", GameMain.Config.SoundVolume);
GameMain.SoundManager.SetCategoryGainMultiplier("default", GameMain.Config.SoundVolume, 0);
GameMain.SoundManager.SetCategoryGainMultiplier("waterambience", GameMain.Config.SoundVolume, 0);
if (dummyCharacter != null)
{
@@ -1000,7 +1000,8 @@ namespace Barotrauma
submarineDescriptionCharacterCount = new GUITextBlock(new RectTransform(new Vector2(.5f, 1f), descriptionHeaderGroup.RectTransform), string.Empty, textAlignment: Alignment.TopRight);
var descriptionContainer = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.25f), leftColumn.RectTransform));
descriptionBox = new GUITextBox(new RectTransform(Vector2.One, descriptionContainer.Content.RectTransform, Anchor.Center), font: GUI.SmallFont, wrap: true);
descriptionBox = new GUITextBox(new RectTransform(Vector2.One, descriptionContainer.Content.RectTransform, Anchor.Center), font: GUI.SmallFont, wrap: true, textAlignment: Alignment.TopLeft);
descriptionBox.Padding = new Vector4(10 * GUI.Scale);
descriptionBox.OnTextChanged += (textBox, text) =>
{
@@ -1189,11 +1190,13 @@ namespace Barotrauma
var contentPackList = new GUIListBox(new RectTransform(new Vector2(0.5f, 1.0f - contentPackagesLabel.RectTransform.RelativeSize.Y),
horizontalArea.RectTransform, Anchor.BottomRight));
List<string> contentPacks = Submarine.MainSub.RequiredContentPackages.ToList();
foreach (ContentPackage contentPack in ContentPackage.List)
{
if (!contentPacks.Contains(contentPack.Name)) contentPacks.Add(contentPack.Name);
{
//don't show content packages that only define submarine files
//(it doesn't make sense to require another sub to be installed to install this one)
if (contentPack.Files.All(cp => cp.Type == ContentType.Submarine)) { continue; }
if (!contentPacks.Contains(contentPack.Name)) { contentPacks.Add(contentPack.Name); }
}
foreach (string contentPackageName in contentPacks)
@@ -2371,11 +2374,7 @@ namespace Barotrauma
sub.UpdateTransform();
}
spriteBatch.Begin(SpriteSortMode.BackToFront,
BlendState.AlphaBlend,
null, null, null, null,
cam.Transform);
spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, transformMatrix: cam.Transform);
graphics.Clear(new Color(0.051f, 0.149f, 0.271f, 1.0f));
if (GameMain.DebugDraw)
{
@@ -2383,7 +2382,12 @@ namespace Barotrauma
GUI.DrawLine(spriteBatch, new Vector2(cam.WorldView.X, -Submarine.MainSub.HiddenSubPosition.Y), new Vector2(cam.WorldView.Right, -Submarine.MainSub.HiddenSubPosition.Y), Color.White * 0.5f, 1.0f, (int)(2.0f / cam.Zoom));
}
Submarine.Draw(spriteBatch, true);
Submarine.DrawBack(spriteBatch, editing: true);
spriteBatch.End();
spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, transformMatrix: cam.Transform);
Submarine.DrawFront(spriteBatch, editing: true);
if (!CharacterMode && !WiringMode && GUI.MouseOn == null)
{