From 7c37b1891adcddc0e7d11e5faafddaa554443318 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Mart=C3=ADnez?= Date: Mon, 22 Apr 2013 06:53:55 -0300 Subject: Added support for alignment in HUD items --- src/scriptapi_object.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/scriptapi_object.cpp') diff --git a/src/scriptapi_object.cpp b/src/scriptapi_object.cpp index 9152c9eb3..c07f6565d 100644 --- a/src/scriptapi_object.cpp +++ b/src/scriptapi_object.cpp @@ -47,6 +47,7 @@ struct EnumString es_HudElementStat[] = {HUD_STAT_NUMBER, "number"}, {HUD_STAT_ITEM, "item"}, {HUD_STAT_DIR, "direction"}, + {HUD_STAT_ALIGN, "alignment"}, {0, NULL}, }; @@ -751,6 +752,10 @@ int ObjectRef::l_hud_add(lua_State *L) elem->item = getintfield_default(L, 2, "item", 0); elem->dir = getintfield_default(L, 2, "direction", 0); + lua_getfield(L, 2, "alignment"); + elem->align = lua_istable(L, -1) ? read_v2f(L, -1) : v2f(); + lua_pop(L, 1); + u32 id = get_server(L)->hudAdd(player, elem); if (id == (u32)-1) { delete elem; @@ -833,6 +838,9 @@ int ObjectRef::l_hud_change(lua_State *L) case HUD_STAT_DIR: e->dir = lua_tonumber(L, 4); value = &e->dir; + case HUD_STAT_ALIGN: + e->align = read_v2f(L, 4); + value = &e->align; } get_server(L)->hudChange(player, id, stat, value); -- cgit v1.2.3 From 9894167bbf516c40bf2b8577179ff8f13b8b54e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Mart=C3=ADnez?= Date: Mon, 22 Apr 2013 20:47:59 -0300 Subject: Added offset support for HUD items --- src/scriptapi_object.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/scriptapi_object.cpp') diff --git a/src/scriptapi_object.cpp b/src/scriptapi_object.cpp index c07f6565d..6669ad871 100644 --- a/src/scriptapi_object.cpp +++ b/src/scriptapi_object.cpp @@ -48,6 +48,7 @@ struct EnumString es_HudElementStat[] = {HUD_STAT_ITEM, "item"}, {HUD_STAT_DIR, "direction"}, {HUD_STAT_ALIGN, "alignment"}, + {HUD_STAT_OFFSET, "offset"}, {0, NULL}, }; @@ -756,6 +757,10 @@ int ObjectRef::l_hud_add(lua_State *L) elem->align = lua_istable(L, -1) ? read_v2f(L, -1) : v2f(); lua_pop(L, 1); + lua_getfield(L, 2, "offset"); + elem->offset = lua_istable(L, -1) ? read_v2f(L, -1) : v2f(); + lua_pop(L, 1); + u32 id = get_server(L)->hudAdd(player, elem); if (id == (u32)-1) { delete elem; @@ -841,6 +846,9 @@ int ObjectRef::l_hud_change(lua_State *L) case HUD_STAT_ALIGN: e->align = read_v2f(L, 4); value = &e->align; + case HUD_STAT_OFFSET: + e->offset = read_v2f(L, 4); + value = &e->offset; } get_server(L)->hudChange(player, id, stat, value); -- cgit v1.2.3 From e703c5b81f87550e636ebb1ebb1eb64027a44687 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Mart=C3=ADnez?= Date: Wed, 24 Apr 2013 07:52:46 -0300 Subject: Added support to disable built-in HUD elements --- src/scriptapi_object.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/scriptapi_object.cpp') diff --git a/src/scriptapi_object.cpp b/src/scriptapi_object.cpp index 6669ad871..e2eec5104 100644 --- a/src/scriptapi_object.cpp +++ b/src/scriptapi_object.cpp @@ -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} -- cgit v1.2.3 From d3f0ce62240b7598eded13153eacb410bf2420a1 Mon Sep 17 00:00:00 2001 From: kwolekr Date: Thu, 25 Apr 2013 19:27:22 -0400 Subject: Generalize hud_builtin_enable into hud_set_flags --- src/scriptapi_object.cpp | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) (limited to 'src/scriptapi_object.cpp') diff --git a/src/scriptapi_object.cpp b/src/scriptapi_object.cpp index e2eec5104..4dfdeb8c8 100644 --- a/src/scriptapi_object.cpp +++ b/src/scriptapi_object.cpp @@ -54,10 +54,10 @@ struct EnumString es_HudElementStat[] = struct EnumString es_HudBuiltinElement[] = { - {HUD_BUILTIN_HOTBAR, "hotbar"}, - {HUD_BUILTIN_HEALTHBAR, "healthbar"}, - {HUD_BUILTIN_CROSSHAIR, "crosshair"}, - {HUD_BUILTIN_WIELDITEM, "wielditem"}, + {HUD_FLAG_HOTBAR_VISIBLE, "hotbar"}, + {HUD_FLAG_HEALTHBAR_VISIBLE, "healthbar"}, + {HUD_FLAG_CROSSHAIR_VISIBLE, "crosshair"}, + {HUD_FLAG_WIELDITEM_VISIBLE, "wielditem"}, {0, NULL}, }; @@ -911,30 +911,29 @@ 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) +// hud_set_flags(self, flags) +int ObjectRef::l_hud_set_flags(lua_State *L) { ObjectRef *ref = checkobject(L, 1); Player *player = getplayer(ref); if (player == NULL) return 0; - HudBuiltinElement id; - int id_i; + u32 flags = 0; + u32 mask = 0; + bool flag; - std::string s(lua_tostring(L, 2)); - - // Return nil if component is not in enum - if (!string_to_enum(es_HudBuiltinElement, id_i, s)) + const EnumString *esp = es_HudBuiltinElement; + for (int i = 0; esp[i].str; i++) { + if (getboolfield(L, 2, esp[i].str, flag)) { + flags |= esp[i].num * flag; + mask |= esp[i].num; + } + } + if (!get_server(L)->hudSetFlags(player, flags, mask)) 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); + lua_pushboolean(L, true); return 1; } @@ -1048,9 +1047,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), + luamethod(ObjectRef, hud_set_flags), {0,0} }; -- cgit v1.2.3