This commit is contained in:
CortexCore
2023-10-24 23:37:59 +08:00
parent 325f63d6bc
commit 3e39e627bc
388 changed files with 29043 additions and 889 deletions

View File

@@ -28,7 +28,8 @@
"GUID:ef0bb553b58b90b488bdbe8672e3be0b",
"GUID:045a42f233e479d41adc32d02b99631e",
"GUID:1235ca61e7f433b408ed5a68767e7123",
"GUID:c0b9c98c59e49554c8f4ca6dc4998d79"
"GUID:c0b9c98c59e49554c8f4ca6dc4998d79",
"GUID:48ef04d98836e2640bf90b524bdff904"
],
"includePlatforms": [],
"excludePlatforms": [],

View File

@@ -15,6 +15,7 @@ using BITKit.SceneManagement;
using BITKit.Selection;
using BITKit.Steamwork;
using UnityEditor;
using UnityEngine.InputSystem.Interactions;
namespace BITFALL.UX
{
@@ -38,9 +39,8 @@ namespace BITFALL.UX
[SerializeField] private UXBar armorBar;
[Header(Constant.Header.Input)]
public InputActionReference inventoryAction;
public InputActionReference returnAction;
public InputActionGroup inputActionGroup = new();
[SerializeField] private InputActionReference inventoryAction;
[SerializeField] private InputActionReference returnAction;
[Inject]
private IHealth _health;
@@ -71,11 +71,6 @@ namespace BITFALL.UX
{
playerService.OnPlayerInitialized -= OnPlayerInitializedLocalPlayer;
}
protected override void OnEntryOrExit(bool isEntry)
{
inputActionGroup.RegisterCallback(inventoryAction, OnInventory);
inputActionGroup.allowInput.SetElements(this, isEntry);
}
public void OnActive(ISelectable selectable)
{
seleableLabel.SetActive(false);
@@ -131,7 +126,7 @@ namespace BITFALL.UX
{
if(playerService.LocalPlayer is null) return;
if(_health.IsAlive is false) return;
if(context.JustPressed())
if(context is {interaction:PressInteraction,performed:true})
UXService.Entry<UXInventory>();
}

View File

@@ -1,9 +1,11 @@
using System.Collections.Generic;
using BITFALL.Entities.Equipment;
using BITFALL.Entities.Inventory;
using BITFALL.Player.Inventory;
using UnityEngine;
using UnityEngine.UIElements;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Interactions;
using BITKit;
using BITKit.UX;
using BITKit.Entities;
@@ -17,7 +19,7 @@ namespace BITFALL.UX
[Header(Constant.Header.Input)]
public InputActionReference inventoryAction;
public InputActionReference returnAction;
public InputActionGroup inputActionGroup = new();
[Header(Constant.Header.Components)]
public UXBar weightBar;
@@ -31,11 +33,8 @@ namespace BITFALL.UX
[Header(Constant.Header.InternalVariables)]
private readonly Dictionary<int, UXContainer> itemContainers = new();
private readonly Dictionary<string, UXContainer> equipContainers = new();
private readonly IntervalUpdate returnInterval = new(0.1f);
[Inject]
private IBasicItemContainer inventory;
[Inject]
private IPlayerInventory _playerInventory;
private IEntityInventory inventory;
[Inject]
private IEntityEquipmentContainer equipContainer;
private IEntity _entity;
@@ -65,11 +64,6 @@ namespace BITFALL.UX
});
}
}
protected override void OnEntryOrExit(bool isEntry)
{
inputActionGroup.allowInput.SetElements(this, isEntry);
returnInterval.Reset();
}
protected override void OnEnable()
{
base.OnEnable();
@@ -81,7 +75,6 @@ namespace BITFALL.UX
{
inventory = null;
equipContainer = null;
_playerInventory = null;
}
protected override void OnDisable()
@@ -94,7 +87,6 @@ namespace BITFALL.UX
{
entity.Inject(this);
itemContainers.Clear();
equipContainers.Clear();
builder.Clear();
var weighted = entity.Get<IPlayerInventoryWeightable>();
@@ -107,7 +99,7 @@ namespace BITFALL.UX
inventory.OnAdd += OnAdd;
inventory.OnRemove += OnRemove;
inventory.OnUsed += OnRemove;
inventory.OnUsedItem += OnRemove;
inventory.OnSet += OnSet;
_entity = entity;
@@ -116,7 +108,7 @@ namespace BITFALL.UX
}
private void OnInventory(InputAction.CallbackContext context)
{
if (context.JustPressed())
if(context is {interaction:PressInteraction,performed:true})
UXService.Entry<UXHud>();
}
private static void OnReturn(InputAction.CallbackContext context)
@@ -132,10 +124,11 @@ namespace BITFALL.UX
}
private void OnAdd(IBasicItem item)
{
var asset = Addressables.LoadAssetAsync<AssetableItem>(item.AddressablePath).WaitForCompletion();
var uxContainer = builder.BuildAsContainer();
uxContainer.icon.style.backgroundImage = asset.SquareIcon;
uxContainer.contextLabel.text = asset.Name;
// var asset = Addressables.LoadAssetAsync<AssetableItem>(item.AddressablePath).WaitForCompletion();
// var uxContainer = builder.BuildAsContainer();
// uxContainer.icon.style.backgroundImage = asset.SquareIcon;
// uxContainer.contextLabel.text = asset.Name;
var uxContainer = UXUtils.CreateItemContainer(builder.BuildAsContainer(), item);
uxContainer.button.clicked += () =>
{
UseItem(item);
@@ -170,14 +163,7 @@ namespace BITFALL.UX
private void UseItem(IBasicItem item)
{
if (_playerInventory.TryUseItem(item))
{
}
else if (_playerInventory.TryUseItemCustom(item))
{
}
inventory.TryUseItem(item);
}
private void DropItem(IBasicItem item)
@@ -189,7 +175,7 @@ namespace BITFALL.UX
var asset = item.GetAssetable();
if (!equipContainers.TryGetValue(slot.GetType().Name, out var container)) return;
container.icon.style.backgroundImage = asset.SquareIcon;
BIT4Log.Log<UXInventory>($"已装备:{item.Name}@{slot.GetType().Name}");
//BIT4Log.Log<UXInventory>($"已装备:{item.Name}@{slot.GetType().Name}");
}
private void DeEquip(IEquipmentSlot slot, IBasicItem item)
{

View File

@@ -0,0 +1,123 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Xml.Linq;
using BITFALL.Entities.Inventory;
using BITFALL.UX;
using BITKit;
using BITKit.Entities;
using BITKit.Entities.Player;
using BITKit.UX;
using Cysharp.Threading.Tasks;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Interactions;
using UnityEngine.UIElements;
namespace BITFALL.Items
{
public sealed class UXInventorySwap : UIToolKitPanel
{
[Header(Constant.Header.Input)]
[SerializeField] private InputActionReference escapeAction;
[SerializeField] private InputActionReference inventoryAction;
[Header(Constant.Header.Services)]
[SerializeReference,SubclassSelector] private IPlayerService playerService;
[Header(Constant.Header.Prefabs)]
[SerializeField] private VisualTreeAsset itemPrefab;
[Inject]
private IEntitySwapItem swapItem;
[Inject]
private IEntityInventory inventory;
private VisualElement selfContainer;
private VisualElement otherContainer;
protected override void Start()
{
base.Start();
inputActionGroup.RegisterCallback(escapeAction, OnEscape);
inputActionGroup.RegisterCallback(inventoryAction, OnInventory);
selfContainer = document.rootVisualElement.Q<VisualElement>("self-container");
otherContainer = document.rootVisualElement.Q<VisualElement>("other-container");
}
protected override void OnEnable()
{
base.OnEnable();
playerService.OnPlayerInitialized += OnPlayerInitialized;
}
protected override void OnDisable()
{
base.OnDisable();
playerService.OnPlayerInitialized -= OnPlayerInitialized;
}
private void OnPlayerInitialized(Entity obj)
{
obj.Inject(this);
swapItem.OnSwapOpened += OnSwapOpened;
swapItem.OnSwapClosed += OnSwapClosed;
inventory.OnAdd+=_=>ReBuild();
inventory.OnRemove+=_=>ReBuild();
inventory.OnRebuild+=_=>ReBuild();
}
private void OnSwapClosed(IBasicItemContainer obj)
{
UXService.Entry<UXHud>();
}
private void OnSwapOpened(IBasicItemContainer obj)
{
UXService.Entry<UXInventorySwap>();
ReBuild(obj);
}
private void OnInventory(InputAction.CallbackContext obj)
{
if(obj is not {interaction:PressInteraction,performed:true}) return;
UXService.Entry<UXHud>();
swapItem.Close();
}
private void OnEscape(InputAction.CallbackContext obj)
{
if (obj.performed)
UXService.Entry<UXHud>();
swapItem.Close();
}
private async void ReBuild()
{
await UniTask.NextFrame();
if(swapItem.TryGetCurrentContainer(out var container))
ReBuild(container);
}
private void ReBuild(IBasicItemContainer other)
{
otherContainer.Clear();
selfContainer.Clear();
foreach (var item in other.GetItems())
{
var container = otherContainer.Create(itemPrefab);
UXUtils.CreateItemContainer(container, item);
container.Q<Button>().clicked += () => swapItem.Add(item);
}
foreach (var item in inventory.GetItems())
{
var container = selfContainer.Create(itemPrefab);
UXUtils.CreateItemContainer(container, item);
container.Q<Button>().clicked += () => swapItem.Remove(item);
}
}
}
}

View File

@@ -27,7 +27,6 @@ namespace BITFALL.UX
[Header(Constant.Header.Input)]
[SerializeField] private InputActionReference returnAction;
[SerializeField] private InputActionReference inventoryAction;
public InputActionGroup inputActionGroup;
protected override void Start()
{
@@ -42,12 +41,6 @@ namespace BITFALL.UX
};
OnDisconnected();
}
protected override void OnEntryOrExit(bool isEntry)
{
inputActionGroup.allowInput.SetElements(this, isEntry);
}
private void OnConnected()
{
backgroundImage.SetActive(false);

View File

@@ -0,0 +1,22 @@
using System.Collections;
using System.Collections.Generic;
using BITKit;
using BITKit.UX;
using UnityEngine;
using UnityEngine.UIElements;
namespace BITFALL.UX
{
public static class UXUtils
{
public static UXContainer CreateItemContainer(VisualElement visualElement, IBasicItem item)
{
var asset = item.GetAssetable();
var uxContainer = new UXContainer(visualElement);
uxContainer.icon.style.backgroundImage = asset.SquareIcon;
uxContainer.contextLabel.text = asset.Name;
return uxContainer;
}
}
}