(5a377a8ee) Unstable v0.9.1000.0

This commit is contained in:
Juan Pablo Arce
2020-05-13 12:55:42 -03:00
parent b143329701
commit a1ca41aa5d
426 changed files with 14384 additions and 5708 deletions
@@ -345,9 +345,7 @@ namespace Barotrauma
{
hideButton.RectTransform.SetPosition(Anchor.TopLeft, Pivot.TopLeft);
hideButton.RectTransform.NonScaledSize = new Point(HideButtonWidth, HUDLayoutSettings.BottomRightInfoArea.Height);
hideButton.RectTransform.AbsoluteOffset = new Point(
personalSlotArea.Right + Spacing * 2,
HUDLayoutSettings.BottomRightInfoArea.Y);
hideButton.RectTransform.AbsoluteOffset = new Point(HUDLayoutSettings.BottomRightInfoArea.Left - HideButtonWidth + GUI.IntScaleCeiling(2f), HUDLayoutSettings.BottomRightInfoArea.Y + GUI.IntScaleCeiling(1f));
hideButton.Visible = true;
SetIndicatorSizes();
@@ -356,7 +354,6 @@ namespace Barotrauma
break;
case Layout.Right:
{
int extraOffset = 0;
int x = HUDLayoutSettings.InventoryAreaLower.Right;
int personalSlotX = HUDLayoutSettings.InventoryAreaLower.Right - SlotSize.X - Spacing;
for (int i = 0; i < slots.Length; i++)
@@ -373,17 +370,18 @@ namespace Barotrauma
}
int lowerX = x;
int personalSlotY = GameMain.GraphicsHeight - bottomOffset * 2 - Spacing * 2 - (int)(!GUI.IsFourByThree() ? UnequippedIndicator.size.Y * UIScale * IndicatorScaleAdjustment : UnequippedIndicator.size.Y * UIScale * IndicatorScaleAdjustment * 2f);
for (int i = 0; i < SlotPositions.Length; i++)
{
if (HideSlot(i)) continue;
if (PersonalSlots.HasFlag(SlotTypes[i]))
{
SlotPositions[i] = new Vector2(personalSlotX, GameMain.GraphicsHeight - bottomOffset * 2 - extraOffset - Spacing * 2);
SlotPositions[i] = new Vector2(personalSlotX, personalSlotY);
personalSlotX -= slots[i].Rect.Width + Spacing;
}
else
{
SlotPositions[i] = new Vector2(x, GameMain.GraphicsHeight - bottomOffset - extraOffset);
SlotPositions[i] = new Vector2(x, GameMain.GraphicsHeight - bottomOffset);
x += slots[i].Rect.Width + Spacing;
}
}
@@ -393,7 +391,7 @@ namespace Barotrauma
{
if (!HideSlot(i)) continue;
x -= slots[i].Rect.Width + Spacing;
SlotPositions[i] = new Vector2(x, GameMain.GraphicsHeight - bottomOffset - extraOffset);
SlotPositions[i] = new Vector2(x, GameMain.GraphicsHeight - bottomOffset);
}
}
break;
@@ -401,12 +399,14 @@ namespace Barotrauma
{
int x = HUDLayoutSettings.InventoryAreaLower.X;
int personalSlotX = x;
int personalSlotY = GameMain.GraphicsHeight - bottomOffset * 2 - Spacing * 2 - (int)(!GUI.IsFourByThree() ? UnequippedIndicator.size.Y * UIScale * IndicatorScaleAdjustment : UnequippedIndicator.size.Y * UIScale * IndicatorScaleAdjustment * 2f);
for (int i = 0; i < SlotPositions.Length; i++)
{
if (HideSlot(i)) continue;
if (PersonalSlots.HasFlag(SlotTypes[i]))
{
SlotPositions[i] = new Vector2(personalSlotX, GameMain.GraphicsHeight - bottomOffset * 2 - Spacing * 2);
SlotPositions[i] = new Vector2(personalSlotX, personalSlotY);
personalSlotX += slots[i].Rect.Width + Spacing;
}
else
@@ -493,7 +493,7 @@ namespace Barotrauma
((selectedSlot != null && selectedSlot.IsSubSlot) || (draggingItem != null && (draggingSlot == null || !draggingSlot.MouseOn())));
if (CharacterHealth.OpenHealthWindow != null) hoverOnInventory = true;
if (layout == Layout.Default)
if (layout == Layout.Default && (Screen.Selected != GameMain.SubEditorScreen || Screen.Selected is SubEditorScreen editor && editor.WiringMode))
{
if (hideButton.Visible)
{
@@ -525,8 +525,7 @@ namespace Barotrauma
for (int i = 0; i < capacity; i++)
{
if (Items[i] != null && Items[i] != draggingItem && Character.Controlled?.Inventory == this &&
GUI.KeyboardDispatcher.Subscriber == null && !CrewManager.IsCommandInterfaceOpen &&
slots[i].QuickUseKey != Keys.None && PlayerInput.KeyHit(slots[i].QuickUseKey))
GUI.KeyboardDispatcher.Subscriber == null && !CrewManager.IsCommandInterfaceOpen && PlayerInput.InventoryKeyHit(slots[i].InventoryKeyIndex))
{
QuickUseItem(Items[i], true, false, true);
}
@@ -586,6 +585,19 @@ namespace Barotrauma
}
}
}
// In sub editor we cannot hover over the slot because they are not rendered so we override it here
if (Screen.Selected is SubEditorScreen subEditor && !subEditor.WiringMode)
{
for (int i = 0; i < slots.Length; i++)
{
var subInventory = GetSubInventory(i);
if (subInventory != null)
{
ShowSubInventory(new SlotReference(this, slots[i], i, false, Items[i].GetComponent<ItemContainer>().Inventory), deltaTime, cam, hideSubInventories, true);
}
}
}
foreach (var subInventorySlot in hideSubInventories)
{
@@ -771,21 +783,16 @@ namespace Barotrauma
}
}
private void AssignQuickUseNumKeys()
public void AssignQuickUseNumKeys()
{
int num = 1;
int keyBindIndex = 0;
for (int i = 0; i < slots.Length; i++)
{
if (HideSlot(i))
{
slots[i].QuickUseKey = Keys.None;
continue;
}
if (HideSlot(i)) continue;
if (SlotTypes[i] == InvSlotType.Any)
{
slots[i].QuickUseKey = Keys.D0 + num % 10;
num++;
slots[i].InventoryKeyIndex = keyBindIndex;
keyBindIndex++;
}
}
}
@@ -808,16 +815,21 @@ namespace Barotrauma
{
if (item.Container == null || character.Inventory.FindIndex(item.Container) == -1) // Not a subinventory in the character's inventory
{
return item.ParentInventory is CharacterInventory ?
QuickUseAction.TakeFromCharacter : QuickUseAction.TakeFromContainer;
if (character.SelectedItems.Any(i => i?.OwnInventory != null && i.OwnInventory.CanBePut(item)))
{
return QuickUseAction.PutToEquippedItem;
}
else
{
return item.ParentInventory is CharacterInventory ? QuickUseAction.TakeFromCharacter : QuickUseAction.TakeFromContainer;
}
}
else
{
var selectedContainer = character.SelectedConstruction?.GetComponent<ItemContainer>();
if (selectedContainer != null &&
selectedContainer.Inventory != null &&
!selectedContainer.Inventory.Locked &&
allowInventorySwap)
!selectedContainer.Inventory.Locked)
{
// Move the item from the subinventory to the selected container
return QuickUseAction.PutToContainer;
@@ -854,7 +866,7 @@ namespace Barotrauma
{
return QuickUseAction.TakeFromCharacter;
}
else if (character.SelectedItems.Any(i => i?.OwnInventory != null && i.OwnInventory.CanBePut(item)))
else if (character.SelectedItems.Any(i => i?.OwnInventory != null && i.OwnInventory.CanBePut(item)) && allowInventorySwap)
{
return QuickUseAction.PutToEquippedItem;
}
@@ -882,13 +894,40 @@ namespace Barotrauma
private void QuickUseItem(Item item, bool allowEquip, bool allowInventorySwap, bool allowApplyTreatment)
{
if (Screen.Selected is SubEditorScreen editor && !editor.WiringMode && !Submarine.Unloading)
{
// Find the slot the item was contained in and flash it
if (item.ParentInventory?.slots != null)
{
var invSlots = item.ParentInventory.slots;
var invItems = item.ParentInventory.Items;
for (int i = 0; i < invSlots.Length; i++)
{
if (i < 0 || invSlots.Length <= i || i < 0 || invItems.Length <= i) { break; }
var slot = invSlots[i];
var slotItem = invItems[i];
if (slotItem == item)
{
slot.ShowBorderHighlight(GUI.Style.Red, 0.1f, 0.4f);
GUI.PlayUISound(GUISoundType.PickItem);
break;
}
}
}
item.Remove();
return;
}
var quickUseAction = GetQuickUseAction(item, allowEquip, allowInventorySwap, allowApplyTreatment);
bool success = false;
switch (quickUseAction)
{
case QuickUseAction.Equip:
//attempt to put in a free slot first
for (int i = 0; i < capacity; i++)
for (int i = capacity - 1; i >= 0; i--)
{
if (Items[i] != null) continue;
if (SlotTypes[i] == InvSlotType.Any || !item.AllowedSlots.Any(a => a.HasFlag(SlotTypes[i]))) continue;
@@ -898,11 +937,11 @@ namespace Barotrauma
if (!success)
{
for (int i = 0; i < capacity; i++)
for (int i = capacity - 1; i >= 0; i--)
{
if (SlotTypes[i] == InvSlotType.Any || !item.AllowedSlots.Any(a => a.HasFlag(SlotTypes[i]))) continue;
//something else already equipped in the slot, attempt to unequip it
if (Items[i] != null && Items[i].AllowedSlots.Contains(InvSlotType.Any))
// something else already equipped in a hand slot, attempt to unequip it so items aren't unnecessarily swapped to it
if (Items[i] != null && Items[i].AllowedSlots.Contains(InvSlotType.Any) && SlotTypes[i] == InvSlotType.LeftHand || SlotTypes[i] == InvSlotType.RightHand)
{
TryPutItem(Items[i], Character.Controlled, new List<InvSlotType>() { InvSlotType.Any }, true);
}
@@ -1003,6 +1042,7 @@ namespace Barotrauma
prevUIScale != UIScale ||
prevHUDScale != GUI.Scale)
{
CreateSlots();
SetSlotPositions(layout);
prevUIScale = UIScale;
prevHUDScale = GUI.Scale;
@@ -237,6 +237,7 @@ namespace Barotrauma.Items.Components
{
StopPicking(null);
PlaySound(forcedOpen ? ActionType.OnPicked : ActionType.OnUse);
if (isOpen) { stuck = MathHelper.Clamp(stuck - StuckReductionOnOpen, 0.0f, 100.0f); }
}
}
}
@@ -245,7 +246,8 @@ namespace Barotrauma.Items.Components
{
base.ClientRead(type, msg, sendingTime);
bool open = msg.ReadBoolean();
bool open = msg.ReadBoolean();
bool broken = msg.ReadBoolean();
bool forcedOpen = msg.ReadBoolean();
SetState(open, isNetworkMessage: true, sendNetworkMessage: false, forcedOpen: forcedOpen);
Stuck = msg.ReadRangedSingle(0.0f, 100.0f, 8);
@@ -258,6 +260,7 @@ namespace Barotrauma.Items.Components
}
if (isStuck) { OpenState = 0.0f; }
IsBroken = broken;
PredictedState = null;
}
}
@@ -1,4 +1,5 @@
using Microsoft.Xna.Framework;
using Barotrauma.Networking;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
@@ -52,5 +53,13 @@ namespace Barotrauma.Items.Components
}
}
}
public void ClientRead(ServerNetObject type, IReadMessage msg, float sendingTime)
{
CurrPowerConsumption = powerConsumption;
charging = true;
timer = Duration;
IsActive = true;
}
}
}
@@ -71,6 +71,8 @@ namespace Barotrauma.Items.Components
base.ClientRead(type, msg, sendingTime);
bool shouldBeAttached = msg.ReadBoolean();
Vector2 simPosition = new Vector2(msg.ReadSingle(), msg.ReadSingle());
UInt16 submarineID = msg.ReadUInt16();
Submarine sub = Entity.FindEntityByID(submarineID) as Submarine;
if (!attachable)
{
@@ -84,6 +86,7 @@ namespace Barotrauma.Items.Components
{
Drop(false, null);
item.SetTransform(simPosition, 0.0f);
item.Submarine = sub;
AttachToWall();
}
}
@@ -4,7 +4,7 @@ using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.IO;
using Barotrauma.IO;
using System.Text;
using System.Xml.Linq;
@@ -4,7 +4,7 @@ using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.IO;
using Barotrauma.IO;
using System.Linq;
using System.Xml.Linq;
@@ -436,8 +436,7 @@ namespace Barotrauma.Items.Components
if (subElement.Attribute("color") != null) color = subElement.GetAttributeColor("color", Color.White);
string style = subElement.Attribute("style") == null ?
null : subElement.GetAttributeString("style", "");
GuiFrame = new GUIFrame(RectTransform.Load(subElement, GUI.Canvas, Anchor.Center), style, color);
GuiFrame = new GUIFrame(RectTransform.Load(subElement, GUI.Canvas.ItemComponentHolder, Anchor.Center), style, color);
DefaultLayout = GUILayoutSettings.Load(subElement);
break;
case "alternativelayout":
@@ -28,7 +28,7 @@ namespace Barotrauma.Items.Components
}
private string text;
[Serialize("", true, translationTextTag: "Label.", description: "The text displayed in the label."), Editable(100)]
[Serialize("", true, translationTextTag: "Label.", description: "The text displayed in the label.", alwaysUseInstanceValues: true), Editable(100)]
public string Text
{
get { return text; }
@@ -58,7 +58,7 @@ namespace Barotrauma.Items.Components
private set;
}
[Editable, Serialize("0,0,0,255", true, description: "The color of the text displayed on the label (R,G,B,A).")]
[Editable, Serialize("0,0,0,255", true, description: "The color of the text displayed on the label (R,G,B,A).", alwaysUseInstanceValues: true)]
public Color TextColor
{
get { return textColor; }
@@ -69,7 +69,7 @@ namespace Barotrauma.Items.Components
}
}
[Editable(0.0f, 10.0f), Serialize(1.0f, true, description: "The scale of the text displayed on the label.")]
[Editable(0.0f, 10.0f), Serialize(1.0f, true, description: "The scale of the text displayed on the label.", alwaysUseInstanceValues: true)]
public float TextScale
{
get { return textBlock == null ? 1.0f : textBlock.TextScale; }
@@ -48,7 +48,10 @@ namespace Barotrauma.Items.Components
{
if (light.LightSprite != null && (item.body == null || item.body.Enabled) && lightBrightness > 0.0f && IsOn)
{
light.LightSprite.Draw(spriteBatch, new Vector2(item.DrawPosition.X, -item.DrawPosition.Y), lightColor * lightBrightness, 0.0f, item.Scale, SpriteEffects.None, item.SpriteDepth - 0.0001f);
Vector2 origin = light.LightSprite.Origin;
if (light.LightSpriteEffect == SpriteEffects.FlipHorizontally) { origin.X = light.LightSprite.SourceRect.Width - origin.X; }
if (light.LightSpriteEffect == SpriteEffects.FlipVertically) { origin.Y = light.LightSprite.SourceRect.Height - origin.Y; }
light.LightSprite.Draw(spriteBatch, new Vector2(item.DrawPosition.X, -item.DrawPosition.Y), lightColor * lightBrightness, origin, -light.Rotation, item.Scale, light.LightSpriteEffect, item.SpriteDepth - 0.0001f);
}
}
@@ -76,7 +76,7 @@ namespace Barotrauma.Items.Components
public void ClientRead(ServerNetObject type, IReadMessage msg, float sendingTime)
{
state = msg.ReadBoolean();
State = msg.ReadBoolean();
ushort userID = msg.ReadUInt16();
if (userID == 0)
{
@@ -16,6 +16,10 @@ namespace Barotrauma.Items.Components
private GUIScrollBar forceSlider;
private GUITickBox autoControlIndicator;
private int particlesPerSec = 60;
private float particleTimer;
public float AnimSpeed
{
get;
@@ -318,10 +318,10 @@ namespace Barotrauma.Items.Components
{
if (item.ParentInventory.slots[availableSlotIndex].HighlightTimer <= 0.0f)
{
item.ParentInventory.slots[availableSlotIndex].ShowBorderHighlight(GUI.Style.Green, 0.5f, 0.5f);
item.ParentInventory.slots[availableSlotIndex].ShowBorderHighlight(GUI.Style.Green, 0.5f, 0.5f, 0.2f);
if (slotIndex < inputContainer.Capacity)
{
inputContainer.Inventory.slots[slotIndex].ShowBorderHighlight(GUI.Style.Green, 0.5f, 0.5f);
inputContainer.Inventory.slots[slotIndex].ShowBorderHighlight(GUI.Style.Green, 0.5f, 0.5f, 0.2f);
}
}
}
@@ -337,10 +337,22 @@ namespace Barotrauma.Items.Components
slotRect.Center.ToVector2(),
color: requiredItem.ItemPrefab.InventoryIconColor * 0.3f,
scale: Math.Min(slotRect.Width / itemIcon.size.X, slotRect.Height / itemIcon.size.Y));
if (requiredItem.UseCondition && requiredItem.MinCondition < 1.0f)
{
GUI.DrawRectangle(spriteBatch, new Rectangle(slotRect.X, slotRect.Bottom - 8, slotRect.Width, 8), Color.Black * 0.8f, true);
GUI.DrawRectangle(spriteBatch,
new Rectangle(slotRect.X, slotRect.Bottom - 8, (int)(slotRect.Width * requiredItem.MinCondition), 8),
GUI.Style.Green * 0.8f, true);
}
if (slotRect.Contains(PlayerInput.MousePosition))
{
string toolTipText = requiredItem.ItemPrefab.Name;
if (requiredItem.UseCondition && requiredItem.MinCondition < 1.0f)
{
toolTipText += " " + (int)Math.Round(requiredItem.MinCondition * 100) + "%";
}
if (!string.IsNullOrEmpty(requiredItem.ItemPrefab.Description))
{
toolTipText += '\n' + requiredItem.ItemPrefab.Description;
@@ -91,6 +91,7 @@ namespace Barotrauma.Items.Components
if ((item.Submarine == null && displayedSubs.Count > 0) || //item not inside a sub anymore, but display is still showing subs
!displayedSubs.Contains(item.Submarine) || //current sub not displayer
item.Submarine.DockedTo.Any(s => !displayedSubs.Contains(s)) || //some of the docked subs not diplayed
!submarineContainer.Children.Any() || // We lack a GUI
displayedSubs.Any(s => s != item.Submarine && !item.Submarine.DockedTo.Contains(s))) //displaying a sub that shouldn't be displayed
{
CreateHUD();
@@ -116,15 +117,17 @@ namespace Barotrauma.Items.Components
private void DrawHUDFront(SpriteBatch spriteBatch, GUICustomComponent container)
{
if (Voltage < MinVoltage)
{
{
Vector2 textSize = GUI.Font.MeasureString(noPowerTip);
Vector2 textPos = GuiFrame.Rect.Center.ToVector2();
GUI.DrawString(spriteBatch, textPos - textSize / 2, noPowerTip,
GUI.Style.Orange * (float)Math.Abs(Math.Sin(Timing.TotalTime)), Color.Black * 0.8f, font: GUI.SubHeadingFont);
GUI.Style.Orange * (float)Math.Abs(Math.Sin(Timing.TotalTime)), Color.Black * 0.8f, font: GUI.SubHeadingFont);
return;
}
if (!submarineContainer.Children.Any()) { return; }
foreach (GUIComponent child in submarineContainer.Children.First().Children)
{
if (child.UserData is Hull hull)
@@ -151,7 +154,7 @@ namespace Barotrauma.Items.Components
foreach (Hull hull in Hull.hullList)
{
var hullFrame = submarineContainer.Children.First().FindChild(hull);
var hullFrame = submarineContainer.Children.FirstOrDefault()?.FindChild(hull);
if (hullFrame == null) { continue; }
if (GUI.MouseOn == hullFrame || hullFrame.IsParentOf(GUI.MouseOn))
@@ -175,7 +178,7 @@ namespace Barotrauma.Items.Components
foreach (Hull hull in Hull.hullList)
{
if (hull.Submarine == null) continue;
var hullFrame = submarineContainer.Children.First().FindChild(hull);
var hullFrame = submarineContainer.Children.FirstOrDefault()?.FindChild(hull);
if (hullFrame == null) continue;
hullDatas.TryGetValue(hull, out HullData hullData);
@@ -163,7 +163,7 @@ namespace Barotrauma.Items.Components
{
pumpSpeedLockTimer -= deltaTime;
isActiveLockTimer -= deltaTime;
autoControlIndicator.Selected = pumpSpeedLockTimer > 0.0f || isActiveLockTimer > 0.0f;
autoControlIndicator.Selected = IsAutoControlled;
PowerButton.Enabled = isActiveLockTimer <= 0.0f;
if (HasPower)
{
@@ -192,9 +192,10 @@ namespace Barotrauma.Items.Components
{
RelativeOffset = new Vector2(0, fissionMeter.RectTransform.RelativeOffset.Y + meterSize.Y)
},
style: "DeviceSlider", barSize: 0.1f)
style: "DeviceSlider", barSize: 0.15f)
{
Enabled = false,
Step = 1.0f / 255,
OnMoved = (GUIScrollBar bar, float scrollAmount) =>
{
LastUser = Character.Controlled;
@@ -209,9 +210,10 @@ namespace Barotrauma.Items.Components
{
RelativeOffset = new Vector2(0, turbineMeter.RectTransform.RelativeOffset.Y + meterSize.Y)
},
style: "DeviceSlider", barSize: 0.1f, isHorizontal: true)
style: "DeviceSlider", barSize: 0.15f, isHorizontal: true)
{
Enabled = false,
Step = 1.0f / 255,
OnMoved = (GUIScrollBar bar, float scrollAmount) =>
{
LastUser = Character.Controlled;
@@ -715,8 +717,14 @@ namespace Barotrauma.Items.Components
targetTurbineOutput = msg.ReadRangedSingle(0.0f, 100.0f, 8);
degreeOfSuccess = msg.ReadRangedSingle(0.0f, 1.0f, 8);
FissionRateScrollBar.BarScroll = targetFissionRate / 100.0f;
TurbineOutputScrollBar.BarScroll = targetTurbineOutput / 100.0f;
if (Math.Abs(FissionRateScrollBar.BarScroll - targetFissionRate / 100.0f) > 0.01f)
{
FissionRateScrollBar.BarScroll = targetFissionRate / 100.0f;
}
if (Math.Abs(TurbineOutputScrollBar.BarScroll - targetTurbineOutput / 100.0f) > 0.01f)
{
TurbineOutputScrollBar.BarScroll = targetTurbineOutput / 100.0f;
}
IsActive = true;
}
@@ -18,6 +18,8 @@ namespace Barotrauma.Items.Components
Disruption
}
private PathFinder pathFinder;
private bool dynamicDockingIndicator = true;
private bool unsentChanges;
@@ -45,7 +47,7 @@ namespace Barotrauma.Items.Components
private Sprite sonarBlip;
private Sprite lineSprite;
private Dictionary<string, Sprite> targetIcons = new Dictionary<string, Sprite>();
private readonly Dictionary<string, Sprite> targetIcons = new Dictionary<string, Sprite>();
private float displayBorderSize;
@@ -65,7 +67,23 @@ namespace Barotrauma.Items.Components
//Vector2 = vector from the ping source to the position of the disruption
//float = strength of the disruption, between 0-1
List<Pair<Vector2, float>> disruptedDirections = new List<Pair<Vector2, float>>();
private readonly List<Pair<Vector2, float>> disruptedDirections = new List<Pair<Vector2, float>>();
class CachedDistance
{
public readonly Vector2 TransducerWorldPos;
public readonly Vector2 WorldPos;
public readonly float Distance;
public CachedDistance(Vector2 transducerWorldPos, Vector2 worldPos, float dist)
{
TransducerWorldPos = transducerWorldPos;
WorldPos = worldPos;
Distance = dist;
}
}
private readonly Dictionary<object, CachedDistance> markerDistances = new Dictionary<object, CachedDistance>();
private readonly Color positiveColor = Color.Green;
private readonly Color warningColor = Color.Orange;
@@ -74,7 +92,7 @@ namespace Barotrauma.Items.Components
public static readonly Vector2 controlBoxSize = new Vector2(0.33f, 0.32f);
public static readonly Vector2 controlBoxOffset = new Vector2(0.025f, 0);
public static readonly float sonarAreaSize = 1.09f;
private static readonly float sonarAreaSize = 1.09f;
private static readonly Dictionary<BlipType, Color[]> blipColorGradient = new Dictionary<BlipType, Color[]>()
{
@@ -94,6 +112,8 @@ namespace Barotrauma.Items.Components
public float DisplayRadius { get; private set; }
public static Vector2 GUISizeCalculation => Vector2.One * Math.Min(GUI.RelativeHorizontalAspectRatio, 1f) * sonarAreaSize;
partial void InitProjSpecific(XElement element)
{
System.Diagnostics.Debug.Assert(Enum.GetValues(typeof(BlipType)).Cast<BlipType>().All(t => blipColorGradient.ContainsKey(t)));
@@ -254,7 +274,7 @@ namespace Barotrauma.Items.Components
controlContainer.RectTransform.SetPosition(Anchor.TopLeft);
sonarView.RectTransform.ScaleBasis = ScaleBasis.Smallest;
sonarView.RectTransform.SetPosition(Anchor.CenterRight);
sonarView.RectTransform.Resize(Vector2.One * GUI.RelativeHorizontalAspectRatio * sonarAreaSize);
sonarView.RectTransform.Resize(GUISizeCalculation);
GUITextBlock.AutoScaleAndNormalize(passiveTickBox.TextBlock, activeTickBox.TextBlock, zoomText, directionalModeSwitchText);
}
}
@@ -490,6 +510,7 @@ namespace Barotrauma.Items.Components
disruptedDirections.Clear();
foreach (AITarget t in AITarget.List)
{
if (t.Entity is Character c && c.Params.HideInSonar) { continue; }
if (t.SoundRange <= 0.0f || float.IsNaN(t.SoundRange) || float.IsInfinity(t.SoundRange)) { continue; }
float distSqr = Vector2.DistanceSquared(t.WorldPosition, transducerCenter);
@@ -652,12 +673,16 @@ namespace Barotrauma.Items.Components
DrawMarker(spriteBatch,
GameMain.GameSession.StartLocation.Name,
"outpost",
(Level.Loaded.StartPosition - transducerCenter), displayScale, center, DisplayRadius);
GameMain.GameSession.StartLocation.Name,
Level.Loaded.StartPosition, transducerCenter,
displayScale, center, DisplayRadius);
DrawMarker(spriteBatch,
GameMain.GameSession.EndLocation.Name,
"outpost",
(Level.Loaded.EndPosition - transducerCenter), displayScale, center, DisplayRadius);
GameMain.GameSession.EndLocation.Name,
Level.Loaded.EndPosition, transducerCenter,
displayScale, center, DisplayRadius);
foreach (AITarget aiTarget in AITarget.List)
{
@@ -669,7 +694,9 @@ namespace Barotrauma.Items.Components
DrawMarker(spriteBatch,
aiTarget.SonarLabel,
aiTarget.SonarIconIdentifier,
aiTarget.WorldPosition - transducerCenter, displayScale, center, DisplayRadius * 0.975f);
aiTarget,
aiTarget.WorldPosition, transducerCenter,
displayScale, center, DisplayRadius * 0.975f);
}
}
@@ -684,7 +711,9 @@ namespace Barotrauma.Items.Components
DrawMarker(spriteBatch,
mission.SonarLabel,
mission.SonarIconIdentifier,
sonarPosition - transducerCenter, displayScale, center, DisplayRadius * 0.95f);
mission,
sonarPosition, transducerCenter,
displayScale, center, DisplayRadius * 0.95f);
}
}
}
@@ -701,9 +730,10 @@ namespace Barotrauma.Items.Components
if (sub.WorldPosition.Y > Level.Loaded.Size.Y) { continue; }
DrawMarker(spriteBatch,
sub.Info.Name,
sub.Info.DisplayName,
sub.Info.HasTag(SubmarineTag.Shuttle) ? "shuttle" : "submarine",
sub.WorldPosition - transducerCenter,
sub,
sub.WorldPosition, transducerCenter,
displayScale, center, DisplayRadius * 0.95f);
}
@@ -801,8 +831,11 @@ namespace Barotrauma.Items.Components
{
if (Level.Loaded != null && dockingPort.Item.Submarine.WorldPosition.Y > Level.Loaded.Size.Y) { continue; }
if (dockingPort.Item.Submarine == null) { continue; }
if (dockingPort.Item.Submarine.Info.IsWreck) { continue; }
//don't show the docking ports of the opposing team on the sonar
if (item.Submarine != null && dockingPort.Item.Submarine != null)
if (item.Submarine != null)
{
if ((dockingPort.Item.Submarine.TeamID == Character.TeamType.Team1 && item.Submarine.TeamID == Character.TeamType.Team2) ||
(dockingPort.Item.Submarine.TeamID == Character.TeamType.Team2 && item.Submarine.TeamID == Character.TeamType.Team1))
@@ -947,14 +980,13 @@ namespace Barotrauma.Items.Components
}
foreach (AITarget aiTarget in AITarget.List)
{
if (aiTarget.SonarDisruption <= 0.0f || !aiTarget.Enabled) { continue; }
float disruption = aiTarget.Entity is Character c ? c.Params.SonarDisruption : aiTarget.SonarDisruption;
if (disruption <= 0.0f || !aiTarget.Enabled) { continue; }
float distSqr = Vector2.DistanceSquared(aiTarget.WorldPosition, pingSource);
if (distSqr > worldPingRadiusSqr) { continue; }
float disruptionDist = (float)Math.Sqrt(distSqr);
disruptedDirections.Add(new Pair<Vector2, float>((aiTarget.WorldPosition - pingSource) / disruptionDist, aiTarget.SonarDisruption));
CreateBlipsForDisruption(aiTarget.WorldPosition, aiTarget.SonarDisruption);
CreateBlipsForDisruption(aiTarget.WorldPosition, disruption);
}
}
@@ -1127,6 +1159,7 @@ namespace Barotrauma.Items.Components
foreach (Character c in Character.CharacterList)
{
if (c.AnimController.CurrentHull != null || !c.Enabled) { continue; }
if (c.Params.HideInSonar) { continue; }
if (DetectSubmarineWalls && c.AnimController.CurrentHull == null && item.CurrentHull != null) { continue; }
if (c.AnimController.SimplePhysicsEnabled)
@@ -1298,9 +1331,42 @@ namespace Barotrauma.Items.Components
sonarBlip.Draw(spriteBatch, center + pos, color * 0.5f, sonarBlip.Origin, 0, scale * 0.08f, SpriteEffects.None, 0);
}
private void DrawMarker(SpriteBatch spriteBatch, string label, string iconIdentifier, Vector2 position, float scale, Vector2 center, float radius)
private void DrawMarker(SpriteBatch spriteBatch, string label, string iconIdentifier, object targetIdentifier, Vector2 worldPosition, Vector2 transducerPosition, float scale, Vector2 center, float radius)
{
float dist = position.Length();
float dist = Vector2.Distance(worldPosition, transducerPosition);
if (Vector2.DistanceSquared(worldPosition, transducerPosition) > Range * Range)
{
if (markerDistances.TryGetValue(targetIdentifier, out CachedDistance cachedDistance))
{
if (Vector2.DistanceSquared(cachedDistance.TransducerWorldPos, transducerPosition) > 500 * 500 ||
Vector2.DistanceSquared(cachedDistance.WorldPos, worldPosition) > 500 * 500)
{
markerDistances.Remove(targetIdentifier);
CalculateDistance();
}
else
{
dist = cachedDistance.Distance;
}
}
else
{
CalculateDistance();
}
}
void CalculateDistance()
{
pathFinder ??= new PathFinder(WayPoint.WayPointList, indoorsSteering: false);
var path = pathFinder.FindPath(ConvertUnits.ToSimUnits(transducerPosition), ConvertUnits.ToSimUnits(worldPosition));
if (!path.Unreachable)
{
markerDistances.Add(targetIdentifier, new CachedDistance(transducerPosition, worldPosition, path.TotalLength));
dist = path.TotalLength;
}
}
Vector2 position = worldPosition - transducerPosition;
position *= zoom;
position *= scale;
@@ -390,7 +390,7 @@ namespace Barotrauma.Items.Components
};
// Sonar area
steerArea = new GUICustomComponent(new RectTransform(Vector2.One * GUI.RelativeHorizontalAspectRatio * Sonar.sonarAreaSize, GuiFrame.RectTransform, Anchor.CenterRight, scaleBasis: ScaleBasis.Smallest),
steerArea = new GUICustomComponent(new RectTransform(Sonar.GUISizeCalculation, GuiFrame.RectTransform, Anchor.CenterRight, scaleBasis: ScaleBasis.Smallest),
(spriteBatch, guiCustomComponent) => { DrawHUD(spriteBatch, guiCustomComponent.Rect); }, null);
steerRadius = steerArea.Rect.Width / 2;
@@ -667,7 +667,7 @@ namespace Barotrauma.Items.Components
if (Vector2.DistanceSquared(PlayerInput.MousePosition, steerArea.Rect.Center.ToVector2()) < steerRadius * steerRadius)
{
if (PlayerInput.PrimaryMouseButtonHeld() && !CrewManager.IsCommandInterfaceOpen && !GameSession.IsInfoFrameOpen)
if (PlayerInput.PrimaryMouseButtonHeld() && !CrewManager.IsCommandInterfaceOpen && !GameSession.IsTabMenuOpen)
{
Vector2 displaySubPos = (-sonar.DisplayOffset * sonar.Zoom) / sonar.Range * sonar.DisplayRadius * sonar.Zoom;
displaySubPos.Y = -displaySubPos.Y;
@@ -13,6 +13,8 @@ namespace Barotrauma.Items.Components
bool isStuck = msg.ReadBoolean();
if (isStuck)
{
ushort submarineID = msg.ReadUInt16();
ushort hullID = msg.ReadUInt16();
Vector2 simPosition = new Vector2(
msg.ReadSingle(),
msg.ReadSingle());
@@ -20,7 +22,12 @@ namespace Barotrauma.Items.Components
msg.ReadSingle(),
msg.ReadSingle());
UInt16 entityID = msg.ReadUInt16();
Entity entity = Entity.FindEntityByID(entityID);
Entity entity = Entity.FindEntityByID(entityID);
Submarine submarine = Entity.FindEntityByID(submarineID) as Submarine;
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)
{
@@ -30,12 +37,14 @@ namespace Barotrauma.Items.Components
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()})");
@@ -46,6 +55,7 @@ namespace Barotrauma.Items.Components
}
else if (entity is Item item)
{
if (item.Removed) { return; }
StickToTarget(item.body.FarseerBody, axis);
}
else if (entity is Submarine sub)
@@ -27,6 +27,8 @@ namespace Barotrauma.Items.Components
private FixActions requestStartFixAction;
public float FakeBrokenTimer;
[Serialize("", false, description: "An optional description of the needed repairs displayed in the repair interface.")]
public string Description
{
@@ -117,9 +119,18 @@ namespace Barotrauma.Items.Components
case "emitter":
case "particleemitter":
particleEmitters.Add(new ParticleEmitter(subElement));
particleEmitterConditionRanges.Add(new Vector2(
subElement.GetAttributeFloat("mincondition", 0.0f),
subElement.GetAttributeFloat("maxcondition", 100.0f)));
float minCondition = subElement.GetAttributeFloat("mincondition", 0.0f);
float maxCondition = subElement.GetAttributeFloat("maxcondition", 100.0f);
if (maxCondition < minCondition)
{
DebugConsole.ThrowError("Invalid damage particle configuration in the Repairable component of " + item.Name + ". MaxCondition needs to be larger than MinCondition.");
float temp = maxCondition;
maxCondition = minCondition;
minCondition = temp;
}
particleEmitterConditionRanges.Add(new Vector2(minCondition, maxCondition));
break;
}
}
@@ -127,6 +138,9 @@ namespace Barotrauma.Items.Components
partial void UpdateProjSpecific(float deltaTime)
{
FakeBrokenTimer -= deltaTime;
item.FakeBroken = FakeBrokenTimer > 0.0f;
if (!GameMain.IsMultiplayer)
{
switch (requestStartFixAction)
@@ -141,10 +155,10 @@ namespace Barotrauma.Items.Components
break;
}
}
for (int i = 0; i < particleEmitters.Count; i++)
{
if (item.ConditionPercentage >= particleEmitterConditionRanges[i].X && item.ConditionPercentage <= particleEmitterConditionRanges[i].Y)
if ((item.ConditionPercentage >= particleEmitterConditionRanges[i].X && item.ConditionPercentage <= particleEmitterConditionRanges[i].Y) || FakeBrokenTimer > 0.0f)
{
particleEmitters[i].Emit(deltaTime, item.WorldPosition, item.CurrentHull);
}
@@ -66,6 +66,15 @@ namespace Barotrauma.Items.Components
if (target == null) { return; }
Vector2 startPos = new Vector2(source.DrawPosition.X, -source.DrawPosition.Y);
var turret = source?.GetComponent<Turret>();
if (turret != null)
{
startPos = new Vector2(source.WorldRect.X + turret.TransformedBarrelPos.X, -(source.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;
}
}
Vector2 endPos = new Vector2(target.DrawPosition.X, -target.DrawPosition.Y);
if (Snapped)
@@ -379,7 +379,7 @@ namespace Barotrauma.Items.Components
ConnectionPanel.HighlightedWire = wire;
bool allowRewiring = GameMain.NetworkMember?.ServerSettings == null || GameMain.NetworkMember.ServerSettings.AllowRewiring;
if (allowRewiring && !wire.Locked && (!panel.Locked || Screen.Selected == GameMain.SubEditorScreen))
if (allowRewiring && (!wire.Locked && !panel.Locked || Screen.Selected == GameMain.SubEditorScreen))
{
//start dragging the wire
if (PlayerInput.PrimaryMouseButtonHeld()) { DraggingConnected = wire; }
@@ -56,15 +56,6 @@ namespace Barotrauma.Items.Components
};
}
public override void OnItemLoaded()
{
base.OnItemLoaded();
if (!string.IsNullOrEmpty(DisplayedWelcomeMessage))
{
ShowOnDisplay(DisplayedWelcomeMessage);
}
}
private void SendOutput(string input)
{
if (input.Length > MaxMessageLength)
@@ -123,6 +114,11 @@ namespace Barotrauma.Items.Components
public override void AddToGUIUpdateList()
{
base.AddToGUIUpdateList();
if (!string.IsNullOrEmpty(DisplayedWelcomeMessage))
{
ShowOnDisplay(DisplayedWelcomeMessage);
DisplayedWelcomeMessage = "";
}
if (shouldSelectInputBox)
{
inputBox.Select();
@@ -17,14 +17,60 @@ namespace Barotrauma.Items.Components
partial class WireSection
{
public VertexPositionColorTexture[] vertices;
public VertexPositionColorTexture[] shiftedVertices;
private float cachedWidth = 0f;
private void RecalculateVertices(Wire wire, float width)
{
if (MathUtils.NearlyEqual(cachedWidth, width)) { return; }
cachedWidth = width;
vertices = new VertexPositionColorTexture[4];
Vector2 expandDir = start-end;
expandDir.Normalize();
float temp = expandDir.X;
expandDir.X = -expandDir.Y;
expandDir.Y = -temp;
Rectangle srcRect = wire.wireSprite.SourceRect;
expandDir *= width * srcRect.Height * 0.5f;
Vector2 rectLocation = srcRect.Location.ToVector2();
Vector2 rectSize = srcRect.Size.ToVector2();
Vector2 textureSize = new Vector2(wire.wireSprite.Texture.Width, wire.wireSprite.Texture.Height);
Vector2 topLeftUv = rectLocation / textureSize;
Vector2 bottomRightUv = (rectLocation + rectSize) / textureSize;
Vector2 invStart = new Vector2(start.X, -start.Y);
Vector2 invEnd = new Vector2(end.X, -end.Y);
vertices[0] = new VertexPositionColorTexture(new Vector3(invStart + expandDir, 0f), Color.White, topLeftUv);
vertices[2] = new VertexPositionColorTexture(new Vector3(invEnd + expandDir, 0f), Color.White, new Vector2(bottomRightUv.X, topLeftUv.Y));
vertices[1] = new VertexPositionColorTexture(new Vector3(invStart - expandDir, 0f), Color.White, new Vector2(topLeftUv.X, bottomRightUv.Y));
vertices[3] = new VertexPositionColorTexture(new Vector3(invEnd - expandDir, 0f), Color.White, bottomRightUv);
shiftedVertices = (VertexPositionColorTexture[])vertices.Clone();
}
public void Draw(SpriteBatch spriteBatch, Wire wire, Color color, Vector2 offset, float depth, float width = 0.3f)
{
if (width <= 0f) { return; }
RecalculateVertices(wire, width);
for (int i=0;i<vertices.Length;i++)
{
shiftedVertices[i].Color = color;
shiftedVertices[i].Position = vertices[i].Position;
shiftedVertices[i].Position.X += offset.X;
shiftedVertices[i].Position.Y -= offset.Y;
}
spriteBatch.Draw(wire.wireSprite.Texture,
new Vector2(start.X + offset.X, -(start.Y + offset.Y)), wire.wireSprite.SourceRect, color,
-angle,
new Vector2(0.0f, wire.wireSprite.size.Y / 2.0f),
new Vector2(length / wire.wireSprite.size.X, width),
SpriteEffects.None,
shiftedVertices,
depth);
}
@@ -110,7 +156,7 @@ namespace Barotrauma.Items.Components
drawOffset = sub.DrawPosition + sub.HiddenSubPosition;
}
float depth = item.IsSelected ? 0.0f : wireSprite.Depth + ((item.ID % 100) * 0.00001f);
float depth = item.IsSelected ? 0.0f : Screen.Selected is SubEditorScreen editor && editor.WiringMode ? 0.00002f : wireSprite.Depth + ((item.ID % 100) * 0.00001f);
if (item.IsHighlighted)
{
@@ -239,10 +285,12 @@ namespace Barotrauma.Items.Components
public static void UpdateEditing(List<Wire> wires)
{
var doubleClicked = PlayerInput.DoubleClicked();
Wire equippedWire =
Character.Controlled?.SelectedItems[0]?.GetComponent<Wire>() ??
Character.Controlled?.SelectedItems[1]?.GetComponent<Wire>();
if (equippedWire != null)
if (equippedWire != null && GUI.MouseOn == null)
{
if (PlayerInput.PrimaryMouseButtonClicked() && Character.Controlled.SelectedConstruction == null)
{
@@ -252,7 +300,7 @@ namespace Barotrauma.Items.Components
}
//dragging a node of some wire
if (draggingWire != null)
if (draggingWire != null && !doubleClicked)
{
if (Character.Controlled != null)
{
@@ -283,15 +331,18 @@ namespace Barotrauma.Items.Components
if (selectedNodeIndex.HasValue)
{
nodeWorldPos.X = MathUtils.Round(nodeWorldPos.X, Submarine.GridSize.X / 2.0f);
nodeWorldPos.Y = MathUtils.Round(nodeWorldPos.Y, Submarine.GridSize.Y / 2.0f);
if (!PlayerInput.IsShiftDown())
{
nodeWorldPos.X = MathUtils.Round(nodeWorldPos.X, Submarine.GridSize.X / 2.0f);
nodeWorldPos.Y = MathUtils.Round(nodeWorldPos.Y, Submarine.GridSize.Y / 2.0f);
}
draggingWire.nodes[(int)selectedNodeIndex] = nodeWorldPos;
draggingWire.UpdateSections();
}
else
{
if (Vector2.DistanceSquared(nodeWorldPos, draggingWire.nodes[(int)highlightedNodeIndex]) > Submarine.GridSize.X * Submarine.GridSize.X)
if (Vector2.DistanceSquared(nodeWorldPos, draggingWire.nodes[(int)highlightedNodeIndex]) > Submarine.GridSize.X * Submarine.GridSize.X || PlayerInput.IsShiftDown())
{
selectedNodeIndex = highlightedNodeIndex;
}
@@ -304,6 +355,8 @@ namespace Barotrauma.Items.Components
return;
}
bool updateHighlight = true;
//a wire has been selected -> check if we should start dragging one of the nodes
float nodeSelectDist = 10, sectionSelectDist = 5;
highlightedNodeIndex = null;
@@ -359,6 +412,37 @@ namespace Barotrauma.Items.Components
{
selectedWire.nodes.RemoveAt(closestIndex);
selectedWire.UpdateSections();
}
// if only one end of the wire is disconnect pick it back up with double click
else if (doubleClicked && equippedWire == null && Character.Controlled != null && selectedWire.connections.Any(conn => conn != null))
{
if (selectedWire.connections[0] == null && closestIndex == 0 || selectedWire.connections[1] == null && closestIndex == selectedWire.nodes.Count - 1)
{
selectedWire.IsActive = true;
selectedWire.nodes.RemoveAt(closestIndex);
selectedWire.UpdateSections();
// flip the wire
if (closestIndex == 0)
{
selectedWire.nodes.Reverse();
selectedWire.connections[0] = selectedWire.connections[1];
selectedWire.connections[1] = null;
}
selectedWire.shouldClearConnections = false;
Character.Controlled.Inventory.TryPutItem(selectedWire.item, Character.Controlled, new List<InvSlotType> { InvSlotType.LeftHand, InvSlotType.RightHand });
foreach (var entity in MapEntity.mapEntityList)
{
if (entity is Item item)
{
item.GetComponent<ConnectionPanel>()?.DisconnectedWires.Remove(selectedWire);
}
}
MapEntity.SelectedList.Clear();
selectedWire.shouldClearConnections = true;
updateHighlight = false;
}
}
}
}
@@ -400,7 +484,7 @@ namespace Barotrauma.Items.Components
}
}
if (highlighted != null)
if (highlighted != null && updateHighlight)
{
highlighted.item.IsHighlighted = true;
if (PlayerInput.PrimaryMouseButtonClicked())
@@ -411,6 +495,20 @@ namespace Barotrauma.Items.Components
}
}
public bool IsMouseOn()
{
if (GUI.MouseOn == null)
{
Vector2 mousePos = GameMain.SubEditorScreen.Cam.ScreenToWorld(PlayerInput.MousePosition);
if (item.Submarine != null) { mousePos -= (item.Submarine.Position + item.Submarine.HiddenSubPosition); }
if (GetClosestNodeIndex(mousePos, 10, out _) > -1) { return true; }
if (GetClosestSectionIndex(mousePos, 10, out _) > -1) { return true; }
}
return false;
}
public void ClientRead(ServerNetObject type, IReadMessage msg, float sendingTime)
{
int eventIndex = msg.ReadRangedInteger(0, (int)Math.Ceiling(MaxNodeCount / (float)MaxNodesPerNetworkEvent));
@@ -5,7 +5,7 @@ using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.IO;
using Barotrauma.IO;
using System.Linq;
using System.Xml.Linq;
@@ -19,6 +19,8 @@ namespace Barotrauma.Items.Components
private float recoilTimer;
private float RetractionTime => Math.Max(Reload * RetractionDurationMultiplier, RecoilTime);
private RoundSound startMoveSound, endMoveSound, moveSound;
private SoundChannel moveSoundChannel;
@@ -83,6 +85,11 @@ namespace Barotrauma.Items.Components
}
}
public Sprite BarrelSprite
{
get { return barrelSprite; }
}
partial void InitProjSpecific(XElement element)
{
foreach (XElement subElement in element.Elements())
@@ -126,7 +133,7 @@ namespace Barotrauma.Items.Components
partial void LaunchProjSpecific()
{
recoilTimer = Math.Max(Reload, 0.1f);
recoilTimer = RetractionTime;
PlaySound(ActionType.OnUse);
Vector2 particlePos = new Vector2(item.WorldRect.X + transformedBarrelPos.X, item.WorldRect.Y - transformedBarrelPos.Y);
foreach (ParticleEmitter emitter in particleEmitters)
@@ -135,6 +142,12 @@ namespace Barotrauma.Items.Components
}
}
public override void UpdateBroken(float deltaTime, Camera cam)
{
base.UpdateBroken(deltaTime, cam);
recoilTimer -= deltaTime;
}
partial void UpdateProjSpecific(float deltaTime)
{
recoilTimer -= deltaTime;
@@ -232,15 +245,21 @@ namespace Barotrauma.Items.Components
float recoilOffset = 0.0f;
if (Math.Abs(RecoilDistance) > 0.0f && recoilTimer > 0.0f)
{
//move the barrel backwards 0.1 seconds after launching
if (recoilTimer >= Math.Max(Reload, 0.1f) - 0.1f)
float diff = RetractionTime - RecoilTime;
if (recoilTimer >= diff)
{
recoilOffset = RecoilDistance * (1.0f - (recoilTimer - (Math.Max(Reload, 0.1f) - 0.1f)) / 0.1f);
//move the barrel backwards 0.1 seconds (defined by RecoilTime) after launching
recoilOffset = RecoilDistance * (1.0f - (recoilTimer - diff) / RecoilTime);
}
else if (recoilTimer <= diff - RetractionDelay)
{
//move back to normal position while reloading
float t = diff - RetractionDelay;
recoilOffset = RecoilDistance * recoilTimer / t;
}
//move back to normal position while reloading
else
{
recoilOffset = RecoilDistance * recoilTimer / (Math.Max(Reload, 0.1f) - 0.1f);
recoilOffset = RecoilDistance;
}
}
@@ -504,7 +523,7 @@ namespace Barotrauma.Items.Components
public void ClientRead(ServerNetObject type, IReadMessage msg, float sendingTime)
{
UInt16 projectileID = msg.ReadUInt16();
float newTargetRotation = msg.ReadRangedSingle(minRotation, maxRotation, 8);
float newTargetRotation = msg.ReadRangedSingle(minRotation, maxRotation, 16);
if (Character.Controlled == null || user != Character.Controlled)
{
@@ -514,13 +533,21 @@ namespace Barotrauma.Items.Components
//projectile removed, do nothing
if (projectileID == 0) { return; }
if (!(Entity.FindEntityByID(projectileID) is Item projectile))
//ID ushort.MaxValue = launched without a projectile
if (projectileID == ushort.MaxValue)
{
DebugConsole.ThrowError("Failed to launch a projectile - item with the ID \"" + projectileID + " not found");
return;
Launch(null);
}
else
{
if (!(Entity.FindEntityByID(projectileID) is Item projectile))
{
DebugConsole.ThrowError("Failed to launch a projectile - item with the ID \"" + projectileID + " not found");
return;
}
Launch(projectile, launchRotation: newTargetRotation);
}
Launch(projectile);
}
}
}
@@ -31,7 +31,7 @@ namespace Barotrauma
public Sprite SlotSprite;
public Keys QuickUseKey;
public int InventoryKeyIndex = -1;
public int SubInventoryDir = -1;
@@ -191,7 +191,7 @@ namespace Barotrauma
public Item Item;
public bool IsSubSlot;
public string Tooltip;
public List<ColorData> TooltipColorData;
public List<RichTextData> TooltipRichTextData;
public SlotReference(Inventory parentInventory, InventorySlot slot, int slotIndex, bool isSubSlot, Inventory subInventory = null)
{
@@ -201,7 +201,7 @@ namespace Barotrauma
Inventory = subInventory;
IsSubSlot = isSubSlot;
Item = ParentInventory.Items[slotIndex];
TooltipColorData = ColorData.GetColorData(GetTooltip(Item), out Tooltip);
TooltipRichTextData = RichTextData.GetRichTextData(GetTooltip(Item), out Tooltip);
}
private string GetTooltip(Item item)
@@ -450,12 +450,33 @@ namespace Barotrauma
}
}*/
bool mouseOn = interactRect.Contains(PlayerInput.MousePosition) && !Locked && !mouseOnGUI;
bool mouseOn = interactRect.Contains(PlayerInput.MousePosition) && !Locked && !mouseOnGUI && !slot.Disabled;
// Delete item from container in sub editor
if (SubEditorScreen.IsSubEditor() && PlayerInput.IsCtrlDown())
{
draggingItem = null;
var mouseDrag = SubEditorScreen.MouseDragStart != Vector2.Zero && Vector2.Distance(PlayerInput.MousePosition, SubEditorScreen.MouseDragStart) >= GUI.Scale * 20;
if (mouseOn && (PlayerInput.PrimaryMouseButtonClicked() || mouseDrag))
{
if (item != null)
{
if (mouseDrag) { item.OwnInventory?.DeleteAllItems(); }
slot.ShowBorderHighlight(GUI.Style.Red, 0.1f, 0.4f);
if (!mouseDrag)
{
GUI.PlayUISound(GUISoundType.PickItem);
}
item.Remove();
}
}
}
if (PlayerInput.LeftButtonHeld() && PlayerInput.RightButtonHeld())
{
mouseOn = false;
}
if (selectedSlot != null && selectedSlot.Slot != slot)
{
//subinventory slot highlighted -> don't allow highlighting this one
@@ -476,11 +497,14 @@ namespace Barotrauma
// &&
//(highlightedSubInventories.Count == 0 || highlightedSubInventories.Contains(this) || highlightedSubInventorySlot?.Slot == slot || highlightedSubInventory.Owner == item))
{
slot.State = GUIComponent.ComponentState.Hover;
if (selectedSlot == null || (!selectedSlot.IsSubSlot && isSubSlot))
{
selectedSlot = new SlotReference(this, slot, slotIndex, isSubSlot, Items[slotIndex]?.GetComponent<ItemContainer>()?.Inventory);
var slotRef = new SlotReference(this, slot, slotIndex, isSubSlot, Items[slotIndex]?.GetComponent<ItemContainer>()?.Inventory);
if (Screen.Selected is SubEditorScreen editor && !editor.WiringMode && slotRef.ParentInventory is CharacterInventory) { return; }
selectedSlot = slotRef;
}
if (draggingItem == null)
@@ -668,18 +692,34 @@ namespace Barotrauma
DrawSlot(spriteBatch, this, slots[i], Items[i], i, drawItem);
}
}
/// <summary>
/// Check if the mouse is hovering on top of the slot
/// </summary>
/// <param name="slot">The desired slot we want to check</param>
/// <returns>True if our mouse is hover on the slot, false otherwise</returns>
public static bool IsMouseOnSlot(InventorySlot slot)
{
var rect = new Rectangle(slot.InteractRect.X, slot.InteractRect.Y, slot.InteractRect.Width, slot.InteractRect.Height);
rect.Offset(slot.DrawOffset);
return rect.Contains(PlayerInput.MousePosition);
}
/// <summary>
/// Is the mouse on any inventory element (slot, equip button, subinventory...)
/// </summary>
/// <returns></returns>
public static bool IsMouseOnInventory()
public static bool IsMouseOnInventory(bool ignoreDraggedItem = false)
{
if (Character.Controlled == null) return false;
var isSubEditor = Screen.Selected is SubEditorScreen editor && !editor.WiringMode;
if (Character.Controlled == null) { return false; }
if (draggingItem != null || DraggingInventory != null) return true;
if (!ignoreDraggedItem)
{
if (draggingItem != null || DraggingInventory != null) { return true; }
}
if (Character.Controlled.Inventory != null)
if (Character.Controlled.Inventory != null && !isSubEditor)
{
var inv = Character.Controlled.Inventory;
for (var i = 0; i < inv.slots.Length; i++)
@@ -699,7 +739,8 @@ namespace Barotrauma
}
}
}
if (Character.Controlled.SelectedCharacter?.Inventory != null)
if (Character.Controlled.SelectedCharacter?.Inventory != null && !isSubEditor)
{
var inv = Character.Controlled.SelectedCharacter.Inventory;
for (var i = 0; i < inv.slots.Length; i++)
@@ -830,9 +871,9 @@ namespace Barotrauma
return CursorState.Default;
}
protected static void DrawToolTip(SpriteBatch spriteBatch, string toolTip, Rectangle highlightedSlot, List<ColorData> colorData = null)
protected static void DrawToolTip(SpriteBatch spriteBatch, string toolTip, Rectangle highlightedSlot, List<RichTextData> richTextData = null)
{
GUIComponent.DrawToolTip(spriteBatch, toolTip, highlightedSlot, colorData);
GUIComponent.DrawToolTip(spriteBatch, toolTip, highlightedSlot, richTextData);
}
public void DrawSubInventory(SpriteBatch spriteBatch, int slotIndex)
@@ -928,7 +969,8 @@ namespace Barotrauma
{
Character.Controlled.ClearInputs();
if (CharacterHealth.OpenHealthWindow != null &&
if (!IsMouseOnInventory(ignoreDraggedItem: true) &&
CharacterHealth.OpenHealthWindow != null &&
CharacterHealth.OpenHealthWindow.OnItemDropped(draggingItem, false))
{
draggingItem = null;
@@ -946,8 +988,33 @@ namespace Barotrauma
}
else
{
GUI.PlayUISound(GUISoundType.DropItem);
draggingItem.Drop(Character.Controlled);
bool removed = false;
if (Screen.Selected is SubEditorScreen editor)
{
if (editor.EntityMenu.Rect.Contains(PlayerInput.MousePosition))
{
draggingItem.Remove();
removed = true;
}
else
{
if (editor.WiringMode)
{
draggingItem.Remove();
removed = true;
}
else
{
draggingItem.Drop(Character.Controlled);
}
}
}
else
{
draggingItem.Drop(Character.Controlled);
}
GUI.PlayUISound(removed ? GUISoundType.PickItem : GUISoundType.DropItem);
}
}
else if (selectedSlot.ParentInventory.Items[selectedSlot.SlotIndex] != draggingItem)
@@ -1015,7 +1082,7 @@ namespace Barotrauma
protected static Rectangle GetSubInventoryHoverArea(SlotReference subSlot)
{
Rectangle hoverArea;
if (!subSlot.Inventory.Movable())
if (!subSlot.Inventory.Movable() || Character.Controlled?.Inventory == subSlot.ParentInventory && !Character.Controlled.HasEquippedItem(subSlot.Item))
{
hoverArea = subSlot.Slot.Rect;
hoverArea.Location += subSlot.Slot.DrawOffset.ToPoint();
@@ -1038,7 +1105,9 @@ namespace Barotrauma
}
if (subSlot.Slot.SubInventoryDir < 0)
{
hoverArea.Height -= hoverArea.Bottom - subSlot.Slot.Rect.Bottom;
// 24/2/2020 - the below statement makes the sub inventory extend all the way to the bottom of the screen because of a double negative
// Not sure if it's intentional or not but it was causing hover issues and disabling it seems to have no detrimental effects.
// hoverArea.Height -= hoverArea.Bottom - subSlot.Slot.Rect.Bottom;
}
else
{
@@ -1088,7 +1157,7 @@ namespace Barotrauma
string toolTip = mouseOnHealthInterface ? TextManager.Get("QuickUseAction.UseTreatment") :
Character.Controlled.FocusedItem != null ?
TextManager.GetWithVariable("PutItemIn", "[itemname]", Character.Controlled.FocusedItem.Name, true) :
TextManager.Get("DropItem");
TextManager.Get(Screen.Selected is SubEditorScreen editor && editor.EntityMenu.Rect.Contains(PlayerInput.MousePosition) ? "Delete" : "DropItem");
int textWidth = (int)Math.Max(GUI.Font.MeasureString(draggingItem.Name).X, GUI.SmallFont.MeasureString(toolTip).X);
int textSpacing = (int)(15 * GUI.Scale);
Point shadowBorders = (new Point(40, 10)).Multiply(GUI.Scale);
@@ -1111,7 +1180,7 @@ namespace Barotrauma
{
Rectangle slotRect = selectedSlot.Slot.Rect;
slotRect.Location += selectedSlot.Slot.DrawOffset.ToPoint();
DrawToolTip(spriteBatch, selectedSlot.Tooltip, slotRect, selectedSlot.TooltipColorData);
DrawToolTip(spriteBatch, selectedSlot.Tooltip, slotRect, selectedSlot.TooltipRichTextData);
}
}
@@ -1154,6 +1223,11 @@ namespace Barotrauma
if (inventory != null && inventory.Locked) { slotColor = Color.Gray * 0.5f; }
spriteBatch.Draw(slotSprite.Texture, rect, slotSprite.SourceRect, slotColor);
if (SubEditorScreen.IsSubEditor() && PlayerInput.IsCtrlDown() && selectedSlot?.Slot == slot)
{
GUI.DrawRectangle(spriteBatch, rect, GUI.Style.Red * 0.3f, isFilled: true);
}
bool canBePut = false;
@@ -1181,7 +1255,7 @@ namespace Barotrauma
if (item != null && drawItem)
{
if (!item.IsFullCondition && (itemContainer == null || !itemContainer.ShowConditionInContainedStateIndicator))
if (!item.IsFullCondition && !item.Prefab.HideConditionBar && (itemContainer == null || !itemContainer.ShowConditionInContainedStateIndicator))
{
GUI.DrawRectangle(spriteBatch, new Rectangle(rect.X, rect.Bottom - 8, rect.Width, 8), Color.Black * 0.8f, true);
GUI.DrawRectangle(spriteBatch,
@@ -1308,10 +1382,10 @@ namespace Barotrauma
if (inventory != null &&
!inventory.Locked &&
Character.Controlled?.Inventory == inventory &&
slot.QuickUseKey != Keys.None)
slot.InventoryKeyIndex != -1)
{
spriteBatch.Draw(slotHotkeySprite.Texture, rect.ScaleSize(1.15f), slotHotkeySprite.SourceRect, slotColor);
GUI.DrawString(spriteBatch, rect.Location.ToVector2() + new Vector2((int)(4.25f * UIScale), (int)Math.Ceiling(-1.5f * UIScale)), slot.QuickUseKey.ToString().Substring(1, 1), Color.Black, font: GUI.HotkeyFont);
GUI.DrawString(spriteBatch, rect.Location.ToVector2() + new Vector2((int)(4.25f * UIScale), (int)Math.Ceiling(-1.5f * UIScale)), GameMain.Config.InventoryKeyBind(slot.InventoryKeyIndex).Name, Color.Black, font: GUI.HotkeyFont);
}
}
@@ -32,17 +32,28 @@ namespace Barotrauma
private readonly Dictionary<DecorativeSprite, DecorativeSprite.State> spriteAnimState = new Dictionary<DecorativeSprite, DecorativeSprite.State>();
public bool FakeBroken;
private Sprite activeSprite;
public override Sprite Sprite
{
get { return activeSprite; }
}
public override bool DrawOverWater
public override Rectangle Rect
{
get { return base.DrawOverWater || (GetComponent<Wire>() != null && IsSelected); }
get { return base.Rect; }
set
{
cachedVisibleSize = null;
base.Rect = value;
}
}
public override bool DrawBelowWater => (!(Screen.Selected is SubEditorScreen editor) || !editor.WiringMode || !isWire) && base.DrawBelowWater;
public override bool DrawOverWater => base.DrawOverWater || (IsSelected || Screen.Selected is SubEditorScreen editor && editor.WiringMode) && isWire;
private GUITextBlock itemInUseWarning;
private GUITextBlock ItemInUseWarning
{
@@ -62,6 +73,10 @@ namespace Barotrauma
{
get
{
if (!GameMain.SubEditorScreen.ShowThalamus && prefab.Category.HasFlag(MapEntityCategory.Thalamus))
{
return false;
}
return parentInventory == null && (body == null || body.Enabled) && ShowItems;
}
}
@@ -156,6 +171,14 @@ namespace Barotrauma
decorativeSprite.Sprite.EnsureLazyLoaded();
spriteAnimState.Add(decorativeSprite, new DecorativeSprite.State());
}
UpdateSpriteStates(0.0f);
}
private Vector2? cachedVisibleSize;
public void ResetCachedVisibleSize()
{
cachedVisibleSize = null;
}
public override bool IsVisible(Rectangle worldView)
@@ -167,19 +190,28 @@ namespace Barotrauma
}
//no drawable components and the body has been disabled = nothing to draw
if (drawableComponents.Count == 0 && body != null && !body.Enabled)
if (!hasComponentsToDraw && body != null && !body.Enabled)
{
return false;
}
float padding = 100.0f;
Vector2 size = new Vector2(rect.Width + padding, rect.Height + padding);
foreach (IDrawableComponent drawable in drawableComponents)
Vector2 size;
if (cachedVisibleSize.HasValue)
{
size.X = Math.Max(drawable.DrawSize.X, size.X);
size.Y = Math.Max(drawable.DrawSize.Y, size.Y);
size = cachedVisibleSize.Value;
}
else
{
float padding = 100.0f;
size = new Vector2(rect.Width + padding, rect.Height + padding);
foreach (IDrawableComponent drawable in drawableComponents)
{
size.X = Math.Max(drawable.DrawSize.X, size.X);
size.Y = Math.Max(drawable.DrawSize.Y, size.Y);
}
size *= 0.5f;
cachedVisibleSize = size;
}
size *= 0.5f;
//cache world position so we don't need to calculate it 4 times
Vector2 worldPosition = WorldPosition;
@@ -199,7 +231,8 @@ namespace Barotrauma
BrokenItemSprite fadeInBrokenSprite = null;
float fadeInBrokenSpriteAlpha = 0.0f;
if (condition < Prefab.Health)
float displayCondition = FakeBroken ? 0.0f : condition;
if (displayCondition < Prefab.Health)
{
for (int i = 0; i < Prefab.BrokenSprites.Count; i++)
{
@@ -207,14 +240,14 @@ namespace Barotrauma
{
float min = i > 0 ? Prefab.BrokenSprites[i - i].MaxCondition : 0.0f;
float max = Prefab.BrokenSprites[i].MaxCondition;
fadeInBrokenSpriteAlpha = 1.0f - ((condition - min) / (max - min));
fadeInBrokenSpriteAlpha = 1.0f - ((displayCondition - min) / (max - min));
if (fadeInBrokenSpriteAlpha > 0.0f && fadeInBrokenSpriteAlpha < 1.0f)
{
fadeInBrokenSprite = Prefab.BrokenSprites[i];
}
continue;
}
if (condition <= Prefab.BrokenSprites[i].MaxCondition)
if (displayCondition <= Prefab.BrokenSprites[i].MaxCondition)
{
activeSprite = Prefab.BrokenSprites[i].Sprite;
break;
@@ -262,7 +295,7 @@ namespace Barotrauma
float rotation = decorativeSprite.GetRotation(ref spriteAnimState[decorativeSprite].RotationState);
Vector2 offset = decorativeSprite.GetOffset(ref spriteAnimState[decorativeSprite].OffsetState) * Scale;
decorativeSprite.Sprite.Draw(spriteBatch, new Vector2(DrawPosition.X + offset.X, -(DrawPosition.Y + offset.Y)), color,
SpriteRotation + rotation, Scale, activeSprite.effects,
SpriteRotation + rotation, decorativeSprite.Scale * Scale, activeSprite.effects,
depth: Math.Min(depth + (decorativeSprite.Sprite.Depth - activeSprite.Depth), 0.999f));
}
}
@@ -306,7 +339,7 @@ namespace Barotrauma
Vector2 transformedOffset = new Vector2(ca * offset.X + sa * offset.Y, -sa * offset.X + ca * offset.Y);
decorativeSprite.Sprite.Draw(spriteBatch, new Vector2(DrawPosition.X + transformedOffset.X, -(DrawPosition.Y + transformedOffset.Y)), color,
-body.Rotation + rotation, Scale, activeSprite.effects,
-body.Rotation + rotation, decorativeSprite.Scale * Scale, activeSprite.effects,
depth: depth + (decorativeSprite.Sprite.Depth - activeSprite.Depth));
}
}
@@ -671,6 +704,13 @@ namespace Barotrauma
HUDLayoutSettings.ChatBoxArea.Width + disallowedPadding, HUDLayoutSettings.ChatBoxArea.Height));
}
if (Screen.Selected is SubEditorScreen editor)
{
disallowedAreas.Add(editor.EntityMenu.Rect);
disallowedAreas.Add(editor.TopPanel.Rect);
disallowedAreas.Add(editor.ToggleEntityMenuButton.Rect);
}
GUI.PreventElementOverlap(elementsToMove, disallowedAreas,
new Rectangle(
0, 20,
@@ -826,19 +866,21 @@ namespace Barotrauma
}
readonly List<ColoredText> texts = new List<ColoredText>();
public List<ColoredText> GetHUDTexts(Character character)
public List<ColoredText> GetHUDTexts(Character character, bool recreateHudTexts = true)
{
// Always create the texts if they have not yet been created
if (texts.Any() && !recreateHudTexts) { return texts; }
texts.Clear();
foreach (ItemComponent ic in components)
{
if (string.IsNullOrEmpty(ic.DisplayMsg)) continue;
if (!ic.CanBePicked && !ic.CanBeSelected) continue;
if (ic is Holdable holdable && !holdable.CanBeDeattached()) continue;
if (string.IsNullOrEmpty(ic.DisplayMsg)) { continue; }
if (!ic.CanBePicked && !ic.CanBeSelected) { continue; }
if (ic is Holdable holdable && !holdable.CanBeDeattached()) { continue; }
Color color = Color.Gray;
if (ic.HasRequiredItems(character, false))
{
if (ic is Repairable repairable)
if (ic is Repairable)
{
if (!IsFullCondition) { color = Color.Cyan; }
}
@@ -847,9 +889,12 @@ namespace Barotrauma
color = Color.Cyan;
}
}
texts.Add(new ColoredText(ic.DisplayMsg, color, false));
}
if ((PlayerInput.KeyDown(Keys.LeftShift) || PlayerInput.KeyDown(Keys.RightShift)) && CrewManager.DoesItemHaveContextualOrders(this))
{
texts.Add(new ColoredText(TextManager.ParseInputTypes(TextManager.Get("itemmsgcontextualorders")), Color.Cyan, false));
}
return texts;
}
@@ -857,17 +902,17 @@ namespace Barotrauma
{
if (Screen.Selected is SubEditorScreen)
{
if (editingHUD != null && editingHUD.UserData == this) editingHUD.AddToGUIUpdateList();
if (editingHUD != null && editingHUD.UserData == this) { editingHUD.AddToGUIUpdateList(); }
}
else
{
if (HasInGameEditableProperties)
{
if (editingHUD != null && editingHUD.UserData == this) editingHUD.AddToGUIUpdateList();
if (editingHUD != null && editingHUD.UserData == this) { editingHUD.AddToGUIUpdateList(); }
}
}
if (Character.Controlled != null && Character.Controlled?.SelectedConstruction != this) return;
if (Character.Controlled != null && Character.Controlled?.SelectedConstruction != this) { return; }
bool needsLayoutUpdate = false;
foreach (ItemComponent ic in activeHUDs)
@@ -1213,8 +1258,8 @@ namespace Barotrauma
{
if (itemContainerIndex < 0 || itemContainerIndex >= parentItem.components.Count)
{
string errorMsg = "Failed to spawn item \"" + (itemIdentifier ?? "null") +
"\" in the inventory of \"" + parentItem.prefab.Identifier + "\" (component index out of range). Index: " + itemContainerIndex + ", components: " + parentItem.components.Count + ".";
string errorMsg =
$"Failed to spawn item \"{(itemIdentifier ?? "null")}\" in the inventory of \"{parentItem.prefab.Identifier} ({parentItem.ID})\" (component index out of range). Index: {itemContainerIndex}, components: {parentItem.components.Count}.";
GameAnalyticsManager.AddErrorEventOnce("Item.ReadSpawnData:ContainerIndexOutOfRange" + (itemName ?? "null") + (itemIdentifier ?? "null"),
GameAnalyticsSDK.Net.EGAErrorSeverity.Error,
errorMsg);
@@ -66,16 +66,17 @@ namespace Barotrauma
[Serialize("", false)]
public string ImpactSoundTag { get; private set; }
public override void UpdatePlacing(Camera cam)
{
Vector2 position = Submarine.MouseToWorldGrid(cam, Submarine.MainSub);
if (PlayerInput.SecondaryMouseButtonClicked())
{
selected = null;
return;
}
var potentialContainer = MapEntity.GetPotentialContainer(position);
if (!ResizeHorizontal && !ResizeVertical)
{
@@ -88,6 +89,14 @@ namespace Barotrauma
item.SetTransform(ConvertUnits.ToSimUnits(Submarine.MainSub == null ? item.Position : item.Position - Submarine.MainSub.Position), 0.0f);
item.FindHull();
if (PlayerInput.IsShiftDown())
{
if (potentialContainer?.OwnInventory?.TryPutItem(item, Character.Controlled) ?? false)
{
GUI.PlayUISound(GUISoundType.PickItem);
}
}
placePosition = Vector2.Zero;
return;
}
@@ -124,6 +133,12 @@ namespace Barotrauma
}
}
if (potentialContainer != null)
{
potentialContainer.IsHighlighted = true;
}
//if (PlayerInput.GetMouseState.RightButton == ButtonState.Pressed) selected = null;
}
@@ -141,26 +156,10 @@ namespace Barotrauma
if (!ResizeHorizontal && !ResizeVertical)
{
sprite.Draw(spriteBatch, new Vector2(position.X, -position.Y) + sprite.size / 2.0f * Scale, SpriteColor, scale: Scale);
}
else
{
Vector2 placeSize = size;
if (placePosition == Vector2.Zero)
{
if (PlayerInput.PrimaryMouseButtonHeld()) placePosition = position;
}
else
{
if (ResizeHorizontal)
placeSize.X = Math.Max(position.X - placePosition.X, size.X);
if (ResizeVertical)
placeSize.Y = Math.Max(placePosition.Y - position.Y, size.Y);
position = placePosition;
}
if (sprite != null) sprite.DrawTiled(spriteBatch, new Vector2(position.X, -position.Y), placeSize, color: SpriteColor);
sprite?.DrawTiled(spriteBatch, new Vector2(position.X, -position.Y), size, color: SpriteColor);
}
}