SuperTuxKart
networking_lobby.hpp
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 InputDevice;
29 class Server;
30 enum KartTeam : int8_t;
31 struct LobbyPlayer;
32 
33 namespace GUIEngine
34 {
35  class ButtonWidget;
36  class LabelWidget;
37  class ListWidget;
38  class IconButtonWidget;
39  class TextBoxWidget;
40 }
41 
42 namespace irr
43 {
44  namespace gui
45  {
46  class STKModifiedSpriteBank;
47  }
48 }
49 
55  public GUIEngine::ScreenSingleton<NetworkingLobby>,
57 {
58 private:
59  enum LobbyState
60  {
61  LS_ADD_PLAYERS,
62  LS_CONNECTING
63  } m_state;
64 
66 
68 
69  uint64_t m_ping_update_timer;
70  std::map<std::string, LobbyPlayer> m_player_names;
71  std::shared_ptr<Server> m_joined_server;
72 
73  std::vector<gui::GlyphLayout> m_server_info;
74  int m_server_info_height;
75 
76  core::stringw m_start_text, m_ready_text, m_live_join_text,
77  m_configuration_text, m_spectate_text;
78 
79  float m_start_timeout;
80  int64_t m_cur_starting_timer;
81  unsigned m_min_start_game_players;
82 
83  bool m_allow_change_team, m_has_auto_start_in_server,
84  m_server_configurable, m_client_live_joinable,
85  m_reload_server_info, m_displayed_addon_install_cmd;
86 
87  video::ITexture* m_config_texture;
88  video::ITexture* m_spectate_texture;
89 
90  GUIEngine::IconButtonWidget* m_back_widget;
91  GUIEngine::LabelWidget* m_header;
92  GUIEngine::LabelWidget* m_text_bubble;
93  GUIEngine::LabelWidget* m_timeout_message;
94  GUIEngine::IconButtonWidget* m_start_button;
95  GUIEngine::IconButtonWidget* m_config_button;
96  GUIEngine::ListWidget* m_player_list;
97  GUIEngine::TextBoxWidget* m_chat_box;
98  GUIEngine::ButtonWidget* m_send_button;
99  GUIEngine::ButtonWidget* m_emoji_button;
100 
101  irr::gui::STKModifiedSpriteBank* m_icon_bank;
102 
104  virtual void unloaded() OVERRIDE;
105 
106  virtual void onTextUpdated() OVERRIDE {}
107  virtual bool onEnterPressed(const irr::core::stringw& text) OVERRIDE;
108  void updatePlayerPings();
109 
110 public:
111 
112  virtual void onUpdate(float delta) OVERRIDE;
113 
115  virtual void loadedFromFile() OVERRIDE;
116 
118  virtual void eventCallback(GUIEngine::Widget* widget, const std::string& name,
119  const int playerID) OVERRIDE;
120 
122  virtual void beforeAddingWidget() OVERRIDE;
123 
125  virtual void init() OVERRIDE;
126 
128  virtual void tearDown() OVERRIDE;
129 
131  virtual bool onEscapePressed() OVERRIDE;
132 
133  void finishAddingPlayers();
134  void addMoreServerInfo(core::stringw info);
135  void setJoinedServer(std::shared_ptr<Server> server)
136  {
137  m_joined_server = server;
138  m_server_info.clear();
139  }
140  void updateServerInfos();
141  void updatePlayers();
142  void openSplitscreenDialog(InputDevice* device);
143  void addSplitscreenPlayer(irr::core::stringw name);
144  void cleanAddedPlayers();
145  void initAutoStartTimer(bool grand_prix_started, unsigned min_players,
146  float start_timeout, unsigned server_max_player);
147  void setStartingTimerTo(float t);
148  void toggleServerConfigButton(bool val) { m_server_configurable = val; }
149  void reloadServerInfos() { m_reload_server_info = true; }
150 }; // class NetworkingLobby
151 
152 #endif
Definition: server.hpp:43
Contains all GUI engine related classes and functions.
Definition: abstract_state_manager.hpp:31
Definition: client_lobby.hpp:39
A text field widget.
Definition: text_box_widget.hpp:52
NetworkingLobby()
This is the lobby screen that is shown on all clients, but not on the server.
Definition: networking_lobby.cpp:73
Handles the networking lobby.
Definition: networking_lobby.hpp:54
A button widget with an icon and optionnaly a label beneath.
Definition: icon_button_widget.hpp:43
virtual void eventCallback(GUIEngine::Widget *widget, const std::string &name, const int playerID) OVERRIDE
implement callback from parent class GUIEngine::Screen
Definition: networking_lobby.cpp:618
virtual void onUpdate(float delta) OVERRIDE
optional callback you can override to be notified at every frame.
Definition: networking_lobby.cpp:296
base class for input devices
Definition: input_device.hpp:47
virtual void tearDown() OVERRIDE
implement callback from parent class GUIEngine::Screen
Definition: networking_lobby.cpp:702
A vertical list widget with text entries.
Definition: list_widget.hpp:49
virtual void beforeAddingWidget() OVERRIDE
implement callback from parent class GUIEngine::Screen
Definition: networking_lobby.cpp:153
A simple label widget.
Definition: label_widget.hpp:35
A text button widget.
Definition: button_widget.hpp:40
Represents a single GUI screen.
Definition: screen.hpp:94
Definition: text_box_widget.hpp:41
Declares a class to be a singleton.
Definition: screen.hpp:57
virtual void unloaded() OVERRIDE
implement optional callback from parent class GUIEngine::Screen
Definition: networking_lobby.cpp:695
virtual bool onEscapePressed() OVERRIDE
implement callback from parent class GUIEngine::Screen
Definition: networking_lobby.cpp:714
The nearly-abstract base of all widgets (not fully abstract since a bare Widget can be created for th...
Definition: widget.hpp:138
virtual void loadedFromFile() OVERRIDE
implement callback from parent class GUIEngine::Screen
Definition: networking_lobby.cpp:95
virtual void init() OVERRIDE
implement callback from parent class GUIEngine::Screen
Definition: networking_lobby.cpp:162