sets the named property of a specified gui node * * Instead of using specific setteres such as gui.set_position or gui.set_scale, * you can use gui.set instead and supply the property as a string or a hash. * While this function is similar to go.get and go.set, there are a few more restrictions * when operating in the gui namespace. Most notably, only these named propertie
| 885 | * ``` |
| 886 | */ |
| 887 | static int LuaSet(lua_State* L) |
| 888 | { |
| 889 | DM_LUA_STACK_CHECK(L, 0); |
| 890 | |
| 891 | Scene* scene = GuiScriptInstance_Check(L); |
| 892 | |
| 893 | dmhash_t property_hash = dmScript::CheckHashOrString(L, 2); |
| 894 | dmGui::PropDesc* pd = dmGui::GetPropertyDesc(property_hash); |
| 895 | |
| 896 | dmGameObject::PropertyVar property_var; |
| 897 | dmGameObject::PropertyResult result = dmGameObject::LuaToVar(L, 3, property_var); |
| 898 | |
| 899 | if (result != dmGameObject::PROPERTY_RESULT_OK) |
| 900 | { |
| 901 | return DM_LUA_ERROR("Property '%s' has an unsupported type", dmHashReverseSafe64(property_hash)); |
| 902 | } |
| 903 | |
| 904 | dmGameObject::LuaToPropertyOptionsResult options_result = {}; |
| 905 | |
| 906 | if (lua_gettop(L) > 3) |
| 907 | { |
| 908 | dmGameObject::LuaToPropertyOptions(L, 4, &options_result); |
| 909 | } |
| 910 | |
| 911 | if (dmScript::IsURL(L, 1)) |
| 912 | { |
| 913 | dmMessage::URL sender; |
| 914 | dmScript::GetURL(L, &sender); |
| 915 | dmMessage::URL target; |
| 916 | dmScript::ResolveURL(L, 1, &target, &sender); |
| 917 | bool is_self = (sender.m_Socket == target.m_Socket) && |
| 918 | (sender.m_Path == target.m_Path) && |
| 919 | (sender.m_Fragment == target.m_Fragment); |
| 920 | if (!is_self) |
| 921 | { |
| 922 | return DM_LUA_ERROR("'gui.set()' can only be used to change a property of the GUI component itself, use 'msg.url()'"); |
| 923 | } |
| 924 | dmGameObject::HInstance instance = (dmGameObject::HInstance)scene->m_Context->m_GetUserDataCallback(scene); |
| 925 | result = dmGameObject::SetProperty(instance, target.m_Fragment, property_hash, options_result.m_Options, property_var); |
| 926 | if (result != dmGameObject::PROPERTY_RESULT_OK) |
| 927 | { |
| 928 | return HandleGoSetResult(L, result, property_hash, instance, target, options_result.m_Options); |
| 929 | } |
| 930 | return 0; |
| 931 | } |
| 932 | HNode hnode; |
| 933 | LuaCheckNodeInternal(L, 1, &hnode); |
| 934 | |
| 935 | if (pd) |
| 936 | { |
| 937 | if (pd->m_Component == 0xff) |
| 938 | { |
| 939 | if (pd->m_Property == dmGui::PROPERTY_ROTATION) |
| 940 | { |
| 941 | Quat* q = dmScript::ToQuat(L, 3); |
| 942 | if (q) |
| 943 | { |
| 944 | dmGui::SetNodeProperty(scene, hnode, pd->m_Property, Vector4(*q)); |
nothing calls this directly
no test coverage detected