2013-04-14 00:20:22 +02:00
|
|
|
/*
|
|
|
|
Minetest
|
|
|
|
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
|
|
|
Copyright (C) 2010-2013 blue42u, Jonathon Anderson <anderjon@umail.iu.edu>
|
|
|
|
Copyright (C) 2010-2013 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2013-08-11 04:09:45 +02:00
|
|
|
#include "hud.h"
|
|
|
|
#include "settings.h"
|
2013-04-14 00:20:22 +02:00
|
|
|
#include "util/numeric.h"
|
|
|
|
#include "log.h"
|
2017-01-09 20:39:22 +01:00
|
|
|
#include "client.h"
|
2013-08-11 04:09:45 +02:00
|
|
|
#include "inventory.h"
|
2017-08-18 19:25:07 +02:00
|
|
|
#include "shader.h"
|
2015-03-05 11:52:57 +01:00
|
|
|
#include "client/tile.h"
|
2013-08-11 04:09:45 +02:00
|
|
|
#include "localplayer.h"
|
2014-01-26 21:31:59 +01:00
|
|
|
#include "camera.h"
|
2014-04-05 14:12:36 +02:00
|
|
|
#include "porting.h"
|
2014-11-28 20:06:34 +01:00
|
|
|
#include "fontengine.h"
|
2015-03-09 14:32:11 +01:00
|
|
|
#include "guiscalingfilter.h"
|
2016-02-07 04:08:43 +01:00
|
|
|
#include "mesh.h"
|
2017-03-10 18:25:58 +01:00
|
|
|
#include "wieldmesh.h"
|
2017-06-26 20:11:17 +02:00
|
|
|
#include "client/renderingengine.h"
|
2013-04-14 00:20:22 +02:00
|
|
|
|
2014-04-21 14:10:59 +02:00
|
|
|
#ifdef HAVE_TOUCHSCREENGUI
|
2017-11-08 23:56:20 +01:00
|
|
|
#include "gui/touchscreengui.h"
|
2014-04-21 14:10:59 +02:00
|
|
|
#endif
|
2013-04-14 00:20:22 +02:00
|
|
|
|
2017-07-02 20:29:58 +02:00
|
|
|
Hud::Hud(gui::IGUIEnvironment *guienv, Client *client, LocalPlayer *player,
|
2016-04-11 05:51:36 +02:00
|
|
|
Inventory *inventory)
|
|
|
|
{
|
2017-07-02 20:29:58 +02:00
|
|
|
driver = RenderingEngine::get_video_driver();
|
2013-04-14 00:20:22 +02:00
|
|
|
this->guienv = guienv;
|
2017-01-09 20:39:22 +01:00
|
|
|
this->client = client;
|
2013-04-14 00:20:22 +02:00
|
|
|
this->player = player;
|
|
|
|
this->inventory = inventory;
|
2014-05-05 07:45:20 +02:00
|
|
|
|
2016-04-11 05:51:36 +02:00
|
|
|
m_hud_scaling = g_settings->getFloat("hud_scaling");
|
2017-06-26 20:11:17 +02:00
|
|
|
m_hotbar_imagesize = floor(HOTBAR_IMAGE_SIZE *
|
|
|
|
RenderingEngine::getDisplayDensity() + 0.5f);
|
2016-04-11 05:51:36 +02:00
|
|
|
m_hotbar_imagesize *= m_hud_scaling;
|
2014-04-05 14:12:36 +02:00
|
|
|
m_padding = m_hotbar_imagesize / 12;
|
|
|
|
|
2017-08-18 08:07:59 +02:00
|
|
|
for (auto &hbar_color : hbar_colors)
|
|
|
|
hbar_color = video::SColor(255, 255, 255, 255);
|
2015-02-08 18:45:19 +01:00
|
|
|
|
2017-01-09 20:39:22 +01:00
|
|
|
tsrc = client->getTextureSource();
|
2015-02-08 18:45:19 +01:00
|
|
|
|
2013-04-14 00:20:22 +02:00
|
|
|
v3f crosshair_color = g_settings->getV3F("crosshair_color");
|
|
|
|
u32 cross_r = rangelim(myround(crosshair_color.X), 0, 255);
|
|
|
|
u32 cross_g = rangelim(myround(crosshair_color.Y), 0, 255);
|
|
|
|
u32 cross_b = rangelim(myround(crosshair_color.Z), 0, 255);
|
|
|
|
u32 cross_a = rangelim(g_settings->getS32("crosshair_alpha"), 0, 255);
|
|
|
|
crosshair_argb = video::SColor(cross_a, cross_r, cross_g, cross_b);
|
2015-02-08 18:45:19 +01:00
|
|
|
|
2013-04-14 00:20:22 +02:00
|
|
|
v3f selectionbox_color = g_settings->getV3F("selectionbox_color");
|
|
|
|
u32 sbox_r = rangelim(myround(selectionbox_color.X), 0, 255);
|
|
|
|
u32 sbox_g = rangelim(myround(selectionbox_color.Y), 0, 255);
|
|
|
|
u32 sbox_b = rangelim(myround(selectionbox_color.Z), 0, 255);
|
|
|
|
selectionbox_argb = video::SColor(255, sbox_r, sbox_g, sbox_b);
|
2015-02-08 18:45:19 +01:00
|
|
|
|
2013-04-26 02:56:12 +02:00
|
|
|
use_crosshair_image = tsrc->isKnownSourceImage("crosshair.png");
|
2013-09-03 19:51:40 +02:00
|
|
|
|
2016-02-07 04:08:43 +01:00
|
|
|
m_selection_boxes.clear();
|
2016-02-11 04:57:01 +01:00
|
|
|
m_halo_boxes.clear();
|
|
|
|
|
2017-05-12 00:18:36 +02:00
|
|
|
std::string mode_setting = g_settings->get("node_highlighting");
|
|
|
|
|
|
|
|
if (mode_setting == "halo") {
|
|
|
|
m_mode = HIGHLIGHT_HALO;
|
|
|
|
} else if (mode_setting == "none") {
|
|
|
|
m_mode = HIGHLIGHT_NONE;
|
|
|
|
} else {
|
|
|
|
m_mode = HIGHLIGHT_BOX;
|
|
|
|
}
|
|
|
|
|
2016-02-07 04:08:43 +01:00
|
|
|
m_selection_material.Lighting = false;
|
|
|
|
|
|
|
|
if (g_settings->getBool("enable_shaders")) {
|
2017-01-09 20:39:22 +01:00
|
|
|
IShaderSource *shdrsrc = client->getShaderSource();
|
2016-02-07 04:08:43 +01:00
|
|
|
u16 shader_id = shdrsrc->getShader(
|
2017-05-12 00:18:36 +02:00
|
|
|
m_mode == HIGHLIGHT_HALO ? "selection_shader" : "default_shader", 1, 1);
|
2016-02-07 04:08:43 +01:00
|
|
|
m_selection_material.MaterialType = shdrsrc->getShaderInfo(shader_id).material;
|
|
|
|
} else {
|
|
|
|
m_selection_material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
|
|
|
|
}
|
|
|
|
|
2017-05-12 00:18:36 +02:00
|
|
|
if (m_mode == HIGHLIGHT_BOX) {
|
2016-02-07 04:08:43 +01:00
|
|
|
m_selection_material.Thickness =
|
2015-01-09 18:04:25 +01:00
|
|
|
rangelim(g_settings->getS16("selectionbox_width"), 1, 5);
|
2017-05-12 00:18:36 +02:00
|
|
|
} else if (m_mode == HIGHLIGHT_HALO) {
|
2016-02-07 04:08:43 +01:00
|
|
|
m_selection_material.setTexture(0, tsrc->getTextureForMesh("halo.png"));
|
|
|
|
m_selection_material.setFlag(video::EMF_BACK_FACE_CULLING, true);
|
|
|
|
} else {
|
|
|
|
m_selection_material.MaterialType = video::EMT_SOLID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Hud::~Hud()
|
|
|
|
{
|
|
|
|
if (m_selection_mesh)
|
|
|
|
m_selection_mesh->drop();
|
2013-04-14 00:20:22 +02:00
|
|
|
}
|
|
|
|
|
2016-01-24 14:19:17 +01:00
|
|
|
void Hud::drawItem(const ItemStack &item, const core::rect<s32>& rect,
|
|
|
|
bool selected)
|
|
|
|
{
|
2014-04-05 14:12:36 +02:00
|
|
|
if (selected) {
|
2017-06-19 15:20:30 +02:00
|
|
|
/* draw hihlighting around selected item */
|
|
|
|
if (use_hotbar_selected_image) {
|
|
|
|
core::rect<s32> imgrect2 = rect;
|
|
|
|
imgrect2.UpperLeftCorner.X -= (m_padding*2);
|
|
|
|
imgrect2.UpperLeftCorner.Y -= (m_padding*2);
|
|
|
|
imgrect2.LowerRightCorner.X += (m_padding*2);
|
|
|
|
imgrect2.LowerRightCorner.Y += (m_padding*2);
|
|
|
|
video::ITexture *texture = tsrc->getTexture(hotbar_selected_image);
|
|
|
|
core::dimension2di imgsize(texture->getOriginalSize());
|
|
|
|
draw2DImageFilterScaled(driver, texture, imgrect2,
|
|
|
|
core::rect<s32>(core::position2d<s32>(0,0), imgsize),
|
|
|
|
NULL, hbar_colors, true);
|
|
|
|
} else {
|
|
|
|
video::SColor c_outside(255,255,0,0);
|
|
|
|
//video::SColor c_outside(255,0,0,0);
|
|
|
|
//video::SColor c_inside(255,192,192,192);
|
|
|
|
s32 x1 = rect.UpperLeftCorner.X;
|
|
|
|
s32 y1 = rect.UpperLeftCorner.Y;
|
|
|
|
s32 x2 = rect.LowerRightCorner.X;
|
|
|
|
s32 y2 = rect.LowerRightCorner.Y;
|
|
|
|
// Black base borders
|
|
|
|
driver->draw2DRectangle(c_outside,
|
|
|
|
core::rect<s32>(
|
|
|
|
v2s32(x1 - m_padding, y1 - m_padding),
|
|
|
|
v2s32(x2 + m_padding, y1)
|
|
|
|
), NULL);
|
|
|
|
driver->draw2DRectangle(c_outside,
|
|
|
|
core::rect<s32>(
|
|
|
|
v2s32(x1 - m_padding, y2),
|
|
|
|
v2s32(x2 + m_padding, y2 + m_padding)
|
|
|
|
), NULL);
|
|
|
|
driver->draw2DRectangle(c_outside,
|
|
|
|
core::rect<s32>(
|
|
|
|
v2s32(x1 - m_padding, y1),
|
|
|
|
v2s32(x1, y2)
|
|
|
|
), NULL);
|
|
|
|
driver->draw2DRectangle(c_outside,
|
|
|
|
core::rect<s32>(
|
|
|
|
v2s32(x2, y1),
|
|
|
|
v2s32(x2 + m_padding, y2)
|
|
|
|
), NULL);
|
|
|
|
/*// Light inside borders
|
|
|
|
driver->draw2DRectangle(c_inside,
|
|
|
|
core::rect<s32>(
|
|
|
|
v2s32(x1 - padding/2, y1 - padding/2),
|
|
|
|
v2s32(x2 + padding/2, y1)
|
|
|
|
), NULL);
|
|
|
|
driver->draw2DRectangle(c_inside,
|
|
|
|
core::rect<s32>(
|
|
|
|
v2s32(x1 - padding/2, y2),
|
|
|
|
v2s32(x2 + padding/2, y2 + padding/2)
|
|
|
|
), NULL);
|
|
|
|
driver->draw2DRectangle(c_inside,
|
|
|
|
core::rect<s32>(
|
|
|
|
v2s32(x1 - padding/2, y1),
|
|
|
|
v2s32(x1, y2)
|
|
|
|
), NULL);
|
|
|
|
driver->draw2DRectangle(c_inside,
|
|
|
|
core::rect<s32>(
|
|
|
|
v2s32(x2, y1),
|
|
|
|
v2s32(x2 + padding/2, y2)
|
|
|
|
), NULL);
|
|
|
|
*/
|
2013-04-14 00:20:22 +02:00
|
|
|
}
|
|
|
|
}
|
2014-04-05 14:12:36 +02:00
|
|
|
|
2017-06-19 15:20:30 +02:00
|
|
|
video::SColor bgcolor2(128, 0, 0, 0);
|
|
|
|
if (!use_hotbar_image)
|
|
|
|
driver->draw2DRectangle(bgcolor2, rect, NULL);
|
|
|
|
drawItemStack(driver, g_fontengine->getFont(), item, rect, NULL,
|
|
|
|
client, selected ? IT_ROT_SELECTED : IT_ROT_NONE);
|
|
|
|
}
|
|
|
|
|
2014-04-05 14:12:36 +02:00
|
|
|
//NOTE: selectitem = 0 -> no selected; selectitem 1-based
|
2016-04-11 05:51:36 +02:00
|
|
|
void Hud::drawItems(v2s32 upperleftpos, v2s32 screen_offset, s32 itemcount,
|
|
|
|
s32 inv_offset, InventoryList *mainlist, u16 selectitem, u16 direction)
|
2014-04-05 14:12:36 +02:00
|
|
|
{
|
2014-04-21 14:10:59 +02:00
|
|
|
#ifdef HAVE_TOUCHSCREENGUI
|
2015-01-09 18:04:25 +01:00
|
|
|
if (g_touchscreengui && inv_offset == 0)
|
2014-04-21 14:10:59 +02:00
|
|
|
g_touchscreengui->resetHud();
|
|
|
|
#endif
|
|
|
|
|
2014-04-05 14:12:36 +02:00
|
|
|
s32 height = m_hotbar_imagesize + m_padding * 2;
|
2015-01-09 18:04:25 +01:00
|
|
|
s32 width = (itemcount - inv_offset) * (m_hotbar_imagesize + m_padding * 2);
|
2014-04-05 14:12:36 +02:00
|
|
|
|
|
|
|
if (direction == HUD_DIR_TOP_BOTTOM || direction == HUD_DIR_BOTTOM_TOP) {
|
2016-04-12 13:54:08 +02:00
|
|
|
s32 tmp = height;
|
|
|
|
height = width;
|
|
|
|
width = tmp;
|
2014-04-05 14:12:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Position of upper left corner of bar
|
2016-04-12 13:54:08 +02:00
|
|
|
v2s32 pos = screen_offset;
|
2017-06-26 20:11:17 +02:00
|
|
|
pos.X *= m_hud_scaling * RenderingEngine::getDisplayDensity();
|
|
|
|
pos.Y *= m_hud_scaling * RenderingEngine::getDisplayDensity();
|
2016-04-12 13:54:08 +02:00
|
|
|
pos += upperleftpos;
|
2014-04-05 14:12:36 +02:00
|
|
|
|
2016-04-12 13:54:08 +02:00
|
|
|
// Store hotbar_image in member variable, used by drawItem()
|
2014-04-05 14:12:36 +02:00
|
|
|
if (hotbar_image != player->hotbar_image) {
|
|
|
|
hotbar_image = player->hotbar_image;
|
2017-08-18 08:07:59 +02:00
|
|
|
if (!hotbar_image.empty())
|
2014-04-05 14:12:36 +02:00
|
|
|
use_hotbar_image = tsrc->isKnownSourceImage(hotbar_image);
|
|
|
|
else
|
|
|
|
use_hotbar_image = false;
|
|
|
|
}
|
|
|
|
|
2016-04-12 13:54:08 +02:00
|
|
|
// Store hotbar_selected_image in member variable, used by drawItem()
|
2014-04-05 14:12:36 +02:00
|
|
|
if (hotbar_selected_image != player->hotbar_selected_image) {
|
|
|
|
hotbar_selected_image = player->hotbar_selected_image;
|
2017-08-18 08:07:59 +02:00
|
|
|
if (!hotbar_selected_image.empty())
|
2014-04-05 14:12:36 +02:00
|
|
|
use_hotbar_selected_image = tsrc->isKnownSourceImage(hotbar_selected_image);
|
|
|
|
else
|
|
|
|
use_hotbar_selected_image = false;
|
|
|
|
}
|
|
|
|
|
2016-04-12 13:54:08 +02:00
|
|
|
// draw customized item background
|
2014-04-05 14:12:36 +02:00
|
|
|
if (use_hotbar_image) {
|
2014-05-11 13:26:23 +02:00
|
|
|
core::rect<s32> imgrect2(-m_padding/2, -m_padding/2,
|
2016-04-11 05:51:36 +02:00
|
|
|
width+m_padding/2, height+m_padding/2);
|
2014-04-05 14:12:36 +02:00
|
|
|
core::rect<s32> rect2 = imgrect2 + pos;
|
|
|
|
video::ITexture *texture = tsrc->getTexture(hotbar_image);
|
|
|
|
core::dimension2di imgsize(texture->getOriginalSize());
|
2015-03-09 14:32:11 +01:00
|
|
|
draw2DImageFilterScaled(driver, texture, rect2,
|
2014-04-05 14:12:36 +02:00
|
|
|
core::rect<s32>(core::position2d<s32>(0,0), imgsize),
|
|
|
|
NULL, hbar_colors, true);
|
|
|
|
}
|
|
|
|
|
2016-04-12 13:54:08 +02:00
|
|
|
// Draw items
|
|
|
|
core::rect<s32> imgrect(0, 0, m_hotbar_imagesize, m_hotbar_imagesize);
|
2015-01-09 18:04:25 +01:00
|
|
|
for (s32 i = inv_offset; i < itemcount && (size_t)i < mainlist->getSize(); i++) {
|
2014-04-05 14:12:36 +02:00
|
|
|
s32 fullimglen = m_hotbar_imagesize + m_padding * 2;
|
|
|
|
|
2016-04-12 13:54:08 +02:00
|
|
|
v2s32 steppos;
|
2014-04-05 14:12:36 +02:00
|
|
|
switch (direction) {
|
2015-01-09 18:04:25 +01:00
|
|
|
case HUD_DIR_RIGHT_LEFT:
|
|
|
|
steppos = v2s32(-(m_padding + (i - inv_offset) * fullimglen), m_padding);
|
|
|
|
break;
|
|
|
|
case HUD_DIR_TOP_BOTTOM:
|
|
|
|
steppos = v2s32(m_padding, m_padding + (i - inv_offset) * fullimglen);
|
|
|
|
break;
|
|
|
|
case HUD_DIR_BOTTOM_TOP:
|
|
|
|
steppos = v2s32(m_padding, -(m_padding + (i - inv_offset) * fullimglen));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
steppos = v2s32(m_padding + (i - inv_offset) * fullimglen, m_padding);
|
|
|
|
break;
|
2014-04-05 14:12:36 +02:00
|
|
|
}
|
|
|
|
|
2016-04-11 05:51:36 +02:00
|
|
|
drawItem(mainlist->getItem(i), (imgrect + pos + steppos), (i + 1) == selectitem);
|
2014-04-21 14:10:59 +02:00
|
|
|
|
|
|
|
#ifdef HAVE_TOUCHSCREENGUI
|
|
|
|
if (g_touchscreengui)
|
|
|
|
g_touchscreengui->registerHudItem(i, (imgrect + pos + steppos));
|
|
|
|
#endif
|
2014-04-05 14:12:36 +02:00
|
|
|
}
|
2013-04-14 00:20:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-09 18:04:25 +01:00
|
|
|
void Hud::drawLuaElements(const v3s16 &camera_offset)
|
|
|
|
{
|
2014-12-05 07:09:49 +01:00
|
|
|
u32 text_height = g_fontengine->getTextHeight();
|
2014-11-28 20:06:34 +01:00
|
|
|
irr::gui::IGUIFont* font = g_fontengine->getFont();
|
2014-05-25 14:34:32 +02:00
|
|
|
for (size_t i = 0; i != player->maxHudId(); i++) {
|
|
|
|
HudElement *e = player->getHud(i);
|
2013-04-14 00:20:22 +02:00
|
|
|
if (!e)
|
|
|
|
continue;
|
2015-02-08 18:45:19 +01:00
|
|
|
|
2014-04-28 23:41:27 +02:00
|
|
|
v2s32 pos(floor(e->pos.X * (float) m_screensize.X + 0.5),
|
|
|
|
floor(e->pos.Y * (float) m_screensize.Y + 0.5));
|
2013-04-14 00:20:22 +02:00
|
|
|
switch (e->type) {
|
|
|
|
case HUD_ELEM_IMAGE: {
|
2013-06-24 04:17:50 +02:00
|
|
|
video::ITexture *texture = tsrc->getTexture(e->text);
|
2013-04-14 00:20:22 +02:00
|
|
|
if (!texture)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const video::SColor color(255, 255, 255, 255);
|
|
|
|
const video::SColor colors[] = {color, color, color, color};
|
|
|
|
core::dimension2di imgsize(texture->getOriginalSize());
|
2013-09-19 20:39:19 +02:00
|
|
|
v2s32 dstsize(imgsize.Width * e->scale.X,
|
|
|
|
imgsize.Height * e->scale.Y);
|
|
|
|
if (e->scale.X < 0)
|
2014-04-05 14:12:36 +02:00
|
|
|
dstsize.X = m_screensize.X * (e->scale.X * -0.01);
|
2013-09-19 20:39:19 +02:00
|
|
|
if (e->scale.Y < 0)
|
2014-04-05 14:12:36 +02:00
|
|
|
dstsize.Y = m_screensize.Y * (e->scale.Y * -0.01);
|
2013-09-19 20:39:19 +02:00
|
|
|
v2s32 offset((e->align.X - 1.0) * dstsize.X / 2,
|
|
|
|
(e->align.Y - 1.0) * dstsize.Y / 2);
|
|
|
|
core::rect<s32> rect(0, 0, dstsize.X, dstsize.Y);
|
|
|
|
rect += pos + offset + v2s32(e->offset.X, e->offset.Y);
|
2015-03-09 14:32:11 +01:00
|
|
|
draw2DImageFilterScaled(driver, texture, rect,
|
2013-04-14 00:20:22 +02:00
|
|
|
core::rect<s32>(core::position2d<s32>(0,0), imgsize),
|
|
|
|
NULL, colors, true);
|
|
|
|
break; }
|
|
|
|
case HUD_ELEM_TEXT: {
|
|
|
|
video::SColor color(255, (e->number >> 16) & 0xFF,
|
|
|
|
(e->number >> 8) & 0xFF,
|
|
|
|
(e->number >> 0) & 0xFF);
|
|
|
|
core::rect<s32> size(0, 0, e->scale.X, text_height * e->scale.Y);
|
2017-01-31 18:05:03 +01:00
|
|
|
std::wstring text = unescape_translate(utf8_to_wide(e->text));
|
2013-04-22 11:53:55 +02:00
|
|
|
core::dimension2d<u32> textsize = font->getDimension(text.c_str());
|
|
|
|
v2s32 offset((e->align.X - 1.0) * (textsize.Width / 2),
|
|
|
|
(e->align.Y - 1.0) * (textsize.Height / 2));
|
2013-04-23 01:47:59 +02:00
|
|
|
v2s32 offs(e->offset.X, e->offset.Y);
|
|
|
|
font->draw(text.c_str(), size + pos + offset + offs, color);
|
|
|
|
break; }
|
|
|
|
case HUD_ELEM_STATBAR: {
|
|
|
|
v2s32 offs(e->offset.X, e->offset.Y);
|
2014-04-28 23:41:27 +02:00
|
|
|
drawStatbar(pos, HUD_CORNER_UPPER, e->dir, e->text, e->number, offs, e->size);
|
2013-04-14 00:20:22 +02:00
|
|
|
break; }
|
|
|
|
case HUD_ELEM_INVENTORY: {
|
|
|
|
InventoryList *inv = inventory->getList(e->text);
|
2016-04-11 05:51:36 +02:00
|
|
|
drawItems(pos, v2s32(e->offset.X, e->offset.Y), e->number, 0,
|
|
|
|
inv, e->item, e->dir);
|
2013-04-14 00:20:22 +02:00
|
|
|
break; }
|
2014-01-26 21:31:59 +01:00
|
|
|
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;
|
2017-07-02 20:29:58 +02:00
|
|
|
scene::ICameraSceneNode* camera =
|
|
|
|
RenderingEngine::get_scene_manager()->getActiveCamera();
|
2014-05-05 07:45:20 +02:00
|
|
|
w_pos -= intToFloat(camera_offset, BS);
|
2014-01-26 21:31:59 +01:00
|
|
|
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]);
|
2014-04-05 14:12:36 +02:00
|
|
|
pos.X = m_screensize.X * (0.5 * transformed_pos[0] * zDiv + 0.5);
|
|
|
|
pos.Y = m_screensize.Y * (0.5 - transformed_pos[1] * zDiv * 0.5);
|
2014-01-26 21:31:59 +01:00
|
|
|
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);
|
2017-01-31 18:05:03 +01:00
|
|
|
std::wstring text = unescape_translate(utf8_to_wide(e->name));
|
2014-01-26 21:31:59 +01:00
|
|
|
font->draw(text.c_str(), size + pos, color);
|
|
|
|
std::ostringstream os;
|
2015-07-07 05:55:07 +02:00
|
|
|
os << distance << e->text;
|
2017-01-31 18:05:03 +01:00
|
|
|
text = unescape_translate(utf8_to_wide(os.str()));
|
2014-01-26 21:31:59 +01:00
|
|
|
pos.Y += text_height;
|
|
|
|
font->draw(text.c_str(), size + pos, color);
|
|
|
|
break; }
|
2013-04-14 00:20:22 +02:00
|
|
|
default:
|
|
|
|
infostream << "Hud::drawLuaElements: ignoring drawform " << e->type <<
|
2013-08-01 01:09:57 +02:00
|
|
|
" of hud element ID " << i << " due to unrecognized type" << std::endl;
|
2013-04-14 00:20:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-28 23:41:27 +02:00
|
|
|
void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture,
|
|
|
|
s32 count, v2s32 offset, v2s32 size)
|
|
|
|
{
|
2013-04-20 06:21:32 +02:00
|
|
|
const video::SColor color(255, 255, 255, 255);
|
|
|
|
const video::SColor colors[] = {color, color, color, color};
|
2015-02-08 18:45:19 +01:00
|
|
|
|
2013-06-24 04:17:50 +02:00
|
|
|
video::ITexture *stat_texture = tsrc->getTexture(texture);
|
2013-04-14 00:20:22 +02:00
|
|
|
if (!stat_texture)
|
|
|
|
return;
|
2015-02-08 18:45:19 +01:00
|
|
|
|
2013-04-20 06:21:32 +02:00
|
|
|
core::dimension2di srcd(stat_texture->getOriginalSize());
|
2014-04-28 23:41:27 +02:00
|
|
|
core::dimension2di dstd;
|
|
|
|
if (size == v2s32()) {
|
|
|
|
dstd = srcd;
|
|
|
|
} else {
|
2017-06-26 20:11:17 +02:00
|
|
|
float size_factor = m_hud_scaling * RenderingEngine::getDisplayDensity();
|
2015-02-08 18:45:19 +01:00
|
|
|
dstd.Height = size.Y * size_factor;
|
|
|
|
dstd.Width = size.X * size_factor;
|
|
|
|
offset.X *= size_factor;
|
|
|
|
offset.Y *= size_factor;
|
2014-04-28 23:41:27 +02:00
|
|
|
}
|
2013-04-14 00:20:22 +02:00
|
|
|
|
2013-04-20 06:21:32 +02:00
|
|
|
v2s32 p = pos;
|
|
|
|
if (corner & HUD_CORNER_LOWER)
|
2014-04-28 23:41:27 +02:00
|
|
|
p -= dstd.Height;
|
2013-04-20 06:21:32 +02:00
|
|
|
|
2013-04-23 01:47:59 +02:00
|
|
|
p += offset;
|
|
|
|
|
2013-04-20 06:21:32 +02:00
|
|
|
v2s32 steppos;
|
2017-08-27 19:06:40 +02:00
|
|
|
core::rect<s32> srchalfrect, dsthalfrect;
|
2013-04-20 06:21:32 +02:00
|
|
|
switch (drawdir) {
|
|
|
|
case HUD_DIR_RIGHT_LEFT:
|
|
|
|
steppos = v2s32(-1, 0);
|
2017-08-27 19:06:40 +02:00
|
|
|
srchalfrect = core::rect<s32>(srcd.Width / 2, 0, srcd.Width, srcd.Height);
|
|
|
|
dsthalfrect = core::rect<s32>(dstd.Width / 2, 0, dstd.Width, dstd.Height);
|
2013-04-20 06:21:32 +02:00
|
|
|
break;
|
|
|
|
case HUD_DIR_TOP_BOTTOM:
|
|
|
|
steppos = v2s32(0, 1);
|
2017-08-27 19:06:40 +02:00
|
|
|
srchalfrect = core::rect<s32>(0, 0, srcd.Width, srcd.Height / 2);
|
|
|
|
dsthalfrect = core::rect<s32>(0, 0, dstd.Width, dstd.Height / 2);
|
2013-04-20 06:21:32 +02:00
|
|
|
break;
|
|
|
|
case HUD_DIR_BOTTOM_TOP:
|
|
|
|
steppos = v2s32(0, -1);
|
2017-08-27 19:06:40 +02:00
|
|
|
srchalfrect = core::rect<s32>(0, srcd.Height / 2, srcd.Width, srcd.Height);
|
|
|
|
dsthalfrect = core::rect<s32>(0, dstd.Height / 2, dstd.Width, dstd.Height);
|
2013-04-20 06:21:32 +02:00
|
|
|
break;
|
|
|
|
default:
|
2014-02-13 20:17:42 +01:00
|
|
|
steppos = v2s32(1, 0);
|
2017-08-27 19:06:40 +02:00
|
|
|
srchalfrect = core::rect<s32>(0, 0, srcd.Width / 2, srcd.Height);
|
|
|
|
dsthalfrect = core::rect<s32>(0, 0, dstd.Width / 2, dstd.Height);
|
2013-04-20 06:21:32 +02:00
|
|
|
}
|
2014-04-28 23:41:27 +02:00
|
|
|
steppos.X *= dstd.Width;
|
|
|
|
steppos.Y *= dstd.Height;
|
2015-02-08 18:45:19 +01:00
|
|
|
|
2017-08-27 19:06:40 +02:00
|
|
|
for (s32 i = 0; i < count / 2; i++) {
|
2013-04-20 06:21:32 +02:00
|
|
|
core::rect<s32> srcrect(0, 0, srcd.Width, srcd.Height);
|
2014-04-28 23:41:27 +02:00
|
|
|
core::rect<s32> dstrect(0,0, dstd.Width, dstd.Height);
|
2013-04-20 06:21:32 +02:00
|
|
|
|
|
|
|
dstrect += p;
|
2015-03-09 14:32:11 +01:00
|
|
|
draw2DImageFilterScaled(driver, stat_texture, dstrect, srcrect, NULL, colors, true);
|
2013-04-20 06:21:32 +02:00
|
|
|
p += steppos;
|
2013-04-14 00:20:22 +02:00
|
|
|
}
|
2015-02-08 18:45:19 +01:00
|
|
|
|
2017-08-27 19:06:40 +02:00
|
|
|
if (count % 2 == 1) {
|
|
|
|
dsthalfrect += p;
|
|
|
|
draw2DImageFilterScaled(driver, stat_texture, dsthalfrect, srchalfrect, NULL, colors, true);
|
2013-04-14 00:20:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-28 23:41:27 +02:00
|
|
|
void Hud::drawHotbar(u16 playeritem) {
|
2014-04-05 14:12:36 +02:00
|
|
|
|
|
|
|
v2s32 centerlowerpos(m_displaycenter.X, m_screensize.Y);
|
|
|
|
|
2013-04-14 00:20:22 +02:00
|
|
|
InventoryList *mainlist = inventory->getList("main");
|
|
|
|
if (mainlist == NULL) {
|
2014-02-13 20:17:42 +01:00
|
|
|
//silently ignore this we may not be initialized completely
|
2013-04-14 00:20:22 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-02-08 18:45:19 +01:00
|
|
|
|
2013-05-04 02:08:52 +02:00
|
|
|
s32 hotbar_itemcount = player->hud_hotbar_itemcount;
|
2014-04-05 14:12:36 +02:00
|
|
|
s32 width = hotbar_itemcount * (m_hotbar_imagesize + m_padding * 2);
|
|
|
|
v2s32 pos = centerlowerpos - v2s32(width / 2, m_hotbar_imagesize + m_padding * 3);
|
|
|
|
|
2017-06-26 20:11:17 +02:00
|
|
|
const v2u32 &window_size = RenderingEngine::get_instance()->getWindowSize();
|
|
|
|
if ( (float) width / (float) window_size.X <=
|
2014-04-05 14:12:36 +02:00
|
|
|
g_settings->getFloat("hud_hotbar_max_width")) {
|
|
|
|
if (player->hud_flags & HUD_FLAG_HOTBAR_VISIBLE) {
|
2016-04-11 05:51:36 +02:00
|
|
|
drawItems(pos, v2s32(0, 0), hotbar_itemcount, 0, mainlist, playeritem + 1, 0);
|
2014-04-05 14:12:36 +02:00
|
|
|
}
|
2016-04-11 05:51:36 +02:00
|
|
|
} else {
|
2014-04-05 14:12:36 +02:00
|
|
|
pos.X += width/4;
|
|
|
|
|
|
|
|
v2s32 secondpos = pos;
|
|
|
|
pos = pos - v2s32(0, m_hotbar_imagesize + m_padding);
|
|
|
|
|
|
|
|
if (player->hud_flags & HUD_FLAG_HOTBAR_VISIBLE) {
|
2016-04-11 05:51:36 +02:00
|
|
|
drawItems(pos, v2s32(0, 0), hotbar_itemcount / 2, 0,
|
|
|
|
mainlist, playeritem + 1, 0);
|
|
|
|
drawItems(secondpos, v2s32(0, 0), hotbar_itemcount,
|
|
|
|
hotbar_itemcount / 2, mainlist, playeritem + 1, 0);
|
2014-04-05 14:12:36 +02:00
|
|
|
}
|
|
|
|
}
|
2014-05-11 00:35:31 +02:00
|
|
|
|
|
|
|
//////////////////////////// compatibility code to be removed //////////////
|
|
|
|
// this is ugly as hell but there's no other way to keep compatibility to
|
|
|
|
// old servers
|
2015-02-08 18:45:19 +01:00
|
|
|
if ((player->hud_flags & HUD_FLAG_HEALTHBAR_VISIBLE)) {
|
|
|
|
drawStatbar(v2s32(floor(0.5 * (float)m_screensize.X + 0.5),
|
|
|
|
floor(1 * (float) m_screensize.Y + 0.5)),
|
|
|
|
HUD_CORNER_UPPER, 0, "heart.png",
|
|
|
|
player->hp, v2s32((-10*24)-25,-(48+24+10)), v2s32(24,24));
|
|
|
|
}
|
2014-05-11 00:35:31 +02:00
|
|
|
|
|
|
|
if ((player->hud_flags & HUD_FLAG_BREATHBAR_VISIBLE) &&
|
2015-02-08 18:45:19 +01:00
|
|
|
(player->getBreath() < 11)) {
|
|
|
|
drawStatbar(v2s32(floor(0.5 * (float)m_screensize.X + 0.5),
|
|
|
|
floor(1 * (float) m_screensize.Y + 0.5)),
|
|
|
|
HUD_CORNER_UPPER, 0, "bubble.png",
|
|
|
|
player->getBreath(), v2s32(25,-(48+24+10)), v2s32(24,24));
|
|
|
|
}
|
2014-05-11 00:35:31 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
2013-04-14 00:20:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-11 05:51:36 +02:00
|
|
|
void Hud::drawCrosshair()
|
|
|
|
{
|
2013-04-26 02:56:12 +02:00
|
|
|
if (use_crosshair_image) {
|
2013-06-24 04:17:50 +02:00
|
|
|
video::ITexture *crosshair = tsrc->getTexture("crosshair.png");
|
2013-04-21 03:39:31 +02:00
|
|
|
v2u32 size = crosshair->getOriginalSize();
|
2014-04-05 14:12:36 +02:00
|
|
|
v2s32 lsize = v2s32(m_displaycenter.X - (size.X / 2),
|
|
|
|
m_displaycenter.Y - (size.Y / 2));
|
2013-04-21 03:39:31 +02:00
|
|
|
driver->draw2DImage(crosshair, lsize,
|
|
|
|
core::rect<s32>(0, 0, size.X, size.Y),
|
|
|
|
0, crosshair_argb, true);
|
|
|
|
} else {
|
2014-04-05 14:12:36 +02:00
|
|
|
driver->draw2DLine(m_displaycenter - v2s32(10, 0),
|
|
|
|
m_displaycenter + v2s32(10, 0), crosshair_argb);
|
|
|
|
driver->draw2DLine(m_displaycenter - v2s32(0, 10),
|
|
|
|
m_displaycenter + v2s32(0, 10), crosshair_argb);
|
2013-04-26 01:27:22 +02:00
|
|
|
}
|
2013-04-14 00:20:22 +02:00
|
|
|
}
|
|
|
|
|
2016-02-07 04:08:43 +01:00
|
|
|
void Hud::setSelectionPos(const v3f &pos, const v3s16 &camera_offset)
|
|
|
|
{
|
|
|
|
m_camera_offset = camera_offset;
|
|
|
|
m_selection_pos = pos;
|
|
|
|
m_selection_pos_with_offset = pos - intToFloat(camera_offset, BS);
|
|
|
|
}
|
2015-01-09 18:04:25 +01:00
|
|
|
|
2016-02-07 04:08:43 +01:00
|
|
|
void Hud::drawSelectionMesh()
|
2015-01-09 18:04:25 +01:00
|
|
|
{
|
2017-05-12 00:18:36 +02:00
|
|
|
if (m_mode == HIGHLIGHT_BOX) {
|
2016-02-07 04:08:43 +01:00
|
|
|
// Draw 3D selection boxes
|
|
|
|
video::SMaterial oldmaterial = driver->getMaterial2D();
|
|
|
|
driver->setMaterial(m_selection_material);
|
|
|
|
for (std::vector<aabb3f>::const_iterator
|
|
|
|
i = m_selection_boxes.begin();
|
|
|
|
i != m_selection_boxes.end(); ++i) {
|
|
|
|
aabb3f box = aabb3f(
|
|
|
|
i->MinEdge + m_selection_pos_with_offset,
|
|
|
|
i->MaxEdge + m_selection_pos_with_offset);
|
2015-01-09 18:04:25 +01:00
|
|
|
|
2016-02-07 04:08:43 +01:00
|
|
|
u32 r = (selectionbox_argb.getRed() *
|
2015-01-09 18:04:25 +01:00
|
|
|
m_selection_mesh_color.getRed() / 255);
|
2016-02-07 04:08:43 +01:00
|
|
|
u32 g = (selectionbox_argb.getGreen() *
|
|
|
|
m_selection_mesh_color.getGreen() / 255);
|
|
|
|
u32 b = (selectionbox_argb.getBlue() *
|
|
|
|
m_selection_mesh_color.getBlue() / 255);
|
|
|
|
driver->draw3DBox(box, video::SColor(255, r, g, b));
|
|
|
|
}
|
|
|
|
driver->setMaterial(oldmaterial);
|
2017-05-12 00:18:36 +02:00
|
|
|
} else if (m_mode == HIGHLIGHT_HALO && m_selection_mesh) {
|
2016-02-07 04:08:43 +01:00
|
|
|
// Draw selection mesh
|
|
|
|
video::SMaterial oldmaterial = driver->getMaterial2D();
|
|
|
|
driver->setMaterial(m_selection_material);
|
|
|
|
setMeshColor(m_selection_mesh, m_selection_mesh_color);
|
2016-02-21 06:50:41 +01:00
|
|
|
video::SColor face_color(0,
|
|
|
|
MYMIN(255, m_selection_mesh_color.getRed() * 1.5),
|
|
|
|
MYMIN(255, m_selection_mesh_color.getGreen() * 1.5),
|
|
|
|
MYMIN(255, m_selection_mesh_color.getBlue() * 1.5));
|
|
|
|
setMeshColorByNormal(m_selection_mesh, m_selected_face_normal,
|
|
|
|
face_color);
|
2016-02-07 04:08:43 +01:00
|
|
|
scene::IMesh* mesh = cloneMesh(m_selection_mesh);
|
|
|
|
translateMesh(mesh, m_selection_pos_with_offset);
|
|
|
|
u32 mc = m_selection_mesh->getMeshBufferCount();
|
|
|
|
for (u32 i = 0; i < mc; i++) {
|
|
|
|
scene::IMeshBuffer *buf = mesh->getMeshBuffer(i);
|
|
|
|
driver->drawMeshBuffer(buf);
|
|
|
|
}
|
|
|
|
mesh->drop();
|
|
|
|
driver->setMaterial(oldmaterial);
|
2013-04-14 00:20:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-07 04:08:43 +01:00
|
|
|
void Hud::updateSelectionMesh(const v3s16 &camera_offset)
|
|
|
|
{
|
|
|
|
m_camera_offset = camera_offset;
|
2017-05-12 00:18:36 +02:00
|
|
|
if (m_mode != HIGHLIGHT_HALO)
|
2016-02-07 04:08:43 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (m_selection_mesh) {
|
|
|
|
m_selection_mesh->drop();
|
|
|
|
m_selection_mesh = NULL;
|
|
|
|
}
|
|
|
|
|
2017-08-18 08:07:59 +02:00
|
|
|
if (m_selection_boxes.empty()) {
|
2016-02-07 04:08:43 +01:00
|
|
|
// No pointed object
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// New pointed object, create new mesh.
|
|
|
|
|
|
|
|
// Texture UV coordinates for selection boxes
|
|
|
|
static f32 texture_uv[24] = {
|
|
|
|
0,0,1,1,
|
|
|
|
0,0,1,1,
|
|
|
|
0,0,1,1,
|
|
|
|
0,0,1,1,
|
|
|
|
0,0,1,1,
|
|
|
|
0,0,1,1
|
|
|
|
};
|
|
|
|
|
2016-02-11 04:57:01 +01:00
|
|
|
// Use single halo box instead of multiple overlapping boxes.
|
|
|
|
// Temporary solution - problem can be solved with multiple
|
|
|
|
// rendering targets, or some method to remove inner surfaces.
|
|
|
|
// Thats because of halo transparency.
|
|
|
|
|
|
|
|
aabb3f halo_box(100.0, 100.0, 100.0, -100.0, -100.0, -100.0);
|
|
|
|
m_halo_boxes.clear();
|
|
|
|
|
2017-08-18 08:07:59 +02:00
|
|
|
for (const auto &selection_box : m_selection_boxes) {
|
|
|
|
halo_box.addInternalBox(selection_box);
|
2016-02-11 04:57:01 +01:00
|
|
|
}
|
2016-02-07 04:08:43 +01:00
|
|
|
|
2016-02-11 04:57:01 +01:00
|
|
|
m_halo_boxes.push_back(halo_box);
|
|
|
|
m_selection_mesh = convertNodeboxesToMesh(
|
|
|
|
m_halo_boxes, texture_uv, 0.5);
|
2016-02-07 04:08:43 +01:00
|
|
|
}
|
2013-04-14 00:20:22 +02:00
|
|
|
|
|
|
|
void Hud::resizeHotbar() {
|
2017-06-26 20:11:17 +02:00
|
|
|
const v2u32 &window_size = RenderingEngine::get_instance()->getWindowSize();
|
|
|
|
|
|
|
|
if (m_screensize != window_size) {
|
|
|
|
m_hotbar_imagesize = floor(HOTBAR_IMAGE_SIZE *
|
|
|
|
RenderingEngine::getDisplayDensity() + 0.5);
|
2016-04-11 05:51:36 +02:00
|
|
|
m_hotbar_imagesize *= m_hud_scaling;
|
2014-04-05 14:12:36 +02:00
|
|
|
m_padding = m_hotbar_imagesize / 12;
|
2017-06-26 20:11:17 +02:00
|
|
|
m_screensize = window_size;
|
2014-04-05 14:12:36 +02:00
|
|
|
m_displaycenter = v2s32(m_screensize.X/2,m_screensize.Y/2);
|
|
|
|
}
|
2013-04-14 00:20:22 +02:00
|
|
|
}
|
2013-08-11 04:09:45 +02:00
|
|
|
|
2016-02-07 20:27:50 +01:00
|
|
|
struct MeshTimeInfo {
|
2017-05-26 14:03:36 +02:00
|
|
|
u64 time;
|
2016-02-07 20:27:50 +01:00
|
|
|
scene::IMesh *mesh;
|
|
|
|
};
|
|
|
|
|
2013-08-11 04:09:45 +02:00
|
|
|
void drawItemStack(video::IVideoDriver *driver,
|
|
|
|
gui::IGUIFont *font,
|
|
|
|
const ItemStack &item,
|
|
|
|
const core::rect<s32> &rect,
|
|
|
|
const core::rect<s32> *clip,
|
2017-01-09 20:39:22 +01:00
|
|
|
Client *client,
|
2016-02-07 20:27:50 +01:00
|
|
|
ItemRotationKind rotation_kind)
|
2013-08-11 04:09:45 +02:00
|
|
|
{
|
2016-02-07 20:27:50 +01:00
|
|
|
static MeshTimeInfo rotation_time_infos[IT_ROT_NONE];
|
2017-06-11 13:58:43 +02:00
|
|
|
static thread_local bool enable_animations =
|
2016-01-24 14:19:17 +01:00
|
|
|
g_settings->getBool("inventory_items_animations");
|
|
|
|
|
|
|
|
if (item.empty()) {
|
2016-02-07 20:27:50 +01:00
|
|
|
if (rotation_kind < IT_ROT_NONE) {
|
|
|
|
rotation_time_infos[rotation_kind].mesh = NULL;
|
2016-01-24 14:19:17 +01:00
|
|
|
}
|
2013-08-11 04:09:45 +02:00
|
|
|
return;
|
2016-01-24 14:19:17 +01:00
|
|
|
}
|
2015-02-08 18:45:19 +01:00
|
|
|
|
2017-01-09 20:39:22 +01:00
|
|
|
const ItemDefinition &def = item.getDefinition(client->idef());
|
2017-03-10 18:25:58 +01:00
|
|
|
ItemMesh *imesh = client->idef()->getWieldMesh(def.name, client);
|
2016-01-24 14:19:17 +01:00
|
|
|
|
2017-03-10 18:25:58 +01:00
|
|
|
if (imesh && imesh->mesh) {
|
|
|
|
scene::IMesh *mesh = imesh->mesh;
|
2016-01-24 14:19:17 +01:00
|
|
|
driver->clearZBuffer();
|
|
|
|
s32 delta = 0;
|
2016-02-07 20:27:50 +01:00
|
|
|
if (rotation_kind < IT_ROT_NONE) {
|
|
|
|
MeshTimeInfo &ti = rotation_time_infos[rotation_kind];
|
|
|
|
if (mesh != ti.mesh) {
|
|
|
|
ti.mesh = mesh;
|
2016-03-06 20:31:16 +01:00
|
|
|
ti.time = porting::getTimeMs();
|
2016-01-24 14:19:17 +01:00
|
|
|
} else {
|
2016-03-06 20:31:16 +01:00
|
|
|
delta = porting::getDeltaMs(ti.time, porting::getTimeMs()) % 100000;
|
2016-01-24 14:19:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
core::rect<s32> oldViewPort = driver->getViewPort();
|
|
|
|
core::matrix4 oldProjMat = driver->getTransform(video::ETS_PROJECTION);
|
|
|
|
core::matrix4 oldViewMat = driver->getTransform(video::ETS_VIEW);
|
|
|
|
core::matrix4 ProjMatrix;
|
|
|
|
ProjMatrix.buildProjectionMatrixOrthoLH(2, 2, -1, 100);
|
|
|
|
driver->setTransform(video::ETS_PROJECTION, ProjMatrix);
|
|
|
|
driver->setTransform(video::ETS_VIEW, ProjMatrix);
|
|
|
|
core::matrix4 matrix;
|
|
|
|
matrix.makeIdentity();
|
|
|
|
|
|
|
|
if (enable_animations) {
|
2017-03-10 18:25:58 +01:00
|
|
|
float timer_f = (float) delta / 5000.0;
|
2016-01-24 14:19:17 +01:00
|
|
|
matrix.setRotationDegrees(core::vector3df(0, 360 * timer_f, 0));
|
|
|
|
}
|
2013-08-11 04:09:45 +02:00
|
|
|
|
2016-01-24 14:19:17 +01:00
|
|
|
driver->setTransform(video::ETS_WORLD, matrix);
|
|
|
|
driver->setViewPort(rect);
|
|
|
|
|
2017-03-10 18:25:58 +01:00
|
|
|
video::SColor basecolor =
|
|
|
|
client->idef()->getItemstackColor(item, client);
|
|
|
|
|
2016-01-24 14:19:17 +01:00
|
|
|
u32 mc = mesh->getMeshBufferCount();
|
|
|
|
for (u32 j = 0; j < mc; ++j) {
|
|
|
|
scene::IMeshBuffer *buf = mesh->getMeshBuffer(j);
|
2017-03-10 18:25:58 +01:00
|
|
|
// we can modify vertices relatively fast,
|
|
|
|
// because these meshes are not buffered.
|
|
|
|
assert(buf->getHardwareMappingHint_Vertex() == scene::EHM_NEVER);
|
|
|
|
video::SColor c = basecolor;
|
|
|
|
if (imesh->buffer_colors.size() > j) {
|
2017-04-21 15:34:59 +02:00
|
|
|
ItemPartColor *p = &imesh->buffer_colors[j];
|
|
|
|
if (p->override_base)
|
|
|
|
c = p->color;
|
2017-03-10 18:25:58 +01:00
|
|
|
}
|
2017-06-01 23:18:55 +02:00
|
|
|
if (imesh->needs_shading)
|
|
|
|
colorizeMeshBuffer(buf, &c);
|
|
|
|
else
|
|
|
|
setMeshBufferColor(buf, c);
|
2016-01-24 14:19:17 +01:00
|
|
|
video::SMaterial &material = buf->getMaterial();
|
|
|
|
material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
|
|
|
|
material.Lighting = false;
|
|
|
|
driver->setMaterial(material);
|
|
|
|
driver->drawMeshBuffer(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
driver->setTransform(video::ETS_VIEW, oldViewMat);
|
|
|
|
driver->setTransform(video::ETS_PROJECTION, oldProjMat);
|
|
|
|
driver->setViewPort(oldViewPort);
|
2013-08-11 04:09:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(def.type == ITEM_TOOL && item.wear != 0)
|
|
|
|
{
|
|
|
|
// Draw a progressbar
|
|
|
|
float barheight = rect.getHeight()/16;
|
|
|
|
float barpad_x = rect.getWidth()/16;
|
|
|
|
float barpad_y = rect.getHeight()/16;
|
|
|
|
core::rect<s32> progressrect(
|
|
|
|
rect.UpperLeftCorner.X + barpad_x,
|
|
|
|
rect.LowerRightCorner.Y - barpad_y - barheight,
|
|
|
|
rect.LowerRightCorner.X - barpad_x,
|
|
|
|
rect.LowerRightCorner.Y - barpad_y);
|
|
|
|
|
|
|
|
// Shrink progressrect by amount of tool damage
|
|
|
|
float wear = item.wear / 65535.0;
|
|
|
|
int progressmid =
|
|
|
|
wear * progressrect.UpperLeftCorner.X +
|
|
|
|
(1-wear) * progressrect.LowerRightCorner.X;
|
|
|
|
|
|
|
|
// Compute progressbar color
|
|
|
|
// wear = 0.0: green
|
|
|
|
// wear = 0.5: yellow
|
|
|
|
// wear = 1.0: red
|
|
|
|
video::SColor color(255,255,255,255);
|
|
|
|
int wear_i = MYMIN(floor(wear * 600), 511);
|
|
|
|
wear_i = MYMIN(wear_i + 10, 511);
|
|
|
|
if(wear_i <= 255)
|
|
|
|
color.set(255, wear_i, 255, 0);
|
|
|
|
else
|
|
|
|
color.set(255, 255, 511-wear_i, 0);
|
|
|
|
|
|
|
|
core::rect<s32> progressrect2 = progressrect;
|
|
|
|
progressrect2.LowerRightCorner.X = progressmid;
|
|
|
|
driver->draw2DRectangle(color, progressrect2, clip);
|
|
|
|
|
|
|
|
color = video::SColor(255,0,0,0);
|
|
|
|
progressrect2 = progressrect;
|
|
|
|
progressrect2.UpperLeftCorner.X = progressmid;
|
|
|
|
driver->draw2DRectangle(color, progressrect2, clip);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(font != NULL && item.count >= 2)
|
|
|
|
{
|
|
|
|
// Get the item count as a string
|
|
|
|
std::string text = itos(item.count);
|
2015-07-07 05:55:07 +02:00
|
|
|
v2u32 dim = font->getDimension(utf8_to_wide(text).c_str());
|
2013-08-11 04:09:45 +02:00
|
|
|
v2s32 sdim(dim.X,dim.Y);
|
|
|
|
|
|
|
|
core::rect<s32> rect2(
|
|
|
|
/*rect.UpperLeftCorner,
|
|
|
|
core::dimension2d<u32>(rect.getWidth(), 15)*/
|
|
|
|
rect.LowerRightCorner - sdim,
|
|
|
|
sdim
|
|
|
|
);
|
|
|
|
|
|
|
|
video::SColor bgcolor(128,0,0,0);
|
|
|
|
driver->draw2DRectangle(bgcolor, rect2, clip);
|
|
|
|
|
|
|
|
video::SColor color(255,255,255,255);
|
|
|
|
font->draw(text.c_str(), rect2, color, false, false, clip);
|
|
|
|
}
|
|
|
|
}
|