daily update on 20240828 by nitload youmu, autotexture added
This commit is contained in:
@@ -40,6 +40,9 @@ using System.Text;
|
||||
|
||||
namespace StgSharp.Controls
|
||||
{
|
||||
|
||||
public delegate void RenderButtonTextureCallback(ButtonStatus status, float beginTime, in TextureProvider texture);
|
||||
|
||||
public enum ButtonStatus
|
||||
{
|
||||
Error = 0b0,
|
||||
@@ -57,22 +60,19 @@ namespace StgSharp.Controls
|
||||
HighlightToDisable = -(Highlight | Disable),
|
||||
}
|
||||
|
||||
public delegate void RenderButtonTextureCallback(ButtonStatus status, float beginTime, in TextureProvider texture);
|
||||
|
||||
public class TriggerButton : ControllingItem
|
||||
{
|
||||
private TextureProvider _texture;
|
||||
private float _statusBeginTime;
|
||||
|
||||
public TriggerButton Left { get; internal set; }
|
||||
public TriggerButton Right { get; internal set; }
|
||||
public TriggerButton Up { get; internal set; }
|
||||
public TriggerButton Down { get; internal set; }
|
||||
private Action? confirmCallback;
|
||||
private Action? disableCallback;
|
||||
|
||||
#nullable enable
|
||||
private Action? enableCallback;
|
||||
private Action? disableCallback;
|
||||
private Action? confirmCallback;
|
||||
private float _statusBeginTime;
|
||||
|
||||
private RenderButtonTextureCallback _renderButton;
|
||||
private TextureProvider _texture;
|
||||
|
||||
#nullable restore
|
||||
|
||||
public TriggerButton()
|
||||
@@ -80,11 +80,25 @@ namespace StgSharp.Controls
|
||||
CurrentStatus = ButtonStatus.Disable;
|
||||
}
|
||||
|
||||
protected ButtonStatus CurrentStatus { get; set; }
|
||||
public event Action ConfirmEvent
|
||||
{
|
||||
add { confirmCallback += value; }
|
||||
remove { confirmCallback -= value; }
|
||||
}
|
||||
|
||||
private RenderButtonTextureCallback _renderButton;
|
||||
public event Action DisableEvent
|
||||
{
|
||||
add { disableCallback += value; }
|
||||
remove { disableCallback -= value; }
|
||||
}
|
||||
|
||||
public event RenderButtonTextureCallback RenderButtonTexture
|
||||
public event Action EnableEvent
|
||||
{
|
||||
add { enableCallback += value; }
|
||||
remove { enableCallback -= value; }
|
||||
}
|
||||
|
||||
public event RenderButtonTextureCallback RenderButtonTexture
|
||||
{
|
||||
add
|
||||
{
|
||||
@@ -97,7 +111,7 @@ namespace StgSharp.Controls
|
||||
_renderButton += value;
|
||||
}
|
||||
}
|
||||
remove
|
||||
remove
|
||||
{
|
||||
if (_renderButton != null)
|
||||
{
|
||||
@@ -106,48 +120,51 @@ namespace StgSharp.Controls
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public ReadOnlySpan<vec4d> TextureBox
|
||||
protected ButtonStatus CurrentStatus { get; set; }
|
||||
|
||||
public void DeHighlight()
|
||||
{
|
||||
get => MemoryMarshal.Cast<vec2d, vec4d>(_texture.TextureCoordinate);
|
||||
}
|
||||
|
||||
public bool IsHighLighted { get; internal set; }
|
||||
|
||||
public bool IsDisabled { get; internal set; }
|
||||
public vec2d Position { get; set; }
|
||||
public Rectangle BoundingBox { get; set; }
|
||||
|
||||
public bool IsEntity => true;
|
||||
|
||||
public event Action EnableEvent
|
||||
{
|
||||
add { enableCallback += value; }
|
||||
remove { enableCallback -= value; }
|
||||
}
|
||||
|
||||
public event Action DisableEvent
|
||||
{
|
||||
add { disableCallback += value; }
|
||||
remove { disableCallback -= value; }
|
||||
}
|
||||
|
||||
public event Action ConfirmEvent
|
||||
{
|
||||
add { confirmCallback += value; }
|
||||
remove { confirmCallback -= value; }
|
||||
}
|
||||
|
||||
internal void Init( ButtonStatus status )
|
||||
{
|
||||
if (CurrentStatus == ButtonStatus.Error)
|
||||
if (CurrentStatus == ButtonStatus.Highlight)
|
||||
{
|
||||
CurrentStatus = status;
|
||||
CurrentStatus = ButtonStatus.HighlightToEnable;
|
||||
}
|
||||
}
|
||||
|
||||
public void Disable()
|
||||
{
|
||||
CurrentStatus = CurrentStatus switch
|
||||
{
|
||||
ButtonStatus.Enable => ButtonStatus.EnableToDisable,
|
||||
ButtonStatus.Highlight => ButtonStatus.HighlightToDisable,
|
||||
_ => CurrentStatus,
|
||||
};
|
||||
if (disableCallback != null)
|
||||
{
|
||||
disableCallback();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,18 +178,16 @@ namespace StgSharp.Controls
|
||||
{
|
||||
return;
|
||||
}
|
||||
if ( enableCallback != null)enableCallback();
|
||||
if (enableCallback != null)
|
||||
{
|
||||
enableCallback();
|
||||
}
|
||||
}
|
||||
|
||||
public void Disable()
|
||||
public IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
{
|
||||
CurrentStatus = CurrentStatus switch
|
||||
{
|
||||
ButtonStatus.Enable => ButtonStatus.EnableToDisable,
|
||||
ButtonStatus.Highlight => ButtonStatus.HighlightToDisable,
|
||||
_ => CurrentStatus,
|
||||
};
|
||||
if (disableCallback != null) disableCallback();
|
||||
_renderButton(CurrentStatus, _statusBeginTime, in _texture);
|
||||
yield return new PlainGeometryMesh(this.BoundingBox, _texture);
|
||||
}
|
||||
|
||||
public void Highlight()
|
||||
@@ -185,21 +200,18 @@ namespace StgSharp.Controls
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (confirmCallback != null) confirmCallback();
|
||||
}
|
||||
|
||||
public void DeHighlight()
|
||||
{
|
||||
if (CurrentStatus == ButtonStatus.Highlight)
|
||||
if (confirmCallback != null)
|
||||
{
|
||||
CurrentStatus = ButtonStatus.HighlightToEnable;
|
||||
confirmCallback();
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
internal void Init(ButtonStatus status)
|
||||
{
|
||||
_renderButton(CurrentStatus,_statusBeginTime, in _texture);
|
||||
yield return new PlainGeometryMesh(this.BoundingBox, _texture);
|
||||
if (CurrentStatus == ButtonStatus.Error)
|
||||
{
|
||||
CurrentStatus = status;
|
||||
}
|
||||
}
|
||||
|
||||
}//----------------------------------- End of class --------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user