X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fengineer%2Ftrainproperties.cpp;h=96c8313d4800d2809cf5da62021d5f1d9a4ab5a8;hb=dc3b2bce73df40ea885a1960a825e5cd3a33c045;hp=eb132c0e68f1eef1d9ea4a72e7280e430aa298a6;hpb=e375f8bf215058398795be1010ffec89d0150114;p=r2c2.git diff --git a/source/engineer/trainproperties.cpp b/source/engineer/trainproperties.cpp index eb132c0..96c8313 100644 --- a/source/engineer/trainproperties.cpp +++ b/source/engineer/trainproperties.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of the MSP Märklin suite -Copyright © 2006-2009 Mikkosoft Productions, Mikko Rasa +Copyright © 2006-2010 Mikkosoft Productions, Mikko Rasa Distributed under the GPL */ @@ -9,6 +9,7 @@ Distributed under the GPL #include #include #include +#include "libmarklin/locotype.h" #include "engineer.h" #include "trainproperties.h" @@ -34,12 +35,15 @@ TrainProperties::TrainProperties(Engineer &e, const GLtk::Resources &r, Train *t add(*(drp_type=new GLtk::Dropdown(res))); drp_type->set_geometry(GLtk::Geometry(60, geom.h-50, geom.w-70, 20)); - const map &locos = engineer.get_catalogue().get_locomotives(); + const map &vehs = engineer.get_catalogue().get_vehicles(); unsigned n = 0; - for(map::const_iterator i=locos.begin(); i!=locos.end(); ++i, ++n) + for(map::const_iterator i=vehs.begin(); i!=vehs.end(); ++i, ++n) { + if(!dynamic_cast(i->second)) + continue; + drp_type->append(format("%d %s", i->second->get_article_number(), i->second->get_name())); - if(train && i->second==&train->get_locomotive().get_type()) + if(train && i->second==&train->get_locomotive_type()) drp_type->set_selected_index(n); } @@ -48,24 +52,31 @@ TrainProperties::TrainProperties(Engineer &e, const GLtk::Resources &r, Train *t if(train) { - ent_addr->set_text(lexical_cast(train->get_locomotive().get_address())); + ent_addr->set_text(lexical_cast(train->get_address())); ent_name->set_text(train->get_name()); } else - ent_name->set_text(format("Train %d", engineer.get_traffic_manager().get_trains().size()+1)); + ent_name->set_text(format("Train %d", engineer.get_layout().get_trains().size()+1)); } void TrainProperties::on_ok_clicked() { if(!train) { - const map &locos = engineer.get_catalogue().get_locomotives(); - map::const_iterator i = locos.begin(); - advance(i, drp_type->get_selected_index()); + const map &vehs = engineer.get_catalogue().get_vehicles(); + map::const_iterator i = vehs.begin(); + unsigned n = drp_type->get_selected_index(); + while(!dynamic_cast(i->second)) + ++i; + while(n) + { + if(dynamic_cast(i->second)) + --n; + ++i; + } unsigned addr = lexical_cast(ent_addr->get_text()); - Locomotive *loco = new Locomotive(*i->second, engineer.get_control(), addr); - train = new Train(engineer.get_traffic_manager(), *loco); + train = new Train(engineer.get_layout(), *dynamic_cast(i->second), addr); } train->set_name(ent_name->get_text());