mail[Wesnoth-commits] r36534 - in /trunk/src/gui/dialogs: lobby_main.cpp 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 02, 2009 - 21:32:
Author: ilor
Date: Thu Jul  2 21:32:45 2009
New Revision: 36534

URL: http://svn.gna.org/viewcvs/wesnoth?rev=36534&view=rev
Log:
WIP on the new lobby dialog

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

Modified: trunk/src/gui/dialogs/lobby_main.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/lobby_main.cpp?rev=36534&r1=36533&r2=36534&view=diff
==============================================================================
--- trunk/src/gui/dialogs/lobby_main.cpp (original)
+++ trunk/src/gui/dialogs/lobby_main.cpp Thu Jul  2 21:32:45 2009
@@ -17,11 +17,21 @@
 #include "gui/dialogs/field.hpp"
 
 #include "gui/widgets/listbox.hpp"
+#include "gui/widgets/text_box.hpp"
 #include "foreach.hpp"
+#include "log.hpp"
+#include "network.hpp"
+
+#include <boost/bind.hpp>
+
+static lg::log_domain log_network("network");
+#define LOG_NW LOG_STREAM(info, log_network)
+#define ERR_NW LOG_STREAM(err, log_network)
 
 namespace gui2 {
 
 tlobby_main::tlobby_main()
+: gamelist_(NULL), chat_log_(NULL)
 {
 }
 
@@ -54,9 +64,83 @@
 
 void tlobby_main::pre_show(CVideo& /*video*/, twindow& window)
 {
-       gamelist_ =
-               dynamic_cast<tlistbox*>(window.find_widget("game_list", 
false));
+       gamelist_ = dynamic_cast<tlistbox*>(window.find_widget("game_list", 
false));
        VALIDATE(gamelist_, missing_widget("game_list"));
+
+       chat_log_ = dynamic_cast<ttext_box*>(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));
+}
+
+void tlobby_main::network_handler()
+{
+       config data;
+       try {
+               const network::connection sock = network::receive_data(data);
+               if(sock) {
+                       process_network_data(data);
+               }
+       } catch(network::error& e) {
+               ERR_NW << "caught network::error in network_handler: " << 
e.message << "\n";
+               throw;
+       }
+}
+
+void tlobby_main::process_network_data(const config &data)
+{
+       if (const config &c = data.child("error")) {
+               throw network::error(c["message"]);
+       } else if (const config &c = data.child("message")) {
+               process_message(c);
+       } else if (const config &c = data.child("whisper")) {
+               process_message(c, true);
+       } else if(data.child("gamelist")) {
+               process_gamelist(c);
+       } else if (const config &c = data.child("gamelist_diff")) {
+               process_gamelist_diff(c);
+       } else if (const config &c = data.child("room_join")) {
+               process_room_join(c);
+       } else if (const config &c = data.child("room_part")) {
+               process_room_part(c);
+       } else if (const config &c = data.child("room_query_response")) {
+               process_room_query_response(c);
+       }
+}
+
+void tlobby_main::process_message(const config &data, bool whisper /*= 
false*/)
+{
+       const 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;
+       chat_log_->set_value(chat_log_->text() + "\n" + ss.str());
+}
+
+void tlobby_main::process_gamelist(const config &data)
+{
+}
+
+void tlobby_main::process_gamelist_diff(const config &data)
+{
+}
+
+void tlobby_main::process_room_join(const config &data)
+{
+}
+
+void tlobby_main::process_room_part(const config& data)
+{
+}
+
+void tlobby_main::process_room_query_response(const config &data)
+{
 }
 
 } // 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=36534&r1=36533&r2=36534&view=diff
==============================================================================
--- trunk/src/gui/dialogs/lobby_main.hpp (original)
+++ trunk/src/gui/dialogs/lobby_main.hpp Thu Jul  2 21:32:45 2009
@@ -22,6 +22,7 @@
 namespace gui2 {
 
 class tlistbox;
+class ttext_box;
 
 class tlobby_main : public tdialog
 {
@@ -30,6 +31,25 @@
 
        void update_gamelist(const config& cfg);
 private:
+       /**
+        * Network polling callback
+        */
+       void network_handler();
+
+       void process_network_data(const config& data);
+
+       void process_message(const config& data, bool whisper = false);
+
+       void process_gamelist(const config& data);
+
+       void process_gamelist_diff(const config& data);
+
+       void process_room_join(const config& data);
+
+       void process_room_part(const config& data);
+
+       void process_room_query_response(const config& data);
+
        /** Inherited from tdialog. */
        twindow* build_window(CVideo& video);
 
@@ -37,6 +57,8 @@
        void pre_show(CVideo& video, twindow& window);
 
        tlistbox* gamelist_;
+
+       ttext_box* chat_log_;
 };
 
 } // namespace gui2




Related Messages


Powered by MHonArc, Updated Thu Jul 02 23:40:36 2009