// Project Lab - NHTV Igad #include "UnrealProject.h" #include "OverlayMessageBox.h" #include "ScreenOverlay.h" void UOverlayMessageBoxItem::NativeConstruct() { m_label = Cast(WidgetTree->FindWidget("Label")); onPressed.AddDynamic(this, &UOverlayMessageBoxItem::m_OnPressed); Super::NativeConstruct(); } void UOverlayMessageBoxItem::SetText(const FString& text) { if(!m_label) { GERROR("UOverlayMessageBoxItem Label not set on " + GetName()); return; } m_label->SetText(FText::FromString(text)); } void UOverlayMessageBoxItem::m_OnPressed() { //Cast(GetSubMenu())->returnCode = index; //UMenuScreenBase* screen = GetSubMenu()->GetScreen(); //check(m_info); m_info->Close(index); //if(screen) // screen->CloseActiveSubMenu(); //else // GERROR("screen == nullptr, should not happen"); } void UOverlayMessageBox::NativeConstruct() { Super::NativeConstruct(); m_buttonContainer = Cast(WidgetTree->FindWidget("ButtonContainer")); m_caption = Cast(WidgetTree->FindWidget("Caption")); m_message = Cast(WidgetTree->FindWidget("Message")); } void UOverlayMessageBox::SetMessageBoxInfo(class UMsgBoxInfo* info) { if(!buttonItemClass) { GERROR("Button item class not set on " + GetName()); return; } m_buttonContainer->ClearChildren(); m_info = info; UOverlayMessageBoxItem* selectItem = 0; for(FString option : info->options) { UOverlayMessageBoxItem* item = CreateWidget(GetWorld(), buttonItemClass); item->m_info = info; UHorizontalBoxSlot* slot = Cast(m_buttonContainer->AddChild(item)); slot->SetHorizontalAlignment(HAlign_Fill); slot->SetVerticalAlignment(VAlign_Fill); slot->SetSize(FSlateChildSize(ESlateSizeRule::Fill)); item->SetButtonText(option); if(option == info->defaultOption) selectItem = item; else if(!selectItem) selectItem = item; } m_caption->SetText(FText::FromString(info->caption)); m_message->SetText(FText::FromString(info->message)); RescanItems(); SelectNewItem(selectItem); }