Revision: 1465
          http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=1465&view=rev
Author:   rorthomas
Date:     2010-07-19 19:45:43 +0000 (Mon, 19 Jul 2010)

Log Message:
-----------
added stream registration results
added new MP gui
fixed runtime condition crash when it tried to the beamfactory before its 
initialization

Modified Paths:
--------------
    trunk/source/main/BeamFactory.cpp
    trunk/source/main/ChatSystem.cpp
    trunk/source/main/NetworkStreamManager.cpp
    trunk/source/main/RoR.list
    trunk/source/main/RoRFrameListener.cpp
    trunk/source/main/RoRFrameListener.h
    trunk/source/main/Streamable.cpp
    trunk/source/main/Streamable.h
    trunk/source/main/StreamableFactory.h
    trunk/source/main/network.cpp

Added Paths:
-----------
    trunk/source/main/gui_mp.cpp
    trunk/source/main/gui_mp.h

Modified: trunk/source/main/BeamFactory.cpp
===================================================================
--- trunk/source/main/BeamFactory.cpp   2010-07-19 18:17:14 UTC (rev 1464)
+++ trunk/source/main/BeamFactory.cpp   2010-07-19 19:45:43 UTC (rev 1465)
@@ -138,6 +138,11 @@
        if(!CACHE.checkResourceLoaded(filename, group))
        {
                LogManager::getSingleton().logMessage("wont add remote stream 
(truck not existing): '"+filename+"'");
+
+               // add 0 to the map so we know its stream is existing but not 
usable for us
+               std::map < int, std::map < unsigned int, Beam *> > &streamables 
= getStreams();
+               streamables[reg->sourceid][reg->streamid] = 0;
+
                return 0;
        }
 

Modified: trunk/source/main/ChatSystem.cpp
===================================================================
--- trunk/source/main/ChatSystem.cpp    2010-07-19 18:17:14 UTC (rev 1464)
+++ trunk/source/main/ChatSystem.cpp    2010-07-19 19:45:43 UTC (rev 1465)
@@ -32,6 +32,10 @@
 #include "utils.h"
 #include "PlayerColours.h"
 
+#ifdef USE_MYGUI
+#include "gui_mp.h"
+#endif  // USE_MYGUI
+
 using namespace Ogre;
 
 ///////////////////////////////////
@@ -81,81 +85,10 @@
 {
        if(!net) return;
 
-       LOCKSTREAMS();
-
-       std::map < int, std::map < unsigned int, ChatSystem *> > &streamables = 
getStreams();
-       std::map < int, std::map < unsigned int, ChatSystem *> >::iterator it1;
-
-       // the player itself
-       String oname = "tracks/MPPlayerList/Player0";
-       String colname = "tracks/MPPlayerList/Player0/Colour";
-       TextAreaOverlayElement *te = 
(TextAreaOverlayElement*)OverlayManager::getSingleton().getOverlayElement(oname);
-       TextAreaOverlayElement *tec = 
(TextAreaOverlayElement*)OverlayManager::getSingleton().getOverlayElement(colname);
-#ifdef USE_SOCKETW
-       if(te && tec)
-       {
-               user_info_t *c = net->getLocalUserData();
-               if(c)
-               {
-                       try
-                       {
-                               UTFString username = tryConvertUTF(c->username);
-                               te->setCaption(username);
-
-                               String matName = 
PlayerColours::getSingleton().getColourMaterial(c->colournum);
-                               tec->setMaterialName(matName);
-                               if(c->authstatus & AUTH_ADMIN)
-                                       te->setColour(ColourValue(1,0,0));
-                               else if(c->authstatus & AUTH_RANKED)
-                                       te->setColour(ColourValue(0,1,0));
-                               else
-                                       te->setColour(ColourValue::Black);
-
-
-                       } catch(...)
-                       {
-                       }
-               }
-       }
-
-       int num=1;
-       for(it1=streamables.begin(); it1!=streamables.end();it1++)
-       {
-               if(it1->second.size() == 0) continue;
-
-               client_t *c = net->getClientInfo(it1->first);
-               if(!c) continue;
-
-               try
-               {
-                       UTFString username = tryConvertUTF(c->user.username);
-
-                       String plstr = StringConverter::toString(num) + ": " + 
ColoredTextAreaOverlayElement::StripColors(username);
-
-                       String oname = "tracks/MPPlayerList/Player" + 
StringConverter::toString(num);
-                       String colname = "tracks/MPPlayerList/Player"+ 
StringConverter::toString(num)+"/Colour";
-                       te = 
(TextAreaOverlayElement*)OverlayManager::getSingleton().getOverlayElement(oname);
-                       tec = 
(TextAreaOverlayElement*)OverlayManager::getSingleton().getOverlayElement(colname);
-                       if(!te || !tec) break;
-                       te->setCaption(plstr);
-                       String matName = 
PlayerColours::getSingleton().getColourMaterial(c->user.colournum);
-                       tec->setMaterialName(matName);
-                       if(c->user.authstatus & AUTH_ADMIN)
-                               te->setColour(ColourValue(1,0,0));
-                       else if(c->user.authstatus & AUTH_RANKED)
-                               te->setColour(ColourValue(0,1,0));
-                       else
-                               te->setColour(ColourValue::Black);
-
-               } catch(...)
-               {
-               }
-
-               num++;
-       }
-#endif //SOCKETW
-
-       UNLOCKSTREAMS();
+#ifdef USE_MYGUI
+       // TODO: we need to do this upon changes only, not all the time
+       GUI_Multiplayer::getSingleton().update();
+#endif // USE_MYGUI
 }
 
 ChatSystem *ChatSystemFactory::getFirstChatSystem()

Modified: trunk/source/main/NetworkStreamManager.cpp
===================================================================
--- trunk/source/main/NetworkStreamManager.cpp  2010-07-19 18:17:14 UTC (rev 
1464)
+++ trunk/source/main/NetworkStreamManager.cpp  2010-07-19 19:45:43 UTC (rev 
1465)
@@ -64,6 +64,14 @@
        stream->setSourceID(mysourceid);
        stream->setStreamID(streamid);
 
+       // add IDs to registration
+       reg->origin_sourceid = mysourceid;
+       reg->origin_streamid = streamid;
+       reg->status = 0;
+
+       // tell the stream that its a local stream (an origin)
+       stream->isOrigin = true;
+
        // add new stream map to the streams map
        if(streams.find(mysourceid) == streams.end())
                streams[mysourceid] = std::map < unsigned int, Streamable *>();

Modified: trunk/source/main/RoR.list
===================================================================
--- trunk/source/main/RoR.list  2010-07-19 18:17:14 UTC (rev 1464)
+++ trunk/source/main/RoR.list  2010-07-19 19:45:43 UTC (rev 1465)
@@ -1,5 +1,6 @@
 set (HEADER_FILES
   gui_friction.h
+  gui_mp.h
   gui_inputmanager.h
   gui_manager.h
   gui_menu.h
@@ -118,6 +119,7 @@
 )
 set (SOURCE_FILES
   gui_friction.cpp
+  gui_mp.cpp
   gui_inputmanager.cpp
   gui_manager.cpp
   gui_menu.cpp
@@ -247,6 +249,8 @@
 SOURCE_GROUP("GUI" FILES
   gui_friction.cpp
   gui_friction.h
+  gui_mp.cpp
+  gui_mp.h
   gui_inputmanager.cpp
   gui_inputmanager.h
   gui_manager.cpp

Modified: trunk/source/main/RoRFrameListener.cpp
===================================================================
--- trunk/source/main/RoRFrameListener.cpp      2010-07-19 18:17:14 UTC (rev 
1464)
+++ trunk/source/main/RoRFrameListener.cpp      2010-07-19 19:45:43 UTC (rev 
1465)
@@ -86,6 +86,7 @@
 #include "gui_manager.h"
 #include "gui_menu.h"
 #include "gui_friction.h"
+#include "gui_mp.h"
 #include "SelectorWindow.h"
 #include "LoadingWindow.h"
 #endif //MYGUI
@@ -773,6 +774,7 @@
        enablePosStor = (SETTINGS.getSetting("Position Storage")=="Yes");
        objectCounter=0;
        hdrListener=0;
+       netPointToUID=-1;
        mDOF=0;
        mDOFDebug=false;
        mouseGrabForce=100000.0f;
@@ -1176,6 +1178,9 @@
                bool connres = net->connect();
 #ifdef USE_MYGUI
                LoadingWindow::get()->hide();
+
+               new GUI_Multiplayer(net);
+
 #endif //USE_MYGUI
                if(!connres)
                {
@@ -7911,3 +7916,9 @@
 {
        loading_state = value;
 }
+
+void RoRFrameListener::setNetPointToUID(int uid)
+{
+       // TODO: setup arrow
+       netPointToUID = uid;
+}

Modified: trunk/source/main/RoRFrameListener.h
===================================================================
--- trunk/source/main/RoRFrameListener.h        2010-07-19 18:17:14 UTC (rev 
1464)
+++ trunk/source/main/RoRFrameListener.h        2010-07-19 19:45:43 UTC (rev 
1465)
@@ -212,6 +212,7 @@
        int interactivemap;
     bool xfire_enabled;
        int externalCameraMode;
+       int netPointToUID;
 
        //    Beam *beam;
        int loading_state;
@@ -336,6 +337,8 @@
                        const Vector3 &position = Vector3::ZERO,
                        const Quaternion &orient = Quaternion::IDENTITY,const 
Vector3 &scale = Vector3::UNIT_SCALE);
        void showspray(bool s);
+       int getNetPointToUID() { return netPointToUID; };
+       void setNetPointToUID(int uid);
 
        Character *person;
        ChatSystem *netChat;

Modified: trunk/source/main/Streamable.cpp
===================================================================
--- trunk/source/main/Streamable.cpp    2010-07-19 18:17:14 UTC (rev 1464)
+++ trunk/source/main/Streamable.cpp    2010-07-19 19:45:43 UTC (rev 1465)
@@ -32,7 +32,7 @@
 
 using namespace Ogre;
 
-Streamable::Streamable()
+Streamable::Streamable() : isOrigin(false)
 {
        //NetworkStreamManager::getSingleton().addStream(this);
        pthread_mutex_init(&recv_work_mutex, NULL);
@@ -145,3 +145,16 @@
 {
        pthread_mutex_unlock(&recv_work_mutex);
 }
+
+void Streamable::addStreamRegistrationResult(int sourceid, stream_register_t 
reg)
+{
+       mStreamableResults[sourceid] = reg;
+}
+
+int Streamable::getStreamRegisterResultForSource(int sourceid, 
stream_register_t *reg)
+{
+       if(mStreamableResults.find(sourceid) == mStreamableResults.end())
+               return 1;
+       *reg = mStreamableResults[sourceid];
+       return 0;
+}

Modified: trunk/source/main/Streamable.h
===================================================================
--- trunk/source/main/Streamable.h      2010-07-19 18:17:14 UTC (rev 1464)
+++ trunk/source/main/Streamable.h      2010-07-19 19:45:43 UTC (rev 1465)
@@ -51,6 +51,11 @@
        void setStreamID(unsigned int id) { this->streamid=id; };
        void setSourceID(unsigned int id) { this->sourceid=id; };
 
+       bool getIsOrigin() { return isOrigin; };
+
+       void addStreamRegistrationResult(int source, stream_register_t reg);
+       int getStreamRegisterResultForSource(int sourceid, stream_register_t 
*reg);
+
 protected:
        // constructor/destructor are protected, so you cannot create instances 
without using the factory
        Streamable();
@@ -89,6 +94,11 @@
 
        void lockReceiveQueue();
        void unlockReceiveQueue();
+
+private:
+       std::map < int, stream_register_t > mStreamableResults;
+       bool isOrigin;
+
 };
 
 #endif //STREAMABLE_H__

Modified: trunk/source/main/StreamableFactory.h
===================================================================
--- trunk/source/main/StreamableFactory.h       2010-07-19 18:17:14 UTC (rev 
1464)
+++ trunk/source/main/StreamableFactory.h       2010-07-19 19:45:43 UTC (rev 
1465)
@@ -132,7 +132,17 @@
                        {
                                // add it to the streams list
                                
NetworkStreamManager::getSingleton().addRemoteStream(s, reg.sourceid, 
reg.streamid);
+                               reg.reg.status = 1;
+                       } else
+                       {
+                               // error creating stream, tell the sourceid 
that it failed
+                               reg.reg.status = -1;
                        }
+                       // fixup the registration information
+                       reg.reg.origin_sourceid = reg.sourceid;
+                       reg.reg.origin_streamid = reg.streamid;
+
+                       stream_creation_results.push_back(reg);
                        stream_registrations.pop_front();
                }
                // then deletions:
@@ -169,6 +179,111 @@
                }
        }
 
