diff options
Diffstat (limited to 'src/client/trademenu.cc')
-rw-r--r-- | src/client/trademenu.cc | 122 |
1 files changed, 98 insertions, 24 deletions
diff --git a/src/client/trademenu.cc b/src/client/trademenu.cc index 75b9d67..7e9be4f 100644 --- a/src/client/trademenu.cc +++ b/src/client/trademenu.cc @@ -7,6 +7,7 @@ #include "ui/button.h" #include "ui/paint.h" #include "ui/ui.h" +#include "ui/listitem.h" #include "client/trademenu.h" namespace client @@ -25,18 +26,30 @@ TradeMenu::TradeMenu(ui::Widget *parent, const char * label) : ui::Window(parent 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_namelabel = new ui::Label(menu_tradewindow); + 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->show(); + + menu_inventorylistview = new ui::ListView(menu_tradewindow); + menu_inventorylistview->set_label("inventorylistview"); + menu_inventorylistview->set_background(false); + menu_inventorylistview->set_border(true); + + + menu_traderlistview = new ui::ListView(menu_tradewindow); + menu_traderlistview->set_label("traderlistview"); + menu_traderlistview->set_background(false); + menu_traderlistview->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"); + std::string test("test"); + set_item_type(test); + hide(); } @@ -45,6 +58,56 @@ TradeMenu::~TradeMenu() } +void TradeMenu::set_item_type(std::string const & itemtype) +{ + ui::ListItem *item_label = 0; + + menu_namelabel->set_text(0); + + // update inventorylistview + menu_inventorylistview->remove_children(); + + //core::Inventory *inventory = 0; + + + item_label = new ui::ListItem(menu_inventorylistview, "Inventory item 1"); + item_label->set_height(item_label->font()->height() * 2.0f); + + item_label = new ui::ListItem(menu_inventorylistview, "Inventory item 2"); + item_label->set_height(item_label->font()->height() * 2.0f); + + item_label = new ui::ListItem(menu_inventorylistview, "Inventory item 3"); + item_label->set_height(item_label->font()->height() * 2.0f); + + item_label = new ui::ListItem(menu_inventorylistview, "Inventory item 4"); + item_label->set_height(item_label->font()->height() * 2.0f); + + item_label = new ui::ListItem(menu_inventorylistview, "Inventory item 5"); + item_label->set_height(item_label->font()->height() * 2.0f); + + menu_inventorylistview->event_resize(); + + // update traderlistview + menu_traderlistview->remove_children(); + + item_label = new ui::ListItem(menu_traderlistview, "Shop item 1"); + item_label->set_height(item_label->font()->height() * 2.0f); + + item_label = new ui::ListItem(menu_traderlistview, "Shop item 2"); + item_label->set_height(item_label->font()->height() * 2.0f); + + item_label = new ui::ListItem(menu_traderlistview, "Shop item 3"); + item_label->set_height(item_label->font()->height() * 2.0f); + + item_label = new ui::ListItem(menu_traderlistview, "Shop item 4"); + item_label->set_height(item_label->font()->height() * 2.0f); + + item_label = new ui::ListItem(menu_traderlistview, "Shop item 5"); + item_label->set_height(item_label->font()->height() * 2.0f); + + menu_traderlistview->event_resize(); +} + void TradeMenu::resize() { const float smallmargin = ui::UI::elementsize.height(); @@ -58,25 +121,36 @@ void TradeMenu::resize() 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); + menu_namelabel->set_size(menu_tradewindow->width() - fontmargin * 2.0f, menu_namelabel->font()->height()); + menu_namelabel->set_location(fontmargin, fontmargin); - // 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); + // resize inventory listview + menu_inventorylistview->set_size(ui::UI::elementsize.width(), menu_tradewindow->height() - smallmargin * 2.0f - fontmargin * 3.0f); + menu_inventorylistview->set_location(fontmargin, fontmargin * 3.0f); + // resize trader listview + menu_traderlistview->set_size(ui::UI::elementsize.width(), menu_tradewindow->height() - smallmargin * 2.0f - fontmargin * 3.0f); + menu_traderlistview->set_location(menu_tradewindow->width() - menu_traderlistview->width() - fontmargin, fontmargin * 3.0f); + + // resize close button 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 ); } +bool TradeMenu::on_emit(Widget *sender, const Event event, void *data) +{ + if (event == ui::Widget::EventListItemClicked) { + if (sender->parent() == menu_inventorylistview) { + // item from inventory selected + menu_namelabel->set_text("SELL " + static_cast<ui::ListItem *>(sender)->text()); + } else if (sender->parent() == menu_traderlistview) { + // item from trader selected + menu_namelabel->set_text("BUY " + static_cast<ui::ListItem *>(sender)->text()); + } + return true; + } + + return ui::Window::on_emit(sender, event, data); +} + } |