Hi,
Thanks a lot for your answer, and sorry for this awfully long following wall.
First to answer your question, yes, i have a widget which is a event journal, where events are added one by one.
Each event is a new STextBlock added to the journal widget, which is mainly a SVerticalBox in a SScrollBox, so i am adding widgets one by one during runtime.
The first ones are displayed immediately, and after 10 or 15 events, they take about 10 seconds to display.
All widgets are inside a mother widget which divides the screen in 3 columns, each column containing many widgets that may be visible or not during the game.
Each of those widgets contains many elements, sometimes added proceduraly.
All the daughters widgets belong to the same custom class SYagWindow which is a SCompoundWidget mainly containing a title, a close button, and a container which is called YagWindowContainer.
Then all the window-widgets are filled in the hud.cpp file in the PostInitializeComponents function, after the initialisation of the mother widget:
YagHUD.cpp:
void AYagHUD::PostInitializeComponents()
{
Super::PostInitializeComponents();
if (GEngine && GEngine->GameViewport)
{
// get viewport
UGameViewportClient* Viewport = GEngine->GameViewport;
// mother widget that contains everything
SAssignNew(YagHUDWidget, SYagHUDWidget)
.YagHUD(TWeakObjectPtr<AYagHUD>(this));
// add the mother widget
Viewport->AddViewportWidgetContent(SNew(SWeakWidget).PossiblyNullContent(YagHUDWidget.ToSharedRef()));
YagHUDWidget->SetVisibility(EVisibility::Visible);
// set up widgets
SetupYagJournalWidget();
YagJournalWidget->HideYagWindow();
SetupYagMainMenuWidget();
YagMainMenuWidget->HideYagWindow();
[..............................................................................]
}
}
The setup function are filling the container (YagWindowContainer) with slots containing other widgets, like this:
YagMainMenuWidget->YagWindowContainer->AddSlot()
.FillHeight(1.f)
[
SNew(SOverlay)
+ SOverlay::Slot()
.HAlign(HAlign_Fill)
.VAlign(VAlign_Fill)
[
SNew(SVerticalBox)
+ SVerticalBox::Slot()
[
SNew(SButton)
.ButtonStyle(&YagMainMenuWidget->YagGlobalStyle->YagButtonStyle)
.TextStyle(&YagMainMenuWidget->YagGlobalStyle->YagButtonTextStyle)
.Text(FText::FromString(Display(TextEnum::ACTION)))
.OnClicked(YagActionWidget.ToSharedRef(), &SYagWindow::ToggleYagActionWindow)
]
[.....................................................................]
]
];
Beside the complex nesting of elements, one thing i hate in my code is that all widget belong to the same class SYagWindow.
So i have to define them in the hud.cpp, then call delegates in the SYagWindow, which calls back functions in the hud.cpp.
That’s really ugly.
The way to get rid of that mess would be to have every widget be a daughter class of SYagWindow, but i couldn’t find a way to make inheritance work with widgets.
I enclose a new screenshot with most of the widgets made visible, so maybe it will make more sense.
Again, sorry for this very long post, hope you can understand something in this jungle
Cheers
Cedric