The Battle for Wesnoth  1.17.4+dev
player_info.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2022
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  const 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_.get_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 {
167  update_relation();
168 }
169 
171 {
173  update_relation();
174 }
175 
177 {
179  update_relation();
180 }
181 
183 {
184  result_open_whisper_ = true;
185  get_window()->close();
186 }
187 
189 {
190  chat_.send_command("query", "status " + info_.name);
191  get_window()->close();
192 }
193 
195 {
196  do_kick_ban(false);
197  get_window()->close();
198 }
199 
201 {
202  do_kick_ban(true);
203  get_window()->close();
204 }
205 
207 {
208  do_stopgame();
209  get_window()->close();
210 }
211 
213 {
214  std::stringstream ss;
215  ss << "stopgame " << info_.name;
216  if(!reason_->get_value().empty()) {
217  ss << " " << reason_->get_value();
218  }
219 
220  chat_.send_command("query", ss.str());
221 }
222 
224 {
225  std::stringstream ss;
226  ss << (ban ? "kban " : "kick ") << info_.name;
227  if(ban && !time_->get_value().empty()) {
228  ss << " " << time_->get_value();
229  }
230  if(!reason_->get_value().empty()) {
231  ss << " " << reason_->get_value();
232  }
233 
234  chat_.send_command("query", ss.str());
235 }
236 
237 } // 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:585
void connect_signal_mouse_left_click(dispatcher &dispatcher, const signal &signal)
Connects a signal handler for a left mouse button click.
Definition: dispatcher.cpp:172
logger & info()
Definition: log.cpp:89
This class represents the info a client has about a game on the server.
Definition: lobby_data.hpp:65
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
const mp::user_info & info_
Definition: player_info.hpp:77
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:248
std::string name
Definition: lobby_data.hpp:74
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:293
Main entry points of multiplayer mode.
Definition: lobby_data.cpp:52
virtual void set_label(const t_string &label)
user_relation get_relation() const
Definition: lobby_data.cpp:75
This file contains the settings handling of the widget library.
void set_visible(const visibility visible)
Definition: widget.cpp:477
std::pair< preferences::acquaintance *, bool > add_acquaintance(const std::string &nick, const std::string &mode, const std::string &notes)
Definition: game.cpp:229
std::string name
Definition: lobby_data.hpp:54
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
base class of top level items, the only item which needs to store the final canvases to draw on...
Definition: window.hpp:65