mail[Wesnoth-commits] r36570 - in /trunk: data/gui/default/window/lobby_main.cfg src/gui/dialogs/lobby_main.cpp src/gui/dialogs/lobby_main.hpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by kailoran on July 04, 2009 - 23:20:
Author: ilor
Date: Sat Jul  4 11:39:28 2009
New Revision: 36570

URL: http://svn.gna.org/viewcvs/wesnoth?rev=36570&view=rev
Log:
more WIP on the lobby dialog, very basic chat support

Modified:
    trunk/data/gui/default/window/lobby_main.cfg
    trunk/src/gui/dialogs/lobby_main.cpp
    trunk/src/gui/dialogs/lobby_main.hpp

Modified: trunk/data/gui/default/window/lobby_main.cfg
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/gui/default/window/lobby_main.cfg?rev=36570&r1=36569&r2=36570&view=diff
==============================================================================
--- trunk/data/gui/default/window/lobby_main.cfg (original)
+++ trunk/data/gui/default/window/lobby_main.cfg Sat Jul  4 11:39:28 2009
@@ -186,12 +186,12 @@
                                                        {GAMELISTBOX}
                                                {VERTICAL_SEP}
                                                        {VERTICAL_BEGIN}
-                                                               [text_box]
+                                                               [label]
                                                                        id = 
"chat_log"
                                                                        
definition = "default"
                                                                        label 
= ""
                                                                        
height = 200
-                                                               [/text_box]
+                                                               [/label]
                                                        {VERTICAL_SEP}
                                                                
{HORIZONTAL_BEGIN}
                                                                        
[text_box]

Modified: trunk/src/gui/dialogs/lobby_main.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/lobby_main.cpp?rev=36570&r1=36569&r2=36570&view=diff
==============================================================================
--- trunk/src/gui/dialogs/lobby_main.cpp (original)
+++ trunk/src/gui/dialogs/lobby_main.cpp Sat Jul  4 11:39:28 2009
@@ -21,9 +21,11 @@
 #include "gui/widgets/label.hpp"
 #include "gui/widgets/listbox.hpp"
 #include "gui/widgets/text_box.hpp"
+
 #include "foreach.hpp"
 #include "log.hpp"
 #include "network.hpp"
+#include "game_preferences.hpp"
 
 #include <boost/bind.hpp>
 
@@ -41,9 +43,39 @@
 
 namespace gui2 {
 
+
+void tlobby_main::send_chat_message(const std::string& message, bool 
/*allies_only*/)
+{
+       config data, msg;
+       msg["message"] = message;
+       msg["sender"] = preferences::login();
+       data.add_child("message", msg);
+
+       add_chat_message(time(NULL), preferences::login(), 0, message); 
//local echo
+       network::send_data(data, 0, true);
+}
+
+void tlobby_main::add_chat_message(const time_t& time, const std::string& 
speaker,
+       int /*side*/, const std::string& message, 
events::chat_handler::MESSAGE_TYPE /*type*/)
+{
+       //chat_.add_message(time, speaker, message);
+       //chat_.update_textbox(chat_textbox_);
+       std::stringstream ss;
+       ss << "<" << speaker << "> ";
+       ss << message;
+       LOG_NW << "Message: " << ss.str() << std::endl;
+       chat_log_->set_label(chat_log_->label() + "\n" + ss.str());
+       window_->invalidate_layout();
+}
+
 tlobby_main::tlobby_main()
 : games_(), games_initialized_(false)
 , gamelistbox_(NULL), chat_log_(NULL)
+, window_(NULL), chat_input_(NULL)
+{
+}
+
+tlobby_main::~tlobby_main()
 {
 }
 
@@ -83,6 +115,7 @@
                observe_button->set_callback_mouse_left_click(
                        dialog_callback<tlobby_main, 
&tlobby_main::observe_button_callback>);
        }
+       window_->invalidate_layout();
 }
 
 void tlobby_main::pre_show(CVideo& /*video*/, twindow& window)
@@ -90,10 +123,24 @@
        gamelistbox_ = 
dynamic_cast<tlistbox*>(window.find_widget("game_list", false));
        VALIDATE(gamelistbox_, missing_widget("game_list"));
 
