You've already forked LuckyWorld
Organize the code related to selecting robots and levels in blueprints into C++, and organize the related referenced blueprints
This commit is contained in:
57
Source/Luckyrobots/Private/LuckyRobotsFunctionLibrary.cpp
Normal file
57
Source/Luckyrobots/Private/LuckyRobotsFunctionLibrary.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "LuckyRobotsFunctionLibrary.h"
|
||||
#include "LuckyRobotsGameInstance.h"
|
||||
|
||||
TArray<FRobotData> ULuckyRobotsFunctionLibrary::GetActiveRobotDataList(const UObject* WorldContextObject)
|
||||
{
|
||||
TArray<FRobotData> RobotDataList;
|
||||
ULuckyRobotsGameInstance* LuckyRobotsGameInstance = Cast<ULuckyRobotsGameInstance>(WorldContextObject->GetWorld()->GetGameInstance());
|
||||
if (LuckyRobotsGameInstance)
|
||||
{
|
||||
if (LuckyRobotsGameInstance->RobotDataDataTable)
|
||||
{
|
||||
FString ContextString;
|
||||
TArray<FName> RowNames = LuckyRobotsGameInstance->RobotDataDataTable->GetRowNames();
|
||||
for (auto RowString : RowNames)
|
||||
{
|
||||
FRobotData* pRow = LuckyRobotsGameInstance->RobotDataDataTable->FindRow<FRobotData>(FName(RowString), ContextString);
|
||||
if (pRow)
|
||||
{
|
||||
if (pRow->bActive)
|
||||
{
|
||||
RobotDataList.Add(*pRow);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return RobotDataList;
|
||||
}
|
||||
|
||||
TArray<FLevelData> ULuckyRobotsFunctionLibrary::GetActiveLevelDataList(const UObject* WorldContextObject)
|
||||
{
|
||||
TArray<FLevelData> LevelDataList;
|
||||
ULuckyRobotsGameInstance* LuckyRobotsGameInstance = Cast<ULuckyRobotsGameInstance>(WorldContextObject->GetWorld()->GetGameInstance());
|
||||
if (LuckyRobotsGameInstance)
|
||||
{
|
||||
if (LuckyRobotsGameInstance->LevelDataTable)
|
||||
{
|
||||
FString ContextString;
|
||||
TArray<FName> RowNames = LuckyRobotsGameInstance->LevelDataTable->GetRowNames();
|
||||
for (auto RowString : RowNames)
|
||||
{
|
||||
FLevelData* pRow = LuckyRobotsGameInstance->LevelDataTable->FindRow<FLevelData>(FName(RowString), ContextString);
|
||||
if (pRow)
|
||||
{
|
||||
if (pRow->bActive)
|
||||
{
|
||||
LevelDataList.Add(*pRow);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return LevelDataList;
|
||||
}
|
@ -2,4 +2,31 @@
|
||||
|
||||
|
||||
#include "LuckyRobotsGameMode.h"
|
||||
#include "LuckyRobotsGameInstance.h"
|
||||
#include "LuckyRobotsFunctionLibrary.h"
|
||||
|
||||
UClass* ALuckyRobotsGameMode::GetDefaultPawnClassForController_Implementation(AController* InController)
|
||||
{
|
||||
UClass* RobotClass = Super::GetDefaultPawnClassForController_Implementation(InController);
|
||||
|
||||
ERobotsName CurrentRobot = ERobotsName::None;
|
||||
ULuckyRobotsGameInstance* LuckyRobotsGameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance());
|
||||
if (LuckyRobotsGameInstance)
|
||||
{
|
||||
CurrentRobot = LuckyRobotsGameInstance->CurrentSelectRobot;
|
||||
}
|
||||
if (CurrentRobot != ERobotsName::None)
|
||||
{
|
||||
TArray<FRobotData> ActiveRobotDataList = ULuckyRobotsFunctionLibrary::GetActiveRobotDataList(this);
|
||||
for (auto ActiveRobotData : ActiveRobotDataList)
|
||||
{
|
||||
if (ActiveRobotData.Name == CurrentRobot)
|
||||
{
|
||||
RobotClass = ActiveRobotData.RobotClass;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return RobotClass;
|
||||
}
|
@ -4,6 +4,7 @@
|
||||
#include "MainScreenUserWidget.h"
|
||||
#include "Engine/DataTable.h"
|
||||
#include "LuckyRobotsGameInstance.h"
|
||||
#include "LuckyRobotsFunctionLibrary.h"
|
||||
|
||||
void UMainScreenUserWidget::NativeConstruct()
|
||||
{
|
||||
@ -20,38 +21,13 @@ void UMainScreenUserWidget::InitData()
|
||||
ULuckyRobotsGameInstance* LuckyRobotsGameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance());
|
||||
if (LuckyRobotsGameInstance)
|
||||
{
|
||||
UEnum* QualityEnum = StaticEnum<EQualityEnum>();
|
||||
for (int32 i = 0; i < QualityEnum->NumEnums() - 1; i++)
|
||||
{
|
||||
if (EQualityEnum(QualityEnum->GetValueByIndex(i)) == LuckyRobotsGameInstance->CurrentSelectQuality)
|
||||
{
|
||||
iCurrentSelectRobot = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
iCurrentSelectQuality = int(LuckyRobotsGameInstance->CurrentSelectQuality);
|
||||
}
|
||||
}
|
||||
|
||||
void UMainScreenUserWidget::InitRobotData()
|
||||
{
|
||||
if (RobotDataDataTable)
|
||||
{
|
||||
RobotDataList.Empty();
|
||||
|
||||
FString ContextString;
|
||||
TArray<FName> RowNames = RobotDataDataTable->GetRowNames();
|
||||
for (auto RowString : RowNames)
|
||||
{
|
||||
FRobotData* pRow = RobotDataDataTable->FindRow<FRobotData>(FName(RowString), ContextString);
|
||||
if (pRow)
|
||||
{
|
||||
if (pRow->bActive)
|
||||
{
|
||||
RobotDataList.Add(*pRow);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
RobotDataList = ULuckyRobotsFunctionLibrary::GetActiveRobotDataList(this);
|
||||
|
||||
iCurrentSelectRobot = 0;
|
||||
UpdateSelectRobot();
|
||||
@ -59,49 +35,19 @@ void UMainScreenUserWidget::InitRobotData()
|
||||
|
||||
void UMainScreenUserWidget::InitLevelData()
|
||||
{
|
||||
LevelDataList = ULuckyRobotsFunctionLibrary::GetActiveLevelDataList(this);
|
||||
|
||||
FRobotData CurrentRobotData = GetCurrentRobotData();
|
||||
if (CurrentRobotData.Name != ERobotsName::None)
|
||||
{
|
||||
if (LevelDataTable)
|
||||
{
|
||||
LevelDataList.Empty();
|
||||
TArray<FLevelData> ActiveLevelDataList = LevelDataList;
|
||||
|
||||
FString ContextString;
|
||||
TArray<FName> RowNames = LevelDataTable->GetRowNames();
|
||||
for (auto RowString : RowNames)
|
||||
{
|
||||
FLevelData* pRow = LevelDataTable->FindRow<FLevelData>(FName(RowString), ContextString);
|
||||
if (pRow)
|
||||
{
|
||||
if (pRow->bActive)
|
||||
{
|
||||
if (pRow->RobotTypeList.Find(CurrentRobotData.RobotType) >= 0)
|
||||
{
|
||||
LevelDataList.Add(*pRow);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (LevelDataTable)
|
||||
LevelDataList.Empty();
|
||||
for (auto ActiveLevelData : ActiveLevelDataList)
|
||||
{
|
||||
LevelDataList.Empty();
|
||||
|
||||
FString ContextString;
|
||||
TArray<FName> RowNames = LevelDataTable->GetRowNames();
|
||||
for (auto RowString : RowNames)
|
||||
if (ActiveLevelData.RobotTypeList.Find(CurrentRobotData.RobotType) >= 0)
|
||||
{
|
||||
FLevelData* pRow = LevelDataTable->FindRow<FLevelData>(FName(RowString), ContextString);
|
||||
if (pRow)
|
||||
{
|
||||
if (pRow->bActive)
|
||||
{
|
||||
LevelDataList.Add(*pRow);
|
||||
}
|
||||
}
|
||||
LevelDataList.Add(ActiveLevelData);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -197,8 +143,7 @@ void UMainScreenUserWidget::UpdateSelectQuality()
|
||||
ULuckyRobotsGameInstance* LuckyRobotsGameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance());
|
||||
if (LuckyRobotsGameInstance)
|
||||
{
|
||||
UEnum* QualityEnum = StaticEnum<EQualityEnum>();
|
||||
LuckyRobotsGameInstance->CurrentSelectQuality = EQualityEnum(QualityEnum->GetValueByIndex(iCurrentSelectQuality));
|
||||
LuckyRobotsGameInstance->CurrentSelectQuality = static_cast<EQualityEnum>(iCurrentSelectQuality);
|
||||
}
|
||||
BPUpdateSelectQuality();
|
||||
}
|
Reference in New Issue
Block a user