The Battle for Wesnoth  1.15.2+dev
player_info.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2018 by Tomasz Sniatowski <kailoran@gmail.com>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
16 
18 #include "gui/widgets/button.hpp"
19 #include "gui/widgets/label.hpp"
20 #include "gui/widgets/settings.hpp"
21 #include "gui/widgets/text_box.hpp"
22 #include "gui/widgets/window.hpp"
23 
24 #include "preferences/game.hpp"
25 #include "gettext.hpp"
26 
27 #include "utils/functional.hpp"
28 
29 namespace gui2
30 {
31 namespace dialogs
32 {
33 
34 REGISTER_DIALOG(lobby_player_info)
35 
37  mp::user_info& info,
38  const mp::lobby_info& li)
39  : chat_(chat)
40  , info_(info)
41  , reason_(nullptr)
42  , time_(nullptr)
43  , relation_(nullptr)
44  , add_to_friends_(nullptr)
45  , add_to_ignores_(nullptr)
46  , remove_from_list_(nullptr)
47  , result_open_whisper_(false)
48  , lobby_info_(li)
49 {
50 }
51 
53 {
54 }
55 
57 {
58  relation_ = find_widget<label>(&window, "relation_info", false, true);
60  find_widget<button>(&window, "start_whisper", false),
62  this,
63  std::ref(window)));
64 
65  add_to_friends_ = find_widget<button>(&window, "add_to_friends", false, true);
69 
70  add_to_ignores_ = find_widget<button>(&window, "add_to_ignores", false, true);
74 
76  = find_widget<button>(&window, "remove_from_list", false, true);
80 
82  find_widget<button>(&window, "check_status", false),
84  this,
85  std::ref(window)));
86 
88  find_widget<button>(&window, "kick", false),
90  this,
91  std::ref(window)));
92 
94  find_widget<button>(&window, "kick_ban", false),
96  this,
97  std::ref(window)));
98 
100  find_widget<button>(&window, "stopgame", false),
102  this,
103  std::ref(window)));
104 
105  find_widget<label>(&window, "player_name", false).set_label(info_.name);
106 
107  std::stringstream loc;
109  if(game != nullptr) {
110  loc << _("In game:") << " " << game->name << " ";
111  if(info_.observing) {
112  loc << _("(observing)");
113  } else {
114  loc << _("(playing)");
115  }
116  } else {
117  loc << _("In lobby");
118  }
119 
120  time_ = find_widget<text_box>(&window, "time", false, true);
121  reason_ = find_widget<text_box>(&window, "reason", false, true);
122  window.add_to_tab_order(reason_);
123  window.add_to_tab_order(time_);
124 
125  find_widget<label>(&window, "location_info", false).set_label(loc.str());
126 
127  update_relation();
128 
130  widget* aw = window.find("admin", false);
132  }
133 }
134 
136 {
137 }
138 
140 {
141  add_to_friends_->set_active(false);
142  add_to_ignores_->set_active(false);
144  switch(info_.relation) {
146  relation_->set_label(_("On friends list"));
149  break;
151  relation_->set_label(_("On ignores list"));
154  break;
156  relation_->set_label(_("Neither a friend nor ignored"));
159  break;
160  case mp::user_info::ME:
161  relation_->set_label(_("You"));
162  break;
163  default:
164  relation_->set_label(_("Error"));
165  }
166 }
167 
169 {
172  update_relation();
173 }
174 
176 {
179  update_relation();
180 }
181 
183 {
186  update_relation();
187 }
188 
190 {
191  result_open_whisper_ = true;
192  w.close();
193 }
194 
196 {
197  chat_.send_command("query", "status " + info_.name);
198  w.close();
199 }
200 
202 {
203  do_kick_ban(false);
204  w.close();
205 }
206 
208 {
209  do_kick_ban(true);
210  w.close();
211 }
212 
214 {
215  do_stopgame();
216  w.close();
217 }
218 
220 {
221  std::stringstream ss;
222  ss << "stopgame " << info_.name;
223  if(!reason_->get_value().empty()) {
224  ss << " " << reason_->get_value();
225  }
226 
227  chat_.send_command("query", ss.str());
228 }
229 
231 {
232  std::stringstream ss;
233  ss << (ban ? "kban " : "kick ") << info_.name;
234  if(ban && !time_->get_value().empty()) {
235  ss << " " << time_->get_value();
236  }
237  if(!reason_->get_value().empty()) {
238  ss << " " << reason_->get_value();
239  }
240 
241  chat_.send_command("query", ss.str());
242 }
243 
244 } // namespace dialogs
245 } // namespace gui2
void close()
Requests to close the window.
Definition: window.hpp:182
virtual void pre_show(window &window) override
Inherited from modal_dialog.
Definition: player_info.cpp:56
virtual widget * find(const std::string &id, const bool must_be_active)
Returns a widget with the wanted id.
Definition: widget.cpp:581
void stopgame_button_callback(window &w)
void start_whisper_button_callback(window &w)
bool is_authenticated()
Definition: game.cpp:181
void check_status_button_callback(window &w)
logger & info()
Definition: log.cpp:90
This class represents the info a client has about a game on the server.
Definition: lobby_data.hpp:138
std::string get_value() const
This file contains the window object, this object is a top level container which has the event manage...
Base class for all widgets.
Definition: widget.hpp:47
void send_command(const std::string &cmd, const std::string &args="")
Definition: chat_events.cpp:86
bool remove_acquaintance(const std::string &nick)
Definition: game.cpp:281
std::string name
Definition: lobby_data.hpp:147
const mp::lobby_info & lobby_info_
Definition: player_info.hpp:95
Generic file dialog.
Definition: field-fwd.hpp:22
game_info * get_game_by_id(int id)
Returns info on a game with the given game ID.
Definition: lobby_info.cpp:275
Pubic entry points for the MP workflow.
Definition: lobby_data.cpp:50
virtual void set_label(const t_string &label)
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:91
This file contains the settings handling of the widget library.
void kick_ban_button_callback(window &w)
void set_visible(const visibility visible)
Definition: widget.cpp:473
std::pair< preferences::acquaintance *, bool > add_acquaintance(const std::string &nick, const std::string &mode, const std::string &notes)
Definition: game.cpp:259
void connect_signal_mouse_left_click(dispatcher &dispatcher, const signal_function &signal)
Connects a signal handler for a left mouse button click.
Definition: dispatcher.cpp:233
Various uncategorised dialogs.
std::string name
Definition: lobby_data.hpp:127
The user set the widget invisible, that means:
events::chat_handler & chat_
Definition: player_info.hpp:77
int w
virtual void post_show(window &window) override
Inherited from modal_dialog.
Handling of system events.
Definition: manager.hpp:42
virtual void set_active(const bool active) override
See styled_widget::set_active.
Definition: button.cpp:62
user_relation relation
Definition: lobby_data.hpp:129
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:62