X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fengineer%2Ftrainproperties.cpp;h=004747cdd1224456ecf0493e1d175e64823160ed;hb=bc8ac89bbe774bb133b758416182aa18e5e0a5a5;hp=adb48d3385edc039d8c319bfb3b7e94518911133;hpb=9462461b00b65c0018114802cfba8f290d6b2d42;p=r2c2.git diff --git a/source/engineer/trainproperties.cpp b/source/engineer/trainproperties.cpp index adb48d3..004747c 100644 --- a/source/engineer/trainproperties.cpp +++ b/source/engineer/trainproperties.cpp @@ -1,21 +1,73 @@ +/* $Id$ + +This file is part of the MSP Märklin suite +Copyright © 2006-2009 Mikkosoft Productions, Mikko Rasa +Distributed under the GPL +*/ + +#include +#include +#include +#include +#include "engineer.h" #include "trainproperties.h" +using namespace std; using namespace Msp; +using namespace Marklin; -TrainProperties::TrainProperties(GLtk::Resources &r, Train &t): - Panel(r), +TrainProperties::TrainProperties(Engineer &e, const GLtk::Resources &r, Train *t): + Widget(r), + Dialog(r), + engineer(e), train(t) { - set_size(200, 50); + set_size(200, 120); + + GLtk::Label *label; + add(*(label=new GLtk::Label(res, "Train properties"))); + label->set_geometry(GLtk::Geometry(10, geom.h-25, geom.w-20, 20)); + + add(*(ent_addr=new GLtk::Entry(res))); + ent_addr->set_geometry(GLtk::Geometry(10, geom.h-50, 40, 20)); + + add(*(drp_type=new GLtk::Dropdown(res))); + drp_type->set_geometry(GLtk::Geometry(60, geom.h-50, geom.w-70, 20)); - add(*(ent_name=new GLtk::Entry(res, train.get_name()))); - ent_name->set_geometry( + const map &locos = engineer.get_catalogue().get_locomotives(); + unsigned n = 0; + for(map::const_iterator i=locos.begin(); i!=locos.end(); ++i, ++n) + { + drp_type->append(format("%d %s", i->second->get_article_number(), i->second->get_name())); + if(train && i->second==&train->get_locomotive().get_type()) + drp_type->set_selected_index(n); + } - GLtk::Button *btn; + add(*(ent_name=new GLtk::Entry(res))); + ent_name->set_geometry(GLtk::Geometry(10, geom.h-75, geom.w-20, 20)); + + if(train) + { + ent_addr->set_text(lexical_cast(train->get_locomotive().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)); +} + +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()); - add(*(btn=new GLtk::Button(res, "OK"))); - btn->set_geometry(geom.width-45, 5, 40, 25); + 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); + engineer.place_train(*train); + } - add(*(btn=new GLtk::Button(res, "Cncl"))); - btn->set_geometry(geom.width-45, 5, 40, 25); + train->set_name(ent_name->get_text()); }