Author: mordante
Date: Sun Mar 13 20:18:31 2011
New Revision: 48898

URL: http://svn.gna.org/viewcvs/wesnoth?rev=48898&view=rev
Log:
Polish the tmp_cmd_wrapper class.

Modified:
    trunk/src/gui/dialogs/mp_cmd_wrapper.cpp
    trunk/src/gui/dialogs/mp_cmd_wrapper.hpp

Modified: trunk/src/gui/dialogs/mp_cmd_wrapper.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/mp_cmd_wrapper.cpp?rev=48898&r1=48897&r2=48898&view=diff
==============================================================================
--- trunk/src/gui/dialogs/mp_cmd_wrapper.cpp (original)
+++ trunk/src/gui/dialogs/mp_cmd_wrapper.cpp Sun Mar 13 20:18:31 2011
@@ -18,9 +18,8 @@
 #include "gui/dialogs/mp_cmd_wrapper.hpp"
 
 #include "gui/widgets/button.hpp"
-#include "gui/dialogs/field.hpp"
-#include "gui/widgets/label.hpp"
 #include "gui/widgets/settings.hpp"
+#include "gui/widgets/window.hpp"
 
 #include "game_preferences.hpp"
 
@@ -45,6 +44,9 @@
  *
  * time & & text_box & o &
  *         The time the ban lasts. $
+ *
+ * user_label & & label & o &
+ *         The label to show which user has been selected. $
  *
  * send_message & & button & m &
  *         Execute /msg. $
@@ -72,13 +74,24 @@
 
 REGISTER_DIALOG(mp_cmd_wrapper)
 
