aboutsummaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorsapier <Sapier at GMX dot net>2014-04-28 23:41:27 +0200
committersapier <Sapier at GMX dot net>2014-05-07 21:46:27 +0200
commitd3ee617f37984b380ebe32cd37ef1cda66d96c48 (patch)
treeff40e272e0b5ab7525d66ddd3b98fa3eed71a496 /src/script
parentc80d67f48e2011c88bbb9e755ee4f5e7f5391f63 (diff)
downloadminetest-d3ee617f37984b380ebe32cd37ef1cda66d96c48.tar.gz
minetest-d3ee617f37984b380ebe32cd37ef1cda66d96c48.tar.bz2
minetest-d3ee617f37984b380ebe32cd37ef1cda66d96c48.zip
Fix heart + bubble bar size on different texture packs
Add DPI support for statbar Move heart+bubble bar to Lua HUD Add statbar size (based upon an idea by blue42u) Add support for customizing breath and statbar
Diffstat (limited to 'src/script')
-rw-r--r--src/script/cpp_api/s_env.cpp18
-rw-r--r--src/script/cpp_api/s_env.h3
-rw-r--r--src/script/lua_api/l_object.cpp36
-rw-r--r--src/script/lua_api/l_object.h3
4 files changed, 60 insertions, 0 deletions
diff --git a/src/script/cpp_api/s_env.cpp b/src/script/cpp_api/s_env.cpp
index b0de675ec..ee3783bb9 100644
--- a/src/script/cpp_api/s_env.cpp
+++ b/src/script/cpp_api/s_env.cpp
@@ -58,6 +58,24 @@ void ScriptApiEnv::environment_Step(float dtime)
}
}
+void ScriptApiEnv::player_event(ServerActiveObject* player, std::string type)
+{
+ SCRIPTAPI_PRECHECKHEADER
+
+ // Get minetest.registered_playerevents
+ lua_getglobal(L, "minetest");
+ lua_getfield(L, -1, "registered_playerevents");
+
+ // Call callbacks
+ objectrefGetOrCreate(player); // player
+ lua_pushstring(L,type.c_str()); // event type
+ try {
+ script_run_callbacks(L, 2, RUN_CALLBACKS_MODE_FIRST);
+ } catch (LuaError &e) {
+ getServer()->setAsyncFatalError(e.what());
+ }
+}
+
void ScriptApiEnv::environment_OnMapgenInit(MapgenParams *mgparams)
{
SCRIPTAPI_PRECHECKHEADER
diff --git a/src/script/cpp_api/s_env.h b/src/script/cpp_api/s_env.h
index 51cf15036..33bd81ab3 100644
--- a/src/script/cpp_api/s_env.h
+++ b/src/script/cpp_api/s_env.h
@@ -37,6 +37,9 @@ public:
// After initializing mapgens
void environment_OnMapgenInit(MapgenParams *mgparams);
+ //called on player event
+ void player_event(ServerActiveObject* player, std::string type);
+
void initializeEnvironment(ServerEnvironment *env);
};
diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp
index 30d423e6a..704037437 100644
--- a/src/script/lua_api/l_object.cpp
+++ b/src/script/lua_api/l_object.cpp
@@ -906,6 +906,10 @@ int ObjectRef::l_hud_add(lua_State *L)
elem->scale = lua_istable(L, -1) ? read_v2f(L, -1) : v2f();
lua_pop(L, 1);
+ lua_getfield(L, 2, "size");
+ 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);
@@ -924,6 +928,11 @@ int ObjectRef::l_hud_add(lua_State *L)
elem->world_pos = lua_istable(L, -1) ? read_v3f(L, -1) : v3f();
lua_pop(L, 1);
+ /* check for known deprecated element usage */
+ if ((elem->type == HUD_ELEM_STATBAR) && (elem->size == v2s32())) {
+ log_deprecated(L,"Deprecated usage of statbar without size!");
+ }
+
u32 id = getServer(L)->hudAdd(player, elem);
if (id == (u32)-1) {
delete elem;
@@ -1019,6 +1028,10 @@ int ObjectRef::l_hud_change(lua_State *L)
e->world_pos = read_v3f(L, 4);
value = &e->world_pos;
break;
+ case HUD_STAT_SIZE:
+ e->size = read_v2s32(L, 4);
+ value = &e->size;
+ break;
}
getServer(L)->hudChange(player, id, stat, value);
@@ -1101,6 +1114,28 @@ int ObjectRef::l_hud_set_flags(lua_State *L)
return 1;
}
+int ObjectRef::l_hud_get_flags(lua_State *L)
+{
+ ObjectRef *ref = checkobject(L, 1);
+ Player *player = getplayer(ref);
+ if (player == NULL)
+ return 0;
+
+ lua_newtable(L);
+ lua_pushboolean(L, player->hud_flags & HUD_FLAG_HOTBAR_VISIBLE);
+ lua_setfield(L, -2, "hotbar");
+ lua_pushboolean(L, player->hud_flags & HUD_FLAG_HEALTHBAR_VISIBLE);
+ lua_setfield(L, -2, "healthbar");
+ lua_pushboolean(L, player->hud_flags & HUD_FLAG_CROSSHAIR_VISIBLE);
+ lua_setfield(L, -2, "crosshair");
+ lua_pushboolean(L, player->hud_flags & HUD_FLAG_WIELDITEM_VISIBLE);
+ lua_setfield(L, -2, "wielditem");
+ lua_pushboolean(L, player->hud_flags & HUD_FLAG_BREATHBAR_VISIBLE);
+ lua_setfield(L, -2, "breathbar");
+
+ return 1;
+}
+
// hud_set_hotbar_itemcount(self, hotbar_itemcount)
int ObjectRef::l_hud_set_hotbar_itemcount(lua_State *L)
{
@@ -1321,6 +1356,7 @@ const luaL_reg ObjectRef::methods[] = {
luamethod(ObjectRef, hud_change),
luamethod(ObjectRef, hud_get),
luamethod(ObjectRef, hud_set_flags),
+ luamethod(ObjectRef, hud_get_flags),
luamethod(ObjectRef, hud_set_hotbar_itemcount),
luamethod(ObjectRef, hud_set_hotbar_image),
luamethod(ObjectRef, hud_set_hotbar_selected_image),
diff --git a/src/script/lua_api/l_object.h b/src/script/lua_api/l_object.h
index f6070585d..d51ca379f 100644
--- a/src/script/lua_api/l_object.h
+++ b/src/script/lua_api/l_object.h
@@ -216,6 +216,9 @@ private:
// hud_set_flags(self, flags)
static int l_hud_set_flags(lua_State *L);
+ // hud_get_flags()
+ static int l_hud_get_flags(lua_State *L);
+
// hud_set_hotbar_itemcount(self, hotbar_itemcount)
static int l_hud_set_hotbar_itemcount(lua_State *L);