]> git.tdb.fi Git - r2c2.git/blobdiff - source/engineer/engineer.cpp
Implement an UI for importing locomotives from the driver
[r2c2.git] / source / engineer / engineer.cpp
index 87e3dda10003c7fd917dec1a94b619f2911ffb93..d0c879c02067ebb260d841528c05cd26eafb5649 100644 (file)
@@ -27,6 +27,7 @@
 #include "3d/vehicle.h"
 #include "engineer.h"
 #include "mainwindow.h"
+#include "newtraindialog.h"
 #include "traindialog.h"
 #include "trainview.h"
 
@@ -40,6 +41,7 @@ Engineer::Engineer(int argc, char **argv):
        keyboard(window),
        mouse(window),
        ui_res("r2c2.res"),
+       import_active(false),
        layout(catalogue, (options.driver.empty() ? 0 : Driver::create(options.driver))),
        layout_3d(layout),
        server(0),
@@ -71,6 +73,8 @@ Engineer::Engineer(int argc, char **argv):
        DataFile::load(catalogue, "wagons.dat");
        DataFile::load(layout, options.layout_fn);
 
+       if(layout.has_driver())
+               layout.get_driver().signal_locomotive_detected.connect(sigc::mem_fun(this, &Engineer::locomotive_detected));
        layout.signal_train_added.connect(sigc::mem_fun(this, &Engineer::train_added));
        layout.signal_emergency.connect(sigc::mem_fun(this, &Engineer::set_status));
        const set<Block *> &blocks = layout.get_all<Block>();
@@ -296,6 +300,23 @@ Object *Engineer::pick_object(const Vector &p)
        return layout.pick<Track>(Ray(start, Vector(ray)));
 }
 
+void Engineer::locomotive_detected(const Driver::DetectedLocomotive &loco)
+{
+       if(!import_active)
+       {
+               NewTrainDialog *dlg = new NewTrainDialog(*this);
+               dlg->prefill(loco);
+               dlg->signal_response.connect(sigc::mem_fun(this, &Engineer::import_finished));
+               root->add(*dlg);
+               import_active = true;
+       }
+}
+
+void Engineer::import_finished(int)
+{
+       import_active = false;
+}
+
 void Engineer::process_new_train(Train &train)
 {
        Vehicle3D &loco3d = layout_3d.get_3d(train.get_vehicle(0));