diff --git a/Content/BattleField/BattleFieldMap.umap b/Content/BattleField/BattleFieldMap.umap index 250219a..9ad146d 100644 Binary files a/Content/BattleField/BattleFieldMap.umap and b/Content/BattleField/BattleFieldMap.umap differ diff --git a/Content/MainMenu/BP_SessionListEntry.uasset b/Content/MainMenu/BP_SessionListEntry.uasset new file mode 100644 index 0000000..a4ac921 Binary files /dev/null and b/Content/MainMenu/BP_SessionListEntry.uasset differ diff --git a/Content/MainMenu/BP_SessionListMenu.uasset b/Content/MainMenu/BP_SessionListMenu.uasset new file mode 100644 index 0000000..96d32d8 Binary files /dev/null and b/Content/MainMenu/BP_SessionListMenu.uasset differ diff --git a/Content/MainMenu/MainMenu.uasset b/Content/MainMenu/MainMenu.uasset index 8a95a1f..a85cde8 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 ec2d162..ccc2f9a 100644 Binary files a/Content/MainMenu/MainMenuLevel.umap and b/Content/MainMenu/MainMenuLevel.umap differ diff --git a/Source/TurnBasedTutorial/MyMainMenu.cpp b/Source/TurnBasedTutorial/MyMainMenu.cpp new file mode 100644 index 0000000..898b1f8 --- /dev/null +++ b/Source/TurnBasedTutorial/MyMainMenu.cpp @@ -0,0 +1,29 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "MyMainMenu.h" + +#include "Components/Button.h" +#include "Kismet/GameplayStatics.h" + +void UMyMainMenu::NativeConstruct() +{ + Super::NativeConstruct(); + + HostOnlineGameButton->OnClicked.AddDynamic(this, &ThisClass::UMyMainMenu::OnHostOnlineGameButtonClicked); +} + +void UMyMainMenu::OnHostOnlineGameButtonClicked() +{ + GetMyGameSubsystem()->CreateSession(2, true); + UGameplayStatics::OpenLevel(GetWorld(), FName(TEXT("BattleFieldMap"))); + this->RemoveFromParent(); +} + +UMyGameInstanceSubsystem* UMyMainMenu::GetMyGameSubsystem() const +{ + const UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(GetWorld()); + UMyGameInstanceSubsystem* GameInstanceSubsystem = GameInstance->GetSubsystem(); + return GameInstanceSubsystem; +} + diff --git a/Source/TurnBasedTutorial/MyMainMenu.h b/Source/TurnBasedTutorial/MyMainMenu.h new file mode 100644 index 0000000..aa65ef3 --- /dev/null +++ b/Source/TurnBasedTutorial/MyMainMenu.h @@ -0,0 +1,31 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "Blueprint/UserWidget.h" +#include "MyGameInstanceSubsystem.h" + +#include "MyMainMenu.generated.h" + +/** + * + */ +UCLASS() +class TURNBASEDTUTORIAL_API UMyMainMenu : public UUserWidget +{ + GENERATED_BODY() + +public: + UPROPERTY(meta = (BindWidget)) + class UButton* HostOnlineGameButton; + + virtual void NativeConstruct() override; + +protected: + UFUNCTION() + void OnHostOnlineGameButtonClicked(); + +private: + UMyGameInstanceSubsystem* GetMyGameSubsystem() const; +}; diff --git a/Source/TurnBasedTutorial/MySessionListWidget.cpp b/Source/TurnBasedTutorial/MySessionListWidget.cpp new file mode 100644 index 0000000..6b5e3e3 --- /dev/null +++ b/Source/TurnBasedTutorial/MySessionListWidget.cpp @@ -0,0 +1,32 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "MySessionListWidget.h" + +#include "MyGameInstanceSubsystem.h" +#include "Kismet/GameplayStatics.h" + +void UMySessionListWidget::NativeConstruct() +{ + Super::NativeConstruct(); + + const auto MyGameInstanceSubsystem = GetMyGameSubsystem(); + MyGameInstanceSubsystem->OnFindSessionsCompleteEvent.AddUObject(this, &ThisClass::FillSessionListFromDelegate); + + + // Initiate search + MyGameInstanceSubsystem->FindSessions(10, true); +} + +void UMySessionListWidget::FillSessionListFromDelegate(const TArray& SessionResults, + bool bSuccessful) +{ + UE_LOG(LogTemp, Warning, TEXT("FIND SESSION DELEGATED %d %d"), bSuccessful, SessionResults.Num()); +} + +UMyGameInstanceSubsystem* UMySessionListWidget::GetMyGameSubsystem() const +{ + const UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(GetWorld()); + UMyGameInstanceSubsystem* GameInstanceSubsystem = GameInstance->GetSubsystem(); + return GameInstanceSubsystem; +} diff --git a/Source/TurnBasedTutorial/MySessionListWidget.h b/Source/TurnBasedTutorial/MySessionListWidget.h new file mode 100644 index 0000000..7a0f57d --- /dev/null +++ b/Source/TurnBasedTutorial/MySessionListWidget.h @@ -0,0 +1,35 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "MyGameInstanceSubsystem.h" + +#include "Blueprint/UserWidget.h" +#include "MySessionListWidget.generated.h" + +/** + * + */ +UCLASS() +class TURNBASEDTUTORIAL_API UMySessionListWidget : public UUserWidget +{ + GENERATED_BODY() + +protected: + virtual void NativeConstruct() override; + + UPROPERTY(meta = (BindWidget)) + class UButton* ConnectToSelectedSessionButton; + + UPROPERTY(meta = (BindWidget)) + class UButton* GoBackToMainMenuButton; + + UPROPERTY(meta = (BindWidget)) + class UListView* AvailableSessionsList; + + void FillSessionListFromDelegate(const TArray& SessionResults, bool bSuccessful); + +private: + UMyGameInstanceSubsystem* GetMyGameSubsystem() const; +};