Faction Test v1.0.1.0
This commit is contained in:
+102
-29
@@ -4,6 +4,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using Barotrauma.IO;
|
||||
using System.Collections.Immutable;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
|
||||
@@ -37,7 +38,6 @@ namespace Barotrauma
|
||||
protected set;
|
||||
}
|
||||
|
||||
public CampaignSettings CurrentSettings = new CampaignSettings(element: null);
|
||||
public GUIButton CampaignCustomizeButton { get; set; }
|
||||
public GUIMessageBox CampaignCustomizeSettings { get; set; }
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace Barotrauma
|
||||
|
||||
var saveFrame = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.1f), saveList.Content.RectTransform) { MinSize = new Point(0, 45) }, style: "ListBoxElement")
|
||||
{
|
||||
UserData = saveInfo.FilePath
|
||||
UserData = saveInfo
|
||||
};
|
||||
|
||||
var nameText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.5f), saveFrame.RectTransform), Path.GetFileNameWithoutExtension(saveInfo.FilePath),
|
||||
@@ -87,10 +87,9 @@ namespace Barotrauma
|
||||
};
|
||||
|
||||
string saveTimeStr = string.Empty;
|
||||
if (saveInfo.SaveTime > 0)
|
||||
if (saveInfo.SaveTime.TryUnwrap(out var time))
|
||||
{
|
||||
DateTime time = ToolBox.Epoch.ToDateTime(saveInfo.SaveTime);
|
||||
saveTimeStr = time.ToString();
|
||||
saveTimeStr = time.ToLocalUserString();
|
||||
}
|
||||
new GUITextBlock(new RectTransform(new Vector2(1.0f, 1.0f), saveFrame.RectTransform),
|
||||
text: saveTimeStr, textAlignment: Alignment.Right, font: GUIStyle.SmallFont)
|
||||
@@ -102,8 +101,29 @@ namespace Barotrauma
|
||||
return saveFrame;
|
||||
}
|
||||
|
||||
protected void SortSaveList()
|
||||
{
|
||||
saveList.Content.RectTransform.SortChildren((c1, c2) =>
|
||||
{
|
||||
if (c1.GUIComponent.UserData is not CampaignMode.SaveInfo file1
|
||||
|| c2.GUIComponent.UserData is not CampaignMode.SaveInfo file2)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!file1.SaveTime.TryUnwrap(out var file1WriteTime)
|
||||
|| !file2.SaveTime.TryUnwrap(out var file2WriteTime))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return file2WriteTime.CompareTo(file1WriteTime);
|
||||
});
|
||||
}
|
||||
|
||||
public struct CampaignSettingElements
|
||||
{
|
||||
public SettingValue<string> SelectedPreset;
|
||||
public SettingValue<bool> TutorialEnabled;
|
||||
public SettingValue<bool> RadiationEnabled;
|
||||
public SettingValue<int> MaxMissionCount;
|
||||
@@ -115,6 +135,7 @@ namespace Barotrauma
|
||||
{
|
||||
return new CampaignSettings(element: null)
|
||||
{
|
||||
PresetName = SelectedPreset.GetValue(),
|
||||
TutorialEnabled = TutorialEnabled.GetValue(),
|
||||
RadiationEnabled = RadiationEnabled.GetValue(),
|
||||
MaxMissionCount = MaxMissionCount.GetValue(),
|
||||
@@ -165,9 +186,13 @@ namespace Barotrauma
|
||||
{
|
||||
const float verticalSize = 0.14f;
|
||||
|
||||
bool loadingPreset = false;
|
||||
|
||||
GUILayoutGroup presetDropdownLayout = new GUILayoutGroup(new RectTransform(new Vector2(1f, verticalSize), parent.RectTransform), isHorizontal: true, childAnchor: Anchor.CenterLeft);
|
||||
new GUITextBlock(new RectTransform(new Vector2(0.5f, 1f), presetDropdownLayout.RectTransform), TextManager.Get("campaignsettingpreset"));
|
||||
GUIDropDown presetDropdown = new GUIDropDown(new RectTransform(new Vector2(0.5f, 1f), presetDropdownLayout.RectTransform), elementCount: CampaignModePresets.List.Length);
|
||||
GUIDropDown presetDropdown = new GUIDropDown(new RectTransform(new Vector2(0.5f, 1f), presetDropdownLayout.RectTransform), elementCount: CampaignModePresets.List.Length + 1);
|
||||
presetDropdown.AddItem(TextManager.Get("karmapreset.custom"), null);
|
||||
presetDropdown.Select(0);
|
||||
|
||||
presetDropdownLayout.RectTransform.MinSize = new Point(0, presetDropdown.Rect.Height);
|
||||
|
||||
@@ -175,21 +200,30 @@ namespace Barotrauma
|
||||
{
|
||||
string name = settings.PresetName;
|
||||
presetDropdown.AddItem(TextManager.Get($"preset.{name}").Fallback(name), settings);
|
||||
|
||||
if (settings.PresetName.Equals(prevSettings.PresetName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
presetDropdown.SelectItem(settings);
|
||||
}
|
||||
}
|
||||
|
||||
var presetValue = new SettingValue<string>(
|
||||
get: () => presetDropdown.SelectedData is CampaignSettings settings ? settings.PresetName : string.Empty,
|
||||
set: static _ => { }); // we do not need a way to set this value
|
||||
|
||||
GUIListBox settingsList = new GUIListBox(new RectTransform(new Vector2(1f, 1f - verticalSize), parent.RectTransform))
|
||||
{
|
||||
Spacing = GUI.IntScale(5)
|
||||
};
|
||||
|
||||
SettingValue<bool> tutorialEnabled = isSinglePlayer ?
|
||||
CreateTickbox(settingsList.Content, TextManager.Get("CampaignOption.EnableTutorial"), TextManager.Get("campaignoption.enabletutorial.tooltip"), prevSettings.TutorialEnabled, verticalSize) :
|
||||
new SettingValue<bool>(() => false, b => { });
|
||||
SettingValue<bool> radiationEnabled = CreateTickbox(settingsList.Content, TextManager.Get("CampaignOption.EnableRadiation"), TextManager.Get("campaignoption.enableradiation.tooltip"), prevSettings.RadiationEnabled, verticalSize);
|
||||
CreateTickbox(settingsList.Content, TextManager.Get("CampaignOption.EnableTutorial"), TextManager.Get("campaignoption.enabletutorial.tooltip"), prevSettings.TutorialEnabled, verticalSize, OnValuesChanged) :
|
||||
new SettingValue<bool>(static () => false, static _ => { });
|
||||
SettingValue<bool> radiationEnabled = CreateTickbox(settingsList.Content, TextManager.Get("CampaignOption.EnableRadiation"), TextManager.Get("campaignoption.enableradiation.tooltip"), prevSettings.RadiationEnabled, verticalSize, OnValuesChanged);
|
||||
|
||||
ImmutableArray<SettingCarouselElement<Identifier>> startingSetOptions = StartItemSet.Sets.OrderBy(s => s.Order).Select(set => new SettingCarouselElement<Identifier>(set.Identifier, $"startitemset.{set.Identifier}")).ToImmutableArray();
|
||||
SettingCarouselElement<Identifier> prevStartingSet = startingSetOptions.FirstOrNull(element => element.Value == prevSettings.StartItemSet) ?? startingSetOptions[1];
|
||||
SettingValue<Identifier> startingSetInput = CreateSelectionCarousel(settingsList.Content, TextManager.Get("startitemset"), TextManager.Get("startitemsettooltip"), prevStartingSet, verticalSize, startingSetOptions);
|
||||
SettingValue<Identifier> startingSetInput = CreateSelectionCarousel(settingsList.Content, TextManager.Get("startitemset"), TextManager.Get("startitemsettooltip"), prevStartingSet, verticalSize, startingSetOptions, OnValuesChanged);
|
||||
|
||||
ImmutableArray<SettingCarouselElement<StartingBalanceAmount>> fundOptions = ImmutableArray.Create(
|
||||
new SettingCarouselElement<StartingBalanceAmount>(StartingBalanceAmount.Low, "startingfunds.low"),
|
||||
@@ -198,7 +232,7 @@ namespace Barotrauma
|
||||
);
|
||||
|
||||
SettingCarouselElement<StartingBalanceAmount> prevStartingFund = fundOptions.FirstOrNull(element => element.Value == prevSettings.StartingBalanceAmount) ?? fundOptions[1];
|
||||
SettingValue<StartingBalanceAmount> startingFundsInput = CreateSelectionCarousel(settingsList.Content, TextManager.Get("startingfundsdescription"), TextManager.Get("startingfundstooltip"), prevStartingFund, verticalSize, fundOptions);
|
||||
SettingValue<StartingBalanceAmount> startingFundsInput = CreateSelectionCarousel(settingsList.Content, TextManager.Get("startingfundsdescription"), TextManager.Get("startingfundstooltip"), prevStartingFund, verticalSize, fundOptions, OnValuesChanged);
|
||||
|
||||
ImmutableArray<SettingCarouselElement<GameDifficulty>> difficultyOptions = ImmutableArray.Create(
|
||||
new SettingCarouselElement<GameDifficulty>(GameDifficulty.Easy, "difficulty.easy"),
|
||||
@@ -208,30 +242,38 @@ namespace Barotrauma
|
||||
);
|
||||
|
||||
SettingCarouselElement<GameDifficulty> prevDifficulty = difficultyOptions.FirstOrNull(element => element.Value == prevSettings.Difficulty) ?? difficultyOptions[1];
|
||||
SettingValue<GameDifficulty> difficultyInput = CreateSelectionCarousel(settingsList.Content, TextManager.Get("leveldifficulty"), TextManager.Get("leveldifficultyexplanation"), prevDifficulty, verticalSize, difficultyOptions);
|
||||
SettingValue<GameDifficulty> difficultyInput = CreateSelectionCarousel(settingsList.Content, TextManager.Get("leveldifficulty"), TextManager.Get("leveldifficultyexplanation"), prevDifficulty, verticalSize, difficultyOptions, OnValuesChanged);
|
||||
|
||||
SettingValue<int> maxMissionCountInput = CreateGUINumberInputCarousel(settingsList.Content, TextManager.Get("maxmissioncount"), TextManager.Get("maxmissioncounttooltip"),
|
||||
prevSettings.MaxMissionCount,
|
||||
valueStep: 1, minValue: CampaignSettings.MinMissionCountLimit, maxValue: CampaignSettings.MaxMissionCountLimit,
|
||||
verticalSize);
|
||||
verticalSize,
|
||||
OnValuesChanged);
|
||||
|
||||
presetDropdown.OnSelected = (selected, o) =>
|
||||
presetDropdown.OnSelected = (_, o) =>
|
||||
{
|
||||
if (o is CampaignSettings settings)
|
||||
{
|
||||
tutorialEnabled.SetValue(isSinglePlayer && settings.TutorialEnabled);
|
||||
radiationEnabled.SetValue(settings.RadiationEnabled);
|
||||
maxMissionCountInput.SetValue(settings.MaxMissionCount);
|
||||
startingFundsInput.SetValue(settings.StartingBalanceAmount);
|
||||
difficultyInput.SetValue(settings.Difficulty);
|
||||
startingSetInput.SetValue(settings.StartItemSet);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
if (o is not CampaignSettings settings) { return false; }
|
||||
|
||||
loadingPreset = true;
|
||||
tutorialEnabled.SetValue(isSinglePlayer && settings.TutorialEnabled);
|
||||
radiationEnabled.SetValue(settings.RadiationEnabled);
|
||||
maxMissionCountInput.SetValue(settings.MaxMissionCount);
|
||||
startingFundsInput.SetValue(settings.StartingBalanceAmount);
|
||||
difficultyInput.SetValue(settings.Difficulty);
|
||||
startingSetInput.SetValue(settings.StartItemSet);
|
||||
loadingPreset = false;
|
||||
return true;
|
||||
};
|
||||
|
||||
void OnValuesChanged()
|
||||
{
|
||||
if (loadingPreset) { return; }
|
||||
presetDropdown.Select(0);
|
||||
}
|
||||
|
||||
return new CampaignSettingElements
|
||||
{
|
||||
SelectedPreset = presetValue,
|
||||
TutorialEnabled = tutorialEnabled,
|
||||
RadiationEnabled = radiationEnabled,
|
||||
MaxMissionCount = maxMissionCountInput,
|
||||
@@ -241,7 +283,7 @@ namespace Barotrauma
|
||||
};
|
||||
|
||||
// Create a number input with plus and minus buttons because for some reason the default GUINumberInput buttons don't work when in a GUIMessageBox
|
||||
static SettingValue<int> CreateGUINumberInputCarousel(GUIComponent parent, LocalizedString description, LocalizedString tooltip, int defaultValue, int valueStep, int minValue, int maxValue, float verticalSize)
|
||||
static SettingValue<int> CreateGUINumberInputCarousel(GUIComponent parent, LocalizedString description, LocalizedString tooltip, int defaultValue, int valueStep, int minValue, int maxValue, float verticalSize, Action onChanged)
|
||||
{
|
||||
GUILayoutGroup inputContainer = CreateSettingBase(parent, description, tooltip, horizontalSize: 0.55f, verticalSize: verticalSize);
|
||||
|
||||
@@ -266,9 +308,11 @@ namespace Barotrauma
|
||||
|
||||
minusButton.OnClicked = plusButton.OnClicked = ChangeValue;
|
||||
|
||||
numberInput.OnValueChanged += _ => onChanged();
|
||||
|
||||
bool ChangeValue(GUIButton btn, object userData)
|
||||
{
|
||||
if (!(userData is int change)) { return false; }
|
||||
if (userData is not int change) { return false; }
|
||||
|
||||
numberInput.IntValue += change;
|
||||
return true;
|
||||
@@ -278,7 +322,7 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
static SettingValue<T> CreateSelectionCarousel<T>(GUIComponent parent, LocalizedString description, LocalizedString tooltip, SettingCarouselElement<T> defaultValue, float verticalSize,
|
||||
ImmutableArray<SettingCarouselElement<T>> options)
|
||||
ImmutableArray<SettingCarouselElement<T>> options, Action onChanged)
|
||||
{
|
||||
GUILayoutGroup inputContainer = CreateSettingBase(parent, description, tooltip, horizontalSize: 0.55f, verticalSize: verticalSize);
|
||||
|
||||
@@ -329,6 +373,8 @@ namespace Barotrauma
|
||||
return true;
|
||||
}
|
||||
|
||||
numberInput.OnValueChanged += _ => onChanged();
|
||||
|
||||
void SetValue(int value)
|
||||
{
|
||||
numberInput.IntValue = value;
|
||||
@@ -338,7 +384,7 @@ namespace Barotrauma
|
||||
return new SettingValue<T>(() => options[numberInput.IntValue].Value, t => SetValue(options.IndexOf(e => Equals(e.Value, t))));
|
||||
}
|
||||
|
||||
static SettingValue<bool> CreateTickbox(GUIComponent parent, LocalizedString description, LocalizedString tooltip, bool defaultValue, float verticalSize)
|
||||
static SettingValue<bool> CreateTickbox(GUIComponent parent, LocalizedString description, LocalizedString tooltip, bool defaultValue, float verticalSize, Action onChanged)
|
||||
{
|
||||
GUILayoutGroup inputContainer = CreateSettingBase(parent, description, tooltip, 0.7f, verticalSize);
|
||||
GUILayoutGroup tickboxContainer = new GUILayoutGroup(new RectTransform(new Vector2(0.3f, 1.0f), inputContainer.RectTransform), childAnchor: Anchor.Center);
|
||||
@@ -350,6 +396,13 @@ namespace Barotrauma
|
||||
tickBox.Box.IgnoreLayoutGroups = true;
|
||||
tickBox.Box.RectTransform.SetPosition(Anchor.CenterRight);
|
||||
inputContainer.RectTransform.Parent.MinSize = new Point(0, tickBox.RectTransform.MinSize.Y);
|
||||
|
||||
tickBox.OnSelected += _ =>
|
||||
{
|
||||
onChanged();
|
||||
return true;
|
||||
};
|
||||
|
||||
return new SettingValue<bool>(() => tickBox.Selected, b => tickBox.Selected = b);
|
||||
}
|
||||
|
||||
@@ -367,5 +420,25 @@ namespace Barotrauma
|
||||
return inputContainer;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void UpdateLoadMenu(IEnumerable<CampaignMode.SaveInfo> saveFiles = null);
|
||||
|
||||
protected bool DeleteSave(GUIButton button, object obj)
|
||||
{
|
||||
if (obj is not CampaignMode.SaveInfo saveInfo) { return false; }
|
||||
|
||||
var header = TextManager.Get("deletedialoglabel");
|
||||
var body = TextManager.GetWithVariable("deletedialogquestion", "[file]", Path.GetFileNameWithoutExtension(saveInfo.FilePath));
|
||||
|
||||
EventEditorScreen.AskForConfirmation(header, body, () =>
|
||||
{
|
||||
SaveUtil.DeleteSave(saveInfo.FilePath);
|
||||
prevSaveFiles?.RemoveAll(s => s.FilePath == saveInfo.FilePath);
|
||||
UpdateLoadMenu(prevSaveFiles.ToList());
|
||||
return true;
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
-48
@@ -192,7 +192,7 @@ namespace Barotrauma
|
||||
yield return CoroutineStatus.Success;
|
||||
}
|
||||
|
||||
public void UpdateLoadMenu(IEnumerable<CampaignMode.SaveInfo> saveFiles = null)
|
||||
public override void UpdateLoadMenu(IEnumerable<CampaignMode.SaveInfo> saveFiles = null)
|
||||
{
|
||||
prevSaveFiles?.Clear();
|
||||
prevSaveFiles = null;
|
||||
@@ -220,37 +220,16 @@ namespace Barotrauma
|
||||
CreateSaveElement(saveInfo);
|
||||
}
|
||||
|
||||
saveList.Content.RectTransform.SortChildren((c1, c2) =>
|
||||
{
|
||||
string file1 = c1.GUIComponent.UserData as string;
|
||||
string file2 = c2.GUIComponent.UserData as string;
|
||||
DateTime file1WriteTime = DateTime.MinValue;
|
||||
DateTime file2WriteTime = DateTime.MinValue;
|
||||
try
|
||||
{
|
||||
file1WriteTime = File.GetLastWriteTime(file1);
|
||||
}
|
||||
catch
|
||||
{
|
||||
//do nothing - DateTime.MinValue will be used and the element will get sorted at the bottom of the list
|
||||
};
|
||||
try
|
||||
{
|
||||
file2WriteTime = File.GetLastWriteTime(file2);
|
||||
}
|
||||
catch
|
||||
{
|
||||
//do nothing - DateTime.MinValue will be used and the element will get sorted at the bottom of the list
|
||||
};
|
||||
return file2WriteTime.CompareTo(file1WriteTime);
|
||||
});
|
||||
SortSaveList();
|
||||
|
||||
loadGameButton = new GUIButton(new RectTransform(new Vector2(0.45f, 0.12f), loadGameContainer.RectTransform, Anchor.BottomRight), TextManager.Get("LoadButton"))
|
||||
{
|
||||
OnClicked = (btn, obj) =>
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(saveList.SelectedData as string)) { return false; }
|
||||
LoadGame?.Invoke(saveList.SelectedData as string);
|
||||
if (saveList.SelectedData is not CampaignMode.SaveInfo saveInfo) { return false; }
|
||||
if (string.IsNullOrWhiteSpace(saveInfo.FilePath)) { return false; }
|
||||
LoadGame?.Invoke(saveInfo.FilePath);
|
||||
|
||||
CoroutineManager.StartCoroutine(WaitForCampaignSetup(), "WaitForCampaignSetup");
|
||||
return true;
|
||||
},
|
||||
@@ -264,37 +243,20 @@ namespace Barotrauma
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
private bool SelectSaveFile(GUIComponent component, object obj)
|
||||
{
|
||||
string fileName = (string)obj;
|
||||
if (obj is not CampaignMode.SaveInfo saveInfo) { return true; }
|
||||
string fileName = saveInfo.FilePath;
|
||||
|
||||
loadGameButton.Enabled = true;
|
||||
deleteMpSaveButton.Visible = deleteMpSaveButton.Enabled = GameMain.Client.IsServerOwner;
|
||||
deleteMpSaveButton.Enabled = GameMain.GameSession?.SavePath != fileName;
|
||||
if (deleteMpSaveButton.Visible)
|
||||
{
|
||||
deleteMpSaveButton.UserData = obj as string;
|
||||
deleteMpSaveButton.UserData = saveInfo;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool DeleteSave(GUIButton button, object obj)
|
||||
{
|
||||
string saveFile = obj as string;
|
||||
if (obj == null) { return false; }
|
||||
|
||||
var header = TextManager.Get("deletedialoglabel");
|
||||
var body = TextManager.GetWithVariable("deletedialogquestion", "[file]", Path.GetFileNameWithoutExtension(saveFile));
|
||||
|
||||
EventEditorScreen.AskForConfirmation(header, body, () =>
|
||||
{
|
||||
SaveUtil.DeleteSave(saveFile);
|
||||
prevSaveFiles?.RemoveAll(s => s.FilePath == saveFile);
|
||||
UpdateLoadMenu(prevSaveFiles.ToList());
|
||||
return true;
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+51
-86
@@ -194,7 +194,7 @@ namespace Barotrauma
|
||||
{
|
||||
TextGetter = () =>
|
||||
{
|
||||
int initialMoney = CurrentSettings.InitialMoney;
|
||||
int initialMoney = CampaignSettings.CurrentSettings.InitialMoney;
|
||||
if (subList.SelectedData is SubmarineInfo subInfo)
|
||||
{
|
||||
initialMoney -= subInfo.Price;
|
||||
@@ -208,15 +208,15 @@ namespace Barotrauma
|
||||
{
|
||||
OnClicked = (tb, userdata) =>
|
||||
{
|
||||
CreateCustomizeWindow(CurrentSettings, settings =>
|
||||
CreateCustomizeWindow(CampaignSettings.CurrentSettings, settings =>
|
||||
{
|
||||
CampaignSettings prevSettings = CurrentSettings;
|
||||
CurrentSettings = settings;
|
||||
CampaignSettings prevSettings = CampaignSettings.CurrentSettings;
|
||||
CampaignSettings.CurrentSettings = settings;
|
||||
if (prevSettings.InitialMoney != settings.InitialMoney)
|
||||
{
|
||||
object selectedData = subList.SelectedData;
|
||||
UpdateSubList(SubmarineInfo.SavedSubmarines);
|
||||
if (selectedData is SubmarineInfo selectedSub && selectedSub.Price <= CurrentSettings.InitialMoney)
|
||||
if (selectedData is SubmarineInfo selectedSub && selectedSub.Price <= CampaignSettings.CurrentSettings.InitialMoney)
|
||||
{
|
||||
subList.Select(selectedData);
|
||||
}
|
||||
@@ -375,6 +375,7 @@ namespace Barotrauma
|
||||
{
|
||||
|
||||
onClosed?.Invoke(elements.CreateSettings());
|
||||
GameSettings.SaveCurrentConfig();
|
||||
return CampaignCustomizeSettings.Close(button, o);
|
||||
};
|
||||
}
|
||||
@@ -399,7 +400,7 @@ namespace Barotrauma
|
||||
|
||||
SubmarineInfo selectedSub = null;
|
||||
|
||||
if (!(subList.SelectedData is SubmarineInfo)) { return false; }
|
||||
if (subList.SelectedData is not SubmarineInfo) { return false; }
|
||||
selectedSub = subList.SelectedData as SubmarineInfo;
|
||||
|
||||
if (selectedSub.SubmarineClass == SubmarineClass.Undefined)
|
||||
@@ -419,7 +420,7 @@ namespace Barotrauma
|
||||
string savePath = SaveUtil.CreateSavePath(SaveUtil.SaveType.Singleplayer, saveNameBox.Text);
|
||||
bool hasRequiredContentPackages = selectedSub.RequiredContentPackagesInstalled;
|
||||
|
||||
CampaignSettings settings = CurrentSettings;
|
||||
CampaignSettings settings = CampaignSettings.CurrentSettings;
|
||||
|
||||
if (selectedSub.HasTag(SubmarineTag.Shuttle) || !hasRequiredContentPackages)
|
||||
{
|
||||
@@ -476,7 +477,7 @@ namespace Barotrauma
|
||||
{
|
||||
foreach (GUIComponent child in subList.Content.Children)
|
||||
{
|
||||
if (!(child.UserData is SubmarineInfo sub)) { return; }
|
||||
if (child.UserData is not SubmarineInfo sub) { return; }
|
||||
child.Visible = string.IsNullOrEmpty(filter) || sub.DisplayName.Contains(filter.ToLower(), StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
@@ -487,9 +488,9 @@ namespace Barotrauma
|
||||
(subPreviewContainer.Parent as GUILayoutGroup)?.Recalculate();
|
||||
subPreviewContainer.ClearChildren();
|
||||
|
||||
if (!(obj is SubmarineInfo sub)) { return true; }
|
||||
if (obj is not SubmarineInfo sub) { return true; }
|
||||
#if !DEBUG
|
||||
if (sub.Price > CurrentSettings.InitialMoney && !GameMain.DebugDraw)
|
||||
if (sub.Price > CampaignSettings.CurrentSettings.InitialMoney && !GameMain.DebugDraw)
|
||||
{
|
||||
SetPage(0);
|
||||
nextButton.Enabled = false;
|
||||
@@ -551,7 +552,7 @@ namespace Barotrauma
|
||||
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.5f), infoContainer.RectTransform),
|
||||
TextManager.GetWithVariable("currencyformat", "[credits]", string.Format(CultureInfo.InvariantCulture, "{0:N0}", sub.Price)), textAlignment: Alignment.BottomRight, font: GUIStyle.SmallFont)
|
||||
{
|
||||
TextColor = sub.Price > CurrentSettings.InitialMoney ? GUIStyle.Red : textBlock.TextColor * 0.8f,
|
||||
TextColor = sub.Price > CampaignSettings.CurrentSettings.InitialMoney ? GUIStyle.Red : textBlock.TextColor * 0.8f,
|
||||
ToolTip = textBlock.ToolTip
|
||||
};
|
||||
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.5f), infoContainer.RectTransform),
|
||||
@@ -563,7 +564,7 @@ namespace Barotrauma
|
||||
#if !DEBUG
|
||||
if (!GameMain.DebugDraw)
|
||||
{
|
||||
if (sub.Price > CurrentSettings.InitialMoney || !sub.IsCampaignCompatible)
|
||||
if (sub.Price > CampaignSettings.CurrentSettings.InitialMoney || !sub.IsCampaignCompatible)
|
||||
{
|
||||
textBlock.CanBeFocused = false;
|
||||
textBlock.TextColor *= 0.5f;
|
||||
@@ -573,7 +574,7 @@ namespace Barotrauma
|
||||
}
|
||||
if (SubmarineInfo.SavedSubmarines.Any())
|
||||
{
|
||||
var validSubs = subsToShow.Where(s => s.IsCampaignCompatible && s.Price <= CurrentSettings.InitialMoney).ToList();
|
||||
var validSubs = subsToShow.Where(s => s.IsCampaignCompatible && s.Price <= CampaignSettings.CurrentSettings.InitialMoney).ToList();
|
||||
if (validSubs.Count > 0)
|
||||
{
|
||||
subList.Select(validSubs[Rand.Int(validSubs.Count)]);
|
||||
@@ -581,7 +582,7 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateLoadMenu(IEnumerable<CampaignMode.SaveInfo> saveFiles = null)
|
||||
public override void UpdateLoadMenu(IEnumerable<CampaignMode.SaveInfo> saveFiles = null)
|
||||
{
|
||||
prevSaveFiles?.Clear();
|
||||
prevSaveFiles = null;
|
||||
@@ -649,46 +650,27 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
saveList.Content.RectTransform.SortChildren((c1, c2) =>
|
||||
{
|
||||
string file1 = c1.GUIComponent.UserData as string;
|
||||
string file2 = c2.GUIComponent.UserData as string;
|
||||
DateTime file1WriteTime = DateTime.MinValue;
|
||||
DateTime file2WriteTime = DateTime.MinValue;
|
||||
try
|
||||
{
|
||||
file1WriteTime = File.GetLastWriteTime(file1);
|
||||
}
|
||||
catch
|
||||
{
|
||||
//do nothing - DateTime.MinValue will be used and the element will get sorted at the bottom of the list
|
||||
};
|
||||
try
|
||||
{
|
||||
file2WriteTime = File.GetLastWriteTime(file2);
|
||||
}
|
||||
catch
|
||||
{
|
||||
//do nothing - DateTime.MinValue will be used and the element will get sorted at the bottom of the list
|
||||
};
|
||||
return file2WriteTime.CompareTo(file1WriteTime);
|
||||
});
|
||||
SortSaveList();
|
||||
|
||||
loadGameButton = new GUIButton(new RectTransform(new Vector2(0.45f, 0.12f), loadGameContainer.RectTransform, Anchor.BottomRight), TextManager.Get("LoadButton"))
|
||||
{
|
||||
OnClicked = (btn, obj) =>
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(saveList.SelectedData as string)) { return false; }
|
||||
LoadGame?.Invoke(saveList.SelectedData as string);
|
||||
if (saveList.SelectedData is not CampaignMode.SaveInfo saveInfo) { return false; }
|
||||
if (string.IsNullOrWhiteSpace(saveInfo.FilePath)) { return false; }
|
||||
LoadGame?.Invoke(saveInfo.FilePath);
|
||||
|
||||
return true;
|
||||
},
|
||||
Enabled = false
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private bool SelectSaveFile(GUIComponent component, object obj)
|
||||
{
|
||||
string fileName = (string)obj;
|
||||
if (obj is not CampaignMode.SaveInfo saveInfo) { return true; }
|
||||
|
||||
string fileName = saveInfo.FilePath;
|
||||
|
||||
XDocument doc = SaveUtil.LoadGameSessionDoc(fileName);
|
||||
if (doc?.Root == null)
|
||||
@@ -701,72 +683,55 @@ namespace Barotrauma
|
||||
|
||||
RemoveSaveFrame();
|
||||
|
||||
string subName = doc.Root.GetAttributeString("submarine", "");
|
||||
string saveTime = doc.Root.GetAttributeString("savetime", "unknown");
|
||||
DateTime? time = null;
|
||||
if (long.TryParse(saveTime, out long unixTime))
|
||||
{
|
||||
time = ToolBox.Epoch.ToDateTime(unixTime);
|
||||
saveTime = time.ToString();
|
||||
}
|
||||
string subName = saveInfo.SubmarineName;
|
||||
LocalizedString saveTime = saveInfo.SaveTime
|
||||
.Select(t => (LocalizedString)t.ToLocalUserString())
|
||||
.Fallback(TextManager.Get("Unknown"));
|
||||
|
||||
string mapseed = doc.Root.GetAttributeString("mapseed", "unknown");
|
||||
|
||||
var saveFileFrame = new GUIFrame(new RectTransform(new Vector2(0.45f, 0.6f), loadGameContainer.RectTransform, Anchor.TopRight)
|
||||
{
|
||||
RelativeOffset = new Vector2(0.0f, 0.1f)
|
||||
}, style: "InnerFrame")
|
||||
var saveFileFrame = new GUIFrame(
|
||||
new RectTransform(new Vector2(0.45f, 0.6f), loadGameContainer.RectTransform, Anchor.TopRight)
|
||||
{
|
||||
RelativeOffset = new Vector2(0.0f, 0.1f)
|
||||
}, style: "InnerFrame")
|
||||
{
|
||||
UserData = "savefileframe"
|
||||
};
|
||||
|
||||
var titleText = new GUITextBlock(new RectTransform(new Vector2(0.9f, 0.2f), saveFileFrame.RectTransform, Anchor.TopCenter)
|
||||
{
|
||||
RelativeOffset = new Vector2(0, 0.05f)
|
||||
},
|
||||
var titleText = new GUITextBlock(
|
||||
new RectTransform(new Vector2(0.9f, 0.2f), saveFileFrame.RectTransform, Anchor.TopCenter)
|
||||
{
|
||||
RelativeOffset = new Vector2(0, 0.05f)
|
||||
},
|
||||
Path.GetFileNameWithoutExtension(fileName), font: GUIStyle.LargeFont, textAlignment: Alignment.Center);
|
||||
titleText.Text = ToolBox.LimitString(titleText.Text, titleText.Font, titleText.Rect.Width);
|
||||
|
||||
var layoutGroup = new GUILayoutGroup(new RectTransform(new Vector2(0.8f, 0.5f), saveFileFrame.RectTransform, Anchor.Center)
|
||||
{
|
||||
RelativeOffset = new Vector2(0, 0.1f)
|
||||
});
|
||||
var layoutGroup = new GUILayoutGroup(
|
||||
new RectTransform(new Vector2(0.8f, 0.5f), saveFileFrame.RectTransform, Anchor.Center)
|
||||
{
|
||||
RelativeOffset = new Vector2(0, 0.1f)
|
||||
});
|
||||
|
||||
new GUITextBlock(new RectTransform(new Vector2(1, 0), layoutGroup.RectTransform), $"{TextManager.Get("Submarine")} : {subName}", font: GUIStyle.SmallFont);
|
||||
new GUITextBlock(new RectTransform(new Vector2(1, 0), layoutGroup.RectTransform), $"{TextManager.Get("LastSaved")} : {saveTime}", font: GUIStyle.SmallFont);
|
||||
new GUITextBlock(new RectTransform(new Vector2(1, 0), layoutGroup.RectTransform), $"{TextManager.Get("MapSeed")} : {mapseed}", font: GUIStyle.SmallFont);
|
||||
new GUITextBlock(new RectTransform(new Vector2(1, 0), layoutGroup.RectTransform),
|
||||
$"{TextManager.Get("Submarine")} : {subName}", font: GUIStyle.SmallFont);
|
||||
new GUITextBlock(new RectTransform(new Vector2(1, 0), layoutGroup.RectTransform),
|
||||
$"{TextManager.Get("LastSaved")} : {saveTime}", font: GUIStyle.SmallFont);
|
||||
new GUITextBlock(new RectTransform(new Vector2(1, 0), layoutGroup.RectTransform),
|
||||
$"{TextManager.Get("MapSeed")} : {mapseed}", font: GUIStyle.SmallFont);
|
||||
|
||||
new GUIButton(new RectTransform(new Vector2(0.4f, 0.15f), saveFileFrame.RectTransform, Anchor.BottomCenter)
|
||||
{
|
||||
RelativeOffset = new Vector2(0, 0.1f)
|
||||
}, TextManager.Get("Delete"), style: "GUIButtonSmall")
|
||||
{
|
||||
UserData = fileName,
|
||||
UserData = saveInfo,
|
||||
OnClicked = DeleteSave
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool DeleteSave(GUIButton button, object obj)
|
||||
{
|
||||
string saveFile = obj as string;
|
||||
if (obj == null) { return false; }
|
||||
|
||||
LocalizedString header = TextManager.Get("deletedialoglabel");
|
||||
LocalizedString body = TextManager.GetWithVariable("deletedialogquestion", "[file]", Path.GetFileNameWithoutExtension(saveFile));
|
||||
|
||||
EventEditorScreen.AskForConfirmation(header, body, () =>
|
||||
{
|
||||
SaveUtil.DeleteSave(saveFile);
|
||||
prevSaveFiles?.RemoveAll(s => s.FilePath == saveFile);
|
||||
UpdateLoadMenu(prevSaveFiles.ToList());
|
||||
return true;
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void RemoveSaveFrame()
|
||||
{
|
||||
GUIComponent prevFrame = null;
|
||||
|
||||
Reference in New Issue
Block a user