Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 684e08e514580a9803f821b4e09912b98fc61b6f (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
/*
   client/worldview.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 "core/application.h"
#include "client/targeticonbutton.h"
#include "client/worldview.h"
#include "client/video.h"
#include "ui/ui.h"

namespace client
{

WorldView::WorldView(ui::Widget *parent) : ui::Widget(parent)
{
	set_label("worldview");
	set_border(false);
	set_background(false);

	// add child widgets
	view_devinfo = new DevInfoWidget(this);
	view_statsinfo = new StatsInfoWidget(this);
	view_keyinfo = new KeyInfoWidget(this);

	view_playerview = new PlayerView(this);
	view_playerview->raise();
	view_playerview->hide();

	// icon buttons
	view_menubutton = new ui::IconButton(this, "bitmaps/icons/button_menu", "ui_menu");

	view_launchbutton  = new ui::IconButton(this, "bitmaps/icons/button_launch", "launch");
	view_dockbutton  = new TargetIconButton(this, "bitmaps/icons/button_dock", "dock", core::Entity::Dockable);

	view_chatbutton = new ui::IconButton(this, "bitmaps/icons/button_chat", "ui_chat");
	view_mapbutton  = new ui::IconButton(this, "bitmaps/icons/button_map", "ui_map");
}

WorldView::~WorldView()
{

}

void WorldView::resize()
{
	set_size(parent()->size());

	//const float largemargin = ui::UI::elementsize.width() * 0.25
	const float smallmargin = ui::UI::elementsize.height();

	// resize player view
	view_playerview->set_size(size());

	// reposition devinfo widget
	view_devinfo->set_size(font()->width()*32, font()->height()*5);
	view_devinfo->set_location(smallmargin, smallmargin);

	// reposition stats widget
	view_statsinfo->set_size(font()->width()*12, font()->height()*5);
	view_statsinfo->set_location(width() - view_statsinfo->width() - smallmargin, smallmargin);

	// reposition keypress widget
	view_keyinfo->set_size(font()->width()*12, font()->height()*1);
	view_keyinfo->set_location(width() - view_keyinfo->width() - smallmargin,
				   height() - view_keyinfo->height() - smallmargin);

	// icons
	const float icon_margin = 4.0f;
	const float icon_size = 48.0f;
	const float icon_count = 6;
	const float l = (width() - ((icon_count + 1) * icon_margin) - (icon_count * icon_size)) * 0.5f;

	view_menubutton->set_geometry(l, icon_margin, icon_size, icon_size);
	// spacer
	view_dockbutton->set_geometry(l + 2.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size);
	view_launchbutton->set_geometry(l + 2.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size);
	// spacer
	view_chatbutton->set_geometry(l + 4.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size);
	view_mapbutton->set_geometry(l + 5.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size);
}

void WorldView::clear()
{
	view_playerview->clear();
}

void WorldView::event_text(const std::string & text)
{
	view_playerview->event_text(text);
}

void WorldView::draw()
{
	// worldview is only drawn when the application is connected
	// and the loader screen is not shown

	view_devinfo->set_visible(draw_devinfo->value() ? true : false);
	view_statsinfo->set_visible(draw_stats->value() ? true : false);
	view_keyinfo->set_visible(draw_keypress->value() ? true : false);

	if (ui::root()->active() || !core::game()->interactive() || !core::localcontrol() || (core::localplayer()->view() && !core::localplayer()->view()->menus().size())) {
		view_playerview->hide();
		view_menubutton->hide();
		view_dockbutton->hide();
		view_launchbutton->hide();
		view_chatbutton->hide();
		view_mapbutton->hide();
	} else {
		view_playerview->show();
		view_playerview->set_focus();

		if (core::localcontrol()->state() == core::Entity::Docked) {
			view_launchbutton->show();
			view_dockbutton->hide();
		} else {
			view_launchbutton->hide();
			view_dockbutton->show();
		}

		view_menubutton->show();
		view_chatbutton->show();
		view_mapbutton->show();
	}
}

}