/// <summary> /// Activate the mover. /// </summary> /// <param name="actionMenu">The menu that requested the mover.</param> /// <param name="limit">The limit distance that the unit can move.</param> public void Activate(ActionMenu actionMenu, float limit) { // Store the menu. this.MenuField = actionMenu; // Enables the mover with the specified limit. this.EnabledField = true; this.LimitField = limit; this.Moving = false; this.Orienting = false; this.ReadyToOrient = false; // Register the mover to listen the input events. InputManager.Instance.CursorDown += new EventHandler <CursorDownArgs>(CursorDown_Handler); InputManager.Instance.CursorUpdate += new EventHandler <CursorUpdateArgs>(CursorUpdate_Handler); InputManager.Instance.CursorUp += new EventHandler <CursorUpArgs>(CursorUp_Handler); // Create the area. Vector2 areaPosition = new Vector2(this.Unit.Position.X + this.Unit.Texture.Width / 2, this.Unit.Position.Y + this.Unit.Texture.Height / 4); this.AreaField = new Area(areaPosition, limit, this.Unit.Player.PlayerIndex == PlayerIndex.One ? AreaManager.PlayerOneMovementAreaColor : AreaManager.PlayerTwoMovementAreaColor); }
/// <summary> /// Deactivate the mover. /// </summary> public void Deactivate() { // Delete the menu. this.MenuField = null; // Disables the mover. this.EnabledField = false; this.LimitField = 0; this.Moving = false; this.Orienting = false; this.ReadyToOrient = false; // Unregister the mover to listen the input events. InputManager.Instance.CursorDown -= new EventHandler <CursorDownArgs>(CursorDown_Handler); InputManager.Instance.CursorUpdate -= new EventHandler <CursorUpdateArgs>(CursorUpdate_Handler); InputManager.Instance.CursorUp -= new EventHandler <CursorUpArgs>(CursorUp_Handler); // Reset the position of the mover. this.PositionField = new Vector2(this.Unit.Position.X + this.Unit.Texture.Width / 2, this.Unit.Position.Y + this.Unit.Texture.Height / 4); // Destroy the area. this.AreaField = null; }