Merge branch 'master' into dev

# Conflicts:
#	Barotrauma/BarotraumaClient/ClientSource/Characters/Character.cs
#	Barotrauma/BarotraumaClient/ClientSource/DebugConsole.cs
#	Barotrauma/BarotraumaClient/ClientSource/GUI/Store.cs
#	Barotrauma/BarotraumaClient/ClientSource/Items/Inventory.cs
#	Barotrauma/BarotraumaClient/ClientSource/Items/Item.cs
#	Barotrauma/BarotraumaClient/ClientSource/Map/Map/Radiation.cs
#	Barotrauma/BarotraumaClient/ClientSource/Map/MapEntity.cs
#	Barotrauma/BarotraumaClient/ClientSource/Networking/ServerList/ServerInfo.cs
#	Barotrauma/BarotraumaClient/ClientSource/Screens/MainMenuScreen/MainMenuScreen.cs
#	Barotrauma/BarotraumaClient/ClientSource/Screens/ServerListScreen/ServerListScreen.cs
#	Barotrauma/BarotraumaClient/ClientSource/Screens/SubEditorScreen.cs
#	Barotrauma/BarotraumaClient/ClientSource/Serialization/SerializableEntityEditor.cs
#	Barotrauma/BarotraumaClient/ClientSource/Settings/SettingsMenu.cs
#	Barotrauma/BarotraumaClient/ClientSource/SpamServerFilter.cs
#	Barotrauma/BarotraumaClient/ClientSource/Sprite/Sprite.cs
#	Barotrauma/BarotraumaClient/ClientSource/Steam/Lobby.cs
#	Barotrauma/BarotraumaClient/LinuxClient.csproj
#	Barotrauma/BarotraumaClient/MacClient.csproj
#	Barotrauma/BarotraumaClient/WindowsClient.csproj
#	Barotrauma/BarotraumaServer/LinuxServer.csproj
#	Barotrauma/BarotraumaServer/MacServer.csproj
#	Barotrauma/BarotraumaServer/ServerSource/GameMain.cs
#	Barotrauma/BarotraumaServer/ServerSource/Steam/SteamManager.cs
#	Barotrauma/BarotraumaServer/ServerSource/Traitors/TraitorManager.cs
#	Barotrauma/BarotraumaServer/WindowsServer.csproj
#	Barotrauma/BarotraumaShared/SharedSource/Characters/Animation/HumanoidAnimController.cs
#	Barotrauma/BarotraumaShared/SharedSource/Characters/Animation/Ragdoll.cs
#	Barotrauma/BarotraumaShared/SharedSource/DebugConsole.cs
#	Barotrauma/BarotraumaShared/SharedSource/Extensions/IEnumerableExtensions.cs
#	Barotrauma/BarotraumaShared/SharedSource/GameSession/GameModes/CampaignMode.cs
#	Barotrauma/BarotraumaShared/SharedSource/Items/ItemPrefab.cs
#	Barotrauma/BarotraumaShared/SharedSource/Map/Map/Location.cs
#	Barotrauma/BarotraumaShared/SharedSource/Serialization/Editable/ConditionallyEditable.cs
#	Barotrauma/BarotraumaShared/SharedSource/Settings/GameSettings.cs
#	Barotrauma/BarotraumaShared/changelog.txt
#	Libraries/BarotraumaLibs/BarotraumaCore/Utils/MathUtils.cs
This commit is contained in:
Regalis11
2024-04-24 17:38:13 +03:00
312 changed files with 14040 additions and 3327 deletions
@@ -218,6 +218,7 @@ namespace Barotrauma
{
if (primaryMouseButtonHeld)
{
ShowHulls = true;
hull.WaterVolume += 100000.0f * deltaTime;
hull.networkUpdatePending = true;
hull.serverUpdateDelay = 0.5f;
@@ -99,6 +99,10 @@ namespace Barotrauma
}
}
//restore the previous selection
MapEntity.SelectedList.Clear();
entities.ForEach(e => MapEntity.AddSelection(e));
return element;
}
}
@@ -279,6 +279,9 @@ namespace Barotrauma.Lights
light.Position = pos;
}
//above the top boundary of the level (in an inactive respawn shuttle?)
if (Level.Loaded != null && light.WorldPosition.Y > Level.Loaded.Size.Y) { continue; }
float range = light.LightSourceParams.TextureRange;
if (light.LightSprite != null)
{
@@ -379,7 +382,7 @@ namespace Barotrauma.Lights
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, transformMatrix: spriteBatchTransform);
Vector3 glowColorHSV = ToolBox.RGBToHSV(AmbientLight);
glowColorHSV.Z = Math.Max(glowColorHSV.Z, 0.4f);
Color glowColor = ToolBox.HSVToRGB(glowColorHSV.X, glowColorHSV.Y, glowColorHSV.Z);
Color glowColor = ToolBoxCore.HSVToRGB(glowColorHSV.X, glowColorHSV.Y, glowColorHSV.Z);
Vector2 glowSpriteSize = new Vector2(gapGlowTexture.Width, gapGlowTexture.Height);
foreach (var gap in Gap.GapList)
{
@@ -184,7 +184,8 @@ namespace Barotrauma
connection.CrackSegments.Clear();
connection.CrackSegments.AddRange(MathUtils.GenerateJaggedLine(
connectionStart, connectionEnd,
iterations, connectionLength * generationParams.ConnectionIndicatorDisplacementMultiplier));
iterations, connectionLength * generationParams.ConnectionIndicatorDisplacementMultiplier,
rng: Rand.GetRNG(Rand.RandSync.ServerAndClient)));
}
private void LocationChanged(Location prevLocation, Location newLocation)
@@ -9,8 +9,8 @@ namespace Barotrauma
{
private static readonly LocalizedString radiationTooltip = TextManager.Get("RadiationTooltip");
private static float spriteIndex;
private readonly SpriteSheet sheet = GUIStyle.RadiationAnimSpriteSheet;
private int maxFrames => sheet.FrameCount + 1;
private readonly SpriteSheet? sheet = GUIStyle.RadiationAnimSpriteSheet;
private int maxFrames => (sheet?.FrameCount ?? 0) + 1;
private bool isHovingOver;
@@ -18,7 +18,7 @@ namespace Barotrauma
{
if (!Enabled) { return; }
UISprite uiSprite = GUIStyle.Radiation;
UISprite? uiSprite = GUIStyle.Radiation;
var (offsetX, offsetY) = Map.DrawOffset * zoom;
var (centerX, centerY) = container.Center.ToVector2();
var (halfSizeX, halfSizeY) = new Vector2(container.Width / 2f, container.Height / 2f) * zoom;
@@ -29,18 +29,21 @@ namespace Barotrauma
Vector2 spriteScale = new Vector2(zoom);
uiSprite.Sprite.DrawTiled(spriteBatch, topLeft, size, color: Params.RadiationAreaColor, startOffset: Vector2.Zero, textureScale: spriteScale);
uiSprite?.Sprite.DrawTiled(spriteBatch, topLeft, size, color: Params.RadiationAreaColor, startOffset: Vector2.Zero, textureScale: spriteScale);
Vector2 topRight = topLeft + Vector2.UnitX * size.X;
int index = 0;
for (float i = 0; i <= size.Y; i += sheet.FrameSize.Y / 2f * zoom)
if (sheet != null)
{
bool isEven = ++index % 2 == 0;
Vector2 origin = new Vector2(0.5f, 0) * sheet.FrameSize.X;
// every other sprite's animation is reversed to make it seem more chaotic
int sprite = (int) MathF.Floor(isEven ? spriteIndex : maxFrames - spriteIndex);
sheet.Draw(spriteBatch, sprite, topRight + new Vector2(0, i), Params.RadiationBorderTint, origin, 0f, spriteScale);
for (float i = 0; i <= size.Y; i += sheet.FrameSize.Y / 2f * zoom)
{
bool isEven = ++index % 2 == 0;
Vector2 origin = new Vector2(0.5f, 0) * sheet.FrameSize.X;
// every other sprite's animation is reversed to make it seem more chaotic
int sprite = (int) MathF.Floor(isEven ? spriteIndex : maxFrames - spriteIndex);
sheet.Draw(spriteBatch, sprite, topRight + new Vector2(0, i), Params.RadiationBorderTint, origin, 0f, spriteScale);
}
}
isHovingOver = container.Contains(PlayerInput.MousePosition) && PlayerInput.MousePosition.X < topLeft.X + size.X;
@@ -888,12 +888,12 @@ namespace Barotrauma
var hsvBase = hsv;
hsvBase.Y *= 4f;
hsvBase.Z *= 0.8f;
btn.Color = ToolBox.HSVToRGB(hsvBase.X, hsvBase.Y, hsvBase.Z);
btn.SelectedColor = ToolBox.HSVToRGB(hsvBase.X, hsvBase.Y, hsvBase.Z);
btn.Color = ToolBoxCore.HSVToRGB(hsvBase.X, hsvBase.Y, hsvBase.Z);
btn.SelectedColor = ToolBoxCore.HSVToRGB(hsvBase.X, hsvBase.Y, hsvBase.Z);
var hsvHover = hsv;
hsvHover.Z *= 1.2f;
btn.HoverColor = ToolBox.HSVToRGB(hsvHover.X, hsvHover.Y, hsvHover.Z);
btn.HoverColor = ToolBoxCore.HSVToRGB(hsvHover.X, hsvHover.Y, hsvHover.Z);
}
public static List<MapEntity> FilteredSelectedList { get; private set; } = new List<MapEntity>();
@@ -51,6 +51,72 @@ namespace Barotrauma
UpdateSpriteStates(0.0f);
}
public static Vector2 UpgradeTextureOffset(
Vector2 targetSize,
Vector2 originalTextureOffset,
SubmarineInfo submarineInfo,
Rectangle sourceRect,
Vector2 scale,
bool flippedX,
bool flippedY)
{
if (submarineInfo.GameVersion <= Sprite.LastBrokenTiledSpriteGameVersion)
{
// Tiled sprite rendering was significantly changed after v1.2.3.0:
// Rendering flipped, scaled and offset textures was completely broken,
// but some existing community submarines depend on that old behavior,
// so let's redo some of the broken logic here if the sub is old enough
Vector2 flipper = (flippedX ? -1f : 1f, flippedY ? -1f : 1f);
var textureOffset = originalTextureOffset * flipper;
textureOffset = new Vector2(
MathUtils.PositiveModulo((int)-textureOffset.X, sourceRect.Width),
MathUtils.PositiveModulo((int)-textureOffset.Y, sourceRect.Height));
textureOffset.X = (textureOffset.X / scale.X) % sourceRect.Width;
textureOffset.Y = (textureOffset.Y / scale.Y) % sourceRect.Height;
Vector2 flippedDrawOffset = Vector2.Zero;
if (flippedX)
{
float diff = targetSize.X % (sourceRect.Width * scale.X);
flippedDrawOffset.X = (sourceRect.Width * scale.X - diff) / scale.X;
flippedDrawOffset.X =
MathUtils.NearlyEqual(flippedDrawOffset.X, MathF.Round(flippedDrawOffset.X)) ?
MathF.Round(flippedDrawOffset.X) : flippedDrawOffset.X;
}
if (flippedY)
{
float diff = targetSize.Y % (sourceRect.Height * scale.Y);
flippedDrawOffset.Y = (sourceRect.Height * scale.Y - diff) / scale.Y;
flippedDrawOffset.Y =
MathUtils.NearlyEqual(flippedDrawOffset.Y, MathF.Round(flippedDrawOffset.Y)) ?
MathF.Round(flippedDrawOffset.Y) : flippedDrawOffset.Y;
}
var textureOffsetPlusFlipBs = textureOffset + flippedDrawOffset;
if (textureOffsetPlusFlipBs.X > sourceRect.Width)
{
var diff = textureOffsetPlusFlipBs.X - sourceRect.Width;
textureOffset.X = (textureOffset.X + diff * (scale.X - 1f)) % sourceRect.Width;
}
if (textureOffsetPlusFlipBs.Y > sourceRect.Height)
{
var diff = textureOffsetPlusFlipBs.Y - sourceRect.Height;
textureOffset.Y = (textureOffset.Y + diff * (scale.Y - 1f)) % sourceRect.Height;
}
textureOffset *= scale * flipper;
return -textureOffset;
}
return originalTextureOffset;
}
partial void CreateConvexHull(Vector2 position, Vector2 size, float rotation)
{
if (!CastShadow) { return; }
@@ -112,8 +178,8 @@ namespace Barotrauma
foreach (LightSource light in Lights)
{
Vector2 bgOffset = new Vector2(
MathUtils.PositiveModulo((int)-textOffset.X, light.texture.Width),
MathUtils.PositiveModulo((int)-textOffset.Y, light.texture.Height));
MathUtils.PositiveModulo(-textOffset.X, light.texture.Width),
MathUtils.PositiveModulo(-textOffset.Y, light.texture.Height));
light.LightTextureOffset = bgOffset;
}
@@ -128,6 +194,16 @@ namespace Barotrauma
CanTakeKeyBoardFocus = false
};
var editor = new SerializableEntityEditor(listBox.Content.RectTransform, this, inGame, showName: true, titleFont: GUIStyle.LargeFont) { UserData = this };
if (editor.Fields.TryGetValue(nameof(Scale).ToIdentifier(), out GUIComponent[] scaleFields) &&
scaleFields.FirstOrDefault() is GUINumberInput scaleInput)
{
//texture offset needs to be adjusted when scaling the entity to keep the look of the entity unchanged
scaleInput.OnValueChanged += (GUINumberInput numberInput) =>
{
TextureOffset *= (Scale / ScaleWhenTextureOffsetSet);
};
}
if (Submarine.MainSub?.Info?.Type == SubmarineType.OutpostModule)
{
@@ -334,8 +410,6 @@ namespace Barotrauma
float depth = GetDrawDepth();
Vector2 textureOffset = this.textureOffset;
if (FlippedX) { textureOffset.X = -textureOffset.X; }
if (FlippedY) { textureOffset.Y = -textureOffset.Y; }
if (back && damageEffect == null && !isWiringMode)
{
@@ -365,8 +439,8 @@ namespace Barotrauma
Prefab.BackgroundSprite.effects ^= SpriteEffects;
Vector2 backGroundOffset = new Vector2(
MathUtils.PositiveModulo((int)-textureOffset.X, Prefab.BackgroundSprite.SourceRect.Width),
MathUtils.PositiveModulo((int)-textureOffset.Y, Prefab.BackgroundSprite.SourceRect.Height));
MathUtils.PositiveModulo(-textureOffset.X, Prefab.BackgroundSprite.SourceRect.Width * TextureScale.X * Scale),
MathUtils.PositiveModulo(-textureOffset.Y, Prefab.BackgroundSprite.SourceRect.Height * TextureScale.Y * Scale));
Prefab.BackgroundSprite.DrawTiled(
spriteBatch,
@@ -442,11 +516,17 @@ namespace Barotrauma
Math.Abs(rect.Location.X - drawSection.Location.X),
Math.Abs(rect.Location.Y - drawSection.Location.Y));
if (FlippedX && IsHorizontal) { sectionOffset.X = drawSection.Right - rect.Right; }
if (FlippedY && !IsHorizontal) { sectionOffset.Y = (rect.Y - rect.Height) - (drawSection.Y - drawSection.Height); }
if (FlippedX && IsHorizontal) { sectionOffset.X = rect.Right - drawSection.Right; }
if (FlippedY && !IsHorizontal) { sectionOffset.Y = (drawSection.Y - drawSection.Height) - (rect.Y - rect.Height); }
sectionOffset.X += MathUtils.PositiveModulo((int)-textureOffset.X, Prefab.Sprite.SourceRect.Width);
sectionOffset.Y += MathUtils.PositiveModulo((int)-textureOffset.Y, Prefab.Sprite.SourceRect.Height);
sectionOffset.X += MathUtils.PositiveModulo(-textureOffset.X, Prefab.Sprite.SourceRect.Width * TextureScale.X * Scale);
sectionOffset.Y += MathUtils.PositiveModulo(-textureOffset.Y, Prefab.Sprite.SourceRect.Height * TextureScale.Y * Scale);
Vector2 pos = new Vector2(drawSection.X, drawSection.Y);
pos -= rect.Location.ToVector2();
pos = advanceX * pos.X + advanceY * pos.Y;
pos += rect.Location.ToVector2();
pos = new Vector2(pos.X + rect.Width / 2 + drawOffset.X, -(pos.Y - rect.Height / 2 + drawOffset.Y));
Vector2 pos = new Vector2(drawSection.X, drawSection.Y);
pos -= rect.Location.ToVector2();
@@ -499,6 +499,13 @@ namespace Barotrauma
}
}
if (Hull.HullList.Any(h => h.WaterVolume > 0.0f))
{
errorMsgs.Add(TextManager.Get("WaterInHullsWarning").Value);
warnings.Add(SubEditorScreen.WarningType.WaterInHulls);
Hull.ShowHulls = true;
}
if (Info.Type == SubmarineType.Player)
{
foreach (Item item in Item.ItemList)
@@ -477,12 +477,19 @@ namespace Barotrauma
Vector2 backGroundOffset = Vector2.Zero;
Vector2 textureOffset = element.GetAttributeVector2("textureoffset", Vector2.Zero);
if (flippedX) { textureOffset.X = -textureOffset.X; }
if (flippedY) { textureOffset.Y = -textureOffset.Y; }
textureOffset = Structure.UpgradeTextureOffset(
targetSize: rect.Size.ToVector2(),
originalTextureOffset: textureOffset,
submarineInfo: submarineInfo,
sourceRect: prefab.Sprite.SourceRect,
scale: textureScale * scale,
flippedX: flippedX,
flippedY: flippedY);
backGroundOffset = new Vector2(
MathUtils.PositiveModulo((int)-textureOffset.X, prefab.Sprite.SourceRect.Width),
MathUtils.PositiveModulo((int)-textureOffset.Y, prefab.Sprite.SourceRect.Height));
MathUtils.PositiveModulo(-textureOffset.X, prefab.Sprite.SourceRect.Width * textureScale.X * scale),
MathUtils.PositiveModulo(-textureOffset.Y, prefab.Sprite.SourceRect.Height * textureScale.Y * scale));
prefab.Sprite.DrawTiled(
spriteBatch: spriteRecorder,