private void HandleKey() { ReadPressedKeys(); foreach (var key in m_newPressedKeys) { if (m_oldPressedKeys.Contains(key)) { continue; } if (!MyInput.Static.IsKeyValid((MyKeys)key)) { ShowControlIsNotValidMessageBox(); break; } MyGuiAudio.PlaySound(MyGuiSounds.HudMouseClick); MyControl ctrl = MyInput.Static.GetControl((MyKeys)key); if (ctrl != null) { if (ctrl.Equals(m_controlBeingSet)) { OverwriteAssignment(ctrl, key); CloseScreen(); } else { StringBuilder controlText = null; MyControl.AppendName(ref controlText, (MyKeys)key); ShowControlIsAlreadyAssigned(ctrl, controlText, () => OverwriteAssignment(ctrl, key)); } } else { m_controlBeingSet.SetControl(m_deviceType, (MyKeys)key); CloseScreen(); } break; } m_oldPressedKeys.Clear(); MyUtils.Swap(ref m_oldPressedKeys, ref m_newPressedKeys); }
private void HandleMouseButton() { MyInput.Static.GetListOfPressedMouseButtons(m_newPressedMouseButtons); // don't assign buttons that were pressed when we arrived in the menu foreach (var button in m_newPressedMouseButtons) { if (!m_oldPressedMouseButtons.Contains(button)) { MyGuiAudio.PlaySound(MyGuiSounds.HudMouseClick); if (!MyInput.Static.IsMouseButtonValid(button)) { ShowControlIsNotValidMessageBox(); break; } MyControl ctrl = MyInput.Static.GetControl(button); if (ctrl != null) { if (ctrl.Equals(m_controlBeingSet)) { OverwriteAssignment(ctrl, button); CloseScreen(); } else { StringBuilder controlText = null; MyControl.AppendName(ref controlText, button); ShowControlIsAlreadyAssigned(ctrl, controlText, () => OverwriteAssignment(ctrl, button)); } } else { m_controlBeingSet.SetControl(button); CloseScreen(); } break; } } m_oldPressedMouseButtons.Clear(); MyUtils.Swap(ref m_oldPressedMouseButtons, ref m_newPressedMouseButtons); }
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; } }