The Battle for Wesnoth  1.15.0+dev
player_info.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2018 by Tomasz Sniatowski <kailoran@gmail.com>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
16 
18 #include "gui/widgets/button.hpp"
19 #include "gui/widgets/label.hpp"
20 #include "gui/widgets/settings.hpp"
21 #include "gui/widgets/text_box.hpp"
22 #include "gui/widgets/window.hpp"
23 
24 #include "preferences/game.hpp"
25 #include "gettext.hpp"
26 
27 #include "utils/functional.hpp"
28 
29 namespace gui2
30 {
31 namespace dialogs
32 {
33 
34 REGISTER_DIALOG(lobby_player_info)
35 
37  mp::user_info& info,
38  const mp::lobby_info& li)
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);
60  find_widget<button>(&window, "start_whisper", false),
62  this,
63  std::ref(window)));
64 
65  add_to_friends_ = find_widget<button>(&window, "add_to_friends", false, true);
69 
70  add_to_ignores_ = find_widget<button>(&window, "add_to_ignores", false, true);
74 
76  = find_widget<button>(&window, "remove_from_list", false, true);
80 
82  find_widget<button>(&window, "check_status", false),
84  this,
85  std::ref(window)));
86 
88  find_widget<button>(&window, "kick", false),
90  this,
91  std::ref(window)));
92 
94  find_widget<button>(&window, "kick_ban", false),
96  this,
97  std::ref(window)));
98 
99  find_widget<label>(&window, "player_name", false).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>(&window, "time", false, true);
115  reason_ = find_widget<text_box>(&window, "reason", false, true);
116  window.add_to_tab_order(reason_);
117  window.add_to_tab_order(time_);
118 
119  find_widget<label>(&window, "location_info", false).set_label(loc.str());
120 
121  update_relation();
122 
124  widget* aw = window.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_.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;
154  case mp::user_info::ME:
155  relation_->set_label(_("You"));
156  break;
157  default:
158  relation_->set_label(_("Error"));
159  }
160 }
161 
163 {
166  update_relation();
167 }
168 
170 {
173  update_relation();
174 }
175 
177 {
180  update_relation();
181 }
182 
184 {
185  result_open_whisper_ = true;
186  w.close();
187 }
188 
190 {
191  chat_.send_command("query", "status " + info_.name);
192  w.close();
193 }
194 
196 {
197  do_kick_ban(false);
198  w.close();
199 }
200 
202 {
203  do_kick_ban(true);
204  w.close();
205 }
206 
208 {
209  std::stringstream ss;
210  ss << (ban ? "kban " : "kick ") << info_.name;
211  if(ban && !time_->get_value().empty()) {
212  ss << " " << time_->get_value();
213  }
214  if(!reason_->get_value().empty()) {
215  ss << " " << reason_->get_value();
216  }
217 
218  chat_.send_command("query", ss.str());
219 }
220 
221 } // namespace dialogs
222 } // namespace gui2
void close()
Requests to close the window.
Definition: window.hpp:183
virtual void pre_show(window &window) override
Inherited from modal_dialog.
Definition: player_info.cpp:56
virtual widget * find(const std::string &id, const bool must_be_active)
Returns a widget with the wanted id.
Definition: widget.cpp:581
void start_whisper_button_callback(window &w)
bool is_authenticated()
Definition: game.cpp:184
void check_status_button_callback(window &w)
logger & info()
Definition: log.cpp:90
This class represents the info a client has about a game on the server.
Definition: lobby_data.hpp:138
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:47
void send_command(const std::string &cmd, const std::string &args="")
Definition: chat_events.cpp:86
bool remove_acquaintance(const std::string &nick)
Definition: game.cpp:284
std::string name
Definition: lobby_data.hpp:147
const mp::lobby_info & lobby_info_
Definition: player_info.hpp:91
Generic file dialog.
Definition: field-fwd.hpp:22
game_info * get_game_by_id(int id)
Returns info on a game with the given game ID.
Definition: lobby_info.cpp:272
Pubic entry points for the MP workflow.
Definition: lobby_data.cpp:49
virtual void set_label(const t_string &label)
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:91
This file contains the settings handling of the widget library.
void kick_ban_button_callback(window &w)
void set_visible(const visibility visible)
Definition: widget.cpp:473
std::pair< preferences::acquaintance *, bool > add_acquaintance(const std::string &nick, const std::string &mode, const std::string &notes)
Definition: game.cpp:262
void connect_signal_mouse_left_click(dispatcher &dispatcher, const signal_function &signal)
Connects a signal handler for a left mouse button click.
Definition: dispatcher.cpp:233
Various uncategorised dialogs.
std::string name
Definition: lobby_data.hpp:127
The user set the widget invisible, that means:
events::chat_handler & chat_
Definition: player_info.hpp:73
int w
virtual void post_show(window &window) override
Inherited from modal_dialog.
Handling of system events.
Definition: manager.hpp:41
virtual void set_active(const bool active) override
See styled_widget::set_active.
Definition: button.cpp:62
user_relation relation
Definition: lobby_data.hpp:129
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:63