using Godot; namespace Cirno.Scripts.Actors; [Tool] public partial class PreviewMarker3D : Marker3D { private Texture2D _texture; protected Texture2D Texture { get => _texture; set { _texture = value; if (Engine.IsEditorHint()) { QueueRedraw(); } } } private bool _fixedSize; private bool _billboard; private float _pixelSize = 0.1f; [Export] protected bool FixedSize { get => _fixedSize; set { _fixedSize = value; if (Engine.IsEditorHint()) { QueueRedraw(); } } } [Export] protected bool Billboard { get => _billboard; set { _billboard = value; if (Engine.IsEditorHint()) { QueueRedraw(); } } } [Export] protected float PixelSize { get => _pixelSize; set { _pixelSize = value; if (Engine.IsEditorHint()) { QueueRedraw(); } } } [ExportToolButton("Update Icon")] public Callable RedrawButton => Callable.From(Redraw); [ExportToolButton("Clear Children")] public Callable ClearChildrenButton => Callable.From(ClearChildren); private Sprite3D _sprite; public override void _Ready() { _sprite = GetNodeOrNull("Sprite3D"); ClearChildren(); if (Engine.IsEditorHint()) { QueueRedraw(); return; } } private void Redraw() { QueueRedraw(); } private void ClearChildren() { var children = GetChildren(); foreach (var child in children) { if (child is Sprite3D) { child.QueueFree(); } } _sprite = null; } protected void QueueRedraw() { if (!Engine.IsEditorHint()) return; if (_texture is null) return; if (_sprite is null) { //GD.Print("Remaking sprite"); _sprite = new EditorSprite3D(); this.AddChild(_sprite); //_sprite.Owner = GetTree().EditedSceneRoot; } _sprite.Texture = _texture; //_sprite.SetRotationDegrees(new Vector3(-45, 45, 0)); _sprite.FixedSize = FixedSize; _sprite.SetBillboardMode(Billboard ? BaseMaterial3D.BillboardModeEnum.Enabled : BaseMaterial3D.BillboardModeEnum.Disabled); _sprite.TextureFilter = BaseMaterial3D.TextureFilterEnum.Nearest; _sprite.PixelSize = PixelSize; } protected void SetSpriteAlpha(float alpha) { if (!Engine.IsEditorHint()) return; if (_sprite is not null) { //GD.Print($"Modulating sprite to {alpha}"); _sprite.SetModulate(new Color(_sprite.Modulate.R, _sprite.Modulate.G, _sprite.Modulate.B, alpha)); } else { GD.Print("Sprite was null"); } } }