Skip to content

Commit

Permalink
Merge pull request scp-fs2open#5879 from JohnAFernandez/Fix-Player-Me…
Browse files Browse the repository at this point in the history
…nu-Smarter

QOL: Don't reset the position in the player list if we switch modes
  • Loading branch information
JohnAFernandez committed Dec 11, 2023
2 parents 252392b + cd95b14 commit 36e7598
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 35 deletions.
75 changes: 40 additions & 35 deletions code/menuui/playermenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ char Player_select_very_first_pilot_callsign[CALLSIGN_LEN + 2];

extern int Main_hall_bitmap; // bitmap handle to the main hall bitmap

int Player_select_mode; // single or multiplayer - never set directly. use player_select_init_player_stuff()
int Player_select_mode = PLAYER_SELECT_UNINITED; // single or multiplayer - never set directly. use player_select_init_player_stuff()
int Player_select_num_pilots; // # of pilots on the list
int Player_select_list_start; // index of first list item to start displaying in the box
int Player_select_pilot; // index into the Pilot array of which is selected as the active pilot
Expand Down Expand Up @@ -952,52 +952,57 @@ int player_select_get_last_pilot()

void player_select_init_player_stuff(int mode)
{
Player_select_list_start = 0;
// If we did not change mode, then we need to initialize the data.
bool initializing = Player_select_mode == PLAYER_SELECT_UNINITED;

// set the select mode to single player for default
Player_select_mode = mode;

auto pilots = player_select_enumerate_pilots();
// Copy the enumerated pilots into the appropriate local variables
Player_select_num_pilots = static_cast<int>(pilots.size());
for (auto i = 0; i < MAX_PILOTS; ++i) {
if (i < static_cast<int>(pilots.size())) {
strcpy_s(Pilots_arr[i], pilots[i].c_str());
}
Pilots[i] = Pilots_arr[i];
}
if (initializing){
Player_select_list_start = 0;

// if we have a "last_player", and they're in the list, bash them to the top of the list
if (Player_select_last_pilot[0] != '\0') {
int i,j;
for (i = 0; i < Player_select_num_pilots; ++i) {
if (!stricmp(Player_select_last_pilot,Pilots[i])) {
break;
auto pilots = player_select_enumerate_pilots();
// Copy the enumerated pilots into the appropriate local variables
Player_select_num_pilots = static_cast<int>(pilots.size());
for (auto i = 0; i < MAX_PILOTS; ++i) {
if (i < static_cast<int>(pilots.size())) {
strcpy_s(Pilots_arr[i], pilots[i].c_str());
}
Pilots[i] = Pilots_arr[i];
}
if (i != Player_select_num_pilots) {
for (j = i; j > 0; --j) {
strncpy(Pilots[j], Pilots[j-1], strlen(Pilots[j-1])+1);

// if we have a "last_player", and they're in the list, bash them to the top of the list
if (Player_select_last_pilot[0] != '\0') {
int i,j;
for (i = 0; i < Player_select_num_pilots; ++i) {
if (!stricmp(Player_select_last_pilot,Pilots[i])) {
break;
}
}
if (i != Player_select_num_pilots) {
for (j = i; j > 0; --j) {
strncpy(Pilots[j], Pilots[j-1], strlen(Pilots[j-1])+1);
}
strncpy(Pilots[0], Player_select_last_pilot, strlen(Player_select_last_pilot)+1);
}
strncpy(Pilots[0], Player_select_last_pilot, strlen(Player_select_last_pilot)+1);
}
}

Player = NULL;
Player = NULL;

// if this value is -1, it means we should set it to the num pilots count
if (Player_select_initial_count == -1) {
Player_select_initial_count = Player_select_num_pilots;
}
// if this value is -1, it means we should set it to the num pilots count
if (Player_select_initial_count == -1) {
Player_select_initial_count = Player_select_num_pilots;
}

// select the first pilot if any exist, otherwise set to -1
if (Player_select_num_pilots == 0) {
Player_select_pilot = -1;
player_select_set_middle_text(XSTR( "Type Callsign and Press Enter", 381));
player_select_set_controls(1); // gray out the controls
player_select_create_new_pilot();
} else {
Player_select_pilot = 0;
// select the first pilot if any exist, otherwise set to -1
if (Player_select_num_pilots == 0) {
Player_select_pilot = -1;
player_select_set_middle_text(XSTR( "Type Callsign and Press Enter", 381));
player_select_set_controls(1); // gray out the controls
player_select_create_new_pilot();
} else {
Player_select_pilot = 0;
}
}
}

Expand Down
1 change: 1 addition & 0 deletions code/menuui/playermenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "globalincs/pstypes.h"

// general defines
#define PLAYER_SELECT_UNINITED -1 // Used only on program start
#define PLAYER_SELECT_MODE_SINGLE 0 // looking through single player pilots
#define PLAYER_SELECT_MODE_MULTI 1 // looking through multi player pilots

Expand Down

0 comments on commit 36e7598

Please sign in to comment.