-       chat_log_ = dynamic_cast<ttext_box*>(window.find_widget("chat_log", 
false));
+       chat_log_ = dynamic_cast<tlabel*>(window.find_widget("chat_log", 
false));
        VALIDATE(chat_log_, missing_widget("chat_log"));
 
        
window.set_event_loop_pre_callback(boost::bind(&tlobby_main::network_handler, 
this));
+       window_ = &window;
+
+       tbutton* send_message = 
dynamic_cast<tbutton*>(window.find_widget("send_message", false));
+       VALIDATE(send_message, missing_widget("send_message"));
+       
send_message->set_callback_mouse_left_click(dialog_callback<tlobby_main,
+               &tlobby_main::send_message_button_callback>);
+
+       chat_input_ = 
dynamic_cast<ttext_box*>(window.find_widget("chat_input", false));
+       VALIDATE(chat_input_, missing_widget("chat_input"));
+}
+
+void tlobby_main::post_show(twindow& /*window*/)
+{
+       window_ = NULL;
 }
 
 void tlobby_main::network_handler()
@@ -133,18 +180,13 @@
 
 void tlobby_main::process_message(const config &data, bool /*whisper / *= 
false*/)
 {
-       const std::string& sender = data["sender"];
+       std::string sender = data["sender"];
        const std::string& message = data["message"];
        const std::string& room = data["room"];
-       std::stringstream ss;
-       ss << "<";
        if (!room.empty()) {
-               ss << room << ": ";
-       }
-       ss << sender << "> ";
-       ss << message;
-       LOG_NW << "Message: " << ss.str() << std::endl;
-       //chat_log_->set_value(chat_log_->text() + "\n" + ss.str());
+               sender = room + ": " + sender;
+       }
+       add_chat_message(time(0), sender, 0, message);
 }
 
 void tlobby_main::process_gamelist(const config &data)
@@ -190,4 +232,12 @@
        LOG_NW << "observe_button_callback\n";
 }
 
+void tlobby_main::send_message_button_callback(gui2::twindow &window)
+{
+       const std::string& input = chat_input_->get_value();
+       if (input.empty()) return;
+       chat_handler::do_speak(input);
+       chat_input_->set_value("");
+}
+
 } // namespace gui2

Modified: trunk/src/gui/dialogs/lobby_main.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/lobby_main.hpp?rev=36570&r1=36569&r2=36570&view=diff
==============================================================================
--- trunk/src/gui/dialogs/lobby_main.hpp (original)
+++ trunk/src/gui/dialogs/lobby_main.hpp Sat Jul  4 11:39:28 2009
@@ -17,6 +17,7 @@
 
 #include "gui/dialogs/dialog.hpp"
 #include "config.hpp"
+#include "chat_events.hpp"
 
 class config;
 
@@ -25,13 +26,21 @@
 class tlabel;
 class tlistbox;
 class ttext_box;
+class twindow;
 
-class tlobby_main : public tdialog
+class tlobby_main : public tdialog, private events::chat_handler
 {
 public:
        tlobby_main();
 
+       ~tlobby_main();
+
        void update_gamelist(const config& cfg);
+protected:
+       void send_chat_message(const std::string& message, bool 
/*allies_only*/);
+       void add_chat_message(const time_t& time, const std::string& speaker,
+               int side, const std::string& message,
+               events::chat_handler::MESSAGE_TYPE type = 
events::chat_handler::MESSAGE_PRIVATE);
 private:
        /**
         * Network polling callback
@@ -56,6 +65,8 @@
 
        void observe_button_callback(twindow& window);
 
+       void send_message_button_callback(twindow& window);
+
 
        /** Inherited from tdialog. */
        twindow* build_window(CVideo& video);
@@ -63,13 +74,20 @@
        /** Inherited from tdialog. */
        void pre_show(CVideo& video, twindow& window);
 
+       /** Inherited from tdialog. */
+       void post_show(twindow& window);
+
        config games_;
 
        bool games_initialized_;
 
        tlistbox* gamelistbox_;
 
-       ttext_box* chat_log_;
+       tlabel* chat_log_;
+
+       ttext_box* chat_input_;
+
+       twindow* window_;
 };
 
 } // namespace gui2




Related Messages


Powered by MHonArc, Updated Sun Jul 05 00:40:33 2009