mirror of
https://github.com/luanti-org/luanti.git
synced 2025-10-05 19:31:04 +00:00
Simplify HUD handling in Player class
This commit is contained in:
parent
bb74b9d488
commit
36b5374715
6 changed files with 35 additions and 65 deletions
|
@ -307,11 +307,8 @@ void Hud::drawItems(v2s32 screen_pos, v2s32 screen_offset, s32 itemcount, v2f al
|
|||
|
||||
bool Hud::hasElementOfType(HudElementType type)
|
||||
{
|
||||
for (size_t i = 0; i != player->maxHudId(); i++) {
|
||||
HudElement *e = player->getHud(i);
|
||||
if (!e)
|
||||
continue;
|
||||
if (e->type == type)
|
||||
for (HudElement *e : player->getHudElements()) {
|
||||
if (e && e->type == type)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -342,9 +339,13 @@ void Hud::drawLuaElements(const v3s16 &camera_offset)
|
|||
const u32 text_height = g_fontengine->getTextHeight();
|
||||
gui::IGUIFont *const font = g_fontengine->getFont();
|
||||
|
||||
// Reorder elements by z_index
|
||||
std::vector<HudElement*> elems;
|
||||
elems.reserve(player->maxHudId());
|
||||
|
||||
elems.reserve(player->getHudElements().size());
|
||||
for (HudElement *e : player->getHudElements()) {
|
||||
if (e)
|
||||
elems.push_back(e);
|
||||
}
|
||||
|
||||
// Add builtin elements if the server doesn't send them.
|
||||
// Declared here such that they have the same lifetime as the elems vector
|
||||
|
@ -361,17 +362,10 @@ void Hud::drawLuaElements(const v3s16 &camera_offset)
|
|||
elems.push_back(&hotbar);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i != player->maxHudId(); i++) {
|
||||
HudElement *e = player->getHud(i);
|
||||
if (!e)
|
||||
continue;
|
||||
|
||||
auto it = elems.begin();
|
||||
while (it != elems.end() && (*it)->z_index <= e->z_index)
|
||||
++it;
|
||||
|
||||
elems.insert(it, e);
|
||||
}
|
||||
// Reorder by Z-index for rendering
|
||||
std::sort(elems.begin(), elems.end(), [] (HudElement *l, HudElement *r) {
|
||||
return l->z_index < r->z_index;
|
||||
});
|
||||
|
||||
for (HudElement *e : elems) {
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue