multiplayer_lobby.hpp

Go to the documentation of this file.
00001 /* $Id: multiplayer_lobby.hpp 49494 2011-05-12 17:22:20Z zaroth $ */
00002 /*
00003    Copyright (C) 2007 - 2009
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 as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
00014 */
00015 
00016 /** @file multiplayer_lobby.hpp */
00017 
00018 #ifndef MULTIPLAYER_LOBBY_HPP_INCLUDED
00019 #define MULTIPLAYER_LOBBY_HPP_INCLUDED
00020 
00021 #include "multiplayer_ui.hpp"
00022 #include "game_preferences.hpp"
00023 #include "image.hpp"
00024 
00025 class config;
00026 class video;
00027 class game_display;
00028 
00029 /**
00030  * This module controls the multiplayer lobby.
00031  *
00032  * A section on the server which allows players to chat, create games, and join
00033  * games.
00034  */
00035 namespace mp {
00036 class gamebrowser : public gui::menu {
00037 public:
00038     struct game_item {
00039 
00040         game_item() :
00041             mini_map(),
00042             id(),
00043             map_data(),
00044             name(),
00045             map_info(),
00046             map_info_size(),
00047             gold(),
00048             xp(),
00049             vision(),
00050             status(),
00051             time_limit(),
00052             vacant_slots(0),
00053             current_turn(0),
00054             reloaded(false),
00055             started(false),
00056             fog(false),
00057             shroud(false),
00058             observers(false),
00059             shuffle_sides(false),
00060             use_map_settings(false),
00061             verified(false),
00062             password_required(false),
00063             have_era(false)
00064         {
00065         }
00066 
00067         surface mini_map;
00068         std::string id;
00069         std::string map_data;
00070         std::string name;
00071         std::string map_info;
00072         std::string map_info_size;
00073         std::string gold;
00074         std::string xp;
00075         std::string vision;
00076         std::string status;
00077         std::string time_limit;
00078         size_t vacant_slots;
00079         unsigned int current_turn;
00080         bool reloaded;
00081         bool started;
00082         bool fog;
00083         bool shroud;
00084         bool observers;
00085         bool shuffle_sides;
00086         bool use_map_settings;
00087         bool verified;
00088         bool password_required;
00089         bool have_era;
00090     };
00091     gamebrowser(CVideo& video, const config &map_hashes);
00092     void scroll(unsigned int pos);
00093     void handle_event(const SDL_Event& event);
00094     void set_inner_location(const SDL_Rect& rect);
00095     void set_item_height(unsigned int height);
00096     void set_game_items(const config& cfg, const config& game_config);
00097     void draw();
00098     void draw_contents();
00099     void draw_row(const size_t row_index, const SDL_Rect& rect, ROW_TYPE type);
00100     SDL_Rect get_item_rect(size_t index) const;
00101     bool empty() const { return games_.empty(); }
00102     bool selection_is_joinable() const
00103     { return empty() ? false : (games_[selected_].vacant_slots > 0 && !games_[selected_].started && games_[selected_].have_era); }
00104     // Moderators may observe any game.
00105     bool selection_is_observable() const { return empty() ? false : (games_[selected_].observers && games_[selected_].have_era) || preferences::is_authenticated(); }
00106     bool selected() const { return double_clicked_ && !empty(); }
00107     void reset_selection() { double_clicked_ = false; }
00108     int selection() const { return selected_; }
00109     game_item selected_game() { return games_[selected_]; }
00110     void select_game(const std::string& id);
00111     bool game_matches_filter(const game_item& i, const config& cfg);
00112 protected:
00113     unsigned int row_height() const { return item_height_ + (2 * style_->get_thickness()); }
00114 private:
00115     image::locator gold_icon_locator_;
00116     image::locator xp_icon_locator_;
00117     image::locator vision_icon_locator_;
00118     image::locator time_limit_icon_locator_;
00119     image::locator observer_icon_locator_;
00120     image::locator no_observer_icon_locator_;
00121     image::locator shuffle_sides_icon_locator_;
00122 
00123     const config &map_hashes_;
00124 
00125     unsigned int item_height_;
00126     int margin_;
00127     int minimap_size_;
00128     int h_padding_;
00129     int header_height_;
00130     size_t selected_;
00131     std::pair<size_t, size_t> visible_range_;
00132     std::vector<game_item> games_;
00133     std::vector<size_t> redraw_items_;
00134     std::vector<int> widths_;
00135     bool double_clicked_;
00136     bool ignore_next_doubleclick_;
00137     bool last_was_doubleclick_;
00138 };
00139 
00140 class lobby : public ui
00141 {
00142 public:
00143     lobby(game_display& d, const config& cfg, chat& c, config& gamelist);
00144 
00145     virtual void process_event();
00146 
00147 protected:
00148     virtual void hide_children(bool hide=true);
00149     virtual void layout_children(const SDL_Rect& rect);
00150     virtual void process_network_data(const config& data, const network::connection sock);
00151 
00152     virtual void gamelist_updated(bool silent=true);
00153 private:
00154 
00155     class lobby_sorter : public gui::menu::basic_sorter
00156     {
00157         const config& cfg_;
00158 
00159         bool column_sortable(int column) const;
00160         bool less(int column, const gui::menu::item& row1, const gui::menu::item& row2) const;
00161 
00162         enum { MAP_COLUMN = 0, STATUS_COLUMN = 2};
00163     public:
00164         lobby_sorter(const config& cfg);
00165     };
00166 
00167     std::vector<bool> game_vacant_slots_;
00168     std::vector<bool> game_observers_;
00169 
00170     gui::button observe_game_;
00171     gui::button join_game_;
00172     gui::button create_game_;
00173     gui::button skip_replay_;
00174     gui::button game_preferences_;
00175     gui::button quit_game_;
00176 
00177     gui::button apply_filter_;
00178     gui::button invert_filter_;
00179     gui::button vacant_slots_;
00180     gui::button friends_in_game_;
00181     gui::label filter_label_;
00182     gui::textbox filter_text_;
00183 
00184     int last_selected_game_;
00185 
00186     lobby_sorter sorter_;
00187     gamebrowser games_menu_;
00188 
00189     std::map<std::string,std::string> minimaps_;
00190 
00191     std::string search_string_;
00192 };
00193 
00194 } // end namespace mp
00195 
00196 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:03:06 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs