X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fengineer%2Ftrainproperties.cpp;h=4596000724a204bff97b9c53a685d973318cf511;hb=e2ecc5a6e8e8056cd09599e60140498f322b87b6;hp=67a957959fca96c04a8b8ab9338d7f62933b5e24;hpb=a73b245826e8c1bc1f1394e9aa21618f8f31a6c5;p=r2c2.git diff --git a/source/engineer/trainproperties.cpp b/source/engineer/trainproperties.cpp index 67a9579..4596000 100644 --- a/source/engineer/trainproperties.cpp +++ b/source/engineer/trainproperties.cpp @@ -1,13 +1,15 @@ /* $Id$ This file is part of the MSP Märklin suite -Copyright © 2006-2008 Mikkosoft Productions, Mikko Rasa +Copyright © 2006-2010 Mikkosoft Productions, Mikko Rasa Distributed under the GPL */ #include +#include #include #include +#include "libmarklin/locotype.h" #include "engineer.h" #include "trainproperties.h" @@ -15,55 +17,80 @@ using namespace std; using namespace Msp; using namespace Marklin; -TrainProperties::TrainProperties(Engineer &e, GLtk::Resources &r, Train *t): +TrainProperties::TrainProperties(Engineer &e, const GLtk::Resources &r, Train *t): Widget(r), - Panel(r), + Dialog(r), engineer(e), train(t) { - set_size(200, 95); + set_size(200, 145); + + 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-30, 40, 20)); + 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-30, geom.w-70, 20)); + drp_type->set_geometry(GLtk::Geometry(60, geom.h-50, geom.w-70, 20)); - const map &locos = engineer.get_catalogue().get_locomotives(); - for(map::const_iterator i=locos.begin(); i!=locos.end(); ++i) - drp_type->append(format("%d %s", i->second->get_article_number(), i->second->get_name())); + const map &vehs = engineer.get_catalogue().get_vehicles(); + unsigned n = 0; + for(map::const_iterator i=vehs.begin(); i!=vehs.end(); ++i, ++n) + { + if(!dynamic_cast(i->second)) + continue; - add(*(ent_name=new GLtk::Entry(res, "Train"))); - ent_name->set_geometry(GLtk::Geometry(10, geom.h-55, geom.w-20, 20)); + drp_type->append(format("%d %s", i->second->get_article_number(), i->second->get_name())); + if(train && i->second==&train->get_locomotive_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)); - add(*(btn=new GLtk::Button(res, "OK"))); - btn->set_style("green"); - btn->set_geometry(GLtk::Geometry(geom.w-40, 10, 30, 25)); - btn->signal_clicked.connect(sigc::mem_fun(this, &TrainProperties::ok_clicked)); + add(*(drp_priority=new GLtk::Dropdown(res))); + drp_priority->set_geometry(GLtk::Geometry(10, geom.h-100, geom.w-20, 20)); + drp_priority->append("Standard freight"); + drp_priority->append("Express freight"); + drp_priority->append("Unspecified"); + drp_priority->append("Standard passenger"); + drp_priority->append("Express passenger"); - add(*(btn=new GLtk::Button(res, "Cncl"))); - btn->set_style("red"); - btn->set_geometry(GLtk::Geometry(geom.w-80, 10, 30, 25)); - btn->signal_clicked.connect(sigc::mem_fun(this, &TrainProperties::cancel_clicked)); + if(train) + { + ent_addr->set_text(lexical_cast(train->get_address())); + ent_name->set_text(train->get_name()); + drp_priority->set_selected_index(train->get_priority()+2); + } + else + { + ent_name->set_text(format("Train %d", engineer.get_layout().get_trains().size()+1)); + drp_priority->set_selected_index(2); + } } -void TrainProperties::ok_clicked() +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()); - train = engineer.add_train(*i->second, lexical_cast(ent_addr->get_text())); + 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()); + train = new Train(engineer.get_layout(), *dynamic_cast(i->second), addr); } train->set_name(ent_name->get_text()); - signal_ok.emit(); -} - -void TrainProperties::cancel_clicked() -{ - signal_cancel.emit(); + train->set_priority(drp_priority->get_selected_index()-2); }