Skip to content

Commit

Permalink
feat(nui): add SET_NUI_ZINDEX
Browse files Browse the repository at this point in the history
  • Loading branch information
poco8537 committed Dec 4, 2024
1 parent 5053bc6 commit 1d67b44
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
30 changes: 30 additions & 0 deletions code/components/nui-resources/src/ResourceUIScripting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,36 @@ static InitFunction initFunction([] ()
context.SetResult(nui::HasFocusKeepInput());
});

fx::ScriptEngine::RegisterNativeHandler("SET_NUI_ZINDEX", [](fx::ScriptContext& context)
{
fx::OMPtr<IScriptRuntime> runtime;

if (FX_FAILED(fx::GetCurrentScriptRuntime(&runtime)))
{
return;
}

fx::Resource* resource = reinterpret_cast<fx::Resource*>(runtime->GetParentObject());
if (!resource)
{
return;
}

fwRefContainer<ResourceUI> resourceUI = resource->GetComponent<ResourceUI>();
if (!resourceUI.GetRef() || !resourceUI->HasFrame())
{
return;
}

if (resource->GetName().find('"') != std::string::npos)
{
return;
}

int zIndex = context.GetArgument<int>(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<IScriptRuntime> runtime;
Expand Down
13 changes: 13 additions & 0 deletions ext/native-decls/SetNuiZindex.md
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 5 additions & 0 deletions ext/ui-build/data/root.html
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 1d67b44

Please sign in to comment.