diff --git a/Subsurface/Source/GUI/GUIListBox.cs b/Subsurface/Source/GUI/GUIListBox.cs index 81fc0f2b2..bf8942282 100644 --- a/Subsurface/Source/GUI/GUIListBox.cs +++ b/Subsurface/Source/GUI/GUIListBox.cs @@ -207,31 +207,7 @@ namespace Barotrauma { y += child.Rect.Height + spacing; } - - - if (scrollBar.IsHorizontal) - { - if (child.Rect.Right < rect.X) continue; - if (child.Rect.Right > rect.Right) break; - - if (child.Rect.X < rect.X && child.Rect.Right >= rect.X) - { - x = rect.X; - continue; - } - } - else - { - if (child.Rect.Y + child.Rect.Height < rect.Y) continue; - if (child.Rect.Y + child.Rect.Height > rect.Y + rect.Height) break; - - if (child.Rect.Y < rect.Y && child.Rect.Y + child.Rect.Height >= rect.Y) - { - y = rect.Y; - continue; - } - } - + if (deltaTime>0.0f) child.Update(deltaTime); if (enabled && child.CanBeFocused && (MouseOn == this || (MouseOn != null && this.IsParentOf(MouseOn))) && child.Rect.Contains(PlayerInput.MousePosition)) @@ -407,6 +383,8 @@ namespace Barotrauma if (!scrollBarHidden) scrollBar.Draw(spriteBatch); + GameMain.CurrGraphicsDevice.ScissorRectangle = frame.Rect; + int lastVisible = 0; for (int i = 0; i < children.Count; i++) { @@ -422,6 +400,8 @@ namespace Barotrauma lastVisible = i; child.Draw(spriteBatch); } + + GameMain.CurrGraphicsDevice.ScissorRectangle = new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight); } private bool IsChildVisible(GUIComponent child) @@ -431,22 +411,12 @@ namespace Barotrauma if (scrollBar.IsHorizontal) { if (child.Rect.Right < rect.X) return false; - if (child.Rect.Right > rect.Right) return false; - - if (child.Rect.X < rect.X && child.Rect.Right >= rect.X) - { - return false; - } + if (child.Rect.X > rect.Right) return false; } else { - if (child.Rect.Y + child.Rect.Height < rect.Y) return false; - if (child.Rect.Y + child.Rect.Height > rect.Y + rect.Height) return false; - - if (child.Rect.Y < rect.Y && child.Rect.Y + child.Rect.Height >= rect.Y) - { - return false; - } + if (child.Rect.Bottom < rect.Y) return false; + if (child.Rect.Y > rect.Bottom) return false; } return true; diff --git a/Subsurface/Source/GUI/GUITextBlock.cs b/Subsurface/Source/GUI/GUITextBlock.cs index 091cd0617..121ec6650 100644 --- a/Subsurface/Source/GUI/GUITextBlock.cs +++ b/Subsurface/Source/GUI/GUITextBlock.cs @@ -26,6 +26,9 @@ namespace Barotrauma public bool Wrap; + private bool overflowClipActive; + public bool OverflowClip; + private float textDepth; public override Vector4 Padding @@ -84,13 +87,7 @@ namespace Barotrauma get { return textDepth; } set { textDepth = MathHelper.Clamp(value, 0.0f, 1.0f); } } - - public bool LimitText - { - get; - set; - } - + public Vector2 TextPos { get { return textPos; } @@ -157,8 +154,8 @@ namespace Barotrauma } - public GUITextBlock(Rectangle rect, string text, Color? color, Color? textColor, Alignment alignment, Alignment textAlignment = Alignment.Left, string style = null, GUIComponent parent = null, bool wrap = false) - : this (rect, text, style, alignment, textAlignment, parent, wrap, null) + public GUITextBlock(Rectangle rect, string text, Color? color, Color? textColor, Alignment alignment, Alignment textAlignment = Alignment.Left, string style = null, GUIComponent parent = null, bool wrap = false, ScalableFont font = null) + : this (rect, text, style, alignment, textAlignment, parent, wrap, font) { if (color != null) this.color = (Color)color; if (textColor != null) this.textColor = (Color)textColor; @@ -198,32 +195,29 @@ namespace Barotrauma { if (text == null) return; + overflowClipActive = false; + wrappedText = text; - Vector2 size = MeasureText(text); + Vector2 size = MeasureText(text); if (Wrap && rect.Width > 0) { wrappedText = ToolBox.WrapText(text, rect.Width - padding.X - padding.Z, Font, textScale); - - Vector2 newSize = MeasureText(wrappedText); - - size = newSize; + size = MeasureText(wrappedText); } - - if (LimitText && text.Length>1 && size.Y > rect.Height) + else if (OverflowClip) { - string[] lines = text.Split('\n'); - text = string.Join("\n", lines, 0, lines.Length-1); + overflowClipActive = size.X > rect.Width; } - + textPos = new Vector2(rect.Width / 2.0f, rect.Height / 2.0f); origin = size * 0.5f; - if (textAlignment.HasFlag(Alignment.Left)) + if (textAlignment.HasFlag(Alignment.Left) && !overflowClipActive) origin.X += (rect.Width / 2.0f - padding.X) - size.X / 2; - if (textAlignment.HasFlag(Alignment.Right)) + if (textAlignment.HasFlag(Alignment.Right) || overflowClipActive) origin.X -= (rect.Width / 2.0f - padding.Z) - size.X / 2; if (textAlignment.HasFlag(Alignment.Top)) @@ -253,7 +247,7 @@ namespace Barotrauma private Vector2 MeasureText(string text) { - if (Font==null) return Vector2.Zero; + if (Font == null) return Vector2.Zero; Vector2 size = Vector2.Zero; while (size == Vector2.Zero) @@ -280,13 +274,13 @@ namespace Barotrauma Rectangle drawRect = rect; if (offset != Vector2.Zero) drawRect.Location += offset.ToPoint(); - - //if (currColor.A * currColor.A > 0.0f) GUI.DrawRectangle(spriteBatch, rect, currColor * (currColor.A / 255.0f), true); - + base.Draw(spriteBatch); if (TextGetter != null) Text = TextGetter(); + if (overflowClipActive) GameMain.CurrGraphicsDevice.ScissorRectangle = rect; + if (!string.IsNullOrEmpty(text)) { Font.DrawString(spriteBatch, @@ -297,6 +291,8 @@ namespace Barotrauma SpriteEffects.None, textDepth); } + if (overflowClipActive) GameMain.CurrGraphicsDevice.ScissorRectangle = new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight); + DrawChildren(spriteBatch); if (OutlineColor.A * currColor.A > 0.0f) GUI.DrawRectangle(spriteBatch, rect, OutlineColor * (currColor.A / 255.0f), false); diff --git a/Subsurface/Source/GUI/GUITextBox.cs b/Subsurface/Source/GUI/GUITextBox.cs index 2390cb7d7..2c89b42e3 100644 --- a/Subsurface/Source/GUI/GUITextBox.cs +++ b/Subsurface/Source/GUI/GUITextBox.cs @@ -27,6 +27,8 @@ namespace Barotrauma public OnTextChangedHandler OnTextChanged; public bool CaretEnabled; + + private int? maxTextWidth; public GUITextBlock.TextGetterHandler TextGetter { @@ -40,12 +42,17 @@ namespace Barotrauma set { textBlock.Wrap = value; } } - public bool LimitText + public int? MaxTextWidth { - get { return textBlock.LimitText; } - set { textBlock.LimitText = value; } + get { return maxTextWidth; } + set + { + textBlock.OverflowClip = value != null && (int)value > textBlock.Rect.Width - textBlock.Padding.X - textBlock.Padding.Z; + + maxTextWidth = value; + } } - + public bool Enabled { get; @@ -118,7 +125,7 @@ namespace Barotrauma } } - public String Text + public string Text { get { @@ -126,28 +133,22 @@ namespace Barotrauma } set { + if (textBlock.Text == value) return; + textBlock.Text = value; if (textBlock.Text == null) textBlock.Text = ""; if (textBlock.Text != "") { - /*//if you attempt to display a Character that is not in your font - //you will get an exception, so we filter the characters - //remove the filtering if you're using a default Character in your spritefont - String filtered = ""; - foreach (char c in value) + if (!Wrap) { - if (Font.Characters.Contains(c)) filtered += c; - } + int maxWidth = MaxTextWidth == null ? (int)(textBlock.Rect.Width - textBlock.Padding.X - textBlock.Padding.Z) : (int)MaxTextWidth; - textBlock.Text = filtered;*/ - - if (!Wrap && Font.MeasureString(textBlock.Text).X > rect.Width) - { - //ensure that text cannot be larger than the box - Text = textBlock.Text.Substring(0, textBlock.Text.Length - 1); + if (Font.MeasureString(textBlock.Text).X > maxWidth) + { + Text = textBlock.Text.Substring(0, textBlock.Text.Length - 1); + } } - } } } @@ -178,8 +179,9 @@ namespace Barotrauma if (parent != null) parent.AddChild(this); - textBlock = new GUITextBlock(new Rectangle(0,0,0,0), "", color, textColor, textAlignment, style, this); + textBlock = new GUITextBlock(new Rectangle(0,0,0,0), "", color, textColor, textAlignment, style, this); + Font = GUI.Font; GUI.Style.Apply(textBlock, style == "" ? "GUITextBox" : style); diff --git a/Subsurface/Source/GameMain.cs b/Subsurface/Source/GameMain.cs index 78fc56525..4ed6562ce 100644 --- a/Subsurface/Source/GameMain.cs +++ b/Subsurface/Source/GameMain.cs @@ -104,7 +104,16 @@ namespace Barotrauma { get { return NetworkMember as GameClient; } } + + public static RasterizerState ScissorTestEnable + { + get; + private set; + } + /// + /// Total seconds elapsed after startup + /// public double TotalElapsedTime { get; @@ -179,6 +188,8 @@ namespace Barotrauma CurrGraphicsDevice = GraphicsDevice; + ScissorTestEnable = new RasterizerState() { ScissorTestEnable = true }; + Hyper.ComponentModel.HyperTypeDescriptionProvider.Add(typeof(Character)); Hyper.ComponentModel.HyperTypeDescriptionProvider.Add(typeof(Item)); Hyper.ComponentModel.HyperTypeDescriptionProvider.Add(typeof(Items.Components.ItemComponent)); diff --git a/Subsurface/Source/Networking/ChatMessage.cs b/Subsurface/Source/Networking/ChatMessage.cs index 47a155e0b..57696c76f 100644 --- a/Subsurface/Source/Networking/ChatMessage.cs +++ b/Subsurface/Source/Networking/ChatMessage.cs @@ -2,8 +2,6 @@ using Lidgren.Network; using Microsoft.Xna.Framework; using System; -using System.Collections.Generic; -using System.Linq; using System.Text; namespace Barotrauma.Networking @@ -17,15 +15,15 @@ namespace Barotrauma.Networking class ChatMessage { public const float SpeakRange = 2000.0f; - + public static Color[] MessageColor = - { - Color.White, //default - Color.Red, //error + { + new Color(125, 140, 153), //default + new Color(204, 74, 78), //error new Color(63, 72, 204), //dead - Color.LightGreen, //server - Color.Yellow, //radio - new Color(153, 217, 234) //private + new Color(157, 225, 160), //server + new Color(148, 230, 7), //radio + new Color(228, 199, 27) //private }; public readonly string Text; diff --git a/Subsurface/Source/Networking/NetworkMember.cs b/Subsurface/Source/Networking/NetworkMember.cs index 57697573f..74c558539 100644 --- a/Subsurface/Source/Networking/NetworkMember.cs +++ b/Subsurface/Source/Networking/NetworkMember.cs @@ -158,6 +158,7 @@ namespace Barotrauma.Networking new Rectangle(chatBox.Rect.X, chatBox.Rect.Y + chatBox.Rect.Height + 20, chatBox.Rect.Width, 25), Color.White * 0.5f, Color.Black, Alignment.TopLeft, Alignment.Left, "", inGameHUD); chatMsgBox.Font = GUI.SmallFont; + chatMsgBox.MaxTextWidth = chatBox.Rect.Width * 2; chatMsgBox.Padding = Vector4.Zero; chatMsgBox.OnEnterPressed = EnterChatMessage; chatMsgBox.OnTextChanged = TypingChatMessage; @@ -247,10 +248,9 @@ namespace Barotrauma.Networking displayedText = message.SenderName + ": " + displayedText; } - GUITextBlock msg = new GUITextBlock(new Rectangle(0, 0, chatBox.Rect.Width, 0), displayedText, + GUITextBlock msg = new GUITextBlock(new Rectangle(0, 0, chatBox.Rect.Width - 40, 0), displayedText, ((chatBox.CountChildren % 2) == 0) ? Color.Transparent : Color.Black * 0.1f, message.Color, - Alignment.Left, null, null, true); - msg.Font = GUI.SmallFont; + Alignment.Left, Alignment.TopLeft, "", null, true, GUI.SmallFont); msg.UserData = message.SenderName; msg.Padding = new Vector4(20.0f, 0, 0, 0); diff --git a/Subsurface/Source/Networking/ServerLog.cs b/Subsurface/Source/Networking/ServerLog.cs index bcb15c838..2c0df9748 100644 --- a/Subsurface/Source/Networking/ServerLog.cs +++ b/Subsurface/Source/Networking/ServerLog.cs @@ -59,21 +59,21 @@ namespace Barotrauma.Networking { LogFrame = new GUIFrame(new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.Black * 0.5f); - GUIFrame innerFrame = new GUIFrame(new Rectangle(0,0,400, 400), null, Alignment.Center, "", LogFrame); - innerFrame.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f); + GUIFrame innerFrame = new GUIFrame(new Rectangle(0, 0, 500, 400), null, Alignment.Center, "", LogFrame); + innerFrame.Padding = new Vector4(10.0f, 20.0f, 10.0f, 20.0f); - new GUITextBlock(new Rectangle(-200,0,100,15), "Filter", "", Alignment.TopRight, Alignment.TopRight, innerFrame, false, GUI.SmallFont); + new GUITextBlock(new Rectangle(-200, 0, 100, 15), "Filter", "", Alignment.TopRight, Alignment.TopRight, innerFrame, false, GUI.SmallFont); - GUITextBox searchBox = new GUITextBox(new Rectangle(-20,0,180,15), Alignment.TopRight, "", innerFrame); + GUITextBox searchBox = new GUITextBox(new Rectangle(-20, 0, 180, 15), Alignment.TopRight, "", innerFrame); searchBox.Font = GUI.SmallFont; searchBox.OnTextChanged = FilterMessages; GUIComponent.KeyboardDispatcher.Subscriber = searchBox; - var clearButton = new GUIButton(new Rectangle(0,0,15,15), "x", Alignment.TopRight, "", innerFrame); + var clearButton = new GUIButton(new Rectangle(0, 0, 15, 15), "x", Alignment.TopRight, "", innerFrame); clearButton.OnClicked = ClearFilter; clearButton.UserData = searchBox; - listBox = new GUIListBox(new Rectangle(0,20,0,335), "", innerFrame); + listBox = new GUIListBox(new Rectangle(0, 30, 0, 310), "", innerFrame); var currLines = lines.ToList(); diff --git a/Subsurface/Source/Screens/EditCharacterScreen.cs b/Subsurface/Source/Screens/EditCharacterScreen.cs index d6a10e1ed..1b213b23b 100644 --- a/Subsurface/Source/Screens/EditCharacterScreen.cs +++ b/Subsurface/Source/Screens/EditCharacterScreen.cs @@ -145,7 +145,7 @@ namespace Barotrauma //-------------------- HUD ----------------------------- - spriteBatch.Begin(); + spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, GameMain.ScissorTestEnable); GUIpanel.Draw(spriteBatch); diff --git a/Subsurface/Source/Screens/EditMapScreen.cs b/Subsurface/Source/Screens/EditMapScreen.cs index 22524bbb2..3ca4cf2fd 100644 --- a/Subsurface/Source/Screens/EditMapScreen.cs +++ b/Subsurface/Source/Screens/EditMapScreen.cs @@ -193,10 +193,10 @@ namespace Barotrauma var catButton = new GUIButton(new Rectangle(0, y, 0, 20), category.ToString(), Alignment.Left, "", leftPanel); catButton.UserData = i; catButton.OnClicked = SelectTab; - y+=25; + y += 25; GUItabs[i] = new GUIFrame(new Rectangle(GameMain.GraphicsWidth / 2 - width / 2, GameMain.GraphicsHeight / 2 - height / 2, width, height), ""); - GUItabs[i].Padding = new Vector4(10.0f, 30.0f, 10.0f, 10.0f); + GUItabs[i].Padding = new Vector4(10.0f, 30.0f, 10.0f, 20.0f); new GUITextBlock(new Rectangle(-200, 0, 100, 15), "Filter", "", Alignment.TopRight, Alignment.CenterRight, GUItabs[i], false, GUI.SmallFont); @@ -1103,7 +1103,7 @@ namespace Barotrauma //-------------------- HUD ----------------------------- - spriteBatch.Begin(); + spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, GameMain.ScissorTestEnable); if (Submarine.MainSub != null) { diff --git a/Subsurface/Source/Screens/GameScreen.cs b/Subsurface/Source/Screens/GameScreen.cs index b351f7461..51773d304 100644 --- a/Subsurface/Source/Screens/GameScreen.cs +++ b/Subsurface/Source/Screens/GameScreen.cs @@ -201,7 +201,7 @@ namespace Barotrauma DrawMap(graphics, spriteBatch); - spriteBatch.Begin(); + spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, GameMain.ScissorTestEnable); if (Character.Controlled != null && Character.Controlled.SelectedConstruction != null) { diff --git a/Subsurface/Source/Screens/LobbyScreen.cs b/Subsurface/Source/Screens/LobbyScreen.cs index 5e6e29208..f94dbdeb1 100644 --- a/Subsurface/Source/Screens/LobbyScreen.cs +++ b/Subsurface/Source/Screens/LobbyScreen.cs @@ -369,10 +369,8 @@ namespace Barotrauma } graphics.Clear(Color.Black); - - //GameMain.GameScreen.DrawMap(graphics, spriteBatch); - - spriteBatch.Begin(); + + spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, GameMain.ScissorTestEnable); Sprite backGround = GameMain.GameSession.Map.CurrentLocation.Type.Background; spriteBatch.Draw(backGround.Texture, Vector2.Zero, null, Color.White, 0.0f, Vector2.Zero, diff --git a/Subsurface/Source/Screens/MainMenuScreen.cs b/Subsurface/Source/Screens/MainMenuScreen.cs index 688ce7944..98210df3e 100644 --- a/Subsurface/Source/Screens/MainMenuScreen.cs +++ b/Subsurface/Source/Screens/MainMenuScreen.cs @@ -500,8 +500,8 @@ namespace Barotrauma GameMain.TitleScreen.Draw(spriteBatch, graphics, (float)deltaTime); //Game1.GameScreen.DrawMap(graphics, spriteBatch); - - spriteBatch.Begin(0, BlendState.AlphaBlend); + + spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, GameMain.ScissorTestEnable); buttonsTab.Draw(spriteBatch); if (selectedTab>0) menuTabs[(int)selectedTab].Draw(spriteBatch); diff --git a/Subsurface/Source/Screens/NetLobbyScreen.cs b/Subsurface/Source/Screens/NetLobbyScreen.cs index e8b894552..9d5ab90ff 100644 --- a/Subsurface/Source/Screens/NetLobbyScreen.cs +++ b/Subsurface/Source/Screens/NetLobbyScreen.cs @@ -3,9 +3,6 @@ using Lidgren.Network; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Barotrauma.Networking; -using FarseerPhysics; -using FarseerPhysics.Factories; -using FarseerPhysics.Dynamics; using System.IO; using System.Linq; using System.Collections.Generic; @@ -198,6 +195,7 @@ namespace Barotrauma chatBox = new GUIListBox(new Rectangle(0,0,0,chatFrame.Rect.Height-80), Color.White, "", chatFrame); textBox = new GUITextBox(new Rectangle(0, 25, 0, 25), Alignment.Bottom, "", chatFrame); + textBox.MaxTextWidth = textBox.Rect.Width * 2; textBox.Font = GUI.SmallFont; //player info panel ------------------------------------------------------------ @@ -1015,7 +1013,7 @@ namespace Barotrauma { graphics.Clear(Color.Black); - spriteBatch.Begin(); + spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, GameMain.ScissorTestEnable); if (backgroundSprite!=null) { @@ -1041,16 +1039,15 @@ namespace Barotrauma { float prevSize = chatBox.BarSize; - while (chatBox.CountChildren>20) + while (chatBox.CountChildren > 20) { chatBox.RemoveChild(chatBox.children[1]); } - - GUITextBlock msg = new GUITextBlock(new Rectangle(0, 0, chatBox.Rect.Width, 0), + + GUITextBlock msg = new GUITextBlock(new Rectangle(0, 0, chatBox.Rect.Width-20, 0), message.TextWithSender, ((chatBox.CountChildren % 2) == 0) ? Color.Transparent : Color.Black*0.1f, message.Color, - Alignment.Left, "", null, true); - msg.Font = GUI.SmallFont; + Alignment.Left, Alignment.TopLeft, "", null, true, GUI.SmallFont); msg.UserData = message; msg.CanBeFocused = false; diff --git a/Subsurface/Source/Screens/ServerListScreen.cs b/Subsurface/Source/Screens/ServerListScreen.cs index 52d6983f9..8811f13e9 100644 --- a/Subsurface/Source/Screens/ServerListScreen.cs +++ b/Subsurface/Source/Screens/ServerListScreen.cs @@ -322,7 +322,7 @@ namespace Barotrauma GameMain.TitleScreen.DrawLoadingText = false; GameMain.TitleScreen.Draw(spriteBatch, graphics, (float)deltaTime); - spriteBatch.Begin(); + spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, GameMain.ScissorTestEnable); menu.Draw(spriteBatch); diff --git a/Subsurface/Submarines/Aegir Mark III.sub b/Subsurface/Submarines/Aegir Mark III.sub index da7dc9ada..d595d2975 100644 Binary files a/Subsurface/Submarines/Aegir Mark III.sub and b/Subsurface/Submarines/Aegir Mark III.sub differ diff --git a/Subsurface/Submarines/Nehalennia.sub b/Subsurface/Submarines/Nehalennia.sub index 512b0e158..d21d7b160 100644 Binary files a/Subsurface/Submarines/Nehalennia.sub and b/Subsurface/Submarines/Nehalennia.sub differ diff --git a/Subsurface/Submarines/Vellamo.sub b/Subsurface/Submarines/Vellamo.sub index 90cb4f5a0..841320461 100644 Binary files a/Subsurface/Submarines/Vellamo.sub and b/Subsurface/Submarines/Vellamo.sub differ