]> git.tdb.fi Git - r2c2.git/blobdiff - source/engineer/routeselect.cpp
Further adjustments to changes in GLtk
[r2c2.git] / source / engineer / routeselect.cpp
index cd1e7042e846b730ca180b71a96efe4ff21e5f29..ae3dd8340949304b22c4a08bf3ba313307a153b9 100644 (file)
@@ -1,42 +1,39 @@
-/* $Id$
-
-This file is part of the MSP Märklin suite
-Copyright © 2009 Mikkosoft Productions, Mikko Rasa
-Distributed under the GPL
-*/
-
 #include <msp/gltk/label.h>
 #include "engineer.h"
-#include "libmarklin/route.h"
+#include "libr2c2/route.h"
+#include "libr2c2/trainrouter.h"
 #include "routeselect.h"
 
 using namespace std;
 using namespace Msp;
-using namespace Marklin;
+using namespace R2C2;
 
-RouteSelect::RouteSelect(Engineer &e, const GLtk::Resources &r, Train &t):
-       GLtk::Widget(r),
-       Dialog(r),
+RouteSelect::RouteSelect(Engineer &e, Train &t):
        engineer(e),
        train(t)
 {
        set_size(200, 95);
 
        GLtk::Label *label;
-       add(*(label = new GLtk::Label(res, "Select route")));
+       add(*(label = new GLtk::Label("Select route")));
        label->set_geometry(GLtk::Geometry(10, geom.h-25, geom.w-20, 20));
 
-       add(*(drp_route = new GLtk::Dropdown(res)));
+       add(*(drp_route = new GLtk::Dropdown));
        drp_route->set_geometry(GLtk::Geometry(10, geom.h-50, geom.w-20, 20));
        drp_route->append("(none)");
        drp_route->set_selected_index(0);
-       const set<Route *> &routes = engineer.get_layout().get_routes();
+
+       const Route *current_route = 0;
+       if(TrainRouter *router = train.get_ai_of_type<TrainRouter>())
+               current_route = router->get_route();
+
+       const set<Route *> &routes = engineer.get_layout().get_all<Route>();
        unsigned n = 1;
        for(set<Route *>::const_iterator i=routes.begin(); i!=routes.end(); ++i)
                if(!(*i)->is_temporary())
                {
                        drp_route->append((*i)->get_name());
-                       if(*i==train.get_route())
+                       if(*i==current_route)
                                drp_route->set_selected_index(n);
                        ++n;
                }
@@ -46,7 +43,7 @@ void RouteSelect::on_ok_clicked()
 {
        if(drp_route->get_selected_index()>0)
        {
-               const set<Route *> &routes = engineer.get_layout().get_routes();
+               const set<Route *> &routes = engineer.get_layout().get_all<Route>();
                set<Route *>::const_iterator i = routes.begin();
                unsigned n = drp_route->get_selected_index()-1;
                while(i!=routes.end())
@@ -59,10 +56,9 @@ void RouteSelect::on_ok_clicked()
                        }
                        ++i;
                }
-               
-               if(!train.set_route(*i))
-                       engineer.set_status("Could not set route");
+
+               train.ai_message(TrainAI::Message("set-route", *i));
        }
        else
-               train.set_route(0);
+               train.ai_message(TrainAI::Message("clear-route"));
 }