Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 8c69a7a0d607098c11340add711076151148e1ac (plain)
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
/*
   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(true);	

	if (label)	
		set_label(label);
	else
		set_label("buymenu");

	// model pane (left)
	menu_modelpane = new ui::Window(this);
	menu_modelpane->set_label("modelpane");
	menu_modelpane->set_background(true);
	menu_modelpane->set_border(true);

	menu_modelview = new ui::ModelView(menu_modelpane);
	menu_modelview->set_label("modelview");
	menu_modelview->set_background(false);
	menu_modelview->set_border(false);

	menu_closebutton = new ui::Button(menu_modelpane, "Close","view hide");

	// text pane (right)
	menu_textpane = new ui::Window(this);
	menu_textpane->set_label("textpane");
	menu_textpane->set_background(true);
	menu_textpane->set_border(true);

	menu_namelabel = new ui::Label(menu_textpane);
	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_scrollpane = new ui::ScrollPane(menu_textpane, menu_infotext);
	menu_scrollpane->set_background(false);
	menu_scrollpane->set_border(false);
	menu_scrollpane->set_alignment(ui::AlignTop);

	menu_buybutton = new ui::Button(menu_textpane, "Buy");

	menu_infotimestamp = 0;
	menu_inforecord = 0;

	menu_modelpane->raise(); // DEBUG
	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 " + itemtype + ' ' + itemname + "; view hide");
	menu_buybutton->set_label("buy " + itemname);

	menu_infotext.clear();
	menu_namelabel->set_text(0);
	menu_modelview->set_modelname(0);

	core::Info *info = core::game()->info(itemtype+'/'+itemname);
	if (info) {
		menu_namelabel->set_text(info->name());
		menu_modelview->set_modelname(info->modelname());

		for (core::Info::Text::iterator it = info->text().begin(); it != info->text().end(); it++) {
			menu_infotext.push_back((*it));
		}
		menu_infotimestamp = info->timestamp();
	} else {
		menu_infotext.push_back("Information is not available");
		menu_infotimestamp = 0;
	}

	menu_inforecord = info;
}

void BuyMenu::resize()
{
	const float smallmargin = ui::UI::elementsize.height();

	set_size(parent()->size());

	// reposition model pane (left)
	menu_modelpane->set_size(ui::UI::elementsize.width() * 1.5f, height() -  smallmargin * 4.0f);
	menu_modelpane->set_location(smallmargin, smallmargin * 2.0f);

	menu_closebutton->set_size(ui::UI::elementsize);
	menu_closebutton->set_location((menu_modelpane->width() - menu_closebutton->width()) * 0.5f, 
			menu_modelpane->height() - menu_closebutton->height() -  ui::UI::elementsize.height() * 0.5f);

	menu_modelview->set_size(menu_modelpane->width()-8, menu_modelpane->width()-8);
	menu_modelview->set_location(4, 4);

	// reposition text pane (right)
	menu_textpane->set_size(width() - smallmargin * 3.0f - menu_modelpane->width(),  height() -  smallmargin * 4.0f);
	menu_textpane->set_location(smallmargin * 2.0f + menu_modelpane->width(), smallmargin * 2.0f);

	menu_buybutton->set_size(ui::UI::elementsize);
	menu_buybutton->set_location((menu_textpane->width() - menu_buybutton->width()) * 0.5f, 
			menu_textpane->height() - menu_buybutton->height() -  ui::UI::elementsize.height() * 0.5f);

	menu_namelabel->set_size(menu_textpane->width(), menu_namelabel->font()->height() * 2.0f);
	menu_namelabel->set_location(0, 4);

	menu_scrollpane->set_size(menu_textpane->width() - 8, menu_buybutton->top() - menu_namelabel->bottom() - 8 );
	menu_scrollpane->set_location(4,  menu_namelabel->bottom() + 4);

}

void BuyMenu::draw()
{
	// update content if necessary
	if (menu_infotimestamp && (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);
}

}