Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[PS] Display fade overlay for locked skins #63

Merged
merged 21 commits into from
Mar 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Config/BaseProgressionSystem.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ DataAssetInternal=/ProgressionSystem/DataAssets/DA_ProgressionSystem.DA_Progress

; Increment save file version extennsion to force users run empty save
; Increment whenever a major changes done with safe file structure
SaveFileVersionExtensionInternal=4
SaveFileVersionExtensionInternal=5
Binary file modified Content/DataAssets/DA_ProgressionSystem.uasset
Binary file not shown.
Binary file modified Content/DataAssets/DT_ProgressionSettings.uasset
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void UPSSpotComponent::OnInitialized_Implementation()
UPSWorldSubsystem& WorldSubsystem = UPSWorldSubsystem::Get();
WorldSubsystem.OnCurrentActiveSaveRowChanged.AddUniqueDynamic(this, &ThisClass::OnCurrentActiveSaveRowChanged);
WorldSubsystem.OnCurrentScoreChanged.AddUniqueDynamic(this, &ThisClass::OnCurrentScoreChanged);

BIND_ON_GAME_STATE_CHANGED(this, ThisClass::OnGameStateChanged);
constexpr bool bApplySkin = false;
RefreshAmountOfUnlockedSkins(bApplySkin);

Expand All @@ -47,6 +47,15 @@ void UPSSpotComponent::OnReset_Implementation()
}
}

// Listen game states to switch character skin.
void UPSSpotComponent::OnGameStateChanged_Implementation(ECurrentGameState CurrentGameState)
{
if (CurrentGameState == ECurrentGameState::GameStarting)
{
TryRestorePlayerSkin();
}
}

// Called when the game starts
void UPSSpotComponent::BeginPlay()
{
Expand All @@ -67,27 +76,54 @@ void UPSSpotComponent::OnUnregister()
Super::OnUnregister();
}

void UPSSpotComponent::OnCurrentScoreChanged_Implementation(const FPSSaveToDiskData& CurrentSaveToDiskDataRow, const FPSRowData& CurrentProgressionSettingsRow)
// Check is player is allowed to play with current skin if not switch to allowed
void UPSSpotComponent::TryRestorePlayerSkin()
{
const APlayerCharacter* PlayerCharacter = UMyBlueprintFunctionLibrary::GetLocalPlayerCharacter();
// it's possible that spot might not be loaded till that time so no ensure added
const UPSSpotComponent* CurrentSpot = UPSWorldSubsystem::Get().GetCurrentSpot();
if (CurrentSpot == nullptr || CurrentSpot != this)
{
return;
}

UMySkeletalMeshComponent& MeshComp = GetMeshChecked();
const int32 CurrentSkinIndex = MeshComp.GetAppliedSkinIndex();

if (!ensureMsgf(PlayerCharacter, TEXT("ASSERT: [%i] %hs:\n'PlayerCharacter' is not valid!"), __LINE__, __FUNCTION__))
// Current skins is available no need to switch to last avaialble
if (MeshComp.IsSkinAvailable(CurrentSkinIndex))
{
return;
}
const FPlayerTag& PlayerTag = PlayerCharacter->GetPlayerTag();
if (GetMeshChecked().GetPlayerTag() == PlayerTag)

// find last unlocked skin
for (int32 Count = CurrentSkinIndex; Count >= 0; Count--)
{
if (Count == 0 || MeshComp.IsSkinAvailable(Count))
{
MeshComp.ApplySkinByIndex(Count);

constexpr bool bApplySkin = true;
RefreshAmountOfUnlockedSkins(bApplySkin);
break;
}
}
}

// Updates the progression unlocked skins when score changes
void UPSSpotComponent::OnCurrentScoreChanged_Implementation(const FPSSaveToDiskData& CurrentSaveToDiskDataRow, const FPSSettingsRow& CurrentProgressionSettingsRow)
{
if (IsCurrentSpot())
{
constexpr bool bApplySkin = true;
RefreshAmountOfUnlockedSkins(bApplySkin);
}
}

