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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
|
/*
client/gamewindow.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 "ui/ui.h"
#include "client/targeticonbutton.h"
#include "client/gamewindow.h"
namespace client
{
GameWindow::GameWindow(ui::Widget *parent) : ui::Window(parent)
{
set_label("gamewindow");
set_border(false);
set_background(false);
gamewindow_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());
// sub menus
gamewindow_map = new MapWindow(this);
gamewindow_entitymenu = new EntityMenu(this, "entitymenu");
gamewindow_buymenu = new BuyMenu(this);
gamewindow_trademenu = new TradeMenu(this);
gamewindow_inventory = new InventoryWindow(this);
gamewindow_chat = new Chat(this);
// icon buttons
gamewindow_menubutton = new ui::IconButton(this, "bitmaps/icons/button_menu", "ui_menu");
gamewindow_launchbutton = new ui::IconButton(this, "bitmaps/icons/button_launch", "launch");
gamewindow_dockbutton = new TargetIconButton(this, "bitmaps/icons/button_dock", "dock", core::Entity::Dockable);
gamewindow_homebutton = new ui::IconButton(this, "bitmaps/icons/button_home", "view main");
gamewindow_chatbutton = new ui::IconButton(this, "bitmaps/icons/button_chat", "ui_chat");
gamewindow_mapbutton = new ui::IconButton(this, "bitmaps/icons/button_map", "ui_map");
gamewindow_inventorybutton = new ui::IconButton(this, "bitmaps/icons/button_ship", "ui_inventory");
}
GameWindow::~GameWindow()
{
}
void GameWindow::clear()
{
gamewindow_chat->clear();
gamewindow_chat->hide();
gamewindow_map->hide();
gamewindow_inventory->hide();
gamewindow_entitymenu->hide();
gamewindow_buymenu->hide();
gamewindow_trademenu->hide();
}
void GameWindow::event_text(const std::string & text)
{
gamewindow_chat->event_text(text);
}
void GameWindow::toggle_map()
{
if (!map()->visible()) {
if (chat()->visible() && !chat()->small_view()) {
chat()->hide();
}
if (inventory()->visible()) {
inventory()->hide();
}
if (gamewindow_entitymenu->visible()) {
gamewindow_entitymenu->hide();
}
if (gamewindow_buymenu->visible()) {
gamewindow_buymenu->hide();
}
if (gamewindow_trademenu->visible()) {
gamewindow_trademenu->hide();
}
}
map()->toggle();
/* if (map()->visible() && chat()->visible() && chat()->small_view()) {
chat()->raise();
}
*/
}
void GameWindow::toggle_inventory()
{
if (!inventory()->visible()) {
if (chat()->visible() && !chat()->small_view()) {
chat()->hide();
}
if (map()->visible()) {
map()->hide();
}
if (gamewindow_entitymenu->visible()) {
gamewindow_entitymenu->hide();
}
if (gamewindow_buymenu->visible()) {
gamewindow_buymenu->hide();
}
if (gamewindow_trademenu->visible()) {
gamewindow_trademenu->hide();
}
}
inventory()->toggle();
/* if (inventory()->visible() && chat()->visible() && chat()->small_view()) {
chat()->raise();
}
*/
}
void GameWindow::toggle_chat()
{
if (chat()->small_view()) {
chat()->hide();
}
if (!chat()->visible()) {
if (map()->visible())
map()->hide();
if (inventory()->visible()) {
inventory()->hide();
}
if (gamewindow_entitymenu->visible()) {
gamewindow_entitymenu->hide();
}
if (gamewindow_buymenu->visible()) {
gamewindow_buymenu->hide();
}
if (gamewindow_trademenu->visible()) {
gamewindow_trademenu->hide();
}
}
chat()->set_small_view(false);
chat()->toggle();
}
void GameWindow::toggle_chatbar()
{
if (!chat()->small_view()) {
chat()->hide();
}
chat()->set_small_view(true);
chat()->toggle();
}
void GameWindow::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 int id;
if (argstr >> id) {
// hide other menus
gamewindow_entitymenu->hide();
gamewindow_trademenu->hide();
// hide other windows
gamewindow_chat->hide();
gamewindow_map->hide();
gamewindow_inventory->hide();
// requesting the info through game makes sure it is retreived from the server
gamewindow_buymenu->set_item( core::game()->request_info(id));
// show buy menu
gamewindow_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
gamewindow_buymenu->hide();
gamewindow_entitymenu->hide();
// hide other windows
gamewindow_chat->hide();
gamewindow_map->hide();
gamewindow_inventory->hide();
// show trade menu
gamewindow_trademenu->set_itemtype(core::InfoType::find(typestr));
gamewindow_trademenu->show();
} 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
gamewindow_buymenu->hide();
gamewindow_entitymenu->hide();
gamewindow_trademenu->hide();
} else {
// hide other menus
gamewindow_buymenu->hide();
gamewindow_trademenu->hide();
// hide other windows
gamewindow_chat->hide();
gamewindow_map->hide();
gamewindow_inventory->hide();
// show other menus
gamewindow_entitymenu->generate(core::localplayer()->view(), label.c_str());
gamewindow_entitymenu->show();
}
/* if (chat()->visible() && chat()->small_view())
chat()->raise();
*/
}
void GameWindow::resize()
{
const float smallmargin = ui::UI::elementsize.height();
set_size(parent()->size());
// icons
const float icon_margin = 4.0f;
const float icon_size = 48.0f;
const float icon_count = 7;
const float l = (width() - ((icon_count + 1) * icon_margin) - (icon_count * icon_size)) * 0.5f;
gamewindow_menubutton->set_geometry(l, icon_margin, icon_size, icon_size);
// spacer
gamewindow_dockbutton->set_geometry(l + 2.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size);
gamewindow_launchbutton->set_geometry(l + 2.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size);
gamewindow_homebutton->set_geometry(l + 3.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size);
gamewindow_inventorybutton->set_geometry(l + 4.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size);
gamewindow_chatbutton->set_geometry(l + 5.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size);
gamewindow_mapbutton->set_geometry(l + 6.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size);
// reposition buy menu
gamewindow_buymenu->event_resize();
// reposition trade menu
gamewindow_trademenu->event_resize();
// set hud geometry
gamewindow_hud->set_geometry(0, 0, width(), height());
gamewindow_hud->event_resize();
// reposition entity menus
gamewindow_entitymenu->set_size(width() - smallmargin * 2, height() - smallmargin * 4);
gamewindow_entitymenu->set_location(smallmargin, smallmargin * 2);
// reposition map
gamewindow_map->set_size(width() - smallmargin * 2, height() - smallmargin * 4);
gamewindow_map->set_location(smallmargin, smallmargin * 2);
// reposition inventory
gamewindow_inventory->set_size(width() - smallmargin * 2, height() - smallmargin * 4);
gamewindow_inventory->set_location(smallmargin, smallmargin * 2);
}
void GameWindow::draw()
{
ui::Window::draw();
const float smallmargin = ui::UI::elementsize.height();
if (core::localcontrol()->state() == core::Entity::Docked) {
gamewindow_launchbutton->show();
gamewindow_dockbutton->hide();
} else {
gamewindow_launchbutton->hide();
gamewindow_dockbutton->show();
}
if (core::localplayer()->view()) {
// hide hide when a view is set
gamewindow_hud->hide();
// docking view
if (core::localplayer()->view()->menus().size()) {
if (gamewindow_entitymenu->generated_entity() != core::localplayer()->view()) {
// initially show the menu
show_menu("main");
map()->hide();
chat()->hide();
// hide other windows
gamewindow_chat->hide();
gamewindow_map->hide();
gamewindow_inventory->hide();
} else if (!gamewindow_entitymenu->visible() && !gamewindow_buymenu->visible() && !gamewindow_trademenu->visible() &&
!inventory()->visible() && !map()->visible() && (!chat()->visible() || chat()->small_view())) {
// show the menu if there's no other window open
gamewindow_entitymenu->show();
}
gamewindow_homebutton->enable();
} else {
// entity without menus, plain view
this->hide();
return;
}
} else {
gamewindow_homebutton->disable();
if (gamewindow_entitymenu->visible()) {
gamewindow_entitymenu->hide();
}
if (gamewindow_entitymenu->generated_entity()) {
gamewindow_entitymenu->generate(0, 0);
}
if (gamewindow_buymenu->visible()) {
gamewindow_buymenu->hide();
}
if (gamewindow_trademenu->visible()) {
gamewindow_trademenu->hide();
}
if (!map()->visible() && !chat()->visible() && !inventory()->visible()) {
gamewindow_hud->set_focus();
}
gamewindow_hud->show();
}
// reposition chat widget
if (chat()->visible()) {
if (gamewindow_chat->small_view()) {
gamewindow_chat->set_size(width() - smallmargin * 2, font()->height() * 2);
gamewindow_chat->set_location(smallmargin, height() - smallmargin *2 - gamewindow_chat->height());
} else {
gamewindow_chat->set_geometry(gamewindow_map->location(), gamewindow_map->size());
}
gamewindow_chat->event_resize();
}
}
bool GameWindow::on_keypress(const int key, const unsigned int modifier)
{
switch (key) {
case SDLK_ESCAPE:
if (gamewindow_entitymenu->visible()) {
gamewindow_entitymenu->hide();
return true;
}
if (gamewindow_buymenu->visible()) {
gamewindow_buymenu->hide();
return true;
}
if (gamewindow_trademenu->visible()) {
gamewindow_trademenu->hide();
return true;
}
if (map()->visible()) {
map()->hide();
return true;
}
if (inventory()->visible()) {
inventory()->hide();
return true;
}
break;
default:
break;
}
return Window::on_keypress(key, modifier);
}
}
|