mirror of
https://github.com/luanti-org/luanti.git
synced 2026-10-12 02:18:30 +00:00
HUD inventory: allow custom background per element (#17359)
This commit is contained in:
@@ -2117,6 +2117,8 @@ Displays a horizontal bar made up of half-images with an optional background.
|
||||
### `inventory`
|
||||
|
||||
* `text`: The name of the inventory list to be displayed.
|
||||
* `text2`: Optional texture name for the inventory background. If not specified,
|
||||
the player's hotbar background is used.
|
||||
* `number`: Amount of item slots in the inventory to be displayed.
|
||||
Integer in range [u16].
|
||||
* `item`: The slot at this index is rendered as if it were selected
|
||||
|
||||
@@ -342,8 +342,9 @@ local hud_inventory_defs = {
|
||||
position = {x=0.7, y=0.5},
|
||||
direction = 3,
|
||||
text = "main",
|
||||
number = 4,
|
||||
item = 2,
|
||||
text2 = "testhud_inventory_bg.png",
|
||||
number = 1,
|
||||
item = 0,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 92 B |
+7
-7
@@ -234,7 +234,7 @@ void Hud::drawItem(const ItemStack &item, const core::rect<s32>& rect,
|
||||
// mainlist can be NULL, but draw the frame anyway.
|
||||
void Hud::drawItems(v2s32 screen_pos, v2s32 screen_offset, s32 itemcount, v2f alignment,
|
||||
s32 inv_offset, InventoryList *mainlist, u16 selectitem, u16 direction,
|
||||
bool is_hotbar)
|
||||
bool is_hotbar, const std::string &background_image)
|
||||
{
|
||||
s32 height = m_hotbar_imagesize + m_padding * 2;
|
||||
s32 width = (itemcount - inv_offset) * (m_hotbar_imagesize + m_padding * 2);
|
||||
@@ -251,11 +251,11 @@ void Hud::drawItems(v2s32 screen_pos, v2s32 screen_offset, s32 itemcount, v2f al
|
||||
pos.X += (alignment.X - 1.0f) * (width * 0.5f);
|
||||
pos.Y += (alignment.Y - 1.0f) * (height * 0.5f);
|
||||
|
||||
// Store hotbar_image in member variable, used by drawItem()
|
||||
if (hotbar_image != player->hotbar_image) {
|
||||
hotbar_image = player->hotbar_image;
|
||||
use_hotbar_image = !hotbar_image.empty();
|
||||
}
|
||||
// Store the effective background image in a member variable, used by drawItem().
|
||||
// An inventory HUD element can override the player's hotbar image with text2.
|
||||
hotbar_image = background_image.empty() ?
|
||||
player->hotbar_image : background_image;
|
||||
use_hotbar_image = !hotbar_image.empty();
|
||||
|
||||
// Store hotbar_selected_image in member variable, used by drawItem()
|
||||
if (hotbar_selected_image != player->hotbar_selected_image) {
|
||||
@@ -447,7 +447,7 @@ void Hud::drawLuaElements(const v3s16 &camera_offset, bool only_unhidable)
|
||||
if (!inv)
|
||||
warningstream << "HUD: Unknown inventory list. name=" << e->text << std::endl;
|
||||
drawItems(pos, v2s32(e->offset.X, e->offset.Y), e->number, e->align, 0,
|
||||
inv, e->item, e->dir, false);
|
||||
inv, e->item, e->dir, false, e->text2);
|
||||
break; }
|
||||
case HUD_ELEM_WAYPOINT: {
|
||||
if (!calculateScreenPos(camera_offset, e, &pos))
|
||||
|
||||
+1
-1
@@ -106,7 +106,7 @@ private:
|
||||
|
||||
void drawItems(v2s32 screen_pos, v2s32 screen_offset, s32 itemcount, v2f alignment,
|
||||
s32 inv_offset, InventoryList *mainlist, u16 selectitem,
|
||||
u16 direction, bool is_hotbar);
|
||||
u16 direction, bool is_hotbar, const std::string &background_image = "");
|
||||
|
||||
void drawItem(const ItemStack &item, const core::rect<s32> &rect, bool selected);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user