Transforming received in-sub mouse coordinates to outside coordinates if the character is outside and vice versa, HiddenSubPosition fix (can't use Level.Loaded to find the top of the level because the level isn't loaded yet)

This commit is contained in:
Regalis
2017-01-05 19:07:18 +02:00
parent 518eea746e
commit beac45458e
7 changed files with 86 additions and 49 deletions

View File

@@ -811,7 +811,7 @@ namespace Barotrauma
//Level.Loaded.Move(-amount);
}
public static Submarine GetClosest(Vector2 worldPosition)
public static Submarine FindClosest(Vector2 worldPosition)
{
Submarine closest = null;
float closestDist = 0.0f;
@@ -828,6 +828,24 @@ namespace Barotrauma
return closest;
}
/// <summary>
/// Finds the sub whose borders contain the position
/// </summary>
public static Submarine FindContaining(Vector2 position)
{
foreach (Submarine sub in Submarine.Loaded)
{
Rectangle subBorders = sub.Borders;
subBorders.Location += sub.HiddenSubPosition.ToPoint() - new Microsoft.Xna.Framework.Point(0, sub.Borders.Height);
subBorders.Inflate(500.0f, 500.0f);
if (subBorders.Contains(position)) return sub;
}
return null;
}
//saving/loading ----------------------------------------------------
public bool Save()
@@ -1056,7 +1074,10 @@ namespace Barotrauma
//place the sub above the top of the level
HiddenSubPosition = HiddenSubStartPosition;
if (Level.Loaded != null) HiddenSubPosition += Vector2.UnitY * Level.Loaded.Size.Y;
if (GameMain.GameSession != null && GameMain.GameSession.Level != null)
{
HiddenSubPosition += Vector2.UnitY * GameMain.GameSession.Level.Size.Y;
}
foreach (Submarine sub in Submarine.loaded)
{

View File

@@ -207,7 +207,7 @@ namespace Barotrauma
Submarine closestSub = null;
if (Character.Controlled == null)
{
closestSub = Submarine.GetClosest(GameMain.GameScreen.Cam.WorldViewCenter);
closestSub = Submarine.FindClosest(GameMain.GameScreen.Cam.WorldViewCenter);
}
else
{