You've already forked LuckyWorld
Fix Folder Structure
This commit is contained in:
149
Source/Luckyrobots/Private/Menus/MainScreenUserWidget.cpp
Normal file
149
Source/Luckyrobots/Private/Menus/MainScreenUserWidget.cpp
Normal file
@ -0,0 +1,149 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "Menus/MainScreenUserWidget.h"
|
||||
#include "Engine/DataTable.h"
|
||||
#include "Core/LuckyRobotsGameInstance.h"
|
||||
#include "FunctionLibraries/LuckyRobotsFunctionLibrary.h"
|
||||
|
||||
void UMainScreenUserWidget::NativeConstruct()
|
||||
{
|
||||
Super::NativeConstruct();
|
||||
|
||||
InitData();
|
||||
}
|
||||
|
||||
void UMainScreenUserWidget::InitData()
|
||||
{
|
||||
InitRobotData();
|
||||
InitLevelData();
|
||||
|
||||
ULuckyRobotsGameInstance* LuckyRobotsGameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance());
|
||||
if (LuckyRobotsGameInstance)
|
||||
{
|
||||
iCurrentSelectQuality = int(LuckyRobotsGameInstance->CurrentSelectQuality);
|
||||
}
|
||||
}
|
||||
|
||||
void UMainScreenUserWidget::InitRobotData()
|
||||
{
|
||||
RobotDataList = ULuckyRobotsFunctionLibrary::GetActiveRobotDataList(this);
|
||||
|
||||
iCurrentSelectRobot = 0;
|
||||
UpdateSelectRobot();
|
||||
}
|
||||
|
||||
void UMainScreenUserWidget::InitLevelData()
|
||||
{
|
||||
LevelDataList = ULuckyRobotsFunctionLibrary::GetActiveLevelDataList(this);
|
||||
|
||||
FRobotData CurrentRobotData = GetCurrentRobotData();
|
||||
if (CurrentRobotData.Name != ERobotsName::None)
|
||||
{
|
||||
TArray<FLevelData> ActiveLevelDataList = LevelDataList;
|
||||
|
||||
LevelDataList.Empty();
|
||||
for (auto ActiveLevelData : ActiveLevelDataList)
|
||||
{
|
||||
if (ActiveLevelData.RobotTypeList.Find(CurrentRobotData.RobotType) >= 0)
|
||||
{
|
||||
LevelDataList.Add(ActiveLevelData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
LuckyRobotsGameInstance->CurrentSelectQuality = static_cast<EQualityEnum>(iCurrentSelectQuality);
|
||||
}
|
||||
BPUpdateSelectQuality();
|
||||
}
|
Reference in New Issue
Block a user