OnClientGUIClick: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(Change to resource root.)
 
(15 intermediate revisions by 10 users not shown)
Line 1: Line 1:
{{Client event}}
{{Client event}}
__NOTOC__
__NOTOC__
هذه الوظيفة تحدث عند نقر الاعب بالماوس على أي
This event happens when any gui-element clicked.
 
{{Note|The '''player''' who clicked the gui-element is always the [[localPlayer]].}}
gui-element


==Parameters==  
==Parameters==  
Line 9: Line 8:
string button, string state, int absoluteX, int absoluteY
string button, string state, int absoluteX, int absoluteY
</syntaxhighlight>
</syntaxhighlight>
*'''button:''' اسم الزر الذي سيتم الضغت عليه يمكنه ان يكون ''left'', ''right'', ''middle''
*'''button:''' the name of the button which will be clicked, it can be ''left'', ''right'', ''middle''.
*'''state:''' حالة الزر من الماوس فـ اذا تم النقر عليه
*'''state:''' the state of the mouse button, will be ''down'' if the mouse button was pushed, or ''up'' if it was released. '''Please note currently only the ''up'' state is supported.'''
 
*'''absoluteX:''' the X position of the mouse cursor, in pixels, measured from the left side of the screen.
''down''
*'''absoluteY:''' the Y position of the mouse cursor, in pixels, measured from the top of the screen.
 
التوقف عن الضغت على الزر
 
''up''
*'''absoluteX:''' مؤشر الماوس، بالبكسل، وتقاس من الجانب الأيسر من الشاشة
*'''absoluteY:''' مؤشر الماوس، بالبكسل، وتقاس من أعلى الشاشة


==Source==
==Source==
السورس في هذا الحدث هو اي
The [[event system#Event source|source]] of this event is the GUI element that was clicked.
 
{{Note|If the GUI Element attached to this event has a parent element, this event will be triggered once the parent element of the attached element is clicked too. You can set the parameter '''propagate''' to ''false'' in the call to [[addEventHandler]] to prevent this.}}
gui-element
 
تم النقر عليها


==Example==  
==Example==  
هذا المثال يُنشئ مربع تحرير جنبا إلى جنب مع "إخراج"! زر. عند النقر فوق الزر مع زر الماوس الأيسر، فإنه يخرج الرسالة من مربع التحرير الى مربع الدردشة.
This example creates an edit box alongside an "Output!" button. When the button is clicked with the left mouse button, it will output the message in the edit box into the chat box.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--[[ onClientResourceStart
-- When client's resource starts, create the GUI
هو الحدث الذي يحدث عند بدأ السكربت او المود بالتشغيل في احداث كلنت]]
function initGUI( )
function initGUI( )
     -- نقوم الآن بـ صنع الزر
     -- Create our button
     btnOutput = guiCreateButton( 0.7, 0.1, 0.2, 0.1, "Output!", true )
     btnOutput = guiCreateButton( 0.7, 0.1, 0.2, 0.1, "Output!", true )


     --[[ ونربط هذا الزر مع ال
     -- And attach our button to the outputEditBox function
    gui-edit]]
     addEventHandler ( "onClientGUIClick", btnOutput, outputEditBox, false )
     addEventHandler ( "onClientGUIClick", btnOutput, outputEditBox, false ) -- الحدث


     --[[ نقوم الآن بـ صنع
     -- Create an edit box and define it as "editBox".
    gui-edit
    ونسميها او نختصرها بـ
    " editBox "
    ]]
     editBox = guiCreateEdit( 0.3, 0.1, 0.4, 0.1, "Type your message here!", true )
     editBox = guiCreateEdit( 0.3, 0.1, 0.4, 0.1, "Type your message here!", true )
     guiEditSetMaxLength ( editBox, 128 ) -- آخر طول النص لـ مربع الدردشة وهو 128
     guiEditSetMaxLength ( editBox, 128 ) -- The max chatbox text length is 128, so force this
end
end
addEventHandler( "onClientResourceStart", getResourceRootElement( getThisResource( ) ), initGUI )
addEventHandler( "onClientResourceStart", resourceRoot, initGUI )


-- Setup our function to output the message to the chatbox
-- Setup our function to output the message to the chatbox
function outputEditBox ( button )
function outputEditBox ( button )
     if button == "left" then
     if button == "left" then
         local text = guiGetText ( editBox )-- يآخذ الكلام الذي تم كتابته
         local text = guiGetText ( editBox )-- Get the text from the edit box
         outputChatBox ( text ) --[[ اذا القينا نظرة فوق على كلمة
         outputChatBox ( text ) -- Output that text
                                  سـ نرى انها مختصرة بـ كلمة
                                  text
                                    و سـيآخذ الكلام الذي يوجد في
                                    text
                                    ويضعه في مربع الشات عند الضغت على الزر]]                                   
     end
     end
end
end
</syntaxhighlight>
</syntaxhighlight>


==أنظر ايضاً==
[[pl:onClientGUIClick]]
===احداث GUI===
 
==See Also==
{{GUI_events}}
{{GUI_events}}
===Client event functions===
===Client event functions===
{{Client_event_functions}}
{{Client_event_functions}}

Latest revision as of 16:40, 19 October 2022

This event happens when any gui-element clicked.

[[{{{image}}}|link=|]] Note: The player who clicked the gui-element is always the localPlayer.

Parameters

string button, string state, int absoluteX, int absoluteY
  • button: the name of the button which will be clicked, it can be left, right, middle.
  • state: the state of the mouse button, will be down if the mouse button was pushed, or up if it was released. Please note currently only the up state is supported.
  • absoluteX: the X position of the mouse cursor, in pixels, measured from the left side of the screen.
  • absoluteY: the Y position of the mouse cursor, in pixels, measured from the top of the screen.

Source

The source of this event is the GUI element that was clicked.

[[{{{image}}}|link=|]] Note: If the GUI Element attached to this event has a parent element, this event will be triggered once the parent element of the attached element is clicked too. You can set the parameter propagate to false in the call to addEventHandler to prevent this.

Example

This example creates an edit box alongside an "Output!" button. When the button is clicked with the left mouse button, it will output the message in the edit box into the chat box.

-- When client's resource starts, create the GUI
function initGUI( )
    -- Create our button
    btnOutput = guiCreateButton( 0.7, 0.1, 0.2, 0.1, "Output!", true )

    -- And attach our button to the outputEditBox function
    addEventHandler ( "onClientGUIClick", btnOutput, outputEditBox, false )

    -- Create an edit box and define it as "editBox".
    editBox = guiCreateEdit( 0.3, 0.1, 0.4, 0.1, "Type your message here!", true )
    guiEditSetMaxLength ( editBox, 128 ) -- The max chatbox text length is 128, so force this
end
addEventHandler( "onClientResourceStart", resourceRoot, initGUI )

-- Setup our function to output the message to the chatbox
function outputEditBox ( button )
    if button == "left" then
        local text = guiGetText ( editBox )-- Get the text from the edit box
        outputChatBox ( text ) -- Output that text
    end
end

See Also

Input

GUI


Client event functions