The Battle for Wesnoth  1.19.0-dev
player_info.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2024
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/text_box.hpp"
22 #include "gui/widgets/window.hpp"
23 
24 #include "preferences/game.hpp"
26 #include "gettext.hpp"
27 
28 #include <functional>
29 
30 namespace gui2::dialogs
31 {
32 
33 REGISTER_DIALOG(lobby_player_info)
34 
36  const mp::user_info& info,
37  const mp::lobby_info& li)
38  : modal_dialog(window_id())
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);
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_.get_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 {
166  update_relation();
167 }
168 
170 {
172  update_relation();
173 }
174 
176 {
178  update_relation();
179 }
180 
182 {
183  result_open_whisper_ = true;
184  get_window()->close();
185 }
186 
188 {
189  chat_.send_command("query", "status " + info_.name);
190  get_window()->close();
191 }
192 
194 {
195  do_kick_ban(false);
196  get_window()->close();
197 }
198 
200 {
201  do_kick_ban(true);
202  get_window()->close();
203 }
204 
206 {
207  do_stopgame();
208  get_window()->close();
209 }
210 
212 {
213  std::stringstream ss;
214  ss << "stopgame " << info_.name;
215  if(!reason_->get_value().empty()) {
216  ss << " " << reason_->get_value();
217  }
218 
219  chat_.send_command("query", ss.str());
220 }
221 
223 {
224  std::stringstream ss;
225  ss << (ban ? "kban " : "kick ") << info_.name;
226  if(ban && !time_->get_value().empty()) {
227  ss << " " << time_->get_value();
228  }
229  if(!reason_->get_value().empty()) {
230  ss << " " << reason_->get_value();
231  }
232 
233  chat_.send_command("query", ss.str());
234 }
235 
236 } // namespace dialogs
void send_command(const std::string &cmd, const std::string &args="")
Definition: chat_events.cpp:82
Simple push button.
Definition: button.hpp:36
virtual void set_active(const bool active) override
See styled_widget::set_active.
Definition: button.cpp:63
virtual void post_show(window &window) override
Actions to be taken after the window has been shown.
const mp::user_info & info_
Definition: player_info.hpp:77
const mp::lobby_info & lobby_info_
Definition: player_info.hpp:93
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
Definition: player_info.cpp:56
events::chat_handler & chat_
Definition: player_info.hpp:75
Abstract base class for all modal dialogs.
window * get_window()
Returns a pointer to the dialog's window.
virtual void set_label(const t_string &text)
std::string get_value() const
Base class for all widgets.
Definition: widget.hpp:53
void set_visible(const visibility visible)
Definition: widget.cpp:470
@ invisible
The user set the widget invisible, that means:
base class of top level items, the only item which needs to store the final canvases to draw on.
Definition: window.hpp:63
void close()
Requests to close the window.
Definition: window.hpp:223
widget * find(const std::string &id, const bool must_be_active) override
See widget::find.
Definition: window.cpp:784
void add_to_tab_order(widget *widget, int at=-1)
Add the widget to the tabbing order.
Definition: window.cpp:1233
game_info * get_game_by_id(int id)
Returns info on a game with the given game ID.
Definition: lobby_info.cpp:287
static std::string _(const char *str)
Definition: gettext.hpp:93
This file contains the window object, this object is a top level container which has the event manage...
Handling of system events.
REGISTER_DIALOG(tod_new_schedule)
void connect_signal_mouse_left_click(dispatcher &dispatcher, const signal &signal)
Connects a signal handler for a left mouse button click.
Definition: dispatcher.cpp:177
logger & info()
Definition: log.cpp:314
Main entry points of multiplayer mode.
Definition: lobby_data.cpp:50
bool logged_in_as_moderator()
Gets whether the currently logged-in user is a moderator.
bool remove_acquaintance(const std::string &nick)
Definition: game.cpp:238
std::pair< preferences::acquaintance *, bool > add_acquaintance(const std::string &nick, const std::string &mode, const std::string &notes)
Definition: game.cpp:224
This class represents the info a client has about a game on the server.
Definition: lobby_data.hpp:63
user_relation get_relation() const
Definition: lobby_data.cpp:73
std::string name
Definition: lobby_data.hpp:51