using Cthangover.Core.Factories.Impls; using Cthangover.Core.Scenes; using Cthangover.Mods.Dialog.Action; using Cthangover.Mods.Time; using Cthangover.Mods.Interface.View; using Godot; using Cthangover.Core.UI; using Cthangover.Mods.Interface.Base.Lists; using Cthangover.Core.UI.Dialog; using Cthangover.Core.UI.Event; using Cthangover.Core.UI.Executable; using Cthangover.Core.Scenarios; using Cthangover.Core.Interactive; namespace Cthangover.Mods.Dialog.Action.Impls { /// /// Sets the scene background on the ViewBox, including depth and albedo maps /// for the lighting system. Resolves textures through BackgroundFactory on /// construction (OnStartQueue) — depth and albedo are loaded from the same /// sprite ID with "_depth" / "_albedo" suffixes. Kills any in-progress /// background transition before setting the new texture. Textures are nulled /// after application to prevent stale reuse across dialog restarts. /// Sets SceneContextNode.LastBackgroundID so the scene manager can restore /// the correct background on scene revisit. /// public class ActionBackground : ActionCommand { /// Sprite resource ID resolved through on construction. Also loads depth (_depth) and albedo (_albedo) variants. public string SpriteID { get; set; } /// Direct texture override. When non-null, bypasses factory resolution. Set to null after application to prevent stale reuse. public Texture2D Texture { get; set; } /// Depth map for the lighting system, loaded from + "_depth". public Texture2D DepthTexture { get; set; } /// Albedo color map for the lighting system, loaded from + "_albedo". public Texture2D AlbedoTexture { get; set; } /// Preloads textures when the dialog queue is first created, resolving SpriteID through the factory. public override ConstructType ConstructType { get; set; } = ConstructType.OnStartQueue; /// Background is set imperatively — the dialog continues immediately. public override WaitType WaitType { get; set; } = WaitType.NoWait; /// Resolves plus its _depth/_albedo variants through the background factory. public override void DoConstruct() { base.DoConstruct(); if (Texture == null && !string.IsNullOrEmpty(SpriteID)) Texture = BackgroundFactory.Instance.Get(SpriteID); if (!string.IsNullOrEmpty(SpriteID)) { DepthTexture = BackgroundFactory.Instance.Get(SpriteID + "_depth"); AlbedoTexture = BackgroundFactory.Instance.Get(SpriteID + "_albedo"); } } /// /// Applies the background to the ViewBox, kills any in-flight background /// transition and feeds the depth/albedo maps to the light controller. /// Consumed textures are nulled so a reused action cannot re-apply stale data. /// public override void DoRun(DialogRuntime runtime) { if (Texture == null) return; SceneContextNode.LastBackgroundID = SpriteID; var viewBox = Scene.Find("ViewBox"); viewBox?.KillTransitionTween(); viewBox?.SetBackgroundTexture(Texture); var controller = UiLightController.Instance; controller?.SetupDepthMap(DepthTexture); controller?.SetupAlbedoMap(AlbedoTexture); Texture = null; DepthTexture = null; AlbedoTexture = null; } } }