From fdb60380031914f510fbd53e269ffa9160118200 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Mon, 13 Mar 2006 08:03:17 +0000 Subject: [PATCH] fix unlocks re-celebrated every time the app is run --- stepmania/src/ScreenUnlockCelebrate.cpp | 8 +++--- stepmania/src/UnlockManager.cpp | 35 +++++++++++++++++-------- stepmania/src/UnlockManager.h | 6 ++--- 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/stepmania/src/ScreenUnlockCelebrate.cpp b/stepmania/src/ScreenUnlockCelebrate.cpp index 6ebf124a83..14ff8172af 100644 --- a/stepmania/src/ScreenUnlockCelebrate.cpp +++ b/stepmania/src/ScreenUnlockCelebrate.cpp @@ -10,11 +10,11 @@ void ScreenUnlockCelebrate::Init() // We shouldn't be called if there aren't any unlocks to celebrate ASSERT( UNLOCKMAN->AnyUnlocksToCelebrate() ); - ScreenUnlockBrowse::Init(); - // Mark this unlock as celebrated - int iIndex = UNLOCKMAN->GetUnlockIndexToCelebrate(); - UNLOCKMAN->m_UnlockEntries[iIndex].m_bCelebrated = true; + int iUnlockID = UNLOCKMAN->GetUnlockEntryIDToCelebrate(); + UNLOCKMAN->UnlockEntryID( iUnlockID ); + + ScreenUnlockBrowse::Init(); } void ScreenUnlockCelebrate::MenuLeft( const InputEventPlus &input ) diff --git a/stepmania/src/UnlockManager.cpp b/stepmania/src/UnlockManager.cpp index 567cfdcabe..2a3b582a94 100644 --- a/stepmania/src/UnlockManager.cpp +++ b/stepmania/src/UnlockManager.cpp @@ -290,15 +290,20 @@ bool UnlockEntry::IsValid() const } } -bool UnlockEntry::IsLocked() const +bool UnlockEntry::IsRequirementMet() const { float fScores[NUM_UnlockRequirement]; UNLOCKMAN->GetPoints( PROFILEMAN->GetMachineProfile(), fScores ); for( int i = 0; i < NUM_UnlockRequirement; ++i ) if( m_fRequirement[i] && fScores[i] >= m_fRequirement[i] ) - return false; + return true; + return false; +} + +bool UnlockEntry::IsLocked() const +{ if( m_iEntryID != -1 && PROFILEMAN->GetMachineProfile()->m_UnlockedEntryIDs.find(m_iEntryID) != PROFILEMAN->GetMachineProfile()->m_UnlockedEntryIDs.end() ) return false; @@ -427,10 +432,6 @@ void UnlockManager::Load() if( bRoulette ) m_RouletteCodes.insert( current.m_iEntryID ); - // TODO: Persist celebrated info? - if( !current.IsLocked() ) - current.m_bCelebrated = false; - // Make sure that we don't have duplicate unlock IDs. This can cause problems // with UnlockCelebrate and with codes. FOREACH_CONST( UnlockEntry, m_UnlockEntries, ue ) @@ -559,11 +560,21 @@ bool UnlockManager::AllAreLocked() const return true; } -int UnlockManager::GetUnlockIndexToCelebrate() const +int UnlockManager::GetUnlockEntryIDToCelebrate() const { FOREACH_CONST( UnlockEntry, m_UnlockEntries, ue ) { - if( !ue->IsLocked() && !ue->m_bCelebrated ) + if( ue->IsRequirementMet() && ue->IsLocked() ) + return ue->m_iEntryID; + } + return -1; +} + +int UnlockManager::GetUnlockEntryIndexToCelebrate() const +{ + FOREACH_CONST( UnlockEntry, m_UnlockEntries, ue ) + { + if( ue->IsRequirementMet() && ue->IsLocked() ) return ue - m_UnlockEntries.begin(); } return -1; @@ -571,7 +582,7 @@ int UnlockManager::GetUnlockIndexToCelebrate() const bool UnlockManager::AnyUnlocksToCelebrate() const { - return GetUnlockIndexToCelebrate() != -1; + return GetUnlockEntryIDToCelebrate() != -1; } void UnlockManager::GetUnlocksByType( UnlockRewardType t, vector &apEntries ) @@ -643,7 +654,8 @@ public: static int PreferUnlockEntryID( T* p, lua_State *L ) { int iUnlockEntryID = IArg(1); p->PreferUnlockEntryID(iUnlockEntryID); return 0; } static int GetNumUnlocks( T* p, lua_State *L ) { lua_pushnumber( L, p->GetNumUnlocks() ); return 1; } static int AllAreLocked( T* p, lua_State *L ) { lua_pushboolean( L, p->AllAreLocked() ); return 1; } - static int GetUnlockIndexToCelebrate( T* p, lua_State *L ) { lua_pushnumber( L, p->GetUnlockIndexToCelebrate() ); return 1; } + static int GetUnlockEntryIDToCelebrate( T* p, lua_State *L ) { lua_pushnumber( L, p->GetUnlockEntryIDToCelebrate() ); return 1; } + static int GetUnlockEntryIndexToCelebrate( T* p, lua_State *L ) { lua_pushnumber( L, p->GetUnlockEntryIndexToCelebrate() ); return 1; } static int AnyUnlocksToCelebrate( T* p, lua_State *L ) { lua_pushboolean( L, p->AnyUnlocksToCelebrate() ); return 1; } static int GetUnlockEntry( T* p, lua_State *L ) { int iIndex = IArg(1); p->m_UnlockEntries[iIndex].PushSelf(L); return 1; } static int GetSongsUnlockedByEntryID( T* p, lua_State *L ) @@ -672,7 +684,8 @@ public: ADD_METHOD( PreferUnlockEntryID ); ADD_METHOD( GetNumUnlocks ); ADD_METHOD( AllAreLocked ); - ADD_METHOD( GetUnlockIndexToCelebrate ); + ADD_METHOD( GetUnlockEntryIDToCelebrate ); + ADD_METHOD( GetUnlockEntryIndexToCelebrate ); ADD_METHOD( AnyUnlocksToCelebrate ); ADD_METHOD( GetUnlockEntry ); ADD_METHOD( GetSongsUnlockedByEntryID ); diff --git a/stepmania/src/UnlockManager.h b/stepmania/src/UnlockManager.h index 48c90fd92e..d7988467f8 100644 --- a/stepmania/src/UnlockManager.h +++ b/stepmania/src/UnlockManager.h @@ -53,7 +53,6 @@ public: ZERO( m_fRequirement ); m_iEntryID = -1; - m_bCelebrated = false; } UnlockRewardType m_Type; @@ -67,9 +66,9 @@ public: float m_fRequirement[NUM_UnlockRequirement]; int m_iEntryID; - bool m_bCelebrated; bool IsValid() const; + bool IsRequirementMet() const; bool IsLocked() const; RString GetModifier() const { return m_cmd.GetArg(1).s; } RString GetDescription() const; @@ -103,7 +102,8 @@ public: // Gets number of unlocks for title screen int GetNumUnlocks() const; bool AllAreLocked() const; - int GetUnlockIndexToCelebrate() const; + int GetUnlockEntryIDToCelebrate() const; + int GetUnlockEntryIndexToCelebrate() const; bool AnyUnlocksToCelebrate() const; void GetPoints( const Profile *pProfile, float fScores[NUM_UnlockRequirement] ) const;