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

#include <InteractionContextWidget.h>

Inheritance diagram for UInteractionContextWidget:
IInteractionHUD

Public Member Functions

 UInteractionContextWidget (const FObjectInitializer &ObjectInitializer)
 
virtual bool Initialize () override
 
virtual void NativeConstruct () override
 
virtual void SetAiming (const bool bValue) override
 
void StartedAiming ()
 
void StoppedAiming ()
 
virtual void StartFocusOnObject (const FString &ObjectName, const FInteractionData &InteractionData) override
 
virtual void StartFocusOnCharacter (const FString &CharacterName, const FInteractionData &InteractionData) override
 
virtual void ShowCustomPrompt (const FInteractionData &InteractionData) override
 
virtual void SetSelectedInteraction (const int32 Index) override
 
virtual void StartSelection (const float Time) override
 
virtual void StopSelection () override
 
virtual void HideCustomPrompt () override
 
virtual void EndFocus () override
 
void OnStartFocusOnObject (const FString &ObjectName, const FInteractionData &InteractionData)
 
void OnStartFocusOnCharacter (const FString &CharacterName, const FInteractionData &InteractionData)
 
void OnShowCustomPrompt (const FInteractionData &InteractionData)
 
void OnHideCustomPrompt ()
 
void OnEndFocus ()
 
UWidget * GetCurrentSelection () const
 

Protected Attributes

int32 SelectedIndex = 0
 
class UOverlay * ContextOverlay = nullptr
 
class UVerticalBox * ContextVerticalBox = nullptr
 
class UVerticalBox * PromptVerticalBox = nullptr
 

Private Attributes

TSubclassOf< class UInteractionTypeWidgetInteractionTypeWidgetClass
 
FInteractionData CurrentInteractionData
 

Constructor & Destructor Documentation

◆ UInteractionContextWidget()

UInteractionContextWidget::UInteractionContextWidget ( const FObjectInitializer & ObjectInitializer)
13 : Super(ObjectInitializer)
14{
15 const ConstructorHelpers::FClassFinder<UInteractionTypeWidget> InteractionTypeBP(TEXT("/Interaction/Widgets/WBP_InteractionType"));
16 if (!ensure(InteractionTypeBP.Class != nullptr)) return;
17 InteractionTypeWidgetClass = InteractionTypeBP.Class;
18}
TSubclassOf< class UInteractionTypeWidget > InteractionTypeWidgetClass
Definition InteractionContextWidget.h:75

Member Function Documentation

◆ EndFocus()

void UInteractionContextWidget::EndFocus ( )
overridevirtual

Implements IInteractionHUD.

331{
332 // ContextVerticalBox->ClearChildren();
334 ContextVerticalBox->SetVisibility(ESlateVisibility::Collapsed);
335 ContextOverlay->SetRenderOpacity(0.0f);
336 SelectedIndex = 0;
337 OnEndFocus();
338}
int32 SelectedIndex
Definition InteractionContextWidget.h:63
FInteractionData CurrentInteractionData
Definition InteractionContextWidget.h:77
class UOverlay * ContextOverlay
Definition InteractionContextWidget.h:67
class UVerticalBox * ContextVerticalBox
Definition InteractionContextWidget.h:69
static FInteractionData None()
Definition BaseData.h:583

◆ GetCurrentSelection()

UWidget * UInteractionContextWidget::GetCurrentSelection ( ) const
341{
342 UInteractionTypeWidget* Selection = Cast<UInteractionTypeWidget>(ContextVerticalBox->GetChildAt(SelectedIndex));
343 if(Selection == nullptr){return nullptr;}
344 return Selection;
345
346}
Definition InteractionTypeWidget.h:14

◆ HideCustomPrompt()

void UInteractionContextWidget::HideCustomPrompt ( )
overridevirtual

Implements IInteractionHUD.

