The Battle for Wesnoth  1.19.5+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 
18 #include "gui/widgets/button.hpp"
19 #include "gui/widgets/label.hpp"
20 #include "gui/widgets/text_box.hpp"
21 #include "gui/widgets/window.hpp"
22 
25 #include "gettext.hpp"
26 
27 #include <functional>
28 
29 namespace gui2::dialogs
30 {
31 
32 REGISTER_DIALOG(lobby_player_info)
33 
35  const mp::user_info& info,
36  const mp::lobby_info& li)
37  : modal_dialog(window_id())
38  , chat_(chat)
39  , info_(info)
40  , reason_(nullptr)
41  , time_(nullptr)
42  , relation_(nullptr)
43  , add_to_friends_(nullptr)
44  , add_to_ignores_(nullptr)
45  , remove_from_list_(nullptr)
46  , result_open_whisper_(false)
47  , lobby_info_(li)
48 {
49 }
50 
52 {
53 }
54 
56 {
57  relation_ = find_widget<label>("relation_info", false, true);
58 
59  button& whisper = find_widget<button>("start_whisper");
63  } else {
64  whisper.set_active(false);
65  }
66 
67  add_to_friends_ = find_widget<button>("add_to_friends", false, true);
71 
72  add_to_ignores_ = find_widget<button>("add_to_ignores", false, true);
76 
78  = find_widget<button>("remove_from_list", false, true);
82 
84  find_widget<button>("check_status"),
86 
88  find_widget<button>("kick"),
89  std::bind(&lobby_player_info::kick_button_callback, this));
90 
92  find_widget<button>("kick_ban"),
94 
96  find_widget<button>("stopgame"),
98 
99  find_widget<label>("player_name").set_label(info_.name);
100 
101  std::stringstream loc;
103  if(game != nullptr) {
104  loc << _("In game:") << " " << game->name << " ";
105  if(info_.observing) {
106  loc << _("(observing)");
107  } else {
108  loc << _("(playing)");
109  }
110  } else {
111  loc << _("In lobby");
112  }
113 
114  time_ = find_widget<text_box>("time", false, true);
115  reason_ = find_widget<text_box>("reason", false, true);
118 
119  find_widget<label>("location_info").set_label(loc.str());
120 
121  update_relation();
122 
124  widget* aw = find("admin", false);
126  }
127 }
128 
130 {
131 }
132 
134 {
135  add_to_friends_->set_active(false);
136  add_to_ignores_->set_active(false);
138  switch(info_.get_relation()) {
140  relation_->set_label(_("On friends list"));
143  break;
145  relation_->set_label(_("On ignores list"));
148  break;
150  relation_->set_label(_("Neither a friend nor ignored"));
153  break;
155  relation_->set_label(_("You"));
156  break;
157  default:
158  relation_->set_label(_("Error"));
159  }
160 }
161 
163 {
164  prefs::get().add_acquaintance(info_.name, "friend", "");
165  update_relation();
166 }
167 
169 {
170  prefs::get().add_acquaintance(info_.name, "ignore", "");
171  update_relation();
172 }
173 
175 {
177  update_relation();
178 }
179 
181 {
182  result_open_whisper_ = true;
183  get_window()->close();
184 }
185 
187 {
188  chat_.send_command("query", "status " + info_.name);
189  get_window()->close();
190 }
191 
193 {
194  do_kick_ban(false);
195  get_window()->close();
196 }
197 
199 {
200  do_kick_ban(true);
201  get_window()->close();
202 }
203 
205 {
206  do_stopgame();
207  get_window()->close();
208 }
209 
211 {
212  std::stringstream ss;
213  ss << "stopgame " << info_.name;
214  if(!reason_->get_value().empty()) {
215  ss << " " << reason_->get_value();
216  }
217 
218  chat_.send_command("query", ss.str());
219 }
220 
222 {
223  std::stringstream ss;
224  ss << (ban ? "kban " : "kick ") << info_.name;
225  if(ban && !time_->get_value().empty()) {
226  ss << " " << time_->get_value();
227  }
228  if(!reason_->get_value().empty()) {
229  ss << " " << reason_->get_value();
230  }
231 
232  chat_.send_command("query", ss.str());
233 }
234 
235 } // 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:64
virtual void post_show() override
Actions to be taken after the window has been shown.
const mp::user_info & info_
Definition: player_info.hpp:77
virtual void pre_show() override
Actions to be taken before showing the window.
Definition: player_info.cpp:55
const mp::lobby_info & lobby_info_
Definition: player_info.hpp:93
events::chat_handler & chat_
Definition: player_info.hpp:75
Abstract base class for all modal dialogs.
virtual void set_label(const t_string &text)
std::string get_value() const
Base class for all widgets.
Definition: widget.hpp:55
void set_visible(const visibility visible)
Definition: widget.cpp:479
window * get_window()
Get the parent window.
Definition: widget.cpp:117
@ invisible
The user set the widget invisible, that means:
void close()
Requests to close the window.
Definition: window.hpp:219
widget * find(const std::string &id, const bool must_be_active) override
See widget::find.
Definition: window.cpp:778
void add_to_tab_order(widget *widget, int at=-1)
Add the widget to the tabbing order.
Definition: window.cpp:1225
game_info * get_game_by_id(int id)
Returns info on a game with the given game ID.
Definition: lobby_info.cpp:287
static prefs & get()
std::pair< preferences::acquaintance *, bool > add_acquaintance(const std::string &nick, const std::string &mode, const std::string &notes)
bool remove_acquaintance(const std::string &nick)
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(editor_edit_unit)
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:319
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.
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