メインコンテンツまでスキップ

Put it all together - In Game Store Displays - (Unreal Engine module)

Last updated on July 28, 2025

Connect the UI to show store displays

  1. Open the SectionedShopWidget_Starter CPP file, navigate to the OnParentRefreshButtonClicked() function, and replace the existing implementation with the code below. This calls the QueryOrGetDisplays() function using OnQueryOrGetDisplaysCompleted() as the completion delegate. The bRefreshing flag is set to true 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);
    }
  2. Find the OnQueryOrGetDisplaysCompleted() function and replace its implementation with the code below. This triggers the QueryOrGetSectionsForDisplay() function if it finds a display matching the TargetDisplayName variable, using OnQueryOrGetSectionsCompleted() 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;
    }
    }
  3. Go to the OnQueryOrGetSectionsCompleted() function and replace its implementation with the code below. This triggers QueryOrGetOffersInSection() for each retrieved section, using OnQueryOrGetOffersInSectionCompleted() 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;
    }
    }
  4. Navigate to the NativeOnActivated() function and replace its implementation with the code below. This calls QueryOrGetDisplays() as soon as the widget is opened, while preserving the current value of bRefreshing. 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);
    }
    }