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
|
/*
client/buymenu.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/ui.h"
#include "ui/button.h"
#include "ui/paint.h"
#include "client/buymenu.h"
#include "core/info.h"
#include "core/application.h"
namespace client
{
BuyMenu::BuyMenu(ui::Widget *parent, const char * label) : ui::Window(parent)
{
set_border(false);
set_background(false);
if (label)
set_label(label);
else
set_label("buymenu");
menu_buywindow = new ui::Window(this);
menu_buywindow->set_label("buywindow");
menu_buywindow->set_background(true);
menu_buywindow->set_border(true);
menu_namelabel = new ui::Label(menu_buywindow);
menu_namelabel->set_label("infolabel");
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_modelview = new ui::ModelView(menu_buywindow);
menu_modelview->set_label("modelview");
menu_modelview->set_background(false);
menu_modelview->set_border(false);
menu_scrollpane = new ui::ScrollPane(menu_buywindow, menu_infotext);
menu_scrollpane->set_background(false);
menu_scrollpane->set_border(false);
menu_scrollpane->set_alignment(ui::AlignTop);
menu_closebutton = new ui::Button(menu_buywindow, "Return", "view hide");
menu_buybutton = new ui::Button(menu_buywindow, "Buy");
menu_infotimestamp = 0;
menu_inforecord = 0;
hide();
}
BuyMenu::~BuyMenu()
{
}
void BuyMenu::set_item(std::string const & itemtype, std::string const & itemname)
{
menu_itemtype.assign(itemtype);
aux::to_label(menu_itemtype);
menu_itemname.assign(itemname);
aux::to_label(menu_itemname);
menu_buybutton->set_command("remote buy " + menu_itemtype + ' ' + menu_itemname + "; view hide");
menu_buybutton->set_label("buy " + menu_itemname);
menu_infotext.clear();
menu_namelabel->set_text(0);
menu_modelview->set_modelname(0);
menu_inforecord = core::game()->info(menu_itemtype, menu_itemname);
if (menu_inforecord) {
menu_namelabel->set_text(menu_inforecord->name());
menu_modelview->set_modelname(menu_inforecord->modelname());
for (core::Info::Text::const_iterator it = menu_inforecord->text().begin(); it != menu_inforecord->text().end(); it++) {
menu_infotext.push_back((*it));
}
menu_infotimestamp = menu_inforecord->timestamp();
} else {
menu_infotext.push_back("Information is not available");
menu_infotimestamp = 0;
menu_inforecord = 0;
}
}
void BuyMenu::resize()
{
const float smallmargin = ui::UI::elementsize.height();
const float fontmargin = menu_namelabel->font()->height();
// this menu takes the entire screen
set_size(parent()->size());
// resize the subwindow
menu_buywindow->set_size(width() - smallmargin * 2.0f, height()- smallmargin * 4.0f);
menu_buywindow->set_location(smallmargin, smallmargin * 2.0f);
// resize label
menu_namelabel->set_size(menu_buywindow->width() - fontmargin * 2.0f, menu_namelabel->font()->height());
menu_namelabel->set_location(fontmargin, fontmargin);
// resize model view
menu_modelview->set_size(ui::UI::elementsize.width() * 1.5f,
menu_buywindow->height() - smallmargin * 2.0f - fontmargin * 3.0f);
menu_modelview->set_location(fontmargin, fontmargin * 3.0f);
// resize infotext pane
menu_scrollpane->set_size(menu_buywindow->width() - ui::UI::elementsize.width() * 1.5f - fontmargin * 3.0f,
menu_buywindow->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_buywindow->width() * 0.5f - ui::UI::elementsize.width() - smallmargin * 2.0f, menu_buywindow->height() - smallmargin * 1.5f);
menu_closebutton->set_size(ui::UI::elementsize);
menu_closebutton->set_location(menu_buywindow->width() * 0.5f + smallmargin * 2.0f, menu_buywindow->height() - smallmargin * 1.5f);
}
void BuyMenu::draw()
{
// update content if necessary
if (menu_infotimestamp && menu_inforecord && (menu_infotimestamp != menu_inforecord->timestamp()))
set_item(menu_itemtype, menu_itemname);
}
bool BuyMenu::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);
}
}
|