KLingo Project Documentation 1.0.0
Unreal Engine 5.6 C++ Project Documentation
로딩중...
검색중...
일치하는것 없음
UDialogManager.cpp
이 파일의 문서화 페이지로 가기
1// Copyright (c) 2025 Doppleddiggong. All rights reserved. Unauthorized copying, modification, or distribution of this file, via any medium is strictly prohibited. Proprietary and confidential.
2
7#include "UDialogManager.h"
8
9#include "FComponentHelper.h"
10#include "UDialogWidget.h"
11#include "UObject/Object.h"
12
13#include "GameFramework/PlayerController.h"
14#include "Engine/LocalPlayer.h"
15#include "Engine/GameInstance.h"
16#include "Blueprint/UserWidget.h"
17#include "Engine/Engine.h"
18#include "Engine/World.h"
19#include "Onepiece/Onepiece.h"
20
21#define DIALOGWIDGET_PATH TEXT("/Game/CustomContents/UI/WBP_Dialog.WBP_Dialog_C")
22
27
29{
30 // 위젯이 있으면 정리
31 if (DialogWidget)
32 {
33 // 타이머 즉시 정리 (NativeDestruct보다 먼저)
34 DialogWidget->HideDialogImmediately();
35
36 // 뷰포트에서 제거
37 if (DialogWidget->IsInViewport())
38 {
39 DialogWidget->RemoveFromParent();
40 }
41
42 // 참조 해제
43 DialogWidget = nullptr;
44 }
45
46 Super::Deinitialize();
47}
48
50{
51 if (World == nullptr || !World->IsGameWorld())
52 return;
53
54 // 위젯이 유효하고 같은 월드이며, 뷰포트에 추가되어 있는지 확인
55 if (IsValid(DialogWidget) &&
56 DialogWidget->GetWorld() == World &&
57 DialogWidget->IsInViewport())
58 {
59 return;
60 }
61
62 // 기존 위젯이 있으면 정리
63 if (DialogWidget)
64 {
65 if (DialogWidget->IsInViewport())
66 DialogWidget->RemoveFromParent();
67
68 DialogWidget = nullptr;
69 }
70
71 ULocalPlayer* LocalPlayer = GetLocalPlayer();
72 if (LocalPlayer == nullptr)
73 return;
74
75 APlayerController* PC = LocalPlayer->GetPlayerController(World);
76 if (PC == nullptr)
77 return;
78
80 return;
81
82 UDialogWidget* NewWidget = CreateWidget<UDialogWidget>(PC, DialogWidgetClass);
83 if (!NewWidget)
84 return;
85
86 NewWidget->AddToViewport(GameLayer::ToastManager);
87 DialogWidget = NewWidget;
88}
89
90void UDialogManager::ShowToast(const FString& Message)
91{
92 if (Message.IsEmpty())
93 return;
94
95 UWorld* World = GetWorld();
96 if (!World)
97 return;
98
100
101 if (DialogWidget)
102 DialogWidget->ShowDialog(Message);
103}
104
106{
107 UWorld* World = GetWorld();
108 if (!World)
109 return;
110
111 if (!DialogWidget)
112 return;
113
114 if (DialogWidget->GetWorld() != World)
115 return;
116
117 DialogWidget->HideDialogImmediately();
118}
FComponentHelper 구조체를 선언합니다.
#define DIALOGWIDGET_PATH
UDialogManager 클래스를 선언합니다.
텍스트 출력하는 다이얼로그 위젯을 선언합니다.
void HideToastImmediately()
활성 토스트 메시지를 즉시 숨깁니다.
void EnsureWidgetForWorld(UWorld *World)
현재 월드에 위젯이 없으면 생성하고 뷰포트에 부착합니다.
TSubclassOf< class UDialogWidget > DialogWidgetClass
void ShowToast(const FString &Message)
TObjectPtr< class UDialogWidget > DialogWidget
virtual void Deinitialize() override
텍스트 출력하는 다이얼로그 위젯입니다.
static const int32 ToastManager
Definition Onepiece.h:13
static T * LoadAsset(const TCHAR *Path)