1 #include <msp/gltk/label.h>
3 #include "libr2c2/route.h"
4 #include "libr2c2/trainrouter.h"
5 #include "routeselect.h"
11 RouteSelect::RouteSelect(Engineer &e, Train &t):
18 add(*(label = new GLtk::Label("Select route")));
19 label->set_geometry(GLtk::Geometry(10, geom.h-25, geom.w-20, 20));
21 add(*(drp_route = new GLtk::Dropdown));
22 drp_route->set_geometry(GLtk::Geometry(10, geom.h-50, geom.w-20, 20));
23 drp_route->append("(none)");
24 drp_route->set_selected_index(0);
26 const Route *current_route = 0;
27 if(TrainRouter *router = dynamic_cast<TrainRouter *>(train.get_tagged_ai("router")))
28 current_route = router->get_route();
30 const set<Route *> &routes = engineer.get_layout().get_routes();
32 for(set<Route *>::const_iterator i=routes.begin(); i!=routes.end(); ++i)
33 if(!(*i)->is_temporary())
35 drp_route->append((*i)->get_name());
37 drp_route->set_selected_index(n);
42 void RouteSelect::on_ok_clicked()
44 if(drp_route->get_selected_index()>0)
46 const set<Route *> &routes = engineer.get_layout().get_routes();
47 set<Route *>::const_iterator i = routes.begin();
48 unsigned n = drp_route->get_selected_index()-1;
49 while(i!=routes.end())
51 if(!(*i)->is_temporary())
60 train.ai_message(TrainAI::Message("set-route", *i));
63 train.ai_message(TrainAI::Message("clear-route"));