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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
/*
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::Widget(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_modelview = new ui::ModelView(menu_buywindow);
menu_modelview->set_label("modelview");
menu_modelview->set_background(false);
menu_modelview->set_border(false);
menu_namelabel = new ui::Label(menu_buywindow);
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_msgtext = new ui::Label(menu_buywindow);
menu_msgtext->set_label("label");
menu_msgtext->set_background(false);
menu_msgtext->set_border(false);
menu_msgtext->set_alignment(ui::AlignCenter);
menu_pricetext = new ui::PlainText(menu_buywindow);
menu_pricetext->set_label("pricetext");
menu_pricetext->set_background(false);
menu_pricetext->set_border(false);
menu_pricetext->set_font(ui::root()->font_small());
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(core::Info *info)
{
menu_infotext.clear();
menu_namelabel->set_text(0);
menu_modelview->clear();
menu_buybutton->hide();
menu_modelview->hide();
menu_msgtext->hide();
// if the information timestamp is 0, the info is available
menu_inforecord = info;
if (!menu_inforecord) {
menu_buybutton->hide();
menu_modelview->hide();
menu_infotext.push_back("Information is not available");
menu_infotimestamp = 0;
} else {
for (core::Info::Text::const_iterator it = menu_inforecord->text().begin(); it != menu_inforecord->text().end(); it++) {
menu_infotext.push_back((*it));
}
if (menu_inforecord->type() && menu_inforecord->label().size()) {
menu_namelabel->set_text(menu_inforecord->name());
menu_modelview->set_modelname(menu_inforecord->modelname());
menu_modelview->set_colors(core::localplayer()->color(), core::localplayer()->color_second());
menu_buybutton->set_command("remote buy " + menu_inforecord->type()->label() + ' ' + menu_inforecord->label() + "; view hide");
menu_buybutton->set_label("buy " + menu_inforecord->type()->label() + ' ' + menu_inforecord->label());
menu_modelview->show();
if (core::localplayer()->credits() < menu_inforecord->price()) {
menu_msgtext->set_text("^1Not enough credits");
menu_msgtext->show();
} else {
menu_buybutton->show();
}
}
menu_infotimestamp = menu_inforecord->timestamp();
}
}
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);
menu_msgtext->set_size(menu_modelview->width(), fontmargin);
menu_msgtext->set_location(menu_modelview->left(), menu_modelview->top());
menu_pricetext->set_size(menu_modelview->width(), fontmargin * 2.0f);
menu_pricetext->set_location(menu_modelview->left(), menu_modelview->bottom() - menu_pricetext->height());
// 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_inforecord && (menu_infotimestamp != menu_inforecord->timestamp()))
set_item(menu_inforecord);
if (menu_inforecord) {
std::stringstream creditstr;
creditstr << core::localplayer()->credits();
std::stringstream pricestr;
pricestr << menu_inforecord->price();
std::stringstream str;
str << " Price: " << aux::pad_left(pricestr.str(),12);
str << '\n';
str << " Credits: " << aux::pad_left(creditstr.str(),12);
menu_pricetext->set_text(str.str());
} else {
menu_pricetext->clear();
}
}
bool BuyMenu::on_keypress(const int key, const unsigned int modifier)
{
switch (key) {
case SDLK_ESCAPE:
this->hide();
return true;
break;
default:
break;
}
return Widget::on_keypress(key, modifier);
}
}
|