The Battle for Wesnoth  1.17.10+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  : modal_dialog(window_id())
41  , chat_(chat)
42  , info_(info)
43  , reason_(nullptr)
44  , time_(nullptr)
45  , relation_(nullptr)
46  , add_to_friends_(nullptr)
47  , add_to_ignores_(nullptr)
48  , remove_from_list_(nullptr)
49  , result_open_whisper_(false)
50  , lobby_info_(li)
51 {
52 }
53 
55 {
56 }
57 
59 {
60  relation_ = find_widget<label>(&window, "relation_info", false, true);
61 
62  button& whisper = find_widget<button>(&window, "start_whisper", false);
66  } else {
67  whisper.set_active(false);
68  }
69 
70  add_to_friends_ = find_widget<button>(&window, "add_to_friends", false, true);
74 
75  add_to_ignores_ = find_widget<button>(&window, "add_to_ignores", false, true);
79 
81  = find_widget<button>(&window, "remove_from_list", false, true);
85 
87  find_widget<button>(&window, "check_status", false),
89 
91  find_widget<button>(&window, "kick", false),
92  std::bind(&lobby_player_info::kick_button_callback, this));
93 
95  find_widget<button>(&window, "kick_ban", false),
97 
99  find_widget<button>(&window, "stopgame", false),
101 
102  find_widget<label>(&window, "player_name", false).set_label(info_.name);
103 
104  std::stringstream loc;
106  if(game != nullptr) {
107  loc << _("In game:") << " " << game->name << " ";
108  if(info_.observing) {
109  loc << _("(observing)");
110  } else {
111  loc << _("(playing)");
112  }
113  } else {
114  loc << _("In lobby");
115  }
116 
117  time_ = find_widget<text_box>(&window, "time", false, true);
118  reason_ = find_widget<text_box>(&window, "reason", false, true);
119  window.add_to_tab_order(reason_);
120  window.add_to_tab_order(time_);
121 
122  find_widget<label>(&window, "location_info", false).set_label(loc.str());
123 
124  update_relation();
125 
127  widget* aw = window.find("admin", false);
129  }
130 }
131 
133 {
134 }
135 
137 {
138  add_to_friends_->set_active(false);
139  add_to_ignores_->set_active(false);
141  switch(info_.get_relation()) {
143  relation_->set_label(_("On friends list"));
146  break;
148  relation_->set_label(_("On ignores list"));
151  break;
153  relation_->set_label(_("Neither a friend nor ignored"));
156  break;
158  relation_->set_label(_("You"));
159  break;
160  default:
161  relation_->set_label(_("Error"));
162  }
163 }
164 
166 {
168  update_relation();
169 }
170 
172 {
174  update_relation();
175 }
176 
178 {
180  update_relation();
181 }
182 
184 {
185  result_open_whisper_ = true;
186  get_window()->close();
187 }
188 
190 {
191  chat_.send_command("query", "status " + info_.name);
192  get_window()->close();
193 }
194 
196 {
197  do_kick_ban(false);
198  get_window()->close();
199 }
200 
202 {
203  do_kick_ban(true);
204  get_window()->close();
205 }
206 
208 {
209  do_stopgame();
210  get_window()->close();
211 }
212 
214 {
215  std::stringstream ss;
216  ss << "stopgame " << info_.name;
217  if(!reason_->get_value().empty()) {
218  ss << " " << reason_->get_value();
219  }
220 
221  chat_.send_command("query", ss.str());
222 }
223 
225 {
226  std::stringstream ss;
227  ss << (ban ? "kban " : "kick ") << info_.name;
228  if(ban && !time_->get_value().empty()) {
229  ss << " " << time_->get_value();
230  }
231  if(!reason_->get_value().empty()) {
232  ss << " " << reason_->get_value();
233  }
234 
235  chat_.send_command("query", ss.str());
236 }
237 
238 } // namespace dialogs
window(const builder_window::window_resolution &definition)
< Needs to be initialized in show.
Definition: window.cpp:263
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:58
virtual widget * find(const std::string &id, const bool must_be_active)
Returns a widget with the wanted id.
Definition: widget.cpp:541
void connect_signal_mouse_left_click(dispatcher &dispatcher, const signal &signal)
Connects a signal handler for a left mouse button click.
Definition: dispatcher.cpp:179
logger & info()
Definition: log.cpp:182
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:53
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
static std::string _(const char *str)
Definition: gettext.hpp:93
bool remove_acquaintance(const std::string &nick)
Definition: game.cpp:242
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:456
std::pair< preferences::acquaintance *, bool > add_acquaintance(const std::string &nick, const std::string &mode, const std::string &notes)
Definition: game.cpp:228
window * get_window()
Returns a pointer to the dialog&#39;s window.
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
Abstract base class for all modal dialogs.
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:66