+       bool checkStreamsOK(int sourceid)
+       {
+               // walk client and the streams and checks for errors
+               typename std::map < int, std::map < unsigned int, X *> > 
&streamables = getStreams();
+               typename std::map < int, std::map < unsigned int, X *> 
>::iterator it1;
+               typename std::map < unsigned int, X *>::iterator it2;
+
+               bool ok = true;
+               for(it1=streamables.begin(); it1!=streamables.end();it1++)
+               {
+                       if(it1->first != sourceid) continue;
+                       for(it2=it1->second.begin(); 
it2!=it1->second.end();it2++)
+                       {
+                               if(it2->second == 0)
+                               {
+                                       ok = false;
+                                       break;
+                               }
+                       }
+                       break;
+               }
+               return ok;
+       }
+
+       bool checkStreamsRemoteOK(int sourceid)
+       {
+               // walk client and the streams and checks for errors
+               typename std::map < int, std::map < unsigned int, X *> > 
&streamables = getStreams();
+               typename std::map < int, std::map < unsigned int, X *> 
>::iterator it1;
+               typename std::map < unsigned int, X *>::iterator it2;
+
+               bool ok = false;
+               for(it1=streamables.begin(); it1!=streamables.end();it1++)
+               {
+                       for(it2=it1->second.begin(); 
it2!=it1->second.end();it2++)
+                       {
+                               if(!it2->second)
+                                       continue;
+                               if(!it2->second->getIsOrigin())
+                                       continue;
+                               stream_register_t reg;
+                               reg.status = -2;
+                               int res = 
it2->second->getStreamRegisterResultForSource(sourceid, &reg);
+                               if(!res)
+                               {
+                                       if(reg.status == 1)
+                                               ok = true;
+                               }
+                               break;
+                       }
+                       break;
+               }
+               return ok;
+       }
+
+       int getStreamRegistrationResults(std::deque < stream_reg_t > 
*net_results)
+       {
+               LOCKSTREAMS();
+               // move list entries over to the list in the networking thread
+               int res = 0;
+               while (!stream_creation_results.empty())
+               {
+                       stream_reg_t reg = stream_creation_results.front();
+                       net_results->push_back(reg);
+                       stream_creation_results.pop_front();
+                       res++;
+               }
+               UNLOCKSTREAMS();
+               return res;
+       }
+
+       int addStreamRegistrationResults(int sourceid, stream_register_t *reg)
+       {
+               typename std::map < int, std::map < unsigned int, X *> > 
&streamables = getStreams();
+               typename std::map < int, std::map < unsigned int, X *> 
>::iterator it1;
+               typename std::map < unsigned int, X *>::iterator it2;
+
+               int res = 0;
+               for(it1=streamables.begin(); it1!=streamables.end();it1++)
+               {
+                       for(it2=it1->second.begin(); 
it2!=it1->second.end();it2++)
+                       {
+                               if(!it2->second)
+                                       continue;
+                               if(!it2->second->getIsOrigin())
+                                       continue;
+                               int sid = it2->second->getSourceID();
+                               int stid = it2->second->getStreamID();
+                               // only use our locally created streams
+                               if(stid == reg->origin_streamid)
+                               {
+                                       
it2->second->addStreamRegistrationResult(sourceid, *reg);
+                                       if(reg->status == 1)
+                                               
LogManager::getSingleton().logMessage("Client " + 
StringConverter::toString(sourceid) + " successfully loaded stream " + 
StringConverter::toString(reg->origin_streamid) + " with name '" + reg->name + 
"', result code: " + StringConverter::toString(reg->status));
+                                       else
+                                               
LogManager::getSingleton().logMessage("Client " + 
StringConverter::toString(sourceid) + " could not load stream " + 
StringConverter::toString(reg->origin_streamid) + " with name '" + reg->name + 
"', result code: " + StringConverter::toString(reg->status));
+                                       res++;
+                                       break;
+                               }
+                       }
+                       break;
+               }
+               return res;
+       }
+
 protected:
        static T* ms_Singleton;
        pthread_mutex_t stream_reg_mutex;
