The Battle for Wesnoth  1.15.12+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 
25 #include "preferences/game.hpp"
27 #include "gettext.hpp"
28 
29 #include <functional>
30 
31 namespace gui2::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);
59 
60  button& whisper = find_widget<button>(&window, "start_whisper", false);
64  } else {
65  whisper.set_active(false);
66  }
67 
68  add_to_friends_ = find_widget<button>(&window, "add_to_friends", false, true);
72 
73  add_to_ignores_ = find_widget<button>(&window, "add_to_ignores", false, true);
77 
79  = find_widget<button>(&window, "remove_from_list", false, true);
83 
85  find_widget<button>(&window, "check_status", false),
87 
89  find_widget<button>(&window, "kick", false),
90  std::bind(&lobby_player_info::kick_button_callback, this));
91 
93  find_widget<button>(&window, "kick_ban", false),
95 
97  find_widget<button>(&window, "stopgame", false),
99 
100  find_widget<label>(&window, "player_name", false).set_label(info_.name);
101 
102  std::stringstream loc;
104  if(game != nullptr) {
105  loc << _("In game:") << " " << game->name << " ";
106  if(info_.observing) {
107  loc << _("(observing)");
108  } else {
109  loc << _("(playing)");
110  }
111  } else {
112  loc << _("In lobby");
113  }
114 
115  time_ = find_widget<text_box>(&window, "time", false, true);
116  reason_ = find_widget<text_box>(&window, "reason", false, true);
117  window.add_to_tab_order(reason_);
118  window.add_to_tab_order(time_);
119 
120  find_widget<label>(&window, "location_info", false).set_label(loc.str());
121 
122  update_relation();
123 
125  widget* aw = window.find("admin", false);
127  }
128 }
129 
131 {
132 }
133 
135 {
136  add_to_friends_->set_active(false);
137  add_to_ignores_->set_active(false);
139  switch(info_.relation) {
141  relation_->set_label(_("On friends list"));
144  break;
146  relation_->set_label(_("On ignores list"));
149  break;
151  relation_->set_label(_("Neither a friend nor ignored"));
154  break;
156  relation_->set_label(_("You"));
157  break;
158  default:
159  relation_->set_label(_("Error"));
160  }
161 }
162 
164 {
167  update_relation();
168 }
169 
171 {
174  update_relation();
175 }
176 
178 {
181  update_relation();
182 }
183 
185 {
186  result_open_whisper_ = true;
187  get_window()->close();
188 }
189 
191 {
192  chat_.send_command("query", "status " + info_.name);
193  get_window()->close();
194 }
195 
197 {
198  do_kick_ban(false);
199  get_window()->close();
200 }
201 
203 {
204  do_kick_ban(true);
205  get_window()->close();
206 }
207 
209 {
210  do_stopgame();
211  get_window()->close();
212 }
213 
215 {
216  std::stringstream ss;
217  ss << "stopgame " << info_.name;
218  if(!reason_->get_value().empty()) {
219  ss << " " << reason_->get_value();
220  }
221 
222  chat_.send_command("query", ss.str());
223 }
224 
226 {
227  std::stringstream ss;
228  ss << (ban ? "kban " : "kick ") << info_.name;
229  if(ban && !time_->get_value().empty()) {
230  ss << " " << time_->get_value();
231  }
232  if(!reason_->get_value().empty()) {
233  ss << " " << reason_->get_value();
234  }
235 
236  chat_.send_command("query", ss.str());
237 }
238 
239 } // namespace dialogs
void close()
Requests to close the window.
Definition: window.hpp:181
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
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:583
logger & info()
Definition: log.cpp:88
This class represents the info a client has about a game on the server.
Definition: lobby_data.hpp:141
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:49
void send_command(const std::string &cmd, const std::string &args="")
Definition: chat_events.cpp:84
window * get_window() const
Returns a pointer to the dialog&#39;s window.
static std::string _(const char *str)
Definition: gettext.hpp:92
bool remove_acquaintance(const std::string &nick)
Definition: game.cpp:249
std::string name
Definition: lobby_data.hpp:150
const mp::lobby_info & lobby_info_
Definition: player_info.hpp:92
bool logged_in_as_moderator()
Gets whether the currently logged-in user is a moderator.
game_info * get_game_by_id(int id)
Returns info on a game with the given game ID.
Definition: lobby_info.cpp:273
Main entry points of multiplayer mode.
Definition: lobby_data.cpp:51
virtual void set_label(const t_string &label)
This file contains the settings handling of the widget library.
void set_visible(const visibility visible)
Definition: widget.cpp:475
std::pair< preferences::acquaintance *, bool > add_acquaintance(const std::string &nick, const std::string &mode, const std::string &notes)
Definition: game.cpp:230
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:171
std::string name
Definition: lobby_data.hpp:128
The user set the widget invisible, that means:
events::chat_handler & chat_
Definition: player_info.hpp:74
virtual void post_show(window &window) override
Actions to be taken after the window has been shown.
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
Simple push button.
Definition: button.hpp:35
user_relation relation
Definition: lobby_data.hpp:131
base class of top level items, the only item which needs to store the final canvases to draw on...
Definition: window.hpp:64