This commit is contained in:
martinluckyrobots 2025-03-29 22:43:51 +08:00
parent 64bb8f1075
commit 0ce046cfaf
12 changed files with 203 additions and 48 deletions

View File

@ -248,7 +248,7 @@ GameDefaultMap=/Game/Map/SelectLevel.SelectLevel
GlobalDefaultGameMode=/Game/Blueprint/Game/BP_LuckyRobots.BP_LuckyRobots_C
GlobalDefaultServerGameMode=/Game/luckyBot/blueprint/gameBP/luckycar.luckycar_C
GameInstanceClass=/Game/Blueprint/Game/BP_LuckyGameinstanceMode.BP_LuckyGameinstanceMode_C
EditorStartupMap=/Game/Levels/House05/Maps/AIUE_vol8_04.AIUE_vol8_04
EditorStartupMap=/Game/Map/SelectLevel.SelectLevel
[/Script/LinuxTargetPlatform.LinuxTargetSettings]
SpatializationPlugin=
@ -321,4 +321,5 @@ MaxAgentRadius=100.000000
[/Script/Engine.Engine]
+ActiveGameNameRedirects=(OldGameName="TP_VehicleAdv",NewGameName="/Script/Luckyrobots")
+ActiveGameNameRedirects=(OldGameName="/Script/TP_VehicleAdv",NewGameName="/Script/Luckyrobots")
+ActiveGameNameRedirects=(OldGameName="/Script/TP_VehicleAdv",NewGameName="/Script/Luckyrobots")

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

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

View File

@ -4,6 +4,7 @@
#include "CoreMinimal.h"
#include "Engine/GameInstance.h"
#include "SharedDef.h"
#include "LuckyrobotsGameInstance.generated.h"
/**
@ -13,5 +14,14 @@ UCLASS()
class LUCKYROBOTS_API ULuckyrobotsGameInstance : public UGameInstance
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
ERobotsName CurrentSelectRobot;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
ELevelEnum CurrentSelectLevel;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
EQualityEnum CurrentSelectQuality;
};

View File

@ -15,7 +15,9 @@ UCLASS()
class LUCKYROBOTS_API UMainScreenUserWidget : public UUserWidget
{
GENERATED_BODY()
protected:
virtual void NativeConstruct();
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Config")
UDataTable* RobotDataDataTable;
@ -34,6 +36,10 @@ public:
int iCurrentSelectRobot;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
int iCurrentSelectLevel;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
int iCurrentSelectQuality;
public:
UFUNCTION(BlueprintCallable)
void InitData();
@ -45,9 +51,34 @@ public:
FRobotData GetCurrentRobotData();
UFUNCTION(BlueprintCallable)
FLevelData GetCurrentLevelData();
UFUNCTION(BlueprintCallable)
void SelectNextRobot();
UFUNCTION(BlueprintCallable)
void SelectPreviousRobot();
UFUNCTION(BlueprintCallable)
void SelectNextLevel();
UFUNCTION(BlueprintCallable)
void SelectPreviousLevel();
UFUNCTION(BlueprintCallable)
void SelectNextQuality();
UFUNCTION(BlueprintCallable)
void SelectPreviousQuality();
void UpdateSelectRobot();
void UpdateSelectLevel();
void UpdateSelectQuality();
public:
UFUNCTION(BlueprintImplementableEvent)
void BPUpdateSelectRobot();
UFUNCTION(BlueprintImplementableEvent)
void BPUpdateSelectLevel();
UFUNCTION(BlueprintImplementableEvent)
void BPUpdateSelectQuality();
};

View File

@ -17,6 +17,24 @@ enum class ERobotsCategories : uint8
OutdoorFlying UMETA(DisplayName = "Outdoor Flying Robots")
};
UENUM(BlueprintType)
enum class ERobotsName : uint8
{
None UMETA(DisplayName = "None"),
Luck_e UMETA(DisplayName = "Luck-e"),
Stretch UMETA(DisplayName = "Stretch"),
LuckyDrone UMETA(DisplayName = "Lucky Drone"),
DJIDrone UMETA(DisplayName = "DJI Drone"),
ArmLucky UMETA(DisplayName = "Arm Lucky"),
UnitreeG1 UMETA(DisplayName = "Unitree G1"),
StretchRobotV1 UMETA(DisplayName = "Stretch Robot V1"),
PandaArmRobot UMETA(DisplayName = "Panda Arm Robot"),
PuralinkRobot UMETA(DisplayName = "Puralink Robot"),
UnitreeGo2 UMETA(DisplayName = "Unitree Go 2"),
RevoluteRobot UMETA(DisplayName = "Revolute Robot"),
BostonSpotRobot UMETA(DisplayName = "Boston Spot Robot")
};
UENUM(BlueprintType)
enum class ELevelType : uint8
{
@ -26,13 +44,39 @@ enum class ELevelType : uint8
TestLevel UMETA(DisplayName = "TestLevel")
};
UENUM(BlueprintType)
enum class ELevelEnum : uint8
{
None UMETA(DisplayName = "None"),
TestLevel UMETA(DisplayName = "Test Level"),
Loft UMETA(DisplayName = "Loft"),
Rome UMETA(DisplayName = "Rome"),
Paris UMETA(DisplayName = "Paris"),
Marseille UMETA(DisplayName = "Marseille"),
Istanbul UMETA(DisplayName = "Istanbul"),
Office UMETA(DisplayName = "Office"),
BasicForest UMETA(DisplayName = "Basic Forest"),
NaturalForest UMETA(DisplayName = "Natural Forest"),
KitchenForArmRobot UMETA(DisplayName = "Kitchen for Arm Robot"),
PipeFabric UMETA(DisplayName = "Pipe Fabric")
};
UENUM(BlueprintType)
enum class EQualityEnum : uint8
{
Epic UMETA(DisplayName = "Epic"),
High UMETA(DisplayName = "High"),
Middle UMETA(DisplayName = "Middle"),
Low UMETA(DisplayName = "Low")
};
USTRUCT(BlueprintType)
struct FRobotData : public FTableRowBase
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FString Name;
ERobotsName Name;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TSubclassOf<AActor> RobotClass;
@ -50,7 +94,7 @@ public:
ERobotsCategories RobotType;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FString HelpStr;
FText HelpText;
};
USTRUCT(BlueprintType)
@ -62,13 +106,14 @@ public:
int ID;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FString LevelName;
ELevelEnum LevelEnum;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
ELevelType LevelType;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FString MenuName;
FString LevelName;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
UTexture2D* LevelImage;