This article relates to the game "Dota 2". Click here for more information.
This article relates to the workshop tools for "Dota 2". Click here for more information.
This article's documentation is for Source 2. Click here for more information.

Difference between revisions of "Dota 2 Workshop Tools/Panorama/GameUI SetMouseCallback Example"

From Valve Developer Community
Jump to: navigation, search
m (Added Panorama category)
(Added top icons)
 
Line 1: Line 1:
 +
{{Dota 2Tools topicons}}
 
  <nowiki>
 
  <nowiki>
 
// This is an example of how to use the GameUI.SetMouseCallback function
 
// This is an example of how to use the GameUI.SetMouseCallback function

Latest revision as of 01:02, 16 May 2020

// 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;
} );