Space Plunder
Loading...
Searching...
No Matches
UNotificationManager Class Reference

#include <NotificationManager.h>

Inheritance diagram for UNotificationManager:
INotificationManagerInterface

Public Member Functions

 UNotificationManager (const FObjectInitializer &ObjectInitializer)
 
virtual void AddNotificationToQueue (const FNotificationData &Data) override
 
virtual void AddNotification (const FNotificationData &Data) override
 
virtual void UpdateValue (const int32 IncreaseAmount, const int32 TotalValue, const FGameplayTag &HUDSlot) override
 
virtual bool GetIsShowingNotification (FUniqueID &UniqueID) const override
 
bool GetIsShowingNotification () const
 

Protected Member Functions

virtual bool Initialize () override
 
virtual void NativePreConstruct () override
 
virtual void NativeConstruct () override
 
void OnShowNotifications ()
 
void OnStopNotifications ()
 
void GetSlots ()
 
USlotWidgetFindSlotByTag (const FGameplayTag &SlotTag) const
 

Protected Attributes

bool bDebuggingMode = false
 
bool bMultipleAtOnce = true
 
bool bInstant = false
 
float NextNotificationTime = 3.0f
 
float InitialNotificationDelay = 3.0f
 
float EndNotificationDelay = 5.0f
 
TArray< FNotificationDataNotificationsQueue
 
class UOverlay * NotificationOverlay = nullptr
 
class UOverlay * SlotsOverlay = nullptr
 
TMap< FGameplayTag, USlotWidget * > HUDSlots
 
TMap< FGameplayTag, TSubclassOf< UUserWidget > > SlotWidgetClasses
 

Private Member Functions

void ShowNotifications ()
 
void AddNotification ()
 
void StopNotifications ()
 
bool IsValidSlot (const FGameplayTag &SlotTag) const
 
TSubclassOf< UUserWidget > GetCustomClass (const FGameplayTag &SlotTag)
 

Private Attributes

TSubclassOf< UUserWidget > NotificationWidgetClass
 
int32 CurrentIndex = 0
 
bool bIsShowingNotification = false
 
INotificationInterfaceCurrentNotification = nullptr
 
FTimerHandle NotificationTimerHandle
 
FTimerHandle InitialNotificationTimerHandle
 
FTimerHandle NotificationEndTimerHandle
 

Constructor & Destructor Documentation

◆ UNotificationManager()

UNotificationManager::UNotificationManager ( const FObjectInitializer & ObjectInitializer)
explicit
10 :Super(ObjectInitializer)
11{
12
13}

Member Function Documentation

◆ AddNotification() [1/2]

