Ejemplo n.º 1
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);
                }
            }
        }
        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;
            }
        }
Ejemplo n.º 3
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.º 4
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);
                }
            }
        }