diff --git a/code/components/nui-resources/src/ResourceUIScripting.cpp b/code/components/nui-resources/src/ResourceUIScripting.cpp index 28442272ea..6197a06d58 100644 --- a/code/components/nui-resources/src/ResourceUIScripting.cpp +++ b/code/components/nui-resources/src/ResourceUIScripting.cpp @@ -425,6 +425,36 @@ static InitFunction initFunction([] () context.SetResult(nui::HasFocusKeepInput()); }); + fx::ScriptEngine::RegisterNativeHandler("SET_NUI_ZINDEX", [](fx::ScriptContext& context) + { + fx::OMPtr runtime; + + if (FX_FAILED(fx::GetCurrentScriptRuntime(&runtime))) + { + return; + } + + fx::Resource* resource = reinterpret_cast(runtime->GetParentObject()); + if (!resource) + { + return; + } + + fwRefContainer resourceUI = resource->GetComponent(); + if (!resourceUI.GetRef() || !resourceUI->HasFrame()) + { + return; + } + + if (resource->GetName().find('"') != std::string::npos) + { + return; + } + + int zIndex = context.GetArgument(0); + nui::PostRootMessage(fmt::sprintf(R"({ "type": "setZIndex", "frameName": "%s", "zIndex": "%d" })", resource->GetName(), zIndex)); + }); + fx::ScriptEngine::RegisterNativeHandler("SET_NUI_FOCUS", [] (fx::ScriptContext& context) { fx::OMPtr runtime; diff --git a/ext/native-decls/SetNuiZindex.md b/ext/native-decls/SetNuiZindex.md new file mode 100644 index 0000000000..f3616e1995 --- /dev/null +++ b/ext/native-decls/SetNuiZindex.md @@ -0,0 +1,13 @@ +--- +ns: CFX +apiset: client +--- +## SET_NUI_ZINDEX + +```c +void SET_NUI_ZINDEX(int zIndex); +``` +Set the z-index of the NUI resource. + +## Parameters +* **zIndex**: New z-index value. diff --git a/ext/ui-build/data/root.html b/ext/ui-build/data/root.html index 9a4f700fe9..59dfde464b 100644 --- a/ext/ui-build/data/root.html +++ b/ext/ui-build/data/root.html @@ -55,6 +55,11 @@ handoverBlob = data.data; } else if (data.type == 'setServerAddress') { serverAddress = data.data; + } else if (data.type == 'setZIndex') { + const { frameName, zIndex } = data; + if (frameName in citFrames) { + citFrames[frameName].style.zIndex = zIndex; + } } break; }