Hud: Modify Y-positioning of health/breath starbars to prevent overlapping with Hotbar
This commit is contained in:
parent
a0535d286b
commit
15c037614f
@ -7,7 +7,7 @@ local health_bar_definition =
|
|||||||
number = 20,
|
number = 20,
|
||||||
direction = 0,
|
direction = 0,
|
||||||
size = { x=24, y=24 },
|
size = { x=24, y=24 },
|
||||||
offset = { x=(-10*24)-25, y=-(48+24+10)},
|
offset = { x=(-10*24)-25, y=-(48+24+16)},
|
||||||
}
|
}
|
||||||
|
|
||||||
local breath_bar_definition =
|
local breath_bar_definition =
|
||||||
@ -18,7 +18,7 @@ local breath_bar_definition =
|
|||||||
number = 20,
|
number = 20,
|
||||||
direction = 0,
|
direction = 0,
|
||||||
size = { x=24, y=24 },
|
size = { x=24, y=24 },
|
||||||
offset = {x=25,y=-(48+24+10)},
|
offset = {x=25,y=-(48+24+16)},
|
||||||
}
|
}
|
||||||
|
|
||||||
local hud_ids = {}
|
local hud_ids = {}
|
||||||
|
60
src/hud.cpp
60
src/hud.cpp
@ -58,22 +58,22 @@ Hud::Hud(video::IVideoDriver *driver, scene::ISceneManager* smgr,
|
|||||||
for (unsigned int i=0; i < 4; i++ ){
|
for (unsigned int i=0; i < 4; i++ ){
|
||||||
hbar_colors[i] = hbar_color;
|
hbar_colors[i] = hbar_color;
|
||||||
}
|
}
|
||||||
|
|
||||||
tsrc = gamedef->getTextureSource();
|
tsrc = gamedef->getTextureSource();
|
||||||
|
|
||||||
v3f crosshair_color = g_settings->getV3F("crosshair_color");
|
v3f crosshair_color = g_settings->getV3F("crosshair_color");
|
||||||
u32 cross_r = rangelim(myround(crosshair_color.X), 0, 255);
|
u32 cross_r = rangelim(myround(crosshair_color.X), 0, 255);
|
||||||
u32 cross_g = rangelim(myround(crosshair_color.Y), 0, 255);
|
u32 cross_g = rangelim(myround(crosshair_color.Y), 0, 255);
|
||||||
u32 cross_b = rangelim(myround(crosshair_color.Z), 0, 255);
|
u32 cross_b = rangelim(myround(crosshair_color.Z), 0, 255);
|
||||||
u32 cross_a = rangelim(g_settings->getS32("crosshair_alpha"), 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);
|
crosshair_argb = video::SColor(cross_a, cross_r, cross_g, cross_b);
|
||||||
|
|
||||||
v3f selectionbox_color = g_settings->getV3F("selectionbox_color");
|
v3f selectionbox_color = g_settings->getV3F("selectionbox_color");
|
||||||
u32 sbox_r = rangelim(myround(selectionbox_color.X), 0, 255);
|
u32 sbox_r = rangelim(myround(selectionbox_color.X), 0, 255);
|
||||||
u32 sbox_g = rangelim(myround(selectionbox_color.Y), 0, 255);
|
u32 sbox_g = rangelim(myround(selectionbox_color.Y), 0, 255);
|
||||||
u32 sbox_b = rangelim(myround(selectionbox_color.Z), 0, 255);
|
u32 sbox_b = rangelim(myround(selectionbox_color.Z), 0, 255);
|
||||||
selectionbox_argb = video::SColor(255, sbox_r, sbox_g, sbox_b);
|
selectionbox_argb = video::SColor(255, sbox_r, sbox_g, sbox_b);
|
||||||
|
|
||||||
use_crosshair_image = tsrc->isKnownSourceImage("crosshair.png");
|
use_crosshair_image = tsrc->isKnownSourceImage("crosshair.png");
|
||||||
|
|
||||||
hotbar_image = "";
|
hotbar_image = "";
|
||||||
@ -244,7 +244,7 @@ void Hud::drawLuaElements(v3s16 camera_offset) {
|
|||||||
HudElement *e = player->getHud(i);
|
HudElement *e = player->getHud(i);
|
||||||
if (!e)
|
if (!e)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
v2s32 pos(floor(e->pos.X * (float) m_screensize.X + 0.5),
|
v2s32 pos(floor(e->pos.X * (float) m_screensize.X + 0.5),
|
||||||
floor(e->pos.Y * (float) m_screensize.Y + 0.5));
|
floor(e->pos.Y * (float) m_screensize.Y + 0.5));
|
||||||
switch (e->type) {
|
switch (e->type) {
|
||||||
@ -331,26 +331,22 @@ void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture,
|
|||||||
{
|
{
|
||||||
const video::SColor color(255, 255, 255, 255);
|
const video::SColor color(255, 255, 255, 255);
|
||||||
const video::SColor colors[] = {color, color, color, color};
|
const video::SColor colors[] = {color, color, color, color};
|
||||||
|
|
||||||
video::ITexture *stat_texture = tsrc->getTexture(texture);
|
video::ITexture *stat_texture = tsrc->getTexture(texture);
|
||||||
if (!stat_texture)
|
if (!stat_texture)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
core::dimension2di srcd(stat_texture->getOriginalSize());
|
core::dimension2di srcd(stat_texture->getOriginalSize());
|
||||||
core::dimension2di dstd;
|
core::dimension2di dstd;
|
||||||
if (size == v2s32()) {
|
if (size == v2s32()) {
|
||||||
dstd = srcd;
|
dstd = srcd;
|
||||||
} else {
|
} else {
|
||||||
dstd.Height = size.Y * g_settings->getFloat("hud_scaling") *
|
double size_factor = g_settings->getFloat("hud_scaling") *
|
||||||
porting::getDisplayDensity();
|
|
||||||
dstd.Width = size.X * g_settings->getFloat("hud_scaling") *
|
|
||||||
porting::getDisplayDensity();
|
|
||||||
|
|
||||||
offset.X *= g_settings->getFloat("hud_scaling") *
|
|
||||||
porting::getDisplayDensity();
|
|
||||||
|
|
||||||
offset.Y *= g_settings->getFloat("hud_scaling") *
|
|
||||||
porting::getDisplayDensity();
|
porting::getDisplayDensity();
|
||||||
|
dstd.Height = size.Y * size_factor;
|
||||||
|
dstd.Width = size.X * size_factor;
|
||||||
|
offset.X *= size_factor;
|
||||||
|
offset.Y *= size_factor;
|
||||||
}
|
}
|
||||||
|
|
||||||
v2s32 p = pos;
|
v2s32 p = pos;
|
||||||
@ -375,7 +371,7 @@ void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture,
|
|||||||
}
|
}
|
||||||
steppos.X *= dstd.Width;
|
steppos.X *= dstd.Width;
|
||||||
steppos.Y *= dstd.Height;
|
steppos.Y *= dstd.Height;
|
||||||
|
|
||||||
for (s32 i = 0; i < count / 2; i++)
|
for (s32 i = 0; i < count / 2; i++)
|
||||||
{
|
{
|
||||||
core::rect<s32> srcrect(0, 0, srcd.Width, srcd.Height);
|
core::rect<s32> srcrect(0, 0, srcd.Width, srcd.Height);
|
||||||
@ -385,7 +381,7 @@ void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture,
|
|||||||
driver->draw2DImage(stat_texture, dstrect, srcrect, NULL, colors, true);
|
driver->draw2DImage(stat_texture, dstrect, srcrect, NULL, colors, true);
|
||||||
p += steppos;
|
p += steppos;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count % 2 == 1)
|
if (count % 2 == 1)
|
||||||
{
|
{
|
||||||
core::rect<s32> srcrect(0, 0, srcd.Width / 2, srcd.Height);
|
core::rect<s32> srcrect(0, 0, srcd.Width / 2, srcd.Height);
|
||||||
@ -406,7 +402,7 @@ void Hud::drawHotbar(u16 playeritem) {
|
|||||||
//silently ignore this we may not be initialized completely
|
//silently ignore this we may not be initialized completely
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 hotbar_itemcount = player->hud_hotbar_itemcount;
|
s32 hotbar_itemcount = player->hud_hotbar_itemcount;
|
||||||
s32 width = hotbar_itemcount * (m_hotbar_imagesize + m_padding * 2);
|
s32 width = hotbar_itemcount * (m_hotbar_imagesize + m_padding * 2);
|
||||||
v2s32 pos = centerlowerpos - v2s32(width / 2, m_hotbar_imagesize + m_padding * 3);
|
v2s32 pos = centerlowerpos - v2s32(width / 2, m_hotbar_imagesize + m_padding * 3);
|
||||||
@ -432,24 +428,26 @@ void Hud::drawHotbar(u16 playeritem) {
|
|||||||
//////////////////////////// compatibility code to be removed //////////////
|
//////////////////////////// compatibility code to be removed //////////////
|
||||||
// this is ugly as hell but there's no other way to keep compatibility to
|
// this is ugly as hell but there's no other way to keep compatibility to
|
||||||
// old servers
|
// old servers
|
||||||
if ( player->hud_flags & HUD_FLAG_HEALTHBAR_VISIBLE)
|
if ((player->hud_flags & HUD_FLAG_HEALTHBAR_VISIBLE)) {
|
||||||
drawStatbar(v2s32(floor(0.5 * (float) m_screensize.X + 0.5),
|
drawStatbar(v2s32(floor(0.5 * (float)m_screensize.X + 0.5),
|
||||||
floor(1 * (float) m_screensize.Y + 0.5)),
|
floor(1 * (float) m_screensize.Y + 0.5)),
|
||||||
HUD_CORNER_UPPER, 0, "heart.png",
|
HUD_CORNER_UPPER, 0, "heart.png",
|
||||||
player->hp, v2s32((-10*24)-25,-(48+24+10)), v2s32(24,24));
|
player->hp, v2s32((-10*24)-25,-(48+24+10)), v2s32(24,24));
|
||||||
|
}
|
||||||
|
|
||||||
if ((player->hud_flags & HUD_FLAG_BREATHBAR_VISIBLE) &&
|
if ((player->hud_flags & HUD_FLAG_BREATHBAR_VISIBLE) &&
|
||||||
(player->getBreath() < 11))
|
(player->getBreath() < 11)) {
|
||||||
drawStatbar(v2s32(floor(0.5 * (float) m_screensize.X + 0.5),
|
drawStatbar(v2s32(floor(0.5 * (float)m_screensize.X + 0.5),
|
||||||
floor(1 * (float) m_screensize.Y + 0.5)),
|
floor(1 * (float) m_screensize.Y + 0.5)),
|
||||||
HUD_CORNER_UPPER, 0, "heart.png",
|
HUD_CORNER_UPPER, 0, "bubble.png",
|
||||||
player->getBreath(), v2s32(25,-(48+24+10)), v2s32(24,24));
|
player->getBreath(), v2s32(25,-(48+24+10)), v2s32(24,24));
|
||||||
|
}
|
||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Hud::drawCrosshair() {
|
void Hud::drawCrosshair() {
|
||||||
|
|
||||||
if (use_crosshair_image) {
|
if (use_crosshair_image) {
|
||||||
video::ITexture *crosshair = tsrc->getTexture("crosshair.png");
|
video::ITexture *crosshair = tsrc->getTexture("crosshair.png");
|
||||||
v2u32 size = crosshair->getOriginalSize();
|
v2u32 size = crosshair->getOriginalSize();
|
||||||
@ -495,7 +493,7 @@ void drawItemStack(video::IVideoDriver *driver,
|
|||||||
{
|
{
|
||||||
if(item.empty())
|
if(item.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const ItemDefinition &def = item.getDefinition(gamedef->idef());
|
const ItemDefinition &def = item.getDefinition(gamedef->idef());
|
||||||
video::ITexture *texture = gamedef->idef()->getInventoryTexture(def.name, gamedef);
|
video::ITexture *texture = gamedef->idef()->getInventoryTexture(def.name, gamedef);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user