Release 1.8.6.2 - Calm Before the Storm

This commit is contained in:
Markus Isberg
2025-04-10 11:29:43 +00:00
parent c2705bc701
commit 14f61af41c
32 changed files with 505 additions and 199 deletions
@@ -911,6 +911,11 @@ namespace Barotrauma
PauseMenu.AddToGUIUpdateList();
}
foreach (var openAccordion in GUIComponent.OpenAccordionPopups)
{
openAccordion.AddToGUIUpdateList(order: 1);
}
SocialOverlay.Instance?.AddToGuiUpdateList();
GUIContextMenu.AddActiveToGUIUpdateList();
@@ -1127,7 +1127,7 @@ namespace Barotrauma
component = LoadGUIImage(element, parent);
break;
case "accordion":
return LoadAccordion(element, parent);
return LoadAccordion(element, parent, openOnTop: element.GetAttributeBool("openontop", false));
case "gridtext":
LoadGridText(element, parent);
return null;
@@ -1147,6 +1147,19 @@ namespace Barotrauma
component.toolTip = element.GetAttributeString("tooltip", string.Empty);
GUITextBlock textBlock = component as GUITextBlock ?? (component as GUIButton)?.TextBlock;
if (textBlock != null)
{
if (element.GetAttributeBool("autoscalevertical", false))
{
textBlock.AutoScaleVertical = true;
}
if (element.GetAttributeBool("autoscalehorizontal", false))
{
textBlock.AutoScaleHorizontal = true;
}
}
if (element.GetAttributeBool("resizetofitchildren", false))
{
Vector2 relativeResizeScale = element.GetAttributeVector2("relativeresizescale", Vector2.One);
@@ -1209,6 +1222,10 @@ namespace Barotrauma
var maxVersion = new Version(attribute.Value);
if (GameMain.Version > maxVersion) { return false; }
break;
case "identifierdismissed":
Identifier identifier = element.GetAttributeIdentifier(attribute.Name.ToString(), Identifier.Empty);
if (MainMenuScreen.DismissedNotifications.Contains(identifier)) { return false; }
break;
case "buildconfiguration":
switch (attribute.Value.ToString().ToLowerInvariant())
{
@@ -1286,12 +1303,18 @@ namespace Barotrauma
private static GUIButton LoadLink(XElement element, RectTransform parent)
{
Identifier identifier = element.GetAttributeIdentifier("identifier", Identifier.Empty);
var button = LoadGUIButton(element, parent);
string url = element.GetAttributeString("url", "");
button.OnClicked = (btn, userdata) =>
{
try
{
if (!identifier.IsEmpty)
{
MainMenuScreen.AddDismissedNotification(identifier);
}
if (SteamManager.IsInitialized)
{
SteamManager.OverlayCustomUrl(url);
@@ -1348,6 +1371,8 @@ namespace Barotrauma
private static GUIButton LoadGUIButton(XElement element, RectTransform parent)
{
Identifier identifier = element.GetAttributeIdentifier("identifier", Identifier.Empty);
string style = element.GetAttributeString("style", "");
if (style == "null") { style = null; }
@@ -1359,10 +1384,19 @@ namespace Barotrauma
element.GetAttributeString("text", "");
text = text.Replace(@"\n", "\n");
return new GUIButton(RectTransform.Load(element, parent),
var button = new GUIButton(RectTransform.Load(element, parent),
text: text,
textAlignment: textAlignment,
style: style);
button.OnClicked = (btn, userdata) =>
{
if (!identifier.IsEmpty)
{
MainMenuScreen.AddDismissedNotification(identifier);
}
return true;
};
return button;
}
private static GUIListBox LoadGUIListBox(XElement element, RectTransform parent)
@@ -1415,11 +1449,14 @@ namespace Barotrauma
{
sprite = new Sprite(element);
}
return new GUIImage(RectTransform.Load(element, parent), sprite, scaleToFit: true);
var scaleToFit = element.GetAttributeEnum("scaletofit", GUIImage.ScalingMode.ScaleToFitSmallestExtent);
return new GUIImage(RectTransform.Load(element, parent), sprite, scaleToFit: scaleToFit);
}
private static GUIButton LoadAccordion(ContentXElement element, RectTransform parent)
public static readonly List<GUIComponent> OpenAccordionPopups = new List<GUIComponent>();
/// <param name="openOnTop">Should the contents of the accordion be forced to open on top of other UI elements?</param>
private static GUIButton LoadAccordion(ContentXElement element, RectTransform parent, bool openOnTop)
{
var button = LoadGUIButton(element, parent);
List<GUIComponent> content = new List<GUIComponent>();
@@ -1431,6 +1468,7 @@ namespace Barotrauma
contentElement.Visible = false;
contentElement.IgnoreLayoutGroups = true;
content.Add(contentElement);
contentElement.UserData = (contentElement.RectTransform.Anchor, contentElement.RectTransform.Pivot);
}
}
button.OnClicked = (btn, userdata) =>
@@ -1438,8 +1476,32 @@ namespace Barotrauma
bool visible = content.FirstOrDefault()?.Visible ?? true;
foreach (GUIComponent contentElement in content)
{
contentElement.Visible = !visible;
contentElement.IgnoreLayoutGroups = !contentElement.Visible;
if (openOnTop)
{
contentElement.rectTransform.Parent = null;
//the element is drawn in screen space over anything (no longer a child of the original parent),
//we need to calculate the screen space position manually
contentElement.rectTransform.SetPosition(Anchor.TopLeft);
(Anchor anchor, Pivot pivot) = ((Anchor anchor, Pivot pivot))contentElement.UserData;
contentElement.rectTransform.ScreenSpaceOffset =
RectTransform.CalculateAnchorPoint(anchor, button.Rect) +
RectTransform.CalculatePivotOffset(pivot, contentElement.Rect.Size);
contentElement.Visible = true;
if (OpenAccordionPopups.Contains(contentElement))
{
OpenAccordionPopups.Remove(contentElement);
}
else
{
OpenAccordionPopups.Clear();
OpenAccordionPopups.Add(contentElement);
}
}
else
{
contentElement.Visible = !visible;
contentElement.IgnoreLayoutGroups = !contentElement.Visible;
}
}
if (button.Parent is GUILayoutGroup layoutGroup)
{
@@ -2,7 +2,6 @@
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Barotrauma
@@ -14,6 +13,24 @@ namespace Barotrauma
private static bool loadingTextures;
public enum ScalingMode
{
/// <summary>
/// No automatic scaling, the image is drawn using <see cref="Scale"/>
/// </summary>
None,
/// <summary>
/// Automatically scales the image so it fits the smallest extent of the component
/// (leaving empty space around the image if its aspect ratio is different than that of the GUIImage)
/// </summary>
ScaleToFitSmallestExtent,
/// <summary>
/// Automatically scales the image so it fits the largest extent of the component,
/// cutting out the parts that go outside the bounds of the component.
/// </summary>
ScaleToFitLargestExtent,
}
public static bool LoadingTextures
{
get
@@ -30,7 +47,7 @@ namespace Barotrauma
private bool crop;
private readonly bool scaleToFit;
private readonly ScalingMode scaleToFit;
private bool lazyLoaded, loading;
@@ -89,7 +106,7 @@ namespace Barotrauma
sprite = value;
sourceRect = value == null ? Rectangle.Empty : value.SourceRect;
origin = value == null ? Vector2.Zero : value.size / 2;
if (scaleToFit) { RecalculateScale(); }
if (scaleToFit != ScalingMode.None) { RecalculateScale(); }
}
}
@@ -97,17 +114,27 @@ namespace Barotrauma
public ComponentState? OverrideState = null;
public GUIImage(RectTransform rectT, string style, bool scaleToFit = false)
public GUIImage(RectTransform rectT, string style, bool scaleToFit)
: this(rectT, null, null, scaleToFit ? ScalingMode.ScaleToFitSmallestExtent : ScalingMode.None, style)
{
}
public GUIImage(RectTransform rectT, string style, ScalingMode scaleToFit = ScalingMode.None)
: this(rectT, null, null, scaleToFit, style)
{
}
public GUIImage(RectTransform rectT, Sprite sprite, Rectangle? sourceRect = null, bool scaleToFit = false)
public GUIImage(RectTransform rectT, Sprite sprite, bool scaleToFit, Rectangle? sourceRect = null)
: this(rectT, sprite, sourceRect, scaleToFit ? ScalingMode.ScaleToFitSmallestExtent : ScalingMode.None, null)
{
}
public GUIImage(RectTransform rectT, Sprite sprite, Rectangle? sourceRect = null, ScalingMode scaleToFit = ScalingMode.None)
: this(rectT, sprite, sourceRect, scaleToFit, null)
{
}
private GUIImage(RectTransform rectT, Sprite sprite, Rectangle? sourceRect, bool scaleToFit, string style) : base(style, rectT)
private GUIImage(RectTransform rectT, Sprite sprite, Rectangle? sourceRect, ScalingMode scaleToFit, string style) : base(style, rectT)
{
this.scaleToFit = scaleToFit;
Sprite = sprite;
@@ -123,7 +150,7 @@ namespace Barotrauma
{
color = hoverColor = selectedColor = pressedColor = disabledColor = Color.White;
}
if (!scaleToFit)
if (scaleToFit == ScalingMode.None)
{
Scale = 1.0f;
}
@@ -176,9 +203,11 @@ namespace Barotrauma
Color currentColor = GetColor(State);
if (BlendState != null)
Rectangle prevScissorRect = spriteBatch.GraphicsDevice.ScissorRectangle;
if (BlendState != null || scaleToFit == ScalingMode.ScaleToFitLargestExtent)
{
spriteBatch.End();
spriteBatch.GraphicsDevice.ScissorRectangle = Rectangle.Intersect(prevScissorRect, Rect);
spriteBatch.Begin(blendState: BlendState, samplerState: GUI.SamplerState, rasterizerState: GameMain.ScissorTestEnable);
}
@@ -205,9 +234,10 @@ namespace Barotrauma
Scale, SpriteEffects, 0.0f);
}
if (BlendState != null)
if (BlendState != null || scaleToFit == ScalingMode.ScaleToFitLargestExtent)
{
spriteBatch.End();
spriteBatch.GraphicsDevice.ScissorRectangle = prevScissorRect;
spriteBatch.Begin(SpriteSortMode.Deferred, samplerState: GUI.SamplerState, rasterizerState: GameMain.ScissorTestEnable);
}
}
@@ -219,9 +249,18 @@ namespace Barotrauma
sourceRect = sprite.SourceRect;
}
Scale = sprite == null || sprite.SourceRect.Width == 0 || sprite.SourceRect.Height == 0 ?
1.0f :
Math.Min(RectTransform.Rect.Width / (float)sprite.SourceRect.Width, RectTransform.Rect.Height / (float)sprite.SourceRect.Height);
if (sprite == null || sprite.SourceRect.Width == 0 || sprite.SourceRect.Height == 0)
{
Scale = 1.0f;
}
else if (scaleToFit == ScalingMode.ScaleToFitLargestExtent)
{
Scale = Math.Max(RectTransform.Rect.Width / (float)sprite.SourceRect.Width, RectTransform.Rect.Height / (float)sprite.SourceRect.Height);
}
else
{
Scale = Math.Min(RectTransform.Rect.Width / (float)sprite.SourceRect.Width, RectTransform.Rect.Height / (float)sprite.SourceRect.Height);
}
}
private async Task<bool> LoadTextureAsync()
@@ -749,8 +749,8 @@ namespace Barotrauma
/// </summary>
private bool ActiveServiceFull()
{
return (PendingHires.Count(ci => ci.BotStatus == BotStatus.PendingHireToActiveService) + campaign.CrewManager.GetCharacterInfos().Count())
>= CrewManager.MaxCrewSize;
int pendingHireCount = PendingHires?.Count(ci => ci.BotStatus == BotStatus.PendingHireToActiveService) ?? 0;
return pendingHireCount + campaign.CrewManager.GetCharacterInfos().Count() >= CrewManager.MaxCrewSize;
}
private bool EnoughReputationToHire(CharacterInfo characterInfo)
@@ -25,8 +25,6 @@ namespace Barotrauma
private Video currSplashScreen;
private DateTime videoStartTime;
private bool mirrorBackground;
public struct PendingSplashScreen
{
public string Filename;
@@ -108,8 +106,7 @@ namespace Barotrauma
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, samplerState: GUI.SamplerState);
GUI.DrawBackgroundSprite(spriteBatch, currentBackgroundTexture, Color.White, drawArea,
spriteEffects: mirrorBackground ? SpriteEffects.FlipHorizontally : SpriteEffects.None);
GUI.DrawBackgroundSprite(spriteBatch, currentBackgroundTexture, Color.White, drawArea);
overlay.Draw(spriteBatch, Vector2.Zero, scale: overlayScale);
double noiseT = Timing.TotalTime * 0.02f;
@@ -386,7 +383,6 @@ namespace Barotrauma
{
currentBackgroundTexture = missions.Where(m => m.Prefab.HasPortraits).First().Prefab.GetPortrait(Rand.Int(int.MaxValue));
}
mirrorBackground = Rand.Range(0.0f, 1.0f) < 0.5f;
while (!drawn)
{
@@ -255,7 +255,7 @@ namespace Barotrauma
pageIndicators = new GUIImage[pageCount];
for (int i = 0; i < pageCount; i++)
{
pageIndicators[i] = new GUIImage(new RectTransform(indicatorSize, pageIndicatorHolder.RectTransform) { AbsoluteOffset = new Point(xPos, yPos) }, pageIndicator, null, true);
pageIndicators[i] = new GUIImage(new RectTransform(indicatorSize, pageIndicatorHolder.RectTransform) { AbsoluteOffset = new Point(xPos, yPos) }, pageIndicator, scaleToFit: true);
xPos += indicatorSize.X + HUDLayoutSettings.Padding;
}
@@ -799,8 +799,6 @@ namespace Barotrauma
customizeTabOpen = !hasUpgradeModules && hasSwappableItems;
customizeTabOpen = false;
GUIComponent[] categoryFrames = GetFrames(category);
foreach (GUIComponent itemFrame in itemPreviews.Values)
{