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,12 +26,15 @@ void UCustomButton::SynchronizeProperties()
|
||||
{
|
||||
Super::SynchronizeProperties();
|
||||
|
||||
if (TextBlock)
|
||||
{
|
||||
TextBlock->SetText(ButtonText);
|
||||
|
||||
FSlateFontInfo Font = TextBlock->GetFont();
|
||||
Font.Size = TextSize;
|
||||
TextBlock->SetFont(Font);
|
||||
}
|
||||
}
|
||||
|
||||
TObjectPtr<UTextBlock> UCustomButton::GetTextBlock()
|
||||
{
|
||||
|
@ -10,8 +10,11 @@ class UTextBlock;
|
||||
class UButton;
|
||||
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnButtonClickedEventCustom);
|
||||
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnButtonPressedEventCustom);
|
||||
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnButtonReleasedEventCustom);
|
||||
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnButtonHoverEventCustom);
|
||||
|
||||
/**
|
||||
@ -23,7 +26,6 @@ class VAMPIRES_API UCustomButton : public UUserWidget
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
UPROPERTY(BlueprintAssignable)
|
||||
FOnButtonClickedEventCustom OnClicked;
|
||||
|
||||
@ -66,26 +68,23 @@ public:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Button Settings | Sound")
|
||||
TObjectPtr<USoundBase> ButtonUnhoveredSound;
|
||||
|
||||
private:
|
||||
protected:
|
||||
UPROPERTY(meta = (BindWidget))
|
||||
TObjectPtr<UButton> ButtonBody;
|
||||
|
||||
UPROPERTY(meta = (BindWidget))
|
||||
TObjectPtr<UTextBlock> TextBlock;
|
||||
|
||||
protected:
|
||||
|
||||
virtual void NativeConstruct() override;
|
||||
|
||||
virtual void SynchronizeProperties() override;
|
||||
|
||||
public:
|
||||
|
||||
TObjectPtr<UTextBlock> GetTextBlock();
|
||||
|
||||
private:
|
||||
protected:
|
||||
UFUNCTION()
|
||||
void OnButtonClicked();
|
||||
virtual void OnButtonClicked();
|
||||
|
||||
UFUNCTION()
|
||||
void OnButtonPressed();
|
||||
|
@ -5,42 +5,27 @@
|
||||
|
||||
#include "StarterWeaponButtonDataObject.h"
|
||||
#include "Blueprint/WidgetBlueprintLibrary.h"
|
||||
#include "Components/Button.h"
|
||||
#include "Components/Image.h"
|
||||
#include "Components/TextBlock.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
#include "vampires/VampireGameInstance.h"
|
||||
|
||||
void UStarterWeaponButtonWidget::NativeConstruct()
|
||||
{
|
||||
Super::NativeConstruct();
|
||||
}
|
||||
|
||||
void UStarterWeaponButtonWidget::NativeOnListItemObjectSet(UObject* ListItemObject)
|
||||
{
|
||||
if (UStarterWeaponButtonDataObject* Item = Cast<UStarterWeaponButtonDataObject>(ListItemObject))
|
||||
{
|
||||
WeaponNameTextBlock->SetText(Item->WeaponName);
|
||||
TextBlock->SetText(Item->WeaponName);
|
||||
DescriptionTextBlock->SetText(Item->WeaponDescription);
|
||||
WeaponIcon->SetBrushFromTexture(Item->WeaponIcon);
|
||||
Parent = Item->Parent;
|
||||
WeaponTemplate = Item->WeaponTemplate;
|
||||
}
|
||||
}
|
||||
|
||||
if (Body)
|
||||
void UStarterWeaponButtonWidget::OnButtonClicked()
|
||||
{
|
||||
Body->OnClicked.AddUniqueDynamic(this, &UStarterWeaponButtonWidget::OnClicked);
|
||||
Super::OnButtonClicked();
|
||||
|
||||
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()
|
||||
{
|
||||
if (UVampireGameInstance* GameInstance = Cast<UVampireGameInstance>(GetGameInstance()))
|
||||
{
|
||||
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
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "VampireInteractiveWidget.h"
|
||||
#include "CustomButton.h"
|
||||
#include "Blueprint/IUserObjectListEntry.h"
|
||||
#include "Blueprint/UserWidget.h"
|
||||
#include "StarterWeaponButtonWidget.generated.h"
|
||||
@ -11,24 +11,18 @@
|
||||
class AWeapon;
|
||||
class UTextBlock;
|
||||
class UImage;
|
||||
class UButton;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class VAMPIRES_API UStarterWeaponButtonWidget : public UVampireInteractiveWidget, public IUserObjectListEntry
|
||||
class VAMPIRES_API UStarterWeaponButtonWidget : public UCustomButton, public IUserObjectListEntry
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
UPROPERTY(meta=(BindWidget))
|
||||
TObjectPtr<UButton> Body;
|
||||
|
||||
UPROPERTY(meta=(BindWidget))
|
||||
TObjectPtr<UImage> WeaponIcon;
|
||||
|
||||
UPROPERTY(meta=(BindWidget))
|
||||
TObjectPtr<UTextBlock> WeaponNameTextBlock;
|
||||
|
||||
UPROPERTY(meta=(BindWidget))
|
||||
TObjectPtr<UTextBlock> DescriptionTextBlock;
|
||||
|
||||
@ -38,16 +32,7 @@ class VAMPIRES_API UStarterWeaponButtonWidget : public UVampireInteractiveWidget
|
||||
UPROPERTY()
|
||||
TObjectPtr<UUserWidget> Parent;
|
||||
|
||||
virtual void NativeConstruct() override;
|
||||
|
||||
virtual void NativeOnListItemObjectSet(UObject* ListItemObject) override;
|
||||
|
||||
UFUNCTION()
|
||||
virtual void OnClicked();
|
||||
|
||||
UFUNCTION()
|
||||
void OnHoveredDelegate();
|
||||
|
||||
UFUNCTION()
|
||||
void OnUnhoveredDelegate();
|
||||
virtual void OnButtonClicked() override;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user