添加节点状态

This commit is contained in:
997146918 2025-09-22 19:38:12 +08:00
parent 1dfaab4de9
commit 0fc222490a
6 changed files with 68 additions and 7 deletions

View File

@ -2,7 +2,7 @@
"BuildId": "37670630", "BuildId": "37670630",
"Modules": "Modules":
{ {
"ProjectFish": "UnrealEditor-ProjectFish.dll", "ProjectFish": "UnrealEditor-ProjectFish-0001.dll",
"ProjectFishEditor": "UnrealEditor-ProjectFishEditor.dll" "ProjectFishEditor": "UnrealEditor-ProjectFishEditor-0001.dll"
} }
} }

View File

@ -420,6 +420,13 @@ enum class EMapNodeType : uint8
Boss UMETA(DisplayName = "关底Boss") Boss UMETA(DisplayName = "关底Boss")
}; };
UENUM(BlueprintType)
enum class EMapNodeState : uint8
{
Moveable UMETA(DisplayName = "可移动到"),
Immovable UMETA(DisplayName = "不可移动到"),
};
//地图层 //地图层
USTRUCT(BlueprintType) USTRUCT(BlueprintType)
struct FMapLayer struct FMapLayer

View File

@ -58,6 +58,16 @@ int32 UFishingMapSystem::GetNodeAtLayerIndex(FGuid NodeID) const
return -1; return -1;
} }
TObjectPtr<UFishingMapNode> UFishingMapSystem::GetNode(FGuid NodeID)
{
for (auto node: AllNodes)
{
if (node->NodeID == NodeID)
return node;
}
return nullptr;
}
void UFishingMapSystem::ClearMap() void UFishingMapSystem::ClearMap()
{ {
AllNodes.Empty(); AllNodes.Empty();
@ -65,6 +75,20 @@ void UFishingMapSystem::ClearMap()
AllLayers.Empty(); AllLayers.Empty();
} }
void UFishingMapSystem::MoveToNode(FGuid NodeID)
{
TArray<FGuid> MoveableNodeIDs;
GetAllConnectedNodes(NodeID, MoveableNodeIDs);
for (auto node:AllNodes)
{
if (MoveableNodeIDs.Find(node->NodeID) == -1)
{
//节点不在可移动的列表内,更新状态
OnNodeStateChange.Broadcast(EMapNodeState::Immovable);
}
}
}
void UFishingMapSystem::GenerateNodes() void UFishingMapSystem::GenerateNodes()
{ {
@ -219,3 +243,19 @@ TArray<FSimpleConnection> UFishingMapSystem::GenerateNonCrossingConnections(int3
return Connections; return Connections;
} }
void UFishingMapSystem::GetAllConnectedNodes(FGuid NodeID, TArray<FGuid>& ConnectedNodes)
{
//获取所有可移动的节点
ConnectedNodes.Add(NodeID);
if (GetNode(NodeID)->ConnectedNodes.Num() != 0)
{
ConnectedNodes.Append(GetNode(NodeID)->ConnectedNodes);
for (auto ConnectedNode : GetNode(NodeID)->ConnectedNodes)
{
GetAllConnectedNodes(ConnectedNode, ConnectedNodes);
}
}
}

View File

@ -5,7 +5,7 @@
#include "ProjectFish/Definations.h" #include "ProjectFish/Definations.h"
#include "FishingMapSystem.generated.h" #include "FishingMapSystem.generated.h"
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnNodeStateChange, EMapNodeState, NewState);
// 简化的地图节点 // 简化的地图节点
UCLASS(BlueprintType) UCLASS(BlueprintType)
@ -23,6 +23,10 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ToolTip = "节点类型")) UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ToolTip = "节点类型"))
EMapNodeType NodeType = EMapNodeType::Battle; EMapNodeType NodeType = EMapNodeType::Battle;
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ToolTip = "节点状态"))
EMapNodeState NodeState = EMapNodeState::Moveable;
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ToolTip = "层级索引")) UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ToolTip = "层级索引"))
int32 LayerIndex = 0; int32 LayerIndex = 0;
@ -60,6 +64,9 @@ public:
UPROPERTY(BlueprintReadOnly, meta = (ToolTip = "按层级组织的节点")) UPROPERTY(BlueprintReadOnly, meta = (ToolTip = "按层级组织的节点"))
TArray<FMapLayer> AllLayers; TArray<FMapLayer> AllLayers;
UPROPERTY(BlueprintAssignable)
FOnNodeStateChange OnNodeStateChange;
// 生成地图 // 生成地图
UFUNCTION(BlueprintCallable, Category = "FishingMap") UFUNCTION(BlueprintCallable, Category = "FishingMap")
void GenerateMap(); void GenerateMap();
@ -67,18 +74,23 @@ public:
// 使用配置生成地图 // 使用配置生成地图
void GenerateMapWithConfig(const UMapConfigAsset* Config); void GenerateMapWithConfig(const UMapConfigAsset* Config);
// 获取总层数 // 获取总层数
int32 GetLayerCount() const { return AllLayers.Num(); } int32 GetLayerCount() const { return AllLayers.Num(); }
UFUNCTION(BlueprintPure, Category = "FishingMap") UFUNCTION(BlueprintPure, Category = "FishingMap")
int32 GetNodeAtLayerIndex(FGuid NodeID) const; int32 GetNodeAtLayerIndex(FGuid NodeID) const;
TObjectPtr<UFishingMapNode> GetNode(FGuid NodeID) ;
// 清空地图 // 清空地图
UFUNCTION(BlueprintCallable, Category = "FishingMap") UFUNCTION(BlueprintCallable, Category = "FishingMap")
void ClearMap(); void ClearMap();
UFUNCTION(BlueprintCallable, Category = "FishingMap")
void MoveToNode(FGuid NodeID);
private:
void GetAllConnectedNodes(FGuid NodeID, TArray<FGuid>& ConnectedNodes);
protected: protected:
// 生成节点 // 生成节点
void GenerateNodes(); void GenerateNodes();
@ -93,3 +105,5 @@ protected:
// 生成无交叉的连接方案 // 生成无交叉的连接方案
TArray<FSimpleConnection> GenerateNonCrossingConnections(int32 FromLayer, int32 ToLayer); TArray<FSimpleConnection> GenerateNonCrossingConnections(int32 FromLayer, int32 ToLayer);
}; };