Ejemplo n.º 1
0
        public override void HandleInput(MyGuiInput input, bool receivedFocusInThisUpdate)
        {
            base.HandleInput(input, receivedFocusInThisUpdate);

            if (input.IsNewLeftMousePressed() || input.IsNewRightMousePressed() || input.IsNewKeyPress(Keys.Space) || input.IsNewKeyPress(Keys.Enter))
                Canceling();
        }
Ejemplo n.º 2
0
        public override bool HandleInput(MyGuiInput input, bool hasKeyboardActiveControl, bool hasKeyboardActiveControlPrevious, bool receivedFocusInThisUpdate)
        {
            //If this control is not enable, do nothing
            if (!IsEnable)
            {
                return(false);
            }

            if (Visible)
            {
                if (((input.IsKeyPress(Keys.LeftShift) || input.IsKeyPress(Keys.RightShift)) && input.IsNewKeyPress(Keys.Tab)) || input.IsNewKeyPress(Keys.Up) || input.IsNewGamepadKeyUpPressed())
                {
                    SelectPrev();
                }
                if ((!(input.IsKeyPress(Keys.LeftShift) || input.IsKeyPress(Keys.RightShift)) && input.IsNewKeyPress(Keys.Tab)) || input.IsNewKeyPress(Keys.Down) || input.IsNewGamepadKeyDownPressed())
                {
                    SelectNext();
                }
                if (input.IsNewKeyPress(Keys.Escape) || input.IsJoystickButtonNewPressed(MyJoystickButtonsEnum.J02))
                {
                    HideScreenIfPossible();
                }

                if (m_displayedItems[m_selected] != null)
                {
                    if (input.IsNewKeyPress(Keys.Left) || input.IsNewGamepadKeyLeftPressed())
                    {
                        m_displayedItems[m_selected].ChangeValueDown();
                    }
                    if (input.IsNewKeyPress(Keys.Right) || input.IsNewGamepadKeyRightPressed())
                    {
                        m_displayedItems[m_selected].ChangeValueUp();
                    }
                    if (input.IsNewKeyPress(Keys.Enter) || input.IsNewKeyPress(Keys.Space) || input.IsJoystickButtonNewPressed(MyJoystickButtonsEnum.J01))
                    {
                        m_displayedItems[m_selected].ChangeValueUp();
                    }
                }

                HandleMouse(input);
            }

            if (input.IsNewGameControlPressed(MyGameControlEnums.WHEEL_CONTROL))
            {
                m_first = 0;
                Visible = !Visible;
                if (Visible == false)
                {
                    MyAudio.AddCue2D(MySoundCuesEnum.GuiWheelControlClose);
                }
                else
                {
                    MyAudio.AddCue2D(MySoundCuesEnum.GuiWheelControlOpen);
                }
            }

            return(base.HandleInput(input, hasKeyboardActiveControl, hasKeyboardActiveControlPrevious, receivedFocusInThisUpdate));
        }
Ejemplo n.º 3
0
        public void Update(MyDebugSystem system, MyGuiInput input)
        {
            input.GetPressedKeys(m_pressedKeys);
            short modifier = 0;

            if (input.IsAnyAltKeyPressed())
            {
                modifier |= (short)MyShortcut.ModifierValue.Alt;
            }
            if (input.IsAnyShiftKeyPressed())
            {
                modifier |= (short)MyShortcut.ModifierValue.Shift;
            }
            if (input.IsAnyCtrlKeyPressed())
            {
                modifier |= (short)MyShortcut.ModifierValue.Control;
            }

            foreach (Keys k in m_pressedKeys)
            {
                var key = (Keys)k;
                if (key == Keys.LeftAlt || key == Keys.RightAlt || key == Keys.LeftShift || key == Keys.RightShift || key == Keys.LeftControl || key == Keys.RightControl)
                {
                    continue;
                }

                if (input.IsNewKeyPress(key))
                {
                    OnKeyPressed(system, key, modifier);
                }
            }
        }
Ejemplo n.º 4
0
        public override void HandleInput(MyGuiInput input, bool receivedFocusInThisUpdate)
        {
            base.HandleInput(input, receivedFocusInThisUpdate);

            if (input.IsNewLeftMousePressed() || input.IsNewRightMousePressed() || input.IsNewKeyPress(Keys.Space) || input.IsNewKeyPress(Keys.Enter))
            {
                Canceling();
            }
        }
Ejemplo n.º 5
0
        public override void HandleInput(MyGuiInput input, bool receivedFocusInThisUpdate)
        {
            base.HandleInput(input, receivedFocusInThisUpdate);

            if (input.IsNewKeyPress(Keys.Enter))
            {
                OnSendClick(null);
            }
        }
Ejemplo n.º 6
0
        public override void HandleInput(MyGuiInput input, bool receivedFocusInThisUpdate)
        {
            base.HandleInput(input, receivedFocusInThisUpdate);

            if (input.IsNewKeyPress(Keys.Escape))
            {
                //CloseScreen();
                OnCancelClick(null);
            }
        }
    internal static void HandleInput(MySolarMapRenderer renderer, MyGuiInput input, bool receivedFocusInThisUpdate)
    {
        if (input.IsNewKeyPress(Keys.NumPad7))
        {
            center = renderer.GetTargetSector();
        }

        if (input.IsNewKeyPress(Keys.NumPad9))
        {
            point = renderer.GetTargetSector();
        }

        if (input.IsNewKeyPress(Keys.NumPad8))
        {
            System.Diagnostics.Debug.WriteLine(string.Format("MyFactions.AddFactionArea(MyMwcObjectBuilder_FactionEnum.China, new MyMwcVector3Int({0}), new MyMwcVector3Int({1}));", center, point));
            MyFactions.AddFactionArea(MyMwcObjectBuilder_FactionEnum.China, center, point);
        }

        if (input.IsNewKeyPress(Keys.NumPad4))
        {
            Debug.WriteLine(MyFactions.GetFactionBySector(renderer.GetTargetSector()));
        }
    }
        //  Method returns true if input was captured by control, so no other controls, nor screen can use input in this update
        public override bool HandleInput(MyGuiInput input, bool hasKeyboardActiveControl, bool hasKeyboardActiveControlPrevious, bool isThisFirstHandleInput)
        {
            bool ret = base.HandleInput(input, hasKeyboardActiveControl, hasKeyboardActiveControlPrevious, isThisFirstHandleInput);

            if (ret == false)
            {
                if (((IsMouseOver() == true) && (input.IsNewLeftMousePressed() == true)) ||
                    ((hasKeyboardActiveControl == true) && ((input.IsNewKeyPress(Keys.Enter) || (input.IsNewKeyPress(Keys.Space))))))
                {
                    if (!Selected)
                    {
                        MyAudio.AddCue2D(MySoundCuesEnum.GuiMouseClick);
                        Selected = true;
                        ret      = true;
                    }
                }
            }

            return(ret);
        }
Ejemplo n.º 9
0
        public override bool HandleInput(MyGuiInput input, bool hasKeyboardActiveControl, bool hasKeyboardActiveControlPrevious, bool receivedFocusInThisUpdate)
        {
            bool ret = base.HandleInput(input, hasKeyboardActiveControl, hasKeyboardActiveControlPrevious, receivedFocusInThisUpdate);

            if (ret == false)
            {
                if (MouseEnter != null || MouseLeave != null)
                {
                    bool isMouseOver = CheckMouseOver();
                    if (isMouseOver != lastIsMouseOver)
                    {
                        if (isMouseOver)
                        {
                            if (MouseEnter != null)
                            {
                                MouseEnter(this, EventArgs.Empty);
                            }
                        }
                        else
                        {
                            if (MouseLeave != null)
                            {
                                MouseLeave(this, EventArgs.Empty);
                            }
                        }
                    }
                    lastIsMouseOver = isMouseOver;
                }

                if (Click != null)
                {
                    if (((CheckMouseOver() == true) && input.IsNewLeftMousePressed()) ||
                        ((hasKeyboardActiveControl == true) && ((input.IsNewKeyPress(Keys.Enter) || (input.IsNewKeyPress(Keys.Space)) || (input.IsNewGameControlPressed(MyGameControlEnums.FIRE_PRIMARY) && !input.IsNewLeftMousePressed())))))
                    {
                        Click(this, EventArgs.Empty);
                    }
                }
            }

            return(ret);
        }
Ejemplo n.º 10
0
        //  Method returns true if input was captured by control, so no other controls, nor screen can use input in this update
        public override bool HandleInput(MyGuiInput input, bool hasKeyboardActiveControl, bool hasKeyboardActiveControlPrevious, bool isThisFirstHandleInput)
        {
            if (!Enabled)
            {
                return(false);
            }

            bool ret = base.HandleInput(input, hasKeyboardActiveControl, hasKeyboardActiveControlPrevious, isThisFirstHandleInput);

            if (ret == false)
            {
                if (((IsMouseOver() == true) && input.IsNewLeftMousePressed()) ||
                    ((hasKeyboardActiveControl == true) && ((input.IsNewKeyPress(Keys.Enter) || (input.IsNewKeyPress(Keys.Space)) || (input.IsNewGameControlPressed(MyGameControlEnums.FIRE_PRIMARY) && !input.IsNewLeftMousePressed())))))
                {
                    UserCheck();

                    ret = true;
                }
            }

            return(ret);
        }
Ejemplo n.º 11
0
        private bool HandleCurrentPreselected(MyGuiInput input)
        {
            bool captureInput = false;

            HandleMouseWheelScroll(input, ref captureInput);

            //  Keyboard movement
            if (input.IsNewKeyPress(Keys.Down))
            {
                MovePreselected(true, true);
                captureInput = true;
            }
            else if (input.IsNewKeyPress(Keys.Up))
            {
                MovePreselected(false, true);
                captureInput = true;
            }
            else if (input.IsNewKeyPress(Keys.Right))
            {
                MovePreselected(true, false);
                captureInput = true;
            }
            else if (input.IsNewKeyPress(Keys.Left))
            {
                MovePreselected(false, false);
                captureInput = true;
            }
            else if (input.IsNewKeyPress(Keys.PageDown))
            {
                MovePreselected(true, true, false, true);
                captureInput = true;
            }
            else if (input.IsNewKeyPress(Keys.PageUp))
            {
                MovePreselected(false, true, false, true);
                captureInput = true;
            }
            else if (input.IsNewKeyPress(Keys.Home))
            {
                MovePreselected(false, true, false, false, true);
                captureInput = true;
            }
            else if (input.IsNewKeyPress(Keys.End))
            {
                MovePreselected(true, true, false, false, true);
                captureInput = true;
            }

            return captureInput;
        }
