示例#1
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); };
        }
示例#2
0
        public UIManager()
        {
            _anchorManager = new AnchorManager();

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

                //if (_mouseDownControls[0] == MouseOverControl)
                //    AttemptDragControl(MouseOverControl, Mouse.Position);
                if (_isDraggingControl)
                {
                    DoDragControl(Mouse.Position);
                }
            };

            Engine.Input.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();
                            }
                        });
                    }
                }
            };

            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);
                    }
                    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)
                    {
                        _gumps.ForEach(s =>
                        {
                            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); };
        }