Optimizing WB_MainScreen
This commit is contained in:
parent
28c87e6f85
commit
55fabb31e8
Binary file not shown.
@ -16,7 +16,8 @@ UClass* ALuckyRobotsGameMode::GetDefaultPawnClassForController_Implementation(AC
|
|||||||
UClass* RobotClass = Super::GetDefaultPawnClassForController_Implementation(InController);
|
UClass* RobotClass = Super::GetDefaultPawnClassForController_Implementation(InController);
|
||||||
|
|
||||||
ERobotsName CurrentRobot = ERobotsName::None;
|
ERobotsName CurrentRobot = ERobotsName::None;
|
||||||
if (ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance()))
|
ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance());
|
||||||
|
if (GameInstance)
|
||||||
{
|
{
|
||||||
CurrentRobot = GameInstance->CurrentSelectRobot;
|
CurrentRobot = GameInstance->CurrentSelectRobot;
|
||||||
}
|
}
|
||||||
|
@ -5,18 +5,24 @@
|
|||||||
#include "Engine/DataTable.h"
|
#include "Engine/DataTable.h"
|
||||||
#include "Core/LuckyRobotsGameInstance.h"
|
#include "Core/LuckyRobotsGameInstance.h"
|
||||||
#include "FunctionLibraries/LuckyRobotsFunctionLibrary.h"
|
#include "FunctionLibraries/LuckyRobotsFunctionLibrary.h"
|
||||||
|
#include "Subsystems/SubsystemBlueprintLibrary.h"
|
||||||
|
#include "VaRestSubsystem.h"
|
||||||
|
#include <Kismet/GameplayStatics.h>
|
||||||
|
|
||||||
void UMainScreenUserWidget::NativeConstruct()
|
void UMainScreenUserWidget::NativeConstruct()
|
||||||
{
|
{
|
||||||
Super::NativeConstruct();
|
Super::NativeConstruct();
|
||||||
InitData();
|
InitData();
|
||||||
|
|
||||||
BPSendReadyJson();
|
DoSendReadyJson();
|
||||||
BPGetdataHTTP();
|
|
||||||
if (ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance()))
|
ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance());
|
||||||
|
if (GameInstance)
|
||||||
{
|
{
|
||||||
GameInstance->bIsFirstOpenGame = false;
|
GameInstance->bIsFirstOpenGame = false;
|
||||||
GameInstance->DoResolutionChange(bIsFullScreen);
|
GameInstance->DoResolutionChange(bIsFullScreen);
|
||||||
|
|
||||||
|
GameInstance->OnMessageDispatched.AddDynamic(this, &UMainScreenUserWidget::OnMessageDispatchedHandler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,7 +31,8 @@ void UMainScreenUserWidget::InitData()
|
|||||||
InitRobotData();
|
InitRobotData();
|
||||||
InitLevelData();
|
InitLevelData();
|
||||||
|
|
||||||
if (ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance()))
|
ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance());
|
||||||
|
if (GameInstance)
|
||||||
{
|
{
|
||||||
CurrentQualityIndex = static_cast<int32>(GameInstance->CurrentSelectQuality);
|
CurrentQualityIndex = static_cast<int32>(GameInstance->CurrentSelectQuality);
|
||||||
}
|
}
|
||||||
@ -116,9 +123,33 @@ void UMainScreenUserWidget::SelectPreviousQuality()
|
|||||||
UpdateSelectQuality();
|
UpdateSelectQuality();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UMainScreenUserWidget::DoResolutionChange()
|
||||||
|
{
|
||||||
|
ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance());
|
||||||
|
if (GameInstance)
|
||||||
|
{
|
||||||
|
bIsFullScreen = !bIsFullScreen;
|
||||||
|
GameInstance->DoResolutionChange(bIsFullScreen);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UMainScreenUserWidget::GameStart()
|
||||||
|
{
|
||||||
|
if (UKismetSystemLibrary::IsValidSoftObjectReference(CurrentSelectLevelObject))
|
||||||
|
{
|
||||||
|
ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance());
|
||||||
|
if (GameInstance)
|
||||||
|
{
|
||||||
|
GameInstance->bIsFirstOpenGame = true;
|
||||||
|
UGameplayStatics::OpenLevelBySoftObjectPtr(this, CurrentSelectLevelObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void UMainScreenUserWidget::UpdateSelectRobot()
|
void UMainScreenUserWidget::UpdateSelectRobot()
|
||||||
{
|
{
|
||||||
if (ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance()))
|
ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance());
|
||||||
|
if (GameInstance)
|
||||||
{
|
{
|
||||||
GameInstance->CurrentSelectRobot = GetCurrentRobotData().Name;
|
GameInstance->CurrentSelectRobot = GetCurrentRobotData().Name;
|
||||||
}
|
}
|
||||||
@ -128,7 +159,8 @@ void UMainScreenUserWidget::UpdateSelectRobot()
|
|||||||
|
|
||||||
void UMainScreenUserWidget::UpdateSelectLevel()
|
void UMainScreenUserWidget::UpdateSelectLevel()
|
||||||
{
|
{
|
||||||
if (ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance()))
|
ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance());
|
||||||
|
if (GameInstance)
|
||||||
{
|
{
|
||||||
GameInstance->CurrentSelectLevel = GetCurrentLevelData().LevelEnum;
|
GameInstance->CurrentSelectLevel = GetCurrentLevelData().LevelEnum;
|
||||||
}
|
}
|
||||||
@ -137,9 +169,110 @@ void UMainScreenUserWidget::UpdateSelectLevel()
|
|||||||
|
|
||||||
void UMainScreenUserWidget::UpdateSelectQuality()
|
void UMainScreenUserWidget::UpdateSelectQuality()
|
||||||
{
|
{
|
||||||
if (ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance()))
|
ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance());
|
||||||
|
if (GameInstance)
|
||||||
{
|
{
|
||||||
GameInstance->CurrentSelectQuality = static_cast<EQualityEnum>(CurrentQualityIndex);
|
GameInstance->CurrentSelectQuality = static_cast<EQualityEnum>(CurrentQualityIndex);
|
||||||
}
|
}
|
||||||
BPUpdateSelectQuality();
|
BPUpdateSelectQuality();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FParsedData UMainScreenUserWidget::DoJsonParse(const FString& JsonString)
|
||||||
|
{
|
||||||
|
FParsedData ParsedData;
|
||||||
|
|
||||||
|
auto VaRestSubsystem = CastChecked<UVaRestSubsystem>(USubsystemBlueprintLibrary::GetEngineSubsystem(UVaRestSubsystem::StaticClass()), ECastCheckedType::NullChecked);
|
||||||
|
|
||||||
|
if (!VaRestSubsystem)
|
||||||
|
{
|
||||||
|
return ParsedData;
|
||||||
|
}
|
||||||
|
|
||||||
|
UVaRestJsonObject* VaRestJsonObject = VaRestSubsystem->ConstructVaRestJsonObject();
|
||||||
|
if (!VaRestJsonObject)
|
||||||
|
{
|
||||||
|
return ParsedData;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (VaRestJsonObject->DecodeJson(JsonString, true))
|
||||||
|
{
|
||||||
|
UVaRestJsonObject* TempJsonObject = VaRestJsonObject->GetObjectField("startup_instructions");
|
||||||
|
if (TempJsonObject)
|
||||||
|
{
|
||||||
|
ParsedData.LevelName = TempJsonObject->GetStringField("level");
|
||||||
|
ParsedData.CharacterName = TempJsonObject->GetStringField("character");
|
||||||
|
ParsedData.Quality = TempJsonObject->GetStringField("quality");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UE_LOG(LogTemp, Error, TEXT("Parse Problem"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ParsedData;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UMainScreenUserWidget::OnMessageDispatchedHandler(const FString& Message)
|
||||||
|
{
|
||||||
|
ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance());
|
||||||
|
if (GameInstance)
|
||||||
|
{
|
||||||
|
FParsedData ParsedData = DoJsonParse(Message);
|
||||||
|
if (ParsedData.CharacterName == "DRONE")
|
||||||
|
{
|
||||||
|
GameInstance->CurrentSelectRobot = ERobotsName::LuckyDrone;
|
||||||
|
}else if(ParsedData.CharacterName == "Stretch Robot V1")
|
||||||
|
{
|
||||||
|
GameInstance->CurrentSelectRobot = ERobotsName::StretchRobotV1;
|
||||||
|
}
|
||||||
|
|
||||||
|
GameInstance->bIsFirstOpenGame = true;
|
||||||
|
|
||||||
|
ELevelEnum TempLevelEnum = ELevelEnum::None;
|
||||||
|
if (ParsedData.LevelName == "LOFT")
|
||||||
|
{
|
||||||
|
TempLevelEnum = ELevelEnum::Loft;
|
||||||
|
}else if(ParsedData.LevelName == "ISTANBUL")
|
||||||
|
{
|
||||||
|
TempLevelEnum = ELevelEnum::Istanbul;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TempLevelEnum != ELevelEnum::None)
|
||||||
|
{
|
||||||
|
TArray<FLevelData> TempLevelDataList = ULuckyRobotsFunctionLibrary::GetActiveLevelDataList(this);
|
||||||
|
for (const FLevelData& LevelData : TempLevelDataList)
|
||||||
|
{
|
||||||
|
if (LevelData.LevelEnum == TempLevelEnum && LevelData.LevelObject)
|
||||||
|
{
|
||||||
|
UGameplayStatics::OpenLevelBySoftObjectPtr(this, LevelData.LevelObject);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UMainScreenUserWidget::DoSendReadyJson()
|
||||||
|
{
|
||||||
|
auto VaRestSubsystem = CastChecked<UVaRestSubsystem>(USubsystemBlueprintLibrary::GetEngineSubsystem(UVaRestSubsystem::StaticClass()), ECastCheckedType::NullChecked);
|
||||||
|
|
||||||
|
if (!VaRestSubsystem)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
UVaRestJsonObject* VaRestJsonObject = VaRestSubsystem->ConstructVaRestJsonObject();
|
||||||
|
if (!VaRestJsonObject)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
VaRestJsonObject->SetStringField("name", "game_is_loaded");
|
||||||
|
ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance());
|
||||||
|
if (GameInstance)
|
||||||
|
{
|
||||||
|
FString SendedString = VaRestJsonObject->EncodeJsonToSingleString();
|
||||||
|
GameInstance->DoSendMessage(SendedString);
|
||||||
|
UE_LOG(LogTemp, Log, TEXT("Sended: %s"), *SendedString);
|
||||||
|
}
|
||||||
|
}
|
@ -7,7 +7,9 @@
|
|||||||
void UGameUserWidget::NativeConstruct()
|
void UGameUserWidget::NativeConstruct()
|
||||||
{
|
{
|
||||||
Super::NativeConstruct();
|
Super::NativeConstruct();
|
||||||
if (ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance()))
|
|
||||||
|
ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance());
|
||||||
|
if (GameInstance)
|
||||||
{
|
{
|
||||||
GameInstance->GameUserWidget = this;
|
GameInstance->GameUserWidget = this;
|
||||||
}
|
}
|
||||||
|
@ -68,10 +68,21 @@ public:
|
|||||||
UFUNCTION(BlueprintCallable)
|
UFUNCTION(BlueprintCallable)
|
||||||
void SelectPreviousQuality();
|
void SelectPreviousQuality();
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintCallable)
|
||||||
|
void DoResolutionChange();
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintCallable)
|
||||||
|
void GameStart();
|
||||||
|
|
||||||
void UpdateSelectRobot();
|
void UpdateSelectRobot();
|
||||||
void UpdateSelectLevel();
|
void UpdateSelectLevel();
|
||||||
void UpdateSelectQuality();
|
void UpdateSelectQuality();
|
||||||
|
|
||||||
|
public:
|
||||||
|
FParsedData DoJsonParse(const FString& JsonString);
|
||||||
|
void OnMessageDispatchedHandler(const FString& Message);
|
||||||
|
void DoSendReadyJson();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UFUNCTION(BlueprintImplementableEvent)
|
UFUNCTION(BlueprintImplementableEvent)
|
||||||
void BPUpdateSelectRobot();
|
void BPUpdateSelectRobot();
|
||||||
@ -79,8 +90,4 @@ public:
|
|||||||
void BPUpdateSelectLevel();
|
void BPUpdateSelectLevel();
|
||||||
UFUNCTION(BlueprintImplementableEvent)
|
UFUNCTION(BlueprintImplementableEvent)
|
||||||
void BPUpdateSelectQuality();
|
void BPUpdateSelectQuality();
|
||||||
UFUNCTION(BlueprintImplementableEvent)
|
|
||||||
void BPSendReadyJson();
|
|
||||||
UFUNCTION(BlueprintImplementableEvent)
|
|
||||||
void BPGetdataHTTP();
|
|
||||||
};
|
};
|
||||||
|
@ -671,3 +671,18 @@ public:
|
|||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
FTransform Transform;
|
FTransform Transform;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
USTRUCT(BlueprintType)
|
||||||
|
struct FParsedData
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
UPROPERTY(BlueprintReadWrite, Category = "Parsed Data")
|
||||||
|
FString LevelName;
|
||||||
|
|
||||||
|
UPROPERTY(BlueprintReadWrite, Category = "Parsed Data")
|
||||||
|
FString CharacterName;
|
||||||
|
|
||||||
|
UPROPERTY(BlueprintReadWrite, Category = "Parsed Data")
|
||||||
|
FString Quality;
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user