1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-05-10 19:38:43 +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)
### MLEM.Ui
Fixes
- Fixed images not updating their hidden state properly when the displayed texture changes
## 6.1.0
### MLEM

View file

@ -30,13 +30,12 @@ namespace MLEM.Ui.Elements {
/// </summary>
public TextureRegion Texture {
get {
var ret = this.GetTextureCallback?.Invoke(this) ?? this.texture;
this.CheckTextureChange(ret);
return ret;
this.CheckTextureChange();
return this.displayedTexture;
}
set {
this.texture = value;
this.CheckTextureChange(value);
this.explicitlySetTexture = value;
this.CheckTextureChange();
}
}
/// <summary>
@ -75,8 +74,8 @@ namespace MLEM.Ui.Elements {
public override bool IsHidden => base.IsHidden || this.Texture == null;
private bool scaleToImage;
private TextureRegion texture;
private TextureRegion lastTexture;
private TextureRegion explicitlySetTexture;
private TextureRegion displayedTexture;
/// <summary>
/// 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);
}
/// <inheritdoc />
public override void Update(GameTime time) {
this.CheckTextureChange();
base.Update(time);
}
/// <inheritdoc />
public override void Draw(GameTime time, SpriteBatch batch, float alpha, SpriteBatchContext context) {
if (this.Texture == null)
@ -123,11 +128,12 @@ namespace MLEM.Ui.Elements {
base.Draw(time, batch, alpha, context);
}
private void CheckTextureChange(TextureRegion newTexture) {
if (this.lastTexture == newTexture)
private void CheckTextureChange() {
var newTexture = this.GetTextureCallback?.Invoke(this) ?? this.explicitlySetTexture;
if (this.displayedTexture == newTexture)
return;
var nullChanged = this.lastTexture == null != (newTexture == null);
this.lastTexture = newTexture;
var nullChanged = this.displayedTexture == null != (newTexture == null);
this.displayedTexture = newTexture;
if (nullChanged || this.scaleToImage)
this.SetAreaDirty();
}