The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
mp_cmd_wrapper.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2016 by Thomas Baumhauer
4  Part of the Battle for Wesnoth Project http://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 
16 #define GETTEXT_DOMAIN "wesnoth-lib"
17 
19 
20 #include "gui/auxiliary/field.hpp"
21 #include "gui/widgets/button.hpp"
22 #include "gui/widgets/settings.hpp"
23 #include "gui/widgets/window.hpp"
24 
25 #include "game_preferences.hpp"
26 
27 namespace gui2
28 {
29 
30 /*WIKI
31  * @page = GUIWindowDefinitionWML
32  * @order = 2_mp_cmd_wrapper
33  *
34  * == Multiplayer command wrapper ==
35  *
36  * This shows a dialog that provides a graphical front-end
37  * to various commands in the multiplayer lobby
38  *
39  * @begin{table}{dialog_widgets}
40  *
41  * message & & text_box & o &
42  * Text to send as a private message. $
43  *
44  * reason & & text_box & o &
45  * The reason for a ban. $
46  *
47  * time & & text_box & o &
48  * The time the ban lasts. $
49  *
50  * user_label & & label & o &
51  * The label to show which user has been selected. $
52  *
53  * send_message & & button & m &
54  * Execute /msg. $
55  *
56  * add_friend & & button & m &
57  * Execute /friend. $
58  *
59  * add_ignore & & button & m &
60  * Execute /ignore. $
61  *
62  * remove & & button & m &
63  * Execute /remove. $
64  *
65  * status & & button & m &
66  * Execute /query status. $
67  *
68  * kick & & button & m &
69  * Execute /query kick. $
70  *
71  * ban & & button & m &
72  * Execute /query kban. $
73  *
74  * mod_options & & grid & m &
75  * Grid containing the status/kick/ban options. This grid and its
76  * children are hidden when these options are unavailable. $
77  *
78  * @end{table}
79  */
80 
81 REGISTER_DIALOG(mp_cmd_wrapper)
82 
84  : message_(), reason_(), time_()
85 {
86  register_text("message", false, message_, true);
87  register_text("reason", false, reason_);
88  register_text("time", false, time_);
89  register_label("user_label", false, user);
90 
91  set_always_save_fields(true);
92 }
93 
95 {
96 #if defined(_WIN32) || defined(__APPLE__)
98  = find_widget<ttext_box>(&window, "message", false, false);
99  if(message) {
100  /**
101  * @todo For some reason the text wrapping fails on Windows and Mac,
102  * this causes an exception to be thrown, which brings the user back
103  * to the main menu. So avoid that problem by imposing a maximum
104  * length (the number of letters W that fit).
105  */
106  message->set_maximum_length(18);
107  }
108 #endif
109 
110  const bool authenticated = preferences::is_authenticated();
111 
112  if(tgrid* g = find_widget<tgrid>(&window, "mod_options", false, false)) {
113  g->set_active(authenticated);
114  g->set_visible(authenticated ? twidget::tvisible::visible : twidget::tvisible::invisible);
115  }
116 
117  /**
118  * @todo Not really happy with the retval code in general. Need to give it
119  * some more thought. Therefore separated the set_retval from the
120  * set_active code.
121  */
122  if(tbutton* b = find_widget<tbutton>(&window, "add_friend", false, false)) {
123  b->set_retval(1);
124  }
125 
126  if(tbutton* b = find_widget<tbutton>(&window, "add_ignore", false, false)) {
127  b->set_retval(2);
128  }
129 
130  if(tbutton* b = find_widget<tbutton>(&window, "remove", false, false)) {
131  b->set_retval(3);
132  }
133 
134  if(tbutton* b = find_widget<tbutton>(&window, "status", false, false)) {
135  b->set_retval(4);
136  }
137 
138  if(tbutton* b = find_widget<tbutton>(&window, "kick", false, false)) {
139  b->set_retval(5);
140  }
141 
142  if(tbutton* b = find_widget<tbutton>(&window, "ban", false, false)) {
143  b->set_retval(6);
144  }
145 }
146 
147 } // namespace gui2
Base container class.
Definition: grid.hpp:29
This file contains the window object, this object is a top level container which has the event manage...
REGISTER_DIALOG(label_settings)
GLboolean GLboolean g
Definition: glew.h:7319
Class for a single line text area.
Definition: text_box.hpp:118
Implements some helper classes to ease adding fields to a dialog and hide the synchronization needed...
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
Simple push button.
Definition: button.hpp:32
GLdouble GLdouble GLdouble b
Definition: glew.h:6966
The user set the widget invisible, that means:
Definition: widget.hpp:103
This file contains the settings handling of the widget library.
void pre_show(twindow &window)
Inherited from tdialog.
The user sets the widget visible, that means:
Definition: widget.hpp:79
GLsizei GLenum GLuint GLuint GLsizei char * message
Definition: glew.h:2499
void set_maximum_length(const size_t maximum_length)
Definition: text.cpp:73