/** * @brief Checks whether the given node is a virtual confunc that can be overridden from inheriting nodes. * @param node The node to check (must be a confunc node). * @return @c true if the given node is a dummy node, @c false otherwise. */ static qboolean UI_ConFuncIsVirtual (const uiNode_t *const node) { /* magic way to know if it is a dummy node (used for inherited confunc) */ const uiNode_t *dummy = (const uiNode_t*) Cmd_GetUserdata(node->name); assert(node); assert(UI_NodeInstanceOf(node, "confunc")); return (dummy != NULL && dummy->parent == NULL); }
/** * @brief Callback every time the parent window is closed (pop from the active window stack) */ static void UI_ConFuncNodeClose (uiNode_t *node) { if (UI_ConFuncIsVirtual(node)) { const value_t *property = UI_GetPropertyFromBehaviour(node->behaviour, "onClick"); uiNode_t *userData = (uiNode_t*) Cmd_GetUserdata(node->name); UI_RemoveListener(userData, property, node); } }
/** * @brief Callback every time the parent window is opened (pushed into the active window stack) */ static void UI_ConFuncNodeInit (uiNode_t *node, linkedList_t *params) { if (UI_ConFuncIsVirtual(node)) { const value_t *property = UI_GetPropertyFromBehaviour(node->behaviour, "onClick"); uiNode_t *userData = (uiNode_t*) Cmd_GetUserdata(node->name); UI_AddListener(userData, property, node); } }
/** * @brief Checks whether the given node is a virtual confunc that can be overridden from inheriting nodes. * @param node The node to check (must be a confunc node). * @return @c true if the given node is a dummy node, @c false otherwise. */ static bool UI_ConFuncIsVirtual (const uiNode_t* const node) { /* magic way to know if it is a dummy node (used for inherited confunc) */ const uiNode_t* dummy = static_cast<const uiNode_t*>(Cmd_GetUserdata(node->name)); assert(node); assert(UI_NodeInstanceOf(node, "confunc")); return (dummy != nullptr && dummy->parent == nullptr); }
/** * @brief Callback every time the parent window is closed (pop from the active window stack) */ void uiConFuncNode::onWindowClosed (uiNode_t* node) { if (UI_ConFuncIsVirtual(node)) { const value_t* property = UI_GetPropertyFromBehaviour(node->behaviour, "onClick"); uiNode_t* userData = static_cast<uiNode_t*>(Cmd_GetUserdata(node->name)); UI_RemoveListener(userData, property, node); } }
/** * @brief Cleanup tasks on removing a console function * @param node The node to delete. */ void uiConFuncNode::deleteNode (uiNode_t* node) { onWindowClosed(node); if (Cmd_Exists(node->name)) { uiNode_t* userData = (uiNode_t*)Cmd_GetUserdata(node->name); if (userData && userData == node) Cmd_RemoveCommand(node->name); } uiNode::deleteNode(node); }