diff --git a/Content/MainMenu/BP_MainMenuGameMode.uasset b/Content/MainMenu/BP_MainMenuGameMode.uasset index 0f7a079..e269c55 100644 Binary files a/Content/MainMenu/BP_MainMenuGameMode.uasset and b/Content/MainMenu/BP_MainMenuGameMode.uasset differ diff --git a/Content/MainMenu/BP_MainMenuPlayerController.uasset b/Content/MainMenu/BP_MainMenuPlayerController.uasset index 4a59f6f..caf849d 100644 Binary files a/Content/MainMenu/BP_MainMenuPlayerController.uasset and b/Content/MainMenu/BP_MainMenuPlayerController.uasset differ diff --git a/Content/MainMenu/BP_SessionListEntry.uasset b/Content/MainMenu/BP_SessionListEntry.uasset index a4ac921..36dc2c5 100644 Binary files a/Content/MainMenu/BP_SessionListEntry.uasset and b/Content/MainMenu/BP_SessionListEntry.uasset differ diff --git a/Content/MainMenu/BP_SessionListMenu.uasset b/Content/MainMenu/BP_SessionListMenu.uasset index 96d32d8..0f1b13f 100644 Binary files a/Content/MainMenu/BP_SessionListMenu.uasset and b/Content/MainMenu/BP_SessionListMenu.uasset differ diff --git a/Content/MainMenu/MainMenu.uasset b/Content/MainMenu/MainMenu.uasset index a85cde8..ae87ceb 100644 Binary files a/Content/MainMenu/MainMenu.uasset and b/Content/MainMenu/MainMenu.uasset differ diff --git a/Content/MainMenu/MainMenuLevel.umap b/Content/MainMenu/MainMenuLevel.umap index ccc2f9a..da732e9 100644 Binary files a/Content/MainMenu/MainMenuLevel.umap and b/Content/MainMenu/MainMenuLevel.umap differ diff --git a/Content/MainMenu/fotor-ai-2023050222244.uasset b/Content/MainMenu/fotor-ai-2023050222244.uasset index d0de5c1..7145ff0 100644 Binary files a/Content/MainMenu/fotor-ai-2023050222244.uasset and b/Content/MainMenu/fotor-ai-2023050222244.uasset differ diff --git a/Source/TurnBasedTutorial/MyMainMenu.cpp b/Source/TurnBasedTutorial/MyMainMenu.cpp index 898b1f8..a7b4750 100644 --- a/Source/TurnBasedTutorial/MyMainMenu.cpp +++ b/Source/TurnBasedTutorial/MyMainMenu.cpp @@ -15,7 +15,7 @@ void UMyMainMenu::NativeConstruct() void UMyMainMenu::OnHostOnlineGameButtonClicked() { - GetMyGameSubsystem()->CreateSession(2, true); + GetMyGameSubsystem()->CreateSession(1, true); UGameplayStatics::OpenLevel(GetWorld(), FName(TEXT("BattleFieldMap"))); this->RemoveFromParent(); } diff --git a/Source/TurnBasedTutorial/MySessionListEntryWidget.cpp b/Source/TurnBasedTutorial/MySessionListEntryWidget.cpp new file mode 100644 index 0000000..da10049 --- /dev/null +++ b/Source/TurnBasedTutorial/MySessionListEntryWidget.cpp @@ -0,0 +1,22 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "MySessionListEntryWidget.h" + +#include "OnlineSessionSettings.h" +#include "Interfaces/OnlineSessionInterface.h" +#include "Components/TextBlock.h" + +void UMySessionListEntryWidget::Update(int SessionIndex, const FOnlineSessionSearchResult& Session) +{ + SessionId = SessionIndex; + IndexText->SetText(FText::AsNumber(SessionIndex + 1)); + // TODO: SessionNameText->SetText(FText::FromString(Session.Session.SessionSettings.Get(...))) + SessionNameText->SetText(FText::FromString("Test session name")); + + int MaxPlayerCount = Session.Session.SessionSettings.NumPublicConnections; + int CurPlayerCount = MaxPlayerCount - Session.Session.NumOpenPublicConnections; + + PlayersCountText->SetText(FText::AsNumber(CurPlayerCount)); + PingText->SetText(FText::AsNumber(Session.PingInMs)); +} diff --git a/Source/TurnBasedTutorial/MySessionListEntryWidget.h b/Source/TurnBasedTutorial/MySessionListEntryWidget.h new file mode 100644 index 0000000..d6c3b31 --- /dev/null +++ b/Source/TurnBasedTutorial/MySessionListEntryWidget.h @@ -0,0 +1,35 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "Interfaces/OnlineSessionInterface.h" +#include "Blueprint/UserWidget.h" +#include "MySessionListEntryWidget.generated.h" + +/** + * + */ +UCLASS() +class TURNBASEDTUTORIAL_API UMySessionListEntryWidget : public UUserWidget +{ + GENERATED_BODY() + +public: + UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(BindWidget)) + class UTextBlock* IndexText; + + UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(BindWidget)) + class UTextBlock* SessionNameText; + + UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(BindWidget)) + class UTextBlock* PlayersCountText; + + UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(BindWidget)) + class UTextBlock* PingText; + + void Update(int SessionIndex, const FOnlineSessionSearchResult& Session); + + int SessionId; + FString SessionName; +}; diff --git a/Source/TurnBasedTutorial/MySessionListWidget.cpp b/Source/TurnBasedTutorial/MySessionListWidget.cpp index 6b5e3e3..f962ca7 100644 --- a/Source/TurnBasedTutorial/MySessionListWidget.cpp +++ b/Source/TurnBasedTutorial/MySessionListWidget.cpp @@ -4,6 +4,8 @@ #include "MySessionListWidget.h" #include "MyGameInstanceSubsystem.h" +#include "Components/VerticalBox.h" +#include "MySessionListEntryWidget.h" #include "Kismet/GameplayStatics.h" void UMySessionListWidget::NativeConstruct() @@ -11,19 +13,40 @@ void UMySessionListWidget::NativeConstruct() Super::NativeConstruct(); const auto MyGameInstanceSubsystem = GetMyGameSubsystem(); - MyGameInstanceSubsystem->OnFindSessionsCompleteEvent.AddUObject(this, &ThisClass::FillSessionListFromDelegate); + MyGameInstanceSubsystem->OnFindSessionsCompleteEvent.AddUObject(this, &ThisClass::RefreshList); // Initiate search MyGameInstanceSubsystem->FindSessions(10, true); } -void UMySessionListWidget::FillSessionListFromDelegate(const TArray& SessionResults, +void UMySessionListWidget::RefreshList(const TArray& SessionResults, bool bSuccessful) { - UE_LOG(LogTemp, Warning, TEXT("FIND SESSION DELEGATED %d %d"), bSuccessful, SessionResults.Num()); + if (!bSuccessful) + { + UE_LOG(LogTemp, Error, TEXT("Find sessions FAILED!!!!")); + // TODO: Mark find sessions error + return; + } + SessionListBox->ClearChildren(); + for (const auto &Session: SessionResults) + { + auto *ItemWidget = CreateWidget(this, EntryClass); + ItemWidget->Update(SessionListBox->GetChildrenCount(), Session); + SessionListBox->AddChild(ItemWidget); + } } + +void UMySessionListWidget::OnRefreshListButtonClicked() +{ + // TODO: Show that we started searching... + // Initiate search + GetMyGameSubsystem()->FindSessions(10, true); +} + + UMyGameInstanceSubsystem* UMySessionListWidget::GetMyGameSubsystem() const { const UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(GetWorld()); diff --git a/Source/TurnBasedTutorial/MySessionListWidget.h b/Source/TurnBasedTutorial/MySessionListWidget.h index 7a0f57d..bae8515 100644 --- a/Source/TurnBasedTutorial/MySessionListWidget.h +++ b/Source/TurnBasedTutorial/MySessionListWidget.h @@ -26,10 +26,19 @@ protected: class UButton* GoBackToMainMenuButton; UPROPERTY(meta = (BindWidget)) - class UListView* AvailableSessionsList; - - void FillSessionListFromDelegate(const TArray& SessionResults, bool bSuccessful); + class UButton* RefreshListButton; + + UPROPERTY(meta = (BindWidget)) + class UVerticalBox* SessionListBox; + UPROPERTY(EditDefaultsOnly, Category="Session Info Class") + TSubclassOf EntryClass; + + void RefreshList(const TArray& SessionResults, bool bSuccessful); + private: - UMyGameInstanceSubsystem* GetMyGameSubsystem() const; + UMyGameInstanceSubsystem* GetMyGameSubsystem() const; + + UFUNCTION() + void OnRefreshListButtonClicked(); };