00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef GUI_DIALOGS_LOBBY_HPP_INCLUDED
00017 #define GUI_DIALOGS_LOBBY_HPP_INCLUDED
00018
00019 #include "gui/dialogs/dialog.hpp"
00020 #include "gui/widgets/tree_view.hpp"
00021 #include "chat_events.hpp"
00022 #include "gui/dialogs/lobby/lobby_info.hpp"
00023
00024 #include <boost/scoped_ptr.hpp>
00025
00026 class display;
00027
00028 #ifdef GUI2_EXPERIMENTAL_LISTBOX
00029 #include "gui/widgets/list.hpp"
00030 #endif
00031 namespace gui2 {
00032
00033 class tgrid;
00034 class tlabel;
00035 #ifndef GUI2_EXPERIMENTAL_LISTBOX
00036 class tlistbox;
00037 #endif
00038 class ttext_box;
00039 class twindow;
00040 class tmulti_page;
00041 class ttoggle_button;
00042
00043 struct tlobby_chat_window
00044 {
00045 tlobby_chat_window(const std::string& name, bool whisper)
00046 : name(name), whisper(whisper), pending_messages(0)
00047 {
00048 }
00049 std::string name;
00050 bool whisper;
00051 int pending_messages;
00052 };
00053
00054 struct tplayer_list;
00055
00056 struct tsub_player_list
00057 {
00058 void init(twindow& w, const std::string& id);
00059 void show_toggle_callback(twidget* widget);
00060 void auto_hide();
00061 tlabel* label;
00062 tlabel* count;
00063 ttoggle_button* show_toggle;
00064 tlistbox* list;
00065 ttree_view_node* tree;
00066 tlabel* tree_label;
00067 };
00068
00069 struct tplayer_list
00070 {
00071 void init(twindow& w);
00072 void update_sort_icons();
00073 tsub_player_list active_game;
00074 tsub_player_list active_room;
00075 tsub_player_list other_rooms;
00076 tsub_player_list other_games;
00077
00078 ttoggle_button* sort_by_name;
00079 ttoggle_button* sort_by_relation;
00080
00081 ttree_view* tree;
00082 };
00083
00084 class tlobby_main : public tdialog, private events::chat_handler
00085 {
00086 public:
00087 tlobby_main(const config& game_config, lobby_info& info, display& disp);
00088
00089 ~tlobby_main();
00090
00091
00092
00093
00094 void set_preferences_callback(boost::function<void ()> f);
00095
00096 void update_gamelist();
00097
00098 protected:
00099 void update_gamelist_header();
00100
00101 void update_gamelist_diff();
00102
00103 void update_gamelist_filter();
00104
00105 std::map<std::string, string_map> make_game_row_data(const game_info& game);
00106
00107 void adjust_game_row_contents(const game_info& game, int idx, tgrid* grid);
00108
00109 public:
00110
00111 void update_playerlist();
00112
00113 enum legacy_result { QUIT, JOIN, OBSERVE, CREATE, PREFERENCES };
00114
00115 legacy_result get_legacy_result() const { return legacy_result_; }
00116
00117 enum t_notify_mode {
00118 NOTIFY_NONE,
00119 NOTIFY_MESSAGE,
00120 NOTIFY_MESSAGE_OTHER_WINDOW,
00121 NOTIFY_SERVER_MESSAGE,
00122 NOTIFY_OWN_NICK,
00123 NOTIFY_FRIEND_MESSAGE,
00124 NOTIFY_WHISPER,
00125 NOTIFY_WHISPER_OTHER_WINDOW,
00126 NOTIFY_LOBBY_JOIN,
00127 NOTIFY_LOBBY_QUIT,
00128 NOTIFY_COUNT
00129 };
00130
00131 void do_notify(t_notify_mode mode);
00132
00133 protected:
00134
00135 virtual void send_chat_message(const std::string& message, bool );
00136
00137 virtual void user_relation_changed(const std::string& name);
00138
00139
00140 virtual void add_chat_message(const time_t& time, const std::string& speaker,
00141 int side, const std::string& message,
00142 events::chat_handler::MESSAGE_TYPE type = events::chat_handler::MESSAGE_PRIVATE);
00143
00144
00145 virtual void add_whisper_sent(const std::string& receiver, const std::string& message);
00146
00147
00148 virtual void add_whisper_received(const std::string& sender, const std::string& message);
00149
00150
00151 virtual void add_chat_room_message_sent(const std::string& room, const std::string& message);
00152
00153
00154 virtual void add_chat_room_message_received(const std::string& room,
00155 const std::string& speaker, const std::string& message);
00156 private:
00157 void update_selected_game();
00158
00159
00160
00161
00162 void append_to_chatbox(const std::string& text);
00163
00164
00165
00166
00167 void append_to_chatbox(const std::string& text, size_t id);
00168
00169
00170
00171
00172 legacy_result legacy_result_;
00173
00174
00175
00176
00177
00178 room_info* active_window_room();
00179
00180
00181
00182
00183
00184
00185 tlobby_chat_window* room_window_open(const std::string& room, bool open_new);
00186
00187
00188
00189
00190
00191
00192 tlobby_chat_window* whisper_window_open(const std::string& name, bool open_new);
00193
00194
00195
00196
00197 tlobby_chat_window* search_create_window(const std::string& name, bool whisper, bool open_new);
00198
00199
00200
00201
00202 bool whisper_window_active(const std::string& name);
00203
00204
00205
00206
00207 bool room_window_active(const std::string& room);
00208
00209
00210
00211
00212 void increment_waiting_whsipers(const std::string& name);
00213
00214
00215
00216
00217 void increment_waiting_messages(const std::string& room);
00218
00219
00220
00221
00222 void add_whisper_window_whisper(const std::string& sender, const std::string& message);
00223
00224
00225
00226
00227
00228 void add_active_window_whisper(const std::string& sender, const std::string& message);
00229
00230
00231
00232
00233 void add_room_window_message(const std::string& room, const std::string& sender, const std::string& message);
00234
00235
00236
00237
00238 void add_active_window_message(const std::string& sender, const std::string& message);
00239
00240
00241
00242
00243
00244 void switch_to_window(tlobby_chat_window* t);
00245
00246 void switch_to_window(size_t id);
00247
00248 void active_window_changed();
00249
00250 void close_active_window();
00251
00252 void close_window(size_t idx);
00253
00254
00255
00256
00257
00258 void network_handler();
00259
00260 void process_network_data(const config& data);
00261
00262 void process_message(const config& data, bool whisper = false);
00263
00264 void process_gamelist(const config& data);
00265
00266 void process_gamelist_diff(const config& data);
00267
00268 void process_room_join(const config& data);
00269
00270 void process_room_part(const config& data);
00271
00272 void process_room_query_response(const config& data);
00273
00274 void join_button_callback(twindow& window);
00275
00276 void observe_button_callback(twindow& window);
00277
00278 void join_global_button_callback(twindow& window);
00279
00280 void observe_global_button_callback(twindow& window);
00281
00282 void join_or_observe(int index);
00283
00284
00285
00286
00287
00288
00289
00290 bool do_game_join(int idx, bool observe);
00291
00292 void send_message_button_callback(twindow& window);
00293
00294 void send_message_to_active_window(const std::string& input);
00295
00296 void close_window_button_callback(twindow& window);
00297
00298 void create_button_callback(twindow& window);
00299
00300 void show_preferences_button_callback(twindow& window);
00301
00302 void refresh_button_callback(twindow& window);
00303
00304 void quit_button_callback(twindow& window);
00305
00306 void room_switch_callback(twindow& window);
00307
00308 void chat_input_keypress_callback(
00309 bool& handled
00310 , bool& halt
00311 , const SDLKey key
00312 , twindow& window);
00313
00314 void game_filter_reload();
00315
00316 void game_filter_change_callback(twidget* widget);
00317
00318 void game_filter_keypress_callback(const SDLKey key);
00319
00320 void gamelist_change_callback(twindow& window);
00321
00322 void player_filter_callback(twidget* widget);
00323
00324 void user_dialog_callback(user_info* info);
00325
00326 void skip_replay_changed_callback(twidget* w);
00327
00328
00329 virtual const std::string& window_id() const;
00330
00331
00332 virtual void post_build(CVideo& video, twindow& window);
00333
00334
00335 void pre_show(CVideo& video, twindow& window);
00336
00337
00338 void post_show(twindow& window);
00339
00340 const config& game_config_;
00341
00342 tlistbox* gamelistbox_;
00343
00344 tlistbox* userlistbox_;
00345
00346 tlistbox* roomlistbox_;
00347
00348 tmulti_page* chat_log_container_;
00349
00350 ttext_box* chat_input_;
00351
00352 twindow* window_;
00353
00354 lobby_info& lobby_info_;
00355
00356 boost::function<void ()> preferences_callback_;
00357
00358
00359
00360
00361
00362 std::vector<tlobby_chat_window> open_windows_;
00363
00364 size_t active_window_;
00365
00366 ttoggle_button* filter_friends_;
00367
00368 ttoggle_button* filter_ignored_;
00369
00370 ttoggle_button* filter_slots_;
00371
00372 ttoggle_button* filter_invert_;
00373
00374 ttext_box* filter_text_;
00375
00376 int selected_game_id_;
00377
00378 tplayer_list player_list_;
00379
00380 bool player_list_dirty_;
00381
00382 bool gamelist_dirty_;
00383
00384 unsigned last_gamelist_update_;
00385
00386 bool gamelist_diff_update_;
00387
00388 display& disp_;
00389
00390
00391 unsigned long lobby_update_timer_;
00392
00393
00394 boost::function<void()> preferences_wrapper_;
00395
00396 std::vector<int> gamelist_id_at_row_;
00397
00398 bool delay_playerlist_update_;
00399
00400 bool delay_gamelist_update_;
00401
00402 friend struct lobby_delay_gamelist_update_guard;
00403 };
00404
00405 }
00406
00407 #endif
00408