Merge branch 'master' of https://github.com/Regalis11/Barotrauma into develop

This commit is contained in:
EvilFactory
2024-01-11 11:42:33 -03:00
20 changed files with 263 additions and 137 deletions
+1 -1
View File
@@ -73,7 +73,7 @@ body:
label: Version label: Version
description: Which version of the game did the bug happen in? You can see the current version number in the bottom left corner of your screen in the main menu. description: Which version of the game did the bug happen in? You can see the current version number in the bottom left corner of your screen in the main menu.
options: options:
- v1.2.7.0 (Winter Update hotfix) - v1.2.8.0 (Winter Update hotfix 2)
- Other - Other
validations: validations:
required: true required: true
@@ -1421,10 +1421,27 @@ namespace Barotrauma.Items.Components
{ {
Sprite sprite = structure.Sprite; Sprite sprite = structure.Sprite;
if (sprite is null) { return; } if (sprite is null) { return; }
Vector2 textureOffset = structure.TextureOffset;
textureOffset = new Vector2(
MathUtils.PositiveModulo(-textureOffset.X, sprite.SourceRect.Width * structure.TextureScale.X * structure.Scale),
MathUtils.PositiveModulo(-textureOffset.Y, sprite.SourceRect.Height * structure.TextureScale.Y * structure.Scale));
RectangleF entityRect = ScaleRectToUI(structure, parent, border); RectangleF entityRect = ScaleRectToUI(structure, parent, border);
Vector2 spriteScale = new Vector2(entityRect.Size.X / sprite.size.X, entityRect.Size.Y / sprite.size.Y); Vector2 spriteScale = new Vector2(entityRect.Size.X / structure.Rect.Width, entityRect.Size.Y / structure.Rect.Height);
sprite.Draw(spriteBatch, new Vector2(entityRect.Location.X + inflate, entityRect.Location.Y + inflate), structure.SpriteColor, Vector2.Zero, 0f, spriteScale, sprite.effects ^ structure.SpriteEffects); float rotation = MathHelper.ToRadians(structure.Rotation);
sprite.DrawTiled(
spriteBatch: spriteBatch,
position: entityRect.Location + entityRect.Size * 0.5f + (inflate, inflate),
targetSize: entityRect.Size,
rotation: rotation,
origin: entityRect.Size * 0.5f,
color: structure.SpriteColor,
startOffset: textureOffset * spriteScale,
textureScale: structure.TextureScale * structure.Scale * spriteScale,
depth: structure.SpriteDepth,
spriteEffects: sprite.effects ^ structure.SpriteEffects);
} }
private static RectangleF ScaleRectToUI(MapEntity entity, RectangleF parentRect, RectangleF worldBorders) private static RectangleF ScaleRectToUI(MapEntity entity, RectangleF parentRect, RectangleF worldBorders)
@@ -86,7 +86,7 @@ namespace Barotrauma
MathUtils.RoundTowardsClosest(center.Y, Submarine.GridSize.Y) - center.Y - Submarine.GridSize.Y / 2); MathUtils.RoundTowardsClosest(center.Y, Submarine.GridSize.Y) - center.Y - Submarine.GridSize.Y / 2);
MapEntity.SelectedList.Clear(); MapEntity.SelectedList.Clear();
entities.ForEach(e => MapEntity.AddSelection(e)); assemblyEntities.ForEach(e => MapEntity.AddSelection(e));
foreach (MapEntity mapEntity in assemblyEntities) foreach (MapEntity mapEntity in assemblyEntities)
{ {
@@ -99,6 +99,10 @@ namespace Barotrauma
} }
} }
//restore the previous selection
MapEntity.SelectedList.Clear();
entities.ForEach(e => MapEntity.AddSelection(e));
return element; return element;
} }
} }
@@ -51,6 +51,72 @@ namespace Barotrauma
UpdateSpriteStates(0.0f); 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) partial void CreateConvexHull(Vector2 position, Vector2 size, float rotation)
{ {
if (!CastShadow) { return; } if (!CastShadow) { return; }
@@ -112,8 +178,8 @@ namespace Barotrauma
foreach (LightSource light in Lights) foreach (LightSource light in Lights)
{ {
Vector2 bgOffset = new Vector2( Vector2 bgOffset = new Vector2(
MathUtils.PositiveModulo((int)-textOffset.X, light.texture.Width), MathUtils.PositiveModulo(-textOffset.X, light.texture.Width),
MathUtils.PositiveModulo((int)-textOffset.Y, light.texture.Height)); MathUtils.PositiveModulo(-textOffset.Y, light.texture.Height));
light.LightTextureOffset = bgOffset; light.LightTextureOffset = bgOffset;
} }
@@ -128,6 +194,16 @@ namespace Barotrauma
CanTakeKeyBoardFocus = false CanTakeKeyBoardFocus = false
}; };
var editor = new SerializableEntityEditor(listBox.Content.RectTransform, this, inGame, showName: true, titleFont: GUIStyle.LargeFont) { UserData = this }; 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) if (Submarine.MainSub?.Info?.Type == SubmarineType.OutpostModule)
{ {
@@ -334,8 +410,6 @@ namespace Barotrauma
float depth = GetDrawDepth(); float depth = GetDrawDepth();
Vector2 textureOffset = this.textureOffset; Vector2 textureOffset = this.textureOffset;
if (FlippedX) { textureOffset.X = -textureOffset.X; }
if (FlippedY) { textureOffset.Y = -textureOffset.Y; }
if (back && damageEffect == null && !isWiringMode) if (back && damageEffect == null && !isWiringMode)
{ {
@@ -365,8 +439,8 @@ namespace Barotrauma
Prefab.BackgroundSprite.effects ^= SpriteEffects; Prefab.BackgroundSprite.effects ^= SpriteEffects;
Vector2 backGroundOffset = new Vector2( Vector2 backGroundOffset = new Vector2(
MathUtils.PositiveModulo((int)-textureOffset.X, Prefab.BackgroundSprite.SourceRect.Width), MathUtils.PositiveModulo(-textureOffset.X, Prefab.BackgroundSprite.SourceRect.Width * TextureScale.X * Scale),
MathUtils.PositiveModulo((int)-textureOffset.Y, Prefab.BackgroundSprite.SourceRect.Height)); MathUtils.PositiveModulo(-textureOffset.Y, Prefab.BackgroundSprite.SourceRect.Height * TextureScale.Y * Scale));
Prefab.BackgroundSprite.DrawTiled( Prefab.BackgroundSprite.DrawTiled(
spriteBatch, spriteBatch,
@@ -442,11 +516,11 @@ namespace Barotrauma
Math.Abs(rect.Location.X - drawSection.Location.X), Math.Abs(rect.Location.X - drawSection.Location.X),
Math.Abs(rect.Location.Y - drawSection.Location.Y)); Math.Abs(rect.Location.Y - drawSection.Location.Y));
if (FlippedX && IsHorizontal) { sectionOffset.X = drawSection.Right - rect.Right; } if (FlippedX && IsHorizontal) { sectionOffset.X = rect.Right - drawSection.Right; }
if (FlippedY && !IsHorizontal) { sectionOffset.Y = (rect.Y - rect.Height) - (drawSection.Y - drawSection.Height); } 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.X += MathUtils.PositiveModulo(-textureOffset.X, Prefab.Sprite.SourceRect.Width * TextureScale.X * Scale);
sectionOffset.Y += MathUtils.PositiveModulo((int)-textureOffset.Y, Prefab.Sprite.SourceRect.Height); sectionOffset.Y += MathUtils.PositiveModulo(-textureOffset.Y, Prefab.Sprite.SourceRect.Height * TextureScale.Y * Scale);
Vector2 pos = new Vector2(drawSection.X, drawSection.Y); Vector2 pos = new Vector2(drawSection.X, drawSection.Y);
pos -= rect.Location.ToVector2(); pos -= rect.Location.ToVector2();
@@ -477,12 +477,19 @@ namespace Barotrauma
Vector2 backGroundOffset = Vector2.Zero; Vector2 backGroundOffset = Vector2.Zero;
Vector2 textureOffset = element.GetAttributeVector2("textureoffset", 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( backGroundOffset = new Vector2(
MathUtils.PositiveModulo((int)-textureOffset.X, prefab.Sprite.SourceRect.Width), MathUtils.PositiveModulo(-textureOffset.X, prefab.Sprite.SourceRect.Width * textureScale.X * scale),
MathUtils.PositiveModulo((int)-textureOffset.Y, prefab.Sprite.SourceRect.Height)); MathUtils.PositiveModulo(-textureOffset.Y, prefab.Sprite.SourceRect.Height * textureScale.Y * scale));
prefab.Sprite.DrawTiled( prefab.Sprite.DrawTiled(
spriteBatch: spriteRecorder, spriteBatch: spriteRecorder,
@@ -583,12 +583,23 @@ namespace Barotrauma
} }
}; };
HandleSetterValueTampering(numberInput, () => property.GetFloatValue(entity));
refresh += () =>
{
if (!numberInput.TextBox.Selected) { numberInput.FloatValue = (float)property.GetValue(entity); }
};
if (!Fields.ContainsKey(property.Name)) { Fields.Add(property.Name.ToIdentifier(), new GUIComponent[] { numberInput }); }
return frame;
}
private static void HandleSetterValueTampering(GUINumberInput numberInput, Func<float> getter)
{
// Lots of UI boilerplate to handle all(?) cases where the property's setter may be called // Lots of UI boilerplate to handle all(?) cases where the property's setter may be called
// and modify the input value (e.g. rotation value wrapping) // and modify the input value (e.g. rotation value wrapping)
void HandleSetterModifyingInput(GUINumberInput numInput) void HandleSetterModifyingInput(GUINumberInput numInput)
{ {
var inputFloatValue = numInput.FloatValue; var inputFloatValue = numInput.FloatValue;
var resultingFloatValue = property.GetFloatValue(entity); var resultingFloatValue = getter();
if (!MathUtils.NearlyEqual(resultingFloatValue, inputFloatValue)) if (!MathUtils.NearlyEqual(resultingFloatValue, inputFloatValue))
{ {
numInput.FloatValue = resultingFloatValue; numInput.FloatValue = resultingFloatValue;
@@ -602,12 +613,6 @@ namespace Barotrauma
numberInput.PlusButton.OnClicked += HandleSetterModifyingInputOnButtonClicked; numberInput.PlusButton.OnClicked += HandleSetterModifyingInputOnButtonClicked;
numberInput.MinusButton.OnPressed += HandleSetterModifyingInputOnButtonPressed; numberInput.MinusButton.OnPressed += HandleSetterModifyingInputOnButtonPressed;
numberInput.MinusButton.OnClicked += HandleSetterModifyingInputOnButtonClicked; numberInput.MinusButton.OnClicked += HandleSetterModifyingInputOnButtonClicked;
refresh += () =>
{
if (!numberInput.TextBox.Selected) { numberInput.FloatValue = (float)property.GetValue(entity); }
};
if (!Fields.ContainsKey(property.Name)) { Fields.Add(property.Name.ToIdentifier(), new GUIComponent[] { numberInput }); }
return frame;
} }
public GUIComponent CreateEnumField(ISerializableEntity entity, SerializableProperty property, object value, LocalizedString displayName, LocalizedString toolTip) public GUIComponent CreateEnumField(ISerializableEntity entity, SerializableProperty property, object value, LocalizedString displayName, LocalizedString toolTip)
@@ -881,26 +886,33 @@ namespace Barotrauma
numberInput.MaxValueFloat = editableAttribute.MaxValueFloat; numberInput.MaxValueFloat = editableAttribute.MaxValueFloat;
numberInput.DecimalsToDisplay = editableAttribute.DecimalCount; numberInput.DecimalsToDisplay = editableAttribute.DecimalCount;
numberInput.ValueStep = editableAttribute.ValueStep; numberInput.ValueStep = editableAttribute.ValueStep;
numberInput.ForceShowPlusMinusButtons = editableAttribute.ForceShowPlusMinusButtons;
if (i == 0) numberInput.FloatValue = i == 0 ? value.X : value.Y;
numberInput.FloatValue = value.X;
else
numberInput.FloatValue = value.Y;
int comp = i; int comp = i;
numberInput.OnValueChanged += (numInput) => numberInput.OnValueChanged += (numInput) =>
{ {
Vector2 newVal = (Vector2)property.GetValue(entity); Vector2 newVal = (Vector2)property.GetValue(entity);
if (comp == 0) if (comp == 0)
{
newVal.X = numInput.FloatValue; newVal.X = numInput.FloatValue;
}
else else
{
newVal.Y = numInput.FloatValue; newVal.Y = numInput.FloatValue;
}
if (SetPropertyValue(property, entity, newVal)) if (SetPropertyValue(property, entity, newVal))
{ {
TrySendNetworkUpdate(entity, property); TrySendNetworkUpdate(entity, property);
} }
}; };
HandleSetterValueTampering(numberInput, () =>
{
Vector2 currVal = (Vector2)property.GetValue(entity);
return comp == 0 ? currVal.X : currVal.Y;
});
fields[i] = numberInput; fields[i] = numberInput;
} }
refresh += () => refresh += () =>
@@ -284,6 +284,11 @@ namespace Barotrauma
} }
} }
/// <summary>
/// Last version of the game that had broken handling of sprites that were scaled, flipped and offset
/// </summary>
public static readonly Version LastBrokenTiledSpriteGameVersion = new Version(major: 1, minor: 2, build: 7, revision: 0);
public void DrawTiled(ISpriteBatch spriteBatch, public void DrawTiled(ISpriteBatch spriteBatch,
Vector2 position, Vector2 position,
Vector2 targetSize, Vector2 targetSize,
@@ -298,8 +303,9 @@ namespace Barotrauma
if (Texture == null) { return; } if (Texture == null) { return; }
spriteEffects ??= effects; spriteEffects ??= effects;
bool flipHorizontal = (spriteEffects.Value & SpriteEffects.FlipHorizontally) != 0;
bool flipVertical = (spriteEffects.Value & SpriteEffects.FlipVertically) != 0; bool flipHorizontal = spriteEffects.Value.HasFlag(SpriteEffects.FlipHorizontally);
bool flipVertical = spriteEffects.Value.HasFlag(SpriteEffects.FlipVertically);
float addedRotation = rotation + this.rotation; float addedRotation = rotation + this.rotation;
if (flipHorizontal != flipVertical) { addedRotation = -addedRotation; } if (flipHorizontal != flipVertical) { addedRotation = -addedRotation; }
@@ -317,42 +323,42 @@ namespace Barotrauma
void drawSection(Vector2 slicePos, Rectangle sliceRect) void drawSection(Vector2 slicePos, Rectangle sliceRect)
{ {
Vector2 transformedPos = slicePos - position; Vector2 transformedPos = slicePos;
if (flipHorizontal)
{
transformedPos.X = targetSize.X - transformedPos.X - sliceRect.Width * scale.X;
}
if (flipVertical)
{
transformedPos.Y = targetSize.Y - transformedPos.Y - sliceRect.Height * scale.Y;
}
transformedPos = advanceX * transformedPos.X + advanceY * transformedPos.Y; transformedPos = advanceX * transformedPos.X + advanceY * transformedPos.Y;
transformedPos += position - transformedOrigin; transformedPos += position - transformedOrigin;
spriteBatch.Draw(texture, transformedPos, sliceRect, drawColor, addedRotation, Vector2.Zero, scale, spriteEffects.Value, depth ?? this.depth); spriteBatch.Draw(
texture: texture,
position: transformedPos,
sourceRectangle: sliceRect,
color: drawColor,
rotation: addedRotation,
origin: Vector2.Zero,
scale: scale,
effects: spriteEffects.Value,
layerDepth: depth ?? this.depth);
} }
//wrap the drawOffset inside the sourceRect //wrap the drawOffset inside the sourceRect
drawOffset.X = (drawOffset.X / scale.X) % sourceRect.Width; drawOffset.X = (drawOffset.X / scale.X) % sourceRect.Width;
drawOffset.Y = (drawOffset.Y / scale.Y) % sourceRect.Height; drawOffset.Y = (drawOffset.Y / scale.Y) % sourceRect.Height;
Vector2 flippedDrawOffset = Vector2.Zero;
if (flipHorizontal)
{
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 (flipVertical)
{
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;
}
drawOffset += flippedDrawOffset;
//how many times the texture needs to be drawn on the x-axis //how many times the texture needs to be drawn on the x-axis
int xTiles = (int)Math.Ceiling((targetSize.X + drawOffset.X * scale.X) / (sourceRect.Width * scale.X)); int xTiles = (int)Math.Ceiling((targetSize.X + drawOffset.X * scale.X) / (sourceRect.Width * scale.X));
//how many times the texture needs to be drawn on the y-axis //how many times the texture needs to be drawn on the y-axis
int yTiles = (int)Math.Ceiling((targetSize.Y + drawOffset.Y * scale.Y) / (sourceRect.Height * scale.Y)); int yTiles = (int)Math.Ceiling((targetSize.Y + drawOffset.Y * scale.Y) / (sourceRect.Height * scale.Y));
//where the current tile is being drawn; //where the current tile is being drawn;
Vector2 currDrawPosition = position - drawOffset; Vector2 currDrawPosition = -drawOffset;
//which part of the texture we are currently drawing //which part of the texture we are currently drawing
Rectangle texPerspective = sourceRect; Rectangle texPerspective = sourceRect;
@@ -364,54 +370,22 @@ namespace Barotrauma
texPerspective.Height = sourceRect.Height; texPerspective.Height = sourceRect.Height;
//offset to the left, draw a partial slice //offset to the left, draw a partial slice
if (currDrawPosition.X < position.X) if (currDrawPosition.X < 0)
{ {
float diff = (position.X - currDrawPosition.X); float diff = -currDrawPosition.X;
currDrawPosition.X += diff; currDrawPosition.X += diff;
texPerspective.Width -= (int)diff; texPerspective.Width -= (int)diff;
if (!flipHorizontal)
{
texPerspective.X += (int)diff;
}
if (!flipVertical)
{
texPerspective.Y += (int)diff;
}
}
//drawing an offset flipped sprite, need to draw an extra slice to the left side
if (currDrawPosition.X > position.X && x == 0)
{
if (flipHorizontal)
{
int sliceWidth = (int)((currDrawPosition.X - position.X) * scale.X);
Vector2 slicePos = currDrawPosition; texPerspective.X += (int)diff;
slicePos.X = position.X;
Rectangle sliceRect = texPerspective;
sliceRect.X = SourceRect.X;
sliceRect.Width = (int)(sliceWidth / scale.X);
if (flipVertical)
{
slicePos.Y += flippedDrawOffset.Y;
}
drawSection(slicePos, sliceRect);
currDrawPosition.X = slicePos.X + sliceWidth;
}
} }
//make sure the rightmost tiles don't go over the right side //make sure the rightmost tiles don't go over the right side
if (x == xTiles - 1) if (x == xTiles - 1)
{ {
int diff = (int)(((currDrawPosition.X + texPerspective.Width * scale.X) - (position.X + targetSize.X)) / scale.X); int diff = (int)(((currDrawPosition.X + texPerspective.Width * scale.X) - targetSize.X) / scale.X);
texPerspective.Width -= diff; texPerspective.Width -= diff;
if (flipHorizontal)
{
texPerspective.X += diff;
}
} }
currDrawPosition.Y = position.Y - drawOffset.Y; currDrawPosition.Y = -drawOffset.Y;
for (int y = 0; y < yTiles; y++) for (int y = 0; y < yTiles; y++)
{ {
@@ -419,45 +393,19 @@ namespace Barotrauma
texPerspective.Height = sourceRect.Height; texPerspective.Height = sourceRect.Height;
//offset above the top, draw a partial slice //offset above the top, draw a partial slice
if (currDrawPosition.Y < position.Y) if (currDrawPosition.Y < 0f)
{ {
float diff = (position.Y - currDrawPosition.Y); float diff = -currDrawPosition.Y;
currDrawPosition.Y += diff; currDrawPosition.Y += diff;
texPerspective.Height -= (int)diff; texPerspective.Height -= (int)diff;
if (!flipVertical) texPerspective.Y += (int)diff;
{
texPerspective.Y += (int)diff;
}
}
//drawing an offset flipped sprite, need to draw an extra slice to the top
if (currDrawPosition.Y > position.Y && y == 0)
{
if (flipVertical)
{
int sliceHeight = (int)((currDrawPosition.Y - position.Y) * scale.Y);
Vector2 slicePos = currDrawPosition;
slicePos.Y = position.Y;
Rectangle sliceRect = texPerspective;
sliceRect.Y = SourceRect.Y;
sliceRect.Height = (int)(sliceHeight / scale.Y);
drawSection(slicePos, sliceRect);
currDrawPosition.Y = slicePos.Y + sliceHeight;
}
} }
//make sure the bottommost tiles don't go over the bottom //make sure the bottommost tiles don't go over the bottom
if (y == yTiles - 1) if (y == yTiles - 1)
{ {
int diff = (int)(((currDrawPosition.Y + texPerspective.Height * scale.Y) - (position.Y + targetSize.Y)) / scale.Y); int diff = (int)(((currDrawPosition.Y + texPerspective.Height * scale.Y) - targetSize.Y) / scale.Y);
texPerspective.Height -= diff; texPerspective.Height -= diff;
if (flipVertical)
{
texPerspective.Y += diff;
}
} }
drawSection(currDrawPosition, texPerspective); drawSection(currDrawPosition, texPerspective);
@@ -6,7 +6,7 @@
<RootNamespace>Barotrauma</RootNamespace> <RootNamespace>Barotrauma</RootNamespace>
<Authors>FakeFish, Undertow Games</Authors> <Authors>FakeFish, Undertow Games</Authors>
<Product>Barotrauma</Product> <Product>Barotrauma</Product>
<Version>1.2.7.0</Version> <Version>1.2.8.0</Version>
<Copyright>Copyright © FakeFish 2018-2023</Copyright> <Copyright>Copyright © FakeFish 2018-2023</Copyright>
<Platforms>AnyCPU;x64</Platforms> <Platforms>AnyCPU;x64</Platforms>
<AssemblyName>Barotrauma</AssemblyName> <AssemblyName>Barotrauma</AssemblyName>
+1 -1
View File
@@ -6,7 +6,7 @@
<RootNamespace>Barotrauma</RootNamespace> <RootNamespace>Barotrauma</RootNamespace>
<Authors>FakeFish, Undertow Games</Authors> <Authors>FakeFish, Undertow Games</Authors>
<Product>Barotrauma</Product> <Product>Barotrauma</Product>
<Version>1.2.7.0</Version> <Version>1.2.8.0</Version>
<Copyright>Copyright © FakeFish 2018-2023</Copyright> <Copyright>Copyright © FakeFish 2018-2023</Copyright>
<Platforms>AnyCPU;x64</Platforms> <Platforms>AnyCPU;x64</Platforms>
<AssemblyName>Barotrauma</AssemblyName> <AssemblyName>Barotrauma</AssemblyName>
@@ -6,7 +6,7 @@
<RootNamespace>Barotrauma</RootNamespace> <RootNamespace>Barotrauma</RootNamespace>
<Authors>FakeFish, Undertow Games</Authors> <Authors>FakeFish, Undertow Games</Authors>
<Product>Barotrauma</Product> <Product>Barotrauma</Product>
<Version>1.2.7.0</Version> <Version>1.2.8.0</Version>
<Copyright>Copyright © FakeFish 2018-2023</Copyright> <Copyright>Copyright © FakeFish 2018-2023</Copyright>
<Platforms>AnyCPU;x64</Platforms> <Platforms>AnyCPU;x64</Platforms>
<AssemblyName>Barotrauma</AssemblyName> <AssemblyName>Barotrauma</AssemblyName>
@@ -6,7 +6,7 @@
<RootNamespace>Barotrauma</RootNamespace> <RootNamespace>Barotrauma</RootNamespace>
<Authors>FakeFish, Undertow Games</Authors> <Authors>FakeFish, Undertow Games</Authors>
<Product>Barotrauma Dedicated Server</Product> <Product>Barotrauma Dedicated Server</Product>
<Version>1.2.7.0</Version> <Version>1.2.8.0</Version>
<Copyright>Copyright © FakeFish 2018-2023</Copyright> <Copyright>Copyright © FakeFish 2018-2023</Copyright>
<Platforms>AnyCPU;x64</Platforms> <Platforms>AnyCPU;x64</Platforms>
<AssemblyName>DedicatedServer</AssemblyName> <AssemblyName>DedicatedServer</AssemblyName>
+1 -1
View File
@@ -6,7 +6,7 @@
<RootNamespace>Barotrauma</RootNamespace> <RootNamespace>Barotrauma</RootNamespace>
<Authors>FakeFish, Undertow Games</Authors> <Authors>FakeFish, Undertow Games</Authors>
<Product>Barotrauma Dedicated Server</Product> <Product>Barotrauma Dedicated Server</Product>
<Version>1.2.7.0</Version> <Version>1.2.8.0</Version>
<Copyright>Copyright © FakeFish 2018-2023</Copyright> <Copyright>Copyright © FakeFish 2018-2023</Copyright>
<Platforms>AnyCPU;x64</Platforms> <Platforms>AnyCPU;x64</Platforms>
<AssemblyName>DedicatedServer</AssemblyName> <AssemblyName>DedicatedServer</AssemblyName>
@@ -6,7 +6,7 @@
<RootNamespace>Barotrauma</RootNamespace> <RootNamespace>Barotrauma</RootNamespace>
<Authors>FakeFish, Undertow Games</Authors> <Authors>FakeFish, Undertow Games</Authors>
<Product>Barotrauma Dedicated Server</Product> <Product>Barotrauma Dedicated Server</Product>
<Version>1.2.7.0</Version> <Version>1.2.8.0</Version>
<Copyright>Copyright © FakeFish 2018-2023</Copyright> <Copyright>Copyright © FakeFish 2018-2023</Copyright>
<Platforms>AnyCPU;x64</Platforms> <Platforms>AnyCPU;x64</Platforms>
<AssemblyName>DedicatedServer</AssemblyName> <AssemblyName>DedicatedServer</AssemblyName>
@@ -255,7 +255,11 @@ namespace Barotrauma
} }
if (subObjectives.Any(so => so.CanBeCompleted)) { return; } if (subObjectives.Any(so => so.CanBeCompleted)) { return; }
UpdateSimpleEscape(deltaTime); UpdateSimpleEscape(deltaTime);
if (cannotFindSafeHull && !character.IsInFriendlySub && objectiveManager.Objectives.None(o => o is AIObjectiveReturn))
bool inFriendlySub =
character.IsInFriendlySub ||
(character.IsEscorted && character.IsInPlayerSub);
if (cannotFindSafeHull && !inFriendlySub && objectiveManager.Objectives.None(o => o is AIObjectiveReturn))
{ {
if (OrderPrefab.Prefabs.TryGet("return".ToIdentifier(), out OrderPrefab orderPrefab)) if (OrderPrefab.Prefabs.TryGet("return".ToIdentifier(), out OrderPrefab orderPrefab))
{ {
@@ -436,7 +436,10 @@ namespace Barotrauma
break; break;
case "statvalue": case "statvalue":
var newStatValue = new AppliedStatValue(subElement); var newStatValue = new AppliedStatValue(subElement);
afflictionStatValues.Add(newStatValue.StatType, newStatValue); if (newStatValue.StatType == StatTypes.None || !afflictionStatValues.TryAdd(newStatValue.StatType, newStatValue))
{
DebugConsole.ThrowError($"Invalid stat value in the affliction \"{parentDebugName}\".", contentPackage: element.ContentPackage);
}
break; break;
case "abilityflag": case "abilityflag":
AbilityFlags flagType = subElement.GetAttributeEnum("flagtype", AbilityFlags.None); AbilityFlags flagType = subElement.GetAttributeEnum("flagtype", AbilityFlags.None);
@@ -3141,6 +3141,7 @@ namespace Barotrauma
if (character.IsDead) { return; } if (character.IsDead) { return; }
if (!UseInHealthInterface) { return; } if (!UseInHealthInterface) { return; }
GameAnalyticsManager.AddDesignEvent("ApplyTreatment:" + Prefab.Identifier);
#if CLIENT #if CLIENT
if (user == Character.Controlled) if (user == Character.Controlled)
{ {
@@ -834,7 +834,7 @@ namespace Barotrauma
[Serialize(true, IsPropertySaveable.No)] [Serialize(true, IsPropertySaveable.No)]
public bool CanFlipY { get; private set; } public bool CanFlipY { get; private set; }
[Serialize(0.1f, IsPropertySaveable.No)] [Serialize(0.01f, IsPropertySaveable.No)]
public float MinScale { get; private set; } public float MinScale { get; private set; }
[Serialize(10.0f, IsPropertySaveable.No)] [Serialize(10.0f, IsPropertySaveable.No)]
@@ -11,6 +11,7 @@ using System.Xml.Linq;
using System.Collections.Immutable; using System.Collections.Immutable;
using Barotrauma.Abilities; using Barotrauma.Abilities;
#if CLIENT #if CLIENT
using System.Diagnostics;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using Barotrauma.Lights; using Barotrauma.Lights;
#endif #endif
@@ -281,14 +282,21 @@ namespace Barotrauma
} }
} }
public float ScaleWhenTextureOffsetSet { get; private set; } = 1.0f;
protected Vector2 textureOffset = Vector2.Zero; protected Vector2 textureOffset = Vector2.Zero;
[Editable(MinValueFloat = -1000f, MaxValueFloat = 1000f, ValueStep = 10f), Serialize("0.0, 0.0", IsPropertySaveable.Yes)] [Editable(ForceShowPlusMinusButtons = true, ValueStep = 1f), Serialize("0.0, 0.0", IsPropertySaveable.Yes)]
public Vector2 TextureOffset public Vector2 TextureOffset
{ {
get { return textureOffset; } get { return textureOffset; }
set set
{ {
textureOffset = value; textureOffset = value;
textureOffset.X =
MathUtils.PositiveModulo(textureOffset.X, Sprite.SourceRect.Width * TextureScale.X * Scale);
textureOffset.Y =
MathUtils.PositiveModulo(textureOffset.Y, Sprite.SourceRect.Height * TextureScale.Y * Scale);
ScaleWhenTextureOffsetSet = Scale;
#if CLIENT #if CLIENT
SetLightTextureOffset(); SetLightTextureOffset();
#endif #endif
@@ -1584,6 +1592,9 @@ namespace Barotrauma
Submarine = submarine, Submarine = submarine,
}; };
bool flippedX = element.GetAttributeBool(nameof(FlippedX), false);
bool flippedY = element.GetAttributeBool(nameof(FlippedY), false);
if (submarine?.Info.GameVersion != null) if (submarine?.Info.GameVersion != null)
{ {
SerializableProperty.UpgradeGameVersion(s, s.Prefab.ConfigElement, submarine.Info.GameVersion); SerializableProperty.UpgradeGameVersion(s, s.Prefab.ConfigElement, submarine.Info.GameVersion);
@@ -1594,6 +1605,19 @@ namespace Barotrauma
{ {
s.CrushDepth = Math.Max(s.CrushDepth, GameMain.GameSession.LevelData.InitialDepth * Physics.DisplayToRealWorldRatio + 500); s.CrushDepth = Math.Max(s.CrushDepth, GameMain.GameSession.LevelData.InitialDepth * Physics.DisplayToRealWorldRatio + 500);
} }
#if CLIENT
s.TextureOffset = UpgradeTextureOffset(
targetSize: rect.Size.ToVector2(),
originalTextureOffset:
// Note: cannot use s.TextureOffset because wrapping is very weird in the old logic
element.GetAttributeVector2("TextureOffset", Vector2.Zero),
submarineInfo: submarine.Info,
sourceRect: s.Sprite.SourceRect,
scale: s.Scale * s.TextureScale,
flippedX: flippedX,
flippedY: flippedY);
#endif
} }
bool hasDamage = false; bool hasDamage = false;
@@ -1637,8 +1661,8 @@ namespace Barotrauma
} }
} }
if (element.GetAttributeBool(nameof(FlippedX), false)) { s.FlipX(false); } if (flippedX) { s.FlipX(false); }
if (element.GetAttributeBool(nameof(FlippedY), false)) { s.FlipY(false); } if (flippedY) { s.FlipY(false); }
//structures with a body drop a shadow by default //structures with a body drop a shadow by default
if (element.GetAttribute(nameof(UseDropShadow)) == null) if (element.GetAttribute(nameof(UseDropShadow)) == null)
@@ -45,7 +45,7 @@ sealed class ConditionallyEditable : Editable
=> (entity is Item { body: null } item && item.Prefab.AllowRotatingInEditor) => (entity is Item { body: null } item && item.Prefab.AllowRotatingInEditor)
|| (entity is Structure structure && structure.Prefab.AllowRotatingInEditor), || (entity is Structure structure && structure.Prefab.AllowRotatingInEditor),
ConditionType.Attachable ConditionType.Attachable
=> entity is Holdable { Attachable: true }, => GetComponent<Holdable>(entity) is Holdable { Attachable: true },
ConditionType.HasBody ConditionType.HasBody
=> entity is Structure { HasBody: true } or Item { body: not null }, => entity is Structure { HasBody: true } or Item { body: not null },
ConditionType.Pickable ConditionType.Pickable
@@ -53,14 +53,28 @@ sealed class ConditionallyEditable : Editable
ConditionType.OnlyByStatusEffectsAndNetwork ConditionType.OnlyByStatusEffectsAndNetwork
=> GameMain.NetworkMember is { IsServer: true }, => GameMain.NetworkMember is { IsServer: true },
ConditionType.HasIntegratedButtons ConditionType.HasIntegratedButtons
=> entity is Door { HasIntegratedButtons: true }, => GetComponent<Door>(entity) is { HasIntegratedButtons: true },
ConditionType.IsToggleableController ConditionType.IsToggleableController
=> entity is Controller { IsToggle: true } controller && controller.Item.GetComponent<ConnectionPanel>() != null, => GetComponent<Controller>(entity) is Controller { IsToggle: true } controller &&
controller.Item.GetComponent<ConnectionPanel>() != null,
ConditionType.HasConnectionPanel ConditionType.HasConnectionPanel
=> (entity is Item item && item.GetComponent<ConnectionPanel>() != null) => GetComponent<ConnectionPanel>(entity) != null,
|| (entity is ItemComponent ic && ic.Item.GetComponent<ConnectionPanel>() != null),
_ _
=> false => false
}; };
static T GetComponent<T>(ISerializableEntity e) where T : ItemComponent
{
if (e is T t) { return t; }
if (e is Item item)
{
return item.GetComponent<T>();
}
if (e is ItemComponent ic)
{
return ic.Item.GetComponent<T>();
}
return null;
}
} }
} }
+18
View File
@@ -1,3 +1,21 @@
-------------------------------------------------------------------------------------------------------------------------------------------------
v1.2.8.0
-------------------------------------------------------------------------------------------------------------------------------------------------
Changes:
- Allow scaling most items below 0.1 in the submarine editor again. We set 0.1 as a hard limit because smaller scales caused issues with tiling items (such as labels), without realizing some sub builders have found some creative uses for heavily downscaled items (such as tiny turrets used as "dials").
Fixes:
- Fixed escorted characters trying to leave the sub if they can't find a safe hull to get to (e.g. when the sub is flooded).
- Fixed rotated structures not appearing rotated on the status monitor.
- Fixed wires getting misaligned when saving them in an item assembly.
- Fixed security NPCs being unable to swap batteries in stun batons.
- Fixed inability to edit the false output of a switch in multiplayer.
- (Finally) fixed texture offsets on tiled sprites such as background walls behaving erratically on non-default texture scales and mirrored entities.
Modding:
- Fixed crashing if an affliction prefab contains stat values with a duplicate type, or multiple stat values whose type can't be parsed.
------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------
v1.2.7.0 v1.2.7.0
------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------