Ejemplo n.º 12
0
        public override bool HandleInput(MyGuiInput input, bool hasKeyboardActiveControl, bool hasKeyboardActiveControlPrevious, bool receivedFocusInThisUpdate)
        {
            bool captureInput = base.HandleInput(input, hasKeyboardActiveControl, hasKeyboardActiveControlPrevious, receivedFocusInThisUpdate);

            if (Enabled && !captureInput && m_rows.Count > 0)
            {
                #region handle scrollbar
                if (m_verticalScrollBar != null)
                {
                    if (m_verticalScrollBar.HandleInput(input, hasKeyboardActiveControl, hasKeyboardActiveControlPrevious, receivedFocusInThisUpdate))
                    {
                        captureInput = true;
                    }
                }
                if (m_horizontalScrollBar != null)
                {
                    if (m_horizontalScrollBar.HandleInput(input, hasKeyboardActiveControl, hasKeyboardActiveControlPrevious, receivedFocusInThisUpdate))
                    {
                        captureInput = true;
                    }
                }
                #endregion

                // handle only if mouse is over the control
                if (IsMouseOver() && !captureInput)
                {
                    #region handle mouse
                    HandleCurrentMousePreselected();
                    m_doubleClickTimer += MyConstants.PHYSICS_STEP_SIZE_IN_MILLISECONDS;

                    // selection by mouse
                    var preselectedItem = GetMousePreselectedItem();
                    if (input.IsNewLeftMousePressed())
                    {
                        if (preselectedItem != null && preselectedItem.Enabled)
                        {
                            // double click handle                            
                            if (m_doubleClickTimer <= DOUBLE_CLICK_DELAY && m_mouseLastPosition != null && (m_mouseLastPosition.Value - MyGuiManager.MouseCursorPosition).Length() <= 0.005f)
                            {
                                if (ItemDoubleClick != null)
                                {
                                    ItemDoubleClick(this, new MyGuiControlListboxItemEventArgs(m_mousePreselectedRowIndex.Value, m_mousePreselectedItemIndex.Value, preselectedItem.Key));
                                    MyAudio.AddCue2D(MySoundCuesEnum.GuiMouseClick);
                                    MyAudio.AddCue2D(MySoundCuesEnum.GuiMouseClick);
                                }
                            }
                            // click handle
                            else
                            {
                                int? oldSelectedRowIndex = m_selectedRowIndex;
                                int? oldSelectedItemIndex = m_selectedItemIndex;

                                SetSelectedItem(m_mousePreselectedRowIndex, m_mousePreselectedItemIndex);
                                HandleMultiSelect(input.IsAnyCtrlKeyPressed(), input.IsAnyShiftKeyPressed(),
                                    oldSelectedRowIndex, oldSelectedItemIndex, m_selectedRowIndex, m_selectedItemIndex);

                                MyAudio.AddCue2D(MySoundCuesEnum.GuiMouseClick);
                                ResetPreselected();
                            }

                            m_mouseLastPosition = MyGuiManager.MouseCursorPosition;
                            m_doubleClickTimer = 0;
                            m_isListboxItemDragging = true;
                            captureInput = true;
                        }
                    }
                    // listbox item dragging
                    else if (input.IsLeftMousePressed())
                    {
                        if (m_isListboxItemDragging)
                        {
                            if (m_mouseLastPosition != null &&
                                preselectedItem != null &&
                                preselectedItem.Enabled && 
                                m_mousePreselectedItemIndex == m_previousMousePreselectedItemIndex &&
                                m_mousePreselectedRowIndex == m_previousMousePreselectedRowIndex)
                            {
                                Vector2 mouseDistanceFromLastUpdate = MyGuiManager.MouseCursorPosition - m_mouseLastPosition.Value;
                                if (mouseDistanceFromLastUpdate.Length() != 0.0f)
                                {
                                    if (ItemDrag != null)
                                    {
                                        ItemDrag(this, new MyGuiControlListboxItemEventArgs(m_mousePreselectedRowIndex.Value, m_previousMousePreselectedItemIndex.Value, preselectedItem.Key));
                                    }
                                    m_isListboxItemDragging = false;
                                }

                                captureInput = true;
                            }
                        }
                        m_mouseLastPosition = MyGuiManager.MouseCursorPosition;
                    }
                    else
                    {
                        m_isListboxItemDragging = false;
                    }
                    #endregion

                    #region handle keyboard
                    if (hasKeyboardActiveControl)
                    {
                        // handle selection move
                        if (HandleCurrentPreselected(input))
                        {
                            captureInput = true;
                            preselectedItem = GetPreselectedItem();
                        }

                        // selection by keyboard
                        if (input.IsNewKeyPress(Keys.Enter) || input.IsNewKeyPress(Keys.Space))
                        {                            
                            if (preselectedItem != null && preselectedItem.Enabled)
                            {
                                SetSelectedItem(m_preselectedRowIndex, m_preselectedItemIndex);
                                MyAudio.AddCue2D(MySoundCuesEnum.GuiMouseClick);
                            }
                            captureInput = true;
                        }
                    }
                    else
                    {
                        HandleMouseWheelScroll(input, ref captureInput);
                    }
                    #endregion
                }
                else
                {
                    m_mousePreselectedItemIndex = null;
                    m_mousePreselectedRowIndex = null;
                }
            }

            return captureInput;
        }
Ejemplo n.º 13
0
        public virtual void HandleInput(MyGuiInput input, bool receivedFocusInThisUpdate)
        {
            //  Here we can make some one-time initialization hidden in update
            bool isThisFirstHandleInput = !m_firstUpdateServed;

            if (m_firstUpdateServed == false && m_keyboardControlIndex == -1) //m_keyboardControlIndex could be set from constructor
            {
                //  Move to first control that can accept it
                //Controls.HandleKeyboardActiveIndex(true);
                HandleKeyboardActiveIndex(true);

                //  Never again call this update-initialization
                m_firstUpdateServed = true;
            }

            // if we are dragging some control, then we don't pass this focus to controls
            if(MyFakes.CONTROLS_MOVE_ENABLED && input.IsKeyPress(Keys.M))
            {
                if(HandleControlMoving(input))
                {
                    return;
                }
            }

            if (MyModelsStatisticsConstants.GET_MODEL_STATISTICS_AUTOMATICALLY)
            {
                if(MyMinerGame.IsGameReady)
                    Models.MyModels.LogUsageInformation();
            }

            if (!HandleControlsInput(input, receivedFocusInThisUpdate))
            {
                bool handled = false;
                //  If input wasn't completely handled or captured by some control, only then we can handle screen's input
                if ((input.IsKeyPress(Keys.LeftShift) && (input.IsNewKeyPress(Keys.Tab))) || (input.IsNewKeyPress(Keys.Up)) || (input.IsNewGamepadKeyUpPressed()))
                {
                    handled = HandleKeyboardActiveIndex(false);
                }
                else if ((input.IsNewKeyPress(Keys.Tab)) || (input.IsNewKeyPress(Keys.Down)) || (input.IsNewGamepadKeyDownPressed()))
                {
                    handled = HandleKeyboardActiveIndex(true);
                }
                else if ((m_closeOnEsc == true) && ((input.IsNewKeyPress(Keys.Escape) || input.IsJoystickButtonNewPressed(MyJoystickButtonsEnum.J02))))
                {
                    Canceling();
                }
                else if ((OnEnterCallback != null) && (input.IsNewKeyPress(Keys.Enter)))
                {
                    OnEnterCallback();
                }

                // Scrolling down/up between controls using mouse scroll wheel
                //if (input.PreviousMouseScrollWheelValue() > input.MouseScrollWheelValue())
                //{
                //    handled = HandleKeyboardActiveIndex(true);
                //}
                //else if (input.PreviousMouseScrollWheelValue() < input.MouseScrollWheelValue())
                //{
                //    handled = HandleKeyboardActiveIndex(false);
                //}

                if (!handled)
                {
                    HandleUnhandledInput(input, receivedFocusInThisUpdate);
                }
            }
        }
