diff --git a/Subsurface/Source/GUI/GUIListBox.cs b/Subsurface/Source/GUI/GUIListBox.cs index fe83cf11c..36a6e7b0c 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)) @@ -415,6 +391,8 @@ namespace Barotrauma if (!scrollBarHidden) scrollBar.Draw(spriteBatch); + GameMain.CurrGraphicsDevice.ScissorRectangle = frame.Rect; + int lastVisible = 0; for (int i = 0; i < children.Count; i++) { @@ -430,6 +408,8 @@ namespace Barotrauma lastVisible = i; child.Draw(spriteBatch); } + + GameMain.CurrGraphicsDevice.ScissorRectangle = new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight); } private bool IsChildVisible(GUIComponent child) @@ -439,22 +419,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 05a2c85d2..ecbe20031 100644 --- a/Subsurface/Source/GUI/GUITextBlock.cs +++ b/Subsurface/Source/GUI/GUITextBlock.cs @@ -26,6 +26,9 @@ namespace Barotrauma public bool Wrap; + private bool overflowScrollActive; + public bool OverflowScroll; + 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; + overflowScrollActive = 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 (OverflowScroll) { - string[] lines = text.Split('\n'); - text = string.Join("\n", lines, 0, lines.Length-1); + overflowScrollActive = 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) && !overflowScrollActive) origin.X += (rect.Width / 2.0f - padding.X) - size.X / 2; - if (textAlignment.HasFlag(Alignment.Right)) + if (textAlignment.HasFlag(Alignment.Right) || overflowScrollActive) 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 (overflowScrollActive) GameMain.CurrGraphicsDevice.ScissorRectangle = rect; + if (!string.IsNullOrEmpty(text)) { Font.DrawString(spriteBatch, @@ -297,6 +291,8 @@ namespace Barotrauma SpriteEffects.None, textDepth); } + if (overflowScrollActive) 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/GameMain.cs b/Subsurface/Source/GameMain.cs index 8b64febd1..4cb9f2492 100644 --- a/Subsurface/Source/GameMain.cs +++ b/Subsurface/Source/GameMain.cs @@ -105,6 +105,12 @@ namespace Barotrauma get { return NetworkMember as GameClient; } } + public static RasterizerState ScissorTestEnable + { + get; + private set; + } + /// /// Total seconds elapsed after startup /// @@ -179,6 +185,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/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 0c3285fd8..92467963d 100644 --- a/Subsurface/Source/Screens/EditMapScreen.cs +++ b/Subsurface/Source/Screens/EditMapScreen.cs @@ -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 d6685f0ab..594aa19a1 100644 --- a/Subsurface/Source/Screens/GameScreen.cs +++ b/Subsurface/Source/Screens/GameScreen.cs @@ -199,7 +199,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 5d36ba8f5..35431b920 100644 --- a/Subsurface/Source/Screens/MainMenuScreen.cs +++ b/Subsurface/Source/Screens/MainMenuScreen.cs @@ -499,8 +499,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 bebdfabe7..401bdd02b 100644 --- a/Subsurface/Source/Screens/NetLobbyScreen.cs +++ b/Subsurface/Source/Screens/NetLobbyScreen.cs @@ -1005,7 +1005,7 @@ namespace Barotrauma { graphics.Clear(Color.Black); - spriteBatch.Begin(); + spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, GameMain.ScissorTestEnable); if (backgroundSprite!=null) { diff --git a/Subsurface/Source/Screens/ServerListScreen.cs b/Subsurface/Source/Screens/ServerListScreen.cs index 8d66d0cc9..1919ae3fa 100644 --- a/Subsurface/Source/Screens/ServerListScreen.cs +++ b/Subsurface/Source/Screens/ServerListScreen.cs @@ -353,12 +353,10 @@ 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); - - //if (previewPlayer!=null) previewPlayer.Draw(spriteBatch); - + GUI.Draw((float)deltaTime, spriteBatch, null); spriteBatch.End();