325{
327 PromptVerticalBox->ClearChildren();
328}
class UVerticalBox * PromptVerticalBox
Definition InteractionContextWidget.h:71

◆ Initialize()

bool UInteractionContextWidget::Initialize ( )
overridevirtual
21{
22 const bool Success = Super::Initialize();
23 if(!Success) return false;
24 if (!ensure(ContextOverlay != nullptr)) return false;
25 if (!ensure(ContextVerticalBox != nullptr)) return false;
26 if (!ensure(InteractionTypeWidgetClass != nullptr)) return false;
27 if (!ensure(PromptVerticalBox != nullptr)) return false;
28 return true;
29}

◆ NativeConstruct()

void UInteractionContextWidget::NativeConstruct ( )
overridevirtual
32{
33 Super::NativeConstruct();
34 ContextVerticalBox->ClearChildren();
35 SelectedIndex = 0;
36}

◆ OnEndFocus()

void UInteractionContextWidget::OnEndFocus ( )

◆ OnHideCustomPrompt()

void UInteractionContextWidget::OnHideCustomPrompt ( )

◆ OnShowCustomPrompt()

void UInteractionContextWidget::OnShowCustomPrompt ( const FInteractionData & InteractionData)

◆ OnStartFocusOnCharacter()

void UInteractionContextWidget::OnStartFocusOnCharacter ( const FString & CharacterName,
const FInteractionData & InteractionData )

◆ OnStartFocusOnObject()

void UInteractionContextWidget::OnStartFocusOnObject ( const FString & ObjectName,
const FInteractionData & InteractionData )

◆ SetAiming()

void UInteractionContextWidget::SetAiming ( const bool bValue)
overridevirtual

Implements IInteractionHUD.

39{
40 if(bValue)
41 {
43 }
44 else
45 {
47 }
48}

◆ SetSelectedInteraction()

void UInteractionContextWidget::SetSelectedInteraction ( const int32 Index)
overridevirtual

Implements IInteractionHUD.

299{
300 UInteractionTypeWidget* Selection = Cast<UInteractionTypeWidget>(ContextVerticalBox->GetChildAt(SelectedIndex));
301 if(Selection == nullptr){return;}
302 Selection->SetSelected(false);
303 SelectedIndex = Index;
304 UInteractionTypeWidget* NewSelection = Cast<UInteractionTypeWidget>(ContextVerticalBox->GetChildAt(SelectedIndex));
305 if(NewSelection == nullptr){return;}
306 NewSelection->SetSelected(true);
307 // UE_LOG(LogTemp, Warning, TEXT("Selected Index: %i"), SelectedIndex);
308}
void SetSelected(const bool bValue)
Definition InteractionTypeWidget.cpp:48

◆ ShowCustomPrompt()

void UInteractionContextWidget::ShowCustomPrompt ( const FInteractionData & InteractionData)
overridevirtual

Implements IInteractionHUD.

