添加节点状态

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",
"Modules":
{
"ProjectFish": "UnrealEditor-ProjectFish.dll",
"ProjectFishEditor": "UnrealEditor-ProjectFishEditor.dll"
"ProjectFish": "UnrealEditor-ProjectFish-0001.dll",
"ProjectFishEditor": "UnrealEditor-ProjectFishEditor-0001.dll"
}
}

View File

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

View File

@ -58,6 +58,16 @@ int32 UFishingMapSystem::GetNodeAtLayerIndex(FGuid NodeID) const
return -1;
}
TObjectPtr<UFishingMapNode> UFishingMapSystem::GetNode(FGuid NodeID)
{
for (auto node: AllNodes)
{
if (node->NodeID == NodeID)
return node;
}
return nullptr;
}
void UFishingMapSystem::ClearMap()
{
AllNodes.Empty();
@ -65,6 +75,20 @@ void UFishingMapSystem::ClearMap()
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()
{
@ -219,3 +243,19 @@ TArray<FSimpleConnection> UFishingMapSystem::GenerateNonCrossingConnections(int3
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 "FishingMapSystem.generated.h"
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnNodeStateChange, EMapNodeState, NewState);
// 简化的地图节点
UCLASS(BlueprintType)
@ -23,6 +23,10 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ToolTip = "节点类型"))
EMapNodeType NodeType = EMapNodeType::Battle;
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ToolTip = "节点状态"))
EMapNodeState NodeState = EMapNodeState::Moveable;
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ToolTip = "层级索引"))
int32 LayerIndex = 0;
@ -60,25 +64,33 @@ public:
UPROPERTY(BlueprintReadOnly, meta = (ToolTip = "按层级组织的节点"))
TArray<FMapLayer> AllLayers;
UPROPERTY(BlueprintAssignable)
FOnNodeStateChange OnNodeStateChange;
// 生成地图
UFUNCTION(BlueprintCallable, Category = "FishingMap")
void GenerateMap();
// 使用配置生成地图
void GenerateMapWithConfig(const UMapConfigAsset* Config);
// 获取总层数
int32 GetLayerCount() const { return AllLayers.Num(); }
UFUNCTION(BlueprintPure, Category = "FishingMap")
int32 GetNodeAtLayerIndex(FGuid NodeID) const;
TObjectPtr<UFishingMapNode> GetNode(FGuid NodeID) ;
// 清空地图
UFUNCTION(BlueprintCallable, Category = "FishingMap")
void ClearMap();
UFUNCTION(BlueprintCallable, Category = "FishingMap")
void MoveToNode(FGuid NodeID);
private:
void GetAllConnectedNodes(FGuid NodeID, TArray<FGuid>& ConnectedNodes);
protected:
// 生成节点
void GenerateNodes();
@ -92,4 +104,6 @@ protected:
// 生成无交叉的连接方案
TArray<FSimpleConnection> GenerateNonCrossingConnections(int32 FromLayer, int32 ToLayer);
};
};