blob: 77fb60dee2ac85fd1f997bec2c468962a850d0a9 (
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
|
/*
client/hudtargetstatus.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/hudtargetstatus.h"
#include "client/targets.h"
#include "client/client.h"
#include "ui/ui.h"
#include "ui/paint.h"
namespace client
{
HUDTargetStatus::HUDTargetStatus(ui::Widget *parent) : ui::Widget(parent)
{
set_border(true);
set_background(true);
set_font(ui::root()->font_tiny());
}
void HUDTargetStatus::draw_background()
{
ui::Paint::draw_material(global_location(), size(), "ui/window");
}
void HUDTargetStatus::draw()
{
const core::Entity *target = targets::current();
if (target) {
const float padding = font()->width() * 0.25f;
math::Vector2f pos(global_location());
pos[0] += padding;
pos[1] += padding;
math::Vector2f s(width() - 2.0f * padding, height() - 2.0f * padding);
// reputation color
std::string label_color;
const float reputation = core::localplayer()->reputation(target->faction());
if (reputation >= core::range::reputation_friendly) {
// friendly
label_color.assign("^2");
} else if (reputation <= core::range::reputation_hostile) {
// hostile
label_color.assign("^1");
} else {
label_color.assign("^B");
}
std::ostringstream targetinfostr;
if (target->type() == core::Entity::Controlable) {
const core::EntityControlable *target_controlable = static_cast<const core::EntityControlable *>(target);
if (target_controlable->owner()) {
targetinfostr << label_color << target_controlable->owner()->name() << "\n";
} else {
targetinfostr << label_color << target->name() << "\n";
}
if (target->info()) {
targetinfostr << "^N" << target->info()->name() << "\n";
} else {
targetinfostr << "\n";
}
} else {
targetinfostr << label_color << target->name() << "\n";
if (target->info()) {
core::game()->request_info(target->info()->id());
targetinfostr << "^N" << target->info()->name() << "\n";
} else {
targetinfostr << "\n";
}
}
float d = math::distance(core::localcontrol()->location(), target->location())
- target->radius() - core::localcontrol()->radius();
if (d > 0) {
targetinfostr << "^NDist:^B ";
if (d > 100.0f) {
targetinfostr << roundf(d * 0.1f) << "km";
} else {
targetinfostr << roundf(d * 100.0f) << "m";
}
if (core::localcontrol()->speed() > 0.1f) {
targetinfostr << "^N ETA:^B ";
float eta = floorf(d / core::localcontrol()->speed());
if (eta > 60.0f) {
float etamin = floorf(eta / 60.0f);
targetinfostr << etamin << "min ";
eta -= etamin * 60;
}
targetinfostr << eta << "sec";
}
// } else if (target->has_flag(core::Entity::Dockable)) {
// targetinfostr << "^FDock";
} else {
targetinfostr << "^B--";
}
ui::Paint::set_color(palette()->foreground());
ui::Paint::draw_label(pos, s, font() , targetinfostr.str(), ui::AlignLeft | ui::AlignTop);
}
}
bool HUDTargetStatus::on_keypress(const int key, const unsigned int modifier)
{
return false;
}
} // namespace client
|