From 4a74e56edad300c17a3c06cf4c9e9dc913a606d9 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Thu, 14 Nov 2024 21:18:36 +0300 Subject: [PATCH] add update_settings --- res/content/base/scripts/hud.lua | 5 +++-- src/graphics/render/TextNote.cpp | 4 ++++ src/graphics/render/TextNote.hpp | 2 ++ src/logic/scripting/lua/libs/libtext3d.cpp | 8 ++++++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/res/content/base/scripts/hud.lua b/res/content/base/scripts/hud.lua index b53dbbd7c..55b78fa64 100644 --- a/res/content/base/scripts/hud.lua +++ b/res/content/base/scripts/hud.lua @@ -35,6 +35,7 @@ function on_hud_open() end function on_hud_render() - local pos = gfx.text3d.get_pos(textid) - gfx.text3d.set_pos(textid, {pos[1], pos[2]+time.delta(), pos[3]}) + gfx.text3d.update_settings(textid, { + color={math.sin(time.uptime() * 12) * 0.5 + 0.5, 0, 0, 1} + }) end diff --git a/src/graphics/render/TextNote.cpp b/src/graphics/render/TextNote.cpp index cdce1549c..b5136279c 100644 --- a/src/graphics/render/TextNote.cpp +++ b/src/graphics/render/TextNote.cpp @@ -18,6 +18,10 @@ const NotePreset& TextNote::getPreset() const { return preset; } +void TextNote::updatePreset(const dv::value& data) { + preset.deserialize(data); +} + void TextNote::setPosition(const glm::vec3& position) { this->position = position; } diff --git a/src/graphics/render/TextNote.hpp b/src/graphics/render/TextNote.hpp index d7982fce1..e16afd30c 100644 --- a/src/graphics/render/TextNote.hpp +++ b/src/graphics/render/TextNote.hpp @@ -16,6 +16,8 @@ class TextNote { const NotePreset& getPreset() const; + void updatePreset(const dv::value& data); + void setPosition(const glm::vec3& position); const glm::vec3& getPosition() const; diff --git a/src/logic/scripting/lua/libs/libtext3d.cpp b/src/logic/scripting/lua/libs/libtext3d.cpp index e29f4e5ba..4469e792f 100644 --- a/src/logic/scripting/lua/libs/libtext3d.cpp +++ b/src/logic/scripting/lua/libs/libtext3d.cpp @@ -56,6 +56,13 @@ static int l_set_pos(lua::State* L) { return 0; } +static int l_update_settings(lua::State* L) { + if (auto note = renderer->texts->get(lua::tointeger(L, 1))) { + note->updatePreset(lua::tovalue(L, 2)); + } + return 0; +} + const luaL_Reg text3dlib[] = { {"show", lua::wrap}, {"hide", lua::wrap}, @@ -63,5 +70,6 @@ const luaL_Reg text3dlib[] = { {"set_text", lua::wrap}, {"get_pos", lua::wrap}, {"set_pos", lua::wrap}, + {"update_settings", lua::wrap}, {NULL, NULL} };