Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef MULTIPLAYER_UI_HPP_INCLUDED
00016 #define MULTIPLAYER_UI_HPP_INCLUDED
00017
00018 #include "chat_events.hpp"
00019 #include "hotkeys.hpp"
00020 #include "network.hpp"
00021 #include "preferences_display.hpp"
00022 #include "widgets/label.hpp"
00023 #include "widgets/menu.hpp"
00024 #include "widgets/textbox.hpp"
00025
00026 #include <deque>
00027
00028 class display;
00029 class game_display;
00030 class config;
00031 class game_state;
00032
00033 namespace mp {
00034
00035 enum controller { CNTR_NETWORK = 0, CNTR_LOCAL, CNTR_COMPUTER, CNTR_EMPTY, CNTR_RESERVED, CNTR_LAST };
00036
00037 void check_response(network::connection res, const config& data);
00038
00039 void level_to_gamestate(config& level, game_state& state);
00040
00041 std::string get_color_string(int id);
00042
00043
00044 class chat
00045 {
00046 public:
00047 chat();
00048
00049 void add_message(const time_t& time, const std::string& user,
00050 const std::string& message);
00051
00052 void init_textbox(gui::textbox& textbox);
00053 void update_textbox(gui::textbox& textbox);
00054
00055 private:
00056 struct msg {
00057 msg(const time_t& time, const std::string& user, const std::string& message)
00058 : time(time), user(user), message(message) {};
00059 time_t time;
00060 std::string user;
00061 std::string message;
00062 };
00063 typedef std::deque<msg> msg_hist;
00064
00065 std::string format_message(const msg& message);
00066 SDL_Color color_message(const msg& message);
00067
00068 msg_hist message_history_;
00069 msg_hist::size_type last_update_;
00070 };
00071
00072
00073
00074
00075
00076 class ui : public gui::widget, private events::chat_handler, private font::floating_label_context
00077 {
00078 public:
00079 enum result { CONTINUE, JOIN, OBSERVE, CREATE, PREFERENCES, PLAY, QUIT };
00080
00081 ui(game_display& d, const std::string& title,
00082 const config& cfg, chat& c, config& gamelist);
00083
00084
00085
00086
00087
00088
00089 void process_network();
00090
00091
00092
00093
00094
00095 result get_result();
00096
00097
00098
00099
00100
00101
00102
00103 void set_location(const SDL_Rect& rect);
00104 using widget::set_location;
00105
00106 protected:
00107 int xscale(int x) const;
00108 int yscale(int y) const;
00109 static const int xscale_base;
00110 static const int yscale_base;
00111
00112 SDL_Rect client_area() const;
00113
00114 game_display& disp_;
00115 game_display& disp() { return disp_; };
00116
00117
00118
00119
00120
00121
00122 const config& game_config() const;
00123
00124 virtual void draw_contents();
00125
00126 virtual void process_event();
00127
00128 virtual void handle_event(const SDL_Event& event);
00129 virtual void handle_key_event(const SDL_KeyboardEvent& event);
00130
00131
00132 void add_chat_message(const time_t& time, const std::string& speaker,
00133 int side, const std::string& message,
00134 events::chat_handler::MESSAGE_TYPE type=events::chat_handler::MESSAGE_PRIVATE);
00135 void send_chat_message(const std::string& message, bool allies_only=false);
00136
00137
00138 void process_message(const config& msg, const bool whisper=false);
00139
00140
00141
00142
00143
00144
00145 virtual void process_network_data(const config& data, const network::connection sock);
00146
00147
00148
00149
00150
00151 virtual void process_network_error(network::error& error);
00152
00153
00154
00155
00156
00157 virtual bool accept_connections() { return false; };
00158
00159
00160 virtual void process_network_connection(const network::connection sock);
00161
00162
00163
00164
00165
00166 virtual void hide_children(bool hide=true);
00167
00168
00169
00170
00171
00172 virtual void layout_children(const SDL_Rect& rect);
00173
00174
00175 result set_result(result res);
00176
00177
00178
00179
00180
00181 void set_selected_game(const std::string& game_name);
00182
00183
00184
00185
00186
00187 virtual void gamelist_updated(bool silent=true);
00188
00189
00190 void set_user_list(const std::vector<std::string>&, bool silent);
00191 void set_user_menu_items(const std::vector<std::string>& list);
00192
00193
00194 config& gamelist() { return gamelist_; };
00195
00196 void append_to_title(const std::string& name);
00197 const gui::label& title() const;
00198
00199 std::string get_selected_user_game();
00200 bool selected_user_changed() const { return selected_user_changed_; }
00201 void set_selected_user_changed(const bool& changed) { selected_user_changed_ = changed; }
00202
00203 private:
00204
00205
00206
00207
00208 bool initialized_;
00209 bool gamelist_initialized_;
00210
00211
00212 const hotkey::basic_handler hotkey_handler_;
00213
00214 const preferences::display_manager disp_manager_;
00215
00216
00217
00218
00219
00220 const config& game_config_;
00221
00222 chat& chat_;
00223
00224 config& gamelist_;
00225
00226 gui::label title_;
00227 gui::textbox entry_textbox_;
00228 gui::textbox chat_textbox_;
00229
00230 gui::menu users_menu_;
00231
00232 std::vector<std::string> user_list_;
00233
00234 std::string selected_game_;
00235
00236 std::string selected_user_;
00237 bool selected_user_changed_;
00238
00239 result result_;
00240
00241 bool gamelist_refresh_;
00242
00243 Uint32 lobby_clock_;
00244
00245 public:
00246 enum user_relation { ME, FRIEND, NEUTRAL, IGNORED };
00247 enum user_state { LOBBY, GAME, SEL_GAME };
00248
00249 private:
00250 struct user_info
00251 {
00252 user_info() :
00253 name(),
00254 game_id(),
00255 location(),
00256 relation(ME),
00257 state(LOBBY),
00258 registered()
00259 {
00260 }
00261
00262 std::string name;
00263 std::string game_id;
00264 std::string location;
00265 user_relation relation;
00266 user_state state;
00267
00268 bool registered;
00269 bool operator> (const user_info& b) const;
00270 };
00271 };
00272
00273 typedef std::vector<const config *> faction_list;
00274
00275 int find_suitable_faction(faction_list const &fl, const config &side);
00276
00277 }
00278
00279 #endif