-tmp_cmd_wrapper::tmp_cmd_wrapper(const t_string& user) :
-               message_(), reason_(), time_(), user_(user) { }
+tmp_cmd_wrapper::tmp_cmd_wrapper(const t_string& user)
+       : message_()
+       , reason_()
+       , time_()
+{
+       register_text2("message", false, message_, true);
+       register_text2("reason", false, reason_);
+       register_text2("time", false, time_);
+       register_label2("user_label", false, user);
+
+       set_always_save_fields(true);
+}
 
 void tmp_cmd_wrapper::pre_show(CVideo& /*video*/, twindow& window)
 {
+#if defined(_WIN32) || defined(__APPLE__)
        ttext_box* message =
-               dynamic_cast<ttext_box*>(window.find("message", false));
+                       find_widget<ttext_box>(&window, "message", false, 
false);
        if(message) {
                /**
                 * @todo For some reason the text wrapping fails on Windows and 
Mac,
@@ -86,66 +99,52 @@
                 * to the main menu. So avoid that problem by imposing a maximum
                 * length (the number of letters W that fit).
                 */
-#if defined(_WIN32) || defined(__APPLE__)
                message->set_maximum_length(18);
+       }
 #endif
-               window.keyboard_capture(message);
+
+       const bool authenticated = preferences::is_authenticated();
+
+       if(tbutton* b = find_widget<tbutton>(&window, "status", false, false)) {
+               b->set_active(authenticated);
        }
 
-       message = dynamic_cast<ttext_box*>(window.find("reason", false));
-       if(message) message->set_active(preferences::is_authenticated());
-
-       message = dynamic_cast<ttext_box*>(window.find("time", false));
-       if(message) message->set_active(preferences::is_authenticated());
-
-       tlabel* label =
-               dynamic_cast<tlabel*>(window.find("user_label", false));
-       if(label) label->set_label(user_);
-
-
-       tbutton* b = dynamic_cast<tbutton*>(window.find("add_friend", false));
-       if(b) b->set_retval(1);
-
-       b = dynamic_cast<tbutton*>(window.find("add_ignore", false));
-       if(b) b->set_retval(2);
-
-       b = dynamic_cast<tbutton*>(window.find("remove", false));
-       if(b) b->set_retval(3);
-
-       b = dynamic_cast<tbutton*>(window.find("status", false));
-       if(b) {
-               b->set_retval(4);
-               b->set_active(preferences::is_authenticated());
+       if(tbutton* b = find_widget<tbutton>(&window, "kick", false, false)) {
+               b->set_active(authenticated);
        }
 
-       b = dynamic_cast<tbutton*>(window.find("kick", false));
-       if(b) {
-               b->set_retval(5);
-               b->set_active(preferences::is_authenticated());
+       if(tbutton* b = find_widget<tbutton>(&window, "ban", false, false)) {
+               b->set_active(authenticated);
        }
 
-       b = dynamic_cast<tbutton*>(window.find("ban", false));
-       if(b) {
-               b->set_retval(6);
-               b->set_active(preferences::is_authenticated());
+       /**
+        * @todo Not really happy with the retval code in general. Need to give 
it
+        * some more thought. Therefore seperated the set_retval from the
+        * set_active code.
+        */
+       if(tbutton* b = find_widget<tbutton>(&window, "add_friend", false, 
false)) {
+               b->set_retval(1);
        }
 
-}
+       if(tbutton* b = find_widget<tbutton>(&window, "add_ignore", false, 
false)) {
+               b->set_retval(2);
+       }
 
-void tmp_cmd_wrapper::post_show(twindow& window)
-{
-       ttext_box* message =
-               dynamic_cast<ttext_box*>(window.find("message", false));
-       message_ = message ? message_ = message->get_value() : "";
+       if(tbutton* b = find_widget<tbutton>(&window, "remove", false, false)) {
+               b->set_retval(3);
+       }
 
-       ttext_box* reason =
-               dynamic_cast<ttext_box*>(window.find("reason", false));
-       reason_ = reason ? reason_ = reason->get_value() : "";
+       if(tbutton* b = find_widget<tbutton>(&window, "status", false, false)) {
+               b->set_retval(4);
+       }
 
-       ttext_box* time =
-               dynamic_cast<ttext_box*>(window.find("time", false));
-       time_ = time ? time_ = time->get_value() : "";
+       if(tbutton* b = find_widget<tbutton>(&window, "kick", false, false)) {
+               b->set_retval(5);
+       }
 
+       if(tbutton* b = find_widget<tbutton>(&window, "ban", false, false)) {
+               b->set_retval(6);
+       }
 }
 
 } // namespace gui2

Modified: trunk/src/gui/dialogs/mp_cmd_wrapper.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/mp_cmd_wrapper.hpp?rev=48898&r1=48897&r2=48898&view=diff
==============================================================================
--- trunk/src/gui/dialogs/mp_cmd_wrapper.hpp (original)
+++ trunk/src/gui/dialogs/mp_cmd_wrapper.hpp Sun Mar 13 20:18:31 2011
@@ -24,7 +24,15 @@
 class tmp_cmd_wrapper : public tdialog
 {
 public:
+
+       /**
+        * Constructor.
+        *
+        * The text which shows the selected user.
+        */
        tmp_cmd_wrapper(const t_string& user);
+
+       /***** ***** ***** setters / getters for members ***** ****** *****/
 
        const std::string& message() const { return message_; }
        const std::string& reason() const { return reason_; }
@@ -32,20 +40,20 @@
 
 private:
 
-       /** Inherited from tdialog, implemented by REGISTER_DIALOG. */
-       virtual const std::string& window_id() const;
+       /** The message to send to another user. */
+       std::string message_;
+
+       /** The reason for an action; kick, ban. */
+       std::string reason_;
+
+       /** The duration of a ban. */
+       std::string time_;
 
        /** Inherited from tdialog. */
        void pre_show(CVideo& video, twindow& window);
 
-       /** Inherited from tdialog. */
-       void post_show(twindow& window);
-
-       std::string message_;
-       std::string reason_;
-       std::string time_;
-
-       t_string user_;
+       /** Inherited from tdialog, implemented by REGISTER_DIALOG. */
+       virtual const std::string& window_id() const;
 };
 
 } // namespace gui2


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to