From 6a8e9639c163f637d140bc89e9283268b23d1338 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 13 Dec 2023 22:06:12 +0100 Subject: [PATCH 1/3] updated dependencies --- CHANGELOG.md | 4 ++++ Demos/Demos.FNA.csproj | 2 +- Demos/Demos.csproj | 2 +- MLEM.Extended/Font/GenericStashFont.cs | 2 +- MLEM.Extended/MLEM.Extended.csproj | 2 +- Sandbox/Sandbox.csproj | 2 +- Tests/Tests.FNA.csproj | 9 +++------ Tests/Tests.csproj | 9 +++------ ThirdParty/FNA | 2 +- ThirdParty/FontStashSharp | 2 +- 10 files changed, 17 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f772185..7cd5203 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,10 @@ Fixes - Fixed panels updating their relevant children too much when the scroll bar is hidden - Fixed a stack overflow exception when a panel's scroll bar auto-hiding causes elements to gain height +### MLEM.Extended +Improvements +- Updated to FontStashSharp 1.3.0's API + ### MLEM.Data Fixes - Fixed various exception types not being wrapped by ContentLoadExceptions when loading raw or JSON content diff --git a/Demos/Demos.FNA.csproj b/Demos/Demos.FNA.csproj index dbb05db..9af1d93 100644 --- a/Demos/Demos.FNA.csproj +++ b/Demos/Demos.FNA.csproj @@ -1,7 +1,7 @@  - netstandard2.0 + net8.0 Demos $(DefineConstants);FNA false diff --git a/Demos/Demos.csproj b/Demos/Demos.csproj index 31946ae..fd1516b 100644 --- a/Demos/Demos.csproj +++ b/Demos/Demos.csproj @@ -1,7 +1,7 @@  - netstandard2.0 + net8.0 false diff --git a/MLEM.Extended/Font/GenericStashFont.cs b/MLEM.Extended/Font/GenericStashFont.cs index a6f2b9e..f9a5b74 100644 --- a/MLEM.Extended/Font/GenericStashFont.cs +++ b/MLEM.Extended/Font/GenericStashFont.cs @@ -38,7 +38,7 @@ namespace MLEM.Extended.Font { /// protected override void DrawCharacter(SpriteBatch batch, int codePoint, string character, Vector2 position, Color color, float rotation, Vector2 scale, SpriteEffects effects, float layerDepth) { - this.Font.DrawText(batch, character, position, color, scale, rotation, Vector2.Zero, layerDepth); + this.Font.DrawText(batch, character, position, color, rotation, Vector2.Zero, scale, layerDepth); } } diff --git a/MLEM.Extended/MLEM.Extended.csproj b/MLEM.Extended/MLEM.Extended.csproj index 3e8fd8f..59fca03 100644 --- a/MLEM.Extended/MLEM.Extended.csproj +++ b/MLEM.Extended/MLEM.Extended.csproj @@ -27,7 +27,7 @@ all - + all diff --git a/Sandbox/Sandbox.csproj b/Sandbox/Sandbox.csproj index f3e3703..a1b5759 100644 --- a/Sandbox/Sandbox.csproj +++ b/Sandbox/Sandbox.csproj @@ -19,7 +19,7 @@ - + diff --git a/Tests/Tests.FNA.csproj b/Tests/Tests.FNA.csproj index 7ce18a8..ed57fb9 100644 --- a/Tests/Tests.FNA.csproj +++ b/Tests/Tests.FNA.csproj @@ -21,12 +21,9 @@ - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index c4f10d0..013fba0 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -20,12 +20,9 @@ - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + diff --git a/ThirdParty/FNA b/ThirdParty/FNA index d0a0892..354e216 160000 --- a/ThirdParty/FNA +++ b/ThirdParty/FNA @@ -1 +1 @@ -Subproject commit d0a0892f17dd8bebd36319294509cdca8ae8c810 +Subproject commit 354e2161b759fa052b25e94209d6ea463aaf098f diff --git a/ThirdParty/FontStashSharp b/ThirdParty/FontStashSharp index c50bf54..2d40e9f 160000 --- a/ThirdParty/FontStashSharp +++ b/ThirdParty/FontStashSharp @@ -1 +1 @@ -Subproject commit c50bf544bcfb217b518727a0a38eb71fc5725092 +Subproject commit 2d40e9f0f681595dbd4341a3e5a64ed6e31f9556 From b935bd0a6115854ae888eb8892636d136b3b2667 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 13 Dec 2023 22:57:23 +0100 Subject: [PATCH 2/3] Added the ability to set a custom SamplerState for images --- CHANGELOG.md | 1 + MLEM.Ui/Elements/Image.cs | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cd5203..19b2844 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ Fixes Additions - Added UiControls.NavType, which stores the most recently used type of ui navigation - Added SetWidthBasedOnAspect and SetHeightBasedOnAspect to images +- Added the ability to set a custom SamplerState for images Improvements - Allow scrolling panels to contain other scrolling panels diff --git a/MLEM.Ui/Elements/Image.cs b/MLEM.Ui/Elements/Image.cs index f53f64b..2c09d20 100644 --- a/MLEM.Ui/Elements/Image.cs +++ b/MLEM.Ui/Elements/Image.cs @@ -96,6 +96,11 @@ namespace MLEM.Ui.Elements { } } } + /// + /// The sampler state that this image's should be drawn with. + /// If this is , the current 's will be used, which will likely be the same as . + /// + public SamplerState SamplerState; /// public override bool IsHidden => base.IsHidden || this.Texture == null; @@ -153,6 +158,14 @@ namespace MLEM.Ui.Elements { public override void Draw(GameTime time, SpriteBatch batch, float alpha, SpriteBatchContext context) { if (this.Texture == null) return; + + if (this.SamplerState != null) { + batch.End(); + var localContext = context; + localContext.SamplerState = this.SamplerState; + batch.Begin(localContext); + } + var center = new Vector2(this.Texture.Width / 2F, this.Texture.Height / 2F); var color = this.Color.OrDefault(Microsoft.Xna.Framework.Color.White) * alpha; if (this.MaintainImageAspect) { @@ -163,6 +176,12 @@ namespace MLEM.Ui.Elements { var scale = new Vector2(1F / this.Texture.Width, 1F / this.Texture.Height) * this.DisplayArea.Size; batch.Draw(this.Texture, this.DisplayArea.Location + center * scale, color, this.ImageRotation, center, scale * this.ImageScale, this.ImageEffects, 0); } + + if (this.SamplerState != null) { + batch.End(); + batch.Begin(context); + } + base.Draw(time, batch, alpha, context); } From 7d314a589e8d910a626ac4ef1dcc30ca046e5b94 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sat, 16 Dec 2023 21:37:49 +0100 Subject: [PATCH 3/3] improved Element ToString --- MLEM.Ui/Elements/Element.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/MLEM.Ui/Elements/Element.cs b/MLEM.Ui/Elements/Element.cs index 3daa80d..45eb7cf 100644 --- a/MLEM.Ui/Elements/Element.cs +++ b/MLEM.Ui/Elements/Element.cs @@ -1236,12 +1236,13 @@ namespace MLEM.Ui.Elements { /// public override string ToString() { - var ret = this.GetType().ToString(); - // elements will contain their path up to the root (Paragraph@Panel@...@RootName) + var ret = this.GetType().Name; + // elements will contain their path up to the root and their index in each parent + // eg Paragraph 2 @ Panel 3 @ ... @ Group RootName if (this.Parent != null) { - ret += $"@{this.Parent}"; + ret += $" {this.Parent.Children.IndexOf(this)} @ {this.Parent}"; } else if (this.Root?.Element == this) { - ret += $"@{this.Root.Name}"; + ret += $" {this.Root.Name}"; } return ret; }