void UNotificationManager::AddNotification ( )
private
147{
148 if(bMultipleAtOnce == false)
149 {
150 NotificationOverlay->ClearChildren();
151 }
152 if(NotificationsQueue.IsEmpty() == false)
153 {
155 if(bDebuggingMode){UE_LOG(LogBaseWidgets ,Warning,TEXT("UNotificationManager::AddNotification Add Notification Widget"));}
156 const FNotificationData& Data = NotificationsQueue[0];
157 TSubclassOf<UUserWidget> WidgetClass = NotificationWidgetClass;
158 if(Data.bUseCustomClass && GetCustomClass(Data.SlotName) != nullptr)
159 {
160 WidgetClass = GetCustomClass(Data.SlotName);
161 }
162 UUserWidget* NotificationWidget = CreateWidget<UUserWidget>(GetOwningPlayer(), WidgetClass);
163 if(NotificationWidget == nullptr){UE_LOG(LogBaseWidgets ,Error,TEXT("UNotificationManager::AddNotification NotificationWidget null"));StopNotifications();return;}
164 CurrentNotification = Cast<INotificationInterface>(NotificationWidget);
165 if(CurrentNotification == nullptr)
166 {
167 UE_LOG(LogBaseWidgets, Error, TEXT("UNotificationManager::AddNotification INotificationInterface null"));
168 return;
169 }
172
173 if(Data.bUseSlot && IsValidSlot(Data.SlotName))
174 {
175 const USlotWidget* SlotWidget = FindSlotByTag(Data.SlotName);
176 if(SlotWidget == nullptr){UE_LOG(LogBaseWidgets, Error, TEXT("UNotificationManager::AddNotification Slot %s Doesn't Exist on %s"), *Data.SlotName.ToString(), *GetName())return;}
177 SlotWidget->AddWidgetToSlot(NotificationWidget, false);
178 }
179 else
180 {
181 NotificationOverlay->AddChildToOverlay(NotificationWidget);
182 }
183 NotificationsQueue.RemoveAt(0);
184 if(bInstant)
185 {
186 GetWorld()->GetTimerManager().ClearTimer(NotificationEndTimerHandle);
188 return;
189 }
190 float FullNextNotificationTime = NextNotificationTime;
191 if(Data.bUseCustomLife)
192 {
193 FullNextNotificationTime += Data.LifeDuration;
194 }
195 GetWorld()->GetTimerManager().SetTimer(NotificationTimerHandle, this, &UNotificationManager::AddNotification, FullNextNotificationTime);
196 }
197 else
198 {
200 GetWorld()->GetTimerManager().SetTimer(NotificationEndTimerHandle, this, &UNotificationManager::StopNotifications, EndNotificationDelay);
201 }
202}
virtual void SetLifeDuration(const float Value)=0
virtual void SetNotificationData(const FNotificationData &Data)=0
bool IsValidSlot(const FGameplayTag &SlotTag) const
Definition NotificationManager.cpp:204
float NextNotificationTime
Definition NotificationManager.h:57
TSubclassOf< UUserWidget > NotificationWidgetClass
Definition NotificationManager.h:87
bool bMultipleAtOnce
Definition NotificationManager.h:53
float EndNotificationDelay
Definition NotificationManager.h:61
FTimerHandle NotificationTimerHandle
Definition NotificationManager.h:97
bool bInstant
Definition NotificationManager.h:55
USlotWidget * FindSlotByTag(const FGameplayTag &SlotTag) const
Definition NotificationManager.cpp:49
void AddNotification()
Definition NotificationManager.cpp:146
TSubclassOf< UUserWidget > GetCustomClass(const FGameplayTag &SlotTag)
Definition NotificationManager.cpp:211
class UOverlay * NotificationOverlay
Definition NotificationManager.h:66
void StopNotifications()
Definition NotificationManager.cpp:222
bool bIsShowingNotification
Definition NotificationManager.h:92
bool bDebuggingMode
Definition NotificationManager.h:50
INotificationInterface * CurrentNotification
Definition NotificationManager.h:94
TArray< FNotificationData > NotificationsQueue
Definition NotificationManager.h:63
FTimerHandle NotificationEndTimerHandle
Definition NotificationManager.h:101
Definition SlotWidget.h:16
Definition RadialWheelData.h:17
bool bUseSlot
Definition RadialWheelData.h:31
bool bUseCustomClass
Definition RadialWheelData.h:42
FGameplayTag SlotName
Definition RadialWheelData.h:33
bool bUseCustomLife
Definition RadialWheelData.h:45
float LifeDuration
Definition RadialWheelData.h:47

◆ AddNotification() [2/2]

void UNotificationManager::AddNotification ( const FNotificationData & Data)
overridevirtual

Implements INotificationManagerInterface.

80{
81 if(bDebuggingMode){UE_LOG(LogBaseWidgets ,Warning,TEXT("UNotificationManager::AddNotification Add Notification Widget"));}
82 TSubclassOf<UUserWidget> WidgetClass = NotificationWidgetClass;
83 if(Data.bUseCustomClass && GetCustomClass(Data.SlotName) != nullptr)
84 {
85 WidgetClass = GetCustomClass(Data.SlotName);
86 }
87 UUserWidget* NotificationWidget = CreateWidget<UUserWidget>(GetOwningPlayer(), WidgetClass);
88 if(NotificationWidget == nullptr){UE_LOG(LogBaseWidgets ,Error,TEXT("UNotificationManager::AddNotification NotificationWidget null"));return;}
89 INotificationInterface* Notification = Cast<INotificationInterface>(NotificationWidget);
90 if(Notification == nullptr)
91 {
92 UE_LOG(LogBaseWidgets, Error, TEXT("UNotificationManager::AddNotification INotificationInterface null"));
93 return;
94 }
95 float Lifetime = NextNotificationTime;
96 if(Data.bUseCustomLife)
97 {
98 Lifetime = Data.LifeDuration;
99 }
100 Notification->SetLifeDuration(Lifetime);
101 Notification->SetNotificationData(Data);
102
103 if(Data.bUseSlot && IsValidSlot(Data.SlotName))
104 {
105 const USlotWidget* SlotWidget = FindSlotByTag(Data.SlotName);
106 if(SlotWidget == nullptr){UE_LOG(LogBaseWidgets, Error, TEXT("UNotificationManager::AddNotification Slot %s Doesn't Exist on %s"), *Data.SlotName.ToString(), *GetName())return;}
107 SlotWidget->AddWidgetToSlot(NotificationWidget, false);
108 }
109 else
110 {
111 NotificationOverlay->AddChildToOverlay(NotificationWidget);
112 }
113}
Definition NotificationInterface.h:21

