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) {
|
if (save_world) {
|
||||||
controller->saveWorld();
|
controller->saveWorld();
|
||||||
}
|
}
|
||||||
|
// unblock all bindings
|
||||||
|
Events::enableBindings();
|
||||||
// destroy LevelScreen and run quit callbacks
|
// destroy LevelScreen and run quit callbacks
|
||||||
engine->setScreen(nullptr);
|
engine->setScreen(nullptr);
|
||||||
// create and go to menu screen
|
// create and go to menu screen
|
||||||
|
|||||||
@ -133,6 +133,17 @@ static int l_reset_bindings(lua::State*) {
|
|||||||
return 0;
|
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[] = {
|
const luaL_Reg inputlib[] = {
|
||||||
{"keycode", lua::wrap<l_keycode>},
|
{"keycode", lua::wrap<l_keycode>},
|
||||||
{"mousecode", lua::wrap<l_mousecode>},
|
{"mousecode", lua::wrap<l_mousecode>},
|
||||||
@ -143,4 +154,5 @@ const luaL_Reg inputlib[] = {
|
|||||||
{"is_active", lua::wrap<l_is_active>},
|
{"is_active", lua::wrap<l_is_active>},
|
||||||
{"is_pressed", lua::wrap<l_is_pressed>},
|
{"is_pressed", lua::wrap<l_is_pressed>},
|
||||||
{"reset_bindings", lua::wrap<l_reset_bindings>},
|
{"reset_bindings", lua::wrap<l_reset_bindings>},
|
||||||
|
{"enable_binding", lua::wrap<l_enable_binding>},
|
||||||
{NULL, NULL}};
|
{NULL, NULL}};
|
||||||
|
|||||||
@ -78,6 +78,10 @@ void Events::pollEvents() {
|
|||||||
|
|
||||||
for (auto& entry : bindings) {
|
for (auto& entry : bindings) {
|
||||||
auto& binding = entry.second;
|
auto& binding = entry.second;
|
||||||
|
if (!binding.enable) {
|
||||||
|
binding.state = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
binding.justChange = false;
|
binding.justChange = false;
|
||||||
|
|
||||||
bool newstate = 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,
|
const std::string& filename, const std::string& source,
|
||||||
BindType bindType
|
BindType bindType
|
||||||
);
|
);
|
||||||
|
static void enableBindings();
|
||||||
};
|
};
|
||||||
|
|||||||
@ -137,6 +137,7 @@ struct Binding {
|
|||||||
int code;
|
int code;
|
||||||
bool state = false;
|
bool state = false;
|
||||||
bool justChange = false;
|
bool justChange = false;
|
||||||
|
bool enable = true;
|
||||||
|
|
||||||
Binding() = default;
|
Binding() = default;
|
||||||
Binding(inputtype type, int code) : type(type), code(code) {
|
Binding(inputtype type, int code) : type(type), code(code) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user