第一次提交
This commit is contained in:
39
Source/PHYInventory/Public/UI/ItemStacks/ItemData.h
Normal file
39
Source/PHYInventory/Public/UI/ItemStacks/ItemData.h
Normal file
@@ -0,0 +1,39 @@
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GIS_CoreStructLibray.h"
|
||||
#include "GIS_ItemInfo.h"
|
||||
#include "UObject/Object.h"
|
||||
#include "ItemData.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
class UItemStackContainer;
|
||||
|
||||
UCLASS()
|
||||
class PHYINVENTORY_API UItemData : public UObject
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
private:
|
||||
// item info
|
||||
FGIS_ItemInfo ItemInfo;
|
||||
// item slot definition
|
||||
FGIS_ItemSlotDefinition ItemSlotDefinition;
|
||||
TWeakObjectPtr<UItemStackContainer> OwningItemStackContainer;
|
||||
public:
|
||||
const FGIS_ItemInfo& GetItemInfo() const { return ItemInfo; }
|
||||
void SetItemInfo(const FGIS_ItemInfo& InInfo) { ItemInfo = InInfo; }
|
||||
UItemStackContainer* GetContainer() const;
|
||||
void SetContainer(UItemStackContainer* InContainer);
|
||||
|
||||
const FGIS_ItemSlotDefinition& GetItemSlotDefinition() const { return ItemSlotDefinition; }
|
||||
void SetItemSlotDefinition(const FGIS_ItemSlotDefinition& InDef) { ItemSlotDefinition = InDef; }
|
||||
void Reset();
|
||||
bool IsValidItem() const;
|
||||
int32 GetItemSlotIndex() const;
|
||||
};
|
||||
@@ -0,0 +1,44 @@
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Blueprint/DragDropOperation.h"
|
||||
#include "ItemDataDragDropOperation.generated.h"
|
||||
|
||||
class UItemData;
|
||||
class UItemStackContainer;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class PHYINVENTORY_API UItemDataDragDropOperation : public UDragDropOperation
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
protected:
|
||||
TWeakObjectPtr<UItemStackContainer> TargetItemStackView;
|
||||
TWeakObjectPtr<UItemData> TargetItemData;
|
||||
int32 TargetItemIndex = INDEX_NONE;
|
||||
TWeakObjectPtr<UItemStackContainer> SourceItemStackView;
|
||||
TWeakObjectPtr<UItemData> SourceItemData;
|
||||
int32 SourceItemIndex = INDEX_NONE;
|
||||
public:
|
||||
UItemStackContainer* GetTargetItemStackView() const;
|
||||
void SetTargetItemStackView(UItemStackContainer* InItemStackContainer);
|
||||
|
||||
UItemData* GetTargetItemData() const;
|
||||
void SetTargetItemData(UItemData* InItemData);
|
||||
|
||||
int32 GetTargetItemIndex() const;
|
||||
void SetTargetItemIndex(int32 InTargetItemIndex);
|
||||
|
||||
UItemStackContainer* GetSourceItemStackView() const;
|
||||
void SetSourceItemStackView(UItemStackContainer* InItemStackContainer);
|
||||
|
||||
UItemData* GetSourceItemData() const;
|
||||
void SetSourceItemData(UItemData* InItemData);
|
||||
|
||||
int32 GwtSourceItemIndex() const;
|
||||
void SetSourceItemIndex(int32 InSourceItemIndex);
|
||||
};
|
||||
@@ -0,0 +1,40 @@
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "CommonUserWidget.h"
|
||||
#include "ItemDataDraggingWidget.generated.h"
|
||||
|
||||
class UCommonTextBlock;
|
||||
class UImage;
|
||||
class USizeBox;
|
||||
/**
|
||||
* 拖拽时候显示的物品数据小部件
|
||||
*/
|
||||
UCLASS()
|
||||
class PHYINVENTORY_API UItemDataDraggingWidget : public UCommonUserWidget
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
UPROPERTY(meta=(BindWidget))
|
||||
USizeBox* MainSizeBox;
|
||||
UPROPERTY(meta=(BindWidget))
|
||||
UImage* IconImage;
|
||||
UPROPERTY(meta=(BindWidget))
|
||||
UCommonTextBlock* AmountText;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
UTexture2D* IconTexture;
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
int32 ItemAmount = 0;
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
float Height = 64.f;
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
float Width = 64.f;
|
||||
protected:
|
||||
virtual void NativePreConstruct() override;
|
||||
public:
|
||||
void SetAmount(int32 InAmount);
|
||||
void SetIcon(UTexture2D* InIconTexture);
|
||||
};
|
||||
146
Source/PHYInventory/Public/UI/ItemStacks/ItemStackContainer.h
Normal file
146
Source/PHYInventory/Public/UI/ItemStacks/ItemStackContainer.h
Normal file
@@ -0,0 +1,146 @@
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "CommonUserWidget.h"
|
||||
#include "GIS_InventoryMeesages.h"
|
||||
#include "GIS_ItemInfo.h"
|
||||
#include "ItemData.h"
|
||||
|
||||
#include "UI/Common/GUIS_UserWidgetInterface.h"
|
||||
#include "ItemStackContainer.generated.h"
|
||||
|
||||
class UCommonTabListWidgetBase;
|
||||
class UGIS_AsyncAction_WaitInventorySystem;
|
||||
class UListView;
|
||||
class IItemFilterInterface;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FItemSelectionOrHoveredChanged,UItemData*,SelectedItemData,bool,bSelected);
|
||||
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FItemClickedEvent,UItemData*,ClickedItemData);
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FItemEntryGeneratedEvent,UUserWidget*,Widget);
|
||||
|
||||
UCLASS()
|
||||
class PHYINVENTORY_API UItemStackContainer : public UCommonUserWidget,public IGUIS_UserWidgetInterface
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
protected:
|
||||
//~ Begin IGUIS_UserWidgetInterface Interface
|
||||
virtual void SetOwningActor_Implementation(AActor* NewOwningActor) override;
|
||||
virtual void OnDeactivated_Implementation() override;
|
||||
virtual void OnActivated_Implementation() override;
|
||||
virtual AActor* GetOwningActor_Implementation() override;
|
||||
//~ End IGUIS_UserWidgetInterface Interface
|
||||
public:
|
||||
// 添加过滤器对象
|
||||
void AddFilterObject(UObject* InFilterObject);
|
||||
// 移除过滤器对象
|
||||
void RemoveFilterObject(UObject* InFilterObject);
|
||||
UPROPERTY(BlueprintAssignable)
|
||||
FItemSelectionOrHoveredChanged OnItemSelectionChanged;
|
||||
UPROPERTY(BlueprintAssignable)
|
||||
FItemSelectionOrHoveredChanged OnItemHoveredChanged;
|
||||
UPROPERTY(BlueprintAssignable)
|
||||
FItemClickedEvent OnItemClicked;
|
||||
UPROPERTY(BlueprintAssignable)
|
||||
FItemEntryGeneratedEvent OnItemEntryGenerated;
|
||||
UPROPERTY(BlueprintAssignable)
|
||||
FItemClickedEvent OnItemDoubleClicked;
|
||||
UPROPERTY()
|
||||
UGIS_AsyncAction_WaitInventorySystem* WaitInventorySystem;
|
||||
void SetSelectedIndexForNewItem(const int32 NewSelectedIndex);
|
||||
// 交换两个item data槽位
|
||||
bool SwapItemDataSlots(const int32 IndexA,const int32 IndexB);
|
||||
bool SwapItemDataToOtherContainer(const int32 SourceIndex,UItemStackContainer* TargetContainer,const int32 TargetIndex);
|
||||
// 检查是否可以移动item
|
||||
virtual bool CanMoveItem(const int32 IndexA,UItemStackContainer* TargetContainer,const int32 IndexB);
|
||||
// 是否允许拖拽操作
|
||||
UFUNCTION(BlueprintImplementableEvent,BlueprintPure,BlueprintCallable)
|
||||
bool IsDraggingAllowed() const;
|
||||
FORCEINLINE bool IsItemActionAllowed() const { return bAllowItemAction; }
|
||||
int32 FindItemSlotIndex(const UItemData* InItemData) const;
|
||||
FORCEINLINE TArray<TObjectPtr<UItemData>> GetItemDataArray() const { return ItemDataArray; }
|
||||
// 同步item data数组到listview
|
||||
void SyncItemDataToListView();
|
||||
// 用来拖拽操作时记录上一次放下的item index
|
||||
int32 LastDropIndex = INDEX_NONE;
|
||||
private:
|
||||
TWeakObjectPtr<AActor> OwningActor;
|
||||
TWeakObjectPtr<UGIS_InventorySystemComponent> InventorySystemComponent;
|
||||
// 配置
|
||||
UPROPERTY(EditAnywhere,Category="Config|ItemStackContainer")
|
||||
FGameplayTag CollectionToTrackTag;
|
||||
// Item所有tag过滤器映射表,可以通过name来过滤Item,用于tab切换等功能
|
||||
UPROPERTY(EditAnywhere,Category="Config|Filter")
|
||||
TMap<FName,FGameplayTagQuery> ItemFilterMap;
|
||||
// 要过滤的Item名称
|
||||
UPROPERTY(EditAnywhere,Category="Config|Filter")
|
||||
FName ItemFilterName;
|
||||
UPROPERTY(EditAnywhere,Category="Config")
|
||||
bool bAllowItemAction = true;
|
||||
UPROPERTY(EditAnywhere,Category="Config")
|
||||
bool bCreateDefaultItemDataSlots = true;
|
||||
UPROPERTY(EditAnywhere,Category="Config",meta=(EditCondition="bCreateDefaultItemDataSlots"))
|
||||
int32 DefaultItemDataSlotCount = 20;
|
||||
UPROPERTY()
|
||||
TArray<UObject*> ItemFilterObjects;
|
||||
// 容器用来展示item的listview
|
||||
UPROPERTY(BlueprintReadOnly,meta=(AllowPrivateAccess="true"))
|
||||
TObjectPtr<UListView> ItemListView;
|
||||
UPROPERTY()
|
||||
TObjectPtr<UCommonTabListWidgetBase> FilterTabsReference;
|
||||
// 当前容器中关联的item数据
|
||||
UPROPERTY()
|
||||
TArray<TObjectPtr<UItemData>> ItemDataArray;
|
||||
|
||||
// The item stack data
|
||||
// 给指定槽位的ItemData赋值
|
||||
void AssignItemInfoToItemData(const FGIS_ItemInfo& InInfo,const int32 SlotIndex);
|
||||
void UnassignItemInfoToItemData(const FGIS_ItemInfo& InInfo);
|
||||
int32 FindItemIndexFromDataByStackID(const FGuid& StackID) const;
|
||||
|
||||
// 从库存系统获取数据
|
||||
TArray<FGIS_ItemInfo> GetItemInfoArrayFromInventorySystem();
|
||||
// 重置item data数组
|
||||
void ResetItemDataArray();
|
||||
// 设置或添加item info到item data数组
|
||||
void SetOrAddItemInfoToItemDataArray(const FGIS_ItemInfo& InInfo,const int32 SlotIndex);
|
||||
// 同步item infos到item data数组
|
||||
void SyncItemInfoToItemDataArray(const TArray<FGIS_ItemInfo>& InItemInfos);
|
||||
|
||||
// 为新物品查找合适的item data槽位
|
||||
int32 FindSuitableItemDataSlotForNewItem();
|
||||
// 聚合函数,同步所有数据
|
||||
void SyncAll();
|
||||
public:
|
||||
// 必须配置filter map才能使用
|
||||
void ApplyFilter(const FName& InFilterName);
|
||||
private:
|
||||
void HandleItemSelectionChanged(UObject* Object) const;
|
||||
void HandleItemHoveredChanged(UObject* Object, bool bIsHovered) const;
|
||||
void HandleItemClicked(UObject* Object) const;
|
||||
void HandleListViewEntryWidgetGenerated(UUserWidget& UserWidget) const;
|
||||
void HandleItemDoubleClicked(UObject* Object) const;
|
||||
void RegisterListViewEvents();
|
||||
void UnregisterListViewEvents() const;
|
||||
FDelegateHandle ItemSelectionChangedHandle;
|
||||
FDelegateHandle ItemHoveredChangedHandle;
|
||||
FDelegateHandle ItemClickedHandle;
|
||||
FDelegateHandle ListViewEntryWidgetGeneratedHandle;
|
||||
FDelegateHandle ItemDoubleClickedHandle;
|
||||
int32 SelectedIndexForNewItem = INDEX_NONE;
|
||||
|
||||
// 处理库存系统的item堆栈变化消息
|
||||
UFUNCTION()
|
||||
void HandleInventoryStackChanged(const FGIS_InventoryStackUpdateMessage& Message);
|
||||
UFUNCTION()
|
||||
void HandleTabSelected(FName TabId);
|
||||
UFUNCTION()
|
||||
void HandleInventorySystemInitialized();
|
||||
// 创建默认的item data槽位
|
||||
void CreateDefaultItemDataSlots();
|
||||
};
|
||||
60
Source/PHYInventory/Public/UI/ItemStacks/ItemStack_Base.h
Normal file
60
Source/PHYInventory/Public/UI/ItemStacks/ItemStack_Base.h
Normal file
@@ -0,0 +1,60 @@
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
|
||||
#include "UI/Common/GUIS_ListEntry.h"
|
||||
#include "ItemStack_Base.generated.h"
|
||||
|
||||
class UItemDataDragDropOperation;
|
||||
class UItemDataDraggingWidget;
|
||||
class UAmountContainerBase;
|
||||
class USizeBox;
|
||||
class UMenuAnchor;
|
||||
class UGUIS_UIActionWidget;
|
||||
class UGUIS_UIActionFactory;
|
||||
class UItemData;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class PHYINVENTORY_API UItemStack_Base : public UGUIS_ListEntry
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
private:
|
||||
UPROPERTY()
|
||||
UItemData* ItemData;
|
||||
UPROPERTY(meta=(BindWidgetOptional))
|
||||
UGUIS_UIActionWidget* DynamicUIActionWidget;
|
||||
UPROPERTY(EditAnywhere, Category="Config")
|
||||
TSoftObjectPtr<UGUIS_UIActionFactory> UIActionFactory;
|
||||
UPROPERTY(meta=(BindWidgetOptional))
|
||||
UMenuAnchor* ActionsAnchor;
|
||||
UPROPERTY(meta=(BindWidgetOptional))
|
||||
UAmountContainerBase* AmountContainer;
|
||||
UPROPERTY(EditAnywhere, Category="Config")
|
||||
TEnumAsByte<EHorizontalAlignment> ActionAnchorHorizontalAlignment = HAlign_Right;
|
||||
UPROPERTY(EditAnywhere, Category="Config")
|
||||
TEnumAsByte<EVerticalAlignment> ActionAnchorVerticalAlignment = VAlign_Center;
|
||||
UPROPERTY(EditAnywhere, Category="Config")
|
||||
TSubclassOf<UItemDataDraggingWidget> DraggingWidgetClass;
|
||||
protected:
|
||||
virtual void UpdateAmount();
|
||||
virtual void ResetState();
|
||||
virtual void NativeOnListItemObjectSet(UObject* ListItemObject) override;
|
||||
|
||||
virtual void NativeOnEntryReleased() override;
|
||||
virtual void NativePreConstruct() override;
|
||||
virtual void NativeOnDeselected(bool bBroadcast) override;
|
||||
virtual void NativeOnSelected(bool bBroadcast) override;
|
||||
|
||||
// 拖拽操作
|
||||
// 从这个item发起拖拽得时候调用
|
||||
UItemDataDragDropOperation* DragFromSource(const FString& Tag);
|
||||
// 放下到这个item的时候调用
|
||||
void DropToDest(UItemDataDragDropOperation& DragOperation) const;
|
||||
virtual void NativeOnDragDetected(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent, UDragDropOperation*& OutOperation) override;
|
||||
virtual bool NativeOnDrop(const FGeometry& InGeometry, const FDragDropEvent& InDragDropEvent, UDragDropOperation* InOperation) override;
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "CommonUserWidget.h"
|
||||
#include "AmountContainerBase.generated.h"
|
||||
|
||||
/**
|
||||
* 用来显示数量的容器基类
|
||||
*/
|
||||
UCLASS()
|
||||
class PHYINVENTORY_API UAmountContainerBase : public UCommonUserWidget
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
protected:
|
||||
UPROPERTY(meta=(BindWidget))
|
||||
class USizeBox* Container;
|
||||
UPROPERTY(meta=(BindWidget))
|
||||
class UCommonTextBlock* AmountText;
|
||||
public:
|
||||
void UpdateAmount(float InAmount, const FNumberFormattingOptions* const Options = nullptr) const;
|
||||
};
|
||||
Reference in New Issue
Block a user