This article relates to the game "Dota 2". Click here for more information.
This article relates to the SDK/Workshop Tools for "Dota 2 Workshop Tools". Click here for more information.
This article's documentation is for Source 2. Click here for more information.

GameUI SetMouseCallback Example

From Valve Developer Community
Jump to navigation Jump to search
English (en)中文 (zh)Translate (Translate)

// This is an example of how to use the GameUI.SetMouseCallback function
GameUI.SetMouseCallback( function( eventName, arg ) {
	var CONSUME_EVENT = true;
	var CONTINUE_PROCESSING_EVENT = false;

	if ( GameUI.GetClickBehaviors() !== CLICK_BEHAVIORS.DOTA_CLICK_BEHAVIOR_NONE )
		return CONTINUE_PROCESSING_EVENT;

	if ( eventName == "pressed" )
	{
		// Left-click is move to position
		if ( arg === 0 )
		{
			var order = {};
			order.OrderType = dotaunitorder_t.DOTA_UNIT_ORDER_MOVE_TO_POSITION;
			order.Position = GameUI.GetScreenWorldPosition( GameUI.GetCursorPosition() );
			order.Queue = false;
			order.ShowEffects = false;
			Game.PrepareUnitOrders( order );
			return CONSUME_EVENT;
		}

		// Disable right-click
		if ( arg === 1 )
		{
			return CONSUME_EVENT;
		}
	}
	else if ( eventName === "wheeled" )
	{
		if ( arg < 0 )
		{
			var order = {};
			order.OrderType = dotaunitorder_t.DOTA_UNIT_ORDER_MOVE_TO_POSITION;
			order.Position = GameUI.GetScreenWorldPosition( GameUI.GetCursorPosition() );
			order.Queue = false;
			order.ShowEffects = false;
			Game.PrepareUnitOrders( order );
			return CONSUME_EVENT;		
		}
		else if ( arg > 0 )
		{
			var order = {};
			order.OrderType = dotaunitorder_t.DOTA_UNIT_ORDER_ATTACK_MOVE;
			order.Position = GameUI.GetScreenWorldPosition( GameUI.GetCursorPosition() );
			order.Queue = false;
			order.ShowEffects = false;
			Game.PrepareUnitOrders( order );
			return CONSUME_EVENT;		
		}
	}
	return CONTINUE_PROCESSING_EVENT;
} );