Merge branch 'master' into new-netcode

Conflicts:
	Subsurface/Barotrauma.csproj
This commit is contained in:
Regalis
2017-04-03 18:36:22 +03:00
18 changed files with 262 additions and 82 deletions
+10
View File
@@ -176,6 +176,7 @@
<Compile Include="Source\Screens\BlurEffect.cs" /> <Compile Include="Source\Screens\BlurEffect.cs" />
<Compile Include="Source\Networking\Voting.cs" /> <Compile Include="Source\Networking\Voting.cs" />
<Compile Include="Source\Screens\ServerListScreen.cs" /> <Compile Include="Source\Screens\ServerListScreen.cs" />
<Compile Include="Source\SpriteSheet.cs" />
<Compile Include="Source\Timing.cs" /> <Compile Include="Source\Timing.cs" />
<Compile Include="Source\Utils\Homoglyphs.cs" /> <Compile Include="Source\Utils\Homoglyphs.cs" />
<Compile Include="Source\Utils\MTRandom.cs" /> <Compile Include="Source\Utils\MTRandom.cs" />
@@ -422,6 +423,9 @@
<Content Include="Content\Characters\Human\fhead7[black].png"> <Content Include="Content\Characters\Human\fhead7[black].png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Content\Characters\Human\fhead8.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Characters\Human\ftorso[black].png"> <Content Include="Content\Characters\Human\ftorso[black].png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
@@ -852,12 +856,18 @@
<Content Include="Content\Particles\fire.png"> <Content Include="Content\Particles\fire.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Content\Particles\FlameRoundParticleSheet.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Particles\flames.png"> <Content Include="Content\Particles\flames.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Content\Particles\shrapnel.png"> <Content Include="Content\Particles\shrapnel.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Content\Particles\SmokeParticleSheet.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Sounds\Damage\StructureBlunt10.ogg"> <Content Include="Content\Sounds\Damage\StructureBlunt10.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<Character name ="human" humanoid="true" needsair="true" genders="true" maleheadid="1,8" femaleheadid="1,7" drowningtime="30"> <Character name ="human" humanoid="true" needsair="true" genders="true" maleheadid="1,8" femaleheadid="1,8" drowningtime="30">
<name firstname="Content/Characters/Human/[GENDER]firstnames.txt" lastname="Content/Characters/Human/lastnames.txt" /> <name firstname="Content/Characters/Human/[GENDER]firstnames.txt" lastname="Content/Characters/Human/lastnames.txt" />
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

@@ -111,19 +111,20 @@
</shockwave> </shockwave>
<flame <flame
startsizemin="0.3,0.3" startsizemax="0.5,0.5" startsizemin="0.5,0.3" startsizemax="1.0,0.5"
sizechangemin="0.1,0.1" sizechangemax="0.2,0.2" sizechangemin="0.1,0.1" sizechangemax="0.2,0.2"
startrotationmin ="-20.0" startrotationmax="20" startrotationmin ="-20.0" startrotationmax="20"
startcolor="1.0, 1.0, 1.0" startalpha="1.0" startcolor="1.0, 1.0, 1.0" startalpha="1.0"
colorchange="-0.9, -1.5, -6.3, -1.2" colorchange="-0.9, -1.5, -6.3, -1.2"
lifetime="2.5" lifetime="2.5"
growtime ="0.05" growtime ="0.2"
drawtarget="air" drawtarget="air"
collideswithwalls="true" collideswithwalls="true"
blendstate="additive" blendstate="additive"
velocitychange="0.0, 2.5"> velocitychange="0.0, 2.5"
<sprite texture="Content/Particles/fire.png" sourcerect="0,0,96,96"/> animduration="1.2"
<sprite texture="Content/Particles/fire.png" sourcerect="96,0,96,96"/> loopanim="false">
<animatedsprite texture="Content/Particles/FlameRoundParticleSheet.png" sourcerect="0,0,2048,2048" columns="10" rows="5" origin="0.5,0.8"/>
</flame> </flame>
<steam <steam
@@ -144,14 +145,17 @@
startsizemin="0.4,0.4" startsizemax="0.5,0.5" startsizemin="0.4,0.4" startsizemax="0.5,0.5"
sizechangemin="0.25,0.25" sizechangemax="0.3,0.3" sizechangemin="0.25,0.25" sizechangemax="0.3,0.3"
startrotationmin ="0.0" startrotationmax="360" startrotationmin ="0.0" startrotationmax="360"
startcolor="0.0, 0.0, 0.0" startalpha="0.5" startcolor="0.0, 0.0, 0.0" startalpha="1.0"
colorchange="0.0, 0.0, 0.0, -0.25" colorchange="0.0, 0.0, 0.0, -0.25"
growtime ="0.2" growtime ="0.2"
lifetime="3" lifetime="5"
collideswithwalls="true" collideswithwalls="true"
collisionradius="30.0" collisionradius="80.0"
velocitychange="0.0, 2.5"> velocitychange="0.0, 2.5"
<sprite texture="Content/Particles/spatter.png" sourcerect="128,128,128,128"/> animduration="4"
restitution="0.98"
loopanim="false">
<animatedsprite texture="Content/Particles/SmokeParticleSheet.png" sourcerect="0,0,1024,1024" columns="5" rows="5"/>
</smoke> </smoke>
<explosionfire <explosionfire
Binary file not shown.

