1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
/*
client/trademenu.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/button.h"
#include "ui/paint.h"
#include "ui/ui.h"
#include "ui/listitem.h"
#include "client/trademenu.h"
namespace client
{
TradeMenu::TradeMenu(ui::Widget *parent, const char * label) : ui::Window(parent)
{
set_border(false);
set_background(false);
if (label)
set_label(label);
else
set_label("trademenu");
menu_tradewindow = new ui::Window(this);
menu_tradewindow->set_label("tradewindow");
menu_tradewindow->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_closebutton = new ui::Button(menu_tradewindow, "Return", "view hide");
std::string test("test");
set_item_type(test);
hide();
}
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();
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 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(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);
}
}
|