Ejemplo n.º 14
0
        //  Method returns true if input was captured by control, so no other controls, nor screen can use input in this update
        public override bool HandleInput(MyGuiInput input, bool hasKeyboardActiveControl, bool hasKeyboardActiveControlPrevious, bool receivedFocusInThisUpdate)
        {
            bool captureInput = base.HandleInput(input, hasKeyboardActiveControl, hasKeyboardActiveControlPrevious, receivedFocusInThisUpdate);

            //Assert();

            if (captureInput == false)
            {
                if ((IsMouseOver() == true) && (input.IsNewLeftMousePressed() == true) && (m_supportListBoxMode == false && !m_isOpen) && m_scrollBarDragging == false)
                    return true;
                // Make sure here, that whenever not in listbox mode, switch opened/closed state when clicked on combobobox
                //if ((IsMouseOver() == true) && (input.IsNewLeftMouseReleased() == true) && (m_supportListBoxMode == false) && m_scrollBarDragging == false)
                if (input.IsNewLeftMouseReleased() && !m_supportListBoxMode && !m_scrollBarDragging) 
                {
                    if (IsMouseOver() && !m_isOpen || IsMouseOverSelectedItem() && m_isOpen) 
                    {
                        MyAudio.AddCue2D(MySoundCuesEnum.GuiMouseClick);
                        SwitchComboboxMode();
                        captureInput = true;
                    }
                }

                if ((hasKeyboardActiveControl == true) && ((input.IsNewKeyPress(Keys.Enter)) || (input.IsNewKeyPress(Keys.Space) || (input.IsNewGameControlPressed(MyGameControlEnums.FIRE_PRIMARY) && !input.IsNewLeftMousePressed()))))
                {
                    MyAudio.AddCue2D(MySoundCuesEnum.GuiMouseClick);

                    if ((m_preselectedKeyboardIndex.HasValue) && (m_preselectedKeyboardIndex.Value < m_items.Count))
                    {
                        if (m_isOpen == false)
                        {
                            SetScrollBarPositionByIndex(m_selected.Key);
                        }
                        else
                        {
                            SelectItemByKey(m_items[m_preselectedKeyboardIndex.Value].Key);
                        }
                    }

                    //  Close but capture focus for this update so parent screen don't receive this ENTER
                    SwitchComboboxMode();
                    captureInput = true;
                }

                //  In listbox mode, the list is always in opened state
                if (m_isOpen == true)
                {                   
                    #region Handle mouse and scrollbar interaction
                    if (m_showScrollBar == true && input.IsLeftMousePressed() == true)
                    {
                        //  Handles mouse input of dragging the scrollbar up or down
                        Vector2 position = GetDrawPosition();
                        MyRectangle2D openedArea = GetOpenedArea();
                        float minX = position.X + m_size.Value.X - m_scrollBarWidth;
                        float maxX = position.X + m_size.Value.X;
                        float minY = m_supportListBoxMode == false ? position.Y + m_size.Value.Y / 2.0f : position.Y - m_size.Value.Y / 2.0f;
                        float maxY = minY + openedArea.Size.Y;

                        // if we are already scrolling, the area used for scrollbar moving will be extended to whole screen
                        if (m_scrollBarDragging)
                        {
                            minX = 0;
                            maxX = 1;
                            minY = 0;
                            maxY = 1;
                        }

                        // In case mouse cursor is intersecting scrollbar area, start scroll bar dragging mode
                        if ((MyGuiManager.MouseCursorPosition.X >= minX) && (MyGuiManager.MouseCursorPosition.X <= maxX)
                            && (MyGuiManager.MouseCursorPosition.Y >= minY) && (MyGuiManager.MouseCursorPosition.Y <= maxY))
                        {                           
                            // Are we over thee scroll bar handle?
                            float P0 = m_scrollBarCurrentPosition.Value + (openedArea.LeftTop.Y);
                            if (MyGuiManager.MouseCursorPosition.Y > P0 && MyGuiManager.MouseCursorPosition.Y < P0 + m_scrollBarHeight)
                            {
                                if (m_mousePositionReinit)
                                {
                                    m_mouseOldPosition = MyGuiManager.MouseCursorPosition.Y;
                                    m_mousePositionReinit = false;
                                }

                                float mdeff = MyGuiManager.MouseCursorPosition.Y - m_mouseOldPosition;
                                if (mdeff > float.Epsilon || mdeff < float.Epsilon)
                                {
                                    SetScrollBarPosition(m_scrollBarCurrentNonadjustedPosition + mdeff);
                                }

                                m_mouseOldPosition = MyGuiManager.MouseCursorPosition.Y;
                            }
                            else
                            {
                                // If we are not over the scrollbar handle -> jump:
                                float scrollPositionY = MyGuiManager.MouseCursorPosition.Y - (openedArea.LeftTop.Y) - m_scrollBarHeight / 2.0f;
                                SetScrollBarPosition(scrollPositionY);
                            }

                            m_scrollBarDragging = true;
                        }
                    }
                    #endregion

                    // Reset mouse parameters after it was released now
                    if (input.IsNewLeftMouseReleased())
                    {
                        m_mouseOldPosition = MyGuiManager.MouseCursorPosition.Y;
                        m_mousePositionReinit = true;
                    }

                    //  Don't try close combobox if listbox mode is suported.
                    if (m_supportListBoxMode == false)
                    {
                        //  If ESC was pressed while combobox has keyboard focus and combobox was opened, then close combobox but don't send this ESC to parent screen
                        //  Or if user clicked outside of the combobox's area
                        if (((hasKeyboardActiveControl == true) && (input.IsNewKeyPress(Keys.Escape) || input.IsJoystickButtonNewPressed(MyJoystickButtonsEnum.J02))) ||
                            ((IsMouseOverOnOpenedArea() != true) && (IsMouseOver() != true) && (input.IsNewLeftMouseReleased() == true)))
                        {
                            MyAudio.AddCue2D(MySoundCuesEnum.GuiMouseClick);
                            m_isOpen = false;
                        }

                        //  Still capture focus, don't allow parent screen to receive this ESCAPE
                        captureInput = true;
                    }

                    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    //  Mouse controling items in the combobox
                    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                    if (m_scrollBarDragging == false)
                    {
                        #region Handle item that is under mouse cursor
                        //  Search for item that is under the mouse cursor
                        m_preselectedMouseOverPrevious = m_preselectedMouseOver;
                        m_preselectedMouseOver = null;

                        //  The following are used for controlling scroll window range
                        int startIndex = 0;
                        int endIndex = m_items.Count;
                        float widthOffSet = 0f;
                        if (m_showScrollBar == true)
                        {
                            if (m_supportSmoothScroll == true)
                            {
                                //  Extend the display items range by 1(top and bottom) in smooth scrolling mode because of the scenario of partial rendering
                                startIndex = Math.Max(0, m_displayItemsStartIndex - 1);
                                endIndex = Math.Min(m_items.Count, endIndex + 1);
                            }
                            else
                            {
                                startIndex = m_displayItemsStartIndex;
                                endIndex = m_displayItemsEndIndex;
                            }
                            widthOffSet = 0.025f;
                        }

                        for (int i = startIndex; i < endIndex; i++)
                        {
                            Vector2 position = GetOpenItemPosition(i - m_displayItemsStartIndex);
                            MyRectangle2D openedArea = GetOpenedArea();
                            Vector2 min = new Vector2(position.X, Math.Max(openedArea.LeftTop.Y, position.Y));
                            Vector2 max = min + new Vector2(m_size.Value.X - widthOffSet, m_comboboxItemDeltaHeight);

                            if ((MyGuiManager.MouseCursorPosition.X >= min.X) && (MyGuiManager.MouseCursorPosition.X <= max.X) && (MyGuiManager.MouseCursorPosition.Y >= min.Y) && (MyGuiManager.MouseCursorPosition.Y <= max.Y))
                            {
                                m_preselectedMouseOver = m_items[i];

                                //  Auto snap(scroll) current pre-selected/selected item to be fully visible 
                                if (m_supportSmoothScroll == true)
                                {
                                    if (position.Y + 0.001f < openedArea.LeftTop.Y)
                                    {
                                        float scrollUpBy = m_scrollBarCurrentPosition.Value;
                                        scrollUpBy -= 0.001f;
                                        SetScrollBarPosition(scrollUpBy);
                                    }
                                    else if (position.Y + m_comboboxItemDeltaHeight - 0.001f > openedArea.LeftTop.Y + openedArea.Size.Y)
                                    {
                                        float scrollDownBy = m_scrollBarCurrentPosition.Value;
                                        scrollDownBy += 0.001f;
                                        SetScrollBarPosition(scrollDownBy);
                                    }
                                }
                            }
                        }

                        if (m_preselectedMouseOver != null && m_preselectedMouseOver != m_preselectedMouseOverPrevious)
                        {
                            MyAudio.AddCue2D(MySoundCuesEnum.GuiMouseOver);
                        }

                        //  To be used to check for mouse double click action
                        m_doubleClickTimer += MyConstants.PHYSICS_STEP_SIZE_IN_MILLISECONDS;

                        #endregion

                        #region Selecting item in opened combobox area
                        //  Select item when user clicks on it
                        if (input.IsNewLeftMouseReleased() == true && m_preselectedMouseOver != null)
                        {                            
                            //  Checks for double click, only listbox mode supports this type of input
                            if (m_supportListBoxMode == true && m_preselectedMouseOver.Key.Equals(m_selected.Key) == true && m_doubleClickTimer < DOUBLE_CLICK_DELAY)
                            {
                                if (OnSelectItemDoubleClick != null)
                                    OnSelectItemDoubleClick();
                            }
                            m_doubleClickTimer = 0;

                            //m_selected = m_preselectedMouseOver;
                            SelectItemByKey(m_preselectedMouseOver.Key);

                            MyAudio.AddCue2D(MySoundCuesEnum.GuiMouseClick);
                            if (m_supportListBoxMode == false) m_isOpen = false;

                            //  Still capture focus, don't allow parent screen to receive this CLICK
                            captureInput = true;                                                   
                        }
                        #endregion

                        #region Keyboard and scrollwheel controlling items in combobox

                        if (hasKeyboardActiveControl == true || IsMouseOverOnOpenedArea())
                        {
                            if (m_mouseWheelValueLast == null) m_mouseWheelValueLast = input.MouseScrollWheelValue();

                            if (input.MouseScrollWheelValue() < m_mouseWheelValueLast)
                            {
                                HandleItemMovement(true);
                                captureInput = true;
                            }
                            else if (input.MouseScrollWheelValue() > m_mouseWheelValueLast)
                            {
                                HandleItemMovement(false);
                                captureInput = true;
                            }

                            //  Keyboard and mouse movement
                            if (input.IsNewKeyPress(Keys.Down) || input.IsNewGamepadKeyDownPressed())
                            {
                                HandleItemMovement(true);
                                captureInput = true;
                            }
                            else if (input.IsNewKeyPress(Keys.Up) || input.IsNewGamepadKeyUpPressed())
                            {
                                HandleItemMovement(false);
                                captureInput = true;
                            }
                            else if (input.IsNewKeyPress(Keys.PageDown))
                            {
                                HandleItemMovement(true, true);
                            }
                            else if (input.IsNewKeyPress(Keys.PageUp))
                            {
                                HandleItemMovement(false, true);
                            }
                            else if (input.IsNewKeyPress(Keys.Home))
                            {
                                HandleItemMovement(true, false, true);
                            }
                            else if (input.IsNewKeyPress(Keys.End))
                            {
                                HandleItemMovement(false, false, true);
                            }
                            else if (input.IsNewKeyPress(Keys.Tab))
                            {
                                //  We want to close the combobox without selecting any item and forward TAB or SHIF+TAB to parent screen so it can navigate to next control
                                if (m_supportListBoxMode == false && m_isOpen) SwitchComboboxMode();
                                captureInput = false;
                            }

                            m_mouseWheelValueLast = input.MouseScrollWheelValue();
                        }
                        #endregion
                    }
                    else
                    {
                        // When finished scrollbar dragging, set it to false and enable input capturing again
                        if (input.IsNewLeftMouseReleased()) m_scrollBarDragging = false;
                        captureInput = true;
                    }
                }
            }

            return captureInput;
        }
Ejemplo n.º 15
0
        public bool HandleInput(MyGuiInput input, bool hasKeyboardActiveControl, bool hasKeyboardActiveControlPrevious, bool receivedFocusInThisUpdate)
        {
            var oldHooveredItem = HooveredItem;
            HooveredItem = null;

            bool captured =
                m_body.HandleInput(input, hasKeyboardActiveControl, hasKeyboardActiveControlPrevious, receivedFocusInThisUpdate) ||
                m_vScrollbar.HandleInput(input, hasKeyboardActiveControl, hasKeyboardActiveControlPrevious, receivedFocusInThisUpdate) ||
                m_hScrollbar.HandleInput(input, hasKeyboardActiveControl, hasKeyboardActiveControlPrevious, receivedFocusInThisUpdate);

            if (hasKeyboardActiveControl)
            {
                if (FocusedItem == null &&
                    m_body.GetItemCount() > 0 &&
                    (input.IsNewKeyPress(Keys.Up) ||
                     input.IsNewKeyPress(Keys.Down) ||
                     input.IsNewKeyPress(Keys.Left) ||
                     input.IsNewKeyPress(Keys.Right) ||
                     input.DeltaMouseScrollWheelValue() != 0))
                {
                    FocusItem(m_body[0]);
                }
                else if (FocusedItem != null)
                {
                    if (input.IsNewKeyPress(Keys.Down) || (input.DeltaMouseScrollWheelValue() < 0 && Contains(MyGuiManager.MouseCursorPosition.X, MyGuiManager.MouseCursorPosition.Y)))
                    {
                        FocusItem(NextVisible(m_body, FocusedItem));
                    }

                    if (input.IsNewKeyPress(Keys.Up) || (input.DeltaMouseScrollWheelValue() > 0 && Contains(MyGuiManager.MouseCursorPosition.X, MyGuiManager.MouseCursorPosition.Y)))
                    {
                        FocusItem(PrevVisible(m_body, FocusedItem));
                    }

                    if (input.IsNewKeyPress(Keys.Right))
                    {
                        if (FocusedItem.GetItemCount() > 0)
                        {
                            if (!FocusedItem.IsExpanded)
                            {
                                FocusedItem.IsExpanded = true;
                            }
                            else
                            {
                                var next = NextVisible(FocusedItem, FocusedItem);
                                FocusItem(next);
                            }
                        }
                    }

                    if (input.IsNewKeyPress(Keys.Left))
                    {
                        if (FocusedItem.GetItemCount() > 0 && FocusedItem.IsExpanded)
                        {
                            FocusedItem.IsExpanded = false;
                        }
                        else if (FocusedItem.Parent is MyTreeViewItem)
                        {
                            FocusItem(FocusedItem.Parent as MyTreeViewItem);
                        }
                    }

                    if (FocusedItem.GetItemCount() > 0)
                    {
                        if (input.IsNewKeyPress(Keys.Add))
                        {
                            FocusedItem.IsExpanded = true;
                        }

                        if (input.IsNewKeyPress(Keys.Subtract))
                        {
                            FocusedItem.IsExpanded = false;
                        }
                    }
                }

                if (input.IsNewKeyPress(Keys.PageDown))
                {
                    m_vScrollbar.PageDown();
                }

                if (input.IsNewKeyPress(Keys.PageUp))
                {
                    m_vScrollbar.PageUp();
                }

                captured = captured ||
                           input.IsNewKeyPress(Keys.PageDown) ||
                           input.IsNewKeyPress(Keys.PageUp) ||
                           input.IsNewKeyPress(Keys.Down) ||
                           input.IsNewKeyPress(Keys.Up) ||
                           input.IsNewKeyPress(Keys.Left) ||
                           input.IsNewKeyPress(Keys.Right) ||
                           input.IsNewKeyPress(Keys.Add) ||
                           input.IsNewKeyPress(Keys.Subtract) ||
                           input.DeltaMouseScrollWheelValue() != 0;
            }

            // Hoovered item changed
            if (HooveredItem != oldHooveredItem)
            {
                m_control.ShowToolTip(HooveredItem == null ? null : HooveredItem.ToolTip);
                MyAudio.AddCue2D(MySoundCuesEnum.GuiMouseOver);
            }

            return captured;
        }
        public override bool HandleInput(MyGuiInput input, bool hasKeyboardActiveControl, bool hasKeyboardActiveControlPrevious, bool receivedFocusInThisUpdate)
        {
            //If this control is not enable, do nothing
            if (!IsEnable) return false;

            if (Visible)
            {
                if (((input.IsKeyPress(Keys.LeftShift) || input.IsKeyPress(Keys.RightShift)) && input.IsNewKeyPress(Keys.Tab)) || input.IsNewKeyPress(Keys.Up) || input.IsNewGamepadKeyUpPressed())
                    SelectPrev();
                if ((!(input.IsKeyPress(Keys.LeftShift) || input.IsKeyPress(Keys.RightShift)) && input.IsNewKeyPress(Keys.Tab)) || input.IsNewKeyPress(Keys.Down) || input.IsNewGamepadKeyDownPressed())
                    SelectNext();
                if (input.IsNewKeyPress(Keys.Escape) || input.IsJoystickButtonNewPressed(MyJoystickButtonsEnum.J02))
                    HideScreenIfPossible();

                if (m_displayedItems[m_selected] != null)
                {
                    if (input.IsNewKeyPress(Keys.Left) || input.IsNewGamepadKeyLeftPressed())
                        m_displayedItems[m_selected].ChangeValueDown();
                    if (input.IsNewKeyPress(Keys.Right) || input.IsNewGamepadKeyRightPressed())
                        m_displayedItems[m_selected].ChangeValueUp();
                    if (input.IsNewKeyPress(Keys.Enter) || input.IsNewKeyPress(Keys.Space) || input.IsJoystickButtonNewPressed(MyJoystickButtonsEnum.J01))
                        m_displayedItems[m_selected].ChangeValueUp();
                }
                
                HandleMouse(input);
            }

            if (input.IsNewGameControlPressed(MyGameControlEnums.WHEEL_CONTROL))
            {
                m_first = 0;
                Visible = !Visible;
                if (Visible == false)
                {
                    MyAudio.AddCue2D(MySoundCuesEnum.GuiWheelControlClose);
                }
                else
                {
                    MyAudio.AddCue2D(MySoundCuesEnum.GuiWheelControlOpen);
                }
            }

            return base.HandleInput(input, hasKeyboardActiveControl, hasKeyboardActiveControlPrevious, receivedFocusInThisUpdate);
        }
        public override void HandleInput(MyGuiInput input, bool receivedFocusInThisUpdate)
        {
            base.HandleInput(input, receivedFocusInThisUpdate);

            if (input.IsNewKeyPress(Keys.Escape))
            {
                //CloseScreen();
                OnCancelClick(null);
            }
        }
