9-Sliced UI sprites & some new UI graphics

This commit is contained in:
Regalis
2017-04-07 21:45:32 +03:00
parent a2e21a78f9
commit 1fe6427c05
7 changed files with 87 additions and 6 deletions

View File

@@ -1040,6 +1040,9 @@
<Content Include="Content\UI\uiIcons.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\UI\UI_Atlas.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\utg_4.mp4">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>

View File

@@ -9,7 +9,7 @@
<ErrorReportUrlHistory />
<FallbackCulture>en-US</FallbackCulture>
<VerifyUploadedFiles>false</VerifyUploadedFiles>
<ProjectView>ShowAllFiles</ProjectView>
<ProjectView>ProjectFiles</ProjectView>
</PropertyGroup>
<PropertyGroup>
<ReferencePath>

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 KiB

View File

@@ -11,7 +11,7 @@
outlinecolor="0.5, 0.57, 0.6, 1.0">
<Sprite texture="Content/UI/uiBackground.png" size="0.0, 0.0" sourcerect ="0.0, 90.0, 0.0, 100.0"/>
<Sprite texture="Content/UI/UI_Atlas.png" size="0.0, 0.0" sourcerect ="13, 6, 420, 647" slice="208,88,238,585"/>
</GUIFrame>
<GUIButton
@@ -22,8 +22,7 @@
hovercolor="0.88, 0.25, 0.15, 1.0"
selectedcolor="1.0, 0.0, 0.0, 1.0">
<Sprite texture="Content/UI/uiButton.png" size="1.0, 1.0" tile="false" maintainaspectratio="false" sourcerect ="0.0, 0.0, 0.0, 71.0"/>
<Sprite texture="Content/UI/UI_Atlas.png" sourcerect ="13, 667, 220, 59" slice="27,673,226,718"/>
</GUIButton>
<GUITextBlock

View File

@@ -18,6 +18,18 @@ namespace Barotrauma
private set;
}
public bool Slice
{
get;
set;
}
public Rectangle[] Slices
{
get;
set;
}
public bool MaintainAspectRatio
{
get;
@@ -80,7 +92,40 @@ namespace Barotrauma
bool maintainAspect = ToolBox.GetAttributeBool(subElement, "maintainaspectratio",false);
bool tile = ToolBox.GetAttributeBool(subElement, "tile", true);
Sprites.Add(new UISprite(sprite, tile, maintainAspect));
UISprite newSprite = new UISprite(sprite, tile, maintainAspect);
Vector4 sliceVec = ToolBox.GetAttributeVector4(subElement, "slice", Vector4.Zero);
if (sliceVec != Vector4.Zero)
{
Rectangle slice = new Rectangle((int)sliceVec.X, (int)sliceVec.Y, (int)(sliceVec.Z - sliceVec.X), (int)(sliceVec.W - sliceVec.Y));
newSprite.Slice = true;
newSprite.Slices = new Rectangle[9];
//top-left
newSprite.Slices[0] = new Rectangle(newSprite.Sprite.SourceRect.Location, slice.Location - newSprite.Sprite.SourceRect.Location);
//top-mid
newSprite.Slices[1] = new Rectangle(slice.Location.X, newSprite.Slices[0].Y, slice.Width, newSprite.Slices[0].Height);
//top-right
newSprite.Slices[2] = new Rectangle(slice.Right, newSprite.Slices[0].Y, newSprite.Sprite.SourceRect.Right - slice.Right, newSprite.Slices[0].Height);
//mid-left
newSprite.Slices[3] = new Rectangle(newSprite.Slices[0].X, slice.Y, newSprite.Slices[0].Width, slice.Height);
//center
newSprite.Slices[4] = slice;
//mid-right
newSprite.Slices[5] = new Rectangle(newSprite.Slices[2].X, slice.Y, newSprite.Slices[2].Width, slice.Height);
//bottom-left
newSprite.Slices[6] = new Rectangle(newSprite.Slices[0].X, slice.Bottom, newSprite.Slices[0].Width, newSprite.Sprite.SourceRect.Bottom - slice.Bottom);
//bottom-mid
newSprite.Slices[7] = new Rectangle(newSprite.Slices[1].X, slice.Bottom, newSprite.Slices[1].Width, newSprite.Sprite.SourceRect.Bottom - slice.Bottom);
//bottom-right
newSprite.Slices[8] = new Rectangle(newSprite.Slices[2].X, slice.Bottom, newSprite.Slices[2].Width, newSprite.Sprite.SourceRect.Bottom - slice.Bottom);
}
Sprites.Add(newSprite);
break;
}
}

View File

@@ -298,7 +298,36 @@ namespace Barotrauma
{
foreach (UISprite uiSprite in sprites)
{
if (uiSprite.Tile)
if (uiSprite.Slice)
{
Vector2 pos = new Vector2(rect.X, rect.Y);
int centerWidth = rect.Width - uiSprite.Slices[0].Width - uiSprite.Slices[2].Width;
int centerHeight = rect.Height - uiSprite.Slices[0].Height - uiSprite.Slices[8].Height;
for (int x = 0; x<3; x++)
{
int width = x == 1 ? centerWidth : uiSprite.Slices[x].Width;
for (int y = 0; y<3; y++)
{
int height = y == 1 ? centerHeight : uiSprite.Slices[x + y * 3].Height;
//GUI.DrawString(spriteBatch, pos, x + ", " + y, Color.White);
uiSprite.Sprite.DrawTiled(
spriteBatch,
pos,
new Vector2(width, height),
Vector2.Zero,
uiSprite.Slices[x + y * 3],
currColor * (currColor.A / 255.0f));
pos.Y += height;
}
pos.X += width;
pos.Y = rect.Y;
}
}
else if (uiSprite.Tile)
{
Vector2 startPos = new Vector2(rect.X, rect.Y);
Vector2 size = new Vector2(Math.Min(uiSprite.Sprite.SourceRect.Width, rect.Width), Math.Min(uiSprite.Sprite.SourceRect.Height, rect.Height));

View File

@@ -300,6 +300,11 @@ namespace Barotrauma
}
public void DrawTiled(SpriteBatch spriteBatch, Vector2 pos, Vector2 targetSize, Vector2 startOffset, Color color)
{
DrawTiled(spriteBatch, pos, targetSize, startOffset, sourceRect, color);
}
public void DrawTiled(SpriteBatch spriteBatch, Vector2 pos, Vector2 targetSize, Vector2 startOffset, Rectangle sourceRect, Color color)
{
//pos.X = (int)pos.X;
//pos.Y = (int)pos.Y;