CustomizeWidget 중복 열림 방지

김여울·2025년 12월 19일

내일배움캠프

목록 보기
133/139

목표

컨트롤러에 bool 플래그를 만들고, 좌클릭 상호작용 시 체크해서 막기!

1️⃣ LNControllerInGame.h

private:
    // 커스터마이징 UI가 열려있는지 여부
    bool bIsCustomizeOpen = false;

public:
    // 커스터마이징 UI 열림/닫힘 상태 설정 함수
    UFUNCTION(BlueprintCallable, Category = "LN|Customize")
    void SetCustomizeOpen(bool bOpen);
    
    // 커스터마이징 UI가 열려있는지 확인하는 함수
    UFUNCTION(BlueprintPure, Category = "LN|Customize")
    bool IsCustomizeOpen() const { return bIsCustomizeOpen; }

2️⃣ LNControllerInGame.cpp

void ALNControllerInGame::SetCustomizeOpen(bool bOpen)
{
    bIsCustomizeOpen = bOpen;
    UE_LOG(LogTemp, Log, TEXT("[Controller] CustomizeOpen: %s"), bOpen ? TEXT("True") : TEXT("False"));
}

3️⃣ CustomizeWidget.cpp

NativeConstruct (위젯 열릴 때)

void UCustomizeWidget::NativeConstruct()
{
    Super::NativeConstruct();

    // ✅ 위젯 열릴 때 플래그 true로 설정
    if (ALNControllerInGame* PC = Cast<ALNControllerInGame>(GetOwningPlayer()))
    {
        PC->SetCustomizeOpen(true);
    }

    // ... 기존 코드
}

NativeDestruct (위젯 닫힐 때)

void UCustomizeWidget::NativeDestruct()
{
    // ✅ 위젯 닫힐 때 플래그 false로 설정
    if (ALNControllerInGame* PC = Cast<ALNControllerInGame>(GetOwningPlayer()))
    {
        PC->SetCustomizeOpen(false);
    }

    // ... 기존 코드 (카메라 복구 등)
    
    Super::NativeDestruct();
}

4️⃣ 좌클릭 상호작용 (CustomizeStation)

void ALNCustomizeStation::LeftClickInteract(AActor* Interactor)
{
	ALNCharacter* Character = Cast<ALNCharacter>(Interactor);
	if (!IsValid(Character)) return;

	ALNControllerInGame* PC = Cast<ALNControllerInGame>(Character->GetController());
	if (!IsValid(PC)) return;
	
    // 이미 CustomizeWidget이 열려있으면 무시
	if (PC->IsCustomizeOpen())
	{
		return;
	}
	// 커스터마이징 메뉴 생성
	PC->Client_OpenCustomizeUI();
}

동작 흐름

1. 상자 좌클릭
   → IsCustomizeOpen() 확인
   → false → CustomizeWidget 열림
   
2. CustomizeWidget.NativeConstruct()
   → SetCustomizeOpen(true) 호출
   
3. 위젯 열려있는 상태에서 다시 좌클릭
   → IsCustomizeOpen() 확인
   → true → Return (무시) 
   
4. CustomizeWidget 닫힘 (Save/Cancel)
   → NativeDestruct()
   → SetCustomizeOpen(false) 호출
   
5. 다시 좌클릭 가능 

0개의 댓글