diff --git a/Content/Widgets/BP_CustomButton.uasset b/Content/Widgets/BP_CustomButton.uasset new file mode 100644 index 0000000..45d0578 --- /dev/null +++ b/Content/Widgets/BP_CustomButton.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4c2b2e8eab0f6833f74989ee9172003b93541f069f2e8d85963fb2e5a6a33959 +size 28820 diff --git a/Source/vampires/DetectGamepad.h b/Source/vampires/DetectGamepad.h new file mode 100644 index 0000000..9028502 --- /dev/null +++ b/Source/vampires/DetectGamepad.h @@ -0,0 +1,16 @@ +// Louis Hobbs | 2024-2025 + +#pragma once + +#include "CoreMinimal.h" +#include "Kismet/BlueprintFunctionLibrary.h" +#include "DetectGamepad.generated.h" + +/** + * + */ +UCLASS() +class VAMPIRES_API UDetectGamepad : public UBlueprintFunctionLibrary +{ + GENERATED_BODY() +}; diff --git a/Source/vampires/Widgets/CustomButton.cpp b/Source/vampires/Widgets/CustomButton.cpp new file mode 100644 index 0000000..0630035 --- /dev/null +++ b/Source/vampires/Widgets/CustomButton.cpp @@ -0,0 +1,52 @@ +// Louis Hobbs | 2024-2025 + + +#include "CustomButton.h" + +#include "Components/Button.h" +#include "Components/TextBlock.h" + +void UCustomButton::NativeConstruct() +{ + Super::NativeConstruct(); + + ButtonBody->OnClicked.AddUniqueDynamic(this, &UCustomButton::OnButtonClicked); + ButtonBody->OnPressed.AddUniqueDynamic(this, &UCustomButton::OnButtonPressed); + ButtonBody->OnReleased.AddUniqueDynamic(this, &UCustomButton::OnButtonReleased); + ButtonBody->OnHovered.AddUniqueDynamic(this, &UCustomButton::OnButtonHovered); + ButtonBody->OnUnhovered.AddUniqueDynamic(this, &UCustomButton::OnButtonHovered); + + TextBlock->SetText(ButtonText); +} + +void UCustomButton::SynchronizeProperties() +{ + Super::SynchronizeProperties(); + + TextBlock->SetText(ButtonText); +} + +TObjectPtr UCustomButton::GetTextBlock() +{ + return TextBlock; +} + +void UCustomButton::OnButtonClicked() +{ + OnClicked.Broadcast(); +} + +void UCustomButton::OnButtonPressed() +{ + OnPressed.Broadcast(); +} + +void UCustomButton::OnButtonReleased() +{ + OnReleased.Broadcast(); +} + +void UCustomButton::OnButtonHovered() +{ + OnHovered.Broadcast(); +} diff --git a/Source/vampires/Widgets/CustomButton.h b/Source/vampires/Widgets/CustomButton.h new file mode 100644 index 0000000..c6c3d7c --- /dev/null +++ b/Source/vampires/Widgets/CustomButton.h @@ -0,0 +1,71 @@ +// Louis Hobbs | 2024-2025 + +#pragma once + +#include "CoreMinimal.h" +#include "Blueprint/UserWidget.h" +#include "CustomButton.generated.h" + +class UTextBlock; +class UButton; + +DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnButtonClickedEventCustom); +DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnButtonPressedEventCustom); +DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnButtonReleasedEventCustom); +DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnButtonHoverEventCustom); + +/** + * + */ +UCLASS() +class VAMPIRES_API UCustomButton : public UUserWidget +{ + GENERATED_BODY() + +public: + + UPROPERTY(BlueprintAssignable) + FOnButtonClickedEventCustom OnClicked; + + UPROPERTY(BlueprintAssignable) + FOnButtonPressedEventCustom OnPressed; + + UPROPERTY(BlueprintAssignable) + FOnButtonReleasedEventCustom OnReleased; + + UPROPERTY(BlueprintAssignable) + FOnButtonHoverEventCustom OnHovered; + + UPROPERTY(EditAnywhere, BlueprintReadOnly) + FText ButtonText = FText::FromString("Default"); + +private: + UPROPERTY(meta = (BindWidget)) + TObjectPtr ButtonBody; + + UPROPERTY(meta = (BindWidget)) + TObjectPtr TextBlock; + +protected: + + virtual void NativeConstruct() override; + + virtual void SynchronizeProperties() override; + +public: + + TObjectPtr GetTextBlock(); + +private: + UFUNCTION() + void OnButtonClicked(); + + UFUNCTION() + void OnButtonPressed(); + + UFUNCTION() + void OnButtonReleased(); + + UFUNCTION() + void OnButtonHovered(); +};