Ejemplo n.º 18
0
        //  Method returns true if input was captured by control, so no other controls, nor screen can use input in this update
        public override bool HandleInput(MyGuiInput input, bool hasKeyboardActiveControl, bool hasKeyboardActiveControlPrevious, bool isThisFirstHandleInput)
        {
            if (!Enabled)
                return false;

            bool ret = base.HandleInput(input, hasKeyboardActiveControl, hasKeyboardActiveControlPrevious, isThisFirstHandleInput);

            if (ret == false)
            {
                if (((IsMouseOver() == true) && input.IsNewLeftMousePressed() ) ||
                    ((hasKeyboardActiveControl == true) && ((input.IsNewKeyPress(Keys.Enter) || (input.IsNewKeyPress(Keys.Space)) || (input.IsNewGameControlPressed(MyGameControlEnums.FIRE_PRIMARY) && !input.IsNewLeftMousePressed())))))
                {
                    UserCheck();

                    ret = true;
                }
            }

            return ret;
        }
Ejemplo n.º 19
0
        public static void HandleInput(MyGuiInput input)
        {
            if (input.IsAnyAltPress())
            {
                for (int i = 0; i <= 9; i++)
                {
                    var key = (Keys)((int)Keys.NumPad0 + i);
                    if (input.IsNewKeyPress(key))
                    {
                        PressedKey(key, input.IsAnyCtrlKeyPressed());
                    }
                }

                if (input.IsNewKeyPress(Keys.Add))
                {
                    PressedKey(Keys.Add);
                }

                if (input.IsNewKeyPress(Keys.Subtract))
                {
                    PressedKey(Keys.Subtract);
                }

                if (input.IsNewKeyPress(Keys.Enter))
                {
                    PressedKey(Keys.Enter);
                }

                if (input.IsNewKeyPress(Keys.Delete))
                {
                    PressedKey(Keys.Delete);
                }

                if (input.IsKeyPress(Keys.PageDown))
                {
                    MyRenderProfiler.PreviousFrame();
                }

                if (input.IsKeyPress(Keys.PageUp))
                {
                    MyRenderProfiler.NextFrame();
                }

                if (input.IsKeyPress(Keys.Multiply))
                {
                    PressedKey(Keys.Multiply);
                }

                if (input.IsKeyPress(Keys.Divide))
                {
                    PressedKey(Keys.Divide);
                }

                if ((((input.IsKeyPress(Keys.PageDown)) ||
                      (input.IsKeyPress(Keys.PageUp))) && input.IsAnyCtrlKeyPressed())
                    ||
                    (input.IsKeyPress(Keys.Multiply) || input.IsKeyPress(Keys.Divide))
                    )

                {
                    System.Threading.Thread.Sleep(100);
                }
            }
        }
Ejemplo n.º 20
0
        //  Method returns true if input was captured by control, so no other controls, nor screen can use input in this update
        public override bool HandleInput(MyGuiInput input, bool hasKeyboardActiveControl, bool hasKeyboardActiveControlPrevious, bool receivedFocusInThisUpdate)
        {
            bool captureInput = base.HandleInput(input, hasKeyboardActiveControl, hasKeyboardActiveControlPrevious, receivedFocusInThisUpdate);

            if (captureInput == false)
            {
                if (((IsMouseOver() == true) && ((input.IsNewLeftMouseReleased() == true))) ||
                    ((hasKeyboardActiveControl == true) && (m_canHandleKeyboardInput == true) && ((input.IsJoystickButtonNewPressed(MyJoystickButtonsEnum.J01)) || (input.IsNewKeyPress(Keys.Enter)) || (input.IsNewKeyPress(Keys.Space)))))
                {
                    if (m_implementedFeature == false)
                    {
                        MyAudio.AddCue2D(MySoundCuesEnum.GuiMouseClick);
                        MyGuiManager.AddScreen(new MyGuiScreenMessageBox(MyMessageBoxType.ERROR, MyTextsWrapperEnum.FeatureNotYetImplemented,
                            MyTextsWrapperEnum.MessageBoxCaptionFeatureDisabled, MyTextsWrapperEnum.Ok, null));
                    }
                    else if (m_accessForbiddenReason != null)
                    {
                        MyAudio.AddCue2D(MySoundCuesEnum.GuiMouseClick);
                        MyGuiManager.AddScreen(new MyGuiScreenMessageBox(MyMessageBoxType.ERROR, m_accessForbiddenReason.Value,
                            MyTextsWrapperEnum.MessageBoxCaptionFeatureDisabled, MyTextsWrapperEnum.Ok, null));
                    }
                    else if (Enabled || UseSwitchMode)
                    {
                        MyAudio.AddCue2D(MySoundCuesEnum.GuiMouseClick);
                        if (m_onButtonClick != null)
                        {
                            m_onButtonClick(this);
                        }
                        else if (m_onIndexedButtonClick != null)
                        {
                            m_onIndexedButtonClick(m_buttonIndex);
                        }
                    }

                    captureInput = true;
                }
            }

            return captureInput;
        }
Ejemplo n.º 21
0
        public virtual void HandleInput(MyGuiInput input, bool receivedFocusInThisUpdate)
        {
            //  Here we can make some one-time initialization hidden in update
            bool isThisFirstHandleInput = !m_firstUpdateServed;

            if (m_firstUpdateServed == false && m_keyboardControlIndex == -1) //m_keyboardControlIndex could be set from constructor
            {
                //  Move to first control that can accept it
                //Controls.HandleKeyboardActiveIndex(true);
                HandleKeyboardActiveIndex(true);

                //  Never again call this update-initialization
                m_firstUpdateServed = true;
            }

            // if we are dragging some control, then we don't pass this focus to controls
            if (MyFakes.CONTROLS_MOVE_ENABLED && input.IsKeyPress(Keys.M))
            {
                if (HandleControlMoving(input))
                {
                    return;
                }
            }

            if (MyModelsStatisticsConstants.GET_MODEL_STATISTICS_AUTOMATICALLY)
            {
                if (MyMinerGame.IsGameReady)
                {
                    Models.MyModels.LogUsageInformation();
                }
            }

            if (!HandleControlsInput(input, receivedFocusInThisUpdate))
            {
                bool handled = false;
                //  If input wasn't completely handled or captured by some control, only then we can handle screen's input
                if ((input.IsKeyPress(Keys.LeftShift) && (input.IsNewKeyPress(Keys.Tab))) || (input.IsNewKeyPress(Keys.Up)) || (input.IsNewGamepadKeyUpPressed()))
                {
                    handled = HandleKeyboardActiveIndex(false);
                }
                else if ((input.IsNewKeyPress(Keys.Tab)) || (input.IsNewKeyPress(Keys.Down)) || (input.IsNewGamepadKeyDownPressed()))
                {
                    handled = HandleKeyboardActiveIndex(true);
                }
                else if ((m_closeOnEsc == true) && ((input.IsNewKeyPress(Keys.Escape) || input.IsJoystickButtonNewPressed(MyJoystickButtonsEnum.J02))))
                {
                    Canceling();
                }
                else if ((OnEnterCallback != null) && (input.IsNewKeyPress(Keys.Enter)))
                {
                    OnEnterCallback();
                }

                // Scrolling down/up between controls using mouse scroll wheel
                //if (input.PreviousMouseScrollWheelValue() > input.MouseScrollWheelValue())
                //{
                //    handled = HandleKeyboardActiveIndex(true);
                //}
                //else if (input.PreviousMouseScrollWheelValue() < input.MouseScrollWheelValue())
                //{
                //    handled = HandleKeyboardActiveIndex(false);
                //}

                if (!handled)
                {
                    HandleUnhandledInput(input, receivedFocusInThisUpdate);
                }
            }
        }
