// Fill out your copyright notice in the Description page of Project Settings. #include "MainScreenUserWidget.h" #include "Engine/DataTable.h" void UMainScreenUserWidget::InitData() { InitRobotData(); InitLevelData(); } void UMainScreenUserWidget::InitRobotData() { FLevelData CurrentLevelData = GetCurrentLevelData(); if (CurrentLevelData.ID > 0) { if (RobotDataDataTable) { RobotDataList.Empty(); FString ContextString; TArray RowNames = RobotDataDataTable->GetRowNames(); for (auto RowString : RowNames) { FRobotData* pRow = RobotDataDataTable->FindRow(FName(RowString), ContextString); if (pRow) { if (pRow->bActive) { if (CurrentLevelData.RobotTypeList.Find(pRow->RobotType) >= 0) { RobotDataList.Add(*pRow); } } } } } } else { if (RobotDataDataTable) { RobotDataList.Empty(); FString ContextString; TArray RowNames = RobotDataDataTable->GetRowNames(); for (auto RowString : RowNames) { FRobotData* pRow = RobotDataDataTable->FindRow(FName(RowString), ContextString); if (pRow) { if (pRow->bActive) { RobotDataList.Add(*pRow); } } } } } BPUpdateSelectRobot(); } void UMainScreenUserWidget::InitLevelData() { FRobotData CurrentRobotData = GetCurrentRobotData(); if (!CurrentRobotData.Name.IsEmpty()) { if (LevelDataTable) { LevelDataList.Empty(); FString ContextString; TArray RowNames = LevelDataTable->GetRowNames(); for (auto RowString : RowNames) { FLevelData* pRow = LevelDataTable->FindRow(FName(RowString), ContextString); if (pRow) { if (pRow->bActive) { if (pRow->RobotTypeList.Find(CurrentRobotData.RobotType) >= 0) { LevelDataList.Add(*pRow); } } } } } } else { if (LevelDataTable) { LevelDataList.Empty(); FString ContextString; TArray RowNames = LevelDataTable->GetRowNames(); for (auto RowString : RowNames) { FLevelData* pRow = LevelDataTable->FindRow(FName(RowString), ContextString); if (pRow) { if (pRow->bActive) { LevelDataList.Add(*pRow); } } } } } BPUpdateSelectLevel(); } FRobotData UMainScreenUserWidget::GetCurrentRobotData() { FRobotData CurrentRobotData; if (RobotDataList.IsValidIndex(iCurrentSelectRobot)) { CurrentRobotData = RobotDataList[iCurrentSelectRobot]; } return CurrentRobotData; } FLevelData UMainScreenUserWidget::GetCurrentLevelData() { FLevelData CurrentLevelData; if (LevelDataList.IsValidIndex(iCurrentSelectLevel)) { CurrentLevelData = LevelDataList[iCurrentSelectLevel]; } return CurrentLevelData; }