daily update on 20240828 by nitload youmu, autotexture added

This commit is contained in:
Nitload
2024-08-28 10:58:31 +08:00
parent d082071f2d
commit 1ee4e4a42f
586 changed files with 60910 additions and 123106 deletions
@@ -35,81 +35,183 @@ using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Controls
{
public delegate void RenderButtonTextureCallback(ButtonStatus status, float beginTime, in TextureProvider texture);
public enum ButtonStatus
{
Error = 0b0,
Disable = 0b1,
Enable = 0b10,
Highlight = 0b100,
Confirm = 0b1000,
DisableToEnable = Disable | Enable,
EnableToDisable = -(Enable | DisableToEnable),
EnableToHighlight = Enable | Highlight,
HighlightToEnable = -(Enable | Highlight),
HighlightToDisable = -(Highlight | Disable),
}
public class TriggerButton : ControllingItem
{
private AnimationBuilder switchAnimationBuilder;
private Action? confirmCallback;
private Action? disableCallback;
#nullable enable
private Action? enableAction;
private Action? disableAction;
private Action? confirmAction;
private Action? enableCallback;
private float _statusBeginTime;
private RenderButtonTextureCallback _renderButton;
private TextureProvider _texture;
#nullable restore
public override vec4d[] TextureBox
public TriggerButton()
{
get { return switchAnimationBuilder.TextureFrame.VertexStream; }
}
public bool IsHighLighted { get; internal set; }
public bool IsDisabled { get; internal set; }
public event Action EnableEvent
{
add { enableAction += value; }
remove { enableAction -= value; }
}
public event Action DisableEvent
{
add { disableAction += value; }
remove { disableAction -= value; }
CurrentStatus = ButtonStatus.Disable;
}
public event Action ConfirmEvent
{
add { confirmAction += value; }
remove { confirmAction -= value; }
add { confirmCallback += value; }
remove { confirmCallback -= value; }
}
public void Enable(AnimationBuilder animation)
public event Action DisableEvent
{
if (!IsDisabled)
add { disableCallback += value; }
remove { disableCallback -= value; }
}
public event Action EnableEvent
{
add { enableCallback += value; }
remove { enableCallback -= value; }
}
public event RenderButtonTextureCallback RenderButtonTexture
{
add
{
if (_renderButton == null)
{
_renderButton = value;
}
else
{
_renderButton += value;
}
}
remove
{
if (_renderButton != null)
{
_renderButton -= value;
}
}
}
public bool IsHighLighted { get; internal set; }
public bool IsDisabled { get; internal set; }
public bool IsEntity => true;
public ReadOnlySpan<vec4d> TextureBox
{
get => MemoryMarshal.Cast<vec2d, vec4d>(_texture.TextureCoordinate);
}
public Rectangle BoundingBox { get; set; }
public TriggerButton Left { get; internal set; }
public TriggerButton Right { get; internal set; }
public TriggerButton Up { get; internal set; }
public TriggerButton Down { get; internal set; }
public vec2d Position { get; set; }
internal TextureProvider Texture
{
get => _texture;
set => _texture = value;
}
protected ButtonStatus CurrentStatus { get; set; }
public void DeHighlight()
{
if (CurrentStatus == ButtonStatus.Highlight)
{
CurrentStatus = ButtonStatus.HighlightToEnable;
}
}
public void Disable()
{
CurrentStatus = CurrentStatus switch
{
ButtonStatus.Enable => ButtonStatus.EnableToDisable,
ButtonStatus.Highlight => ButtonStatus.HighlightToDisable,
_ => CurrentStatus,
};
if (disableCallback != null)
{
disableCallback();
}
}
public void Enable()
{
if (CurrentStatus == ButtonStatus.Disable)
{
CurrentStatus = ButtonStatus.DisableToEnable;
}
else
{
return;
}
if (switchAnimationBuilder == null || switchAnimationBuilder.IsComplete)
if (enableCallback != null)
{
switchAnimationBuilder = animation;
enableCallback();
}
if( enableAction != null)enableAction();
}
public void Disable(AnimationBuilder animation)
public IEnumerator<PlainGeometryMesh> GetEnumerator()
{
if (switchAnimationBuilder == null || switchAnimationBuilder.IsComplete)
{
switchAnimationBuilder = animation;
}
if (disableAction != null) disableAction();
_renderButton(CurrentStatus, _statusBeginTime, in _texture);
yield return new PlainGeometryMesh(this.BoundingBox, _texture);
}
public void Highlight(AnimationBuilder animation)
public void Highlight()
{
if (switchAnimationBuilder == null || switchAnimationBuilder.IsComplete)
if (CurrentStatus == ButtonStatus.Enable)
{
switchAnimationBuilder = animation;
CurrentStatus |= ButtonStatus.EnableToHighlight;
}
else
{
return;
}
if (confirmCallback != null)
{
confirmCallback();
}
if (confirmAction != null) confirmAction();
}
public override IEnumerator<PlainGeometryMesh> GetEnumerator()
internal void Init(ButtonStatus status)
{
yield return new PlainGeometryMesh(this.BoundingBox, switchAnimationBuilder.GetAnimationFrame(),
this.TextureBox);
if (CurrentStatus == ButtonStatus.Error)
{
CurrentStatus = status;
}
}
}//----------------------------------- End of class --------------------------------------------