Ejemplo n.º 22
0
        //  Method returns true if input was captured by control, so no other controls, nor screen can use input in this update
        public override bool HandleInput(MyGuiInput input, bool hasKeyboardActiveControl, bool hasKeyboardActiveControlPrevious, bool isThisFirstHandleInput)
        {
            if (!Visible)
            {
                return(false);
            }

            bool ret = base.HandleInput(input, hasKeyboardActiveControl, hasKeyboardActiveControlPrevious, isThisFirstHandleInput);

            if (ret == false)
            {
                if ((IsMouseOver() == true) && (input.IsNewLeftMousePressed() == true))
                {
                    m_carriagePositionIndex = GetCarriagePositionFromMouseCursor();
                    ret = true;
                }

                if ((m_hasKeyboardActiveControl == true) && (hasKeyboardActiveControlPrevious == false))
                {
                    UpdateLastKeyPressTimes(null);
                }

                if (hasKeyboardActiveControl == true)
                {
                    bool isShiftPressed = input.IsKeyPress(Keys.LeftShift) || input.IsKeyPress(Keys.RightShift);
                    bool isCapsLockOn   = (ushort)MyGuiInput.GetKeyState(0x14) == 1;

                    //(deltaFromLastKeypress > MyGuiConstants.TEXTBOX_KEYPRESS_DELAY)
                    //int deltaFromLastKeypress = MyMinerGame.TotalGameTime_Miliseconds - m_lastKeyPressTime;

                    input.GetPressedKeys(m_pressedKeys);

                    for (int i = 0; i < m_pressedKeys.Count; i++)
                    {
                        System.Diagnostics.Debug.Assert(input.IsKeyPress((Keys)m_pressedKeys[i]));
                    }

                    //  Transform pressed letters, characters, numbers, etc to real character/string
                    for (int i = 0; i < m_pressedKeys.Count; i++)
                    {
                        bool tempShift     = isShiftPressed;
                        bool transformText = true;
                        MyGuiControlTextboxKeyToString pressedKey = m_keyToString[(int)m_pressedKeys[i]];

                        //Allow to enter only digits in case such textbox type is set
                        if (m_type == MyGuiControlTextboxType.DIGITS_ONLY)
                        {
                            if ((pressedKey != null) && !input.IsKeyDigit(pressedKey.Key) && pressedKey.Key != Keys.OemPeriod && pressedKey.Key != Keys.Decimal)
                            {
                                transformText = false;
                            }
                        }

                        if (transformText)
                        {
                            //  If we have mapping from this key to string (that means it's allowed character)
                            if (pressedKey != null && m_text.Length < m_maxLength && pressedKey.Character != null && pressedKey.CharacterWhenShift != null)
                            {
                                ret = true;
                                if (IsEnoughDelay((Keys)m_pressedKeys[i], MyGuiConstants.TEXTBOX_CHANGE_DELAY))
                                {
                                    if (Char.IsLetter(pressedKey.Character, 0))
                                    {
                                        if (isCapsLockOn)
                                        {
                                            tempShift = !tempShift;//carefull here variable is not used anymore so we can invert it
                                        }
                                    }
                                    m_text = m_text.Insert(m_carriagePositionIndex, (tempShift == true) ? pressedKey.CharacterWhenShift : pressedKey.Character);

                                    m_carriagePositionIndex++;
                                    UpdateLastKeyPressTimes((Keys)m_pressedKeys[i]);

                                    OnTextChanged();
                                }
                            }
                        }
                    }

                    //  Move left
                    if ((input.IsKeyPress(Keys.Left)) && (IsEnoughDelay(Keys.Left, MyGuiConstants.TEXTBOX_MOVEMENT_DELAY)))
                    {
                        m_carriagePositionIndex--;
                        if (m_carriagePositionIndex < 0)
                        {
                            m_carriagePositionIndex = 0;
                        }
                        UpdateLastKeyPressTimes(Keys.Left);
                    }

                    //  Move right
                    if ((input.IsKeyPress(Keys.Right)) && (IsEnoughDelay(Keys.Right, MyGuiConstants.TEXTBOX_MOVEMENT_DELAY)))
                    {
                        m_carriagePositionIndex++;
                        if (m_carriagePositionIndex > m_text.Length)
                        {
                            m_carriagePositionIndex = m_text.Length;
                        }
                        UpdateLastKeyPressTimes(Keys.Right);
                    }

                    //  Move home
                    if ((input.IsNewKeyPress(Keys.Home)) && (IsEnoughDelay(Keys.Home, MyGuiConstants.TEXTBOX_MOVEMENT_DELAY)))
                    {
                        m_carriagePositionIndex = 0;
                        UpdateLastKeyPressTimes(Keys.Home);
                    }

                    //  Move end
                    if ((input.IsNewKeyPress(Keys.End)) && (IsEnoughDelay(Keys.End, MyGuiConstants.TEXTBOX_MOVEMENT_DELAY)))
                    {
                        m_carriagePositionIndex = m_text.Length;
                        UpdateLastKeyPressTimes(Keys.End);
                    }

                    //  Delete
                    if ((input.IsKeyPress(Keys.Delete)) && (IsEnoughDelay(Keys.Delete, MyGuiConstants.TEXTBOX_MOVEMENT_DELAY)))
                    {
                        if (m_carriagePositionIndex < m_text.Length)
                        {
                            m_text = m_text.Remove(m_carriagePositionIndex, 1);
                            UpdateLastKeyPressTimes(Keys.Delete);

                            OnTextChanged();
                        }
                    }

                    //  Backspace
                    if ((input.IsKeyPress(Keys.Back)) && (IsEnoughDelay(Keys.Back, MyGuiConstants.TEXTBOX_MOVEMENT_DELAY)))
                    {
                        if (m_carriagePositionIndex > 0)
                        {
                            // Handle text scrolling, basicaly try hold carriage on same position in textBox window (avoid textBox with hidden characters)
                            var carriagePositionChange = GetCarriagePosition(m_carriagePositionIndex) - GetCarriagePosition(m_carriagePositionIndex - 1);;
                            var textAreaPosition       = GetTextAreaPosition();
                            if (m_slidingWindowPosition.X - carriagePositionChange.X >= textAreaPosition.X)
                            {
                                m_slidingWindowPosition.X -= carriagePositionChange.X;
                            }
                            else
                            {
                                m_slidingWindowPosition.X = textAreaPosition.X;
                            }

                            m_text = m_text.Remove(m_carriagePositionIndex - 1, 1);
                            m_carriagePositionIndex--;
                            UpdateLastKeyPressTimes(Keys.Back);

                            OnTextChanged();
                        }
                    }

                    ResetLastKeyPressTimes(input);
                    m_formattedAlready = false;
                }
                else
                {
                    if (m_type == MyGuiControlTextboxType.DIGITS_ONLY && m_formattedAlready == false && !string.IsNullOrEmpty(m_text))
                    {
                        var number        = MyValueFormatter.GetDecimalFromString(m_text, 1);
                        int decimalDigits = (number - (int)number > 0) ? 1 : 0;
                        m_text = MyValueFormatter.GetFormatedFloat((float)number, decimalDigits, "");
                        m_carriagePositionIndex = m_text.Length;
                        m_formattedAlready      = true;
                    }
                }
            }

            return(ret);
        }
Ejemplo n.º 23
0
        public bool HandleInput(MyGuiInput input, bool hasKeyboardActiveControl, bool hasKeyboardActiveControlPrevious, bool receivedFocusInThisUpdate)
        {
            var oldHooveredItem = HooveredItem;

            HooveredItem = null;

            bool captured =
                m_body.HandleInput(input, hasKeyboardActiveControl, hasKeyboardActiveControlPrevious, receivedFocusInThisUpdate) ||
                m_vScrollbar.HandleInput(input, hasKeyboardActiveControl, hasKeyboardActiveControlPrevious, receivedFocusInThisUpdate) ||
                m_hScrollbar.HandleInput(input, hasKeyboardActiveControl, hasKeyboardActiveControlPrevious, receivedFocusInThisUpdate);

            if (hasKeyboardActiveControl)
            {
                if (FocusedItem == null &&
                    m_body.GetItemCount() > 0 &&
                    (input.IsNewKeyPress(Keys.Up) ||
                     input.IsNewKeyPress(Keys.Down) ||
                     input.IsNewKeyPress(Keys.Left) ||
                     input.IsNewKeyPress(Keys.Right) ||
                     input.DeltaMouseScrollWheelValue() != 0))
                {
                    FocusItem(m_body[0]);
                }
                else if (FocusedItem != null)
                {
                    if (input.IsNewKeyPress(Keys.Down) || (input.DeltaMouseScrollWheelValue() < 0 && Contains(MyGuiManager.MouseCursorPosition.X, MyGuiManager.MouseCursorPosition.Y)))
                    {
                        FocusItem(NextVisible(m_body, FocusedItem));
                    }

                    if (input.IsNewKeyPress(Keys.Up) || (input.DeltaMouseScrollWheelValue() > 0 && Contains(MyGuiManager.MouseCursorPosition.X, MyGuiManager.MouseCursorPosition.Y)))
                    {
                        FocusItem(PrevVisible(m_body, FocusedItem));
                    }

                    if (input.IsNewKeyPress(Keys.Right))
                    {
                        if (FocusedItem.GetItemCount() > 0)
                        {
                            if (!FocusedItem.IsExpanded)
                            {
                                FocusedItem.IsExpanded = true;
                            }
                            else
                            {
                                var next = NextVisible(FocusedItem, FocusedItem);
                                FocusItem(next);
                            }
                        }
                    }

                    if (input.IsNewKeyPress(Keys.Left))
                    {
                        if (FocusedItem.GetItemCount() > 0 && FocusedItem.IsExpanded)
                        {
                            FocusedItem.IsExpanded = false;
                        }
                        else if (FocusedItem.Parent is MyTreeViewItem)
                        {
                            FocusItem(FocusedItem.Parent as MyTreeViewItem);
                        }
                    }

                    if (FocusedItem.GetItemCount() > 0)
                    {
                        if (input.IsNewKeyPress(Keys.Add))
                        {
                            FocusedItem.IsExpanded = true;
                        }

                        if (input.IsNewKeyPress(Keys.Subtract))
                        {
                            FocusedItem.IsExpanded = false;
                        }
                    }
                }

                if (input.IsNewKeyPress(Keys.PageDown))
                {
                    m_vScrollbar.PageDown();
                }

                if (input.IsNewKeyPress(Keys.PageUp))
                {
                    m_vScrollbar.PageUp();
                }

                captured = captured ||
                           input.IsNewKeyPress(Keys.PageDown) ||
                           input.IsNewKeyPress(Keys.PageUp) ||
                           input.IsNewKeyPress(Keys.Down) ||
                           input.IsNewKeyPress(Keys.Up) ||
                           input.IsNewKeyPress(Keys.Left) ||
                           input.IsNewKeyPress(Keys.Right) ||
                           input.IsNewKeyPress(Keys.Add) ||
                           input.IsNewKeyPress(Keys.Subtract) ||
                           input.DeltaMouseScrollWheelValue() != 0;
            }

            // Hoovered item changed
            if (HooveredItem != oldHooveredItem)
            {
                m_control.ShowToolTip(HooveredItem == null ? null : HooveredItem.ToolTip);
                MyAudio.AddCue2D(MySoundCuesEnum.GuiMouseOver);
            }

            return(captured);
        }
