v0.11.0.9
This commit is contained in:
+8
-10
@@ -95,23 +95,21 @@ namespace Barotrauma.Items.Components
|
||||
// TODO, This works fine as of now but if GUI.PreventElementOverlap ever gets fixed this block of code may become obsolete or detrimental.
|
||||
// Only do this if there's only one linked component. If you link more containers then may
|
||||
// GUI.PreventElementOverlap have mercy on your HUD layout
|
||||
if (item.linkedTo.Count(entity => entity is Item item && item.DisplaySideBySideWhenLinked) == 1)
|
||||
if (GuiFrame != null && item.linkedTo.Count(entity => entity is Item item && item.DisplaySideBySideWhenLinked) == 1)
|
||||
{
|
||||
foreach (MapEntity linkedTo in item.linkedTo)
|
||||
{
|
||||
if (!(linkedTo is Item linkedItem)) continue;
|
||||
if (!linkedItem.Components.Any()) continue;
|
||||
if (!(linkedTo is Item linkedItem) || !linkedItem.DisplaySideBySideWhenLinked) { continue; }
|
||||
if (!linkedItem.Components.Any()) { continue; }
|
||||
|
||||
var itemContainer = linkedItem.Components.First();
|
||||
if (itemContainer == null) { continue; }
|
||||
|
||||
if (!itemContainer.Item.DisplaySideBySideWhenLinked) continue;
|
||||
var itemContainer = linkedItem.GetComponent<ItemContainer>();
|
||||
if (itemContainer?.GuiFrame == null || itemContainer.AllowUIOverlap) { continue; }
|
||||
|
||||
// how much spacing do we want between the components
|
||||
var padding = (int) (8 * GUI.Scale);
|
||||
// Move the linked container to the right and move the fabricator to the left
|
||||
itemContainer.GuiFrame.RectTransform.AbsoluteOffset = new Point(GuiFrame.Rect.Width / -2 - padding, 0);
|
||||
GuiFrame.RectTransform.AbsoluteOffset = new Point(itemContainer.GuiFrame.Rect.Width / 2 + padding, 0);
|
||||
// Move the linked container to the right and move the deconstructor to the left
|
||||
itemContainer.GuiFrame.RectTransform.AbsoluteOffset = new Point(100, 0);
|
||||
GuiFrame.RectTransform.AbsoluteOffset = new Point(-100, 0);
|
||||
}
|
||||
}
|
||||
return base.Select(character);
|
||||
|
||||
@@ -212,23 +212,21 @@ namespace Barotrauma.Items.Components
|
||||
// TODO, This works fine as of now but if GUI.PreventElementOverlap ever gets fixed this block of code may become obsolete or detrimental.
|
||||
// Only do this if there's only one linked component. If you link more containers then may
|
||||
// GUI.PreventElementOverlap have mercy on your HUD layout
|
||||
if (item.linkedTo.Count(entity => entity is Item item && item.DisplaySideBySideWhenLinked) == 1)
|
||||
if (GuiFrame != null && item.linkedTo.Count(entity => entity is Item item && item.DisplaySideBySideWhenLinked) == 1)
|
||||
{
|
||||
foreach (MapEntity linkedTo in item.linkedTo)
|
||||
{
|
||||
if (!(linkedTo is Item linkedItem)) continue;
|
||||
if (!linkedItem.Components.Any()) continue;
|
||||
|
||||
var itemContainer = linkedItem.Components.First();
|
||||
if (itemContainer == null) { continue; }
|
||||
if (!(linkedTo is Item linkedItem) || !linkedItem.DisplaySideBySideWhenLinked) { continue; }
|
||||
if (!linkedItem.Components.Any()) { continue; }
|
||||
|
||||
if (!itemContainer.Item.DisplaySideBySideWhenLinked) continue;
|
||||
var itemContainer = linkedItem.GetComponent<ItemContainer>();
|
||||
if (itemContainer?.GuiFrame == null || itemContainer.AllowUIOverlap) { continue; }
|
||||
|
||||
// how much spacing do we want between the components
|
||||
var padding = (int) (8 * GUI.Scale);
|
||||
// Move the linked container to the right and move the fabricator to the left
|
||||
itemContainer.GuiFrame.RectTransform.AbsoluteOffset = new Point(GuiFrame.Rect.Width / -2 - padding, 0);
|
||||
GuiFrame.RectTransform.AbsoluteOffset = new Point(itemContainer.GuiFrame.Rect.Width / 2 + padding, 0);
|
||||
itemContainer.GuiFrame.RectTransform.AbsoluteOffset = new Point(-100, 0);
|
||||
GuiFrame.RectTransform.AbsoluteOffset = new Point(100, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
OnClicked = (button, data) =>
|
||||
{
|
||||
targetLevel = null;
|
||||
TargetLevel = null;
|
||||
IsActive = !IsActive;
|
||||
if (GameMain.Client != null)
|
||||
{
|
||||
@@ -112,7 +112,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
if (pumpSpeedLockTimer <= 0.0f)
|
||||
{
|
||||
targetLevel = null;
|
||||
TargetLevel = null;
|
||||
}
|
||||
float newValue = barScroll * 200.0f - 100.0f;
|
||||
if (Math.Abs(newValue - FlowPercentage) < 0.1f) { return false; }
|
||||
@@ -215,14 +215,33 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public void ClientRead(ServerNetObject type, IReadMessage msg, float sendingTime)
|
||||
{
|
||||
int msgStartPos = msg.BitPosition;
|
||||
|
||||
float flowPercentage = msg.ReadRangedInteger(-10, 10) * 10.0f;
|
||||
bool isActive = msg.ReadBoolean();
|
||||
bool hijacked = msg.ReadBoolean();
|
||||
float? targetLevel;
|
||||
if (msg.ReadBoolean())
|
||||
{
|
||||
targetLevel = msg.ReadSingle();
|
||||
}
|
||||
else
|
||||
{
|
||||
targetLevel = null;
|
||||
}
|
||||
|
||||
if (correctionTimer > 0.0f)
|
||||
{
|
||||
StartDelayedCorrection(type, msg.ExtractBits(5 + 1), sendingTime);
|
||||
int msgLength = msg.BitPosition - msgStartPos;
|
||||
msg.BitPosition = msgStartPos;
|
||||
StartDelayedCorrection(type, msg.ExtractBits(msgLength), sendingTime);
|
||||
return;
|
||||
}
|
||||
|
||||
FlowPercentage = msg.ReadRangedInteger(-10, 10) * 10.0f;
|
||||
IsActive = msg.ReadBoolean();
|
||||
FlowPercentage = flowPercentage;
|
||||
IsActive = isActive;
|
||||
Hijacked = hijacked;
|
||||
TargetLevel = targetLevel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -502,8 +502,16 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
if (item.Removed) { return; }
|
||||
|
||||
Vector2 clampedOptimalTurbineOutput = optimalTurbineOutput;
|
||||
Vector2 clampedAllowedTurbineOutput = allowedTurbineOutput;
|
||||
if (clampedOptimalTurbineOutput.X > 100.0f)
|
||||
{
|
||||
clampedOptimalTurbineOutput = new Vector2(92.0f, 110.0f);
|
||||
clampedAllowedTurbineOutput = new Vector2(85.0f, 110.0f);
|
||||
}
|
||||
|
||||
DrawMeter(spriteBatch, container.Rect,
|
||||
turbineOutputMeter, TurbineOutput, new Vector2(0.0f, 100.0f), optimalTurbineOutput, allowedTurbineOutput);
|
||||
turbineOutputMeter, TurbineOutput, new Vector2(0.0f, 100.0f), clampedOptimalTurbineOutput, clampedAllowedTurbineOutput);
|
||||
}
|
||||
|
||||
public override void UpdateHUD(Character character, float deltaTime, Camera cam)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Barotrauma.Networking;
|
||||
using Barotrauma.Extensions;
|
||||
using Barotrauma.Networking;
|
||||
using FarseerPhysics;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
@@ -14,7 +15,8 @@ namespace Barotrauma.Items.Components
|
||||
public enum BlipType
|
||||
{
|
||||
Default,
|
||||
Disruption
|
||||
Disruption,
|
||||
Destructible
|
||||
}
|
||||
|
||||
private PathFinder pathFinder;
|
||||
@@ -28,11 +30,18 @@ namespace Barotrauma.Items.Components
|
||||
private GUITickBox activeTickBox, passiveTickBox;
|
||||
private GUITextBlock signalWarningText;
|
||||
|
||||
private GUIFrame lowerAreaFrame;
|
||||
|
||||
private GUIScrollBar zoomSlider;
|
||||
|
||||
private GUIButton directionalModeSwitch;
|
||||
private Vector2? pingDragDirection = null;
|
||||
|
||||
/// <summary>
|
||||
/// Can be null if the property HasMineralScanner is false
|
||||
/// </summary>
|
||||
private GUIButton mineralScannerSwitch;
|
||||
|
||||
private GUIFrame controlContainer;
|
||||
|
||||
private GUICustomComponent sonarView;
|
||||
@@ -46,7 +55,7 @@ namespace Barotrauma.Items.Components
|
||||
private Sprite sonarBlip;
|
||||
private Sprite lineSprite;
|
||||
|
||||
private readonly Dictionary<string, Sprite> targetIcons = new Dictionary<string, Sprite>();
|
||||
private readonly Dictionary<string, Tuple<Sprite, Color>> targetIcons = new Dictionary<string, Tuple<Sprite, Color>>();
|
||||
|
||||
private float displayBorderSize;
|
||||
|
||||
@@ -60,10 +69,12 @@ namespace Barotrauma.Items.Components
|
||||
private const float DisruptionUpdateInterval = 0.2f;
|
||||
private float disruptionUpdateTimer;
|
||||
|
||||
private float zoomSqrt;
|
||||
|
||||
private float showDirectionalIndicatorTimer;
|
||||
|
||||
private List<LevelObject> nearbyObjects = new List<LevelObject>();
|
||||
private const float NearbyObjectUpdateInterval = 1.0f;
|
||||
float nearbyObjectUpdateTimer;
|
||||
|
||||
//Vector2 = vector from the ping source to the position of the disruption
|
||||
//float = strength of the disruption, between 0-1
|
||||
private readonly List<Pair<Vector2, float>> disruptedDirections = new List<Pair<Vector2, float>>();
|
||||
@@ -103,6 +114,10 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
BlipType.Disruption,
|
||||
new Color[] { Color.TransparentBlack, new Color(254, 68, 19), new Color(255, 220, 62), new Color(255, 255, 255) }
|
||||
},
|
||||
{
|
||||
BlipType.Destructible,
|
||||
new Color[] { Color.TransparentBlack, new Color(74, 113, 75) * 0.8f, new Color(151, 236, 172) * 0.8f, new Color(153, 217, 234) * 0.8f }
|
||||
}
|
||||
};
|
||||
|
||||
@@ -114,6 +129,15 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public static Vector2 GUISizeCalculation => Vector2.One * Math.Min(GUI.RelativeHorizontalAspectRatio, 1f) * sonarAreaSize;
|
||||
|
||||
private List<Tuple<Vector2, List<Item>>> MineralClusters { get; set; }
|
||||
|
||||
private readonly List<GUITextBlock> textBlocksToScaleAndNormalize = new List<GUITextBlock>();
|
||||
|
||||
private bool isConnectedToSteering;
|
||||
|
||||
private bool AllowUsingMineralScanner =>
|
||||
HasMineralScanner && !isConnectedToSteering;
|
||||
|
||||
partial void InitProjSpecific(XElement element)
|
||||
{
|
||||
System.Diagnostics.Debug.Assert(Enum.GetValues(typeof(BlipType)).Cast<BlipType>().All(t => blipColorGradient.ContainsKey(t)));
|
||||
@@ -151,7 +175,9 @@ namespace Barotrauma.Items.Components
|
||||
break;
|
||||
case "icon":
|
||||
var targetIconSprite = new Sprite(subElement);
|
||||
targetIcons.Add(subElement.GetAttributeString("identifier", ""), targetIconSprite);
|
||||
var color = subElement.GetAttributeColor("color", Color.White);
|
||||
targetIcons.Add(subElement.GetAttributeString("identifier", ""),
|
||||
new Tuple<Sprite, Color>(targetIconSprite, color));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -166,16 +192,20 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
protected override void CreateGUI()
|
||||
{
|
||||
bool isConnectedToSteering = item.GetComponent<Steering>() != null;
|
||||
Vector2 size = isConnectedToSteering ? controlBoxSize : new Vector2(controlBoxSize.X * 2.0f, controlBoxSize.Y);
|
||||
isConnectedToSteering = item.GetComponent<Steering>() != null;
|
||||
Vector2 size = isConnectedToSteering ? controlBoxSize : new Vector2(0.46f, 0.4f);
|
||||
|
||||
controlContainer = new GUIFrame(new RectTransform(size, GuiFrame.RectTransform, Anchor.BottomRight, Pivot.BottomLeft), "ItemUI");
|
||||
controlContainer = new GUIFrame(new RectTransform(size, GuiFrame.RectTransform, Anchor.BottomLeft), "ItemUI");
|
||||
if (!isConnectedToSteering && !GUI.IsFourByThree())
|
||||
{
|
||||
controlContainer.RectTransform.MaxSize = new Point((int)(380 * GUI.xScale), (int)(300 * GUI.yScale));
|
||||
}
|
||||
var paddedControlContainer = new GUIFrame(new RectTransform(controlContainer.Rect.Size - GUIStyle.ItemFrameMargin, controlContainer.RectTransform, Anchor.Center)
|
||||
{
|
||||
AbsoluteOffset = GUIStyle.ItemFrameOffset
|
||||
}, style: null);
|
||||
// Based on the height difference to the steering control box so that the elements keep the same size
|
||||
float extraHeight = 0.03f;
|
||||
float extraHeight = 0.0694f;
|
||||
var sonarModeArea = new GUIFrame(new RectTransform(new Vector2(1, 0.4f + extraHeight), paddedControlContainer.RectTransform, Anchor.TopCenter), style: null);
|
||||
SonarModeSwitch = new GUIButton(new RectTransform(new Vector2(0.2f, 1), sonarModeArea.RectTransform), string.Empty, style: "SwitchVertical")
|
||||
{
|
||||
@@ -215,10 +245,15 @@ namespace Barotrauma.Items.Components
|
||||
passiveTickBox.TextBlock.OverrideTextColor(GUI.Style.TextColor);
|
||||
activeTickBox.TextBlock.OverrideTextColor(GUI.Style.TextColor);
|
||||
|
||||
var lowerArea = new GUIFrame(new RectTransform(new Vector2(1, 0.4f + extraHeight), paddedControlContainer.RectTransform, Anchor.BottomCenter), style: null);
|
||||
var zoomContainer = new GUIFrame(new RectTransform(new Vector2(1, 0.45f), lowerArea.RectTransform, Anchor.TopCenter), style: null);
|
||||
textBlocksToScaleAndNormalize.Clear();
|
||||
textBlocksToScaleAndNormalize.Add(passiveTickBox.TextBlock);
|
||||
textBlocksToScaleAndNormalize.Add(activeTickBox.TextBlock);
|
||||
|
||||
lowerAreaFrame = new GUIFrame(new RectTransform(new Vector2(1, 0.4f + extraHeight), paddedControlContainer.RectTransform, Anchor.BottomCenter), style: null);
|
||||
var zoomContainer = new GUIFrame(new RectTransform(new Vector2(1, 0.45f), lowerAreaFrame.RectTransform, Anchor.TopCenter), style: null);
|
||||
var zoomText = new GUITextBlock(new RectTransform(new Vector2(0.3f, 0.6f), zoomContainer.RectTransform, Anchor.CenterLeft),
|
||||
TextManager.Get("SonarZoom"), font: GUI.SubHeadingFont, textAlignment: Alignment.CenterRight);
|
||||
textBlocksToScaleAndNormalize.Add(zoomText);
|
||||
zoomSlider = new GUIScrollBar(new RectTransform(new Vector2(0.5f, 0.8f), zoomContainer.RectTransform, Anchor.CenterLeft)
|
||||
{
|
||||
RelativeOffset = new Vector2(0.35f, 0)
|
||||
@@ -236,9 +271,10 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
};
|
||||
|
||||
new GUIFrame(new RectTransform(new Vector2(0.8f, 0.01f), paddedControlContainer.RectTransform, Anchor.Center), style: "HorizontalLine");
|
||||
new GUIFrame(new RectTransform(new Vector2(0.8f, 0.01f), paddedControlContainer.RectTransform, Anchor.Center), style: "HorizontalLine")
|
||||
{ UserData = "horizontalline" };
|
||||
|
||||
var directionalModeFrame = new GUIFrame(new RectTransform(new Vector2(1, 0.45f), lowerArea.RectTransform, Anchor.BottomCenter), style: null);
|
||||
var directionalModeFrame = new GUIFrame(new RectTransform(new Vector2(1, 0.45f), lowerAreaFrame.RectTransform, Anchor.BottomCenter), style: null);
|
||||
directionalModeSwitch = new GUIButton(new RectTransform(new Vector2(0.3f, 0.8f), directionalModeFrame.RectTransform, Anchor.CenterLeft), string.Empty, style: "SwitchHorizontal")
|
||||
{
|
||||
OnClicked = (button, data) =>
|
||||
@@ -255,11 +291,20 @@ namespace Barotrauma.Items.Components
|
||||
};
|
||||
var directionalModeSwitchText = new GUITextBlock(new RectTransform(new Vector2(0.7f, 1), directionalModeFrame.RectTransform, Anchor.CenterRight),
|
||||
TextManager.Get("SonarDirectionalPing"), GUI.Style.TextColor, GUI.SubHeadingFont, Alignment.CenterLeft);
|
||||
textBlocksToScaleAndNormalize.Add(directionalModeSwitchText);
|
||||
|
||||
if (AllowUsingMineralScanner)
|
||||
{
|
||||
AddMineralScannerSwitchToGUI();
|
||||
}
|
||||
else
|
||||
{
|
||||
mineralScannerSwitch = null;
|
||||
}
|
||||
|
||||
GuiFrame.CanBeFocused = false;
|
||||
|
||||
GUITextBlock.AutoScaleAndNormalize(passiveTickBox.TextBlock, activeTickBox.TextBlock, zoomText, directionalModeSwitchText);
|
||||
|
||||
GUITextBlock.AutoScaleAndNormalize(textBlocksToScaleAndNormalize);
|
||||
|
||||
sonarView = new GUICustomComponent(new RectTransform(Vector2.One * 0.7f, GuiFrame.RectTransform, Anchor.BottomRight, scaleBasis: ScaleBasis.BothHeight),
|
||||
(spriteBatch, guiCustomComponent) => { DrawSonar(spriteBatch, guiCustomComponent.Rect); }, null);
|
||||
@@ -271,11 +316,16 @@ namespace Barotrauma.Items.Components
|
||||
if (isConnectedToSteering)
|
||||
{
|
||||
controlContainer.RectTransform.RelativeOffset = controlBoxOffset;
|
||||
controlContainer.RectTransform.SetPosition(Anchor.TopLeft);
|
||||
controlContainer.RectTransform.SetPosition(Anchor.TopRight);
|
||||
sonarView.RectTransform.ScaleBasis = ScaleBasis.Smallest;
|
||||
sonarView.RectTransform.SetPosition(Anchor.CenterRight);
|
||||
sonarView.RectTransform.SetPosition(Anchor.CenterLeft);
|
||||
sonarView.RectTransform.Resize(GUISizeCalculation);
|
||||
GUITextBlock.AutoScaleAndNormalize(passiveTickBox.TextBlock, activeTickBox.TextBlock, zoomText, directionalModeSwitchText);
|
||||
GUITextBlock.AutoScaleAndNormalize(textBlocksToScaleAndNormalize);
|
||||
}
|
||||
else if (GUI.RelativeHorizontalAspectRatio > 0.75f)
|
||||
{
|
||||
sonarView.RectTransform.RelativeOffset = new Vector2(0.13f * GUI.RelativeHorizontalAspectRatio, 0);
|
||||
sonarView.RectTransform.SetPosition(Anchor.BottomRight);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,10 +343,58 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
base.OnItemLoaded();
|
||||
zoomSlider.BarScroll = MathUtils.InverseLerp(MinZoom, MaxZoom, zoom);
|
||||
if (AllowUsingMineralScanner && mineralScannerSwitch == null)
|
||||
{
|
||||
AddMineralScannerSwitchToGUI();
|
||||
GUITextBlock.AutoScaleAndNormalize(textBlocksToScaleAndNormalize);
|
||||
}
|
||||
//make the sonarView customcomponent render the steering view so it gets drawn in front of the sonar
|
||||
item.GetComponent<Steering>()?.AttachToSonarHUD(sonarView);
|
||||
}
|
||||
|
||||
private void AddMineralScannerSwitchToGUI()
|
||||
{
|
||||
// First adjust other elements to make room for the additional switch
|
||||
controlContainer.RectTransform.RelativeSize = new Vector2(
|
||||
controlContainer.RectTransform.RelativeSize.X,
|
||||
controlContainer.RectTransform.RelativeSize.Y * 1.25f);
|
||||
SonarModeSwitch.Parent.RectTransform.RelativeSize = new Vector2(
|
||||
SonarModeSwitch.Parent.RectTransform.RelativeSize.X,
|
||||
SonarModeSwitch.Parent.RectTransform.RelativeSize.Y * 0.8f);
|
||||
lowerAreaFrame.Parent.GetChildByUserData("horizontalline").RectTransform.RelativeOffset =
|
||||
new Vector2(0.0f, -0.1f);
|
||||
lowerAreaFrame.RectTransform.RelativeSize = new Vector2(
|
||||
lowerAreaFrame.RectTransform.RelativeSize.X,
|
||||
lowerAreaFrame.RectTransform.RelativeSize.Y * 1.2f);
|
||||
zoomSlider.Parent.RectTransform.RelativeSize = new Vector2(
|
||||
zoomSlider.Parent.RectTransform.RelativeSize.X,
|
||||
zoomSlider.Parent.RectTransform.RelativeSize.Y * (2.0f / 3.0f));
|
||||
directionalModeSwitch.Parent.RectTransform.RelativeSize = new Vector2(
|
||||
directionalModeSwitch.Parent.RectTransform.RelativeSize.X,
|
||||
zoomSlider.Parent.RectTransform.RelativeSize.Y);
|
||||
directionalModeSwitch.Parent.RectTransform.SetPosition(Anchor.Center);
|
||||
|
||||
// Then add the scanner switch
|
||||
var mineralScannerFrame = new GUIFrame(new RectTransform(new Vector2(1.0f, zoomSlider.Parent.RectTransform.RelativeSize.Y), lowerAreaFrame.RectTransform, Anchor.BottomCenter), style: null);
|
||||
mineralScannerSwitch = new GUIButton(new RectTransform(new Vector2(0.3f, 0.8f), mineralScannerFrame.RectTransform, Anchor.CenterLeft), string.Empty, style: "SwitchHorizontal")
|
||||
{
|
||||
OnClicked = (button, data) =>
|
||||
{
|
||||
useMineralScanner = !useMineralScanner;
|
||||
button.Selected = useMineralScanner;
|
||||
if (GameMain.Client != null)
|
||||
{
|
||||
unsentChanges = true;
|
||||
correctionTimer = CorrectionDelay;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
var mineralScannerSwitchText = new GUITextBlock(new RectTransform(new Vector2(0.7f, 1), mineralScannerFrame.RectTransform, Anchor.CenterRight),
|
||||
TextManager.Get("SonarMineralScanner"), GUI.Style.TextColor, GUI.SubHeadingFont, Alignment.CenterLeft);
|
||||
textBlocksToScaleAndNormalize.Add(mineralScannerSwitchText);
|
||||
}
|
||||
|
||||
public override void UpdateHUD(Character character, float deltaTime, Camera cam)
|
||||
{
|
||||
showDirectionalIndicatorTimer -= deltaTime;
|
||||
@@ -339,6 +437,32 @@ namespace Barotrauma.Items.Components
|
||||
Vector2.DistanceSquared(sonarView.Rect.Center.ToVector2(), PlayerInput.MousePosition) <
|
||||
(sonarView.Rect.Width / 2 * sonarView.Rect.Width / 2);
|
||||
|
||||
if (AllowUsingMineralScanner && Level.Loaded != null && !Level.Loaded.Generating)
|
||||
{
|
||||
if (MineralClusters == null)
|
||||
{
|
||||
MineralClusters = new List<Tuple<Vector2, List<Item>>>();
|
||||
foreach (var p in Level.Loaded.PathPoints)
|
||||
{
|
||||
foreach (var c in p.ClusterLocations)
|
||||
{
|
||||
if (c.Resources.None(i => i != null && !i.Removed && i.Tags.Contains("ore"))) { continue; }
|
||||
var pos = Vector2.Zero;
|
||||
foreach (var r in c.Resources)
|
||||
{
|
||||
pos += r.WorldPosition;
|
||||
}
|
||||
pos /= c.Resources.Count;
|
||||
MineralClusters.Add(new Tuple<Vector2, List<Item>>(pos, c.Resources));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MineralClusters.RemoveAll(t => t.Item2 == null || t.Item2.None() || t.Item2.All(i => i == null || i.Removed));
|
||||
}
|
||||
}
|
||||
|
||||
if (UseTransducers && connectedTransducers.Count == 0)
|
||||
{
|
||||
return;
|
||||
@@ -348,21 +472,45 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
if (Level.Loaded != null)
|
||||
{
|
||||
nearbyObjectUpdateTimer -= deltaTime;
|
||||
if (nearbyObjectUpdateTimer <= 0.0f)
|
||||
{
|
||||
nearbyObjects.Clear();
|
||||
foreach (var nearbyObject in Level.Loaded.LevelObjectManager.GetAllObjects(transducerCenter, range * zoom))
|
||||
{
|
||||
if (!nearbyObject.VisibleOnSonar) { continue; }
|
||||
float objectRange = range + nearbyObject.SonarRadius;
|
||||
if (Vector2.DistanceSquared(transducerCenter, nearbyObject.WorldPosition) < objectRange * objectRange)
|
||||
{
|
||||
nearbyObjects.Add(nearbyObject);
|
||||
}
|
||||
}
|
||||
nearbyObjectUpdateTimer = NearbyObjectUpdateInterval;
|
||||
}
|
||||
|
||||
List<LevelTrigger> ballastFloraSpores = new List<LevelTrigger>();
|
||||
Dictionary<LevelTrigger, Vector2> levelTriggerFlows = new Dictionary<LevelTrigger, Vector2>();
|
||||
for (var pingIndex = 0; pingIndex < activePingsCount; ++pingIndex)
|
||||
{
|
||||
var activePing = activePings[pingIndex];
|
||||
foreach (LevelObject levelObject in Level.Loaded.LevelObjectManager.GetAllObjects(transducerCenter, range * activePing.State / zoom))
|
||||
float pingRange = range * activePing.State / zoom;
|
||||
foreach (LevelObject levelObject in nearbyObjects)
|
||||
{
|
||||
if (levelObject.Triggers == null) { continue; }
|
||||
//gather all nearby triggers that are causing the water to flow into the dictionary
|
||||
foreach (LevelTrigger trigger in levelObject.Triggers)
|
||||
{
|
||||
Vector2 flow = trigger.GetWaterFlowVelocity();
|
||||
//ignore ones that are barely doing anything (flow^2 < 1)
|
||||
if (flow.LengthSquared() > 1.0f && !levelTriggerFlows.ContainsKey(trigger))
|
||||
//ignore ones that are barely doing anything (flow^2 <= 1)
|
||||
if (flow.LengthSquared() >= 1.0f && !levelTriggerFlows.ContainsKey(trigger))
|
||||
{
|
||||
levelTriggerFlows.Add(trigger, flow);
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(trigger.InfectIdentifier) &&
|
||||
Vector2.DistanceSquared(transducerCenter, trigger.WorldPosition) < pingRange / 2 * pingRange / 2)
|
||||
{
|
||||
ballastFloraSpores.Add(trigger);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -400,6 +548,19 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
foreach (LevelTrigger spore in ballastFloraSpores)
|
||||
{
|
||||
Vector2 blipPos = spore.WorldPosition + Rand.Vector(spore.ColliderRadius * Rand.Range(0.0f, 1.0f));
|
||||
SonarBlip sporeBlip = new SonarBlip(blipPos, Rand.Range(0.1f, 0.5f), 0.5f)
|
||||
{
|
||||
Rotation = Rand.Range(-MathHelper.TwoPi, MathHelper.TwoPi),
|
||||
BlipType = BlipType.Default,
|
||||
Velocity = Rand.Vector(100f, Rand.RandSync.Unsynced)
|
||||
};
|
||||
|
||||
sonarBlips.Add(sporeBlip);
|
||||
}
|
||||
|
||||
float outsideLevelFlow = 0.0f;
|
||||
if (transducerCenter.X < 0.0f)
|
||||
{
|
||||
@@ -721,6 +882,23 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
if (AllowUsingMineralScanner && useMineralScanner && CurrentMode == Mode.Active && MineralClusters != null)
|
||||
{
|
||||
foreach (var t in MineralClusters)
|
||||
{
|
||||
var unobtainedMinerals = t.Item2.Where(i => i != null && i.GetRootInventoryOwner() == i);
|
||||
if (unobtainedMinerals.None()) { continue; }
|
||||
if (!CheckResourceMarkerVisibility(t.Item1, transducerCenter)) { continue; }
|
||||
var i = unobtainedMinerals.FirstOrDefault();
|
||||
if (i == null) { continue; }
|
||||
DrawMarker(spriteBatch,
|
||||
i.Name, "mineral", i,
|
||||
t.Item1, transducerCenter,
|
||||
displayScale, center, DisplayRadius * 0.95f,
|
||||
onlyShowTextOnMouseOver: true);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (Submarine sub in Submarine.Loaded)
|
||||
{
|
||||
if (!sub.ShowSonarMarker) { continue; }
|
||||
@@ -967,8 +1145,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
for (var pingIndex = 0; pingIndex < activePingsCount; ++pingIndex)
|
||||
{
|
||||
var activePing = activePings[pingIndex];
|
||||
foreach (LevelObject levelObject in Level.Loaded.LevelObjectManager.GetAllObjects(pingSource, range * activePing.State))
|
||||
foreach (LevelObject levelObject in nearbyObjects)
|
||||
{
|
||||
if (levelObject.ActivePrefab?.SonarDisruption <= 0.0f) { continue; }
|
||||
|
||||
@@ -1101,9 +1278,9 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
foreach (Voronoi2.GraphEdge edge in cell.Edges)
|
||||
{
|
||||
if (!edge.IsSolid) continue;
|
||||
if (!edge.IsSolid) { continue; }
|
||||
float cellDot = Vector2.Dot(cell.Center - pingSource, (edge.Center + cell.Translation) - cell.Center);
|
||||
if (cellDot > 0) continue;
|
||||
if (cellDot > 0) { continue; }
|
||||
|
||||
float facingDot = Vector2.Dot(
|
||||
Vector2.Normalize(edge.Point1 - edge.Point2),
|
||||
@@ -1114,7 +1291,8 @@ namespace Barotrauma.Items.Components
|
||||
edge.Point2 + cell.Translation,
|
||||
pingSource, transducerPos,
|
||||
pingRadius, prevPingRadius,
|
||||
350.0f, 3.0f * (Math.Abs(facingDot) + 1.0f), range, pingStrength, passive);
|
||||
350.0f, 3.0f * (Math.Abs(facingDot) + 1.0f), range, pingStrength, passive,
|
||||
blipType : cell.IsDestructible ? BlipType.Destructible : BlipType.Default);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1203,7 +1381,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
|
||||
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)
|
||||
float lineStep, float zStep, float range, float pingStrength, bool passive, BlipType blipType = BlipType.Default)
|
||||
{
|
||||
lineStep /= zoom;
|
||||
zStep /= zoom;
|
||||
@@ -1219,13 +1397,13 @@ namespace Barotrauma.Items.Components
|
||||
//ignore if outside the display
|
||||
Vector2 transducerDiff = point - transducerPos;
|
||||
Vector2 transducerDisplayDiff = transducerDiff * displayScale;
|
||||
if (transducerDisplayDiff.LengthSquared() > DisplayRadius * DisplayRadius) continue;
|
||||
if (transducerDisplayDiff.LengthSquared() > DisplayRadius * DisplayRadius) { 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;
|
||||
if (displayPointDistSqr < prevPingRadius * prevPingRadius || displayPointDistSqr > pingRadius * pingRadius) { continue; }
|
||||
|
||||
//ignore if direction is disrupted
|
||||
float transducerDist = transducerDiff.Length();
|
||||
@@ -1240,7 +1418,7 @@ namespace Barotrauma.Items.Components
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (disrupted) continue;
|
||||
if (disrupted) { continue; }
|
||||
|
||||
float displayPointDist = (float)Math.Sqrt(displayPointDistSqr);
|
||||
float alpha = pingStrength * Rand.Range(1.5f, 2.0f);
|
||||
@@ -1252,8 +1430,8 @@ namespace Barotrauma.Items.Components
|
||||
int minDist = (int)(200 / zoom);
|
||||
sonarBlips.RemoveAll(b => b.FadeTimer < fadeTimer && Math.Abs(pos.X - b.Position.X) < minDist && Math.Abs(pos.Y - b.Position.Y) < minDist);
|
||||
|
||||
var blip = new SonarBlip(pos, fadeTimer, 1.0f + ((displayPointDist + z) / DisplayRadius));
|
||||
if (!passive && !CheckBlipVisibility(blip, transducerPos)) continue;
|
||||
var blip = new SonarBlip(pos, fadeTimer, 1.0f + ((displayPointDist + z) / DisplayRadius), blipType);
|
||||
if (!passive && !CheckBlipVisibility(blip, transducerPos)) { continue; }
|
||||
|
||||
sonarBlips.Add(blip);
|
||||
zStep += 0.5f / zoom;
|
||||
@@ -1267,7 +1445,7 @@ namespace Barotrauma.Items.Components
|
||||
alpha -= 0.1f;
|
||||
}
|
||||
|
||||
if (alpha < 0) break;
|
||||
if (alpha < 0) { break; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1296,6 +1474,30 @@ namespace Barotrauma.Items.Components
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Based largely on existing CheckBlipVisibility() code
|
||||
/// </summary>
|
||||
private bool CheckResourceMarkerVisibility(Vector2 resourcePos, Vector2 transducerPos)
|
||||
{
|
||||
var distSquared = Vector2.DistanceSquared(transducerPos, resourcePos);
|
||||
if (distSquared > Range * Range)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (currentPingIndex != -1 && activePings[currentPingIndex].IsDirectional)
|
||||
{
|
||||
var pos = (resourcePos - transducerPos) * displayScale * zoom;
|
||||
pos.Y = -pos.Y;
|
||||
var length = pos.Length();
|
||||
var dir = pos / length;
|
||||
if (Vector2.Dot(activePings[currentPingIndex].Direction, dir) < DirectionalPingDotProduct)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void DrawBlip(SpriteBatch spriteBatch, SonarBlip blip, Vector2 transducerPos, Vector2 center, float strength, float blipScale)
|
||||
{
|
||||
strength = MathHelper.Clamp(strength, 0.0f, 1.0f);
|
||||
@@ -1334,7 +1536,8 @@ namespace Barotrauma.Items.Components
|
||||
sonarBlip.Draw(spriteBatch, center + pos, color * 0.5f, sonarBlip.Origin, 0, scale, SpriteEffects.None, 0);
|
||||
}
|
||||
|
||||
private void DrawMarker(SpriteBatch spriteBatch, string label, string iconIdentifier, object targetIdentifier, Vector2 worldPosition, Vector2 transducerPosition, 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,
|
||||
bool onlyShowTextOnMouseOver = false)
|
||||
{
|
||||
float linearDist = Vector2.Distance(worldPosition, transducerPosition);
|
||||
float dist = linearDist;
|
||||
@@ -1391,16 +1594,27 @@ namespace Barotrauma.Items.Components
|
||||
markerPos.Y = (int)markerPos.Y;
|
||||
|
||||
float alpha = 1.0f;
|
||||
if (linearDist * scale < radius)
|
||||
if (!onlyShowTextOnMouseOver)
|
||||
{
|
||||
float normalizedDist = linearDist * scale / radius;
|
||||
alpha = Math.Max(normalizedDist - 0.4f, 0.0f);
|
||||
|
||||
float mouseDist = Vector2.Distance(PlayerInput.MousePosition, markerPos);
|
||||
float hoverThreshold = 150.0f;
|
||||
if (mouseDist < hoverThreshold)
|
||||
if (linearDist * scale < radius)
|
||||
{
|
||||
alpha += (hoverThreshold - mouseDist) / hoverThreshold;
|
||||
float normalizedDist = linearDist * scale / radius;
|
||||
alpha = Math.Max(normalizedDist - 0.4f, 0.0f);
|
||||
|
||||
float mouseDist = Vector2.Distance(PlayerInput.MousePosition, markerPos);
|
||||
float hoverThreshold = 150.0f;
|
||||
if (mouseDist < hoverThreshold)
|
||||
{
|
||||
alpha += (hoverThreshold - mouseDist) / hoverThreshold;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
float mouseDist = Vector2.Distance(PlayerInput.MousePosition, markerPos);
|
||||
if (mouseDist > 5)
|
||||
{
|
||||
alpha = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1410,7 +1624,8 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
else
|
||||
{
|
||||
targetIcons[iconIdentifier].Draw(spriteBatch, markerPos);
|
||||
var iconInfo = targetIcons[iconIdentifier];
|
||||
iconInfo.Item1.Draw(spriteBatch, markerPos, iconInfo.Item2);
|
||||
}
|
||||
|
||||
if (alpha <= 0.0f) { return; }
|
||||
@@ -1441,11 +1656,13 @@ namespace Barotrauma.Items.Components
|
||||
screenBackground?.Remove();
|
||||
lineSprite?.Remove();
|
||||
|
||||
foreach (Sprite sprite in targetIcons.Values)
|
||||
foreach (var t in targetIcons.Values)
|
||||
{
|
||||
sprite.Remove();
|
||||
t.Item1.Remove();
|
||||
}
|
||||
targetIcons.Clear();
|
||||
|
||||
MineralClusters = null;
|
||||
}
|
||||
|
||||
public void ClientWrite(IWriteMessage msg, object[] extraData = null)
|
||||
@@ -1460,6 +1677,7 @@ namespace Barotrauma.Items.Components
|
||||
float pingAngle = MathUtils.WrapAngleTwoPi(MathUtils.VectorToAngle(pingDirection));
|
||||
msg.WriteRangedSingle(MathUtils.InverseLerp(0.0f, MathHelper.TwoPi, pingAngle), 0.0f, 1.0f, 8);
|
||||
}
|
||||
msg.Write(useMineralScanner);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1471,6 +1689,7 @@ namespace Barotrauma.Items.Components
|
||||
float zoomT = 1.0f;
|
||||
bool directionalPing = useDirectionalPing;
|
||||
float directionT = 0.0f;
|
||||
bool mineralScanner = useMineralScanner;
|
||||
if (isActive)
|
||||
{
|
||||
zoomT = msg.ReadRangedSingle(0.0f, 1.0f, 8);
|
||||
@@ -1479,6 +1698,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
directionT = msg.ReadRangedSingle(0.0f, 1.0f, 8);
|
||||
}
|
||||
mineralScanner = msg.ReadBoolean();
|
||||
}
|
||||
|
||||
if (correctionTimer > 0.0f)
|
||||
@@ -1500,6 +1720,11 @@ namespace Barotrauma.Items.Components
|
||||
pingDirection = new Vector2((float)Math.Cos(pingAngle), (float)Math.Sin(pingAngle));
|
||||
}
|
||||
useDirectionalPing = directionalModeSwitch.Selected = directionalPing;
|
||||
useMineralScanner = mineralScanner;
|
||||
if (mineralScannerSwitch != null)
|
||||
{
|
||||
mineralScannerSwitch.Selected = mineralScanner;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1510,6 +1735,10 @@ namespace Barotrauma.Items.Components
|
||||
passiveTickBox.Selected = !isActive;
|
||||
activeTickBox.Selected = isActive;
|
||||
directionalModeSwitch.Selected = useDirectionalPing;
|
||||
if (mineralScannerSwitch != null)
|
||||
{
|
||||
mineralScannerSwitch.Selected = useMineralScanner;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
protected override void CreateGUI()
|
||||
{
|
||||
controlContainer = new GUIFrame(new RectTransform(new Vector2(Sonar.controlBoxSize.X, 1 - Sonar.controlBoxSize.Y * 2), GuiFrame.RectTransform, Anchor.CenterLeft), "ItemUI");
|
||||
controlContainer = new GUIFrame(new RectTransform(new Vector2(Sonar.controlBoxSize.X, 1 - Sonar.controlBoxSize.Y * 2), GuiFrame.RectTransform, Anchor.CenterRight), "ItemUI");
|
||||
var paddedControlContainer = new GUIFrame(new RectTransform(controlContainer.Rect.Size - GUIStyle.ItemFrameMargin, controlContainer.RectTransform, Anchor.Center)
|
||||
{
|
||||
AbsoluteOffset = GUIStyle.ItemFrameOffset
|
||||
@@ -265,7 +265,7 @@ namespace Barotrauma.Items.Components
|
||||
levelStartSelected ? Destination.LevelStart : Destination.LevelEnd);
|
||||
|
||||
// Status ->
|
||||
statusContainer = new GUIFrame(new RectTransform(Sonar.controlBoxSize, GuiFrame.RectTransform, Anchor.BottomLeft)
|
||||
statusContainer = new GUIFrame(new RectTransform(Sonar.controlBoxSize, GuiFrame.RectTransform, Anchor.BottomRight)
|
||||
{
|
||||
RelativeOffset = Sonar.controlBoxOffset
|
||||
}, "ItemUI");
|
||||
@@ -319,8 +319,7 @@ namespace Barotrauma.Items.Components
|
||||
centerText = $"({TextManager.Get("Meter")})";
|
||||
rightTextGetter = () =>
|
||||
{
|
||||
Vector2 pos = controlledSub == null ? Vector2.Zero : controlledSub.Position;
|
||||
float realWorldDepth = Level.Loaded == null ? 0.0f : Math.Abs(pos.Y - Level.Loaded.Size.Y) * Physics.DisplayToRealWorldRatio;
|
||||
float realWorldDepth = controlledSub == null ? -1000.0f : controlledSub.RealWorldDepth;
|
||||
return ((int)realWorldDepth).ToString();
|
||||
};
|
||||
break;
|
||||
@@ -340,9 +339,9 @@ namespace Barotrauma.Items.Components
|
||||
//docking interface ----------------------------------------------------
|
||||
float dockingButtonSize = 1.1f;
|
||||
float elementScale = 0.6f;
|
||||
dockingContainer = new GUIFrame(new RectTransform(Sonar.controlBoxSize, GuiFrame.RectTransform, Anchor.BottomLeft, scaleBasis: ScaleBasis.Smallest)
|
||||
dockingContainer = new GUIFrame(new RectTransform(Sonar.controlBoxSize, GuiFrame.RectTransform, Anchor.BottomRight, scaleBasis: ScaleBasis.Smallest)
|
||||
{
|
||||
RelativeOffset = new Vector2(Sonar.controlBoxOffset.X + 0.05f, Sonar.controlBoxOffset.Y)
|
||||
RelativeOffset = new Vector2(Sonar.controlBoxOffset.X + 0.05f, -0.05f)
|
||||
}, style: null);
|
||||
|
||||
dockText = TextManager.Get("label.navterminaldock", fallBackTag: "captain.dock");
|
||||
@@ -437,7 +436,7 @@ namespace Barotrauma.Items.Components
|
||||
};
|
||||
|
||||
// Sonar area
|
||||
steerArea = new GUICustomComponent(new RectTransform(Sonar.GUISizeCalculation, GuiFrame.RectTransform, Anchor.CenterRight, scaleBasis: ScaleBasis.Smallest),
|
||||
steerArea = new GUICustomComponent(new RectTransform(Sonar.GUISizeCalculation, GuiFrame.RectTransform, Anchor.CenterLeft, scaleBasis: ScaleBasis.Smallest),
|
||||
(spriteBatch, guiCustomComponent) => { DrawHUD(spriteBatch, guiCustomComponent.Rect); }, null);
|
||||
steerRadius = steerArea.Rect.Width / 2;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user