WIP, Walls are drawn per section instead of entire wall, thus enabling hiding parts of the wall or more advanced manipulation of sections.

This commit is contained in:
Sebastian Broberg
2016-08-28 16:04:30 +02:00
parent f14242ca81
commit 1729c55820
2 changed files with 41 additions and 5 deletions
+8 -5
View File
@@ -374,11 +374,14 @@ namespace Barotrauma
} }
Vector2 drawOffset = Submarine == null ? Vector2.Zero : Submarine.DrawPosition; Vector2 drawOffset = Submarine == null ? Vector2.Zero : Submarine.DrawPosition;
prefab.sprite.DrawTiled(spriteBatch, new Vector2(rect.X + drawOffset.X, -(rect.Y + drawOffset.Y)), new Vector2(rect.Width, rect.Height), Vector2.Zero, color); if(sections.Length == 1)
prefab.sprite.DrawTiledT(spriteBatch, new Vector2(rect.X + drawOffset.X, -(rect.Y + drawOffset.Y)), new Vector2(rect.Width, rect.Height), Vector2.Zero, color,Point.Zero);
foreach (WallSection s in sections) foreach (WallSection s in sections)
{ {
Point offset = rect.Location - s.rect.Location;
if (sections.Length != 1 && s.damage < prefab.MaxHealth)
prefab.sprite.DrawTiledT(spriteBatch, new Vector2(s.rect.X + drawOffset.X, -(s.rect.Y + drawOffset.Y)), new Vector2(s.rect.Width, s.rect.Height), Vector2.Zero, color, offset);
if (s.isHighLighted) if (s.isHighLighted)
{ {
@@ -391,9 +394,9 @@ namespace Barotrauma
if (s.damage < 0.01f) continue; if (s.damage < 0.01f) continue;
GUI.DrawRectangle(spriteBatch, /* GUI.DrawRectangle(spriteBatch,
new Vector2(s.rect.X + drawOffset.X, -(s.rect.Y + drawOffset.Y)), new Vector2(s.rect.Width, s.rect.Height), new Vector2(s.rect.X + drawOffset.X, -(s.rect.Y + drawOffset.Y)), new Vector2(s.rect.Width, s.rect.Height),
Color.Black * (s.damage / prefab.MaxHealth), true); Color.Black * (s.damage / prefab.MaxHealth), true);*/
} }
/* /*
if(_convexHulls == null) return; if(_convexHulls == null) return;
+33
View File
@@ -222,7 +222,40 @@ namespace Barotrauma
{ {
DrawTiled(spriteBatch, pos, targetSize, Vector2.Zero, color); DrawTiled(spriteBatch, pos, targetSize, Vector2.Zero, color);
} }
public Point DrawTiledT(SpriteBatch spriteBatch, Vector2 pos, Vector2 targetSize, Vector2 startOffset, Color color, Point offset)
{
//how many times the texture needs to be drawn on the x-axis
int xTiles = (int)Math.Ceiling((targetSize.X + startOffset.X) / sourceRect.Width);
//how many times the texture needs to be drawn on the y-axis
int yTiles = (int)Math.Ceiling((targetSize.Y + startOffset.Y) / sourceRect.Height);
Rectangle TexPerspective = sourceRect;
TexPerspective.Location += offset;
TexPerspective.Width = (int)Math.Min(targetSize.X, sourceRect.Width);
TexPerspective.Height = (int)Math.Min(targetSize.Y, sourceRect.Height);
for (int y = 0; y < yTiles; y++)
{
TexPerspective.X = sourceRect.X;
TexPerspective.Width = (int)Math.Min(targetSize.X, sourceRect.Width);
TexPerspective.Height = (int)Math.Min(targetSize.Y, sourceRect.Height);
float top = pos.Y + TexPerspective.Height * y;
for (int x = 0; x < xTiles; x++)
{
float left = pos.X + TexPerspective.Width * x;
if (xTiles - 1 == x && x != 0)
TexPerspective.Width = (int)(targetSize.X - TexPerspective.Width * x);
TexPerspective.Height = Math.Min((int)(targetSize.Y - TexPerspective.Height * y), TexPerspective.Height);
spriteBatch.Draw(texture, new Vector2(left,top),TexPerspective, color, rotation, Vector2.Zero, 1.0f, effects, depth);
TexPerspective.X += TexPerspective.Width;
if (TexPerspective.X >= sourceRect.X+sourceRect.Width)
TexPerspective.X = sourceRect.X;
}
}
return sourceRect.Location-TexPerspective.Location;
}
public void DrawTiled(SpriteBatch spriteBatch, Vector2 pos, Vector2 targetSize, Vector2 startOffset, Color color) public void DrawTiled(SpriteBatch spriteBatch, Vector2 pos, Vector2 targetSize, Vector2 startOffset, Color color)
{ {
//pos.X = (int)pos.X; //pos.X = (int)pos.X;