1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-05-23 00:53:37 +02:00

Fixed images not updating their hidden state properly when the displayed texture changes

This commit is contained in:
Ell 2023-02-03 11:31:18 +01:00
parent 7f7a9c6415
commit 6be4143331
2 changed files with 21 additions and 11 deletions

View file

@ -12,6 +12,10 @@ Jump to version:
## 6.2.0 (In Development) ## 6.2.0 (In Development)
### MLEM.Ui
Fixes
- Fixed images not updating their hidden state properly when the displayed texture changes
## 6.1.0 ## 6.1.0
### MLEM ### MLEM

View file

@ -30,13 +30,12 @@ namespace MLEM.Ui.Elements {
/// </summary> /// </summary>
public TextureRegion Texture { public TextureRegion Texture {
get { get {
var ret = this.GetTextureCallback?.Invoke(this) ?? this.texture; this.CheckTextureChange();
this.CheckTextureChange(ret); return this.displayedTexture;
return ret;
} }
set { set {
this.texture = value; this.explicitlySetTexture = value;
this.CheckTextureChange(value); this.CheckTextureChange();
} }
} }
/// <summary> /// <summary>
@ -75,8 +74,8 @@ namespace MLEM.Ui.Elements {
public override bool IsHidden => base.IsHidden || this.Texture == null; public override bool IsHidden => base.IsHidden || this.Texture == null;
private bool scaleToImage; private bool scaleToImage;
private TextureRegion texture; private TextureRegion explicitlySetTexture;
private TextureRegion lastTexture; private TextureRegion displayedTexture;
/// <summary> /// <summary>
/// Creates a new image with the given settings /// Creates a new image with the given settings
@ -106,6 +105,12 @@ namespace MLEM.Ui.Elements {
return this.Texture != null && this.scaleToImage ? this.Texture.Size.ToVector2() * this.Scale : base.CalcActualSize(parentArea); return this.Texture != null && this.scaleToImage ? this.Texture.Size.ToVector2() * this.Scale : base.CalcActualSize(parentArea);
} }
/// <inheritdoc />
public override void Update(GameTime time) {
this.CheckTextureChange();
base.Update(time);
}
/// <inheritdoc /> /// <inheritdoc />
public override void Draw(GameTime time, SpriteBatch batch, float alpha, SpriteBatchContext context) { public override void Draw(GameTime time, SpriteBatch batch, float alpha, SpriteBatchContext context) {
if (this.Texture == null) if (this.Texture == null)
@ -123,11 +128,12 @@ namespace MLEM.Ui.Elements {
base.Draw(time, batch, alpha, context); base.Draw(time, batch, alpha, context);
} }
private void CheckTextureChange(TextureRegion newTexture) { private void CheckTextureChange() {
if (this.lastTexture == newTexture) var newTexture = this.GetTextureCallback?.Invoke(this) ?? this.explicitlySetTexture;
if (this.displayedTexture == newTexture)
return; return;
var nullChanged = this.lastTexture == null != (newTexture == null); var nullChanged = this.displayedTexture == null != (newTexture == null);
this.lastTexture = newTexture; this.displayedTexture = newTexture;
if (nullChanged || this.scaleToImage) if (nullChanged || this.scaleToImage)
this.SetAreaDirty(); this.SetAreaDirty();
} }