multiplayer_lobby.hpp

Go to the documentation of this file.
00001 /* $Id: multiplayer_lobby.hpp 25781 2008-04-13 02:22:17Z dave $ */
00002 /*
00003    Copyright (C) 2007 - 2008
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License version 2
00008    or at your option any later version.
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY.
00011 
00012    See the COPYING file for more details.
00013 */
00014 
00015 //! @file multiplayer_lobby.hpp
00016 //!
00017 
00018 #ifndef MULTIPLAYER_LOBBY_HPP_INCLUDED
00019 #define MULTIPLAYER_LOBBY_HPP_INCLUDED
00020 
00021 #include "multiplayer_ui.hpp"
00022 
00023 #include <map>
00024 
00025 class config;
00026 class video;
00027 class game_display;
00028 
00029 //! This module controls the multiplayer lobby. 
00030 //! A section on the server which allows players to chat, 
00031 //! create games, and join games.
00032 namespace mp {
00033 class gamebrowser : public gui::menu {
00034 public:
00035     struct game_item {
00036         surface mini_map;
00037         std::string id;
00038         std::string map_data;
00039         std::string name;
00040         std::string map_info;
00041         std::string map_info_size;
00042         std::string gold;
00043         std::string xp;
00044         std::string vision;
00045         std::string status;
00046         std::string time_limit;
00047         size_t vacant_slots;
00048         unsigned int current_turn;
00049         bool reloaded;
00050         bool started;
00051         bool fog;
00052         bool shroud;
00053         bool observers;
00054         bool use_map_settings;
00055         bool verified;
00056         bool password_required;
00057         bool have_era;
00058     };
00059     gamebrowser(CVideo& video,const config* map_hashes);
00060     void scroll(unsigned int pos);
00061     void handle_event(const SDL_Event& event);
00062     void set_inner_location(const SDL_Rect& rect);
00063     void set_item_height(unsigned int height);
00064     void set_game_items(const config& cfg, const config& game_config);
00065     void draw();
00066     void draw_contents();
00067     void draw_row(const size_t row_index, const SDL_Rect& rect, ROW_TYPE type);
00068     SDL_Rect get_item_rect(size_t index) const;
00069     bool empty() const { return games_.empty(); }
00070     bool selection_is_joinable() const
00071     { return empty() ? false : (games_[selected_].vacant_slots > 0 && !games_[selected_].started && games_[selected_].have_era); }
00072     bool selection_is_observable() const { return empty() ? false : games_[selected_].observers && games_[selected_].have_era; }
00073     bool selected() const { return double_clicked_ && !empty(); }
00074     void reset_selection() { double_clicked_ = false; }
00075     int selection() const { return selected_; }
00076     game_item selected_game() { return games_[selected_]; }
00077 protected:
00078     unsigned int row_height() const { return item_height_ + (2 * style_->get_thickness()); }
00079 private:
00080     image::locator gold_icon_locator_;
00081     image::locator xp_icon_locator_;
00082     image::locator vision_icon_locator_;
00083     image::locator time_limit_icon_locator_;
00084     image::locator observer_icon_locator_;
00085     image::locator no_observer_icon_locator_;
00086 
00087     const config* map_hashes_;
00088 
00089     unsigned int item_height_;
00090     int margin_;
00091     int minimap_size_;
00092     int h_padding_;
00093     int header_height_;
00094     size_t selected_;
00095     std::pair<size_t, size_t> visible_range_;
00096     std::vector<game_item> games_;
00097     std::vector<size_t> redraw_items_;
00098     std::vector<int> widths_;
00099     bool double_clicked_;
00100     bool ignore_next_doubleclick_;
00101     bool last_was_doubleclick_;
00102 };
00103 
00104 class lobby : public ui
00105 {
00106 public:
00107     lobby(game_display& d, const config& cfg, chat& c, config& gamelist);
00108 
00109     virtual void process_event();
00110 
00111 protected:
00112     virtual void hide_children(bool hide=true);
00113     virtual void layout_children(const SDL_Rect& rect);
00114     virtual void process_network_data(const config& data, const network::connection sock);
00115 
00116     virtual void gamelist_updated(bool silent=true);
00117 private:
00118 
00119     class lobby_sorter : public gui::menu::basic_sorter
00120     {
00121         const config& cfg_;
00122 
00123         bool column_sortable(int column) const;
00124         bool less(int column, const gui::menu::item& row1, const gui::menu::item& row2) const;
00125 
00126         enum { MAP_COLUMN = 0, STATUS_COLUMN = 2};
00127     public:
00128         lobby_sorter(const config& cfg);
00129     };
00130 
00131     std::vector<bool> game_vacant_slots_;
00132     std::vector<bool> game_observers_;
00133 
00134     gui::button observe_game_;
00135     gui::button join_game_;
00136     gui::button create_game_;
00137     gui::button skip_replay_;
00138 #ifndef USE_TINY_GUI
00139     gui::button game_preferences_;
00140 #endif
00141     gui::button quit_game_;
00142 
00143     int last_selected_game_;
00144 
00145     lobby_sorter sorter_;
00146     gamebrowser games_menu_;
00147 
00148     std::map<std::string,std::string> minimaps_;
00149 };
00150 
00151 } // end namespace mp
00152 
00153 #endif

Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs