mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-07-25 19:51:37 +00:00
Support assigning functions to hotkeys from the JS GUI without involving a GUI object.
Allows developers and modders to register and unregister hotkeys without having to specify, change or overwrite XML files. Also allows implementing the main menu GUI page with only GUI objects for one submenu, refs #5387 / D2240. Differential Revision: https://code.wildfiregames.com/D2260 Idea by nani in D2257. This was SVN commit r22851.
This commit is contained in:
@@ -61,6 +61,18 @@ JS::Value JSI_GUIManager::GetGUIObjectByName(ScriptInterface::CxPrivate* pCxPriv
|
||||
return JS::ObjectValue(*guiObj->GetJSObject());
|
||||
}
|
||||
|
||||
void JSI_GUIManager::SetGlobalHotkey(ScriptInterface::CxPrivate* pCxPrivate, const std::string& hotkeyTag, JS::HandleValue function)
|
||||
{
|
||||
CGUI* guiPage = static_cast<CGUI*>(pCxPrivate->pCBData);
|
||||
guiPage->SetGlobalHotkey(hotkeyTag, function);
|
||||
}
|
||||
|
||||
void JSI_GUIManager::UnsetGlobalHotkey(ScriptInterface::CxPrivate* pCxPrivate, const std::string& hotkeyTag)
|
||||
{
|
||||
CGUI* guiPage = static_cast<CGUI*>(pCxPrivate->pCBData);
|
||||
guiPage->UnsetGlobalHotkey(hotkeyTag);
|
||||
}
|
||||
|
||||
std::wstring JSI_GUIManager::SetCursor(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& name)
|
||||
{
|
||||
std::wstring old = g_CursorName;
|
||||
@@ -87,6 +99,8 @@ void JSI_GUIManager::RegisterScriptFunctions(const ScriptInterface& scriptInterf
|
||||
{
|
||||
scriptInterface.RegisterFunction<void, std::wstring, JS::HandleValue, JS::HandleValue, &PushGuiPage>("PushGuiPage");
|
||||
scriptInterface.RegisterFunction<void, std::wstring, JS::HandleValue, &SwitchGuiPage>("SwitchGuiPage");
|
||||
scriptInterface.RegisterFunction<void, std::string, JS::HandleValue, &SetGlobalHotkey>("SetGlobalHotkey");
|
||||
scriptInterface.RegisterFunction<void, std::string, &UnsetGlobalHotkey>("UnsetGlobalHotkey");
|
||||
scriptInterface.RegisterFunction<void, JS::HandleValue, &PopGuiPage>("PopGuiPage");
|
||||
scriptInterface.RegisterFunction<JS::Value, std::string, &GetGUIObjectByName>("GetGUIObjectByName");
|
||||
scriptInterface.RegisterFunction<std::wstring, std::wstring, &SetCursor>("SetCursor");
|
||||
|
||||
Reference in New Issue
Block a user