fix unlocks re-celebrated every time the app is run

This commit is contained in:
Chris Danford
2006-03-13 08:03:17 +00:00
parent 4eb0b1f86e
commit fdb6038003
3 changed files with 31 additions and 18 deletions
+4 -4
View File
@@ -10,11 +10,11 @@ void ScreenUnlockCelebrate::Init()
// We shouldn't be called if there aren't any unlocks to celebrate // We shouldn't be called if there aren't any unlocks to celebrate
ASSERT( UNLOCKMAN->AnyUnlocksToCelebrate() ); ASSERT( UNLOCKMAN->AnyUnlocksToCelebrate() );
ScreenUnlockBrowse::Init();
// Mark this unlock as celebrated // Mark this unlock as celebrated
int iIndex = UNLOCKMAN->GetUnlockIndexToCelebrate(); int iUnlockID = UNLOCKMAN->GetUnlockEntryIDToCelebrate();
UNLOCKMAN->m_UnlockEntries[iIndex].m_bCelebrated = true; UNLOCKMAN->UnlockEntryID( iUnlockID );
ScreenUnlockBrowse::Init();
} }
void ScreenUnlockCelebrate::MenuLeft( const InputEventPlus &input ) void ScreenUnlockCelebrate::MenuLeft( const InputEventPlus &input )
+24 -11
View File
@@ -290,15 +290,20 @@ bool UnlockEntry::IsValid() const
} }
} }
bool UnlockEntry::IsLocked() const bool UnlockEntry::IsRequirementMet() const
{ {
float fScores[NUM_UnlockRequirement]; float fScores[NUM_UnlockRequirement];
UNLOCKMAN->GetPoints( PROFILEMAN->GetMachineProfile(), fScores ); UNLOCKMAN->GetPoints( PROFILEMAN->GetMachineProfile(), fScores );
for( int i = 0; i < NUM_UnlockRequirement; ++i ) for( int i = 0; i < NUM_UnlockRequirement; ++i )
if( m_fRequirement[i] && fScores[i] >= m_fRequirement[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() ) if( m_iEntryID != -1 && PROFILEMAN->GetMachineProfile()->m_UnlockedEntryIDs.find(m_iEntryID) != PROFILEMAN->GetMachineProfile()->m_UnlockedEntryIDs.end() )
return false; return false;
@@ -427,10 +432,6 @@ void UnlockManager::Load()
if( bRoulette ) if( bRoulette )
m_RouletteCodes.insert( current.m_iEntryID ); 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 // Make sure that we don't have duplicate unlock IDs. This can cause problems
// with UnlockCelebrate and with codes. // with UnlockCelebrate and with codes.
FOREACH_CONST( UnlockEntry, m_UnlockEntries, ue ) FOREACH_CONST( UnlockEntry, m_UnlockEntries, ue )
@@ -559,11 +560,21 @@ bool UnlockManager::AllAreLocked() const
return true; return true;
} }
int UnlockManager::GetUnlockIndexToCelebrate() const int UnlockManager::GetUnlockEntryIDToCelebrate() const
{ {
FOREACH_CONST( UnlockEntry, m_UnlockEntries, ue ) 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 ue - m_UnlockEntries.begin();
} }
return -1; return -1;
@@ -571,7 +582,7 @@ int UnlockManager::GetUnlockIndexToCelebrate() const
bool UnlockManager::AnyUnlocksToCelebrate() const bool UnlockManager::AnyUnlocksToCelebrate() const
{ {
return GetUnlockIndexToCelebrate() != -1; return GetUnlockEntryIDToCelebrate() != -1;
} }
void UnlockManager::GetUnlocksByType( UnlockRewardType t, vector<UnlockEntry *> &apEntries ) void UnlockManager::GetUnlocksByType( UnlockRewardType t, vector<UnlockEntry *> &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 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 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 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 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 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 ) static int GetSongsUnlockedByEntryID( T* p, lua_State *L )
@@ -672,7 +684,8 @@ public:
ADD_METHOD( PreferUnlockEntryID ); ADD_METHOD( PreferUnlockEntryID );
ADD_METHOD( GetNumUnlocks ); ADD_METHOD( GetNumUnlocks );
ADD_METHOD( AllAreLocked ); ADD_METHOD( AllAreLocked );
ADD_METHOD( GetUnlockIndexToCelebrate ); ADD_METHOD( GetUnlockEntryIDToCelebrate );
ADD_METHOD( GetUnlockEntryIndexToCelebrate );
ADD_METHOD( AnyUnlocksToCelebrate ); ADD_METHOD( AnyUnlocksToCelebrate );
ADD_METHOD( GetUnlockEntry ); ADD_METHOD( GetUnlockEntry );
ADD_METHOD( GetSongsUnlockedByEntryID ); ADD_METHOD( GetSongsUnlockedByEntryID );
+3 -3
View File
@@ -53,7 +53,6 @@ public:
ZERO( m_fRequirement ); ZERO( m_fRequirement );
m_iEntryID = -1; m_iEntryID = -1;
m_bCelebrated = false;
} }
UnlockRewardType m_Type; UnlockRewardType m_Type;
@@ -67,9 +66,9 @@ public:
float m_fRequirement[NUM_UnlockRequirement]; float m_fRequirement[NUM_UnlockRequirement];
int m_iEntryID; int m_iEntryID;
bool m_bCelebrated;
bool IsValid() const; bool IsValid() const;
bool IsRequirementMet() const;
bool IsLocked() const; bool IsLocked() const;
RString GetModifier() const { return m_cmd.GetArg(1).s; } RString GetModifier() const { return m_cmd.GetArg(1).s; }
RString GetDescription() const; RString GetDescription() const;
@@ -103,7 +102,8 @@ public:
// Gets number of unlocks for title screen // Gets number of unlocks for title screen
int GetNumUnlocks() const; int GetNumUnlocks() const;
bool AllAreLocked() const; bool AllAreLocked() const;
int GetUnlockIndexToCelebrate() const; int GetUnlockEntryIDToCelebrate() const;
int GetUnlockEntryIndexToCelebrate() const;
bool AnyUnlocksToCelebrate() const; bool AnyUnlocksToCelebrate() const;
void GetPoints( const Profile *pProfile, float fScores[NUM_UnlockRequirement] ) const; void GetPoints( const Profile *pProfile, float fScores[NUM_UnlockRequirement] ) const;