◆ AddNotificationToQueue()

void UNotificationManager::AddNotificationToQueue ( const FNotificationData & Data)
overridevirtual

Implements INotificationManagerInterface.

65{
66 NotificationsQueue.Add(Data);
67 GetWorld()->GetTimerManager().ClearTimer(NotificationEndTimerHandle);
68 if(bInstant)
69 {
71 return;
72 }
73 if(bIsShowingNotification == false)
74 {
76 }
77}
FTimerHandle InitialNotificationTimerHandle
Definition NotificationManager.h:99
float InitialNotificationDelay
Definition NotificationManager.h:59
void ShowNotifications()
Definition NotificationManager.cpp:138

◆ FindSlotByTag()

USlotWidget * UNotificationManager::FindSlotByTag ( const FGameplayTag & SlotTag) const
protected
50{
51 for(int32 i = 0; i < SlotsOverlay->GetChildrenCount(); ++i)
52 {
53 if(SlotsOverlay->GetChildAt(i) == nullptr){continue;}
54 USlotWidget* SlotWidget = Cast<USlotWidget>(SlotsOverlay->GetChildAt(i));
55 if(SlotWidget == nullptr){continue;}
56 if(SlotTag == SlotWidget->SlotTag)
57 {
58 return SlotWidget;
59 }
60 }
61 return nullptr;
62}
class UOverlay * SlotsOverlay
Definition NotificationManager.h:68
FGameplayTag SlotTag
Definition SlotWidget.h:22

◆ GetCustomClass()

TSubclassOf< UUserWidget > UNotificationManager::GetCustomClass ( const FGameplayTag & SlotTag)
private
212{
213 if(SlotWidgetClasses.Find(SlotTag) != nullptr)
214 {
215 const TSubclassOf<UUserWidget>* WidgetPtr = SlotWidgetClasses.Find(SlotTag);
216 return *WidgetPtr;
217 }
218 return nullptr;
219}
TMap< FGameplayTag, TSubclassOf< UUserWidget > > SlotWidgetClasses
Definition NotificationManager.h:74

◆ GetIsShowingNotification() [1/2]

bool UNotificationManager::GetIsShowingNotification ( ) const
inline
31{ return bIsShowingNotification; };

◆ GetIsShowingNotification() [2/2]

bool UNotificationManager::GetIsShowingNotification ( FUniqueID & UniqueID) const
overridevirtual

Returns if showing a notification and the ID of the one showwing

Implements INotificationManagerInterface.

121{
123 {
124 if(CurrentNotification != nullptr)
125 {
127 }
128 else
129 {
130 return false;
131 }
132 }
134}
virtual FNotificationData GetNotificationData() const =0
FUniqueID NotificationID
Definition RadialWheelData.h:21

◆ GetSlots()

void UNotificationManager::GetSlots ( )
protected
39{
40 if(SlotsOverlay == nullptr){return;}
41 for(const auto Widget : SlotsOverlay->GetAllChildren())
42 {
43 USlotWidget* SlotWidget = Cast<USlotWidget>(Widget);
44 if(SlotWidget == nullptr){continue;}
45 HUDSlots.Add(SlotWidget->SlotTag, SlotWidget);
46 }
47}
TMap< FGameplayTag, USlotWidget * > HUDSlots
Definition NotificationManager.h:71

◆ Initialize()

bool UNotificationManager::Initialize ( )
overrideprotectedvirtual
16{
17 const bool Success = Super::Initialize();
18 if(!Success) return false;
19 if (!ensure(NotificationOverlay != nullptr)) return false;
20 if (!ensure(SlotsOverlay != nullptr)) return false;
21
22 return true;
23}

