diff --git a/.gitignore b/.gitignore index 1847e03c..a1ce6e33 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,7 @@ appimage-build/ /res/content/* !/res/content/base *.mtl + +# libs +/libs/ +/vcpkg_installed/ \ No newline at end of file diff --git a/res/layouts/pages/settings.xml b/res/layouts/pages/settings.xml index 07608086..f5ec33d7 100644 --- a/res/layouts/pages/settings.xml +++ b/res/layouts/pages/settings.xml @@ -11,6 +11,7 @@ + diff --git a/res/layouts/pages/settings.xml.lua b/res/layouts/pages/settings.xml.lua index 345d5620..24256c84 100644 --- a/res/layouts/pages/settings.xml.lua +++ b/res/layouts/pages/settings.xml.lua @@ -11,6 +11,7 @@ function set_page(btn, page) document.s_dsp.enabled = true document.s_gfx.enabled = true document.s_ctl.enabled = true + document.s_rst.enabled = true document[btn].enabled = false document.menu.page = page end diff --git a/res/layouts/pages/settings_display.xml.lua b/res/layouts/pages/settings_display.xml.lua index 492ddef9..a0bc9579 100644 --- a/res/layouts/pages/settings_display.xml.lua +++ b/res/layouts/pages/settings_display.xml.lua @@ -59,4 +59,5 @@ function on_open() create_checkbox("display.fullscreen", "Fullscreen") create_checkbox("camera.shaking", "Camera Shaking") create_checkbox("camera.inertia", "Camera Inertia") + create_checkbox("camera.fov-effects", "Camera FOV Effects") end diff --git a/res/layouts/pages/settings_reset.xml b/res/layouts/pages/settings_reset.xml new file mode 100644 index 00000000..e7bbc83a --- /dev/null +++ b/res/layouts/pages/settings_reset.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/res/layouts/pages/settings_reset.xml.lua b/res/layouts/pages/settings_reset.xml.lua new file mode 100644 index 00000000..a8ca2a9f --- /dev/null +++ b/res/layouts/pages/settings_reset.xml.lua @@ -0,0 +1,44 @@ +function reset(category) + if category == "aud" then + reset_audio() + elseif category == "dsp" then + reset_display() + elseif category == "gfx" then + reset_graphics() + elseif category == "ctl" then + reset_control() + end +end + +function reset_setting(name) + core.set_setting(name, core.get_setting_info(name).def) +end + +function reset_audio() + reset_setting("audio.volume-master") + reset_setting("audio.volume-regular") + reset_setting("audio.volume-ui") + reset_setting("audio.volume-ambient") + reset_setting("audio.volume-music") +end + +function reset_display() + reset_setting("camera.fov") + reset_setting("display.framerate") + reset_setting("display.fullscreen") + reset_setting("camera.shaking") + reset_setting("camera.inertia") + reset_setting("camera.fov-effects") +end + +function reset_graphics() + reset_setting("chunks.load-distance") + reset_setting("chunks.load-speed") + reset_setting("graphics.fog-curve") + reset_setting("graphics.gamma") + reset_setting("graphics.backlight") +end + +function reset_control() + input.reset_bindings() +end diff --git a/res/texts/ru_RU.txt b/res/texts/ru_RU.txt index 2b907a59..df8f945e 100644 --- a/res/texts/ru_RU.txt +++ b/res/texts/ru_RU.txt @@ -38,6 +38,7 @@ menu.Page not found=Страница не найдена menu.Quit=Выход menu.Save and Quit to Menu=Сохранить и Выйти в Меню menu.Settings=Настройки +menu.Reset settings=Сбросить настройки menu.Contents Menu=Меню контентпаков menu.Open data folder=Открыть папку данных menu.Open content folder=Открыть папку [content] @@ -59,6 +60,7 @@ settings.Ambient=Фон settings.Backlight=Подсветка settings.Camera Shaking=Тряска Камеры settings.Camera Inertia=Инерция Камеры +settings.Camera FOV Effects=Эффекты поля зрения settings.Fog Curve=Кривая Тумана settings.FOV=Поле Зрения settings.Fullscreen=Полный экран diff --git a/src/core_defs.cpp b/src/core_defs.cpp index 7d19acd1..7186aa72 100644 --- a/src/core_defs.cpp +++ b/src/core_defs.cpp @@ -31,7 +31,7 @@ void corecontent::setup(EnginePaths* paths, ContentBuilder* builder) { auto bindsFile = paths->getResourcesFolder()/fs::path("bindings.toml"); if (fs::is_regular_file(bindsFile)) { Events::loadBindings( - bindsFile.u8string(), files::read_string(bindsFile) + bindsFile.u8string(), files::read_string(bindsFile), BindType::BIND ); } diff --git a/src/engine.cpp b/src/engine.cpp index 6ba4fcee..c13e817b 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -131,7 +131,7 @@ void Engine::loadControls() { if (fs::is_regular_file(controls_file)) { logger.info() << "loading controls"; std::string text = files::read_string(controls_file); - Events::loadBindings(controls_file.u8string(), text); + Events::loadBindings(controls_file.u8string(), text, BindType::BIND); } } @@ -287,7 +287,7 @@ static void load_configs(const fs::path& root) { auto bindsFile = configFolder/fs::path("bindings.toml"); if (fs::is_regular_file(bindsFile)) { Events::loadBindings( - bindsFile.u8string(), files::read_string(bindsFile) + bindsFile.u8string(), files::read_string(bindsFile), BindType::BIND ); } } diff --git a/src/logic/scripting/lua/libs/libinput.cpp b/src/logic/scripting/lua/libs/libinput.cpp index 84dde256..53f1effd 100644 --- a/src/logic/scripting/lua/libs/libinput.cpp +++ b/src/logic/scripting/lua/libs/libinput.cpp @@ -1,4 +1,7 @@ +#include + #include "engine.hpp" +#include "files/files.hpp" #include "frontend/hud.hpp" #include "frontend/screens/Screen.hpp" #include "graphics/ui/GUI.hpp" @@ -109,6 +112,27 @@ static int l_is_pressed(lua::State* L) { } } +static void resetPackBindings(fs::path& packFolder) { + auto configFolder = packFolder/fs::path("config"); + auto bindsFile = configFolder/fs::path("bindings.toml"); + if (fs::is_regular_file(bindsFile)) { + Events::loadBindings( + bindsFile.u8string(), + files::read_string(bindsFile), + BindType::REBIND + ); + } +} + +static int l_reset_bindings(lua::State*) { + auto resFolder = engine->getPaths()->getResourcesFolder(); + resetPackBindings(resFolder); + for (auto& pack : engine->getContentPacks()) { + resetPackBindings(pack.folder); + } + return 0; +} + const luaL_Reg inputlib[] = { {"keycode", lua::wrap}, {"mousecode", lua::wrap}, @@ -118,4 +142,5 @@ const luaL_Reg inputlib[] = { {"get_binding_text", lua::wrap}, {"is_active", lua::wrap}, {"is_pressed", lua::wrap}, + {"reset_bindings", lua::wrap}, {NULL, NULL}}; diff --git a/src/window/Events.cpp b/src/window/Events.cpp index 092e4a0d..f310969b 100644 --- a/src/window/Events.cpp +++ b/src/window/Events.cpp @@ -106,9 +106,9 @@ void Events::pollEvents() { } Binding& Events::getBinding(const std::string& name) { - auto found = bindings.find(name); + const auto found = bindings.find(name); if (found == bindings.end()) { - throw std::runtime_error("binding '" + name + "' does not exists"); + throw std::runtime_error("binding '" + name + "' does not exist"); } return found->second; } @@ -126,6 +126,10 @@ void Events::bind(const std::string& name, inputtype type, int code) { } void Events::rebind(const std::string& name, inputtype type, int code) { + const auto& found = bindings.find(name); + if (found == bindings.end()) { + throw std::runtime_error("binding '" + name + "' does not exist"); + } bindings[name] = Binding(type, code); } @@ -193,7 +197,8 @@ std::string Events::writeBindings() { } void Events::loadBindings( - const std::string& filename, const std::string& source + const std::string& filename, const std::string& source, + BindType bindType ) { auto map = toml::parse(filename, source); for (auto& [sectionName, section] : map.asObject()) { @@ -214,7 +219,12 @@ void Events::loadBindings( << util::quote(key) << ")"; continue; } - Events::bind(key, type, code); + if (bindType == BindType::BIND) { + Events::bind(key, type, code); + } else if (bindType == BindType::REBIND) { + Events::rebind(key, type, code); + } + } } } diff --git a/src/window/Events.hpp b/src/window/Events.hpp index 230145a9..f5ed5720 100644 --- a/src/window/Events.hpp +++ b/src/window/Events.hpp @@ -9,6 +9,11 @@ inline constexpr short KEYS_BUFFER_SIZE = 1036; +enum class BindType { + BIND = 0, + REBIND = 1 +}; + class Events { static bool keys[KEYS_BUFFER_SIZE]; static uint frames[KEYS_BUFFER_SIZE]; @@ -52,6 +57,7 @@ public: static std::string writeBindings(); static void loadBindings( - const std::string& filename, const std::string& source + const std::string& filename, const std::string& source, + BindType bindType ); };