2024-04-06 16:33:57 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using BITFALL.Hotkey;
|
|
|
|
using BITKit;
|
|
|
|
using BITKit.Entities;
|
|
|
|
using BITKit.Entities.Player;
|
|
|
|
using BITKit.IData;
|
|
|
|
using BITKit.Selection;
|
|
|
|
using BITKit.UX;
|
|
|
|
using MyNamespace;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.InputSystem;
|
|
|
|
using UnityEngine.InputSystem.Interactions;
|
|
|
|
using UnityEngine.UIElements;
|
|
|
|
|
|
|
|
namespace BITFALL.UX
|
|
|
|
{
|
2024-04-15 14:57:50 +08:00
|
|
|
public class UxPanelWorldHotkeyCollection : UXPanelBase
|
2024-04-06 16:33:57 +08:00
|
|
|
{
|
|
|
|
[SerializeField] private InputActionReference[] returnActions;
|
|
|
|
[SerializeField] private VisualTreeAsset commandTemplate;
|
2024-04-15 14:57:50 +08:00
|
|
|
[SerializeField] private UxPanelDataInspector inspector;
|
2024-04-06 16:33:57 +08:00
|
|
|
|
|
|
|
[Inject] private ISelector _selector;
|
|
|
|
|
|
|
|
[UXBindPath("commands-container")] private VisualElement _commandContainer;
|
|
|
|
protected override void OnPlayerInitialized(Entity obj)
|
|
|
|
{
|
|
|
|
base.OnPlayerInitialized(obj);
|
|
|
|
_selector.OnActive+=OnActive;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnPanelEntry()
|
|
|
|
{
|
|
|
|
base.OnPanelEntry();
|
|
|
|
foreach (var action in returnActions)
|
|
|
|
{
|
2024-08-11 16:16:31 +08:00
|
|
|
InputActionGroup.RegisterCallback(action, OnReturn);
|
2024-04-06 16:33:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
private void OnReturn(InputAction.CallbackContext obj)
|
|
|
|
{
|
|
|
|
if (obj is not { interaction: PressInteraction, performed: true }) return;
|
|
|
|
OnReturn();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnReturn()
|
|
|
|
{
|
2024-08-11 16:16:31 +08:00
|
|
|
UxService.Entry<UXHud>();
|
2024-04-06 16:33:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnPanelExit()
|
|
|
|
{
|
|
|
|
base.OnPanelExit();
|
|
|
|
foreach (var action in returnActions)
|
|
|
|
{
|
2024-08-11 16:16:31 +08:00
|
|
|
InputActionGroup.UnRegisterCallback(action, OnReturn);
|
2024-04-06 16:33:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnActive(ISelectable obj)
|
|
|
|
{
|
|
|
|
if (obj.Transform.TryGetComponent<IHotkeyCollection>(out var hotkeyCollection) is false) return;
|
|
|
|
|
|
|
|
Entry();
|
|
|
|
_commandContainer.Clear();
|
|
|
|
|
|
|
|
foreach (var hotkey in hotkeyCollection.Hotkeys)
|
|
|
|
{
|
|
|
|
var instance =new UXContainer(_commandContainer.Create(commandTemplate)) ;
|
|
|
|
|
|
|
|
if (hotkey.OnPerform is null && hotkey.Data is IBindableData bindableData)
|
|
|
|
{
|
|
|
|
instance.button.clicked += () => inspector.Inspect(bindableData.Data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
instance.button.clicked += hotkey.OnPerform;
|
|
|
|
}
|
|
|
|
|
|
|
|
instance.button.text = hotkey.Name;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|