258{
259 OnShowCustomPrompt(InteractionData);
260 PromptVerticalBox->ClearChildren();
261 if(InteractionData.DefaultInteraction == -1){return;}
262 ContextOverlay->SetRenderOpacity(1.0f);
263 FInteractionType DefaultInteraction;
264 if(InteractionData.bShowDefault && InteractionData.GetDefaultInteraction(DefaultInteraction))
265 {
266 if(DefaultInteraction.bHide){return;}
267 UInteractionTypeWidget* SingleBoxWidget = CreateWidget<UInteractionTypeWidget>(GetOwningPlayer(), InteractionTypeWidgetClass);
268 if(SingleBoxWidget == nullptr){return;}
269 //@TODO Get Input Key //
270 const FString EnumValue = UBaseHelpersBPLib::GetEnumValue(UEnum::GetValueAsString(DefaultInteraction.InteractionType));
271 // UBaseHelpersBPLib::Action
272 SingleBoxWidget->SetInteractionText("", EnumValue, "");
273 SingleBoxWidget->SetAvailable(DefaultInteraction.bAvailable);
274 SingleBoxWidget->SetHasProgress(DefaultInteraction.bHold);
275 SingleBoxWidget->SetSelected(true);
276 PromptVerticalBox->AddChildToVerticalBox(SingleBoxWidget);
277 return;
278 }
279 int32 Index = 0;
280 for(const auto& InteractionType : InteractionData.InteractionTypes)
281 {
282 if(InteractionType.bHide){Index++;continue;}
283 UInteractionTypeWidget* SingleBoxWidget = CreateWidget<UInteractionTypeWidget>(GetOwningPlayer(), InteractionTypeWidgetClass);
284 if(SingleBoxWidget == nullptr){Index++;continue;}
285 FString EnumValue = UBaseHelpersBPLib::GetEnumValue(UEnum::GetValueAsString(InteractionType.InteractionType));
286 SingleBoxWidget->SetInteractionText("", EnumValue, "");
287 SingleBoxWidget->SetHasProgress(InteractionType.bHold);
288 SingleBoxWidget->SetAvailable(InteractionType.bAvailable);
289 if(Index == SelectedIndex)
290 {
291 SingleBoxWidget->SetSelected(true);
292 }
293 PromptVerticalBox->AddChildToVerticalBox(SingleBoxWidget);
294 Index++;
295 }
296}
static FString GetEnumValue(const FString &BaseString)
Definition BaseHelpersBPLib.cpp:511
void OnShowCustomPrompt(const FInteractionData &InteractionData)
void SetAvailable(const bool bValue)
Definition InteractionTypeWidget.cpp:67
void SetInteractionText(const FString &Key="[E]", const FString &InteractionType="Open", const FString &Name="Door") const
Definition InteractionTypeWidget.cpp:37
void SetHasProgress(const bool bValue) const
Definition InteractionTypeWidget.cpp:62
int32 DefaultInteraction
Definition BaseData.h:443
bool bShowDefault
Definition BaseData.h:440
bool GetDefaultInteraction(FInteractionType &Default) const
Definition BaseData.h:473
Definition BaseData.h:333
bool bHide
Definition BaseData.h:343
bool bHold
Definition BaseData.h:339
bool bAvailable
Definition BaseData.h:341
EInteractionType InteractionType
Definition BaseData.h:337

◆ StartedAiming()

void UInteractionContextWidget::StartedAiming ( )

◆ StartFocusOnCharacter()

void UInteractionContextWidget::StartFocusOnCharacter ( const FString & CharacterName,
const FInteractionData & InteractionData )
overridevirtual

Implements IInteractionHUD.

