/* client/mainwindow.cc This file is part of the Osirion project and is distributed under the terms and conditions of the GNU General Public License version 2 */ #include "core/application.h" #include "client/mainwindow.h" #include "client/video.h" #include "ui/ui.h" namespace client { MainWindow::MainWindow(ui::Widget *parent) : ui::Widget(parent) { set_label("mainwindow"); set_border(false); set_background(false); // console notifications widget mainwindow_notificationswidget = new Notifications(this); // developer info widget mainwindow_devinfowidget = new DevInfoWidget(this); // statistics widget mainwindow_statsinfowidget = new StatsInfoWidget(this); // key info widget mainwindow_keyinfowidget = new KeyInfoWidget(this); // clock widget mainwindow_clockwidget = new ClockInfoWidget(this); // game window mainwindow_gamewindow = new GameWindow(this); mainwindow_gamewindow->raise(); mainwindow_gamewindow->hide(); // main menus mainwindow_mainmenu = new MainMenu(this); mainwindow_mainmenu->raise(); mainwindow_mainmenu->hide(); } MainWindow::~MainWindow() { } void MainWindow::resize() { set_size(parent()->size()); //const float largemargin = ui::UI::elementsize.width() * 0.25 const float smallmargin = ui::UI::elementsize.height(); // reposition notifications mainwindow_notificationswidget->set_size(width() - smallmargin * 2, height() - smallmargin * 4); mainwindow_notificationswidget->set_location(smallmargin, smallmargin * 2); // reposition devinfo widget mainwindow_devinfowidget->set_size(font()->width()*32, font()->height()*5); mainwindow_devinfowidget->set_location(smallmargin, smallmargin); // reposition stats widget mainwindow_statsinfowidget->set_size(font()->width()*12, font()->height()*5); mainwindow_statsinfowidget->set_location(width() - mainwindow_statsinfowidget->width() - smallmargin, smallmargin); // reposition clock mainwindow_clockwidget->set_size(font()->width()*7, font()->height()); mainwindow_clockwidget->set_location(width() - mainwindow_clockwidget->width() - smallmargin, mainwindow_statsinfowidget->bottom() + smallmargin); // reposition keypress widget mainwindow_keyinfowidget->set_size(font()->width()*12, font()->height()*1); mainwindow_keyinfowidget->set_location(width() - mainwindow_keyinfowidget->width() - smallmargin, height() - mainwindow_keyinfowidget->height() - smallmargin); // resize game window mainwindow_gamewindow->set_size(size()); // resize mainmenu window mainwindow_mainmenu->set_size(size()); } void MainWindow::clear() { // clear console notifications mainwindow_notificationswidget->clear(); // clear the game window mainwindow_gamewindow->clear(); } void MainWindow::event_text(const std::string & text) { mainwindow_notificationswidget->event_text(text); mainwindow_gamewindow->event_text(text); } void MainWindow::draw() { // the mainwindow is only drawn if the application is connected // and the loader screen is not shown mainwindow_devinfowidget->set_visible(draw_devinfo->value() > 0 ? true : false); mainwindow_statsinfowidget->set_visible(draw_stats->value() > 0 ? true : false); mainwindow_keyinfowidget->set_visible(draw_keypress->value() > 0 ? true : false); if (draw_clock->value() <= 0) { mainwindow_clockwidget->set_mode(ClockInfoWidget::ClockOff); } else if (draw_clock->value() == 1) { mainwindow_clockwidget->set_mode(ClockInfoWidget::Clock12Hours); } else { mainwindow_clockwidget->set_mode(ClockInfoWidget::Clock24Hours); } if (!mainwindow_mainmenu->visible()) { if (!core::game()->interactive() || !core::localcontrol()) { mainwindow_gamewindow->hide(); mainwindow_mainmenu->show(); } else if (core::localcontrol()->state() == core::Entity::Destroyed) { mainwindow_gamewindow->hide(); mainwindow_mainmenu->show_menu("respawn"); } else if (mainwindow_gamewindow->hidden()) { mainwindow_gamewindow->show(); } } else { if (mainwindow_gamewindow->visible()) { mainwindow_gamewindow->hide(); } } } }