Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #define GETTEXT_DOMAIN "wesnoth-lib"
00017
00018 #include "gui/dialogs/mp_connect.hpp"
00019
00020 #include "foreach.hpp"
00021 #include "game_preferences.hpp"
00022 #include "gui/dialogs/field.hpp"
00023 #include "gui/widgets/button.hpp"
00024 #ifdef GUI2_EXPERIMENTAL_LISTBOX
00025 #include "gui/widgets/list.hpp"
00026 #else
00027 #include "gui/widgets/listbox.hpp"
00028 #endif
00029 #include "gui/widgets/settings.hpp"
00030 #include "video.hpp"
00031
00032 #include <boost/bind.hpp>
00033
00034 namespace gui2 {
00035
00036 namespace {
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 class tmp_server_list : public tdialog
00061 {
00062 public:
00063 tmp_server_list() :
00064 host_name_()
00065 {}
00066
00067 const std::string& host_name() const { return host_name_; }
00068
00069 private:
00070 std::string host_name_;
00071
00072
00073 virtual const std::string& window_id() const;
00074
00075
00076 void pre_show(CVideo& video, twindow& window);
00077
00078
00079 void post_show(twindow& window);
00080 };
00081
00082 REGISTER_DIALOG(mp_server_list)
00083
00084 void tmp_server_list::pre_show(CVideo& , twindow& window)
00085 {
00086 tlistbox& list = find_widget<tlistbox>(&window, "server_list", false);
00087
00088 window.keyboard_capture(&list);
00089
00090 const std::vector<game_config::server_info>&
00091 pref_servers = preferences::server_list();
00092
00093 foreach(const game_config::server_info& server, pref_servers) {
00094
00095 std::map<std::string, string_map> data;
00096 string_map item;
00097
00098 item["label"] = server.name;
00099 data.insert(std::make_pair("name", item));
00100
00101 item["label"] = server.address;
00102 data.insert(std::make_pair("address", item));
00103
00104 list.add_row(data);
00105 }
00106 }
00107
00108 void tmp_server_list::post_show(twindow& window)
00109 {
00110 if(get_retval() == twindow::OK) {
00111
00112 const tlistbox& list = find_widget<const tlistbox>(
00113 &window, "server_list", false);
00114
00115 const tgrid* row = list.get_row_grid(list.get_selected_row());
00116 assert(row);
00117
00118 host_name_ = find_widget<const tcontrol>(row, "address", false).label();
00119 }
00120 }
00121
00122 }
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143 REGISTER_DIALOG(mp_connect)
00144
00145 static void show_server_list(
00146 CVideo& video
00147 , twindow& window
00148 , tfield_text* host_name)
00149 {
00150 assert(host_name);
00151
00152 tmp_server_list dlg;
00153 dlg.show(video);
00154
00155 if(dlg.get_retval() == twindow::OK) {
00156 host_name->set_widget_value(window, dlg.host_name());
00157 }
00158 }
00159
00160 tmp_connect::tmp_connect()
00161 : host_name_(register_text("host_name"
00162 , true
00163 , preferences::network_host
00164 , preferences::set_network_host
00165 , true))
00166 {
00167 }
00168
00169 void tmp_connect::pre_show(CVideo& video, twindow& window)
00170 {
00171 assert(host_name_);
00172
00173
00174 if(tbutton* button = find_widget<tbutton>(&window, "list", false, false)) {
00175
00176 connect_signal_mouse_left_click(*button, boost::bind(
00177 show_server_list
00178 , boost::ref(video)
00179 , boost::ref(window)
00180 , host_name_));
00181 }
00182
00183 }
00184
00185 tdialog* tmp_connect::mp_server_list_for_unit_test()
00186 {
00187 return new tmp_server_list();
00188 }
00189
00190 }
00191