diff options
Diffstat (limited to 'src/hud.cpp')
-rw-r--r-- | src/hud.cpp | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/src/hud.cpp b/src/hud.cpp index 183f94e49..80112a6ec 100644 --- a/src/hud.cpp +++ b/src/hud.cpp @@ -29,14 +29,17 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "inventory.h" #include "tile.h" #include "localplayer.h" +#include "camera.h" #include <IGUIStaticText.h> -Hud::Hud(video::IVideoDriver *driver, gui::IGUIEnvironment* guienv, - gui::IGUIFont *font, u32 text_height, IGameDef *gamedef, +Hud::Hud(video::IVideoDriver *driver, scene::ISceneManager* smgr, + gui::IGUIEnvironment* guienv, gui::IGUIFont *font, + u32 text_height, IGameDef *gamedef, LocalPlayer *player, Inventory *inventory) { this->driver = driver; + this->smgr = smgr; this->guienv = guienv; this->font = font; this->text_height = text_height; @@ -268,6 +271,33 @@ void Hud::drawLuaElements() { InventoryList *inv = inventory->getList(e->text); drawItem(pos, hotbar_imagesize, e->number, inv, e->item, e->dir); break; } + case HUD_ELEM_WAYPOINT: { + v3f p_pos = player->getPosition() / BS; + v3f w_pos = e->world_pos * BS; + float distance = floor(10 * p_pos.getDistanceFrom(e->world_pos)) / 10; + scene::ICameraSceneNode* camera = smgr->getActiveCamera(); + core::matrix4 trans = camera->getProjectionMatrix(); + trans *= camera->getViewMatrix(); + f32 transformed_pos[4] = { w_pos.X, w_pos.Y, w_pos.Z, 1.0f }; + trans.multiplyWith1x4Matrix(transformed_pos); + if (transformed_pos[3] < 0) + break; + f32 zDiv = transformed_pos[3] == 0.0f ? 1.0f : + core::reciprocal(transformed_pos[3]); + pos.X = screensize.X * (0.5 * transformed_pos[0] * zDiv + 0.5); + pos.Y = screensize.Y * (0.5 - transformed_pos[1] * zDiv * 0.5); + video::SColor color(255, (e->number >> 16) & 0xFF, + (e->number >> 8) & 0xFF, + (e->number >> 0) & 0xFF); + core::rect<s32> size(0, 0, 200, 2 * text_height); + std::wstring text = narrow_to_wide(e->name); + font->draw(text.c_str(), size + pos, color); + std::ostringstream os; + os<<distance<<e->text; + text = narrow_to_wide(os.str()); + pos.Y += text_height; + font->draw(text.c_str(), size + pos, color); + break; } default: infostream << "Hud::drawLuaElements: ignoring drawform " << e->type << " of hud element ID " << i << " due to unrecognized type" << std::endl; @@ -477,4 +507,3 @@ void drawItemStack(video::IVideoDriver *driver, font->draw(text.c_str(), rect2, color, false, false, clip); } } - |