The Battle for Wesnoth  1.17.0-dev
player_info.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2021
3  by Tomasz Sniatowski <kailoran@gmail.com>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
17 
19 #include "gui/widgets/button.hpp"
20 #include "gui/widgets/label.hpp"
21 #include "gui/widgets/settings.hpp"
22 #include "gui/widgets/text_box.hpp"
23 #include "gui/widgets/window.hpp"
24 
26 #include "preferences/game.hpp"
28 #include "gettext.hpp"
29 
30 #include <functional>
31 
32 namespace gui2::dialogs
33 {
34 
35 REGISTER_DIALOG(lobby_player_info)
36 
38  mp::user_info& info,
39  const mp::lobby_info& li)
40  : chat_(chat)
41  , info_(info)
42  , reason_(nullptr)
43  , time_(nullptr)
44  , relation_(nullptr)
45  , add_to_friends_(nullptr)
46  , add_to_ignores_(nullptr)
47  , remove_from_list_(nullptr)
48  , result_open_whisper_(false)
49  , lobby_info_(li)
50 {
51 }
52 
54 {
55 }
56 
58 {
59  relation_ = find_widget<label>(&window, "relation_info", false, true);
60 
61  button& whisper = find_widget<button>(&window, "start_whisper", false);
65  } else {
66  whisper.set_active(false);
67  }
68 
69  add_to_friends_ = find_widget<button>(&window, "add_to_friends", false, true);
73 
74  add_to_ignores_ = find_widget<button>(&window, "add_to_ignores", false, true);
78 
80  = find_widget<button>(&window, "remove_from_list", false, true);
84 
86  find_widget<button>(&window, "check_status", false),
88 
90  find_widget<button>(&window, "kick", false),
91  std::bind(&lobby_player_info::kick_button_callback, this));
92 
94  find_widget<button>(&window, "kick_ban", false),
96 
98  find_widget<button>(&window, "stopgame", false),
100 
101  find_widget<label>(&window, "player_name", false).set_label(info_.name);
102 
103  std::stringstream loc;
105  if(game != nullptr) {
106  loc << _("In game:") << " " << game->name << " ";
107  if(info_.observing) {
108  loc << _("(observing)");
109  } else {
110  loc << _("(playing)");
111  }
112  } else {
113  loc << _("In lobby");
114  }
115 
116  time_ = find_widget<text_box>(&window, "time", false, true);
117  reason_ = find_widget<text_box>(&window, "reason", false, true);
118  window.add_to_tab_order(reason_);
119  window.add_to_tab_order(time_);
120 
121  find_widget<label>(&window, "location_info", false).set_label(loc.str());
122 
123  update_relation();
124 
126  widget* aw = window.find("admin", false);
128  }
129 }
130 
132 {
133 }
134 
136 {
137  add_to_friends_->set_active(false);
138  add_to_ignores_->set_active(false);
140  switch(info_.relation) {
142  relation_->set_label(_("On friends list"));
145  break;
147  relation_->set_label(_("On ignores list"));
150  break;
152  relation_->set_label(_("Neither a friend nor ignored"));
155  break;
157  relation_->set_label(_("You"));
158  break;
159  default:
160  relation_->set_label(_("Error"));
161  }
162 }
163 
165 {
168  update_relation();
169 }
170 
172 {
175  update_relation();
176 }
177 
179 {
182  update_relation();
183 }
184 
186 {
187  result_open_whisper_ = true;
188  get_window()->close();
189 }
190 
192 {
193  chat_.send_command("query", "status " + info_.name);
194  get_window()->close();
195 }
196 
198 {
199  do_kick_ban(false);
200  get_window()->close();
201 }
202 
204 {
205  do_kick_ban(true);
206  get_window()->close();
207 }
208 
210 {
211  do_stopgame();
212  get_window()->close();
213 }
214 
216 {
217  std::stringstream ss;
218  ss << "stopgame " << info_.name;
219  if(!reason_->get_value().empty()) {
220  ss << " " << reason_->get_value();
221  }
222 
223  chat_.send_command("query", ss.str());
224 }
225 
227 {
228  std::stringstream ss;
229  ss << (ban ? "kban " : "kick ") << info_.name;
230  if(ban && !time_->get_value().empty()) {
231  ss << " " << time_->get_value();
232  }
233  if(!reason_->get_value().empty()) {
234  ss << " " << reason_->get_value();
235  }
236 
237  chat_.send_command("query", ss.str());
238 }
239 
240 } // namespace dialogs
void close()
Requests to close the window.
Definition: window.hpp:182
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
Definition: player_info.cpp:57
virtual widget * find(const std::string &id, const bool must_be_active)
Returns a widget with the wanted id.
Definition: widget.cpp:584
logger & info()
Definition: log.cpp:89
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:85
window * get_window() const
Returns a pointer to the dialog&#39;s window.
static std::string _(const char *str)
Definition: gettext.hpp:93
bool remove_acquaintance(const std::string &nick)
Definition: game.cpp:255
std::string name
Definition: lobby_data.hpp:150
const mp::lobby_info & lobby_info_
Definition: player_info.hpp:93
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:282
Main entry points of multiplayer mode.
Definition: lobby_data.cpp:52
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:476
std::pair< preferences::acquaintance *, bool > add_acquaintance(const std::string &nick, const std::string &mode, const std::string &notes)
Definition: game.cpp:236
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:172
std::string name
Definition: lobby_data.hpp:128
The user set the widget invisible, that means:
events::chat_handler & chat_
Definition: player_info.hpp:75
virtual void post_show(window &window) override
Actions to be taken after the window has been shown.
Handling of system events.
Definition: manager.hpp:43
virtual void set_active(const bool active) override
See styled_widget::set_active.
Definition: button.cpp:63
Simple push button.
Definition: button.hpp:36
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:65