The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
player_info.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2016 by Tomasz Sniatowski <[email protected]>
3  Part of the Battle for Wesnoth Project http://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 #include "gui/dialogs/helper.hpp"
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 
23 #include "game_preferences.hpp"
24 #include "gettext.hpp"
25 
26 #include "utils/functional.hpp"
27 
28 namespace gui2
29 {
30 
31 REGISTER_DIALOG(lobby_player_info)
32 
34  user_info& info,
35  const lobby_info& li)
36  : chat_(chat)
37  , info_(info)
38  , reason_(nullptr)
39  , time_(nullptr)
40  , relation_(nullptr)
41  , add_to_friends_(nullptr)
42  , add_to_ignores_(nullptr)
43  , remove_from_list_(nullptr)
44  , result_open_whisper_(false)
45  , lobby_info_(li)
46 {
47 }
48 
50 {
51 }
52 
54 {
55  relation_ = find_widget<tlabel>(&window, "relation_info", false, true);
57  find_widget<tbutton>(&window, "start_whisper", false),
59  this,
60  std::ref(window)));
61 
62  add_to_friends_ = &find_widget<tbutton>(&window, "add_to_friends", false);
66  this,
67  std::ref(window)));
68 
69  add_to_ignores_ = &find_widget<tbutton>(&window, "add_to_ignores", false);
73  this,
74  std::ref(window)));
75 
77  = &find_widget<tbutton>(&window, "remove_from_list", false);
81  this,
82  std::ref(window)));
83 
85  find_widget<tbutton>(&window, "check_status", false),
87  this,
88  std::ref(window)));
89 
91  find_widget<tbutton>(&window, "kick", false),
93  this,
94  std::ref(window)));
95 
97  find_widget<tbutton>(&window, "kick_ban", false),
99  this,
100  std::ref(window)));
101 
102  find_widget<tlabel>(&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  find_widget<tlabel>(&window, "location_info", false).set_label(loc.str());
118 
119  update_relation(window);
120 
122  twidget* aw = window.find("admin", false);
124  }
125 }
126 
128 {
129 }
130 
132 {
133  add_to_friends_->set_active(false);
134  add_to_ignores_->set_active(false);
136  switch(info_.relation) {
137  case user_info::FRIEND:
138  relation_->set_label(_("On friends list"));
141  break;
142  case user_info::IGNORED:
143  relation_->set_label(_("On ignores list"));
146  break;
147  case user_info::NEUTRAL:
148  relation_->set_label(_("Neither a friend nor ignored"));
151  break;
152  case user_info::ME:
153  relation_->set_label(_("You"));
154  break;
155  default:
156  relation_->set_label(_("Error"));
157  }
158  w.invalidate_layout();
159 }
160 
162 {
165  update_relation(w);
166 }
167 
169 {
172  update_relation(w);
173 }
174 
176 {
179  update_relation(w);
180 }
181 
183 {
184  result_open_whisper_ = true;
185  w.close();
186 }
187 
189 {
190  chat_.send_command("query", "status " + info_.name);
191  w.close();
192 }
193 
195 {
196  do_kick_ban(false);
197  w.close();
198 }
199 
201 {
202  do_kick_ban(true);
203  w.close();
204 }
205 
207 {
208  std::stringstream ss;
209  ss << (ban ? "kban" : "kick ") << info_.name;
210  if(ban && !time_->get_value().empty()) {
211  ss << " " << time_->get_value();
212  }
213  if(!reason_->get_value().empty()) {
214  ss << " " << reason_->get_value();
215  }
216 
217  chat_.send_command("query", ss.str());
218 }
219 
220 } // end namespace gui2
virtual void set_active(const bool active) override
See tcontrol::set_active.
Definition: button.cpp:58
events::chat_handler & chat_
Definition: player_info.hpp:71
void kick_ban_button_callback(twindow &w)
game_info * get_game_by_id(int id)
Definition: info.cpp:242
void remove_from_list_button_callback(twindow &w)
logger & info()
Definition: log.cpp:91
void update_relation(twindow &w)
REGISTER_DIALOG(label_settings)
This class represents the collective information the client has about the players and games on the se...
Definition: info.hpp:25
virtual void set_label(const t_string &label)
Definition: control.cpp:330
void do_kick_ban(bool ban)
void send_command(const std::string &cmd, const std::string &args="")
Definition: chat_events.cpp:75
void connect_signal_mouse_left_click(tdispatcher &dispatcher, const tsignal_function &signal)
Connects a signal handler for a left mouse button click.
Definition: dispatcher.hpp:710
bool remove_acquaintance(const std::string &nick)
std::string get_value() const
Definition: text.hpp:76
This class represents the information a client has about another player.
Definition: data.hpp:102
user_relation relation
Definition: data.hpp:127
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:62
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
void add_to_friends_button_callback(twindow &w)
The user set the widget invisible, that means:
Definition: widget.hpp:103
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:82
void add_to_ignores_button_callback(twindow &w)
const lobby_info & lobby_info_
Definition: player_info.hpp:89
This file contains the settings handling of the widget library.
void start_whisper_button_callback(twindow &w)
GLubyte GLubyte GLubyte GLubyte w
Definition: glew.h:1858
int game_id
Definition: data.hpp:126
void close()
Requests to close the window.
Definition: window.hpp:235
void pre_show(twindow &window)
Inherited from tdialog.
Definition: player_info.cpp:53
void check_status_button_callback(twindow &w)
bool add_friend(const std::string &nick, const std::string &notes)
bool add_ignore(const std::string &nick, const std::string &reason)
bool observing
Definition: data.hpp:130
Handling of system events.
Definition: manager.hpp:42
std::string name
Definition: data.hpp:125
GLenum GLint ref
Definition: glew.h:1813
void post_show(twindow &window)
Inherited from tdialog.
This class represents the info a client has about a game on the server.
Definition: data.hpp:136
Base class for all widgets.
Definition: widget.hpp:49
static void set_label(twindow &window, const std::string &id, const std::string &label)
Definition: unit_attack.cpp:89
std::string name
Definition: data.hpp:146
virtual twidget * find(const std::string &id, const bool must_be_active)
Returns a widget with the wanted id.
Definition: widget.cpp:558
void set_visible(const tvisible::scoped_enum visible)
Definition: widget.cpp:445
void invalidate_layout()
Updates the size of the window.
Definition: window.cpp:941
void kick_button_callback(twindow &w)