**Note**: `offset` _will_ adapt to screen DPI as well as user defined scaling
factor!
+The `z_index` field specifies the order of HUD elements from back to front.
+Lower z-index elements are displayed behind higher z-index elements. Elements
+with same z-index are displayed in an arbitrary order. Default 0.
+Supports negative values.
+
Below are the specific uses for fields in each type; fields not listed for that
type are ignored.
size = { x=100, y=100 },
-- Size of element in pixels
+
+ z_index = 0,
+ -- Z index : lower z-index HUDs are displayed behind higher z-index HUDs
}
Particle definition
v2f *offset;
v3f *world_pos;
v2s32 *size;
+ s16 z_index;
} hudadd;
struct
{
e->offset = *event->hudadd.offset;
e->world_pos = *event->hudadd.world_pos;
e->size = *event->hudadd.size;
+ e->z_index = event->hudadd.z_index;
hud_server_to_client[server_id] = player->addHud(e);
delete event->hudadd.pos;
case HUD_STAT_SIZE:
e->size = *event->hudchange.v2s32data;
break;
+
+ case HUD_STAT_Z_INDEX:
+ e->z_index = event->hudchange.data;
+ break;
}
delete event->hudchange.v3fdata;
{
u32 text_height = g_fontengine->getTextHeight();
irr::gui::IGUIFont* font = g_fontengine->getFont();
+
+ // Reorder elements by z_index
+ std::vector<size_t> ids;
+
for (size_t i = 0; i != player->maxHudId(); i++) {
HudElement *e = player->getHud(i);
if (!e)
continue;
+ auto it = ids.begin();
+ while (it != ids.end() && player->getHud(*it)->z_index <= e->z_index)
+ ++it;
+
+ ids.insert(it, i);
+ }
+
+ for (size_t i : ids) {
+ HudElement *e = player->getHud(i);
+
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) {
{HUD_STAT_ALIGN, "alignment"},
{HUD_STAT_OFFSET, "offset"},
{HUD_STAT_WORLD_POS, "world_pos"},
+ {HUD_STAT_SIZE, "size"},
+ {HUD_STAT_Z_INDEX, "z_index"},
{0, NULL},
};
HUD_STAT_ALIGN,
HUD_STAT_OFFSET,
HUD_STAT_WORLD_POS,
- HUD_STAT_SIZE
+ HUD_STAT_SIZE,
+ HUD_STAT_Z_INDEX,
};
struct HudElement {
v2f offset;
v3f world_pos;
v2s32 size;
+ s16 z_index = 0;
};
extern const EnumString es_HudElementType[];
v2f offset;
v3f world_pos;
v2s32 size;
+ s16 z_index = 0;
*pkt >> server_id >> type >> pos >> name >> scale >> text >> number >> item
>> dir >> align >> offset;
*pkt >> size;
} catch(SerializationError &e) {};
+ try {
+ *pkt >> z_index;
+ }
+ catch(PacketError &e) {}
+
ClientEvent *event = new ClientEvent();
event->type = CE_HUDADD;
event->hudadd.server_id = server_id;
event->hudadd.offset = new v2f(offset);
event->hudadd.world_pos = new v3f(world_pos);
event->hudadd.size = new v2s32(size);
+ event->hudadd.z_index = z_index;
m_client_event_queue.push(event);
}
v2f1000 offset
v3f1000 world_pos
v2s32 size
+ s16 z_index
*/
TOCLIENT_HUDRM = 0x4a,
elem->size = lua_istable(L, -1) ? read_v2s32(L, -1) : v2s32();
lua_pop(L, 1);
- elem->name = getstringfield_default(L, 2, "name", "");
- elem->text = getstringfield_default(L, 2, "text", "");
- elem->number = getintfield_default(L, 2, "number", 0);
- elem->item = getintfield_default(L, 2, "item", 0);
- elem->dir = getintfield_default(L, 2, "direction", 0);
+ elem->name = getstringfield_default(L, 2, "name", "");
+ elem->text = getstringfield_default(L, 2, "text", "");
+ elem->number = getintfield_default(L, 2, "number", 0);
+ elem->item = getintfield_default(L, 2, "item", 0);
+ elem->dir = getintfield_default(L, 2, "direction", 0);
+ elem->z_index = MYMAX(S16_MIN, MYMIN(S16_MAX,
+ getintfield_default(L, 2, "z_index", 0)));
// Deprecated, only for compatibility's sake
if (elem->dir == 0)
push_v3f(L, elem->world_pos);
lua_setfield(L, -2, "world_pos");
+
+ lua_pushnumber(L, elem->z_index);
+ lua_setfield(L, -2, "z_index");
}
HudElementStat read_hud_change(lua_State *L, HudElement *elem, void **value)
elem->size = read_v2s32(L, 4);
*value = &elem->size;
break;
+ case HUD_STAT_Z_INDEX:
+ elem->z_index = MYMAX(S16_MIN, MYMIN(S16_MAX, luaL_checknumber(L, 4)));
+ *value = &elem->z_index;
+ break;
}
return stat;
}
pkt << id << (u8) form->type << form->pos << form->name << form->scale
<< form->text << form->number << form->item << form->dir
- << form->align << form->offset << form->world_pos << form->size;
+ << form->align << form->offset << form->world_pos << form->size
+ << form->z_index;
Send(&pkt);
}