(3a98135bd) Merge branch 'dev' of https://github.com/Regalis11/Barotrauma-development into dev

This commit is contained in:
Joonas Rikkonen
2019-03-29 17:21:37 +02:00
parent c0cf060526
commit d974a5d72f
11 changed files with 151 additions and 197 deletions
@@ -327,6 +327,8 @@ namespace Barotrauma
debugInteractablesAtCursor.Clear(); debugInteractablesAtCursor.Clear();
debugInteractablesNearCursor.Clear(); debugInteractablesNearCursor.Clear();
bool draggingItemToWorld = CharacterInventory.DraggingItemToWorld;
//reduce the amount of aim assist if an item has been selected //reduce the amount of aim assist if an item has been selected
//= can't switch selection to another item without deselecting the current one first UNLESS the cursor is directly on the item //= can't switch selection to another item without deselecting the current one first UNLESS the cursor is directly on the item
//otherwise it would be too easy to accidentally switch the selected item when rewiring items //otherwise it would be too easy to accidentally switch the selected item when rewiring items
@@ -349,6 +351,15 @@ namespace Barotrauma
if (item.ParentInventory != null) continue; if (item.ParentInventory != null) continue;
if (ignoredItems != null && ignoredItems.Contains(item)) continue; if (ignoredItems != null && ignoredItems.Contains(item)) continue;
if (draggingItemToWorld)
{
if (item.OwnInventory == null ||
!item.OwnInventory.CanBePut(CharacterInventory.draggingItem))
{
continue;
}
}
float distanceToItem = float.PositiveInfinity; float distanceToItem = float.PositiveInfinity;
if (item.IsInsideTrigger(displayPosition, out Rectangle transformedTrigger)) if (item.IsInsideTrigger(displayPosition, out Rectangle transformedTrigger))
{ {
@@ -248,7 +248,7 @@ namespace Barotrauma
scale: scale); scale: scale);
} }
if (!GUI.DisableItemHighlights) if (!GUI.DisableItemHighlights && !Inventory.DraggingItemToWorld)
{ {
var hudTexts = focusedItem.GetHUDTexts(character); var hudTexts = focusedItem.GetHUDTexts(character);
@@ -2,7 +2,6 @@ using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using System; using System;
using System.Xml.Linq; using System.Xml.Linq;
using System.Collections.Generic;
using Barotrauma.Media; using Barotrauma.Media;
using System.IO; using System.IO;
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input;
@@ -12,8 +11,8 @@ namespace Barotrauma
class VideoPlayer class VideoPlayer
{ {
private Video currentVideo; private Video currentVideo;
private Point resolution;
private string filePath; private string filePath;
private bool isPlaying;
private GUIFrame background, videoFrame, textFrame; private GUIFrame background, videoFrame, textFrame;
private GUITextBlock title, textContent, objectiveTitle, objectiveText; private GUITextBlock title, textContent, objectiveTitle, objectiveText;
@@ -22,14 +21,7 @@ namespace Barotrauma
private Color backgroundColor = new Color(0f, 0f, 0f, 1f); private Color backgroundColor = new Color(0f, 0f, 0f, 1f);
private Action callbackOnStop; private Action callbackOnStop;
private bool isPlaying; private Point scaledResolution;
public bool IsPlaying()
{
return isPlaying;
}
private Point defaultResolution = new Point(936, 540);
private readonly int borderSize = 20; private readonly int borderSize = 20;
private readonly Point buttonSize = new Point(160, 50); private readonly Point buttonSize = new Point(160, 50);
private readonly int titleHeight = 30; private readonly int titleHeight = 30;
@@ -51,41 +43,35 @@ namespace Barotrauma
public struct VideoSettings public struct VideoSettings
{ {
public string File; public string File;
public int Width;
public int Height;
public VideoSettings(XElement element) public VideoSettings(XElement element)
{ {
File = element.GetAttributeString("file", string.Empty); File = element.GetAttributeString("file", string.Empty);
Width = 0;
Height = 0;
} }
} }
public VideoPlayer() public VideoPlayer() // GUI elements with size set to Point.Zero are resized based on content
{ {
int screenWidth = (int)(GameMain.GraphicsWidth * 0.55f); int screenWidth = (int)(GameMain.GraphicsWidth * 0.55f);
defaultResolution = new Point(screenWidth, (int)(screenWidth / 16f * 9f)); scaledResolution = new Point(screenWidth, (int)(screenWidth / 16f * 9f));
int width = defaultResolution.X; int width = scaledResolution.X;
int height = defaultResolution.Y; int height = scaledResolution.Y;
background = new GUIFrame(new RectTransform(new Point(GameMain.GraphicsWidth, GameMain.GraphicsHeight), GUI.Canvas, Anchor.Center), "InnerFrame", backgroundColor); background = new GUIFrame(new RectTransform(new Point(GameMain.GraphicsWidth, GameMain.GraphicsHeight), GUI.Canvas, Anchor.Center), "InnerFrame", backgroundColor);
videoFrame = new GUIFrame(new RectTransform(new Point(width + borderSize, height + borderSize), background.RectTransform, Anchor.Center, Pivot.Center) { AbsoluteOffset = new Point((int)(-100 / (GUI.Scale * 0.6f)), 0) }, "SonarFrame"); videoFrame = new GUIFrame(new RectTransform(Point.Zero, background.RectTransform, Anchor.Center, Pivot.Center) { AbsoluteOffset = new Point((int)(-100 / (GUI.Scale * 0.6f)), 0) }, "SonarFrame");
//videoFrame.RectTransform.AbsoluteOffset = new Point(-borderSize, 0);
textFrame = new GUIFrame(new RectTransform(new Point(width + borderSize, height + borderSize * 2), videoFrame.RectTransform, Anchor.CenterLeft, Pivot.CenterLeft), "TextFrame"); textFrame = new GUIFrame(new RectTransform(Point.Zero, videoFrame.RectTransform, Anchor.CenterLeft, Pivot.CenterLeft), "TextFrame");
textFrame.RectTransform.AbsoluteOffset = new Point(borderSize + videoFrame.Rect.Width, 0); textFrame.RectTransform.AbsoluteOffset = new Point(width + borderSize * 2, 0);
videoView = new GUICustomComponent(new RectTransform(new Point(width, height), videoFrame.RectTransform, Anchor.Center), videoView = new GUICustomComponent(new RectTransform(Point.Zero, videoFrame.RectTransform, Anchor.Center), (spriteBatch, guiCustomComponent) => { DrawVideo(spriteBatch, guiCustomComponent.Rect); });
(spriteBatch, guiCustomComponent) => { DrawVideo(spriteBatch, guiCustomComponent.Rect); });
title = new GUITextBlock(new RectTransform(Point.Zero, textFrame.RectTransform, Anchor.TopLeft, Pivot.TopLeft) { AbsoluteOffset = new Point(5, 10) }, string.Empty, font: GUI.VideoTitleFont, textColor: new Color(253, 174, 0), textAlignment: Alignment.Left); title = new GUITextBlock(new RectTransform(Point.Zero, textFrame.RectTransform, Anchor.TopLeft, Pivot.TopLeft) { AbsoluteOffset = new Point(5, 10) }, string.Empty, font: GUI.VideoTitleFont, textColor: new Color(253, 174, 0), textAlignment: Alignment.Left);
textContent = new GUITextBlock(new RectTransform(new Vector2(1f, .8f), textFrame.RectTransform, Anchor.TopLeft, Pivot.TopLeft) { AbsoluteOffset = new Point(0, borderSize + titleHeight) }, string.Empty, font: GUI.Font, textAlignment: Alignment.TopLeft); textContent = new GUITextBlock(new RectTransform(Point.Zero, textFrame.RectTransform, Anchor.TopLeft, Pivot.TopLeft) { AbsoluteOffset = new Point(0, borderSize + titleHeight) }, string.Empty, font: GUI.Font, textAlignment: Alignment.TopLeft);
objectiveTitle = new GUITextBlock(new RectTransform(new Vector2(1f, 0f), textFrame.RectTransform, Anchor.TopCenter, Pivot.TopCenter), string.Empty, font: GUI.ObjectiveTitleFont, textAlignment: Alignment.CenterRight, textColor: Color.White); objectiveTitle = new GUITextBlock(new RectTransform(new Vector2(1f, 0f), textFrame.RectTransform, Anchor.TopCenter, Pivot.TopCenter), string.Empty, font: GUI.ObjectiveTitleFont, textAlignment: Alignment.CenterRight, textColor: Color.White);
objectiveTitle.Text = TextManager.Get("NewObjective"); objectiveTitle.Text = TextManager.Get("NewObjective");
objectiveText = new GUITextBlock(new RectTransform(new Point(textFrame.Rect.Width, textHeight), textFrame.RectTransform, Anchor.TopCenter, Pivot.TopCenter), string.Empty, font: GUI.ObjectiveNameFont, textColor: new Color(4, 180, 108), textAlignment: Alignment.CenterRight); objectiveText = new GUITextBlock(new RectTransform(Point.Zero, textFrame.RectTransform, Anchor.TopCenter, Pivot.TopCenter), string.Empty, font: GUI.ObjectiveNameFont, textColor: new Color(4, 180, 108), textAlignment: Alignment.CenterRight);
objectiveTitle.Visible = objectiveText.Visible = false; objectiveTitle.Visible = objectiveText.Visible = false;
} }
@@ -124,16 +110,16 @@ namespace Barotrauma
currentVideo.Dispose(); currentVideo.Dispose();
currentVideo = null; currentVideo = null;
currentVideo = CreateVideo(); currentVideo = CreateVideo(scaledResolution);
} }
public void AddToGUIUpdateList(bool ignoreChildren = false, int order = 0) public void AddToGUIUpdateList(bool ignoreChildren = false, int order = 0)
{ {
if (!IsPlaying()) return; if (!isPlaying) return;
background.AddToGUIUpdateList(ignoreChildren, order); background.AddToGUIUpdateList(ignoreChildren, order);
} }
public void LoadContentWithObjective(string contentPath, VideoSettings videoSettings, TextSettings textSettings, string contentId, bool startPlayback, string objective, Action callback = null) public void LoadContent(string contentPath, VideoSettings videoSettings, TextSettings textSettings, string contentId, bool startPlayback, string objective = "", Action callback = null)
{ {
callbackOnStop = callback; callbackOnStop = callback;
filePath = contentPath + videoSettings.File; filePath = contentPath + videoSettings.File;
@@ -153,19 +139,10 @@ namespace Barotrauma
currentVideo = null; currentVideo = null;
} }
resolution = new Point(videoSettings.Width, videoSettings.Height); currentVideo = CreateVideo(scaledResolution);
if (resolution.X == 0 || resolution.Y == 0) videoFrame.RectTransform.NonScaledSize += scaledResolution + new Point(borderSize, borderSize);
{ videoView.RectTransform.NonScaledSize += scaledResolution;
resolution = defaultResolution;
}
currentVideo = CreateVideo();
objectiveTitle.Visible = objectiveText.Visible = true;
videoFrame.RectTransform.NonScaledSize += resolution + new Point(borderSize, borderSize);
videoView.RectTransform.NonScaledSize += resolution;
title.Text = TextManager.Get(contentId); title.Text = TextManager.Get(contentId);
title.RectTransform.NonScaledSize += new Point(textSettings.Width, titleHeight); title.RectTransform.NonScaledSize += new Point(textSettings.Width, titleHeight);
@@ -175,79 +152,27 @@ namespace Barotrauma
textSettings.Text = ToolBox.WrapText(textSettings.Text, textSettings.Width, GUI.Font); textSettings.Text = ToolBox.WrapText(textSettings.Text, textSettings.Width, GUI.Font);
int wrappedHeight = textSettings.Text.Split('\n').Length * textHeight; int wrappedHeight = textSettings.Text.Split('\n').Length * textHeight;
textFrame.RectTransform.NonScaledSize += new Point(textSettings.Width + borderSize, wrappedHeight + borderSize + buttonSize.Y + titleHeight); textFrame.RectTransform.NonScaledSize += new Point(textSettings.Width + borderSize, wrappedHeight + borderSize + buttonSize.Y + titleHeight);
textContent.RectTransform.NonScaledSize = new Point(textSettings.Width, wrappedHeight); textContent.RectTransform.NonScaledSize += new Point(textSettings.Width, wrappedHeight);
} }
textContent.Text = textSettings.Text; textContent.Text = textSettings.Text;
objectiveTitle.RectTransform.AbsoluteOffset = new Point(-10, textContent.RectTransform.Rect.Height + (int)(textHeight * 1.75f)); if (!string.IsNullOrEmpty(objective))
objectiveText.RectTransform.AbsoluteOffset = new Point(-10, textContent.RectTransform.Rect.Height + objectiveTitle.Rect.Height + (int)(textHeight * 2.25f));
textFrame.RectTransform.NonScaledSize += new Point(0, objectiveFrameHeight);
objectiveText.RectTransform.NonScaledSize += new Point(textFrame.Rect.Width, textHeight);
objectiveText.Text = objective;
var okButton = new GUIButton(new RectTransform(buttonSize, textFrame.RectTransform, Anchor.BottomRight, Pivot.BottomRight) { AbsoluteOffset = new Point(20, 20) },
TextManager.Get("OK"))
{ {
OnClicked = DisposeVideo objectiveTitle.RectTransform.AbsoluteOffset = new Point(-10, textContent.RectTransform.Rect.Height + (int)(textHeight * 1.95f));
}; objectiveText.RectTransform.AbsoluteOffset = new Point(-10, textContent.RectTransform.Rect.Height + objectiveTitle.Rect.Height + (int)(textHeight * 2.25f));
if (startPlayback) Play(); textFrame.RectTransform.NonScaledSize += new Point(0, objectiveFrameHeight);
} objectiveText.RectTransform.NonScaledSize += new Point(textFrame.Rect.Width, textHeight);
objectiveText.Text = objective;
public void LoadContent(string contentPath, VideoSettings videoSettings, TextSettings textSettings, string contentId, bool startPlayback, Action callback = null) objectiveTitle.Visible = objectiveText.Visible = true;
{
callbackOnStop = callback;
filePath = contentPath + videoSettings.File;
if (!File.Exists(filePath))
{
DebugConsole.ThrowError("No video found at: " + filePath);
DisposeVideo(null, null);
return;
} }
else
ResetFrameSizes();
if (currentVideo != null)
{ {
currentVideo.Dispose(); textFrame.RectTransform.NonScaledSize += new Point(0, borderSize);
currentVideo = null; objectiveTitle.Visible = objectiveText.Visible = false;
} }
resolution = new Point(0, 0);
if (currentVideo == null) // No preloaded video found
{
resolution = new Point(videoSettings.Width, videoSettings.Height);
if (resolution.X == 0 || resolution.Y == 0)
{
resolution = defaultResolution;
}
currentVideo = CreateVideo();
}
objectiveTitle.Visible = objectiveText.Visible = false;
videoFrame.RectTransform.NonScaledSize += resolution + new Point(borderSize, borderSize);
videoView.RectTransform.NonScaledSize += resolution;
title.Text = TextManager.Get(contentId);
title.RectTransform.NonScaledSize += new Point(textSettings.Width, titleHeight);
if (textSettings.Text != string.Empty)
{
textSettings.Text = ToolBox.WrapText(textSettings.Text, textSettings.Width, GUI.Font);
int wrappedHeight = textSettings.Text.Split('\n').Length * textHeight;
textFrame.RectTransform.NonScaledSize += new Point(textSettings.Width + borderSize, wrappedHeight + borderSize + buttonSize.Y + titleHeight);
textContent.RectTransform.NonScaledSize = new Point(textSettings.Width, wrappedHeight);
}
textContent.Text = textSettings.Text;
var okButton = new GUIButton(new RectTransform(buttonSize, textFrame.RectTransform, Anchor.BottomRight, Pivot.BottomRight) { AbsoluteOffset = new Point(20, 20) }, var okButton = new GUIButton(new RectTransform(buttonSize, textFrame.RectTransform, Anchor.BottomRight, Pivot.BottomRight) { AbsoluteOffset = new Point(20, 20) },
TextManager.Get("OK")) TextManager.Get("OK"))
{ {
@@ -269,13 +194,12 @@ namespace Barotrauma
objectiveText.RectTransform.NonScaledSize = Point.Zero; objectiveText.RectTransform.NonScaledSize = Point.Zero;
} }
private Video CreateVideo() private Video CreateVideo(Point resolution)
{ {
Video video = null; Video video = null;
try try
{ {
//video = new Video(GameMain.Instance.GraphicsDevice, GameMain.SoundManager, "Content/splashscreen.mp4", 1280, 720);
video = new Video(GameMain.Instance.GraphicsDevice, GameMain.SoundManager, filePath, (uint)resolution.X, (uint)resolution.Y); video = new Video(GameMain.Instance.GraphicsDevice, GameMain.SoundManager, filePath, (uint)resolution.X, (uint)resolution.Y);
} }
catch (Exception e) catch (Exception e)
@@ -5,7 +5,6 @@ using Microsoft.Xna.Framework;
using Barotrauma.Items.Components; using Barotrauma.Items.Components;
using System.Linq; using System.Linq;
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input;
using System.Windows;
namespace Barotrauma.Tutorials namespace Barotrauma.Tutorials
{ {
@@ -42,12 +41,8 @@ namespace Barotrauma.Tutorials
private bool disableTutorialOnDeficiencyFound = true; private bool disableTutorialOnDeficiencyFound = true;
private GUIFrame holderFrame, objectiveFrame; private GUIFrame holderFrame, objectiveFrame;
//private GUIButton toggleButton;
//private bool objectivesOpen = false;
//private float openState = 0f;
private List<TutorialSegment> activeObjectives = new List<TutorialSegment>(); private List<TutorialSegment> activeObjectives = new List<TutorialSegment>();
private string objectiveTranslated; private string objectiveTranslated;
//private Point objectiveBaseOffset = Point.Zero;
private float floodTutorialTimer = 0.0f; private float floodTutorialTimer = 0.0f;
private const float floodTutorialDelay = 2.0f; private const float floodTutorialDelay = 2.0f;
@@ -113,7 +108,6 @@ namespace Barotrauma.Tutorials
base.Initialize(); base.Initialize();
videoPlayer = new VideoPlayer(); videoPlayer = new VideoPlayer();
characterTimeOnSonar = new List<Pair<Character, float>>(); characterTimeOnSonar = new List<Pair<Character, float>>();
//objectivesOpen = true;
} }
public void LoadPartiallyComplete(XElement element) public void LoadPartiallyComplete(XElement element)
@@ -137,15 +131,6 @@ namespace Barotrauma.Tutorials
} }
} }
private void PreloadVideoContent() // Have to see if needed with videos
{
/*for (int i = 0; i < segments.Count; i++)
{
if (segments[i].ContentType != ContentTypes.Video || segments[i].IsTriggered) continue;
spriteSheetPlayer.PreloadContent(playableContentPath, "tutorial", segments[i].Id, segments[i].VideoContent);
}*/
}
public void SavePartiallyComplete(XElement element) public void SavePartiallyComplete(XElement element)
{ {
XElement tutorialElement = new XElement("contextualtutorial"); XElement tutorialElement = new XElement("contextualtutorial");
@@ -177,10 +162,7 @@ namespace Barotrauma.Tutorials
{ {
if (!Initialized) return; if (!Initialized) return;
PreloadVideoContent();
base.Start(); base.Start();
injuredMember = null; injuredMember = null;
activeObjectives.Clear(); activeObjectives.Clear();
objectiveTranslated = TextManager.Get("Objective"); objectiveTranslated = TextManager.Get("Objective");
@@ -249,21 +231,6 @@ namespace Barotrauma.Tutorials
{ {
holderFrame = new GUIFrame(new RectTransform(new Point(GameMain.GraphicsWidth, GameMain.GraphicsHeight), GUI.Canvas, Anchor.Center)); holderFrame = new GUIFrame(new RectTransform(new Point(GameMain.GraphicsWidth, GameMain.GraphicsHeight), GUI.Canvas, Anchor.Center));
objectiveFrame = new GUIFrame(HUDLayoutSettings.ToRectTransform(HUDLayoutSettings.ObjectiveAnchor, holderFrame.RectTransform), style: null); objectiveFrame = new GUIFrame(HUDLayoutSettings.ToRectTransform(HUDLayoutSettings.ObjectiveAnchor, holderFrame.RectTransform), style: null);
/*int toggleButtonWidth = (int)(30 * GUI.Scale);
int toggleButtonHeight = (int)(40 * GUI.Scale);
toggleButton = new GUIButton(new RectTransform(new Point(toggleButtonWidth, toggleButtonHeight), objectiveFrame.RectTransform, Anchor.CenterRight) { AbsoluteOffset = new Point(0, 20) }, style: "UIToggleButton");
toggleButton.OnClicked += (GUIButton btn, object userdata) =>
{
objectivesOpen = !objectivesOpen;
foreach (GUIComponent child in btn.Children)
{
child.SpriteEffects = objectivesOpen ? SpriteEffects.FlipHorizontally : SpriteEffects.None;
}
return true;
};
objectiveBaseOffset = new Point((int)(-2.5f * toggleButton.Rect.Width), 0);*/
} }
public override void AddToGUIUpdateList() public override void AddToGUIUpdateList()
@@ -311,48 +278,11 @@ namespace Barotrauma.Tutorials
{ {
CheckActiveObjectives(activeObjectives[i], deltaTime); CheckActiveObjectives(activeObjectives[i], deltaTime);
} }
/*if (activeObjectives.Count > 0)
{
if (objectivesOpen)
{
openState -= deltaTime * 5.0f;
}
else
{
openState += deltaTime * 5.0f;
}
openState = MathHelper.Clamp(openState, 0.0f, 1.0f);
float widestObjective = 0f;
for (int i = 0; i < activeObjectives.Count; i++)
{
if (activeObjectives[i].ReplayButton.Rect.Width > widestObjective)
{
widestObjective = activeObjectives[i].ReplayButton.Rect.Width;
}
}
float objectivesHiddenOffset = widestObjective + toggleButton.Rect.Width + 100f;
for (int i = 0; i < activeObjectives.Count; i++)
{
activeObjectives[i].ReplayButton.RectTransform.AbsoluteOffset = objectiveBaseOffset + new Point((int)MathHelper.SmoothStep(0, objectivesHiddenOffset, openState), 0);
}
}*/
} }
private void ClosePreTextAndTriggerVideoCallback() private void ClosePreTextAndTriggerVideoCallback()
{ {
if (!string.IsNullOrEmpty(activeSegment.Objective)) videoPlayer.LoadContent(playableContentPath, new VideoPlayer.VideoSettings(activeSegment.VideoContent), new VideoPlayer.TextSettings(activeSegment.VideoContent), activeSegment.Id, true, activeSegment.Objective, CurrentSegmentStopCallback);
{
videoPlayer.LoadContentWithObjective(playableContentPath, new VideoPlayer.VideoSettings(activeSegment.VideoContent), new VideoPlayer.TextSettings(activeSegment.VideoContent), activeSegment.Id, true, activeSegment.Objective, CurrentSegmentStopCallback);
}
else
{
videoPlayer.LoadContent(playableContentPath, new VideoPlayer.VideoSettings(activeSegment.VideoContent), new VideoPlayer.TextSettings(activeSegment.VideoContent), activeSegment.Id, true, CurrentSegmentStopCallback);
}
} }
private void CurrentSegmentStopCallback() private void CurrentSegmentStopCallback()
@@ -804,7 +734,7 @@ namespace Barotrauma.Tutorials
{ {
if (ContentRunning) return; if (ContentRunning) return;
ContentRunning = true; ContentRunning = true;
videoPlayer.LoadContent(playableContentPath, new VideoPlayer.VideoSettings(segment.VideoContent), new VideoPlayer.TextSettings(segment.VideoContent), segment.Id, true, () => ContentRunning = false); videoPlayer.LoadContent(playableContentPath, new VideoPlayer.VideoSettings(segment.VideoContent), new VideoPlayer.TextSettings(segment.VideoContent), segment.Id, true, callback: () => ContentRunning = false);
} }
private IEnumerable<object> WaitToStop() private IEnumerable<object> WaitToStop()
@@ -7,7 +7,7 @@ namespace Barotrauma.Items.Components
{ {
public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime) public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime)
{ {
DeattachTimer = msg.ReadSingle(); deattachTimer = msg.ReadSingle();
if (deattachTimer >= DeattachDuration) if (deattachTimer >= DeattachDuration)
{ {
holdable.DeattachFromWall(); holdable.DeattachFromWall();
@@ -1,6 +1,7 @@
using Barotrauma.Particles; using Barotrauma.Particles;
using FarseerPhysics; using FarseerPhysics;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@@ -11,12 +12,21 @@ using System.Xml.Linq;
namespace Barotrauma.Items.Components namespace Barotrauma.Items.Components
{ {
partial class RepairTool partial class RepairTool
#if DEBUG
: IDrawableComponent
#endif
{ {
public ParticleEmitter ParticleEmitter public ParticleEmitter ParticleEmitter
{ {
get; get;
private set; private set;
} }
#if DEBUG
public Vector2 DrawSize
{
get { return GameMain.DebugDraw ? Vector2.One * Range : Vector2.Zero; }
}
#endif
private List<ParticleEmitter> ParticleEmitterHitStructure = new List<ParticleEmitter>(); private List<ParticleEmitter> ParticleEmitterHitStructure = new List<ParticleEmitter>();
private List<ParticleEmitter> ParticleEmitterHitCharacter = new List<ParticleEmitter>(); private List<ParticleEmitter> ParticleEmitterHitCharacter = new List<ParticleEmitter>();
@@ -122,5 +132,17 @@ namespace Barotrauma.Items.Components
emitter.Second.Emit(deltaTime, particlePos, item.CurrentHull, particleAngle + MathHelper.Pi, -particleAngle + MathHelper.Pi); emitter.Second.Emit(deltaTime, particlePos, item.CurrentHull, particleAngle + MathHelper.Pi, -particleAngle + MathHelper.Pi);
} }
} }
#if DEBUG
public void Draw(SpriteBatch spriteBatch, bool editing)
{
if (GameMain.DebugDraw && IsActive)
{
GUI.DrawLine(spriteBatch,
new Vector2(debugRayStartPos.X, -debugRayStartPos.Y),
new Vector2(debugRayEndPos.X, -debugRayEndPos.Y),
Color.Yellow);
}
}
#endif
} }
} }
@@ -301,7 +301,7 @@ namespace Barotrauma
protected virtual void ControlInput(Camera cam) protected virtual void ControlInput(Camera cam)
{ {
// Note that these targets are static. Therefore the outcome is the same if this method is called multiple times or only once. // Note that these targets are static. Therefore the outcome is the same if this method is called multiple times or only once.
if (selectedSlot != null || draggingItem != null) if (selectedSlot != null && !DraggingItemToWorld)
{ {
cam.Freeze = true; cam.Freeze = true;
} }
@@ -609,8 +609,17 @@ namespace Barotrauma
if (selectedSlot == null) if (selectedSlot == null)
{ {
draggingItem.Drop(Character.Controlled); if (DraggingItemToWorld &&
GUI.PlayUISound(GUISoundType.DropItem); Character.Controlled.FocusedItem?.OwnInventory != null &&
Character.Controlled.FocusedItem.OwnInventory.TryPutItem(draggingItem, Character.Controlled))
{
GUI.PlayUISound(GUISoundType.PickItem);
}
else
{
GUI.PlayUISound(GUISoundType.DropItem);
draggingItem.Drop(Character.Controlled);
}
} }
else if (selectedSlot.ParentInventory.Items[selectedSlot.SlotIndex] != draggingItem) else if (selectedSlot.ParentInventory.Items[selectedSlot.SlotIndex] != draggingItem)
{ {
@@ -702,6 +711,23 @@ namespace Barotrauma
int iconSize = (int)(64 * GUI.Scale); int iconSize = (int)(64 * GUI.Scale);
float scale = Math.Min(Math.Min(iconSize / sprite.size.X, iconSize / sprite.size.Y), 1.5f); float scale = Math.Min(Math.Min(iconSize / sprite.size.X, iconSize / sprite.size.Y), 1.5f);
Vector2 itemPos = PlayerInput.MousePosition; Vector2 itemPos = PlayerInput.MousePosition;
if (GUI.MouseOn == null && selectedSlot == null)
{
var shadowSprite = GUI.Style.GetComponentStyle("OuterGlow").Sprites[GUIComponent.ComponentState.None][0];
string toolTip = Character.Controlled.FocusedItem != null ?
TextManager.Get("PutItemIn").Replace("[itemname]", Character.Controlled.FocusedItem.Name) :
TextManager.Get("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);
shadowSprite.Draw(spriteBatch,
new Rectangle(itemPos.ToPoint() - new Point(iconSize / 2) - shadowBorders, new Point(iconSize + textWidth + textSpacing, iconSize) + shadowBorders.Multiply(2)), Color.Black * 0.8f);
GUI.DrawString(spriteBatch, new Vector2(itemPos.X + iconSize / 2 + textSpacing, itemPos.Y - iconSize / 2), draggingItem.Name, Color.White);
GUI.DrawString(spriteBatch, new Vector2(itemPos.X + iconSize / 2 + textSpacing, itemPos.Y), toolTip,
color: Character.Controlled.FocusedItem == null ? Color.Red : Color.LightGreen,
font: GUI.SmallFont);
}
sprite.Draw(spriteBatch, itemPos + Vector2.One * 2, Color.Black, scale: scale); sprite.Draw(spriteBatch, itemPos + Vector2.One * 2, Color.Black, scale: scale);
sprite.Draw(spriteBatch, sprite.Draw(spriteBatch,
itemPos, itemPos,
@@ -1656,7 +1656,8 @@ namespace Barotrauma
#if CLIENT #if CLIENT
if (isLocalPlayer) if (isLocalPlayer)
{ {
if (GUI.MouseOn == null && !CharacterInventory.IsMouseOnInventory()) if (GUI.MouseOn == null &&
(!CharacterInventory.IsMouseOnInventory() || CharacterInventory.DraggingItemToWorld))
{ {
if (findFocusedTimer <= 0.0f || Screen.Selected == GameMain.SubEditorScreen) if (findFocusedTimer <= 0.0f || Screen.Selected == GameMain.SubEditorScreen)
{ {
@@ -2,12 +2,15 @@
using Lidgren.Network; using Lidgren.Network;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using System; using System;
using System.Linq;
using System.Xml.Linq; using System.Xml.Linq;
namespace Barotrauma.Items.Components namespace Barotrauma.Items.Components
{ {
partial class LevelResource : ItemComponent, IServerSerializable partial class LevelResource : ItemComponent, IServerSerializable
{ {
private float lastSentDeattachTimer;
[Serialize(1.0f, false)] [Serialize(1.0f, false)]
public float DeattachDuration public float DeattachDuration
{ {
@@ -21,12 +24,29 @@ namespace Barotrauma.Items.Components
get { return deattachTimer; } get { return deattachTimer; }
set set
{ {
deattachTimer = Math.Max(0.0f, value);
//clients don't deattach the item until the server says so (handled in ClientRead) //clients don't deattach the item until the server says so (handled in ClientRead)
if ((GameMain.NetworkMember == null || !GameMain.NetworkMember.IsClient) && deattachTimer >= DeattachDuration) if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsClient)
{
return;
}
deattachTimer = Math.Max(0.0f, value);
#if SERVER
if (deattachTimer >= DeattachDuration)
{
if (holdable.Attached){ item.CreateServerEvent(this); }
holdable.DeattachFromWall();
}
else if (Math.Abs(lastSentDeattachTimer - deattachTimer) > 0.1f)
{
item.CreateServerEvent(this);
lastSentDeattachTimer = deattachTimer;
}
#else
if (deattachTimer >= DeattachDuration)
{ {
holdable.DeattachFromWall(); holdable.DeattachFromWall();
} }
#endif
} }
} }
@@ -67,7 +87,10 @@ namespace Barotrauma.Items.Components
return; return;
} }
holdable.Reattachable = false; holdable.Reattachable = false;
holdable.PickingTime = float.MaxValue; if (requiredItems.Any())
{
holdable.PickingTime = float.MaxValue;
}
var body = item.body ?? holdable.Body; var body = item.body ?? holdable.Body;
@@ -18,6 +18,8 @@ namespace Barotrauma.Items.Components
private Vector2 pickedPosition; private Vector2 pickedPosition;
private float activeTimer; private float activeTimer;
private Vector2 debugRayStartPos, debugRayEndPos;
[Serialize(0.0f, false)] [Serialize(0.0f, false)]
public float Range { get; set; } public float Range { get; set; }
@@ -247,6 +249,7 @@ namespace Barotrauma.Items.Components
var levelResource = targetItem.GetComponent<LevelResource>(); var levelResource = targetItem.GetComponent<LevelResource>();
if (levelResource != null && levelResource.IsActive && if (levelResource != null && levelResource.IsActive &&
levelResource.requiredItems.Any() &&
levelResource.HasRequiredItems(user, addMessage: false)) levelResource.HasRequiredItems(user, addMessage: false))
{ {
levelResource.DeattachTimer += deltaTime; levelResource.DeattachTimer += deltaTime;
@@ -678,17 +678,24 @@ namespace Barotrauma
Body closestBody = null; Body closestBody = null;
if (allowInsideFixture) if (allowInsideFixture)
{ {
var aabb = new FarseerPhysics.Collision.AABB(rayStart - Vector2.UnitY * 0.001f, rayStart + Vector2.UnitY * 0.001f); var aabb = new FarseerPhysics.Collision.AABB(rayStart - Vector2.One * 0.001f, rayStart + Vector2.One * 0.001f);
GameMain.World.QueryAABB((fixture) => GameMain.World.QueryAABB((fixture) =>
{ {
if (!CheckFixtureCollision(fixture, ignoredBodies, collisionCategory, ignoreSensors, customPredicate)) { return false; } if (!CheckFixtureCollision(fixture, ignoredBodies, collisionCategory, ignoreSensors, customPredicate)) { return true; }
fixture.Body.GetTransform(out FarseerPhysics.Common.Transform transform);
if (!fixture.Shape.TestPoint(ref transform, ref rayStart)) { return true; }
closestFraction = 0.0f; closestFraction = 0.0f;
closestNormal = Vector2.Normalize(rayEnd - rayStart); closestNormal = Vector2.Normalize(rayEnd - rayStart);
if (fixture.Body != null) closestBody = fixture.Body; if (fixture.Body != null) closestBody = fixture.Body;
return true; return false;
}, ref aabb); }, ref aabb);
if (closestFraction <= 0.0f) if (closestFraction <= 0.0f)
{ {
lastPickedPosition = rayStart;
lastPickedFraction = closestFraction;
lastPickedNormal = closestNormal;
return closestBody; return closestBody;
} }
} }
@@ -740,14 +747,21 @@ namespace Barotrauma
if (allowInsideFixture) if (allowInsideFixture)
{ {
var aabb = new FarseerPhysics.Collision.AABB(rayStart - Vector2.UnitY * 0.001f, rayStart + Vector2.UnitY * 0.001f); var aabb = new FarseerPhysics.Collision.AABB(rayStart - Vector2.One * 0.001f, rayStart + Vector2.One * 0.001f);
GameMain.World.QueryAABB((fixture) => GameMain.World.QueryAABB((fixture) =>
{ {
if (bodies.Contains(fixture.Body) || fixture.Body == null) { return false; } if (bodies.Contains(fixture.Body) || fixture.Body == null) { return true; }
if (!CheckFixtureCollision(fixture, ignoredBodies, collisionCategory, ignoreSensors, customPredicate)) { return false; } if (!CheckFixtureCollision(fixture, ignoredBodies, collisionCategory, ignoreSensors, customPredicate)) { return true; }
fixture.Body.GetTransform(out FarseerPhysics.Common.Transform transform);
if (!fixture.Shape.TestPoint(ref transform, ref rayStart)) { return true; }
closestFraction = 0.0f; closestFraction = 0.0f;
lastPickedPosition = rayStart;
lastPickedFraction = 0.0f;
lastPickedNormal = Vector2.Normalize(rayEnd - rayStart);
bodies.Add(fixture.Body); bodies.Add(fixture.Body);
return true; return false;
}, ref aabb); }, ref aabb);
} }