Skip to content

Commit

Permalink
feat: inventory keybind (#66)
Browse files Browse the repository at this point in the history
## 개요
I키로 인벤토리를 띄울 수 있음
  • Loading branch information
colibrishin authored Nov 21, 2024
1 parent 585d664 commit 3e89a5c
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 6 deletions.
Binary file not shown.
Binary file modified Content/ThirdPerson/Input/IMC_Default.uasset
Binary file not shown.
Binary file added Content/ThirdPerson/Input/IMC_HUD.uasset
Binary file not shown.
3 changes: 2 additions & 1 deletion Source/wunthshin/Components/Weapon/C_WSWeapon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ void UC_WSWeapon::SetupInputComponent()
{
APlayerController* PC = UGameplayStatics::GetPlayerController(GetWorld(), 0);

if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PC->GetLocalPlayer()); !Subsystem->HasMappingContext(IMC_Weapon))
if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PC->GetLocalPlayer());
!Subsystem->HasMappingContext(IMC_Weapon))
{
Subsystem->AddMappingContext(IMC_Weapon, 0);
}
Expand Down
71 changes: 67 additions & 4 deletions Source/wunthshin/Widgets/MainGame/WG_WSInGameBundle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@

#include "WG_WSInGameBundle.h"

#include "EnhancedInputComponent.h"
#include "EnhancedInputSubsystems.h"
#include "FCTween.h"
#include "FCTweenUObject.h"
#include "wunthshin/Widgets/Inventory/WG_WSInventory.h"
#include "Blueprint/UserWidget.h"
#include "Components/Button.h"

#include "Kismet/GameplayStatics.h"

#include "wunthshin/Subsystem/GameInstanceSubsystem/Character/CharacterSubsystem.h"
#include "wunthshin/Actors/Pawns/Character/AA_WSCharacter.h"

Expand Down Expand Up @@ -41,13 +46,65 @@ void UWG_WSInGameBundle::NativeConstruct()
void UWG_WSInGameBundle::NativeOnInitialized()
{
Super::NativeOnInitialized();

if (const APlayerController* PlayerController = GetPlayerContext().GetPlayerController())
{
if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PlayerController->GetLocalPlayer());
!Subsystem->HasMappingContext(InputMappingContext))
{
Subsystem->AddMappingContext(InputMappingContext, 1);
}

if (UEnhancedInputComponent* EnhancedInputComponent = Cast<UEnhancedInputComponent>(GetPlayerContext().GetPlayerController()->InputComponent))
{
EnhancedInputComponent->BindAction(InventoryAction, ETriggerEvent::Started, this, &UWG_WSInGameBundle::OpenWindowInventory);
}
}
}

void UWG_WSInGameBundle::NativeDestruct()
{
Super::NativeDestruct();

if (const APlayerController* PlayerController = GetPlayerContext().GetPlayerController())
{
if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PlayerController->GetLocalPlayer());
Subsystem->HasMappingContext(InputMappingContext))
{
Subsystem->RemoveMappingContext(InputMappingContext);
}

if (UEnhancedInputComponent* EnhancedInputComponent = Cast<UEnhancedInputComponent>(GetPlayerContext().GetPlayerController()->InputComponent))
{
EnhancedInputComponent->ClearBindingsForObject(this);
}
}
}

void UWG_WSInGameBundle::NativeTick(const FGeometry& MyGeometry, float InDeltaTime)
{
Super::NativeTick(MyGeometry, InDeltaTime);
}

UWG_WSInGameBundle::UWG_WSInGameBundle(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer),
FadeImage(nullptr),
Button_OpenInventory(nullptr),
CharacterRoot(nullptr)
{
if (static ConstructorHelpers::FObjectFinder<UInputMappingContext> IMC_HUD(TEXT("/Script/EnhancedInput.InputMappingContext'/Game/ThirdPerson/Input/IMC_HUD.IMC_HUD'"));
IMC_HUD.Succeeded())
{
InputMappingContext = IMC_HUD.Object;
}

if (static ConstructorHelpers::FObjectFinder<UInputAction> IA_Inventory(TEXT("/Script/EnhancedInput.InputAction'/Game/ThirdPerson/Input/Actions/IA_Inventory.IA_Inventory'"));
IA_Inventory.Succeeded())
{
InventoryAction = IA_Inventory.Object;
}
}

