Convert StarterWeaponButtonWidget to CustomButton
This commit is contained in:
parent
6252377264
commit
e129f2f0cc
BIN
Content/Widgets/MainMenu/BP_StarterButtonWIdget.uasset
(Stored with Git LFS)
BIN
Content/Widgets/MainMenu/BP_StarterButtonWIdget.uasset
(Stored with Git LFS)
Binary file not shown.
@ -26,11 +26,14 @@ void UCustomButton::SynchronizeProperties()
|
|||||||
{
|
{
|
||||||
Super::SynchronizeProperties();
|
Super::SynchronizeProperties();
|
||||||
|
|
||||||
TextBlock->SetText(ButtonText);
|
if (TextBlock)
|
||||||
|
{
|
||||||
FSlateFontInfo Font = TextBlock->GetFont();
|
TextBlock->SetText(ButtonText);
|
||||||
Font.Size = TextSize;
|
|
||||||
TextBlock->SetFont(Font);
|
FSlateFontInfo Font = TextBlock->GetFont();
|
||||||
|
Font.Size = TextSize;
|
||||||
|
TextBlock->SetFont(Font);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TObjectPtr<UTextBlock> UCustomButton::GetTextBlock()
|
TObjectPtr<UTextBlock> UCustomButton::GetTextBlock()
|
||||||
@ -83,7 +86,7 @@ void UCustomButton::OnButtonHovered()
|
|||||||
void UCustomButton::OnButtonUnhovered()
|
void UCustomButton::OnButtonUnhovered()
|
||||||
{
|
{
|
||||||
OnUnhovered.Broadcast();
|
OnUnhovered.Broadcast();
|
||||||
|
|
||||||
if (ButtonUnhoveredSound)
|
if (ButtonUnhoveredSound)
|
||||||
{
|
{
|
||||||
UGameplayStatics::PlaySound2D(GetWorld(), ButtonUnhoveredSound);
|
UGameplayStatics::PlaySound2D(GetWorld(), ButtonUnhoveredSound);
|
||||||
|
@ -10,8 +10,11 @@ class UTextBlock;
|
|||||||
class UButton;
|
class UButton;
|
||||||
|
|
||||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnButtonClickedEventCustom);
|
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnButtonClickedEventCustom);
|
||||||
|
|
||||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnButtonPressedEventCustom);
|
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnButtonPressedEventCustom);
|
||||||
|
|
||||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnButtonReleasedEventCustom);
|
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnButtonReleasedEventCustom);
|
||||||
|
|
||||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnButtonHoverEventCustom);
|
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnButtonHoverEventCustom);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -23,7 +26,6 @@ class VAMPIRES_API UCustomButton : public UUserWidget
|
|||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
UPROPERTY(BlueprintAssignable)
|
UPROPERTY(BlueprintAssignable)
|
||||||
FOnButtonClickedEventCustom OnClicked;
|
FOnButtonClickedEventCustom OnClicked;
|
||||||
|
|
||||||
@ -38,13 +40,13 @@ public:
|
|||||||
|
|
||||||
UPROPERTY(BlueprintAssignable)
|
UPROPERTY(BlueprintAssignable)
|
||||||
FOnButtonHoverEventCustom OnUnhovered;
|
FOnButtonHoverEventCustom OnUnhovered;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Button Settings | Text")
|
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Button Settings | Text")
|
||||||
FText ButtonText = FText::FromString("Default");
|
FText ButtonText = FText::FromString("Default");
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Button Settings | Text")
|
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Button Settings | Text")
|
||||||
int TextSize = 30.0f;
|
int TextSize = 30.0f;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Button Settings | Color")
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Button Settings | Color")
|
||||||
FLinearColor ButtonHoveredTextColor = {0, 1, 0, 1};
|
FLinearColor ButtonHoveredTextColor = {0, 1, 0, 1};
|
||||||
|
|
||||||
@ -59,33 +61,30 @@ public:
|
|||||||
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Button Settings | Sound")
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Button Settings | Sound")
|
||||||
TObjectPtr<USoundBase> ButtonReleasedSound;
|
TObjectPtr<USoundBase> ButtonReleasedSound;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Button Settings | Sound")
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Button Settings | Sound")
|
||||||
TObjectPtr<USoundBase> ButtonHoveredSound;
|
TObjectPtr<USoundBase> ButtonHoveredSound;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Button Settings | Sound")
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Button Settings | Sound")
|
||||||
TObjectPtr<USoundBase> ButtonUnhoveredSound;
|
TObjectPtr<USoundBase> ButtonUnhoveredSound;
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
UPROPERTY(meta = (BindWidget))
|
UPROPERTY(meta = (BindWidget))
|
||||||
TObjectPtr<UButton> ButtonBody;
|
TObjectPtr<UButton> ButtonBody;
|
||||||
|
|
||||||
UPROPERTY(meta = (BindWidget))
|
UPROPERTY(meta = (BindWidget))
|
||||||
TObjectPtr<UTextBlock> TextBlock;
|
TObjectPtr<UTextBlock> TextBlock;
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
virtual void NativeConstruct() override;
|
virtual void NativeConstruct() override;
|
||||||
|
|
||||||
virtual void SynchronizeProperties() override;
|
virtual void SynchronizeProperties() override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
TObjectPtr<UTextBlock> GetTextBlock();
|
TObjectPtr<UTextBlock> GetTextBlock();
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
void OnButtonClicked();
|
virtual void OnButtonClicked();
|
||||||
|
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
void OnButtonPressed();
|
void OnButtonPressed();
|
||||||
|
@ -5,42 +5,27 @@
|
|||||||
|
|
||||||
#include "StarterWeaponButtonDataObject.h"
|
#include "StarterWeaponButtonDataObject.h"
|
||||||
#include "Blueprint/WidgetBlueprintLibrary.h"
|
#include "Blueprint/WidgetBlueprintLibrary.h"
|
||||||
#include "Components/Button.h"
|
|
||||||
#include "Components/Image.h"
|
#include "Components/Image.h"
|
||||||
#include "Components/TextBlock.h"
|
#include "Components/TextBlock.h"
|
||||||
#include "Kismet/GameplayStatics.h"
|
#include "Kismet/GameplayStatics.h"
|
||||||
#include "vampires/VampireGameInstance.h"
|
#include "vampires/VampireGameInstance.h"
|
||||||
|
|
||||||
void UStarterWeaponButtonWidget::NativeConstruct()
|
|
||||||
{
|
|
||||||
Super::NativeConstruct();
|
|
||||||
}
|
|
||||||
|
|
||||||
void UStarterWeaponButtonWidget::NativeOnListItemObjectSet(UObject* ListItemObject)
|
void UStarterWeaponButtonWidget::NativeOnListItemObjectSet(UObject* ListItemObject)
|
||||||
{
|
{
|
||||||
if (UStarterWeaponButtonDataObject* Item = Cast<UStarterWeaponButtonDataObject>(ListItemObject))
|
if (UStarterWeaponButtonDataObject* Item = Cast<UStarterWeaponButtonDataObject>(ListItemObject))
|
||||||
{
|
{
|
||||||
WeaponNameTextBlock->SetText(Item->WeaponName);
|
TextBlock->SetText(Item->WeaponName);
|
||||||
DescriptionTextBlock->SetText(Item->WeaponDescription);
|
DescriptionTextBlock->SetText(Item->WeaponDescription);
|
||||||
WeaponIcon->SetBrushFromTexture(Item->WeaponIcon);
|
WeaponIcon->SetBrushFromTexture(Item->WeaponIcon);
|
||||||
Parent = Item->Parent;
|
Parent = Item->Parent;
|
||||||
WeaponTemplate = Item->WeaponTemplate;
|
WeaponTemplate = Item->WeaponTemplate;
|
||||||
|
|
||||||
if (Body)
|
|
||||||
{
|
|
||||||
Body->OnClicked.AddUniqueDynamic(this, &UStarterWeaponButtonWidget::OnClicked);
|
|
||||||
|
|
||||||
Body->OnHovered.AddUniqueDynamic(this, &UStarterWeaponButtonWidget::PlayHoveredSound);
|
|
||||||
Body->OnHovered.AddUniqueDynamic(this, &UStarterWeaponButtonWidget::OnHoveredDelegate);
|
|
||||||
|
|
||||||
Body->OnUnhovered.AddUniqueDynamic(this, &UStarterWeaponButtonWidget::OnUnhoveredDelegate);
|
|
||||||
Body->OnUnhovered.AddUniqueDynamic(this, &UStarterWeaponButtonWidget::PlayUnhoveredSound);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UStarterWeaponButtonWidget::OnClicked()
|
void UStarterWeaponButtonWidget::OnButtonClicked()
|
||||||
{
|
{
|
||||||
|
Super::OnButtonClicked();
|
||||||
|
|
||||||
if (UVampireGameInstance* GameInstance = Cast<UVampireGameInstance>(GetGameInstance()))
|
if (UVampireGameInstance* GameInstance = Cast<UVampireGameInstance>(GetGameInstance()))
|
||||||
{
|
{
|
||||||
GameInstance->StarterWeapon = WeaponTemplate;
|
GameInstance->StarterWeapon = WeaponTemplate;
|
||||||
@ -58,15 +43,3 @@ void UStarterWeaponButtonWidget::OnClicked()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UStarterWeaponButtonWidget::OnHoveredDelegate()
|
|
||||||
{
|
|
||||||
SetTextBlockHovered(WeaponNameTextBlock);
|
|
||||||
SetTextBlockHovered(DescriptionTextBlock);
|
|
||||||
}
|
|
||||||
|
|
||||||
void UStarterWeaponButtonWidget::OnUnhoveredDelegate()
|
|
||||||
{
|
|
||||||
SetTextBlockUnhovered(WeaponNameTextBlock);
|
|
||||||
SetTextBlockUnhovered(DescriptionTextBlock);
|
|
||||||
}
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
#include "VampireInteractiveWidget.h"
|
#include "CustomButton.h"
|
||||||
#include "Blueprint/IUserObjectListEntry.h"
|
#include "Blueprint/IUserObjectListEntry.h"
|
||||||
#include "Blueprint/UserWidget.h"
|
#include "Blueprint/UserWidget.h"
|
||||||
#include "StarterWeaponButtonWidget.generated.h"
|
#include "StarterWeaponButtonWidget.generated.h"
|
||||||
@ -11,24 +11,18 @@
|
|||||||
class AWeapon;
|
class AWeapon;
|
||||||
class UTextBlock;
|
class UTextBlock;
|
||||||
class UImage;
|
class UImage;
|
||||||
class UButton;
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
UCLASS()
|
UCLASS()
|
||||||
class VAMPIRES_API UStarterWeaponButtonWidget : public UVampireInteractiveWidget, public IUserObjectListEntry
|
class VAMPIRES_API UStarterWeaponButtonWidget : public UCustomButton, public IUserObjectListEntry
|
||||||
{
|
{
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
|
||||||
UPROPERTY(meta=(BindWidget))
|
|
||||||
TObjectPtr<UButton> Body;
|
|
||||||
|
|
||||||
UPROPERTY(meta=(BindWidget))
|
UPROPERTY(meta=(BindWidget))
|
||||||
TObjectPtr<UImage> WeaponIcon;
|
TObjectPtr<UImage> WeaponIcon;
|
||||||
|
|
||||||
UPROPERTY(meta=(BindWidget))
|
|
||||||
TObjectPtr<UTextBlock> WeaponNameTextBlock;
|
|
||||||
|
|
||||||
UPROPERTY(meta=(BindWidget))
|
UPROPERTY(meta=(BindWidget))
|
||||||
TObjectPtr<UTextBlock> DescriptionTextBlock;
|
TObjectPtr<UTextBlock> DescriptionTextBlock;
|
||||||
|
|
||||||
@ -38,16 +32,7 @@ class VAMPIRES_API UStarterWeaponButtonWidget : public UVampireInteractiveWidget
|
|||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
TObjectPtr<UUserWidget> Parent;
|
TObjectPtr<UUserWidget> Parent;
|
||||||
|
|
||||||
virtual void NativeConstruct() override;
|
|
||||||
|
|
||||||
virtual void NativeOnListItemObjectSet(UObject* ListItemObject) override;
|
virtual void NativeOnListItemObjectSet(UObject* ListItemObject) override;
|
||||||
|
|
||||||
UFUNCTION()
|
virtual void OnButtonClicked() override;
|
||||||
virtual void OnClicked();
|
|
||||||
|
|
||||||
UFUNCTION()
|
|
||||||
void OnHoveredDelegate();
|
|
||||||
|
|
||||||
UFUNCTION()
|
|
||||||
void OnUnhoveredDelegate();
|
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user