Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 0eeafba22a0da38a0691c94c6e28fc9ecbdc83d5 (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/hudenginestatus.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 "client/input.h"
#include "client/hudenginestatus.h"
#include "core/core.h"
#include "core/application.h"
#include "ui/ui.h"
#include "ui/iconbutton.h"
#include "ui/paint.h"
#include "render/camera.h"
#include "render/gl.h"
#include "render/render.h"

namespace client
{

HUDEngineStatus::HUDEngineStatus(ui::Widget *parent) : ui::Widget(parent)
{
	set_border(false);
	set_background(false);
		
	_button_auto_palette = new ui::Palette(*palette());
	_button_auto = new ui::IconButton(this, "bitmaps/hud/button_auto", "freeflight");
	_button_auto->set_palette(_button_auto_palette);
	
	_button_lock_palette = new ui::Palette(*palette());
	_button_lock = new ui::IconButton(this, "bitmaps/hud/button_lock", "ui_control");
	_button_lock->set_palette(_button_lock_palette);
}

HUDEngineStatus::~HUDEngineStatus()
{
	delete _button_auto_palette;
	delete _button_lock_palette;
}

void HUDEngineStatus::resize()
{
	const float padding =  ui::root()->font_tiny()->width();
	const float icon_size = 48.0f;
	
	_button_auto->set_size(icon_size * 2.0f, icon_size);
	_button_auto->set_location(padding, padding);
	
	_button_lock->set_size(icon_size * 2.0f, icon_size);
	_button_lock->set_location(width() - padding - _button_lock->width(), padding);
	
}

void HUDEngineStatus::draw()
{
	const float padding =  ui::root()->font_tiny()->width();
	
	math::Vector2f s(size());
	s[0] -= 2.0f * padding;
	s[1] = ui::root()->font_large()->height();
	
	math::Vector2f pos(global_location());
	pos[0] += padding;
	pos[1] += height() - s[1] - padding;
	
	// thrust
	const float blink_t = core::application()->time() * 2.0f;
	std::ostringstream thruststr;
	switch(core::localcontrol()->state())
	{
		case core::Entity::Normal:
			thruststr << "^B" << roundf(core::localcontrol()->thrust() * 100.0f) << "%";
			break;
		case core::Entity::ImpulseInitiate:
		case core::Entity::JumpInitiate:
			
			if ((blink_t - floorf(blink_t)) < 0.5f)
			{
				thruststr << "^B--";
			}
			break;
		default:
			thruststr << "^B--";
			break;
	}

	// speed
	std::ostringstream speedstr;
	speedstr << "^B" << roundf(core::localcontrol()->speed() * 100.0f);
	
	ui::Paint::set_color(palette()->foreground());
	ui::Paint::draw_label(pos, s, ui::root()->font_large(), thruststr.str(), ui::AlignLeft | ui::AlignTop);
	ui::Paint::draw_label(pos, s, ui::root()->font_large(), speedstr.str(), ui::AlignRight | ui::AlignTop);
	
	// autopilot and control lock buttons

	// see HUD::draw()
	const bool control_lock = !input::mouse_control;

	if (core::localplayer()->autopilot_target())
	{
		_button_auto->enable();
		if (control_lock || ((blink_t - floorf(blink_t)) < 0.5f))
		{
			_button_auto_palette->set_foreground(palette()->mission());
		} else
		{
			_button_auto_palette->set_foreground(palette()->foreground());
		}
	} else
	{
		_button_auto->disable();
	}
	
	if (control_lock)
	{
		_button_lock_palette->set_foreground(math::Color(1.0f, 0.0f, 0.0f));
	} else
	{
		// free controls
		_button_lock_palette->set_foreground(palette()->foreground());
	}
	
	// health bar size
	const float hb_width = width() - 12 * ui::root()->font_large()->width() - 2.0f * padding;
	const float hb_height = ui::root()->font_tiny()->width();
	const float hb_f = hb_width * core::localcontrol()->health() / 100.0f;
	
	pos.assign(global_location());
	pos[0] += (width() - hb_width) * 0.5f;
	pos[1] += height() - hb_height - padding;
	
	// health bar
	gl::color(0, 1, 0, 1);
	gl::begin(gl::Quads);
	gl::vertex(pos[0], pos[1]);
	gl::vertex(pos[0] + hb_f, pos[1]);
	gl::vertex(pos[0] + hb_f, pos[1] + hb_height);
	gl::vertex(pos[0], pos[1] + hb_height);
	gl::end();
	
	// health bar frame
	gl::color(palette()->foreground());
	
	gl::begin(gl::LineLoop);
	gl::vertex(pos[0], pos[1]);
	gl::vertex(pos[0] + hb_width, pos[1]);
	gl::vertex(pos[0] + hb_width, pos[1] + hb_height);
	gl::vertex(pos[0], pos[1] + hb_height);
	gl::end();
}

bool HUDEngineStatus::on_keypress(const int key, const unsigned int modifier)
{
	return false;
}

} // namespace client