예제 #1
0
 public virtual bool MouseButtonUp(GameTime gameTime, MouseButtonEventArgs e)
 {
     return false;
 }
예제 #2
0
 private void OnMouseComponentButtonUp(object sender, MouseButtonEventArgs e)
 {
     foreach (var module in InputModules)
     {
         var input = module as IInputModule;
         if (input != null)
         {
             if (input.MouseButtonUp(GameTime, e))
                 break;
         }
     }
 }
예제 #3
0
 public override bool MouseButtonUp(GameTime gameTime, MouseButtonEventArgs e)
 {
     switch (e.Button)
     {
         case MouseButton.Left:
             Digging = false;
             return true;
     }
     return false;
 }
예제 #4
0
 public override bool MouseButtonDown(GameTime gameTime, MouseButtonEventArgs e)
 {
     switch (e.Button)
     {
         case MouseButton.Left:
             Digging = true;
             return true;
         case MouseButton.Right:
             var item = Game.Client.Inventory.Hotbar[Game.Client.HotbarSelection];
                 Game.Client.QueuePacket(new PlayerBlockPlacementPacket(
                 Game.HighlightedBlock.X, (sbyte)Game.HighlightedBlock.Y, Game.HighlightedBlock.Z,
                 Game.HighlightedBlockFace, item.ID, item.Count, item.Metadata));
             return true;
     }
     return false;
 }
예제 #5
0
 public override bool MouseButtonUp(GameTime gameTime, MouseButtonEventArgs e)
 {
     return Game.Client.CurrentWindow != null;
 }
예제 #6
0
 public override bool MouseButtonDown(GameTime gameTime, MouseButtonEventArgs e)
 {
     if (Game.Client.CurrentWindow == null)
         return false;
     var id = Game.Client.CurrentWindow.ID;
     if (id == -1)
         id = 0; // Minecraft is stupid
     var item = ItemStack.EmptyStack;
     if (SelectedSlot > -1)
         item = Game.Client.CurrentWindow[SelectedSlot];
     var packet = new ClickWindowPacket(id, SelectedSlot, e.Button == MouseButton.Right,
         0, Keyboard.GetState().IsKeyDown(Keys.LeftShift) || Keyboard.GetState().IsKeyDown(Keys.RightShift),
         item.ID, item.Count, item.Metadata);
     if (packet.SlotIndex == -999)
     {
         // Special case (throwing item) TODO
     }
     else
     {
         var backup = Game.Client.CurrentWindow.GetSlots();
         var staging = (ItemStack)HeldItem.Clone();
         Window.HandleClickPacket(packet, Game.Client.CurrentWindow, ref staging);
         HeldItem = staging;
         Game.Client.CurrentWindow.SetSlots(backup);
     }
     Game.Client.QueuePacket(packet);
     return true;
 }
예제 #7
0
        /// <summary>
        /// Processes a change between two states.
        /// </summary>
        /// <param name="newState">The new state.</param>
        /// <param name="oldState">The old state.</param>
        private void Process(MouseState newState, MouseState oldState)
        {
            // Movement.
            if ((newState.X != oldState.X) || (newState.Y != oldState.Y))
            {
                var args = new MouseMoveEventArgs(newState.X, newState.Y, (newState.X - oldState.X), (newState.Y - oldState.Y));
                if (Move != null)
                    Move(this, args);
            }

            // Scrolling.
            if (newState.ScrollWheelValue != oldState.ScrollWheelValue)
            {
                var args = new MouseScrollEventArgs(newState.X, newState.Y, newState.ScrollWheelValue, (newState.ScrollWheelValue - oldState.ScrollWheelValue));
                if (Scroll != null)
                    Scroll(this, args);
            }

            // A bit of code duplication here, shame XNA doesn't expose button state through an enumeration...

            // Left button.
            if (newState.LeftButton != oldState.LeftButton)
            {
                var args = new MouseButtonEventArgs(newState.X, newState.Y, MouseButton.Left, (newState.LeftButton == ButtonState.Pressed));
                if (args.IsPressed)
                {
                    if (ButtonDown != null)
                        ButtonDown(this, args);
                }
                else
                {
                    if (ButtonUp != null)
                        ButtonUp(this, args);
                }
            }

            // Right button.
            if (newState.RightButton != oldState.RightButton)
            {
                var args = new MouseButtonEventArgs(newState.X, newState.Y, MouseButton.Right, (newState.RightButton == ButtonState.Pressed));
                if (args.IsPressed)
                {
                    if (ButtonDown != null)
                        ButtonDown(this, args);
                }
                else
                {
                    if (ButtonUp != null)
                        ButtonUp(this, args);
                }
            }

            // Middle button.
            if (newState.MiddleButton != oldState.MiddleButton)
            {
                var args = new MouseButtonEventArgs(newState.X, newState.Y, MouseButton.Middle, (newState.MiddleButton == ButtonState.Pressed));
                if (args.IsPressed)
                {
                    if (ButtonDown != null)
                        ButtonDown(this, args);
                }
                else
                {
                    if (ButtonUp != null)
                        ButtonUp(this, args);
                }
            }
        }