@@ -176,6 +291,7 @@
 
        std::deque < stream_reg_t > stream_registrations;
        std::deque < stream_del_t > stream_deletions;
+       std::deque < stream_reg_t > stream_creation_results;
 
        std::map < int, std::map < unsigned int, X *> > &getStreams()
        {

Added: trunk/source/main/gui_mp.cpp
===================================================================
--- trunk/source/main/gui_mp.cpp                                (rev 0)
+++ trunk/source/main/gui_mp.cpp        2010-07-19 19:45:43 UTC (rev 1465)
@@ -0,0 +1,332 @@
+/*
+This source file is part of Rigs of Rods
+Copyright 2005,2006,2007,2008,2009 Pierre-Michel Ricordel
+Copyright 2007,2008,2009 Thomas Fischer
+
+For more information, see http://www.rigsofrods.com/
+
+Rigs of Rods is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License version 3, as 
+published by the Free Software Foundation.
+
+Rigs of Rods is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Rigs of Rods.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+// created by Thomas Fischer thomas{AT}thomasfischer{DOT}biz, 7th of September 
2009
+
+#ifdef USE_MYGUI
+
+#include "gui_mp.h"
+#include "gui_manager.h"
+#include "Settings.h"
+
+#include "language.h"
+#include "RoRFrameListener.h"
+#include "network.h"
+#include "PlayerColours.h"
+#include "BeamFactory.h"
+
+template<> GUI_Multiplayer * Singleton< GUI_Multiplayer >::ms_Singleton = 0;
+GUI_Multiplayer* GUI_Multiplayer::getSingletonPtr(void)
+{
+       return ms_Singleton;
+}
+GUI_Multiplayer& GUI_Multiplayer::getSingleton(void)
+{
+       assert( ms_Singleton );  return ( *ms_Singleton );
+}
+
+GUI_Multiplayer::GUI_Multiplayer(Network *_net) : net(_net), msgwin(0)
+{
+       // tooltip window
+       tooltipPanel = 
MyGUI::Gui::getInstance().createWidget<MyGUI::Widget>("PanelSmall", 0, 0, 200, 
20,  MyGUI::Align::Default, "ToolTip");
+       tooltipText = 
tooltipPanel->createWidget<MyGUI::StaticText>("StaticText", 4, 2, 200, 16,  
MyGUI::Align::Default);
+       tooltipText->setFontName("VeraMono");
+       //tooltipPanel->setAlpha(0.9f);
+       tooltipText->setFontHeight(16);
+       tooltipPanel->setVisible(false);
+       
+       // message window
+       msgwin = 
MyGUI::Gui::getInstance().createWidget<MyGUI::Window>("WindowCSX", 0, 0, 400, 
300,  MyGUI::Align::Center, "Overlapped");
+       msgwin->setCaption(_L("Player Information"));
+       msgtext = msgwin->createWidget<MyGUI::Edit>("EditStretch", 0, 0, 400, 
300,  MyGUI::Align::Default, "helptext");
+       msgtext->setCaption("");
+       msgtext->setEditWordWrap(true);
+       msgtext->setEditStatic(true);
+       msgwin->setVisible(false);
+
+       // now the main GUI
+       MyGUI::IntSize gui_area = 
GUIManager::getSingleton().getGUI()->getViewSize();
+       int x=gui_area.width - 200, y=30, lineheight=16;
+       mpPanel = 
MyGUI::Gui::getInstance().createWidget<MyGUI::Widget>("FlowContainer", x, y, 
200, gui_area.height,  MyGUI::Align::Default, "Main");
+       mpPanel->setVisible(true);
+
+       y=0;
+       for(int i = 0; i < MAX_PEERS + 1; i++) // plus 1 for local entry
+       {
+               x=100; // space for icons
+               player_row_t *row = &player_rows[i];
+               row->playername = 
mpPanel->createWidget<MyGUI::StaticText>("StaticText", x, y+1, 200, lineheight, 
 MyGUI::Align::Default, "Main");
+               row->playername->setCaption("Player " + 
StringConverter::toString(i));
+               row->playername->setFontName("VeraMoBd");
+               row->playername->setUserString("tooltip", "user name");
+               row->playername->eventToolTip = MyGUI::newDelegate(this, 
&GUI_Multiplayer::openToolTip);
+               row->playername->setNeedToolTip(true);
+               row->playername->setVisible(false);
+               row->playername->setFontHeight(lineheight);
+               row->playername->setAlpha(1);
+
+               x -= 18;
+               row->flagimg = 
mpPanel->createWidget<MyGUI::StaticImage>("StaticImage", x, y + 3, 16, 11,  
MyGUI::Align::Default, "Main");
+               row->flagimg->setUserString("tooltip", "user country");
+               row->flagimg->eventToolTip = MyGUI::newDelegate(this, 
&GUI_Multiplayer::openToolTip);
+               row->flagimg->setNeedToolTip(true);
+               row->flagimg->setVisible(false);
+
+               x -= 18;
+               row->statimg = 
mpPanel->createWidget<MyGUI::StaticImage>("StaticImage", x, y, 16, 16,  
MyGUI::Align::Default, "Main");
+               row->statimg->setUserString("tooltip", "user authentication 
level");
+               row->statimg->eventToolTip = MyGUI::newDelegate(this, 
&GUI_Multiplayer::openToolTip);
+               row->statimg->setNeedToolTip(true);
+               row->statimg->setVisible(false);
+
+               x -= 18;
+               row->userTruckOKImg = 
mpPanel->createWidget<MyGUI::StaticImage>("StaticImage", x, y, 16, 16,  
MyGUI::Align::Default, "Main");
+               row->userTruckOKImg->setUserString("tooltip", "truck loading 
state");
+               row->userTruckOKImg->eventToolTip = MyGUI::newDelegate(this, 
&GUI_Multiplayer::openToolTip);
+               row->userTruckOKImg->setNeedToolTip(true);
+               row->userTruckOKImg->setVisible(false);
+               row->userTruckOKImg->eventMouseButtonClick = 
MyGUI::newDelegate(this, &GUI_Multiplayer::clickInfoIcon);
+
+               x -= 18;
+               row->userTruckOKRemoteImg = 
mpPanel->createWidget<MyGUI::StaticImage>("StaticImage", x, y, 16, 16,  
MyGUI::Align::Default, "Main");
+               row->userTruckOKRemoteImg->setUserString("tooltip", "remote 
truck loading state");
+               row->userTruckOKRemoteImg->eventToolTip = 
MyGUI::newDelegate(this, &GUI_Multiplayer::openToolTip);
+               row->userTruckOKRemoteImg->setNeedToolTip(true);
+               row->userTruckOKRemoteImg->setVisible(false);
+               row->userTruckOKRemoteImg->eventMouseButtonClick = 
MyGUI::newDelegate(this, &GUI_Multiplayer::clickInfoIcon);
+               
+               x -= 18;
+               row->usergoimg = 
mpPanel->createWidget<MyGUI::StaticImage>("StaticImage", x, y, 16, 16,  
MyGUI::Align::Default, "Main");
+               row->usergoimg->setUserString("num", 
StringConverter::toString(i));
+               row->usergoimg->setUserString("tooltip", "go to user");
+               row->usergoimg->setImageTexture("user_go.png");
+               row->usergoimg->eventToolTip = MyGUI::newDelegate(this, 
&GUI_Multiplayer::openToolTip);
+               row->usergoimg->setNeedToolTip(true);
+               row->usergoimg->setVisible(false);
+               row->usergoimg->eventMouseButtonClick = 
MyGUI::newDelegate(this, &GUI_Multiplayer::clickUserGoIcon);
+
+               /*
+               img = 
MyGUI::Gui::getInstance().createWidget<MyGUI::StaticImage>("StaticImage", x-36, 
y, 16, 16,  MyGUI::Align::Default, "Overlapped");
+               img->setImageTexture("information.png");
+               img->eventMouseButtonClick = MyGUI::newDelegate(this, 
&GUI_Multiplayer::clickInfoIcon);
+               img->eventToolTip = MyGUI::newDelegate(this, 
&GUI_Multiplayer::openToolTip);
+               img->setNeedToolTip(true);
+               img->setUserString("info", StringConverter::toString(i));
+               img->setUserString("tooltip", "information about the user");
+               */
+
+               y += lineheight;
+       }
+}
+
+GUI_Multiplayer::~GUI_Multiplayer()
+{
+}
+
+void GUI_Multiplayer::updateSlot(player_row_t *row, user_info_t *c, bool self)
+{
+       int x = 100;
+       int y = row->playername->getPosition().top;
+       // name
+       row->playername->setCaption(c->username);
+       Ogre::ColourValue col = 
PlayerColours::getSingleton().getColour(c->colournum);
+       row->playername->setTextColour(MyGUI::Colour(col.r, col.g, col.b, 
col.a));
+       row->playername->setVisible(true);
+       x -= 18;
+       
+       // flag
+       Ogre::vector<Ogre::String>::type parts = 
StringUtil::split(string(c->language), "_");
+       if(parts.size() == 2)
+       {
+               String lang = parts[1];
+               StringUtil::toLowerCase(lang);
+               row->flagimg->setImageTexture(lang + ".png");
+               row->flagimg->setUserString("tooltip", "user language: " + 
parts[0] + " user country: " + parts[1]);
+               row->flagimg->setVisible(true);
+               row->flagimg->setPosition(x, y);
+               x -= 18;
+       } else
+       {
+               row->flagimg->setVisible(false);
+       }
+       
+       // auth
+       if(c->authstatus == AUTH_NONE)
+       {
+               row->statimg->setVisible(false);
+       } else if (c->authstatus & AUTH_ADMIN)
+       {
+               row->statimg->setVisible(true);
+               row->statimg->setImageTexture("flag_red.png");
+               row->statimg->setUserString("tooltip", "Server Administrator");
+               row->statimg->setPosition(x, y);
+               x -= 18;
+       } else if (c->authstatus & AUTH_MOD)
+       {
+               row->statimg->setVisible(true);
+               row->statimg->setImageTexture("flag_blue.png");
+               row->statimg->setUserString("tooltip", "Server Moderator");
+               row->statimg->setPosition(x, y);
+               x -= 18;
+       } else if (c->authstatus & AUTH_RANKED)
+       {
+               row->statimg->setVisible(true);
+               row->statimg->setImageTexture("flag_green.png");
+               row->statimg->setUserString("tooltip", "ranked user");
+               row->statimg->setPosition(x, y);
+               x -= 18;
+       }
+
+       // truck ok image
+       if(!self)
+       {
+               row->userTruckOKImg->setVisible(true);
+               row->userTruckOKRemoteImg->setVisible(true);
+               row->userTruckOKImg->setUserString("uid", 
StringConverter::toString(c->uniqueid));
+               row->userTruckOKRemoteImg->setUserString("uid", 
StringConverter::toString(c->uniqueid));
+               row->userTruckOKImg->setPosition(x, y);
+               x -= 18;
+               row->userTruckOKRemoteImg->setPosition(x, y);
+               x -= 18;
+
+               bool ok = 
BeamFactory::getSingleton().checkStreamsOK(c->uniqueid);
+               if(ok)
+               {
+                       row->userTruckOKImg->setImageTexture("accept.png");
+                       row->userTruckOKImg->setUserString("tooltip", "Truck 
loaded correctly, no errors");
+               } else
+               {
+                       row->userTruckOKImg->setImageTexture("cancel.png");
+                       row->userTruckOKImg->setUserString("tooltip", "Truck 
loading errors");
+               }
+
+               bool rok = 
BeamFactory::getSingleton().checkStreamsRemoteOK(c->uniqueid);
+               if(rok)
+               {
+                       
row->userTruckOKRemoteImg->setImageTexture("accept.png");
+                       row->userTruckOKRemoteImg->setUserString("tooltip", 
"Remote Truck loaded correctly, no errors");
+               } else
+               {
+                       
row->userTruckOKRemoteImg->setImageTexture("cancel.png");
+                       row->userTruckOKRemoteImg->setUserString("tooltip", 
"Remote Truck loading errors");
+               }
+       } else
+       {
+               row->userTruckOKImg->setVisible(false);
+               row->userTruckOKRemoteImg->setVisible(false);
+       }
+       
+       // user go img
+       if(!self)
+       {
+               row->usergoimg->setVisible(true);
+               row->usergoimg->setPosition(x, y);
+               x -= 18;
+               row->usergoimg->setUserString("uid", 
StringConverter::toString(c->uniqueid));
+               if (eflsingleton && eflsingleton->getNetPointToUID() == 
c->uniqueid)
+               {
+                       // active for this user
+                       row->usergoimg->setAlpha(1.0f);
+               } else
+               {
+                       // inactive for this user
+                       row->usergoimg->setAlpha(0.4f);
+               }
+       } else
+       {
+               row->usergoimg->setVisible(false);
+       }
+}
+
+int GUI_Multiplayer::update()
+{
+       client_t clients[MAX_PEERS];
+       int slotid = 0;
+       
+       // add local player to first slot always
+       user_info_t *lu = net->getLocalUserData();
+       updateSlot(&player_rows[slotid], lu, true);
+       slotid++;
+
+       // add remote players
+       int res = net->getClientInfos(clients);
+       if(res) return 1;
+       for(int i = 0; i < MAX_PEERS; i++, slotid++)
+       {
+               client_t *c = &clients[i];
+               player_row_t *row = &player_rows[slotid];
+               if(!c->used)
+               {
+                       row->flagimg->setVisible(false);
+                       row->playername->setVisible(false);
+                       row->statimg->setVisible(false);
+                       row->usergoimg->setVisible(false);
+                       row->userTruckOKImg->setVisible(false);
+                       row->userTruckOKRemoteImg->setVisible(false);
+                       continue;
+               }
+               try
+               {
+                       updateSlot(row, &c->user, false);
+               } catch(...)
+               {
+                       continue;
+               }
+       }
+       return 0;
+}
+
+
+void GUI_Multiplayer::clickUserGoIcon(MyGUI::WidgetPtr sender)
+{
+       int uid = StringConverter::parseInt(sender->getUserString("uid"));
+       if (!eflsingleton)
+               return;
+       if(eflsingleton->getNetPointToUID() == uid)
+               eflsingleton->setNetPointToUID(-1);
+       else
+               eflsingleton->setNetPointToUID(uid);
+}
+
+void GUI_Multiplayer::clickInfoIcon(MyGUI::WidgetPtr sender)
+{
+       msgtext->setCaption("FOOBAR: "+sender->getUserString("info"));
+       msgwin->setVisible(true);
+}
+
+void GUI_Multiplayer::openToolTip(MyGUI::WidgetPtr sender, const 
MyGUI::ToolTipInfo &t)
+{
+       if(t.type == MyGUI::ToolTipInfo::Show)
+       {
+               string txt = sender->getUserString("tooltip");
+               if(!txt.empty())
+               {
+                       tooltipText->setCaption(txt);
+                       tooltipPanel->setVisible(true);
+                       tooltipPanel->setPosition(t.point - 
MyGUI::IntPoint(210, 8));
+               }
+       } else if(t.type == MyGUI::ToolTipInfo::Hide)
+       {
+               tooltipPanel->setVisible(false);
+       }
+}
+
+#endif //MYGUI
+

Added: trunk/source/main/gui_mp.h
===================================================================
--- trunk/source/main/gui_mp.h                          (rev 0)
+++ trunk/source/main/gui_mp.h  2010-07-19 19:45:43 UTC (rev 1465)
@@ -0,0 +1,73 @@
+/*
+This source file is part of Rigs of Rods
+Copyright 2005,2006,2007,2008,2009 Pierre-Michel Ricordel
+Copyright 2007,2008,2009 Thomas Fischer
+
+For more information, see http://www.rigsofrods.com/
+
+Rigs of Rods is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License version 3, as 
+published by the Free Software Foundation.
+
+Rigs of Rods is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Rigs of Rods.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+// created by Thomas Fischer thomas{AT}thomasfischer{DOT}biz, 18th of July 2010
+
+#ifdef USE_MYGUI 
+
+#ifndef GUI_MP_H__
+#define GUI_MP_H__
+
+#include <MyGUI.h>
+#include "OgreSingleton.h"
+#include "OgrePrerequisites.h"
+#include "Beam.h"
+
+class Collisions;
+
+class GUI_Multiplayer : public Ogre::Singleton< GUI_Multiplayer >, public 
MemoryAllocatedObject
+{
+public:
+       GUI_Multiplayer(Network *net);
+       ~GUI_Multiplayer();
+       static GUI_Multiplayer& getSingleton(void);
+       static GUI_Multiplayer* getSingletonPtr(void);
+
+       int update();
+protected:
+
+       typedef struct player_row_t {
+               MyGUI::StaticImagePtr flagimg;
+               MyGUI::StaticImagePtr statimg;
+               MyGUI::StaticImagePtr usergoimg;
+               MyGUI::StaticImagePtr userTruckOKImg;
+               MyGUI::StaticImagePtr userTruckOKRemoteImg;
+               MyGUI::StaticTextPtr  playername;
+       } player_row_t;
+       Network *net;
+       MyGUI::WindowPtr msgwin;
+       MyGUI::EditPtr msgtext;
+       MyGUI::WidgetPtr tooltipPanel, mpPanel;
+       MyGUI::StaticTextPtr tooltipText;
+
+       player_row_t player_rows[MAX_PEERS + 1];
+
+       void clickInfoIcon(MyGUI::WidgetPtr sender);
+       void openToolTip(MyGUI::WidgetPtr sender, const MyGUI::ToolTipInfo &t);
+       void clickUserGoIcon(MyGUI::WidgetPtr sender);
+
+       
+       void updateSlot(player_row_t *row, user_info_t *c, bool self);
+};
+
+#endif //GUI_MP_H__
+
+#endif //MYGUI
+

Modified: trunk/source/main/network.cpp
===================================================================
--- trunk/source/main/network.cpp       2010-07-19 18:17:14 UTC (rev 1464)
+++ trunk/source/main/network.cpp       2010-07-19 19:45:43 UTC (rev 1465)
@@ -488,8 +488,21 @@
 
        char *buffer=(char*)ror_malloc(MAX_MESSAGE_LENGTH);
        bool autoDl = (SETTINGS.getSetting("AutoDownload") == "Yes");
+       std::deque < stream_reg_t > streamCreationResults;
        LogManager::getSingleton().logMessage("Receivethread starting");
        // unlimited timeout, important!
+
+       // wait for beamfactory to be existant before doing anything
+       // otherwise you can get runtime conditions
+       while(!BeamFactory::getSingletonPtr())
+       {
+#ifndef WIN32
+                       sleep(1);
+#else
+                       Sleep(1000);
+#endif
+       };
+
        socket.set_timeout(0,0);
        while (!shutdown)
        {
@@ -505,6 +518,17 @@
                        return;
                }
 
+               // check for stream registration errors and notify the remote 
client
+               if(BeamFactory::getSingletonPtr() && 
BeamFactory::getSingletonPtr()->getStreamRegistrationResults(&streamCreationResults))
+               {
+                       while (!streamCreationResults.empty())
+                       {
+                               stream_reg_t r = streamCreationResults.front();
+                               stream_register_t reg = r.reg;
+                               sendmessage(&socket, 
MSG2_STREAM_REGISTER_RESULT, 0, sizeof(stream_register_t), (char *)&reg);
+                               streamCreationResults.pop_front();
+                       }
+               }
 
                // TODO: produce new streamable classes when required
                if(header.command == MSG2_STREAM_REGISTER)
@@ -544,6 +568,12 @@
                        }
                        continue;
                }
+               else if(header.command == MSG2_STREAM_REGISTER_RESULT)
+               {
+                       stream_register_t *reg = (stream_register_t *)buffer;
+                       
BeamFactory::getSingleton().addStreamRegistrationResults(header.source, reg);
+                       LogManager::getSingleton().logMessage(" * received 
stream registration result: " + StringConverter::toString(header.source) + ": 
"+StringConverter::toString(header.streamid));
+               }
                else if(header.command == MSG2_CHAT && header.source == -1)
                {
                        ChatSystem *cs = 
ChatSystemFactory::getSingleton().getFirstChatSystem();


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Rigsofrods-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rigsofrods-devel

Reply via email to