◆ IsValidSlot()

bool UNotificationManager::IsValidSlot ( const FGameplayTag & SlotTag) const
private
205{
206 const USlotWidget* SlotWidget = FindSlotByTag(SlotTag);
207 if(SlotWidget == nullptr){UE_LOG(LogBaseWidgets, Error, TEXT("UNotificationManager::IsValidSlot Slot %s Doesn't Exist on %s"), *SlotTag.ToString(), *GetName());return false;}
208 return true;
209}

◆ NativeConstruct()

void UNotificationManager::NativeConstruct ( )
overrideprotectedvirtual
32{
33 Super::NativeConstruct();
34 GetSlots();
35 if(NotificationWidgetClass == nullptr){UE_LOG(LogBaseWidgets, Error, TEXT("NotificationWidgetClass NUll in UNotificationManager"));}
36}
void GetSlots()
Definition NotificationManager.cpp:38

◆ NativePreConstruct()

void UNotificationManager::NativePreConstruct ( )
overrideprotectedvirtual
26{
27 Super::NativePreConstruct();
28 GetSlots();
29}

◆ OnShowNotifications()

void UNotificationManager::OnShowNotifications ( )
protected

◆ OnStopNotifications()

void UNotificationManager::OnStopNotifications ( )
protected

◆ ShowNotifications()

void UNotificationManager::ShowNotifications ( )
private
139{
140 if(NotificationWidgetClass == nullptr){UE_LOG(LogBaseWidgets, Error, TEXT("NotificationWidgetClass NUll in UNotificationManager"));return;}
142 // bIsShowingNotification = true;
144}

◆ StopNotifications()

void UNotificationManager::StopNotifications ( )
private
223{
224 if(bDebuggingMode){UE_LOG(LogBaseWidgets ,Warning,TEXT("Stop Notifications"));}
226 if(NotificationOverlay != nullptr)
227 {
228 NotificationOverlay->ClearChildren();
229 }
230 NotificationsQueue.Empty();
232}

◆ UpdateValue()

void UNotificationManager::UpdateValue ( const int32 IncreaseAmount,
const int32 TotalValue,
const FGameplayTag & HUDSlot )
overridevirtual

Implements INotificationManagerInterface.

116{
117 //@TODO UpdateValue , Maybe Change Vars to be able to just be A seperate Value
118}

Member Data Documentation

◆ bDebuggingMode

bool UNotificationManager::bDebuggingMode = false
protected

◆ bInstant

bool UNotificationManager::bInstant = false
protected

◆ bIsShowingNotification

bool UNotificationManager::bIsShowingNotification = false
private

◆ bMultipleAtOnce

bool UNotificationManager::bMultipleAtOnce = true
protected

◆ CurrentIndex

int32 UNotificationManager::CurrentIndex = 0
private

◆ CurrentNotification

INotificationInterface* UNotificationManager::CurrentNotification = nullptr
private

◆ EndNotificationDelay

float UNotificationManager::EndNotificationDelay = 5.0f
protected

◆ HUDSlots

TMap<FGameplayTag, USlotWidget*> UNotificationManager::HUDSlots
protected

◆ InitialNotificationDelay

float UNotificationManager::InitialNotificationDelay = 3.0f
protected

◆ InitialNotificationTimerHandle

FTimerHandle UNotificationManager::InitialNotificationTimerHandle
private

◆ NextNotificationTime

float UNotificationManager::NextNotificationTime = 3.0f
protected

◆ NotificationEndTimerHandle

FTimerHandle UNotificationManager::NotificationEndTimerHandle
private

◆ NotificationOverlay

class UOverlay* UNotificationManager::NotificationOverlay = nullptr
protected

◆ NotificationsQueue

TArray<FNotificationData> UNotificationManager::NotificationsQueue
protected

◆ NotificationTimerHandle

FTimerHandle UNotificationManager::NotificationTimerHandle
private

◆ NotificationWidgetClass

TSubclassOf<UUserWidget> UNotificationManager::NotificationWidgetClass
private

◆ SlotsOverlay

class UOverlay* UNotificationManager::SlotsOverlay = nullptr
protected

◆ SlotWidgetClasses

TMap<FGameplayTag, TSubclassOf<UUserWidget> > UNotificationManager::SlotWidgetClasses
protected

The documentation for this class was generated from the following files: