From d3ee617f37984b380ebe32cd37ef1cda66d96c48 Mon Sep 17 00:00:00 2001 From: sapier Date: Mon, 28 Apr 2014 23:41:27 +0200 Subject: Fix heart + bubble bar size on different texture packs Add DPI support for statbar Move heart+bubble bar to Lua HUD Add statbar size (based upon an idea by blue42u) Add support for customizing breath and statbar --- src/hud.cpp | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) (limited to 'src/hud.cpp') diff --git a/src/hud.cpp b/src/hud.cpp index c385211f2..7f2f4276c 100644 --- a/src/hud.cpp +++ b/src/hud.cpp @@ -228,7 +228,8 @@ void Hud::drawLuaElements(v3s16 camera_offset) { if (!e) continue; - v2s32 pos(e->pos.X * m_screensize.X, e->pos.Y * m_screensize.Y); + v2s32 pos(floor(e->pos.X * (float) m_screensize.X + 0.5), + floor(e->pos.Y * (float) m_screensize.Y + 0.5)); switch (e->type) { case HUD_ELEM_IMAGE: { video::ITexture *texture = tsrc->getTexture(e->text); @@ -266,7 +267,7 @@ void Hud::drawLuaElements(v3s16 camera_offset) { break; } case HUD_ELEM_STATBAR: { v2s32 offs(e->offset.X, e->offset.Y); - drawStatbar(pos, HUD_CORNER_UPPER, e->dir, e->text, e->number, offs); + drawStatbar(pos, HUD_CORNER_UPPER, e->dir, e->text, e->number, offs, e->size); break; } case HUD_ELEM_INVENTORY: { InventoryList *inv = inventory->getList(e->text); @@ -308,7 +309,9 @@ void Hud::drawLuaElements(v3s16 camera_offset) { } -void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture, s32 count, v2s32 offset) { +void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture, + s32 count, v2s32 offset, v2s32 size) +{ const video::SColor color(255, 255, 255, 255); const video::SColor colors[] = {color, color, color, color}; @@ -317,10 +320,25 @@ void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture, s return; core::dimension2di srcd(stat_texture->getOriginalSize()); + core::dimension2di dstd; + if (size == v2s32()) { + dstd = srcd; + } else { + dstd.Height = size.Y * g_settings->getFloat("gui_scaling") * + porting::getDisplayDensity(); + dstd.Width = size.X * g_settings->getFloat("gui_scaling") * + porting::getDisplayDensity(); + + offset.X *= g_settings->getFloat("gui_scaling") * + porting::getDisplayDensity(); + + offset.Y *= g_settings->getFloat("gui_scaling") * + porting::getDisplayDensity(); + } v2s32 p = pos; if (corner & HUD_CORNER_LOWER) - p -= srcd.Height; + p -= dstd.Height; p += offset; @@ -338,13 +356,13 @@ void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture, s default: steppos = v2s32(1, 0); } - steppos.X *= srcd.Width; - steppos.Y *= srcd.Height; + steppos.X *= dstd.Width; + steppos.Y *= dstd.Height; for (s32 i = 0; i < count / 2; i++) { core::rect srcrect(0, 0, srcd.Width, srcd.Height); - core::rect dstrect(srcrect); + core::rect dstrect(0,0, dstd.Width, dstd.Height); dstrect += p; driver->draw2DImage(stat_texture, dstrect, srcrect, NULL, colors, true); @@ -354,7 +372,7 @@ void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture, s if (count % 2 == 1) { core::rect srcrect(0, 0, srcd.Width / 2, srcd.Height); - core::rect dstrect(srcrect); + core::rect dstrect(0,0, dstd.Width / 2, dstd.Height); dstrect += p; driver->draw2DImage(stat_texture, dstrect, srcrect, NULL, colors, true); @@ -362,7 +380,7 @@ void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture, s } -void Hud::drawHotbar(s32 halfheartcount, u16 playeritem, s32 breath) { +void Hud::drawHotbar(u16 playeritem) { v2s32 centerlowerpos(m_displaycenter.X, m_screensize.Y); @@ -393,13 +411,6 @@ void Hud::drawHotbar(s32 halfheartcount, u16 playeritem, s32 breath) { drawItems(secondpos, hotbar_itemcount, hotbar_itemcount/2, mainlist, playeritem + 1, 0); } } - - if (player->hud_flags & HUD_FLAG_HEALTHBAR_VISIBLE) - drawStatbar(pos - v2s32(0, 4), HUD_CORNER_LOWER, HUD_DIR_LEFT_RIGHT, - "heart.png", halfheartcount, v2s32(0, 0)); - if (player->hud_flags & HUD_FLAG_BREATHBAR_VISIBLE && breath <= 10) - drawStatbar(pos - v2s32(-180, 4), HUD_CORNER_LOWER, HUD_DIR_LEFT_RIGHT, - "bubble.png", breath*2, v2s32(0, 0)); } -- cgit v1.2.3