mirror of
https://github.com/minetest/minetest.git
synced 2024-12-02 12:33:45 +01:00
Hud: Fix offset being ignored by inventory bar
This commit is contained in:
parent
9a04dfd0f5
commit
eae33951ad
@ -945,6 +945,7 @@ Displays a horizontal bar made up of half-images.
|
|||||||
* `number`: Number of items in the inventory to be displayed.
|
* `number`: Number of items in the inventory to be displayed.
|
||||||
* `item`: Position of item that is selected.
|
* `item`: Position of item that is selected.
|
||||||
* `direction`
|
* `direction`
|
||||||
|
* `offset`: offset in pixels from position.
|
||||||
|
|
||||||
### `waypoint`
|
### `waypoint`
|
||||||
Displays distance to selected world position.
|
Displays distance to selected world position.
|
||||||
|
30
src/hud.cpp
30
src/hud.cpp
@ -196,24 +196,25 @@ void Hud::drawItem(const ItemStack &item, const core::rect<s32>& rect,
|
|||||||
}
|
}
|
||||||
|
|
||||||
//NOTE: selectitem = 0 -> no selected; selectitem 1-based
|
//NOTE: selectitem = 0 -> no selected; selectitem 1-based
|
||||||
void Hud::drawItems(v2s32 upperleftpos, s32 itemcount, s32 offset,
|
void Hud::drawItems(v2s32 upperleftpos, s32 itemcount, s32 inv_offset,
|
||||||
InventoryList *mainlist, u16 selectitem, u16 direction)
|
InventoryList *mainlist, u16 selectitem, u16 direction, const v2s32 &offset)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_TOUCHSCREENGUI
|
#ifdef HAVE_TOUCHSCREENGUI
|
||||||
if ( (g_touchscreengui) && (offset == 0))
|
if (g_touchscreengui && inv_offset == 0)
|
||||||
g_touchscreengui->resetHud();
|
g_touchscreengui->resetHud();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
s32 height = m_hotbar_imagesize + m_padding * 2;
|
s32 height = m_hotbar_imagesize + m_padding * 2;
|
||||||
s32 width = (itemcount - offset) * (m_hotbar_imagesize + m_padding * 2);
|
s32 width = (itemcount - inv_offset) * (m_hotbar_imagesize + m_padding * 2);
|
||||||
|
|
||||||
if (direction == HUD_DIR_TOP_BOTTOM || direction == HUD_DIR_BOTTOM_TOP) {
|
if (direction == HUD_DIR_TOP_BOTTOM || direction == HUD_DIR_BOTTOM_TOP) {
|
||||||
width = m_hotbar_imagesize + m_padding * 2;
|
width = m_hotbar_imagesize + m_padding * 2;
|
||||||
height = (itemcount - offset) * (m_hotbar_imagesize + m_padding * 2);
|
height = (itemcount - inv_offset) * (m_hotbar_imagesize + m_padding * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Position of upper left corner of bar
|
// Position of upper left corner of bar
|
||||||
v2s32 pos = upperleftpos;
|
v2s32 pos = upperleftpos + offset;
|
||||||
|
pos *= g_settings->getFloat("hud_scaling") * porting::getDisplayDensity();
|
||||||
|
|
||||||
if (hotbar_image != player->hotbar_image) {
|
if (hotbar_image != player->hotbar_image) {
|
||||||
hotbar_image = player->hotbar_image;
|
hotbar_image = player->hotbar_image;
|
||||||
@ -243,8 +244,7 @@ void Hud::drawItems(v2s32 upperleftpos, s32 itemcount, s32 offset,
|
|||||||
NULL, hbar_colors, true);
|
NULL, hbar_colors, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (s32 i = offset; i < itemcount && (size_t)i < mainlist->getSize(); i++)
|
for (s32 i = inv_offset; i < itemcount && (size_t)i < mainlist->getSize(); i++) {
|
||||||
{
|
|
||||||
v2s32 steppos;
|
v2s32 steppos;
|
||||||
s32 fullimglen = m_hotbar_imagesize + m_padding * 2;
|
s32 fullimglen = m_hotbar_imagesize + m_padding * 2;
|
||||||
|
|
||||||
@ -252,16 +252,16 @@ void Hud::drawItems(v2s32 upperleftpos, s32 itemcount, s32 offset,
|
|||||||
|
|
||||||
switch (direction) {
|
switch (direction) {
|
||||||
case HUD_DIR_RIGHT_LEFT:
|
case HUD_DIR_RIGHT_LEFT:
|
||||||
steppos = v2s32(-(m_padding + (i - offset) * fullimglen), m_padding);
|
steppos = v2s32(-(m_padding + (i - inv_offset) * fullimglen), m_padding);
|
||||||
break;
|
break;
|
||||||
case HUD_DIR_TOP_BOTTOM:
|
case HUD_DIR_TOP_BOTTOM:
|
||||||
steppos = v2s32(m_padding, m_padding + (i - offset) * fullimglen);
|
steppos = v2s32(m_padding, m_padding + (i - inv_offset) * fullimglen);
|
||||||
break;
|
break;
|
||||||
case HUD_DIR_BOTTOM_TOP:
|
case HUD_DIR_BOTTOM_TOP:
|
||||||
steppos = v2s32(m_padding, -(m_padding + (i - offset) * fullimglen));
|
steppos = v2s32(m_padding, -(m_padding + (i - inv_offset) * fullimglen));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
steppos = v2s32(m_padding + (i - offset) * fullimglen, m_padding);
|
steppos = v2s32(m_padding + (i - inv_offset) * fullimglen, m_padding);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,7 +275,8 @@ void Hud::drawItems(v2s32 upperleftpos, s32 itemcount, s32 offset,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Hud::drawLuaElements(const v3s16 &camera_offset) {
|
void Hud::drawLuaElements(const v3s16 &camera_offset)
|
||||||
|
{
|
||||||
u32 text_height = g_fontengine->getTextHeight();
|
u32 text_height = g_fontengine->getTextHeight();
|
||||||
irr::gui::IGUIFont* font = g_fontengine->getFont();
|
irr::gui::IGUIFont* font = g_fontengine->getFont();
|
||||||
for (size_t i = 0; i != player->maxHudId(); i++) {
|
for (size_t i = 0; i != player->maxHudId(); i++) {
|
||||||
@ -326,7 +327,8 @@ void Hud::drawLuaElements(const v3s16 &camera_offset) {
|
|||||||
break; }
|
break; }
|
||||||
case HUD_ELEM_INVENTORY: {
|
case HUD_ELEM_INVENTORY: {
|
||||||
InventoryList *inv = inventory->getList(e->text);
|
InventoryList *inv = inventory->getList(e->text);
|
||||||
drawItems(pos, e->number, 0, inv, e->item, e->dir);
|
v2s32 offs(e->offset.X, e->offset.Y);
|
||||||
|
drawItems(pos, e->number, 0, inv, e->item, e->dir, offs);
|
||||||
break; }
|
break; }
|
||||||
case HUD_ELEM_WAYPOINT: {
|
case HUD_ELEM_WAYPOINT: {
|
||||||
v3f p_pos = player->getPosition() / BS;
|
v3f p_pos = player->getPosition() / BS;
|
||||||
|
@ -148,8 +148,9 @@ private:
|
|||||||
void drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture,
|
void drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture,
|
||||||
s32 count, v2s32 offset, v2s32 size=v2s32());
|
s32 count, v2s32 offset, v2s32 size=v2s32());
|
||||||
|
|
||||||
void drawItems(v2s32 upperleftpos, s32 itemcount, s32 offset,
|
void drawItems(v2s32 upperleftpos, s32 itemcount, s32 inv_offset,
|
||||||
InventoryList *mainlist, u16 selectitem, u16 direction);
|
InventoryList *mainlist, u16 selectitem, u16 direction,
|
||||||
|
const v2s32 &offset = v2s32(0, 0));
|
||||||
|
|
||||||
void drawItem(const ItemStack &item, const core::rect<s32>& rect,
|
void drawItem(const ItemStack &item, const core::rect<s32>& rect,
|
||||||
bool selected);
|
bool selected);
|
||||||
|
Loading…
Reference in New Issue
Block a user