mirror of
https://github.com/OpenMW/openmw.git
synced 2025-04-13 08:58:35 +00:00
Merge branch 'keep-menu-actions-after-load' into 'master'
#8365 Keep MENU-registered input actions between games See merge request OpenMW/openmw!4554
This commit is contained in:
commit
6e9d15f91d
@ -38,10 +38,10 @@ namespace
|
||||
sol::state lua;
|
||||
LuaUtil::InputAction::Registry registry;
|
||||
LuaUtil::InputAction::Info a({ "a", LuaUtil::InputAction::Type::Boolean, "test", "a_name", "a_description",
|
||||
sol::make_object(lua, false) });
|
||||
sol::make_object(lua, false), false });
|
||||
registry.insert(a);
|
||||
LuaUtil::InputAction::Info b({ "b", LuaUtil::InputAction::Type::Boolean, "test", "b_name", "b_description",
|
||||
sol::make_object(lua, false) });
|
||||
sol::make_object(lua, false), false });
|
||||
registry.insert(b);
|
||||
LuaUtil::Callback bindA({ lua.load("return function() return true end")(), sol::table(lua, sol::create) });
|
||||
LuaUtil::Callback bindBToA(
|
||||
|
@ -139,16 +139,18 @@ namespace MWLua
|
||||
}));
|
||||
|
||||
api["actions"] = std::ref(context.mLuaManager->inputActions());
|
||||
api["registerAction"] = [manager = context.mLuaManager](sol::table options) {
|
||||
LuaUtil::InputAction::Info parsedOptions;
|
||||
parsedOptions.mKey = options["key"].get<std::string_view>();
|
||||
parsedOptions.mType = options["type"].get<LuaUtil::InputAction::Type>();
|
||||
parsedOptions.mL10n = options["l10n"].get<std::string_view>();
|
||||
parsedOptions.mName = options["name"].get<std::string_view>();
|
||||
parsedOptions.mDescription = options["description"].get<std::string_view>();
|
||||
parsedOptions.mDefaultValue = options["defaultValue"].get<sol::main_object>();
|
||||
manager->inputActions().insert(std::move(parsedOptions));
|
||||
};
|
||||
api["registerAction"]
|
||||
= [manager = context.mLuaManager, persistent = context.mType == Context::Menu](sol::table options) {
|
||||
LuaUtil::InputAction::Info parsedOptions;
|
||||
parsedOptions.mKey = options["key"].get<std::string_view>();
|
||||
parsedOptions.mType = options["type"].get<LuaUtil::InputAction::Type>();
|
||||
parsedOptions.mL10n = options["l10n"].get<std::string_view>();
|
||||
parsedOptions.mName = options["name"].get<std::string_view>();
|
||||
parsedOptions.mDescription = options["description"].get<std::string_view>();
|
||||
parsedOptions.mDefaultValue = options["defaultValue"].get<sol::main_object>();
|
||||
parsedOptions.mPersistent = persistent;
|
||||
manager->inputActions().insert(std::move(parsedOptions));
|
||||
};
|
||||
api["bindAction"] = [manager = context.mLuaManager](
|
||||
std::string_view key, const sol::table& callback, sol::table dependencies) {
|
||||
std::vector<std::string_view> parsedDependencies;
|
||||
@ -178,14 +180,16 @@ namespace MWLua
|
||||
};
|
||||
|
||||
api["triggers"] = std::ref(context.mLuaManager->inputTriggers());
|
||||
api["registerTrigger"] = [manager = context.mLuaManager](sol::table options) {
|
||||
LuaUtil::InputTrigger::Info parsedOptions;
|
||||
parsedOptions.mKey = options["key"].get<std::string_view>();
|
||||
parsedOptions.mL10n = options["l10n"].get<std::string_view>();
|
||||
parsedOptions.mName = options["name"].get<std::string_view>();
|
||||
parsedOptions.mDescription = options["description"].get<std::string_view>();
|
||||
manager->inputTriggers().insert(std::move(parsedOptions));
|
||||
};
|
||||
api["registerTrigger"]
|
||||
= [manager = context.mLuaManager, persistent = context.mType == Context::Menu](sol::table options) {
|
||||
LuaUtil::InputTrigger::Info parsedOptions;
|
||||
parsedOptions.mKey = options["key"].get<std::string_view>();
|
||||
parsedOptions.mL10n = options["l10n"].get<std::string_view>();
|
||||
parsedOptions.mName = options["name"].get<std::string_view>();
|
||||
parsedOptions.mDescription = options["description"].get<std::string_view>();
|
||||
parsedOptions.mPersistent = persistent;
|
||||
manager->inputTriggers().insert(std::move(parsedOptions));
|
||||
};
|
||||
api["registerTriggerHandler"]
|
||||
= [manager = context.mLuaManager](std::string_view key, const sol::table& callback) {
|
||||
manager->inputTriggers().registerHandler(key, LuaUtil::Callback::fromLua(callback));
|
||||
|
@ -654,8 +654,8 @@ namespace MWLua
|
||||
MWBase::Environment::get().getL10nManager()->dropCache();
|
||||
mUiResourceManager.clear();
|
||||
mLua.dropScriptCache();
|
||||
mInputActions.clear();
|
||||
mInputTriggers.clear();
|
||||
mInputActions.clear(true);
|
||||
mInputTriggers.clear(true);
|
||||
initConfiguration();
|
||||
|
||||
ESM::LuaScripts globalData;
|
||||
|
@ -239,6 +239,29 @@ namespace LuaUtil
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void Registry::clear(bool force)
|
||||
{
|
||||
std::vector<Info> infoToKeep;
|
||||
if (!force)
|
||||
{
|
||||
for (const Info& info : mInfo)
|
||||
if (info.mPersistent)
|
||||
infoToKeep.push_back(info);
|
||||
}
|
||||
mKeys.clear();
|
||||
mIds.clear();
|
||||
mInfo.clear();
|
||||
mHandlers.clear();
|
||||
mBindings.clear();
|
||||
mValues.clear();
|
||||
mBindingTree.clear();
|
||||
if (!force)
|
||||
{
|
||||
for (const Info& i : infoToKeep)
|
||||
insert(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace InputTrigger
|
||||
@ -292,5 +315,24 @@ namespace LuaUtil
|
||||
}),
|
||||
handlers.end());
|
||||
}
|
||||
|
||||
void Registry::clear(bool force)
|
||||
{
|
||||
std::vector<Info> infoToKeep;
|
||||
if (!force)
|
||||
{
|
||||
for (const Info& info : mInfo)
|
||||
if (info.mPersistent)
|
||||
infoToKeep.push_back(info);
|
||||
}
|
||||
mInfo.clear();
|
||||
mHandlers.clear();
|
||||
mIds.clear();
|
||||
if (!force)
|
||||
{
|
||||
for (const Info& i : infoToKeep)
|
||||
insert(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ namespace LuaUtil::InputAction
|
||||
std::string mName;
|
||||
std::string mDescription;
|
||||
sol::main_object mDefaultValue;
|
||||
bool mPersistent;
|
||||
};
|
||||
|
||||
class MultiTree
|
||||
@ -73,16 +74,7 @@ namespace LuaUtil::InputAction
|
||||
{
|
||||
mHandlers[safeIdByKey(key)].push_back(handler);
|
||||
}
|
||||
void clear()
|
||||
{
|
||||
mKeys.clear();
|
||||
mIds.clear();
|
||||
mInfo.clear();
|
||||
mHandlers.clear();
|
||||
mBindings.clear();
|
||||
mValues.clear();
|
||||
mBindingTree.clear();
|
||||
}
|
||||
void clear(bool force = false);
|
||||
|
||||
private:
|
||||
using Id = MultiTree::Node;
|
||||
@ -110,6 +102,7 @@ namespace LuaUtil::InputTrigger
|
||||
std::string mL10n;
|
||||
std::string mName;
|
||||
std::string mDescription;
|
||||
bool mPersistent;
|
||||
};
|
||||
|
||||
class Registry
|
||||
@ -130,12 +123,7 @@ namespace LuaUtil::InputTrigger
|
||||
void insert(const Info& info);
|
||||
void registerHandler(std::string_view key, const LuaUtil::Callback& callback);
|
||||
void activate(std::string_view key);
|
||||
void clear()
|
||||
{
|
||||
mInfo.clear();
|
||||
mHandlers.clear();
|
||||
mIds.clear();
|
||||
}
|
||||
void clear(bool force = false);
|
||||
|
||||
private:
|
||||
using Id = size_t;
|
||||
|
Loading…
x
Reference in New Issue
Block a user