diff --git a/Subsurface/Characters/HumanoidAnimController.cs b/Subsurface/Characters/HumanoidAnimController.cs index d11ea22d3..13f22e6db 100644 --- a/Subsurface/Characters/HumanoidAnimController.cs +++ b/Subsurface/Characters/HumanoidAnimController.cs @@ -48,7 +48,8 @@ namespace Subsurface } break; case Physics.CollisionPlatform: - if (IgnorePlatforms || stairs != null) return -1; + Structure platform = fixture.Body.UserData as Structure; + if (IgnorePlatforms || LowestLimb.Position.Y < platform.Rect.Y) return -1; break; case Physics.CollisionWall: break; @@ -353,7 +354,7 @@ namespace Subsurface Limb head = GetLimb(LimbType.Head); - if (currentHull != null && currentHull.Volume < currentHull.FullVolume && !head.inWater) + if (currentHull != null && (currentHull.Rect.Y - currentHull.Surface > 50.0f) && !head.inWater) { surfaceLimiter = (ConvertUnits.ToDisplayUnits(head.SimPosition.Y)-surfaceY); surfaceLimiter = Math.Max(1.0f, surfaceLimiter); @@ -399,7 +400,7 @@ namespace Subsurface movement = MathUtils.SmoothStep(movement, TargetMovement, 0.3f); //dont try to move upwards if head is already out of water - if (surfaceLimiter > 1.0f) + if (surfaceLimiter > 1.0f && TargetMovement.Y > 0.0f) { if (TargetMovement.X == 0.0f) { diff --git a/Subsurface/Characters/Limb.cs b/Subsurface/Characters/Limb.cs index 06ab52c59..6c6ce7fcf 100644 --- a/Subsurface/Characters/Limb.cs +++ b/Subsurface/Characters/Limb.cs @@ -74,6 +74,11 @@ namespace Subsurface get { return doesFlip; } } + public Vector2 Position + { + get { return ConvertUnits.ToDisplayUnits(body.Position); } + } + public Vector2 SimPosition { get { return body.Position; } diff --git a/Subsurface/Characters/Ragdoll.cs b/Subsurface/Characters/Ragdoll.cs index 281c328f5..abdc11695 100644 --- a/Subsurface/Characters/Ragdoll.cs +++ b/Subsurface/Characters/Ragdoll.cs @@ -268,11 +268,17 @@ namespace Subsurface if (ignorePlatforms) return false; //the collision is ignored if the lowest limb is under the platform - if (lowestLimb==null || lowestLimb.SimPosition.Y < f2.Body.Position.Y) return false; + if (lowestLimb==null || lowestLimb.Position.Y < structure.Rect.Y) return false; } else if (structure.StairDirection!=Direction.None) { - if (inWater || !(targetMovement.Y>Math.Abs(targetMovement.X/2.0f)) && lowestLimb.body.Position.Y < ConvertUnits.ToSimUnits(structure.Rect.Y - structure.Rect.Height) + 0.5f) + if (inWater || !(targetMovement.Y>Math.Abs(targetMovement.X/2.0f)) && lowestLimb.Position.Y < structure.Rect.Y - structure.Rect.Height + 50.0f) + { + stairs = null; + return false; + } + + if (targetMovement.Y >= 0.0f && lowestLimb.SimPosition.Y > ConvertUnits.ToSimUnits(structure.Rect.Y - Submarine.GridSize.Y * 8.0f)) { stairs = null; return false; diff --git a/Subsurface/Content/UI/style.xml b/Subsurface/Content/UI/style.xml index 53f89f74b..73b0c7357 100644 --- a/Subsurface/Content/UI/style.xml +++ b/Subsurface/Content/UI/style.xml @@ -47,11 +47,11 @@ - + 0) + if (Wrap && rect.Width>0) { - text = text.Replace("\n"," "); + //text = text.Replace("\n"," "); text = ToolBox.WrapText(text, rect.Width, Font); Vector2 newSize = MeasureText(); - Rectangle newRect = rect; + //Rectangle newRect = rect; //newRect.Width += (int)(newSize.X-size.X); - newRect.Height += (int)(newSize.Y - size.Y); + //newRect.Height += (int)(newSize.Y - size.Y); - Rect = newRect; + //Rect = newRect; size = newSize; } @@ -184,6 +186,8 @@ namespace Subsurface GUI.DrawRectangle(spriteBatch, rect, currColor*(currColor.A/255.0f), true); + base.Draw(spriteBatch); + if (TextGetter != null) text = TextGetter(); if (!string.IsNullOrEmpty(text)) diff --git a/Subsurface/GUI/GUITextBox.cs b/Subsurface/GUI/GUITextBox.cs index 3ee6794e4..00cbbda46 100644 --- a/Subsurface/GUI/GUITextBox.cs +++ b/Subsurface/GUI/GUITextBox.cs @@ -24,6 +24,12 @@ namespace Subsurface public delegate bool OnTextChangedHandler(GUITextBox textBox, string text); public OnTextChangedHandler OnTextChanged; + public bool Wrap + { + get { return textBlock.Wrap; } + set { textBlock.Wrap = value; } + } + public bool Enabled { get; @@ -74,9 +80,9 @@ namespace Subsurface textBlock.Text = filtered; - if (Font.MeasureString(textBlock.Text).X > rect.Width) + if (!Wrap && Font.MeasureString(textBlock.Text).X > rect.Width) { - //recursion to ensure that text cannot be larger than the box + //ensure that text cannot be larger than the box Text = textBlock.Text.Substring(0, textBlock.Text.Length - 1); } } @@ -111,7 +117,7 @@ namespace Subsurface if (parent != null) parent.AddChild(this); - textBlock = new GUITextBlock(new Rectangle(0,0,0,0), "", color, textColor, textAlignment, null, this); + textBlock = new GUITextBlock(new Rectangle(0,0,0,0), "", color, textColor, textAlignment, style, this); textBlock.Padding = new Vector4(10.0f, 0.0f, 10.0f, 0.0f); if (style != null) style.Apply(textBlock, this); @@ -121,6 +127,7 @@ namespace Subsurface public void Select() { + Selected = true; keyboardDispatcher.Subscriber = this; if (Clicked != null) Clicked(this); } @@ -172,7 +179,7 @@ namespace Subsurface { GUI.DrawLine(spriteBatch, new Vector2((int)caretPos.X + 2, caretPos.Y + 3), - new Vector2((int)caretPos.X + 2, caretPos.Y + rect.Height - 3), + new Vector2((int)caretPos.X + 2, caretPos.Y + Font.MeasureString(Text).Y - 3), textBlock.TextColor * (textBlock.TextColor.A / 255.0f)); } diff --git a/Subsurface/Map/Location.cs b/Subsurface/Map/Location.cs index 016cd05ea..0eb31e44d 100644 --- a/Subsurface/Map/Location.cs +++ b/Subsurface/Map/Location.cs @@ -44,7 +44,7 @@ namespace Subsurface private string RandomName(LocationType type) { string name = ToolBox.GetRandomLine("Content/Map/locationNames.txt"); - int nameFormatIndex = Rand.Int(type.NameFormats.Count); + int nameFormatIndex = Rand.Int(type.NameFormats.Count, false); return type.NameFormats[nameFormatIndex].Replace("[name]", name); } } diff --git a/Subsurface/Map/LocationType.cs b/Subsurface/Map/LocationType.cs index 877cf1c29..453e23dff 100644 --- a/Subsurface/Map/LocationType.cs +++ b/Subsurface/Map/LocationType.cs @@ -47,7 +47,7 @@ namespace Subsurface { Debug.Assert(list.Count > 0, "LocationType.list.Count == 0, you probably need to initialize LocationTypes"); - int randInt = Rand.Int(totalWeight); + int randInt = Rand.Int(totalWeight, false); foreach (LocationType type in list) { diff --git a/Subsurface/Map/Map.cs b/Subsurface/Map/Map.cs index c189bd182..e48c16ab4 100644 --- a/Subsurface/Map/Map.cs +++ b/Subsurface/Map/Map.cs @@ -64,8 +64,7 @@ namespace Subsurface iceTexture = Game1.TextureLoader.FromFile("Content/Map/iceSurface.png"); iceCraters = Game1.TextureLoader.FromFile("Content/Map/iceCraters.png"); iceCrack = Game1.TextureLoader.FromFile("Content/Map/iceCrack.png"); - - + Rand.SetSyncedSeed(this.seed); GenerateLocations(); diff --git a/Subsurface/Map/Structure.cs b/Subsurface/Map/Structure.cs index 7fd09c742..3976ade8f 100644 --- a/Subsurface/Map/Structure.cs +++ b/Subsurface/Map/Structure.cs @@ -208,7 +208,7 @@ namespace Subsurface bodies = new List(); Body newBody = BodyFactory.CreateRectangle(Game1.World, - ConvertUnits.ToSimUnits(rect.Width * Math.Sqrt(2.0) - Submarine.GridSize.X), + ConvertUnits.ToSimUnits(rect.Width * Math.Sqrt(2.0) + Submarine.GridSize.X*3.0f), ConvertUnits.ToSimUnits(10), 1.5f); @@ -218,7 +218,6 @@ namespace Subsurface (StairDirection == Direction.Right) ? -Submarine.GridSize.X*1.5f : Submarine.GridSize.X*1.5f, - Submarine.GridSize.Y*2.0f); - newBody.Position = ConvertUnits.ToSimUnits(stairPos); newBody.Rotation = (StairDirection == Direction.Right) ? MathHelper.PiOver4 : -MathHelper.PiOver4; newBody.Friction = 0.8f; @@ -228,6 +227,25 @@ namespace Subsurface newBody.UserData = this; bodies.Add(newBody); + //newBody = BodyFactory.CreateRectangle(Game1.World, + // ConvertUnits.ToSimUnits(Submarine.GridSize.X*2), + // ConvertUnits.ToSimUnits(10.0f), + // 1.5f); + + //newBody.BodyType = BodyType.Static; + ////newBody.IsSensor = true; + + //newBody.Position = ConvertUnits.ToSimUnits( + // new Vector2(Position.X + (rect.Width/2 + Submarine.GridSize.X) * ((StairDirection == Direction.Right) ? -1.0f : 1.0f), rect.Y + 5.0f)); + ////newBody.Rotation = (StairDirection == Direction.Right) ? MathHelper.PiOver4 : -MathHelper.PiOver4; + ////newBody.Friction = 0.8f; + + //newBody.CollisionCategories = Physics.CollisionStairs; + + //newBody.UserData = this; + + //bodies.Add(newBody); + } } diff --git a/Subsurface/Screens/NetLobbyScreen.cs b/Subsurface/Screens/NetLobbyScreen.cs index ec592915f..6acb63cf7 100644 --- a/Subsurface/Screens/NetLobbyScreen.cs +++ b/Subsurface/Screens/NetLobbyScreen.cs @@ -32,6 +32,7 @@ namespace Subsurface private float camAngle; public bool IsServer; + public string ServerName, ServerMessage; public Submarine SelectedMap { @@ -44,6 +45,16 @@ namespace Subsurface get { return modeList.SelectedData as GameModePreset; } } + //for guitextblock delegate + public string GetServerName() + { + return ServerName; + } + public string GetServerMessage() + { + return ServerMessage; + } + public TimeSpan GameDuration { get @@ -145,8 +156,8 @@ namespace Subsurface textBox.Select(); - new GUITextBlock(new Rectangle(0, 30, 0, 30), "Selected submarine:", GUI.style, infoFrame); - subList = new GUIListBox(new Rectangle(0, 60, 200, 200), Color.White, GUI.style, infoFrame); + new GUITextBlock(new Rectangle(0, 110, 0, 30), "Selected submarine:", GUI.style, infoFrame); + subList = new GUIListBox(new Rectangle(0, 140, 200, 200), Color.White, GUI.style, infoFrame); subList.OnSelected = SelectMap; subList.Enabled = (Game1.Server != null); @@ -169,8 +180,8 @@ namespace Subsurface return; } - new GUITextBlock(new Rectangle(220, 30, 0, 30), "Selected game mode: ", GUI.style, infoFrame); - modeList = new GUIListBox(new Rectangle(220, 60, 200, 200), GUI.style, infoFrame); + new GUITextBlock(new Rectangle(220, 110, 0, 30), "Selected game mode: ", GUI.style, infoFrame); + modeList = new GUIListBox(new Rectangle(220, 140, 200, 200), GUI.style, infoFrame); modeList.Enabled = (Game1.Server != null); foreach (GameModePreset mode in GameModePreset.list) @@ -186,29 +197,39 @@ namespace Subsurface textBlock.UserData = mode; } - GUITextBlock durationText = new GUITextBlock(new Rectangle((int)(modeList.Rect.Right + 20 - 80), 30, 100, 20), + GUITextBlock durationText = new GUITextBlock(new Rectangle((int)(modeList.Rect.Right + 20 - 80), 110, 100, 20), "Game duration: ", GUI.style, Alignment.Left, Alignment.TopLeft, infoFrame); durationText.TextGetter = DurationText; - durationBar = new GUIScrollBar(new Rectangle((int)(modeList.Rect.Right + 20 - 80), 60, 180, 20), + durationBar = new GUIScrollBar(new Rectangle((int)(modeList.Rect.Right + 20 - 80), 140, 180, 20), GUI.style, 0.1f, infoFrame); durationBar.BarSize = 0.1f; durationBar.Enabled = (Game1.Server != null); - new GUITextBlock(new Rectangle((int)(modeList.Rect.Right + 20 - 80), 100, 100, 20), + new GUITextBlock(new Rectangle((int)(modeList.Rect.Right + 20 - 80), 180, 100, 20), "Level Seed: ", GUI.style, Alignment.Left, Alignment.TopLeft, infoFrame); - seedBox = new GUITextBox(new Rectangle((int)(modeList.Rect.Right + 20 - 80), 130, 180, 20), + seedBox = new GUITextBox(new Rectangle((int)(modeList.Rect.Right + 20 - 80), 210, 180, 20), Alignment.TopLeft, GUI.style, infoFrame); seedBox.OnEnter = SelectSeed; seedBox.Enabled = (Game1.Server != null); LevelSeed = ToolBox.RandomSeed(8); + var serverName = new GUITextBlock(new Rectangle(0, 0, 200, 30), + "Server: ", GUI.style, Alignment.Left, Alignment.TopLeft, infoFrame); + serverName.TextGetter = GetServerName; + + var serverMessage = new GUITextBox(new Rectangle(0, 30, 360, 70),null,null, Alignment.TopLeft, Alignment.TopLeft, GUI.style, infoFrame); + serverMessage.Enabled = false; + serverMessage.Wrap = true; + if (IsServer && Game1.Server != null) { - GUIButton startButton = new GUIButton(new Rectangle(0, 0, 200, 30), "Start", GUI.style, infoFrame); + GUIButton startButton = new GUIButton(new Rectangle(0, 0, 200, 30), "Start", Alignment.TopRight, GUI.style, infoFrame); startButton.OnClicked = Game1.Server.StartGame; + serverMessage.Enabled = true; + //mapList.OnSelected = new GUIListBox.OnSelectedHandler(Game1.server.UpdateNetLobby); modeList.OnSelected = Game1.Server.UpdateNetLobby; durationBar.OnMoved = Game1.Server.UpdateNetLobby; @@ -517,6 +538,8 @@ namespace Subsurface msg.Write(selectedMap.Hash.Hash); } + msg.Write(ServerName); + msg.Write(modeList.SelectedIndex-1); msg.Write(durationBar.BarScroll); msg.Write(LevelSeed); @@ -538,7 +561,9 @@ namespace Subsurface string mapName = msg.ReadString(); string md5Hash = msg.ReadString(); - TrySelectMap(mapName, md5Hash); + TrySelectMap(mapName, md5Hash); + + ServerName = msg.ReadString(); //mapList.Select(msg.ReadInt32()); modeList.Select(msg.ReadInt32()); diff --git a/Subsurface/Utils/ToolBox.cs b/Subsurface/Utils/ToolBox.cs index 0d3918a26..24f412f47 100644 --- a/Subsurface/Utils/ToolBox.cs +++ b/Subsurface/Utils/ToolBox.cs @@ -256,27 +256,56 @@ namespace Subsurface .ToArray()); } - public static string WrapText(string text, float lineWidth, SpriteFont font) + public static string WrapText(string text, float lineLength, SpriteFont font) { - if (GUI.Font.MeasureString(text).X < lineWidth) return text; + if (font.MeasureString(text).X < lineLength) return text; + + string[] words = text.Split(' ', '\n'); - string[] words = text.Split(' '); StringBuilder wrappedText = new StringBuilder(); - float linewidth = 0f; + float linePos = 0f; float spaceWidth = font.MeasureString(" ").X; for (int i = 0; i < words.Length; ++i) { - Vector2 size = font.MeasureString(words[i]); - if (linewidth + size.X < lineWidth) + if (string.IsNullOrWhiteSpace(words[i])) continue; + + Vector2 size; + string tempWord = words[i]; + string prevWord = words[i]; + while ((size = font.MeasureString(tempWord)).X > lineLength) { - linewidth += size.X + spaceWidth; + tempWord = tempWord.Remove(tempWord.Length - 1, 1); + + + } + words[i] = tempWord; + if (prevWord.Length> tempWord.Length) + { + wrappedText.Append(words[i]); + wrappedText.Append(" \n"); + wrappedText.Append(prevWord.Remove(0, tempWord.Length)); + linePos = lineLength*2.0f; + continue; + + } + + if (linePos + size.X < lineLength) + { + wrappedText.Append(words[i]); + linePos += size.X + spaceWidth; } else { + //if (i>0)wrappedText.Remove(wrappedText.Length - 1, 1); wrappedText.Append("\n"); - linewidth = size.X + spaceWidth; + wrappedText.Append(words[i]); + + + + + linePos = size.X + spaceWidth; } - wrappedText.Append(words[i]); + if (i