Ejemplo n.º 24
0
        public override bool HandleInput(MyGuiInput input, bool hasKeyboardActiveControl, bool hasKeyboardActiveControlPrevious, bool receivedFocusInThisUpdate)
        {
            //If this control is not enable, do nothing
            if (!IsEnabled)
            {
                return(false);
            }

            bool isKeyPress = false;
            bool backwardSelectDirection = input.IsKeyPress(Keys.LeftShift) || input.IsKeyPress(Keys.RightShift);
            int  deltaWheelPos           = input.PreviousMouseScrollWheelValue() - input.MouseScrollWheelValue();

            if (deltaWheelPos != 0) // determine just direction
            {
                deltaWheelPos /= Math.Abs(deltaWheelPos);
            }

            if (input.IsNewGameControlPressed(MyGameControlEnums.SELECT_AMMO_BULLET))
            {
                isKeyPress      = true;
                m_selectedGroup = MyMwcObjectBuilder_AmmoGroupEnum.Bullet;
            }

            if (input.IsNewGameControlPressed(MyGameControlEnums.SELECT_AMMO_MISSILE))
            {
                isKeyPress      = true;
                m_selectedGroup = MyMwcObjectBuilder_AmmoGroupEnum.Missile;
            }

            if (input.IsNewGameControlPressed(MyGameControlEnums.SELECT_AMMO_CANNON))
            {
                isKeyPress      = true;
                m_selectedGroup = MyMwcObjectBuilder_AmmoGroupEnum.Cannon;
            }

            if (input.IsNewGameControlPressed(MyGameControlEnums.SELECT_AMMO_UNIVERSAL_LAUNCHER_FRONT))
            {
                isKeyPress      = true;
                m_selectedGroup = MyMwcObjectBuilder_AmmoGroupEnum.UniversalLauncherFront;
            }

            if (input.IsNewGameControlPressed(MyGameControlEnums.SELECT_AMMO_UNIVERSAL_LAUNCHER_BACK))
            {
                isKeyPress      = true;
                m_selectedGroup = MyMwcObjectBuilder_AmmoGroupEnum.UniversalLauncherBack;
            }

            // in case of wheel direction modify flags to run correct code
            if (deltaWheelPos > 0 && Visible && IsEnabled)
            {
                isKeyPress = true;
                backwardSelectDirection = false;
            }
            // in case of wheel direction modify flags to run correct code
            if (deltaWheelPos < 0 && Visible && IsEnabled)
            {
                isKeyPress = true;
                backwardSelectDirection = true;
            }

            if (isKeyPress)
            {
                if (Visible == false)
                {
                    //I am here when the menu opens
                    LoadAmmoFromShip();
                    //If player change fire commands during game play, we need to show actual buttons names.
                    //ReloadControlText();
                    MyGuiSmallShipHelperAmmo.ResetDescription();
                }
                else
                {
                    if (m_selectedGroup == m_selectedGroupLast)
                    {
                        // if (!MyFakes.MW25D)
                        {
                            if (!backwardSelectDirection)
                            {
                                m_selectedIndex++;
                            }
                            else
                            {
                                m_selectedIndex--;
                            }
                        }
                        // else
                        //   m_selectedIndex = 0;
                    }
                    else
                    {
                        //I am here when category is changed
                        LoadAmmoFromShip();
                        MyGuiSmallShipHelperAmmo.ResetDescription();
                    }

                    if (m_selectedIndex >= m_ammoTypesAmounts.Count)
                    {
                        m_selectedIndex = 0;
                    }
                    if (m_selectedIndex < 0)
                    {
                        m_selectedIndex = m_ammoTypesAmounts.Count - 1;
                    }
                }

                Visible             = true;
                m_selectedGroupLast = m_selectedGroup;
                if (m_selectedIndex < m_ammoTypesAmounts.Count && m_selectedIndex >= 0)
                {
                    m_selectedAmmo = m_ammoTypesAmounts[m_selectedIndex].Type;
                }

                MyAudio.AddCue2D(MySoundCuesEnum.SfxHudWeaponScroll);
            }


            //Because I do not want the gun fired before I made the choice, the menu disappears after the release of key (not press)
            if (Visible)
            {
                if (!MySession.Is25DSector)
                {
                    if (input.IsGameControlPressed(MyGameControlEnums.FIRE_PRIMARY) && m_selectedAmmo != 0)
                    {
                        MySession.PlayerShip.Weapons.AmmoAssignments.AssignAmmo(MyMwcObjectBuilder_FireKeyEnum.Primary, m_selectedGroup, m_selectedAmmo);
                        m_isPressLast = true;
                    }
                    if (input.IsGameControlPressed(MyGameControlEnums.FIRE_SECONDARY) && m_selectedAmmo != 0)
                    {
                        MySession.PlayerShip.Weapons.AmmoAssignments.AssignAmmo(MyMwcObjectBuilder_FireKeyEnum.Secondary, m_selectedGroup, m_selectedAmmo);
                        m_isPressLast = true;
                    }
                    if (input.IsGameControlPressed(MyGameControlEnums.FIRE_THIRD) && m_selectedAmmo != 0)
                    {
                        MySession.PlayerShip.Weapons.AmmoAssignments.AssignAmmo(MyMwcObjectBuilder_FireKeyEnum.Third, m_selectedGroup, m_selectedAmmo);
                        m_isPressLast = true;
                    }
                    if (input.IsGameControlPressed(MyGameControlEnums.FIRE_FOURTH) && m_selectedAmmo != 0)
                    {
                        MySession.PlayerShip.Weapons.AmmoAssignments.AssignAmmo(MyMwcObjectBuilder_FireKeyEnum.Fourth, m_selectedGroup, m_selectedAmmo);
                        m_isPressLast = true;
                    }
                    if (input.IsGameControlPressed(MyGameControlEnums.FIRE_FIFTH) && m_selectedAmmo != 0)
                    {
                        MySession.PlayerShip.Weapons.AmmoAssignments.AssignAmmo(MyMwcObjectBuilder_FireKeyEnum.Fifth, m_selectedGroup, m_selectedAmmo);
                        m_isPressLast = true;
                    }

                    if (input.IsNewKeyPress(Keys.Escape))
                    {
                        Visible = false;
                    }
                }
                else
                {  //MyFakes.MW25D
                    if (input.IsGameControlPressed(MyGameControlEnums.FIRE_PRIMARY) && m_selectedAmmo != 0)
                    {
                        MySession.PlayerShip.Weapons.AmmoAssignments.AssignAmmo(MyMwcObjectBuilder_FireKeyEnum.Primary, m_selectedGroup, m_selectedAmmo);
                        m_isPressLast = true;
                    }
                    if (input.IsGameControlPressed(MyGameControlEnums.FIRE_SECONDARY) && m_selectedAmmo != 0)
                    {
                        MySession.PlayerShip.Weapons.AmmoAssignments.AssignAmmo(MyMwcObjectBuilder_FireKeyEnum.Primary, m_selectedGroup, m_selectedAmmo);
                        m_isPressLast = true;
                    }
                    if (input.IsGameControlPressed(MyGameControlEnums.FIRE_THIRD) && m_selectedAmmo != 0)
                    {
                        MySession.PlayerShip.Weapons.AmmoAssignments.AssignAmmo(MyMwcObjectBuilder_FireKeyEnum.Primary, m_selectedGroup, m_selectedAmmo);
                        m_isPressLast = true;
                    }
                    if (input.IsGameControlPressed(MyGameControlEnums.FIRE_FOURTH) && m_selectedAmmo != 0)
                    {
                        MySession.PlayerShip.Weapons.AmmoAssignments.AssignAmmo(MyMwcObjectBuilder_FireKeyEnum.Primary, m_selectedGroup, m_selectedAmmo);
                        m_isPressLast = true;
                    }
                    if (input.IsGameControlPressed(MyGameControlEnums.FIRE_FIFTH) && m_selectedAmmo != 0)
                    {
                        MySession.PlayerShip.Weapons.AmmoAssignments.AssignAmmo(MyMwcObjectBuilder_FireKeyEnum.Primary, m_selectedGroup, m_selectedAmmo);
                        m_isPressLast = true;
                    }

                    if (input.IsNewKeyPress(Keys.Escape))
                    {
                        Visible = false;
                    }
                }

                for (int i = m_ammoTypesAmounts.Count - 1; i >= 0; i--)
                {
                    int itemsPerColumn = 7;

                    int orderX = (int)m_selectedGroup + i / itemsPerColumn;
                    int orderY = i % itemsPerColumn;

                    /*
                     * Vector2 mousePos = MyGuiManager.MouseCursorPosition;
                     * if (MyVideoModeManager.IsTripleHead() == true)
                     *  mousePos += new Vector2(-1, 0);
                     *
                     * if (MyGuiSmallShipHelpers.GetMyGuiSmallShipHelperAmmo(m_ammoTypesAmounts[i].Type).IsPointInMyArea(mousePos))
                     * {
                     * }
                     */
                    //if (MyGuiSmallShipHelpers.GetMyGuiSmallShipHelperAmmo(m_ammoTypesAmounts[i].Type).IsPointInMyArea(MyGuiManager.MouseCursorPosition))
                    MyGuiSmallShipHelperAmmo ammoHelper =
                        MyGuiObjectBuilderHelpers.GetGuiHelper(MyMwcObjectBuilderTypeEnum.SmallShip_Ammo, (int)m_ammoTypesAmounts[i].Type) as MyGuiSmallShipHelperAmmo;
                    if (ammoHelper.IsPointInMyArea(MyGuiManager.MouseCursorPosition))
                    {
                        if (m_selectedIndex != i || m_selectedAmmo != m_ammoTypesAmounts[m_selectedIndex].Type)
                        {
                            MyAudio.AddCue2D(MySoundCuesEnum.SfxHudWeaponScroll);
                        }
                        m_selectedIndex = i;
                        m_selectedAmmo  = m_ammoTypesAmounts[m_selectedIndex].Type;
                    }
                }

                //if (!MyFakes.MW25D)
                {
                    if (m_isPressLast &&
                        !input.IsGameControlPressed(MyGameControlEnums.FIRE_PRIMARY) &&
                        !input.IsGameControlPressed(MyGameControlEnums.FIRE_SECONDARY) &&
                        !input.IsGameControlPressed(MyGameControlEnums.FIRE_THIRD) &&
                        !input.IsGameControlPressed(MyGameControlEnums.FIRE_FOURTH) &&
                        !input.IsGameControlPressed(MyGameControlEnums.FIRE_FIFTH))
                    {
                        //I am here when the menu closes
                        m_isPressLast = false;
                        Visible       = false;
                        MyAudio.AddCue2D(MySoundCuesEnum.SfxHudWeaponSelect);
                    }
                }

                /*  else
                 * {
                 *    if (isKeyPress)
                 *        MyAudio.AddCue2D(MySoundCuesEnum.SfxHudWeaponSelect);
                 * } */
            }

            /*
             * if (MyFakes.MW25D)
             * {
             * return false;
             * }   */

            return(base.HandleInput(input, hasKeyboardActiveControl, hasKeyboardActiveControlPrevious, receivedFocusInThisUpdate));
        }
            public override void HandleInput(MyGuiInput input, bool receivedFocusInThisUpdate)
            {
                base.HandleInput(input, receivedFocusInThisUpdate);
                if (input.IsNewKeyPress(Keys.Escape))
                {
                    Canceling();
                }

                //  Do nothing if base.HandleInput closing this screen right now
                if (m_state == MyGuiScreenState.CLOSING || m_state == MyGuiScreenState.HIDING)
                {
                    return;
                }

                if (m_deviceType == MyGuiInputDeviceEnum.Keyboard)
                {
                    List <Toolkit.Input.Keys> pressedKeys = new List <Toolkit.Input.Keys>();
                    input.GetListOfPressedKeys(pressedKeys);

                    //  don't assign keys that were pressed when we arrived in the menu
                    foreach (var key in pressedKeys)
                    {
                        if (!m_oldPressedKeys.Contains(key))
                        {
                            if (key == Keys.Control)
                            {
                                continue;                      //there is always LeftControl or RightControl pressed with this
                            }
                            if (key == Keys.Shift)
                            {
                                continue;                    //there is always LeftShift or RightShift pressed with this
                            }
                            MyAudio.AddCue2D(MySoundCuesEnum.GuiMouseClick);

                            if (!MyGuiInput.IsKeyValid((Keys)key))
                            {
                                ShowControlIsNotValidMessageBox(); break;
                            }

                            MyControl ctrl = input.GetControl((Keys)key, m_control.GetGameControlTypeEnum());
                            if (ctrl != null)
                            {
                                if (ctrl.Equals(m_control))
                                {
                                    CloseScreen(); return;
                                }
                                ShowControlIsAlreadyAssigned(ctrl); break;
                            }
                            m_control.SetControl((Keys)key);
                            m_buttonsDictionary[m_control].SetText(new StringBuilder(m_control.GetControlButtonName(MyGuiInputDeviceEnum.Keyboard)));
                            CloseScreen(); return;
                        }
                    }
                    m_oldPressedKeys = pressedKeys;
                }
                else if (m_deviceType == MyGuiInputDeviceEnum.Mouse)
                {
                    var pressedMouseButtons = new List <MyMouseButtonsEnum>();
                    input.GetListOfPressedMouseButtons(pressedMouseButtons);

                    //  don't assign buttons that were pressed when we arrived in the menu
                    foreach (var button in pressedMouseButtons)
                    {
                        if (!m_oldPressedMouseButtons.Contains(button))
                        {
                            MyAudio.AddCue2D(MySoundCuesEnum.GuiMouseClick);
                            if (!MyGuiInput.IsMouseButtonValid(button))
                            {
                                ShowControlIsNotValidMessageBox(); break;
                            }

                            MyControl ctrl = input.GetControl(button, m_control.GetGameControlTypeEnum());
                            if (ctrl != null)
                            {
                                if (ctrl.Equals(m_control))
                                {
                                    CloseScreen(); return;
                                }
                                ShowControlIsAlreadyAssigned(ctrl); break;
                            }
                            m_control.SetControl(button);
                            m_buttonsDictionary[m_control].SetText(new StringBuilder(m_control.GetControlButtonName(MyGuiInputDeviceEnum.Mouse)));
                            CloseScreen(); return;
                        }
                    }
                    m_oldPressedMouseButtons = pressedMouseButtons;
                }
                else if (m_deviceType == MyGuiInputDeviceEnum.Joystick)
                {
                    var pressedJoystickButtons = new List <MyJoystickButtonsEnum>();
                    input.GetListOfPressedJoystickButtons(pressedJoystickButtons);

                    //  don't assign buttons that were pressed when we arrived in the menu
                    foreach (var button in pressedJoystickButtons)
                    {
                        if (!m_oldPressedJoystickButtons.Contains(button))
                        {
                            MyAudio.AddCue2D(MySoundCuesEnum.GuiMouseClick);
                            if (!MyGuiInput.IsJoystickButtonValid(button))
                            {
                                ShowControlIsNotValidMessageBox(); break;
                            }

                            MyControl ctrl = input.GetControl(button, m_control.GetGameControlTypeEnum());
                            if (ctrl != null)
                            {
                                if (ctrl.Equals(m_control))
                                {
                                    CloseScreen(); return;
                                }
                                ShowControlIsAlreadyAssigned(ctrl); break;
                            }
                            m_control.SetControl(button);
                            m_buttonsDictionary[m_control].SetText(new StringBuilder(m_control.GetControlButtonName(MyGuiInputDeviceEnum.Joystick)));
                            CloseScreen(); return;
                        }
                    }
                    m_oldPressedJoystickButtons = pressedJoystickButtons;
                }
                else if (m_deviceType == MyGuiInputDeviceEnum.JoystickAxis)
                {
                    var pressedJoystickAxes = new List <MyJoystickAxesEnum>();
                    input.GetListOfPressedJoystickAxes(pressedJoystickAxes);

                    //  don't assign axes that were pressed when we arrived in the menu
                    foreach (var axis in pressedJoystickAxes)
                    {
                        if (!m_oldPressedJoystickAxes.Contains(axis))
                        {
                            MyAudio.AddCue2D(MySoundCuesEnum.GuiMouseClick);
                            if (!MyGuiInput.IsJoystickAxisValid(axis))
                            {
                                ShowControlIsNotValidMessageBox(); break;
                            }

                            MyControl ctrl = input.GetControl(axis, m_control.GetGameControlTypeEnum());
                            if (ctrl != null)
                            {
                                if (ctrl.Equals(m_control))
                                {
                                    CloseScreen(); return;
                                }
                                ShowControlIsAlreadyAssigned(ctrl); break;
                            }
                            m_control.SetControl(axis);
                            m_buttonsDictionary[m_control].SetText(new StringBuilder(m_control.GetControlButtonName(MyGuiInputDeviceEnum.JoystickAxis)));
                            CloseScreen(); return;
                        }
                    }
                    m_oldPressedJoystickAxes = pressedJoystickAxes;
                }
            }
