Skip to content

Commit 0b1d1ee

Browse files
authored
Merge pull request #3357 from notimaginative/fix_briefing_music_reset
Only close common_select when we should
2 parents 123feba + 3e1d89b commit 0b1d1ee

File tree

1 file changed

+80
-53
lines changed

1 file changed

+80
-53
lines changed

freespace2/freespace.cpp

Lines changed: 80 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -4954,6 +4954,40 @@ void game_process_event( int current_state, int event )
49544954
}
49554955
}
49564956

4957+
static bool going_to_briefing_state(int new_state)
4958+
{
4959+
switch (new_state) {
4960+
case GS_STATE_TEAM_SELECT:
4961+
case GS_STATE_SHIP_SELECT:
4962+
case GS_STATE_WEAPON_SELECT:
4963+
case GS_STATE_OPTIONS_MENU:
4964+
case GS_STATE_GAMEPLAY_HELP:
4965+
case GS_STATE_HOTKEY_SCREEN:
4966+
case GS_STATE_MULTI_MISSION_SYNC:
4967+
case GS_STATE_BRIEFING:
4968+
case GS_STATE_CMD_BRIEF:
4969+
case GS_STATE_RED_ALERT:
4970+
case GS_STATE_FICTION_VIEWER:
4971+
return true;
4972+
}
4973+
4974+
return false;
4975+
}
4976+
4977+
static bool going_to_menu_state(int new_state)
4978+
{
4979+
switch (new_state) {
4980+
case GS_STATE_MAIN_MENU:
4981+
case GS_STATE_PXO:
4982+
case GS_STATE_MULTI_JOIN_GAME:
4983+
case GS_STATE_STANDALONE_MAIN:
4984+
case GS_STATE_QUIT_GAME:
4985+
return true;
4986+
}
4987+
4988+
return false;
4989+
}
4990+
49574991
// Called when a state is being left.
49584992
// The current state is still at old_state, but as soon as
49594993
// this function leaves, then the current state will become
@@ -5002,17 +5036,15 @@ void game_leave_state( int old_state, int new_state )
50025036
switch (old_state) {
50035037
case GS_STATE_BRIEFING:
50045038
brief_stop_voices();
5005-
if ( (new_state != GS_STATE_OPTIONS_MENU) && (new_state != GS_STATE_WEAPON_SELECT)
5006-
&& (new_state != GS_STATE_SHIP_SELECT) && (new_state != GS_STATE_HOTKEY_SCREEN)
5007-
&& (new_state != GS_STATE_TEAM_SELECT) && (new_state != GS_STATE_MULTI_MISSION_SYNC)){
5039+
5040+
if ( !going_to_briefing_state(new_state) ) {
50085041
common_select_close();
5009-
if ( (new_state == GS_STATE_MAIN_MENU) || (new_state == GS_STATE_PXO)
5010-
|| (new_state == GS_STATE_MULTI_JOIN_GAME) )
5011-
{
5012-
freespace_stop_mission();
5042+
5043+
if ( going_to_menu_state(new_state) ) {
5044+
freespace_stop_mission();
50135045
}
50145046
}
5015-
5047+
50165048
// COMMAND LINE OPTION
50175049
if (Cmdline_multi_stream_chat_to_file){
50185050
cfwrite_string(NOX("-------------------------------------------\n"),Multi_chat_stream);
@@ -5048,67 +5080,57 @@ void game_leave_state( int old_state, int new_state )
50485080
cmd_brief_hold();
50495081
} else {
50505082
cmd_brief_close();
5051-
common_select_close();
50525083

5053-
if (new_state != GS_STATE_BRIEFING) {
5054-
common_music_close();
5055-
}
5084+
if ( !going_to_briefing_state(new_state) ) {
5085+
common_select_close();
50565086

5057-
if ( (new_state == GS_STATE_MAIN_MENU) || (new_state == GS_STATE_PXO)
5058-
|| (new_state == GS_STATE_MULTI_JOIN_GAME) )
5059-
{
5060-
freespace_stop_mission();
5087+
if ( going_to_menu_state(new_state) ) {
5088+
freespace_stop_mission();
5089+
}
50615090
}
50625091
}
50635092
break;
50645093

50655094
case GS_STATE_RED_ALERT:
50665095
red_alert_close();
5067-
common_select_close();
5068-
if ( (new_state == GS_STATE_MAIN_MENU) || (new_state == GS_STATE_PXO)
5069-
|| (new_state == GS_STATE_MULTI_JOIN_GAME) )
5070-
{
5071-
freespace_stop_mission();
5096+
5097+
if ( !going_to_briefing_state(new_state) ) {
5098+
common_select_close();
5099+
5100+
if ( going_to_menu_state(new_state) ) {
5101+
freespace_stop_mission();
5102+
}
50725103
}
50735104
break;
50745105

50755106
case GS_STATE_SHIP_SELECT:
5076-
if ( new_state != GS_STATE_OPTIONS_MENU && new_state != GS_STATE_WEAPON_SELECT &&
5077-
new_state != GS_STATE_HOTKEY_SCREEN &&
5078-
new_state != GS_STATE_BRIEFING && new_state != GS_STATE_TEAM_SELECT && (new_state != GS_STATE_MULTI_MISSION_SYNC)) {
5107+
if ( !going_to_briefing_state(new_state) ) {
50795108
common_select_close();
5080-
if ( (new_state == GS_STATE_MAIN_MENU) || (new_state == GS_STATE_PXO)
5081-
|| (new_state == GS_STATE_MULTI_JOIN_GAME) )
5082-
{
5083-
freespace_stop_mission();
5109+
5110+
if ( going_to_menu_state(new_state) ) {
5111+
freespace_stop_mission();
50845112
}
50855113
}
50865114
break;
50875115

50885116
case GS_STATE_WEAPON_SELECT:
5089-
if ( new_state != GS_STATE_OPTIONS_MENU && new_state != GS_STATE_SHIP_SELECT &&
5090-
new_state != GS_STATE_HOTKEY_SCREEN &&
5091-
new_state != GS_STATE_BRIEFING && new_state != GS_STATE_TEAM_SELECT && (new_state != GS_STATE_MULTI_MISSION_SYNC)) {
5117+
if ( !going_to_briefing_state(new_state) ) {
50925118
common_select_close();
5093-
if ( (new_state == GS_STATE_MAIN_MENU) || (new_state == GS_STATE_PXO)
5094-
|| (new_state == GS_STATE_MULTI_JOIN_GAME) )
5095-
{
5096-
freespace_stop_mission();
5119+
5120+
if ( going_to_menu_state(new_state) ) {
5121+
freespace_stop_mission();
50975122
}
50985123
}
50995124
break;
51005125

51015126
case GS_STATE_TEAM_SELECT:
5102-
if ( new_state != GS_STATE_OPTIONS_MENU && new_state != GS_STATE_SHIP_SELECT &&
5103-
new_state != GS_STATE_HOTKEY_SCREEN &&
5104-
new_state != GS_STATE_BRIEFING && new_state != GS_STATE_WEAPON_SELECT && (new_state != GS_STATE_MULTI_MISSION_SYNC)) {
5127+
if ( !going_to_briefing_state(new_state) ) {
51055128
common_select_close();
5106-
if ( (new_state == GS_STATE_MAIN_MENU) || (new_state == GS_STATE_PXO)
5107-
|| (new_state == GS_STATE_MULTI_JOIN_GAME) )
5108-
{
5109-
freespace_stop_mission();
5129+
5130+
if ( going_to_menu_state(new_state) ) {
5131+
freespace_stop_mission();
51105132
}
5111-
}
5133+
}
51125134
break;
51135135

51145136
case GS_STATE_MAIN_MENU:
@@ -5122,6 +5144,12 @@ void game_leave_state( int old_state, int new_state )
51225144

51235145
options_menu_close();
51245146

5147+
// can't use going_to_briefing_state() here since it doesn't catch sub-optionmenu states
5148+
// it's basically just to catch the exit game button
5149+
if ( going_to_menu_state(new_state) ) {
5150+
common_select_close();
5151+
}
5152+
51255153
if (new_state != GS_STATE_CONTROL_CONFIG && new_state != GS_STATE_HUD_CONFIG) {
51265154
// unpause all sounds, since we could be headed back to the game
51275155
// only unpause if we're in-mission; we could also be in the main hall
@@ -5318,7 +5346,9 @@ void game_leave_state( int old_state, int new_state )
53185346
break;
53195347

53205348
case GS_STATE_MULTI_MISSION_SYNC:
5321-
common_select_close();
5349+
if ( !going_to_briefing_state(new_state) ) {
5350+
common_select_close();
5351+
}
53225352

53235353
// if we're moving into the options menu we don't need to do anything else
53245354
if(new_state == GS_STATE_OPTIONS_MENU){
@@ -5339,7 +5369,7 @@ void game_leave_state( int old_state, int new_state )
53395369
Game_mode |= GM_IN_MISSION;
53405370

53415371
// any other state needs to close out the mission, because we're not going in to gameplay.
5342-
} else if (new_state == GS_STATE_PXO || new_state == GS_STATE_MULTI_JOIN_GAME) {
5372+
} else if ( going_to_menu_state(new_state) ) {
53435373
freespace_stop_mission();
53445374
}
53455375

@@ -5396,16 +5426,13 @@ void game_leave_state( int old_state, int new_state )
53965426

53975427
case GS_STATE_FICTION_VIEWER:
53985428
fiction_viewer_close();
5399-
common_select_close();
54005429

5401-
if ( (new_state != GS_STATE_BRIEFING) && (new_state != GS_STATE_CMD_BRIEF) ) {
5402-
common_music_close();
5403-
}
5430+
if ( !going_to_briefing_state(new_state) ) {
5431+
common_select_close();
54045432

5405-
if ( (new_state == GS_STATE_MAIN_MENU) || (new_state == GS_STATE_PXO)
5406-
|| (new_state == GS_STATE_MULTI_JOIN_GAME) )
5407-
{
5408-
freespace_stop_mission();
5433+
if ( going_to_menu_state(new_state) ) {
5434+
freespace_stop_mission();
5435+
}
54095436
}
54105437
break;
54115438

0 commit comments

Comments
 (0)