Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 2c2ecaaec780c6579db79521ff0d286158b1adfd (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
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
/*
   client/playerview.cc
   This file is part of the Osirion project and is distributed under
   the terms and conditions of the GNU General Public License version 2
*/

#include <string>
#include <sstream>

#include "core/info.h"
#include "core/application.h"
#include "audio/audio.h"
#include "client/playerview.h"
#include "ui/ui.h"

namespace client
{

PlayerView::PlayerView(ui::Widget *parent) : ui::Widget(parent)
{
	set_label("playerview");
	set_border(false);
	set_background(false);

	view_notify = new Notifications(this);
	view_hud = new HUD(this);

	label_viewname = new ui::Label(this);
	label_viewname->set_label("viewnamelabel");
	label_viewname->set_alignment(ui::AlignCenter);
	label_viewname->set_background(true);
	label_viewname->set_font(ui::root()->font_large());

	view_chat = new Chat(this);
	view_map = new Map(this);
	view_entitymenu = new EntityMenu(this);
	view_buymenu = new BuyMenu(this);
	view_trademenu = new TradeMenu(this);
	
	//view_hud->set_focus();
	//view_hud->raise();
	//view_entitymenu->raise();
}

PlayerView::~PlayerView()
{
}

void PlayerView::clear()
{
	view_chat->clear();
	view_notify->clear();

	view_chat->hide();
	view_map->hide();
	view_entitymenu->hide();
	view_buymenu->hide();
	view_trademenu->hide();
}

void PlayerView::event_text(const std::string & text)
{
	view_chat->event_text(text);
	view_notify->event_text(text);
}

void PlayerView::toggle_map()
{

	if (!map()->visible()) {
		if (chat()->visible() && !chat()->small_view())
			chat()->hide();

		if (view_entitymenu->visible())
			view_entitymenu->hide();
	}

	map()->toggle();
	audio::play("ui/menu");

	if (map()->visible() && chat()->visible() && chat()->small_view()) {
		chat()->raise();
	}
}

void PlayerView::toggle_chat()
{
	if (!chat()->visible()) {
		if (map()->visible())
			map()->hide();

		if (view_entitymenu->visible())
			view_entitymenu->hide();
	}
	chat()->set_small_view(false);
	chat()->toggle();
	audio::play("ui/menu");
}

void PlayerView::toggle_chatbar()
{
	chat()->set_small_view(true);
	chat()->toggle();
}

void PlayerView::show_menu(const std::string & args)
{
	if (!args.size())
		return;

	if (!core::localplayer()->view())
		return;

	if (!core::localplayer()->view()->menus().size())
		return;

	std::stringstream argstr(args);
	std::string label;
	if (!(argstr >> label))
		return;

	if (label.compare("buy") == 0) {
		// buy menu, single item
		unsigned long id;

		if (argstr >> id) {
			// hide other menus
			view_entitymenu->hide();
			view_trademenu->hide();
						
			// requesting the info through game makes sure it is retreived from the server
			view_buymenu->set_item( core::game()->info(id) ); 
			// show buy menu
			view_buymenu->show();			
		} else {
			con_print << "usage: view buy [info id] show the buy menu for this kind of item" << std::endl;
		}

	} else if (label.compare("trade") == 0) {
		// invetory based trade
		std::string typestr;
		
		if(argstr >> typestr) {
			aux::to_label(typestr);
		
			// hide other menus
			view_buymenu->hide();
			view_entitymenu->hide();
			// show trade menu
			view_trademenu->show();
			view_trademenu->set_item_type(core::InfoType::find(typestr));
		} else {
			con_print << "usage: view trade [string] show the trade menu for this type of items" << std::endl;
		}
		
	} else if (label.compare("hide") == 0) {
		// hide all menus
		view_buymenu->hide();
		view_entitymenu->hide();
		view_trademenu->hide();
	} else {
		// hide other menus
		view_buymenu->hide();
		view_trademenu->hide();
		// show other menus
		view_entitymenu->generate(core::localplayer()->view(), label.c_str());
		view_entitymenu->show();
	}

	if (chat()->visible() && chat()->small_view())
		chat()->raise();
}

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

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

	// reposition buy menu
	view_buymenu->event_resize();
	// reposition trade menu
	view_trademenu->event_resize();

	// set hud geometry
	view_hud->set_geometry(0, 0, width(), height());
	view_hud->event_resize();

	// reposition map
	view_map->set_size(width() -  smallmargin * 2, height() -  smallmargin * 4);
	view_map->set_location(smallmargin, smallmargin * 2);

	// reposition notifications
	view_notify->set_geometry(view_map->location(), view_map->size());

	// reposition labels
	label_viewname->set_size(ui::UI::elementsize.width() * 1.5f, ui::UI::elementsize.height());
	label_viewname->set_location(width() - label_viewname->width() - smallmargin, height() - label_viewname->height() - smallmargin * 0.5f);
}

void PlayerView::draw()
{
	const float smallmargin = ui::UI::elementsize.height();

	if (core::localplayer()->view()) {

		// hide hide when a view is set
		view_hud->hide();

		// docking view
		if (core::localplayer()->view()->menus().size()) {

			// entity with menus

			if (map()->visible()) {
				label_viewname->set_text(core::localplayer()->zone()->name());
			} else {
				label_viewname->set_text(core::localplayer()->view()->name());
			}

			label_viewname->show();

			if (view_entitymenu->generated_entity() != core::localplayer()->view()) {
				// initially show the menu
				show_menu("main");
				map()->hide();
				chat()->hide();
				audio::play("ui/menu");

			} else if (!view_entitymenu->visible() && !view_buymenu->visible() && !view_trademenu->visible() &&
					!map()->visible() && (!chat()->visible() || chat()->small_view())) {

				// show the menu if there's no other window open
				view_entitymenu->show();
				audio::play("ui/menu");
			}

			view_notify->set_size(width() - smallmargin * 3.0f - ui::UI::elementsize.width() * 1.5f, height() -  smallmargin * 4.0f);
			view_notify->set_location(smallmargin * 2.0f + ui::UI::elementsize.width() * 1.5f, smallmargin * 2.0f);

		} else {
			// entity without menus, plain view
			this->hide();
			return;
		}

	} else {
		view_notify->set_geometry(view_map->location(), view_map->size());

		if (view_entitymenu->visible()) {
			view_entitymenu->hide();
		}

		if (view_entitymenu->generated_entity()) {
			view_entitymenu->generate(0, 0);
		}

		if (view_buymenu->visible()) {
			view_buymenu->hide();
		}

		if (view_trademenu->visible()) {
			view_trademenu->hide();
		}
		
		if (map()->visible()) {
			label_viewname->set_text(core::localplayer()->zone()->name());
			label_viewname->show();
		} else {
			label_viewname->hide();
		}

		if (!map()->visible() && !chat()->visible()) {
			view_hud->set_focus();
		}

		view_hud->show();
	}

	// reposition chat widget
	if (view_chat->small_view()) {
		view_chat->set_size(width() - smallmargin * 2, font()->height() * 2);
		view_chat->set_location(smallmargin, height() - smallmargin *2 - view_chat->height());
	} else {
		view_chat->set_geometry(view_map->location(), view_map->size());
	}
	view_chat->event_resize();
}

}