Respect fadein/out for Window.DrawConditions() and Window.IsOpen

This commit is contained in:
goaaats 2025-05-10 18:37:34 +02:00
parent 5c33d150cd
commit c33a5346b1

View file

@ -41,6 +41,10 @@ public abstract class Window
private bool internalLastIsOpen = false;
private bool internalIsOpen = false;
private bool internalWantsToClose = false;
private bool internalLastDrawConditions = true;
private bool internalDrawConditions = true;
private bool internalIsPinned = false;
private bool internalIsClickthrough = false;
private bool didPushInternalAlpha = false;
@ -229,7 +233,18 @@ public abstract class Window
public bool IsOpen
{
get => this.internalIsOpen;
set => this.internalIsOpen = value;
set
{
if (!value && this.internalIsOpen)
{
this.internalWantsToClose = true;
}
else if (value && !this.internalIsOpen)
{
this.internalWantsToClose = false;
this.internalIsOpen = true;
}
}
}
private bool CanShowCloseButton => this.ShowCloseButton && !this.internalIsClickthrough;
@ -360,22 +375,7 @@ public abstract class Window
UIGlobals.PlaySoundEffect(this.OnCloseSfxId);
}
if (this.fadeOutTexture != null)
{
this.fadeOutTimer -= ImGui.GetIO().DeltaTime;
if (this.fadeOutTimer <= 0f)
{
this.fadeOutTexture.Dispose();
this.fadeOutTexture = null;
this.OnSafeToRemove();
}
else
{
this.DrawFakeFadeOutWindow();
}
}
this.fadeInTimer = doFades ? 0f : FadeInOutTime;
DrawFadeOut();
return;
}
@ -384,8 +384,15 @@ public abstract class Window
this.fadeInTimer = FadeInOutTime;
this.Update();
if (!this.DrawConditions())
this.internalDrawConditions = this.DrawConditions();
if (this.internalDrawConditions == this.internalLastDrawConditions && !this.internalDrawConditions)
{
DrawFadeOut();
return;
}
if (this.internalDrawConditions)
this.internalLastDrawConditions = this.internalDrawConditions;
var hasNamespace = !string.IsNullOrEmpty(this.Namespace);
@ -607,12 +614,21 @@ public abstract class Window
this.pushedFadeInAlpha = false;
}
if (!this.internalIsOpen && this.fadeOutTexture == null && doFades)
if (this.internalDrawConditions != this.internalLastDrawConditions && !this.internalDrawConditions)
{
this.fadeOutTexture = Service<TextureManager>.Get().CreateDrawListTexture(
"WindowFadeOutTexture");
this.fadeOutTexture.ResizeAndDrawWindow(this.WindowName, Vector2.One);
this.fadeOutTimer = FadeInOutTime;
this.internalLastDrawConditions = this.internalDrawConditions;
SetupFadeOut();
}
if (this.internalWantsToClose)
{
this.internalIsOpen = false;
this.internalWantsToClose = false;
}
if (!this.internalIsOpen)
{
SetupFadeOut();
}
if (printWindow)
@ -632,6 +648,38 @@ public abstract class Window
if (hasNamespace)
ImGui.PopID();
return;
void SetupFadeOut()
{
if (this.fadeOutTexture == null && doFades)
{
this.fadeOutTexture = Service<TextureManager>.Get().CreateDrawListTexture(
"WindowFadeOutTexture");
this.fadeOutTexture.ResizeAndDrawWindow(this.WindowName, Vector2.One);
this.fadeOutTimer = FadeInOutTime;
}
}
void DrawFadeOut()
{
if (this.fadeOutTexture != null)
{
this.fadeOutTimer -= ImGui.GetIO().DeltaTime;
if (this.fadeOutTimer <= 0f)
{
this.fadeOutTexture.Dispose();
this.fadeOutTexture = null;
this.OnSafeToRemove();
}
else
{
this.DrawFakeFadeOutWindow();
}
}
this.fadeInTimer = doFades ? 0f : FadeInOutTime;
}
}
private unsafe void ApplyConditionals()