FCTweenInstance* UWG_WSInGameBundle::FadeInOut(bool bIsIn, float InDuration)
{
float Start = bIsIn ? 1.0f : 0.0f;
Expand All @@ -58,12 +115,18 @@ FCTweenInstance* UWG_WSInGameBundle::FadeInOut(bool bIsIn, float InDuration)

void UWG_WSInGameBundle::OpenWindow(FName InWindowName)
{
FadeInOut(false)->SetOnComplete([=, this] ()
if (ChildWidgets[InWindowName]->GetVisibility() == ESlateVisibility::Hidden && !ChildWidgets[InWindowName]->IsInAnimation())
{
ChildWidgets[InWindowName]->OnVisibleWidget();
})->CreateUObject(this);
ChildWidgets[InWindowName]->SetInAnimation(true);

FadeInOut(false)->SetOnComplete([this, InWindowName] ()
{
ChildWidgets[InWindowName]->OnVisibleWidget();
ChildWidgets[InWindowName]->SetInAnimation(false);
})->CreateUObject(this);

FadeInOut(true);
FadeInOut(true);
}
}

void UWG_WSInGameBundle::InitCharacterSlots()
Expand Down
12 changes: 12 additions & 0 deletions Source/wunthshin/Widgets/MainGame/WG_WSInGameBundle.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#pragma once

#include "CoreMinimal.h"
#include "InputMappingContext.h"

#include "Blueprint/UserWidget.h"
#include "wunthshin/Widgets/WG_WSUserWidgetBase.h"
#include "WG_WSInGameBundle.generated.h"
Expand All @@ -27,13 +29,23 @@ class WUNTHSHIN_API UWG_WSInGameBundle : public UWG_WSUserWidgetBase
Status,
Menu,
};


UPROPERTY(VisibleAnywhere, BlueprintReadOnly, meta=(AllowPrivateAccess = "true"))
UInputMappingContext* InputMappingContext;

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, meta=(AllowPrivateAccess = "true"))
UInputAction* InventoryAction;

protected:
virtual void NativeConstruct() override;
virtual void NativeOnInitialized() override;
virtual void NativeDestruct() override;
virtual void NativeTick(const FGeometry& MyGeometry, float InDeltaTime) override;

public:
UWG_WSInGameBundle(const FObjectInitializer& ObjectInitializer);

static FCTweenInstance* FadeInOut(bool bIsIn = false, float InDuration = 1.f);

protected:
Expand Down
2 changes: 2 additions & 0 deletions Source/wunthshin/Widgets/WG_WSUserWidgetBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ void UWG_WSUserWidgetBase::SetVisibleWidget(bool bIsVisible)
void UWG_WSUserWidgetBase::OnVisibleWidget()
{
SetVisibleWidget(true);
GetPlayerContext().GetPlayerController()->SetInputMode(FInputModeUIOnly{});
}

void UWG_WSUserWidgetBase::OnHideWidget()
{
SetVisibleWidget(false);
GetPlayerContext().GetPlayerController()->SetInputMode(FInputModeGameOnly{});
}
7 changes: 6 additions & 1 deletion Source/wunthshin/Widgets/WG_WSUserWidgetBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class WUNTHSHIN_API UWG_WSUserWidgetBase : public UUserWidget
{
GENERATED_BODY()

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, meta=(AllowPrivateAccess = "true"))
bool bInAnimation = false;

protected:
virtual void NativeConstruct() override;
bool InitializeWidget();
Expand All @@ -26,11 +29,13 @@ class WUNTHSHIN_API UWG_WSUserWidgetBase : public UUserWidget
void OnVisibleWidget();
UFUNCTION()
void OnHideWidget();

void SetInAnimation(const bool InValue) { bInAnimation = InValue; }
bool IsInAnimation() const { return bInAnimation; }

protected:
void SetVisibleWidget(bool bIsVisible);

protected:
UPROPERTY(VisibleAnywhere, meta = (BindWidget))
TMap<FName,class UWG_WSUserWidgetBase*> ChildWidgets;
};

0 comments on commit 3e89a5c

Please sign in to comment.