This commit is contained in:
Oscar
2025-06-10 23:24:50 +03:00
parent de85b85b13
commit 5c9be94aba
24 changed files with 1187 additions and 580 deletions

View File

@@ -4,7 +4,7 @@ namespace Sandbox.UI;
public abstract class InteractionButton : Component, Component.IPressable
{
[Property] public string Label { get; set; } = "Label";
[Property] public virtual string Label { get; set; } = "Label";
[Property] public bool RequiresHold { get; set; } = false;
private HoverInfoPanel _uiPanel;
private GameObject _interactionPanelPrefab { get; set; }
@@ -12,25 +12,24 @@ public abstract class InteractionButton : Component, Component.IPressable
protected override void OnStart()
{
base.OnStart();
_interactionPanelPrefab = GameObject.GetPrefab("prefabs/InteractionPanel.prefab");
Log.Info(_interactionPanelPrefab.Name);
Assert.True(_interactionPanelPrefab.IsValid(), $"No InteractionPanel prefab found for {GameObject.Name}!");
_interactionPanelPrefab = GameObject.GetPrefab( "prefabs/InteractionPanel.prefab" );
Assert.True( _interactionPanelPrefab.IsValid(), $"No InteractionPanel prefab found for {GameObject.Name}!" );
}
public virtual void Hover(IPressable.Event e)
public virtual void Hover( IPressable.Event e )
{
CreatePanel();
}
public virtual void Blur(IPressable.Event e)
public virtual void Blur( IPressable.Event e )
{
DestroyPanel();
}
public virtual void Look(IPressable.Event e)
public virtual void Look( IPressable.Event e )
{
if (_uiPanel != null)
if ( _uiPanel != null )
{
_uiPanel.ProgressionHold = 0f;
}
@@ -40,34 +39,39 @@ public abstract class InteractionButton : Component, Component.IPressable
{
return true;
}
public virtual bool Press(IPressable.Event e)
public virtual bool Press( IPressable.Event e )
{
if (_uiPanel != null)
// // Проверяем, что событие относится именно к этому объекту
// if ( e.Source.GameObject != this.GameObject )
// return false; // Игнорируем, событие для другого объекта
if ( _uiPanel != null )
{
_uiPanel?.SetPressed(true);
_uiPanel.SetPressed( true );
}
return true;
return false;
}
public virtual void Release(IPressable.Event e)
public virtual void Release( IPressable.Event e )
{
if (_uiPanel != null)
if ( _uiPanel != null )
{
_uiPanel?.SetPressed(false);
_uiPanel?.SetPressed( false );
}
}
protected void CreatePanel()
{
if (_uiPanel != null) return;
if ( _uiPanel != null ) return;
var panelGo = _interactionPanelPrefab.Clone();
panelGo.WorldPosition = WorldPosition;
panelGo.Parent = Scene;
_uiPanel = panelGo.Components.Get<HoverInfoPanel>();
if (_uiPanel != null)
if ( _uiPanel != null )
{
_uiPanel.InteractionString = Label;
_uiPanel.IsHoldInteraction = RequiresHold;
@@ -75,13 +79,13 @@ public abstract class InteractionButton : Component, Component.IPressable
}
}
protected async void DestroyPanel()
protected void DestroyPanel()
{
if (_uiPanel == null) return;
if ( _uiPanel == null ) return;
_uiPanel.GameObject.Destroy();
_uiPanel = null;
await Task.DelaySeconds(0.05f);
// await Task.DelaySeconds(0.05f);
}
}

View File

@@ -13,13 +13,20 @@ public sealed class TeleportMazeButton : InteractionButton
public override bool Press( IPressable.Event e )
{
base.Press( e );
if ( Maze.IsValid() )
{
Maze.RpcRequestMaze();
}
DoTeleport();
return true;
return false;
// if ( Maze.IsValid() )
// {
// Maze.RpcRequestMaze();
// }
// else
// {
// Log.Info( "pressed teleport maze" );
// return false;
// }
//
// DoTeleport();
// return true;
}
private async void DoTeleport()