diff --git a/res/scripts/stdlib.lua b/res/scripts/stdlib.lua index eedc9d43..3cbf60a4 100644 --- a/res/scripts/stdlib.lua +++ b/res/scripts/stdlib.lua @@ -47,6 +47,7 @@ local function complete_app_lib(app) end app.reset_content = core.reset_content app.is_content_loaded = core.is_content_loaded + app.set_title = core.set_title function app.config_packs(packs_list) -- Check if packs are valid and add dependencies to the configuration diff --git a/src/engine/WindowControl.cpp b/src/engine/WindowControl.cpp index 5ae96965..a93c1599 100644 --- a/src/engine/WindowControl.cpp +++ b/src/engine/WindowControl.cpp @@ -33,11 +33,12 @@ WindowControl::Result WindowControl::initialize() { auto& settings = engine.getSettings(); std::string title = project.title; - if (title.empty()) { - title = "VoxelCore v" + - std::to_string(ENGINE_VERSION_MAJOR) + "." + - std::to_string(ENGINE_VERSION_MINOR); + if (!title.empty()) { + title += " - "; } + title += "VoxelCore v" + + std::to_string(ENGINE_VERSION_MAJOR) + "." + + std::to_string(ENGINE_VERSION_MINOR); if (ENGINE_DEBUG_BUILD) { title += " [debug]"; } diff --git a/src/logic/scripting/lua/libs/libcore.cpp b/src/logic/scripting/lua/libs/libcore.cpp index 8f8a7bc8..3989fd7f 100644 --- a/src/logic/scripting/lua/libs/libcore.cpp +++ b/src/logic/scripting/lua/libs/libcore.cpp @@ -25,6 +25,7 @@ #include "graphics/ui/gui_util.hpp" #include "graphics/ui/GUI.hpp" #include "graphics/ui/elements/Menu.hpp" +#include "window/Window.hpp" using namespace scripting; @@ -298,6 +299,12 @@ static int l_capture_output(lua::State* L) { return 1; } +static int l_set_title(lua::State* L) { + auto title = lua::require_string(L, 1); + engine->getWindow().setTitle(title); + return 0; +} + const luaL_Reg corelib[] = { {"blank", lua::wrap}, {"get_version", lua::wrap}, @@ -319,5 +326,6 @@ const luaL_Reg corelib[] = { {"open_url", lua::wrap}, {"quit", lua::wrap}, {"capture_output", lua::wrap}, + {"set_title", lua::wrap}, {nullptr, nullptr} }; diff --git a/src/window/Window.hpp b/src/window/Window.hpp index 71004470..a5a3240b 100644 --- a/src/window/Window.hpp +++ b/src/window/Window.hpp @@ -36,6 +36,7 @@ public: virtual void setMode(WindowMode mode) = 0; virtual WindowMode getMode() const = 0; + virtual void setTitle(const std::string& title) = 0; virtual void setIcon(const ImageData* image) = 0; virtual void pushScissor(glm::vec4 area) = 0; diff --git a/src/window/detail/GLFWWindow.cpp b/src/window/detail/GLFWWindow.cpp index a80c10e0..236ce16d 100644 --- a/src/window/detail/GLFWWindow.cpp +++ b/src/window/detail/GLFWWindow.cpp @@ -468,6 +468,10 @@ public: return mode; } + void setTitle(const std::string& title) override { + glfwSetWindowTitle(window, title.c_str()); + } + void setIcon(const ImageData* image) override { if (image == nullptr) { glfwSetWindowIcon(window, 0, nullptr);