mirror of
https://github.com/luanti-org/luanti.git
synced 2025-10-13 16:45:20 +02:00
Added support to disable built-in HUD elements
This commit is contained in:
committed by
Perttu Ahola
parent
33dd267fd9
commit
e703c5b81f
@@ -52,6 +52,15 @@ struct EnumString es_HudElementStat[] =
|
||||
{0, NULL},
|
||||
};
|
||||
|
||||
struct EnumString es_HudBuiltinElement[] =
|
||||
{
|
||||
{HUD_BUILTIN_HOTBAR, "hotbar"},
|
||||
{HUD_BUILTIN_HEALTHBAR, "healthbar"},
|
||||
{HUD_BUILTIN_CROSSHAIR, "crosshair"},
|
||||
{HUD_BUILTIN_WIELDITEM, "wielditem"},
|
||||
{0, NULL},
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
ObjectRef
|
||||
@@ -902,6 +911,33 @@ int ObjectRef::l_hud_get(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
// hud_builtin_enable(self, id, flag)
|
||||
int ObjectRef::l_hud_builtin_enable(lua_State *L)
|
||||
{
|
||||
ObjectRef *ref = checkobject(L, 1);
|
||||
Player *player = getplayer(ref);
|
||||
if (player == NULL)
|
||||
return 0;
|
||||
|
||||
HudBuiltinElement id;
|
||||
int id_i;
|
||||
|
||||
std::string s(lua_tostring(L, 2));
|
||||
|
||||
// Return nil if component is not in enum
|
||||
if (!string_to_enum(es_HudBuiltinElement, id_i, s))
|
||||
return 0;
|
||||
|
||||
id = (HudBuiltinElement)id_i;
|
||||
|
||||
bool flag = (bool)lua_toboolean(L, 3);
|
||||
|
||||
bool ok = get_server(L)->hudBuiltinEnable(player, id, flag);
|
||||
|
||||
lua_pushboolean(L, (int)ok);
|
||||
return 1;
|
||||
}
|
||||
|
||||
ObjectRef::ObjectRef(ServerActiveObject *object):
|
||||
m_object(object)
|
||||
{
|
||||
@@ -1012,6 +1048,7 @@ const luaL_reg ObjectRef::methods[] = {
|
||||
luamethod(ObjectRef, hud_remove),
|
||||
luamethod(ObjectRef, hud_change),
|
||||
luamethod(ObjectRef, hud_get),
|
||||
luamethod(ObjectRef, hud_builtin_enable),
|
||||
//luamethod(ObjectRef, hud_lock_next_bar),
|
||||
//luamethod(ObjectRef, hud_unlock_bar),
|
||||
{0,0}
|
||||
|
Reference in New Issue
Block a user