Build 0.21.1.0
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user