diff --git a/Barotrauma/BarotraumaClient/Source/Map/MapEntity.cs b/Barotrauma/BarotraumaClient/Source/Map/MapEntity.cs index a49b60add..4af2b17ec 100644 --- a/Barotrauma/BarotraumaClient/Source/Map/MapEntity.cs +++ b/Barotrauma/BarotraumaClient/Source/Map/MapEntity.cs @@ -505,7 +505,7 @@ namespace Barotrauma foreach (MapEntity e in selectedList) { e.prefab?.DrawPlacing(spriteBatch, - new Rectangle(e.WorldRect.Location + new Point((int)moveAmount.X, (int)-moveAmount.Y), e.WorldRect.Size)); + new Rectangle(e.WorldRect.Location + new Point((int)moveAmount.X, (int)-moveAmount.Y), e.WorldRect.Size), e.Scale); GUI.DrawRectangle(spriteBatch, new Vector2(e.WorldRect.X, -e.WorldRect.Y) + moveAmount, new Vector2(e.rect.Width, e.rect.Height), diff --git a/Barotrauma/BarotraumaClient/Source/Map/Structure.cs b/Barotrauma/BarotraumaClient/Source/Map/Structure.cs index 6bf1f97f8..b1ea776e0 100644 --- a/Barotrauma/BarotraumaClient/Source/Map/Structure.cs +++ b/Barotrauma/BarotraumaClient/Source/Map/Structure.cs @@ -41,13 +41,7 @@ namespace Barotrauma MathHelper.Clamp(value.Y, 0.01f, 10)); } } - - // Only for testing in the debug build. Not saved. -#if DEBUG - [Editable, Serialize(true, false)] -#endif - public bool DrawTiled { get; protected set; } = true; - + protected Vector2 textureOffset = Vector2.Zero; [Editable(MinValueFloat = -1000f, MaxValueFloat = 1000f, ValueStep = 10f), Serialize("0.0, 0.0", true)] public Vector2 TextureOffset @@ -101,7 +95,7 @@ namespace Barotrauma editingHUD = new GUIFrame(new RectTransform(new Vector2(0.3f, 0.25f), GUI.Canvas, Anchor.CenterRight) { MinSize = new Point(400, 0) }) { UserData = this }; GUIListBox listBox = new GUIListBox(new RectTransform(new Vector2(0.95f, 0.8f), editingHUD.RectTransform, Anchor.Center), style: null); var editor = new SerializableEntityEditor(listBox.Content.RectTransform, this, inGame, showName: true, elementHeight: 20); - + var buttonContainer = new GUILayoutGroup(new RectTransform(new Point(listBox.Content.Rect.Width, 20)), isHorizontal: true) { Stretch = true, @@ -234,62 +228,35 @@ namespace Barotrauma } dropShadowOffset.Y = -dropShadowOffset.Y; } + + SpriteEffects oldEffects = Prefab.BackgroundSprite.effects; + Prefab.BackgroundSprite.effects ^= SpriteEffects; - if (DrawTiled) + Point backGroundOffset = new Point( + MathUtils.PositiveModulo((int)-textureOffset.X, Prefab.BackgroundSprite.SourceRect.Width), + MathUtils.PositiveModulo((int)-textureOffset.Y, Prefab.BackgroundSprite.SourceRect.Height)); + + Prefab.BackgroundSprite.DrawTiled( + spriteBatch, + new Vector2(rect.X + drawOffset.X, -(rect.Y + drawOffset.Y)), + new Vector2(rect.Width, rect.Height), + color: color, + textureScale: TextureScale * Scale, + startOffset: backGroundOffset); + + if (UseDropShadow) { - SpriteEffects oldEffects = Prefab.BackgroundSprite.effects; - Prefab.BackgroundSprite.effects ^= SpriteEffects; - - Point backGroundOffset = new Point( - MathUtils.PositiveModulo((int)-textureOffset.X, Prefab.BackgroundSprite.SourceRect.Width), - MathUtils.PositiveModulo((int)-textureOffset.Y, Prefab.BackgroundSprite.SourceRect.Height)); - Prefab.BackgroundSprite.DrawTiled( spriteBatch, - new Vector2(rect.X + drawOffset.X, -(rect.Y + drawOffset.Y)), + new Vector2(rect.X + drawOffset.X, -(rect.Y + drawOffset.Y)) + dropShadowOffset, new Vector2(rect.Width, rect.Height), - color: color, + color: Color.Black * 0.5f, textureScale: TextureScale * Scale, - startOffset: backGroundOffset); - - if (UseDropShadow) - { - Prefab.BackgroundSprite.DrawTiled( - spriteBatch, - new Vector2(rect.X + drawOffset.X, -(rect.Y + drawOffset.Y)) + dropShadowOffset, - new Vector2(rect.Width, rect.Height), - color: Color.Black * 0.5f, - textureScale: TextureScale * Scale, - startOffset: backGroundOffset, - depth: (depth + Prefab.BackgroundSprite.Depth) / 2.0f); - } - - Prefab.BackgroundSprite.effects = oldEffects; + startOffset: backGroundOffset, + depth: (depth + Prefab.BackgroundSprite.Depth) / 2.0f); } - else - { - Prefab.BackgroundSprite.Draw( - spriteBatch, - new Vector2(rect.X + drawOffset.X, -(rect.Y + drawOffset.Y)), - color, - Vector2.Zero, - scale: Scale, - rotate: 0, - spriteEffect: SpriteEffects); - if (UseDropShadow) - { - Prefab.BackgroundSprite.Draw( - spriteBatch, - new Vector2(rect.X + drawOffset.X, -(rect.Y + drawOffset.Y)) + dropShadowOffset, - Color.Black * 0.5f, - Vector2.Zero, - scale: Scale, - rotate: 0, - spriteEffect: SpriteEffects, - depth: (depth + Prefab.BackgroundSprite.Depth) / 2.0f); - } - } + Prefab.BackgroundSprite.effects = oldEffects; } } @@ -316,39 +283,25 @@ namespace Barotrauma Submarine.DamageEffectColor = color; } } + + Point sectionOffset = new Point( + Math.Abs(rect.Location.X - Sections[i].rect.Location.X), + Math.Abs(rect.Location.Y - Sections[i].rect.Location.Y)); - if (DrawTiled) - { - Point sectionOffset = new Point( - Math.Abs(rect.Location.X - Sections[i].rect.Location.X), - Math.Abs(rect.Location.Y - Sections[i].rect.Location.Y)); + if (FlippedX && IsHorizontal) sectionOffset.X = Sections[i].rect.Right - rect.Right; + if (FlippedY && !IsHorizontal) sectionOffset.Y = (rect.Y - rect.Height) - (Sections[i].rect.Y - Sections[i].rect.Height); - if (FlippedX && IsHorizontal) sectionOffset.X = Sections[i].rect.Right - rect.Right; - if (FlippedY && !IsHorizontal) sectionOffset.Y = (rect.Y - rect.Height) - (Sections[i].rect.Y - Sections[i].rect.Height); + sectionOffset.X += MathUtils.PositiveModulo((int)-textureOffset.X, prefab.sprite.SourceRect.Width); + sectionOffset.Y += MathUtils.PositiveModulo((int)-textureOffset.Y, prefab.sprite.SourceRect.Height); - sectionOffset.X += MathUtils.PositiveModulo((int)-textureOffset.X, prefab.sprite.SourceRect.Width); - sectionOffset.Y += MathUtils.PositiveModulo((int)-textureOffset.Y, prefab.sprite.SourceRect.Height); - - prefab.sprite.DrawTiled( - spriteBatch, - new Vector2(Sections[i].rect.X + drawOffset.X, -(Sections[i].rect.Y + drawOffset.Y)), - new Vector2(Sections[i].rect.Width, Sections[i].rect.Height), - color: color, - startOffset: sectionOffset, - depth: depth, - textureScale: TextureScale * Scale); - } - else - { - prefab.sprite.Draw( - spriteBatch, - new Vector2(rect.X + drawOffset.X, -(rect.Y + drawOffset.Y)), - color, - Vector2.Zero, - scale: Scale, - rotate: 0, - spriteEffect: SpriteEffects); - } + prefab.sprite.DrawTiled( + spriteBatch, + new Vector2(Sections[i].rect.X + drawOffset.X, -(Sections[i].rect.Y + drawOffset.Y)), + new Vector2(Sections[i].rect.Width, Sections[i].rect.Height), + color: color, + startOffset: sectionOffset, + depth: depth, + textureScale: TextureScale * Scale); } prefab.sprite.effects = oldEffects; } diff --git a/Barotrauma/BarotraumaClient/Source/Screens/ServerListScreen.cs b/Barotrauma/BarotraumaClient/Source/Screens/ServerListScreen.cs index 0dad0848e..df3078f5f 100644 --- a/Barotrauma/BarotraumaClient/Source/Screens/ServerListScreen.cs +++ b/Barotrauma/BarotraumaClient/Source/Screens/ServerListScreen.cs @@ -95,19 +95,6 @@ namespace Barotrauma filterIncompatible = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.27f), tickBoxHolder.RectTransform), TextManager.Get("FilterIncompatibleServers")); filterIncompatible.OnSelected += (tickBox) => { FilterServers(); return true; }; - var filterHolder = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.5f), leftColumn.RectTransform)) { RelativeSpacing = 0.05f }; - - new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), filterHolder.RectTransform), TextManager.Get("FilterServers")); - searchBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 0.13f), filterHolder.RectTransform), ""); - - var tickBoxHolder = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.5f), filterHolder.RectTransform)); - - searchBox.OnTextChanged += (txtBox, txt) => { FilterServers(); return true; }; - filterPassword = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.27f), tickBoxHolder.RectTransform), TextManager.Get("FilterPassword")); - filterPassword.OnSelected += (tickBox) => { FilterServers(); return true; }; - filterIncompatible = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.27f), tickBoxHolder.RectTransform), TextManager.Get("FilterIncompatibleServers")); - filterIncompatible.OnSelected += (tickBox) => { FilterServers(); return true; }; - filterFull = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.27f), tickBoxHolder.RectTransform), TextManager.Get("FilterFullServers")); filterFull.OnSelected += (tickBox) => { FilterServers(); return true; }; filterEmpty = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.27f), tickBoxHolder.RectTransform), TextManager.Get("FilterEmptyServers")); @@ -165,6 +152,58 @@ namespace Barotrauma Enabled = false }; + //------------------------------------------------------------------------------------- + //right column + //------------------------------------------------------------------------------------- + + var rightColumn = new GUILayoutGroup(new RectTransform(new Vector2(1.0f - leftColumn.RectTransform.RelativeSize.X - 0.017f, 1.0f), + paddedFrame.RectTransform, Anchor.CenterRight)) + { + RelativeSpacing = 0.02f, + Stretch = true + }; + + var serverListHolder = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 1.0f), rightColumn.RectTransform)) { Stretch = true, RelativeSpacing = 0.02f }; + + serverList = new GUIListBox(new RectTransform(new Vector2(1.0f, 1.0f), serverListHolder.RectTransform, Anchor.Center)) + { + OnSelected = (btn, obj) => { + ServerInfo serverInfo = (ServerInfo)obj; + + serverInfo.CreatePreviewWindow(serverPreview); + + return true; + } + }; + + serverList.OnSelected += SelectServer; + + serverPreview = new GUIListBox(new RectTransform(new Vector2(1.0f, 1.0f), serverListHolder.RectTransform, Anchor.Center)); + + columnRelativeWidth = new float[] { 0.04f, 0.02f, 0.044f, 0.77f, 0.02f, 0.075f, 0.06f }; + + var buttonContainer = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.075f), rightColumn.RectTransform), style: null); + + GUIButton button = new GUIButton(new RectTransform(new Vector2(0.25f, 0.9f), buttonContainer.RectTransform, Anchor.TopLeft), + TextManager.Get("Back"), style: "GUIButtonLarge") + { + OnClicked = GameMain.MainMenuScreen.ReturnToMainMenu + }; + + var refreshButton = new GUIButton(new RectTransform(new Vector2(buttonContainer.Rect.Height / (float)buttonContainer.Rect.Width, 0.9f), buttonContainer.RectTransform, Anchor.Center), + "", style: "GUIButtonRefresh") { + + ToolTip = TextManager.Get("ServerListRefresh"), + OnClicked = RefreshServers + }; + + joinButton = new GUIButton(new RectTransform(new Vector2(0.25f, 0.9f), buttonContainer.RectTransform, Anchor.TopRight), + TextManager.Get("ServerListJoin"), style: "GUIButtonLarge") + { + OnClicked = JoinServer, + Enabled = false + }; + //-------------------------------------------------------- button.SelectedColor = button.Color; @@ -207,6 +246,18 @@ namespace Barotrauma UserData = "noresults" }; } + + return true; + } + + private bool RefreshJoinButtonState(GUIComponent component, object obj) + { + if (obj == null || waitingForRefresh) return false; + + if (!string.IsNullOrWhiteSpace(clientNameBox.Text) && !string.IsNullOrWhiteSpace(ipBox.Text)) + { + joinButton.Enabled = true; + } else { joinButton.Enabled = false; diff --git a/Barotrauma/BarotraumaShared/Source/Map/Hull.cs b/Barotrauma/BarotraumaShared/Source/Map/Hull.cs index b4490cfe6..02219e083 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Hull.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Hull.cs @@ -166,6 +166,25 @@ namespace Barotrauma } } + public string DisplayName + { + get; + private set; + } + + private string roomName; + [Editable, Serialize("", true, translationTextTag: "RoomName.")] + public string RoomName + { + get { return roomName; } + set + { + if (roomName == value) { return; } + roomName = value; + DisplayName = TextManager.Get(roomName, returnNull: true) ?? roomName; + } + } + public override Rectangle Rect { get diff --git a/Barotrauma/BarotraumaShared/Source/Map/MapEntity.cs b/Barotrauma/BarotraumaShared/Source/Map/MapEntity.cs index 569b5ccff..858b7bcca 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/MapEntity.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/MapEntity.cs @@ -520,15 +520,9 @@ namespace Barotrauma } } } - - // The value should always be copied from the prefab. Editing is enabled only for testing the scale in the sub editor (changes are not saved). - -#if DEBUG + [Serialize(1f, false), Editable(0.1f, 10f, DecimalCount = 3, ValueStep = 0.1f)] -#else - [Serialize(1f, false)] -#endif - public float Scale { get; set; } = 1; + public virtual float Scale { get; set; } = 1; #endregion } } diff --git a/Barotrauma/BarotraumaShared/Source/Map/Structure.cs b/Barotrauma/BarotraumaShared/Source/Map/Structure.cs index 3f0889562..022ce6b33 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Structure.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Structure.cs @@ -159,6 +159,32 @@ namespace Barotrauma private set; } + private float scale = 1.0f; + public override float Scale + { + get { return scale; } + set + { + if (scale == value) { return; } + scale = MathHelper.Clamp(value, 0.1f, 10.0f); + + float relativeScale = scale / prefab.Scale; + + if (!ResizeHorizontal || !ResizeVertical) + { + int newWidth = ResizeHorizontal ? rect.Width : (int)(defaultRect.Width * relativeScale); + int newHeight = ResizeVertical ? rect.Height : (int)(defaultRect.Height * relativeScale); + Rect = new Rectangle(rect.X, rect.Y, newWidth, newHeight); + if (Sections != null) + { + UpdateSections(); + } + } + } + } + + private Rectangle defaultRect; + public override Rectangle Rect { get @@ -169,9 +195,13 @@ namespace Barotrauma { Rectangle oldRect = Rect; base.Rect = value; - if (Prefab.Body) CreateSections(); + if (Prefab.Body) + { + CreateSections(); + } else { + if (Sections == null) { return; } foreach (WallSection sec in Sections) { Rectangle secRect = sec.rect; @@ -189,11 +219,11 @@ namespace Barotrauma public float BodyWidth { - get { return Prefab.BodyWidth > 0.0f ? Prefab.BodyWidth : rect.Width; } + get { return Prefab.BodyWidth > 0.0f ? Prefab.BodyWidth * scale : rect.Width; } } public float BodyHeight { - get { return Prefab.BodyHeight > 0.0f ? Prefab.BodyHeight : rect.Height; } + get { return Prefab.BodyHeight > 0.0f ? Prefab.BodyHeight * scale : rect.Height; } } /// @@ -261,8 +291,9 @@ namespace Barotrauma public Structure(Rectangle rectangle, StructurePrefab sp, Submarine submarine) : base(sp, submarine) { - if (rectangle.Width == 0 || rectangle.Height == 0) return; System.Diagnostics.Debug.Assert(rectangle.Width > 0 && rectangle.Height > 0); + if (rectangle.Width == 0 || rectangle.Height == 0) return; + defaultRect = rectangle; rect = rectangle; #if CLIENT @@ -961,6 +992,7 @@ namespace Barotrauma private void UpdateSections() { + if (Bodies == null) return; foreach (Body b in Bodies) { GameMain.World.RemoveBody(b); @@ -1024,9 +1056,9 @@ namespace Barotrauma if (BodyWidth > 0.0f) rect.Width = (int)BodyWidth; if (BodyHeight > 0.0f) rect.Height = Math.Max((int)Math.Round(BodyHeight * (rect.Height / (float)this.rect.Height)), 1); } - if (FlippedX) diffFromCenter = -diffFromCenter; + if (FlippedX) { diffFromCenter = -diffFromCenter; } - Vector2 bodyOffset = ConvertUnits.ToSimUnits(Prefab.BodyOffset); + Vector2 bodyOffset = ConvertUnits.ToSimUnits(Prefab.BodyOffset) * scale; if (FlippedX) { bodyOffset.X = -bodyOffset.X; } if (FlippedY) { bodyOffset.Y = -bodyOffset.Y; } @@ -1046,7 +1078,8 @@ namespace Barotrauma { newBody.Position = structureCenter + bodyOffset + new Vector2( (float)Math.Cos(IsHorizontal ? -BodyRotation : MathHelper.PiOver2 - BodyRotation), - (float)Math.Sin(IsHorizontal ? -BodyRotation : MathHelper.PiOver2 - BodyRotation)) * ConvertUnits.ToSimUnits(diffFromCenter); + (float)Math.Sin(IsHorizontal ? -BodyRotation : MathHelper.PiOver2 - BodyRotation)) + * ConvertUnits.ToSimUnits(diffFromCenter); newBody.Rotation = -BodyRotation; } else @@ -1187,6 +1220,9 @@ namespace Barotrauma { XElement element = new XElement("Structure"); + int width = ResizeHorizontal ? rect.Width : defaultRect.Width; + int height = ResizeVertical ? rect.Height : defaultRect.Height; + element.Add( new XAttribute("name", prefab.Name), new XAttribute("identifier", prefab.Identifier), @@ -1194,7 +1230,7 @@ namespace Barotrauma new XAttribute("rect", (int)(rect.X - Submarine.HiddenSubPosition.X) + "," + (int)(rect.Y - Submarine.HiddenSubPosition.Y) + "," + - rect.Width + "," + rect.Height)); + width + "," + height)); if (FlippedX) element.Add(new XAttribute("flippedx", true)); if (FlippedY) element.Add(new XAttribute("flippedy", true));