]> git.tdb.fi Git - r2c2.git/blobdiff - source/engineer/engineer.cpp
Add TrainView for viewing the layout from the train's perspective
[r2c2.git] / source / engineer / engineer.cpp
index b6651342f2137bd24a58b94b5de0e0da21c913b2..59aaeeca9f9e3aef5677ccc5196c7a0d6b57a1a1 100644 (file)
@@ -5,6 +5,7 @@ Copyright © 2006-2010 Mikkosoft Productions, Mikko Rasa
 Distributed under the GPL
 */
 
+#include <algorithm>
 #include <cmath>
 #include <cstdlib>
 #include <limits>
@@ -33,6 +34,7 @@ Distributed under the GPL
 #include "mainpanel.h"
 #include "trainpanel.h"
 #include "trainproperties.h"
+#include "trainview.h"
 
 using namespace std;
 using namespace Marklin;
@@ -137,6 +139,26 @@ void Engineer::set_status(const string &text)
        status_timeout = Time::now()+10*Time::sec;
 }
 
+void Engineer::rearrange_panels()
+{
+       int y = main_panel->get_geometry().y;
+       for(list<TrainPanel *>::iterator i=train_panels.begin(); i!=train_panels.end(); ++i)
+       {
+               y -= (*i)->get_geometry().h;
+               (*i)->set_position(0, y);
+       }
+}
+
+void Engineer::add_train_view(TrainView &tv)
+{
+       train_views.push_back(&tv);
+}
+
+void Engineer::remove_train_view(TrainView &tv)
+{
+       train_views.erase(remove(train_views.begin(), train_views.end(), &tv), train_views.end());
+}
+
 void Engineer::pick(bool with_ep)
 {
        picking = true;
@@ -158,6 +180,9 @@ void Engineer::tick()
        layout.tick();
        event_disp.tick(Time::zero);
 
+       for(list<TrainView *>::iterator i=train_views.begin(); i!=train_views.end(); ++i)
+               (*i)->prepare();
+
        if(status_timeout && Time::now()>status_timeout)
        {
                main_panel->set_status_text(string());
@@ -403,12 +428,8 @@ void Engineer::train_added(Train &train)
 {
        TrainPanel *tpanel = new TrainPanel(*this, ui_res, train);
        root->add(*tpanel);
-       int y = main_panel->get_geometry().y;
-       for(list<TrainPanel *>::iterator i=train_panels.begin(); i!=train_panels.end(); ++i)
-               y -= (*i)->get_geometry().h;
-       tpanel->set_position(0, y-tpanel->get_geometry().h);
        train_panels.push_back(tpanel);
-       tpanel->set_visible(true);
+       rearrange_panels();
 
        Vehicle3D &loco3d = layout_3d.get_vehicle(train.get_vehicle(0));
        overlay->set_label(loco3d, train.get_name());