]> git.tdb.fi Git - r2c2.git/blobdiff - source/engineer/traindialog.cpp
Set speed slider range from the advertised top speed of the train
[r2c2.git] / source / engineer / traindialog.cpp
index 4d1d492099cf69a760eeeaff71a4aa10c4616840..432f3dd22c99b98f7ea8d212b2dfeb73db861b9c 100644 (file)
@@ -1,5 +1,7 @@
 #include <msp/core/maputils.h>
 #include <msp/core/raii.h>
+#include <msp/gltk/part.h>
+#include <msp/gltk/root.h>
 #include <msp/gltk/stack.h>
 #include <msp/strings/format.h>
 #include "libr2c2/aicontrol.h"
@@ -8,6 +10,7 @@
 #include "libr2c2/trainstatus.h"
 #include "controlpanel.h"
 #include "routerpanel.h"
+#include "timetablepanel.h"
 #include "traindialog.h"
 #include "vehiclespanel.h"
 
@@ -30,6 +33,9 @@ TrainDialog::TrainDialog(Engineer &e, R2C2::Train &t):
        btn_expand->signal_clicked.connect(sigc::mem_fun(this, &TrainDialog::expand_clicked));
        lbl_speed = dynamic_cast<GLtk::Label *>(get_item(widgets, "lbl_speed"));
        sld_speed = dynamic_cast<GLtk::Slider *>(get_item(widgets, "sld_speed"));
+       float max_speed = train.get_maximum_speed();
+       if(max_speed>0)
+               sld_speed->set_range(0, max_speed*3.6/train.get_layout().get_catalogue().get_scale());
        sld_speed->signal_value_changed.connect(sigc::mem_fun(this, &TrainDialog::ui_speed_changed));
        tgl_forward = dynamic_cast<GLtk::Toggle *>(get_item(widgets, "tgl_forward"));
        tgl_forward->signal_toggled.connect(sigc::mem_fun(this, &TrainDialog::ui_forward_toggled));
@@ -55,6 +61,11 @@ TrainDialog::TrainDialog(Engineer &e, R2C2::Train &t):
        panels.push_back(pnl);
        dynamic_cast<GLtk::Toggle *>(get_item(widgets, "tgl_router"))->signal_toggled.connect(sigc::bind(sigc::mem_fun(this, &TrainDialog::toggle_panel), pnl));
 
+       pnl_expander->add(*(pnl = new TimetablePanel(engineer, train)));
+       pnl->set_visible(false);
+       panels.push_back(pnl);
+       dynamic_cast<GLtk::Toggle *>(get_item(widgets, "tgl_timetable"))->signal_toggled.connect(sigc::bind(sigc::mem_fun(this, &TrainDialog::toggle_panel), pnl));
+
        AIControl *control = train.get_ai_of_type<AIControl>();
        if(!control)
                control = new AIControl(train);
@@ -69,6 +80,19 @@ TrainDialog::TrainDialog(Engineer &e, R2C2::Train &t):
        train.signal_ai_event.connect(sigc::mem_fun(this, &TrainDialog::ai_event));
 }
 
+void TrainDialog::autosize_special(const GLtk::Part &part, GLtk::Geometry &ageom) const
+{
+       GLtk::Dialog::autosize_special(part, ageom);
+
+       if(part.get_name()=="children")
+       {
+               GLtk::Geometry egeom;
+               pnl_expander->autosize(egeom);
+               const GLtk::Sides &margin = layout->get_margin();
+               ageom.w = max(ageom.w, margin.left+margin.right+egeom.w);
+       }
+}
+
 void TrainDialog::ai_event(TrainAI &, const TrainAI::Message &msg)
 {
        if(msg.type=="status-changed")
@@ -112,11 +136,8 @@ void TrainDialog::expand_clicked()
 {
        pnl_expander->set_visible(!pnl_expander->is_visible());
        btn_expand->set_style(pnl_expander->is_visible() ? "arrow_up" : "arrow_down");
-       GLtk::Geometry ageom = geom;
-       ageom.h = 0;
-       layout->autosize(ageom);
-       ageom.y = geom.y+geom.h-ageom.h;
-       set_geometry(ageom);
+       signal_autosize_changed.emit();
+       find_ancestor<GLtk::Root>()->get_layout()->update();
 }
 
 void TrainDialog::toggle_panel(bool show, GLtk::Panel *panel)