Merge pull request #339 from ChancellorIkseew/add-bindings-block/unblock
add lua function block/unblock bindings
This commit is contained in:
commit
47c6c98b4a
@ -60,6 +60,8 @@ static int l_close_world(lua::State* L) {
|
||||
if (save_world) {
|
||||
controller->saveWorld();
|
||||
}
|
||||
// unblock all bindings
|
||||
Events::enableBindings();
|
||||
// destroy LevelScreen and run quit callbacks
|
||||
engine->setScreen(nullptr);
|
||||
// create and go to menu screen
|
||||
|
||||
@ -133,6 +133,17 @@ static int l_reset_bindings(lua::State*) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_enable_binding(lua::State* L) {
|
||||
std::string bindname = lua::require_string(L, 1);
|
||||
bool enable = lua::toboolean(L, 2);
|
||||
const auto& bind = Events::bindings.find(bindname);
|
||||
if (bind == Events::bindings.end()) {
|
||||
throw std::runtime_error("unknown binding " + util::quote(bindname));
|
||||
}
|
||||
Events::bindings[bindname].enable = enable;
|
||||
return 0;
|
||||
}
|
||||
|
||||
const luaL_Reg inputlib[] = {
|
||||
{"keycode", lua::wrap<l_keycode>},
|
||||
{"mousecode", lua::wrap<l_mousecode>},
|
||||
@ -143,4 +154,5 @@ const luaL_Reg inputlib[] = {
|
||||
{"is_active", lua::wrap<l_is_active>},
|
||||
{"is_pressed", lua::wrap<l_is_pressed>},
|
||||
{"reset_bindings", lua::wrap<l_reset_bindings>},
|
||||
{"enable_binding", lua::wrap<l_enable_binding>},
|
||||
{NULL, NULL}};
|
||||
|
||||
@ -78,6 +78,10 @@ void Events::pollEvents() {
|
||||
|
||||
for (auto& entry : bindings) {
|
||||
auto& binding = entry.second;
|
||||
if (!binding.enable) {
|
||||
binding.state = false;
|
||||
continue;
|
||||
}
|
||||
binding.justChange = false;
|
||||
|
||||
bool newstate = false;
|
||||
@ -228,3 +232,10 @@ void Events::loadBindings(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Events::enableBindings() {
|
||||
for (auto& entry : bindings) {
|
||||
auto& binding = entry.second;
|
||||
binding.enable = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -60,4 +60,5 @@ public:
|
||||
const std::string& filename, const std::string& source,
|
||||
BindType bindType
|
||||
);
|
||||
static void enableBindings();
|
||||
};
|
||||
|
||||
@ -137,6 +137,7 @@ struct Binding {
|
||||
int code;
|
||||
bool state = false;
|
||||
bool justChange = false;
|
||||
bool enable = true;
|
||||
|
||||
Binding() = default;
|
||||
Binding(inputtype type, int code) : type(type), code(code) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user