第一次提交

This commit is contained in:
不明不惑
2026-03-03 01:23:02 +08:00
commit 3e434877e8
1053 changed files with 102411 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "GIS_PickupComponent.h"
#include "GIS_CurrencyPickupComponent.generated.h"
class UGIS_CurrencySystemComponent;
/**
* Component for picking up currencies into the currency system.
* 用于将货币拾取到货币系统的组件。
*/
UCLASS(ClassGroup=(GIS), meta=(BlueprintSpawnableComponent))
class GENERICINVENTORYSYSTEM_API UGIS_CurrencyPickupComponent : public UGIS_PickupComponent
{
GENERATED_BODY()
public:
/**
* Called when the game starts to initialize the component.
* 游戏开始时调用以初始化组件。
*/
virtual void BeginPlay() override;
/**
* Performs the pickup logic, adding currencies to the picker's currency system.
* 执行拾取逻辑,将货币添加到拾取者的货币系统。
* @param Picker The inventory system component of the actor performing the pickup. 执行拾取的演员的库存系统组件。
* @return True if the pickup was successful, false otherwise. 如果拾取成功则返回true否则返回false。
*/
virtual bool Pickup(UGIS_InventorySystemComponent* Picker) override;
protected:
/**
* The currency system component associated with this pickup.
* 与此拾取关联的货币系统组件。
*/
UPROPERTY()
UGIS_CurrencySystemComponent* OwningCurrencySystem;
};

View File

@@ -0,0 +1,66 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "GameplayTagContainer.h"
#include "GIS_PickupComponent.h"
#include "GIS_InventoryPickupComponent.generated.h"
class UGIS_ItemCollection;
/**
* Component for picking up an entire inventory into a specified collection.
* 用于将整个库存拾取到指定集合的组件。
*/
UCLASS(ClassGroup=(GIS), meta=(BlueprintSpawnableComponent))
class GENERICINVENTORYSYSTEM_API UGIS_InventoryPickupComponent : public UGIS_PickupComponent
{
GENERATED_BODY()
public:
/**
* Called when the game starts to initialize the component.
* 游戏开始时调用以初始化组件。
*/
virtual void BeginPlay() override;
/**
* Performs the pickup logic, transferring the inventory to the picker's collection.
* 执行拾取逻辑,将库存转移到拾取者的集合。
* @param Picker The inventory system component of the actor picking up the inventory. 拾取库存的演员的库存系统组件。
* @return True if the pickup was successful, false otherwise. 如果拾取成功则返回true否则返回false。
*/
virtual bool Pickup(UGIS_InventorySystemComponent* Picker) override;
/**
* Gets the owning inventory system component.
* 获取拥有的库存系统组件。
* @return The inventory system component, or nullptr if not set. 库存系统组件如果未设置则返回nullptr。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category="GIS|Pickup")
UGIS_InventorySystemComponent* GetOwningInventory() const;
protected:
/**
* Adds the pickup inventory to the specified destination collection.
* 将拾取的库存添加到指定的目标集合。
* @param DestCollection The destination collection to add the inventory to. 要添加库存的目标集合。
* @return True if the addition was successful, false otherwise. 如果添加成功则返回true否则返回false。
*/
bool AddPickupToCollection(UGIS_ItemCollection* DestCollection);
/**
* Specifies the collection in the picker's inventory to add the items to (defaults to Item.Collection.Main if not set).
* 指定拾取者库存中要添加道具的集合如果未设置默认为Item.Collection.Main
*/
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Pickup", meta=(Categories="GIS.Collection"))
FGameplayTag CollectionTag;
/**
* The inventory system component associated with this pickup.
* 与此拾取关联的库存系统组件。
*/
UPROPERTY()
TObjectPtr<UGIS_InventorySystemComponent> Inventory;
};

View File