Ejemplo n.º 26
0
        //  Method returns true if input was captured by control, so no other controls, nor screen can use input in this update
        public override bool HandleInput(MyGuiInput input, bool hasKeyboardActiveControl, bool hasKeyboardActiveControlPrevious, bool isThisFirstHandleInput)
        {
            if (!Visible)
            {
                return false;
            }

            bool ret = base.HandleInput(input, hasKeyboardActiveControl, hasKeyboardActiveControlPrevious, isThisFirstHandleInput);
            
            if (ret == false)
            {
                if ((IsMouseOver() == true) && (input.IsNewLeftMousePressed() == true))                    
                {
                    m_carriagePositionIndex = GetCarriagePositionFromMouseCursor();
                    ret = true;
                }

                if ((m_hasKeyboardActiveControl == true) && (hasKeyboardActiveControlPrevious == false))
                {
                    UpdateLastKeyPressTimes(null);
                }

                if (hasKeyboardActiveControl == true)
                {
                    bool isShiftPressed = input.IsKeyPress(Keys.LeftShift) || input.IsKeyPress(Keys.RightShift);
                    bool isCapsLockOn = (ushort)MyGuiInput.GetKeyState(0x14) == 1;

                    //(deltaFromLastKeypress > MyGuiConstants.TEXTBOX_KEYPRESS_DELAY)
                    //int deltaFromLastKeypress = MyMinerGame.TotalGameTime_Miliseconds - m_lastKeyPressTime;

                    input.GetPressedKeys(m_pressedKeys);

                    for (int i = 0; i < m_pressedKeys.Count; i++)
                    {
                        System.Diagnostics.Debug.Assert(input.IsKeyPress((Keys)m_pressedKeys[i]));
                    }

                    //  Transform pressed letters, characters, numbers, etc to real character/string
                    for (int i = 0; i < m_pressedKeys.Count; i++)
                    {
                        bool tempShift = isShiftPressed;
                        bool transformText = true;
                        MyGuiControlTextboxKeyToString pressedKey = m_keyToString[(int)m_pressedKeys[i]];

                        //Allow to enter only digits in case such textbox type is set
                        if (m_type == MyGuiControlTextboxType.DIGITS_ONLY)
                        {
                            if ((pressedKey != null) && !input.IsKeyDigit(pressedKey.Key) && pressedKey.Key != Keys.OemPeriod && pressedKey.Key != Keys.Decimal)
                            {
                                transformText = false;
                            }
                        }

                        if (transformText)  
                        {
                            //  If we have mapping from this key to string (that means it's allowed character)
                            if (pressedKey != null && m_text.Length < m_maxLength && pressedKey.Character != null && pressedKey.CharacterWhenShift != null)
                            {
                                ret = true;
                                if (IsEnoughDelay((Keys)m_pressedKeys[i], MyGuiConstants.TEXTBOX_CHANGE_DELAY))
                                {
                                    if (Char.IsLetter(pressedKey.Character, 0))
                                    {
                                        if (isCapsLockOn)
                                            tempShift = !tempShift;//carefull here variable is not used anymore so we can invert it
                                        
                                    }
                                    m_text = m_text.Insert(m_carriagePositionIndex, (tempShift == true) ? pressedKey.CharacterWhenShift : pressedKey.Character);
                                
                                    m_carriagePositionIndex++;
                                    UpdateLastKeyPressTimes((Keys)m_pressedKeys[i]);

                                    OnTextChanged();
                                }
                            }
                        }
                    }

                    //  Move left
                    if ((input.IsKeyPress(Keys.Left)) && (IsEnoughDelay(Keys.Left, MyGuiConstants.TEXTBOX_MOVEMENT_DELAY)))
                    {
                        m_carriagePositionIndex--;
                        if (m_carriagePositionIndex < 0) m_carriagePositionIndex = 0;
                        UpdateLastKeyPressTimes(Keys.Left);
                    }

                    //  Move right
                    if ((input.IsKeyPress(Keys.Right)) && (IsEnoughDelay(Keys.Right, MyGuiConstants.TEXTBOX_MOVEMENT_DELAY)))
                    {
                        m_carriagePositionIndex++;
                        if (m_carriagePositionIndex > m_text.Length) m_carriagePositionIndex = m_text.Length;
                        UpdateLastKeyPressTimes(Keys.Right);
                    }

                    //  Move home
                    if ((input.IsNewKeyPress(Keys.Home)) && (IsEnoughDelay(Keys.Home, MyGuiConstants.TEXTBOX_MOVEMENT_DELAY)))
                    {
                        m_carriagePositionIndex = 0;
                        UpdateLastKeyPressTimes(Keys.Home);
                    }

                    //  Move end
                    if ((input.IsNewKeyPress(Keys.End)) && (IsEnoughDelay(Keys.End, MyGuiConstants.TEXTBOX_MOVEMENT_DELAY)))
                    {
                        m_carriagePositionIndex = m_text.Length;
                        UpdateLastKeyPressTimes(Keys.End);
                    }

                    //  Delete
                    if ((input.IsKeyPress(Keys.Delete)) && (IsEnoughDelay(Keys.Delete, MyGuiConstants.TEXTBOX_MOVEMENT_DELAY)))
                    {
                        if (m_carriagePositionIndex < m_text.Length)
                        {
                            m_text = m_text.Remove(m_carriagePositionIndex, 1);
                            UpdateLastKeyPressTimes(Keys.Delete);

                            OnTextChanged();
                        }
                    }

                    //  Backspace
                    if ((input.IsKeyPress(Keys.Back)) && (IsEnoughDelay(Keys.Back, MyGuiConstants.TEXTBOX_MOVEMENT_DELAY)))
                    {
                        if (m_carriagePositionIndex > 0)
                        {
                            // Handle text scrolling, basicaly try hold carriage on same position in textBox window (avoid textBox with hidden characters)
                            var carriagePositionChange = GetCarriagePosition(m_carriagePositionIndex) - GetCarriagePosition(m_carriagePositionIndex-1); ;
                            var textAreaPosition = GetTextAreaPosition();
                            if (m_slidingWindowPosition.X - carriagePositionChange.X >= textAreaPosition.X)
                            {
                                m_slidingWindowPosition.X -= carriagePositionChange.X;
                            }
                            else
                            {
                                m_slidingWindowPosition.X = textAreaPosition.X;
                            }

                            m_text = m_text.Remove(m_carriagePositionIndex - 1, 1);
                            m_carriagePositionIndex--;
                            UpdateLastKeyPressTimes(Keys.Back);

                            OnTextChanged();
                        }
                    }

                    ResetLastKeyPressTimes(input);
                    m_formattedAlready = false;
                }
                else
                {
                    if (m_type == MyGuiControlTextboxType.DIGITS_ONLY && m_formattedAlready == false && !string.IsNullOrEmpty(m_text))
                    {
                        var number = MyValueFormatter.GetDecimalFromString(m_text, 1);
                        int decimalDigits = (number - (int)number > 0) ? 1 : 0;
                        m_text = MyValueFormatter.GetFormatedFloat((float)number, decimalDigits, "");
                        m_carriagePositionIndex = m_text.Length;
                        m_formattedAlready = true;
                    }
                }
            }

            return ret;
        }
        public override void HandleInput(MyGuiInput input, bool receivedFocusInThisUpdate)
        {
            base.HandleInput(input, receivedFocusInThisUpdate);

            if (MyGuiInput.ENABLE_DEVELOPER_KEYS)
            {
                if (input.IsNewKeyPress(Keys.C) && input.IsAnyCtrlKeyPressed())
                {
                    CopySector();
                }
                if (input.IsNewKeyPress(Keys.V) && input.IsAnyCtrlKeyPressed())
                {
                    PasteSector();
                }
            }


            if (MyFakes.DRAW_FACTION_AREAS_IN_SOLAR_MAP)
            {
                MySolarMapAreaInput.HandleInput(m_solarMapRender, input, receivedFocusInThisUpdate);
            }

            float   rollIndicator     = input.GetRoll();
            Vector2 rotationIndicator = Vector2.Zero;

            if (input.IsNewRightMousePressed() && MyVideoModeManager.IsHardwareCursorUsed())
            {
                m_oldRotationIndicator = input.GetRotation();
            }

            if (input.IsRightMousePressed())
            {
                if (MyVideoModeManager.IsHardwareCursorUsed())
                {
                    rotationIndicator      = m_oldRotationIndicator - input.GetRotation();
                    m_oldRotationIndicator = input.GetRotation();
                }
                else
                {
                    rotationIndicator = input.GetRotation();
                }
            }
            Vector3 moveIndicator = input.GetPositionDelta();

            if (input.IsKeyPress(Keys.Left))
            {
                moveIndicator.X = -1;
            }
            if (input.IsKeyPress(Keys.Right))
            {
                moveIndicator.X = 1;
            }
            if (input.IsKeyPress(Keys.Up))
            {
                moveIndicator.Z = -1;
            }
            if (input.IsKeyPress(Keys.Down))
            {
                moveIndicator.Z = 1;
            }

            m_camera.Zoom(input.DeltaMouseScrollWheelValue());

            m_camera.MoveAndRotate(moveIndicator, rotationIndicator, rollIndicator, 1);


            bool sectorChanged = false;

            if (m_lastSector != m_camera.TargetSector)
            {
                sectorChanged = true;
                m_lastSector  = m_camera.TargetSector;
            }



            MySolarSystemMapNavigationMark navigationMarkUnderMouse = GetNearestNavigationMarkUnderMouseCursor();

            const float maxHeightForEnter = MySolarSystemMapCamera.SECTOR_SIZE_GAMEUNITS * 16;

            if (sectorChanged) // we have moved camera so deselect sector
            {
                m_selectedSector = null;
            }


            // tool tips
            if (m_lastNavigationMarkUnderMouse != navigationMarkUnderMouse)
            {
                m_toolTip.ClearToolTips();
                if (navigationMarkUnderMouse != null)
                {
                    m_toolTip.AddToolTip(new StringBuilder(GetSectorName(navigationMarkUnderMouse)));
                    if (!String.IsNullOrEmpty(navigationMarkUnderMouse.Description))
                    {
                        m_toolTip.AddToolTip(new StringBuilder(navigationMarkUnderMouse.Description), Color.LightGray);
                    }
                    m_toolTip.AddToolTip(new StringBuilder(navigationMarkUnderMouse.Sector.ToString()), Color.LightGray);
                }
                m_lastNavigationMarkUnderMouse = navigationMarkUnderMouse;
            }



            if (navigationMarkUnderMouse != null)
            {
                MyGuiManager.SetMouseCursorTexture(MyGuiManager.GetMouseCursorHandTexture());

                if (input.IsNewLeftMousePressed() && !m_travelButton.IsMouseOver())
                {
                    MyAudio.AddCue2D(MySoundCuesEnum.GuiMouseClick);
                    if (m_selectedNavigationMark != null)
                    {
                        m_selectedNavigationMark.Highlight = false;
                    }

                    m_selectedNavigationMark           = navigationMarkUnderMouse;
                    m_selectedNavigationMark.Highlight = true;
                    sectorChanged          = true;
                    m_slectionLocked       = true;
                    m_travelButton.Visible = false;
                }
                if (input.IsNewLeftMouseDoubleClick())
                {
                    TravelToSector(navigationMarkUnderMouse.Sector, navigationMarkUnderMouse.MissionID);
                }
            }
            else if (m_camera.CameraDistance < maxHeightForEnter && !m_slectionLocked)
            {
                if (MyGuiScreenGamePlay.CanTravelToSector(m_camera.TargetSector))
                {
                    //MyGuiManager.SetMouseCursorTexture(MyGuiManager.GetMouseCursorHandTexture());
                    if (m_selectedNavigationMark != null)
                    {
                        m_selectedNavigationMark.Highlight = false;
                    }

                    var navigationMarkUnderCamera = GetNavigationMarkUnderCamera();
                    if (navigationMarkUnderCamera != null && navigationMarkUnderCamera.Sector == m_camera.TargetSector)
                    {
                        m_selectedNavigationMark = navigationMarkUnderCamera;
                    }
                    else
                    {
                        m_selectedNavigationMark = new MySolarSystemMapNavigationMark(m_camera.TargetSector, "");
                        m_travelButton.Visible   = false;
                    }
                }
                else
                {
                    m_selectedNavigationMark = null;
                }
            }
            else if (input.IsNewLeftMousePressed())
            {
                if (m_selectedNavigationMark != null)
                {
                    m_selectedNavigationMark.Highlight = false;
                }
                if (!m_travelButton.IsMouseOver())
                {
                    m_selectedNavigationMark = null;
                }
                m_slectionLocked = false;
            }
            else if (sectorChanged && m_camera.CameraDistance > maxHeightForEnter && !m_slectionLocked)
            {
                m_selectedNavigationMark = null;
            }
            else
            {
                MyGuiManager.SetMouseCursorTexture(MyGuiManager.GetMouseCursorArrowTexture());
            }



            if (m_selectedNavigationMark != null)
            {
                if (!m_travelButton.Visible)
                {
                    m_travelButton.Text.Clear();
                    string text = GetSectorName(m_selectedNavigationMark);
                    if (text.Length > 21)
                    {
                        text  = text.Substring(0, 20);
                        text += "…";
                    }
                    m_travelButton.Text.Append(MyTextsWrapper.GetFormatString(MyTextsWrapperEnum.TravelTo, text));
                    //                    float width = MyGuiManager.GetNormalizedSize( MyGuiManager.GetFontMinerWarsBlue(), m_travelButton.Text, 1).X + 0.05f;
                    //  m_travelButton.SetSize(new Vector2(width, MyGuiConstants.BACK_BUTTON_SIZE.Y));
                    m_travelButton.Visible = true;
                }
            }
            else
            {
                m_travelButton.Visible = false;
            }
        }
        //  Method returns true if input was captured by control, so no other controls, nor screen can use input in this update
        public override bool HandleInput(MyGuiInput input, bool hasKeyboardActiveControl, bool hasKeyboardActiveControlPrevious, bool isThisFirstHandleInput)
        {
            bool ret = base.HandleInput(input, hasKeyboardActiveControl, hasKeyboardActiveControlPrevious, isThisFirstHandleInput);

            if (ret == false)
            {
                if (((IsMouseOver() == true) && (input.IsNewLeftMousePressed() == true)) ||
                    ((hasKeyboardActiveControl == true) && ((input.IsNewKeyPress(Keys.Enter) || (input.IsNewKeyPress(Keys.Space))))))
                {
                    if (!Selected) 
                    {
                        MyAudio.AddCue2D(MySoundCuesEnum.GuiMouseClick);
                        Selected = true;
                        ret = true;
                    }                    
                }
            }

            return ret;
        }
