gui/dialogs/mp_cmd_wrapper.cpp

Go to the documentation of this file.
00001 /* $Id: mp_cmd_wrapper.cpp 52533 2012-01-07 02:35:17Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2009 - 2012 by Thomas Baumhauer <thomas.baumhauer@NOSPAMgmail.com>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
00014 */
00015 
00016 #define GETTEXT_DOMAIN "wesnoth-lib"
00017 
00018 #include "gui/dialogs/mp_cmd_wrapper.hpp"
00019 
00020 #include "gui/dialogs/field.hpp"
00021 #include "gui/widgets/button.hpp"
00022 #include "gui/widgets/settings.hpp"
00023 #include "gui/widgets/window.hpp"
00024 
00025 #include "game_preferences.hpp"
00026 
00027 namespace gui2 {
00028 
00029 /*WIKI
00030  * @page = GUIWindowDefinitionWML
00031  * @order = 2_mp_cmd_wrapper
00032  *
00033  * == Multiplayer command wrapper ==
00034  *
00035  * This shows a dialog that provides a graphical front-end
00036  * to various commands in the multiplayer lobby
00037  *
00038  * @begin{table}{dialog_widgets}
00039  *
00040  * message & & text_box & o &
00041  *         Text to send as a private message. $
00042  *
00043  * reason & & text_box & o &
00044  *         The reason for a ban. $
00045  *
00046  * time & & text_box & o &
00047  *         The time the ban lasts. $
00048  *
00049  * user_label & & label & o &
00050  *         The label to show which user has been selected. $
00051  *
00052  * send_message & & button & m &
00053  *         Execute /msg. $
00054  *
00055  * add_friend & & button & m &
00056  *         Execute /friend. $
00057  *
00058  * add_ignore & & button & m &
00059  *         Execute /ignore. $
00060  *
00061  * remove & & button & m &
00062  *         Execute /remove. $
00063  *
00064  * status & & button & m &
00065  *         Execute /query status. $
00066  *
00067  * kick & & button & m &
00068  *         Execute /query kick. $
00069  *
00070  * ban & & button & m &
00071  *         Execute /query kban. $
00072  *
00073  * @end{table}
00074  */
00075 
00076 REGISTER_DIALOG(mp_cmd_wrapper)
00077 
00078 tmp_cmd_wrapper::tmp_cmd_wrapper(const t_string& user)
00079     : message_()
00080     , reason_()
00081     , time_()
00082 {
00083     register_text("message", false, message_, true);
00084     register_text("reason", false, reason_);
00085     register_text("time", false, time_);
00086     register_label("user_label", false, user);
00087 
00088     set_always_save_fields(true);
00089 }
00090 
00091 void tmp_cmd_wrapper::pre_show(CVideo& /*video*/, twindow& window)
00092 {
00093 #if defined(_WIN32) || defined(__APPLE__)
00094     ttext_box* message =
00095             find_widget<ttext_box>(&window, "message", false, false);
00096     if(message) {
00097         /**
00098          * @todo For some reason the text wrapping fails on Windows and Mac,
00099          * this causes an exception to be thrown, which brings the user back
00100          * to the main menu. So avoid that problem by imposing a maximum
00101          * length (the number of letters W that fit).
00102          */
00103         message->set_maximum_length(18);
00104     }
00105 #endif
00106 
00107     const bool authenticated = preferences::is_authenticated();
00108 
00109     if(tbutton* b = find_widget<tbutton>(&window, "status", false, false)) {
00110         b->set_active(authenticated);
00111     }
00112 
00113     if(tbutton* b = find_widget<tbutton>(&window, "kick", false, false)) {
00114         b->set_active(authenticated);
00115     }
00116 
00117     if(tbutton* b = find_widget<tbutton>(&window, "ban", false, false)) {
00118         b->set_active(authenticated);
00119     }
00120 
00121     /**
00122      * @todo Not really happy with the retval code in general. Need to give it
00123      * some more thought. Therefore seperated the set_retval from the
00124      * set_active code.
00125      */
00126     if(tbutton* b = find_widget<tbutton>(&window, "add_friend", false, false)) {
00127         b->set_retval(1);
00128     }
00129 
00130     if(tbutton* b = find_widget<tbutton>(&window, "add_ignore", false, false)) {
00131         b->set_retval(2);
00132     }
00133 
00134     if(tbutton* b = find_widget<tbutton>(&window, "remove", false, false)) {
00135         b->set_retval(3);
00136     }
00137 
00138     if(tbutton* b = find_widget<tbutton>(&window, "status", false, false)) {
00139         b->set_retval(4);
00140     }
00141 
00142     if(tbutton* b = find_widget<tbutton>(&window, "kick", false, false)) {
00143         b->set_retval(5);
00144     }
00145 
00146     if(tbutton* b = find_widget<tbutton>(&window, "ban", false, false)) {
00147         b->set_retval(6);
00148     }
00149 }
00150 
00151 } // namespace gui2
00152 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:02:58 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs