Пример #1
0
        public static void OnRightMouseButtonDown()
        {
            HandleMouseInput();

            if (MouseOverControl != null)
            {
                MakeTopMostGump(MouseOverControl);
                MouseOverControl.InvokeMouseDown(Mouse.Position, MouseButtonType.Right);

                if (MouseOverControl.AcceptKeyboardInput)
                {
                    _keyboardFocusControl = MouseOverControl;
                }
                _mouseDownControls[(int)MouseButtonType.Right] = MouseOverControl;
            }
            else
            {
                foreach (Control s in Gumps)
                {
                    if (s.ControlInfo.IsModal && s.ControlInfo.ModalClickOutsideAreaClosesThisControl)
                    {
                        s.Dispose();
                        Mouse.CancelDoubleClick = true;
                    }
                }
            }

            ShowGamePopup(null);
        }
Пример #2
0
        public static void OnLeftMouseButtonDown()
        {
            HandleMouseInput();
            _validForDClick = null;
            if (MouseOverControl != null)
            {
                MakeTopMostGump(MouseOverControl);
                MouseOverControl.InvokeMouseDown(Mouse.Position, MouseButton.Left);

                if (MouseOverControl.AcceptKeyboardInput)
                {
                    _keyboardFocusControl = MouseOverControl;
                }
                _mouseDownControls[(int)MouseButton.Left] = MouseOverControl;
            }
            else
            {
                if (IsModalControlOpen)
                {
                    foreach (Control s in Gumps)
                    {
                        if (s.ControlInfo.IsModal && s.ControlInfo.ModalClickOutsideAreaClosesThisControl)
                        {
                            s.Dispose();
                            Mouse.CancelDoubleClick = true;
                        }
                    }
                }
            }
        }
Пример #3
0
        public static void OnExtraMouseButtonDown(int btn)
        {
            HandleMouseInput();
            if (MouseOverControl != null)
            {
                MakeTopMostGump(MouseOverControl);
                MouseOverControl.InvokeMouseDown(Mouse.Position, (MouseButtonType)btn);

                if (MouseOverControl.IsEnabled && MouseOverControl.IsVisible)
                {
                    if (_lastFocus != MouseOverControl)
                    {
                        _lastFocus?.OnFocusLeft();
                        MouseOverControl.OnFocusEnter();
                        _lastFocus = MouseOverControl;
                    }
                }

                _mouseDownControls[btn] = MouseOverControl;
            }
            else
            {
                foreach (Control s in Gumps)
                {
                    if (s.ControlInfo.IsModal && s.ControlInfo.ModalClickOutsideAreaClosesThisControl)
                    {
                        s.Dispose();
                        Mouse.CancelDoubleClick = true;
                    }
                }
            }

            ShowGamePopup(null);
        }
Пример #4
0
        public static void OnLeftMouseButtonDown()
        {
            HandleMouseInput();
            _validForDClick = null;
            if (MouseOverControl != null)
            {
                MakeTopMostGump(MouseOverControl);
                MouseOverControl.InvokeMouseDown(Mouse.Position, MouseButtonType.Left);

                if (MouseOverControl.AcceptKeyboardInput)
                {
                    _keyboardFocusControl = MouseOverControl;
                }

                if (MouseOverControl.IsEnabled && MouseOverControl.IsVisible)
                {
                    if (_lastFocus != MouseOverControl)
                    {
                        _lastFocus?.OnFocusLeft();
                        MouseOverControl.OnFocusEnter();
                        _lastFocus = MouseOverControl;
                    }
                }

                _mouseDownControls[(int)MouseButtonType.Left] = MouseOverControl;
            }
            else
            {
                foreach (Control s in Gumps)
                {
                    if (s.ControlInfo.IsModal && s.ControlInfo.ModalClickOutsideAreaClosesThisControl)
                    {
                        s.Dispose();
                        Mouse.CancelDoubleClick = true;
                    }
                }
            }

            if (PopupMenu != null && !PopupMenu.Bounds.Contains(Mouse.Position.X, Mouse.Position.Y))
            {
                ShowGamePopup(null);
            }
        }
