mirror of
https://github.com/luanti-org/luanti.git
synced 2025-09-15 18:57:08 +00:00
Remove hotbar element features
This commit is contained in:
parent
29d1dcd23b
commit
a4303f0562
4 changed files with 55 additions and 162 deletions
|
@ -1840,10 +1840,6 @@ Displays a horizontal bar made up of half-images with an optional background.
|
||||||
* `direction`: Direction the list will be displayed in
|
* `direction`: Direction the list will be displayed in
|
||||||
* `offset`: offset in pixels from position.
|
* `offset`: offset in pixels from position.
|
||||||
* `alignment`: The alignment of the inventory.
|
* `alignment`: The alignment of the inventory.
|
||||||
* `world_pos`: Inventory of the hotbar depending on `hotbar_source`
|
|
||||||
`x` the index of the `hotbar_source` table to be used, if 0 use all next to each other
|
|
||||||
`y` an additional length to clamp the size, if 0 use whole length as defined in `hotbar_source`
|
|
||||||
`z` an additional offset to adjust where the displayed inventory starts
|
|
||||||
|
|
||||||
### `waypoint`
|
### `waypoint`
|
||||||
|
|
||||||
|
|
|
@ -239,62 +239,6 @@ local hud_hotbar_defs = {
|
||||||
alignment = {x=-1, y=1},
|
alignment = {x=-1, y=1},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
hotbar_source = {
|
|
||||||
{list = "craft", length = 4, offset = 3},
|
|
||||||
{list = "main", length = 5, offset = 0},
|
|
||||||
},
|
|
||||||
hotbar_image = "default_stone.png^[opacity:150",
|
|
||||||
{
|
|
||||||
type = "hotbar",
|
|
||||||
position = {x=0.5, y=0.2},
|
|
||||||
world_pos = {x=1},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type = "hotbar",
|
|
||||||
position = {x=0.5, y=0.3},
|
|
||||||
world_pos = {x=1, y=6},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type = "hotbar",
|
|
||||||
position = {x=0.5, y=0.4},
|
|
||||||
world_pos = {x=1, z=5, y=3},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type = "hotbar",
|
|
||||||
position = {x=0.5, y=0.5},
|
|
||||||
world_pos = {x=2},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type = "hotbar",
|
|
||||||
position = {x=0.5, y=0.6},
|
|
||||||
world_pos = {x=2, z=1, y=3},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type = "hotbar",
|
|
||||||
position = {x=0.5, y=0.7},
|
|
||||||
world_pos = {x=2},
|
|
||||||
direction = 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type = "hotbar",
|
|
||||||
position = {x=0.5, y=0.8},
|
|
||||||
world_pos = {x=2, z=1, y=3},
|
|
||||||
direction = 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type = "hotbar",
|
|
||||||
position = {x=0.2, y=0.5},
|
|
||||||
world_pos = {x=2, z=1, y=3},
|
|
||||||
direction = 2,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type = "hotbar",
|
|
||||||
position = {x=0.8, y=0.5},
|
|
||||||
world_pos = {x=2, z=1, y=3},
|
|
||||||
direction = 3,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
hotbar_source = {
|
hotbar_source = {
|
||||||
{list = "craft", length = 4, offset = 3},
|
{list = "craft", length = 4, offset = 3},
|
||||||
|
@ -308,27 +252,6 @@ local hud_hotbar_defs = {
|
||||||
position = {x=0.5, y=0.8},
|
position = {x=0.5, y=0.8},
|
||||||
direction = 1,
|
direction = 1,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
type = "hotbar",
|
|
||||||
position = {x=0.5, y=0.7},
|
|
||||||
world_pos = {z=1, y=10},
|
|
||||||
direction = 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type = "hotbar",
|
|
||||||
position = {x=0.5, y=0.6},
|
|
||||||
world_pos = {z=1, y=10},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type = "hotbar",
|
|
||||||
position = {x=0.5, y=0.5},
|
|
||||||
world_pos = {z=17, y=5},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type = "hotbar",
|
|
||||||
position = {x=0.5, y=0.4},
|
|
||||||
world_pos = {z=10, y=10},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
type = "hotbar",
|
type = "hotbar",
|
||||||
position = {x=0.2, y=0.5},
|
position = {x=0.2, y=0.5},
|
||||||
|
@ -346,9 +269,8 @@ local hud_hotbar_defs = {
|
||||||
local player_hud_hotbars= {}
|
local player_hud_hotbars= {}
|
||||||
core.register_chatcommand("hudhotbars", {
|
core.register_chatcommand("hudhotbars", {
|
||||||
description = "Shows some test Lua HUD elements of type hotbar. " ..
|
description = "Shows some test Lua HUD elements of type hotbar. " ..
|
||||||
"(Cycles between: none, aligned using all direction and offset," ..
|
"(Cycles between tests for: none, aligned all direction and offset," ..
|
||||||
"changed hotbar_source each only using a single inventory," ..
|
"changed hotbar_source all direction and hotbar image)",
|
||||||
"using multiple inventories (world_pos.x = 0))",
|
|
||||||
func = function(name)
|
func = function(name)
|
||||||
local player = core.get_player_by_name(name)
|
local player = core.get_player_by_name(name)
|
||||||
if not player then
|
if not player then
|
||||||
|
|
|
@ -335,8 +335,9 @@ void Hud::drawInventory(const v2s32& screen_pos, const v2f& offset, s32 itemcoun
|
||||||
drawItems(pos, itemcount, 0, mainlist, selectitem, direction);
|
drawItems(pos, itemcount, 0, mainlist, selectitem, direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If max_inv_length == 0 do not clamp size
|
||||||
void Hud::drawHotbar(const v2s32 &screen_pos, const v2f &offset, u16 direction,
|
void Hud::drawHotbar(const v2s32 &screen_pos, const v2f &offset, u16 direction,
|
||||||
const v2f &alignment, const v3f &world_pos)
|
const v2f &alignment, s32 max_inv_length, s32 inv_offset)
|
||||||
{
|
{
|
||||||
if (g_touchcontrols)
|
if (g_touchcontrols)
|
||||||
g_touchcontrols->resetHotbarRects();
|
g_touchcontrols->resetHotbarRects();
|
||||||
|
@ -345,70 +346,48 @@ void Hud::drawHotbar(const v2s32 &screen_pos, const v2f &offset, u16 direction,
|
||||||
u16 wield_index = player->getWieldIndex() + 1;
|
u16 wield_index = player->getWieldIndex() + 1;
|
||||||
v2s32 screen_offset(offset.X, offset.Y);
|
v2s32 screen_offset(offset.X, offset.Y);
|
||||||
|
|
||||||
if (!world_pos.X) {
|
// All invs next to each other
|
||||||
// All invs next to each other
|
if (inv_offset > player->hotbar_source.getMaxLength())
|
||||||
if (world_pos.Z > player->hotbar_source.getMaxLength())
|
return;
|
||||||
return;
|
max_inv_length = max_inv_length ? max_inv_length :
|
||||||
s32 hotbar_length = world_pos.Y ? world_pos.Y : player->hotbar_source.getMaxLength() - world_pos.Z;
|
player->hotbar_source.getMaxLength() - inv_offset;
|
||||||
|
|
||||||
s32 height, width;
|
s32 height, width;
|
||||||
v2s32 pos;
|
v2s32 pos;
|
||||||
getInventoryDimensions(screen_pos, screen_offset, hotbar_length, alignment,
|
getInventoryDimensions(screen_pos, screen_offset, max_inv_length, alignment,
|
||||||
direction, pos, width, height);
|
direction, pos, width, height);
|
||||||
drawInventoryBackground(pos, width, height);
|
drawInventoryBackground(pos, width, height);
|
||||||
|
|
||||||
// Handle offset
|
// Handle offset
|
||||||
std::size_t source_index = 0;
|
std::size_t source_index = 0;
|
||||||
u16 length_before = 0;
|
u16 length_before = 0;
|
||||||
for (s32 inv_offset = world_pos.Z; source_index < sources.size(); source_index++) {
|
for (s32 i_offset = inv_offset; source_index < sources.size(); source_index++) {
|
||||||
const HotbarSource::Source& source = sources[source_index];
|
const HotbarSource::Source& source = sources[source_index];
|
||||||
if (inv_offset < source.length) {
|
if (i_offset < source.length) {
|
||||||
s32 inv_length = MYMIN(source.length - inv_offset, hotbar_length);
|
s32 inv_length = MYMIN(source.length - i_offset, max_inv_length);
|
||||||
|
|
||||||
drawItems(pos + getInventoryPosOffset(direction, 0, hotbar_length - inv_length),
|
drawItems(pos + getInventoryPosOffset(direction, 0, max_inv_length - inv_length),
|
||||||
inv_length + source.offset + inv_offset, source.offset + inv_offset,
|
inv_length + source.offset + i_offset, source.offset + i_offset,
|
||||||
inventory->getList(source.list), wield_index + source.offset,
|
inventory->getList(source.list), wield_index + source.offset,
|
||||||
direction, true, 0);
|
direction, true, 0);
|
||||||
length_before = inv_length;
|
length_before = inv_length;
|
||||||
source_index++;
|
source_index++;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
inv_offset -= source.length;
|
|
||||||
}
|
}
|
||||||
|
i_offset -= source.length;
|
||||||
|
}
|
||||||
|
|
||||||
for (; source_index < sources.size(); source_index++) {
|
for (; source_index < sources.size(); source_index++) {
|
||||||
const HotbarSource::Source& source = sources[source_index];
|
const HotbarSource::Source& source = sources[source_index];
|
||||||
s32 inv_length = MYMIN(source.length, hotbar_length - length_before);
|
s32 inv_length = MYMIN(source.length, max_inv_length - length_before);
|
||||||
if(inv_length <= 0)
|
if(inv_length <= 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
drawItems(pos + getInventoryPosOffset(direction, length_before, hotbar_length - inv_length),
|
drawItems(pos + getInventoryPosOffset(direction, length_before, max_inv_length - inv_length),
|
||||||
inv_length + source.offset,
|
inv_length + source.offset,
|
||||||
source.offset, inventory->getList(source.list),
|
source.offset, inventory->getList(source.list),
|
||||||
wield_index - length_before + source.offset, direction, true, length_before);
|
wield_index - length_before + source.offset, direction, true, length_before);
|
||||||
length_before += inv_length;
|
length_before += inv_length;
|
||||||
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Only a single inventory
|
|
||||||
if (world_pos.X > sources.size())
|
|
||||||
return;
|
|
||||||
const HotbarSource::Source& source = sources[world_pos.X-1];
|
|
||||||
if (world_pos.Z > source.length)
|
|
||||||
return;
|
|
||||||
s32 inv_length = world_pos.Y ? world_pos.Y : source.length - world_pos.Z;
|
|
||||||
|
|
||||||
s32 height, width;
|
|
||||||
v2s32 pos;
|
|
||||||
getInventoryDimensions(screen_pos, screen_offset, inv_length, alignment, direction,
|
|
||||||
pos, width, height);
|
|
||||||
drawInventoryBackground(pos, width, height);
|
|
||||||
|
|
||||||
u16 length_before = player->hotbar_source.getLengthBefore(world_pos.X - 1);
|
|
||||||
s32 inv_offset = source.offset + world_pos.Z;
|
|
||||||
inv_length = MYMIN(inv_length, source.length);
|
|
||||||
drawItems(pos, inv_length + inv_offset, inv_offset, inventory->getList(source.list),
|
|
||||||
wield_index - length_before + inv_offset, direction, true, length_before);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -673,25 +652,21 @@ void Hud::drawLuaElements(const v3s16 &camera_offset)
|
||||||
client->getMinimap()->drawMinimap(rect);
|
client->getMinimap()->drawMinimap(rect);
|
||||||
break; }
|
break; }
|
||||||
case HUD_ELEM_HOTBAR: {
|
case HUD_ELEM_HOTBAR: {
|
||||||
if (!e->world_pos.X) { // Handle splitting caused by hud_hotbar_max_width
|
// Handle splitting caused by hud_hotbar_max_width
|
||||||
u16 hotbar_itemcount = e->world_pos.Y ? e->world_pos.Y :
|
u16 hotbar_itemcount = player->hotbar_source.getMaxLength();
|
||||||
player->hotbar_source.getMaxLength();
|
s32 width = hotbar_itemcount * (m_hotbar_imagesize + m_padding * 2);
|
||||||
hotbar_itemcount -= e->world_pos.Z;
|
const v2u32 &window_size = RenderingEngine::getWindowSize();
|
||||||
s32 width = hotbar_itemcount * (m_hotbar_imagesize + m_padding * 2);
|
if ((float) width / (float) window_size.X >
|
||||||
const v2u32 &window_size = RenderingEngine::getWindowSize();
|
g_settings->getFloat("hud_hotbar_max_width")) {
|
||||||
if ((float) width / (float) window_size.X >
|
v2s32 upper_pos = pos - v2s32(0, m_hotbar_imagesize + m_padding);
|
||||||
g_settings->getFloat("hud_hotbar_max_width")) {
|
u16 upper_itemcount = hotbar_itemcount/2;
|
||||||
v2s32 upper_pos = pos - v2s32(0, m_hotbar_imagesize + m_padding);
|
drawHotbar(upper_pos, e->offset, e->dir, e->align, upper_itemcount, 0);
|
||||||
u16 upper_itemcount = hotbar_itemcount/2;
|
drawHotbar(pos, e->offset, e->dir, e->align,
|
||||||
drawHotbar(upper_pos, e->offset, e->dir, e->align,
|
hotbar_itemcount - upper_itemcount, upper_itemcount);
|
||||||
{0.f, (float) upper_itemcount, e->world_pos.Z});
|
break;
|
||||||
drawHotbar(pos, e->offset, e->dir, e->align,
|
} else {
|
||||||
{0.f, (float) hotbar_itemcount - upper_itemcount,
|
drawHotbar(pos, e->offset, e->dir, e->align);
|
||||||
e->world_pos.Z + upper_itemcount});
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
drawHotbar(pos, e->offset, e->dir, e->align, e->world_pos);
|
|
||||||
break; }
|
break; }
|
||||||
default:
|
default:
|
||||||
infostream << "Hud::drawLuaElements: ignoring drawform " << e->type
|
infostream << "Hud::drawLuaElements: ignoring drawform " << e->type
|
||||||
|
|
|
@ -116,7 +116,7 @@ private:
|
||||||
v2f alignment, InventoryList *mainlist, u16 selectitem, u16 direction);
|
v2f alignment, InventoryList *mainlist, u16 selectitem, u16 direction);
|
||||||
|
|
||||||
void drawHotbar(const v2s32 &pos, const v2f &offset, u16 direction, const v2f &alignment,
|
void drawHotbar(const v2s32 &pos, const v2f &offset, u16 direction, const v2f &alignment,
|
||||||
const v3f &world_pos);
|
s32 max_inv_length = 0, s32 inv_offset = 0);
|
||||||
|
|
||||||
void drawCompassTranslate(HudElement *e, video::ITexture *texture,
|
void drawCompassTranslate(HudElement *e, video::ITexture *texture,
|
||||||
const core::rect<s32> &rect, int way);
|
const core::rect<s32> &rect, int way);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue