stairs fix, wraptext fix, moved drawing sprites from GUIFrame to GUIComponent, server name and "welcome text" in netlobby
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -47,11 +47,11 @@
|
||||
</GUIScrollBar>
|
||||
|
||||
<GUITextBox
|
||||
color="0.8, 0.8, 0.8, 1.0"
|
||||
color="0.5, 0.5, 0.5, 1.0"
|
||||
|
||||
textcolor="0.0, 0.0, 0.0, 1.0"
|
||||
textcolor="1.0, 1.0, 1.0, 1.0"
|
||||
outlinecolor="0.5, 0.57, 0.6, 1.0">
|
||||
<Sprite texture="Content\UI\uiBackground.png" size="0.0, 1.0" sourcerect ="0.0, 0.0, 0.0, 90.0"/>
|
||||
<Sprite texture="Content\UI\uiBackground.png" size="0.0, 0.0" sourcerect ="0.0, 90.0, 0.0, 100.0"/>
|
||||
</GUITextBox>
|
||||
|
||||
<GUIMessageBox
|
||||
|
||||
@@ -194,7 +194,25 @@ namespace Subsurface
|
||||
|
||||
public virtual void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
Color currColor = color;
|
||||
if (state == ComponentState.Selected) currColor = selectedColor;
|
||||
if (state == ComponentState.Hover) currColor = hoverColor;
|
||||
|
||||
GUI.DrawRectangle(spriteBatch, rect, currColor * (currColor.A / 255.0f), true);
|
||||
|
||||
if (sprites != null)
|
||||
{
|
||||
foreach (Sprite sprite in sprites)
|
||||
{
|
||||
Vector2 startPos = new Vector2(rect.X, rect.Y);
|
||||
Vector2 size = new Vector2(sprite.SourceRect.Width, sprite.SourceRect.Height);
|
||||
|
||||
if (sprite.size.X == 0.0f) size.X = rect.Width;
|
||||
if (sprite.size.Y == 0.0f) size.Y = rect.Height;
|
||||
|
||||
sprite.DrawTiled(spriteBatch, startPos, size, currColor * (currColor.A / 255.0f));
|
||||
}
|
||||
}
|
||||
|
||||
//Color newColor = color;
|
||||
//if (state == ComponentState.Selected) newColor = selectedColor;
|
||||
|
||||
@@ -39,27 +39,14 @@ namespace Subsurface
|
||||
|
||||
public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
|
||||
{
|
||||
base.Draw(spriteBatch);
|
||||
|
||||
|
||||
Color currColor = color;
|
||||
if (state == ComponentState.Selected) currColor = selectedColor;
|
||||
if (state == ComponentState.Hover) currColor = hoverColor;
|
||||
|
||||
GUI.DrawRectangle(spriteBatch, rect, currColor * (currColor.A/255.0f), true);
|
||||
|
||||
if (sprites != null)
|
||||
{
|
||||
foreach (Sprite sprite in sprites)
|
||||
{
|
||||
Vector2 startPos = new Vector2(rect.X, rect.Y);
|
||||
Vector2 size = new Vector2(sprite.SourceRect.Width, sprite.SourceRect.Height);
|
||||
|
||||
if (sprite.size.X == 0.0f) size.X = rect.Width;
|
||||
if (sprite.size.Y == 0.0f) size.Y = rect.Height;
|
||||
|
||||
sprite.DrawTiled(spriteBatch, startPos, size, currColor * (currColor.A / 255.0f));
|
||||
}
|
||||
}
|
||||
base.Draw(spriteBatch);
|
||||
|
||||
if (OutlineColor != Color.Transparent)
|
||||
{
|
||||
|
||||
@@ -19,7 +19,9 @@ namespace Subsurface
|
||||
public delegate string TextGetterHandler();
|
||||
public TextGetterHandler TextGetter;
|
||||
|
||||
private bool wrap;
|
||||
public bool Wrap;
|
||||
|
||||
|
||||
|
||||
public override Vector4 Padding
|
||||
{
|
||||
@@ -111,7 +113,7 @@ namespace Subsurface
|
||||
|
||||
//if (wrap)
|
||||
//{
|
||||
this.wrap = wrap;
|
||||
this.Wrap = wrap;
|
||||
// this.text = ToolBox.WrapText(this.text, rect.Width);
|
||||
//}
|
||||
|
||||
@@ -124,19 +126,19 @@ namespace Subsurface
|
||||
|
||||
Vector2 size = MeasureText();
|
||||
|
||||
if (wrap && rect.Width>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))
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -208,7 +208,7 @@ namespace Subsurface
|
||||
bodies = new List<Body>();
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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<words.Length-1) wrappedText.Append(" ");
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user