X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fengineer%2Frouteselect.cpp;h=770a455a4130b7406e22a6f348c38b680b757626;hb=7a36d396eded897c421424905b2c938d770df341;hp=3413220a46aea4c8cac349230c29cdc486cd7850;hpb=025c23f199c411cc2ec1a6d2e85bf24460150ceb;p=r2c2.git diff --git a/source/engineer/routeselect.cpp b/source/engineer/routeselect.cpp index 3413220..770a455 100644 --- a/source/engineer/routeselect.cpp +++ b/source/engineer/routeselect.cpp @@ -1,55 +1,64 @@ -/* $Id$ - -This file is part of the MSP Märklin suite -Copyright © 2009 Mikkosoft Productions, Mikko Rasa -Distributed under the GPL -*/ - #include #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 map &routes = engineer.get_layout().get_routes(); + + const Route *current_route = 0; + if(TrainRouter *router = train.get_ai_of_type()) + current_route = router->get_route(); + + const set &routes = engineer.get_layout().get_routes(); unsigned n = 1; - for(map::const_iterator i=routes.begin(); i!=routes.end(); ++i, ++n) - { - drp_route->append(i->second->get_name()); - if(i->second==train.get_route()) - drp_route->set_selected_index(n); - } + for(set::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 map &routes = engineer.get_layout().get_routes(); - map::const_iterator i = routes.begin(); - advance(i, drp_route->get_selected_index()-1); - - train.set_route(i->second); + const set &routes = engineer.get_layout().get_routes(); + set::const_iterator i = routes.begin(); + 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")); }