1 #include <msp/gltk/floatingarrangement.h>
2 #include <msp/time/utils.h>
3 #include "departuresdialog.h"
5 #include "newtraindialog.h"
6 #include "traindialog.h"
7 #include "userinterface.h"
13 UserInterface::UserInterface(Engineer &e, Graphics::Window &window, Input::Keyboard &keyboard, Input::Mouse &mouse):
15 resources("data/r2c2.res"),
16 root(resources, &window, &keyboard, &mouse),
20 GLtk::Layout *root_layout = new GLtk::Layout;
21 root.set_layout(root_layout);
22 root_layout->set_margin(GLtk::Sides());
23 root_arrangement = new GLtk::FloatingArrangement(*root_layout);
24 root.set_visible(true);
28 main_wnd.set_position(0, window.get_height()-main_wnd.get_geometry().h);
30 Layout &layout = engineer.get_layout();
31 if(layout.has_driver())
33 Driver &driver = layout.get_driver();
34 driver.signal_locomotive_detected.connect(sigc::mem_fun(this, &UserInterface::locomotive_detected));
37 engineer.get_layout().signal_emergency.connect(sigc::hide<0>(sigc::mem_fun(this, &UserInterface::set_status)));
40 UserInterface::~UserInterface()
42 while(!dyn_dialogs.empty())
43 delete dyn_dialogs.front();
44 delete root_arrangement;
47 void UserInterface::set_status(const string &text)
49 main_wnd.set_status_text(text);
50 status_timeout = Time::now()+10*Time::sec;
53 void UserInterface::add_dynamic_dialog(DynamicDialog &dd)
55 dyn_dialogs.push_back(&dd);
58 void UserInterface::remove_dynamic_dialog(DynamicDialog &dd)
60 dyn_dialogs.erase(remove(dyn_dialogs.begin(), dyn_dialogs.end(), &dd), dyn_dialogs.end());
63 void UserInterface::show_train(Train &train)
65 TrainDialog *dlg = new TrainDialog(engineer, train);
70 void UserInterface::show_zone(Zone &zone)
72 DeparturesDialog *dlg = new DeparturesDialog(engineer.get_layout(), zone.get_group());
76 void UserInterface::locomotive_detected(const Driver::DetectedLocomotive &loco)
80 NewTrainDialog *dlg = new NewTrainDialog(engineer);
82 dlg->signal_response.connect(sigc::mem_fun(this, &UserInterface::import_finished));
88 void UserInterface::import_finished(int)
90 import_active = false;
93 void UserInterface::tick()
95 Time::TimeStamp t = Time::now();
96 if(status_timeout && t>status_timeout)
98 main_wnd.set_status_text(string());
99 status_timeout = Time::TimeStamp();
102 for(list<DynamicDialog *>::iterator i=dyn_dialogs.begin(); i!=dyn_dialogs.end(); ++i)
106 void UserInterface::render() const