Merge branch 'main' into devtools
This commit is contained in:
commit
0a45987811
@ -252,6 +252,9 @@ static int p_is_enabled(UINode* node) {
|
||||
static int p_move_into(UINode*) {
|
||||
return state->pushcfunction(l_uinode_move_into);
|
||||
}
|
||||
static int p_get_focused(UINode* node) {
|
||||
return state->pushboolean(node->isFocused());
|
||||
}
|
||||
|
||||
static int l_gui_getattr(lua_State* L) {
|
||||
auto docname = lua_tostring(L, 1);
|
||||
@ -287,6 +290,7 @@ static int l_gui_getattr(lua_State* L) {
|
||||
{"back", p_get_back},
|
||||
{"reset", p_get_reset},
|
||||
{"inventory", p_get_inventory},
|
||||
{"focused", p_get_focused},
|
||||
};
|
||||
auto func = getters.find(attr);
|
||||
if (func != getters.end()) {
|
||||
@ -390,6 +394,13 @@ static void p_set_inventory(UINode* node, int idx) {
|
||||
}
|
||||
}
|
||||
}
|
||||
static void p_set_focused(std::shared_ptr<UINode> node, int idx) {
|
||||
if (state->toboolean(idx) && !node->isFocused()) {
|
||||
scripting::engine->getGUI()->setFocus(node);
|
||||
} else if (node->isFocused()){
|
||||
node->defocus();
|
||||
}
|
||||
}
|
||||
|
||||
static int l_gui_setattr(lua_State* L) {
|
||||
auto docname = lua_tostring(L, 1);
|
||||
@ -425,6 +436,13 @@ static int l_gui_setattr(lua_State* L) {
|
||||
if (func != setters.end()) {
|
||||
func->second(node.get(), 4);
|
||||
}
|
||||
static const std::unordered_map<std::string_view, std::function<void(std::shared_ptr<UINode>,int)>> setters2 {
|
||||
{"focused", p_set_focused},
|
||||
};
|
||||
auto func2 = setters2.find(attr);
|
||||
if (func2 != setters2.end()) {
|
||||
func2->second(node, 4);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
#include "../../../window/input.hpp"
|
||||
#include "../../../window/Events.hpp"
|
||||
#include "../../../util/stringutil.hpp"
|
||||
#include "../../../graphics/ui/GUI.hpp"
|
||||
#include "../../../frontend/screens/Screen.hpp"
|
||||
#include "../../../frontend/hud.hpp"
|
||||
#include "../../../engine.hpp"
|
||||
@ -31,7 +32,11 @@ static int l_add_callback(lua_State* L) {
|
||||
throw std::runtime_error("unknown binding "+util::quote(bindname));
|
||||
}
|
||||
state->pushvalue(2);
|
||||
runnable callback = state->createRunnable();
|
||||
runnable callback = [=]() {
|
||||
if (!scripting::engine->getGUI()->isFocusCaught()) {
|
||||
state->createRunnable();
|
||||
}
|
||||
};
|
||||
if (hud) {
|
||||
hud->keepAlive(bind->second.onactived.add(callback));
|
||||
} else {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user