(d9829ac) v0.9.4.0

This commit is contained in:
Regalis
2019-10-24 18:05:42 +02:00
parent 9aa12bcac2
commit b39922a074
319 changed files with 12516 additions and 6815 deletions
@@ -113,7 +113,7 @@ namespace Barotrauma.Items.Components
if (spriteIndex >= propellerSprite.FrameCount) spriteIndex = 0.0f;
}
public void Draw(SpriteBatch spriteBatch, bool editing)
public void Draw(SpriteBatch spriteBatch, bool editing, float itemDepth = -1)
{
if (propellerSprite != null)
{
@@ -271,11 +271,14 @@ namespace Barotrauma.Items.Components
Rectangle slotRect = outputContainer.Inventory.slots[0].Rect;
GUI.DrawRectangle(spriteBatch,
new Rectangle(
slotRect.X, slotRect.Y + (int)(slotRect.Height * (1.0f - progressState)),
slotRect.Width, (int)(slotRect.Height * progressState)),
Color.Green * 0.5f, isFilled: true);
if (fabricatedItem != null)
{
GUI.DrawRectangle(spriteBatch,
new Rectangle(
slotRect.X, slotRect.Y + (int)(slotRect.Height * (1.0f - progressState)),
slotRect.Width, (int)(slotRect.Height * progressState)),
Color.Green * 0.5f, isFilled: true);
}
itemIcon.Draw(
spriteBatch,
@@ -79,6 +79,11 @@ namespace Barotrauma.Items.Components
displayedSubs.AddRange(item.Submarine.DockedTo);
}
public override void FlipX(bool relativeToSub)
{
CreateHUD();
}
public override void UpdateHUD(Character character, float deltaTime, Camera cam)
{
//recreate HUD if the subs we should display have changed
@@ -137,7 +137,7 @@ namespace Barotrauma.Items.Components
var btnText = warningBtn.GetChild<GUITextBlock>();
btnText.Font = GUI.Font;
btnText.Wrap = true;
btnText.Wrap = false;
btnText.SetTextPos();
warningButtons.Add(warningTexts[i], warningBtn);
}
@@ -27,12 +27,16 @@ namespace Barotrauma.Items.Components
private GUITickBox directionalTickBox;
private GUIScrollBar directionalSlider;
private Vector2? pingDragDirection = null;
private GUILayoutGroup activeControlsContainer;
private GUIFrame controlContainer;
private GUICustomComponent sonarView;
private Sprite directionalPingBackground;
private Sprite[] directionalPingButton;
private float displayBorderSize;
private List<SonarBlip> sonarBlips;
@@ -149,14 +153,10 @@ namespace Barotrauma.Items.Components
{
showDirectionalIndicatorTimer = 1.0f;
float pingAngle = MathHelper.Lerp(0.0f, MathHelper.TwoPi, scroll);
pingDirection = new Vector2((float)Math.Cos(pingAngle), (float)Math.Sin(pingAngle));
if (GameMain.Client != null)
{
unsentChanges = true;
correctionTimer = CorrectionDelay;
}
SetPingDirection(new Vector2((float)Math.Cos(pingAngle), (float)Math.Sin(pingAngle)));
return true;
}
},
Range = new Vector2(0,MathHelper.TwoPi)
};
signalWarningText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.15f), paddedControlContainer.RectTransform), "", Color.Orange, textAlignment: Alignment.Center);
@@ -178,6 +178,14 @@ namespace Barotrauma.Items.Components
case "directionalpingcircle":
directionalPingCircle = new Sprite(subElement);
break;
case "directionalpingbackground":
directionalPingBackground = new Sprite(subElement);
break;
case "directionalpingbutton":
if (directionalPingButton == null) { directionalPingButton = new Sprite[3]; }
int index = subElement.GetAttributeInt("index", 0);
directionalPingButton[index] = new Sprite(subElement);
break;
case "screenoverlay":
screenOverlay = new Sprite(subElement);
break;
@@ -206,6 +214,16 @@ namespace Barotrauma.Items.Components
controlContainer.RectTransform.AbsoluteOffset = new Point((int)(viewSize * 0.9f), 0);
}
private void SetPingDirection(Vector2 direction)
{
pingDirection = direction;
if (GameMain.Client != null)
{
unsentChanges = true;
correctionTimer = CorrectionDelay;
}
}
public override void OnItemLoaded()
{
zoomSlider.BarScroll = MathUtils.InverseLerp(MinZoom, MaxZoom, zoom);
@@ -352,6 +370,43 @@ namespace Barotrauma.Items.Components
prevDockingDist = float.MaxValue;
}
if (steering != null && directionalPingButton != null)
{
steering.SteerRadius = useDirectionalPing && pingDragDirection != null ?
-1.0f :
PlayerInput.LeftButtonDown() || !PlayerInput.LeftButtonHeld() ?
(float?)((sonarView.Rect.Width / 2) - (directionalPingButton[0].size.X * sonarView.Rect.Width / screenBackground.size.X)) :
null;
}
if (useDirectionalPing && PlayerInput.LeftButtonHeld())
{
if ((MouseInDirectionalPingRing(sonarView.Rect, false) && PlayerInput.LeftButtonDown()) || pingDragDirection != null)
{
Vector2 newDragDir = Vector2.Normalize(PlayerInput.MousePosition - sonarView.Rect.Center.ToVector2());
if (pingDragDirection == null && !MouseInDirectionalPingRing(sonarView.Rect, true))
{
directionalSlider.BarScrollValue = MathUtils.WrapAngleTwoPi(MathUtils.VectorToAngle(newDragDir));
directionalSlider.OnMoved(directionalSlider, directionalSlider.BarScroll);
}
else if (pingDragDirection != null)
{
float newAngle = MathUtils.VectorToAngle(newDragDir);
float oldAngle = MathUtils.VectorToAngle(pingDragDirection.Value);
float pingAngle = MathUtils.VectorToAngle(pingDirection);
pingAngle = MathUtils.WrapAngleTwoPi(pingAngle + MathUtils.GetShortestAngle(oldAngle, newAngle));
directionalSlider.BarScrollValue = pingAngle;
directionalSlider.OnMoved(directionalSlider, directionalSlider.BarScroll);
}
pingDragDirection = newDragDir;
}
}
else
{
pingDragDirection = null;
}
for (var pingIndex = 0; pingIndex < activePingsCount; ++pingIndex)
{
var activePing = activePings[pingIndex];
@@ -391,6 +446,28 @@ namespace Barotrauma.Items.Components
prevPassivePingRadius = passivePingRadius;
}
private bool MouseInDirectionalPingRing(Rectangle rect, bool onButton)
{
if (!useDirectionalPing || directionalPingButton == null) { return false; }
float endRadius = rect.Width / 2.0f;
float startRadius = endRadius - directionalPingButton[0].size.X * rect.Width / screenBackground.size.X;
Vector2 center = rect.Center.ToVector2();
float dist = Vector2.DistanceSquared(PlayerInput.MousePosition,center);
bool retVal = (dist >= startRadius*startRadius) && (dist < endRadius*endRadius);
if (onButton)
{
float pingAngle = MathUtils.VectorToAngle(pingDirection);
float mouseAngle = MathUtils.VectorToAngle(Vector2.Normalize(PlayerInput.MousePosition - center));
retVal &= Math.Abs(MathUtils.GetShortestAngle(mouseAngle, pingAngle)) < MathHelper.ToRadians(DirectionalPingSector * 0.5f);
}
return retVal;
}
private void DrawSonar(SpriteBatch spriteBatch, Rectangle rect)
{
displayBorderSize = 0.2f;
@@ -403,6 +480,24 @@ namespace Barotrauma.Items.Components
screenBackground.Draw(spriteBatch, center, 0.0f, rect.Width / screenBackground.size.X);
}
if (useDirectionalPing)
{
directionalPingBackground?.Draw(spriteBatch, center, 0.0f, rect.Width / directionalPingBackground.size.X);
if (directionalPingButton != null)
{
int buttonSprIndex = 0;
if (pingDragDirection != null)
{
buttonSprIndex = 2;
}
else if (MouseInDirectionalPingRing(rect, true))
{
buttonSprIndex = 1;
}
directionalPingButton[buttonSprIndex]?.Draw(spriteBatch, center, MathUtils.VectorToAngle(pingDirection), rect.Width / directionalPingBackground.size.X);
}
}
if (currentMode == Mode.Active && currentPingIndex != -1)
{
var activePing = activePings[currentPingIndex];
@@ -47,6 +47,10 @@ namespace Barotrauma.Items.Components
private Sprite maintainPosIndicator, maintainPosOriginIndicator;
private Sprite steeringIndicator;
private List<DockingPort> connectedPorts = new List<DockingPort>();
private float checkConnectedPortsTimer;
private const float CheckConnectedPortsInterval = 1.0f;
private Vector2 keyboardInput = Vector2.Zero;
private float inputCumulation;
@@ -86,6 +90,19 @@ namespace Barotrauma.Items.Components
set;
} = true;
private float steerRadius;
public float? SteerRadius
{
get
{
return steerRadius;
}
set
{
steerRadius = value ?? (steerArea.Rect.Width / 2);
}
}
public List<DockingPort> DockingSources = new List<DockingPort>();
public DockingPort ActiveDockingSource, DockingTarget;
@@ -317,7 +334,7 @@ namespace Barotrauma.Items.Components
{
if (GameMain.Client == null)
{
item.SendSignal(0, "1", "toggle_docking", sender: Character.Controlled);
item.SendSignal(0, "1", "toggle_docking", sender: null);
}
else
{
@@ -384,6 +401,8 @@ namespace Barotrauma.Items.Components
statusContainer.RectTransform.AbsoluteOffset = new Point((int)(viewSize * 0.9f), 0);
steerArea.RectTransform.NonScaledSize = new Point(viewSize);
dockingContainer.RectTransform.AbsoluteOffset = new Point((int)(viewSize * 0.9f), 0);
steerRadius = steerArea.Rect.Width / 2;
}
private void FindConnectedDockingPort()
@@ -661,7 +680,7 @@ namespace Barotrauma.Items.Components
pressureWarningText.Visible = item.Submarine != null && item.Submarine.AtDamageDepth && Timing.TotalTime % 1.0f < 0.5f;
if (Vector2.Distance(PlayerInput.MousePosition, steerArea.Rect.Center.ToVector2()) < steerArea.Rect.Width / 2)
if (Vector2.DistanceSquared(PlayerInput.MousePosition, steerArea.Rect.Center.ToVector2()) < steerRadius * steerRadius)
{
if (PlayerInput.LeftButtonHeld())
{
@@ -735,10 +754,21 @@ namespace Barotrauma.Items.Components
}
if (!UseAutoDocking) { return; }
if (checkConnectedPortsTimer <= 0.0f)
{
Connection dockingConnection = item.Connections?.FirstOrDefault(c => c.Name == "toggle_docking");
if (dockingConnection != null)
{
connectedPorts = item.GetConnectedComponentsRecursive<DockingPort>(dockingConnection);
}
checkConnectedPortsTimer = CheckConnectedPortsInterval;
}
float closestDist = DockingAssistThreshold * DockingAssistThreshold;
DockingModeEnabled = false;
foreach (DockingPort sourcePort in DockingPort.List)
foreach (DockingPort sourcePort in connectedPorts)
{
if (sourcePort.Docked || sourcePort.Item.Submarine == null) { continue; }
if (sourcePort.Item.Submarine != controlledSub) { continue; }
@@ -826,6 +856,7 @@ namespace Barotrauma.Items.Components
int msgStartPos = msg.BitPosition;
bool autoPilot = msg.ReadBoolean();
bool dockingButtonClicked = msg.ReadBoolean();
Vector2 newSteeringInput = steeringInput;
Vector2 newTargetVelocity = targetVelocity;
float newSteeringAdjustSpeed = steeringAdjustSpeed;
@@ -833,6 +864,11 @@ namespace Barotrauma.Items.Components
Vector2? newPosToMaintain = null;
bool headingToStart = false;
if (dockingButtonClicked)
{
item.SendSignal(0, "1", "toggle_docking", sender: null);
}
if (autoPilot)
{
maintainPos = msg.ReadBoolean();