private void HandleMouse(MyGuiInput input) { //Handle mouse wheel if (m_mouseWheelValueLast == null) { m_mouseWheelValueLast = input.MouseScrollWheelValue(); } if (input.MouseScrollWheelValue() < m_mouseWheelValueLast) { //if (!MoveNext()) SelectNext(); } if (input.MouseScrollWheelValue() > m_mouseWheelValueLast) { //if (!MovePrev()) SelectPrev(); } m_mouseWheelValueLast = input.MouseScrollWheelValue(); //Do nothing if mouse don't move. if (!input.IsNewLeftMousePressed() && m_mousePositionLast != null && m_mousePositionLast == MyGuiManager.MouseCursorPosition) { return; } m_mousePositionLast = MyGuiManager.MouseCursorPosition; if (input.IsNewLeftMousePressed() && m_displayedItems[m_selected] != null) { m_displayedItems[m_selected].ChangeValueUp(); } }
// 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; }
private void HandleMouse(MyGuiInput input) { //Handle mouse wheel if (m_mouseWheelValueLast == null) m_mouseWheelValueLast = input.MouseScrollWheelValue(); if (input.MouseScrollWheelValue() < m_mouseWheelValueLast) { //if (!MoveNext()) SelectNext(); } if (input.MouseScrollWheelValue() > m_mouseWheelValueLast) { //if (!MovePrev()) SelectPrev(); } m_mouseWheelValueLast = input.MouseScrollWheelValue(); //Do nothing if mouse don't move. if (!input.IsNewLeftMousePressed() && m_mousePositionLast != null && m_mousePositionLast == MyGuiManager.MouseCursorPosition) return; m_mousePositionLast = MyGuiManager.MouseCursorPosition; if (input.IsNewLeftMousePressed() && m_displayedItems[m_selected] != null) { m_displayedItems[m_selected].ChangeValueUp(); } }
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)); }