v1.6.17.0 (Unto the Breach update)

This commit is contained in:
Regalis11
2024-10-22 17:29:04 +03:00
parent e74b3cdb17
commit 6e6c17e100
417 changed files with 17166 additions and 5870 deletions
@@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Barotrauma.Networking;
namespace Barotrauma
{
@@ -19,7 +20,9 @@ namespace Barotrauma
protected GUIButton loadGameButton;
public Action<SubmarineInfo, string, string, CampaignSettings> StartNewGame;
public Action<string> LoadGame;
public delegate void LoadGameDelegate(string loadPath, Option<uint> backupIndex);
public LoadGameDelegate LoadGame;
protected enum CategoryFilter { All = 0, Vanilla = 1, Custom = 2 }
protected CategoryFilter subFilter = CategoryFilter.All;
@@ -821,5 +824,119 @@ namespace Barotrauma
return true;
}
protected void CreateBackupMenu(IEnumerable<SaveUtil.BackupIndexData> indexData, Action<SaveUtil.BackupIndexData> loadBackup)
{
var backupPopup = new GUIMessageBox("", "", new[] { TextManager.Get("Load"), TextManager.Get("Cancel") }, new Vector2(0.3f, 0.5f), minSize: new Point(500, 500));
GUILayoutGroup campaignSettingContent = new GUILayoutGroup(new RectTransform(new Vector2(1f, 0.8f), backupPopup.Content.RectTransform, Anchor.TopCenter));
GUIListBox backupList = new GUIListBox(new RectTransform(Vector2.One, campaignSettingContent.RectTransform));
bool isIronman = GameMain.NetworkMember?.ServerSettings is { IronmanModeActive: true };
if (!indexData.Any() || isIronman)
{
LocalizedString errorMsg = isIronman
? TextManager.Get("ironmanmodebackupdisclaimer")
: TextManager.Get("nobackups");
var errorBlock = new GUITextBlock(new RectTransform(Vector2.One, campaignSettingContent.RectTransform), errorMsg, font: GUIStyle.SubHeadingFont, textAlignment: Alignment.Center)
{
TextColor = GUIStyle.Red,
IgnoreLayoutGroups = true
};
if (errorBlock.Font.MeasureString(errorMsg).X > campaignSettingContent.Rect.Width)
{
errorBlock.Wrap = true;
errorBlock.SetTextPos();
}
}
if (!isIronman)
{
foreach (var data in indexData.OrderByDescending(static i => i.SaveTime))
{
GUIFrame indexFrame = new GUIFrame(
new RectTransform(new Vector2(1.0f, 1f / SaveUtil.MaxBackupCount), backupList.Content.RectTransform), style: "ListBoxElement")
{
UserData = data
};
GUILayoutGroup indexLayout = new GUILayoutGroup(
new RectTransform(Vector2.One, indexFrame.RectTransform),
isHorizontal: true,
childAnchor: Anchor.CenterLeft)
{
RelativeSpacing = 0.05f,
Stretch = true
};
GUILayoutGroup leftLayout = new GUILayoutGroup(new RectTransform(new Vector2(0.5f, 0.8f), indexLayout.RectTransform), childAnchor: Anchor.TopCenter)
{
RelativeSpacing = 0.05f,
Stretch = true
};
LocalizedString locationName = data.LocationType.IsEmpty || data.LocationNameIdentifier.IsEmpty ?
TextManager.Get("unknown") :
Location.GetName(data.LocationType, data.LocationNameFormatIndex, data.LocationNameIdentifier);
var locationNameBlock = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.5f), leftLayout.RectTransform), locationName, textAlignment: Alignment.CenterLeft)
{
TextColor = Color.White
};
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.5f), leftLayout.RectTransform), TextManager.Get($"savestate.{data.LevelType}"), textAlignment: Alignment.CenterLeft);
GUILayoutGroup rightLayout = new GUILayoutGroup(new RectTransform(new Vector2(0.5f, 0.8f), indexLayout.RectTransform), childAnchor: Anchor.TopCenter)
{
RelativeSpacing = 0.05f,
Stretch = true
};
TimeSpan difference = SerializableDateTime.UtcNow - data.SaveTime;
double totalMinutes = difference.TotalMinutes;
LocalizedString timeFormat = totalMinutes switch
{
< 1 => TextManager.Get("subeditor.savedjustnow"),
> 60 => TextManager.GetWithVariable("saveagehours", "[hours]", ((int)Math.Floor(difference.TotalHours)).ToString()),
_ => TextManager.GetWithVariable("subeditor.saveageminutes", "[minutes]", difference.Minutes.ToString())
};
new GUITextBlock(new RectTransform(Vector2.One, rightLayout.RectTransform), timeFormat, textAlignment: Alignment.CenterRight);
locationNameBlock.Text = ToolBox.LimitString(locationName, locationNameBlock.Font, locationNameBlock.Rect.Width);
}
}
backupList.AfterSelected = (selected, _) =>
{
// to my understanding, there's no way to unselect an item in a GUIListBox
// so no need to check if selected is null
backupPopup.Buttons[0].Enabled = true;
return true;
};
backupPopup.Buttons[1].OnClicked += (button, o) =>
{
backupPopup.Close();
return true;
};
backupPopup.Buttons[0].Enabled = false;
backupPopup.Buttons[0].OnClicked += (button, o) =>
{
if (backupList.SelectedComponent?.UserData is not SaveUtil.BackupIndexData selectedIndexData) { return false; }
backupPopup.Close();
loadBackup?.Invoke(selectedIndexData);
return true;
};
}
}
}