Build 0.21.6.0 (1.0 pre-patch)

This commit is contained in:
Regalis11
2023-01-31 18:08:26 +02:00
parent e1c04bc31d
commit cf9ecd35b3
231 changed files with 4479 additions and 2276 deletions
@@ -216,16 +216,19 @@ namespace Barotrauma.Items.Components
if (brokenSprite == null || !IsBroken)
{
spriteBatch.Draw(doorSprite.Texture, pos,
getSourceRect(doorSprite, openState, IsHorizontal),
color, 0.0f, doorSprite.Origin, item.Scale, item.SpriteEffects, doorSprite.Depth);
if (doorSprite?.Texture != null)
{
spriteBatch.Draw(doorSprite.Texture, pos,
getSourceRect(doorSprite, openState, IsHorizontal),
color, 0.0f, doorSprite.Origin, item.Scale, item.SpriteEffects, doorSprite.Depth);
}
}
float maxCondition = item.Repairables.Any() ?
item.Repairables.Min(r => r.RepairThreshold) / 100.0f * item.MaxCondition :
item.MaxCondition;
float healthRatio = item.Health / maxCondition;
if (brokenSprite != null && healthRatio < 1.0f)
if (brokenSprite?.Texture != null && healthRatio < 1.0f)
{
Vector2 scale = scaleBrokenSprite ? new Vector2(1.0f - healthRatio) : Vector2.One;
if (IsHorizontal) { scale.X = 1; } else { scale.Y = 1; }
@@ -285,34 +288,45 @@ namespace Barotrauma.Items.Components
//sent by the server, or reverting it back to its old state if no msg from server was received
PredictedState = open;
resetPredictionTimer = CorrectionDelay;
if (stateChanged) PlaySound(forcedOpen ? ActionType.OnPicked : ActionType.OnUse);
if (stateChanged && !IsBroken)
{
PlayInteractionSound();
}
}
else
{
isOpen = open;
if (!isNetworkMessage || open != PredictedState)
{
StopPicking(null);
ActionType actionType = ActionType.OnUse;
if (forcedOpen)
StopPicking(null);
if (!IsBroken)
{
actionType = ActionType.OnPicked;
PlayInteractionSound();
}
else
{
if (open && HasSoundsOfType[(int)ActionType.OnOpen])
{
actionType = ActionType.OnOpen;
}
else if (!open && HasSoundsOfType[(int)ActionType.OnClose])
{
actionType = ActionType.OnClose;
}
}
PlaySound(actionType);
if (isOpen) { stuck = MathHelper.Clamp(stuck - StuckReductionOnOpen, 0.0f, 100.0f); }
}
}
}
void PlayInteractionSound()
{
ActionType actionType = ActionType.OnUse;
if (forcedOpen)
{
actionType = ActionType.OnPicked;
}
else
{
if (open && HasSoundsOfType[(int)ActionType.OnOpen])
{
actionType = ActionType.OnOpen;
}
else if (!open && HasSoundsOfType[(int)ActionType.OnClose])
{
actionType = ActionType.OnClose;
}
}
PlaySound(actionType);
}
}
public override void ClientEventRead(IReadMessage msg, float sendingTime)
@@ -55,7 +55,7 @@ namespace Barotrauma.Items.Components
public void DrawElectricity(SpriteBatch spriteBatch)
{
if (timer <= 0.0f) { return; }
if (timer <= 0.0f && Screen.Selected is { IsEditor: false }) { return; }
for (int i = 0; i < nodes.Count; i++)
{
if (nodes[i].Length <= 1.0f) { continue; }
@@ -1,7 +1,9 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections;
using System.Linq;
using static Barotrauma.Inventory;
namespace Barotrauma.Items.Components
{
@@ -250,6 +252,83 @@ namespace Barotrauma.Items.Components
return true;
}
public float GetContainedIndicatorState()
{
if (ShowConditionInContainedStateIndicator)
{
return item.Condition / item.MaxCondition;
}
int targetSlot = Math.Max(ContainedStateIndicatorSlot, 0);
if (targetSlot >= Inventory.Capacity) { return 0.0f; }
var containedItems = Inventory.GetItemsAt(targetSlot);
if (containedItems == null) { return 0.0f; }
Item containedItem = containedItems.FirstOrDefault();
if (ShowTotalStackCapacityInContainedStateIndicator)
{
// No item on the defined slot, check if the items on other slots can be used.
containedItem ??=
containedItems.FirstOrDefault() ??
Inventory.AllItems.FirstOrDefault(it => CanBeContained(it, targetSlot));
if (containedItem == null) { return 0.0f; }
int ignoredItemCount = 0;
var subContainableItems = AllSubContainableItems;
float capacity = GetMaxStackSize(targetSlot);
if (subContainableItems != null)
{
bool useMainContainerCapacity = true;
foreach (Item it in Inventory.AllItems)
{
// Ignore all items in the sub containers.
foreach (RelatedItem ri in subContainableItems)
{
if (ri.MatchesItem(containedItem))
{
// The target item is in a subcontainer -> inverse the logic.
useMainContainerCapacity = false;
break;
}
if (ri.MatchesItem(it))
{
ignoredItemCount++;
}
}
if (!useMainContainerCapacity) { break; }
}
if (useMainContainerCapacity)
{
capacity *= MainContainerCapacity;
}
else
{
// Ignore all items in the main container.
ignoredItemCount = Inventory.AllItems.Count(it => subContainableItems.Any(ri => !ri.MatchesItem(it)));
capacity *= Capacity - MainContainerCapacity;
}
}
int itemCount = Inventory.AllItems.Count() - ignoredItemCount;
return Math.Min(itemCount / Math.Max(capacity, 1), 1);
}
else
{
if (containedItem != null && (Inventory.Capacity == 1 || HasSubContainers))
{
int maxStackSize = Math.Min(containedItem.Prefab.MaxStackSize, GetMaxStackSize(targetSlot));
if (maxStackSize > 1 || containedItem.Prefab.HideConditionBar)
{
return containedItems.Count() / (float)maxStackSize;
}
}
return Inventory.Capacity == 1 || ContainedStateIndicatorSlot > -1 ?
(containedItem == null ? 0.0f : containedItem.Condition / containedItem.MaxCondition) :
Inventory.EmptySlotCount / (float)Inventory.Capacity;
}
}
public void Draw(SpriteBatch spriteBatch, bool editing = false, float itemDepth = -1)
{
if (hideItems || (item.body != null && !item.body.Enabled)) { return; }
@@ -14,8 +14,6 @@ namespace Barotrauma.Items.Components
private CoroutineHandle resetPredictionCoroutine;
private float resetPredictionTimer;
private float currentBrightness;
public Vector2 DrawSize
{
get { return new Vector2(Light.Range * 2, Light.Range * 2); }
@@ -29,14 +27,21 @@ namespace Barotrauma.Items.Components
Light.Position = ParentBody != null ? ParentBody.Position : item.Position;
}
partial void SetLightSourceState(bool enabled, float brightness)
partial void SetLightSourceState(bool enabled, float? brightness)
{
if (Light == null) { return; }
Light.Enabled = enabled;
currentBrightness = brightness;
if (brightness.HasValue)
{
lightBrightness = brightness.Value;
}
else
{
lightBrightness = enabled ? 1.0f : 0.0f;
}
if (enabled)
{
Light.Color = LightColor.Multiply(brightness);
Light.Color = LightColor.Multiply(lightBrightness);
}
}
@@ -73,14 +78,21 @@ namespace Barotrauma.Items.Components
public void Draw(SpriteBatch spriteBatch, bool editing = false, float itemDepth = -1)
{
if (Light.LightSprite != null && (item.body == null || item.body.Enabled) && lightBrightness > 0.0f && IsOn && Light.Enabled)
if (Light?.LightSprite == null) { return; }
if ((item.body == null || item.body.Enabled) && lightBrightness > 0.0f && IsOn && Light.Enabled)
{
Vector2 origin = Light.LightSprite.Origin;
if ((Light.LightSpriteEffect & SpriteEffects.FlipHorizontally) == SpriteEffects.FlipHorizontally) { origin.X = Light.LightSprite.SourceRect.Width - origin.X; }
if ((Light.LightSpriteEffect & SpriteEffects.FlipVertically) == SpriteEffects.FlipVertically) { origin.Y = Light.LightSprite.SourceRect.Height - origin.Y; }
Vector2 drawPos = item.body?.DrawPosition ?? item.DrawPosition;
Light.LightSprite.Draw(spriteBatch, new Vector2(drawPos.X, -drawPos.Y), lightColor * lightBrightness, origin, -Light.Rotation, item.Scale, Light.LightSpriteEffect, itemDepth - 0.0001f);
Color color = lightColor;
if (Light.OverrideLightSpriteAlpha.HasValue)
{
color = new Color(lightColor, Light.OverrideLightSpriteAlpha.Value);
}
Light.LightSprite.Draw(spriteBatch, new Vector2(drawPos.X, -drawPos.Y), color * lightBrightness, origin, -Light.Rotation, item.Scale, Light.LightSpriteEffect, itemDepth - 0.0001f);
}
}
@@ -413,7 +413,7 @@ namespace Barotrauma.Items.Components
var wire = it.GetComponent<Wire>();
if (wire != null && wire.Connections.Any(c => c != null)) { return false; }
if (it.Container?.GetComponent<ItemContainer>() is { DrawInventory: false }) { return false; }
if (it.Container?.GetComponent<ItemContainer>() is { DrawInventory: false } or { AllowAccess: false }) { return false; }
if (it.HasTag("traitormissionitem")) { return false; }
@@ -519,7 +519,10 @@ namespace Barotrauma.Items.Components
Color color = !hasPower ? NoPowerColor : turret.ActiveUser is null ? Color.DimGray : GUIStyle.Green;
weaponSprite.Draw(batch, center, color, origin, rotation, scale, SpriteEffects.None);
}
});
})
{
CanBeFocused = false
};
weaponChilds.Add(component, frame);
}
@@ -72,7 +72,9 @@ namespace Barotrauma.Items.Components
public override bool RecreateGUIOnResolutionChange => true;
public bool TriggerInfographic { get; set; }
public bool IsInfographicVisible => infographic != null && infographic.Visible;
partial void InitProjSpecific(ContentXElement element)
{
CreateGUI();
@@ -108,6 +110,9 @@ namespace Barotrauma.Items.Components
{ AbsoluteOffset = GUIStyle.ItemFrameOffset },
isHorizontal: true)
{
CanBeFocused = true,
HoverCursor = CursorState.Default,
AlwaysOverrideCursor = true,
RelativeSpacing = 0.012f,
Stretch = true
};
@@ -675,7 +680,7 @@ namespace Barotrauma.Items.Components
}
}
if (TriggerInfographic)
if (GuiFrame is not null && GuiFrame.Visible && TriggerInfographic)
{
CreateInfrographic();
TriggerInfographic = false;
@@ -851,8 +856,9 @@ namespace Barotrauma.Items.Components
{
AbsoluteOffset = new Point(0, -50).Multiply(GUI.Scale)
};
new GUIButton(closeButtonRt, TextManager.Get("close"))
new GUIButton(closeButtonRt, TextManager.Get("closeinfographic"))
{
UserData = UIHighlightAction.ElementId.CloseButton,
OnClicked = (_, _) =>
{
CloseInfographic(Character.Controlled);
@@ -871,6 +877,7 @@ namespace Barotrauma.Items.Components
string style = arrowStyle == InfographicArrowStyle.Straight ? "InfographicArrow" : "InfographicArrowCurved";
return new GUIImage(rt, style)
{
CanBeFocused = false,
Rotation = MathHelper.ToRadians(rotationDegrees),
SpriteEffects = spriteEffects
};
@@ -329,6 +329,7 @@ namespace Barotrauma.Items.Components
partial void UpdateSignalsProjSpecific()
{
if (signals == null) { return; }
for (int i = 0; i < signals.Length && i < uiElements.Count; i++)
{
if (uiElements[i] is GUITextBox tb)
@@ -25,14 +25,14 @@ namespace Barotrauma.Items.Components
public static Color editorHighlightColor = Color.Yellow;
public static Color editorSelectedColor = Color.Red;
partial class WireSection
public partial class WireSection
{
public VertexPositionColorTexture[] vertices;
public VertexPositionColorTexture[] shiftedVertices;
private float cachedWidth = 0f;
private void RecalculateVertices(Wire wire, float width)
private void RecalculateVertices(Sprite wireSprite, float width)
{
if (MathUtils.NearlyEqual(cachedWidth, width)) { return; }
cachedWidth = width;
@@ -45,13 +45,13 @@ namespace Barotrauma.Items.Components
expandDir.X = -expandDir.Y;
expandDir.Y = -temp;
Rectangle srcRect = wire.wireSprite.SourceRect;
Rectangle srcRect = wireSprite.SourceRect;
expandDir *= width * srcRect.Height * 0.5f;
Vector2 rectLocation = srcRect.Location.ToVector2();
Vector2 rectSize = srcRect.Size.ToVector2();
Vector2 textureSize = new Vector2(wire.wireSprite.Texture.Width, wire.wireSprite.Texture.Height);
Vector2 textureSize = new Vector2(wireSprite.Texture.Width, wireSprite.Texture.Height);
Vector2 topLeftUv = rectLocation / textureSize;
Vector2 bottomRightUv = (rectLocation + rectSize) / textureSize;
@@ -67,10 +67,10 @@ namespace Barotrauma.Items.Components
shiftedVertices = (VertexPositionColorTexture[])vertices.Clone();
}
public void Draw(SpriteBatch spriteBatch, Wire wire, Color color, Vector2 offset, float depth, float width = 0.3f)
public void Draw(ISpriteBatch spriteBatch, Sprite wireSprite, Color color, Vector2 offset, float depth, float width = 0.3f)
{
if (width <= 0f) { return; }
RecalculateVertices(wire, width);
RecalculateVertices(wireSprite, width);
for (int i = 0; i < vertices.Length; i++)
{
@@ -79,21 +79,22 @@ namespace Barotrauma.Items.Components
shiftedVertices[i].Position.X += offset.X;
shiftedVertices[i].Position.Y -= offset.Y;
}
spriteBatch.Draw(wire.wireSprite.Texture,
spriteBatch.Draw(
wireSprite.Texture,
shiftedVertices,
depth);
}
public static void Draw(SpriteBatch spriteBatch, Wire wire, Vector2 start, Vector2 end, Color color, float depth, float width = 0.3f)
public static void Draw(ISpriteBatch spriteBatch, Sprite wireSprite, Vector2 start, Vector2 end, Color color, float depth, float width = 0.3f)
{
start.Y = -start.Y;
end.Y = -end.Y;
spriteBatch.Draw(wire.wireSprite.Texture,
start, wire.wireSprite.SourceRect, color,
spriteBatch.Draw(wireSprite.Texture,
start, wireSprite.SourceRect, color,
MathUtils.VectorToAngle(end - start),
new Vector2(0.0f, wire.wireSprite.size.Y / 2.0f),
new Vector2((Vector2.Distance(start, end)) / wire.wireSprite.size.X, width),
new Vector2(0.0f, wireSprite.size.Y / 2.0f),
new Vector2((Vector2.Distance(start, end)) / wireSprite.size.X, width),
SpriteEffects.None,
depth);
}
@@ -123,7 +124,7 @@ namespace Barotrauma.Items.Components
get => draggingWire;
}
partial void InitProjSpecific(ContentXElement element)
public static Sprite ExtractWireSprite(ContentXElement element)
{
if (defaultWireSprite == null)
{
@@ -133,6 +134,7 @@ namespace Barotrauma.Items.Components
};
}
Sprite overrideSprite = null;
foreach (var subElement in element.Elements())
{
if (subElement.Name.ToString().Equals("wiresprite", StringComparison.OrdinalIgnoreCase))
@@ -142,9 +144,14 @@ namespace Barotrauma.Items.Components
}
}
wireSprite = overrideSprite ?? defaultWireSprite;
return overrideSprite ?? defaultWireSprite;
}
partial void InitProjSpecific(ContentXElement element)
{
wireSprite = ExtractWireSprite(element);
if (wireSprite != defaultWireSprite) { overrideSprite = wireSprite; }
}
public void Draw(SpriteBatch spriteBatch, bool editing, float itemDepth = -1)
{
@@ -181,20 +188,20 @@ namespace Barotrauma.Items.Components
{
foreach (WireSection section in sections)
{
section.Draw(spriteBatch, this, Screen.Selected == GameMain.GameScreen ? higlightColor : editorHighlightColor, drawOffset, depth + 0.00001f, Width * 2.0f);
section.Draw(spriteBatch, wireSprite, Screen.Selected == GameMain.GameScreen ? higlightColor : editorHighlightColor, drawOffset, depth + 0.00001f, Width * 2.0f);
}
}
else if (item.IsSelected)
{
foreach (WireSection section in sections)
{
section.Draw(spriteBatch, this, editorSelectedColor, drawOffset, depth + 0.00001f, Width * 2.0f);
section.Draw(spriteBatch, wireSprite, editorSelectedColor, drawOffset, depth + 0.00001f, Width * 2.0f);
}
}
foreach (WireSection section in sections)
{
section.Draw(spriteBatch, this, item.Color, drawOffset, depth, Width);
section.Draw(spriteBatch, wireSprite, item.Color, drawOffset, depth, Width);
}
if (nodes.Count > 0)
@@ -239,13 +246,13 @@ namespace Barotrauma.Items.Components
}
WireSection.Draw(
spriteBatch, this,
new Vector2(nodes[nodes.Count - 1].X, nodes[nodes.Count - 1].Y) + drawOffset,
spriteBatch, wireSprite,
nodes[^1] + drawOffset,
new Vector2(newNodePos.X, newNodePos.Y) + drawOffset,
item.Color, 0.0f, Width);
WireSection.Draw(
spriteBatch, this,
spriteBatch, wireSprite,
new Vector2(newNodePos.X, newNodePos.Y) + drawOffset,
item.DrawPosition,
item.Color, itemDepth, Width);
@@ -255,8 +262,8 @@ namespace Barotrauma.Items.Components
else
{
WireSection.Draw(
spriteBatch, this,
new Vector2(nodes[nodes.Count - 1].X, nodes[nodes.Count - 1].Y) + drawOffset,
spriteBatch, wireSprite,
nodes[^1] + drawOffset,
item.DrawPosition,
item.Color, 0.0f, Width);
}
@@ -294,12 +301,12 @@ namespace Barotrauma.Items.Components
Vector2 endPos = start + new Vector2((float)Math.Sin(angle), -(float)Math.Cos(angle)) * 50.0f;
WireSection.Draw(
spriteBatch, this,
spriteBatch, wireSprite,
start, endPos,
GUIStyle.Orange, depth + 0.00001f, 0.2f);
WireSection.Draw(
spriteBatch, this,
spriteBatch, wireSprite,
start, start + (endPos - start) * 0.7f,
item.Color, depth, 0.3f);
}
@@ -9,7 +9,7 @@ namespace Barotrauma.Items.Components
{
private static void GetDamageModifierText(ref LocalizedString description, DamageModifier damageModifier, Identifier afflictionIdentifier)
{
int roundedValue = (int)Math.Round((1 - damageModifier.DamageMultiplier * damageModifier.ProbabilityMultiplier) * 100);
int roundedValue = (int)Math.Round((1 - Math.Min(damageModifier.DamageMultiplier, damageModifier.ProbabilityMultiplier)) * 100);
if (roundedValue == 0) { return; }
string colorStr = XMLExtensions.ToStringHex(GUIStyle.Green);
@@ -18,7 +18,7 @@ namespace Barotrauma.Items.Components
TextManager.Get($"afflictiontype.{afflictionIdentifier}").Fallback(afflictionIdentifier.Value);
if (!description.IsNullOrWhiteSpace()) { description += '\n'; }
description += $" ‖color:{colorStr}‖{roundedValue.ToString("-0;+#")}%‖color:end‖ {afflictionName}";
description += $" ‖color:{colorStr}‖{roundedValue:-0;+#}%‖color:end‖ {afflictionName}";
}
public override void AddTooltipInfo(ref LocalizedString name, ref LocalizedString description)
@@ -36,7 +36,6 @@ namespace Barotrauma.Items.Components
{
continue;
}
foreach (Identifier afflictionIdentifier in damageModifier.ParsedAfflictionIdentifiers)
{
GetDamageModifierText(ref description, damageModifier, afflictionIdentifier);