generated ui nodes indexing
This commit is contained in:
parent
e57b0eca15
commit
1a4c70d21a
@ -1,28 +1,27 @@
|
|||||||
function on_open()
|
function on_open()
|
||||||
new_volume_control("audio.volume-master", "master")
|
new_volume_control("audio.volume-master", "master", "Master Volume")
|
||||||
new_volume_control("audio.volume-regular", "regular")
|
new_volume_control("audio.volume-regular", "regular", "Regular Sounds")
|
||||||
new_volume_control("audio.volume-ui", "ui")
|
new_volume_control("audio.volume-ui", "ui", "UI Sounds")
|
||||||
new_volume_control("audio.volume-ambient", "ambient")
|
new_volume_control("audio.volume-ambient", "ambient", "Ambient")
|
||||||
new_volume_control("audio.volume-music", "music")
|
new_volume_control("audio.volume-music", "music", "Music")
|
||||||
|
|
||||||
gui.reindex("core:pages/settings-audio")
|
|
||||||
|
|
||||||
on_master_change()
|
|
||||||
on_regular_change()
|
|
||||||
on_ui_change()
|
|
||||||
on_ambient_change()
|
|
||||||
on_music_change()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function new_volume_control(setting, id, name)
|
function new_volume_control(setting, id, name)
|
||||||
-- value text label
|
-- value text label
|
||||||
document.tracks_panel:add("<label id='l_"..id.."'>-</label>")
|
document.tracks_panel:add("<label id='l_"..id.."'>-</label>")
|
||||||
-- value track-bar
|
-- value track-bar
|
||||||
document.tracks_panel:add(string.format(
|
document.tracks_panel:add(string.format(
|
||||||
"<trackbar id='t_%s' min='0' max='1' value='1' step='0.01' track-width='5' "..
|
"<trackbar id='t_%s' min='0' max='1' value='1' step='0.01' track-width='5' "..
|
||||||
" consumer='on_%s_change'/>"
|
" consumer='function(x) on_volume_change(%q, %q, %q, x) end'/>"
|
||||||
, id, id))
|
, id, setting, id, name))
|
||||||
|
refresh_label(setting, id, name)
|
||||||
|
end
|
||||||
|
|
||||||
|
function refresh_label(setting, id, name)
|
||||||
|
document["l_"..id].text = (
|
||||||
|
gui.str(name, "settings")..": "..
|
||||||
|
core.str_setting(setting)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_volume_change(setting, id, name, val)
|
function on_volume_change(setting, id, name, val)
|
||||||
@ -31,28 +30,5 @@ function on_volume_change(setting, id, name, val)
|
|||||||
else
|
else
|
||||||
document["t_"..id].value = core.get_setting(setting, val)
|
document["t_"..id].value = core.get_setting(setting, val)
|
||||||
end
|
end
|
||||||
document["l_"..id].text = (
|
refresh_label(setting, id, name)
|
||||||
gui.str(name, "settings")..": "..
|
|
||||||
core.str_setting(setting)
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
function on_master_change(val)
|
|
||||||
on_volume_change("audio.volume-master", "master", "Master Volume", val)
|
|
||||||
end
|
|
||||||
|
|
||||||
function on_regular_change(val)
|
|
||||||
on_volume_change("audio.volume-regular", "regular", "Regular Sounds", val)
|
|
||||||
end
|
|
||||||
|
|
||||||
function on_ui_change(val)
|
|
||||||
on_volume_change("audio.volume-ui", "ui", "UI Sounds", val)
|
|
||||||
end
|
|
||||||
|
|
||||||
function on_ambient_change(val)
|
|
||||||
on_volume_change("audio.volume-ambient", "ambient", "Ambient", val)
|
|
||||||
end
|
|
||||||
|
|
||||||
function on_music_change(val)
|
|
||||||
on_volume_change("audio.volume-music", "music", "Music", val)
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -13,17 +13,21 @@ UiDocument::UiDocument(
|
|||||||
std::shared_ptr<gui::UINode> root,
|
std::shared_ptr<gui::UINode> root,
|
||||||
std::unique_ptr<scripting::Environment> env
|
std::unique_ptr<scripting::Environment> env
|
||||||
) : id(id), script(script), root(root), env(std::move(env)) {
|
) : id(id), script(script), root(root), env(std::move(env)) {
|
||||||
buildIndices(map, root);
|
gui::UINode::getIndices(root, map);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UiDocument::rebuildIndices() {
|
void UiDocument::rebuildIndices() {
|
||||||
buildIndices(map, root);
|
gui::UINode::getIndices(root, map);
|
||||||
}
|
}
|
||||||
|
|
||||||
const uinodes_map& UiDocument::getMap() const {
|
const uinodes_map& UiDocument::getMap() const {
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uinodes_map& UiDocument::getMapWriteable() {
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
const std::string& UiDocument::getId() const {
|
const std::string& UiDocument::getId() const {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@ -48,19 +52,6 @@ int UiDocument::getEnvironment() const {
|
|||||||
return env->getId();
|
return env->getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UiDocument::buildIndices(uinodes_map& map, std::shared_ptr<gui::UINode> node) {
|
|
||||||
const std::string& id = node->getId();
|
|
||||||
if (!id.empty()) {
|
|
||||||
map[id] = node;
|
|
||||||
}
|
|
||||||
auto container = std::dynamic_pointer_cast<gui::Container>(node);
|
|
||||||
if (container) {
|
|
||||||
for (auto subnode : container->getNodes()) {
|
|
||||||
buildIndices(map, subnode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_ptr<UiDocument> UiDocument::read(int penv, std::string name, fs::path file) {
|
std::unique_ptr<UiDocument> UiDocument::read(int penv, std::string name, fs::path file) {
|
||||||
const std::string text = files::read_string(file);
|
const std::string text = files::read_string(file);
|
||||||
auto xmldoc = xml::parse(file.u8string(), text);
|
auto xmldoc = xml::parse(file.u8string(), text);
|
||||||
|
|||||||
@ -42,12 +42,11 @@ public:
|
|||||||
|
|
||||||
const std::string& getId() const;
|
const std::string& getId() const;
|
||||||
const uinodes_map& getMap() const;
|
const uinodes_map& getMap() const;
|
||||||
|
uinodes_map& getMapWriteable();
|
||||||
const std::shared_ptr<gui::UINode> getRoot() const;
|
const std::shared_ptr<gui::UINode> getRoot() const;
|
||||||
const std::shared_ptr<gui::UINode> get(const std::string& id) const;
|
const std::shared_ptr<gui::UINode> get(const std::string& id) const;
|
||||||
const uidocscript& getScript() const;
|
const uidocscript& getScript() const;
|
||||||
int getEnvironment() const;
|
int getEnvironment() const;
|
||||||
// @brief Collect map of all uinodes having identifiers
|
|
||||||
static void buildIndices(uinodes_map& map, std::shared_ptr<gui::UINode> node);
|
|
||||||
|
|
||||||
static std::unique_ptr<UiDocument> read(int env, std::string name, fs::path file);
|
static std::unique_ptr<UiDocument> read(int env, std::string name, fs::path file);
|
||||||
static std::shared_ptr<gui::UINode> readElement(fs::path file);
|
static std::shared_ptr<gui::UINode> readElement(fs::path file);
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
#include "UINode.h"
|
#include "UINode.h"
|
||||||
|
|
||||||
|
#include "containers.h"
|
||||||
#include "../../core/Batch2D.h"
|
#include "../../core/Batch2D.h"
|
||||||
|
|
||||||
using gui::UINode;
|
using gui::UINode;
|
||||||
@ -256,3 +257,19 @@ void UINode::setGravity(Gravity gravity) {
|
|||||||
reposition();
|
reposition();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UINode::getIndices(
|
||||||
|
std::shared_ptr<UINode> node,
|
||||||
|
std::unordered_map<std::string, std::shared_ptr<UINode>>& map
|
||||||
|
) {
|
||||||
|
const std::string& id = node->getId();
|
||||||
|
if (!id.empty()) {
|
||||||
|
map[id] = node;
|
||||||
|
}
|
||||||
|
auto container = std::dynamic_pointer_cast<gui::Container>(node);
|
||||||
|
if (container) {
|
||||||
|
for (auto subnode : container->getNodes()) {
|
||||||
|
getIndices(subnode, map);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <unordered_map>
|
||||||
#include "../../../delegates.h"
|
#include "../../../delegates.h"
|
||||||
#include "../../../window/input.h"
|
#include "../../../window/input.h"
|
||||||
|
|
||||||
@ -193,6 +194,12 @@ namespace gui {
|
|||||||
void reposition();
|
void reposition();
|
||||||
|
|
||||||
virtual void setGravity(Gravity gravity);
|
virtual void setGravity(Gravity gravity);
|
||||||
|
|
||||||
|
// @brief collect all nodes having id
|
||||||
|
static void getIndices(
|
||||||
|
std::shared_ptr<UINode> node,
|
||||||
|
std::unordered_map<std::string, std::shared_ptr<UINode>>& map
|
||||||
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -219,7 +219,9 @@ static int container_add(lua_State* L) {
|
|||||||
auto node = dynamic_cast<gui::Container*>(docnode.node);
|
auto node = dynamic_cast<gui::Container*>(docnode.node);
|
||||||
auto xmlsrc = lua_tostring(L, 2);
|
auto xmlsrc = lua_tostring(L, 2);
|
||||||
try {
|
try {
|
||||||
node->add(guiutil::create(xmlsrc, docnode.document->getEnvironment()));
|
auto subnode = guiutil::create(xmlsrc, docnode.document->getEnvironment());
|
||||||
|
node->add(subnode);
|
||||||
|
gui::UINode::getIndices(subnode, docnode.document->getMapWriteable());
|
||||||
} catch (const std::exception& err) {
|
} catch (const std::exception& err) {
|
||||||
luaL_error(L, err.what());
|
luaL_error(L, err.what());
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user