GetResourceGUIElement: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
mNo edit summary
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
{{Client function}}
{{Client function}}
This function retrieves a resource's GUI element. The resource's GUI element is the element in the element tree which is the default parent of all GUI elements that belong to a particular resource. This has the tag 'guiroot', and each resource has one of these.<!-- You can attach event handlers to this element to easily capture events that originate from your resource (and global events that originate from the root element). ---- Confirm please? ---- -->
This function retrieves a resource's GUI element. The resource's GUI element is the element in the element tree which is the default parent of all GUI elements that belong to a particular resource. It has a predefined variable called '''guiRoot''', and each resource has one of these. You can attach event handlers to this element to easily capture events that originate from your resource (and global events that originate from the root element).


==Syntax==
==Syntax==
<syntaxhighlight lang="lua">element getResourceGUIElement ( [resource theResource=getThisResource()] )</syntaxhighlight>
<syntaxhighlight lang="lua">element getResourceGUIElement ( [ resource theResource = getThisResource( ) ] )</syntaxhighlight>


===Optional Arguments===
===Optional Arguments===
{{OptionalArg}}
{{OptionalArg}}
*'''theResource:''' the resource whose GUI element we are getting. If not specified, assumes the current resource. (the resource returned from [[getThisResource]])
*'''theResource:''' the resource whose GUI element we are getting. If not specified, assumes the current resource.


===Returns===
===Returns===
Line 14: Line 14:


==Example==  
==Example==  
This example creates a window and a button with the cursor showing. If the player clicks on myButton then the window would be destroyed and the cursor would not show. (Not sure if this function works)
This example provides a function for destroying all the GUI elements of a resource.
<syntaxhighlight lang="lua">myWindow = guiCreateWindow ( 0, 0, 0.7, 0.5, "Information", true )
<syntaxhighlight lang="lua">function destroyAllGUIs()
myButton = guiCreateButton ( 0.7, 0.1, 0.2, 0.1, "Output!", true, myWindow )
-- Destroy all of the gui-root's children
showCursor(true)
for _, guiElement in ipairs(getElementChildren(getResourceGUIElement())) do
 
if isElement(guiElement) then -- This checks that the element still exists (in case we already destroyed it's parent).
addEventHandler("onClientGUIClick",getResourceGUIElement(),function()
destroyElement(guiElement)
if(source == myButton)then
end
destroyElement(myWindow)
showCursor(false)
end
end
end,false)
end
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{Client_resource_functions}}
{{Client_resource_functions}}
[[Category:Needs Example]]

Latest revision as of 21:12, 7 August 2018

This function retrieves a resource's GUI element. The resource's GUI element is the element in the element tree which is the default parent of all GUI elements that belong to a particular resource. It has a predefined variable called guiRoot, and each resource has one of these. You can attach event handlers to this element to easily capture events that originate from your resource (and global events that originate from the root element).

Syntax

element getResourceGUIElement ( [ resource theResource = getThisResource( ) ] )

Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.

  • theResource: the resource whose GUI element we are getting. If not specified, assumes the current resource.

Returns

Returns the root GUI element that contains all the other GUI elements.

Example

This example provides a function for destroying all the GUI elements of a resource.

function destroyAllGUIs()
	-- Destroy all of the gui-root's children
	for _, guiElement in ipairs(getElementChildren(getResourceGUIElement())) do
		if isElement(guiElement) then -- This checks that the element still exists (in case we already destroyed it's parent).
			destroyElement(guiElement)
		end
	end
end

See Also