Пример #5
0
        public UIManager()
        {
            GameCursor   = new GameCursor(this);
            _sbUI        = Service.Get <SpriteBatchUI>();
            InputManager = Service.Get <InputManager>();

            InputManager.MouseDragging += (sender, e) =>
            {
                if (_isDraggingControl)
                {
                    DoDragControl(Mouse.Position);
                }
            };

            InputManager.LeftMouseButtonDown += (sender, e) =>
            {
                if (!IsModalControlOpen && ObjectsBlockingInputExists)
                {
                    return;
                }

                if (MouseOverControl != null)
                {
                    MakeTopMostGump(MouseOverControl);
                    MouseOverControl.InvokeMouseDown(Mouse.Position, MouseButton.Left);

                    if (MouseOverControl.AcceptKeyboardInput)
                    {
                        _keyboardFocusControl = MouseOverControl;
                    }
                    _mouseDownControls[(int)MouseButton.Left] = MouseOverControl;
                }
                else
                {
                    if (IsModalControlOpen)
                    {
                        _gumps.ForEach(s =>
                        {
                            if (s.ControlInfo.IsModal && s.ControlInfo.ModalClickOutsideAreaClosesThisControl)
                            {
                                s.Dispose();
                            }
                        });
                    }
                }
            };

            InputManager.LeftMouseButtonUp += (sender, e) =>
            {
                if (!IsModalControlOpen && ObjectsBlockingInputExists)
                {
                    return;
                }

                //if (MouseOverControl == null)
                //    return;
                const int btn = (int)MouseButton.Left;
                EndDragControl(Mouse.Position);

                if (MouseOverControl != null)
                {
                    if (_mouseDownControls[btn] != null && MouseOverControl == _mouseDownControls[btn])
                    {
                        MouseOverControl.InvokeMouseClick(Mouse.Position, MouseButton.Left);
                    }
                    MouseOverControl.InvokeMouseUp(Mouse.Position, MouseButton.Left);

                    if (_mouseDownControls[btn] != null && MouseOverControl != _mouseDownControls[btn])
                    {
                        _mouseDownControls[btn].InvokeMouseUp(Mouse.Position, MouseButton.Left);
                    }
                }
                else
                {
                    _mouseDownControls[btn]?.InvokeMouseUp(Mouse.Position, MouseButton.Left);
                }

                _mouseDownControls[btn] = null;
            };

            InputManager.LeftMouseDoubleClick += () =>
            {
                if (!IsModalControlOpen && ObjectsBlockingInputExists)
                {
                    return(false);
                }
                if (MouseOverControl != null && IsMouseOverUI)
                {
                    return(MouseOverControl.InvokeMouseDoubleClick(Mouse.Position, MouseButton.Left));
                }

                return(false);
            };

            InputManager.RightMouseButtonDown += (sender, e) =>
            {
                if (!IsModalControlOpen && ObjectsBlockingInputExists)
                {
                    return;
                }

                if (MouseOverControl != null)
                {
                    MakeTopMostGump(MouseOverControl);
                    MouseOverControl.InvokeMouseDown(Mouse.Position, MouseButton.Right);

                    if (MouseOverControl.AcceptKeyboardInput)
                    {
                        _keyboardFocusControl = MouseOverControl;
                    }
                    _mouseDownControls[(int)MouseButton.Right] = MouseOverControl;
                }
                else
                {
                    if (IsModalControlOpen)
                    {
                        _gumps.ForEach(s =>
                        {
                            if (s.ControlInfo.IsModal && s.ControlInfo.ModalClickOutsideAreaClosesThisControl)
                            {
                                s.Dispose();
                            }
                        });
                    }
                }
            };

            InputManager.RightMouseButtonUp += (sender, e) =>
            {
                if (!IsModalControlOpen && ObjectsBlockingInputExists)
                {
                    return;
                }

                //if (MouseOverControl == null)
                //    return;
                const int btn = (int)MouseButton.Right;
                EndDragControl(Mouse.Position);

                if (MouseOverControl != null)
                {
                    if (_mouseDownControls[btn] != null && MouseOverControl == _mouseDownControls[btn])
                    {
                        MouseOverControl.InvokeMouseClick(Mouse.Position, MouseButton.Right);
                    }
                    MouseOverControl.InvokeMouseUp(Mouse.Position, MouseButton.Right);

                    if (_mouseDownControls[btn] != null && MouseOverControl != _mouseDownControls[btn])
                    {
                        _mouseDownControls[btn].InvokeMouseUp(Mouse.Position, MouseButton.Right);
                    }
                }
                else
                {
                    _mouseDownControls[btn]?.InvokeMouseUp(Mouse.Position, MouseButton.Right);
                }

                _mouseDownControls[btn] = null;
            };

            InputManager.MouseWheel += (sender, isup) =>
            {
                if (!IsModalControlOpen && ObjectsBlockingInputExists)
                {
                    return;
                }

                if (MouseOverControl != null && MouseOverControl.AcceptMouseInput)
                {
                    MouseOverControl.InvokeMouseWheel(isup ? MouseEvent.WheelScrollUp : MouseEvent.WheelScrollDown);
                }
            };
            InputManager.KeyDown   += (sender, e) => { _keyboardFocusControl?.InvokeKeyDown(e.keysym.sym, e.keysym.mod); };
            InputManager.KeyUp     += (sender, e) => { _keyboardFocusControl?.InvokeKeyUp(e.keysym.sym, e.keysym.mod); };
            InputManager.TextInput += (sender, e) => { _keyboardFocusControl?.InvokeTextInput(e); };
        }
