v0.18.15.0

This commit is contained in:
Regalis11
2022-07-14 16:54:36 +03:00
parent 497045de7e
commit 4a03ee5ab2
36 changed files with 240 additions and 151 deletions
@@ -202,7 +202,7 @@ namespace Barotrauma
OnSelected = (tb) => transferItemsOnSwitch = tb.Selected
};
transferItemsTickBox.RectTransform.Resize(new Point(Math.Min((int)transferItemsTickBox.ContentWidth, transferInfoFrame.Rect.Width), transferItemsTickBox.Rect.Height));
itemTransferInfoBlock = new GUITextBlock(new RectTransform(Vector2.One, transferInfoFrame.RectTransform, Anchor.CenterRight), null)
itemTransferInfoBlock = new GUITextBlock(new RectTransform(Vector2.One, transferInfoFrame.RectTransform, Anchor.CenterRight), null, wrap: true)
{
TextAlignment = Alignment.CenterRight,
Visible = false
@@ -473,7 +473,10 @@ namespace Barotrauma
subsToShow.Sort((x, y) => x.SubmarineClass.CompareTo(y.SubmarineClass));
}
if (transferService) SetConfirmButtonState(selectedSubmarine != null && selectedSubmarine.Name != CurrentOrPendingSubmarine().Name);
if (transferService)
{
SetConfirmButtonState(selectedSubmarine != null && selectedSubmarine.Name != CurrentOrPendingSubmarine().Name);
}
subsToShow.Sort((x, y) => x.SubmarineClass.CompareTo(y.SubmarineClass));
pageCount = Math.Max(1, (int)Math.Ceiling(subsToShow.Count / (float)submarinesPerPage));
@@ -606,12 +609,6 @@ namespace Barotrauma
UpdateItemTransferInfoFrame();
}
private bool ForceItemTransfer()
{
if (selectedSubmarine == null) { return false; }
return !selectedSubmarine.IsManuallyOutfitted && !GameMain.GameSession.IsSubmarineOwned(selectedSubmarine);
}
private bool IsSelectedSubCurrentSub => Submarine.MainSub?.Info?.Name == selectedSubmarine?.Name;
private void UpdateItemTransferInfoFrame()
@@ -625,13 +622,6 @@ namespace Barotrauma
itemTransferInfoBlock.Visible = confirmButton.Enabled;
itemTransferInfoBlock.Text = TextManager.Get("switchingbacktocurrentsub");
}
else if (ForceItemTransfer())
{
TransferItemsOnSwitch = true;
transferItemsTickBox.Visible = false;
itemTransferInfoBlock.Visible = true;
itemTransferInfoBlock.Text = TransferItemsOnSwitch ? TextManager.Get("itemtransferenabledreminder") : TextManager.Get("itemtransferdisabledreminder");
}
else if (GameMain.GameSession?.Campaign?.PendingSubmarineSwitch?.Name == selectedSubmarine.Name)
{
transferItemsTickBox.Visible = false;
@@ -730,6 +720,11 @@ namespace Barotrauma
{
return ShowConfirmationPopup(TextManager.Get("noitemsheader"), TextManager.Get("noitemswarning"));
}
if (!GameMain.GameSession.IsSubmarineOwned(selectedSubmarine) && !selectedSubmarine.IsManuallyOutfitted)
{
var (header, body) = GetItemTransferWarningText();
return ShowConfirmationPopup(header, body);
}
if (selectedSubmarine.LowFuel)
{
return ShowConfirmationPopup(TextManager.Get("lowfuelheader"), TextManager.Get("lowfuelwarning"));
@@ -771,6 +766,13 @@ namespace Barotrauma
}
}
private (LocalizedString header, LocalizedString body) GetItemTransferWarningText()
{
var header = TextManager.Get("itemtransferheader").Fallback("lowfuelheader");
var body = TextManager.Get("itemtransferwarning").Fallback("lowfuelwarning");
return (header, body);
}
private void ShowBuyPrompt(bool purchaseOnly)
{
if (!GameMain.GameSession.Campaign.CanAfford(selectedSubmarine.Price))
@@ -782,7 +784,6 @@ namespace Barotrauma
}
GUIMessageBox msgBox;
if (!purchaseOnly)
{
var text = TextManager.GetWithVariables("purchaseandswitchsubmarinetext",
@@ -794,6 +795,39 @@ namespace Barotrauma
msgBox = new GUIMessageBox(TextManager.Get("purchaseandswitchsubmarineheader"), text, messageBoxOptions);
msgBox.Buttons[0].OnClicked = (applyButton, obj) =>
{
if (!TransferItemsOnSwitch && !IsSelectedSubCurrentSub)
{
if (selectedSubmarine.NoItems)
{
ShowConfirmationPopup(TextManager.Get("noitemsheader"), TextManager.Get("noitemswarning"));
return false;
}
if (!GameMain.GameSession.IsSubmarineOwned(selectedSubmarine) && !selectedSubmarine.IsManuallyOutfitted)
{
var (header, body) = GetItemTransferWarningText();
ShowConfirmationPopup(header, body);
return false;
}
if (selectedSubmarine.LowFuel)
{
ShowConfirmationPopup(TextManager.Get("lowfuelheader"), TextManager.Get("lowfuelwarning"));
return false;
}
}
return Confirm();
};
void ShowConfirmationPopup(LocalizedString header, LocalizedString textBody)
{
msgBox.Close();
var extraConfirmationBox = new GUIMessageBox(header, textBody, new LocalizedString[2] { TextManager.Get("ok"), TextManager.Get("cancel") });
extraConfirmationBox.Buttons[0].OnClicked = (b, o) => Confirm();
extraConfirmationBox.Buttons[0].OnClicked += extraConfirmationBox.Close;
extraConfirmationBox.Buttons[1].OnClicked += extraConfirmationBox.Close;
}
bool Confirm()
{
if (GameMain.Client == null)
{
@@ -806,7 +840,7 @@ namespace Barotrauma
GameMain.Client.InitiateSubmarineChange(selectedSubmarine, TransferItemsOnSwitch, Networking.VoteType.PurchaseAndSwitchSub);
}
return true;
};
}
}
else
{
@@ -842,10 +876,7 @@ namespace Barotrauma
return $"\n\n{TextManager.Get("switchingbacktocurrentsub")}";
}
var s = "\n\n" + TextManager.Get(TransferItemsOnSwitch ? "itemswillbetransferred" : "itemswontbetransferred");
if (!ForceItemTransfer())
{
s += $" {TextManager.Get("toggleitemtransferprompt")}";
}
s += $" {TextManager.Get("toggleitemtransferprompt")}";
return s;
}
}
@@ -330,7 +330,8 @@ namespace Barotrauma
{
Submarine.MainSub.CheckFuel();
SubmarineInfo nextSub = PendingSubmarineSwitch ?? Submarine.MainSub.Info;
if (Level.IsLoadedFriendlyOutpost && nextSub.LowFuel && CargoManager.PurchasedItems.None(i => i.Value.Any(pi => pi.ItemPrefab.Tags.Contains("reactorfuel"))))
bool lowFuel = nextSub.Name == Submarine.MainSub.Info.Name ? Submarine.MainSub.Info.LowFuel : nextSub.LowFuel;
if (Level.IsLoadedFriendlyOutpost && lowFuel && CargoManager.PurchasedItems.None(i => i.Value.Any(pi => pi.ItemPrefab.Tags.Contains("reactorfuel"))))
{
var extraConfirmationBox =
new GUIMessageBox(TextManager.Get("lowfuelheader"),
@@ -693,13 +693,15 @@ namespace Barotrauma
if (ShouldApply(NetFlags.SubList, id, requireUpToDateSave: false))
{
GameMain.GameSession.OwnedSubmarines.Clear();
foreach (int ownedSubIndex in ownedSubIndices)
{
SubmarineInfo sub = GameMain.Client.ServerSubmarines[ownedSubIndex];
if (GameMain.NetLobbyScreen.CheckIfCampaignSubMatches(sub, NetLobbyScreen.SubmarineDeliveryData.Owned))
{
GameMain.GameSession.OwnedSubmarines.Add(sub);
if (GameMain.GameSession.OwnedSubmarines.None(s => s.Name == sub.Name))
{
GameMain.GameSession.OwnedSubmarines.Add(sub);
}
}
}
}
@@ -938,7 +938,7 @@ namespace Barotrauma.Items.Components
DrawMarker(spriteBatch,
Level.Loaded.StartLocation.Name,
(Level.Loaded.StartOutpost != null ? "outpost" : "location").ToIdentifier(),
Level.Loaded.StartLocation.Name,
"startlocation",
Level.Loaded.StartExitPosition, transducerCenter,
displayScale, center, DisplayRadius);
}
@@ -948,7 +948,7 @@ namespace Barotrauma.Items.Components
DrawMarker(spriteBatch,
Level.Loaded.EndLocation.Name,
(Level.Loaded.EndOutpost != null ? "outpost" : "location").ToIdentifier(),
Level.Loaded.EndLocation.Name,
"endlocation",
Level.Loaded.EndExitPosition, transducerCenter,
displayScale, center, DisplayRadius);
}
@@ -91,6 +91,8 @@ namespace Barotrauma.MapCreatures.Behavior
{
foreach (BallastFloraBranch branch in Branches)
{
if (branch.IsRoot && isDead) { continue; }
if (branch.AccumulatedDamage > 0)
{
CreateDamageParticle(branch, branch.AccumulatedDamage);
@@ -101,8 +103,7 @@ namespace Barotrauma.MapCreatures.Behavior
GUI.AddMessage($"{(int)branch.AccumulatedDamage}", GUIStyle.Red, pos, Vector2.UnitY * 10.0f, 3f, playSound: false, subId: Parent?.Submarine?.ID ?? -1);
}
}
if (Character.Controlled != null && Character.Controlled.CurrentHull == branch.CurrentHull &&
branch.IsRoot &&
if (Character.Controlled != null && Character.Controlled.CurrentHull == branch.CurrentHull && branch.IsRoot &&
(branch.AccumulatedDamage > 0.0f || branch.AccumulatedDamage < -0.1f))
{
Character.Controlled.UpdateHUDProgressBar(this,
@@ -216,7 +216,7 @@ namespace Barotrauma
{
if (Math.Sign(flowTargetHull.Rect.Y - rect.Y) != Math.Sign(lerpedFlowForce.Y)) { return; }
float particlesPerSec = Math.Max(open * rect.Width * 0.5f * particleAmountMultiplier, 10.0f);
float particlesPerSec = Math.Max(open * rect.Width * particleAmountMultiplier, 10.0f);
float emitInterval = 1.0f / particlesPerSec;
while (particleTimer > emitInterval)
{
@@ -257,8 +257,8 @@ namespace Barotrauma
/*no dripping from large gaps between rooms (looks bad)*/
((GapSize() <= Structure.WallSectionSize) || !IsRoomToRoom))
{
particleTimer += deltaTime;
float particlesPerSec = open * 100.0f * particleAmountMultiplier;
particleTimer += deltaTime;
float particlesPerSec = open * 10.0f * particleAmountMultiplier;
float emitInterval = 1.0f / particlesPerSec;
while (particleTimer > emitInterval)
{
@@ -271,7 +271,7 @@ namespace Barotrauma
case VoteType.SwitchSub:
string subName1 = inc.ReadString();
bool transferItems = inc.ReadBoolean();
SubmarineInfo info = GameMain.Client.ServerSubmarines.FirstOrDefault(s => s.Name == subName1);
SubmarineInfo info = GameMain.GameSession.OwnedSubmarines.FirstOrDefault(s => s.Name == subName1) ?? GameMain.Client.ServerSubmarines.FirstOrDefault(s => s.Name == subName1);
if (info == null)
{
DebugConsole.ThrowError("Failed to find a matching submarine, vote aborted");
@@ -303,7 +303,7 @@ namespace Barotrauma
case VoteType.PurchaseAndSwitchSub:
case VoteType.SwitchSub:
string subName2 = inc.ReadString();
var submarineInfo = GameMain.Client.ServerSubmarines.FirstOrDefault(s => s.Name == subName2);
var submarineInfo = GameMain.GameSession.OwnedSubmarines.FirstOrDefault(s => s.Name == subName2) ?? GameMain.Client.ServerSubmarines.FirstOrDefault(s => s.Name == subName2);
bool transferItems = inc.ReadBoolean();
int deliveryFee = inc.ReadInt16();
if (submarineInfo == null)
@@ -921,7 +921,7 @@ namespace Barotrauma
toggleEntityMenuButton = new GUIButton(new RectTransform(new Vector2(0.15f, 0.08f), EntityMenu.RectTransform, Anchor.TopCenter, Pivot.BottomCenter) { MinSize = new Point(0, 15) },
style: "UIToggleButtonVertical")
{
ToolTip = RichString.Rich(TextManager.Get("EntityMenuToggleTooltip") + "‖color:125,125,125‖\nQ‖color:end‖"),
ToolTip = RichString.Rich($"{TextManager.Get("EntityMenuToggleTooltip")}\n‖color:125,125,125‖{GameSettings.CurrentConfig.KeyMap.Bindings[InputType.ToggleInventory].Name}‖color:end‖"),
OnClicked = (btn, userdata) =>
{
entityMenuOpen = !entityMenuOpen;
@@ -5187,7 +5187,7 @@ namespace Barotrauma
}
}
if (PlayerInput.KeyHit(Keys.Q) && mode == Mode.Default)
if (GameSettings.CurrentConfig.KeyMap.Bindings[InputType.ToggleInventory].IsHit() && mode == Mode.Default)
{
toggleEntityMenuButton.OnClicked?.Invoke(toggleEntityMenuButton, toggleEntityMenuButton.UserData);
}
@@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.Linq;
using Barotrauma.Items.Components;
using Barotrauma.Extensions;
using System.Diagnostics;
namespace Barotrauma
{
@@ -1437,28 +1438,31 @@ namespace Barotrauma
}
}
break;
case ItemComponent _ when entity is Item item:
foreach (var component in item.Components)
case ItemComponent parentComponent when entity is Item otherItem:
if (otherItem == parentComponent.Item) { continue; }
int componentIndex = parentComponent.Item.Components.FindAll(c => c.GetType() == parentComponent.GetType()).IndexOf(parentComponent);
//find the component of the same type and same index from the other item
var otherComponents = otherItem.Components.FindAll(c => c.GetType() == parentComponent.GetType());
if (componentIndex >= 0 && componentIndex < otherComponents.Count)
{
if (component.GetType() == parentObject.GetType() && component != parentObject)
var component = otherComponents[componentIndex];
Debug.Assert(component.GetType() == parentObject.GetType());
SafeAdd(component, property);
if (value is string stringValue && Enum.TryParse(property.PropertyType, stringValue, out var enumValue))
{
SafeAdd(component, property);
if (value is string stringValue && Enum.TryParse(property.PropertyType, stringValue, out var enumValue))
{
property.PropertyInfo.SetValue(component, enumValue);
}
else
{
try
{
property.PropertyInfo.SetValue(component, value);
}
catch (ArgumentException e)
{
DebugConsole.ThrowError($"Failed to set the value of the property \"{property.Name}\" to {value?.ToString() ?? "null"}", e);
}
}
property.PropertyInfo.SetValue(component, enumValue);
}
else
{
try
{
property.PropertyInfo.SetValue(component, value);
}
catch (ArgumentException e)
{
DebugConsole.ThrowError($"Failed to set the value of the property \"{property.Name}\" to {value?.ToString() ?? "null"}", e);
}
}
}
break;
}
@@ -46,21 +46,7 @@ namespace Barotrauma
return Instance;
}
public void Recreate()
{
if (GUI.SettingsMenuOpen)
{
GUI.SettingsMenuOpen = false;
GUI.SettingsMenuOpen = true;
}
else
{
Create(mainFrame.Parent.RectTransform);
Instance?.SelectTab(Tab.Controls);
}
}
private SettingsMenu(RectTransform mainParent)
private SettingsMenu(RectTransform mainParent, GameSettings.Config setConfig = default)
{
unsavedConfig = GameSettings.CurrentConfig;
@@ -476,8 +462,9 @@ namespace Barotrauma
Slider(voiceChat, (0, 500), 26, (v) => $"{Round(v)} ms", unsavedConfig.Audio.VoiceChatCutoffPrevention, (v) => unsavedConfig.Audio.VoiceChatCutoffPrevention = Round(v), TextManager.Get("CutoffPreventionTooltip"));
}
private readonly Dictionary<GUIButton, Func<LocalizedString>> inputButtonValueNameGetters = new Dictionary<GUIButton, Func<LocalizedString>>();
private bool inputBoxSelectedThisFrame = false;
private void CreateControlsTab()
{
GUIFrame content = CreateNewContentFrame(Tab.Controls);
@@ -501,7 +488,7 @@ namespace Barotrauma
GUILayoutGroup createInputRowLayout()
=> new GUILayoutGroup(new RectTransform((1.0f, 0.1f), keyMapList.Content.RectTransform), isHorizontal: true);
HashSet<GUIButton> inputButtons = new HashSet<GUIButton>();
inputButtonValueNameGetters.Clear();
Action<KeyOrMouse>? currentSetter = null;
void addInputToRow(GUILayoutGroup currRow, LocalizedString labelText, Func<LocalizedString> valueNameGetter, Action<KeyOrMouse> valueSetter, bool isLegacyBind = false)
{
@@ -519,7 +506,7 @@ namespace Barotrauma
{
OnClicked = (btn, obj) =>
{
inputButtons.ForEach(b =>
inputButtonValueNameGetters.Keys.ForEach(b =>
{
if (b != btn) { b.Selected = false; }
});
@@ -544,7 +531,7 @@ namespace Barotrauma
inputBox.Color = Color.Lerp(inputBox.Color, inputBox.DisabledColor, 0.5f);
inputBox.TextColor = Color.Lerp(inputBox.TextColor, label.DisabledTextColor, 0.5f);
}
inputButtons.Add(inputBox);
inputButtonValueNameGetters.Add(inputBox, valueNameGetter);
}
var inputListener = new GUICustomComponent(new RectTransform(Vector2.Zero, layout.RectTransform), onUpdate: (deltaTime, component) =>
@@ -560,7 +547,7 @@ namespace Barotrauma
void clearSetter()
{
currentSetter = null;
inputButtons.ForEach(b => b.Selected = false);
inputButtonValueNameGetters.Keys.ForEach(b => b.Selected = false);
}
void callSetter(KeyOrMouse v)
@@ -663,11 +650,14 @@ namespace Barotrauma
TextManager.Get("Reset"), style: "GUIButtonSmall")
{
ToolTip = TextManager.Get("SetDefaultBindingsTooltip"),
OnClicked = (btn, userdata) =>
OnClicked = (_, userdata) =>
{
unsavedConfig.InventoryKeyMap = GameSettings.Config.InventoryKeyMapping.GetDefault();
unsavedConfig.KeyMap = GameSettings.Config.KeyMapping.GetDefault();
Recreate();
foreach (var btn in inputButtonValueNameGetters.Keys)
{
btn.Text = inputButtonValueNameGetters[btn]();
}
Instance?.SelectTab(Tab.Controls);
return true;
}
@@ -360,8 +360,8 @@ namespace Barotrauma.Steam
if (rules == null) { return; }
if (rules.ContainsKey("message")) serverInfo.ServerMessage = rules["message"];
if (rules.ContainsKey("version")) serverInfo.GameVersion = rules["version"];
if (rules.ContainsKey("message")) { serverInfo.ServerMessage = rules["message"]; }
if (rules.ContainsKey("version")) { serverInfo.GameVersion = rules["version"]; }
if (rules.ContainsKey("playercount"))
{
@@ -371,8 +371,8 @@ namespace Barotrauma.Steam
serverInfo.ContentPackageNames.Clear();
serverInfo.ContentPackageHashes.Clear();
serverInfo.ContentPackageWorkshopIds.Clear();
if (rules.ContainsKey("contentpackage")) serverInfo.ContentPackageNames.AddRange(rules["contentpackage"].Split(','));
if (rules.ContainsKey("contentpackagehash")) serverInfo.ContentPackageHashes.AddRange(rules["contentpackagehash"].Split(','));
if (rules.ContainsKey("contentpackage")) { serverInfo.ContentPackageNames.AddRange(rules["contentpackage"].Split(',')); }
if (rules.ContainsKey("contentpackagehash")) { serverInfo.ContentPackageHashes.AddRange(rules["contentpackagehash"].Split(',')); }
if (rules.ContainsKey("contentpackageid"))
{
serverInfo.ContentPackageWorkshopIds.AddRange(ParseWorkshopIds(rules["contentpackageid"]));
@@ -383,24 +383,26 @@ namespace Barotrauma.Steam
serverInfo.ContentPackageWorkshopIds.AddRange(WorkshopUrlsToIds(workshopUrls));
}
if (rules.ContainsKey("usingwhitelist")) serverInfo.UsingWhiteList = rules["usingwhitelist"] == "True";
if (rules.ContainsKey("usingwhitelist")) { serverInfo.UsingWhiteList = rules["usingwhitelist"] == "True"; }
if (rules.ContainsKey("modeselectionmode"))
{
if (Enum.TryParse(rules["modeselectionmode"], out SelectionMode selectionMode)) serverInfo.ModeSelectionMode = selectionMode;
if (Enum.TryParse(rules["modeselectionmode"], out SelectionMode selectionMode)) { serverInfo.ModeSelectionMode = selectionMode; }
}
if (rules.ContainsKey("subselectionmode"))
{
if (Enum.TryParse(rules["subselectionmode"], out SelectionMode selectionMode)) serverInfo.SubSelectionMode = selectionMode;
if (Enum.TryParse(rules["subselectionmode"], out SelectionMode selectionMode)) { serverInfo.SubSelectionMode = selectionMode; }
}
if (rules.ContainsKey("allowspectating")) serverInfo.AllowSpectating = rules["allowspectating"] == "True";
if (rules.ContainsKey("allowrespawn")) serverInfo.AllowRespawn = rules["allowrespawn"] == "True";
if (rules.ContainsKey("voicechatenabled")) serverInfo.VoipEnabled = rules["voicechatenabled"] == "True";
if (rules.ContainsKey("allowspectating")) { serverInfo.AllowSpectating = rules["allowspectating"] == "True"; }
if (rules.ContainsKey("allowrespawn")) { serverInfo.AllowRespawn = rules["allowrespawn"] == "True"; }
if (rules.ContainsKey("voicechatenabled")) { serverInfo.VoipEnabled = rules["voicechatenabled"] == "True"; }
if (rules.ContainsKey("friendlyfireenabled")) { serverInfo.AllowRespawn = rules["friendlyfireenabled"] == "True"; }
if (rules.ContainsKey("karmaenabled")) { serverInfo.VoipEnabled = rules["karmaenabled"] == "True"; }
if (rules.ContainsKey("traitors"))
{
if (Enum.TryParse(rules["traitors"], out YesNoMaybe traitorsEnabled)) serverInfo.TraitorsEnabled = traitorsEnabled;
if (Enum.TryParse(rules["traitors"], out YesNoMaybe traitorsEnabled)) { serverInfo.TraitorsEnabled = traitorsEnabled; }
}
if (rules.ContainsKey("gamestarted")) serverInfo.GameStarted = rules["gamestarted"] == "True";
if (rules.ContainsKey("gamestarted")) { serverInfo.GameStarted = rules["gamestarted"] == "True"; }
if (rules.ContainsKey("gamemode"))
{
serverInfo.GameMode = rules["gamemode"].ToIdentifier();