207{
208 StartFocusOnObject(CharacterName, InteractionData);
209 return;
210 ContextVerticalBox->SetVisibility(ESlateVisibility::Visible);
211 ContextOverlay->SetRenderOpacity(1.0f);
212 if(CurrentInteractionData == InteractionData)
213 {
214
215 //- Update bHold, bAvailable, bHide //
216 return;
217 }
218 OnStartFocusOnCharacter(CharacterName, InteractionData);
219 CurrentInteractionData = InteractionData;
220 ContextVerticalBox->ClearChildren();
221 if(InteractionData.DefaultInteraction == -1){return;}
222 FInteractionType DefaultInteraction;
223 if(InteractionData.bShowDefault && InteractionData.GetDefaultInteraction(DefaultInteraction))
224 {
225 if(DefaultInteraction.bHide){return;}
226 UInteractionTypeWidget* SingleBoxWidget = CreateWidget<UInteractionTypeWidget>(GetOwningPlayer(), InteractionTypeWidgetClass);
227 if(SingleBoxWidget == nullptr){return;}
228 //@TODO Get Input Key //
229
230 const FString EnumValue = UBaseHelpersBPLib::GetEnumValue(UEnum::GetValueAsString(DefaultInteraction.InteractionType));
231 SingleBoxWidget->SetInteractionText("", EnumValue, CharacterName);
232 SingleBoxWidget->SetAvailable(DefaultInteraction.bAvailable);
233 SingleBoxWidget->SetHasProgress(DefaultInteraction.bHold);
234 SingleBoxWidget->SetSelected(true);
235 ContextVerticalBox->AddChildToVerticalBox(SingleBoxWidget);
236 return;
237 }
238 int32 Index = 0;
239 for(const auto& InteractionType : InteractionData.InteractionTypes)
240 {
241 if(InteractionType.bHide){Index++;continue;}
242 UInteractionTypeWidget* SingleBoxWidget = CreateWidget<UInteractionTypeWidget>(GetOwningPlayer(), InteractionTypeWidgetClass);
243 if(SingleBoxWidget == nullptr){Index++;continue;}
244 FString EnumValue = UBaseHelpersBPLib::GetEnumValue(UEnum::GetValueAsString(InteractionType.InteractionType));
245 SingleBoxWidget->SetInteractionText("", EnumValue, CharacterName);
246 SingleBoxWidget->SetHasProgress(InteractionType.bHold);
247 SingleBoxWidget->SetAvailable(InteractionType.bAvailable);
248 if(Index == SelectedIndex)
249 {
250 SingleBoxWidget->SetSelected(true);
251 }
252 ContextVerticalBox->AddChildToVerticalBox(SingleBoxWidget);
253 Index++;
254 }
255}
void OnStartFocusOnCharacter(const FString &CharacterName, const FInteractionData &InteractionData)
virtual void StartFocusOnObject(const FString &ObjectName, const FInteractionData &InteractionData) override
Definition InteractionContextWidget.cpp:52

◆ StartFocusOnObject()

void UInteractionContextWidget::StartFocusOnObject ( const FString & ObjectName,
const FInteractionData & InteractionData )
overridevirtual

Implements IInteractionHUD.

