You've already forked LuckyWorld
Luckyrobots -> LuckyRobots
This commit is contained in:
@ -1,204 +0,0 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#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()
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
iCurrentSelectRobot = 0;
|
||||
UpdateSelectRobot();
|
||||
}
|
||||
|
||||
void UMainScreenUserWidget::InitLevelData()
|
||||
{
|
||||
FRobotData CurrentRobotData = GetCurrentRobotData();
|
||||
if (CurrentRobotData.Name != ERobotsName::None)
|
||||
{
|
||||
if (LevelDataTable)
|
||||
{
|
||||
LevelDataList.Empty();
|
||||
|
||||
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();
|
||||
|
||||
FString ContextString;
|
||||
TArray<FName> RowNames = LevelDataTable->GetRowNames();
|
||||
for (auto RowString : RowNames)
|
||||
{
|
||||
FLevelData* pRow = LevelDataTable->FindRow<FLevelData>(FName(RowString), ContextString);
|
||||
if (pRow)
|
||||
{
|
||||
if (pRow->bActive)
|
||||
{
|
||||
LevelDataList.Add(*pRow);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
iCurrentSelectLevel = 0;
|
||||
UpdateSelectLevel();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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