Release 1.9.7.0 - Summer Update 2025

This commit is contained in:
Regalis11
2025-06-17 16:38:11 +03:00
parent 22227f13e5
commit ea5a2bc693
297 changed files with 7344 additions and 2421 deletions
@@ -2236,6 +2236,29 @@ namespace Barotrauma
return textBox;
}
/// <summary>
/// Creates a pre-built filter box.
/// </summary>
/// <remarks>
/// The filter function must be set using <see cref="GUITextBox.OnTextChanged"/>.<see langword="add"/>.
/// </remarks>
public static GUITextBox CreateFilterBox(RectTransform rectT)
{
GUITextBox textBox = new(rectT, createClearButton: true)
{
OnEnterPressed = (tb, _) =>
{
tb.Deselect();
return true;
}
};
GUITextBlock label = new(new RectTransform(Vector2.One, textBox.TextBlock.RectTransform, Anchor.CenterLeft), TextManager.Get("serverlog.filter"), GUIStyle.TextColorNormal * 0.75f);
textBox.OnSelected += (_, _) => label.Visible = false;
textBox.OnDeselected += (tb, _) => label.Visible = tb.Text.IsNullOrEmpty();
textBox.OnTextChanged += (tb, text) => label.Visible = !tb.Selected && text.IsNullOrEmpty();
return textBox;
}
public static void NotifyPrompt(LocalizedString header, LocalizedString body)
{
GUIMessageBox msgBox = new GUIMessageBox(header, body, new[] { TextManager.Get("Ok") }, new Vector2(0.2f, 0.175f), minSize: new Point(300, 175));
@@ -2295,9 +2318,61 @@ namespace Barotrauma
return msgBox;
}
#endregion
#nullable enable
#region Item UI
/// <summary>
/// Creates a 7-segment display.
/// </summary>
/// <param name="leftLabel">Returns <see langword="null"/> if <paramref name="leftLabelText"/> is <see langword="null"/> or empty.</param>
/// <param name="rightLabelText">Defaults to <c>TextManager.Get("kilowatt")</c>.</param>
/// <param name="leftLabelFont">Defaults to <see cref="GUIStyle.LargeFont"/>.</param>
public static GUITextBlock CreateDigitalDisplay(RectTransform rect, out GUITextBlock? leftLabel, out GUITextBlock rightLabel, LocalizedString? leftLabelText = null, LocalizedString? rightLabelText = null, LocalizedString? tooltip = null, GUIFont? leftLabelFont = null)
{
GUILayoutGroup textArea = new(rect, isHorizontal: true, childAnchor: Anchor.CenterLeft)
{
Stretch = true,
CanBeFocused = true,
ToolTip = tooltip!,
AbsoluteSpacing = 5
};
#region Element positioning
leftLabel = null;
if (!leftLabelText.IsNullOrEmpty())
{
leftLabel = new GUITextBlock(new RectTransform(new Vector2(0.4f, 1f), textArea.RectTransform), leftLabelText, textColor: GUIStyle.TextColorBright, font: leftLabelFont ?? GUIStyle.LargeFont, textAlignment: Alignment.CenterRight);
}
GUIFrame displayBackground = new(new RectTransform(new Vector2(0.55f, 0.8f), textArea.RectTransform), style: "DigitalFrameDark");
GUITextBlock displayText = new(new RectTransform(new Vector2(0.9f, 0.95f), displayBackground.RectTransform, Anchor.Center), "8888", font: GUIStyle.DigitalFont, textColor: GUIStyle.TextColorDark, textAlignment: Alignment.CenterRight);
displayText.TextScale = Math.Max((displayText.Rect.Height - 10) / GUIStyle.DigitalFont.LineHeight, 0.1f);
rightLabel = new GUITextBlock(new RectTransform(Vector2.Zero, textArea.RectTransform), rightLabelText ?? TextManager.Get("kilowatt"), textColor: GUIStyle.TextColorNormal, font: GUIStyle.Font, textAlignment: Alignment.CenterRight)
{
Padding = Vector4.Zero
};
rightLabel.RectTransform.MinSize = rightLabel.TextSize.ToPoint();
textArea.GetAllChildren().ForEach(child => child.CanBeFocused = false);
return displayText;
}
/// <param name="labelFont">Defaults to <see cref="GUIStyle.SubHeadingFont"/>.</param>
public static GUITickBox CreateIndicatorLight(RectTransform rect, string style = "", LocalizedString? label = null, LocalizedString? tooltip = null, GUIFont? labelFont = null)
{
GUITickBox indicator = new(rect, label, font: labelFont ?? GUIStyle.SubHeadingFont, style: style)
{
Enabled = false,
ToolTip = tooltip!
};
indicator.TextBlock.OverrideTextColor(GUIStyle.TextColorNormal);
return indicator;
}
#endregion
#nullable restore
#endregion
#region Element positioning
private static List<T> CreateElements<T>(int count, RectTransform parent, Func<RectTransform, T> constructor,
Vector2? relativeSize = null, Point? absoluteSize = null,
Anchor anchor = Anchor.TopLeft, Pivot? pivot = null, Point? minSize = null, Point? maxSize = null,
@@ -211,7 +211,7 @@ namespace Barotrauma
}
var selfStyle = Style;
textBlock = new GUITextBlock(new RectTransform(Vector2.One, rectT, Anchor.Center), text, textAlignment: textAlignment, style: null)
textBlock = new GUITextBlock(new RectTransform(Vector2.One, rectT, Anchor.Center), RichString.Rich(text), textAlignment: textAlignment, style: null)
{
TextColor = selfStyle?.TextColor ?? Color.Black,
HoverTextColor = selfStyle?.HoverTextColor ?? Color.Black,
@@ -446,19 +446,22 @@ namespace Barotrauma
UpdateScrollBarSize();
}
public void Select(object userData, Force force = Force.No, AutoScroll autoScroll = AutoScroll.Enabled)
public bool Select(object userData, Force force = Force.No, AutoScroll autoScroll = AutoScroll.Enabled)
{
var children = Content.Children;
int i = 0;
bool wasSelected = false;
foreach (GUIComponent child in children)
{
if (Equals(child.UserData, userData))
{
wasSelected = true;
Select(i, force, autoScroll);
if (!SelectMultiple) { return; }
if (!SelectMultiple) { return true; }
}
i++;
}
return wasSelected;
}
private Point CalculateFrameSize(bool isHorizontal, int scrollBarSize)
@@ -1021,6 +1021,14 @@ namespace Barotrauma
{
MaxTextLength = Client.MaxNameLength
};
nameBox.OnTextChanged += (GUITextBox textBox, string text) =>
{
if (text.Contains('\n') || text.Contains('\r'))
{
textBox.Text = text.Replace("\r\n", " ").Replace('\n', ' ').Replace('\r', ' ');
}
return true;
};
new GUIButton(new RectTransform(groupElementSize, layoutGroup.RectTransform), text: TextManager.Get("confirm"))
{
OnClicked = (button, userData) =>
@@ -1,4 +1,4 @@
#nullable enable
#nullable enable
using System;
using System.Collections.Generic;
@@ -749,7 +749,7 @@ namespace Barotrauma
{
new GUICustomComponent(new RectTransform(Vector2.One, parent.RectTransform, scaleBasis: ScaleBasis.BothHeight), (spriteBatch, component) =>
{
info.DrawPortrait(spriteBatch, component.Rect.Location.ToVector2(), Vector2.Zero, component.Rect.Width);
info.DrawIcon(spriteBatch, component.Rect.Center.ToVector2(), component.Rect.Size.ToVector2());
});
GUILayoutGroup textGroup = new GUILayoutGroup(new RectTransform(new Vector2(1f, 0.8f), parent.RectTransform));
@@ -273,7 +273,7 @@ namespace Barotrauma
new GUICustomComponent(new RectTransform(new Vector2(0.25f, 1f), topLayout.RectTransform), onDraw: (batch, component) =>
{
info.DrawPortrait(batch, component.Rect.Location.ToVector2(), Vector2.Zero, component.Rect.Width, false, false);
info.DrawIcon(batch, component.Rect.Center.ToVector2(), component.Rect.Size.ToVector2());
});
GUILayoutGroup nameLayout = new GUILayoutGroup(new RectTransform(new Vector2(0.3f, 1f), topLayout.RectTransform))
@@ -327,7 +327,7 @@ namespace Barotrauma
if (extraTalent.IsHiddenExtraTalent) { continue; }
GUIImage talentImg = new GUIImage(new RectTransform(Vector2.One, extraTalentList.Content.RectTransform, scaleBasis: ScaleBasis.BothHeight), sprite: extraTalent.Icon, scaleToFit: true)
{
ToolTip = RichString.Rich($"‖color:{Color.White.ToStringHex()}‖{extraTalent.DisplayName}‖color:end‖" + "\n\n" + ToolBox.ExtendColorToPercentageSigns(extraTalent.Description.Value)),
ToolTip = GetTalentTooltip(extraTalent, characterInfo),
Color = GUIStyle.Green
};
}
@@ -637,7 +637,7 @@ namespace Barotrauma
GUIFrame croppedTalentFrame = new GUIFrame(new RectTransform(Vector2.One, talentFrame.RectTransform, anchor: Anchor.Center, scaleBasis: ScaleBasis.BothHeight), style: null);
GUIButton talentButton = new GUIButton(new RectTransform(Vector2.One, croppedTalentFrame.RectTransform, anchor: Anchor.Center), style: null)
{
ToolTip = CreateTooltip(talent, characterInfo),
ToolTip = GetTalentTooltip(talent, characterInfo),
UserData = talent.Identifier,
PressedColor = pressedColor,
Enabled = info.Character != null,
@@ -703,24 +703,6 @@ namespace Barotrauma
},
};
static RichString CreateTooltip(TalentPrefab talent, CharacterInfo? character)
{
LocalizedString progress = string.Empty;
if (character is not null && talent.TrackedStat.TryUnwrap(out var stat))
{
var statValue = character.GetSavedStatValue(StatTypes.None, stat.PermanentStatIdentifier);
var intValue = (int)MathF.Round(statValue);
progress = "\n\n";
progress += statValue < stat.Max
? TextManager.GetWithVariables("talentprogress", ("[amount]", intValue.ToString()), ("[max]", stat.Max.ToString()))
: TextManager.Get("talentprogresscompleted");
}
RichString tooltip = RichString.Rich($"‖color:{Color.White.ToStringHex()}‖{talent.DisplayName}‖color:end‖\n\n{ToolBox.ExtendColorToPercentageSigns(talent.Description.Value)}{progress}");
return tooltip;
}
talentButton.Color = talentButton.HoverColor = talentButton.PressedColor = talentButton.SelectedColor = talentButton.DisabledColor = Color.Transparent;
GUIComponent iconImage;
@@ -814,6 +796,24 @@ namespace Barotrauma
GUITextBlock.AutoScaleAndNormalize(talentResetButton.TextBlock, talentApplyButton.TextBlock);
}
private static RichString GetTalentTooltip(TalentPrefab talent, CharacterInfo? character)
{
LocalizedString progress = string.Empty;
if (character is not null && talent.TrackedStat.TryUnwrap(out var stat))
{
var statValue = character.GetSavedStatValue(StatTypes.None, stat.PermanentStatIdentifier);
var intValue = (int)MathF.Round(statValue);
progress = "\n\n";
progress += statValue < stat.Max
? TextManager.GetWithVariables("talentprogress", ("[amount]", intValue.ToString()), ("[max]", stat.Max.ToString()))
: TextManager.Get("talentprogresscompleted");
}
RichString tooltip = RichString.Rich($"‖color:{Color.White.ToStringHex()}‖{talent.DisplayName}‖color:end‖\n\n{ToolBox.ExtendColorToPercentageSigns(talent.Description.Value)}{progress}");
return tooltip;
}
private bool ResetTalentSelection(GUIButton guiButton, object userData)
{
if (characterInfo is null) { return false; }
@@ -7,6 +7,7 @@ using System.Diagnostics;
using System.Linq;
using Barotrauma.Extensions;
using Barotrauma.Items.Components;
using Barotrauma.Networking;
using FarseerPhysics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
@@ -949,7 +950,7 @@ namespace Barotrauma
GUILayoutGroup buttonLayout = new GUILayoutGroup(rectT(1f, 1f, toggleButton.Frame), isHorizontal: true);
LocalizedString slotText = "";
if (linkedItems.Count() > 1)
if (linkedItems.Count > 1)
{
slotText = TextManager.GetWithVariable("weaponslot", "[number]", string.Join(", ", linkedItems.Select(it => (swappableEntities.IndexOf(it) + 1).ToString())));
}
@@ -978,7 +979,7 @@ namespace Barotrauma
List<GUIFrame> frames = new List<GUIFrame>();
if (currentOrPending != null)
{
bool canUninstall = item.PendingItemSwap != null || !(currentOrPending.SwappableItem?.ReplacementOnUninstall.IsEmpty ?? true);
bool canUninstall = HasPermission && (item.PendingItemSwap != null || !(currentOrPending.SwappableItem?.ReplacementOnUninstall.IsEmpty ?? true));
bool isUninstallPending = item.Prefab.SwappableItem != null && item.PendingItemSwap?.Identifier == item.Prefab.SwappableItem.ReplacementOnUninstall;
if (isUninstallPending) { canUninstall = false; }
@@ -1030,7 +1031,8 @@ namespace Barotrauma
buttonStyle: isPurchased ? "WeaponInstallButton" : "StoreAddToCrateButton").Frame);
if (!(frames.Last().FindChild(c => c is GUIButton, recursive: true) is GUIButton buyButton)) { continue; }
if (PlayerBalance >= price)
if (HasPermission && PlayerBalance >= price)
{
buyButton.Enabled = true;
buyButton.OnClicked += (button, o) =>
@@ -1272,7 +1274,7 @@ namespace Barotrauma
if (!prefabFrame.BuyButton.TryUnwrap(out BuyButtonFrame buyButtonFrame)) { return; }
if (!HasPermission || !prefab.IsApplicable(submarine.Info) || (itemsOnSubmarine != null && !itemsOnSubmarine.Any(it => category.CanBeApplied(it, prefab))))
if (!prefab.IsApplicable(submarine.Info) || (itemsOnSubmarine != null && !itemsOnSubmarine.Any(it => category.CanBeApplied(it, prefab))))
{
prefabFrame.Frame.Enabled = false;
prefabFrame.Description.Enabled = false;
@@ -1289,12 +1291,14 @@ namespace Barotrauma
("[amount]", prefab.Price.GetBuyPrice(prefab, Campaign.UpgradeManager.GetUpgradeLevel(prefab, category), Campaign.Map?.CurrentLocation, characterList).ToString()));
currectConfirmation = EventEditorScreen.AskForConfirmation(TextManager.Get("Upgrades.PurchasePromptTitle"), promptBody, () =>
{
if (GameMain.NetworkMember != null)
if (Campaign.UpgradeManager.TryPurchaseUpgrade(prefab, category))
{
WaitForServerUpdate = true;
if (GameMain.NetworkMember != null)
{
WaitForServerUpdate = true;
}
GameMain.Client?.SendCampaignState();
}
Campaign.UpgradeManager.PurchaseUpgrade(prefab, category);
GameMain.Client?.SendCampaignState();
return true;
}, overrideConfirmButtonSound: GUISoundType.ConfirmTransaction);
@@ -1722,7 +1726,7 @@ namespace Barotrauma
if (buttonParent.FindChild(UpgradeStoreUserData.BuyButton, recursive: true) is GUIButton button)
{
bool canBuy = !WaitForServerUpdate && !isMax && campaign.GetBalance() >= price && prefab.HasResourcesToUpgrade(Character.Controlled, currentLevel + 1);
bool canBuy = !WaitForServerUpdate && HasPermission && !isMax && campaign.GetBalance() >= price && prefab.HasResourcesToUpgrade(Character.Controlled, currentLevel + 1);
button.Enabled = canBuy;
}
@@ -1935,7 +1939,7 @@ namespace Barotrauma
return frames.ToArray();
}
private bool HasPermission => true;
private static bool HasPermission => CampaignMode.AllowedToManageCampaign(ClientPermissions.ManageCampaign);
// just a shortcut to create new RectTransforms since all the new RectTransform and new Vector2 confuses my IDE (and me)
private static RectTransform rectT(float x, float y, GUIComponent parentComponent, Anchor anchor = Anchor.TopLeft, ScaleBasis scaleBasis = ScaleBasis.Normal)