@@ -0,0 +1,75 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "GameplayTagContainer.h"
#include "GIS_PickupComponent.h"
#include "GIS_ItemPickupComponent.generated.h"
class UGIS_InventorySystemComponent;
class UGIS_WorldItemComponent;
class UGIS_ItemCollection;
/**
* Component for picking up a single item, requiring a WorldItemComponent on the same actor.
* 用于拾取单个道具的组件需要与GIS_WorldItemComponent共存于同一演员。
*/
UCLASS(ClassGroup=(GIS), meta=(BlueprintSpawnableComponent))
class GENERICINVENTORYSYSTEM_API UGIS_ItemPickupComponent : public UGIS_PickupComponent
{
GENERATED_BODY()
public:
/**
* Performs the pickup logic, adding the item to the picker's inventory.
* 执行拾取逻辑,将道具添加到拾取者的库存。
* @param Picker The inventory system component of the actor performing the pickup. 执行拾取的演员的库存系统组件。
* @return True if the pickup was successful, false otherwise. 如果拾取成功则返回true否则返回false。
*/
virtual bool Pickup(UGIS_InventorySystemComponent* Picker) override;
/**
* Gets the associated world item component.
* 获取关联的世界道具组件。
* @return The world item component, or nullptr if not found. 世界道具组件如果未找到则返回nullptr。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category="GIS|Pickup")
UGIS_WorldItemComponent* GetWorldItem() const;
protected:
/**
* Specifies the collection in the picker's inventory to add the item to (defaults to Item.Collection.Main if not set).
* 指定拾取者库存中要添加道具的集合如果未设置默认为Item.Collection.Main
*/
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Pickup", meta=(Categories="GIS.Collection"))
FGameplayTag CollectionTag;
/**
* If true, the pickup fails if the full amount cannot be added to the inventory.
* 如果为true当无法将全部数量添加到库存集合时拾取失败。
*/
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Pickup")
bool bFailIfFullAmountNotFit = false;
/**
* Called when the game starts to initialize the component.
* 游戏开始时调用以初始化组件。
*/
virtual void BeginPlay() override;
/**
* Attempts to add the item to the picker's inventory collection.
* 尝试将道具添加到拾取者的库存集合。
* @param Picker The inventory system component of the actor performing the pickup. 执行拾取的演员的库存系统组件。
* @return True if the addition was successful, false otherwise. 如果添加成功则返回true否则返回false。
*/
bool TryAddToCollection(UGIS_InventorySystemComponent* Picker);
/**
* The associated world item component.
* 关联的世界道具组件。
*/
UPROPERTY()
TObjectPtr<UGIS_WorldItemComponent> WorldItemComponent;
};

View File

@@ -0,0 +1,31 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "UObject/Interface.h"
#include "GIS_PickupActorInterface.generated.h"
/**
* Interface for filtering pickup class selection.
* 用于筛选拾取类选择的接口。
* @details Acts as a marker interface for actors that support pickup functionality.
* @细节 作为支持拾取功能的演员的标记接口。
*/
UINTERFACE()
class UGIS_PickupActorInterface : public UInterface
{
GENERATED_BODY()
};
/**
* Interface class for pickup actor functionality.
* 拾取演员功能的接口类。
*/
class GENERICINVENTORYSYSTEM_API IGIS_PickupActorInterface
{
GENERATED_BODY()
// Add interface functions to this class. This is the class that will be inherited to implement this interface.
// 在此添加接口函数。此类将被继承以实现该接口。
};

View File

@@ -0,0 +1,70 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "GIS_PickupComponent.generated.h"
class UGIS_InventorySystemComponent;
/**
* Delegate triggered when a pickup action succeeds or fails.
* 拾取动作成功或失败时触发的委托。
*/
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FGIS_PickupSignature);
/**
* Base component for handling pickup logic in the inventory system.
* 库存系统中处理拾取逻辑的基组件。
* @details Provides the core functionality for picking up items, currencies, or inventories.
* @细节 提供拾取道具、货币或库存的核心功能。
*/
UCLASS(Abstract, Blueprintable, BlueprintType)
class GENERICINVENTORYSYSTEM_API UGIS_PickupComponent : public UActorComponent
{
GENERATED_BODY()
public:
/**
* Constructor for the pickup component.
* 拾取组件的构造函数。
*/
UGIS_PickupComponent();
/**
* Performs the pickup logic, typically called during interaction.
* 执行拾取逻辑,通常在交互时调用。
* @param Picker The inventory system component of the actor performing the pickup. 执行拾取的演员的库存系统组件。
* @return True if the pickup was successful, false otherwise. 如果拾取成功则返回true否则返回false。
*/
UFUNCTION(BlueprintCallable, BlueprintAuthorityOnly, Category="GIS|Pickup")
virtual bool Pickup(UGIS_InventorySystemComponent* Picker);
/**
* Delegate triggered when the pickup action succeeds.
* 拾取动作成功时触发的委托。
*/
UPROPERTY(BlueprintAssignable, Category="Pickup")
FGIS_PickupSignature OnPickupSuccess;
/**
* Delegate triggered when the pickup action fails.
* 拾取动作失败时触发的委托。
*/
UPROPERTY(BlueprintAssignable, Category="Pickup")
FGIS_PickupSignature OnPickupFail;
protected:
/**
* Notifies listeners of a successful pickup.
* 通知监听者拾取成功。
*/
virtual void NotifyPickupSuccess();
/**
* Notifies listeners of a failed pickup.
* 通知监听者拾取失败。
*/
virtual void NotifyPickupFailed();
};

View File

