diff --git a/Config/DefaultEditor.ini b/Config/DefaultEditor.ini index e69de29..f38756e 100644 --- a/Config/DefaultEditor.ini +++ b/Config/DefaultEditor.ini @@ -0,0 +1,2 @@ +[/Script/AdvancedPreviewScene.SharedProfiles] + diff --git a/Content/Blueprints/OvenCookspot_BP.uasset b/Content/Blueprints/OvenCookspot_BP.uasset index c252406..6086ed1 100644 Binary files a/Content/Blueprints/OvenCookspot_BP.uasset and b/Content/Blueprints/OvenCookspot_BP.uasset differ diff --git a/Content/Blueprints/OvenPawn_BP.uasset b/Content/Blueprints/OvenPawn_BP.uasset index 19b81c7..0fe3833 100644 Binary files a/Content/Blueprints/OvenPawn_BP.uasset and b/Content/Blueprints/OvenPawn_BP.uasset differ diff --git a/Content/Meshes/lp_oven_fire.uasset b/Content/Meshes/lp_oven_fire.uasset index e46dfbe..a067566 100644 Binary files a/Content/Meshes/lp_oven_fire.uasset and b/Content/Meshes/lp_oven_fire.uasset differ diff --git a/Content/__ExternalActors__/Levels/Main/1/WT/7J9UKEOU9FZ4MSUVEO0X27.uasset b/Content/__ExternalActors__/Levels/Main/1/WT/7J9UKEOU9FZ4MSUVEO0X27.uasset index afbea61..4b00297 100644 Binary files a/Content/__ExternalActors__/Levels/Main/1/WT/7J9UKEOU9FZ4MSUVEO0X27.uasset and b/Content/__ExternalActors__/Levels/Main/1/WT/7J9UKEOU9FZ4MSUVEO0X27.uasset differ diff --git a/Content/__ExternalActors__/Levels/Main/2/VE/9QQDSCIN5U7EXJZOEVV967.uasset b/Content/__ExternalActors__/Levels/Main/2/VE/9QQDSCIN5U7EXJZOEVV967.uasset index d1f70e7..173f2e1 100644 Binary files a/Content/__ExternalActors__/Levels/Main/2/VE/9QQDSCIN5U7EXJZOEVV967.uasset and b/Content/__ExternalActors__/Levels/Main/2/VE/9QQDSCIN5U7EXJZOEVV967.uasset differ diff --git a/Content/__ExternalActors__/Levels/Main/6/OD/VIU20N2A76GYCO1DVKBZ7K.uasset b/Content/__ExternalActors__/Levels/Main/6/OD/VIU20N2A76GYCO1DVKBZ7K.uasset index d463345..3365f99 100644 Binary files a/Content/__ExternalActors__/Levels/Main/6/OD/VIU20N2A76GYCO1DVKBZ7K.uasset and b/Content/__ExternalActors__/Levels/Main/6/OD/VIU20N2A76GYCO1DVKBZ7K.uasset differ diff --git a/Content/__ExternalActors__/Levels/Main/9/BI/1E2K4JCEVV61RIQPXV14J0.uasset b/Content/__ExternalActors__/Levels/Main/9/BI/1E2K4JCEVV61RIQPXV14J0.uasset index ff0f0b7..d522232 100644 Binary files a/Content/__ExternalActors__/Levels/Main/9/BI/1E2K4JCEVV61RIQPXV14J0.uasset and b/Content/__ExternalActors__/Levels/Main/9/BI/1E2K4JCEVV61RIQPXV14J0.uasset differ diff --git a/Content/__ExternalActors__/Levels/Main/B/54/SRV55I3JSWLTKQNJNVREKY.uasset b/Content/__ExternalActors__/Levels/Main/B/54/SRV55I3JSWLTKQNJNVREKY.uasset index 512d39a..ca7a08c 100644 Binary files a/Content/__ExternalActors__/Levels/Main/B/54/SRV55I3JSWLTKQNJNVREKY.uasset and b/Content/__ExternalActors__/Levels/Main/B/54/SRV55I3JSWLTKQNJNVREKY.uasset differ diff --git a/Content/__ExternalActors__/Levels/Main/E/WP/88HCTL2XJVH0BSO91BGVU1.uasset b/Content/__ExternalActors__/Levels/Main/E/WP/88HCTL2XJVH0BSO91BGVU1.uasset index d8c62e8..9b1f8a0 100644 Binary files a/Content/__ExternalActors__/Levels/Main/E/WP/88HCTL2XJVH0BSO91BGVU1.uasset and b/Content/__ExternalActors__/Levels/Main/E/WP/88HCTL2XJVH0BSO91BGVU1.uasset differ diff --git a/Source/minicook/OvenCookspot.cpp b/Source/minicook/OvenCookspot.cpp index 1ce9e6e..0989df6 100644 --- a/Source/minicook/OvenCookspot.cpp +++ b/Source/minicook/OvenCookspot.cpp @@ -14,19 +14,30 @@ AOvenCookspot::AOvenCookspot() FireMesh = CreateDefaultSubobject("FireSM"); FireElementMesh = CreateDefaultSubobject("FireElementSM"); CookpotMesh = CreateDefaultSubobject("CookpotSM"); + FireLight = CreateDefaultSubobject("FireLight"); FireElementMesh->SetupAttachment(RootComponent); FireMesh->SetupAttachment(RootComponent); CookpotMesh->SetupAttachment(RootComponent); + FireLight->SetupAttachment(RootComponent); } void AOvenCookspot::UpdateFire(const float DeltaTime) const { if (FireScaleCurveXY && FireScaleCurveZ && FireMesh) { - const float ScaleXY = FireScaleCurveXY->GetFloatValue(CurrentHeat); - const float ScaleZ = FireScaleCurveZ->GetFloatValue(CurrentHeat); - FireMesh->SetWorldScale3D(FVector(ScaleXY, ScaleXY, ScaleZ)); + if (CurrentHeat < 0.10) + { + FireMesh->SetWorldScale3D(FVector(0.0f)); + FireLight->SetVisibility(false); + } + else + { + const float ScaleXY = FireScaleCurveXY->GetFloatValue(CurrentHeat); + const float ScaleZ = FireScaleCurveZ->GetFloatValue(CurrentHeat); + FireMesh->SetWorldScale3D(FVector(ScaleXY, ScaleXY, ScaleZ)); + FireLight->SetVisibility(true); + } } else { diff --git a/Source/minicook/OvenCookspot.h b/Source/minicook/OvenCookspot.h index f0c92c2..028b3df 100644 --- a/Source/minicook/OvenCookspot.h +++ b/Source/minicook/OvenCookspot.h @@ -3,6 +3,7 @@ #pragma once #include "CoreMinimal.h" +#include "Components/PointLightComponent.h" #include "GameFramework/Actor.h" #include "OvenCookspot.generated.h" @@ -26,6 +27,8 @@ public: // Called every frame virtual void Tick(float DeltaTime) override; + void SetCurrentHeat(const double InCurrentHeat) { CurrentHeat = InCurrentHeat; } + public: UPROPERTY(EditAnywhere, BlueprintReadWrite) @@ -37,6 +40,9 @@ public: UPROPERTY(EditAnywhere, BlueprintReadWrite) TObjectPtr CookpotMesh; + UPROPERTY(EditAnywhere, BlueprintReadWrite) + TObjectPtr FireLight; + UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Default") TObjectPtr FireScaleCurveXY; @@ -44,5 +50,5 @@ public: TObjectPtr FireScaleCurveZ; private: // [0.0, 1.0] - double CurrentHeat; + double CurrentHeat{0.0}; }; \ No newline at end of file diff --git a/Source/minicook/OvenPawn.cpp b/Source/minicook/OvenPawn.cpp index 28cb4dc..da1c38f 100644 --- a/Source/minicook/OvenPawn.cpp +++ b/Source/minicook/OvenPawn.cpp @@ -50,7 +50,9 @@ auto FCookstove::SetCookingTime(const FTimespan CookingTimespan) -> void void FCookstove::Update(const float DeltaTime, int32 &PlayerScore) { - // If the id is not set, we have no work + OvenCookstoveActor->SetCurrentHeat(CurrentHeat); + + // If the id is not set, we have no work meal-wise if (CurrentMealID == -1 || CurrentlyCooking == false) { return; @@ -112,18 +114,27 @@ void AOvenPawn::BeginPlay() { Super::BeginPlay(); + // Setup the arrays Cookstoves.AddDefaulted(CookspotLocations.Num()); + CookspotDials.AddDefaulted(CookspotLocations.Num()); + verifyf(Cookstoves.Num() == CookspotDials.Num() && + Cookstoves.Num() == CookspotLocations.Num() && + CookspotNeedles.Num() == CookspotLocations.Num(), + TEXT("Data is not synced up! One or more arrays with different sizes!")) + + // Tie up the data together size_t CookspotIdx{0}; for (const AActor *CookspotLoc : CookspotLocations) { FActorSpawnParameters SpawnParameters; - auto *OvenCookspotActor = - GetWorld()->SpawnActor(CookstovePrefab, - CookspotLoc->GetTransform(), - SpawnParameters); + auto *OvenCookspotActor = GetWorld()->SpawnActor(CookstovePrefab, + CookspotLoc->GetTransform(), + SpawnParameters); OvenCookspotActor->SetActorLocation(CookspotLoc->GetActorLocation()); + Cookstoves[CookspotIdx].OvenCookstoveActor = OvenCookspotActor; + CookspotDials[CookspotIdx].NeedleSM = CookspotNeedles[CookspotIdx]; CookspotIdx++; } } @@ -132,9 +143,13 @@ void AOvenPawn::Tick(float DeltaTime) { Super::Tick(DeltaTime); + // TODO: Copying dial ratio to active cookspot back and forth is not ideal for organization, refactor. + // Get the dial ratio and convert it to the CurrentHeat + Cookstoves[ActiveDialIndex].CurrentHeat = CookspotDials[ActiveDialIndex].DialRatio; + int32 ScoreThisFrame{0}; // Check the cooking stoves and update 'em - for (FCookstove Cookstove : Cookstoves) + for (FCookstove &Cookstove : Cookstoves) { Cookstove.Update(DeltaTime, ScoreThisFrame); } @@ -152,7 +167,7 @@ void AOvenPawn::SetupPlayerInputComponent(UInputComponent *PlayerInputComponent) bool AOvenPawn::TrySpawningNewRandomMeal() { bool bSuccess{false}; - for (FCookstove Cookstove : Cookstoves) + for (FCookstove &Cookstove : Cookstoves) { if (!Cookstove.CurrentlyCooking) { @@ -166,4 +181,59 @@ bool AOvenPawn::TrySpawningNewRandomMeal() } } return bSuccess; +} + +auto AOvenPawn::RotateNeedleMouse(double MouseDeltaX) -> void +{ + verifyf(ActiveDialIndex < CookspotDials.Num(), + TEXT( + "The active dials index cannot be out of the bounds of the array 'CookspotDials' with size: %d, current idx: %d" + ), CookspotDials.Num(), ActiveDialIndex) + + FDial &Dial = CookspotDials[ActiveDialIndex]; + verifyf(Dial.NeedleSM, TEXT("The NeedleSM pointer needs to be valid!")) + + Dial.MouseDeltaX = FMath::Clamp((MouseDeltaX / 50.0f) + Dial.MouseDeltaX, -1.0f, 1.0f); + const float NewNeedleRotation = + FMath::GetMappedRangeValueClamped(FVector2D(-1.0f, 1.0f), + FVector2D(0.0f, -140.0f), + Dial.MouseDeltaX); + + Dial.NeedleSM->SetRelativeRotation(FRotator(NewNeedleRotation, 0.0f, 0.0f)); + + Dial.DialRatio = (Dial.MouseDeltaX + 1.0f) / 2.0; +} + +auto AOvenPawn::RotateNeedleController(const FVector2D ThumbstickLocation) -> void +{ + verifyf(ActiveDialIndex < CookspotDials.Num(), + TEXT( + "The active dials index cannot be out of the bounds of the array 'CookspotDials' with size: %d, current idx: %d" + ), CookspotDials.Num(), ActiveDialIndex) + + FDial &Dial = CookspotDials[ActiveDialIndex]; + verifyf(Dial.NeedleSM, TEXT("The NeedleSM pointer needs to be valid!")) + + // Clamp the thumbstick location to a range of [-1.0f, 1.0f] + Dial.DialRatioController += FMath::Clamp(ThumbstickLocation.X / 10.0f, -1.0f, 1.0f); + + const float NewNeedleRotation = FMath::GetMappedRangeValueClamped(FVector2D(-1.0f, 1.0f), FVector2D(0.0f, -140.0f), + Dial.DialRatioController); + + Dial.NeedleSM->SetRelativeRotation(FRotator(NewNeedleRotation, 0.0f, 0.0f)); + + Dial.DialRatio = (Dial.DialRatioController + 1.0) / 2.0; +} + +auto AOvenPawn::CycleActiveOvenDial(const bool CycleRight) -> void +{ + if (CycleRight) + { + ActiveDialIndex = (ActiveDialIndex + 1) % CookspotLocations.Num(); + } + else + { + ActiveDialIndex = ActiveDialIndex == 0 ? CookspotLocations.Num() - 1 : ActiveDialIndex - 1; + } + UE_LOG(LogTemp, Warning, TEXT("Cycled ActiveDialIndex: %d"), ActiveDialIndex); } \ No newline at end of file diff --git a/Source/minicook/OvenPawn.h b/Source/minicook/OvenPawn.h index cf37245..3fa54f5 100644 --- a/Source/minicook/OvenPawn.h +++ b/Source/minicook/OvenPawn.h @@ -128,6 +128,15 @@ public: auto TrySpawningNewRandomMeal() -> bool; + UFUNCTION(BlueprintCallable, Category="Oven Dials|Controlls") + void RotateNeedleMouse(double MouseDeltaX); + + UFUNCTION(BlueprintCallable, Category="Oven Dials|Controlls") + void RotateNeedleController(FVector2D ThumbstickLocation); + + UFUNCTION(BlueprintCallable, Category="Oven Dials|Controlls") + void CycleActiveOvenDial(bool CycleRight); + public: UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Oven Settings") double ScoreMultiplier{1.0}; @@ -148,10 +157,25 @@ public: UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Oven Settings") TObjectPtr RecipesDataTable; - UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Oven Settings") + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Oven Static Meshes") TArray> CookspotLocations; + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Oven Static Meshes") + TArray CookspotNeedles; + private: // An array of all the cookstoves, from left to right on the screen. TArray Cookstoves; + + struct FDial + { + double DialRatio{0.0}; + double DialRatioController{0.0}; + double MouseDeltaX{0.0}; + + TObjectPtr NeedleSM; + }; + + TArray CookspotDials; + int32 ActiveDialIndex{0}; }; \ No newline at end of file