1 // SuperTuxKart - a fun racing game with go-kart 2 // Copyright (C) 2013-2015 Glenn De Jonghe 3 // 4 // This program is free software; you can redistribute it and/or 5 // modify it under the terms of the GNU General Public License 6 // as published by the Free Software Foundation; either version 3 7 // of the License, or (at your option) any later version. 8 // 9 // This program is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with this program; if not, write to the Free Software 16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 18 #ifndef HEADER_NETWORKING_LOBBY_HPP 19 #define HEADER_NETWORKING_LOBBY_HPP 20 21 #include "guiengine/screen.hpp" 22 #include "guiengine/widgets/text_box_widget.hpp" 23 #include "GlyphLayout.h" 24 #include <map> 25 #include <memory> 26 #include <utility> 27 28 class Addon; 29 class InputDevice; 30 class Server; 31 enum KartTeam : int8_t; 32 struct LobbyPlayer; 33 34 namespace GUIEngine 35 { 36 class ButtonWidget; 37 class LabelWidget; 38 class ListWidget; 39 class IconButtonWidget; 40 class TextBoxWidget; 41 } 42 43 namespace irr 44 { 45 namespace gui 46 { 47 class STKModifiedSpriteBank; 48 } 49 } 50 51 /** 52 * \brief Handles the networking lobby 53 * \ingroup states_screens 54 */ 55 class NetworkingLobby : public GUIEngine::Screen, 56 public GUIEngine::ScreenSingleton<NetworkingLobby>, 57 public GUIEngine::ITextBoxWidgetListener 58 { 59 private: 60 enum LobbyState 61 { 62 LS_ADD_PLAYERS, 63 LS_CONNECTING 64 } m_state; 65 66 friend class GUIEngine::ScreenSingleton<NetworkingLobby>; 67 68 NetworkingLobby(); 69 70 uint64_t m_ping_update_timer; 71 std::map<std::string, LobbyPlayer> m_player_names; 72 std::shared_ptr<Server> m_joined_server; 73 74 std::vector<gui::GlyphLayout> m_server_info; 75 int m_server_info_height; 76 77 core::stringw m_start_text, m_ready_text, m_live_join_text, 78 m_configuration_text, m_spectate_text, m_install_addon_text; 79 80 float m_start_timeout; 81 int64_t m_cur_starting_timer; 82 unsigned m_min_start_game_players; 83 84 bool m_allow_change_team, m_has_auto_start_in_server, 85 m_server_configurable, m_client_live_joinable, 86 m_reload_server_info; 87 88 Addon* m_addon_install; 89 video::ITexture* m_config_texture; 90 video::ITexture* m_spectate_texture; 91 video::ITexture* m_addon_texture; 92 93 GUIEngine::IconButtonWidget* m_back_widget; 94 GUIEngine::LabelWidget* m_header; 95 GUIEngine::LabelWidget* m_text_bubble; 96 GUIEngine::LabelWidget* m_timeout_message; 97 GUIEngine::IconButtonWidget* m_start_button; 98 GUIEngine::IconButtonWidget* m_config_button; 99 GUIEngine::ListWidget* m_player_list; 100 GUIEngine::TextBoxWidget* m_chat_box; 101 GUIEngine::ButtonWidget* m_send_button; 102 GUIEngine::ButtonWidget* m_emoji_button; 103 104 irr::gui::STKModifiedSpriteBank* m_icon_bank; 105 106 /** \brief implement optional callback from parent class GUIEngine::Screen */ 107 virtual void unloaded() OVERRIDE; 108 onTextUpdated()109 virtual void onTextUpdated() OVERRIDE {} 110 virtual bool onEnterPressed(const irr::core::stringw& text) OVERRIDE; 111 void updatePlayerPings(); 112 113 public: 114 115 virtual void onUpdate(float delta) OVERRIDE; 116 117 /** \brief implement callback from parent class GUIEngine::Screen */ 118 virtual void loadedFromFile() OVERRIDE; 119 120 /** \brief implement callback from parent class GUIEngine::Screen */ 121 virtual void eventCallback(GUIEngine::Widget* widget, const std::string& name, 122 const int playerID) OVERRIDE; 123 124 /** \brief implement callback from parent class GUIEngine::Screen */ 125 virtual void beforeAddingWidget() OVERRIDE; 126 127 /** \brief implement callback from parent class GUIEngine::Screen */ 128 virtual void init() OVERRIDE; 129 130 /** \brief implement callback from parent class GUIEngine::Screen */ 131 virtual void tearDown() OVERRIDE; 132 133 /** \brief implement callback from parent class GUIEngine::Screen */ 134 virtual bool onEscapePressed() OVERRIDE; 135 136 void finishAddingPlayers(); 137 void addMoreServerInfo(core::stringw info); setJoinedServer(std::shared_ptr<Server> server)138 void setJoinedServer(std::shared_ptr<Server> server) 139 { 140 m_joined_server = server; 141 m_server_info.clear(); 142 } 143 void updateServerInfos(); 144 void updatePlayers(); 145 void openSplitscreenDialog(InputDevice* device); 146 void addSplitscreenPlayer(irr::core::stringw name); 147 void cleanAddedPlayers(); 148 void initAutoStartTimer(bool grand_prix_started, unsigned min_players, 149 float start_timeout, unsigned server_max_player); 150 void setStartingTimerTo(float t); toggleServerConfigButton(bool val)151 void toggleServerConfigButton(bool val) { m_server_configurable = val; } reloadServerInfos()152 void reloadServerInfos() { m_reload_server_info = true; } 153 }; // class NetworkingLobby 154 155 #endif 156