diff --git a/res/layouts/pages/settings-audio.xml b/res/layouts/pages/settings-audio.xml index 27fd4097..61f3ee89 100644 --- a/res/layouts/pages/settings-audio.xml +++ b/res/layouts/pages/settings-audio.xml @@ -1,23 +1,6 @@ - - - - - - - - - - + + + diff --git a/res/layouts/pages/settings-audio.xml.lua b/res/layouts/pages/settings-audio.xml.lua index dd09fefc..f23426e8 100644 --- a/res/layouts/pages/settings-audio.xml.lua +++ b/res/layouts/pages/settings-audio.xml.lua @@ -1,4 +1,12 @@ function on_open() + new_volume_control("audio.volume-master", "master") + new_volume_control("audio.volume-regular", "regular") + new_volume_control("audio.volume-ui", "ui") + new_volume_control("audio.volume-ambient", "ambient") + new_volume_control("audio.volume-music", "music") + + gui.reindex("core:pages/settings-audio") + on_master_change() on_regular_change() on_ui_change() @@ -6,32 +14,45 @@ function on_open() on_music_change() end -function on_volume_change(setting, label, name, val) + +function new_volume_control(setting, id, name) + -- value text label + document.tracks_panel:add("") + -- value track-bar + document.tracks_panel:add(string.format( + "" + , id, id)) +end + +function on_volume_change(setting, id, name, val) if val ~= nil then core.set_setting(setting, val) + else + document["t_"..id].value = core.get_setting(setting, val) end - label.text = ( + document["l_"..id].text = ( gui.str(name, "settings")..": ".. core.str_setting(setting) ) end function on_master_change(val) - on_volume_change("audio.volume-master", document.l_master, "Master Volume", val) + on_volume_change("audio.volume-master", "master", "Master Volume", val) end function on_regular_change(val) - on_volume_change("audio.volume-regular", document.l_regular, "Regular Sounds", val) + on_volume_change("audio.volume-regular", "regular", "Regular Sounds", val) end function on_ui_change(val) - on_volume_change("audio.volume-ui", document.l_ui, "UI Sounds", val) + on_volume_change("audio.volume-ui", "ui", "UI Sounds", val) end function on_ambient_change(val) - on_volume_change("audio.volume-ambient", document.l_ambient, "Ambient", val) + on_volume_change("audio.volume-ambient", "ambient", "Ambient", val) end function on_music_change(val) - on_volume_change("audio.volume-music", document.l_music, "Music", val) + on_volume_change("audio.volume-music", "music", "Music", val) end diff --git a/src/frontend/UiDocument.cpp b/src/frontend/UiDocument.cpp index d68ff06c..01d74aff 100644 --- a/src/frontend/UiDocument.cpp +++ b/src/frontend/UiDocument.cpp @@ -13,9 +13,12 @@ UiDocument::UiDocument( std::shared_ptr root, std::unique_ptr env ) : id(id), script(script), root(root), env(std::move(env)) { - collect(map, root); + buildIndices(map, root); } +void UiDocument::rebuildIndices() { + buildIndices(map, root); +} const uinodes_map& UiDocument::getMap() const { return map; @@ -45,7 +48,7 @@ int UiDocument::getEnvironment() const { return env->getId(); } -void UiDocument::collect(uinodes_map& map, std::shared_ptr node) { +void UiDocument::buildIndices(uinodes_map& map, std::shared_ptr node) { const std::string& id = node->getId(); if (!id.empty()) { map[id] = node; @@ -53,7 +56,7 @@ void UiDocument::collect(uinodes_map& map, std::shared_ptr node) { auto container = std::dynamic_pointer_cast(node); if (container) { for (auto subnode : container->getNodes()) { - collect(map, subnode); + buildIndices(map, subnode); } } } diff --git a/src/frontend/UiDocument.h b/src/frontend/UiDocument.h index 8583f34d..1de3c7ac 100644 --- a/src/frontend/UiDocument.h +++ b/src/frontend/UiDocument.h @@ -38,14 +38,16 @@ public: std::unique_ptr env ); + void rebuildIndices(); + const std::string& getId() const; const uinodes_map& getMap() const; const std::shared_ptr getRoot() const; const std::shared_ptr get(const std::string& id) const; const uidocscript& getScript() const; int getEnvironment() const; - /* Collect map of all uinodes having identifiers */ - static void collect(uinodes_map& map, std::shared_ptr node); + // @brief Collect map of all uinodes having identifiers + static void buildIndices(uinodes_map& map, std::shared_ptr node); static std::unique_ptr read(int env, std::string name, fs::path file); static std::shared_ptr readElement(fs::path file); diff --git a/src/graphics/ui/gui_util.cpp b/src/graphics/ui/gui_util.cpp index dbc9fd62..6b4dc96e 100644 --- a/src/graphics/ui/gui_util.cpp +++ b/src/graphics/ui/gui_util.cpp @@ -31,10 +31,12 @@ std::shared_ptr