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

From Valve Developer Community
Jump to: navigation, search
m (Added category to the page, added shortpagetitle template)
m (Added Panorama category)
 
Line 56: Line 56:
  
 
{{shortpagetitle}}
 
{{shortpagetitle}}
[[Category: Dota 2 Workshop Tools]]
+
[[Category: Dota 2 Workshop Tools]] [[Category: Panorama]]

Latest revision as of 19:27, 5 September 2019

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