diff options
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/Makefile.am | 50 | ||||
-rw-r--r-- | src/client/client.cc | 167 | ||||
-rw-r--r-- | src/client/client.h | 9 | ||||
-rw-r--r-- | src/client/entitymenu.cc | 2 | ||||
-rw-r--r-- | src/client/entitymenu.h | 4 | ||||
-rw-r--r-- | src/client/gamewindow.cc | 450 | ||||
-rw-r--r-- | src/client/gamewindow.h | 103 | ||||
-rw-r--r-- | src/client/inventory.cc | 292 | ||||
-rw-r--r-- | src/client/inventorywindow.cc | 313 | ||||
-rw-r--r-- | src/client/inventorywindow.h (renamed from src/client/inventory.h) | 42 | ||||
-rw-r--r-- | src/client/mainwindow.cc | 92 | ||||
-rw-r--r-- | src/client/mainwindow.h | 24 | ||||
-rw-r--r-- | src/client/playerview.cc | 418 | ||||
-rw-r--r-- | src/client/playerview.h | 99 | ||||
-rw-r--r-- | src/client/testmodelview.cc | 131 | ||||
-rw-r--r-- | src/client/testmodelview.h | 58 | ||||
-rw-r--r-- | src/client/testmodelwindow.cc | 121 | ||||
-rw-r--r-- | src/client/testmodelwindow.h | 55 | ||||
-rw-r--r-- | src/client/trademenu.cc | 8 | ||||
-rw-r--r-- | src/client/trademenu.h | 6 | ||||
-rw-r--r-- | src/client/video.cc | 2 |
21 files changed, 1274 insertions, 1172 deletions
diff --git a/src/client/Makefile.am b/src/client/Makefile.am index 1ac7d54..ceddb6a 100644 --- a/src/client/Makefile.am +++ b/src/client/Makefile.am @@ -9,28 +9,28 @@ endif noinst_HEADERS = \ - action.h \ - buymenu.h \ - chat.h \ - client.h \ - clientext.h \ - entitymenu.h \ - hud.h \ - infowidget.h \ - input.h \ - inventory.h \ - inventorylistview.h \ - joystick.h \ - key.h \ - keyboard.h \ - mainwindow.h \ - map.h \ - notifications.h \ - playerview.h \ - soundext.h \ - targeticonbutton.h \ - targets.h \ - testmodelview.h \ + action.h \ + buymenu.h \ + chat.h \ + client.h \ + clientext.h \ + entitymenu.h \ + gamewindow.h \ + hud.h \ + infowidget.h \ + input.h \ + inventorywindow.h \ + inventorylistview.h \ + joystick.h \ + key.h \ + keyboard.h \ + mainwindow.h \ + map.h \ + notifications.h \ + soundext.h \ + targeticonbutton.h \ + targets.h \ + testmodelwindow.h \ trademenu.h \ video.h @@ -41,22 +41,22 @@ libclient_la_SOURCES = \ client.cc \ clientext.cc \ entitymenu.cc \ + gamewindow.cc \ hud.cc \ infowidget.cc \ input.cc \ inventorylistview.cc \ - inventory.cc \ + inventorywindow.cc \ joystick.cc \ key.cc \ keyboard.cc \ mainwindow.cc \ map.cc \ notifications.cc \ - playerview.cc \ soundext.cc \ targeticonbutton.cc \ targets.cc \ - testmodelview.cc \ + testmodelwindow.cc \ trademenu.cc \ video.cc diff --git a/src/client/client.cc b/src/client/client.cc index 4b27eb7..69f36b6 100644 --- a/src/client/client.cc +++ b/src/client/client.cc @@ -106,8 +106,8 @@ void Client::init(int count, char **arguments) client_mainwindow = new MainWindow(ui::root()); // FIXME needs to be a mainwindow child - client_testmodelview = new TestModelView(ui::root()); - client_testmodelview->hide(); + client_testmodelwindow = new TestModelWindow(ui::root()); + client_testmodelwindow->hide(); // Initialize the video subsystem if (!video::init()) { @@ -247,8 +247,8 @@ void Client::frame() ui::root()->show_menu("join"); } - if (testmodelview()->visible()) { - testmodelview()->raise(); + if (testmodelwindow()->visible()) { + testmodelwindow()->raise(); } if (ui::console()->visible()) { ui::console()->raise(); @@ -421,6 +421,12 @@ void Client::func_r_restart(std::string const &args) /* ---- func_ui ---------------------------------------------------- */ +void Client::func_ui_console(std::string const &args) +{ + ui::console()->toggle(); +} + +// list user interface widgets void Client::func_list_ui(std::string const &args) { if (ui::root()) { @@ -435,11 +441,6 @@ void Client::func_ui_restart(std::string const &args) } } -void Client::func_ui_console(std::string const &args) -{ - ui::console()->toggle(); -} - void Client::func_list_menu(std::string const &args) { if (ui::root()) { @@ -447,6 +448,7 @@ void Client::func_list_menu(std::string const &args) } } +// help for the global ui functions void Client::func_ui_help() { con_print << "^BUser interface functions" << std::endl; @@ -457,6 +459,7 @@ void Client::func_ui_help() con_print << " ui restart reload user interface files" << std::endl; } +// global ui functions void Client::func_ui(std::string const &args) { if (!ui::root()) { @@ -475,47 +478,82 @@ void Client::func_ui(std::string const &args) if (command.compare("help") == 0) { func_ui_help(); + } else if (command.compare("debug") == 0) { ui::UI::ui_debug = !ui::UI::ui_debug; + } else if (command.compare("list") == 0) { ui::root()->list(); + } else if (command.compare("visible") == 0) { ui::root()->list_visible(); + } else if (command.compare("restart") == 0) { ui::root()->load_settings(); + } else { func_ui_help(); } } -void Client::func_ui_chat(std::string const &args) +// help for the global menu functions +void Client::func_menu_help() { - if (client()->connected() && client()->mainwindow()->playerview()->visible()) { - client()->mainwindow()->playerview()->toggle_chat(); - } + con_print << "^Bmenu functions" << std::endl; + con_print << " menu help show this help" << std::endl; + con_print << " menu list list available menus" << std::endl; + con_print << " menu [name] show a menu" << std::endl; + con_print << " menu back return to the previous menu" << std::endl; + con_print << " menu previous return to the previous menu" << std::endl; + con_print << " menu close close the current menu" << std::endl; + con_print << " menu hide hide the current menu" << std::endl; + ui::root()->list_menus(); } -void Client::func_ui_chatbar(std::string const &args) +// global menu fuctions +void Client::func_menu(std::string const &args) { - if (client()->connected() && client()->mainwindow()->playerview()->visible()) { - client()->mainwindow()->playerview()->toggle_chatbar(); + if (!ui::root()) { + con_warn << "User Interface not available!" << std::endl; + return; } -} -void Client::func_ui_inventory(std::string const &args) -{ - if (client()->connected() && client()->mainwindow()->playerview()->visible()) { - client()->mainwindow()->playerview()->toggle_inventory(); + if (!args.size()) { + func_menu_help(); + return; } -} -void Client::func_ui_map(std::string const &args) -{ - if (client()->connected() && client()->mainwindow()->playerview()->visible()) { - client()->mainwindow()->playerview()->toggle_map(); + std::stringstream argstr(args); + std::string command; + argstr >> command; + + aux::to_label(command); + + + if (command.compare("help") == 0) { + func_menu_help(); + + } else if (command.compare("hide") == 0) { + ui::root()->hide_menu(); + + } else if (command.compare("close") == 0) { + ui::root()->hide_menu(); + + } else if (command.compare("back") == 0) { + ui::root()->previous_menu(); + + } else if (command.compare("previous") == 0) { + ui::root()->previous_menu(); + + } else if (command.compare("list") == 0) { + ui::root()->list_menus(); + + } else { + ui::root()->show_menu(command.c_str()); } } +// used by keybinds to open the main menu void Client::func_ui_menu(std::string const &args) { if (client()->connected()) { @@ -534,60 +572,47 @@ void Client::func_ui_menu(std::string const &args) } } -// entity menus -void Client::func_view(std::string const &args) +// used by keybinds to open the chat view +void Client::func_ui_chat(std::string const &args) { - if (client()->mainwindow()) { - client()->mainwindow()->playerview()->show_menu(args); + if (client()->connected() && client()->mainwindow()->gamewindow()->visible()) { + client()->mainwindow()->gamewindow()->toggle_chat(); } } -// global menus -void Client::func_menu(std::string const &args) +// used by keybinds to open the chat bar +void Client::func_ui_chatbar(std::string const &args) { - if (!ui::root()) { - con_warn << "User Interface not available!" << std::endl; - return; + if (client()->connected() && client()->mainwindow()->gamewindow()->visible()) { + client()->mainwindow()->gamewindow()->toggle_chatbar(); } +} - if (!args.size()) { - con_print << "^Bmenu functions" << std::endl; - con_print << " menu help show this help" << std::endl; - con_print << " menu list list available menus" << std::endl; - con_print << " menu [name] show a menu" << std::endl; - con_print << " menu back return to the previous menu" << std::endl; - con_print << " menu previous return to the previous menu" << std::endl; - con_print << " menu close close the current menu" << std::endl; - con_print << " menu hide hide the current menu" << std::endl; - ui::root()->list_menus(); +// used by keybinds to open the inventory view +void Client::func_ui_inventory(std::string const &args) +{ + if (client()->connected() && client()->mainwindow()->gamewindow()->visible()) { + client()->mainwindow()->gamewindow()->toggle_inventory(); } +} - std::stringstream argstr(args); - std::string command; - argstr >> command; - - aux::to_label(command); - - if (command.compare("hide") == 0) { - ui::root()->hide_menu(); - - } else if (command.compare("close") == 0) { - ui::root()->hide_menu(); - - } else if (command.compare("back") == 0) { - ui::root()->previous_menu(); - - } else if (command.compare("previous") == 0) { - ui::root()->previous_menu(); - - } else if (command.compare("list") == 0) { - ui::root()->list_menus(); +// used by keybinds to open the map view +void Client::func_ui_map(std::string const &args) +{ + if (client()->connected() && client()->mainwindow()->gamewindow()->visible()) { + client()->mainwindow()->gamewindow()->toggle_map(); + } +} - } else { - ui::root()->show_menu(command.c_str()); +// used by views and keybinds and to open entity views +void Client::func_view(std::string const &args) +{ + if (client()->mainwindow()) { + client()->mainwindow()->gamewindow()->show_menu(args); } } +// open the testmodel window void Client::func_testmodel(std::string const &args) { // if testmodel is called from the command line, no module has been loaded yet @@ -603,7 +628,7 @@ void Client::func_testmodel(std::string const &args) } if (!client()->connected()) { - client()->client_testmodelview->hide(); + client()->client_testmodelwindow->hide(); ui::console()->show(); return; } @@ -618,9 +643,9 @@ void Client::func_testmodel(std::string const &args) //video::set_loader_message(); //video::frame_loader(); - client()->client_testmodelview->set_modelname(modelname); - client()->client_testmodelview->raise(); // raise the window - client()->client_testmodelview->show(); + client()->client_testmodelwindow->set_modelname(modelname); + client()->client_testmodelwindow->raise(); // raise the window + client()->client_testmodelwindow->show(); if (ui::console()->visible()) { ui::console()->raise(); diff --git a/src/client/client.h b/src/client/client.h index 5b869ad..ff7ac98 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -12,7 +12,7 @@ #include "core/entity.h" #include "client/clientext.h" #include "client/soundext.h" -#include "client/testmodelview.h" +#include "client/testmodelwindow.h" #include "client/mainwindow.h" #include "render/renderext.h" @@ -66,8 +66,8 @@ public: } /// model test widget - inline TestModelView *testmodelview() { - return client_testmodelview; + inline TestModelWindow *testmodelwindow() { + return client_testmodelwindow; } /// local client sends a chat message @@ -89,6 +89,7 @@ private: static void func_list_menu(std::string const &args); static void func_ui_help(); + static void func_menu_help(); static void func_ui(std::string const &args); static void func_ui_chat(std::string const &args); @@ -103,7 +104,7 @@ private: static void func_view(std::string const &args); MainWindow *client_mainwindow; - TestModelView *client_testmodelview; + TestModelWindow *client_testmodelwindow; unsigned long previous_timestamp; }; diff --git a/src/client/entitymenu.cc b/src/client/entitymenu.cc index 56ce235..d2b3f27 100644 --- a/src/client/entitymenu.cc +++ b/src/client/entitymenu.cc @@ -12,7 +12,7 @@ namespace client { -EntityMenu::EntityMenu(ui::Widget *parent, const char * label) : ui::Widget(parent) +EntityMenu::EntityMenu(ui::Widget *parent, const char * label) : ui::Window(parent) { set_border(false); set_background(false); diff --git a/src/client/entitymenu.h b/src/client/entitymenu.h index 4907c98..0285879 100644 --- a/src/client/entitymenu.h +++ b/src/client/entitymenu.h @@ -10,13 +10,13 @@ #include "core/entity.h" #include "ui/container.h" #include "ui/label.h" -#include "ui/widget.h" +#include "ui/window.h" namespace client { /// entity menu -class EntityMenu : public ui::Widget +class EntityMenu : public ui::Window { public: /// create a new menu diff --git a/src/client/gamewindow.cc b/src/client/gamewindow.cc new file mode 100644 index 0000000..d539f53 --- /dev/null +++ b/src/client/gamewindow.cc @@ -0,0 +1,450 @@ +/* + client/gamewindow.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 <string> +#include <sstream> + +#include "core/info.h" +#include "core/application.h" +#include "ui/ui.h" +#include "client/targeticonbutton.h" +#include "client/gamewindow.h" + +namespace client +{ + +GameWindow::GameWindow(ui::Widget *parent) : ui::Window(parent) +{ + set_label("gamewindow"); + set_border(false); + set_background(false); + + gamewindow_hud = new HUD(this); + + label_viewname = new ui::Label(this); + label_viewname->set_label("viewnamelabel"); + label_viewname->set_alignment(ui::AlignCenter); + label_viewname->set_background(true); + label_viewname->set_font(ui::root()->font_large()); + + // sub menus + gamewindow_map = new Map(this); + gamewindow_entitymenu = new EntityMenu(this); + gamewindow_buymenu = new BuyMenu(this); + gamewindow_trademenu = new TradeMenu(this); + gamewindow_inventory = new InventoryWindow(this); + gamewindow_chat = new Chat(this); + + // icon buttons + gamewindow_menubutton = new ui::IconButton(this, "bitmaps/icons/button_menu", "ui_menu"); + + gamewindow_launchbutton = new ui::IconButton(this, "bitmaps/icons/button_launch", "launch"); + gamewindow_dockbutton = new TargetIconButton(this, "bitmaps/icons/button_dock", "dock", core::Entity::Dockable); + + gamewindow_homebutton = new ui::IconButton(this, "bitmaps/icons/button_home", "view main"); + gamewindow_chatbutton = new ui::IconButton(this, "bitmaps/icons/button_chat", "ui_chat"); + gamewindow_mapbutton = new ui::IconButton(this, "bitmaps/icons/button_map", "ui_map"); + gamewindow_inventorybutton = new ui::IconButton(this, "bitmaps/icons/button_ship", "ui_inventory"); +} + +GameWindow::~GameWindow() +{ +} + +void GameWindow::clear() +{ + gamewindow_chat->clear(); + + gamewindow_chat->hide(); + gamewindow_map->hide(); + gamewindow_inventory->hide(); + gamewindow_entitymenu->hide(); + gamewindow_buymenu->hide(); + gamewindow_trademenu->hide(); +} + +void GameWindow::event_text(const std::string & text) +{ + gamewindow_chat->event_text(text); +} + +void GameWindow::toggle_map() +{ + + if (!map()->visible()) { + if (chat()->visible() && !chat()->small_view()) { + chat()->hide(); + } + + if (inventory()->visible()) { + inventory()->hide(); + } + + if (gamewindow_entitymenu->visible()) { + gamewindow_entitymenu->hide(); + } + + if (gamewindow_buymenu->visible()) { + gamewindow_buymenu->hide(); + } + + if (gamewindow_trademenu->visible()) { + gamewindow_trademenu->hide(); + } + } + + map()->toggle(); + +/* if (map()->visible() && chat()->visible() && chat()->small_view()) { + chat()->raise(); + } +*/ +} + +void GameWindow::toggle_inventory() +{ + + if (!inventory()->visible()) { + if (chat()->visible() && !chat()->small_view()) { + chat()->hide(); + } + + if (map()->visible()) { + map()->hide(); + } + + if (gamewindow_entitymenu->visible()) { + gamewindow_entitymenu->hide(); + } + + if (gamewindow_buymenu->visible()) { + gamewindow_buymenu->hide(); + } + + if (gamewindow_trademenu->visible()) { + gamewindow_trademenu->hide(); + } + } + + inventory()->toggle(); + +/* if (inventory()->visible() && chat()->visible() && chat()->small_view()) { + chat()->raise(); + } +*/ +} + +void GameWindow::toggle_chat() +{ + if (chat()->small_view()) { + chat()->hide(); + } + + if (!chat()->visible()) { + if (map()->visible()) + map()->hide(); + + if (inventory()->visible()) { + inventory()->hide(); + } + + if (gamewindow_entitymenu->visible()) { + gamewindow_entitymenu->hide(); + } + + if (gamewindow_buymenu->visible()) { + gamewindow_buymenu->hide(); + } + + if (gamewindow_trademenu->visible()) { + gamewindow_trademenu->hide(); + } + } + + chat()->set_small_view(false); + chat()->toggle(); +} + +void GameWindow::toggle_chatbar() +{ + if (!chat()->small_view()) { + chat()->hide(); + } + + chat()->set_small_view(true); + chat()->toggle(); +} + +void GameWindow::show_menu(const std::string & args) +{ + if (!args.size()) + return; + + if (!core::localplayer()->view()) + return; + + if (!core::localplayer()->view()->menus().size()) + return; + + std::stringstream argstr(args); + std::string label; + if (!(argstr >> label)) + return; + + if (label.compare("buy") == 0) { + // buy menu, single item + unsigned long id; + + if (argstr >> id) { + // hide other menus + gamewindow_entitymenu->hide(); + gamewindow_trademenu->hide(); + // hide other windows + gamewindow_chat->hide(); + gamewindow_map->hide(); + gamewindow_inventory->hide(); + // requesting the info through game makes sure it is retreived from the server + gamewindow_buymenu->set_item( core::game()->request_info(id)); + // show buy menu + gamewindow_buymenu->show(); + } else { + con_print << "usage: view buy [info id] show the buy menu for this kind of item" << std::endl; + } + + } else if (label.compare("trade") == 0) { + // invetory based trade + std::string typestr; + + if(argstr >> typestr) { + aux::to_label(typestr); + + // hide other menus + gamewindow_buymenu->hide(); + gamewindow_entitymenu->hide(); + // hide other windows + gamewindow_chat->hide(); + gamewindow_map->hide(); + gamewindow_inventory->hide(); + // show trade menu + gamewindow_trademenu->set_itemtype(core::InfoType::find(typestr)); + gamewindow_trademenu->show(); + } else { + con_print << "usage: view trade [string] show the trade menu for this type of items" << std::endl; + } + + + } else if (label.compare("hide") == 0) { + // hide all menus + gamewindow_buymenu->hide(); + gamewindow_entitymenu->hide(); + gamewindow_trademenu->hide(); + } else { + // hide other menus + gamewindow_buymenu->hide(); + gamewindow_trademenu->hide(); + // hide other windows + gamewindow_chat->hide(); + gamewindow_map->hide(); + gamewindow_inventory->hide(); + // show other menus + gamewindow_entitymenu->generate(core::localplayer()->view(), label.c_str()); + gamewindow_entitymenu->show(); + } + +/* if (chat()->visible() && chat()->small_view()) + chat()->raise(); +*/ +} + +void GameWindow::resize() +{ + const float smallmargin = ui::UI::elementsize.height(); + + set_size(parent()->size()); + + // icons + const float icon_margin = 4.0f; + const float icon_size = 48.0f; + const float icon_count = 7; + const float l = (width() - ((icon_count + 1) * icon_margin) - (icon_count * icon_size)) * 0.5f; + + gamewindow_menubutton->set_geometry(l, icon_margin, icon_size, icon_size); + // spacer + gamewindow_dockbutton->set_geometry(l + 2.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size); + gamewindow_launchbutton->set_geometry(l + 2.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size); + gamewindow_homebutton->set_geometry(l + 3.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size); + gamewindow_inventorybutton->set_geometry(l + 4.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size); + gamewindow_chatbutton->set_geometry(l + 5.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size); + gamewindow_mapbutton->set_geometry(l + 6.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size); + + // reposition buy menu + gamewindow_buymenu->event_resize(); + // reposition trade menu + gamewindow_trademenu->event_resize(); + + // set hud geometry + gamewindow_hud->set_geometry(0, 0, width(), height()); + gamewindow_hud->event_resize(); + + // reposition map + gamewindow_map->set_size(width() - smallmargin * 2, height() - smallmargin * 4); + gamewindow_map->set_location(smallmargin, smallmargin * 2); + + // reposition inventory + gamewindow_inventory->set_size(width() - smallmargin * 2, height() - smallmargin * 4); + gamewindow_inventory->set_location(smallmargin, smallmargin * 2); + + // reposition labels + label_viewname->set_size(ui::UI::elementsize.width() * 1.5f, ui::UI::elementsize.height()); + label_viewname->set_location(width() - label_viewname->width() - smallmargin, height() - label_viewname->height() - smallmargin * 0.5f); +} + +void GameWindow::draw() +{ + const float smallmargin = ui::UI::elementsize.height(); + + if (core::localcontrol()->state() == core::Entity::Docked) { + gamewindow_launchbutton->show(); + gamewindow_dockbutton->hide(); + } else { + gamewindow_launchbutton->hide(); + gamewindow_dockbutton->show(); + } + + if (core::localplayer()->view()) { + + // hide hide when a view is set + gamewindow_hud->hide(); + + // docking view + if (core::localplayer()->view()->menus().size()) { + + // entity with menus + + if (map()->visible()) { + label_viewname->set_text(core::localplayer()->zone()->name()); + } else { + label_viewname->set_text(core::localplayer()->view()->name()); + } + + label_viewname->show(); + + if (gamewindow_entitymenu->generated_entity() != core::localplayer()->view()) { + // initially show the menu + show_menu("main"); + map()->hide(); + chat()->hide(); + + // hide other windows + gamewindow_chat->hide(); + gamewindow_map->hide(); + gamewindow_inventory->hide(); + + } else if (!gamewindow_entitymenu->visible() && !gamewindow_buymenu->visible() && !gamewindow_trademenu->visible() && + !inventory()->visible() && !map()->visible() && (!chat()->visible() || chat()->small_view())) { + + // show the menu if there's no other window open + gamewindow_entitymenu->show(); + } + + //gamewindow_notify->set_size(width() - smallmargin * 3.0f - ui::UI::elementsize.width() * 1.5f, height() - smallmargin * 4.0f); + //gamewindow_notify->set_location(smallmargin * 2.0f + ui::UI::elementsize.width() * 1.5f, smallmargin * 2.0f); + + gamewindow_homebutton->enable(); + + } else { + // entity without menus, plain view + this->hide(); + return; + } + + } else { + gamewindow_homebutton->disable(); + + //gamewindow_notify->set_geometry(gamewindow_map->location(), gamewindow_map->size()); + + if (gamewindow_entitymenu->visible()) { + gamewindow_entitymenu->hide(); + } + + if (gamewindow_entitymenu->generated_entity()) { + gamewindow_entitymenu->generate(0, 0); + } + + if (gamewindow_buymenu->visible()) { + gamewindow_buymenu->hide(); + } + + if (gamewindow_trademenu->visible()) { + gamewindow_trademenu->hide(); + } + + if (map()->visible()) { + label_viewname->set_text(core::localplayer()->zone()->name()); + label_viewname->show(); + } else { + label_viewname->hide(); + } + + if (!map()->visible() && !chat()->visible() && !inventory()->visible()) { + gamewindow_hud->set_focus(); + } + + gamewindow_hud->show(); + } + + // reposition chat widget + if (chat()->visible()) { + if (gamewindow_chat->small_view()) { + gamewindow_chat->set_size(width() - smallmargin * 2, font()->height() * 2); + gamewindow_chat->set_location(smallmargin, height() - smallmargin *2 - gamewindow_chat->height()); + } else { + gamewindow_chat->set_geometry(gamewindow_map->location(), gamewindow_map->size()); + } + gamewindow_chat->event_resize(); + } +} + +bool GameWindow::on_keypress(const int key, const unsigned int modifier) +{ + switch (key) { + + case SDLK_ESCAPE: + if (gamewindow_entitymenu->visible()) { + gamewindow_entitymenu->hide(); + return true; + } + + if (gamewindow_buymenu->visible()) { + gamewindow_buymenu->hide(); + return true; + } + + if (gamewindow_trademenu->visible()) { + gamewindow_trademenu->hide(); + return true; + } + + if (map()->visible()) { + map()->hide(); + return true; + } + + if (inventory()->visible()) { + inventory()->hide(); + return true; + } + + break; + + default: + break; + } + + return Window::on_keypress(key, modifier); +} + +} diff --git a/src/client/gamewindow.h b/src/client/gamewindow.h new file mode 100644 index 0000000..336158e --- /dev/null +++ b/src/client/gamewindow.h @@ -0,0 +1,103 @@ +/* + client/gamewindow.h + This file is part of the Osirion project and is distributed under + the terms and conditions of the GNU General Public License version 2 +*/ + +#ifndef __INCLUDED_CLIENT_GAMEWINDOW_H__ +#define __INCLUDED_CLIENT_GAMEWINDOW_H__ + +#include "ui/window.h" +#include "ui/label.h" +#include "ui/iconbutton.h" +#include "client/chat.h" +#include "client/buymenu.h" +#include "client/entitymenu.h" +#include "client/inventorywindow.h" +#include "client/trademenu.h" +#include "client/hud.h" +#include "client/map.h" + +namespace client +{ + +/** + * @brief the game user interface base widget + * The GameWindow is drawn if core::localcontrol() is set. + * It contains the HUD, icons and all menus for game interaction. + **/ +class GameWindow : public ui::Window +{ +public: + GameWindow(ui::Widget *parent = 0); + virtual ~GameWindow(); + + void clear(); + + void event_text(const std::string & text); + + /// toggle map window + void toggle_map(); + + /// toggle inventory window + void toggle_inventory(); + + /// togge chat window + void toggle_chat(); + + /// toggle chat bar + void toggle_chatbar(); + + /// show entity menus + void show_menu(const std::string & label); + + inline HUD *hud() { + return gamewindow_hud; + } + inline Map *map() { + return gamewindow_map; + } + inline Chat *chat() { + return gamewindow_chat; + } + inline InventoryWindow *inventory() { + return gamewindow_inventory; + } + inline EntityMenu *menu() { + return gamewindow_entitymenu; + } + +protected: + /// keypress event handler + virtual bool on_keypress(const int key, const unsigned int modifier); + + virtual void draw(); + virtual void resize(); + +private: + HUD *gamewindow_hud; + Chat *gamewindow_chat; + Map *gamewindow_map; + InventoryWindow *gamewindow_inventory; + + EntityMenu *gamewindow_entitymenu; + BuyMenu *gamewindow_buymenu; + TradeMenu *gamewindow_trademenu; + + ui::Label *label_viewname; + + ui::IconButton *gamewindow_menubutton; + ui::IconButton *gamewindow_dockbutton; + ui::IconButton *gamewindow_launchbutton; + ui::IconButton *gamewindow_homebutton; + ui::IconButton *gamewindow_chatbutton; + ui::IconButton *gamewindow_mapbutton; + ui::IconButton *gamewindow_inventorybutton; + + +}; // class GameWindow + +} // namepace client + + +#endif // __INCLUDED_CLIENT_GAMEWINDOW_H__ diff --git a/src/client/inventory.cc b/src/client/inventory.cc deleted file mode 100644 index 4894d3d..0000000 --- a/src/client/inventory.cc +++ /dev/null @@ -1,292 +0,0 @@ -/* - client/inventory.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/inventory.h" -#include "ui/label.h" -#include "ui/listitem.h" -#include "ui/paint.h" -#include "ui/ui.h" - -#include <iomanip> - -namespace client { - -Inventory::Inventory(ui::Widget *parent) : ui::Window(parent) -{ - menu_infotimestamp = 0; - menu_inventorytimestamp = 0; - menu_inforecord = 0; - menu_amount = 0; - - menu_modelview = new ui::ModelView(this); - menu_modelview->set_label("modelview"); - menu_modelview->set_background(false); - menu_modelview->set_border(false); - - menu_namelabel = new ui::Label(this); - menu_namelabel->set_label("label"); - menu_namelabel->set_background(false); - menu_namelabel->set_border(false); - menu_namelabel->set_font(ui::root()->font_large()); - menu_namelabel->set_alignment(ui::AlignCenter); - menu_namelabel->set_text("Inventory"); - - menu_listview = new ui::ListView(this); - menu_listview->set_label("listview"); - menu_listview->set_background(false); - menu_listview->set_border(true); - - menu_inventorytext = new ui::PlainText(this); - menu_inventorytext->set_label("inventorytext"); - menu_inventorytext->set_background(false); - menu_inventorytext->set_border(false); - menu_inventorytext->set_font(ui::root()->font_small()); - - menu_scrollpane = new ui::ScrollPane(this, menu_infotext); - menu_scrollpane->set_background(false); - menu_scrollpane->set_border(false); - menu_scrollpane->set_alignment(ui::AlignTop); - - menu_shipbutton = new ui::IconButton(this, "bitmaps/icons/button_ship"); - - hide(); -} - -Inventory::~Inventory() -{ -} - -void Inventory::toggle() -{ - if (visible()) - hide(); - else - show(); -} -void Inventory::update_inventory() -{ - menu_listview->clear(); - menu_inventorytimestamp = 0; - menu_infotimestamp = 0; - - if (!core::localcontrol() || !core::localcontrol()->inventory()) { - return; - } - - const core::Item *selecteditem = (menu_listview->selected() ? menu_listview->selected()->item() : 0); - - for (core::Inventory::Items::const_iterator it = core::localcontrol()->inventory()->items().begin(); it != core::localcontrol()->inventory()->items().end(); it++) { - core::Item *item = (*it); - - if (!item->info()) { - continue; - } - - // this makes sure inventory info gets requested from the server - core::game()->request_info(item->info()->id()); - - if (item->info()->timestamp() > menu_infotimestamp) { - menu_infotimestamp = item->info()->timestamp(); - } - - if (item->amount() != 0) { - ui::ListItem *listitem = 0; - - std::ostringstream str; - str << item->info()->name().c_str(); - if (item->amount() > 0) { - str << " (" << item->amount() << ")"; - } - - listitem = new ui::ListItem(menu_listview, str.str().c_str()); - listitem->set_height(listitem->font()->height() * 2.0f); - listitem->set_item(item); - listitem->set_info(item->info()); - - std::string sortkey(item->info()->type()->label()); - sortkey += '.'; - sortkey += item->info()->label(); - listitem->set_sortkey(sortkey); - - // preserve previous selection during update - if (item == selecteditem) { - menu_listview->select(listitem); - } - } - } - - // request ship info - if (core::localcontrol()->info()) { - core::game()->request_info(core::localcontrol()->info()->id()); - if (core::localcontrol()->info()->timestamp() > menu_infotimestamp) - menu_infotimestamp = core::localcontrol()->info()->timestamp(); - } - - menu_inventorytimestamp = core::localcontrol()->inventory()->timestamp(); - - if (menu_listview->selected()) { - set_info(menu_listview->selected()->info(), menu_listview->selected()->item()->amount()); - } else if (menu_inforecord != core::localcontrol()->info()) { - set_info(0, 0); - } - - menu_listview->sort(); - menu_listview->event_resize(); -} - -bool Inventory::verify() const -{ - if (!core::localcontrol() || !core::localcontrol()->inventory()) { - return true; - } - - if (menu_inventorytimestamp != core::localcontrol()->inventory()->timestamp()) { - return false; - } - - for (core::Inventory::Items::const_iterator it = core::localcontrol()->inventory()->items().begin(); it != core::localcontrol()->inventory()->items().end(); it++) { - core::Item *item = (*it); - - if (!item->info()) { - continue; - } - if (item->info()->timestamp() > menu_infotimestamp) { - return false; - } - } - return true; -} - -void Inventory::resize() -{ - const float smallmargin = ui::UI::elementsize.height(); - const float fontmargin = ui::root()->font_large()->height(); - const float icon_size = 48.0f; - - // resize label - menu_namelabel->set_size(width() - fontmargin * 2.0f, menu_namelabel->font()->height()); - menu_namelabel->set_location(fontmargin, fontmargin); - - // resize inventory listview - menu_listview->set_size(ui::UI::elementsize.width(), height() - smallmargin * 2.0f - fontmargin * 6.0f); - menu_listview->set_location(fontmargin, fontmargin * 3.0f); - - menu_inventorytext->set_size(menu_listview->width(), fontmargin * 2.0f); - menu_inventorytext->set_location(menu_listview->left(), menu_listview->bottom() + fontmargin); - - menu_shipbutton->set_size(icon_size, icon_size); - menu_shipbutton->set_location(menu_inventorytext->left(), height() - icon_size - fontmargin); - - // resize modelview - menu_modelview->set_size( width() - menu_listview->right() - fontmargin * 2.0f ,ui::UI::elementsize.width()); - menu_modelview->set_location(menu_listview->right() + fontmargin, fontmargin * 3.0f); - - // resize infotext - menu_scrollpane->set_size(menu_modelview->width(), height() - menu_modelview->bottom() - 2.0f * fontmargin); - menu_scrollpane->set_location(menu_modelview->left(), menu_modelview->bottom() + fontmargin); -} - -void Inventory::draw() -{ - if (!verify()) { - update_inventory(); - } - - if (menu_inforecord && (menu_inforecord->timestamp() > menu_infotimestamp)) { - set_info(menu_inforecord, menu_amount); - } - - std::stringstream str; - str << "Credits: " << std::setw(12) << core::localplayer()->credits(); - - if (core::localcontrol() && core::localcontrol()->inventory()) { - core::Inventory *inventory = core::localcontrol()->inventory(); - - std::stringstream cargostr; - cargostr << inventory->capacity_used() << " of " << inventory->capacity(); - - str << '\n' << "Cargo: " << aux::pad_left(cargostr.str(),12); - } - menu_inventorytext->set_text(str.str()); - - Window::draw(); -} - -void Inventory::show() -{ - menu_listview->deselect(); - set_info(0, 0); - Window::show(); -} - -void Inventory::set_info(const core::Info *info, const int amount) -{ - menu_inforecord = info; - menu_infotext.clear(); - menu_amount = amount; - - if (!info) { - menu_modelview->set_modelname(0); - menu_namelabel->set_text("Inventory"); - } else { - std::stringstream titlestr; - titlestr << info->name(); - if (amount > 0) { - titlestr << " (" << amount << ")"; - } - menu_namelabel->set_text(titlestr.str().c_str()); - core::game()->request_info(info->id()); - menu_modelview->set_modelname(info->modelname()); - - for (core::Info::Text::const_iterator it = menu_inforecord->text().begin(); it != menu_inforecord->text().end(); it++) { - menu_infotext.push_back((*it)); - } - if (info->timestamp() > menu_infotimestamp) { - menu_infotimestamp = info->timestamp(); - } - } - -} - -bool Inventory::on_emit(Widget *sender, const Event event, void *data) -{ - if (event == ui::Widget::EventButtonClicked) { - - if (sender == menu_shipbutton) { - menu_listview->deselect(); - set_info(core::localcontrol() ? core::localcontrol()->info() : 0, 0); - } - return true; - - } else if (event == ui::Widget::EventListViewChanged) { - - if (sender == menu_listview) { - set_info(menu_listview->selected() ? menu_listview->selected()->info() : 0, menu_listview->selected()->item()->amount()); - } - return true; - } - - return Window::on_emit(sender, event, data); -} - -bool Inventory::on_keypress(const int key, const unsigned int modifier) -{ - switch (key) { - - case SDLK_ESCAPE: - this->hide(); - return true; - break; - default: - break; - } - - return Window::on_keypress(key, modifier); -} - - -} // namespace client diff --git a/src/client/inventorywindow.cc b/src/client/inventorywindow.cc new file mode 100644 index 0000000..6698565 --- /dev/null +++ b/src/client/inventorywindow.cc @@ -0,0 +1,313 @@ +/* + client/inventorywindow.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/inventorywindow.h" +#include "ui/label.h" +#include "ui/listitem.h" +#include "ui/paint.h" +#include "ui/ui.h" + +#include <iomanip> + +namespace client { + +InventoryWindow::InventoryWindow(ui::Widget *parent) : ui::Window(parent) +{ + inventorywindow_infotimestamp = 0; + inventorywindow_inventorytimestamp = 0; + inventorywindow_inforecord = 0; + inventorywindow_amount = 0; + + inventorywindow_titlelabel = new ui::Label(this); + inventorywindow_titlelabel->set_label("title"); + inventorywindow_titlelabel->set_background(false); + inventorywindow_titlelabel->set_border(false); + inventorywindow_titlelabel->set_font(ui::root()->font_large()); + inventorywindow_titlelabel->set_alignment(ui::AlignCenter); + inventorywindow_titlelabel->set_text("INVENTORY"); + + inventorywindow_modelview = new ui::ModelView(this); + inventorywindow_modelview->set_label("modelview"); + inventorywindow_modelview->set_background(false); + inventorywindow_modelview->set_border(false); + + inventorywindow_modeltitlelabel = new ui::Label(inventorywindow_modelview); + inventorywindow_modeltitlelabel->set_background(false); + inventorywindow_modeltitlelabel->set_border(false); + //inventorywindow_modeltitlelabel->set_font(ui::root()->font_large()); + inventorywindow_modeltitlelabel->set_alignment(ui::AlignCenter); + + inventorywindow_modelnamelabel = new ui::Label(inventorywindow_modelview); + inventorywindow_modelnamelabel->set_background(false); + inventorywindow_modelnamelabel->set_border(false); + //inventorywindow_modelnamelabel->set_font(ui::root()->font_large()); + inventorywindow_modelnamelabel->set_alignment(ui::AlignCenter); + + inventorywindow_listview = new ui::ListView(this); + inventorywindow_listview->set_label("listview"); + inventorywindow_listview->set_background(false); + inventorywindow_listview->set_border(true); + + inventorywindow_inventorytext = new ui::PlainText(this); + inventorywindow_inventorytext->set_label("inventorytext"); + inventorywindow_inventorytext->set_background(false); + inventorywindow_inventorytext->set_border(false); + inventorywindow_inventorytext->set_font(ui::root()->font_small()); + + inventorywindow_scrollpane = new ui::ScrollPane(this, inventorywindow_infotext); + inventorywindow_scrollpane->set_background(false); + inventorywindow_scrollpane->set_border(false); + inventorywindow_scrollpane->set_alignment(ui::AlignTop); + + inventorywindow_shipbutton = new ui::IconButton(this, "bitmaps/icons/button_ship"); + + hide(); +} + +InventoryWindow::~InventoryWindow() +{ +} + +void InventoryWindow::toggle() +{ + if (visible()) + hide(); + else + show(); +} +void InventoryWindow::update_inventory() +{ + inventorywindow_listview->clear(); + inventorywindow_inventorytimestamp = 0; + inventorywindow_infotimestamp = 0; + + if (!core::localcontrol() || !core::localcontrol()->inventory()) { + return; + } + + const core::Item *selecteditem = (inventorywindow_listview->selected() ? inventorywindow_listview->selected()->item() : 0); + + for (core::Inventory::Items::const_iterator it = core::localcontrol()->inventory()->items().begin(); it != core::localcontrol()->inventory()->items().end(); it++) { + core::Item *item = (*it); + + if (!item->info()) { + continue; + } + + // this makes sure inventory info gets requested from the server + core::game()->request_info(item->info()->id()); + + if (item->info()->timestamp() > inventorywindow_infotimestamp) { + inventorywindow_infotimestamp = item->info()->timestamp(); + } + + if (item->amount() != 0) { + ui::ListItem *listitem = 0; + + std::ostringstream str; + str << item->info()->name().c_str(); + if (item->amount() > 0) { + str << " (" << item->amount() << ")"; + } + + listitem = new ui::ListItem(inventorywindow_listview, str.str().c_str()); + listitem->set_height(listitem->font()->height() * 2.0f); + listitem->set_item(item); + listitem->set_info(item->info()); + + std::string sortkey(item->info()->type()->label()); + sortkey += '.'; + sortkey += item->info()->label(); + listitem->set_sortkey(sortkey); + + // preserve previous selection during update + if (item == selecteditem) { + inventorywindow_listview->select(listitem); + } + } + } + + // request ship info + if (core::localcontrol()->info()) { + core::game()->request_info(core::localcontrol()->info()->id()); + if (core::localcontrol()->info()->timestamp() > inventorywindow_infotimestamp) + inventorywindow_infotimestamp = core::localcontrol()->info()->timestamp(); + } + + inventorywindow_inventorytimestamp = core::localcontrol()->inventory()->timestamp(); + + if (inventorywindow_listview->selected()) { + set_info(inventorywindow_listview->selected()->info(), inventorywindow_listview->selected()->item()->amount()); + } else if (inventorywindow_inforecord != core::localcontrol()->info()) { + set_info(0, 0); + } + + inventorywindow_listview->sort(); + inventorywindow_listview->event_resize(); +} + +bool InventoryWindow::verify() const +{ + if (!core::localcontrol() || !core::localcontrol()->inventory()) { + return true; + } + + if (inventorywindow_inventorytimestamp != core::localcontrol()->inventory()->timestamp()) { + return false; + } + + for (core::Inventory::Items::const_iterator it = core::localcontrol()->inventory()->items().begin(); it != core::localcontrol()->inventory()->items().end(); it++) { + core::Item *item = (*it); + + if (!item->info()) { + continue; + } + if (item->info()->timestamp() > inventorywindow_infotimestamp) { + return false; + } + } + return true; +} + +void InventoryWindow::resize() +{ + //const float smallmargin = ui::UI::elementsize.height(); + const float padding = ui::root()->font_large()->height(); + const float icon_size = 24.0f; // small icons + + // resize label + inventorywindow_titlelabel->set_size(width() - padding * 2.0f, inventorywindow_titlelabel->font()->height()); + inventorywindow_titlelabel->set_location(padding, padding); + + // resize inventory listview + inventorywindow_listview->set_size(ui::UI::elementsize.width(), height() -icon_size - padding * 8.0f); + inventorywindow_listview->set_location(padding, padding * 6.0f); + + inventorywindow_inventorytext->set_size(ui::UI::elementsize.width(), padding * 2.0f); + inventorywindow_inventorytext->set_location(inventorywindow_listview->left(), padding * 3.0f); + + inventorywindow_shipbutton->set_size(icon_size, icon_size); + inventorywindow_shipbutton->set_location(inventorywindow_inventorytext->left(), height() - icon_size - padding); + + // resize modelview + inventorywindow_modelview->set_size( width() - inventorywindow_listview->right() - padding * 2.0f ,ui::UI::elementsize.width()); + inventorywindow_modelview->set_location(inventorywindow_listview->right() + padding, padding * 3.0f); + + // modelview title label + inventorywindow_modelnamelabel->set_location(0, 0); + inventorywindow_modelnamelabel->set_size(inventorywindow_modelview->width(), inventorywindow_modelnamelabel->font()->height()); + + // modelview name label + inventorywindow_modeltitlelabel->set_size(inventorywindow_modelview->width(), inventorywindow_modeltitlelabel->font()->height()); + inventorywindow_modeltitlelabel->set_location(0, inventorywindow_modelview->height() - inventorywindow_modeltitlelabel->height()); + + // resize infotext + inventorywindow_scrollpane->set_size(inventorywindow_modelview->width(), height() - inventorywindow_modelview->bottom() - 2.0f * padding); + inventorywindow_scrollpane->set_location(inventorywindow_modelview->left(), inventorywindow_modelview->bottom() + padding); +} + +void InventoryWindow::draw() +{ + if (!verify()) { + update_inventory(); + } + + if (inventorywindow_inforecord && (inventorywindow_inforecord->timestamp() > inventorywindow_infotimestamp)) { + set_info(inventorywindow_inforecord, inventorywindow_amount); + } + + std::stringstream str; + str << "Credits: " << std::setw(12) << core::localplayer()->credits(); + + if (core::localcontrol() && core::localcontrol()->inventory()) { + core::Inventory *inventory = core::localcontrol()->inventory(); + + std::stringstream cargostr; + cargostr << inventory->capacity_used() << " of " << inventory->capacity(); + + str << '\n' << "Cargo: " << aux::pad_left(cargostr.str(),12); + } + inventorywindow_inventorytext->set_text(str.str()); + + Window::draw(); +} + +void InventoryWindow::show() +{ + inventorywindow_listview->deselect(); + set_info(core::localcontrol() ? core::localcontrol()->info() : 0, 0); + inventorywindow_modeltitlelabel->set_text("Ship Info"); + Window::show(); +} + +void InventoryWindow::set_info(const core::Info *info, const int amount) +{ + inventorywindow_inforecord = info; + inventorywindow_infotext.clear(); + inventorywindow_amount = amount; + + if (!info) { + inventorywindow_modelview->set_modelname(0); + inventorywindow_modeltitlelabel->set_text(""); + inventorywindow_modelnamelabel->set_text(""); + } else { + + core::game()->request_info(info->id()); + inventorywindow_modelview->set_modelname(info->modelname()); + inventorywindow_modelnamelabel->set_text(info->name()); + + for (core::Info::Text::const_iterator it = inventorywindow_inforecord->text().begin(); it != inventorywindow_inforecord->text().end(); it++) { + inventorywindow_infotext.push_back((*it)); + } + if (info->timestamp() > inventorywindow_infotimestamp) { + inventorywindow_infotimestamp = info->timestamp(); + } + } + +} + +bool InventoryWindow::on_emit(Widget *sender, const Event event, void *data) +{ + if (event == ui::Widget::EventButtonClicked) { + + if (sender == inventorywindow_shipbutton) { + inventorywindow_listview->deselect(); + set_info(core::localcontrol() ? core::localcontrol()->info() : 0, 0); + inventorywindow_modeltitlelabel->set_text("Ship Info"); + } + return true; + + } else if (event == ui::Widget::EventListViewChanged) { + + if (sender == inventorywindow_listview) { + inventorywindow_modeltitlelabel->set_text("Cargo Info"); + set_info(inventorywindow_listview->selected() ? inventorywindow_listview->selected()->info() : 0, inventorywindow_listview->selected()->item()->amount()); + } + return true; + } + + return Window::on_emit(sender, event, data); +} + +bool InventoryWindow::on_keypress(const int key, const unsigned int modifier) +{ + switch (key) { + + case SDLK_ESCAPE: + this->hide(); + return true; + break; + + default: + break; + } + + return Window::on_keypress(key, modifier); +} + + +} // namespace client diff --git a/src/client/inventory.h b/src/client/inventorywindow.h index 00b3b51..474df25 100644 --- a/src/client/inventory.h +++ b/src/client/inventorywindow.h @@ -1,11 +1,11 @@ /* - client/inventory.h + client/inventorywindow.h This file is part of the Osirion project and is distributed under the terms of the GNU General Public License version 2 */ -#ifndef __INCLUDED_CLIENT_INVENTORY_H__ -#define __INCLUDED_CLIENT_INVENTORY_H__ +#ifndef __INCLUDED_CLIENT_INVENTORYWINDOW_H__ +#define __INCLUDED_CLIENT_INVENTORYWINDOW_H__ #include "core/info.h" #include "core/inventory.h" @@ -21,15 +21,16 @@ namespace client { /** * @brief an inventory window widget */ -class Inventory : public ui::Window +class InventoryWindow : public ui::Window { public: - Inventory(ui::Widget *parent = 0); - ~Inventory(); + InventoryWindow(ui::Widget *parent = 0); + ~InventoryWindow(); void toggle(); virtual void show(); + protected: /// resize event handler virtual void resize(); @@ -50,24 +51,27 @@ private: bool verify() const; - unsigned long menu_inventorytimestamp; - unsigned long menu_infotimestamp; + unsigned long inventorywindow_inventorytimestamp; + unsigned long inventorywindow_infotimestamp; - int menu_amount; + int inventorywindow_amount; - ui::Text menu_infotext; + ui::Text inventorywindow_infotext; + + const core::Info *inventorywindow_inforecord; - const core::Info *menu_inforecord; + ui::ModelView *inventorywindow_modelview; - ui::ModelView *menu_modelview; + ui::Label *inventorywindow_titlelabel; + ui::Label *inventorywindow_modeltitlelabel; + ui::Label *inventorywindow_modelnamelabel; - ui::Label *menu_namelabel; - ui::ListView *menu_listview; - ui::PlainText *menu_inventorytext; - ui::ScrollPane *menu_scrollpane; - ui::IconButton *menu_shipbutton; + ui::ListView *inventorywindow_listview; + ui::PlainText *inventorywindow_inventorytext; + ui::ScrollPane *inventorywindow_scrollpane; + ui::IconButton *inventorywindow_shipbutton; -}; // class Inventory +}; // class InventoryWindow } -#endif // __INCLUDED_CLIENT_INVENTORY_H__ +#endif // __INCLUDED_CLIENT_INVENTORYWINDOW_H__ diff --git a/src/client/mainwindow.cc b/src/client/mainwindow.cc index 91cb9b4..698c5b3 100644 --- a/src/client/mainwindow.cc +++ b/src/client/mainwindow.cc @@ -18,15 +18,25 @@ MainWindow::MainWindow(ui::Widget *parent) : ui::Widget(parent) set_border(false); set_background(false); - // add child widgets - mainwindow_devinfo = new DevInfoWidget(this); - mainwindow_statsinfo = new StatsInfoWidget(this); - mainwindow_keyinfo = new KeyInfoWidget(this); - mainwindow_clock = new ClockInfoWidget(this); - - mainwindow_playerview = new PlayerView(this); - mainwindow_playerview->raise(); - mainwindow_playerview->hide(); + // 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(); } MainWindow::~MainWindow() @@ -41,62 +51,72 @@ void MainWindow::resize() //const float largemargin = ui::UI::elementsize.width() * 0.25 const float smallmargin = ui::UI::elementsize.height(); - // resize player view - mainwindow_playerview->set_size(size()); - + // reposition notifications + mainwindow_notificationswidget->set_size(width() - smallmargin * 2, height() - smallmargin * 4); + mainwindow_notificationswidget->set_location(smallmargin, smallmargin * 2); + // reposition devinfo widget - mainwindow_devinfo->set_size(font()->width()*32, font()->height()*5); - mainwindow_devinfo->set_location(smallmargin, smallmargin); + mainwindow_devinfowidget->set_size(font()->width()*32, font()->height()*5); + mainwindow_devinfowidget->set_location(smallmargin, smallmargin); // reposition stats widget - mainwindow_statsinfo->set_size(font()->width()*12, font()->height()*5); - mainwindow_statsinfo->set_location(width() - mainwindow_statsinfo->width() - smallmargin, smallmargin); + mainwindow_statsinfowidget->set_size(font()->width()*12, font()->height()*5); + mainwindow_statsinfowidget->set_location(width() - mainwindow_statsinfowidget->width() - smallmargin, smallmargin); // reposition clock - mainwindow_clock->set_size(font()->width()*7, font()->height()); - mainwindow_clock->set_location(width() - mainwindow_clock->width() - smallmargin, mainwindow_statsinfo->bottom() + smallmargin); + 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_keyinfo->set_size(font()->width()*12, font()->height()*1); - mainwindow_keyinfo->set_location(width() - mainwindow_keyinfo->width() - smallmargin, - height() - mainwindow_keyinfo->height() - smallmargin); + 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()); } void MainWindow::clear() { - mainwindow_playerview->clear(); + // clear console notifications + mainwindow_notificationswidget->clear(); + + // clear the game window + mainwindow_gamewindow->clear(); } void MainWindow::event_text(const std::string & text) { - mainwindow_playerview->event_text(text); + mainwindow_notificationswidget->event_text(text); + mainwindow_gamewindow->event_text(text); } void MainWindow::draw() { - // the mianwindow is only drawn when the application is connected + // the mainwindow is only drawn if the application is connected // and the loader screen is not shown - // FIXME the mainwindow should alway be visible, except in the loader screen - mainwindow_devinfo->set_visible(draw_devinfo->value() ? true : false); - mainwindow_statsinfo->set_visible(draw_stats->value() ? true : false); - mainwindow_keyinfo->set_visible(draw_keypress->value() ? true : false); + 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_clock->set_mode(ClockInfoWidget::ClockOff); + mainwindow_clockwidget->set_mode(ClockInfoWidget::ClockOff); } else if (draw_clock->value() >= 2) { - mainwindow_clock->set_mode(ClockInfoWidget::Clock12Hours); + mainwindow_clockwidget->set_mode(ClockInfoWidget::Clock12Hours); } else { - mainwindow_clock->set_mode(ClockInfoWidget::Clock24Hours); + mainwindow_clockwidget->set_mode(ClockInfoWidget::Clock24Hours); } - // FIXME - either draw one of the menus or draw the playerview if (ui::root()->active() || !core::game()->interactive() || !core::localcontrol() || (core::localplayer()->view() && !core::localplayer()->view()->menus().size())) { - mainwindow_playerview->hide(); + if (mainwindow_gamewindow->visible()) + mainwindow_gamewindow->hide(); } else { - mainwindow_playerview->show(); - mainwindow_playerview->set_focus(); - + if (!mainwindow_gamewindow->visible()) + mainwindow_gamewindow->show(); } } diff --git a/src/client/mainwindow.h b/src/client/mainwindow.h index 12ea23f..3497913 100644 --- a/src/client/mainwindow.h +++ b/src/client/mainwindow.h @@ -9,8 +9,9 @@ #include "ui/window.h" -#include "client/playerview.h" +#include "client/gamewindow.h" #include "client/infowidget.h" +#include "client/notifications.h" namespace client { @@ -26,21 +27,26 @@ public: void event_text(const std::string & text); - inline PlayerView *playerview() { - return mainwindow_playerview; + inline GameWindow *gamewindow() { + return mainwindow_gamewindow; } + + inline Notifications *notificationswidget() { + return mainwindow_notificationswidget; + } + protected: virtual void draw(); virtual void resize(); private: - DevInfoWidget *mainwindow_devinfo; - StatsInfoWidget *mainwindow_statsinfo; - KeyInfoWidget *mainwindow_keyinfo; - ClockInfoWidget *mainwindow_clock; - Notifications *mainwindow_notify; - PlayerView *mainwindow_playerview; + DevInfoWidget *mainwindow_devinfowidget; + StatsInfoWidget *mainwindow_statsinfowidget; + KeyInfoWidget *mainwindow_keyinfowidget; + ClockInfoWidget *mainwindow_clockwidget; + Notifications *mainwindow_notificationswidget; + GameWindow *mainwindow_gamewindow; }; diff --git a/src/client/playerview.cc b/src/client/playerview.cc deleted file mode 100644 index d5026ef..0000000 --- a/src/client/playerview.cc +++ /dev/null @@ -1,418 +0,0 @@ -/* - client/playerview.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 <string> -#include <sstream> - -#include "core/info.h" -#include "core/application.h" -#include "ui/ui.h" -#include "client/targeticonbutton.h" -#include "client/playerview.h" - - -namespace client -{ - -PlayerView::PlayerView(ui::Widget *parent) : ui::Widget(parent) -{ - set_label("playerview"); - set_border(false); - set_background(false); - - view_notify = new Notifications(this); - view_hud = new HUD(this); - - label_viewname = new ui::Label(this); - label_viewname->set_label("viewnamelabel"); - label_viewname->set_alignment(ui::AlignCenter); - label_viewname->set_background(true); - label_viewname->set_font(ui::root()->font_large()); - - // sub menus - view_map = new Map(this); - view_entitymenu = new EntityMenu(this); - view_buymenu = new BuyMenu(this); - view_trademenu = new TradeMenu(this); - view_inventory = new Inventory(this); - view_chat = new Chat(this); - - // icon buttons - view_menubutton = new ui::IconButton(this, "bitmaps/icons/button_menu", "ui_menu"); - - view_launchbutton = new ui::IconButton(this, "bitmaps/icons/button_launch", "launch"); - view_dockbutton = new TargetIconButton(this, "bitmaps/icons/button_dock", "dock", core::Entity::Dockable); - - view_homebutton = new ui::IconButton(this, "bitmaps/icons/button_home", "view main"); - view_chatbutton = new ui::IconButton(this, "bitmaps/icons/button_chat", "ui_chat"); - view_mapbutton = new ui::IconButton(this, "bitmaps/icons/button_map", "ui_map"); - view_inventorybutton = new ui::IconButton(this, "bitmaps/icons/button_ship", "ui_inventory"); -} - -PlayerView::~PlayerView() -{ -} - -void PlayerView::clear() -{ - view_chat->clear(); - view_notify->clear(); - - view_chat->hide(); - view_map->hide(); - view_inventory->hide(); - view_entitymenu->hide(); - view_buymenu->hide(); - view_trademenu->hide(); -} - -void PlayerView::event_text(const std::string & text) -{ - view_chat->event_text(text); - view_notify->event_text(text); -} - -void PlayerView::toggle_map() -{ - - if (!map()->visible()) { - if (chat()->visible() && !chat()->small_view()) { - chat()->hide(); - } - - if (inventory()->visible()) { - inventory()->hide(); - } - - if (view_entitymenu->visible()) { - view_entitymenu->hide(); - } - - if (view_buymenu->visible()) { - view_buymenu->hide(); - } - - if (view_trademenu->visible()) { - view_trademenu->hide(); - } - } - - map()->toggle(); - -/* if (map()->visible() && chat()->visible() && chat()->small_view()) { - chat()->raise(); - } -*/ -} - -void PlayerView::toggle_inventory() -{ - - if (!inventory()->visible()) { - if (chat()->visible() && !chat()->small_view()) { - chat()->hide(); - } - - if (map()->visible()) { - map()->hide(); - } - - if (view_entitymenu->visible()) { - view_entitymenu->hide(); - } - - if (view_buymenu->visible()) { - view_buymenu->hide(); - } - - if (view_trademenu->visible()) { - view_trademenu->hide(); - } - } - - inventory()->toggle(); - -/* if (inventory()->visible() && chat()->visible() && chat()->small_view()) { - chat()->raise(); - } -*/ -} - -void PlayerView::toggle_chat() -{ - if (chat()->small_view()) { - chat()->hide(); - } - - if (!chat()->visible()) { - if (map()->visible()) - map()->hide(); - - if (inventory()->visible()) { - inventory()->hide(); - } - - if (view_entitymenu->visible()) { - view_entitymenu->hide(); - } - - if (view_buymenu->visible()) { - view_buymenu->hide(); - } - - if (view_trademenu->visible()) { - view_trademenu->hide(); - } - } - - chat()->set_small_view(false); - chat()->toggle(); -} - -void PlayerView::toggle_chatbar() -{ - if (!chat()->small_view()) { - chat()->hide(); - } - - chat()->set_small_view(true); - chat()->toggle(); -} - -void PlayerView::show_menu(const std::string & args) -{ - if (!args.size()) - return; - - if (!core::localplayer()->view()) - return; - - if (!core::localplayer()->view()->menus().size()) - return; - - std::stringstream argstr(args); - std::string label; - if (!(argstr >> label)) - return; - - if (label.compare("buy") == 0) { - // buy menu, single item - unsigned long id; - - if (argstr >> id) { - // hide other menus - view_entitymenu->hide(); - view_trademenu->hide(); - // hide other windows - view_chat->hide(); - view_map->hide(); - view_inventory->hide(); - // requesting the info through game makes sure it is retreived from the server - view_buymenu->set_item( core::game()->request_info(id)); - // show buy menu - view_buymenu->show(); - } else { - con_print << "usage: view buy [info id] show the buy menu for this kind of item" << std::endl; - } - - } else if (label.compare("trade") == 0) { - // invetory based trade - std::string typestr; - - if(argstr >> typestr) { - aux::to_label(typestr); - - // hide other menus - view_buymenu->hide(); - view_entitymenu->hide(); - // hide other windows - view_chat->hide(); - view_map->hide(); - view_inventory->hide(); - // show trade menu - view_trademenu->set_itemtype(core::InfoType::find(typestr)); - view_trademenu->show(); - } else { - con_print << "usage: view trade [string] show the trade menu for this type of items" << std::endl; - } - - - } else if (label.compare("hide") == 0) { - // hide all menus - view_buymenu->hide(); - view_entitymenu->hide(); - view_trademenu->hide(); - } else { - // hide other menus - view_buymenu->hide(); - view_trademenu->hide(); - // hide other windows - view_chat->hide(); - view_map->hide(); - view_inventory->hide(); - // show other menus - view_entitymenu->generate(core::localplayer()->view(), label.c_str()); - view_entitymenu->show(); - } - -/* if (chat()->visible() && chat()->small_view()) - chat()->raise(); -*/ -} - -void PlayerView::resize() -{ - const float smallmargin = ui::UI::elementsize.height(); - - set_size(parent()->size()); - - // icons - const float icon_margin = 4.0f; - const float icon_size = 48.0f; - const float icon_count = 7; - const float l = (width() - ((icon_count + 1) * icon_margin) - (icon_count * icon_size)) * 0.5f; - - view_menubutton->set_geometry(l, icon_margin, icon_size, icon_size); - // spacer - view_dockbutton->set_geometry(l + 2.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size); - view_launchbutton->set_geometry(l + 2.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size); - view_homebutton->set_geometry(l + 3.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size); - view_inventorybutton->set_geometry(l + 4.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size); - view_chatbutton->set_geometry(l + 5.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size); - view_mapbutton->set_geometry(l + 6.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size); - - // reposition buy menu - view_buymenu->event_resize(); - // reposition trade menu - view_trademenu->event_resize(); - - // set hud geometry - view_hud->set_geometry(0, 0, width(), height()); - view_hud->event_resize(); - - // reposition map - view_map->set_size(width() - smallmargin * 2, height() - smallmargin * 4); - view_map->set_location(smallmargin, smallmargin * 2); - - // reposition inventory - view_inventory->set_size(width() - smallmargin * 2, height() - smallmargin * 4); - view_inventory->set_location(smallmargin, smallmargin * 2); - - // reposition notifications - view_notify->set_geometry(view_map->location(), view_map->size()); - - // reposition labels - label_viewname->set_size(ui::UI::elementsize.width() * 1.5f, ui::UI::elementsize.height()); - label_viewname->set_location(width() - label_viewname->width() - smallmargin, height() - label_viewname->height() - smallmargin * 0.5f); -} - -void PlayerView::draw() -{ - const float smallmargin = ui::UI::elementsize.height(); - - if (core::localcontrol()->state() == core::Entity::Docked) { - view_launchbutton->show(); - view_dockbutton->hide(); - } else { - view_launchbutton->hide(); - view_dockbutton->show(); - } - - if (core::localplayer()->view()) { - - // hide hide when a view is set - view_hud->hide(); - - // docking view - if (core::localplayer()->view()->menus().size()) { - - // entity with menus - - if (map()->visible()) { - label_viewname->set_text(core::localplayer()->zone()->name()); - } else { - label_viewname->set_text(core::localplayer()->view()->name()); - } - - label_viewname->show(); - - if (view_entitymenu->generated_entity() != core::localplayer()->view()) { - // initially show the menu - show_menu("main"); - map()->hide(); - chat()->hide(); - - // hide other windows - view_chat->hide(); - view_map->hide(); - view_inventory->hide(); - - } else if (!view_entitymenu->visible() && !view_buymenu->visible() && !view_trademenu->visible() && - !inventory()->visible() && !map()->visible() && (!chat()->visible() || chat()->small_view())) { - - // show the menu if there's no other window open - view_entitymenu->show(); - } - - view_notify->set_size(width() - smallmargin * 3.0f - ui::UI::elementsize.width() * 1.5f, height() - smallmargin * 4.0f); - view_notify->set_location(smallmargin * 2.0f + ui::UI::elementsize.width() * 1.5f, smallmargin * 2.0f); - - view_homebutton->enable(); - - } else { - // entity without menus, plain view - this->hide(); - return; - } - - } else { - view_homebutton->disable(); - - view_notify->set_geometry(view_map->location(), view_map->size()); - - if (view_entitymenu->visible()) { - view_entitymenu->hide(); - } - - if (view_entitymenu->generated_entity()) { - view_entitymenu->generate(0, 0); - } - - if (view_buymenu->visible()) { - view_buymenu->hide(); - } - - if (view_trademenu->visible()) { - view_trademenu->hide(); - } - - if (map()->visible()) { - label_viewname->set_text(core::localplayer()->zone()->name()); - label_viewname->show(); - } else { - label_viewname->hide(); - } - - if (!map()->visible() && !chat()->visible() && !inventory()->visible()) { - view_hud->set_focus(); - } - - view_hud->show(); - } - - // reposition chat widget - if (chat()->visible()) { - if (view_chat->small_view()) { - view_chat->set_size(width() - smallmargin * 2, font()->height() * 2); - view_chat->set_location(smallmargin, height() - smallmargin *2 - view_chat->height()); - } else { - view_chat->set_geometry(view_map->location(), view_map->size()); - } - view_chat->event_resize(); - } -} - -} diff --git a/src/client/playerview.h b/src/client/playerview.h deleted file mode 100644 index e457ef1..0000000 --- a/src/client/playerview.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - client/playerview.h - This file is part of the Osirion project and is distributed under - the terms and conditions of the GNU General Public License version 2 -*/ - -#ifndef __INCLUDED_CLIENT_PLAYERVIEW_H__ -#define __INCLUDED_CLIENT_PLAYERVIEW_H__ - -#include "ui/widget.h" -#include "ui/label.h" -#include "ui/iconbutton.h" -#include "client/chat.h" -#include "client/buymenu.h" -#include "client/entitymenu.h" -#include "client/inventory.h" -#include "client/trademenu.h" -#include "client/hud.h" -#include "client/map.h" -#include "client/notifications.h" - -namespace client -{ - -/// the player's view when joined -class PlayerView : public ui::Widget -{ -public: - PlayerView(ui::Widget *parent = 0); - virtual ~PlayerView(); - - void clear(); - - void event_text(const std::string & text); - - /// toggle map window - void toggle_map(); - - /// toggle inventory window - void toggle_inventory(); - - /// togge chat window - void toggle_chat(); - - /// toggle chat bar - void toggle_chatbar(); - - /// show entity menus - void show_menu(const std::string & label); - - inline HUD *hud() { - return view_hud; - } - inline Map *map() { - return view_map; - } - inline Chat *chat() { - return view_chat; - } - inline Inventory *inventory() { - return view_inventory; - } - inline Notifications *notify() { - return view_notify; - } - inline EntityMenu *menu() { - return view_entitymenu; - } - -protected: - virtual void draw(); - virtual void resize(); - -private: - Notifications *view_notify; - HUD *view_hud; - Chat *view_chat; - Map *view_map; - Inventory *view_inventory; - - EntityMenu *view_entitymenu; - BuyMenu *view_buymenu; - TradeMenu *view_trademenu; - - ui::Label *label_viewname; - - ui::IconButton *view_menubutton; - ui::IconButton *view_dockbutton; - ui::IconButton *view_launchbutton; - ui::IconButton *view_homebutton; - ui::IconButton *view_chatbutton; - ui::IconButton *view_mapbutton; - ui::IconButton *view_inventorybutton; -}; - -} - - -#endif // __INCLUDED_CLIENT_PLAYERVIEW_H__ diff --git a/src/client/testmodelview.cc b/src/client/testmodelview.cc deleted file mode 100644 index 16d9cc1..0000000 --- a/src/client/testmodelview.cc +++ /dev/null @@ -1,131 +0,0 @@ -/* - client/testmodelview.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 "ui/ui.h" -#include "ui/paint.h" -#include "client/testmodelview.h" -#include "model/model.h" - -namespace client -{ - -TestModelView::TestModelView(ui::Widget *parent) -{ - set_background(true); - set_border(false); - set_label("testmodelview"); - testmodelview_modelview = new ui::ModelView(this); - testmodelview_modelview->set_radius(1.0f); - - testmodelview_text = new ui::PlainText(this); - testmodelview_text->set_label("text"); - testmodelview_text->set_background(false); - testmodelview_text->set_border(false); - - testmodelview_wireframebutton = new ui::IconButton(this, "bitmaps/icons/button_wireframe", "toggle r_wireframe"); - - testmodelview_normalsbutton = new ui::IconButton(this, "bitmaps/icons/button_normals", "toggle r_normals"); - - testmodelview_closebutton = new ui::Button(this); - testmodelview_closebutton->set_text("Close"); - testmodelview_closebutton->set_background(true); -} - -TestModelView::~TestModelView() -{ -} - -void TestModelView::set_modelname(const std::string & modelname) -{ - testmodelview_modelview->set_modelname(modelname); -} - -void TestModelView::show() -{ - resize(); - ui::Widget::show(); -} - -void TestModelView::hide() { - ui::Widget::hide(); -} - -void TestModelView::resize() -{ - // this view covers the entire screen - set_size(parent()->size()); - - // resize the label - testmodelview_text->set_size(width() - 16.0f, testmodelview_text->font()->height() * 5.0f); - testmodelview_text->set_location(8.0f, 8.0f); - - // resize the 3d model view - testmodelview_modelview->set_size(width(),height()); - testmodelview_modelview->set_location(0.0f, 0.0f); - - // resize icon buttons - const float icon_margin = 4.0f; - const float icon_size = 48.0f; - const float icon_count = 2; - const float l = (width() - ((icon_count + 1) * icon_margin) - (icon_count * icon_size)) * 0.5f; - - testmodelview_wireframebutton->set_geometry(l, icon_margin, icon_size, icon_size); - testmodelview_normalsbutton->set_geometry(l + 1.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size); - - // reposition close button - testmodelview_closebutton->set_size( - ui::UI::elementsize.width() * 1.5f, - ui::UI::elementsize.height() - ); - testmodelview_closebutton->set_location( - width() - testmodelview_closebutton->width() - ui::UI::elementsize.height(), - height() - testmodelview_closebutton->height() - ui::UI::elementsize.height() * 0.5f - ); -} - -void TestModelView::draw_background() -{ - math::Color color(palette()->background()); - color.a = 1.0f; - ui::Paint::set_color(color); - ui::Paint::draw_rectangle(global_location(), size()); -} - -void TestModelView::draw() -{ - model::Model *model = model::Model::find(testmodelview_modelview->modelname()); - - std::ostringstream str; - str << testmodelview_modelview->modelname() << '\n'; - - if (model) { - size_t frags = 0; - - for (model::Model::Groups::const_iterator git = model->groups().begin(); git != model->groups().end(); git++) { - frags += (*git)->size(); - } - str << '\n'; - str << "tris: " << model->model_tris_count << '\n'; - str << "quads: " << model->model_quad_count << '\n'; - str << "fragments: " << frags << '\n'; - } - testmodelview_text->set_text(str.str()); -} - -bool TestModelView::on_emit(Widget *sender, const Event event, void *data) -{ - if (event == ui::Widget::EventButtonClicked) { - // slider value changed - if (sender == testmodelview_closebutton) { - hide(); - } - return true; - } - return false; -} - -} // namespace client - diff --git a/src/client/testmodelview.h b/src/client/testmodelview.h deleted file mode 100644 index fd363f0..0000000 --- a/src/client/testmodelview.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - client/testmodelview.h - This file is part of the Osirion project and is distributed under - the terms and conditions of the GNU General Public License version 2 -*/ - -#ifndef __INCLUDED_CLIENT_TESTMODELVIEW_H__ -#define __INCLUDED_CLIENT_TESTMODELVIEW_H__ - -#include "ui/widget.h" -#include "ui/button.h" -#include "ui/iconbutton.h" -#include "ui/plaintext.h" -#include "ui/modelview.h" - -namespace client -{ - -/// the world view when connected -class TestModelView : public ui::Widget -{ -public: - TestModelView(ui::Widget *parent = 0); - virtual ~TestModelView(); - - void set_modelname(const std::string & modelname); - - /// show the testmodelview - virtual void show(); - - /// hide the testmodelview - virtual void hide(); - -protected: - /// update model statistics - virtual void draw(); - - /// resize te testmodelview - virtual void resize(); - - /// draw a black background - virtual void draw_background(); - - /// emit event handler - virtual bool on_emit(Widget *sender, const Event event, void *data); - -private: - ui::ModelView *testmodelview_modelview; - ui::PlainText *testmodelview_text; - ui::Button *testmodelview_closebutton; - ui::IconButton *testmodelview_wireframebutton; - ui::IconButton *testmodelview_normalsbutton; - -}; // class TestModelView - -} // namespace client - -#endif // __INCLUDED_CLIENT_TESTMODELVIEW_H__ diff --git a/src/client/testmodelwindow.cc b/src/client/testmodelwindow.cc new file mode 100644 index 0000000..9d8d0b0 --- /dev/null +++ b/src/client/testmodelwindow.cc @@ -0,0 +1,121 @@ +/* + client/testmodelwindow.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 "ui/ui.h" +#include "ui/paint.h" +#include "client/testmodelwindow.h" +#include "model/model.h" + +namespace client +{ + +TestModelWindow::TestModelWindow(ui::Widget *parent) +{ + set_background(true); + set_border(false); + set_label("testmodelwindow"); + testmodelwindow_modelview = new ui::ModelView(this); + testmodelwindow_modelview->set_radius(1.0f); + + testmodelwindow_text = new ui::PlainText(this); + testmodelwindow_text->set_label("text"); + testmodelwindow_text->set_background(false); + testmodelwindow_text->set_border(false); + + testmodelwindow_wireframebutton = new ui::IconButton(this, "bitmaps/icons/button_wireframe", "toggle r_wireframe"); + + testmodelwindow_normalsbutton = new ui::IconButton(this, "bitmaps/icons/button_normals", "toggle r_normals"); + + testmodelwindow_closebutton = new ui::Button(this); + testmodelwindow_closebutton->set_text("Close"); + testmodelwindow_closebutton->set_background(true); +} + +TestModelWindow::~TestModelWindow() +{ +} + +void TestModelWindow::set_modelname(const std::string & modelname) +{ + testmodelwindow_modelview->set_modelname(modelname); +} + +void TestModelWindow::resize() +{ + // this is a fullscreen window + set_size(parent()->size()); + + // resize the label + testmodelwindow_text->set_size(width() - 16.0f, testmodelwindow_text->font()->height() * 5.0f); + testmodelwindow_text->set_location(8.0f, 8.0f); + + // resize the 3d model view + testmodelwindow_modelview->set_size(width(),height()); + testmodelwindow_modelview->set_location(0.0f, 0.0f); + + // resize icon buttons + const float icon_margin = 4.0f; + const float icon_size = 48.0f; + const float icon_count = 2; + const float l = (width() - ((icon_count + 1) * icon_margin) - (icon_count * icon_size)) * 0.5f; + + testmodelwindow_wireframebutton->set_geometry(l, icon_margin, icon_size, icon_size); + testmodelwindow_normalsbutton->set_geometry(l + 1.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size); + + // reposition close button + testmodelwindow_closebutton->set_size( + ui::UI::elementsize.width() * 1.5f, + ui::UI::elementsize.height() + ); + testmodelwindow_closebutton->set_location( + width() - testmodelwindow_closebutton->width() - ui::UI::elementsize.height(), + height() - testmodelwindow_closebutton->height() - ui::UI::elementsize.height() * 0.5f + ); +} + +void TestModelWindow::draw_background() +{ + math::Color color(palette()->background()); + color.a = 1.0f; + ui::Paint::set_color(color); + ui::Paint::draw_rectangle(global_location(), size()); +} + +void TestModelWindow::draw() +{ + model::Model *model = model::Model::find(testmodelwindow_modelview->modelname()); + + std::ostringstream str; + str << testmodelwindow_modelview->modelname() << '\n'; + + if (model) { + size_t frags = 0; + + for (model::Model::Groups::const_iterator git = model->groups().begin(); git != model->groups().end(); git++) { + frags += (*git)->size(); + } + str << '\n'; + str << "tris: " << model->model_tris_count << '\n'; + str << "quads: " << model->model_quad_count << '\n'; + str << "fragments: " << frags << '\n'; + } + testmodelwindow_text->set_text(str.str()); +} + +bool TestModelWindow::on_emit(Widget *sender, const Event event, void *data) +{ + if (event == ui::Widget::EventButtonClicked) { + // slider value changed + if (sender == testmodelwindow_closebutton) { + hide(); + } + return true; + } + return false; +} + +} // namespace client + diff --git a/src/client/testmodelwindow.h b/src/client/testmodelwindow.h new file mode 100644 index 0000000..c6b4e64 --- /dev/null +++ b/src/client/testmodelwindow.h @@ -0,0 +1,55 @@ +/* + client/testmodelwindow.h + This file is part of the Osirion project and is distributed under + the terms and conditions of the GNU General Public License version 2 +*/ + +#ifndef __INCLUDED_CLIENT_TESTMODELWINDOW_H__ +#define __INCLUDED_CLIENT_TESTMODELWINDOW_H__ + +#include "ui/widget.h" +#include "ui/button.h" +#include "ui/iconbutton.h" +#include "ui/plaintext.h" +#include "ui/modelview.h" + +namespace client +{ + +/// the world view when connected +class TestModelWindow : public ui::Widget +{ +public: + TestModelWindow(ui::Widget *parent = 0); + virtual ~TestModelWindow(); + + void set_modelname(const std::string & modelname); + +protected: + /// update model statistics + virtual void draw(); + + /** + * @brief resize the window + * TestModelWindow will copy its parent's size + **/ + virtual void resize(); + + /// draw a black background + virtual void draw_background(); + + /// emit event handler + virtual bool on_emit(Widget *sender, const Event event, void *data); + +private: + ui::ModelView *testmodelwindow_modelview; + ui::PlainText *testmodelwindow_text; + ui::Button *testmodelwindow_closebutton; + ui::IconButton *testmodelwindow_wireframebutton; + ui::IconButton *testmodelwindow_normalsbutton; + +}; // class TestModelWindow + +} // namespace client + +#endif // __INCLUDED_CLIENT_TESTMODELWINDOW_H__ diff --git a/src/client/trademenu.cc b/src/client/trademenu.cc index b6f0cc2..f4a5653 100644 --- a/src/client/trademenu.cc +++ b/src/client/trademenu.cc @@ -17,7 +17,7 @@ namespace client { -TradeMenu::TradeMenu(ui::Widget *parent, const char * label) : ui::Widget(parent) +TradeMenu::TradeMenu(ui::Widget *parent, const char * label) : ui::Window(parent) { set_border(false); set_background(false); @@ -26,9 +26,10 @@ TradeMenu::TradeMenu(ui::Widget *parent, const char * label) : ui::Widget(parent else set_label("trademenu"); - menu_tradewindow = new ui::Window(this); + menu_tradewindow = new ui::Widget(this); menu_tradewindow->set_label("tradewindow"); menu_tradewindow->set_border(true); + menu_tradewindow->set_background(true); menu_modelview = new ui::ModelView(menu_tradewindow); menu_modelview->set_label("modelview"); @@ -121,7 +122,7 @@ void TradeMenu::set_item(ui::ListItem *item) { menu_infotext.clear(); - menu_namelabel->set_text("Trade"); + menu_namelabel->set_text("TRADE"); menu_tradertext->clear(); menu_msgtext->clear(); @@ -379,6 +380,7 @@ bool TradeMenu::on_keypress(const int key, const unsigned int modifier) this->hide(); return true; break; + default: break; } diff --git a/src/client/trademenu.h b/src/client/trademenu.h index 56fe259..c882287 100644 --- a/src/client/trademenu.h +++ b/src/client/trademenu.h @@ -15,14 +15,14 @@ #include "ui/plaintext.h" #include "ui/slider.h" #include "ui/scrollpane.h" -#include "ui/widget.h" +#include "ui/window.h" #include "client/inventorylistview.h" namespace client { /// trade menu -class TradeMenu : public ui::Widget +class TradeMenu : public ui::Window { public: /// create a new trade menu @@ -49,7 +49,7 @@ protected: private: void set_item(ui::ListItem *item); - ui::Window *menu_tradewindow; + ui::Widget *menu_tradewindow; ui::Label *menu_namelabel; ui::PlainText *menu_inventorytext; ui::PlainText *menu_tradertext; diff --git a/src/client/video.cc b/src/client/video.cc index 6be4ff6..a957ef6 100644 --- a/src/client/video.cc +++ b/src/client/video.cc @@ -299,7 +299,7 @@ void set_cursor() ui::root()->set_pointer(); - } else if (client()->mainwindow()->playerview()->map()->hover()) { + } else if (client()->mainwindow()->gamewindow()->map()->hover()) { ui::root()->set_pointer("pointer"); |