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.begin();
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.insert(&dd);
58 void UserInterface::remove_dynamic_dialog(DynamicDialog &dd)
60 dyn_dialogs.erase(&dd);
63 void UserInterface::show_train(Train &train)
65 TrainDialog *dlg = new TrainDialog(engineer, train);
69 void UserInterface::show_zone(Zone &zone)
71 DeparturesDialog *dlg = new DeparturesDialog(engineer.get_layout(), zone.get_group());
75 void UserInterface::locomotive_detected(const Driver::DetectedLocomotive &loco)
79 NewTrainDialog *dlg = new NewTrainDialog(engineer);
81 dlg->signal_response.connect(sigc::mem_fun(this, &UserInterface::import_finished));
87 void UserInterface::import_finished(int)
89 import_active = false;
92 void UserInterface::tick()
94 Time::TimeStamp t = Time::now();
95 if(status_timeout && t>status_timeout)
97 main_wnd.set_status_text(string());
98 status_timeout = Time::TimeStamp();
101 for(set<DynamicDialog *>::iterator i=dyn_dialogs.begin(); i!=dyn_dialogs.end(); ++i)
105 void UserInterface::render() const