@@ -0,0 +1,160 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "GIS_CoreStructLibray.h"
#include "Items/GIS_ItemInfo.h"
#include "Components/ActorComponent.h"
#include "GIS_WorldItemComponent.generated.h"
class UGIS_ItemInstance;
/**
* Delegate triggered when an item info is set.
* 道具信息设置时触发的委托。
*/
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FGIS_ItemInfoSetSignature, const FGIS_ItemInfo&, ItemInfo);
/**
* Component for generating or referencing items in the world.
* 用于在世界中生成或引用道具的组件。
* @details Used by item pickups to generate item instances or by spawned equipment to hold references to source items.
* @细节 道具拾取使用此组件生成道具实例,或由生成的装备使用以持有源道具的引用。
*/
UCLASS(ClassGroup=(GIS), meta=(BlueprintSpawnableComponent))
class GENERICINVENTORYSYSTEM_API UGIS_WorldItemComponent : public UActorComponent
{
GENERATED_BODY()
public:
/**
* Constructor for the world item component.
* 世界道具组件的构造函数。
* @param ObjectInitializer The object initializer. 对象初始化器。
*/
UGIS_WorldItemComponent(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get());
/**
* Gets the properties that should be replicated for this component.
* 获取需要为此组件复制的属性。
* @param OutLifetimeProps Array to store the replicated properties. 存储复制属性的数组。
*/
virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
/**
* Gets the world item component from an actor.
* 从演员获取世界道具组件。
* @param Actor The actor to query for the world item component. 要查询世界道具组件的演员。
* @return The world item component, or nullptr if not found. 世界道具组件如果未找到则返回nullptr。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category="GIS|WorldItem", meta=(DefaultToSelf="Actor"))
static UGIS_WorldItemComponent* GetWorldItemComponent(const AActor* Actor);
/**
* Creates an item instance from a definition.
* 从定义创建道具实例。
* @param ItemDefinition The item definition and amount to create the instance from. 用于创建实例的道具定义和数量。
*/
UFUNCTION(BlueprintCallable, Category="GIS|WorldItem")
void CreateItemFromDefinition(FGIS_ItemDefinitionAmount ItemDefinition);
/**
* Checks if the component has a valid item definition.
* 检查组件是否具有有效的道具定义。
* @return True if the component will auto-create and own an item, false otherwise. 如果组件将自动创建并拥有道具则返回true否则返回false。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category="GIS|WorldItem")
bool HasValidDefinition() const;
/**
* Sets the item info for the component (should be called only once).
* 设置组件的道具信息(应仅调用一次)。
* @param InItem The item instance to set. 要设置的道具实例。
* @param InAmount The amount of the item. 道具数量。
*/
virtual void SetItemInfo(UGIS_ItemInstance* InItem, int32 InAmount);
/**
* Resets the item info for the component.
* 重置组件的道具信息。
*/
void ResetItemInfo();
/**
* Gets the associated item instance.
* 获取关联的道具实例。
* @return The item instance, or nullptr if not set. 道具实例如果未设置则返回nullptr。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category="GIS|WorldItem")
UGIS_ItemInstance* GetItemInstance();
/**
* Creates a duplicated item instance with a new owner.
* 创建具有新拥有者的重复道具实例。
* @param NewOwner The new owner for the duplicated instance. 重复实例的新拥有者。
* @return The duplicated item instance, or nullptr if not possible. 重复的道具实例如果无法创建则返回nullptr。
*/
UGIS_ItemInstance* GetDuplicatedItemInstance(AActor* NewOwner);
/**
* Gets the item info associated with the component.
* 获取与组件关联的道具信息。
* @return The item info. 道具信息。
*/
FGIS_ItemInfo GetItemInfo() const;
/**
* Gets the amount of the associated item instance.
* 获取关联道具实例的数量。
* @return The item amount. 道具数量。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category="GIS|WorldItem")
int32 GetItemAmount() const;
/**
* Called when the game starts to initialize the component.
* 游戏开始时调用以初始化组件。
*/
virtual void BeginPlay() override;
/**
* Gets the owner cast to a specific type.
* 获取特定类型的拥有者。
* @return The owner cast to the specified type, or nullptr if the cast fails. 转换为指定类型的拥有者如果转换失败则返回nullptr。
*/
template <class T>
T* GetTypedOwner()
{
return Cast<T>(GetOwner());
}
/**
* Delegate triggered when a valid item info is set.
* 有效道具信息设置时触发的委托。
*/
UPROPERTY(BlueprintAssignable)
FGIS_ItemInfoSetSignature ItemInfoSetEvent;
protected:
/**
* Item definition used to auto-create an item instance (if set, the component owns the instance).
* 用于自动创建道具实例的道具定义(如果设置,组件拥有该实例)。
*/
UPROPERTY(EditAnywhere, Category="WorldItem")
FGIS_ItemDefinitionAmount Definition;
/**
* The item info associated with this component.
* 与该组件关联的道具信息。
*/
UPROPERTY(VisibleAnywhere, Category="WorldItem", ReplicatedUsing=OnRep_ItemInfo, meta=(ShowInnerProperties))
FGIS_ItemInfo ItemInfo;
/**
* Called when the item info is replicated.
* 道具信息复制时调用。
*/
UFUNCTION()
void OnRep_ItemInfo();
};