Put it all together - In Game Store Displays - (Unreal Engine module)
Connect the UI to show store displays
-
Open the
SectionedShopWidget_Starter
CPP file, navigate to theOnParentRefreshButtonClicked()
function, and replace the existing implementation with the code below. This calls theQueryOrGetDisplays()
function usingOnQueryOrGetDisplaysCompleted()
as the completion delegate. ThebRefreshing
flag is set totrue
to force the subsystem to query the backend, ensuring the retrieved displays, sections, and offers are the latest.void USectionedShopWidget_Starter::OnParentRefreshButtonClicked()
{
if (bRefreshing)
{
return;
}
bRefreshing = true;
Ws_Root->SetWidgetState(EAccelByteWarsWidgetSwitcherState::Loading);
InGameStoreDisplaysSubsystem->QueryOrGetDisplays(
GetOwningPlayer(),
FOnQueryOrGetDisplaysComplete::CreateUObject(this, &ThisClass::OnQueryOrGetDisplaysCompleted),
bRefreshing);
} -
Find the
OnQueryOrGetDisplaysCompleted()
function and replace its implementation with the code below. This triggers theQueryOrGetSectionsForDisplay()
function if it finds a display matching theTargetDisplayName
variable, usingOnQueryOrGetSectionsCompleted()
as the completion delegate.void USectionedShopWidget_Starter::OnQueryOrGetDisplaysCompleted(
TArray<TSharedRef<FAccelByteModelsViewInfo>>& Displays,
const FOnlineError& Error)
{
if (Error.bSucceeded)
{
for (const TSharedRef<FAccelByteModelsViewInfo>& Display : Displays)
{
/**
* Trigger query sections for target display only
* Use Name to find the Display Name set on Admin Portal
* Use Title to retrieve the localized name set on Admin Portal
*/
if (Display->Name.Equals(TargetDisplayName))
{
InGameStoreDisplaysSubsystem->QueryOrGetSectionsForDisplay(
GetOwningPlayer(),
Display->ViewId,
FOnQueryOrGetSectionsInDisplayComplete::CreateUObject(this, &ThisClass::OnQueryOrGetSectionsCompleted),
bRefreshing);
return;
}
}
Ws_Root->SetWidgetState(EAccelByteWarsWidgetSwitcherState::Empty);
}
else
{
Ws_Root->ErrorMessage = Error.ErrorMessage;
Ws_Root->SetWidgetState(EAccelByteWarsWidgetSwitcherState::Error);
bRefreshing = false;
}
} -
Go to the
OnQueryOrGetSectionsCompleted()
function and replace its implementation with the code below. This triggersQueryOrGetOffersInSection()
for each retrieved section, usingOnQueryOrGetOffersInSectionCompleted()
as the completion delegate.void USectionedShopWidget_Starter::OnQueryOrGetSectionsCompleted(
TArray<TSharedRef<FAccelByteModelsSectionInfo>>& Sections,
const FOnlineError& Error)
{
if (Error.bSucceeded)
{
if (Sections.IsEmpty())
{
Ws_Root->SetWidgetState(EAccelByteWarsWidgetSwitcherState::Empty);
return;
}
SectionDatas.Empty();
QueryOrGetOffersInSectionCount = Sections.Num();
for (int i = 0; i < Sections.Num(); ++i)
{
USectionDataObject* Data = NewObject<USectionDataObject>();
Data->SectionInfo = Sections[i].Get();
Data->SectionColor = GetSectionPresetColor(i);
SectionDatas.Add(Data);
InGameStoreDisplaysSubsystem->QueryOrGetOffersInSection(
GetOwningPlayer(),
Sections[i]->SectionId,
FOnQueryOrGetOffersInSectionComplete::CreateUObject(
this, &ThisClass::OnQueryOrGetOffersInSectionCompleted, Sections[i]->SectionId),
bRefreshing);
}
}
else
{
Ws_Root->ErrorMessage = Error.ErrorMessage;
Ws_Root->SetWidgetState(EAccelByteWarsWidgetSwitcherState::Error);
bRefreshing = false;
}
} -
Navigate to the
NativeOnActivated()
function and replace its implementation with the code below. This callsQueryOrGetDisplays()
as soon as the widget is opened, while preserving the current value ofbRefreshing
. This means if the player has opened the menu before, it won’t trigger a backend query again.void USectionedShopWidget_Starter::NativeOnActivated()
{
Super::NativeOnActivated();
InGameStoreDisplaysSubsystem = GetGameInstance()->GetSubsystem<UInGameStoreDisplaysSubsystem_Starter>();
ensure(InGameStoreDisplaysSubsystem);
Ws_Root->SetWidgetState(EAccelByteWarsWidgetSwitcherState::Loading);
InGameStoreDisplaysSubsystem->QueryOrGetDisplays(
GetOwningPlayer(),
FOnQueryOrGetDisplaysComplete::CreateUObject(this, &ThisClass::OnQueryOrGetDisplaysCompleted),
bRefreshing);
// Bind parent's (store essentials) refresh function with this refresh function
if (UShopWidget* ShopWidget = GetFirstOccurenceOuter<UShopWidget>())
{
ShopWidget->OnRefreshButtonClickedDelegates.AddUObject(this, &ThisClass::OnParentRefreshButtonClicked);
}
else if (UShopWidget_Starter* ShopWidget_Starter = GetFirstOccurenceOuter<UShopWidget_Starter>())
{
ShopWidget_Starter->OnRefreshButtonClickedDelegates.AddUObject(this, &ThisClass::OnParentRefreshButtonClicked);
}
}