Build 0.20.16.1

This commit is contained in:
Regalis11
2022-12-20 17:05:53 +02:00
parent 9466d2245b
commit b8fa677148
22 changed files with 217 additions and 106 deletions
@@ -51,9 +51,8 @@ namespace Barotrauma
private readonly GUIFrame modsButtonContainer;
private readonly GUIButton modsButton, modUpdatesButton;
private Task<IReadOnlyList<Steamworks.Ugc.Item>> modUpdateTask;
private float modUpdateTimer = 0.0f;
private const float ModUpdateInterval = 60.0f;
private (DateTime WhenToRefresh, int Count) modUpdateStatus = (DateTime.Now, 0);
private static readonly TimeSpan ModUpdateInterval = TimeSpan.FromSeconds(60.0f);
private readonly GameMain game;
@@ -736,8 +735,7 @@ namespace Barotrauma
public void ResetModUpdateButton()
{
modUpdateTask = null;
modUpdateTimer = 0;
modUpdateStatus = (DateTime.Now, 0);
modUpdatesButton.Visible = false;
}
@@ -958,15 +956,42 @@ namespace Barotrauma
}
}
private void UpdateOutOfDateWorkshopItemCount()
{
if (DateTime.Now < modUpdateStatus.WhenToRefresh) { return; }
if (!SteamManager.IsInitialized) { return; }
var installedPackages = ContentPackageManager.WorkshopPackages;
var ids = SteamManager.Workshop.GetSubscribedItemIds()
.Select(id => id.Value)
.Union(installedPackages
.Select(pkg => pkg.UgcId)
.NotNone()
.OfType<SteamWorkshopId>()
.Select(id => id.Value));
var count = ids
// Deliberately construct Steamworks.Ugc.Item directly
// to not immediately generate a Workshop data request
.Select(id => new Steamworks.Ugc.Item(id))
.Count(item =>
installedPackages.FirstOrDefault(p
=> p.UgcId.TryUnwrap(out SteamWorkshopId id) && id.Value == item.Id)
is { } pkg
// Checking that this item is downloading, waiting to be downloaded
// or is newer than the currently installed copy should be good enough,
// and should still not make a Workshop data request
&& (item.IsDownloading
|| item.IsDownloadPending
|| (item.InstallTime.TryGetValue(out var workshopInstallTime)
&& pkg.InstallTime.TryUnwrap(out var localInstallTime)
&& localInstallTime < workshopInstallTime)));
modUpdateStatus = (DateTime.Now + ModUpdateInterval, count);
}
public override void Update(double deltaTime)
{
modUpdateTimer -= (float)deltaTime;
if (modUpdateTimer <= 0.0f && modUpdateTask is not { IsCompleted: false })
{
modUpdateTask = BulkDownloader.GetItemsThatNeedUpdating();
modUpdateTimer = ModUpdateInterval;
}
#if DEBUG
hostServerButton.Enabled = true;
#else
@@ -976,10 +1001,8 @@ namespace Barotrauma
}
#endif
if (modUpdateTask is { IsCompletedSuccessfully: true })
{
modUpdatesButton.Visible = modUpdateTask.Result.Count > 0;
}
UpdateOutOfDateWorkshopItemCount();
modUpdatesButton.Visible = modUpdateStatus.Count > 0;
if (modUpdatesButton.Visible)
{
@@ -779,6 +779,8 @@ namespace Barotrauma
workshopMenu = Screen.Selected is MainMenuScreen
? (WorkshopMenu)new MutableWorkshopMenu(content)
: (WorkshopMenu)new ImmutableWorkshopMenu(content);
GameMain.MainMenuScreen.ResetModUpdateButton();
}
private void CreateBottomButtons()
@@ -45,18 +45,26 @@ namespace Barotrauma.Steam
protected static readonly Regex bbTagRegex = new Regex(@"\[(.+?)\]",
RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
protected static GUICustomComponent CreateBBCodeElement(string bbCode, GUIListBox container)
protected static void CreateBBCodeElement(Steamworks.Ugc.Item workshopItem, GUIListBox container)
{
Point cachedContainerSize = Point.Zero;
List<BBWord> bbWords = new List<BBWord>();
Stack<BBWord.TagType> tagStack = new Stack<BBWord.TagType>();
void recalculate()
string bbCode = "";
void forceReset()
{
if (cachedContainerSize == container.Content.RectTransform.NonScaledSize) { return; }
bbWords.Clear();
cachedContainerSize = Point.Zero;
}
void recalculate(GUICustomComponent component)
{
if (cachedContainerSize == component.RectTransform.NonScaledSize) { return; }
bbWords.Clear();
cachedContainerSize = container.Content.RectTransform.NonScaledSize;
cachedContainerSize = component.RectTransform.NonScaledSize;
var matches = new Stack<Match>(bbTagRegex.Matches(bbCode).Reverse());
Match? nextTag = null;
@@ -133,11 +141,14 @@ namespace Barotrauma.Steam
{
bbWords.Add(new BBWord(finalWord, currTagType));
}
container.RecalculateChildren();
container.UpdateScrollBarSize();
}
void draw(SpriteBatch spriteBatch, GUICustomComponent component)
{
recalculate();
recalculate(component);
Vector2 currPos = Vector2.Zero;
Vector2 rectPos = component.Rect.Location.ToVector2();
for (int i = 0; i < bbWords.Count; i++)
@@ -180,7 +191,19 @@ namespace Barotrauma.Steam
= component.RectTransform.NonScaledSize.ToVector2() / component.Parent.Rect.Size.ToVector2();
}
return new GUICustomComponent(new RectTransform(Vector2.One, container.Content.RectTransform),
TaskPool.Add(
$"GetWorkshopItemLongDescriptionFor{workshopItem.Id.Value}",
SteamManager.Workshop.GetItemAsap(workshopItem.Id.Value, withLongDescription: true),
t =>
{
if (!t.TryGetResult(out Steamworks.Ugc.Item? workshopItemWithDescription)) { return; }
bbCode = workshopItemWithDescription?.Description ?? "";
forceReset();
});
new GUICustomComponent(
new RectTransform(Vector2.One, container.Content.RectTransform),
onDraw: draw);
}
}
@@ -34,7 +34,7 @@ namespace Barotrauma.Steam
if (numSubscribedMods == memSubscribedModCount) { return; }
memSubscribedModCount = numSubscribedMods;
var subscribedIds = SteamManager.GetSubscribedItems().ToHashSet();
var subscribedIds = SteamManager.Workshop.GetSubscribedItemIds();
var installedIds = ContentPackageManager.WorkshopPackages
.Select(p => p.UgcId)
.NotNone()
@@ -773,7 +773,7 @@ namespace Barotrauma.Steam
#endregion
var descriptionListBox = new GUIListBox(new RectTransform((1.0f, 0.38f), verticalLayout.RectTransform));
CreateBBCodeElement(workshopItem.Description, descriptionListBox);
CreateBBCodeElement(workshopItem, descriptionListBox);
var showInSteamContainer
= new GUIFrame(new RectTransform((1.0f, 0.05f), verticalLayout.RectTransform), style: null);