From 0c509866a37ab47ff0e48d357ca55e31658c37c2 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Thu, 16 Sep 2010 14:12:27 +0000 Subject: map info support, initial trade window --- src/client/Makefile.am | 4 +-- src/client/inventorymenu.cc | 19 ++++++++++++ src/client/inventorymenu.h | 26 +++++++++++++++++ src/client/inventorywindow.cc | 19 ------------ src/client/inventorywindow.h | 26 ----------------- src/client/playerview.cc | 35 +++++++++++++++++----- src/client/trademenu.cc | 50 +++++++++++++++++++++++++++++-- src/client/trademenu.h | 16 ++++++++-- src/core/entity.cc | 12 +++++++- src/core/entity.h | 4 +-- src/core/gameserver.cc | 6 ++++ src/core/parser.cc | 18 ++++++++++++ src/core/parser.h | 11 +++++++ src/ui/Makefile.am | 6 ++-- src/ui/listview.cc | 68 +++++++++++++++++++++++++++++++++++++++++++ src/ui/listview.h | 50 +++++++++++++++++++++++++++++++ 16 files changed, 306 insertions(+), 64 deletions(-) create mode 100644 src/client/inventorymenu.cc create mode 100644 src/client/inventorymenu.h delete mode 100644 src/client/inventorywindow.cc delete mode 100644 src/client/inventorywindow.h create mode 100644 src/ui/listview.cc create mode 100644 src/ui/listview.h diff --git a/src/client/Makefile.am b/src/client/Makefile.am index 3169525..741f5a3 100644 --- a/src/client/Makefile.am +++ b/src/client/Makefile.am @@ -8,7 +8,7 @@ noinst_LTLIBRARIES = libclient.la endif libclient_la_SOURCES = action.cc buymenu.cc chat.cc client.cc clientext.cc \ - entitymenu.cc hud.cc infowidget.cc input.cc inventorywindow.cc joystick.cc key.cc \ + entitymenu.cc hud.cc infowidget.cc input.cc inventorymenu.cc joystick.cc key.cc \ keyboard.cc map.cc notifications.cc playerview.cc soundext.cc targeticonbutton.cc \ targets.cc trademenu.cc video.cc worldview.cc @@ -17,7 +17,7 @@ libclient_la_CFLAGS = $(LIBSDL_CFLAGS) $(GL_CFLAGS) libclient_la_LDFLAGS = -avoid-version -no-undefined $(GL_LIBS) $(LIBSDL_LIBS) noinst_HEADERS = action.h chat.h client.h clientext.h hud.h entitymenu.h \ - input.h inventorywindow.h joystick.h key.h keyboard.h map.h notifications.h soundext.h \ + input.h inventorymenu.h joystick.h key.h keyboard.h map.h notifications.h soundext.h \ targets.h video.h infowidget.h playerview.h worldview.h trademenu.h buymenu.h \ targeticonbutton.h diff --git a/src/client/inventorymenu.cc b/src/client/inventorymenu.cc new file mode 100644 index 0000000..435c3b2 --- /dev/null +++ b/src/client/inventorymenu.cc @@ -0,0 +1,19 @@ +/* + client/inventorymenu.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 "client/inventorymenu.h" + +namespace client { + +InventoryWindow::InventoryWindow(ui::Widget *parent) : ui::Window(parent) +{ +} + +InventoryWindow::~InventoryWindow() +{ +} + +} // namespace client diff --git a/src/client/inventorymenu.h b/src/client/inventorymenu.h new file mode 100644 index 0000000..7d4809a --- /dev/null +++ b/src/client/inventorymenu.h @@ -0,0 +1,26 @@ +/* + client/inventorymenu.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_INVENTORYWINDOW_H__ +#define __INCLUDED_CLIENT_INVENTORYWINDOW_H__ + +#include "ui/window.h" + +namespace client { + +/** + * @brief an inventory window widget + */ +class InventoryWindow : public ui::Window +{ +public: + InventoryWindow(ui::Widget *parent = 0); + ~InventoryWindow(); + +}; // class InventoryWindow + +} +#endif // __INCLUDED_CLIENT_INVENTORYWINDOW_H__ diff --git a/src/client/inventorywindow.cc b/src/client/inventorywindow.cc deleted file mode 100644 index b6ef82b..0000000 --- a/src/client/inventorywindow.cc +++ /dev/null @@ -1,19 +0,0 @@ -/* - 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 "client/inventorywindow.h" - -namespace client { - -InventoryWindow::InventoryWindow(ui::Widget *parent) : ui::Window(parent) -{ -} - -InventoryWindow::~InventoryWindow() -{ -} - -} // namespace client diff --git a/src/client/inventorywindow.h b/src/client/inventorywindow.h deleted file mode 100644 index ec6ad02..0000000 --- a/src/client/inventorywindow.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - 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_INVENTORYWINDOW_H__ -#define __INCLUDED_CLIENT_INVENTORYWINDOW_H__ - -#include "ui/window.h" - -namespace client { - -/** - * @brief an inventory window widget - */ -class InventoryWindow : public ui::Window -{ -public: - InventoryWindow(ui::Widget *parent = 0); - ~InventoryWindow(); - -}; // class InventoryWindow - -} -#endif // __INCLUDED_CLIENT_INVENTORYWINDOW_H__ diff --git a/src/client/playerview.cc b/src/client/playerview.cc index 578e97f..de4c704 100644 --- a/src/client/playerview.cc +++ b/src/client/playerview.cc @@ -33,7 +33,8 @@ PlayerView::PlayerView(ui::Widget *parent) : ui::Widget(parent) view_map = new Map(this); view_entitymenu = new EntityMenu(this); view_buymenu = new BuyMenu(this); - + view_trademenu = new TradeMenu(this); + //view_hud->set_focus(); //view_hud->raise(); //view_entitymenu->raise(); @@ -51,6 +52,8 @@ void PlayerView::clear() view_chat->hide(); view_map->hide(); view_entitymenu->hide(); + view_buymenu->hide(); + view_trademenu->hide(); } void PlayerView::event_text(const std::string & text) @@ -120,24 +123,36 @@ void PlayerView::show_menu(const std::string & args) std::string itemname; if ((argstr >> itemtype) && (argstr >> itemname)) { + // hide other menus + view_entitymenu->hide(); + view_trademenu->hide(); + // show buy menu view_buymenu->set_item(itemtype, itemname); view_buymenu->show(); - view_entitymenu->hide(); + } else { con_print << "usage: view buy [string] [string] buy menu for item type and name" << std::endl; } } else if (label.compare("trade") == 0) { - // trade menu, multiple items - + // hide other menus + view_buymenu->hide(); + view_entitymenu->hide(); + // show trade menu + view_trademenu->show(); + } 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(); + // show other menus view_entitymenu->generate(core::localplayer()->view(), label.c_str()); view_entitymenu->show(); - view_buymenu->hide(); } if (chat()->visible() && chat()->small_view()) @@ -152,6 +167,8 @@ void PlayerView::resize() // 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()); @@ -198,7 +215,7 @@ void PlayerView::draw() chat()->hide(); audio::play("ui/menu"); - } else if (!view_entitymenu->visible() && !view_buymenu->visible() && + } else if (!view_entitymenu->visible() && !view_buymenu->visible() && !view_trademenu->visible() && !map()->visible() && (!chat()->visible() || chat()->small_view())) { // show the menu if there's no other window open @@ -230,6 +247,10 @@ void PlayerView::draw() view_buymenu->hide(); } + if (view_trademenu->visible()) { + view_trademenu->hide(); + } + if (map()->visible()) { label_viewname->set_text(core::localplayer()->zone()->name()); label_viewname->show(); diff --git a/src/client/trademenu.cc b/src/client/trademenu.cc index c60791f..75b9d67 100644 --- a/src/client/trademenu.cc +++ b/src/client/trademenu.cc @@ -4,15 +4,15 @@ the terms of the GNU General Public License version 2 */ -#include "ui/ui.h" #include "ui/button.h" #include "ui/paint.h" +#include "ui/ui.h" #include "client/trademenu.h" namespace client { -TradeMenu::TradeMenu(ui::Window *parent, const char * label) : ui::Window(parent) +TradeMenu::TradeMenu(ui::Widget *parent, const char * label) : ui::Window(parent) { set_border(false); set_background(false); @@ -24,7 +24,19 @@ TradeMenu::TradeMenu(ui::Window *parent, const char * label) : ui::Window(parent menu_tradewindow = new ui::Window(this); menu_tradewindow->set_label("tradewindow"); menu_tradewindow->set_border(true); + + menu_listview = new ui::ListView(menu_tradewindow); + menu_listview->set_label("listview"); + menu_listview->set_background(false); + menu_listview->set_border(true); + + menu_scrollpane = new ui::ScrollPane(menu_tradewindow, menu_infotext); + menu_scrollpane->set_background(false); + menu_scrollpane->set_border(true); + menu_scrollpane->set_alignment(ui::AlignTop); + menu_closebutton = new ui::Button(menu_tradewindow, "Return", "view hide"); + hide(); } @@ -33,4 +45,38 @@ TradeMenu::~TradeMenu() } +void TradeMenu::resize() +{ + const float smallmargin = ui::UI::elementsize.height(); + const float fontmargin = ui::root()->font_large()->height(); + + // this menu takes the entire screen + set_size(parent()->size()); + + // resize the subwindow + menu_tradewindow->set_size(width() - smallmargin * 2.0f, height()- smallmargin * 4.0f); + menu_tradewindow->set_location(smallmargin, smallmargin * 2.0f); + + // resize label + //menu_namelabel->set_size(menu_tradewindow->width() - fontmargin * 2.0f, menu_namelabel->font()->height()); + //menu_namelabel->set_location(fontmargin, fontmargin); + + // resize listview + menu_listview->set_size(ui::UI::elementsize.width() * 1.5f, menu_tradewindow->height() - smallmargin * 2.0f - fontmargin * 3.0f); + menu_listview->set_location(fontmargin, fontmargin * 3.0f); + + // resize infotext pane + menu_scrollpane->set_size(menu_tradewindow->width() - ui::UI::elementsize.width() * 1.5f - fontmargin * 3.0f, + menu_tradewindow->height() - smallmargin * 2.0f - fontmargin * 3.0f); + menu_scrollpane->set_location(ui::UI::elementsize.width() * 1.5f + fontmargin * 2.0f, fontmargin * 3.0f); + + // resize buttons + //menu_buybutton->set_size(ui::UI::elementsize); + //menu_buybutton->set_location(menu_tradewindow->width() * 0.5f - ui::UI::elementsize.width() - smallmargin * 2.0f, menu_tradewindow->height() - smallmargin * 1.5f); + + menu_closebutton->set_size(ui::UI::elementsize); + //menu_closebutton->set_location(menu_tradewindow->width() * 0.5f + smallmargin * 2.0f, menu_tradewindow->height() - smallmargin * 1.5f); + menu_closebutton->set_location(0.5f * (menu_tradewindow->width() - ui::UI::elementsize.width()), menu_tradewindow->height() - smallmargin * 1.5f ); +} + } diff --git a/src/client/trademenu.h b/src/client/trademenu.h index 03b5077..98cf71d 100644 --- a/src/client/trademenu.h +++ b/src/client/trademenu.h @@ -7,9 +7,11 @@ #ifndef __INCLUDED_CLIENT_TRADEMENU_H__ #define __INCLUDED_CLIENT_TRADEMENU_H__ +#include "core/info.h" #include "ui/container.h" #include "ui/label.h" -#include "ui/window.h" +#include "ui/listview.h" +#include "ui/widget.h" namespace client { @@ -18,8 +20,8 @@ namespace client class TradeMenu : public ui::Window { public: - /// create a new menu - TradeMenu(ui::Window *parent, const char * label = 0); + /// create a new trade menu + TradeMenu(ui::Widget *parent, const char * label = 0); ~TradeMenu(); protected: @@ -28,6 +30,14 @@ protected: private: ui::Window *menu_tradewindow; + ui::ListView *menu_listview; + ui::ScrollPane *menu_scrollpane; + ui::Button *menu_closebutton; + + core::Info *menu_inforecord; + ui::Text menu_infotext; + + unsigned long menu_infotimestamp; }; } diff --git a/src/core/entity.cc b/src/core/entity.cc index aa9e45b..baefcea 100644 --- a/src/core/entity.cc +++ b/src/core/entity.cc @@ -204,6 +204,10 @@ void Entity::clear_updates() void Entity::set_info(Info *info) { entity_info = info; + if (entity_info) { + entity_info->set_model(model()); + entity_info->set_name(name()); + } } void Entity::set_inventory(Inventory *inventory) @@ -237,7 +241,13 @@ void Entity::set_model(model::Model *model) entity_model = model; if (entity_model) { entity_radius = entity_model->radius(); - entity_modelname = entity_model->name(); + entity_modelname.assign(entity_model->name()); + } else { + entity_modelname.clear(); + } + + if (entity_info) { + entity_info->set_model(entity_model); } } diff --git a/src/core/entity.h b/src/core/entity.h index 5ddce3a..6a7fa7e 100644 --- a/src/core/entity.h +++ b/src/core/entity.h @@ -162,12 +162,12 @@ public: } ///entity inventory - inline Inventory *inventory() { + inline Inventory *inventory() const { return entity_inventory; } /// entity info - inline const Info *info() const { + inline Info *info() const { return entity_info; } diff --git a/src/core/gameserver.cc b/src/core/gameserver.cc index 2e848e0..4181824 100644 --- a/src/core/gameserver.cc +++ b/src/core/gameserver.cc @@ -13,6 +13,7 @@ #include "core/func.h" #include "core/gameserver.h" #include "core/loader.h" +#include "core/parser.h" #include "core/netserver.h" #include "filesystem/filesystem.h" #include "sys/sys.h" @@ -127,7 +128,10 @@ GameServer::GameServer() : GameInterface() server_maxplayerid = 1; server_startup = application()->timestamp(); + Parser::init(); + server_module = Loader::init(); + if (!server_module) { con_error << "No module loaded.\n"; abort(); @@ -223,6 +227,8 @@ GameServer::~GameServer() */ Func::remove("time"); Func::remove("who"); + + Parser::done(); server_instance = 0; } diff --git a/src/core/parser.cc b/src/core/parser.cc index c5e0a38..7ef44d9 100644 --- a/src/core/parser.cc +++ b/src/core/parser.cc @@ -11,6 +11,17 @@ namespace core { +InfoType *Parser::entity_infotype = 0; + +void Parser::init() +{ + entity_infotype = new InfoType("entity"); +} + +void Parser::done() +{ + entity_infotype = 0; +} bool Parser::got_entity_key(filesystem::IniFile &inifile, core::Entity *entity) { @@ -47,6 +58,13 @@ bool Parser::got_entity_key(filesystem::IniFile &inifile, core::Entity *entity) return false; } + } else if (inifile.got_key_string("info", strval)) { + if (!entity->info()) { + entity->set_info(new Info(entity_infotype, entity->label().c_str())); + } + entity->info()->add_text(strval); + return true; + } else if (inifile.got_key_string("label", strval)) { entity->set_label(strval); return true; diff --git a/src/core/parser.h b/src/core/parser.h index 06ddc27..993c307 100644 --- a/src/core/parser.h +++ b/src/core/parser.h @@ -18,8 +18,19 @@ namespace core class Parser { public: + /// initialize parser infotypes + static void init(); + + /// clean up parser internals + static void done(); + /// read default entity keys from an ini file static bool got_entity_key(filesystem::IniFile &inifile, core::Entity *entity); + +private: + /// default infotype for entities + static InfoType *entity_infotype; + }; } diff --git a/src/ui/Makefile.am b/src/ui/Makefile.am index 561935c..98c8dab 100644 --- a/src/ui/Makefile.am +++ b/src/ui/Makefile.am @@ -8,11 +8,13 @@ noinst_LTLIBRARIES = libui.la endif noinst_HEADERS = bitmap.h button.h console.h container.h definitions.h font.h \ - iconbutton.h inputbox.h label.h menu.h modelview.h paint.h palette.h scrollpane.h toolbar.h ui.h widget.h \ + iconbutton.h inputbox.h label.h listview.h menu.h modelview.h paint.h \ + palette.h scrollpane.h toolbar.h ui.h widget.h \ window.h libui_la_SOURCES = bitmap.cc button.cc console.cc container.cc \ - font.cc iconbutton.cc inputbox.cc label.cc menu.cc modelview.cc paint.cc palette.cc scrollpane.cc \ + font.cc iconbutton.cc inputbox.cc label.cc listview.cc \ + menu.cc modelview.cc paint.cc palette.cc scrollpane.cc \ toolbar.cc ui.cc widget.cc window.cc libui_la_LDFLAGS = -avoid-version -no-undefined diff --git a/src/ui/listview.cc b/src/ui/listview.cc new file mode 100644 index 0000000..56fa324 --- /dev/null +++ b/src/ui/listview.cc @@ -0,0 +1,68 @@ +/* + ui/listview.cc + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#include "ui/listview.h" + +namespace ui +{ + +ListView::ListView(Widget *parent) : Widget(parent) +{ + set_label("listview"); + set_border(true); +} + +ListView::~ListView() +{ +} + +void ListView::set_scroll(float scroll) +{ + listview_scroll = scroll; + if (listview_scroll < 0) + listview_scroll = 0; + + // calculate maximal scroll size + float top = 0; + for (Children::iterator it = children().begin(); it != children().end(); it++) { + top += (*it)->height(); + } + if (listview_scroll > top) listview_scroll = top; +} + +void ListView::inc_scroll(float scroll) +{ + set_scroll(listview_scroll + scroll); +} + +void ListView::dec_scroll(float scroll) +{ + set_scroll(listview_scroll - scroll); +} + +void ListView::resize() +{ + float content_top = 0; + + // reposition all children within the container + for (Children::iterator it = children().begin(); it != children().end(); it++) { + (*it)->set_width(width()); + if (content_top - listview_scroll < 0) { + // child widget is invisible + (*it)->hide(); + } else if ((content_top - listview_scroll) >= height()) { + // child widget is invisible + (*it)->hide(); + } else { + (*it)->show(); + (*it)->set_location(0, content_top - listview_scroll); + } + + content_top += (*it)->height(); + } +} + +} diff --git a/src/ui/listview.h b/src/ui/listview.h new file mode 100644 index 0000000..25fd07c --- /dev/null +++ b/src/ui/listview.h @@ -0,0 +1,50 @@ +/* + ui/listview.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_UI_LISTVIEW_H__ +#define __INCLUDED_UI_LISTVIEW_H__ + +#include +#include "ui/widget.h" + +namespace ui +{ + +/** + * @brief a list of selectable items + **/ +class ListView : public Widget +{ +public: + ListView(Widget *parent=0); + ~ListView(); + + /// current scroll position + inline float scroll() const { + return listview_scroll; + } + + /* -- mutators --------------------------------------------- */ + + /// set scroll + void set_scroll(float scroll); + + /// scroll down + void inc_scroll(float scroll); + + /// scroll up + void dec_scroll(float scroll); + +protected: + virtual void resize(); + +private: + float listview_scroll; +}; + +} // namespacd ui + +#endif // __INCLUDED_UI_LISTVIEW_H__ -- cgit v1.2.3