Organize the code related to selecting robots and levels in blueprints into C++, and organize the related referenced blueprints

This commit is contained in:
martinluckyrobots
2025-03-31 14:59:07 +08:00
parent 73fb958f07
commit c35cf74b49
18 changed files with 130 additions and 74 deletions

View File

@ -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();
}