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);
|
||||
|
||||
ERobotsName CurrentRobot = ERobotsName::None;
|
||||
if (ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance()))
|
||||
ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance());
|
||||
if (GameInstance)
|
||||
{
|
||||
CurrentRobot = GameInstance->CurrentSelectRobot;
|
||||
}
|
||||
|
@ -5,18 +5,24 @@
|
||||
#include "Engine/DataTable.h"
|
||||
#include "Core/LuckyRobotsGameInstance.h"
|
||||
#include "FunctionLibraries/LuckyRobotsFunctionLibrary.h"
|
||||
#include "Subsystems/SubsystemBlueprintLibrary.h"
|
||||
#include "VaRestSubsystem.h"
|
||||
#include <Kismet/GameplayStatics.h>
|
||||
|
||||
void UMainScreenUserWidget::NativeConstruct()
|
||||
{
|
||||
Super::NativeConstruct();
|
||||
InitData();
|
||||
|
||||
BPSendReadyJson();
|
||||
BPGetdataHTTP();
|
||||
if (ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance()))
|
||||
DoSendReadyJson();
|
||||
|
||||
ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance());
|
||||
if (GameInstance)
|
||||
{
|
||||
GameInstance->bIsFirstOpenGame = false;
|
||||
GameInstance->DoResolutionChange(bIsFullScreen);
|
||||
|
||||
GameInstance->OnMessageDispatched.AddDynamic(this, &UMainScreenUserWidget::OnMessageDispatchedHandler);
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,7 +31,8 @@ void UMainScreenUserWidget::InitData()
|
||||
InitRobotData();
|
||||
InitLevelData();
|
||||
|
||||
if (ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance()))
|
||||
ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance());
|
||||
if (GameInstance)
|
||||
{
|
||||
CurrentQualityIndex = static_cast<int32>(GameInstance->CurrentSelectQuality);
|
||||
}
|
||||
@ -116,9 +123,33 @@ void UMainScreenUserWidget::SelectPreviousQuality()
|
||||
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()
|
||||
{
|
||||
if (ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance()))
|
||||
ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance());
|
||||
if (GameInstance)
|
||||
{
|
||||
GameInstance->CurrentSelectRobot = GetCurrentRobotData().Name;
|
||||
}
|
||||
@ -128,7 +159,8 @@ void UMainScreenUserWidget::UpdateSelectRobot()
|
||||
|
||||
void UMainScreenUserWidget::UpdateSelectLevel()
|
||||
{
|
||||
if (ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance()))
|
||||
ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance());
|
||||
if (GameInstance)
|
||||
{
|
||||
GameInstance->CurrentSelectLevel = GetCurrentLevelData().LevelEnum;
|
||||
}
|
||||
@ -137,9 +169,110 @@ void UMainScreenUserWidget::UpdateSelectLevel()
|
||||
|
||||
void UMainScreenUserWidget::UpdateSelectQuality()
|
||||
{
|
||||
if (ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance()))
|
||||
ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance());
|
||||
if (GameInstance)
|
||||
{
|
||||
GameInstance->CurrentSelectQuality = static_cast<EQualityEnum>(CurrentQualityIndex);
|
||||
}
|
||||
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()
|
||||
{
|
||||
Super::NativeConstruct();
|
||||
if (ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance()))
|
||||
|
||||
ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance());
|
||||
if (GameInstance)
|
||||
{
|
||||
GameInstance->GameUserWidget = this;
|
||||
}
|
||||
|
@ -68,10 +68,21 @@ public:
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void SelectPreviousQuality();
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void DoResolutionChange();
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void GameStart();
|
||||
|
||||
void UpdateSelectRobot();
|
||||
void UpdateSelectLevel();
|
||||
void UpdateSelectQuality();
|
||||
|
||||
public:
|
||||
FParsedData DoJsonParse(const FString& JsonString);
|
||||
void OnMessageDispatchedHandler(const FString& Message);
|
||||
void DoSendReadyJson();
|
||||
|
||||
public:
|
||||
UFUNCTION(BlueprintImplementableEvent)
|
||||
void BPUpdateSelectRobot();
|
||||
@ -79,8 +90,4 @@ public:
|
||||
void BPUpdateSelectLevel();
|
||||
UFUNCTION(BlueprintImplementableEvent)
|
||||
void BPUpdateSelectQuality();
|
||||
UFUNCTION(BlueprintImplementableEvent)
|
||||
void BPSendReadyJson();
|
||||
UFUNCTION(BlueprintImplementableEvent)
|
||||
void BPGetdataHTTP();
|
||||
};
|
||||
|
@ -670,4 +670,19 @@ public:
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
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