Skip to content

Commit

Permalink
reduce jumpiness when navigating from main menu to main menu
Browse files Browse the repository at this point in the history
  • Loading branch information
BenLubar committed Oct 10, 2023
1 parent a5ba4ae commit 7c5cce6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
34 changes: 27 additions & 7 deletions src/game/client/swarm/gameui/swarm/vmainmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ const char *( *const wine_get_version )( void ) = static_cast< const char *( * )
#endif

static bool s_bMainMenuShown = false;
static uint16_t s_iLastQuickJoinPublicVisible = 0;
static uint16_t s_iLastQuickJoinFriendsVisible = 0;
static int s_nHoIAFCachedEntries = 0;
static LeaderboardEntry_t s_HoIAFLeaderboardEntryCache[10];
static LeaderboardScoreDetails_Points_t s_HoIAFLeaderboardDetailsCache[10];

//=============================================================================
MainMenu::MainMenu( Panel *parent, const char *panelName ):
Expand Down Expand Up @@ -321,8 +326,19 @@ void MainMenu::Activate()
}

ISteamUserStats *pUserStats = SteamUserStats();
if ( pUserStats && rd_hoiaf_leaderboard_on_main_menu.GetBool() )
if ( pUserStats && !m_bIsLegacy && rd_hoiaf_leaderboard_on_main_menu.GetBool() )
{
for ( int i = 0; i < s_nHoIAFCachedEntries; i++ )
{
m_pTopLeaderboardEntries[i]->SetFromEntry( s_HoIAFLeaderboardEntryCache[i], s_HoIAFLeaderboardDetailsCache[i] );
m_pTopLeaderboardEntries[i]->SetVisible( true );
}

for ( int i = s_nHoIAFCachedEntries; i < NELEMS( m_pTopLeaderboardEntries ); i++ )
{
m_pTopLeaderboardEntries[i]->SetVisible( false );
}

SteamAPICall_t hCall = pUserStats->DownloadLeaderboardEntries( STEAM_LEADERBOARD_HOIAF_CURRENT_SEASON, rd_hoiaf_leaderboard_friends_only.GetBool() ? k_ELeaderboardDataRequestFriends : k_ELeaderboardDataRequestGlobal, 1, 10 );
m_HoIAFTop10Callback.Set( hCall, this, &MainMenu::OnHoIAFTop10ScoresDownloaded );
}
Expand Down Expand Up @@ -1509,6 +1525,9 @@ void MainMenu::OnThink()
m_InactiveHideQuickJoinPublic.Update( m_pPnlQuickJoinPublic->IsVisible() );
m_InactiveHideQuickJoinFriends.Update( m_pPnlQuickJoin->IsVisible() );

s_iLastQuickJoinPublicVisible = m_InactiveHideQuickJoinPublic.m_iGlow;
s_iLastQuickJoinFriendsVisible = m_InactiveHideQuickJoinFriends.m_iGlow;

uint16 iSlideState = m_iInactiveHideMainMenu;
m_pBranchDisclaimer->SetAlpha( RemapValClamped( iSlideState, 32768, 65535, 0, 255 ) );

Expand Down Expand Up @@ -1638,6 +1657,8 @@ void MainMenu::OnOpen()
}

m_iInactiveHideMainMenu = s_bMainMenuShown ? 65535 : 0;
m_InactiveHideQuickJoinPublic.m_iGlow = s_iLastQuickJoinPublicVisible;
m_InactiveHideQuickJoinFriends.m_iGlow = s_iLastQuickJoinFriendsVisible;
if ( s_bMainMenuShown )
m_flLastActiveTime = Plat_FloatTime();

