The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
player_info.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2009 - 2025
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/label.hpp"
22
25#include "gettext.hpp"
26
27#include <functional>
28
29namespace gui2::dialogs
30{
31
32REGISTER_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
54
56{
57 relation_ = find_widget<label>("relation_info", false, true);
58
59 button& whisper = find_widget<button>("start_whisper");
61 connect_signal_mouse_left_click(whisper,
63 } else {
64 whisper.set_active(false);
65 }
66
67 add_to_friends_ = find_widget<button>("add_to_friends", false, true);
68 connect_signal_mouse_left_click(
71
72 add_to_ignores_ = find_widget<button>("add_to_ignores", false, true);
73 connect_signal_mouse_left_click(
76
78 = find_widget<button>("remove_from_list", false, true);
79 connect_signal_mouse_left_click(
82
83 connect_signal_mouse_left_click(
84 find_widget<button>("check_status"),
86
87 connect_signal_mouse_left_click(
88 find_widget<button>("kick"),
90
91 connect_signal_mouse_left_click(
92 find_widget<button>("kick_ban"),
94
95 connect_signal_mouse_left_click(
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
122
124 widget* aw = find("admin", false);
126 }
127}
128
132
134{
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
167
173
179
185
187{
188 chat_.send_command("query", "status " + info_.name);
189 close();
190}
191
197
203
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
map_location loc
Definition move.cpp:172
void send_command(const std::string &cmd, const std::string &args="")
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_
virtual void pre_show() override
Actions to be taken before showing the window.
const mp::lobby_info & lobby_info_
events::chat_handler & chat_
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
@ invisible
The user set the widget invisible, that means:
void close()
Requests to close the window.
Definition window.hpp:216
widget * find(const std::string_view id, const bool must_be_active) override
See widget::find.
Definition window.cpp:776
void add_to_tab_order(widget *widget, int at=-1)
Add the widget to the tabbing order.
Definition window.cpp:1223
game_info * get_game_by_id(int id)
Returns info on a game with the given game ID.
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:100
This file contains the window object, this object is a top level container which has the event manage...
#define REGISTER_DIALOG(window_id)
Wrapper for REGISTER_DIALOG2.
Handling of system events.
Main entry points of multiplayer mode.
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.
user_relation get_relation() const
std::string name