BITFALL/Assets/Artists/Scripts/UX/UXInventoryInspector.cs

83 lines
2.1 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using BITKit;
using BITKit.UX;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Interactions;
using UnityEngine.UIElements;
namespace BITFALL.UX
{
public class UXInventoryInspector : UIToolKitPanel
{
public static void Entry(IBasicItem item)
{
OnInspect?.Invoke(item);
}
public static event Action<IBasicItem> OnInspect;
public static VisualElement Container { get; private set; }
[SerializeField] private InputActionReference cancelAction;
[SerializeField] private InputActionReference inventoryAction;
private UXContainer _container;
[UXBindPath("modify-container")]
private VisualElement _modifyContainer;
protected override void Start()
{
base.Start();
OnInspect += OnInspectItem;
destroyCancellationToken.Register(() =>
{
OnInspect -= OnInspectItem;
});
_container = new UXContainer(document.rootVisualElement);
BITKit.UX.UXUtils.Inject(this);
Container = _modifyContainer;
}
protected override void OnPanelEntry()
{
base.OnPanelEntry();
inputActionGroup.RegisterCallback(cancelAction, OnCancel);
inputActionGroup.RegisterCallback(inventoryAction, OnInventory);
}
protected override void OnPanelExit()
{
base.OnPanelExit();
inputActionGroup.UnRegisterCallback(cancelAction, OnCancel);
inputActionGroup.UnRegisterCallback(inventoryAction, OnInventory);
}
private void OnInventory(InputAction.CallbackContext context)
{
//UXService.Entry<UXInventory>();
if(context is {interaction:PressInteraction,performed:true})
UXService.Return();
}
private void OnCancel(InputAction.CallbackContext obj)
{
UXService.Entry<UXHud>();
}
private void OnInspectItem(IBasicItem obj)
{
Container.Clear();
Entry();
var source = obj.GetAssetable();
_container.titleLabel.text = source.Name;
_container.icon.style.backgroundImage = source.RectangleIcon ? source.RectangleIcon : source.SquareIcon;
_container.contextLabel.text = source.Description;
_container.descriptionLabel.text =string.Join("\n",obj.GetProperties());
}
}
}