Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 3dbb1fb7b16e12e5813cd31644d9b6ed7a8af0aa (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
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

/*
   client/mapwindow.cc
   This file is part of the Osirion project and is distributed under
   the terms of the GNU General Public License version 2
*/

#include "audio/audio.h"
#include "core/application.h"
#include "core/entity.h"
#include "core/entityglobe.h"
#include "client/mapwindow.h"
#include "client/targets.h"
#include "ui/ui.h"
#include "ui/paint.h"
#include "render/gl.h"
#include "render/textures.h"
#include "render/text.h"

namespace client
{

MapWindow::MapWindow(ui::Widget *parent) : ui::Window(parent)
{
	set_label("map");
	set_border(true);
	set_background(true);
	set_font(ui::root()->font_small());

	// ---- right pane
	mapwindow_pane_right = new ui::Widget(this);
	mapwindow_pane_right->set_background(true);
	mapwindow_pane_right->set_border(true);
	
	// modelview, add it first so it gets rendered before anything else
	mapwindow_modelview = new ui::ModelView(mapwindow_pane_right);
	mapwindow_modelview->set_label("modelview");
	mapwindow_modelview->set_background(false);
	mapwindow_modelview->set_border(false);
	
	// target title 
	mapwindow_targetlabel = new ui::Label(mapwindow_pane_right);
	mapwindow_targetlabel->set_label("targetlabel");
	mapwindow_targetlabel->set_background(false);
	mapwindow_targetlabel->set_border(false);
	mapwindow_targetlabel->set_alignment(ui::AlignCenter);
	
	// info label (modelview child)
	mapwindow_infolabel = new ui::Label(mapwindow_pane_right);
	mapwindow_infolabel ->set_label("infolabel");
	mapwindow_infolabel->set_background(false);
	mapwindow_infolabel->set_border(false);
	mapwindow_infolabel->set_alignment(ui::AlignCenter);
	
	// target text
	mapwindow_scrollpane = new ui::ScrollPane(mapwindow_pane_right, mapwindow_infotext);
	mapwindow_scrollpane->set_background(false);
	mapwindow_scrollpane->set_border(false);
	mapwindow_scrollpane->set_alignment(ui::AlignTop);

	// ---- left pane
	mapwindow_pane_left = new ui::Widget(this);
	mapwindow_pane_left->set_background(true);
	mapwindow_pane_left->set_border(true);
	
	// map widget
	mapwindow_mapwidget = new MapWidget(mapwindow_pane_left);
	mapwindow_mapwidget->set_background(false);
	mapwindow_mapwidget->set_border(false);
	
	// galaxy map widget
	mapwindow_galaxymapwidget = new GalaxyMapWidget(mapwindow_pane_left);
	mapwindow_galaxymapwidget->set_background(false);
	mapwindow_galaxymapwidget->set_border(false);
	mapwindow_galaxymapwidget->hide();
	
	// map label
	mapwindow_maplabel = new ui::Label(mapwindow_pane_left);
	mapwindow_maplabel->set_label("maplabel");
	mapwindow_maplabel->set_background(false);
	mapwindow_maplabel->set_border(false);
	mapwindow_maplabel->set_alignment(ui::AlignCenter);
	
	// map buttons
	mapwindow_zonebutton = new ui::IconButton(mapwindow_pane_left, "bitmaps/icons/button_map");
	mapwindow_galaxybutton = new ui::IconButton(mapwindow_pane_left, "bitmaps/icons/button_galaxy");
	
	// ---- window title
	mapwindow_titlelabel = new ui::Label(this);
	mapwindow_titlelabel->set_label("title");
	mapwindow_titlelabel->set_background(false);
	mapwindow_titlelabel->set_border(false);
	mapwindow_titlelabel->set_font(ui::root()->font_large());
	mapwindow_titlelabel->set_alignment(ui::AlignCenter);
	mapwindow_titlelabel->set_text("STAR CHART");
	
	// close button
	mapwindow_closebutton = new ui::IconButton(mapwindow_titlelabel, "bitmaps/icons/window_close");
	


	hide();
}

MapWindow::~MapWindow()
{
}

void MapWindow::hide()
{
	ui::Window::hide();
}

void MapWindow::show()
{
	ui::Window::show();
		
	// show map widget
	mapwindow_mode = ShowZone;
	mapwindow_galaxymapwidget->hide();
	mapwindow_mapwidget->show();
	mapwindow_mapwidget->set_zone(core::localplayer()->zone());
	mapwindow_maplabel->set_text(mapwindow_mapwidget->zone()->name());
	
	// use current HUD target as default selection
	if (core::localplayer()->view()) {
		mapwindow_mapwidget->set_target(core::localplayer()->view());
	} else {
		mapwindow_mapwidget->set_target(targets::current());
	}
	
	// show target or zone info
	if (mapwindow_mapwidget->target()) {
		show_entity_info(mapwindow_mapwidget->target());
	} else {
		show_zone_info(mapwindow_mapwidget->zone());
	}	
}

void MapWindow::resize()
{
	const float padding =  ui::root()->font_large()->height();
	const float icon_size = 24.0f; // small icons
	
	// resize title label
	mapwindow_titlelabel->set_size(width() - padding * 2.0f, mapwindow_titlelabel->font()->height());	
	mapwindow_titlelabel->set_location(padding, padding);

	// resize close button
	mapwindow_closebutton->set_size(mapwindow_titlelabel->font()->height(), mapwindow_titlelabel->font()->height());
	mapwindow_closebutton->set_location(mapwindow_titlelabel->width() - mapwindow_closebutton->width(), 0);
	
	// resize left pane
	mapwindow_pane_left->set_size((width() - padding * 3.0f) * 0.5f, height() - mapwindow_titlelabel->bottom() - 2.0f * padding);
	mapwindow_pane_left->set_location(padding, mapwindow_titlelabel->bottom() + padding);
	
	{
		const ui::Widget *pane = mapwindow_pane_left;
		const float margin_horizontal = pane->font()->width();
		const float margin_vertical = pane->font()->height() * 0.5f;
		
		// resize map label
		mapwindow_maplabel->set_size(pane->width() - 2.0f * margin_horizontal, mapwindow_maplabel->font()->height());
		mapwindow_maplabel->set_location(margin_horizontal, margin_vertical);
	
		// resize zone map widget
		mapwindow_mapwidget->set_size(pane->width() - 2.0f * margin_horizontal, pane->height() - mapwindow_maplabel->bottom() - margin_vertical * 4.0f - icon_size);
		mapwindow_mapwidget->set_location(margin_horizontal, mapwindow_maplabel->bottom() + margin_vertical);
	
		// set galaxy map size equal to zone map size
		mapwindow_galaxymapwidget->set_geometry(mapwindow_mapwidget->location(), mapwindow_mapwidget->size());
	
		// resize map buttons
		float l = (mapwindow_mapwidget->width() - math::min(mapwindow_mapwidget->width(), mapwindow_mapwidget->height())) * 0.5f;
	
		mapwindow_zonebutton->set_size(icon_size, icon_size);
		mapwindow_zonebutton->set_location(mapwindow_maplabel->left() + l, mapwindow_mapwidget->bottom() + margin_vertical);
	
		mapwindow_galaxybutton->set_size(icon_size, icon_size);
		mapwindow_galaxybutton->set_location(mapwindow_maplabel->right() - l - icon_size, mapwindow_mapwidget->bottom() + margin_vertical);
	}
	
	// resize right pane
	mapwindow_pane_right->set_size(mapwindow_pane_left->size());
	mapwindow_pane_right->set_location(mapwindow_pane_left->right() + padding, mapwindow_titlelabel->bottom() + padding);

	{
		const ui::Widget *pane = mapwindow_pane_right;
		const float margin_horizontal = pane->font()->width();
		const float margin_vertical = pane->font()->height() * 0.5f;

		// resize target label
		mapwindow_targetlabel->set_size(pane->width() - margin_horizontal * 2.0f, mapwindow_targetlabel->font()->height());
		mapwindow_targetlabel->set_location(margin_horizontal, margin_vertical);
		
		// resize info label
		mapwindow_infolabel->set_size(pane->width() - margin_horizontal * 2.0f, mapwindow_infolabel->font()->height());
		mapwindow_infolabel->set_location(margin_horizontal, pane->height() * 0.5f);
	
		// resize target modelview
		mapwindow_modelview->set_size(mapwindow_targetlabel->width(), mapwindow_infolabel->top() - mapwindow_targetlabel->bottom() - margin_vertical * 2.0f);
		mapwindow_modelview->set_location(margin_horizontal, mapwindow_targetlabel->bottom() + margin_vertical);
	
		// resize target info text
		mapwindow_scrollpane->set_size(mapwindow_infolabel->width(), pane->height() - mapwindow_infolabel->bottom() - margin_vertical * 2.0f);
		mapwindow_scrollpane->set_location(mapwindow_modelview->left(), mapwindow_infolabel->bottom() + margin_vertical);
	}
}

void MapWindow::draw()
{
	ui::Window::draw();
	
	/*
	// make sure the target still exists
	mapwindow_target = core::localplayer()->zone()->find_entity(mapwindow_target);
	
	mapwindow_mapwidget->set_zone(core::localplayer()->zone());
	mapwindow_mapwidget->set_target(mapwindow_target);
	mapwindow_maplabel->set_text(core::localplayer()->zone()->name());
	
	*/
	if (mapwindow_inforecord) {
		if (mapwindow_infotimestamp != mapwindow_inforecord->timestamp()) {
			// update info
			set_info(mapwindow_inforecord);
		}
	}
	
}

void MapWindow::set_info(const core::Info *info)
{
	mapwindow_inforecord = 0;
	mapwindow_infotimestamp = 0;
	mapwindow_infotext.clear();
	mapwindow_infolabel->clear();
	
	if (info) {
		mapwindow_inforecord = core::game()->request_info(info->id());	
	}
	
	if (mapwindow_inforecord) {
		mapwindow_infolabel->set_text(mapwindow_inforecord->name());
		for (core::Info::Text::const_iterator it = mapwindow_inforecord->text().begin(); it != mapwindow_inforecord->text().end(); it++) {
			mapwindow_infotext.push_back((*it));
		}		
		mapwindow_infotimestamp = mapwindow_inforecord->timestamp();		
	} else {
		mapwindow_infotext.push_back("Information is not available");
		mapwindow_infotimestamp = 0;
	}
}

void MapWindow::show_entity_info(const core::Entity *entity)
{
			
	if (core::localplayer()->zone() == entity->zone()) {
		targets::set_target(entity);
	}
	
	if (entity) {
		if (entity->model()) {
			mapwindow_modelview->set_mode(ui::ModelView::Model);
			mapwindow_modelview->set_modelname(entity->model()->name());
			mapwindow_modelview->set_colors(entity->color(), entity->color_second());
			mapwindow_modelview->set_zoom(2.5f);
			mapwindow_modelview->set_radius(2.0f);
			
		} else if (entity->type() == core::Entity::Globe) {
			mapwindow_modelview->set_mode(ui::ModelView::Globe);
			const core::EntityGlobe *globe = static_cast<const core::EntityGlobe *>(entity);
			mapwindow_modelview->set_colors(globe->color(), globe->color_second());
			mapwindow_modelview->set_globetexturename(
				globe->texturename(),
				globe->coronaname(),
				globe->ringsname(),
				globe->has_flag(core::Entity::Bright)
				
			);
			mapwindow_modelview->set_zoom(2.5f);
			if (globe->has_flag(core::Entity::Bright)) {
				mapwindow_modelview->set_radius(0.5f);
			} else {
				mapwindow_modelview->set_radius(1.0f);
			}
		} else {
			mapwindow_modelview->clear();
		}
		
		mapwindow_targetlabel->set_text(entity->name());
		
		set_info(entity->info());
		mapwindow_modelview->show();
		
	} else {
		set_info(0);
		mapwindow_infotext.clear();		
		mapwindow_modelview->clear();
		
		mapwindow_targetlabel->clear();
		mapwindow_infolabel->clear();
	}
}

void MapWindow::show_zone_info(const core::Zone *zone)
{
	if (zone) {
		set_info(zone->info());
		
		switch (mapwindow_mode) {
			case ShowZone:
				mapwindow_targetlabel->clear();
				break;
			
			case ShowWorld:
				mapwindow_targetlabel->set_text(zone->name());
				break;
		}
	} else {
		set_info(0);
		mapwindow_infotext.clear();
		mapwindow_targetlabel->clear();
	}
	mapwindow_modelview->clear();
}

bool MapWindow::on_keypress(const int key, const unsigned int modifier)
{
	if (key == SDLK_ESCAPE) {
		if (visible()) {
			hide();
			return true;
		}
	}

	return false;
}

bool MapWindow::on_emit(ui::Widget *sender, const ui::Widget::Event event, void *data)
{
	if (sender == mapwindow_closebutton) {
		if (event == ui::Widget::EventButtonClicked) {
			hide();
		}
		return true;
		
	} else if (sender == mapwindow_mapwidget) {
		if (event == ui::Widget::EventClicked) {
			if (mapwindow_mapwidget->target()) {
				show_entity_info(mapwindow_mapwidget->target());
			} else {
				show_zone_info(mapwindow_mapwidget->zone());
			}	
			return true;
		}
	
	} else if (sender == mapwindow_galaxymapwidget) {
		if (event == ui::Widget::EventClicked) {
			show_zone_info(mapwindow_galaxymapwidget->zone());
			return true;
		} else if (event == ui::Widget::EventDoubleClicked) {
			if (mapwindow_galaxymapwidget->zone()) {
				mapwindow_mode = ShowZone;
				mapwindow_galaxymapwidget->hide();
				mapwindow_mapwidget->set_zone(mapwindow_galaxymapwidget->zone());
				mapwindow_mapwidget->show();				
				mapwindow_maplabel->set_text(mapwindow_mapwidget->zone()->name());
				show_zone_info(mapwindow_mapwidget->zone());
			}
			return true;
		}
		
	} else if (sender == mapwindow_zonebutton) {
		if (event == ui::Widget::EventButtonClicked) {
			if (mapwindow_mode == ShowZone) {
				mapwindow_mapwidget->set_target(0);
				show_zone_info(mapwindow_mapwidget->zone());
			} else {
				mapwindow_mode = ShowZone;
				if (mapwindow_galaxymapwidget->zone()) {
					mapwindow_mapwidget->set_zone(mapwindow_galaxymapwidget->zone());
				} else {
					mapwindow_mapwidget->set_zone(core::localplayer()->zone());
				}
				mapwindow_mapwidget->show();
				mapwindow_galaxymapwidget->hide();
				mapwindow_maplabel->set_text(mapwindow_mapwidget->zone()->name());
			}
			return true;
		}
		
	} else if (sender == mapwindow_galaxybutton) {
		if (event == ui::Widget::EventButtonClicked) {
			if (mapwindow_mode == ShowWorld) {
				mapwindow_galaxymapwidget->set_zone(0);
				show_zone_info(0);
			} else {
				mapwindow_mode = ShowWorld;
				mapwindow_mapwidget->hide();
				mapwindow_galaxymapwidget->show();
				mapwindow_galaxymapwidget->set_zone(mapwindow_mapwidget->zone());
				show_zone_info(mapwindow_galaxymapwidget->zone());
				mapwindow_maplabel->set_text("Starsystems");
			}
			return true;
		}
	}
	
	return Window::on_emit(sender, event, data);
}

}