@@ -829,6 +829,51 @@ void MultiplayerScreen::MousePressed(MouseButton button)
829
829
lua_settop (m_lua, 0 );
830
830
}
831
831
832
+ bool MultiplayerScreen::m_returnToMainList ()
833
+ {
834
+ if (m_screenState == MultiplayerScreenState::ROOM_LIST)
835
+ return false ;
836
+
837
+ // Exiting from name setup
838
+ if (m_userName == " " )
839
+ {
840
+ m_suspended = true ;
841
+ g_application->RemoveTickable (this );
842
+ return true ;
843
+ }
844
+
845
+ if (m_screenState == MultiplayerScreenState::IN_ROOM)
846
+ {
847
+ nlohmann::json packet;
848
+ packet[" topic" ] = " room.leave" ;
849
+ m_tcp.SendJSON (packet);
850
+ }
851
+ else
852
+ {
853
+ nlohmann::json packet;
854
+ packet[" topic" ] = " server.rooms" ;
855
+ m_tcp.SendJSON (packet);
856
+ }
857
+
858
+ if (m_textInput->active )
859
+ m_textInput->SetActive (false );
860
+
861
+ if (m_screenState == MultiplayerScreenState::IN_ROOM) {
862
+ m_chatOverlay->AddMessage (" You left the lobby" , 207 , 178 , 41 );
863
+ }
864
+
865
+ m_chatOverlay->EnableOpeningChat ();
866
+
867
+ m_screenState = MultiplayerScreenState::ROOM_LIST;
868
+ m_stopPreview ();
869
+ lua_pushstring (m_lua, " roomList" );
870
+ lua_setglobal (m_lua, " screenState" );
871
+ g_application->DiscordPresenceMulti (" " , 0 , 0 , " " );
872
+ m_roomId = " " ;
873
+ m_hasSelectedMap = false ;
874
+ return true ;
875
+ }
876
+
832
877
void MultiplayerScreen::Tick (float deltaTime)
833
878
{
834
879
// Tick the tcp socket even if we are suspended
@@ -1065,43 +1110,23 @@ void MultiplayerScreen::OnKeyPressed(SDL_Scancode code)
1065
1110
}
1066
1111
else if (code == SDL_SCANCODE_ESCAPE)
1067
1112
{
1068
- if (m_screenState != MultiplayerScreenState::ROOM_LIST)
1069
- {
1070
-
1071
- // Exiting from name setup
1072
- if (m_userName == " " )
1073
- {
1074
- m_suspended = true ;
1075
- g_application->RemoveTickable (this );
1076
- return ;
1077
- }
1113
+ int backScancode = g_gameConfig.GetInt (GameConfigKeys::Key_Back);
1114
+ // SDL_Keycode k = SDL_GetKeyFromScancode(g_gameConfig.GetInt(GameConfigKeys::Key_Back));
1078
1115
1079
- if (m_screenState == MultiplayerScreenState::IN_ROOM)
1080
- {
1081
- nlohmann::json packet;
1082
- packet[" topic" ] = " room.leave" ;
1083
- m_tcp.SendJSON (packet);
1084
- }
1085
- else
1116
+ if (g_gameConfig.GetEnum <Enum_InputDevice>(GameConfigKeys::ButtonInputDevice) != InputDevice::Keyboard
1117
+ || backScancode != SDL_SCANCODE_ESCAPE)
1118
+ {
1119
+ switch (m_screenState)
1086
1120
{
1087
- nlohmann::json packet;
1088
- packet[" topic" ] = " server.rooms" ;
1089
- m_tcp.SendJSON (packet);
1121
+ // Escape works for text editing
1122
+ case MultiplayerScreenState::JOIN_PASSWORD:
1123
+ case MultiplayerScreenState::NEW_ROOM_NAME:
1124
+ case MultiplayerScreenState::NEW_ROOM_PASSWORD:
1125
+ case MultiplayerScreenState::SET_USERNAME:
1126
+ m_returnToMainList ();
1127
+ default :
1128
+ break ;
1090
1129
}
1091
-
1092
- if (m_textInput->active )
1093
- m_textInput->SetActive (false );
1094
-
1095
- m_chatOverlay->AddMessage (" You left the lobby" , 207 , 178 , 41 );
1096
- m_chatOverlay->EnableOpeningChat ();
1097
-
1098
- m_screenState = MultiplayerScreenState::ROOM_LIST;
1099
- m_stopPreview ();
1100
- lua_pushstring (m_lua, " roomList" );
1101
- lua_setglobal (m_lua, " screenState" );
1102
- g_application->DiscordPresenceMulti (" " , 0 , 0 , " " );
1103
- m_roomId = " " ;
1104
- m_hasSelectedMap = false ;
1105
1130
}
1106
1131
}
1107
1132
else if (code == SDL_SCANCODE_RETURN)
@@ -1147,8 +1172,15 @@ void MultiplayerScreen::m_OnButtonPressed(Input::Button buttonCode)
1147
1172
if (IsSuspended () || m_settDiag.IsActive ())
1148
1173
return ;
1149
1174
1150
- if (g_gameConfig.GetEnum <Enum_InputDevice>(GameConfigKeys::ButtonInputDevice) == InputDevice::Keyboard && (m_textInput->active || m_chatOverlay->IsOpen ()))
1151
- return ;
1175
+ if (g_gameConfig.GetEnum <Enum_InputDevice>(GameConfigKeys::ButtonInputDevice) == InputDevice::Keyboard)
1176
+ {
1177
+ if (m_chatOverlay->IsOpen ())
1178
+ return ;
1179
+
1180
+ // Allow Button Back while text editing
1181
+ if (m_textInput->active && buttonCode != Input::Button ::Back)
1182
+ return ;
1183
+ }
1152
1184
1153
1185
m_timeSinceButtonPressed[buttonCode] = 0 ;
1154
1186
@@ -1170,6 +1202,9 @@ void MultiplayerScreen::m_OnButtonPressed(Input::Button buttonCode)
1170
1202
return ;
1171
1203
}
1172
1204
break ;
1205
+ case Input::Button ::Back:
1206
+ if (m_returnToMainList ())
1207
+ return ;
1173
1208
default :
1174
1209
break ;
1175
1210
}
0 commit comments