53{
54 ContextVerticalBox->SetVisibility(ESlateVisibility::Visible);
55 ContextOverlay->SetRenderOpacity(1.0f);
56 if(CurrentInteractionData == InteractionData)
57 {
58 //- We need to Compare the Interaction Data Types with the CurrentInteractionData Types, to check if we need to unhide something //
60 {
61 // UE_LOG(LogTemp,Warning,TEXT("Visible Interactions Same"));
62 //? Extract to Function //
63 int32 Index = 0;
64 for(const auto& InteractionType : InteractionData.GetVisibleInteractions())
65 {
66 if(ContextVerticalBox->GetChildAt(Index) == nullptr){Index++;continue;}
67 UInteractionTypeWidget* SingleBoxWidget = Cast<UInteractionTypeWidget>(ContextVerticalBox->GetChildAt(Index));
68 if(SingleBoxWidget == nullptr){Index++;continue;}
69 SingleBoxWidget->SetAvailable(InteractionType.bAvailable);
70 SingleBoxWidget->SetHasProgress(InteractionType.bHold);
71 if(Index == SelectedIndex)
72 {
73 SingleBoxWidget->SetSelected(true);
74 }
75 Index++;
76 //- Update bHold, bAvailable, bHide //
77 }
78 CurrentInteractionData = InteractionData;
79 // UE_LOG(LogTemp, Warning, TEXT("Update Interaction Context"));
80 return;
81 }
82
83 // else
84 // {
85 // TArray<FInteractionType> NewInteractions;
86 // for (const FInteractionType& Interaction : InteractionData.GetVisibleInteractions())
87 // {
88 // if(!CurrentInteractionData.GetVisibleInteractions().Contains(Interaction))
89 // {
90 // NewInteractions.Add(Interaction);
91 // }
92 // }
93 // UE_LOG(LogTemp,Warning,TEXT("New Interactions: %i"), NewInteractions.Num());
94 //
95 // int32 Index = 0;
96 // for(const auto& Interaction : NewInteractions)
97 // {
98 // UInteractionTypeWidget* SingleBoxWidget = CreateWidget<UInteractionTypeWidget>(GetOwningPlayer(), InteractionTypeWidgetClass);
99 // const FString EnumValue = UBaseHelpersBPLib::GetEnumValue(UEnum::GetValueAsString(Interaction.InteractionType));
100 // SingleBoxWidget->SetInteractionText("", EnumValue, ObjectName);
101 // SingleBoxWidget->SetAvailable(Interaction.bAvailable);
102 // SingleBoxWidget->SetHasProgress(Interaction.bHold);
103 // if(Index == SelectedIndex)
104 // {
105 // SingleBoxWidget->SetSelected(true);
106 // }
107 // ContextVerticalBox->AddChildToVerticalBox(SingleBoxWidget);
108 // Index++;
109 // }
110 // UE_LOG(LogTemp,Warning,TEXT("Change Interactions - Hide UnHide"));
111 // CurrentInteractionData = InteractionData;
112 // return;
113 // }
114 //- !!
115 // int32 Index = 0;
116 // for(const auto& InteractionType : InteractionData.InteractionTypes)
117 // {
118 // if(ContextVerticalBox->GetChildAt(Index) == nullptr)
119 // {
120 // if(CurrentInteractionData.InteractionTypes[Index].bHide != InteractionType.bHide)
121 // {
122 // //- Change From hide to unhide //
123 // }
124 // Index++;continue;
125 // }
126 // if(InteractionType.bHide)
127 // {
128 // const UInteractionTypeWidget* SingleBoxWidget = Cast<UInteractionTypeWidget>(ContextVerticalBox->GetChildAt(Index));
129 // if(SingleBoxWidget == nullptr){Index++;continue;}
130 // ContextVerticalBox->RemoveChildAt(Index);
131 // //? Don't Increase Index if Removing Item?
132 // continue;
133 // }
134 // else
135 // {
136 // //@TODO Unhide ?
137 // UInteractionTypeWidget* SingleBoxWidget = CreateWidget<UInteractionTypeWidget>(GetOwningPlayer(), InteractionTypeWidgetClass);
138 // const FString EnumValue = UBaseHelpersBPLib::GetEnumValue(UEnum::GetValueAsString(InteractionType.InteractionType));
139 // SingleBoxWidget->SetInteractionText("", EnumValue, ObjectName);
140 // SingleBoxWidget->SetAvailable(InteractionType.bAvailable);
141 // SingleBoxWidget->SetHasProgress(InteractionType.bHold);
142 // SingleBoxWidget->SetSelected(true);
143 // ContextVerticalBox->AddChildToVerticalBox(SingleBoxWidget);
144 // }
145 //
146 //
147 // UInteractionTypeWidget* SingleBoxWidget = Cast<UInteractionTypeWidget>(ContextVerticalBox->GetChildAt(Index));
148 // if(SingleBoxWidget == nullptr){Index++;continue;}
149 // SingleBoxWidget->SetAvailable(InteractionType.bAvailable);
150 // SingleBoxWidget->SetHasProgress(InteractionType.bHold);
151 // if(Index == SelectedIndex)
152 // {
153 // SingleBoxWidget->SetSelected(true);
154 // }
155 // Index++;
156 // UE_LOG(LogTemp, Warning, TEXT("Update Interaction Context"));
157 //
158 // }
159 // //- Update bHold, bAvailable, bHide //
160 // return;
161 }
162
163 OnStartFocusOnObject(ObjectName, InteractionData);
164 CurrentInteractionData = InteractionData;
165
166
167 ContextVerticalBox->ClearChildren();
168
169 if(InteractionData.DefaultInteraction == -1){return;}
170 FInteractionType DefaultInteraction;
171 if(InteractionData.bShowDefault && InteractionData.GetDefaultInteraction(DefaultInteraction))
172 {
173 if(DefaultInteraction.bHide){return;}
174 UInteractionTypeWidget* SingleBoxWidget = CreateWidget<UInteractionTypeWidget>(GetOwningPlayer(), InteractionTypeWidgetClass);
175 if(SingleBoxWidget == nullptr){return;}
176 //@TODO Get Input Key //
177 const FString EnumValue = UBaseHelpersBPLib::GetEnumValue(UEnum::GetValueAsString(DefaultInteraction.InteractionType));
178 SingleBoxWidget->SetInteractionText("", EnumValue, ObjectName);
179 SingleBoxWidget->SetAvailable(DefaultInteraction.bAvailable);
180 SingleBoxWidget->SetHasProgress(DefaultInteraction.bHold);
181 SingleBoxWidget->SetSelected(true);
182 ContextVerticalBox->AddChildToVerticalBox(SingleBoxWidget);
183 return;
184 }
185 int32 Index = 0;
186 for(const auto& InteractionType : InteractionData.InteractionTypes)
187 {
188 if(InteractionType.bHide){Index++;continue;}
189 UInteractionTypeWidget* SingleBoxWidget = CreateWidget<UInteractionTypeWidget>(GetOwningPlayer(), InteractionTypeWidgetClass);
190 if(SingleBoxWidget == nullptr){Index++;continue;}
191 //@TODO Get Input Key //
192 const FString EnumValue = UBaseHelpersBPLib::GetEnumValue(UEnum::GetValueAsString(InteractionType.InteractionType));
193 SingleBoxWidget->SetInteractionText("", EnumValue, ObjectName);
194 SingleBoxWidget->SetHasProgress(InteractionType.bHold);
195 SingleBoxWidget->SetAvailable(InteractionType.bAvailable);
196 if(Index == SelectedIndex)
197 {
198 SingleBoxWidget->SetSelected(true);
199 }
200 ContextVerticalBox->AddChildToVerticalBox(SingleBoxWidget);
201 Index++;
202 }
203}
void OnStartFocusOnObject(const FString &ObjectName, const FInteractionData &InteractionData)
TArray< FInteractionType > GetVisibleInteractions() const
Definition BaseData.h:556

