diff --git a/Subsurface/Source/Items/Item.cs b/Subsurface/Source/Items/Item.cs index fe5e3c6cf..8d38540e3 100644 --- a/Subsurface/Source/Items/Item.cs +++ b/Subsurface/Source/Items/Item.cs @@ -286,7 +286,7 @@ namespace Barotrauma } public Item(Rectangle newRect, ItemPrefab itemPrefab, Submarine submarine) - : base(submarine) + : base(itemPrefab, submarine) { prefab = itemPrefab; @@ -1219,7 +1219,7 @@ namespace Barotrauma element.Add(new XAttribute("name", prefab.Name), new XAttribute("ID", ID)); - if (prefab.ResizeHorizontal || prefab.ResizeVertical) + if (ResizeHorizontal || ResizeVertical) { element.Add(new XAttribute("rect", (int)(rect.X - Submarine.HiddenSubPosition.X) + "," + diff --git a/Subsurface/Source/Map/Gap.cs b/Subsurface/Source/Map/Gap.cs index b89793040..5b24d7b07 100644 --- a/Subsurface/Source/Map/Gap.cs +++ b/Subsurface/Source/Map/Gap.cs @@ -20,15 +20,15 @@ namespace Barotrauma //private Sound waterSound; //a value between 0.0f-1.0f (0.0 = closed, 1.0f = open) - float open; + private float open; //the force of the water flow which is exerted on physics bodies - Vector2 flowForce; + private Vector2 flowForce; - Hull flowTargetHull; + private Hull flowTargetHull; - float higherSurface; - float lowerSurface; + private float higherSurface; + private float lowerSurface; public float Open @@ -39,11 +39,6 @@ namespace Barotrauma public Door ConnectedDoor; - //public Vector2 FlowForce - //{ - // get { return flowForce*soundVolume; } - //} - public Vector2 LerpedFlowForce { get { return lerpedFlowForce; } @@ -64,6 +59,20 @@ namespace Barotrauma } } + public override Rectangle Rect + { + get + { + return base.Rect; + } + set + { + base.Rect = value; + + FindHulls(); + } + } + public Gap(MapEntityPrefab prefab, Rectangle rectangle) : this (rectangle, Submarine.Loaded) { } @@ -73,7 +82,7 @@ namespace Barotrauma { } public Gap(Rectangle newRect, bool isHorizontal, Submarine submarine) - : base (submarine) + : base (MapEntityPrefab.list.Find(m=> m.Name == "Gap"), submarine) { rect = newRect; linkedTo = new ObservableCollection(); @@ -169,34 +178,21 @@ namespace Barotrauma GUI.DrawRectangle(sb, new Rectangle(WorldRect.X, -WorldRect.Y, rect.Width, rect.Height), clr * 0.5f, true); - if (isHorizontal) + for (int i = 0; i < linkedTo.Count; i++) { - for (int i = 0; i < linkedTo.Count; i++ ) - { - if (linkedTo[i].Rect.Center.X > rect.Center.X) - { - GUI.DrawRectangle(sb, new Rectangle(WorldRect.Right, -WorldRect.Y, 10, rect.Height), Color.Green * 0.3f, true); - } - else - { - GUI.DrawRectangle(sb, new Rectangle(WorldRect.X - 10, -WorldRect.Y, 10, rect.Height), Color.Green * 0.3f, true); - } - } - } - else - { - for (int i = 0; i < linkedTo.Count; i++) - { - if (linkedTo[i].Rect.Y - linkedTo[i].Rect.Height / 2.0f > rect.Y-rect.Height/2.0f) - { - GUI.DrawRectangle(sb, new Rectangle(WorldRect.X, -WorldRect.Y - 10, rect.Width, 10), Color.Green * 0.3f, true); - } - else - { - GUI.DrawRectangle(sb, new Rectangle(WorldRect.X, -WorldRect.Y + rect.Height, rect.Width, 10), Color.Green * 0.3f, true); - } - } - } + Vector2 dir = isHorizontal ? + new Vector2(Math.Sign(linkedTo[i].Rect.Center.X - rect.Center.X), 0.0f) + : new Vector2(0.0f, Math.Sign((linkedTo[i].Rect.Y - linkedTo[i].Rect.Height / 2.0f) - (rect.Y - rect.Height / 2.0f))); + + Vector2 arrowPos = new Vector2(WorldRect.Center.X, -(WorldRect.Y - WorldRect.Height / 2)); + arrowPos += new Vector2(dir.X * (WorldRect.Width / 2 + 10), dir.Y * (WorldRect.Height / 2 + 10)); + + GUI.Arrow.Draw(sb, + arrowPos, + clr * 0.8f, + GUI.Arrow.Origin, MathUtils.VectorToAngle(dir) + MathHelper.PiOver2, + isHorizontal ? new Vector2(rect.Height / 16.0f, 1.0f) : new Vector2(rect.Width / 16.0f, 1.0f)); + } if (isSelected) { diff --git a/Subsurface/Source/Map/Hull.cs b/Subsurface/Source/Map/Hull.cs index de63e87d8..c65d22791 100644 --- a/Subsurface/Source/Map/Hull.cs +++ b/Subsurface/Source/Map/Hull.cs @@ -74,6 +74,21 @@ namespace Barotrauma } } + public override Rectangle Rect + { + get + { + return base.Rect; + } + set + { + base.Rect = value; + + Item.UpdateHulls(); + Gap.UpdateHulls(); + } + } + public override bool IsLinkable { get { return true; } @@ -151,13 +166,13 @@ namespace Barotrauma } public Hull(MapEntityPrefab prefab, Rectangle rectangle) - : this (rectangle, Submarine.Loaded) + : this (prefab, rectangle, Submarine.Loaded) { } - public Hull(Rectangle rectangle, Submarine submarine) - : base (submarine) + public Hull(MapEntityPrefab prefab, Rectangle rectangle, Submarine submarine) + : base (prefab, submarine) { rect = rectangle; @@ -691,7 +706,7 @@ namespace Barotrauma int.Parse(element.Attribute("height").Value)); } - Hull h = new Hull(rect, submarine); + Hull h = new Hull(MapEntityPrefab.list.Find(m => m.Name == "Hull"), rect, submarine); h.volume = ToolBox.GetAttributeFloat(element, "pressure", 0.0f); diff --git a/Subsurface/Source/Map/MapEntity.cs b/Subsurface/Source/Map/MapEntity.cs index ac310e5bb..12713e97f 100644 --- a/Subsurface/Source/Map/MapEntity.cs +++ b/Subsurface/Source/Map/MapEntity.cs @@ -23,7 +23,9 @@ namespace Barotrauma protected static Vector2 selectionSize = Vector2.Zero; protected static Vector2 startMovingPos = Vector2.Zero; - + + private MapEntityPrefab prefab; + protected List linkedToID; //observable collection because some entities may need to be notified when the collection is modified @@ -66,6 +68,9 @@ namespace Barotrauma //the position and dimensions of the entity protected Rectangle rect; + + private static bool resizing; + private int resizeDirX, resizeDirY; public virtual Rectangle Rect { get { return rect; } @@ -139,12 +144,24 @@ namespace Barotrauma set { isSelected = value; } } + protected bool ResizeHorizontal + { + get { return prefab == null ? false : prefab.ResizeHorizontal; } + } + protected bool ResizeVertical + { + get { return prefab == null ? false : prefab.ResizeVertical; } + } + public virtual string Name { get { return ""; } } - public MapEntity(Submarine submarine) : base(submarine) { } + public MapEntity(MapEntityPrefab prefab, Submarine submarine) : base(submarine) + { + this.prefab = prefab; + } public virtual void Move(Vector2 amount) { @@ -232,6 +249,12 @@ namespace Barotrauma /// public static void UpdateSelecting(Camera cam) { + if (resizing) + { + if (selectedList.Count == 0) resizing = false; + return; + } + foreach (MapEntity e in mapEntityList) { e.isHighlighted = false; @@ -245,7 +268,7 @@ namespace Barotrauma } if (GUIComponent.MouseOn != null || !PlayerInput.MouseInsideWindow) return; - + if (MapEntityPrefab.Selected != null) { selectionPos = Vector2.Zero; @@ -412,6 +435,11 @@ namespace Barotrauma if (selectedList.Count == 1) { selectedList[0].DrawEditing(spriteBatch, cam); + + if (selectedList[0].ResizeHorizontal || selectedList[0].ResizeVertical) + { + selectedList[0].DrawResizing(spriteBatch, cam); + } } else { @@ -443,6 +471,89 @@ namespace Barotrauma public virtual void DrawEditing(SpriteBatch spriteBatch, Camera cam) {} + private void DrawResizing(SpriteBatch spriteBatch, Camera cam) + { + isHighlighted = true; + + int startX = ResizeHorizontal ? -1 : 0; + int StartY = ResizeVertical ? -1 : 0; + + for (int x = startX; x < 2; x += 2) + { + for (int y = StartY; y < 2; y += 2) + { + + Vector2 handlePos = cam.WorldToScreen(Position + new Vector2(x * (rect.Width * 0.5f + 5), y * (rect.Height * 0.5f + 5))); + + bool highlighted = Vector2.Distance(PlayerInput.MousePosition, handlePos)<5.0f; + + GUI.DrawRectangle(spriteBatch, handlePos - new Vector2(3.0f, 3.0f), new Vector2(6.0f, 6.0f), Color.White * (highlighted ? 1.0f : 0.6f), true); + + if (highlighted) + { + if (PlayerInput.LeftButtonDown()) + { + selectionPos = Vector2.Zero; + resizeDirX = x; + resizeDirY = y; + resizing = true; + } + } + } + } + + if (resizing) + { + + Vector2 placePosition = new Vector2(rect.X, rect.Y); + Vector2 placeSize = new Vector2(rect.Width, rect.Height); + + Vector2 mousePos = Submarine.MouseToWorldGrid(cam); + + if (resizeDirX >0) + { + mousePos.X = Math.Max(mousePos.X, rect.X + Submarine.GridSize.X); + placeSize.X = mousePos.X - placePosition.X; + } + else if (resizeDirX <0) + { + mousePos.X = Math.Min(mousePos.X, rect.Right - Submarine.GridSize.X); + + placeSize.X = (placePosition.X + placeSize.X)-mousePos.X; + placePosition.X = mousePos.X; + } + if (resizeDirY < 0) + { + mousePos.Y = Math.Min(mousePos.Y, rect.Y - Submarine.GridSize.Y); + placeSize.Y = placePosition.Y-mousePos.Y; + } + else if (resizeDirY > 0) + { + mousePos.Y = Math.Max(mousePos.Y, rect.Y - rect.Height + Submarine.GridSize.X); + + placeSize.Y = mousePos.Y - (rect.Y - rect.Height); + placePosition.Y = mousePos.Y; + } + + if ((int)placePosition.X != rect.X || (int)placePosition.Y != rect.Y || (int)placeSize.X != rect.Width || (int)placeSize.Y != rect.Height) + { + Rect = new Rectangle((int)placePosition.X, (int)placePosition.Y, (int)placeSize.X, (int)placeSize.Y); + } + + if (!PlayerInput.LeftButtonHeld()) + { + resizing = false; + } + + //if (resizeHorizontal) placeSize.X = position.X - placePosition.X; + //if (resizeVertical) placeSize.Y = placePosition.Y - position.Y; + + //Rectangle newRect = Submarine.AbsRect(placePosition, placeSize); + //newRect.Width = (int)Math.Max(newRect.Width, Submarine.GridSize.X); + //newRect.Height = (int)Math.Max(newRect.Height, Submarine.GridSize.Y); + } + } + public static List FindMapEntities(Vector2 pos) { List foundEntities = new List(); @@ -518,13 +629,6 @@ namespace Barotrauma { mapEntityList[i].OnMapLoaded(); } - - - - //mapEntityList.Sort((x, y) => - //{ - // return x.Name.CompareTo(y.Name); - //}); } diff --git a/Subsurface/Source/Map/Structure.cs b/Subsurface/Source/Map/Structure.cs index 4811dc103..541cea00c 100644 --- a/Subsurface/Source/Map/Structure.cs +++ b/Subsurface/Source/Map/Structure.cs @@ -141,7 +141,7 @@ namespace Barotrauma } public Structure(Rectangle rectangle, StructurePrefab sp, Submarine submarine) - : base(submarine) + : base(sp, submarine) { if (rectangle.Width == 0 || rectangle.Height == 0) return; diff --git a/Subsurface/Source/Map/WayPoint.cs b/Subsurface/Source/Map/WayPoint.cs index e84e0548f..13d850e65 100644 --- a/Subsurface/Source/Map/WayPoint.cs +++ b/Subsurface/Source/Map/WayPoint.cs @@ -96,7 +96,7 @@ namespace Barotrauma } public WayPoint(Rectangle newRect, Submarine submarine) - : base (submarine) + : base (null, submarine) { rect = newRect; linkedTo = new ObservableCollection(); diff --git a/Subsurface/changelog.txt b/Subsurface/changelog.txt index d98901abe..d85390608 100644 --- a/Subsurface/changelog.txt +++ b/Subsurface/changelog.txt @@ -1,3 +1,25 @@ +--------------------------------------------------------------------------------------------------------- +v0.3.4.0 +--------------------------------------------------------------------------------------------------------- + +Multiplayer: +- missing submarine files can be downloaded from the server host +- player syncing bugfixes (aiming is visible to other players, smoother movement in water) +- creature syncing bugfixes (less teleporting around) +- fixed the server lobby displaying wrong numbers of votes at the client's side +- fixed the server list displaying 16/16 players as 0/16 +- saving server settings + +Other: +- skyholder artifacts consume oxygen +- thermal artifacts catch fire even if they're not being held +- placed items/structures can be resized in the editor +- items in the inventory can be swapped between slots by dragging them on top of each other +- slower underwater scooters +- fixed pressure building up in enclosed rooms full of water, even if there were no hull breaches +- an indicator which shows the direction of the sub when spectating +- fixed crashing when loading a submarine with no hulls + --------------------------------------------------------------------------------------------------------- v0.3.3.1 --------------------------------------------------------------------------------------------------------- diff --git a/Subsurface_Solution.v12.suo b/Subsurface_Solution.v12.suo index 9461ffab3..96beba821 100644 Binary files a/Subsurface_Solution.v12.suo and b/Subsurface_Solution.v12.suo differ