After

Width:  |  Height:  |  Size: 621 KiB

@@ -19,6 +19,8 @@ namespace Barotrauma
public float Rotation; public float Rotation;
//public Vector2[] spriteCorners;
public BackgroundSprite(BackgroundSpritePrefab prefab, Vector3 position, float scale, float rotation = 0.0f) public BackgroundSprite(BackgroundSpritePrefab prefab, Vector3 position, float scale, float rotation = 0.0f)
{ {
this.Prefab = prefab; this.Prefab = prefab;
@@ -68,6 +70,8 @@ namespace Barotrauma
DebugConsole.ThrowError(String.Format("Failed to load BackgroundSprites from {0}", configPath), e); DebugConsole.ThrowError(String.Format("Failed to load BackgroundSprites from {0}", configPath), e);
} }
} }
public void PlaceSprites(Level level, int amount) public void PlaceSprites(Level level, int amount)
{ {
sprites = new List<BackgroundSprite>[ sprites = new List<BackgroundSprite>[
@@ -102,14 +106,37 @@ namespace Barotrauma
var newSprite = new BackgroundSprite(prefab, var newSprite = new BackgroundSprite(prefab,
new Vector3((Vector2)pos, Rand.Range(prefab.DepthRange.X, prefab.DepthRange.Y, false)), Rand.Range(prefab.Scale.X, prefab.Scale.Y, false), rotation); new Vector3((Vector2)pos, Rand.Range(prefab.DepthRange.X, prefab.DepthRange.Y, false)), Rand.Range(prefab.Scale.X, prefab.Scale.Y, false), rotation);
Vector2 spriteSize = newSprite.Prefab.Sprite.size * newSprite.Scale; //calculate the positions of the corners of the rotated sprite
Vector2 halfSize = newSprite.Prefab.Sprite.size * newSprite.Scale / 2;
var spriteCorners = new Vector2[]
{
-halfSize, new Vector2(-halfSize.X, halfSize.Y),
halfSize, new Vector2(halfSize.X, -halfSize.Y)
};
int minX = (int)Math.Floor((newSprite.Position.X - spriteSize.X / 2 - newSprite.Position.Z) / GridSize); Vector2 pivotOffset = newSprite.Prefab.Sprite.Origin * newSprite.Scale - halfSize;
int maxX = (int)Math.Floor((newSprite.Position.X + spriteSize.X / 2 + newSprite.Position.Z) / GridSize); pivotOffset.X = -pivotOffset.X;
pivotOffset = new Vector2(
(float)(pivotOffset.X * Math.Cos(-rotation) - pivotOffset.Y * Math.Sin(-rotation)),
(float)(pivotOffset.X * Math.Sin(-rotation) + pivotOffset.Y * Math.Cos(-rotation)));
for (int j = 0; j < 4; j++)
{
spriteCorners[j] = new Vector2(
(float)(spriteCorners[j].X * Math.Cos(-rotation) - spriteCorners[j].Y * Math.Sin(-rotation)),
(float)(spriteCorners[j].X * Math.Sin(-rotation) + spriteCorners[j].Y * Math.Cos(-rotation)));
spriteCorners[j] += (Vector2)pos + pivotOffset;
}
//newSprite.spriteCorners = spriteCorners;
int minX = (int)Math.Floor((spriteCorners.Min(c => c.X) - newSprite.Position.Z) / GridSize);
int maxX = (int)Math.Floor((spriteCorners.Max(c => c.X) + newSprite.Position.Z) / GridSize);
if (minX < 0 || maxX >= sprites.GetLength(0)) continue; if (minX < 0 || maxX >= sprites.GetLength(0)) continue;
int minY = (int)Math.Floor((newSprite.Position.Y - spriteSize.Y / 2 - newSprite.Position.Z) / GridSize); int minY = (int)Math.Floor((spriteCorners.Min(c => c.Y) - newSprite.Position.Z) / GridSize);
int maxY = (int)Math.Floor((newSprite.Position.Y + spriteSize.Y / 2 + newSprite.Position.Z) / GridSize); int maxY = (int)Math.Floor((spriteCorners.Max(c => c.Y) + newSprite.Position.Z) / GridSize);
if (minY < 0 || maxY >= sprites.GetLength(1)) continue; if (minY < 0 || maxY >= sprites.GetLength(1)) continue;
for (int x = minX; x <= maxX; x++) for (int x = minX; x <= maxX; x++)
@@ -279,6 +306,14 @@ namespace Barotrauma
SpriteEffects.None, SpriteEffects.None,
z); z);
/*for (int i = 0; i < 4; i++)
{
GUI.DrawLine(spriteBatch,
new Vector2(sprite.spriteCorners[i].X, -sprite.spriteCorners[i].Y),
new Vector2(sprite.spriteCorners[(i + 1) % 4].X, -sprite.spriteCorners[(i + 1) % 4].Y),
Color.White, 0, 5);
}*/
if (GameMain.DebugDraw) if (GameMain.DebugDraw)
{ {
GUI.DrawRectangle(spriteBatch, new Vector2(sprite.Position.X, -sprite.Position.Y), new Vector2(10.0f, 10.0f), Color.Red, true); GUI.DrawRectangle(spriteBatch, new Vector2(sprite.Position.X, -sprite.Position.Y), new Vector2(10.0f, 10.0f), Color.Red, true);
@@ -43,7 +43,7 @@ namespace Barotrauma
Scale.X = ToolBox.GetAttributeFloat(element, "minsize", 1.0f); Scale.X = ToolBox.GetAttributeFloat(element, "minsize", 1.0f);
Scale.Y = ToolBox.GetAttributeFloat(element, "maxsize", 1.0f); Scale.Y = ToolBox.GetAttributeFloat(element, "maxsize", 1.0f);
DepthRange = ToolBox.GetAttributeVector2(element, "depthrange", Vector2.Zero); DepthRange = ToolBox.GetAttributeVector2(element, "depthrange", new Vector2(0.0f, 1.0f));
AlignWithSurface = ToolBox.GetAttributeBool(element, "alignwithsurface", false); AlignWithSurface = ToolBox.GetAttributeBool(element, "alignwithsurface", false);
+3 -3
View File
@@ -187,15 +187,15 @@ namespace Barotrauma
public void SetTextPos() public void SetTextPos()
{ {
if (text==null) return; if (text == null) return;
wrappedText = text; wrappedText = text;
Vector2 size = MeasureText(text); Vector2 size = MeasureText(text);
if (Wrap && rect.Width>0) if (Wrap && rect.Width > 0)
{ {
wrappedText = ToolBox.WrapText(text, rect.Width - padding.X - padding.Z, Font); wrappedText = ToolBox.WrapText(text, rect.Width - padding.X - padding.Z, Font, textScale);
Vector2 newSize = MeasureText(wrappedText); Vector2 newSize = MeasureText(wrappedText);
+11 -3
View File
@@ -69,6 +69,7 @@ namespace Barotrauma
public static GameSettings Config; public static GameSettings Config;
private CoroutineHandle loadingCoroutine;
private bool hasLoaded; private bool hasLoaded;
private GameTime fixedTime; private GameTime fixedTime;
@@ -203,7 +204,7 @@ namespace Barotrauma
loadingScreenOpen = true; loadingScreenOpen = true;
TitleScreen = new LoadingScreen(GraphicsDevice); TitleScreen = new LoadingScreen(GraphicsDevice);
CoroutineManager.StartCoroutine(Load()); loadingCoroutine = CoroutineManager.StartCoroutine(Load());
} }
public IEnumerable<object> Load() public IEnumerable<object> Load()
@@ -335,6 +336,14 @@ namespace Barotrauma
{ {
loadingScreenOpen = false; loadingScreenOpen = false;
} }
if (!hasLoaded && !CoroutineManager.IsCoroutineRunning(loadingCoroutine))
{
DebugConsole.ThrowError("Loading was interrupted due to an error");
loadingScreenOpen = false;
loadingCoroutine = null;
hasLoaded = true;
}
} }
else if (hasLoaded) else if (hasLoaded)
{ {
@@ -343,8 +352,6 @@ namespace Barotrauma
if (PlayerInput.KeyHit(Keys.Escape)) GUI.TogglePauseMenu(); if (PlayerInput.KeyHit(Keys.Escape)) GUI.TogglePauseMenu();
GUIComponent.ClearUpdateList(); GUIComponent.ClearUpdateList();
DebugConsole.AddToGUIUpdateList();
paused = (DebugConsole.IsOpen || GUI.PauseMenuOpen || GUI.SettingsMenuOpen) && paused = (DebugConsole.IsOpen || GUI.PauseMenuOpen || GUI.SettingsMenuOpen) &&
(NetworkMember == null || !NetworkMember.GameStarted); (NetworkMember == null || !NetworkMember.GameStarted);
@@ -359,6 +366,7 @@ namespace Barotrauma
} }
GUI.AddToGUIUpdateList(); GUI.AddToGUIUpdateList();
DebugConsole.AddToGUIUpdateList();
GUIComponent.UpdateMouseOn(); GUIComponent.UpdateMouseOn();
DebugConsole.Update(this, (float)Timing.Step); DebugConsole.Update(this, (float)Timing.Step);
+34 -22
View File
@@ -174,41 +174,39 @@ namespace Barotrauma
} }
} }
if (size.X > 50.0f) //the firesource will start to shrink if oxygen percentage is below 10
float growModifier = Math.Min((hull.OxygenPercentage / 10.0f) - 1.0f, 1.0f);
for (int i = 0; i < count; i++)
{ {
this.position.Y = MathHelper.Lerp(this.position.Y, hull.Rect.Y - hull.Rect.Height, deltaTime); Vector2 particlePos = new Vector2(
} WorldPosition.X + Rand.Range(0.0f, size.X),
Rand.Range(WorldPosition.Y - size.Y, WorldPosition.Y + 20.0f));
float growModifier = hull.OxygenPercentage < 20.0f ? (hull.OxygenPercentage/10.0f)-1.0f : 1.0f; Vector2 particleVel = new Vector2(
(particlePos.X - (WorldPosition.X + size.X / 2.0f)),
for (int i = 0; i < count; i++ ) (float)Math.Sqrt(size.X) * Rand.Range(0.0f, 15.0f) * growModifier);
{
Vector2 spawnPos = new Vector2(WorldPosition.X + Rand.Range(0.0f, size.X), Rand.Range(WorldPosition.Y - size.Y, WorldPosition.Y) + 10.0f);
Vector2 speed = new Vector2((spawnPos.X - (WorldPosition.X + size.X / 2.0f)), (float)Math.Sqrt(size.X) * Rand.Range(10.0f, 15.0f) * growModifier);
var particle = GameMain.ParticleManager.CreateParticle("flame", var particle = GameMain.ParticleManager.CreateParticle("flame",
spawnPos, speed, 0.0f, hull); particlePos, particleVel, 0.0f, hull);
if (particle == null) continue; if (particle == null) continue;
//make some of the particles create another firesource when they enter another hull
if (Rand.Int(20) == 1) particle.OnChangeHull = OnChangeHull; if (Rand.Int(20) == 1) particle.OnChangeHull = OnChangeHull;
particle.Size *= MathHelper.Clamp(size.X/60.0f * Math.Max(hull.Oxygen/hull.FullVolume, 0.4f), 0.5f, 3.0f); particle.Size *= MathHelper.Clamp(size.X / 60.0f * Math.Max(hull.Oxygen / hull.FullVolume, 0.4f), 0.5f, 1.0f);
if (size.X < 100.0f) continue;
if (Rand.Int(5) == 1) if (Rand.Int(5) == 1)
{ {
var smokeParticle = GameMain.ParticleManager.CreateParticle("smoke", var smokeParticle = GameMain.ParticleManager.CreateParticle("smoke",
spawnPos, speed, 0.0f, hull); particlePos, particleVel * 0.1f, 0.0f, hull);
if (smokeParticle != null) if (smokeParticle != null)
{ {
smokeParticle.Size *= MathHelper.Clamp(size.X / 100.0f * Math.Max(hull.Oxygen / hull.FullVolume, 0.4f), 0.5f, 4.0f); smokeParticle.Size *= MathHelper.Clamp(size.X / 100.0f * Math.Max(hull.Oxygen / hull.FullVolume, 0.4f), 0.5f, 1.0f);
} }
} }
} }
DamageCharacters(deltaTime); DamageCharacters(deltaTime);
@@ -221,13 +219,22 @@ namespace Barotrauma
position.X -= GrowSpeed * growModifier * 0.5f * deltaTime; position.X -= GrowSpeed * growModifier * 0.5f * deltaTime;
size.X += GrowSpeed * growModifier * deltaTime; size.X += GrowSpeed * growModifier * deltaTime;
size.Y = MathHelper.Clamp(size.Y + GrowSpeed * growModifier * deltaTime, 10.0f, 50.0f);
if (size.X > 50.0f)
{
this.position.Y = MathHelper.Lerp(this.position.Y, hull.Rect.Y - hull.Rect.Height + size.Y, deltaTime);
}
LimitSize(); LimitSize();
lightSource.Range = Math.Max(size.X, size.Y) * 10.0f / 2.0f; lightSource.Range = Math.Max(size.X, size.Y) * 10.0f / 2.0f;
lightSource.Color = new Color(1.0f, 0.45f, 0.3f) * Rand.Range(0.8f, 1.0f); lightSource.Color = new Color(1.0f, 0.45f, 0.3f) * Rand.Range(0.8f, 1.0f);
lightSource.Position = position; lightSource.Position = position + Vector2.UnitY * 30.0f;
if (GameMain.Client != null) return;
if (size.X < 1.0f) Remove();
} }
private void OnChangeHull(Vector2 pos, Hull particleHull) private void OnChangeHull(Vector2 pos, Hull particleHull)
@@ -282,15 +289,19 @@ namespace Barotrauma
private void HullWaterExtinquish(float deltaTime) private void HullWaterExtinquish(float deltaTime)
{ {
float extinquishAmount = Math.Min(hull.Volume / 100.0f, size.X)*10.0f*deltaTime; //the higher the surface of the water is relative to the firesource, the faster it puts out the fire
float extinquishAmount = (hull.Surface - (position.Y - size.Y)) * deltaTime;
float steamCount = Rand.Range(-5.0f, (float)Math.Sqrt(extinquishAmount)); if (extinquishAmount < 0.0f) return;
float steamCount = Rand.Range(-5.0f, Math.Min(extinquishAmount * 100.0f, 10));
for (int i = 0; i < steamCount; i++) for (int i = 0; i < steamCount; i++)
{ {
Vector2 spawnPos = new Vector2(position.X + size.X * (i / steamCount) + Rand.Range(-5.0f, 5.0f), Rand.Range(position.Y - size.Y, position.Y) + 10.0f); Vector2 spawnPos = new Vector2(
WorldPosition.X + Rand.Range(0.0f, size.X),
Rand.Range(position.Y - size.Y, WorldPosition.Y) + 10.0f);
Vector2 speed = new Vector2((spawnPos.X - (position.X + size.X / 2.0f)), (float)Math.Sqrt(size.X) * Rand.Range(20.0f, 25.0f)); Vector2 speed = new Vector2((spawnPos.X - (WorldPosition.X + size.X / 2.0f)), (float)Math.Sqrt(size.X) * Rand.Range(20.0f, 25.0f));
var particle = GameMain.ParticleManager.CreateParticle("steam", var particle = GameMain.ParticleManager.CreateParticle("steam",
spawnPos, speed, 0.0f, hull); spawnPos, speed, 0.0f, hull);
@@ -303,6 +314,7 @@ namespace Barotrauma
position.X += extinquishAmount / 2.0f; position.X += extinquishAmount / 2.0f;
size.X -= extinquishAmount; size.X -= extinquishAmount;
//evaporate some of the water
hull.Volume -= extinquishAmount; hull.Volume -= extinquishAmount;
if (GameMain.Client != null) return; if (GameMain.Client != null) return;
+5
View File
@@ -607,6 +607,11 @@ namespace Barotrauma
GUI.SmallFont.DrawString(spriteBatch, "Pressure: " + ((int)pressure - rect.Y).ToString() + GUI.SmallFont.DrawString(spriteBatch, "Pressure: " + ((int)pressure - rect.Y).ToString() +
" - Oxygen: " + ((int)OxygenPercentage), new Vector2(drawRect.X + 5, -drawRect.Y + 5), Color.White); " - Oxygen: " + ((int)OxygenPercentage), new Vector2(drawRect.X + 5, -drawRect.Y + 5), Color.White);
GUI.SmallFont.DrawString(spriteBatch, volume + " / " + FullVolume, new Vector2(drawRect.X + 5, -drawRect.Y + 20), Color.White); GUI.SmallFont.DrawString(spriteBatch, volume + " / " + FullVolume, new Vector2(drawRect.X + 5, -drawRect.Y + 20), Color.White);
foreach (FireSource fs in fireSources)
{
GUI.DrawRectangle(spriteBatch, new Rectangle((int)fs.WorldPosition.X, (int)-fs.WorldPosition.Y, (int)fs.Size.X, (int)fs.Size.Y), Color.Orange, false);
}
} }
if ((IsSelected || isHighlighted) && editing) if ((IsSelected || isHighlighted) && editing)
+2 -2
View File
@@ -654,9 +654,9 @@ namespace Barotrauma
var section = sections[sectionIndex]; var section = sections[sectionIndex];
int particleAmount = (int)(Math.Min(Health - section.damage, damage) * Rand.Range(0.01f, 1.0f)); float particleAmount = Math.Min(Health - section.damage, damage) * Rand.Range(0.01f, 1.0f);
particleAmount = Math.Min(particleAmount, 200); particleAmount = Math.Min(particleAmount + Rand.Range(-5,1), 100);
for (int i = 0; i < particleAmount; i++) for (int i = 0; i < particleAmount; i++)
{ {
Vector2 particlePos = new Vector2( Vector2 particlePos = new Vector2(
+37 -10
View File
@@ -43,6 +43,9 @@ namespace Barotrauma.Particles
private List<Gap> hullGaps; private List<Gap> hullGaps;
private float animState;
private int animFrame;
public ParticlePrefab.DrawTargetType DrawTarget public ParticlePrefab.DrawTargetType DrawTarget
{ {
get { return prefab.DrawTarget; } get { return prefab.DrawTarget; }
@@ -77,6 +80,9 @@ namespace Barotrauma.Particles
spriteIndex = Rand.Int(prefab.Sprites.Count); spriteIndex = Rand.Int(prefab.Sprites.Count);
animState = 0;
animFrame = 0;
currentHull = Hull.FindHull(position, hullGuess); currentHull = Hull.FindHull(position, hullGuess);
this.position = position; this.position = position;
@@ -167,6 +173,13 @@ namespace Barotrauma.Particles
color.G / 255.0f + prefab.ColorChange.Y * deltaTime, color.G / 255.0f + prefab.ColorChange.Y * deltaTime,
color.B / 255.0f + prefab.ColorChange.Z * deltaTime); color.B / 255.0f + prefab.ColorChange.Z * deltaTime);
if (prefab.Sprites[spriteIndex] is SpriteSheet)
{
animState += deltaTime;
int frameCount = ((SpriteSheet)prefab.Sprites[spriteIndex]).FrameCount;
animFrame = (int)Math.Min(Math.Floor(animState / prefab.AnimDuration * frameCount), frameCount - 1);
}
if (prefab.DeleteOnCollision || prefab.CollidesWithWalls) if (prefab.DeleteOnCollision || prefab.CollidesWithWalls)
{ {
Vector2 edgePos = position + prefab.CollisionRadius * Vector2.Normalize(velocity) * size.X; Vector2 edgePos = position + prefab.CollisionRadius * Vector2.Normalize(velocity) * size.X;
@@ -232,7 +245,7 @@ namespace Barotrauma.Particles
velocity -= (velocity / speed) * Math.Min(speed * speed * prefab.WaterDrag * deltaTime, 1.0f); velocity -= (velocity / speed) * Math.Min(speed * speed * prefab.WaterDrag * deltaTime, 1.0f);
} }
private void OnWallCollisionInside(Hull prevHull, Vector2 position) private void OnWallCollisionInside(Hull prevHull, Vector2 edgePos)
{ {
Rectangle prevHullRect = prevHull.WorldRect; Rectangle prevHullRect = prevHull.WorldRect;
@@ -240,24 +253,24 @@ namespace Barotrauma.Particles
velocity -= subVel; velocity -= subVel;
if (position.Y < prevHullRect.Y - prevHullRect.Height) if (edgePos.Y < prevHullRect.Y - prevHullRect.Height)
{ {
position.Y = prevHullRect.Y - prevHullRect.Height + prefab.CollisionRadius; position.Y = prevHullRect.Y - prevHullRect.Height + prefab.CollisionRadius;
velocity.Y = -velocity.Y; velocity.Y = -velocity.Y;
} }
else if (position.Y > prevHullRect.Y) else if (edgePos.Y > prevHullRect.Y)
{ {
position.Y = prevHullRect.Y - prefab.CollisionRadius; position.Y = prevHullRect.Y - prefab.CollisionRadius;
velocity.X = Math.Abs(velocity.Y) * Math.Sign(velocity.X); velocity.X = Math.Abs(velocity.Y) * Math.Sign(velocity.X);
velocity.Y = -velocity.Y * 0.1f; velocity.Y = -velocity.Y * 0.1f;
} }
if (position.X < prevHullRect.X) if (edgePos.X < prevHullRect.X)
{ {
position.X = prevHullRect.X + prefab.CollisionRadius; position.X = prevHullRect.X + prefab.CollisionRadius;
velocity.X = -velocity.X; velocity.X = -velocity.X;
} }
else if (position.X > prevHullRect.X + prevHullRect.Width) else if (edgePos.X > prevHullRect.X + prevHullRect.Width)
{ {
position.X = prevHullRect.X + prevHullRect.Width - prefab.CollisionRadius; position.X = prevHullRect.X + prevHullRect.Width - prefab.CollisionRadius;
velocity.X = -velocity.X; velocity.X = -velocity.X;
@@ -317,11 +330,25 @@ namespace Barotrauma.Particles
drawSize *= ((totalLifeTime - lifeTime) / prefab.GrowTime); drawSize *= ((totalLifeTime - lifeTime) / prefab.GrowTime);
} }
prefab.Sprites[spriteIndex].Draw(spriteBatch, if (prefab.Sprites[spriteIndex] is SpriteSheet)
new Vector2(drawPosition.X, -drawPosition.Y), {
color * alpha, ((SpriteSheet)prefab.Sprites[spriteIndex]).Draw(
prefab.Sprites[spriteIndex].Origin, drawRotation, spriteBatch, animFrame,
drawSize, SpriteEffects.None, prefab.Sprites[spriteIndex].Depth); new Vector2(drawPosition.X, -drawPosition.Y),
color * alpha,
prefab.Sprites[spriteIndex].Origin, drawRotation,
drawSize, SpriteEffects.None, prefab.Sprites[spriteIndex].Depth);
}
else
{
prefab.Sprites[spriteIndex].Draw(spriteBatch,
new Vector2(drawPosition.X, -drawPosition.Y),
color * alpha,
prefab.Sprites[spriteIndex].Origin, drawRotation,
drawSize, SpriteEffects.None, prefab.Sprites[spriteIndex].Depth);
}
} }
} }
} }
+19 -4
View File
@@ -13,6 +13,9 @@ namespace Barotrauma.Particles
public readonly List<Sprite> Sprites; public readonly List<Sprite> Sprites;
public readonly float AnimDuration;
public readonly bool LoopAnim;
public readonly float AngularVelocityMin, AngularVelocityMax; public readonly float AngularVelocityMin, AngularVelocityMax;
public readonly float StartRotationMin, StartRotationMax; public readonly float StartRotationMin, StartRotationMax;
@@ -53,11 +56,21 @@ namespace Barotrauma.Particles
foreach (XElement subElement in element.Elements()) foreach (XElement subElement in element.Elements())
{ {
if (subElement.Name.ToString().ToLowerInvariant() != "sprite") continue; switch (subElement.Name.ToString().ToLowerInvariant())
{
Sprites.Add(new Sprite(subElement)); case "sprite":
Sprites.Add(new Sprite(subElement));
break;
case "spritesheet":
case "animatedsprite":
Sprites.Add(new SpriteSheet(subElement));
break;
}
} }
AnimDuration = ToolBox.GetAttributeFloat(element, "animduration", 1.0f);
LoopAnim = ToolBox.GetAttributeBool(element, "loopanim", true);
if (element.Attribute("angularvelocity") == null) if (element.Attribute("angularvelocity") == null)
{ {
AngularVelocityMin = ToolBox.GetAttributeFloat(element, "angularvelocitymin", 0.0f); AngularVelocityMin = ToolBox.GetAttributeFloat(element, "angularvelocitymin", 0.0f);
@@ -134,7 +147,9 @@ namespace Barotrauma.Particles
DeleteOnCollision = ToolBox.GetAttributeBool(element, "deleteoncollision", false); DeleteOnCollision = ToolBox.GetAttributeBool(element, "deleteoncollision", false);
CollidesWithWalls = ToolBox.GetAttributeBool(element, "collideswithwalls", false); CollidesWithWalls = ToolBox.GetAttributeBool(element, "collideswithwalls", false);
CollisionRadius = ToolBox.GetAttributeFloat(element, "collisionradius", Sprites[0].SourceRect.Width/2.0f); CollisionRadius = ToolBox.GetAttributeFloat(element,
"collisionradius",
Sprites.Count > 0 ? 1 : Sprites[0].SourceRect.Width / 2.0f);
ColorChange = ToolBox.GetAttributeVector4(element, "colorchange", Vector4.Zero); ColorChange = ToolBox.GetAttributeVector4(element, "colorchange", Vector4.Zero);
+5 -5
View File
@@ -14,15 +14,15 @@ namespace Barotrauma
//if two sprites use the same file, they share the same texture //if two sprites use the same file, they share the same texture
string file; string file;
Texture2D texture; protected Texture2D texture;
//the area in the texture that is supposed to be drawn //the area in the texture that is supposed to be drawn
Rectangle sourceRect; Rectangle sourceRect;
//the offset used when drawing the sprite //the offset used when drawing the sprite
Vector2 offset; protected Vector2 offset;
private Vector2 origin; protected Vector2 origin;
//the size of the drawn sprite, if larger than the source, //the size of the drawn sprite, if larger than the source,
//the sprite is tiled to fill the target size //the sprite is tiled to fill the target size
@@ -32,7 +32,7 @@ namespace Barotrauma
public SpriteEffects effects; public SpriteEffects effects;
float depth; protected float depth;
public Rectangle SourceRect public Rectangle SourceRect
{ {
@@ -202,7 +202,7 @@ namespace Barotrauma
this.Draw(spriteBatch, pos, color, origin, rotate, new Vector2(scale, scale), spriteEffect, depth); this.Draw(spriteBatch, pos, color, origin, rotate, new Vector2(scale, scale), spriteEffect, depth);
} }
public void Draw(SpriteBatch spriteBatch, Vector2 pos, Color color, Vector2 origin, float rotate, Vector2 scale, SpriteEffects spriteEffect = SpriteEffects.None, float? depth = null) public virtual void Draw(SpriteBatch spriteBatch, Vector2 pos, Color color, Vector2 origin, float rotate, Vector2 scale, SpriteEffects spriteEffect = SpriteEffects.None, float? depth = null)
{ {
//for (int x = -1; x <= 1; x += 2) //for (int x = -1; x <= 1; x += 2)
//{ //{
+55
View File
@@ -0,0 +1,55 @@
using Microsoft.Xna.Framework;
using System;
using System.Xml.Linq;
using Microsoft.Xna.Framework.Graphics;
namespace Barotrauma
{
class SpriteSheet : Sprite
{
private Rectangle[] sourceRects;
public int FrameCount
{
get { return sourceRects.Length; }
}
public SpriteSheet(XElement element, string path = "", string file = "")
: base(element, path, file)
{
int columnCount = Math.Max(ToolBox.GetAttributeInt(element, "columns", 1), 1);
int rowCount = Math.Max(ToolBox.GetAttributeInt(element, "rows", 1), 1);
sourceRects = new Rectangle[rowCount * columnCount];
int cellWidth = SourceRect.Width / columnCount;
int cellHeight = SourceRect.Height / rowCount;
for (int x = 0; x < columnCount; x++)
{
for (int y = 0; y < rowCount; y++)
{
sourceRects[x + y * columnCount] = new Rectangle(x * cellWidth, y * cellHeight, cellWidth, cellHeight);
}
}
origin = ToolBox.GetAttributeVector2(element, "origin", new Vector2(0.5f, 0.5f));
origin.X = origin.X * cellWidth;
origin.Y = origin.Y * cellHeight;
}
public override void Draw(SpriteBatch spriteBatch, Vector2 pos, Color color, Vector2 origin, float rotate, Vector2 scale, SpriteEffects spriteEffect = SpriteEffects.None, float? depth = default(float?))
{
if (texture == null) return;
spriteBatch.Draw(texture, pos + offset, sourceRects[0], color, rotation + rotate, origin, scale, spriteEffect, depth == null ? this.depth : (float)depth);
}
public void Draw(SpriteBatch spriteBatch, int spriteIndex, Vector2 pos, Color color, Vector2 origin, float rotate, Vector2 scale, SpriteEffects spriteEffect = SpriteEffects.None, float? depth = default(float?))
{
if (texture == null) return;
spriteBatch.Draw(texture, pos + offset, sourceRects[spriteIndex], color, rotation + rotate, origin, scale, spriteEffect, depth == null ? this.depth : (float)depth);
}
}
}
+20 -11
View File
@@ -465,7 +465,7 @@ namespace Barotrauma
return d[n, m]; return d[n, m];
} }
public static string WrapText(string text, float lineLength, ScalableFont font) //TODO: could integrate this into the ScalableFont class directly public static string WrapText(string text, float lineLength, ScalableFont font, float textScale = 1.0f) //TODO: could integrate this into the ScalableFont class directly
{ {
if (font.MeasureString(text).X < lineLength) return text; if (font.MeasureString(text).X < lineLength) return text;
@@ -475,26 +475,35 @@ namespace Barotrauma
StringBuilder wrappedText = new StringBuilder(); StringBuilder wrappedText = new StringBuilder();
float linePos = 0f; float linePos = 0f;
float spaceWidth = font.MeasureString(" ").X; float spaceWidth = font.MeasureString(" ").X * textScale;
for (int i = 0; i < words.Length; ++i) for (int i = 0; i < words.Length; ++i)
{ {
if (string.IsNullOrWhiteSpace(words[i]) && words[i] != "\n") continue; if (string.IsNullOrWhiteSpace(words[i]) && words[i] != "\n") continue;
Vector2 size = font.MeasureString(words[i]); Vector2 size = font.MeasureString(words[i]) * textScale;
if (size.X > lineLength) if (size.X > lineLength)
{ {
while (words[i].Length > 0 && if (linePos == 0.0f)
(size = font.MeasureString((words[i][0]).ToString())).X + linePos < lineLength)
{ {
wrappedText.Append(words[i][0]); wrappedText.AppendLine(words[i]);
words[i] = words[i].Remove(0, 1); }
else
{
do
{
if (words[i].Length == 0) break;
linePos += size.X; wrappedText.Append(words[i][0]);
words[i] = words[i].Remove(0, 1);
linePos += size.X;
} while (words[i].Length > 0 && (size = font.MeasureString((words[i][0]).ToString()) * textScale).X + linePos < lineLength);
wrappedText.Append("\n");
linePos = 0.0f;
i--;
} }
wrappedText.Append("\n");
linePos = 0.0f;
i--;
continue; continue;
} }