Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/hudtargetstatus.cc')
-rw-r--r--src/client/hudtargetstatus.cc97
1 files changed, 97 insertions, 0 deletions
diff --git a/src/client/hudtargetstatus.cc b/src/client/hudtargetstatus.cc
new file mode 100644
index 0000000..1c910d3
--- /dev/null
+++ b/src/client/hudtargetstatus.cc
@@ -0,0 +1,97 @@
+/*
+ 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);
+
+ 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 << "^B" << target_controlable->owner()->name() << "\n";
+ targetinfostr << "^B" << target->name() << "\n";
+ } else {
+ targetinfostr << "^B" << target->name() << "\n";
+ targetinfostr << "\n";
+ }
+ } else {
+ targetinfostr << "^B" << target->name() << "\n";
+ 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
+