Unstable 0.17.1.0

This commit is contained in:
Markus Isberg
2022-03-17 01:25:04 +09:00
parent 3974067915
commit 6d410cc1b7
302 changed files with 5878 additions and 3317 deletions
@@ -522,7 +522,7 @@ namespace Barotrauma.Steam
UserData = tag
};
tagBtn.RectTransform.NonScaledSize
= tagBtn.Font.MeasureString(tagBtn.Text).ToPoint() + new Point(GUI.IntScale(5));
= tagBtn.Font.MeasureString(tagBtn.Text).ToPoint() + new Point(GUI.IntScale(15), GUI.IntScale(5));
tagBtn.RectTransform.IsFixedSize = true;
tagBtn.ClampMouseRectToParent = false;
}
@@ -625,7 +625,7 @@ namespace Barotrauma.Steam
#region Stats box
var statsHorizontalLayout = new GUILayoutGroup(new RectTransform(Vector2.One, statsBox.RectTransform), isHorizontal: true);
var statsVertical0
= new GUILayoutGroup(new RectTransform((1.0f, 1.0f), statsHorizontalLayout.RectTransform));
= new GUILayoutGroup(new RectTransform((1.0f, 1.0f), statsHorizontalLayout.RectTransform), childAnchor: Anchor.TopCenter);
statFrame("", ""); //padding
@@ -680,7 +680,7 @@ namespace Barotrauma.Steam
var tagsLabel = new GUITextBlock(new RectTransform((1.0f, 0.12f), statsVertical0.RectTransform),
TextManager.Get("WorkshopItemTags"), font: GUIStyle.SubHeadingFont);
CreateTagsList(workshopItem.Tags.ToIdentifiers(), new RectTransform((1.0f, 0.3f), statsVertical0.RectTransform), canBeFocused: false);
CreateTagsList(workshopItem.Tags.ToIdentifiers(), new RectTransform((0.97f, 0.3f), statsVertical0.RectTransform), canBeFocused: false);
#endregion
var descriptionListBox = new GUIListBox(new RectTransform((1.0f, 0.38f), verticalLayout.RectTransform));
@@ -71,6 +71,7 @@ namespace Barotrauma.Steam
if (GameMain.Client == null)
{
LeaveLobby();
return;
}
if (lobbyState == LobbyState.NotConnected)
@@ -83,7 +84,7 @@ namespace Barotrauma.Steam
return;
}
var contentPackages = ContentPackageManager.EnabledPackages.All.Where(cp => cp.HasMultiplayerIncompatibleContent);
var contentPackages = ContentPackageManager.EnabledPackages.All.Where(cp => cp.HasMultiplayerSyncedContent);
currentLobby?.SetData("name", serverSettings.ServerName);
currentLobby?.SetData("playercount", (GameMain.Client?.ConnectedClients?.Count ?? 0).ToString());
@@ -357,21 +357,31 @@ namespace Barotrauma.Steam
private IEnumerable<CoroutineStatus> MessageBoxCoroutine(Func<GUITextBlock, GUIMessageBox, IEnumerable<CoroutineStatus>> subcoroutine)
{
var messageBox = new GUIMessageBox("", "", relativeSize: (0.4f, 0.4f), buttons: new [] { TextManager.Get("Cancel") });
var messageBox = new GUIMessageBox("", "...", buttons: new [] { TextManager.Get("Cancel") });
messageBox.Buttons[0].OnClicked = (button, o) =>
{
messageBox.Close();
return false;
};
var currentStepText = new GUITextBlock(new RectTransform((1.0f, 0.8f), messageBox.InnerFrame.RectTransform),
"...", font: GUIStyle.Font)
{
CanBeFocused = false
};
foreach (var status in subcoroutine(currentStepText, messageBox))
var coroutineEval = subcoroutine(messageBox.Text, messageBox);
while (true)
{
bool moveNext = true;
try
{
moveNext = coroutineEval.GetEnumerator().MoveNext();
}
catch (Exception e)
{
DebugConsole.ThrowError($"{e.Message} {e.StackTrace.CleanupStackTrace()}");
messageBox.Close();
}
if (!moveNext)
{
messageBox.Close();
}
var status = coroutineEval.GetEnumerator().Current;
if (messageBox.Closed)
{
yield return CoroutineStatus.Success;
@@ -410,7 +420,7 @@ namespace Barotrauma.Steam
{
SteamManager.Workshop.ForceRedownload(workshopItem);
}
currentStepText.Text = $"Downloading {Percentage(workshopItem.DownloadAmount)}";
currentStepText.Text = TextManager.GetWithVariable("PublishPopupDownload", "[percentage]", Percentage(workshopItem.DownloadAmount));
yield return new WaitForSeconds(0.5f);
}
}
@@ -426,7 +436,7 @@ namespace Barotrauma.Steam
});
while (!ContentPackageManager.WorkshopPackages.Any(p => p.SteamWorkshopId == workshopItem.Id))
{
currentStepText.Text = $"Installing";
currentStepText.Text = TextManager.Get("PublishPopupInstall");
yield return new WaitForSeconds(0.5f);
}
@@ -444,7 +454,7 @@ namespace Barotrauma.Steam
});
while (!localCopyMade)
{
currentStepText.Text = $"Creating local copy";
currentStepText.Text = TextManager.Get("PublishPopupCreateLocal");
yield return new WaitForSeconds(0.5f);
}
@@ -457,47 +467,62 @@ namespace Barotrauma.Steam
GUITextBlock currentStepText, GUIMessageBox messageBox,
string modVersion, Steamworks.Ugc.Editor editor, ContentPackage localPackage)
{
if (!SteamManager.IsInitialized)
{
yield return CoroutineStatus.Failure;
}
bool stagingReady = false;
Exception? stagingException = null;
TaskPool.Add("CreatePublishStagingCopy",
SteamManager.Workshop.CreatePublishStagingCopy(modVersion, localPackage),
(t) =>
{
Exception? exception = t.Exception?.InnerException ?? t.Exception;
if (exception != null)
{
throw new Exception($"Failed to create staging copy: {exception.Message} {exception.StackTrace}");
}
stagingReady = true;
stagingException = t.Exception?.GetInnermost();
});
currentStepText.Text = "Copying item to staging folder...";
currentStepText.Text = TextManager.Get("PublishPopupStaging");
while (!stagingReady) { yield return new WaitForSeconds(0.5f); }
if (stagingException != null)
{
throw new Exception($"Failed to create staging copy: {stagingException.Message} {stagingException.StackTrace.CleanupStackTrace()}");
}
editor = editor
.WithContent(SteamManager.Workshop.PublishStagingDir)
.ForAppId(SteamManager.AppID);
messageBox.Buttons[0].Enabled = false;
Steamworks.Ugc.PublishResult? result = null;
Exception? resultException = null;
TaskPool.Add($"Publishing {localPackage.Name} ({localPackage.SteamWorkshopId})",
editor.SubmitAsync(),
(t) =>
t =>
{
result = ((Task<Steamworks.Ugc.PublishResult>)t).Result;
t.TryGetResult(out result);
resultException = t.Exception?.GetInnermost();
});
currentStepText.Text = "Submitting item to the Workshop...";
while (!result.HasValue) { yield return new WaitForSeconds(0.5f); }
currentStepText.Text = TextManager.Get("PublishPopupSubmit");
while (!result.HasValue && resultException is null) { yield return new WaitForSeconds(0.5f); }
if (result.Value.Success)
if (result is { Success: true })
{
var resultId = result.Value.FileId;
Steamworks.Ugc.Item resultItem = new Steamworks.Ugc.Item(resultId);
SteamManager.Workshop.ForceRedownload(resultItem);
while (!resultItem.IsInstalled)
Task downloadTask = SteamManager.Workshop.ForceRedownload(resultItem);
while (!resultItem.IsInstalled && !downloadTask.IsCompleted)
{
currentStepText.Text = $"Downloading {Percentage(resultItem.DownloadAmount)}";
currentStepText.Text = TextManager.GetWithVariable("PublishPopupDownload", "[percentage]", Percentage(resultItem.DownloadAmount));
yield return new WaitForSeconds(0.5f);
}
if (!resultItem.IsInstalled)
{
throw new Exception($"Failed to install item: download task ended with status {downloadTask.Status}, " +
$"exception was {downloadTask.Exception?.GetInnermost()?.ToString().CleanupStackTrace() ?? "[NULL]"}");
}
bool installed = false;
TaskPool.Add(
"InstallNewlyPublished",
@@ -508,7 +533,7 @@ namespace Barotrauma.Steam
});
while (!installed)
{
currentStepText.Text = $"Installing";
currentStepText.Text = TextManager.Get("PublishPopupInstall");
yield return new WaitForSeconds(0.5f);
}
@@ -524,8 +549,19 @@ namespace Barotrauma.Steam
{
SteamManager.OverlayCustomURL(resultItem.Url);
}
new GUIMessageBox(string.Empty, TextManager.GetWithVariable("workshopitempublished", "[itemname]", localPackage.Name));
}
else if (resultException != null)
{
throw new Exception($"Failed to publish item: {resultException.Message} {resultException.StackTrace.CleanupStackTrace()}");
}
else
{
new GUIMessageBox(TextManager.Get("error"), TextManager.GetWithVariable("workshopitempublishfailed", "[itemname]", localPackage.Name));
}
SteamManager.Workshop.DeletePublishStagingCopy();
messageBox.Close();
}
}
}
@@ -89,7 +89,7 @@ namespace Barotrauma.Steam
}
private static int Round(float v) => (int)MathF.Round(v);
private static string Percentage(float v) => $"{Round(v * 100)}%";
private static string Percentage(float v) => $"{Round(v * 100)}";
private struct ActionCarrier
{
@@ -1,14 +1,13 @@
#nullable enable
using Barotrauma.IO;
using Microsoft.Xna.Framework.Graphics;
using RestSharp;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Barotrauma.IO;
namespace Barotrauma.Steam
{
@@ -180,8 +179,10 @@ namespace Barotrauma.Steam
await CopyDirectory(contentPackage.Dir, contentPackage.Name, Path.GetDirectoryName(contentPackage.Path)!, PublishStagingDir);
//Load filelist.xml and write the hash into it so anyone downloading this mod knows what it should be
ModProject modProject = new ModProject(contentPackage);
modProject.ModVersion = modVersion;
ModProject modProject = new ModProject(contentPackage)
{
ModVersion = modVersion
};
modProject.Save(Path.Combine(PublishStagingDir, ContentPackage.FileListFileName));
}
@@ -1,16 +1,11 @@
#nullable enable
using System;
using Barotrauma.Extensions;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Threading;
using System.Xml.Linq;
using Barotrauma.IO;
using Microsoft.Xna.Framework.Graphics;
using ItemOrPackage = Barotrauma.Either<Steamworks.Ugc.Item, Barotrauma.ContentPackage>;
namespace Barotrauma.Steam
@@ -25,12 +20,12 @@ namespace Barotrauma.Steam
Publish
}
private GUILayoutGroup tabber;
private Dictionary<Tab, (GUIButton Button, GUIFrame Content)> tabContents;
private readonly GUILayoutGroup tabber;
private readonly Dictionary<Tab, (GUIButton Button, GUIFrame Content)> tabContents;
private GUIFrame contentFrame;
private readonly GUIFrame contentFrame;
private CorePackage enabledCorePackage => enabledCoreDropdown.SelectedData as CorePackage ?? throw new Exception("Valid core package not selected");
private CorePackage EnabledCorePackage => enabledCoreDropdown.SelectedData as CorePackage ?? throw new Exception("Valid core package not selected");
private readonly GUIDropDown enabledCoreDropdown;
private readonly GUIListBox enabledRegularModsList;
@@ -173,7 +168,7 @@ namespace Barotrauma.Steam
to.DraggedElement = draggedElement;
to.BarScroll = to.BarScroll * (oldCount / newCount);
to.BarScroll *= (oldCount / newCount);
}
}
@@ -367,7 +362,8 @@ namespace Barotrauma.Steam
{
ToolBox.OpenFileWithShell(mod.Dir);
return false;
}
},
ToolTip = TextManager.Get("OpenLocalModInExplorer")
};
}
else if (ContentPackageManager.WorkshopPackages.Contains(mod))
@@ -386,8 +382,13 @@ namespace Barotrauma.Steam
onInstalledInfoButtonHit(item.Value);
});
return false;
}
},
ToolTip = TextManager.Get("ViewModDetails")
};
if (!SteamManager.IsInitialized)
{
infoButton.Enabled = false;
}
TaskPool.Add(
$"DetermineUpdateRequired{mod.SteamWorkshopId}",
mod.IsUpToDate(),
@@ -398,6 +399,7 @@ namespace Barotrauma.Steam
if (!isUpToDate)
{
infoButton.ApplyStyle(GUIStyle.ComponentStyles["WorkshopMenu.InfoButtonUpdate"]);
infoButton.ToolTip = TextManager.Get("ViewModDetailsUpdateAvailable");
}
});
}
@@ -421,20 +423,26 @@ namespace Barotrauma.Steam
private void CreatePopularModsTab(out GUIListBox popularModsList)
{
GUIFrame content = CreateNewContentFrame(Tab.PopularMods);
if (!SteamManager.IsInitialized)
{
tabContents[Tab.PopularMods].Button.Enabled = false;
}
CreateWorkshopItemList(content, out _, out popularModsList, onSelected: PopulateFrameWithItemInfo);
}
private void CreatePublishTab(out GUIListBox selfModsList)
{
GUIFrame content = CreateNewContentFrame(Tab.Publish);
if (!SteamManager.IsInitialized)
{
tabContents[Tab.Publish].Button.Enabled = false;
}
CreateWorkshopItemOrPackageList(content, out _, out selfModsList, onSelected: PopulatePublishTab);
}
public void Apply()
{
ContentPackageManager.EnabledPackages.SetCore(enabledCorePackage);
ContentPackageManager.EnabledPackages.SetCore(EnabledCorePackage);
ContentPackageManager.EnabledPackages.SetRegular(enabledRegularModsList.Content.Children
.Where(c => c.UserData is RegularPackage).Select(c => (RegularPackage)c.UserData).ToArray());
}