Пример #6
0
        public UIManager()
        {
            AnchorManager = new AnchorManager();

            Engine.Input.MouseDragging += (sender, e) =>
            {
                HandleMouseInput();

                if (_mouseDownControls[0] == MouseOverControl && MouseOverControl != null)
                {
                    AttemptDragControl(MouseOverControl, Mouse.Position, true);
                }

                if (_isDraggingControl)
                {
                    DoDragControl(Mouse.Position);
                }
            };

            Engine.Input.LeftMouseButtonDown += (sender, e) =>
            {
                //if (!IsModalControlOpen /*&& ObjectsBlockingInputExists*/)
                //    return;

                HandleMouseInput();

                if (MouseOverControl != null)
                {
                    MakeTopMostGump(MouseOverControl);
                    MouseOverControl.InvokeMouseDown(Mouse.Position, MouseButton.Left);

                    if (MouseOverControl.AcceptKeyboardInput)
                    {
                        _keyboardFocusControl = MouseOverControl;
                    }
                    _mouseDownControls[(int)MouseButton.Left] = MouseOverControl;
                }
                else
                {
                    if (IsModalControlOpen)
                    {
                        foreach (Control s in Gumps)
                        {
                            if (s.ControlInfo.IsModal && s.ControlInfo.ModalClickOutsideAreaClosesThisControl)
                            {
                                s.Dispose();
                            }
                        }
                    }
                }
            };

            Control lastLeftUp = null, lastRightUp = null;

            Engine.Input.LeftMouseButtonUp += (sender, e) =>
            {
                //if (!IsModalControlOpen && ObjectsBlockingInputExists)
                //    return;

                //if (MouseOverControl == null)
                //    return;

                const int btn = (int)MouseButton.Left;
                EndDragControl(Mouse.Position);

                if (MouseOverControl != null)
                {
                    //if (_mouseDownControls[btn] != null && MouseOverControl == _mouseDownControls[btn])
                    //    MouseOverControl.InvokeMouseClick(Mouse.Position, MouseButton.Left);

                    //if (_mouseDownControls[btn] != null && MouseOverControl == _mouseDownControls[btn])
                    MouseOverControl.InvokeMouseUp(Mouse.Position, MouseButton.Left);

                    if (_mouseDownControls[btn] != null && MouseOverControl != _mouseDownControls[btn])
                    {
                        _mouseDownControls[btn].InvokeMouseUp(Mouse.Position, MouseButton.Left);
                    }

                    lastLeftUp = MouseOverControl;
                }
                else
                {
                    _mouseDownControls[btn]?.InvokeMouseUp(Mouse.Position, MouseButton.Left);
                }

                CloseIfClickOutGumps();
                _mouseDownControls[btn] = null;
            };

            Engine.Input.LeftMouseDoubleClick += (sender, e) =>
            {
                if (MouseOverControl != null && IsMouseOverAControl && MouseOverControl == lastLeftUp)
                {
                    e.Result = MouseOverControl.InvokeMouseDoubleClick(Mouse.Position, MouseButton.Left);
                }
            };

            Engine.Input.RightMouseButtonDown += (sender, e) =>
            {
                //if (!IsModalControlOpen && ObjectsBlockingInputExists)
                //    return;

                if (MouseOverControl != null)
                {
                    MakeTopMostGump(MouseOverControl);
                    MouseOverControl.InvokeMouseDown(Mouse.Position, MouseButton.Right);

                    if (MouseOverControl.AcceptKeyboardInput)
                    {
                        _keyboardFocusControl = MouseOverControl;
                    }
                    _mouseDownControls[(int)MouseButton.Right] = MouseOverControl;
                }
                else
                {
                    if (IsModalControlOpen)
                    {
                        foreach (Control s in Gumps)
                        {
                            if (s.ControlInfo.IsModal && s.ControlInfo.ModalClickOutsideAreaClosesThisControl)
                            {
                                s.Dispose();
                            }
                        }
                    }
                }

                CloseIfClickOutGumps();
            };

            Engine.Input.RightMouseButtonUp += (sender, e) =>
            {
                //if (!IsModalControlOpen /*&& ObjectsBlockingInputExists*/)
                //    return;

                //if (MouseOverControl == null)
                //    return;
                const int btn = (int)MouseButton.Right;
                EndDragControl(Mouse.Position);

                if (MouseOverControl != null)
                {
                    if (_mouseDownControls[btn] != null && MouseOverControl == _mouseDownControls[btn])
                    {
                        //MouseOverControl.InvokeMouseClick(Mouse.Position, MouseButton.Right);
                        MouseOverControl.InvokeMouseCloseGumpWithRClick();
                    }

                    MouseOverControl.InvokeMouseUp(Mouse.Position, MouseButton.Right);

                    if (_mouseDownControls[btn] != null && MouseOverControl != _mouseDownControls[btn])
                    {
                        _mouseDownControls[btn].InvokeMouseUp(Mouse.Position, MouseButton.Right);
                        _mouseDownControls[btn].InvokeMouseCloseGumpWithRClick();
                    }


                    lastRightUp = MouseOverControl;
                }
                else if (_mouseDownControls[btn] != null)
                {
                    _mouseDownControls[btn].InvokeMouseUp(Mouse.Position, MouseButton.Right);
                    _mouseDownControls[btn].InvokeMouseCloseGumpWithRClick();
                }

                CloseIfClickOutGumps();
                _mouseDownControls[btn] = null;
            };

            Engine.Input.RightMouseDoubleClick += (sender, e) =>
            {
                if (MouseOverControl != null && IsMouseOverAControl && MouseOverControl == lastRightUp)
                {
                    e.Result = MouseOverControl.InvokeMouseDoubleClick(Mouse.Position, MouseButton.Right);
                }
            };

            Engine.Input.MouseWheel += (sender, isup) =>
            {
                //if (!IsModalControlOpen /*&& ObjectsBlockingInputExists*/)
                //    return;

                if (MouseOverControl != null && MouseOverControl.AcceptMouseInput)
                {
                    MouseOverControl.InvokeMouseWheel(isup ? MouseEvent.WheelScrollUp : MouseEvent.WheelScrollDown);
                }
            };
            Engine.Input.KeyDown   += (sender, e) => { _keyboardFocusControl?.InvokeKeyDown(e.keysym.sym, e.keysym.mod); };
            Engine.Input.KeyUp     += (sender, e) => { _keyboardFocusControl?.InvokeKeyUp(e.keysym.sym, e.keysym.mod); };
            Engine.Input.TextInput += (sender, e) => { _keyboardFocusControl?.InvokeTextInput(e); };
        }