X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fremote%2Ftrainpanel.cpp;fp=source%2Fremote%2Ftrainpanel.cpp;h=58dcd676a86d2d7af0c8e90a26abce6cba6706f7;hb=f8873062b146028c07f55ad625d2767e45133c27;hp=0000000000000000000000000000000000000000;hpb=a9bbf8d37a2f94a720897fe4f0ab06a016779c69;p=r2c2.git diff --git a/source/remote/trainpanel.cpp b/source/remote/trainpanel.cpp new file mode 100644 index 0000000..58dcd67 --- /dev/null +++ b/source/remote/trainpanel.cpp @@ -0,0 +1,98 @@ +#include +#include +#include +#include +#include +#include +#include +#include "network/client.h" +#include "trainpanel.h" + +using namespace std; +using namespace Msp; +using namespace R2C2; + +TrainPanel::TrainPanel(NetTrain &t): + train(t), + updating(false) +{ + Loader::WidgetMap widgets; + DataFile::load(*this, "data/remote/trainpanel.ui", widgets); + + Msp::GLtk::Button *btn = dynamic_cast(get_item(widgets, "btn_forward")); + btn->signal_clicked.connect(sigc::bind(sigc::mem_fun(&train, &NetTrain::set_reverse), false)); + btn = dynamic_cast(get_item(widgets, "btn_reverse")); + btn->signal_clicked.connect(sigc::bind(sigc::mem_fun(&train, &NetTrain::set_reverse), true)); + + ind_forward = dynamic_cast(get_item(widgets, "ind_forward")); + ind_reverse = dynamic_cast(get_item(widgets, "ind_reverse")); + + sld_speed = dynamic_cast(get_item(widgets, "sld_speed")); + sld_speed->set_range(0, train.get_loco_type().get_maximum_speed()/train.get_client().get_catalogue().get_scale()*3.6); + sld_speed->signal_value_changed.connect(sigc::mem_fun(this, &TrainPanel::ui_speed_changed)); + + lbl_speed = dynamic_cast(get_item(widgets, "lbl_speed")); + + lbl_status = dynamic_cast(get_item(widgets, "lbl_status")); + train.signal_status_changed.connect(sigc::mem_fun(this, &TrainPanel::status_changed)); + lbl_status->set_text(train.get_status()); + + GLtk::Panel *pnl_functions = dynamic_cast(get_item(widgets, "pnl_functions")); + const VehicleType::FunctionMap &functions = train.get_loco_type().get_functions(); + GLtk::Column column(*pnl_functions->get_layout()); + for(VehicleType::FunctionMap::const_iterator i=functions.begin(); i!=functions.end(); ++i) + { + GLtk::Toggle *tgl = new GLtk::Toggle(i->second); + pnl_functions->add(*tgl); + tgl->set_value(train.get_function(i->first)); + tgl->signal_toggled.connect(sigc::bind(sigc::mem_fun(this, &TrainPanel::ui_function_toggled), i->first)); + tgl_functions[i->first] = tgl; + } + + train.signal_target_speed_changed.connect(sigc::mem_fun(this, &TrainPanel::update_speed)); + update_speed(train.get_target_speed()); + train.signal_reverse_changed.connect(sigc::mem_fun(this, &TrainPanel::update_reverse)); + update_reverse(train.get_reverse()); +} + +void TrainPanel::update_reverse(bool r) +{ + ind_forward->set_active(!r); + ind_reverse->set_active(r); +} + +void TrainPanel::update_speed(float s) +{ + SetFlag setf(updating); + float scale_speed = s/train.get_client().get_catalogue().get_scale()*3.6; + sld_speed->set_value(scale_speed); + lbl_speed->set_text(format("%3.0f", scale_speed)); +} + +void TrainPanel::ui_speed_changed(float s) +{ + if(!updating) + { + float real_speed = s*train.get_client().get_catalogue().get_scale()/3.6; + train.set_target_speed(real_speed); + } +} + +void TrainPanel::function_changed(unsigned f, bool a) +{ + SetFlag setf(updating); + map::iterator i = tgl_functions.find(f); + if(i!=tgl_functions.end()) + get_item(tgl_functions, f)->set_value(a); +} + +void TrainPanel::ui_function_toggled(bool a, unsigned f) +{ + if(!updating) + train.set_function(f, a); +} + +void TrainPanel::status_changed(const string &s) +{ + lbl_status->set_text(s); +}