Skip to content

Commit f184997

Browse files
Goober5000claude
andauthored
fix ship select roster scroll-up getting stuck after list shrinks (scp-fs2open#7501)
After a drag-drop that consumed the last unit of a roster class, the active list could shrink while SS_active_list_start was non-zero, making items above the stuck offset (including default ships returned to the pool, such as Seth fighters) unreachable: the up-arrow handler short-circuits when size <= max_show without resetting the offset. - Clamp the preserved scroll offset in ss_synch_interface() against SS_active_list_size - MAX_ICONS_ON_SCREEN. - Harden common_scroll_down_pressed() to reset *start to 0 when the whole list fits on screen. Fixes scp-fs2open#6240 Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 880bfb1 commit f184997

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

code/missionui/missionscreencommon.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,8 +1060,13 @@ int common_scroll_up_pressed(int *start, int size, int max_show)
10601060
//
10611061
int common_scroll_down_pressed(int *start, int size, int max_show)
10621062
{
1063-
// check if we even need to scroll at all
1063+
// if the whole list fits on screen, the start offset must be 0;
1064+
// reset a stale non-zero offset so the up arrow doesn't get stuck
10641065
if ( size <= max_show ) {
1066+
if ( *start > 0 ) {
1067+
*start = 0;
1068+
return 1;
1069+
}
10651070
return 0;
10661071
}
10671072

code/missionui/missionshipchoice.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3307,9 +3307,17 @@ void ss_synch_interface()
33073307

33083308
init_active_list(); // build the list of pool ships
33093309

3310-
if ( old_list_start < SS_active_list_size ) {
3311-
SS_active_list_start = old_list_start;
3310+
// clamp the preserved scroll offset against the largest valid offset
3311+
// for the new list size, so the up arrow can still reach items at the
3312+
// top after a swap shrinks the active list (e.g., to <= MAX_ICONS_ON_SCREEN)
3313+
int max_start = SS_active_list_size - MAX_ICONS_ON_SCREEN;
3314+
if ( max_start < 0 ) {
3315+
max_start = 0;
33123316
}
3317+
if ( old_list_start > max_start ) {
3318+
old_list_start = max_start;
3319+
}
3320+
SS_active_list_start = old_list_start;
33133321

33143322
for ( i = 0; i < MAX_WSS_SLOTS; i++ ) {
33153323
slot = &Ss_wings[i/MAX_WING_SLOTS].ss_slots[i%MAX_WING_SLOTS];

0 commit comments

Comments
 (0)