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

@@ -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)
{