// Updates the progression menu widget when player changed
void UPSSpotComponent::OnCurrentActiveSaveRowChanged_Implementation(const FPlayerTag PlayerTag)
void UPSSpotComponent::OnCurrentActiveSaveRowChanged_Implementation(const FPlayerTag NewPlayerTag, const FPlayerTag PreviousPlayerTag)
{
UMySkeletalMeshComponent& Mesh = GetMeshChecked();
if (Mesh.GetPlayerTag() == PlayerTag)
if (Mesh.GetPlayerTag() == NewPlayerTag)
{
ChangeSpotVisibilityStatus(&Mesh);
constexpr bool bApplySkin = false;
Expand Down Expand Up @@ -120,6 +156,11 @@ void UPSSpotComponent::ChangeSpotVisibilityStatus(UMySkeletalMeshComponent* Mesh
// Refresh Amount Of Unlocked skins for the character (level)s
void UPSSpotComponent::RefreshAmountOfUnlockedSkins(bool bApplySkin)
{
if (!IsCurrentSpot())
{
return;
}

UMySkeletalMeshComponent& SpotMeshComponent = GetMeshChecked();
const int32 UnlockedSkinsAmount = UPSWorldSubsystem::Get().GetCurrentSaveToDiskRowByName().UnlockedSkinsAmount;

Expand All @@ -136,3 +177,11 @@ void UPSSpotComponent::RefreshAmountOfUnlockedSkins(bool bApplySkin)
}
}
}

// Returns true if this is a current spot
bool UPSSpotComponent::IsCurrentSpot() const
{
const APlayerCharacter* PlayerCharacter = UMyBlueprintFunctionLibrary::GetLocalPlayerCharacter();
const FPlayerTag& PlayerTag = PlayerCharacter ? PlayerCharacter->GetPlayerTag() : FPlayerTag::None;
return PlayerCharacter && GetMeshChecked().GetPlayerTag() == PlayerTag;
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void UPSSaveGameData::SavePoints(EEndGameState EndGameState)
return;
}
// Increase the current level's progression by the reward from the end game state
const FPSRowData& CurrentProgressionSettingsRowData = UPSWorldSubsystem::Get().GetCurrentProgressionSettingsRowByName();
const FPSSettingsRow& CurrentProgressionSettingsRowData = UPSWorldSubsystem::Get().GetCurrentProgressionSettingsRow();
if (!ensureMsgf(CurrentProgressionSettingsRowData.Character.IsValid(), TEXT("ASSERT: [%i] %hs:\n'CurrentProgressionSettingsRowData or Points to unlock = 0' is not valid!"), __LINE__, __FUNCTION__))
{
return;
Expand Down Expand Up @@ -147,7 +147,7 @@ void UPSSaveGameData::UnlockAllLevels()
{
// levels
UnlockLevelByName(KeyValue.Key);
const FPSRowData& CurrentProgressionSettingsRowData = UPSWorldSubsystem::Get().GetRowDataByName(KeyValue.Key);
const FPSSettingsRow& CurrentProgressionSettingsRowData = UPSWorldSubsystem::Get().GetSettingsRowByName(KeyValue.Key);
if (!ensureMsgf(CurrentProgressionSettingsRowData.IsValid(), TEXT("ASSERT: [%i] %hs:\n'CurrentProgressionSettingsRowData or Points to unlock = 0' is not valid!"), __LINE__, __FUNCTION__))
{
continue;
Expand Down
2 changes: 1 addition & 1 deletion Source/ProgressionSystemRuntime/Private/Data/PSTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
#include "Data/PSTypes.h"

#include UE_INLINE_GENERATED_CPP_BY_NAME(PSTypes)
const FPSRowData FPSRowData::EmptyData = FPSRowData{};
const FPSSettingsRow FPSSettingsRow::EmptyData = FPSSettingsRow{};
const FPSSaveToDiskData FPSSaveToDiskData::EmptyData = FPSSaveToDiskData{};
37 changes: 20 additions & 17 deletions Source/ProgressionSystemRuntime/Private/Data/PSWorldSubsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,17 @@ UPSWorldSubsystem& UPSWorldSubsystem::Get(const UObject& WorldContextObject)
// Set current row of progression system by tag
void UPSWorldSubsystem::SetCurrentRowByTag(FPlayerTag NewRowPlayerTag)
{
for (const TTuple<FName, FPSRowData>& KeyValue : ProgressionSettingsDataInternal)
const FPSSettingsRow& CurrentSettingsRowData = GetCurrentProgressionSettingsRow();
const FPlayerTag& PreviousPlayerTag = CurrentSettingsRowData.Character;

for (const TTuple<FName, FPSSettingsRow>& KeyValue : ProgressionSettingsDataInternal)
{
const FPSRowData& RowData = KeyValue.Value;
const FPSSettingsRow& RowData = KeyValue.Value;

if (RowData.Character == NewRowPlayerTag)
{
CurrentRowNameInternal = KeyValue.Key;
OnCurrentActiveSaveRowChanged.Broadcast(NewRowPlayerTag);
OnCurrentActiveSaveRowChanged.Broadcast(NewRowPlayerTag, PreviousPlayerTag);
UpdateProgressionStarActors();
return; // Exit immediately after finding the match
}
Expand Down Expand Up @@ -87,26 +90,26 @@ const FPSSaveToDiskData& UPSWorldSubsystem::GetCurrentSaveToDiskRowByName() cons
return SaveGameDataInternal->GetSaveToDiskDataByName(CurrentRowNameInternal);
}

// Returns a current progression row settings data row by name
const FPSRowData& UPSWorldSubsystem::GetCurrentProgressionSettingsRowByName() const
// Returns a current progression settings data row
const FPSSettingsRow& UPSWorldSubsystem::GetCurrentProgressionSettingsRow() const
{
if (const FPSRowData* FoundRow = ProgressionSettingsDataInternal.Find(CurrentRowNameInternal))
if (const FPSSettingsRow* FoundRow = ProgressionSettingsDataInternal.Find(CurrentRowNameInternal))
{
return *FoundRow;
}

return FPSRowData::EmptyData;
return FPSSettingsRow::EmptyData;
}

// Returns the current row data by name.
const FPSRowData& UPSWorldSubsystem::GetRowDataByName(FName CurrentRowName) const
// Returns a current progression settings data row by name
const FPSSettingsRow& UPSWorldSubsystem::GetSettingsRowByName(FName CurrentRowName) const
{
if (const FPSRowData* FoundRow = ProgressionSettingsDataInternal.Find(CurrentRowName))
if (const FPSSettingsRow* FoundRow = ProgressionSettingsDataInternal.Find(CurrentRowName))
{
return *FoundRow;
}

return FPSRowData::EmptyData;
return FPSSettingsRow::EmptyData;
}

// Set the progression system component
Expand All @@ -127,7 +130,7 @@ void UPSWorldSubsystem::RegisterSpotComponent(UPSSpotComponent* MySpotComponent)
return;
}

for (const TTuple<FName, FPSRowData>& RowData : ProgressionSettingsDataInternal)
for (const TTuple<FName, FPSSettingsRow>& RowData : ProgressionSettingsDataInternal)
{
if (RowData.Value.Character == MySpotComponent->GetMeshChecked().GetPlayerTag())
{
Expand Down Expand Up @@ -269,7 +272,7 @@ void UPSWorldSubsystem::UpdateProgressionStarActors()
};

// --- Spawn actors
const FPSRowData& CurrentSettingsRowData = GetCurrentProgressionSettingsRowByName();
const FPSSettingsRow& CurrentSettingsRowData = GetCurrentProgressionSettingsRow();
if (CurrentSettingsRowData.PointsToUnlock)
{
UPoolManagerSubsystem::Get().TakeFromPoolArray(PoolActorHandlersInternal, UPSDataAsset::Get().GetStarActorClass(), CurrentSettingsRowData.PointsToUnlock, OnTakeActorsFromPoolCompleted, ESpawnRequestPriority::High);
Expand All @@ -279,7 +282,7 @@ void UPSWorldSubsystem::UpdateProgressionStarActors()
// Dynamically adds Star actors which representing unlocked and locked progression above the character
void UPSWorldSubsystem::OnTakeActorsFromPoolCompleted(const TArray<FPoolObjectData>& CreatedObjects)
{
const FPSRowData& CurrentSettingsRowData = GetCurrentProgressionSettingsRowByName();
const FPSSettingsRow& CurrentSettingsRowData = GetCurrentProgressionSettingsRow();
const FPSSaveToDiskData& CurrentSaveToDiskRowData = GetCurrentSaveToDiskRowByName();

float CurrentAmountOfUnlocked = CurrentSaveToDiskRowData.CurrentLevelProgression;
Expand Down Expand Up @@ -351,7 +354,7 @@ void UPSWorldSubsystem::OnAsyncLoadGameFromSlotCompleted_Implementation(USaveGam

if (SaveGameDataInternal)
{
for (const TTuple<FName, FPSRowData>& Row : ProgressionSettingsDataInternal)
for (const TTuple<FName, FPSSettingsRow>& Row : ProgressionSettingsDataInternal)
{
SaveGameDataInternal->SetProgressionMap(Row.Key, FPSSaveToDiskData::EmptyData);
}
Expand Down Expand Up @@ -398,7 +401,7 @@ void UPSWorldSubsystem::SaveDataAsync()
return;
}
const FPSSaveToDiskData& CurrenSaveToDiskDataRow = GetCurrentSaveToDiskRowByName();
const FPSRowData& CurrenProgressionSettingsRow = GetCurrentProgressionSettingsRowByName();
const FPSSettingsRow& CurrenProgressionSettingsRow = GetCurrentProgressionSettingsRow();

UpdateProgressionStarActors();
OnCurrentScoreChanged.Broadcast(CurrenSaveToDiskDataRow, CurrenProgressionSettingsRow);
Expand All @@ -423,7 +426,7 @@ void UPSWorldSubsystem::ResetSaveGameData()
}
UMyDataTable::GetRows(*ProgressionDataTable, ProgressionSettingsDataInternal);

for (const TTuple<FName, FPSRowData>& Row : ProgressionSettingsDataInternal)
for (const TTuple<FName, FPSSettingsRow>& Row : ProgressionSettingsDataInternal)
{
SaveGameDataInternal->SetProgressionMap(Row.Key, FPSSaveToDiskData::EmptyData);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void APSStarActor::OnAnyCinematicStarted_Implementation(const UObject* LevelSequ
// Hiding stars with animation in main menu when cinematic is start to play
void APSStarActor::TryPlayHideStarAnimation()
{
const FPSRowData& CurrentProgressionSettingsRow = UPSWorldSubsystem::Get().GetCurrentProgressionSettingsRowByName();
const FPSSettingsRow& CurrentProgressionSettingsRow = UPSWorldSubsystem::Get().GetCurrentProgressionSettingsRow();
const bool bIsFinished = !TryPlayStarAnimation(StartTimeHideStarsInternal, CurrentProgressionSettingsRow.HideStarsAnimation);
if (bIsFinished)
{
Expand All @@ -104,7 +104,7 @@ void APSStarActor::TryPlayHideStarAnimation()
// Menu stars with animation in main menu idle
void APSStarActor::TryPlayMenuStarAnimation()
{
const FPSRowData& CurrentProgressionSettingsRow = UPSWorldSubsystem::Get().GetCurrentProgressionSettingsRowByName();
const FPSSettingsRow& CurrentProgressionSettingsRow = UPSWorldSubsystem::Get().GetCurrentProgressionSettingsRow();
const bool bIsFinished = !TryPlayStarAnimation(StartTimeMenuStarsInternal, CurrentProgressionSettingsRow.MenuStarsAnimation);
if (bIsFinished)
{
Expand Down Expand Up @@ -147,7 +147,7 @@ void APSStarActor::SetStartTimeMenuStars()
// Is get called when a Star actor is initialized
void APSStarActor::OnInitialized(const FVector& PreviousActorLocation)
{
const FPSRowData& CurrentProgressionSettingsRow = UPSWorldSubsystem::Get().GetCurrentProgressionSettingsRowByName();
const FPSSettingsRow& CurrentProgressionSettingsRow = UPSWorldSubsystem::Get().GetCurrentProgressionSettingsRow();
FTransform DesiredTransform = CurrentProgressionSettingsRow.StarActorTransform;

// set offset from previous if it's not first
Expand Down Expand Up @@ -206,7 +206,7 @@ void APSStarActor::SetStarActorProgressMeshMaterial(class UMaterialInstanceDynam
}

// Add a face texture over current star material
const FPSRowData& CurrentSettingsRowData = UPSWorldSubsystem::Get().GetCurrentProgressionSettingsRowByName();
const FPSSettingsRow& CurrentSettingsRowData = UPSWorldSubsystem::Get().GetCurrentProgressionSettingsRow();
const FName StarFaceTextureParameter = UPSDataAsset::Get().GetStarFaceTextureParameter();
const FName StarProgressionMaterialSlotName = UPSDataAsset::Get().GetStarMaterialSlotName();
UTexture* StarFaceTexture = CurrentSettingsRowData.StarFaceTexture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ void UPSEndGameWidget::UpdateStarProgressBarValue(const FPoolObjectData& Created
}

// Updates the progression menu widget when player changed
void UPSEndGameWidget::OnCurrentScoreChanged_Implementation(const FPSSaveToDiskData& CurrenSaveToDiskDataRow, const FPSRowData& CurrenProgressionSettingsRow)
void UPSEndGameWidget::OnCurrentScoreChanged_Implementation(const FPSSaveToDiskData& CurrenSaveToDiskDataRow, const FPSSettingsRow& CurrenProgressionSettingsRow)
{
//set updated amount of stars
if (CurrenSaveToDiskDataRow.CurrentLevelProgression >= CurrenProgressionSettingsRow.PointsToUnlock)
Expand Down
Loading