Unstable 1.1.14.0
This commit is contained in:
@@ -185,9 +185,9 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing, float itemDepth = -1)
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing, float itemDepth = -1, Color? overrideColor = null)
|
||||
{
|
||||
Color color = item.GetSpriteColor(withHighlight: true);
|
||||
Color color = overrideColor ?? item.GetSpriteColor(withHighlight: true);
|
||||
if (brokenSprite == null)
|
||||
{
|
||||
//broken doors turn black if no broken sprite has been configured
|
||||
@@ -202,7 +202,7 @@ namespace Barotrauma.Items.Components
|
||||
weldSpritePos.Y = -weldSpritePos.Y;
|
||||
|
||||
weldedSprite.Draw(spriteBatch,
|
||||
weldSpritePos, item.SpriteColor * (stuck / 100.0f), scale: item.Scale);
|
||||
weldSpritePos, overrideColor ?? (item.SpriteColor * (stuck / 100.0f)), scale: item.Scale);
|
||||
}
|
||||
|
||||
if (openState >= 1.0f) { return; }
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
public Vector2 DrawSize => Vector2.Zero;
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing, float itemDepth = -1)
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing, float itemDepth = -1, Color? overrideColor = null)
|
||||
{
|
||||
if (!editing) { return; }
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Barotrauma.Items.Components
|
||||
get { return item.Rect.Size.ToVector2(); }
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing, float itemDepth = -1)
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing, float itemDepth = -1, Color? overrideColor = null)
|
||||
{
|
||||
if (!IsActive || picker == null || !CanBeAttached(picker) || !picker.IsKeyDown(InputType.Aim) || picker != Character.Controlled)
|
||||
{
|
||||
@@ -50,7 +50,17 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
Submarine.DrawGrid(spriteBatch, 14, gridPos, roundedGridPos, alpha: 0.4f);
|
||||
|
||||
item.Sprite.Draw(
|
||||
Sprite sprite = item.Sprite;
|
||||
foreach (ContainedItemSprite containedSprite in item.Prefab.ContainedSprites)
|
||||
{
|
||||
if (containedSprite.UseWhenAttached)
|
||||
{
|
||||
sprite = containedSprite.Sprite;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
sprite.Draw(
|
||||
spriteBatch,
|
||||
new Vector2(attachPos.X, -attachPos.Y),
|
||||
item.SpriteColor * 0.5f,
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
using System;
|
||||
using Barotrauma.IO;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using Barotrauma.Extensions;
|
||||
using Barotrauma.IO;
|
||||
|
||||
namespace Barotrauma.Items.Components
|
||||
{
|
||||
@@ -48,33 +45,36 @@ namespace Barotrauma.Items.Components
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (ContentXElement limbElement in characterInfo.Ragdoll.MainElement.Elements())
|
||||
if (characterInfo.Ragdoll.MainElement?.Elements() is { } limbElements)
|
||||
{
|
||||
if (!limbElement.GetAttributeString("type", "").Equals("head", StringComparison.OrdinalIgnoreCase)) { continue; }
|
||||
|
||||
ContentXElement spriteElement = limbElement.GetChildElement("sprite");
|
||||
if (spriteElement == null) { continue; }
|
||||
|
||||
ContentPath contentPath = spriteElement.GetAttributeContentPath("texture");
|
||||
|
||||
string spritePath = characterInfo.ReplaceVars(contentPath.Value);
|
||||
string fileName = Path.GetFileNameWithoutExtension(spritePath);
|
||||
|
||||
//go through the files in the directory to find a matching sprite
|
||||
foreach (string file in Directory.GetFiles(Path.GetDirectoryName(spritePath)))
|
||||
foreach (ContentXElement limbElement in limbElements)
|
||||
{
|
||||
if (!file.EndsWith(".png", StringComparison.OrdinalIgnoreCase))
|
||||
if (!limbElement.GetAttributeString("type", "").Equals("head", StringComparison.OrdinalIgnoreCase)) { continue; }
|
||||
|
||||
ContentXElement spriteElement = limbElement.GetChildElement("sprite");
|
||||
if (spriteElement == null) { continue; }
|
||||
|
||||
ContentPath contentPath = spriteElement.GetAttributeContentPath("texture");
|
||||
|
||||
string spritePath = characterInfo.ReplaceVars(contentPath.Value);
|
||||
string fileName = Path.GetFileNameWithoutExtension(spritePath);
|
||||
|
||||
//go through the files in the directory to find a matching sprite
|
||||
foreach (string file in Directory.GetFiles(Path.GetDirectoryName(spritePath)))
|
||||
{
|
||||
continue;
|
||||
if (!file.EndsWith(".png", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
string fileWithoutTags = Path.GetFileNameWithoutExtension(file);
|
||||
fileWithoutTags = fileWithoutTags.Split('[', ']').First();
|
||||
if (fileWithoutTags != fileName) { continue; }
|
||||
Portrait = new Sprite(spriteElement, "", file) { RelativeOrigin = Vector2.Zero };
|
||||
break;
|
||||
}
|
||||
string fileWithoutTags = Path.GetFileNameWithoutExtension(file);
|
||||
fileWithoutTags = fileWithoutTags.Split('[', ']').First();
|
||||
if (fileWithoutTags != fileName) { continue; }
|
||||
Portrait = new Sprite(spriteElement, "", file) { RelativeOrigin = Vector2.Zero };
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (characterInfo.Wearables != null)
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
public override void UpdateHUD(Character character, float deltaTime, Camera cam)
|
||||
public override void UpdateHUDComponentSpecific(Character character, float deltaTime, Camera cam)
|
||||
{
|
||||
currentCrossHairScale = currentCrossHairPointerScale = cam == null ? 1.0f : cam.Zoom;
|
||||
if (crosshairSprite != null)
|
||||
@@ -118,6 +118,7 @@ namespace Barotrauma.Items.Components
|
||||
else if (chargeSoundChannel != null)
|
||||
{
|
||||
chargeSoundChannel.FrequencyMultiplier = MathHelper.Lerp(0.5f, 1.5f, chargeRatio);
|
||||
chargeSoundChannel.Position = new Vector3(item.WorldPosition, 0.0f);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace Barotrauma.Items.Components
|
||||
private int spraySetting = 0;
|
||||
private readonly Point[] sprayArray = new Point[8];
|
||||
|
||||
public override void UpdateHUD(Character character, float deltaTime, Camera cam)
|
||||
public override void UpdateHUDComponentSpecific(Character character, float deltaTime, Camera cam)
|
||||
{
|
||||
if (character == null || !character.IsKeyDown(InputType.Aim)) return;
|
||||
|
||||
@@ -130,7 +130,7 @@ namespace Barotrauma.Items.Components
|
||||
if (body.UserData is Item item)
|
||||
{
|
||||
var door = item.GetComponent<Door>();
|
||||
if (door != null && door.CanBeTraversed) { continue; }
|
||||
if (door != null && (door.IsOpen || door.IsBroken)) { continue; }
|
||||
}
|
||||
|
||||
targetHull = null;
|
||||
@@ -288,7 +288,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing, float itemDepth = -1)
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing, float itemDepth = -1, Color? overrideColor = null)
|
||||
{
|
||||
#if DEBUG
|
||||
if (GameMain.DebugDraw && Character.Controlled != null && Character.Controlled.IsKeyDown(InputType.Aim))
|
||||
|
||||
@@ -150,7 +150,9 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public GUIFrame GuiFrame { get; set; }
|
||||
|
||||
public bool LockGuiFramePosition;
|
||||
private GUIDragHandle guiFrameDragHandle;
|
||||
|
||||
private bool guiFrameUpdatePending;
|
||||
|
||||
[Serialize(false, IsPropertySaveable.No)]
|
||||
public bool AllowUIOverlap
|
||||
@@ -466,7 +468,21 @@ namespace Barotrauma.Items.Components
|
||||
GuiFrame?.AddToGUIUpdateList(order: order);
|
||||
}
|
||||
|
||||
public virtual void UpdateHUD(Character character, float deltaTime, Camera cam) { }
|
||||
public void UpdateHUD(Character character, float deltaTime, Camera cam)
|
||||
{
|
||||
UpdateHUDComponentSpecific(character, deltaTime, cam);
|
||||
if (guiFrameUpdatePending && !PlayerInput.PrimaryMouseButtonHeld())
|
||||
{
|
||||
//send a guiframe position update once the player stops dragging the frame
|
||||
guiFrameUpdatePending = false;
|
||||
if (SerializableProperties.TryGetValue(nameof(GuiFrameOffset).ToIdentifier(), out var property))
|
||||
{
|
||||
GameMain.Client?.CreateEntityEvent(Item, new Item.ChangePropertyEventData(property, this));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void UpdateHUDComponentSpecific(Character character, float deltaTime, Camera cam) { }
|
||||
|
||||
public virtual void UpdateEditing(float deltaTime) { }
|
||||
|
||||
@@ -572,6 +588,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
string style = GuiFrameSource.Attribute("style") == null ? null : GuiFrameSource.GetAttributeString("style", "");
|
||||
GuiFrame = new GUIFrame(RectTransform.Load(GuiFrameSource, GUI.Canvas, Anchor.Center), style, color);
|
||||
GuiFrame.RectTransform.ScreenSpaceOffset = GuiFrameOffset;
|
||||
|
||||
TryCreateDragHandle();
|
||||
|
||||
@@ -583,24 +600,25 @@ namespace Barotrauma.Items.Components
|
||||
GameMain.Instance.ResolutionChanged += OnResolutionChangedPrivate;
|
||||
}
|
||||
|
||||
protected virtual void TryCreateDragHandle()
|
||||
protected void TryCreateDragHandle()
|
||||
{
|
||||
if (GuiFrame != null && GuiFrameSource.GetAttributeBool("draggable", true))
|
||||
{
|
||||
bool hideDragIcons = GuiFrameSource.GetAttributeBool("hidedragicons", false);
|
||||
|
||||
var handle = new GUIDragHandle(new RectTransform(Vector2.One, GuiFrame.RectTransform, Anchor.Center),
|
||||
guiFrameDragHandle = new GUIDragHandle(new RectTransform(Vector2.One, GuiFrame.RectTransform, Anchor.Center),
|
||||
GuiFrame.RectTransform, style: null)
|
||||
{
|
||||
Enabled = !LockGuiFramePosition,
|
||||
DragArea = HUDLayoutSettings.ItemHUDArea
|
||||
};
|
||||
|
||||
int iconHeight = GUIStyle.ItemFrameMargin.Y / 4;
|
||||
var dragIcon = new GUIImage(new RectTransform(new Point(GuiFrame.Rect.Width, iconHeight), handle.RectTransform, Anchor.TopCenter) { AbsoluteOffset = new Point(0, iconHeight / 2) },
|
||||
var dragIcon = new GUIImage(new RectTransform(new Point(GuiFrame.Rect.Width, iconHeight), guiFrameDragHandle.RectTransform, Anchor.TopCenter) { AbsoluteOffset = new Point(0, iconHeight / 2) },
|
||||
style: "GUIDragIndicatorHorizontal");
|
||||
dragIcon.RectTransform.MinSize = new Point(0, iconHeight);
|
||||
|
||||
handle.ValidatePosition = (RectTransform rectT) =>
|
||||
guiFrameDragHandle.ValidatePosition = (RectTransform rectT) =>
|
||||
{
|
||||
var activeHuds = Character.Controlled?.SelectedItem?.ActiveHUDs ?? item.ActiveHUDs;
|
||||
foreach (ItemComponent ic in activeHuds)
|
||||
@@ -624,11 +642,13 @@ namespace Barotrauma.Items.Components
|
||||
//refresh slots to ensure they're rendered at the correct position
|
||||
(ic as ItemContainer)?.Inventory.CreateSlots();
|
||||
}
|
||||
GuiFrameOffset = GuiFrame.RectTransform.ScreenSpaceOffset;
|
||||
guiFrameUpdatePending = true;
|
||||
return true;
|
||||
};
|
||||
|
||||
int buttonHeight = (int)(GUIStyle.ItemFrameMargin.Y * 0.4f);
|
||||
var settingsIcon = new GUIButton(new RectTransform(new Point(buttonHeight), handle.RectTransform, Anchor.TopLeft) { AbsoluteOffset = new Point(buttonHeight / 4), MinSize = new Point(buttonHeight) },
|
||||
var settingsIcon = new GUIButton(new RectTransform(new Point(buttonHeight), guiFrameDragHandle.RectTransform, Anchor.TopLeft) { AbsoluteOffset = new Point(buttonHeight / 4), MinSize = new Point(buttonHeight) },
|
||||
style: "GUIButtonSettings")
|
||||
{
|
||||
OnClicked = (btn, userdata) =>
|
||||
@@ -636,6 +656,14 @@ namespace Barotrauma.Items.Components
|
||||
GUIContextMenu.CreateContextMenu(
|
||||
new ContextMenuOption("item.resetuiposition", isEnabled: true, onSelected: () =>
|
||||
{
|
||||
foreach (var ic in item.Components)
|
||||
{
|
||||
if (ic.GuiFrame != null && ic.GuiFrameOffset != Point.Zero)
|
||||
{
|
||||
ic.GuiFrameOffset = Point.Zero;
|
||||
ic.guiFrameUpdatePending = true;
|
||||
}
|
||||
}
|
||||
if (Character.Controlled?.SelectedItem != null && item != Character.Controlled.SelectedItem)
|
||||
{
|
||||
Character.Controlled.SelectedItem.ForceHUDLayoutUpdate(ignoreLocking: true);
|
||||
@@ -648,7 +676,11 @@ namespace Barotrauma.Items.Components
|
||||
new ContextMenuOption(TextManager.Get(LockGuiFramePosition ? "item.unlockuiposition" : "item.lockuiposition"), isEnabled: true, onSelected: () =>
|
||||
{
|
||||
LockGuiFramePosition = !LockGuiFramePosition;
|
||||
handle.Enabled = !LockGuiFramePosition;
|
||||
guiFrameDragHandle.Enabled = !LockGuiFramePosition;
|
||||
if (SerializableProperties.TryGetValue(nameof(LockGuiFramePosition).ToIdentifier(), out var property))
|
||||
{
|
||||
GameMain.Client?.CreateEntityEvent(Item, new Item.ChangePropertyEventData(property, this));
|
||||
}
|
||||
}));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Barotrauma.Extensions;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using static Barotrauma.Inventory;
|
||||
|
||||
namespace Barotrauma.Items.Components
|
||||
{
|
||||
@@ -97,6 +97,8 @@ namespace Barotrauma.Items.Components
|
||||
partial void InitProjSpecific(ContentXElement element)
|
||||
{
|
||||
slotIcons = new Sprite[capacity];
|
||||
|
||||
int currCapacity = MainContainerCapacity;
|
||||
foreach (var subElement in element.Elements())
|
||||
{
|
||||
switch (subElement.Name.ToString().ToLowerInvariant())
|
||||
@@ -127,6 +129,19 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "subcontainer":
|
||||
int subContainerCapacity = subElement.GetAttributeInt("capacity", 1);
|
||||
var slotIconElement = subElement.GetChildElement("sloticon");
|
||||
if (slotIconElement != null)
|
||||
{
|
||||
var slotIcon = new Sprite(slotIconElement);
|
||||
for (int i = currCapacity; i < currCapacity + subContainerCapacity; i++)
|
||||
{
|
||||
slotIcons[i] = slotIcon;
|
||||
}
|
||||
}
|
||||
currCapacity += subContainerCapacity;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,11 +195,40 @@ namespace Barotrauma.Items.Components
|
||||
};
|
||||
|
||||
LocalizedString labelText = GetUILabel();
|
||||
GUITextBlock label = null;
|
||||
if (!labelText.IsNullOrEmpty())
|
||||
GUITextBlock label = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), content.RectTransform, Anchor.TopCenter),
|
||||
labelText, font: GUIStyle.SubHeadingFont, textAlignment: Alignment.CenterLeft, wrap: true)
|
||||
{
|
||||
IgnoreLayoutGroups = true
|
||||
};
|
||||
|
||||
int buttonSize = GUIStyle.ItemFrameTopBarHeight;
|
||||
Point margin = new Point(buttonSize / 4, buttonSize / 6);
|
||||
|
||||
GUILayoutGroup buttonArea = new GUILayoutGroup(new RectTransform(new Point(GuiFrame.Rect.Width - margin.X * 2, buttonSize - margin.Y * 2), GuiFrame.RectTransform, Anchor.TopCenter) { AbsoluteOffset = new Point(0, margin.Y) },
|
||||
isHorizontal: true, childAnchor: Anchor.TopRight)
|
||||
{
|
||||
label = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), content.RectTransform, Anchor.TopCenter),
|
||||
labelText, font: GUIStyle.SubHeadingFont, textAlignment: Alignment.Center, wrap: true);
|
||||
AbsoluteSpacing = margin.X / 2
|
||||
};
|
||||
if (Inventory.Capacity > 1)
|
||||
{
|
||||
new GUIButton(new RectTransform(Vector2.One, buttonArea.RectTransform, scaleBasis: ScaleBasis.Smallest), style: "SortItemsButton")
|
||||
{
|
||||
ToolTip = TextManager.Get("SortItemsAlphabetically"),
|
||||
OnClicked = (btn, userdata) =>
|
||||
{
|
||||
SortItems();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
new GUIButton(new RectTransform(Vector2.One, buttonArea.RectTransform, scaleBasis: ScaleBasis.Smallest), style: "MergeStacksButton")
|
||||
{
|
||||
ToolTip = TextManager.Get("MergeItemStacks"),
|
||||
OnClicked = (btn, userdata) =>
|
||||
{
|
||||
MergeStacks();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
float minInventoryAreaSize = 0.5f;
|
||||
@@ -215,6 +259,71 @@ namespace Barotrauma.Items.Components
|
||||
Inventory.RectTransform = guiCustomComponent.RectTransform;
|
||||
}
|
||||
|
||||
private void SortItems()
|
||||
{
|
||||
List<List<Item>> itemsPerSlot = new List<List<Item>>();
|
||||
|
||||
for (int i = 0; i < Inventory.Capacity; i++)
|
||||
{
|
||||
var items = Inventory.GetItemsAt(i).ToList();
|
||||
if (items.Any())
|
||||
{
|
||||
itemsPerSlot.Add(items);
|
||||
items.ForEach(it => it.Drop(dropper: null, createNetworkEvent: false, setTransform: false));
|
||||
}
|
||||
}
|
||||
|
||||
itemsPerSlot.Sort((i1, i2) => i1.First().Name.CompareTo(i2.First().Name));
|
||||
foreach (var items in itemsPerSlot)
|
||||
{
|
||||
int firstFreeSlot = -1;
|
||||
for (int i = 0; i < Inventory.Capacity; i++)
|
||||
{
|
||||
if (Inventory.GetItemAt(i) == null && Inventory.CanBePut(items.First()))
|
||||
{
|
||||
firstFreeSlot = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (firstFreeSlot == -1)
|
||||
{
|
||||
items.ForEach(it => it.Drop(dropper: null));
|
||||
continue;
|
||||
}
|
||||
foreach (var item in items)
|
||||
{
|
||||
if (!Inventory.TryPutItem(item, firstFreeSlot, allowSwapping: false, allowCombine: false, user: null, createNetworkEvent: false))
|
||||
{
|
||||
//if putting in the specific slot fails (prevented by containable restrictions?), just put in the first free slot
|
||||
if (!Inventory.TryPutItem(item, user: null, createNetworkEvent: false))
|
||||
{
|
||||
item.Drop(dropper: null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Inventory.CreateNetworkEvent();
|
||||
}
|
||||
|
||||
private void MergeStacks()
|
||||
{
|
||||
for (int i = Inventory.Capacity - 1; i >= 0; i--)
|
||||
{
|
||||
var items = Inventory.GetItemsAt(i).ToList();
|
||||
if (items.None()) { continue; }
|
||||
//find the first stack we can put the item in
|
||||
for (int j = 0; j < i; j++)
|
||||
{
|
||||
if (Inventory.GetItemsAt(j).Any() && Inventory.CanBePutInSlot(items.First(), j))
|
||||
{
|
||||
items.ForEach(it => Inventory.TryPutItem(it, j, allowSwapping: false, allowCombine: false, user: null, createNetworkEvent: false));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Inventory.CreateNetworkEvent();
|
||||
}
|
||||
|
||||
public LocalizedString GetUILabel()
|
||||
{
|
||||
if (UILabel == string.Empty) { return string.Empty; }
|
||||
@@ -277,7 +386,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
int ignoredItemCount = 0;
|
||||
var subContainableItems = AllSubContainableItems;
|
||||
float targetSlotCapacity = GetMaxStackSize(targetSlot);
|
||||
float targetSlotCapacity = Math.Min(containedItem.Prefab.MaxStackSize, GetMaxStackSize(targetSlot));
|
||||
float capacity = targetSlotCapacity * MainContainerCapacity;
|
||||
if (subContainableItems != null)
|
||||
{
|
||||
@@ -310,29 +419,36 @@ namespace Barotrauma.Items.Components
|
||||
int itemCount = Inventory.AllItems.Count() - ignoredItemCount;
|
||||
return Math.Min(itemCount / Math.Max(capacity, 1), 1);
|
||||
}
|
||||
|
||||
//display the state of an item in a specific slot
|
||||
if (Inventory.Capacity == 1 || ContainedStateIndicatorSlot > -1)
|
||||
{
|
||||
if (containedItem == null) { return 0.0f; }
|
||||
//if the contained item has some contained state indicator, show that
|
||||
if (containedItem.GetComponent<ItemContainer>() is { ShowContainedStateIndicator: true } containedItemContainer)
|
||||
{
|
||||
return containedItemContainer.GetContainedIndicatorState();
|
||||
}
|
||||
int maxStackSize = Math.Min(containedItem.Prefab.GetMaxStackSize(Inventory), GetMaxStackSize(targetSlot));
|
||||
if (maxStackSize == 1)
|
||||
{
|
||||
return containedItem.Condition / containedItem.MaxCondition;
|
||||
}
|
||||
return containedItems.Count() / (float)maxStackSize;
|
||||
}
|
||||
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;
|
||||
}
|
||||
return Inventory.EmptySlotCount / (float)Inventory.Capacity;
|
||||
}
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing = false, float itemDepth = -1)
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing = false, float itemDepth = -1, Color? overrideColor = null)
|
||||
{
|
||||
if (hideItems || (item.body != null && !item.body.Enabled)) { return; }
|
||||
DrawContainedItems(spriteBatch, itemDepth);
|
||||
DrawContainedItems(spriteBatch, itemDepth, overrideColor);
|
||||
}
|
||||
|
||||
public void DrawContainedItems(SpriteBatch spriteBatch, float itemDepth)
|
||||
public void DrawContainedItems(SpriteBatch spriteBatch, float itemDepth, Color? overrideColor = null)
|
||||
{
|
||||
Vector2 transformedItemPos = ItemPos * item.Scale;
|
||||
Vector2 transformedItemInterval = ItemInterval * item.Scale;
|
||||
@@ -388,7 +504,7 @@ namespace Barotrauma.Items.Components
|
||||
bool isWiringMode = SubEditorScreen.TransparentWiringMode && SubEditorScreen.IsWiringMode();
|
||||
|
||||
int i = 0;
|
||||
foreach (DrawableContainedItem contained in drawableContainedItems)
|
||||
foreach (ContainedItem contained in containedItems)
|
||||
{
|
||||
Vector2 itemPos = currentItemPos;
|
||||
|
||||
@@ -466,7 +582,7 @@ namespace Barotrauma.Items.Components
|
||||
contained.Item.Sprite.Draw(
|
||||
spriteBatch,
|
||||
new Vector2(itemPos.X, -itemPos.Y),
|
||||
isWiringMode ? contained.Item.GetSpriteColor(withHighlight: true) * 0.15f : contained.Item.GetSpriteColor(withHighlight: true),
|
||||
overrideColor ?? (isWiringMode ? contained.Item.GetSpriteColor(withHighlight: true) * 0.15f : contained.Item.GetSpriteColor(withHighlight: true)),
|
||||
origin,
|
||||
-(contained.Item.body == null ? 0.0f : contained.Item.body.DrawRotation),
|
||||
contained.Item.Scale,
|
||||
@@ -476,7 +592,7 @@ namespace Barotrauma.Items.Components
|
||||
foreach (ItemContainer ic in contained.Item.GetComponents<ItemContainer>())
|
||||
{
|
||||
if (ic.hideItems) { continue; }
|
||||
ic.DrawContainedItems(spriteBatch, containedSpriteDepth);
|
||||
ic.DrawContainedItems(spriteBatch, containedSpriteDepth, overrideColor);
|
||||
}
|
||||
|
||||
i++;
|
||||
@@ -497,7 +613,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
public override void UpdateHUD(Character character, float deltaTime, Camera cam)
|
||||
public override void UpdateHUDComponentSpecific(Character character, float deltaTime, Camera cam)
|
||||
{
|
||||
if (!item.IsInteractable(character)) { return; }
|
||||
if (Inventory.RectTransform != null)
|
||||
@@ -512,19 +628,10 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
//if the item is in the character's inventory, no need to update the item's inventory
|
||||
//because the player can see it by hovering the cursor over the item
|
||||
guiCustomComponent.Visible = DrawInventory && item.ParentInventory?.Owner != character;
|
||||
guiCustomComponent.Visible = DrawInventory && (item.ParentInventory?.Owner != character || Inventory.DrawWhenEquipped);
|
||||
if (!guiCustomComponent.Visible) { return; }
|
||||
|
||||
Inventory.Update(deltaTime, cam);
|
||||
}
|
||||
|
||||
/*public override void DrawHUD(SpriteBatch spriteBatch, Character character)
|
||||
{
|
||||
//if the item is in the character's inventory, no need to draw the item's inventory
|
||||
//because the player can see it by hovering the cursor over the item
|
||||
if (item.ParentInventory?.Owner == character || !DrawInventory) return;
|
||||
|
||||
Inventory.Draw(spriteBatch);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -311,7 +311,7 @@ namespace Barotrauma.Items.Components
|
||||
prevRect = item.Rect;
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing = false, float itemDepth = -1)
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing = false, float itemDepth = -1, Color? overrideColor = null)
|
||||
{
|
||||
if (item.ParentInventory != null) { return; }
|
||||
if (editing)
|
||||
|
||||
@@ -19,13 +19,14 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
private Sprite backgroundSprite;
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing, float itemDepth = -1)
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing, float itemDepth = -1, Color? overrideColor = null)
|
||||
{
|
||||
if (backgroundSprite == null) { return; }
|
||||
|
||||
backgroundSprite.DrawTiled(spriteBatch,
|
||||
new Vector2(item.DrawPosition.X - item.Rect.Width / 2 * item.Scale, -(item.DrawPosition.Y + item.Rect.Height / 2)) - backgroundSprite.Origin * item.Scale,
|
||||
new Vector2(backgroundSprite.size.X * item.Scale, item.Rect.Height), color: item.Color,
|
||||
new Vector2(backgroundSprite.size.X * item.Scale, item.Rect.Height),
|
||||
color: overrideColor ?? item.Color,
|
||||
textureScale: Vector2.One * item.Scale,
|
||||
depth: BackgroundSpriteDepth);
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing = false, float itemDepth = -1)
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing = false, float itemDepth = -1, Color? overrideColor = null)
|
||||
{
|
||||
if (Light?.LightSprite == null) { return; }
|
||||
if ((item.body == null || item.body.Enabled) && lightBrightness > 0.0f && IsOn && Light.Enabled)
|
||||
|
||||
@@ -428,7 +428,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
public override void UpdateHUD(Character character, float deltaTime, Camera cam)
|
||||
public override void UpdateHUDComponentSpecific(Character character, float deltaTime, Camera cam)
|
||||
{
|
||||
inSufficientPowerWarning.Visible = IsActive && !hasPower;
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
public override void UpdateHUD(Character character, float deltaTime, Camera cam)
|
||||
public override void UpdateHUDComponentSpecific(Character character, float deltaTime, Camera cam)
|
||||
{
|
||||
powerIndicator.Selected = hasPower && IsActive;
|
||||
autoControlIndicator.Selected = controlLockTimer > 0.0f;
|
||||
@@ -138,14 +138,14 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing, float itemDepth = -1)
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing, float itemDepth = -1, Color? overrideColor = null)
|
||||
{
|
||||
if (propellerSprite != null)
|
||||
{
|
||||
Vector2 drawPos = item.DrawPosition;
|
||||
drawPos += PropellerPos;
|
||||
drawPos.Y = -drawPos.Y;
|
||||
propellerSprite.Draw(spriteBatch, (int)Math.Floor(spriteIndex), drawPos, Color.White, propellerSprite.Origin, 0.0f, Vector2.One);
|
||||
propellerSprite.Draw(spriteBatch, (int)Math.Floor(spriteIndex), drawPos, overrideColor ?? Color.White, propellerSprite.Origin, 0.0f, Vector2.One);
|
||||
}
|
||||
|
||||
if (editing && !DisablePropellerDamage && propellerDamage != null && !GUI.DisableHUD)
|
||||
|
||||
@@ -38,6 +38,11 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
private FabricationRecipe selectedItem;
|
||||
|
||||
/// <summary>
|
||||
/// Which character's skills the current view is displayed based on
|
||||
/// </summary>
|
||||
private Character displayingForCharacter;
|
||||
|
||||
public Identifier SelectedItemIdentifier => SelectedItem?.TargetItem.Identifier ?? Identifier.Empty;
|
||||
|
||||
private GUIComponent inSufficientPowerWarning;
|
||||
@@ -358,9 +363,11 @@ namespace Barotrauma.Items.Components
|
||||
if (inputInventoryHolder != null)
|
||||
{
|
||||
inputContainer.AllowUIOverlap = true;
|
||||
inputContainer.Inventory.DrawWhenEquipped = true;
|
||||
inputContainer.Inventory.RectTransform = inputInventoryHolder.RectTransform;
|
||||
}
|
||||
outputContainer.AllowUIOverlap = true;
|
||||
outputContainer.Inventory.DrawWhenEquipped = true;
|
||||
outputContainer.Inventory.RectTransform = outputInventoryHolder.RectTransform;
|
||||
}
|
||||
|
||||
@@ -453,13 +460,8 @@ namespace Barotrauma.Items.Components
|
||||
requiresRecipeText.RectTransform.RepositionChildInHierarchy(itemList.Content.RectTransform.GetChildIndex(firstRequiresRecipe.RectTransform));
|
||||
}
|
||||
|
||||
FilterEntities(selectedItemCategory, itemFilterBox?.Text ?? string.Empty);
|
||||
HideEmptyItemListCategories();
|
||||
|
||||
if (selectedItem != null)
|
||||
{
|
||||
//reselect to recreate the info based on the new user's skills
|
||||
SelectItem(character, selectedItem);
|
||||
}
|
||||
}
|
||||
|
||||
private readonly Dictionary<FabricationRecipe.RequiredItem, int> missingIngredientCounts = new Dictionary<FabricationRecipe.RequiredItem, int>();
|
||||
@@ -538,6 +540,8 @@ namespace Barotrauma.Items.Components
|
||||
int slotIndex = 0;
|
||||
foreach (var kvp in missingIngredientCounts)
|
||||
{
|
||||
if (inputContainer.Inventory?.visualSlots == null) { break; }
|
||||
|
||||
var requiredItem = kvp.Key;
|
||||
int missingCount = kvp.Value;
|
||||
|
||||
@@ -560,11 +564,10 @@ namespace Barotrauma.Items.Components
|
||||
var requiredItemPrefab = requiredItem.FirstMatchingPrefab;
|
||||
|
||||
float iconAlpha = 0.0f;
|
||||
ItemPrefab requiredItemToDisplay;
|
||||
int count = requiredItem.ItemPrefabs.Count();
|
||||
if (count > 1)
|
||||
ItemPrefab requiredItemToDisplay = requiredItem.DefaultItem.IsEmpty ? null : requiredItem.ItemPrefabs.FirstOrDefault(p => p.Identifier == requiredItem.DefaultItem);
|
||||
if (requiredItemToDisplay == null && requiredItem.ItemPrefabs.Multiple())
|
||||
{
|
||||
float iconCycleSpeed = 0.5f / count;
|
||||
float iconCycleSpeed = 0.75f;
|
||||
float iconCycleT = (float)Timing.TotalTime * iconCycleSpeed;
|
||||
int iconIndex = (int)(iconCycleT % requiredItem.ItemPrefabs.Count());
|
||||
|
||||
@@ -573,7 +576,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
else
|
||||
{
|
||||
requiredItemToDisplay = requiredItem.ItemPrefabs.FirstOrDefault();
|
||||
requiredItemToDisplay ??= requiredItem.ItemPrefabs.FirstOrDefault();
|
||||
iconAlpha = 1.0f;
|
||||
}
|
||||
if (iconAlpha > 0.0f)
|
||||
@@ -616,9 +619,12 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
if (slotRect.Contains(PlayerInput.MousePosition))
|
||||
{
|
||||
var suitableIngredients = requiredItem.ItemPrefabs.Select(ip => ip.Name).Distinct();
|
||||
LocalizedString toolTipText = string.Join(", ", suitableIngredients.Count() > 3 ? suitableIngredients.SkipLast(suitableIngredients.Count() - 3) : suitableIngredients);
|
||||
if (suitableIngredients.Count() > 3) { toolTipText += "..."; }
|
||||
LocalizedString toolTipText = requiredItem.OverrideHeader;
|
||||
if (requiredItem.OverrideHeader.IsNullOrEmpty())
|
||||
{
|
||||
var suitableIngredients = requiredItem.ItemPrefabs.Where(ip => !ip.HideInMenus).OrderBy(ip => ip.DefaultPrice?.Price ?? 0).Select(ip => ip.Name).Distinct();
|
||||
toolTipText = GetSuitableIngredientText(suitableIngredients);
|
||||
}
|
||||
if (requiredItem.UseCondition && requiredItem.MinCondition < 1.0f)
|
||||
{
|
||||
toolTipText += " " + (int)Math.Round(requiredItem.MinCondition * 100) + "%";
|
||||
@@ -656,15 +662,68 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
private LocalizedString GetSuitableIngredientText(IEnumerable<LocalizedString> itemNameList)
|
||||
{
|
||||
int count = itemNameList.Count();
|
||||
if (count == 0)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
else if (count == 1)
|
||||
{
|
||||
return itemNameList.First();
|
||||
}
|
||||
else if (count == 2)
|
||||
{
|
||||
//[item1] or [item2]
|
||||
return TextManager.GetWithVariables(
|
||||
"DialogRequiredTreatmentOptionsLast",
|
||||
("[treatment1]", itemNameList.ElementAt(0)),
|
||||
("[treatment2]", itemNameList.ElementAt(1)));
|
||||
}
|
||||
else
|
||||
{
|
||||
// [item1], [item2], [item3] ... or [lastitem]
|
||||
LocalizedString itemListStr = TextManager.GetWithVariables(
|
||||
"DialogRequiredTreatmentOptionsFirst",
|
||||
("[treatment1]", itemNameList.ElementAt(0)),
|
||||
("[treatment2]", itemNameList.ElementAt(1)));
|
||||
|
||||
int i;
|
||||
bool isTruncated = false;
|
||||
for (i = 2; i < count - 1; i++)
|
||||
{
|
||||
if (itemListStr.Length > 50)
|
||||
{
|
||||
isTruncated = true;
|
||||
break;
|
||||
}
|
||||
itemListStr = TextManager.GetWithVariables(
|
||||
"DialogRequiredTreatmentOptionsFirst",
|
||||
("[treatment1]", itemListStr),
|
||||
("[treatment2]", itemNameList.ElementAt(i)));
|
||||
}
|
||||
itemListStr = TextManager.GetWithVariables(
|
||||
"DialogRequiredTreatmentOptionsLast",
|
||||
("[treatment1]", itemListStr),
|
||||
("[treatment2]", itemNameList.ElementAt(i)));
|
||||
|
||||
if (isTruncated)
|
||||
{
|
||||
itemListStr += TextManager.Get("ellipsis");
|
||||
}
|
||||
return itemListStr;
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawOutputOverLay(SpriteBatch spriteBatch, GUICustomComponent overlayComponent)
|
||||
{
|
||||
overlayComponent.RectTransform.SetAsLastChild();
|
||||
|
||||
FabricationRecipe targetItem = fabricatedItem ?? selectedItem;
|
||||
if (targetItem != null)
|
||||
if (targetItem != null && outputContainer.Inventory?.visualSlots != null)
|
||||
{
|
||||
Rectangle slotRect = outputContainer.Inventory.visualSlots[0].Rect;
|
||||
|
||||
if (fabricatedItem != null)
|
||||
{
|
||||
float clampedProgressState = Math.Clamp(progressState, 0f, 1f);
|
||||
@@ -699,6 +758,16 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
FabricationRecipe recipe = child.UserData as FabricationRecipe;
|
||||
if (recipe?.DisplayName == null) { continue; }
|
||||
|
||||
if (recipe.HideForNonTraitors)
|
||||
{
|
||||
if (Character.Controlled is not { IsTraitor: true })
|
||||
{
|
||||
child.Visible = false;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
child.Visible =
|
||||
(string.IsNullOrWhiteSpace(filter) || recipe.DisplayName.Contains(filter, StringComparison.OrdinalIgnoreCase)) &&
|
||||
(!category.HasValue || recipe.TargetItem.Category.HasFlag(category.Value));
|
||||
@@ -749,8 +818,9 @@ namespace Barotrauma.Items.Components
|
||||
private bool SelectItem(Character user, FabricationRecipe selectedItem, float? overrideRequiredTime = null)
|
||||
{
|
||||
this.selectedItem = selectedItem;
|
||||
displayingForCharacter = user;
|
||||
|
||||
int max = Math.Max(selectedItem.TargetItem.MaxStackSize / selectedItem.Amount, 1);
|
||||
int max = Math.Max(selectedItem.TargetItem.GetMaxStackSize(outputContainer.Inventory) / selectedItem.Amount, 1);
|
||||
|
||||
if (amountInput != null)
|
||||
{
|
||||
@@ -924,7 +994,7 @@ namespace Barotrauma.Items.Components
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void UpdateHUD(Character character, float deltaTime, Camera cam)
|
||||
public override void UpdateHUDComponentSpecific(Character character, float deltaTime, Camera cam)
|
||||
{
|
||||
activateButton.Enabled = false;
|
||||
inSufficientPowerWarning.Visible = IsActive && !hasPower;
|
||||
@@ -933,6 +1003,12 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
if (!IsActive)
|
||||
{
|
||||
if (selectedItem != null && displayingForCharacter != character)
|
||||
{
|
||||
//reselect to recreate the info based on the new user's skills
|
||||
SelectItem(character, selectedItem);
|
||||
}
|
||||
|
||||
//only check ingredients if the fabricator isn't active (if it is, this is done in Update)
|
||||
if (refreshIngredientsTimer <= 0.0f)
|
||||
{
|
||||
@@ -998,9 +1074,13 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
fabricationLimits[msg.ReadUInt32()] = 0;
|
||||
}
|
||||
|
||||
State = newState;
|
||||
this.amountToFabricate = amountToFabricate;
|
||||
//don't touch the amount unless another character changed it or the fabricator is running
|
||||
//otherwise we may end up reverting the changes the client just did to the amount
|
||||
if ((user != null && user != Character.Controlled) || State != FabricatorState.Stopped)
|
||||
{
|
||||
this.amountToFabricate = amountToFabricate;
|
||||
}
|
||||
this.amountRemaining = amountRemaining;
|
||||
if (newState == FabricatorState.Stopped || recipeHash == 0)
|
||||
{
|
||||
|
||||
@@ -295,7 +295,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
OrderPrefab[] reports = OrderPrefab.Prefabs.Where(o => o.IsReport && o.SymbolSprite != null && !o.Hidden).OrderBy(o => o.Identifier).ToArray();
|
||||
OrderPrefab[] reports = OrderPrefab.Prefabs.Where(o => o.IsVisibleAsReportButton).OrderBy(o => o.Identifier).ToArray();
|
||||
|
||||
GUIFrame bottomFrame = new GUIFrame(new RectTransform(new Vector2(0.5f, 0.15f), paddedContainer.RectTransform, Anchor.BottomCenter) { MaxSize = new Point(int.MaxValue, GUI.IntScale(40)) }, style: null)
|
||||
{
|
||||
@@ -350,10 +350,16 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
};
|
||||
|
||||
List<ItemPrefab> shownItemPrefabs = new List<ItemPrefab>();
|
||||
foreach (ItemPrefab prefab in ItemPrefab.Prefabs.OrderBy(prefab => prefab.Name))
|
||||
{
|
||||
if (prefab.HideInMenus) { continue; }
|
||||
if (shownItemPrefabs.Any(ip => DisplayAsSameItem(ip, prefab)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
CreateItemFrame(prefab, listBox.Content.RectTransform);
|
||||
shownItemPrefabs.Add(prefab);
|
||||
}
|
||||
|
||||
searchBar.OnDeselected += (sender, key) =>
|
||||
@@ -398,6 +404,27 @@ namespace Barotrauma.Items.Components
|
||||
new Point(int.MaxValue, paddedContainer.Rect.Height - bottomFrame.Rect.Height - buttonLayout.Rect.Height);
|
||||
}
|
||||
|
||||
private static Sprite GetPreviewSprite(ItemPrefab prefab)
|
||||
{
|
||||
return prefab.InventoryIcon ?? prefab.Sprite;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If the items have an identical name and icon (e.g. a variant with an alternative fabrication/deconstruction recipe),
|
||||
/// they're displayed as if they were the same item, not as two separate entries.
|
||||
/// </summary>
|
||||
private static bool DisplayAsSameItem(ItemPrefab prefab1, ItemPrefab prefab2)
|
||||
{
|
||||
if (prefab1 == prefab2) { return true; }
|
||||
if (prefab1.Name == prefab2.Name)
|
||||
{
|
||||
var sprite1 = GetPreviewSprite(prefab1);
|
||||
var sprite2 = GetPreviewSprite(prefab2);
|
||||
return sprite1?.FullPath == sprite2?.FullPath && sprite1?.SourceRect == sprite2?.SourceRect;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool VisibleOnItemFinder(Item it)
|
||||
{
|
||||
if (it?.Submarine == null) { return false; }
|
||||
@@ -413,7 +440,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
if (it.Container?.GetComponent<ItemContainer>() is { DrawInventory: false } or { AllowAccess: false }) { return false; }
|
||||
|
||||
if (it.HasTag("traitormissionitem")) { return false; }
|
||||
if (it.HasTag(Tags.TraitorMissionItem)) { return false; }
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -539,13 +566,13 @@ namespace Barotrauma.Items.Components
|
||||
displayedSubs.Add(item.Submarine);
|
||||
displayedSubs.AddRange(item.Submarine.DockedTo.Where(s => s.TeamID == item.Submarine.TeamID));
|
||||
|
||||
subEntities = MapEntity.mapEntityList.Where(me => (item.Submarine is { } sub && sub.IsEntityFoundOnThisSub(me, includingConnectedSubs: true, allowDifferentType: false)) && !me.HiddenInGame).OrderByDescending(w => w.SpriteDepth).ToList();
|
||||
subEntities = MapEntity.MapEntityList.Where(me => (item.Submarine is { } sub && sub.IsEntityFoundOnThisSub(me, includingConnectedSubs: true, allowDifferentType: false)) && !me.HiddenInGame).OrderByDescending(w => w.SpriteDepth).ToList();
|
||||
|
||||
BakeSubmarine(item.Submarine, parentRect);
|
||||
elementSize = GuiFrame.Rect.Size;
|
||||
}
|
||||
|
||||
public override void UpdateHUD(Character character, float deltaTime, Camera cam)
|
||||
public override void UpdateHUDComponentSpecific(Character character, float deltaTime, Camera cam)
|
||||
{
|
||||
//recreate HUD if the subs we should display have changed
|
||||
if (item.Submarine == null && displayedSubs.Count > 0 || // item not inside a sub anymore, but display is still showing subs
|
||||
@@ -824,7 +851,8 @@ namespace Barotrauma.Items.Components
|
||||
foreach (GUIComponent component in listBox.Content.Children)
|
||||
{
|
||||
component.Visible = false;
|
||||
if (component.UserData is ItemPrefab { Name: { } prefabName} prefab && itemsFoundOnSub.Contains(prefab))
|
||||
if (component.UserData is ItemPrefab { Name: { } prefabName} prefab &&
|
||||
(itemsFoundOnSub.Contains(prefab) || itemsFoundOnSub.Any(ip => DisplayAsSameItem(ip, prefab))))
|
||||
{
|
||||
component.Visible = prefabName.ToLower().Contains(text.ToLower());
|
||||
|
||||
@@ -851,9 +879,9 @@ namespace Barotrauma.Items.Components
|
||||
tooltip.RectTransform.ScreenSpaceOffset = new Point(box.Rect.X, box.Rect.Y - height);
|
||||
}
|
||||
|
||||
private void CreateItemFrame(ItemPrefab prefab, RectTransform parent)
|
||||
private static void CreateItemFrame(ItemPrefab prefab, RectTransform parent)
|
||||
{
|
||||
Sprite sprite = prefab.InventoryIcon ?? prefab.Sprite;
|
||||
Sprite sprite = GetPreviewSprite(prefab);
|
||||
if (sprite is null) { return; }
|
||||
GUIFrame frame = new GUIFrame(new RectTransform(new Vector2(1f, 0.25f), parent), style: "ListBoxElement")
|
||||
{
|
||||
@@ -899,7 +927,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
if (!VisibleOnItemFinder(it)) { continue; }
|
||||
|
||||
if (it.Prefab == searchedPrefab)
|
||||
if (DisplayAsSameItem(it.Prefab, searchedPrefab))
|
||||
{
|
||||
// ignore items on players and hidden inventories
|
||||
if (it.FindParentInventory(inv => inv is CharacterInventory || inv is ItemInventory { Owner: Item { HiddenInGame: true }}) is { }) { continue; }
|
||||
@@ -1079,7 +1107,7 @@ namespace Barotrauma.Items.Components
|
||||
if (ShowHullIntegrity)
|
||||
{
|
||||
float amount = 1f + hullData.LinkedHulls.Count;
|
||||
gapOpenSum = hull.ConnectedGaps.Concat(hullData.LinkedHulls.SelectMany(h => h.ConnectedGaps)).Where(g => !g.IsRoomToRoom && !g.HiddenInGame).Sum(g => g.Open) / amount;
|
||||
gapOpenSum = hull.ConnectedGaps.Concat(hullData.LinkedHulls.SelectMany(h => h.ConnectedGaps)).Where(g => g.linkedTo.Count == 1 && !g.HiddenInGame).Sum(g => g.Open) / amount;
|
||||
borderColor = Color.Lerp(neutralColor, GUIStyle.Red, Math.Min(gapOpenSum, 1.0f));
|
||||
}
|
||||
|
||||
|
||||
@@ -181,7 +181,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
private float flickerTimer;
|
||||
private readonly float flickerFrequency = 1;
|
||||
public override void UpdateHUD(Character character, float deltaTime, Camera cam)
|
||||
public override void UpdateHUDComponentSpecific(Character character, float deltaTime, Camera cam)
|
||||
{
|
||||
autoControlIndicator.Selected = IsAutoControlled;
|
||||
PowerButton.Enabled = isActiveLockTimer <= 0.0f;
|
||||
|
||||
@@ -615,7 +615,7 @@ namespace Barotrauma.Items.Components
|
||||
turbineOutputMeter, TurbineOutput, new Vector2(0.0f, 100.0f), clampedOptimalTurbineOutput, clampedAllowedTurbineOutput);
|
||||
}
|
||||
|
||||
public override void UpdateHUD(Character character, float deltaTime, Camera cam)
|
||||
public override void UpdateHUDComponentSpecific(Character character, float deltaTime, Camera cam)
|
||||
{
|
||||
IsActive = true;
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ namespace Barotrauma.Items.Components
|
||||
},
|
||||
{
|
||||
BlipType.Destructible,
|
||||
new Color[] { Color.TransparentBlack, new Color(74, 113, 75) * 0.8f, new Color(151, 236, 172) * 0.8f, new Color(153, 217, 234) * 0.8f }
|
||||
new Color[] { Color.TransparentBlack, new Color(94, 114, 73) * 0.8f, new Color(255, 236, 151) * 0.8f, new Color(242, 243, 194) * 0.8f }
|
||||
},
|
||||
{
|
||||
BlipType.Door,
|
||||
@@ -358,11 +358,6 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
protected override void TryCreateDragHandle()
|
||||
{
|
||||
base.TryCreateDragHandle();
|
||||
}
|
||||
|
||||
private void SetPingDirection(Vector2 direction)
|
||||
{
|
||||
pingDirection = direction;
|
||||
@@ -471,7 +466,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
public override void UpdateHUD(Character character, float deltaTime, Camera cam)
|
||||
public override void UpdateHUDComponentSpecific(Character character, float deltaTime, Camera cam)
|
||||
{
|
||||
showDirectionalIndicatorTimer -= deltaTime;
|
||||
if (GameMain.Client != null)
|
||||
@@ -981,38 +976,41 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
if (GameMain.GameSession == null || Level.Loaded == null) { return; }
|
||||
if (GameMain.GameSession == null) { return; }
|
||||
|
||||
if (Level.Loaded.StartLocation?.Type is { ShowSonarMarker: true })
|
||||
if (Level.Loaded != null)
|
||||
{
|
||||
DrawMarker(spriteBatch,
|
||||
Level.Loaded.StartLocation.Name,
|
||||
(Level.Loaded.StartOutpost != null ? "outpost" : "location").ToIdentifier(),
|
||||
"startlocation",
|
||||
Level.Loaded.StartExitPosition, transducerCenter,
|
||||
displayScale, center, DisplayRadius);
|
||||
}
|
||||
if (Level.Loaded.StartLocation?.Type is { ShowSonarMarker: true })
|
||||
{
|
||||
DrawMarker(spriteBatch,
|
||||
Level.Loaded.StartLocation.Name,
|
||||
(Level.Loaded.StartOutpost != null ? "outpost" : "location").ToIdentifier(),
|
||||
"startlocation",
|
||||
Level.Loaded.StartExitPosition, transducerCenter,
|
||||
displayScale, center, DisplayRadius);
|
||||
}
|
||||
|
||||
if (Level.Loaded is { EndLocation.Type.ShowSonarMarker: true, Type: LevelData.LevelType.LocationConnection })
|
||||
{
|
||||
DrawMarker(spriteBatch,
|
||||
Level.Loaded.EndLocation.Name,
|
||||
(Level.Loaded.EndOutpost != null ? "outpost" : "location").ToIdentifier(),
|
||||
"endlocation",
|
||||
Level.Loaded.EndExitPosition, transducerCenter,
|
||||
displayScale, center, DisplayRadius);
|
||||
}
|
||||
if (Level.Loaded is { EndLocation.Type.ShowSonarMarker: true, Type: LevelData.LevelType.LocationConnection })
|
||||
{
|
||||
DrawMarker(spriteBatch,
|
||||
Level.Loaded.EndLocation.Name,
|
||||
(Level.Loaded.EndOutpost != null ? "outpost" : "location").ToIdentifier(),
|
||||
"endlocation",
|
||||
Level.Loaded.EndExitPosition, transducerCenter,
|
||||
displayScale, center, DisplayRadius);
|
||||
}
|
||||
|
||||
for (int i = 0; i < Level.Loaded.Caves.Count; i++)
|
||||
{
|
||||
var cave = Level.Loaded.Caves[i];
|
||||
if (!cave.DisplayOnSonar) { continue; }
|
||||
DrawMarker(spriteBatch,
|
||||
caveLabel.Value,
|
||||
"cave".ToIdentifier(),
|
||||
"cave" + i,
|
||||
cave.StartPos.ToVector2(), transducerCenter,
|
||||
displayScale, center, DisplayRadius);
|
||||
for (int i = 0; i < Level.Loaded.Caves.Count; i++)
|
||||
{
|
||||
var cave = Level.Loaded.Caves[i];
|
||||
if (cave.MissionsToDisplayOnSonar.None()) { continue; }
|
||||
DrawMarker(spriteBatch,
|
||||
caveLabel.Value,
|
||||
"cave".ToIdentifier(),
|
||||
"cave" + i,
|
||||
cave.StartPos.ToVector2(), transducerCenter,
|
||||
displayScale, center, DisplayRadius);
|
||||
}
|
||||
}
|
||||
|
||||
int missionIndex = 0;
|
||||
@@ -1070,7 +1068,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
if (!sub.ShowSonarMarker) { continue; }
|
||||
if (connectedSubs.Contains(sub)) { continue; }
|
||||
if (sub.WorldPosition.Y > Level.Loaded.Size.Y) { continue; }
|
||||
if (Level.Loaded != null && sub.WorldPosition.Y > Level.Loaded.Size.Y) { continue; }
|
||||
|
||||
if (item.Submarine != null || Character.Controlled != null)
|
||||
{
|
||||
|
||||
@@ -532,6 +532,22 @@ namespace Barotrauma.Items.Components
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Map the rectangular steering vector to a circular area using FG-Squircular Mapping which preserves the angle of the vector.
|
||||
/// </summary>
|
||||
private static Vector2 MapSquareToCircle(Vector2 steeringVector)
|
||||
{
|
||||
float xSqr = steeringVector.X * steeringVector.X;
|
||||
float ySqr = steeringVector.Y * steeringVector.Y;
|
||||
float length = MathF.Sqrt(ySqr + xSqr);
|
||||
if (MathUtils.NearlyEqual(length, 0.0f)) { return Vector2.Zero; }
|
||||
|
||||
//FG-Squircular mapping formula from https://arxiv.org/ftp/arxiv/papers/1509/1509.06344.pdf
|
||||
float x = steeringVector.X * MathF.Sqrt(xSqr + ySqr - xSqr * ySqr) / length;
|
||||
float y = steeringVector.Y * MathF.Sqrt(xSqr + ySqr - xSqr * ySqr) / length;
|
||||
return new Vector2(x, y);
|
||||
}
|
||||
|
||||
public void DrawHUD(SpriteBatch spriteBatch, Rectangle rect)
|
||||
{
|
||||
int width = rect.Width, height = rect.Height;
|
||||
@@ -545,11 +561,9 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
if (!AutoPilot)
|
||||
{
|
||||
Vector2 unitSteeringInput = steeringInput / 100.0f;
|
||||
//map input from rectangle to circle
|
||||
Vector2 steeringInputPos = new Vector2(
|
||||
steeringInput.X * (float)Math.Sqrt(1.0f - 0.5f * unitSteeringInput.Y * unitSteeringInput.Y),
|
||||
-steeringInput.Y * (float)Math.Sqrt(1.0f - 0.5f * unitSteeringInput.X * unitSteeringInput.X));
|
||||
Vector2 steeringInputPos = MapSquareToCircle(steeringInput / 100f) * 100.0f;
|
||||
steeringInputPos.Y = -steeringInputPos.Y;
|
||||
steeringInputPos += steeringOrigin;
|
||||
|
||||
if (steeringIndicator != null)
|
||||
@@ -604,10 +618,8 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
|
||||
//map velocity from rectangle to circle
|
||||
Vector2 unitTargetVel = targetVelocity / 100.0f;
|
||||
Vector2 steeringPos = new Vector2(
|
||||
targetVelocity.X * 0.9f * (float)Math.Sqrt(1.0f - 0.5f * unitTargetVel.Y * unitTargetVel.Y),
|
||||
-targetVelocity.Y * 0.9f * (float)Math.Sqrt(1.0f - 0.5f * unitTargetVel.X * unitTargetVel.X));
|
||||
Vector2 steeringPos = MapSquareToCircle(targetVelocity / 100f) * 90.0f;
|
||||
steeringPos.Y = -steeringPos.Y;
|
||||
steeringPos += steeringOrigin;
|
||||
|
||||
if (steeringIndicator != null)
|
||||
@@ -682,7 +694,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
public override void UpdateHUD(Character character, float deltaTime, Camera cam)
|
||||
public override void UpdateHUDComponentSpecific(Character character, float deltaTime, Camera cam)
|
||||
{
|
||||
if (swapDestinationOrder == null)
|
||||
{
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing, float itemDepth = -1)
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing, float itemDepth = -1, Color? overrideColor = null)
|
||||
{
|
||||
for (var i = 0; i < GrowableSeeds.Length; i++)
|
||||
{
|
||||
|
||||
@@ -122,7 +122,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
public override void UpdateHUD(Character character, float deltaTime, Camera cam)
|
||||
public override void UpdateHUDComponentSpecific(Character character, float deltaTime, Camera cam)
|
||||
{
|
||||
if (chargeIndicator != null)
|
||||
{
|
||||
@@ -131,7 +131,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing = false, float itemDepth = -1)
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing = false, float itemDepth = -1, Color? overrideColor = null)
|
||||
{
|
||||
Vector2 scaledIndicatorSize = indicatorSize * item.Scale;
|
||||
if (scaledIndicatorSize.X <= 2.0f || scaledIndicatorSize.Y <= 2.0f) { return; }
|
||||
|
||||
@@ -10,6 +10,10 @@ namespace Barotrauma.Items.Components
|
||||
private GUITickBox highVoltageIndicator;
|
||||
private GUITickBox lowVoltageIndicator;
|
||||
|
||||
private GUITextBlock powerLabel, loadLabel;
|
||||
|
||||
private LanguageIdentifier prevLanguage;
|
||||
|
||||
partial void InitProjectSpecific(XElement element)
|
||||
{
|
||||
if (GuiFrame == null) { return; }
|
||||
@@ -56,12 +60,12 @@ namespace Barotrauma.Items.Components
|
||||
Stretch = true
|
||||
};
|
||||
|
||||
var powerLabel = new GUITextBlock(new RectTransform(new Vector2(0.4f, 1), upperTextArea.RectTransform),
|
||||
powerLabel = new GUITextBlock(new RectTransform(new Vector2(0.4f, 1), upperTextArea.RectTransform),
|
||||
TextManager.Get("PowerTransferPowerLabel"), textColor: GUIStyle.TextColorBright, font: GUIStyle.LargeFont, textAlignment: Alignment.CenterRight)
|
||||
{
|
||||
ToolTip = TextManager.Get("PowerTransferTipPower")
|
||||
};
|
||||
var loadLabel = new GUITextBlock(new RectTransform(new Vector2(0.4f, 1), lowerTextArea.RectTransform),
|
||||
loadLabel = new GUITextBlock(new RectTransform(new Vector2(0.4f, 1), lowerTextArea.RectTransform),
|
||||
TextManager.Get("PowerTransferLoadLabel"), textColor: GUIStyle.TextColorBright, font: GUIStyle.LargeFont, textAlignment: Alignment.CenterRight)
|
||||
{
|
||||
ToolTip = TextManager.Get("PowerTransferTipLoad")
|
||||
@@ -75,7 +79,7 @@ namespace Barotrauma.Items.Components
|
||||
ToolTip = TextManager.Get("PowerTransferTipPower"),
|
||||
TextGetter = () => {
|
||||
float currPower = powerLoad < 0 ? -powerLoad: 0;
|
||||
if (!(this is RelayComponent) && PowerConnections != null && PowerConnections.Count > 0 && PowerConnections[0].Grid != null)
|
||||
if (this is not RelayComponent && PowerConnections != null && PowerConnections.Count > 0 && PowerConnections[0].Grid != null)
|
||||
{
|
||||
currPower = PowerConnections[0].Grid.Power;
|
||||
}
|
||||
@@ -119,9 +123,11 @@ namespace Barotrauma.Items.Components
|
||||
GUITextBlock.AutoScaleAndNormalize(powerLabel, loadLabel);
|
||||
GUITextBlock.AutoScaleAndNormalize(true, true, powerText, loadText);
|
||||
GUITextBlock.AutoScaleAndNormalize(kw1, kw2);
|
||||
|
||||
prevLanguage = GameSettings.CurrentConfig.Language;
|
||||
}
|
||||
|
||||
public override void UpdateHUD(Character character, float deltaTime, Camera cam)
|
||||
public override void UpdateHUDComponentSpecific(Character character, float deltaTime, Camera cam)
|
||||
{
|
||||
if (GuiFrame == null) return;
|
||||
|
||||
@@ -129,6 +135,13 @@ namespace Barotrauma.Items.Components
|
||||
powerIndicator.Selected = IsActive && voltage > 0;
|
||||
highVoltageIndicator.Selected = Timing.TotalTime % 0.5f < 0.25f && powerIndicator.Selected && voltage > 1.2f;
|
||||
lowVoltageIndicator.Selected = Timing.TotalTime % 0.5f < 0.25f && powerIndicator.Selected && voltage < 0.8f;
|
||||
|
||||
if (prevLanguage != GameSettings.CurrentConfig.Language)
|
||||
{
|
||||
GUITextBlock.AutoScaleAndNormalize(powerIndicator.TextBlock, highVoltageIndicator.TextBlock, lowVoltageIndicator.TextBlock);
|
||||
GUITextBlock.AutoScaleAndNormalize(powerLabel, loadLabel);
|
||||
prevLanguage = GameSettings.CurrentConfig.Language;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,59 +42,98 @@ namespace Barotrauma.Items.Components
|
||||
Vector2 axis = new Vector2(
|
||||
msg.ReadSingle(),
|
||||
msg.ReadSingle());
|
||||
UInt16 entityID = msg.ReadUInt16();
|
||||
StickTargetType targetType = (StickTargetType)msg.ReadByte();
|
||||
|
||||
Entity entity = Entity.FindEntityByID(entityID);
|
||||
Submarine submarine = Entity.FindEntityByID(submarineID) as Submarine;
|
||||
Hull hull = Entity.FindEntityByID(hullID) as Hull;
|
||||
Hull hull = Entity.FindEntityByID(hullID) as Hull;
|
||||
item.Submarine = submarine;
|
||||
item.CurrentHull = hull;
|
||||
item.body.SetTransform(simPosition, item.body.Rotation);
|
||||
if (entity is Character character)
|
||||
|
||||
switch (targetType)
|
||||
{
|
||||
byte limbIndex = msg.ReadByte();
|
||||
if (limbIndex >= character.AnimController.Limbs.Length)
|
||||
{
|
||||
DebugConsole.ThrowError($"Failed to read a projectile update from the server. Limb index out of bounds ({limbIndex}, character: {character.ToString()})");
|
||||
return;
|
||||
}
|
||||
if (character.Removed) { return; }
|
||||
var limb = character.AnimController.Limbs[limbIndex];
|
||||
StickToTarget(limb.body.FarseerBody, axis);
|
||||
}
|
||||
else if (entity is Structure structure)
|
||||
{
|
||||
byte bodyIndex = msg.ReadByte();
|
||||
if (bodyIndex == 255) { bodyIndex = 0; }
|
||||
if (bodyIndex >= structure.Bodies.Count)
|
||||
{
|
||||
DebugConsole.ThrowError($"Failed to read a projectile update from the server. Structure body index out of bounds ({bodyIndex}, structure: {structure.ToString()})");
|
||||
return;
|
||||
}
|
||||
var body = structure.Bodies[bodyIndex];
|
||||
StickToTarget(body, axis);
|
||||
}
|
||||
else if (entity is Item item)
|
||||
{
|
||||
if (item.Removed) { return; }
|
||||
var door = item.GetComponent<Door>();
|
||||
if (door != null)
|
||||
{
|
||||
StickToTarget(door.Body.FarseerBody, axis);
|
||||
}
|
||||
else if (item.body != null)
|
||||
{
|
||||
StickToTarget(item.body.FarseerBody, axis);
|
||||
}
|
||||
}
|
||||
else if (entity is Submarine sub)
|
||||
{
|
||||
StickToTarget(sub.PhysicsBody.FarseerBody, axis);
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugConsole.ThrowError($"Failed to read a projectile update from the server. Invalid stick target ({entity?.ToString() ?? "null"}, {entityID})");
|
||||
}
|
||||
case StickTargetType.Structure:
|
||||
UInt16 structureId = msg.ReadUInt16();
|
||||
byte bodyIndex = msg.ReadByte();
|
||||
if (Entity.FindEntityByID(structureId) is Structure structure)
|
||||
{
|
||||
if (bodyIndex == 255) { bodyIndex = 0; }
|
||||
if (bodyIndex >= structure.Bodies.Count)
|
||||
{
|
||||
DebugConsole.ThrowError($"Failed to read a projectile update from the server. Structure body index out of bounds ({bodyIndex}, structure: {structure})");
|
||||
return;
|
||||
}
|
||||
var body = structure.Bodies[bodyIndex];
|
||||
StickToTarget(body, axis);
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugConsole.AddWarning($"\"{item.Prefab.Identifier}\" failed to stick to a structure. Could not find a structure with the ID {structureId}");
|
||||
}
|
||||
break;
|
||||
case StickTargetType.Limb:
|
||||
UInt16 characterId = msg.ReadUInt16();
|
||||
byte limbIndex = msg.ReadByte();
|
||||
if (Entity.FindEntityByID(characterId) is Character character)
|
||||
{
|
||||
if (limbIndex >= character.AnimController.Limbs.Length)
|
||||
{
|
||||
DebugConsole.ThrowError($"Failed to read a projectile update from the server. Limb index out of bounds ({limbIndex}, character: {character})");
|
||||
return;
|
||||
}
|
||||
if (character.Removed) { return; }
|
||||
var limb = character.AnimController.Limbs[limbIndex];
|
||||
StickToTarget(limb.body.FarseerBody, axis);
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugConsole.AddWarning($"\"{this.item.Prefab.Identifier}\" failed to stick to a limb. Could not find a character with the ID {characterId}");
|
||||
}
|
||||
break;
|
||||
case StickTargetType.Item:
|
||||
UInt16 itemID = msg.ReadUInt16();
|
||||
if (Entity.FindEntityByID(itemID) is Item targetItem)
|
||||
{
|
||||
if (targetItem.Removed) { return; }
|
||||
var door = targetItem.GetComponent<Door>();
|
||||
if (door != null)
|
||||
{
|
||||
StickToTarget(door.Body.FarseerBody, axis);
|
||||
}
|
||||
else if (targetItem.body != null)
|
||||
{
|
||||
StickToTarget(targetItem.body.FarseerBody, axis);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugConsole.AddWarning($"\"{this.item.Prefab.Identifier}\" failed to stick to an item. Could not find n item with the ID {itemID}");
|
||||
}
|
||||
break;
|
||||
case StickTargetType.Submarine:
|
||||
UInt16 targetSubmarineId = msg.ReadUInt16();
|
||||
if (Entity.FindEntityByID(targetSubmarineId) is Submarine targetSub)
|
||||
{
|
||||
StickToTarget(targetSub.PhysicsBody.FarseerBody, axis);
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugConsole.AddWarning($"\"{item.Prefab.Identifier}\" failed to stick to a submarine. Could not find a structure with the ID {targetSubmarineId}");
|
||||
}
|
||||
break;
|
||||
case StickTargetType.LevelWall:
|
||||
int levelWallIndex = msg.ReadInt32();
|
||||
var allCells = Level.Loaded.GetAllCells();
|
||||
if (levelWallIndex >= 0 && levelWallIndex < allCells.Count)
|
||||
{
|
||||
StickToTarget(allCells[levelWallIndex].Body, axis);
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugConsole.ThrowError($"Failed to read a projectile update from the server. Level wall index out of bounds ({levelWallIndex}, wall count: {allCells.Count})");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Barotrauma.Items.Components
|
||||
currentTarget?.DrawHUD(spriteBatch, Screen.Selected.Cam, character);
|
||||
}
|
||||
|
||||
public override void UpdateHUD(Character character, float deltaTime, Camera cam)
|
||||
public override void UpdateHUDComponentSpecific(Character character, float deltaTime, Camera cam)
|
||||
{
|
||||
currentTarget?.UpdateHUD(cam, character,deltaTime);
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
#if DEBUG
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing, float itemDepth = -1)
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing, float itemDepth = -1, Color? overrideColor = null)
|
||||
{
|
||||
if (GameMain.DebugDraw && IsActive)
|
||||
{
|
||||
|
||||
@@ -373,12 +373,19 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing, float itemDepth = -1)
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing, float itemDepth = -1, Color? overrideColor = null)
|
||||
{
|
||||
if (GameMain.DebugDraw && Character.Controlled?.FocusedItem == item)
|
||||
{
|
||||
bool paused = !ShouldDeteriorate();
|
||||
if (deteriorationTimer > 0.0f)
|
||||
bool paused = !ShouldDeteriorate() && ForceDeteriorationTimer <= 0.0f;
|
||||
if (ForceDeteriorationTimer > 0.0f)
|
||||
{
|
||||
GUI.DrawString(spriteBatch,
|
||||
new Vector2(item.DrawPosition.X, -item.DrawPosition.Y), "Forced deterioration for " + ((int)ForceDeteriorationTimer) + " s",
|
||||
Color.Red, Color.Black * 0.5f);
|
||||
|
||||
}
|
||||
else if (deteriorationTimer > 0.0f)
|
||||
{
|
||||
GUI.DrawString(spriteBatch,
|
||||
new Vector2(item.DrawPosition.X, -item.DrawPosition.Y), "Deterioration delay " + ((int)deteriorationTimer) + (paused ? " [PAUSED]" : ""),
|
||||
@@ -430,8 +437,7 @@ namespace Barotrauma.Items.Components
|
||||
public void ClientEventRead(IReadMessage msg, float sendingTime)
|
||||
{
|
||||
deteriorationTimer = msg.ReadSingle();
|
||||
deteriorateAlwaysResetTimer = msg.ReadSingle();
|
||||
DeteriorateAlways = msg.ReadBoolean();
|
||||
ForceDeteriorationTimer = msg.ReadSingle();
|
||||
tinkeringDuration = msg.ReadSingle();
|
||||
tinkeringStrength = msg.ReadSingle();
|
||||
tinkeringPowersDevices = msg.ReadBoolean();
|
||||
|
||||
@@ -55,20 +55,6 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
private Vector2 GetSourcePos()
|
||||
{
|
||||
Vector2 sourcePos = source.WorldPosition;
|
||||
if (source is Item sourceItem)
|
||||
{
|
||||
sourcePos = sourceItem.DrawPosition;
|
||||
}
|
||||
else if (source is Limb sourceLimb && sourceLimb.body != null)
|
||||
{
|
||||
sourcePos = sourceLimb.body.DrawPosition;
|
||||
}
|
||||
return sourcePos;
|
||||
}
|
||||
|
||||
partial void InitProjSpecific(ContentXElement element)
|
||||
{
|
||||
foreach (var subElement in element.Elements())
|
||||
@@ -88,34 +74,22 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing, float itemDepth = -1)
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing, float itemDepth = -1, Color? overrideColor = null)
|
||||
{
|
||||
if (target == null || target.Removed) { return; }
|
||||
if (target.ParentInventory != null) { return; }
|
||||
if (source is Limb limb && limb.Removed) { return; }
|
||||
if (source is Entity e && e.Removed) { return; }
|
||||
|
||||
Vector2 startPos = GetSourcePos();
|
||||
Vector2 startPos = GetSourcePos(useDrawPosition: true);
|
||||
startPos.Y = -startPos.Y;
|
||||
if (source is Item sourceItem && !sourceItem.Removed)
|
||||
if ((source as Item)?.GetComponent<Turret>() is { } turret)
|
||||
{
|
||||
var turret = sourceItem.GetComponent<Turret>();
|
||||
var weapon = sourceItem.GetComponent<RangedWeapon>();
|
||||
if (turret != null)
|
||||
if (turret.BarrelSprite != null)
|
||||
{
|
||||
startPos = new Vector2(sourceItem.WorldRect.X + turret.TransformedBarrelPos.X, -(sourceItem.WorldRect.Y - turret.TransformedBarrelPos.Y));
|
||||
if (turret.BarrelSprite != null)
|
||||
{
|
||||
startPos += new Vector2((float)Math.Cos(turret.Rotation), (float)Math.Sin(turret.Rotation)) * turret.BarrelSprite.size.Y * turret.BarrelSprite.RelativeOrigin.Y * item.Scale * 0.9f;
|
||||
}
|
||||
startPos -= turret.GetRecoilOffset();
|
||||
}
|
||||
else if (weapon != null)
|
||||
{
|
||||
Vector2 barrelPos = FarseerPhysics.ConvertUnits.ToDisplayUnits(weapon.TransformedBarrelPos);
|
||||
barrelPos.Y = -barrelPos.Y;
|
||||
startPos += barrelPos;
|
||||
startPos += new Vector2((float)Math.Cos(turret.Rotation), (float)Math.Sin(turret.Rotation)) * turret.BarrelSprite.size.Y * turret.BarrelSprite.RelativeOrigin.Y * item.Scale * 0.9f;
|
||||
}
|
||||
startPos -= turret.GetRecoilOffset();
|
||||
}
|
||||
Vector2 endPos = new Vector2(target.DrawPosition.X, target.DrawPosition.Y);
|
||||
Vector2 flippedPos = target.Sprite.size * target.Scale * (Origin - new Vector2(0.5f));
|
||||
@@ -156,28 +130,28 @@ namespace Barotrauma.Items.Components
|
||||
if (startSprite != null)
|
||||
{
|
||||
float depth = Math.Min(item.GetDrawDepth() + (startSprite.Depth - item.Sprite.Depth), 0.999f);
|
||||
startSprite?.Draw(spriteBatch, startPos, SpriteColor, angle, depth: depth);
|
||||
startSprite?.Draw(spriteBatch, startPos, overrideColor ?? SpriteColor, angle, depth: depth);
|
||||
}
|
||||
if (endSprite != null && (!Snapped || BreakFromMiddle))
|
||||
{
|
||||
float depth = Math.Min(item.GetDrawDepth() + (endSprite.Depth - item.Sprite.Depth), 0.999f);
|
||||
endSprite?.Draw(spriteBatch, endPos, SpriteColor, angle, depth: depth);
|
||||
endSprite?.Draw(spriteBatch, endPos, overrideColor ?? SpriteColor, angle, depth: depth);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawRope(SpriteBatch spriteBatch, Vector2 startPos, Vector2 endPos, int width)
|
||||
private void DrawRope(SpriteBatch spriteBatch, Vector2 startPos, Vector2 endPos, int width, Color? overrideColor = null)
|
||||
{
|
||||
float depth = sprite == null ?
|
||||
item.Sprite.Depth + 0.001f :
|
||||
Math.Min(item.GetDrawDepth() + (sprite.Depth - item.Sprite.Depth), 0.999f);
|
||||
|
||||
|
||||
if (sprite?.Texture == null)
|
||||
{
|
||||
GUI.DrawLine(spriteBatch,
|
||||
startPos,
|
||||
endPos,
|
||||
SpriteColor, depth: depth, width: width);
|
||||
overrideColor ?? SpriteColor, depth: depth, width: width);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -191,7 +165,7 @@ namespace Barotrauma.Items.Components
|
||||
GUI.DrawLine(spriteBatch, sprite,
|
||||
startPos + dir * (x - 5.0f),
|
||||
startPos + dir * (x + sprite.size.X),
|
||||
SpriteColor, depth: depth, width: width);
|
||||
overrideColor ?? SpriteColor, depth: depth, width: width);
|
||||
}
|
||||
float leftOver = length - x;
|
||||
if (leftOver > 0.0f)
|
||||
@@ -199,7 +173,7 @@ namespace Barotrauma.Items.Components
|
||||
GUI.DrawLine(spriteBatch, sprite,
|
||||
startPos + dir * (x - 5.0f),
|
||||
endPos,
|
||||
SpriteColor, depth: depth, width: width);
|
||||
overrideColor ?? SpriteColor, depth: depth, width: width);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -207,7 +181,7 @@ namespace Barotrauma.Items.Components
|
||||
GUI.DrawLine(spriteBatch, sprite,
|
||||
startPos,
|
||||
endPos,
|
||||
SpriteColor, depth: depth, width: width);
|
||||
overrideColor ?? SpriteColor, depth: depth, width: width);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,499 @@
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using Barotrauma.Networking;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace Barotrauma.Items.Components
|
||||
{
|
||||
internal sealed partial class CircuitBox
|
||||
{
|
||||
public CircuitBoxUI? UI;
|
||||
public readonly Dictionary<Character, CircuitBoxCursor> ActiveCursors = new Dictionary<Character, CircuitBoxCursor>();
|
||||
public Option<ItemPrefab> HeldComponent = Option.None;
|
||||
|
||||
private const float CursorUpdateInterval = 1f;
|
||||
private float cursorUpdateTimer;
|
||||
|
||||
private readonly Vector2[] recordedCursorPositions = new Vector2[10];
|
||||
private Option<Vector2> recordedDragStart = Option.None;
|
||||
private Option<ItemPrefab> recordedHeldPrefab = Option.None;
|
||||
|
||||
/// <summary>
|
||||
/// If the circuit box was initialized by the server instead of from the save file.
|
||||
/// Used to ensure the wires the server sends are properly connected up when we load in.
|
||||
/// </summary>
|
||||
private bool wasInitializedByServer;
|
||||
|
||||
public Sprite? WireSprite { get; private set; }
|
||||
public Sprite? ConnectionSprite { get; private set; }
|
||||
public Sprite? WireConnectorSprite { get; private set; }
|
||||
public Sprite? ConnectionScrewSprite { get; private set; }
|
||||
public UISprite? NodeFrameSprite { get; private set; }
|
||||
public UISprite? NodeTopSprite { get; private set; }
|
||||
|
||||
protected override void CreateGUI()
|
||||
{
|
||||
base.CreateGUI();
|
||||
GuiFrame.ClearChildren();
|
||||
UI?.CreateGUI(GuiFrame);
|
||||
}
|
||||
|
||||
partial void InitProjSpecific(ContentXElement element)
|
||||
{
|
||||
UI = new CircuitBoxUI(this);
|
||||
IsActive = true;
|
||||
CreateGUI();
|
||||
|
||||
foreach (var subElement in element.Elements())
|
||||
{
|
||||
switch (subElement.Name.ToString().ToLowerInvariant())
|
||||
{
|
||||
case "wiresprite":
|
||||
WireSprite = new Sprite(subElement);
|
||||
break;
|
||||
case "connectionsprite":
|
||||
ConnectionSprite = new Sprite(subElement);
|
||||
break;
|
||||
case "wireconnectorsprite":
|
||||
WireConnectorSprite = new Sprite(subElement);
|
||||
break;
|
||||
case "connectionscrewsprite":
|
||||
ConnectionScrewSprite = new Sprite(subElement);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (GUIStyle.GetComponentStyle("CircuitBoxTop") is { } topStyle)
|
||||
{
|
||||
NodeTopSprite = topStyle.Sprites[GUIComponent.ComponentState.None][0];
|
||||
}
|
||||
|
||||
if (GUIStyle.GetComponentStyle("CircuitBoxFrame") is { } compStyle)
|
||||
{
|
||||
NodeFrameSprite = compStyle.Sprites[GUIComponent.ComponentState.None][0];
|
||||
}
|
||||
}
|
||||
|
||||
public override bool ShouldDrawHUD(Character character)
|
||||
=> character == Character.Controlled && (character.SelectedItem == item || character.SelectedSecondaryItem == item);
|
||||
|
||||
public override void UpdateHUDComponentSpecific(Character character, float deltaTime, Camera cam)
|
||||
{
|
||||
if (UI is null) { return; }
|
||||
|
||||
UI.Update(deltaTime);
|
||||
|
||||
if (GameMain.NetworkMember is null) { return; }
|
||||
|
||||
foreach (var (cursorChar, cursor) in ActiveCursors)
|
||||
{
|
||||
if (!cursor.IsActive) { continue; }
|
||||
|
||||
ActiveCursors[cursorChar].Update(deltaTime);
|
||||
}
|
||||
|
||||
Vector2 cursorPos = UI.GetCursorPosition();
|
||||
int lastCursorPosIndex = recordedCursorPositions.Length - 1;
|
||||
|
||||
if (cursorUpdateTimer < CursorUpdateInterval)
|
||||
{
|
||||
cursorUpdateTimer += deltaTime;
|
||||
int cursorIndex = (int)MathF.Floor(cursorUpdateTimer * lastCursorPosIndex);
|
||||
RecordCursorPosition(cursorIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
RecordCursorPosition(lastCursorPosIndex);
|
||||
SendCursorState(recordedCursorPositions, recordedDragStart, recordedHeldPrefab.Select(static c => c.Identifier));
|
||||
|
||||
recordedDragStart = Option.None;
|
||||
recordedHeldPrefab = Option.None;
|
||||
cursorUpdateTimer = 0f;
|
||||
}
|
||||
|
||||
void RecordCursorPosition(int index)
|
||||
{
|
||||
var dragStart = UI.GetDragStart();
|
||||
if (dragStart.IsSome()) { recordedDragStart = dragStart; }
|
||||
|
||||
var heldComponent = HeldComponent;
|
||||
if (heldComponent.IsSome()) { recordedHeldPrefab = heldComponent; }
|
||||
|
||||
if (index >= 0 && index < recordedCursorPositions.Length) { recordedCursorPositions[index] = cursorPos; }
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveComponents(IReadOnlyCollection<CircuitBoxComponent> node)
|
||||
{
|
||||
var ids = node.Select(static n => n.ID).ToImmutableArray();
|
||||
|
||||
if (GameMain.NetworkMember is null)
|
||||
{
|
||||
CreateRefundItemsForUsedResources(ids, Character.Controlled);
|
||||
RemoveComponentInternal(ids);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!node.Any()) { return; }
|
||||
|
||||
CreateClientEvent(new CircuitBoxRemoveComponentEvent(ids));
|
||||
}
|
||||
|
||||
public void AddWire(CircuitBoxConnection one, CircuitBoxConnection two)
|
||||
{
|
||||
if (GameMain.NetworkMember is null)
|
||||
{
|
||||
Connect(one, two, static delegate { }, CircuitBoxWire.SelectedWirePrefab);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!VerifyConnection(one, two)) { return; }
|
||||
|
||||
CreateClientEvent(new CircuitBoxClientAddWireEvent(Color.White, CircuitBoxConnectorIdentifier.FromConnection(one), CircuitBoxConnectorIdentifier.FromConnection(two), CircuitBoxWire.SelectedWirePrefab.UintIdentifier));
|
||||
}
|
||||
|
||||
public void RemoveWires(IReadOnlyCollection<CircuitBoxWire> wires)
|
||||
{
|
||||
var ids = wires.Select(static w => w.ID).ToImmutableArray();
|
||||
if (GameMain.NetworkMember is null)
|
||||
{
|
||||
RemoveWireInternal(ids);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ids.Any()) { return; }
|
||||
CreateClientEvent(new CircuitBoxRemoveWireEvent(ids));
|
||||
}
|
||||
|
||||
public void SelectComponents(IReadOnlyCollection<CircuitBoxNode> moveables, bool overwrite)
|
||||
{
|
||||
if (Character.Controlled is not { ID: var controlledId }) { return; }
|
||||
|
||||
var ids = ImmutableArray.CreateBuilder<ushort>();
|
||||
var ios = ImmutableArray.CreateBuilder<CircuitBoxInputOutputNode.Type>();
|
||||
|
||||
foreach (var moveable in moveables)
|
||||
{
|
||||
if (moveable is { IsSelected: true, IsSelectedByMe: false }) { continue; }
|
||||
|
||||
switch (moveable)
|
||||
{
|
||||
case CircuitBoxComponent node:
|
||||
ids.Add(node.ID);
|
||||
break;
|
||||
case CircuitBoxInputOutputNode io:
|
||||
ios.Add(io.NodeType);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (GameMain.NetworkMember is null)
|
||||
{
|
||||
SelectComponentsInternal(ids, controlledId, overwrite);
|
||||
SelectInputOutputInternal(ios, controlledId, overwrite);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((!ids.Any() && !ios.Any()) && !overwrite) { return; }
|
||||
|
||||
CreateClientEvent(new CircuitBoxSelectNodesEvent(ids.ToImmutable(), ios.ToImmutable(), overwrite, controlledId));
|
||||
}
|
||||
|
||||
public void SelectWires(IReadOnlyCollection<CircuitBoxWire> wires, bool overwrite)
|
||||
{
|
||||
if (Character.Controlled is not { ID: var controlledId }) { return; }
|
||||
|
||||
var ids = (from wire in wires where !wire.IsSelected || wire.IsSelectedByMe select wire.ID).ToImmutableArray();
|
||||
|
||||
if (GameMain.NetworkMember is null)
|
||||
{
|
||||
SelectWiresInternal(ids, controlledId, overwrite);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ids.Any() && !overwrite) { return; }
|
||||
|
||||
CreateClientEvent(new CircuitBoxSelectWiresEvent(ids, overwrite, Character.Controlled.ID));
|
||||
}
|
||||
|
||||
public void MoveComponent(Vector2 moveAmount, IReadOnlyCollection<CircuitBoxNode> moveables)
|
||||
{
|
||||
var ids = ImmutableArray.CreateBuilder<ushort>();
|
||||
var ios = ImmutableArray.CreateBuilder<CircuitBoxInputOutputNode.Type>();
|
||||
|
||||
foreach (CircuitBoxNode move in moveables)
|
||||
{
|
||||
switch (move)
|
||||
{
|
||||
case CircuitBoxComponent node:
|
||||
ids.Add(node.ID);
|
||||
break;
|
||||
case CircuitBoxInputOutputNode io:
|
||||
ios.Add(io.NodeType);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (GameMain.NetworkMember is null)
|
||||
{
|
||||
MoveNodesInternal(ids, ios, moveAmount);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ids.Any() && !ios.Any()) { return; }
|
||||
|
||||
|
||||
CreateClientEvent(new CircuitBoxMoveComponentEvent(ids.ToImmutable(), ios.ToImmutable(), moveAmount));
|
||||
}
|
||||
|
||||
public void AddComponent(ItemPrefab prefab, Vector2 pos)
|
||||
{
|
||||
if (GameMain.NetworkMember is null)
|
||||
{
|
||||
ItemPrefab resource;
|
||||
|
||||
if (IsFull) { return; }
|
||||
|
||||
if (IsInGame())
|
||||
{
|
||||
if (!GetApplicableResourcePlayerHas(prefab, Character.Controlled).TryUnwrap(out var r)) { return; }
|
||||
resource = r.Prefab;
|
||||
RemoveItem(r);
|
||||
}
|
||||
else
|
||||
{
|
||||
resource = ItemPrefab.Prefabs[Tags.FPGACircuit];
|
||||
}
|
||||
|
||||
AddComponentInternal(ICircuitBoxIdentifiable.FindFreeID(Components), prefab, resource, pos, static delegate { });
|
||||
return;
|
||||
}
|
||||
|
||||
CreateClientEvent(new CircuitBoxAddComponentEvent(prefab.UintIdentifier, pos));
|
||||
}
|
||||
|
||||
public partial void OnViewUpdateProjSpecific()
|
||||
{
|
||||
UI?.MouseSnapshotHandler.UpdateConnections();
|
||||
UI?.UpdateComponentList();
|
||||
}
|
||||
|
||||
protected override void OnResolutionChanged()
|
||||
{
|
||||
base.OnResolutionChanged();
|
||||
CreateGUI();
|
||||
}
|
||||
|
||||
// Remove selection when the circuit box is deselected
|
||||
public partial void OnDeselected(Character c)
|
||||
{
|
||||
cursorUpdateTimer = 0f;
|
||||
|
||||
// Server will broadcast the deselection, we don't need to do it ourselves
|
||||
if (GameMain.NetworkMember is not null) { return; }
|
||||
ClearAllSelectionsInternal(c.ID);
|
||||
}
|
||||
|
||||
public void ClientRead(INetSerializableStruct data)
|
||||
{
|
||||
switch (data)
|
||||
{
|
||||
case NetCircuitBoxCursorInfo cursorInfo:
|
||||
{
|
||||
ClientReadCursor(cursorInfo);
|
||||
break;
|
||||
}
|
||||
case CircuitBoxErrorEvent errorData:
|
||||
{
|
||||
DebugConsole.ThrowError($"The server responded with an error: {errorData.Message}");
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(data), data, "This data cannot be handled using direct network messages.");
|
||||
}
|
||||
}
|
||||
|
||||
public void SendMessage(CircuitBoxOpcode opcode, INetSerializableStruct data)
|
||||
{
|
||||
IWriteMessage msg = new WriteOnlyMessage().WithHeader(ClientPacketHeader.CIRCUITBOX);
|
||||
|
||||
msg.WriteNetSerializableStruct(new NetCircuitBoxHeader(
|
||||
Opcode: opcode,
|
||||
ItemID: item.ID,
|
||||
ComponentIndex: (byte)item.GetComponentIndex(this)));
|
||||
|
||||
msg.WriteNetSerializableStruct(data);
|
||||
|
||||
DeliveryMethod deliveryMethod =
|
||||
UnrealiableOpcodes.Contains(opcode)
|
||||
? DeliveryMethod.Unreliable
|
||||
: DeliveryMethod.Reliable;
|
||||
|
||||
GameMain.Client?.ClientPeer?.Send(msg, deliveryMethod);
|
||||
}
|
||||
|
||||
private void SendCursorState(Vector2[] cursorPositions, Option<Vector2> dragStart, Option<Identifier> heldComponent)
|
||||
{
|
||||
if (!IsRoundRunning()) { return; }
|
||||
|
||||
var msg = new NetCircuitBoxCursorInfo(
|
||||
RecordedPositions: cursorPositions,
|
||||
DragStart: dragStart,
|
||||
HeldItem: heldComponent);
|
||||
|
||||
SendMessage(CircuitBoxOpcode.Cursor, msg);
|
||||
}
|
||||
|
||||
public void ClientReadCursor(NetCircuitBoxCursorInfo info)
|
||||
{
|
||||
if (Entity.FindEntityByID(info.CharacterID) is not Character character) { return; }
|
||||
|
||||
if (!ActiveCursors.ContainsKey(character))
|
||||
{
|
||||
var newCursor = new CircuitBoxCursor(info);
|
||||
ActiveCursors.Add(character, newCursor);
|
||||
return;
|
||||
}
|
||||
|
||||
var activeCursor = ActiveCursors[character];
|
||||
activeCursor.UpdateInfo(info);
|
||||
activeCursor.ResetTimers();
|
||||
}
|
||||
|
||||
public void CreateClientEvent(INetSerializableStruct data)
|
||||
=> item.CreateClientEvent(this, new CircuitBoxEventData(data));
|
||||
|
||||
public void ClientEventWrite(IWriteMessage msg, NetEntityEvent.IData? extraData = null)
|
||||
{
|
||||
if (extraData is null) { return; }
|
||||
var eventData = ExtractEventData<CircuitBoxEventData>(extraData);
|
||||
msg.WriteByte((byte)eventData.Opcode);
|
||||
msg.WriteNetSerializableStruct(eventData.Data);
|
||||
}
|
||||
|
||||
public void ClientEventRead(IReadMessage msg, float sendingTime)
|
||||
{
|
||||
var header = (CircuitBoxOpcode)msg.ReadByte();
|
||||
|
||||
switch (header)
|
||||
{
|
||||
case CircuitBoxOpcode.AddComponent:
|
||||
{
|
||||
var data = INetSerializableStruct.Read<CircuitBoxServerCreateComponentEvent>(msg);
|
||||
AddComponentFromData(data);
|
||||
break;
|
||||
}
|
||||
case CircuitBoxOpcode.DeleteComponent:
|
||||
{
|
||||
var data = INetSerializableStruct.Read<CircuitBoxRemoveComponentEvent>(msg);
|
||||
RemoveComponentInternal(data.TargetIDs);
|
||||
break;
|
||||
}
|
||||
case CircuitBoxOpcode.MoveComponent:
|
||||
{
|
||||
var data = INetSerializableStruct.Read<CircuitBoxMoveComponentEvent>(msg);
|
||||
MoveNodesInternal(data.TargetIDs, data.IOs, data.MoveAmount);
|
||||
break;
|
||||
}
|
||||
case CircuitBoxOpcode.UpdateSelection:
|
||||
{
|
||||
var data = INetSerializableStruct.Read<CircuitBoxServerUpdateSelection>(msg);
|
||||
|
||||
var nodeDict = data.ComponentIds.ToImmutableDictionary(static s => s.ID, static s => s.SelectedBy);
|
||||
var wireDict = data.WireIds.ToImmutableDictionary(static s => s.ID, static s => s.SelectedBy);
|
||||
var ioDict = data.InputOutputs.ToImmutableDictionary(static s => s.Type, static s => s.SelectedBy);
|
||||
|
||||
UpdateSelections(nodeDict, wireDict, ioDict);
|
||||
break;
|
||||
}
|
||||
case CircuitBoxOpcode.AddWire:
|
||||
{
|
||||
var data = INetSerializableStruct.Read<CircuitBoxServerCreateWireEvent>(msg);
|
||||
AddWireFromData(data);
|
||||
break;
|
||||
}
|
||||
case CircuitBoxOpcode.RemoveWire:
|
||||
{
|
||||
var data = INetSerializableStruct.Read<CircuitBoxRemoveWireEvent>(msg);
|
||||
RemoveWireInternal(data.TargetIDs);
|
||||
break;
|
||||
}
|
||||
case CircuitBoxOpcode.ServerInitialize:
|
||||
{
|
||||
Components.Clear();
|
||||
Wires.Clear();
|
||||
|
||||
var data = INetSerializableStruct.Read<CircuitBoxInitializeStateFromServerEvent>(msg);
|
||||
foreach (var compData in data.Components) { AddComponentFromData(compData); }
|
||||
foreach (var wireData in data.Wires) { AddWireFromData(wireData); }
|
||||
|
||||
foreach (var node in InputOutputNodes)
|
||||
{
|
||||
node.Position = node.NodeType switch
|
||||
{
|
||||
CircuitBoxInputOutputNode.Type.Input => data.InputPos,
|
||||
CircuitBoxInputOutputNode.Type.Output => data.OutputPos,
|
||||
_ => node.Position
|
||||
};
|
||||
}
|
||||
wasInitializedByServer = true;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(header), header, "This opcode cannot be handled using entity events");
|
||||
}
|
||||
}
|
||||
|
||||
public void AddComponentFromData(CircuitBoxServerCreateComponentEvent data)
|
||||
{
|
||||
if (ItemPrefab.Prefabs.Find(p => p.UintIdentifier == data.UsedResource) is not { } prefab)
|
||||
{
|
||||
throw new Exception($"No item prefab found for \"{data.UsedResource}\"");
|
||||
}
|
||||
|
||||
AddComponentInternalUnsafe(data.ComponentId, FindItemByID(data.BackingItemId), prefab, data.Position);
|
||||
}
|
||||
|
||||
public void AddWireFromData(CircuitBoxServerCreateWireEvent data)
|
||||
{
|
||||
var (req, wireId, possibleItemId) = data;
|
||||
var prefab = ItemPrefab.Prefabs.Find(p => p.UintIdentifier == req.SelectedWirePrefabIdentifier);
|
||||
if (prefab is null)
|
||||
{
|
||||
throw new Exception($"No prefab found for \"{req.SelectedWirePrefabIdentifier}\"");
|
||||
}
|
||||
|
||||
if (!req.Start.FindConnection(this).TryUnwrap(out var start))
|
||||
{
|
||||
throw new Exception($"No connection found for ({req.Start})");
|
||||
}
|
||||
|
||||
if (!req.End.FindConnection(this).TryUnwrap(out var end))
|
||||
{
|
||||
throw new Exception($"No connection found for ({req.Start})");
|
||||
}
|
||||
|
||||
if (possibleItemId.TryUnwrap(out var backingItem))
|
||||
{
|
||||
CreateWireWithItem(start, end, wireId, FindItemByID(backingItem));
|
||||
}
|
||||
else
|
||||
{
|
||||
CreateWireWithoutItem(start, end, wireId, prefab);
|
||||
}
|
||||
}
|
||||
|
||||
public static Item FindItemByID(ushort id)
|
||||
=> Entity.FindEntityByID(id) as Item ?? throw new Exception($"No item with ID {id} exists.");
|
||||
|
||||
public override void AddToGUIUpdateList(int order = 0)
|
||||
{
|
||||
base.AddToGUIUpdateList(order);
|
||||
UI?.AddToGUIUpdateList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,8 @@ namespace Barotrauma.Items.Components
|
||||
public float FlashTimer { get; private set; }
|
||||
public static Wire DraggingConnected { get; private set; }
|
||||
|
||||
private static float ConnectionSpriteSize => 35.0f * GUI.Scale;
|
||||
|
||||
public static void DrawConnections(SpriteBatch spriteBatch, ConnectionPanel panel, Rectangle dragArea, Character character,
|
||||
out (Vector2 tooltipPos, LocalizedString text) tooltip)
|
||||
{
|
||||
@@ -33,8 +35,6 @@ namespace Barotrauma.Items.Components
|
||||
int x = panelRect.X, y = panelRect.Y;
|
||||
int width = panelRect.Width, height = panelRect.Height;
|
||||
|
||||
Vector2 scale = GetScale(panel.GuiFrame.RectTransform.MaxSize, panel.GuiFrame.Rect.Size);
|
||||
|
||||
bool mouseInRect = panelRect.Contains(PlayerInput.MousePosition);
|
||||
|
||||
int totalWireCount = 0;
|
||||
@@ -70,15 +70,15 @@ namespace Barotrauma.Items.Components
|
||||
//two passes: first the connector, then the wires to get the wires to render in front
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
Vector2 rightPos = GetRightPos(x, y, width, scale);
|
||||
Vector2 leftPos = GetLeftPos(x, y, scale);
|
||||
Vector2 rightPos = GetRightPos(x, y, width);
|
||||
Vector2 leftPos = GetLeftPos(x, y);
|
||||
|
||||
Vector2 rightWirePos = new Vector2(x + width - 5 * scale.X, y + 30 * scale.Y);
|
||||
Vector2 leftWirePos = new Vector2(x + 5 * scale.X, y + 30 * scale.Y);
|
||||
Vector2 rightWirePos = new Vector2(x + width - 5 * GUI.Scale, y + 30 * GUI.Scale);
|
||||
Vector2 leftWirePos = new Vector2(x + 5 * GUI.Scale, y + 30 * GUI.Scale);
|
||||
|
||||
int wireInterval = (height - (int)(20 * scale.Y)) / Math.Max(totalWireCount, 1);
|
||||
int connectorIntervalLeft = GetConnectorIntervalLeft(height, scale, panel);
|
||||
int connectorIntervalRight = GetConnectorIntervalRight(height, scale, panel);
|
||||
int wireInterval = (height - (int)(20 * GUI.Scale)) / Math.Max(totalWireCount, 1);
|
||||
int connectorIntervalLeft = GetConnectorIntervalLeft(height, panel);
|
||||
int connectorIntervalRight = GetConnectorIntervalRight(height, panel);
|
||||
|
||||
foreach (Connection c in panel.Connections)
|
||||
{
|
||||
@@ -101,47 +101,26 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
|
||||
Vector2 position = c.IsOutput ? rightPos : leftPos;
|
||||
Color highlightColor = Color.Transparent;
|
||||
if (ConnectionPanel.ShouldDebugDrawWiring)
|
||||
{
|
||||
if (c.IsPower)
|
||||
{
|
||||
highlightColor = VisualizeSignal(0.0f, highlightColor, Color.Red);
|
||||
}
|
||||
else
|
||||
{
|
||||
highlightColor = VisualizeSignal(c.LastReceivedSignal.TimeSinceCreated, highlightColor, Color.LightGreen);
|
||||
highlightColor = VisualizeSignal(c.LastSentSignal.TimeSinceCreated, highlightColor, Color.Orange);
|
||||
}
|
||||
bool mouseOn = Vector2.DistanceSquared(position, PlayerInput.MousePosition) < MathUtils.Pow2(35 * GUI.Scale);
|
||||
DrawConnectionDebugInfo(spriteBatch, c, position, GUI.Scale, out var tooltipText);
|
||||
|
||||
LocalizedString toolTipText = c.GetToolTip();
|
||||
if (mouseOn) { tooltip = (position, toolTipText); }
|
||||
if (!toolTipText.IsNullOrEmpty())
|
||||
if (!tooltipText.IsNullOrEmpty())
|
||||
{
|
||||
var glowSprite = GUIStyle.UIGlowCircular.Value.Sprite;
|
||||
glowSprite.Draw(spriteBatch, position, highlightColor, glowSprite.size / 2,
|
||||
scale: 45.0f / glowSprite.size.X * panel.Scale);
|
||||
bool mouseOn = Vector2.DistanceSquared(position, PlayerInput.MousePosition) < MathUtils.Pow2(35 * GUI.Scale);
|
||||
if (mouseOn)
|
||||
{
|
||||
tooltip = (position, tooltipText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static Color VisualizeSignal(double timeSinceCreated, Color defaultColor, Color color)
|
||||
{
|
||||
if (timeSinceCreated < 1.0f)
|
||||
{
|
||||
float pulseAmount = (MathF.Sin((float)Timing.TotalTimeUnpaused * 10.0f) + 3.0f) / 4.0f;
|
||||
Color targetColor = Color.Lerp(defaultColor, color, pulseAmount);
|
||||
return Color.Lerp(targetColor, defaultColor, (float)timeSinceCreated);
|
||||
}
|
||||
return defaultColor;
|
||||
}
|
||||
|
||||
//outputs are drawn at the right side of the panel, inputs at the left
|
||||
if (c.IsOutput)
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
c.DrawConnection(spriteBatch, panel, rightPos, GetOutputLabelPosition(rightPos, panel, c), scale);
|
||||
c.DrawConnection(spriteBatch, panel, rightPos, GetOutputLabelPosition(rightPos, panel, c));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -154,7 +133,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
c.DrawConnection(spriteBatch, panel, leftPos, GetInputLabelPosition(leftPos, panel, c), scale);
|
||||
c.DrawConnection(spriteBatch, panel, leftPos, GetInputLabelPosition(leftPos, panel, c));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -224,8 +203,8 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
|
||||
|
||||
float step = (width * 0.75f) / panel.DisconnectedWires.Count();
|
||||
x = (int)(x + width / 2 - step * (panel.DisconnectedWires.Count() - 1) / 2);
|
||||
float step = (width * 0.75f) / panel.DisconnectedWires.Count;
|
||||
x = (int)(x + width / 2 - step * (panel.DisconnectedWires.Count - 1) / 2);
|
||||
foreach (Wire wire in panel.DisconnectedWires)
|
||||
{
|
||||
if (wire == DraggingConnected && mouseInRect) { continue; }
|
||||
@@ -243,26 +222,61 @@ namespace Barotrauma.Items.Components
|
||||
//stop dragging a wire item if the cursor is within any connection panel
|
||||
//(so we don't drop the item when dropping the wire on a connection)
|
||||
if (mouseInRect || (GUI.MouseOn?.UserData is ConnectionPanel && GUI.MouseOn.MouseRect.Contains(PlayerInput.MousePosition)))
|
||||
{
|
||||
Inventory.DraggingItems.Clear();
|
||||
}
|
||||
{
|
||||
Inventory.DraggingItems.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawConnection(SpriteBatch spriteBatch, ConnectionPanel panel, Vector2 position, Vector2 labelPos, Vector2 scale)
|
||||
public static void DrawConnectionDebugInfo(SpriteBatch spriteBatch, Connection c, Vector2 position, float scale, out LocalizedString tooltip)
|
||||
{
|
||||
Color highlightColor = Color.Transparent;
|
||||
if (c.IsPower)
|
||||
{
|
||||
highlightColor = VisualizeSignal(0.0f, highlightColor, Color.Red);
|
||||
}
|
||||
else
|
||||
{
|
||||
highlightColor = VisualizeSignal(c.LastReceivedSignal.TimeSinceCreated, highlightColor, Color.LightGreen);
|
||||
highlightColor = VisualizeSignal(c.LastSentSignal.TimeSinceCreated, highlightColor, Color.Orange);
|
||||
}
|
||||
|
||||
LocalizedString toolTipText = c.GetToolTip();
|
||||
if (!toolTipText.IsNullOrEmpty())
|
||||
{
|
||||
var glowSprite = GUIStyle.UIGlowCircular.Value.Sprite;
|
||||
glowSprite.Draw(spriteBatch, position, highlightColor, glowSprite.size / 2,
|
||||
scale: 45.0f / glowSprite.size.X * scale);
|
||||
}
|
||||
|
||||
tooltip = toolTipText;
|
||||
|
||||
static Color VisualizeSignal(double timeSinceCreated, Color defaultColor, Color color)
|
||||
{
|
||||
if (timeSinceCreated < 1.0f)
|
||||
{
|
||||
float pulseAmount = (MathF.Sin((float)Timing.TotalTimeUnpaused * 10.0f) + 3.0f) / 4.0f;
|
||||
Color targetColor = Color.Lerp(defaultColor, color, pulseAmount);
|
||||
return Color.Lerp(targetColor, defaultColor, (float)timeSinceCreated);
|
||||
}
|
||||
return defaultColor;
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawConnection(SpriteBatch spriteBatch, ConnectionPanel panel, Vector2 position, Vector2 labelPos)
|
||||
{
|
||||
string text = DisplayName.Value.ToUpperInvariant();
|
||||
|
||||
//nasty
|
||||
if (GUIStyle.GetComponentStyle("ConnectionPanelLabel")?.Sprites.Values.First().First() is UISprite labelSprite)
|
||||
{
|
||||
Rectangle labelArea = GetLabelArea(labelPos, text, scale);
|
||||
Rectangle labelArea = GetLabelArea(labelPos, text);
|
||||
labelSprite.Draw(spriteBatch, labelArea, IsPower ? GUIStyle.Red : Color.SteelBlue);
|
||||
}
|
||||
|
||||
GUI.DrawString(spriteBatch, labelPos + Vector2.UnitY, text, Color.Black * 0.8f, font: GUIStyle.SmallFont);
|
||||
GUI.DrawString(spriteBatch, labelPos, text, GUIStyle.TextColorBright, font: GUIStyle.SmallFont);
|
||||
|
||||
float connectorSpriteScale = (35.0f / connectionSprite.SourceRect.Width) * panel.Scale;
|
||||
float connectorSpriteScale = ConnectionSpriteSize / connectionSprite.SourceRect.Width;
|
||||
|
||||
connectionSprite.Draw(spriteBatch, position, scale: connectorSpriteScale);
|
||||
|
||||
@@ -270,7 +284,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
private void DrawWires(SpriteBatch spriteBatch, ConnectionPanel panel, Vector2 position, Vector2 wirePosition, bool mouseIn, Wire equippedWire, float wireInterval)
|
||||
{
|
||||
float connectorSpriteScale = (35.0f / connectionSprite.SourceRect.Width) * panel.Scale;
|
||||
float connectorSpriteScale = ConnectionSpriteSize / connectionSprite.SourceRect.Width;
|
||||
|
||||
foreach (var wire in wires)
|
||||
{
|
||||
@@ -285,9 +299,14 @@ namespace Barotrauma.Items.Components
|
||||
wirePosition.Y += wireInterval;
|
||||
}
|
||||
|
||||
if (DraggingConnected != null && Vector2.Distance(position, PlayerInput.MousePosition) < (20.0f * GUI.Scale))
|
||||
bool isMouseOn = Vector2.Distance(position, PlayerInput.MousePosition) < (20.0f * GUI.Scale);
|
||||
if (isMouseOn)
|
||||
{
|
||||
connectionSpriteHighlight.Draw(spriteBatch, position, scale: connectorSpriteScale);
|
||||
}
|
||||
|
||||
if (DraggingConnected != null && isMouseOn)
|
||||
{
|
||||
|
||||
if (!PlayerInput.PrimaryMouseButtonHeld())
|
||||
{
|
||||
@@ -418,7 +437,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
bool mouseOn =
|
||||
canDrag &&
|
||||
!(GUI.MouseOn is GUIDragHandle) &&
|
||||
GUI.MouseOn is not GUIDragHandle &&
|
||||
((PlayerInput.MousePosition.X > Math.Min(start.X, end.X) &&
|
||||
PlayerInput.MousePosition.X < Math.Max(start.X, end.X) &&
|
||||
MathUtils.LineToPointDistanceSquared(start, end, PlayerInput.MousePosition) < 36) ||
|
||||
@@ -442,12 +461,12 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
var wireEnd = end + Vector2.Normalize(start - end) * 30.0f * panel.Scale;
|
||||
var wireEnd = end + Vector2.Normalize(start - end) * 30.0f * GUI.Scale;
|
||||
|
||||
float dist = Vector2.Distance(start, wireEnd);
|
||||
|
||||
float wireWidth = 12 * panel.Scale;
|
||||
float highlight = 5 * panel.Scale;
|
||||
float wireWidth = 12 * GUI.Scale;
|
||||
float highlight = 5 * GUI.Scale;
|
||||
if (mouseOn)
|
||||
{
|
||||
spriteBatch.Draw(wireVertical.Texture, new Rectangle(wireEnd.ToPoint(), new Point((int)(wireWidth + highlight), (int)dist)), wireVertical.SourceRect,
|
||||
@@ -488,110 +507,84 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
Rectangle panelRect = panel.GuiFrame.Rect;
|
||||
int x = panelRect.X, y = panelRect.Y;
|
||||
Vector2 scale = GetScale(panel.GuiFrame.RectTransform.MaxSize, panel.GuiFrame.Rect.Size);
|
||||
Vector2 rightPos = GetRightPos(x, y, panelRect.Width, scale);
|
||||
Vector2 leftPos = GetLeftPos(x, y, scale);
|
||||
int connectorIntervalLeft = GetConnectorIntervalLeft(panelRect.Height, scale, panel);
|
||||
int connectorIntervalRight = GetConnectorIntervalRight(panelRect.Height, scale, panel);
|
||||
Vector2 rightPos = GetRightPos(x, y, panelRect.Width);
|
||||
Vector2 leftPos = GetLeftPos(x, y);
|
||||
int connectorIntervalLeft = GetConnectorIntervalLeft(panelRect.Height, panel);
|
||||
int connectorIntervalRight = GetConnectorIntervalRight(panelRect.Height, panel);
|
||||
newRectSize = panelRect.Size;
|
||||
var labelAreas = new List<Rectangle>();
|
||||
for (int i = 0; i < 100; i++)
|
||||
|
||||
//make sure the connection labels don't overlap horizontally
|
||||
float rightMostInput = panelRect.Center.X;
|
||||
float leftMostOutput = panelRect.Center.X;
|
||||
foreach (var c in panel.Connections)
|
||||
{
|
||||
labelAreas.Clear();
|
||||
foreach (var c in panel.Connections)
|
||||
if (c.IsOutput)
|
||||
{
|
||||
if (c.IsOutput)
|
||||
{
|
||||
var labelArea = GetLabelArea(GetOutputLabelPosition(rightPos, panel, c), c.DisplayName.Value.ToUpperInvariant(), scale);
|
||||
labelAreas.Add(labelArea);
|
||||
rightPos.Y += connectorIntervalLeft;
|
||||
}
|
||||
else
|
||||
{
|
||||
var labelArea = GetLabelArea(GetInputLabelPosition(leftPos, panel, c), c.DisplayName.Value.ToUpperInvariant(), scale);
|
||||
labelAreas.Add(labelArea);
|
||||
leftPos.Y += connectorIntervalRight;
|
||||
}
|
||||
var labelArea = GetLabelArea(GetOutputLabelPosition(rightPos, panel, c), c.DisplayName.Value.ToUpperInvariant());
|
||||
leftMostOutput = Math.Min(leftMostOutput, labelArea.X);
|
||||
rightPos.Y += connectorIntervalLeft;
|
||||
}
|
||||
bool foundOverlap = false;
|
||||
for (int j = 0; j < labelAreas.Count; j++)
|
||||
else
|
||||
{
|
||||
for (int k = 0; k < labelAreas.Count; k++)
|
||||
{
|
||||
if (k == j) { continue; }
|
||||
if (!labelAreas[j].Intersects(labelAreas[k])) { continue; }
|
||||
newRectSize += new Point(10);
|
||||
Point maxSize = new Point(
|
||||
Math.Max(panel.GuiFrame.RectTransform.MaxSize.X, newRectSize.X),
|
||||
Math.Max(panel.GuiFrame.RectTransform.MaxSize.Y, newRectSize.Y));
|
||||
scale = GetScale(maxSize, newRectSize);
|
||||
rightPos = GetRightPos(x, y, newRectSize.X, scale);
|
||||
leftPos = GetLeftPos(x, y, scale);
|
||||
connectorIntervalLeft = GetConnectorIntervalLeft(newRectSize.Y, scale, panel);
|
||||
connectorIntervalRight = GetConnectorIntervalRight(newRectSize.Y, scale, panel);
|
||||
foundOverlap = true;
|
||||
break;
|
||||
}
|
||||
var labelArea = GetLabelArea(GetInputLabelPosition(leftPos, panel, c), c.DisplayName.Value.ToUpperInvariant());
|
||||
rightMostInput = Math.Max(rightMostInput, labelArea.Right);
|
||||
leftPos.Y += connectorIntervalRight;
|
||||
}
|
||||
if (!foundOverlap) { break; }
|
||||
}
|
||||
if (leftMostOutput < rightMostInput)
|
||||
{
|
||||
newRectSize += new Point((int)(rightMostInput - leftMostOutput) + GUI.IntScale(15), 0);
|
||||
}
|
||||
|
||||
//make sure connection sprites don't overlap vertically
|
||||
while (GetConnectorIntervalLeft(newRectSize.Y, panel) < ConnectionSpriteSize ||
|
||||
GetConnectorIntervalRight(newRectSize.Y, panel) < ConnectionSpriteSize)
|
||||
{
|
||||
newRectSize.Y += 10;
|
||||
}
|
||||
return newRectSize.X != panel.GuiFrame.Rect.Width || newRectSize.Y > panel.GuiFrame.Rect.Height;
|
||||
}
|
||||
|
||||
private static Vector2 GetScale(Point maxSize, Point size)
|
||||
{
|
||||
Vector2 scale = new Vector2(GUI.Scale);
|
||||
if (maxSize.X < int.MaxValue)
|
||||
{
|
||||
scale.X = maxSize.X / size.X;
|
||||
}
|
||||
if (maxSize.Y < int.MaxValue)
|
||||
{
|
||||
scale.Y = maxSize.Y / size.Y;
|
||||
}
|
||||
return scale;
|
||||
}
|
||||
|
||||
private static Vector2 GetInputLabelPosition(Vector2 connectorPosition, ConnectionPanel panel, Connection connection)
|
||||
{
|
||||
return new Vector2(
|
||||
connectorPosition.X + 25 * panel.Scale,
|
||||
connectorPosition.Y - 5 * panel.Scale - GUIStyle.SmallFont.MeasureString(connection.DisplayName.ToUpper()).Y);
|
||||
connectorPosition.X + 25 * GUI.Scale,
|
||||
connectorPosition.Y - GUIStyle.SmallFont.MeasureString(connection.DisplayName.ToUpper()).Y / 2);
|
||||
}
|
||||
|
||||
private static Vector2 GetOutputLabelPosition(Vector2 connectorPosition, ConnectionPanel panel, Connection connection)
|
||||
{
|
||||
return new Vector2(
|
||||
connectorPosition.X - 25 * panel.Scale - GUIStyle.SmallFont.MeasureString(connection.DisplayName.ToUpper()).X,
|
||||
connectorPosition.Y + 5 * panel.Scale);
|
||||
connectorPosition.X - 25 * GUI.Scale - GUIStyle.SmallFont.MeasureString(connection.DisplayName.ToUpper()).X,
|
||||
connectorPosition.Y - GUIStyle.SmallFont.MeasureString(connection.DisplayName.ToUpper()).Y / 2);
|
||||
}
|
||||
|
||||
private static Rectangle GetLabelArea(Vector2 labelPos, string text, Vector2 scale)
|
||||
private static Rectangle GetLabelArea(Vector2 labelPos, string text)
|
||||
{
|
||||
Vector2 textSize = GUIStyle.SmallFont.MeasureString(text);
|
||||
Rectangle labelArea = new Rectangle(labelPos.ToPoint(), textSize.ToPoint());
|
||||
labelArea.Inflate(10 * scale.X, 3 * scale.Y);
|
||||
labelArea.Inflate(GUI.IntScale(10), GUI.IntScale(3));
|
||||
return labelArea;
|
||||
}
|
||||
|
||||
private static Vector2 GetLeftPos(int x, int y, Vector2 scale)
|
||||
private static Vector2 GetLeftPos(int x, int y)
|
||||
{
|
||||
return new Vector2(x + 80 * scale.X, y + 60 * scale.Y);
|
||||
return new Vector2(x + 80 * GUI.Scale, y + 60 * GUI.Scale);
|
||||
}
|
||||
|
||||
private static Vector2 GetRightPos(int x, int y, int width, Vector2 scale)
|
||||
private static Vector2 GetRightPos(int x, int y, int width)
|
||||
{
|
||||
return new Vector2(x + width - 80 * scale.X, y + 60 * scale.Y);
|
||||
return new Vector2(x + width - 80 * GUI.Scale, y + 60 * GUI.Scale);
|
||||
}
|
||||
|
||||
private static int GetConnectorIntervalLeft(int height, Vector2 scale, ConnectionPanel panel)
|
||||
private static int GetConnectorIntervalLeft(int height, ConnectionPanel panel)
|
||||
{
|
||||
return (height - (int)(100 * scale.Y)) / Math.Max(panel.Connections.Count(c => c.IsOutput), 1);
|
||||
return (height - GUI.IntScale(60)) / Math.Max(panel.Connections.Count(c => c.IsOutput), 1);
|
||||
}
|
||||
|
||||
private static int GetConnectorIntervalRight(int height, Vector2 scale, ConnectionPanel panel)
|
||||
private static int GetConnectorIntervalRight(int height, ConnectionPanel panel)
|
||||
{
|
||||
return (height - (int)(100 * scale.Y)) / Math.Max(panel.Connections.Count(c => !c.IsOutput), 1);
|
||||
return (height - GUI.IntScale(60)) / Math.Max(panel.Connections.Count(c => !c.IsOutput), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+13
-13
@@ -22,11 +22,6 @@ namespace Barotrauma.Items.Components
|
||||
private SoundChannel rewireSoundChannel;
|
||||
private float rewireSoundTimer;
|
||||
|
||||
public float Scale
|
||||
{
|
||||
get { return GuiFrame.Rect.Width / 400.0f; }
|
||||
}
|
||||
|
||||
private Point originalMaxSize;
|
||||
private Vector2 originalRelativeSize;
|
||||
|
||||
@@ -104,10 +99,10 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public override bool ShouldDrawHUD(Character character)
|
||||
{
|
||||
return character == Character.Controlled && character == user && character.SelectedItem == item;
|
||||
return character == Character.Controlled && character == user && (character.SelectedItem == item || character.SelectedSecondaryItem == item);
|
||||
}
|
||||
|
||||
public override void UpdateHUD(Character character, float deltaTime, Camera cam)
|
||||
public override void UpdateHUDComponentSpecific(Character character, float deltaTime, Camera cam)
|
||||
{
|
||||
if (character != Character.Controlled || character != user || character.SelectedItem != item) { return; }
|
||||
|
||||
@@ -162,10 +157,11 @@ namespace Barotrauma.Items.Components
|
||||
//because some of the wires connected to the panel may not exist yet
|
||||
long msgStartPos = msg.BitPosition;
|
||||
msg.ReadUInt16(); //user ID
|
||||
foreach (Connection _ in Connections)
|
||||
byte connectionCount = msg.ReadByte();
|
||||
for (int i = 0; i < connectionCount; i++)
|
||||
{
|
||||
uint wireCount = msg.ReadVariableUInt32();
|
||||
for (int i = 0; i < wireCount; i++)
|
||||
for (int j = 0; j < wireCount; j++)
|
||||
{
|
||||
msg.ReadUInt16();
|
||||
}
|
||||
@@ -208,21 +204,25 @@ namespace Barotrauma.Items.Components
|
||||
connection.ClearConnections();
|
||||
}
|
||||
|
||||
foreach (Connection connection in Connections)
|
||||
byte connectionCount = msg.ReadByte();
|
||||
for (int i = 0; i < connectionCount; i++)
|
||||
{
|
||||
HashSet<Wire> newWires = new HashSet<Wire>();
|
||||
uint wireCount = msg.ReadVariableUInt32();
|
||||
for (int i = 0; i < wireCount; i++)
|
||||
for (int j = 0; j < wireCount; j++)
|
||||
{
|
||||
ushort wireId = msg.ReadUInt16();
|
||||
|
||||
if (!(Entity.FindEntityByID(wireId) is Item wireItem)) { continue; }
|
||||
if (Entity.FindEntityByID(wireId) is not Item wireItem) { continue; }
|
||||
Wire wireComponent = wireItem.GetComponent<Wire>();
|
||||
if (wireComponent == null) { continue; }
|
||||
|
||||
newWires.Add(wireComponent);
|
||||
}
|
||||
|
||||
//this may happen if the item has been deleted server-side at the point the server is writing this event to the client
|
||||
if (i >= Connections.Count) { continue; }
|
||||
|
||||
var connection = Connections[i];
|
||||
Wire[] oldWires = connection.Wires.Where(w => !newWires.Contains(w)).ToArray();
|
||||
foreach (var wire in oldWires)
|
||||
{
|
||||
|
||||
@@ -244,7 +244,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
public override void UpdateHUD(Character character, float deltaTime, Camera cam)
|
||||
public override void UpdateHUDComponentSpecific(Character character, float deltaTime, Camera cam)
|
||||
{
|
||||
bool elementVisibilityChanged = false;
|
||||
int visibleElementCount = 0;
|
||||
@@ -335,17 +335,18 @@ namespace Barotrauma.Items.Components
|
||||
if (signals == null) { return; }
|
||||
for (int i = 0; i < signals.Length && i < uiElements.Count; i++)
|
||||
{
|
||||
string signal = customInterfaceElementList[i].Signal;
|
||||
if (uiElements[i] is GUITextBox tb)
|
||||
{
|
||||
tb.Text = Screen.Selected is { IsEditor: true } ?
|
||||
customInterfaceElementList[i].Signal :
|
||||
TextManager.Get(customInterfaceElementList[i].Signal).Value;
|
||||
signal :
|
||||
TextManager.Get(signal).Fallback(signal).Value;
|
||||
}
|
||||
else if (uiElements[i] is GUINumberInput ni)
|
||||
{
|
||||
if (ni.InputType == NumberType.Int)
|
||||
{
|
||||
int.TryParse(customInterfaceElementList[i].Signal, out int value);
|
||||
int.TryParse(signal, out int value);
|
||||
ni.IntValue = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Barotrauma.Items.Components
|
||||
get { return new Vector2(rangeX, rangeY) * 2.0f; }
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing, float itemDepth = -1)
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing, float itemDepth = -1, Color? overrideColor = null)
|
||||
{
|
||||
if (!editing || !MapEntity.SelectedList.Contains(item)) { return; }
|
||||
|
||||
|
||||
@@ -86,15 +86,15 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
|
||||
OutputValue = input;
|
||||
ShowOnDisplay(input, addToHistory: true, TextColor);
|
||||
ShowOnDisplay(input, addToHistory: true, TextColor, isWelcomeMessage: false);
|
||||
item.SendSignal(input, "signal_out");
|
||||
}
|
||||
|
||||
partial void ShowOnDisplay(string input, bool addToHistory, Color color)
|
||||
partial void ShowOnDisplay(string input, bool addToHistory, Color color, bool isWelcomeMessage)
|
||||
{
|
||||
if (addToHistory)
|
||||
{
|
||||
messageHistory.Add(new TerminalMessage(input, color));
|
||||
messageHistory.Add(new TerminalMessage(input, color, isWelcomeMessage));
|
||||
while (messageHistory.Count > MaxMessages)
|
||||
{
|
||||
messageHistory.RemoveAt(0);
|
||||
|
||||
@@ -11,9 +11,9 @@ namespace Barotrauma.Items.Components
|
||||
get { return new Vector2(range * 2); }
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing, float itemDepth = -1)
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing, float itemDepth = -1, Color? overrideColor = null)
|
||||
{
|
||||
if (!editing || !MapEntity.SelectedList.Contains(item)) return;
|
||||
if (!editing || !MapEntity.SelectedList.Contains(item)) { return; }
|
||||
|
||||
Vector2 pos = new Vector2(item.DrawPosition.X, -item.DrawPosition.Y);
|
||||
ShapeExtensions.DrawLine(spriteBatch, pos + Vector2.UnitY * range, pos - Vector2.UnitY * range, Color.Cyan * 0.5f, 2);
|
||||
|
||||
@@ -186,12 +186,12 @@ namespace Barotrauma.Items.Components
|
||||
return Color.LightBlue;
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing, float itemDepth = -1)
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing, float itemDepth = -1, Color? overrideColor = null)
|
||||
{
|
||||
Draw(spriteBatch, editing, Vector2.Zero, itemDepth);
|
||||
Draw(spriteBatch, editing, Vector2.Zero, itemDepth, overrideColor);
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing, Vector2 offset, float itemDepth = -1)
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing, Vector2 offset, float itemDepth = -1, Color? overrideColor = null)
|
||||
{
|
||||
if (sections.Count == 0 && !IsActive || Hidden)
|
||||
{
|
||||
@@ -223,7 +223,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
foreach (WireSection section in sections)
|
||||
{
|
||||
section.Draw(spriteBatch, wireSprite, item.Color, drawOffset, depth, Width);
|
||||
section.Draw(spriteBatch, wireSprite, overrideColor ?? item.Color, drawOffset, depth, Width);
|
||||
}
|
||||
|
||||
if (nodes.Count > 0)
|
||||
@@ -271,13 +271,13 @@ namespace Barotrauma.Items.Components
|
||||
spriteBatch, wireSprite,
|
||||
nodes[^1] + drawOffset,
|
||||
new Vector2(newNodePos.X, newNodePos.Y) + drawOffset,
|
||||
item.Color, 0.0f, Width);
|
||||
overrideColor ?? item.Color, 0.0f, Width);
|
||||
|
||||
WireSection.Draw(
|
||||
spriteBatch, wireSprite,
|
||||
new Vector2(newNodePos.X, newNodePos.Y) + drawOffset,
|
||||
item.DrawPosition,
|
||||
item.Color, itemDepth, Width);
|
||||
overrideColor ?? item.Color, itemDepth, Width);
|
||||
|
||||
GUI.DrawRectangle(spriteBatch, new Vector2(newNodePos.X + drawOffset.X, -(newNodePos.Y + drawOffset.Y)) - Vector2.One * 3, Vector2.One * 6, item.Color);
|
||||
}
|
||||
@@ -287,7 +287,7 @@ namespace Barotrauma.Items.Components
|
||||
spriteBatch, wireSprite,
|
||||
nodes[^1] + drawOffset,
|
||||
item.DrawPosition,
|
||||
item.Color, 0.0f, Width);
|
||||
overrideColor ?? item.Color, 0.0f, Width);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -594,7 +594,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
selectedWire.shouldClearConnections = false;
|
||||
Character.Controlled.Inventory.TryPutItem(selectedWire.item, Character.Controlled, new List<InvSlotType> { InvSlotType.LeftHand, InvSlotType.RightHand });
|
||||
foreach (var entity in MapEntity.mapEntityList)
|
||||
foreach (var entity in MapEntity.MapEntityList)
|
||||
{
|
||||
if (entity is Item item)
|
||||
{
|
||||
|
||||
@@ -117,6 +117,13 @@ namespace Barotrauma.Items.Components
|
||||
get { return barrelSprite; }
|
||||
}
|
||||
|
||||
[Serialize(false, IsPropertySaveable.No)]
|
||||
public bool HideBarrelWhenBroken
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
partial void InitProjSpecific(ContentXElement element)
|
||||
{
|
||||
foreach (var subElement in element.Elements())
|
||||
@@ -232,7 +239,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
moveSoundChannel.FadeOutAndDispose();
|
||||
moveSoundChannel = SoundPlayer.PlaySound(endMoveSound.Sound, item.WorldPosition, endMoveSound.Volume, endMoveSound.Range, ignoreMuffling: endMoveSound.IgnoreMuffling, freqMult: endMoveSound.GetRandomFrequencyMultiplier());
|
||||
if (moveSoundChannel != null) moveSoundChannel.Looping = false;
|
||||
if (moveSoundChannel != null) { moveSoundChannel.Looping = false; }
|
||||
}
|
||||
else if (!moveSoundChannel.IsPlaying)
|
||||
{
|
||||
@@ -261,12 +268,13 @@ namespace Barotrauma.Items.Components
|
||||
if (chargeSound != null)
|
||||
{
|
||||
chargeSoundChannel = SoundPlayer.PlaySound(chargeSound.Sound, item.WorldPosition, chargeSound.Volume, chargeSound.Range, ignoreMuffling: chargeSound.IgnoreMuffling, freqMult: chargeSound.GetRandomFrequencyMultiplier());
|
||||
if (chargeSoundChannel != null) chargeSoundChannel.Looping = true;
|
||||
if (chargeSoundChannel != null) { chargeSoundChannel.Looping = true; }
|
||||
}
|
||||
}
|
||||
else if (chargeSoundChannel != null)
|
||||
{
|
||||
chargeSoundChannel.FrequencyMultiplier = MathHelper.Lerp(0.5f, 1.5f, chargeRatio);
|
||||
chargeSoundChannel.Position = new Vector3(item.WorldPosition, 0.0f);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -318,7 +326,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
public override void UpdateHUD(Character character, float deltaTime, Camera cam)
|
||||
public override void UpdateHUDComponentSpecific(Character character, float deltaTime, Camera cam)
|
||||
{
|
||||
if (crosshairSprite != null)
|
||||
{
|
||||
@@ -359,7 +367,7 @@ namespace Barotrauma.Items.Components
|
||||
return new Vector2((float)Math.Cos(rotation), (float)Math.Sin(rotation)) * recoilOffset;
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing = false, float itemDepth = -1)
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing = false, float itemDepth = -1, Color? overrideColor = null)
|
||||
{
|
||||
if (!MathUtils.NearlyEqual(item.Rotation, prevBaseRotation) || !MathUtils.NearlyEqual(item.Scale, prevScale))
|
||||
{
|
||||
@@ -367,53 +375,55 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
Vector2 drawPos = GetDrawPos();
|
||||
|
||||
|
||||
railSprite?.Draw(spriteBatch,
|
||||
drawPos,
|
||||
item.SpriteColor,
|
||||
rotation + MathHelper.PiOver2, item.Scale,
|
||||
SpriteEffects.None, item.SpriteDepth + (railSprite.Depth - item.Sprite.Depth));
|
||||
|
||||
barrelSprite?.Draw(spriteBatch,
|
||||
drawPos - GetRecoilOffset() * item.Scale,
|
||||
item.SpriteColor,
|
||||
rotation + MathHelper.PiOver2, item.Scale,
|
||||
SpriteEffects.None, item.SpriteDepth + (barrelSprite.Depth - item.Sprite.Depth));
|
||||
|
||||
float chargeRatio = currentChargeTime / MaxChargeTime;
|
||||
|
||||
foreach ((Sprite chargeSprite, Vector2 position) in chargeSprites)
|
||||
if (item.Condition > 0.0f || !HideBarrelWhenBroken)
|
||||
{
|
||||
chargeSprite?.Draw(spriteBatch,
|
||||
drawPos - MathUtils.RotatePoint(new Vector2(position.X * chargeRatio, position.Y * chargeRatio) * item.Scale, rotation + MathHelper.PiOver2),
|
||||
item.SpriteColor,
|
||||
railSprite?.Draw(spriteBatch,
|
||||
drawPos,
|
||||
overrideColor ?? item.SpriteColor,
|
||||
rotation + MathHelper.PiOver2, item.Scale,
|
||||
SpriteEffects.None, item.SpriteDepth + (chargeSprite.Depth - item.Sprite.Depth));
|
||||
}
|
||||
SpriteEffects.None, item.SpriteDepth + (railSprite.Depth - item.Sprite.Depth));
|
||||
|
||||
int spinningBarrelCount = spinningBarrelSprites.Count;
|
||||
|
||||
for (int i = 0; i < spinningBarrelCount; i++)
|
||||
{
|
||||
// this block is messy since I was debugging it with a bunch of values, should be cleaned up / optimized if prototype is accepted
|
||||
Sprite spinningBarrel = spinningBarrelSprites[i];
|
||||
float barrelCirclePosition = (MaxCircle * i / spinningBarrelCount + currentBarrelSpin) % MaxCircle;
|
||||
|
||||
float newDepth = item.SpriteDepth + (spinningBarrel.Depth - item.Sprite.Depth) + (barrelCirclePosition > HalfCircle ? 0.0f : 0.001f);
|
||||
|
||||
float barrelColorPosition = (barrelCirclePosition + QuarterCircle) % MaxCircle;
|
||||
float colorOffset = Math.Abs(barrelColorPosition - HalfCircle) / HalfCircle;
|
||||
Color newColorModifier = Color.Lerp(Color.Black, Color.Gray, colorOffset);
|
||||
|
||||
float barrelHalfCirclePosition = Math.Abs(barrelCirclePosition - HalfCircle);
|
||||
float barrelPositionModifier = MathUtils.SmoothStep(barrelHalfCirclePosition / HalfCircle);
|
||||
float newPositionOffset = barrelPositionModifier * SpinningBarrelDistance;
|
||||
|
||||
spinningBarrel.Draw(spriteBatch,
|
||||
drawPos - MathUtils.RotatePoint(new Vector2(newPositionOffset, 0f) * item.Scale, rotation + MathHelper.PiOver2),
|
||||
Color.Lerp(item.SpriteColor, newColorModifier, 0.8f),
|
||||
barrelSprite?.Draw(spriteBatch,
|
||||
drawPos - GetRecoilOffset() * item.Scale,
|
||||
overrideColor ?? item.SpriteColor,
|
||||
rotation + MathHelper.PiOver2, item.Scale,
|
||||
SpriteEffects.None, newDepth);
|
||||
SpriteEffects.None, item.SpriteDepth + (barrelSprite.Depth - item.Sprite.Depth));
|
||||
|
||||
float chargeRatio = currentChargeTime / MaxChargeTime;
|
||||
|
||||
foreach ((Sprite chargeSprite, Vector2 position) in chargeSprites)
|
||||
{
|
||||
chargeSprite?.Draw(spriteBatch,
|
||||
drawPos - MathUtils.RotatePoint(new Vector2(position.X * chargeRatio, position.Y * chargeRatio) * item.Scale, rotation + MathHelper.PiOver2),
|
||||
item.SpriteColor,
|
||||
rotation + MathHelper.PiOver2, item.Scale,
|
||||
SpriteEffects.None, item.SpriteDepth + (chargeSprite.Depth - item.Sprite.Depth));
|
||||
}
|
||||
|
||||
int spinningBarrelCount = spinningBarrelSprites.Count;
|
||||
|
||||
for (int i = 0; i < spinningBarrelCount; i++)
|
||||
{
|
||||
// this block is messy since I was debugging it with a bunch of values, should be cleaned up / optimized if prototype is accepted
|
||||
Sprite spinningBarrel = spinningBarrelSprites[i];
|
||||
float barrelCirclePosition = (MaxCircle * i / spinningBarrelCount + currentBarrelSpin) % MaxCircle;
|
||||
|
||||
float newDepth = item.SpriteDepth + (spinningBarrel.Depth - item.Sprite.Depth) + (barrelCirclePosition > HalfCircle ? 0.0f : 0.001f);
|
||||
|
||||
float barrelColorPosition = (barrelCirclePosition + QuarterCircle) % MaxCircle;
|
||||
float colorOffset = Math.Abs(barrelColorPosition - HalfCircle) / HalfCircle;
|
||||
Color newColorModifier = Color.Lerp(Color.Black, Color.Gray, colorOffset);
|
||||
|
||||
float barrelHalfCirclePosition = Math.Abs(barrelCirclePosition - HalfCircle);
|
||||
float barrelPositionModifier = MathUtils.SmoothStep(barrelHalfCirclePosition / HalfCircle);
|
||||
float newPositionOffset = barrelPositionModifier * SpinningBarrelDistance;
|
||||
|
||||
spinningBarrel.Draw(spriteBatch,
|
||||
drawPos - MathUtils.RotatePoint(new Vector2(newPositionOffset, 0f) * item.Scale, rotation + MathHelper.PiOver2),
|
||||
Color.Lerp(overrideColor ?? item.SpriteColor, newColorModifier, 0.8f),
|
||||
rotation + MathHelper.PiOver2, item.Scale,
|
||||
SpriteEffects.None, newDepth);
|
||||
}
|
||||
}
|
||||
|
||||
if (GameMain.DebugDraw)
|
||||
@@ -593,6 +603,7 @@ namespace Barotrauma.Items.Components
|
||||
if (!recipient.IsPower || !recipient.IsOutput) { continue; }
|
||||
var battery = recipient.Item?.GetComponent<PowerContainer>();
|
||||
if (battery == null || battery.Item.Condition <= 0.0f) { continue; }
|
||||
if (battery.OutputDisabled) { continue; }
|
||||
availableCharge += battery.Charge;
|
||||
availableCapacity += battery.GetCapacity();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user