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