2f107db...5202af9
This commit is contained in:
@@ -458,8 +458,8 @@ namespace Barotrauma
|
||||
slots[i].QuickUseTimer = Math.Max(0.1f, slots[i].QuickUseTimer + deltaTime);
|
||||
if (slots[i].QuickUseTimer >= 1.0f)
|
||||
{
|
||||
CreateNetworkEvent();
|
||||
Items[i].Drop(Character.Controlled);
|
||||
GUI.PlayUISound(GUISoundType.DropItem);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -4,7 +4,6 @@ using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
|
||||
|
||||
namespace Barotrauma.Items.Components
|
||||
{
|
||||
partial class Door : Pickable, IDrawableComponent, IServerSerializable
|
||||
@@ -12,6 +11,15 @@ namespace Barotrauma.Items.Components
|
||||
private ConvexHull convexHull;
|
||||
private ConvexHull convexHull2;
|
||||
|
||||
//openState when the vertices of the convex hull were last calculated
|
||||
private float lastConvexHullState;
|
||||
|
||||
public Vector2 DrawSize
|
||||
{
|
||||
//use the extents of the item as the draw size
|
||||
get { return Vector2.Zero; }
|
||||
}
|
||||
|
||||
private Vector2[] GetConvexHullCorners(Rectangle rect)
|
||||
{
|
||||
Vector2[] corners = new Vector2[4];
|
||||
@@ -32,7 +40,7 @@ namespace Barotrauma.Items.Components
|
||||
(int)(doorSprite.size.Y * item.Scale));
|
||||
|
||||
Rectangle rect = doorRect;
|
||||
if (isHorizontal)
|
||||
if (IsHorizontal)
|
||||
{
|
||||
rect.Width = (int)(rect.Width * (1.0f - openState));
|
||||
}
|
||||
@@ -41,9 +49,9 @@ namespace Barotrauma.Items.Components
|
||||
rect.Height = (int)(rect.Height * (1.0f - openState));
|
||||
}
|
||||
|
||||
if (window.Height > 0 && window.Width > 0)
|
||||
if (Window.Height > 0 && Window.Width > 0)
|
||||
{
|
||||
rect.Height = -(int)(window.Y * item.Scale);
|
||||
rect.Height = -(int)(Window.Y * item.Scale);
|
||||
|
||||
rect.Y += (int)(doorRect.Height * openState);
|
||||
rect.Height = Math.Max(rect.Height - (rect.Y - doorRect.Y), 0);
|
||||
@@ -52,7 +60,7 @@ namespace Barotrauma.Items.Components
|
||||
if (convexHull2 != null)
|
||||
{
|
||||
Rectangle rect2 = doorRect;
|
||||
rect2.Y = rect2.Y + (int)((window.Y * item.Scale - window.Height * item.Scale));
|
||||
rect2.Y = rect2.Y + (int)((Window.Y * item.Scale - Window.Height * item.Scale));
|
||||
|
||||
rect2.Y += (int)(doorRect.Height * openState);
|
||||
rect2.Y = Math.Min(doorRect.Y, rect2.Y);
|
||||
@@ -105,11 +113,11 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
if (openState == 1.0f)
|
||||
{
|
||||
body.Enabled = false;
|
||||
Body.Enabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (isHorizontal)
|
||||
if (IsHorizontal)
|
||||
{
|
||||
Vector2 pos = new Vector2(item.Rect.X, item.Rect.Y - item.Rect.Height / 2);
|
||||
if (item.Submarine != null) pos += item.Submarine.DrawPosition;
|
||||
@@ -159,9 +167,49 @@ namespace Barotrauma.Items.Components
|
||||
(int)brokenSprite.size.X, (int)(brokenSprite.size.Y * (1.0f - openState))),
|
||||
color * alpha, 0.0f, brokenSprite.Origin, scale * item.Scale, SpriteEffects.None, brokenSprite.Depth);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
partial void SetState(bool open, bool isNetworkMessage, bool sendNetworkMessage)
|
||||
{
|
||||
if (isStuck ||
|
||||
(PredictedState == null && isOpen == open) ||
|
||||
(PredictedState != null && isOpen == PredictedState.Value && isOpen == open))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (GameMain.Client != null && !isNetworkMessage)
|
||||
{
|
||||
bool stateChanged = open != PredictedState;
|
||||
|
||||
//clients can "predict" that the door opens/closes when a signal is received
|
||||
//the prediction will be reset after 1 second, setting the door to a state
|
||||
//sent by the server, or reverting it back to its old state if no msg from server was received
|
||||
PredictedState = open;
|
||||
resetPredictionTimer = CorrectionDelay;
|
||||
if (stateChanged) PlaySound(ActionType.OnUse, item.WorldPosition);
|
||||
}
|
||||
else
|
||||
{
|
||||
isOpen = open;
|
||||
if (!isNetworkMessage || open != PredictedState) PlaySound(ActionType.OnUse, item.WorldPosition);
|
||||
}
|
||||
|
||||
//opening a partially stuck door makes it less stuck
|
||||
if (isOpen) stuck = MathHelper.Clamp(stuck - 30.0f, 0.0f, 100.0f);
|
||||
|
||||
}
|
||||
|
||||
public override void ClientRead(ServerNetObject type, Lidgren.Network.NetBuffer msg, float sendingTime)
|
||||
{
|
||||
base.ClientRead(type, msg, sendingTime);
|
||||
|
||||
SetState(msg.ReadBoolean(), isNetworkMessage: true, sendNetworkMessage: false);
|
||||
Stuck = msg.ReadRangedSingle(0.0f, 100.0f, 8);
|
||||
|
||||
PredictedState = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,15 @@ namespace Barotrauma.Items.Components
|
||||
get { return RoundSound.Range; }
|
||||
}
|
||||
|
||||
|
||||
public float VolumeMultiplier
|
||||
{
|
||||
get { return RoundSound.Volume; }
|
||||
}
|
||||
|
||||
public float Range
|
||||
{
|
||||
get { return RoundSound.Range; }
|
||||
}
|
||||
|
||||
public readonly bool Loop;
|
||||
|
||||
@@ -309,15 +317,15 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
private float GetSoundVolume(ItemSound sound)
|
||||
{
|
||||
if (sound == null) return 0.0f;
|
||||
if (sound.VolumeProperty == "") return 1.0f;
|
||||
if (sound == null) { return 0.0f; }
|
||||
if (sound.VolumeProperty == "") { return sound.VolumeMultiplier; }
|
||||
|
||||
if (properties.TryGetValue(sound.VolumeProperty.ToLowerInvariant(), out SerializableProperty property))
|
||||
if (properties.TryGetValue(sound.VolumeProperty, out SerializableProperty property))
|
||||
{
|
||||
float newVolume = 0.0f;
|
||||
try
|
||||
{
|
||||
newVolume = (float)property.GetValue();
|
||||
newVolume = (float)property.GetValue(this);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -353,7 +361,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
return null;
|
||||
}
|
||||
foreach (ItemComponent component in item.components)
|
||||
foreach (ItemComponent component in item.Components)
|
||||
{
|
||||
if (component.name.ToLower() == LinkUIToComponent.ToLower())
|
||||
{
|
||||
@@ -427,9 +435,10 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
|
||||
RoundSound sound = Submarine.LoadRoundSound(subElement);
|
||||
if (sound == null) { break; }
|
||||
ItemSound itemSound = new ItemSound(sound, type, subElement.GetAttributeBool("loop", false))
|
||||
{
|
||||
VolumeProperty = subElement.GetAttributeString("volumeproperty", "")
|
||||
VolumeProperty = subElement.GetAttributeString("volumeproperty", "").ToLowerInvariant()
|
||||
};
|
||||
|
||||
if (soundSelectionModes == null) soundSelectionModes = new Dictionary<ActionType, SoundSelectionMode>();
|
||||
|
||||
@@ -72,7 +72,13 @@ namespace Barotrauma.Items.Components
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
|
||||
public Vector2 DrawSize
|
||||
{
|
||||
//use the extents of the item as the draw size
|
||||
get { return Vector2.Zero; }
|
||||
}
|
||||
|
||||
partial void InitProjSpecific(XElement element)
|
||||
{
|
||||
foreach (XElement subElement in element.Elements())
|
||||
@@ -169,9 +175,10 @@ namespace Barotrauma.Items.Components
|
||||
item.IsHighlighted = false;
|
||||
}
|
||||
|
||||
if (containedItem.body != null)
|
||||
if (containedItem.body != null &&
|
||||
Math.Abs(containedItem.body.FarseerBody.Rotation - currentRotation) > 0.001f)
|
||||
{
|
||||
containedItem.body.FarseerBody.Rotation = currentRotation;
|
||||
containedItem.body.SetTransformIgnoreContacts(containedItem.body.SimPosition, currentRotation);
|
||||
}
|
||||
|
||||
containedItem.Sprite.Draw(
|
||||
|
||||
@@ -209,6 +209,7 @@ namespace Barotrauma.Items.Components
|
||||
return;
|
||||
}
|
||||
|
||||
textBlock.TextDepth = item.SpriteDepth - 0.0001f;
|
||||
textBlock.TextOffset = drawPos - textBlock.Rect.Location.ToVector2() + new Vector2(scrollAmount + scrollPadding, 0.0f);
|
||||
textBlock.DrawManually(spriteBatch);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,11 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
partial class LightComponent : Powered, IServerSerializable, IDrawableComponent
|
||||
{
|
||||
public Vector2 DrawSize
|
||||
{
|
||||
get { return new Vector2(light.Range * 2, light.Range * 2); }
|
||||
}
|
||||
|
||||
private LightSource light;
|
||||
public LightSource Light
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
if (focusTarget != null && character.ViewTarget == focusTarget)
|
||||
{
|
||||
foreach (ItemComponent ic in focusTarget.components)
|
||||
foreach (ItemComponent ic in focusTarget.Components)
|
||||
{
|
||||
ic.DrawHUD(spriteBatch, character);
|
||||
}
|
||||
|
||||
@@ -79,12 +79,8 @@ namespace Barotrauma.Items.Components
|
||||
SetActive(!IsActive, Character.Controlled);
|
||||
|
||||
currPowerConsumption = IsActive ? powerConsumption : 0.0f;
|
||||
|
||||
if (GameMain.Server != null)
|
||||
{
|
||||
item.CreateServerEvent(this);
|
||||
}
|
||||
else if (GameMain.Client != null)
|
||||
|
||||
if (GameMain.Client != null)
|
||||
{
|
||||
item.CreateClientEvent(this);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,12 @@ namespace Barotrauma.Items.Components
|
||||
private set;
|
||||
}
|
||||
|
||||
public Vector2 DrawSize
|
||||
{
|
||||
//use the extents of the item as the draw size
|
||||
get { return Vector2.Zero; }
|
||||
}
|
||||
|
||||
partial void InitProjSpecific(XElement element)
|
||||
{
|
||||
powerIndicator = new GUITickBox(new RectTransform(new Point(30, 30), GuiFrame.RectTransform) { RelativeOffset = new Vector2(0.05f, 0.15f) },
|
||||
@@ -51,12 +57,8 @@ namespace Barotrauma.Items.Components
|
||||
if (Math.Abs(newTargetForce - targetForce) < 0.01) return false;
|
||||
|
||||
targetForce = newTargetForce;
|
||||
if (GameMain.Server != null)
|
||||
{
|
||||
item.CreateServerEvent(this);
|
||||
GameServer.Log(Character.Controlled.LogName + " set the force speed of " + item.Name + " to " + (int)(targetForce) + " %", ServerLog.MessageType.ItemInteraction);
|
||||
}
|
||||
else if (GameMain.Client != null)
|
||||
|
||||
if (GameMain.Client != null)
|
||||
{
|
||||
correctionTimer = CorrectionDelay;
|
||||
item.CreateClientEvent(this);
|
||||
|
||||
@@ -306,13 +306,6 @@ namespace Barotrauma.Items.Components
|
||||
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), paddedFrame.RectTransform), text,
|
||||
textColor: inadequateSkills.Any() ? Color.Red : Color.LightGreen, font: GUI.SmallFont);
|
||||
}
|
||||
|
||||
if (tooltip != null)
|
||||
{
|
||||
GUIComponent.DrawToolTip(spriteBatch, tooltip.Second, tooltip.First);
|
||||
tooltip = null;
|
||||
}
|
||||
}
|
||||
|
||||
float degreeOfSuccess = user == null ? 0.0f : DegreeOfSuccess(user, selectedItem.RequiredSkills);
|
||||
if (degreeOfSuccess > 0.5f) { degreeOfSuccess = 1.0f; }
|
||||
@@ -343,11 +336,7 @@ namespace Barotrauma.Items.Components
|
||||
CancelFabricating(Character.Controlled);
|
||||
}
|
||||
|
||||
if (GameMain.Server != null)
|
||||
{
|
||||
item.CreateServerEvent(this);
|
||||
}
|
||||
else if (GameMain.Client != null)
|
||||
if (GameMain.Client != null)
|
||||
{
|
||||
item.CreateClientEvent(this);
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace Barotrauma.Items.Components
|
||||
CreateHUD();
|
||||
}
|
||||
|
||||
float distort = 1.0f - item.Condition / 100.0f;
|
||||
float distort = 1.0f - item.Condition / item.Prefab.Health;
|
||||
foreach (HullData hullData in hullDatas.Values)
|
||||
{
|
||||
hullData.DistortionTimer -= deltaTime;
|
||||
|
||||
@@ -59,12 +59,7 @@ namespace Barotrauma.Items.Components
|
||||
IsActive = active;
|
||||
if (!IsActive) currPowerConsumption = 0.0f;
|
||||
|
||||
if (GameMain.Server != null)
|
||||
{
|
||||
item.CreateServerEvent(this);
|
||||
GameServer.Log(Character.Controlled.LogName + (IsActive ? " turned on " : " turned off ") + item.Name, ServerLog.MessageType.ItemInteraction);
|
||||
}
|
||||
else if (GameMain.Client != null)
|
||||
if (GameMain.Client != null)
|
||||
{
|
||||
correctionTimer = CorrectionDelay;
|
||||
item.CreateClientEvent(this);
|
||||
@@ -102,12 +97,8 @@ namespace Barotrauma.Items.Components
|
||||
if (Math.Abs(newValue - FlowPercentage) < 0.1f) return false;
|
||||
|
||||
FlowPercentage = newValue;
|
||||
if (GameMain.Server != null)
|
||||
{
|
||||
item.CreateServerEvent(this);
|
||||
GameServer.Log(Character.Controlled.LogName + " set the pumping speed of " + item.Name + " to " + (int)(flowPercentage) + " %", ServerLog.MessageType.ItemInteraction);
|
||||
}
|
||||
else if (GameMain.Client != null)
|
||||
|
||||
if (GameMain.Client != null)
|
||||
{
|
||||
correctionTimer = CorrectionDelay;
|
||||
item.CreateClientEvent(this);
|
||||
|
||||
@@ -162,10 +162,6 @@ namespace Barotrauma.Items.Components
|
||||
OnMoved = (GUIScrollBar bar, float scrollAmount) =>
|
||||
{
|
||||
LastUser = Character.Controlled;
|
||||
if (nextServerLogWriteTime == null)
|
||||
{
|
||||
nextServerLogWriteTime = Math.Max(lastServerLogWriteTime + 1.0f, (float)Timing.TotalTime);
|
||||
}
|
||||
unsentChanges = true;
|
||||
targetFissionRate = scrollAmount * 100.0f;
|
||||
|
||||
@@ -181,10 +177,6 @@ namespace Barotrauma.Items.Components
|
||||
OnMoved = (GUIScrollBar bar, float scrollAmount) =>
|
||||
{
|
||||
LastUser = Character.Controlled;
|
||||
if (nextServerLogWriteTime == null)
|
||||
{
|
||||
nextServerLogWriteTime = Math.Max(lastServerLogWriteTime + 1.0f, (float)Timing.TotalTime);
|
||||
}
|
||||
unsentChanges = true;
|
||||
targetTurbineOutput = scrollAmount * 100.0f;
|
||||
|
||||
@@ -209,10 +201,6 @@ namespace Barotrauma.Items.Components
|
||||
OnMoved = (scrollBar, scrollAmount) =>
|
||||
{
|
||||
LastUser = Character.Controlled;
|
||||
if (nextServerLogWriteTime == null)
|
||||
{
|
||||
nextServerLogWriteTime = Math.Max(lastServerLogWriteTime + 1.0f, (float)Timing.TotalTime);
|
||||
}
|
||||
unsentChanges = true;
|
||||
return true;
|
||||
}
|
||||
@@ -227,10 +215,6 @@ namespace Barotrauma.Items.Components
|
||||
OnMoved = (scrollBar, scrollAmount) =>
|
||||
{
|
||||
LastUser = Character.Controlled;
|
||||
if (nextServerLogWriteTime == null)
|
||||
{
|
||||
nextServerLogWriteTime = Math.Max(lastServerLogWriteTime + 1.0f, (float)Timing.TotalTime);
|
||||
}
|
||||
unsentChanges = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,12 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
partial class Sonar : Powered, IServerSerializable, IClientSerializable
|
||||
{
|
||||
enum Mode
|
||||
{
|
||||
Active,
|
||||
Passive
|
||||
};
|
||||
|
||||
private bool unsentChanges;
|
||||
private float networkUpdateTimer;
|
||||
|
||||
@@ -86,17 +92,12 @@ namespace Barotrauma.Items.Components
|
||||
ToolTip = TextManager.Get("SonarTipActive"),
|
||||
OnSelected = (GUITickBox box) =>
|
||||
{
|
||||
if (GameMain.Server != null)
|
||||
{
|
||||
unsentChanges = true;
|
||||
}
|
||||
else if (GameMain.Client != null)
|
||||
IsActive = box.Selected;
|
||||
if (GameMain.Client != null)
|
||||
{
|
||||
unsentChanges = true;
|
||||
correctionTimer = CorrectionDelay;
|
||||
}
|
||||
IsActive = box.Selected;
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@@ -111,11 +112,7 @@ namespace Barotrauma.Items.Components
|
||||
OnMoved = (scrollbar, scroll) =>
|
||||
{
|
||||
zoom = MathHelper.Lerp(MinZoom, MaxZoom, scroll);
|
||||
if (GameMain.Server != null)
|
||||
{
|
||||
unsentChanges = true;
|
||||
}
|
||||
else if (GameMain.Client != null)
|
||||
if (GameMain.Client != null)
|
||||
{
|
||||
unsentChanges = true;
|
||||
correctionTimer = CorrectionDelay;
|
||||
@@ -136,11 +133,7 @@ namespace Barotrauma.Items.Components
|
||||
OnSelected = (tickBox) =>
|
||||
{
|
||||
useDirectionalPing = tickBox.Selected;
|
||||
if (GameMain.Server != null)
|
||||
{
|
||||
unsentChanges = true;
|
||||
}
|
||||
else if (GameMain.Client != null)
|
||||
if (GameMain.Client != null)
|
||||
{
|
||||
unsentChanges = true;
|
||||
correctionTimer = CorrectionDelay;
|
||||
@@ -154,11 +147,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
float pingAngle = MathHelper.Lerp(0.0f, MathHelper.TwoPi, scroll);
|
||||
pingDirection = new Vector2((float)Math.Cos(pingAngle), (float)Math.Sin(pingAngle));
|
||||
if (GameMain.Server != null)
|
||||
{
|
||||
unsentChanges = true;
|
||||
}
|
||||
else if (GameMain.Client != null)
|
||||
if (GameMain.Client != null)
|
||||
{
|
||||
unsentChanges = true;
|
||||
correctionTimer = CorrectionDelay;
|
||||
@@ -168,9 +157,12 @@ namespace Barotrauma.Items.Components
|
||||
};
|
||||
|
||||
signalWarningText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.15f), paddedControlContainer.RectTransform), "", Color.Orange, textAlignment: Alignment.Center);
|
||||
|
||||
GUITickBox.CreateRadioButtonGroup(new List<GUITickBox>() { activeTickBox, passiveTickBox });
|
||||
|
||||
GUIRadioButtonGroup sonarMode = new GUIRadioButtonGroup();
|
||||
sonarMode.AddRadioButton(Mode.Active, activeTickBox);
|
||||
sonarMode.AddRadioButton(Mode.Passive, passiveTickBox);
|
||||
sonarMode.Selected = Mode.Passive;
|
||||
|
||||
GuiFrame.CanBeFocused = false;
|
||||
}
|
||||
|
||||
@@ -183,27 +175,20 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public override void UpdateHUD(Character character, float deltaTime, Camera cam)
|
||||
{
|
||||
if (unsentChanges)
|
||||
if (GameMain.Client != null)
|
||||
{
|
||||
if (networkUpdateTimer <= 0.0f)
|
||||
if (unsentChanges)
|
||||
{
|
||||
#if CLIENT
|
||||
if (GameMain.Client != null)
|
||||
if (networkUpdateTimer <= 0.0f)
|
||||
{
|
||||
item.CreateClientEvent(this);
|
||||
correctionTimer = CorrectionDelay;
|
||||
networkUpdateTimer = 0.1f;
|
||||
unsentChanges = false;
|
||||
}
|
||||
#endif
|
||||
if (GameMain.Server != null)
|
||||
{
|
||||
item.CreateServerEvent(this);
|
||||
}
|
||||
|
||||
networkUpdateTimer = 0.1f;
|
||||
unsentChanges = false;
|
||||
}
|
||||
networkUpdateTimer -= deltaTime;
|
||||
}
|
||||
networkUpdateTimer -= deltaTime;
|
||||
|
||||
if (sonarView.Rect.Contains(PlayerInput.MousePosition))
|
||||
{
|
||||
@@ -215,7 +200,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
float distort = 1.0f - item.Condition / 100.0f;
|
||||
float distort = 1.0f - item.Condition / item.Prefab.Health;
|
||||
for (int i = sonarBlips.Count - 1; i >= 0; i--)
|
||||
{
|
||||
sonarBlips[i].FadeTimer -= deltaTime * MathHelper.Lerp(0.5f, 2.0f, distort);
|
||||
@@ -304,18 +289,22 @@ namespace Barotrauma.Items.Components
|
||||
return;
|
||||
}
|
||||
|
||||
float passivePingRadius = (float)Math.Sin(Timing.TotalTime * 10);
|
||||
float passivePingRadius = (float)(Timing.TotalTime % 1.0f);
|
||||
if (passivePingRadius > 0.0f)
|
||||
{
|
||||
disruptedDirections.Clear();
|
||||
foreach (AITarget t in AITarget.List)
|
||||
{
|
||||
if (t.SoundRange <= 0.0f || !t.Enabled) continue;
|
||||
if (t.SoundRange <= 0.0f || !t.Enabled) { continue; }
|
||||
|
||||
float distSqr = Vector2.DistanceSquared(t.WorldPosition, transducerCenter);
|
||||
if (distSqr > t.SoundRange * t.SoundRange * 2) { continue; }
|
||||
|
||||
if (Vector2.DistanceSquared(t.WorldPosition, transducerCenter) < t.SoundRange * t.SoundRange)
|
||||
float dist = (float)Math.Sqrt(distSqr);
|
||||
if (dist > prevPassivePingRadius * Range && dist <= passivePingRadius * Range)
|
||||
{
|
||||
Ping(t.WorldPosition, transducerCenter,
|
||||
t.SoundRange * passivePingRadius * 0.2f, t.SoundRange * prevPassivePingRadius * 0.2f, displayScale, t.SoundRange,
|
||||
Ping(t.WorldPosition, transducerCenter,
|
||||
Math.Min(t.SoundRange, range * 0.5f) * displayScale, 0, displayScale, Math.Min(t.SoundRange, range * 0.5f),
|
||||
passive: true, pingStrength: 0.5f);
|
||||
sonarBlips.Add(new SonarBlip(t.WorldPosition, 1.0f, 1.0f));
|
||||
}
|
||||
@@ -653,25 +642,25 @@ namespace Barotrauma.Items.Components
|
||||
CreateBlipsForLine(
|
||||
new Vector2(item.CurrentHull.WorldRect.X, item.CurrentHull.WorldRect.Y),
|
||||
new Vector2(item.CurrentHull.WorldRect.Right, item.CurrentHull.WorldRect.Y),
|
||||
transducerPos,
|
||||
pingSource, transducerPos,
|
||||
pingRadius, prevPingRadius, 50.0f, 5.0f, range, 2.0f, passive);
|
||||
|
||||
CreateBlipsForLine(
|
||||
new Vector2(item.CurrentHull.WorldRect.X, item.CurrentHull.WorldRect.Y - item.CurrentHull.Rect.Height),
|
||||
new Vector2(item.CurrentHull.WorldRect.Right, item.CurrentHull.WorldRect.Y - item.CurrentHull.Rect.Height),
|
||||
transducerPos,
|
||||
pingSource, transducerPos,
|
||||
pingRadius, prevPingRadius, 50.0f, 5.0f, range, 2.0f, passive);
|
||||
|
||||
CreateBlipsForLine(
|
||||
new Vector2(item.CurrentHull.WorldRect.X, item.CurrentHull.WorldRect.Y),
|
||||
new Vector2(item.CurrentHull.WorldRect.X, item.CurrentHull.WorldRect.Y - item.CurrentHull.Rect.Height),
|
||||
transducerPos,
|
||||
pingSource, transducerPos,
|
||||
pingRadius, prevPingRadius, 50.0f, 5.0f, range, 2.0f, passive);
|
||||
|
||||
CreateBlipsForLine(
|
||||
new Vector2(item.CurrentHull.WorldRect.Right, item.CurrentHull.WorldRect.Y),
|
||||
new Vector2(item.CurrentHull.WorldRect.Right, item.CurrentHull.WorldRect.Y - item.CurrentHull.Rect.Height),
|
||||
transducerPos,
|
||||
pingSource, transducerPos,
|
||||
pingRadius, prevPingRadius, 50.0f, 5.0f, range, 2.0f, passive);
|
||||
|
||||
return;
|
||||
@@ -708,7 +697,7 @@ namespace Barotrauma.Items.Components
|
||||
CreateBlipsForLine(
|
||||
start + submarine.WorldPosition,
|
||||
end + submarine.WorldPosition,
|
||||
transducerPos,
|
||||
pingSource, transducerPos,
|
||||
pingRadius, prevPingRadius,
|
||||
200.0f, 2.0f, range, 1.0f, passive);
|
||||
}
|
||||
@@ -721,7 +710,7 @@ namespace Barotrauma.Items.Components
|
||||
CreateBlipsForLine(
|
||||
new Vector2(pingSource.X - range, Level.Loaded.Size.Y),
|
||||
new Vector2(pingSource.X + range, Level.Loaded.Size.Y),
|
||||
transducerPos,
|
||||
pingSource, transducerPos,
|
||||
pingRadius, prevPingRadius,
|
||||
250.0f, 150.0f, range, pingStrength, passive);
|
||||
}
|
||||
@@ -742,7 +731,7 @@ namespace Barotrauma.Items.Components
|
||||
CreateBlipsForLine(
|
||||
edge.Point1 + cell.Translation,
|
||||
edge.Point2 + cell.Translation,
|
||||
transducerPos,
|
||||
pingSource, transducerPos,
|
||||
pingRadius, prevPingRadius,
|
||||
350.0f, 3.0f * (Math.Abs(facingDot) + 1.0f), range, pingStrength, passive);
|
||||
}
|
||||
@@ -763,7 +752,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
CreateBlipsForLine(
|
||||
wall.A, wall.B,
|
||||
transducerPos,
|
||||
pingSource, transducerPos,
|
||||
pingRadius, prevPingRadius,
|
||||
100.0f, 1000.0f, range, pingStrength, passive);
|
||||
}
|
||||
@@ -813,7 +802,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateBlipsForLine(Vector2 point1, Vector2 point2, Vector2 transducerPos, float pingRadius, float prevPingRadius,
|
||||
private void CreateBlipsForLine(Vector2 point1, Vector2 point2, Vector2 pingSource, Vector2 transducerPos, float pingRadius, float prevPingRadius,
|
||||
float lineStep, float zStep, float range, float pingStrength, bool passive)
|
||||
{
|
||||
lineStep /= zoom;
|
||||
@@ -824,19 +813,25 @@ namespace Barotrauma.Items.Components
|
||||
for (float x = 0; x < length; x += lineStep * Rand.Range(0.8f, 1.2f))
|
||||
{
|
||||
Vector2 point = point1 + lineDir * x;
|
||||
//point += cell.Translation;
|
||||
|
||||
Vector2 pointDiff = point - transducerPos;
|
||||
float pointDist = pointDiff.Length();
|
||||
float displayPointDist = pointDist * displayScale;
|
||||
//ignore if outside the display
|
||||
Vector2 transducerDiff = point - transducerPos;
|
||||
Vector2 transducerDisplayDiff = transducerDiff * displayScale;
|
||||
if (transducerDisplayDiff.LengthSquared() > DisplayRadius * DisplayRadius) continue;
|
||||
|
||||
if (displayPointDist > DisplayRadius) continue;
|
||||
if (displayPointDist < prevPingRadius || displayPointDist > pingRadius) continue;
|
||||
//ignore if the point is not within the ping
|
||||
Vector2 pointDiff = point - pingSource;
|
||||
Vector2 displayPointDiff = pointDiff * displayScale;
|
||||
float displayPointDistSqr = displayPointDiff.LengthSquared();
|
||||
if (displayPointDistSqr < prevPingRadius * prevPingRadius || displayPointDistSqr > pingRadius * pingRadius) continue;
|
||||
|
||||
//ignore if direction is disrupted
|
||||
float transducerDist = transducerDiff.Length();
|
||||
Vector2 pingDirection = transducerDiff / transducerDist;
|
||||
bool disrupted = false;
|
||||
foreach (Pair<Vector2, float> disruptDir in disruptedDirections)
|
||||
{
|
||||
float dot = Vector2.Dot(pointDiff / pointDist, disruptDir.First);
|
||||
float dot = Vector2.Dot(pingDirection, disruptDir.First);
|
||||
if (dot > 1.0f - disruptDir.Second)
|
||||
{
|
||||
disrupted = true;
|
||||
@@ -845,10 +840,11 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
if (disrupted) continue;
|
||||
|
||||
float displayPointDist = (float)Math.Sqrt(displayPointDistSqr);
|
||||
float alpha = pingStrength * Rand.Range(1.5f, 2.0f);
|
||||
for (float z = 0; z < DisplayRadius - displayPointDist; z += zStep)
|
||||
for (float z = 0; z < DisplayRadius - transducerDist * displayScale; z += zStep)
|
||||
{
|
||||
Vector2 pos = point + Rand.Vector(150.0f / zoom) + Vector2.Normalize(point - item.WorldPosition) * z / displayScale;
|
||||
Vector2 pos = point + Rand.Vector(150.0f / zoom) + pingDirection * z / displayScale;
|
||||
float fadeTimer = alpha * (1.0f - displayPointDist / range);
|
||||
|
||||
int minDist = (int)(200 / zoom);
|
||||
@@ -902,7 +898,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
strength = MathHelper.Clamp(strength, 0.0f, 1.0f);
|
||||
|
||||
float distort = 1.0f - item.Condition / 100.0f;
|
||||
float distort = 1.0f - item.Condition / item.Prefab.Health;
|
||||
|
||||
Vector2 pos = (blip.Position - transducerPos) * displayScale * zoom;
|
||||
pos.Y = -pos.Y;
|
||||
|
||||
@@ -10,7 +10,19 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
partial class Steering : Powered, IServerSerializable, IClientSerializable
|
||||
{
|
||||
enum Mode
|
||||
{
|
||||
AutoPilot,
|
||||
Manual
|
||||
};
|
||||
private GUITickBox autopilotTickBox, manualTickBox;
|
||||
|
||||
enum Destination
|
||||
{
|
||||
MaintainPos,
|
||||
LevelEnd,
|
||||
LevelStart
|
||||
};
|
||||
private GUITickBox maintainPosTickBox, levelEndTickBox, levelStartTickBox;
|
||||
|
||||
private GUIFrame autoPilotControlsDisabler;
|
||||
@@ -104,8 +116,11 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
};
|
||||
|
||||
GUITickBox.CreateRadioButtonGroup(new List<GUITickBox> { manualTickBox, autopilotTickBox });
|
||||
|
||||
GUIRadioButtonGroup modes = new GUIRadioButtonGroup();
|
||||
modes.AddRadioButton(Mode.AutoPilot, autopilotTickBox);
|
||||
modes.AddRadioButton(Mode.Manual, manualTickBox);
|
||||
modes.Selected = Mode.Manual;
|
||||
|
||||
var autoPilotControls = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.6f), paddedControlContainer.RectTransform), "InnerFrame");
|
||||
var paddedAutoPilotControls = new GUILayoutGroup(new RectTransform(new Vector2(0.8f), autoPilotControls.RectTransform, Anchor.Center))
|
||||
{
|
||||
@@ -205,7 +220,12 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
autoPilotControlsDisabler = new GUIFrame(new RectTransform(Vector2.One, autoPilotControls.RectTransform), "InnerFrame");
|
||||
|
||||
GUITickBox.CreateRadioButtonGroup(new List<GUITickBox> { maintainPosTickBox, levelStartTickBox, levelEndTickBox });
|
||||
GUIRadioButtonGroup destinations = new GUIRadioButtonGroup();
|
||||
destinations.AddRadioButton(Destination.MaintainPos, maintainPosTickBox);
|
||||
destinations.AddRadioButton(Destination.LevelStart, levelStartTickBox);
|
||||
destinations.AddRadioButton(Destination.LevelEnd, levelEndTickBox);
|
||||
destinations.Selected = maintainPos ? Destination.MaintainPos :
|
||||
levelStartSelected ? Destination.LevelStart : Destination.LevelEnd;
|
||||
|
||||
string steeringVelX = TextManager.Get("SteeringVelocityX");
|
||||
string steeringVelY = TextManager.Get("SteeringVelocityY");
|
||||
|
||||
@@ -11,6 +11,12 @@ namespace Barotrauma.Items.Components
|
||||
private GUIProgressBar chargeIndicator;
|
||||
private GUIScrollBar rechargeSpeedSlider;
|
||||
|
||||
public Vector2 DrawSize
|
||||
{
|
||||
//use the extents of the item as the draw size
|
||||
get { return Vector2.Zero; }
|
||||
}
|
||||
|
||||
partial void InitProjSpecific()
|
||||
{
|
||||
if (GuiFrame == null) return;
|
||||
@@ -44,12 +50,7 @@ namespace Barotrauma.Items.Components
|
||||
if (Math.Abs(newRechargeSpeed - rechargeSpeed) < 0.1f) return false;
|
||||
|
||||
RechargeSpeed = newRechargeSpeed;
|
||||
if (GameMain.Server != null)
|
||||
{
|
||||
item.CreateServerEvent(this);
|
||||
GameServer.Log(Character.Controlled.LogName + " set the recharge speed of " + item.Name + " to " + (int)((rechargeSpeed / maxRechargeSpeed) * 100.0f) + " %", ServerLog.MessageType.ItemInteraction);
|
||||
}
|
||||
else if (GameMain.Client != null)
|
||||
if (GameMain.Client != null)
|
||||
{
|
||||
item.CreateClientEvent(this);
|
||||
correctionTimer = CorrectionDelay;
|
||||
|
||||
@@ -22,7 +22,8 @@ namespace Barotrauma.Items.Components
|
||||
powerOnSound = Submarine.LoadRoundSound(subElement, false);
|
||||
break;
|
||||
case "sparksound":
|
||||
sparkSounds.Add(Submarine.LoadRoundSound(subElement, false));
|
||||
var sparkSound = Submarine.LoadRoundSound(subElement, false);
|
||||
if (sparkSound != null) { sparkSounds.Add(sparkSound); }
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
|
||||
var progressBar = user.UpdateHUDProgressBar(
|
||||
targetStructure,
|
||||
targetStructure.ID * 1000 + sectionIndex, //unique "identifier" for each wall section
|
||||
progressBarPos,
|
||||
1.0f - targetStructure.SectionDamage(sectionIndex) / targetStructure.Health,
|
||||
Color.Red, Color.Green);
|
||||
@@ -108,7 +108,7 @@ namespace Barotrauma.Items.Components
|
||||
var progressBar = user.UpdateHUDProgressBar(
|
||||
targetItem,
|
||||
progressBarPos,
|
||||
targetItem.Condition / 100.0f,
|
||||
targetItem.Prefab.Health <= 0.0f ? 0.0f : targetItem.Condition / targetItem.Prefab.Health,
|
||||
Color.Red, Color.Green);
|
||||
if (progressBar != null) { progressBar.Size = new Vector2(60.0f, 20.0f); }
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public override bool ShouldDrawHUD(Character character)
|
||||
{
|
||||
if (!HasRequiredItems(character, false)) return false;
|
||||
if (!HasRequiredItems(character, false) || character.SelectedConstruction != item) return false;
|
||||
return (item.Condition < ShowRepairUIThreshold || (currentFixer == character && item.Condition < item.Prefab.Health));
|
||||
}
|
||||
|
||||
|
||||
@@ -108,10 +108,6 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
panel.Item.CreateClientEvent(panel);
|
||||
}
|
||||
else if (GameMain.Server != null)
|
||||
{
|
||||
panel.Item.CreateServerEvent(panel);
|
||||
}
|
||||
|
||||
draggingConnected = null;
|
||||
}
|
||||
@@ -173,6 +169,8 @@ namespace Barotrauma.Items.Components
|
||||
if (draggingConnected.Connect(this, !alreadyConnected, true))
|
||||
{
|
||||
var otherConnection = draggingConnected.OtherConnection(this);
|
||||
#if SERVER
|
||||
//TODO: ffs
|
||||
if (otherConnection == null)
|
||||
{
|
||||
GameServer.Log(Character.Controlled.LogName + " connected a wire to " +
|
||||
@@ -183,6 +181,7 @@ namespace Barotrauma.Items.Components
|
||||
GameServer.Log(Character.Controlled.LogName + " connected a wire from " +
|
||||
Item.Name + " (" + Name + ") to " + otherConnection.item.Name + " (" + otherConnection.Name + ")", ServerLog.MessageType.ItemInteraction);
|
||||
}
|
||||
#endif
|
||||
|
||||
SetWire(index, draggingConnected);
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
else
|
||||
{
|
||||
GameMain.Client.CreateEntityEvent(item, new object[] { NetEntityEvent.Type.ComponentState, item.components.IndexOf(this), userdata as CustomInterfaceElement });
|
||||
GameMain.Client.CreateEntityEvent(item, new object[] { NetEntityEvent.Type.ComponentState, item.GetComponentIndex(this), userdata as CustomInterfaceElement });
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
@@ -5,6 +5,11 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
partial class MotionSensor : IDrawableComponent
|
||||
{
|
||||
public Vector2 DrawSize
|
||||
{
|
||||
get { return new Vector2(rangeX, rangeY) * 2.0f; }
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing)
|
||||
{
|
||||
if (!editing || !MapEntity.SelectedList.Contains(item)) return;
|
||||
|
||||
@@ -5,6 +5,11 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
partial class WifiComponent : IDrawableComponent
|
||||
{
|
||||
public Vector2 DrawSize
|
||||
{
|
||||
get { return new Vector2(range * 2); }
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing)
|
||||
{
|
||||
if (!editing || !MapEntity.SelectedList.Contains(item)) return;
|
||||
|
||||
@@ -41,7 +41,12 @@ namespace Barotrauma.Items.Components
|
||||
private static Wire draggingWire;
|
||||
private static int? selectedNodeIndex;
|
||||
private static int? highlightedNodeIndex;
|
||||
|
||||
|
||||
public Vector2 DrawSize
|
||||
{
|
||||
get { return sectionExtents; }
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing)
|
||||
{
|
||||
if (sections.Count == 0 && !IsActive || Hidden)
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace Barotrauma.Items.Components
|
||||
visibleCharacters.Clear();
|
||||
foreach (Character c in Character.CharacterList)
|
||||
{
|
||||
if (c == equipper) continue;
|
||||
if (c == equipper || !c.Enabled || c.Removed) { continue; }
|
||||
|
||||
float dist = Vector2.DistanceSquared(equipper.WorldPosition, c.WorldPosition);
|
||||
if (dist < Range * Range)
|
||||
@@ -111,10 +111,9 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
Character closestCharacter = null;
|
||||
float closestDist = float.PositiveInfinity;
|
||||
|
||||
foreach (Character c in visibleCharacters)
|
||||
{
|
||||
if (c == character) continue;
|
||||
if (c == character || !c.Enabled || c.Removed) { continue; }
|
||||
|
||||
float dist = Vector2.DistanceSquared(GameMain.GameScreen.Cam.ScreenToWorld(PlayerInput.MousePosition), c.WorldPosition);
|
||||
if (dist < closestDist)
|
||||
@@ -175,14 +174,14 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
int bleedingTextIndex = MathHelper.Clamp((int)Math.Floor(target.Bleeding / 100.0f) * BleedingTexts.Length, 0, BleedingTexts.Length - 1);
|
||||
texts.Add(BleedingTexts[bleedingTextIndex]);
|
||||
textColors.Add(Color.Lerp(Color.Red, Color.Green, target.Bleeding / 100.0f));
|
||||
textColors.Add(Color.Lerp(Color.Orange, Color.Red, target.Bleeding / 100.0f));
|
||||
}
|
||||
|
||||
var allAfflictions = target.CharacterHealth.GetAllAfflictions();
|
||||
Dictionary<AfflictionPrefab, float> combinedAfflictionStrengths = new Dictionary<AfflictionPrefab, float>();
|
||||
foreach (Affliction affliction in allAfflictions)
|
||||
{
|
||||
if (affliction.Strength < affliction.Prefab.ActivationThreshold || affliction.Strength < affliction.Prefab.ShowIconThreshold) continue;
|
||||
if (affliction.Strength < affliction.Prefab.ActivationThreshold || affliction.Strength <= 0.0f) continue;
|
||||
if (combinedAfflictionStrengths.ContainsKey(affliction.Prefab))
|
||||
{
|
||||
combinedAfflictionStrengths[affliction.Prefab] += affliction.Strength;
|
||||
@@ -196,7 +195,7 @@ namespace Barotrauma.Items.Components
|
||||
foreach (AfflictionPrefab affliction in combinedAfflictionStrengths.Keys)
|
||||
{
|
||||
texts.Add(affliction.Name + ": " + ((int)combinedAfflictionStrengths[affliction]).ToString() + " %");
|
||||
textColors.Add(Color.Lerp(Color.Red, Color.Green, combinedAfflictionStrengths[affliction] / affliction.MaxStrength));
|
||||
textColors.Add(Color.Lerp(Color.Orange, Color.Red, combinedAfflictionStrengths[affliction] / affliction.MaxStrength));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,6 +203,9 @@ namespace Barotrauma.Items.Components
|
||||
hudPos.X += 5.0f;
|
||||
hudPos.Y += 24.0f;
|
||||
|
||||
hudPos.X = (int)hudPos.X;
|
||||
hudPos.Y = (int)hudPos.Y;
|
||||
|
||||
for (int i = 1; i < texts.Count; i++)
|
||||
{
|
||||
GUI.DrawString(spriteBatch, hudPos, texts[i], textColors[i] * alpha, Color.Black * 0.7f * alpha, 2, GUI.SmallFont);
|
||||
|
||||
@@ -61,6 +61,26 @@ namespace Barotrauma.Items.Components
|
||||
private set;
|
||||
}
|
||||
|
||||
public Vector2 DrawSize
|
||||
{
|
||||
get
|
||||
{
|
||||
float size = Math.Max(transformedBarrelPos.X, transformedBarrelPos.Y);
|
||||
if (barrelSprite != null)
|
||||
{
|
||||
if (railSprite != null)
|
||||
{
|
||||
size += Math.Max(Math.Max(barrelSprite.size.X, barrelSprite.size.Y), Math.Max(railSprite.size.X, railSprite.size.Y)) * item.Scale;
|
||||
}
|
||||
else
|
||||
{
|
||||
size += Math.Max(barrelSprite.size.X, barrelSprite.size.Y) * item.Scale;
|
||||
}
|
||||
}
|
||||
return Vector2.One * size * 2;
|
||||
}
|
||||
}
|
||||
|
||||
partial void InitProjSpecific(XElement element)
|
||||
{
|
||||
foreach (XElement subElement in element.Elements())
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using Barotrauma.Networking;
|
||||
using FarseerPhysics;
|
||||
using FarseerPhysics.Collision;
|
||||
using FarseerPhysics.Dynamics;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
@@ -9,6 +8,12 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
partial class DockingPort : ItemComponent, IDrawableComponent, IServerSerializable
|
||||
{
|
||||
public Vector2 DrawSize
|
||||
{
|
||||
//use the extents of the item as the draw size
|
||||
get { return Vector2.Zero; }
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing)
|
||||
{
|
||||
if (dockingState == 0.0f) return;
|
||||
|
||||
@@ -128,12 +128,14 @@ namespace Barotrauma
|
||||
protected float prevUIScale = UIScale;
|
||||
protected float prevHUDScale = GUI.Scale;
|
||||
|
||||
|
||||
protected static Sprite slotSpriteSmall, slotSpriteHorizontal, slotSpriteVertical, slotSpriteRound;
|
||||
public static Sprite EquipIndicator, EquipIndicatorHighlight;
|
||||
public static Sprite DropIndicator, DropIndicatorHighlight;
|
||||
|
||||
public Rectangle BackgroundFrame { get; protected set; }
|
||||
|
||||
private ushort[] receivedItemIDs;
|
||||
private CoroutineHandle syncItemsCoroutine;
|
||||
|
||||
public float HideTimer;
|
||||
|
||||
@@ -504,7 +506,7 @@ namespace Barotrauma
|
||||
|
||||
if (Character.Controlled.SelectedConstruction != null)
|
||||
{
|
||||
foreach (ItemComponent ic in Character.Controlled.SelectedConstruction.components)
|
||||
foreach (ItemComponent ic in Character.Controlled.SelectedConstruction.Components)
|
||||
{
|
||||
var itemContainer = ic as ItemContainer;
|
||||
if (itemContainer?.Inventory?.slots == null) continue;
|
||||
@@ -596,7 +598,6 @@ namespace Barotrauma
|
||||
|
||||
if (selectedSlot == null)
|
||||
{
|
||||
draggingItem.ParentInventory?.CreateNetworkEvent();
|
||||
draggingItem.Drop();
|
||||
GUI.PlayUISound(GUISoundType.DropItem);
|
||||
}
|
||||
@@ -675,7 +676,7 @@ namespace Barotrauma
|
||||
foreach (var slot in highlightedSubInventorySlots)
|
||||
{
|
||||
int slotIndex = Array.IndexOf(slot.ParentInventory.slots, slot.Slot);
|
||||
if (slotIndex > 0 && slotIndex < slot.ParentInventory.slots.Length)
|
||||
if (slotIndex > -1 && slotIndex < slot.ParentInventory.slots.Length)
|
||||
{
|
||||
slot.ParentInventory.DrawSubInventory(spriteBatch, slotIndex);
|
||||
}
|
||||
@@ -788,7 +789,7 @@ namespace Barotrauma
|
||||
GUI.DrawRectangle(spriteBatch, new Rectangle(rect.X, rect.Bottom - 8, rect.Width, 8), Color.Black * 0.8f, true);
|
||||
GUI.DrawRectangle(spriteBatch,
|
||||
new Rectangle(rect.X, rect.Bottom - 8, (int)(rect.Width * item.Condition / item.Prefab.Health), 8),
|
||||
Color.Lerp(Color.Red, Color.Green, item.Condition / 100.0f) * 0.8f, true);
|
||||
Color.Lerp(Color.Red, Color.Green, item.Condition / item.Prefab.Health) * 0.8f, true);
|
||||
}
|
||||
|
||||
if (itemContainer != null)
|
||||
@@ -796,12 +797,12 @@ namespace Barotrauma
|
||||
float containedState = 0.0f;
|
||||
if (itemContainer.ShowConditionInContainedStateIndicator)
|
||||
{
|
||||
containedState = item.Condition / 100.0f;
|
||||
containedState = item.Condition / item.Prefab.Health;
|
||||
}
|
||||
else
|
||||
{
|
||||
containedState = itemContainer.Inventory.Capacity == 1 ?
|
||||
(itemContainer.Inventory.Items[0] == null ? 0.0f : itemContainer.Inventory.Items[0].Condition / 100.0f) :
|
||||
(itemContainer.Inventory.Items[0] == null ? 0.0f : itemContainer.Inventory.Items[0].Condition / item.Prefab.Health) :
|
||||
itemContainer.Inventory.Items.Count(i => i != null) / (float)itemContainer.Inventory.capacity;
|
||||
}
|
||||
|
||||
@@ -962,8 +963,7 @@ namespace Barotrauma
|
||||
{
|
||||
if (receivedItemIDs[i] > 0)
|
||||
{
|
||||
var item = Entity.FindEntityByID(receivedItemIDs[i]) as Item;
|
||||
if (item == null || Items[i] == item) continue;
|
||||
if (!(Entity.FindEntityByID(receivedItemIDs[i]) is Item item) || Items[i] == item) continue;
|
||||
|
||||
TryPutItem(item, i, true, true, null, false);
|
||||
for (int j = 0; j < capacity; j++)
|
||||
@@ -978,5 +978,11 @@ namespace Barotrauma
|
||||
|
||||
receivedItemIDs = null;
|
||||
}
|
||||
|
||||
public void ClientWrite(NetBuffer msg, object[] extraData = null)
|
||||
{
|
||||
SharedWrite(msg, extraData);
|
||||
syncItemsDelay = 1.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@ namespace Barotrauma
|
||||
partial class Item : MapEntity, IDamageable, ISerializableEntity, IServerSerializable, IClientSerializable
|
||||
{
|
||||
public static bool ShowItems = true;
|
||||
|
||||
private readonly List<PosInfo> positionBuffer = new List<PosInfo>();
|
||||
|
||||
private List<ItemComponent> activeHUDs = new List<ItemComponent>();
|
||||
|
||||
@@ -34,6 +36,8 @@ namespace Barotrauma
|
||||
{
|
||||
get { return activeSprite; }
|
||||
}
|
||||
|
||||
public float SpriteRotation;
|
||||
|
||||
private GUITextBlock itemInUseWarning;
|
||||
private GUITextBlock ItemInUseWarning
|
||||
@@ -127,12 +131,36 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
public override bool IsVisible(Rectangle worldView)
|
||||
{
|
||||
//no drawable components and the body has been disabled = nothing to draw
|
||||
if (drawableComponents.Count == 0 && 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)
|
||||
{
|
||||
size.X = Math.Max(drawable.DrawSize.X, size.X);
|
||||
size.Y = Math.Max(drawable.DrawSize.Y, size.Y);
|
||||
}
|
||||
size *= 0.5f;
|
||||
|
||||
Vector2 worldPosition = WorldPosition;
|
||||
if (worldPosition.X - size.X > worldView.Right || worldPosition.X + size.X < worldView.X) return false;
|
||||
if (worldPosition.Y + size.Y < worldView.Y - worldView.Height || worldPosition.Y - size.Y > worldView.Y) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch, bool editing, bool back = true)
|
||||
{
|
||||
if (!Visible || (!editing && hiddenInGame)) return; // TODO: Prevent drawing hiddenInGame objects via cheating with server-side checks
|
||||
if (!Visible || (!editing && hiddenInGame)) return;
|
||||
if (editing && !ShowItems) return;
|
||||
|
||||
Color color = isHighlighted ? Color.Orange : GetSpriteColor();
|
||||
Color color = isHighlighted && !GUI.DisableItemHighlights ? Color.Orange : GetSpriteColor();
|
||||
//if (IsSelected && editing) color = Color.Lerp(color, Color.Gold, 0.5f);
|
||||
|
||||
Sprite activeSprite = prefab.sprite;
|
||||
@@ -816,41 +844,53 @@ namespace Barotrauma
|
||||
}
|
||||
msg.WritePadBits();
|
||||
}
|
||||
|
||||
|
||||
partial void UpdateNetPosition()
|
||||
{
|
||||
if (GameMain.Client == null) { return; }
|
||||
|
||||
Vector2 newVelocity = body.LinearVelocity;
|
||||
Vector2 newPosition = body.SimPosition;
|
||||
float newAngularVelocity = body.AngularVelocity;
|
||||
float newRotation = body.Rotation;
|
||||
body.CorrectPosition(positionBuffer, out newPosition, out newVelocity, out newRotation, out newAngularVelocity);
|
||||
|
||||
body.LinearVelocity = newVelocity;
|
||||
body.AngularVelocity = newAngularVelocity;
|
||||
if (Vector2.DistanceSquared(newPosition, body.SimPosition) > 0.0001f ||
|
||||
Math.Abs(newRotation - body.Rotation) > 0.01f)
|
||||
{
|
||||
body.TargetPosition = newPosition;
|
||||
body.TargetRotation = newRotation;
|
||||
body.MoveToTargetPosition(lerp: true);
|
||||
}
|
||||
|
||||
Vector2 displayPos = ConvertUnits.ToDisplayUnits(body.SimPosition);
|
||||
rect.X = (int)(displayPos.X - rect.Width / 2.0f);
|
||||
rect.Y = (int)(displayPos.Y + rect.Height / 2.0f);
|
||||
}
|
||||
|
||||
public void ClientReadPosition(ServerNetObject type, NetBuffer msg, float sendingTime)
|
||||
{
|
||||
Vector2 newPosition = new Vector2(msg.ReadFloat(), msg.ReadFloat());
|
||||
float newRotation = msg.ReadRangedSingle(0.0f, MathHelper.TwoPi, 7);
|
||||
bool awake = msg.ReadBoolean();
|
||||
Vector2 newVelocity = Vector2.Zero;
|
||||
|
||||
if (awake)
|
||||
{
|
||||
newVelocity = new Vector2(
|
||||
msg.ReadRangedSingle(-MaxVel, MaxVel, 12),
|
||||
msg.ReadRangedSingle(-MaxVel, MaxVel, 12));
|
||||
}
|
||||
|
||||
if (!MathUtils.IsValid(newPosition) || !MathUtils.IsValid(newRotation) || !MathUtils.IsValid(newVelocity))
|
||||
{
|
||||
string errorMsg = "Received invalid position data for the item \"" + Name
|
||||
+ "\" (position: " + newPosition + ", rotation: " + newRotation + ", velocity: " + newVelocity + ")";
|
||||
#if DEBUG
|
||||
DebugConsole.ThrowError(errorMsg);
|
||||
#endif
|
||||
GameAnalyticsManager.AddErrorEventOnce("Item.ClientReadPosition:InvalidData" + ID,
|
||||
GameAnalyticsSDK.Net.EGAErrorSeverity.Error,
|
||||
errorMsg);
|
||||
return;
|
||||
}
|
||||
|
||||
if (body == null)
|
||||
{
|
||||
DebugConsole.ThrowError("Received a position update for an item with no physics body (" + Name + ")");
|
||||
return;
|
||||
}
|
||||
|
||||
body.FarseerBody.Awake = awake;
|
||||
var posInfo = body.ClientRead(type, msg, sendingTime, parentDebugName: Name);
|
||||
msg.ReadPadBits();
|
||||
if (posInfo != null)
|
||||
{
|
||||
int index = 0;
|
||||
while (index < positionBuffer.Count && sendingTime > positionBuffer[index].Timestamp)
|
||||
{
|
||||
index++;
|
||||
}
|
||||
|
||||
positionBuffer.Insert(index, posInfo);
|
||||
}
|
||||
/*body.FarseerBody.Awake = awake;
|
||||
if (body.FarseerBody.Awake)
|
||||
{
|
||||
if ((newVelocity - body.LinearVelocity).LengthSquared() > 8.0f * 8.0f) body.LinearVelocity = newVelocity;
|
||||
@@ -879,7 +919,7 @@ namespace Barotrauma
|
||||
rect.X = (int)(displayPos.X - rect.Width / 2.0f);
|
||||
rect.Y = (int)(displayPos.Y + rect.Height / 2.0f);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
public void CreateClientEvent<T>(T ic) where T : ItemComponent, IClientSerializable
|
||||
@@ -891,6 +931,106 @@ namespace Barotrauma
|
||||
|
||||
GameMain.Client.CreateEntityEvent(this, new object[] { NetEntityEvent.Type.ComponentState, index });
|
||||
}
|
||||
|
||||
public static Item ReadSpawnData(NetBuffer msg, bool spawn = true)
|
||||
{
|
||||
string itemName = msg.ReadString();
|
||||
string itemIdentifier = msg.ReadString();
|
||||
bool descriptionChanged = msg.ReadBoolean();
|
||||
string itemDesc = "";
|
||||
if (descriptionChanged)
|
||||
{
|
||||
itemDesc = msg.ReadString();
|
||||
}
|
||||
ushort itemId = msg.ReadUInt16();
|
||||
ushort inventoryId = msg.ReadUInt16();
|
||||
|
||||
DebugConsole.Log("Received entity spawn message for item " + itemName + ".");
|
||||
|
||||
Vector2 pos = Vector2.Zero;
|
||||
Submarine sub = null;
|
||||
int itemContainerIndex = -1;
|
||||
int inventorySlotIndex = -1;
|
||||
|
||||
if (inventoryId > 0)
|
||||
{
|
||||
itemContainerIndex = msg.ReadByte();
|
||||
inventorySlotIndex = msg.ReadByte();
|
||||
}
|
||||
else
|
||||
{
|
||||
pos = new Vector2(msg.ReadSingle(), msg.ReadSingle());
|
||||
|
||||
ushort subID = msg.ReadUInt16();
|
||||
if (subID > 0)
|
||||
{
|
||||
sub = Submarine.Loaded.Find(s => s.ID == subID);
|
||||
}
|
||||
}
|
||||
|
||||
byte teamID = msg.ReadByte();
|
||||
bool tagsChanged = msg.ReadBoolean();
|
||||
string tags = "";
|
||||
if (tagsChanged)
|
||||
{
|
||||
tags = msg.ReadString();
|
||||
}
|
||||
|
||||
if (!spawn) return null;
|
||||
|
||||
//----------------------------------------
|
||||
|
||||
var itemPrefab = MapEntityPrefab.Find(itemName, itemIdentifier) as ItemPrefab;
|
||||
if (itemPrefab == null) return null;
|
||||
|
||||
Inventory inventory = null;
|
||||
|
||||
var inventoryOwner = FindEntityByID(inventoryId);
|
||||
if (inventoryOwner != null)
|
||||
{
|
||||
if (inventoryOwner is Character)
|
||||
{
|
||||
inventory = (inventoryOwner as Character).Inventory;
|
||||
}
|
||||
else if (inventoryOwner is Item)
|
||||
{
|
||||
if ((inventoryOwner as Item).components[itemContainerIndex] is ItemContainer container)
|
||||
{
|
||||
inventory = container.Inventory;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var item = new Item(itemPrefab, pos, sub)
|
||||
{
|
||||
ID = itemId
|
||||
};
|
||||
|
||||
foreach (WifiComponent wifiComponent in item.GetComponents<WifiComponent>())
|
||||
{
|
||||
wifiComponent.TeamID = (Character.TeamType)teamID;
|
||||
}
|
||||
if (descriptionChanged) item.Description = itemDesc;
|
||||
if (tagsChanged) item.Tags = tags;
|
||||
|
||||
if (sub != null)
|
||||
{
|
||||
item.CurrentHull = Hull.FindHull(pos + sub.Position, null, true);
|
||||
item.Submarine = item.CurrentHull?.Submarine;
|
||||
}
|
||||
|
||||
if (inventory != null)
|
||||
{
|
||||
if (inventorySlotIndex >= 0 && inventorySlotIndex < 255 &&
|
||||
inventory.TryPutItem(item, inventorySlotIndex, false, false, null, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
inventory.TryPutItem(item, null, item.AllowedSlots, false);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
partial void RemoveProjSpecific()
|
||||
{
|
||||
|
||||
@@ -6,6 +6,8 @@ namespace Barotrauma
|
||||
{
|
||||
partial class ItemInventory : Inventory
|
||||
{
|
||||
private string uiLabel;
|
||||
|
||||
protected override void ControlInput(Camera cam)
|
||||
{
|
||||
if (draggingItem == null && HUD.CloseHUD(BackgroundFrame))
|
||||
@@ -84,13 +86,24 @@ namespace Barotrauma
|
||||
|
||||
if (container.InventoryTopSprite == null)
|
||||
{
|
||||
Item item = Owner as Item;
|
||||
string label = container.UILabel ?? item?.Name;
|
||||
if (!string.IsNullOrEmpty(label) && !subInventory)
|
||||
if (uiLabel == null || uiLabel == string.Empty)
|
||||
{
|
||||
if (container.UILabel != null && container.UILabel.Length > 0)
|
||||
{
|
||||
uiLabel = TextManager.Get("UILabel." + container.UILabel);
|
||||
}
|
||||
else
|
||||
{
|
||||
Item item = Owner as Item;
|
||||
uiLabel = item?.Name;
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(uiLabel) && !subInventory)
|
||||
{
|
||||
GUI.DrawString(spriteBatch,
|
||||
new Vector2((int)(BackgroundFrame.Center.X - GUI.Font.MeasureString(label).X / 2), (int)BackgroundFrame.Y + 5),
|
||||
label, Color.White * 0.9f);
|
||||
new Vector2((int)(BackgroundFrame.Center.X - GUI.Font.MeasureString(uiLabel).X / 2), (int)BackgroundFrame.Y + 5),
|
||||
uiLabel, Color.White * 0.9f);
|
||||
}
|
||||
}
|
||||
else if (!subInventory)
|
||||
|
||||
@@ -7,6 +7,12 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
partial class Rope : ItemComponent, IDrawableComponent
|
||||
{
|
||||
public Vector2 DrawSize
|
||||
{
|
||||
//use the extents of the item as the draw size
|
||||
get { return Vector2.Zero; }
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing = false)
|
||||
{
|
||||
if (!IsActive) return;
|
||||
|
||||
Reference in New Issue
Block a user