Ejemplo n.º 29
0
        public override bool HandleInput(MyGuiInput input, bool hasKeyboardActiveControl, bool hasKeyboardActiveControlPrevious, bool receivedFocusInThisUpdate)
        {
            bool ret = base.HandleInput(input, hasKeyboardActiveControl, hasKeyboardActiveControlPrevious, receivedFocusInThisUpdate);

            if (ret == false)
            {
                if (MouseEnter != null|| MouseLeave != null)
                {
                    bool isMouseOver = CheckMouseOver();
                    if (isMouseOver != lastIsMouseOver)
                    {
                        if (isMouseOver)
                        {
                            if (MouseEnter != null)
                            {
                                MouseEnter(this, EventArgs.Empty);
                            }
                        }
                        else
                        {
                            if (MouseLeave != null)
                            {
                                MouseLeave(this, EventArgs.Empty);
                            }
                        }
                    }
                    lastIsMouseOver = isMouseOver;
                }

                if (Click != null)
                {
                    if (((CheckMouseOver() == true) && input.IsNewLeftMousePressed()) ||
                        ((hasKeyboardActiveControl == true) && ((input.IsNewKeyPress(Keys.Enter) || (input.IsNewKeyPress(Keys.Space)) || (input.IsNewGameControlPressed(MyGameControlEnums.FIRE_PRIMARY) && !input.IsNewLeftMousePressed())))))
                    {
                        Click(this, EventArgs.Empty);
                    }
                }
            }

            return ret;
        }
Ejemplo n.º 30
0
        //  Method returns true if input was captured by control, so no other controls, nor screen can use input in this update
        public override bool HandleInput(MyGuiInput input, bool hasKeyboardActiveControl, bool hasKeyboardActiveControlPrevious, bool receivedFocusInThisUpdate)
        {
            bool captureInput = base.HandleInput(input, hasKeyboardActiveControl, hasKeyboardActiveControlPrevious, receivedFocusInThisUpdate);

            if (captureInput == false)
            {
                if (((IsMouseOver() == true) && ((input.IsNewLeftMouseReleased() == true))) ||
                    ((hasKeyboardActiveControl == true) && (m_canHandleKeyboardInput == true) && ((input.IsJoystickButtonNewPressed(MyJoystickButtonsEnum.J01)) || (input.IsNewKeyPress(Keys.Enter)) || (input.IsNewKeyPress(Keys.Space)))))
                {
                    if (m_implementedFeature == false)
                    {
                        MyAudio.AddCue2D(MySoundCuesEnum.GuiMouseClick);
                        MyGuiManager.AddScreen(new MyGuiScreenMessageBox(MyMessageBoxType.ERROR, MyTextsWrapperEnum.FeatureNotYetImplemented,
                                                                         MyTextsWrapperEnum.MessageBoxCaptionFeatureDisabled, MyTextsWrapperEnum.Ok, null));
                    }
                    else if (m_accessForbiddenReason != null)
                    {
                        MyAudio.AddCue2D(MySoundCuesEnum.GuiMouseClick);
                        MyGuiManager.AddScreen(new MyGuiScreenMessageBox(MyMessageBoxType.ERROR, m_accessForbiddenReason.Value,
                                                                         MyTextsWrapperEnum.MessageBoxCaptionFeatureDisabled, MyTextsWrapperEnum.Ok, null));
                    }
                    else if (Enabled || UseSwitchMode)
                    {
                        MyAudio.AddCue2D(MySoundCuesEnum.GuiMouseClick);
                        if (m_onButtonClick != null)
                        {
                            m_onButtonClick(this);
                        }
                        else if (m_onIndexedButtonClick != null)
                        {
                            m_onIndexedButtonClick(m_buttonIndex);
                        }
                    }

                    captureInput = true;
                }
            }

            return(captureInput);
        }