1 #include <msp/core/maputils.h>
2 #include <msp/core/raii.h>
3 #include <msp/gltk/button.h>
4 #include <msp/gltk/column.h>
5 #include "libr2c2/layout.h"
6 #include "libr2c2/route.h"
7 #include "libr2c2/trainrouter.h"
9 #include "routerpanel.h"
15 string route_name(const Route *const &route)
17 return route->get_name();
20 RouterPanel::RouterPanel(Engineer &e, Train &t):
26 Loader::WidgetMap widgets;
27 DataFile::load(*this, "data/routerpanel.ui", widgets);
29 lbl_route = dynamic_cast<GLtk::Label *>(get_item(widgets, "lbl_route"));
30 drp_routes = dynamic_cast<GLtk::Dropdown *>(get_item(widgets, "drp_routes"));
31 drp_routes->set_data(routes);
32 drp_routes->signal_item_selected.connect(sigc::mem_fun(this, &RouterPanel::route_selected));
34 dynamic_cast<GLtk::Button *>(get_item(widgets, "btn_goto"))->signal_clicked.connect(sigc::mem_fun(this, &RouterPanel::goto_clicked));
36 const set<Route *> &lroutes = train.get_layout().get_all<Route>();
37 for(set<Route *>::const_iterator i=lroutes.begin(); i!=lroutes.end(); ++i)
40 TrainRouter *router = train.get_ai_of_type<TrainRouter>();
42 router = new TrainRouter(train);
43 update_route(router->get_route());
45 train.signal_ai_event.connect(sigc::mem_fun(this, &RouterPanel::ai_event));
48 void RouterPanel::ai_event(TrainAI &, const TrainAI::Message &msg)
50 if(msg.type=="route-changed")
51 update_route(msg.value.value<const Route *>());
54 void RouterPanel::update_route(const Route *route)
56 SetFlag setf(updating);
58 lbl_route->set_text(route->get_name());
60 lbl_route->set_text("Free run");
61 drp_routes->set_selected_index(routes.find(route));
64 void RouterPanel::route_selected(unsigned index)
68 const Route *route = routes.get(index);
69 train.ai_message(TrainAI::Message("set-route", route));
73 void RouterPanel::goto_clicked()
76 pick_conn = engineer.signal_pick_done.connect(sigc::mem_fun(this, &RouterPanel::goto_pick_done));
79 void RouterPanel::goto_pick_done(Track *track, unsigned)
81 pick_conn.disconnect();
82 train.ai_message(TrainAI::Message("set-destination-block", &track->get_block()));