◆ StartSelection()

void UInteractionContextWidget::StartSelection ( const float Time)
overridevirtual

Implements IInteractionHUD.

311{
312 UInteractionTypeWidget* Selection = Cast<UInteractionTypeWidget>(ContextVerticalBox->GetChildAt(SelectedIndex));
313 if(Selection == nullptr){return;}
314 Selection->StartSelection(Time);
315}
virtual void StartSelection(const float Time)
Definition InteractionTypeWidget.cpp:73

◆ StoppedAiming()

void UInteractionContextWidget::StoppedAiming ( )

◆ StopSelection()

void UInteractionContextWidget::StopSelection ( )
overridevirtual

Implements IInteractionHUD.

318{
319 UInteractionTypeWidget* Selection = Cast<UInteractionTypeWidget>(ContextVerticalBox->GetChildAt(SelectedIndex));
320 if(Selection == nullptr){return;}
321 Selection->StopSelection();
322}
virtual void StopSelection()
Definition InteractionTypeWidget.cpp:79

Member Data Documentation

◆ ContextOverlay

class UOverlay* UInteractionContextWidget::ContextOverlay = nullptr
protected

◆ ContextVerticalBox

class UVerticalBox* UInteractionContextWidget::ContextVerticalBox = nullptr
protected

◆ CurrentInteractionData

FInteractionData UInteractionContextWidget::CurrentInteractionData
private

◆ InteractionTypeWidgetClass

TSubclassOf<class UInteractionTypeWidget> UInteractionContextWidget::InteractionTypeWidgetClass
private

◆ PromptVerticalBox

class UVerticalBox* UInteractionContextWidget::PromptVerticalBox = nullptr
protected

◆ SelectedIndex

int32 UInteractionContextWidget::SelectedIndex = 0
protected

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