107 lines
		
	
	
		
			3.5 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			107 lines
		
	
	
		
			3.5 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| #pragma once
 | |
| 
 | |
| #include "CoreMinimal.h"
 | |
| #include "Blueprint/UserWidget.h"
 | |
| #include "SkillTreeTypes.h"
 | |
| #include "SkillTreeConnectionsWidget.generated.h"
 | |
| 
 | |
| class USkillTreeComponent;
 | |
| class UUserWidget;
 | |
| class UWidget;
 | |
| 
 | |
| /**
 | |
|  * Widget that automatically draws connection lines between skill tree nodes
 | |
|  * Place this widget in your skill tree UI and it will handle all line rendering
 | |
|  */
 | |
| UCLASS()
 | |
| class UTAD_UI_API USkillTreeConnectionsWidget : public UUserWidget
 | |
| {
 | |
| 	GENERATED_BODY()
 | |
| 
 | |
| public:
 | |
| 	USkillTreeConnectionsWidget(const FObjectInitializer& ObjectInitializer);
 | |
| 
 | |
| 	// Parent widget to search for skill nodes (can be the skill tree widget
 | |
| 	// itself) If not set, will search from the outer widget
 | |
| 	UPROPERTY(EditAnywhere, BlueprintReadWrite,
 | |
| 			  Category = "Skill Tree Connections")
 | |
| 	UUserWidget* SkillTreeWidget;
 | |
| 
 | |
| 	// Reference to the skill tree component (set this in Blueprint)
 | |
| 	UPROPERTY(EditAnywhere, BlueprintReadWrite,
 | |
| 			  Category = "Skill Tree Connections")
 | |
| 	USkillTreeComponent* SkillTreeComponent;
 | |
| 
 | |
| 	// Widget class for skill nodes
 | |
| 	UPROPERTY(EditAnywhere, BlueprintReadWrite,
 | |
| 			  Category = "Skill Tree Connections")
 | |
| 	TSubclassOf<UUserWidget> SkillNodeWidgetClass;
 | |
| 
 | |
| 	// Line thickness in pixels
 | |
| 	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Line Appearance",
 | |
| 			  meta = (ClampMin = "0.5", ClampMax = "10.0"))
 | |
| 	float LineThickness = 2.0f;
 | |
| 
 | |
| 	// Colors for different states
 | |
| 	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Line Colors")
 | |
| 	FLinearColor LockedColor = FLinearColor(0.3f, 0.3f, 0.3f, 1.0f);
 | |
| 
 | |
| 	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Line Colors")
 | |
| 	FLinearColor AvailableColor = FLinearColor(1.0f, 1.0f, 1.0f, 1.0f);
 | |
| 
 | |
| 	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Line Colors")
 | |
| 	FLinearColor SelectedColor = FLinearColor(1.0f, 0.84f, 0.0f, 1.0f);
 | |
| 
 | |
| 	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Line Colors")
 | |
| 	FLinearColor PurchasedColor = FLinearColor(0.0f, 1.0f, 0.0f, 1.0f);
 | |
| 
 | |
| 	// Call this to refresh the lines (useful when skill states change)
 | |
| 	UFUNCTION(BlueprintCallable, Category = "Skill Tree Connections")
 | |
| 	void RefreshConnections();
 | |
| 
 | |
| protected:
 | |
| 	virtual int32 NativePaint(const FPaintArgs&		   Args,
 | |
| 							  const FGeometry&		   AllottedGeometry,
 | |
| 							  const FSlateRect&		   MyCullingRect,
 | |
| 							  FSlateWindowElementList& OutDrawElements,
 | |
| 							  int32 LayerId, const FWidgetStyle& InWidgetStyle,
 | |
| 							  bool bParentEnabled) const override;
 | |
| 
 | |
| 	virtual void NativeConstruct() override;
 | |
| 	virtual void NativeDestruct() override;
 | |
| 
 | |
| private:
 | |
| 	// Event handlers for skill tree component events
 | |
| 	UFUNCTION()
 | |
| 	void OnSkillStateChangedHandler(FName SkillID);
 | |
| 	UFUNCTION()
 | |
| 	void OnSkillSelectionChangedHandler(int32 TotalCost);
 | |
| 	UFUNCTION()
 | |
| 	void OnSkillPurchasedHandler(FName SkillID);
 | |
| 
 | |
| 	// Helper struct to store node information for drawing
 | |
| 	struct FSkillNodeInfo
 | |
| 	{
 | |
| 		FName			SkillID;
 | |
| 		FVector2D		Position;
 | |
| 		ESkillNodeState State;
 | |
| 		TArray<FName>	Prerequisites;
 | |
| 	};
 | |
| 
 | |
| 	// Build the list of nodes and their info
 | |
| 	void BuildNodeInfoList(TArray<FSkillNodeInfo>& OutNodeInfo) const;
 | |
| 
 | |
| 	// Recursively find all widgets of a specific class in the widget hierarchy
 | |
| 	void FindWidgetsOfClass(UWidget* Root, TSubclassOf<UUserWidget> WidgetClass,
 | |
| 							TArray<UUserWidget*>& OutWidgets) const;
 | |
| 
 | |
| 	// Get the color for a line based on the dependent node's state
 | |
| 	FLinearColor GetLineColorForState(ESkillNodeState State) const;
 | |
| 
 | |
| 	// Get SkillID from a skill node widget (looks for "SkillID" property)
 | |
| 	bool GetSkillIDFromWidget(UUserWidget* Widget, FName& OutSkillID) const;
 | |
| 
 | |
| 	// Cache for forcing redraws
 | |
| 	mutable bool bNeedsRedraw = true;
 | |
| };
 |