-/* $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, ++n)
- {
- drp_route->append((*i)->get_name());
- if(*i==train.get_route())
- drp_route->set_selected_index(n);
- }
+ for(set<Route *>::const_iterator i=routes.begin(); i!=routes.end(); ++i)
+ if(!(*i)->is_temporary())
+ {
+ drp_route->append((*i)->get_name());
+ if(*i==current_route)
+ drp_route->set_selected_index(n);
+ ++n;
+ }
}
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();
- advance(i, drp_route->get_selected_index()-1);
-
- train.set_route(*i);
+ unsigned n = drp_route->get_selected_index()-1;
+ while(i!=routes.end())
+ {
+ if(!(*i)->is_temporary())
+ {
+ if(!n)
+ break;
+ --n;
+ }
+ ++i;
+ }
+
+ train.ai_message(TrainAI::Message("set-route", *i));
}
else
- train.set_route(0);
+ train.ai_message(TrainAI::Message("clear-route"));
}