Expand Down Expand Up @@ -2017,23 +2038,22 @@ void MainMenu::MaybeShowTooltip( vgui::Panel *pPanel, const char *szTitle, const

void MainMenu::OnHoIAFTop10ScoresDownloaded( LeaderboardScoresDownloaded_t *pParam, bool bIOFailure )
{
s_nHoIAFCachedEntries = 0;
for ( int i = 0; i < NELEMS( m_pTopLeaderboardEntries ); i++ )
{
m_pTopLeaderboardEntries[i]->ClearData();
m_pTopLeaderboardEntries[i]->SetVisible( false );
}

if ( !bIOFailure && !m_bIsStub )
{
s_nHoIAFCachedEntries = MIN( pParam->m_cEntryCount, NELEMS( m_pTopLeaderboardEntries ) );
for ( int i = 0; i < pParam->m_cEntryCount && i < NELEMS( m_pTopLeaderboardEntries ); i++ )
{
LeaderboardEntry_t entry;
LeaderboardScoreDetails_Points_t details;
bool bOK = SteamUserStats()->GetDownloadedLeaderboardEntry( pParam->m_hSteamLeaderboardEntries, i, &entry, reinterpret_cast< int32 * >( &details ), sizeof( details ) / sizeof( int32 ) );
bool bOK = SteamUserStats()->GetDownloadedLeaderboardEntry( pParam->m_hSteamLeaderboardEntries, i, &s_HoIAFLeaderboardEntryCache[i], reinterpret_cast< int32 * >( &s_HoIAFLeaderboardDetailsCache[i] ), sizeof( s_HoIAFLeaderboardDetailsCache[i] ) / sizeof( int32 ) );
Assert( bOK );
Assert( entry.m_cDetails == sizeof( details ) / sizeof( int32 ) );
Assert( s_HoIAFLeaderboardEntryCache[i].m_cDetails == sizeof( s_HoIAFLeaderboardDetailsCache[i] ) / sizeof( int32 ) );

m_pTopLeaderboardEntries[i]->SetFromEntry( entry, details );
m_pTopLeaderboardEntries[i]->SetFromEntry( s_HoIAFLeaderboardEntryCache[i], s_HoIAFLeaderboardDetailsCache[i] );
m_pTopLeaderboardEntries[i]->SetVisible( !m_bIsLegacy );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ void CRD_VGUI_Main_Menu_HoIAF_Leaderboard_Entry::SetFromEntry( const Leaderboard
g_pVGuiLocalize->ConstructString( wszRankNumber, sizeof( wszRankNumber ), g_pVGuiLocalize->Find( "#rd_main_menu_hoiaf_place_number" ), 1, UTIL_RD_CommaNumber( entry.m_nGlobalRank ) );
m_pLblRankNumber->SetText( wszRankNumber );
m_pLblScore->SetText( UTIL_RD_CommaNumber( entry.m_nScore ) );

InvalidateLayout();
}

void CRD_VGUI_Main_Menu_HoIAF_Leaderboard_Entry::ClearData()
Expand All @@ -100,6 +102,8 @@ void CRD_VGUI_Main_Menu_HoIAF_Leaderboard_Entry::ClearData()
m_pAvatar->SetAvatarBySteamID( NULL );
m_pLblRankNumber->SetText( L"" );
m_pLblScore->SetText( L"" );

InvalidateLayout();
}

CRD_VGUI_Main_Menu_HoIAF_Leaderboard_Entry_Large::CRD_VGUI_Main_Menu_HoIAF_Leaderboard_Entry_Large( vgui::Panel *parent, const char *panelName, vgui::Panel *pActionSignalTarget, const char *pCmd ) :
Expand Down
6 changes: 5 additions & 1 deletion src/game/client/swarm/vgui/tabbedgriddetails.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,8 +592,12 @@ TGD_Grid::~TGD_Grid()

void TGD_Grid::ApplySchemeSettings( vgui::IScheme *pScheme )
{
bool bWasVisible = IsVisible();

LoadControlSettings( m_pScrollBar ? "Resource/UI/TGD_Grid.res" : "Resource/UI/CGD_Grid.res" );

SetVisible( bWasVisible );

BaseClass::ApplySchemeSettings( pScheme );

if ( m_pScrollBar )
Expand Down Expand Up @@ -710,7 +714,7 @@ void TGD_Grid::PerformLayout()
}
}

if ( !bAnyFocus && ( m_pScrollBar || m_pParent->m_pParent->m_hCurrentTab.Get() == m_pParent ) )
if ( !bAnyFocus && m_pParent->m_pParent->m_hCurrentTab.Get() == m_pParent )
{
if ( m_Entries.Count() > m_iLastFocus )
{
Expand Down

0 comments on commit 7c5cce6

Please sign in to comment.