You've already forked LuckyWorld
Update
This commit is contained in:
@ -3,70 +3,64 @@
|
||||
|
||||
#include "MainScreenUserWidget.h"
|
||||
#include "Engine/DataTable.h"
|
||||
#include "LuckyrobotsGameInstance.h"
|
||||
|
||||
void UMainScreenUserWidget::NativeConstruct()
|
||||
{
|
||||
Super::NativeConstruct();
|
||||
|
||||
InitData();
|
||||
}
|
||||
|
||||
void UMainScreenUserWidget::InitData()
|
||||
{
|
||||
InitRobotData();
|
||||
InitLevelData();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UMainScreenUserWidget::InitRobotData()
|
||||
{
|
||||
FLevelData CurrentLevelData = GetCurrentLevelData();
|
||||
if (CurrentLevelData.ID > 0)
|
||||
if (RobotDataDataTable)
|
||||
{
|
||||
if (RobotDataDataTable)
|
||||
{
|
||||
RobotDataList.Empty();
|
||||
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)
|
||||
{
|
||||
if (CurrentLevelData.RobotTypeList.Find(pRow->RobotType) >= 0)
|
||||
{
|
||||
RobotDataList.Add(*pRow);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (RobotDataDataTable)
|
||||
FString ContextString;
|
||||
TArray<FName> RowNames = RobotDataDataTable->GetRowNames();
|
||||
for (auto RowString : RowNames)
|
||||
{
|
||||
RobotDataList.Empty();
|
||||
|
||||
FString ContextString;
|
||||
TArray<FName> RowNames = RobotDataDataTable->GetRowNames();
|
||||
for (auto RowString : RowNames)
|
||||
FRobotData* pRow = RobotDataDataTable->FindRow<FRobotData>(FName(RowString), ContextString);
|
||||
if (pRow)
|
||||
{
|
||||
FRobotData* pRow = RobotDataDataTable->FindRow<FRobotData>(FName(RowString), ContextString);
|
||||
if (pRow)
|
||||
if (pRow->bActive)
|
||||
{
|
||||
if (pRow->bActive)
|
||||
{
|
||||
RobotDataList.Add(*pRow);
|
||||
}
|
||||
RobotDataList.Add(*pRow);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BPUpdateSelectRobot();
|
||||
iCurrentSelectRobot = 0;
|
||||
UpdateSelectRobot();
|
||||
}
|
||||
|
||||
void UMainScreenUserWidget::InitLevelData()
|
||||
{
|
||||
FRobotData CurrentRobotData = GetCurrentRobotData();
|
||||
if (!CurrentRobotData.Name.IsEmpty())
|
||||
if (CurrentRobotData.Name != ERobotsName::None)
|
||||
{
|
||||
if (LevelDataTable)
|
||||
{
|
||||
@ -112,7 +106,8 @@ void UMainScreenUserWidget::InitLevelData()
|
||||
}
|
||||
}
|
||||
|
||||
BPUpdateSelectLevel();
|
||||
iCurrentSelectLevel = 0;
|
||||
UpdateSelectLevel();
|
||||
}
|
||||
|
||||
FRobotData UMainScreenUserWidget::GetCurrentRobotData()
|
||||
@ -133,4 +128,77 @@ FLevelData UMainScreenUserWidget::GetCurrentLevelData()
|
||||
CurrentLevelData = LevelDataList[iCurrentSelectLevel];
|
||||
}
|
||||
return CurrentLevelData;
|
||||
}
|
||||
|
||||
void UMainScreenUserWidget::SelectNextRobot()
|
||||
{
|
||||
iCurrentSelectRobot = FMath::Clamp(iCurrentSelectRobot + 1, 0, RobotDataList.Num() - 1);
|
||||
UpdateSelectRobot();
|
||||
}
|
||||
|
||||
void UMainScreenUserWidget::SelectPreviousRobot()
|
||||
{
|
||||
iCurrentSelectRobot = FMath::Clamp(iCurrentSelectRobot - 1, 0, RobotDataList.Num() - 1);
|
||||
UpdateSelectRobot();
|
||||
}
|
||||
|
||||
void UMainScreenUserWidget::SelectNextLevel()
|
||||
{
|
||||
iCurrentSelectLevel = FMath::Clamp(iCurrentSelectLevel + 1, 0, LevelDataList.Num() - 1);
|
||||
UpdateSelectLevel();
|
||||
}
|
||||
|
||||
void UMainScreenUserWidget::SelectPreviousLevel()
|
||||
{
|
||||
iCurrentSelectLevel = FMath::Clamp(iCurrentSelectLevel - 1, 0, LevelDataList.Num() - 1);
|
||||
UpdateSelectLevel();
|
||||
}
|
||||
|
||||
void UMainScreenUserWidget::SelectNextQuality()
|
||||
{
|
||||
UEnum* QualityEnum = StaticEnum<EQualityEnum>();
|
||||
int QualityEnumNum = QualityEnum->NumEnums() - 1;
|
||||
iCurrentSelectQuality = FMath::Clamp(iCurrentSelectQuality + 1, 0, QualityEnumNum - 1);
|
||||
|
||||
UpdateSelectQuality();
|
||||
}
|
||||
|
||||
void UMainScreenUserWidget::SelectPreviousQuality()
|
||||
{
|
||||
UEnum* QualityEnum = StaticEnum<EQualityEnum>();
|
||||
int QualityEnumNum = QualityEnum->NumEnums() - 1;
|
||||
iCurrentSelectQuality = FMath::Clamp(iCurrentSelectQuality - 1, 0, QualityEnumNum - 1);
|
||||
|
||||
UpdateSelectQuality();
|
||||
}
|
||||
|
||||
void UMainScreenUserWidget::UpdateSelectRobot()
|
||||
{
|
||||
ULuckyrobotsGameInstance* LuckyrobotsGameInstance = Cast<ULuckyrobotsGameInstance>(GetGameInstance());
|
||||
if (LuckyrobotsGameInstance)
|
||||
{
|
||||
LuckyrobotsGameInstance->CurrentSelectRobot = GetCurrentRobotData().Name;
|
||||
}
|
||||
BPUpdateSelectRobot();
|
||||
InitLevelData();
|
||||
}
|
||||
void UMainScreenUserWidget::UpdateSelectLevel()
|
||||
{
|
||||
ULuckyrobotsGameInstance* LuckyrobotsGameInstance = Cast<ULuckyrobotsGameInstance>(GetGameInstance());
|
||||
if (LuckyrobotsGameInstance)
|
||||
{
|
||||
LuckyrobotsGameInstance->CurrentSelectLevel = GetCurrentLevelData().LevelEnum;
|
||||
}
|
||||
BPUpdateSelectLevel();
|
||||
}
|
||||
|
||||
void UMainScreenUserWidget::UpdateSelectQuality()
|
||||
{
|
||||
ULuckyrobotsGameInstance* LuckyrobotsGameInstance = Cast<ULuckyrobotsGameInstance>(GetGameInstance());
|
||||
if (LuckyrobotsGameInstance)
|
||||
{
|
||||
UEnum* QualityEnum = StaticEnum<EQualityEnum>();
|
||||
LuckyrobotsGameInstance->CurrentSelectQuality = EQualityEnum(QualityEnum->GetValueByIndex(iCurrentSelectQuality));
|
||||
}
|
||||
BPUpdateSelectQuality();
|
||||
}
|
Reference in New Issue
Block a user