Skip to content

Commit

Permalink
Added compatibility for MonoGame.Extended 4.0.0 and FNA.Extended
Browse files Browse the repository at this point in the history
  • Loading branch information
Ellpeck committed Jul 10, 2024
1 parent 24277ba commit fa1cafd
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 31 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "FontStashSharp"]
path = ThirdParty/FontStashSharp
url = https://github.com/FontStashSharp/FontStashSharp
[submodule "ThirdParty/MonoGame.Extended"]
path = ThirdParty/MonoGame.Extended
url = https://github.com/craftworkgames/MonoGame.Extended
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ Fixes
- Fixed auto-sized elements sometimes updating their location based on outdated parent positions
- Fixed Panel.ScrollToElement not scrolling correctly when the panel's area is dirty

### MLEM.Extended
Improvements
- **Added compatibility for MonoGame.Extended 4.0.0**
- Added compatibility for FNA.Extended

## 6.3.1

No code changes
Expand Down
7 changes: 4 additions & 3 deletions MLEM.Extended/Extensions/SpriteBatchExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MLEM.Extensions;
using MonoGame.Extended;
using ShapeExtensions = MonoGame.Extended.ShapeExtensions;
using RectangleF = MonoGame.Extended.RectangleF;

namespace MLEM.Extended.Extensions {
/// <summary>
Expand Down Expand Up @@ -54,11 +55,11 @@ public static void Draw(this SpriteBatch batch, Texture2D texture, RectangleF de
public static void DrawGrid(this SpriteBatch batch, Vector2 start, Vector2 tileSize, Point tileCount, Color gridColor, float gridThickness = 1) {
for (var y = 0; y < tileCount.Y; y++) {
for (var x = 0; x < tileCount.X; x++)
batch.DrawRectangle(start + new Vector2(x, y) * tileSize, tileSize, gridColor, gridThickness / 2);
ShapeExtensions.DrawRectangle(batch, start + new Vector2(x, y) * tileSize, tileSize, gridColor, gridThickness / 2);
}

var size = tileSize * tileCount.ToVector2() + new Vector2(gridThickness);
batch.DrawRectangle(start - new Vector2(gridThickness / 2), size, gridColor, gridThickness / 2);
ShapeExtensions.DrawRectangle(batch, start - new Vector2(gridThickness / 2), size, gridColor, gridThickness / 2);
}

}
Expand Down
29 changes: 11 additions & 18 deletions MLEM.Extended/Extensions/TextureExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using MLEM.Extensions;
using MLEM.Textures;
using MonoGame.Extended.TextureAtlases;
using MonoGame.Extended.Graphics;
using NinePatch = MLEM.Textures.NinePatch;
using ExtNinePatch = MonoGame.Extended.Graphics.NinePatch;

namespace MLEM.Extended.Extensions {
/// <summary>
Expand All @@ -9,38 +11,29 @@ namespace MLEM.Extended.Extensions {
public static class TextureExtensions {

/// <summary>
/// Converts a MLEM <see cref="NinePatch"/> to a MonoGame.Extended <see cref="NinePatchRegion2D"/>.
/// Converts a MLEM <see cref="Textures.NinePatch"/> to a MonoGame.Extended <see cref="ExtNinePatch"/>.
/// </summary>
/// <param name="patch">The nine patch to convert</param>
/// <returns>The converted nine patch</returns>
public static NinePatchRegion2D ToExtended(this NinePatch patch) {
return new NinePatchRegion2D(patch.Region.ToExtended(), patch.Padding.Left.Floor(), patch.Padding.Top.Floor(), patch.Padding.Right.Floor(), patch.Padding.Bottom.Floor());
public static ExtNinePatch ToExtended(this NinePatch patch) {
return patch.Region.ToExtended().CreateNinePatch(patch.Padding.Left.Floor(), patch.Padding.Top.Floor(), patch.Padding.Right.Floor(), patch.Padding.Bottom.Floor());
}

/// <summary>
/// Converts a MLEM <see cref="TextureRegion"/> to a MonoGame.Extended <see cref="TextureRegion2D"/>.
/// Converts a MLEM <see cref="TextureRegion"/> to a MonoGame.Extended <see cref="Texture2DRegion"/>.
/// </summary>
/// <param name="region">The nine patch to convert</param>
/// <returns>The converted nine patch</returns>
public static TextureRegion2D ToExtended(this TextureRegion region) {
return new TextureRegion2D(region.Name, region.Texture, region.U, region.V, region.Width, region.Height);
public static Texture2DRegion ToExtended(this TextureRegion region) {
return new Texture2DRegion(region.Texture, region.U, region.V, region.Width, region.Height, region.Name);
}

/// <summary>
/// Converts a MonoGame.Extended <see cref="NinePatchRegion2D"/> to a MLEM <see cref="NinePatch"/>.
/// </summary>
/// <param name="patch">The nine patch to convert</param>
/// <returns>The converted nine patch</returns>
public static NinePatch ToMlem(this NinePatchRegion2D patch) {
return new NinePatch(((TextureRegion2D) patch).ToMlem(), patch.LeftPadding, patch.RightPadding, patch.TopPadding, patch.BottomPadding);
}

/// <summary>
/// Converts a MonoGame.Extended <see cref="TextureRegion2D"/> to a MLEM <see cref="TextureRegion"/>.
/// Converts a MonoGame.Extended <see cref="Texture2DRegion"/> to a MLEM <see cref="TextureRegion"/>.
/// </summary>
/// <param name="region">The nine patch to convert</param>
/// <returns>The converted nine patch</returns>
public static TextureRegion ToMlem(this TextureRegion2D region) {
public static TextureRegion ToMlem(this Texture2DRegion region) {
return new TextureRegion(region.Texture, region.Bounds) {Name = region.Name};
}

Expand Down
4 changes: 2 additions & 2 deletions MLEM.Extended/Font/GenericBitmapFont.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public GenericBitmapFont(BitmapFont font, BitmapFont bold = null, BitmapFont ita

/// <inheritdoc />
protected override float MeasureCharacter(int codePoint) {
var region = this.Font.GetCharacterRegion(codePoint);
return region != null ? new Vector2(region.XAdvance, region.Height).X : 0;
var region = this.Font.GetCharacter(codePoint);
return region != null ? new Vector2(region.XAdvance, region.TextureRegion.Height).X : 0;
}

/// <inheritdoc />
Expand Down
5 changes: 5 additions & 0 deletions MLEM.Extended/MLEM.Extended.FNA.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,18 @@
<ItemGroup>
<ProjectReference Include="..\MLEM\MLEM.FNA.csproj" />

<ProjectReference Condition="'$(TargetFramework)'=='net8.0'" Include="..\ThirdParty\MonoGame.Extended\source\MonoGame.Extended\FNA.Extended.csproj">
<PrivateAssets>all</PrivateAssets>
</ProjectReference>
<ProjectReference Include="..\ThirdParty\FontStashSharp\src\XNA\FontStashSharp.FNA.csproj">
<PrivateAssets>all</PrivateAssets>
</ProjectReference>
<ProjectReference Include="..\ThirdParty\FNA\FNA.csproj">
<PrivateAssets>all</PrivateAssets>
</ProjectReference>
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)'!='net8.0'">
<Compile Remove="Tiled/**" />
<Compile Remove="Extensions/**" />
<Compile Remove="Font/GenericBitmapFont.cs" />
Expand Down
11 changes: 7 additions & 4 deletions MLEM.Extended/MLEM.Extended.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@
<ItemGroup>
<ProjectReference Include="..\MLEM\MLEM.csproj" />

<PackageReference Include="MonoGame.Extended" Version="3.8.0">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="MonoGame.Extended.Tiled" Version="3.8.0">
<PackageReference Condition="'$(TargetFramework)'=='net8.0'" Include="MonoGame.Extended" Version="4.0.0">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="FontStashSharp.MonoGame" Version="1.3.3">
Expand All @@ -35,6 +32,12 @@
</PackageReference>
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)'!='net8.0'">
<Compile Remove="Tiled/**" />
<Compile Remove="Extensions/**" />
<Compile Remove="Font/GenericBitmapFont.cs" />
</ItemGroup>

<ItemGroup>
<None Include="../Media/Logo.png" Pack="true" PackagePath="" />
<None Include="../README.md" Pack="true" PackagePath="" />
Expand Down
2 changes: 1 addition & 1 deletion MLEM.Extended/Tiled/TiledExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public static TiledMapTilesetTile GetTilesetTile(this TiledMapTileset tileset, i
var tilesetTile = tileset.Tiles.FirstOrDefault(t => t.LocalTileIdentifier == localId);
if (tilesetTile == null && createStub) {
if (!TiledExtensions.StubTilesetTiles.TryGetValue(localId, out tilesetTile)) {
tilesetTile = new TiledMapTilesetTile(localId);
tilesetTile = new TiledMapTilesetTile(localId, null, null);
TiledExtensions.StubTilesetTiles.Add(localId, tilesetTile);
}
}
Expand Down
12 changes: 11 additions & 1 deletion MLEM.FNA.sln
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FNA", "ThirdParty\FNA\FNA.c
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FontStashSharp.FNA", "ThirdParty\FontStashSharp\src\XNA\FontStashSharp.FNA.csproj", "{39249E92-EBF2-4951-A086-AB4951C3CCE1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FNA.Core", "ThirdParty\FNA\FNA.Core.csproj", "{458FFA5E-A1C4-4B23-A5D8-259385FEECED}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FNA.Extended", "ThirdParty\MonoGame.Extended\source\MonoGame.Extended\FNA.Extended.csproj", "{B7F73499-9BF0-487D-B20E-B4B67EB3A4EA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FNA.NetStandard", "ThirdParty\FNA\FNA.NetStandard.csproj", "{1A736385-E931-40A9-BBE0-A9286AB2F6B2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -72,5 +74,13 @@ Global
{458FFA5E-A1C4-4B23-A5D8-259385FEECED}.Debug|Any CPU.Build.0 = Debug|x64
{458FFA5E-A1C4-4B23-A5D8-259385FEECED}.Release|Any CPU.ActiveCfg = Release|x64
{458FFA5E-A1C4-4B23-A5D8-259385FEECED}.Release|Any CPU.Build.0 = Release|x64
{B7F73499-9BF0-487D-B20E-B4B67EB3A4EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B7F73499-9BF0-487D-B20E-B4B67EB3A4EA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B7F73499-9BF0-487D-B20E-B4B67EB3A4EA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B7F73499-9BF0-487D-B20E-B4B67EB3A4EA}.Release|Any CPU.Build.0 = Release|Any CPU
{1A736385-E931-40A9-BBE0-A9286AB2F6B2}.Debug|Any CPU.ActiveCfg = Debug|x64
{1A736385-E931-40A9-BBE0-A9286AB2F6B2}.Debug|Any CPU.Build.0 = Debug|x64
{1A736385-E931-40A9-BBE0-A9286AB2F6B2}.Release|Any CPU.ActiveCfg = Release|x64
{1A736385-E931-40A9-BBE0-A9286AB2F6B2}.Release|Any CPU.Build.0 = Release|x64
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion ThirdParty/FNA
Submodule FNA updated 317 files
2 changes: 1 addition & 1 deletion ThirdParty/FontStashSharp
Submodule FontStashSharp updated 45 files
+6 −4 Directory.Build.props
+2 −2 README.md
+7 −0 build/FontStashSharp.MonoGame.sln
+1 −1 samples/FontStashSharp.Samples.CustomRasterizers/FontStashSharp.Samples.CustomRasterizers.MonoGame.csproj
+25 −0 samples/FontStashSharp.Samples.DisableAntialiasing/FontStashSharp.Samples.DisableAntialiasing.MonoGame.csproj
+104 −0 samples/FontStashSharp.Samples.DisableAntialiasing/Game1.cs
+ samples/FontStashSharp.Samples.DisableAntialiasing/Icon.ico
+20 −0 samples/FontStashSharp.Samples.DisableAntialiasing/Program.cs
+1 −1 samples/FontStashSharp.Samples.DynamicSpriteFont/FontStashSharp.Samples.DynamicSpriteFont.FNA.Core.csproj
+1 −1 samples/FontStashSharp.Samples.DynamicSpriteFont/FontStashSharp.Samples.DynamicSpriteFont.MonoGame.csproj
+4 −0 samples/FontStashSharp.Samples.DynamicSpriteFont/FontStashSharp.Samples.DynamicSpriteFont.Stride.csproj
+0 −1 samples/FontStashSharp.Samples.DynamicSpriteFont/Game1.cs
+1 −1 samples/FontStashSharp.Samples.MeasureString/FontStashSharp.Samples.MeasureString.MonoGame.csproj
+1 −1 samples/FontStashSharp.Samples.MonoGameBackend/FontStashSharp.Samples.MonoGameBackend.csproj
+1 −1 samples/FontStashSharp.Samples.MonoGameBackendRotating/FontStashSharp.Samples.MonoGameBackendRotating.csproj
+1 −1 samples/FontStashSharp.Samples.RichText/FontStashSharp.Samples.RichText.FNA.Core.csproj
+1 −1 samples/FontStashSharp.Samples.RichText/FontStashSharp.Samples.RichText.MonoGame.csproj
+5 −1 samples/FontStashSharp.Samples.RichText/FontStashSharp.Samples.RichText.Stride.csproj
+1 −0 samples/FontStashSharp.Samples.RichText/Game1.cs
+1 −1 samples/FontStashSharp.Samples.RotatingText/FontStashSharp.Samples.RotatingText.MonoGame.csproj
+5 −0 samples/FontStashSharp.Samples.RotatingText/FontStashSharp.Samples.RotatingText.Stride.csproj
+1 −1 samples/FontStashSharp.Samples.StaticSpriteFont/FontStashSharp.Samples.StaticSpriteFont.FNA.Core.csproj
+1 −1 samples/FontStashSharp.Samples.StaticSpriteFont/FontStashSharp.Samples.StaticSpriteFont.MonoGame.csproj
+4 −0 samples/FontStashSharp.Samples.StaticSpriteFont/FontStashSharp.Samples.StaticSpriteFont.Stride.csproj
+1 −1 samples/FontStashSharp.Samples.TextureAtlasFull/FontStashSharp.Samples.TextureAtlasFull.MonoGame.csproj
+4 −0 samples/Fonts/license.txt
+ samples/Fonts/pixel_perfect.ttf
+26 −0 samples/Fonts/read me.txt
+1 −1 src/FontStashSharp.Tests/FontStashSharp.Tests.MonoGame.csproj
+22 −0 src/FontStashSharp.Tests/RichTextLayoutTests.cs
+12 −174 src/FontStashSharp/FontAtlas.cs
+45 −30 src/FontStashSharp/FontSystem.cs
+4 −0 src/FontStashSharp/FontSystemDefaults.cs
+8 −0 src/FontStashSharp/FontSystemSettings.cs
+205 −0 src/FontStashSharp/GlyphRenderers.cs
+49 −10 src/FontStashSharp/RichText/LayoutBuilder.cs
+7 −7 src/FontStashSharp/RichText/TextChunk.cs
+4 −4 src/FontStashSharp/SpriteFontBase.IFontStashRenderer.cs
+3 −3 src/FontStashSharp/SpriteFontBase.IFontStashRenderer2.cs
+18 −0 src/FontStashSharp/TextSource.cs
+0 −10 src/FontStashSharp/Utility.cs
+2 −2 src/XNA/FontStashSharp.FNA.Core.csproj
+26 −0 src/XNA/FontStashSharp.FNA.NetStandard.csproj
+1 −1 src/XNA/FontStashSharp.MonoGame.csproj
+1 −2 src/XNA/FontStashSharp.Stride.csproj
1 change: 1 addition & 0 deletions ThirdParty/MonoGame.Extended
Submodule MonoGame.Extended added at 4beea3

0 comments on commit fa1cafd

Please sign in to comment.