OnDgsMousePreClick: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "{{Client event}} __NOTOC__ This event happens when any dgs-element clicked {{Note|The '''player''' who clicked the dgs-element is always the localPlayer.}} {{Note|If you w...")
 
Line 23: Line 23:


btnOutput = DGS:dgsCreateButton( 0.7, 0.1, 0.2, 0.1, "Output!", true )
btnOutput = DGS:dgsCreateButton( 0.7, 0.1, 0.2, 0.1, "Output!", true )
addEventHandler ( "onDgsMousePreClick", btnOutput, cancelTheEvent )
DGS:dgsSetProperty( btnOutput , "clickCoolDown", 1000 )  --Cool Down 1s
addEventHandler ( "onDgsMouseClick", btnOutput, output )
addEventHandler ( "onDgsMousePreClick", btnOutput, onPreClick )
addEventHandler ( "onDgsMouseClick", btnOutput, onClick )


function cancelTheEvent()
function onPreClick ( button, state, x, y, isCoolingDown )
cancelEvent()
if isCoolingDown then
outputChatBox("Cooling Down, Cancelled")
cancelEvent()
else
outputChatBox("Pre Click")
end
end
end


function output( button, state ) --Event is canceled, no longer triggers  
function onClick ( button, state ) --Event is canceled, no longer triggers  
outputChatBox("I Clicked")
outputChatBox("Click")
end
end
</syntaxhighlight>
</syntaxhighlight>

Revision as of 07:12, 12 May 2024

This event happens when any dgs-element clicked

[[{{{image}}}|link=|]] Note: The player who clicked the dgs-element is always the localPlayer.
[[{{{image}}}|link=|]] Note: If you want to ask why everything is triggered... See the forth parameter of addEventHandler
[[{{{image}}}|link=|]] Note: This event is cancelable, which will affect the click effect and related events

Parameters

string button, string state, int absoluteX, int absoluteY, bool isCoolingDown
  • 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 both up and down state are 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.
  • isCoolingDown: A bool indicates whether this dgs element is cooling down. See Property:clickCoolDown

Source

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

Example

DGS = exports.dgs

btnOutput = DGS:dgsCreateButton( 0.7, 0.1, 0.2, 0.1, "Output!", true )
DGS:dgsSetProperty( btnOutput , "clickCoolDown", 1000 )  --Cool Down 1s
addEventHandler ( "onDgsMousePreClick", btnOutput, onPreClick )
addEventHandler ( "onDgsMouseClick", btnOutput, onClick )

function onPreClick ( button, state, x, y, isCoolingDown )
	if isCoolingDown then
		outputChatBox("Cooling Down, Cancelled")
		cancelEvent()
	else
		outputChatBox("Pre Click")
	end
end

function onClick ( button, state ) --Event is canceled, no longer triggers 
	outputChatBox("Click")
end

See Also

DGS events

General

Check Box

Combo Box

Drag'N Drop

Edit

Grid List

Menu

Selector

Mouse

Radio Button

Switch Button

Tab

Animation

Plugin

Media

Color Picker

QRCode

Remote Image

Client event functions