Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef MULTIPLAYER_CONNECT_H_INCLUDED
00019 #define MULTIPLAYER_CONNECT_H_INCLUDED
00020
00021 #include "gamestatus.hpp"
00022 #include "leader_list.hpp"
00023 #include "multiplayer_ui.hpp"
00024 #include "widgets/scrollpane.hpp"
00025 #include "widgets/slider.hpp"
00026 #include "widgets/combo_drag.hpp"
00027
00028 namespace ai {
00029 struct description;
00030 }
00031
00032 namespace mp {
00033
00034 class connect : public mp::ui
00035 {
00036 public:
00037 struct connected_user {
00038 connected_user(const std::string& name, mp::controller controller,
00039 network::connection connection) :
00040 name(name), controller(controller), connection(connection)
00041 {};
00042 std::string name;
00043 mp::controller controller;
00044 network::connection connection;
00045 operator std::string() const
00046 {
00047 return name;
00048 }
00049 };
00050
00051 typedef std::vector<connected_user> connected_user_list;
00052
00053 class side {
00054 public:
00055 side(connect& parent, const config& cfg, int index);
00056
00057 side(const side& a);
00058
00059 void add_widgets_to_scrollpane(gui::scrollpane& pane, int pos);
00060
00061 void process_event();
00062
00063
00064 bool changed();
00065
00066
00067
00068
00069
00070
00071
00072 config get_config() const;
00073
00074
00075
00076
00077
00078 bool available(const std::string& name = "") const;
00079
00080
00081 bool ready_for_start() const;
00082
00083
00084 bool allow_player() const;
00085
00086
00087 void set_controller(mp::controller controller);
00088 mp::controller get_controller() const;
00089
00090
00091 void update_user_list();
00092
00093
00094 const std::string& get_current_player() const
00095 { return current_player_; }
00096
00097 int get_index();
00098
00099 void set_index(int index);
00100
00101 const std::string& get_player_id() const;
00102
00103
00104 void set_player_id(const std::string& player_id);
00105
00106
00107 void set_ready_for_start(bool ready_for_start);
00108
00109 int get_team();
00110
00111 void set_team(int team);
00112
00113 std::vector<std::string> get_children_to_swap();
00114
00115 std::map<std::string, config> get_side_children();
00116
00117 void set_side_children(std::map<std::string, config> children);
00118
00119
00120
00121
00122
00123 void import_network_user(const config& data);
00124
00125
00126 void reset(mp::controller controller);
00127
00128
00129 void resolve_random();
00130 void hide_ai_algorithm_combo(bool invis);
00131 private:
00132 void init_ai_algorithm_combo();
00133 void update_ai_algorithm_combo() {hide_ai_algorithm_combo(parent_->hidden());}
00134
00135
00136 void update_faction_combo();
00137 void update_controller_ui();
00138 void update_ui();
00139
00140
00141
00142
00143
00144
00145 connect* parent_;
00146
00147
00148
00149
00150
00151
00152 config cfg_;
00153
00154
00155 int index_;
00156 std::string id_;
00157 std::string player_id_;
00158 std::string save_id_;
00159 std::string current_player_;
00160 mp::controller controller_;
00161 int faction_;
00162 int team_;
00163 int color_;
00164 int gold_;
00165 int income_;
00166 std::string leader_;
00167 std::string gender_;
00168 std::string ai_algorithm_;
00169 bool ready_for_start_;
00170
00171
00172 bool gold_lock_;
00173 bool income_lock_;
00174 bool team_lock_;
00175 bool color_lock_;
00176
00177
00178 gui::label player_number_;
00179 gui::combo_drag_ptr combo_controller_;
00180 gui::label orig_controller_;
00181 gui::combo combo_ai_algorithm_;
00182 gui::combo combo_faction_;
00183 gui::combo combo_leader_;
00184 gui::combo combo_gender_;
00185 gui::combo combo_team_;
00186 gui::combo combo_color_;
00187 gui::slider slider_gold_;
00188 gui::slider slider_income_;
00189 gui::label label_gold_;
00190 gui::label label_income_;
00191
00192 bool allow_player_;
00193 bool allow_changes_;
00194 bool enabled_;
00195 bool changed_;
00196 leader_list_manager llm_;
00197 };
00198
00199 friend class side;
00200
00201 typedef std::vector<side> side_list;
00202
00203
00204
00205
00206 game_display* disp_;
00207
00208 connect(game_display& disp, const config& game_config, chat& c,
00209 config& gamelist, const mp_game_settings& params, const int num_turns,
00210 mp::controller default_controller, bool local_players_only = false);
00211
00212 virtual void process_event();
00213
00214 void take_reserved_side(connect::side& side, const config& data);
00215
00216
00217
00218
00219
00220 const game_state& get_state();
00221
00222
00223
00224
00225
00226 void start_game();
00227
00228 protected:
00229 virtual void layout_children(const SDL_Rect& rect);
00230
00231 virtual void process_network_data(const config& data, const network::connection sock);
00232 virtual void process_network_error(network::error& error);
00233 virtual bool accept_connections();
00234 virtual void process_network_connection(const network::connection sock);
00235
00236 virtual void hide_children(bool hide=true);
00237
00238 private:
00239
00240
00241
00242
00243
00244
00245
00246 void load_game();
00247 void lists_init();
00248
00249
00250 config* current_config();
00251
00252
00253 void update_level();
00254
00255
00256 void update_and_send_diff(bool update_time_of_day = false);
00257
00258
00259 bool sides_available() const;
00260
00261
00262 bool sides_ready() const;
00263
00264
00265
00266
00267
00268
00269 bool can_start_game() const;
00270
00271
00272
00273
00274
00275 void update_playerlist_state(bool silent=true);
00276
00277
00278 connected_user_list::iterator find_player(const std::string& id);
00279
00280
00281 int find_player_side(const std::string& id) const;
00282
00283
00284 void update_user_combos();
00285
00286 bool local_only_;
00287
00288 config level_;
00289
00290
00291 game_state state_;
00292
00293 mp_game_settings params_;
00294 int num_turns_;
00295
00296
00297 std::vector<const config *> era_sides_;
00298
00299
00300 std::vector<std::string> player_types_;
00301 std::vector<std::string> player_factions_;
00302 std::vector<std::string> player_teams_;
00303 std::vector<std::string> player_colors_;
00304 std::vector<ai::description*> ai_algorithms_;
00305
00306
00307 std::vector<std::string> team_names_;
00308 std::vector<std::string> user_team_names_;
00309 const std::string team_prefix_;
00310
00311 side_list sides_;
00312 connected_user_list users_;
00313
00314 gui::label waiting_label_;
00315 bool message_full_;
00316
00317 controller default_controller_;
00318
00319
00320 gui::scrollpane scroll_pane_;
00321
00322 gui::label type_title_label_;
00323 gui::label faction_title_label_;
00324 gui::label team_title_label_;
00325 gui::label color_title_label_;
00326 gui::label gold_title_label_;
00327 gui::label income_title_label_;
00328
00329 gui::button launch_;
00330 gui::button cancel_;
00331 gui::button add_local_player_;
00332
00333 gui::drop_group_manager_ptr combo_control_group_;
00334
00335 };
00336
00337 }
00338
00339 #endif
00340