Space Plunder
Loading...
Searching...
No Matches
EpicOnlineGameInstance.h
Go to the documentation of this file.
1// Fill out your copyright notice in the Description page of Project Settings.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "Interfaces/OnlineStatsInterface.h"
7// #include "OnlineError.h"
8#include "NetworkReplayStreaming.h"
9#include "Engine/GameInstance.h"
10#include "Interfaces/OnlineSessionInterface.h"
11#include "OnlineSessionSettings.h"
12#include "Data/BaseData.h"
17#include "Interfaces/OnlineIdentityInterface.h"
20// #include "VoiceChat.h"
22#include "PlayFab.h"
23#include "PlayFabAdminDataModels.h"
24#include "Core/PlayFabError.h"
25#include "Core/PlayFabClientDataModels.h"
26#include "EpicOnlineGameInstance.generated.h"
27
29{
30 struct FItemInstance;
31}
32
33DECLARE_LOG_CATEGORY_EXTERN(LogOnlineGameInstance, Display, All);
34
35class UReplayMenu;
36DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnServersFound, const TArray<FServerRow>&, ServerInfo);
37DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnFileDataFound, FString, FileName,const TArray<uint8>&, FileContents);
38DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnFindReplaysComplete, const TArray<FReplayInfo>&, AllReplays);
39
40UCLASS()
41class MENUSYSTEM_API UEpicOnlineGameInstance : public UGameInstance, public IMenuSystem, public IDifficultyInterface,
43{
44 GENERATED_BODY()
45
46public:
47 //- Delegates //
48 UPROPERTY(BlueprintAssignable, Category = "EOS")
49 FOnServersFound OnServersFoundChanged;
50 UPROPERTY(BlueprintAssignable, Category = "EOS")
51 FOnFileDataFound OnFileDataFound;
52 UPROPERTY(BlueprintAssignable, Category = "EOS")
53 FOnFindReplaysComplete OnFindReplaysComplete;
54
55 explicit UEpicOnlineGameInstance(const FObjectInitializer& ObjectInitializer);
56
57
58 virtual void Init() override;
59 virtual void Shutdown() override;
60
61 //- Difficulty Interface //
62 UFUNCTION(BlueprintCallable, Category="Difficulty")
63 virtual EDifficultyLevel GetDifficultyLevel() const override;
64 //- Difficulty //
65 UFUNCTION(BlueprintCallable, Category="EOS")
66 virtual void SetDifficultyLevel(const EDifficultyLevel NewDifficultyLevel) override;
67
68
69 virtual FString GetAuthToken() const override;
70
71 //@ TODO Move to Playfab Component
72 virtual void LoginToPlayFab() override;
73 virtual FString GetPlayFabID() const override;
74 virtual bool GetIsLoggedInToPlayFab() const override;
75 virtual float GetPlayFabCurrency() const override;
76 virtual TArray<UPlayFabJsonObject*> GetPlayFabInventory() const override;
77
78
79 //- Interface Functions //
80 virtual void LoginToEpicOnline(FString ID = "", FString Token = "", FString LoginType = "accountportal") override;
81 virtual void Logout() const override;
82 virtual void CreateEOSSession(FString SessionName, bool bIsDedicatedServer, bool bIsLAN, bool bIsPresence, int32 MaxNumPlayers) override;
83 virtual void FindSessionAndJoin() override;
84 virtual void DestroySession() override;
85
86 virtual FString GetPlayerUserName() const override;
87 virtual bool GetIsPlayerLoggedIn() const override;
88 virtual FString GetCurrentSessionName() const override;
89
90 virtual void LaunchInGameMenu(APlayerController* Player, const bool bOpen = true) override;
91 virtual void LaunchOptionsMenu(APlayerController* Player, UUserWidget* CurrentWidget = nullptr, const bool bOpen = true) override;
92
93 virtual void StartSession() override;
94
95 virtual TSubclassOf<UUserWidget> GetModalWidgetClass() override {return ModalWidgetClass;};
96
97 virtual bool GetDebuggingMode() const override {return bDebuggingMode;};
98
99 //- Possibly Take from Old //
100 virtual void SearchServers() override;
101
102
103 virtual void StartCampaign(const bool bNewGame) const override;
104 virtual void RestartLevel() const;
105
106 virtual void StartHorde() const override;
107
108 //- Save Slots //
109 virtual void SetCurrentSaveSlot(const int32 NewSaveSlot) override{CurrentSaveSlot = NewSaveSlot;};
110
111 virtual int32 GetCurrentSaveSlot() override {return CurrentSaveSlot;};
112 virtual TArray<int32> GetAllSaveSlots() override {return AllSaveSlots;};
113 //@TODO Saave Slot info
114 virtual FUserSaveGame GetSaveInfoFromSlot(const int32 Slot) override {return FUserSaveGame();};
115
116 // virtual void CreatePopup(APlayerController* PlayerController, FModalData ModalData) override;
117 virtual bool GetIsOnlineGame() const override;
118 virtual bool GetIsPublicMatch() const override;
119 virtual EOnlineSubsystem GetOnlineSubsystem() const override;
120
121
122
123
124
125 //- Old interface functions //
126 virtual void Host(FOnlineSessionSettings HostSessionSettings) override;
127 virtual void SinglePlayer() override;
128 virtual void Character() override;
129 virtual void Options() override;
130 virtual void Join(uint32 Index) override;
131 virtual void JoinManualAddress(const FString& IpAddress) override;
132 virtual void Quit(APlayerController* Player) override;
133
134
135 //- New stuff / to add to interface
136 UFUNCTION(BlueprintCallable, Category="EOS")
137 virtual void UpdateStats(FString StatName, int32 Amount);
138 // virtual void UpdateStats(FString StatName, int32 Amount, FOnlineStatUpdate::EOnlineStatModificationType Type);
139 UFUNCTION(BlueprintCallable, Category="EOS")
140 virtual void GetStats(TArray<FString> StatName);
141
142 UFUNCTION(BlueprintCallable, Category="EOS")
143 virtual void LoadMenu() override;
144
145 UFUNCTION(BlueprintCallable, Category="EOS")
146 TArray<uint8> ConvertSaveFileTouint(class USaveGame* SavedGame);
147 UFUNCTION(BlueprintCallable, Category="EOS")
148 class USaveGame* ConvertunitToSaveFile(TArray<uint8> SavedGameArray);
149 UFUNCTION(BlueprintCallable, Category="EOS")
150 void UpdatePlayerData(const FString& FileName, TArray<uint8> SavedGameArray);
151 UFUNCTION(BlueprintCallable, Category="EOS")
152 void GetPlayerData(const FString& FileName);
153
154 UFUNCTION(Category="EOS")
155 void ReadPlayerData(const FString& FileName) const;
156
157 virtual int32 GetMinNumberOfPlayersToStart() const override {return MinNumberOfPlayersToStart;};
158 virtual void SetMinNumberOfPlayersToStart(const int32 Num) override {MinNumberOfPlayersToStart = Num;};
159
160
161 TSharedPtr<FOnlineSessionSearch> OnlineSessionSearch;
162 class IOnlineSubsystem* OnlineSubsystem = nullptr;
163 IOnlineSessionPtr OnlineSessionPtr;
164
165 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="EOS")
166 FString LobbyLevelText;
167 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="EOS")
168 FString StartupLevelText;
169 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="EOS")
170 FString DemoLevelText;
171
172
173
174
175 //- Voice Chat //
176 // UFUNCTION(BlueprintCallable, Category="EOS")
177 // void EOSVoiceChatLogin();
178 // void OnVoiceChatLoginCompleted(const FString& PlayerName,const FVoiceChatResult& Result);
179 // IVoiceChatUser* VoiceChatUser;
180 // UFUNCTION(BlueprintCallable, Category="EOS")
181 // void SetInputVolumeEOS(float NewVolume);
182 // UFUNCTION(BlueprintCallable, Category="EOS")
183 // void SetMuteInputVolumeEOS(bool bIsMuted);
184 // UFUNCTION(BlueprintCallable, Category="EOS")
185 // void SetInputOutputMode(int32 Value);
186
187
188 //- Level Select Interface //
189 virtual UDataTable* GetLevelDataTable() override{return LevelDataTable;};
190
191 // UFUNCTION(BlueprintCallable, Category="Menu System|Levels")
192 virtual void SetSelectedLevel(const FGameLevel GameLevel, const EGameplayMode GameMode) override;
193 // UFUNCTION(BlueprintCallable, Category="Menu System|Levels")
194 virtual FGameLevel GetSelectedLevel(const EGameplayMode GameMode) const override;
195
196 //- Online Profile //
197
198 // virtual FUserProfile GetOnlinePlayerProfile() const override {return OnlinePlayerProfile;};
199 virtual FUserProfile GetOfflinePlayerProfile() const override {return OfflinePlayerProfile;};
200 virtual UDataTable* GetProfilePicturesDT() const override{return ProfilePicturesDT;};
201
202 UFUNCTION(BlueprintCallable, Category="Player Profile")
203 virtual bool SaveOfflinePlayerProfile() override;
204 UFUNCTION(BlueprintCallable, Category="Player Profile")
205 virtual bool LoadOfflinePlayerProfile(FUserProfile& OfflineProfile) override;
206
207protected:
208
209 virtual void ReturnToMainMenu() override;
210
211 UPROPERTY()
212 class UInGameMenuSystemWidget* InGameMenuWidget = nullptr;
213 UPROPERTY(EditAnywhere, Category="Game Instance|Widgets")
214 TSubclassOf<class UUserWidget> InGameMenuClass = nullptr;
215 UPROPERTY()
216 class UOptionsMenuSystemWidget* OptionsMenuWidget = nullptr;
217 UPROPERTY(EditAnywhere, Category="Game Instance|Widgets")
218 TSubclassOf<class UUserWidget> OptionsMenuClass = nullptr;
219
220 TSubclassOf<class UUserWidget> ModalWidgetClass = nullptr;
221
222 UPROPERTY()
223 class UMenuSystemWidget* MainMenu = nullptr;
224 UPROPERTY(EditAnywhere, Category="Game Instance|Widgets")
225 TSubclassOf<class UUserWidget> MenuClass = nullptr;
226
227 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Replay")
228 class UReplayMenu* ReplayMenu = nullptr;
229 UPROPERTY(EditAnywhere, Category="Game Instance|Widgets")
230 TSubclassOf<UReplayMenu> ReplayMenuClass = nullptr;
231
232
233 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Menu System")
234 bool bDebuggingMode = true;
235 bool bInGameMenuOpen = false;
236 bool bOptionsMenuOpen = false;
237
238
239 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Menu System")
240 class UDataTable* ProfilePicturesDT = nullptr;
241 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Menu System")
242 class UDataTable* LevelDataTable = nullptr;
243
244
245
246 //- Gameplay Replays //
247 UFUNCTION(BlueprintCallable, Category = "Replays")
248 virtual bool OpenReplayMenu(APlayerController* Player, const bool bOpen = true) override;
250 UFUNCTION(BlueprintCallable, Category = "Replays")
251 virtual void StartRecordingReplayFromBP(const FString& InName, const FString& FriendlyName) override;
252
253 //- Does nothing ATM //
254 UFUNCTION(BlueprintCallable, Category = "Replays")
255 virtual void CreateReplayEvent(const int32 TimeInMS, const FString& Group, const FString& Meta, const TArray<uint8>& Data) override;
256
258 UFUNCTION(BlueprintCallable, Category = "Replays")
259 virtual void StopRecordingReplayFromBP() override;
261 UFUNCTION(BlueprintCallable, Category = "Replays")
262 virtual void PlayReplayFromBP(FString ReplayName) override;
264 UFUNCTION(BlueprintCallable, Category = "Replays")
265 virtual void FindReplays() override;
267 UFUNCTION(BlueprintCallable, Category = "Replays")
268 virtual void RenameReplay(const FString &ReplayName, const FString &NewFriendlyReplayName) override;
270 UFUNCTION(BlueprintCallable, Category = "Replays")
271 virtual void DeleteReplay(const FString &ReplayName) override;
272
273
274 void OnLoginEOSCompleted(int32 LocalUserNum, bool bSuccess, const FUniqueNetId& UserID, const FString& Error) const;
275 void OnLogoutComplete(const int32 ResultCode, const bool bSuccess) const;
276 void OnCreateSessionCompleted(FName SessionName, bool bSuccess) const;
277 void OnDestroySessionCompleted(FName SessionName, bool bSuccess) const;
278 void OnFindSessionCompleted(bool bSuccess);
279 void OnFindSessionListCompleted(bool bSuccess) const;
280 void OnJoinSessionCompleted(FName SessionName, EOnJoinSessionCompleteResult::Type Result) const;
281
282 //- New //
283 void OnUpdateStatsComplete(const FOnlineError& Result) const;
284 void OnGetStatsComplete(const FOnlineError& Result, const TArray<TSharedRef<const FOnlineStatsUserStats>>& UserStats);
285 void OnWriteUserFileComplete(bool bSuccess, const FUniqueNetId& UserID, const FString& FileName) const;
286 void OnGetUserFileComplete(bool bSuccess, const FUniqueNetId& UserID, const FString& FileName) const;
287
288
289 //- Extras to add? //
290 //bool PlayReplayPlaylist(const struct FReplayPlaylistParams& PlaylistParams);
291 // virtual void AddUserToReplay(const FString& UserString);
292
293 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Menu System|PlayFab")
294 bool bAutoLoginToPlayFab = true;
295 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Menu System|PlayFab")
296 FString CurrencyCode = "PC";
297 UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Menu System|Levels")
298 FGameLevel SelectedCampaignLevel;
299 UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Menu System|Levels")
300 FGameLevel SelectedMultiplayerLevel;
301 UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Menu System|Levels")
302 FGameLevel SelectedHordeLevel;
303 UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Menu System|Levels")
304 FGameLevel SelectedDebugLevel;
305
306
307private:
308
309 IOnlineIdentityPtr GetOnlineIdentity() const;
310
311
312
313 int32 MinNumberOfPlayersToStart = 2;
314 FString CurrentSessionName = "Default_Server_Name";
316
317
318
319 void SetPlayerProfileName();
320
321 // FUserProfile OnlinePlayerProfile;
322 FUserProfile OfflinePlayerProfile;
323
324 int32 CurrentSaveSlot = 1;
325 TArray<int32> AllSaveSlots;
326
327
328
329
330
331 virtual void OnNetworkFailure(UWorld* World, UNetDriver* NewDriver, ENetworkFailure::Type FailureType, const FString& ErrorString);
332
333 //- Gameplay Replays //
334 TSharedPtr<INetworkReplayStreamer> EnumerateStreamsPtr;
335 FEnumerateStreamsCallback OnEnumerateStreamsCompleteDelegate;
336 FDeleteFinishedStreamCallback OnDeleteFinishedStreamCompleteDelegate;
337
338 FRenameReplayCallback OnRenameReplayCompleteDelegate;
339
340
341 void OnEnumerateStreamsComplete(const FEnumerateStreamsResult& Result) const;
342 void OnDeleteFinishedStreamComplete(const FDeleteFinishedStreamResult& Result);
343 void OnReplayRenameFinishedComplete(const FRenameReplayResult& Result);
344
345
346 //@TODO Move to Playfab Component //
347 PlayFabClientPtr ClientAPI = nullptr;
348 PlayFabAdminPtr AdminAPI = nullptr;
349 FString PlayFabID = "";
350 float PlayFabCurrency = 0.0f;
351 TArray<PlayFab::ClientModels::FItemInstance> PlayFabInventory;
352 void SetPlayFabDisplayName();
353 void OnPlayFabLoginSuccess(const PlayFab::ClientModels::FLoginResult& Result);
354 void OnPlayFabError(const PlayFab::FPlayFabCppError& ErrorResult);
355 void OnPlayFabDisplayChangedSuccess(const PlayFab::AdminModels::FUpdateUserTitleDisplayNameResult& Result);
356 void OnPlayFabLGetInventorySuccess(const PlayFab::ClientModels::FGetUserInventoryResult& Result);
357
358
359};
EDifficultyLevel
Definition BaseData.h:1052
UCLASS(Blueprintable, BlueprintType, ClassGroup=(BucciGames), meta=(BlueprintSpawnableComponent)) class CHATSYSTEM_API UChatSystemComponent
Definition ChatSystemComponent.h:13
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnFileDataFound, FString, FileName, const TArray< uint8 > &, FileContents)
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnServersFound, const TArray< FServerRow > &, ServerInfo)
DECLARE_LOG_CATEGORY_EXTERN(LogOnlineGameInstance, Display, All)
EOnlineSubsystem
Definition MenuData.h:49
EGameplayMode
Definition MenuData.h:40
Definition DifficultyInterface.h:19
Definition LevelSelectInterface.h:22
Definition MenuSystem.h:19
Definition ModalInterface.h:21
Definition PlayFabMenu.h:21
Definition ReplayClipInterface.h:20
Definition EpicOnlineGameInstance.h:43
virtual UDataTable * GetProfilePicturesDT() const override
Definition EpicOnlineGameInstance.h:200
virtual TArray< int32 > GetAllSaveSlots() override
Definition EpicOnlineGameInstance.h:112
virtual bool GetDebuggingMode() const override
Definition EpicOnlineGameInstance.h:97
virtual FUserSaveGame GetSaveInfoFromSlot(const int32 Slot) override
Definition EpicOnlineGameInstance.h:114
virtual int32 GetCurrentSaveSlot() override
Definition EpicOnlineGameInstance.h:111
IOnlineSessionPtr OnlineSessionPtr
Definition EpicOnlineGameInstance.h:163
TSharedPtr< FOnlineSessionSearch > OnlineSessionSearch
Definition EpicOnlineGameInstance.h:161
virtual FUserProfile GetOfflinePlayerProfile() const override
Definition EpicOnlineGameInstance.h:199
virtual void SetMinNumberOfPlayersToStart(const int32 Num) override
Definition EpicOnlineGameInstance.h:158
virtual void SetCurrentSaveSlot(const int32 NewSaveSlot) override
Definition EpicOnlineGameInstance.h:109
Definition InGameMenuSystemWidget.h:11
Definition MenuSystemWidget.h:19
Definition OptionsMenuSystemWidget.h:17
Player Recorded Replay clips menu widget.
Definition ReplayMenu.h:25
Definition EpicOnlineGameInstance.h:29
Definition EpicOnlineGameInstance.h:29
Definition MenuData.h:115
Definition BaseData.h:1239
Definition MenuData.h:69