public MyMichalDebugInputComponent() { Static = this; Axes = new List <MyJoystickAxesEnum>(); AxesCollection = new Dictionary <MyJoystickAxesEnum, float?>(); foreach (var axis in Enum.GetValues(typeof(MyJoystickAxesEnum))) { MyJoystickAxesEnum val = (MyJoystickAxesEnum)axis; AxesCollection[val] = null; Axes.Add(val); } AddShortcut(MyKeys.NumPad0, true, false, false, false, () => "Debug draw", DebugDrawFunc); if (MyPerGameSettings.Game == GameEnum.SE_GAME) { AddShortcut(MyKeys.NumPad1, true, false, false, false, () => "Remove grids with space balls", RemoveGridsWithSpaceBallsFunc); AddShortcut(MyKeys.NumPad2, true, false, false, false, () => "Throw 50 ores and 50 scrap metals", ThrowFloatingObjectsFunc); } if (MyPerGameSettings.EnableAi) { AddShortcut(MyKeys.NumPad6, true, false, false, false, () => "Next head matrix", NextHeadMatrix); AddShortcut(MyKeys.NumPad5, true, false, false, false, () => "Previous head matrix", PreviousHeadMatrix); AddShortcut(MyKeys.NumPad3, true, false, false, false, OnSelectBotForDebugMsg, () => { OnSelectDebugBot = !OnSelectDebugBot; return(true); }); AddShortcut(MyKeys.NumPad4, true, false, false, false, () => "Remove bot", () => { MyAIComponent.Static.DebugRemoveFirstBot(); return(true); }); AddShortcut(MyKeys.NumPad7, true, false, false, false, () => { return("DEBUG ANIMALS " + (MyDebugDrawSettings.DEBUG_DRAW_ANIMALS ? "TRUE" : "FALSE")); }, () => { MyDebugDrawSettings.DEBUG_DRAW_ANIMALS = !MyDebugDrawSettings.DEBUG_DRAW_ANIMALS; return(true); }); } }
public void SetNoControl() { m_joystickAxis = MyJoystickAxesEnum.None; m_joystickButton = MyJoystickButtonsEnum.None; m_mouseButton = MyMouseButtonsEnum.None; m_keyboardKey = Keys.None; m_keyboardKey2 = Keys.None; }
public MyControl(MyEditorControlEnums control, MyTextsWrapperEnum text, MyGuiControlTypeEnum controlType, MyMouseButtonsEnum?defaultControlMouse, Keys?defaultControlKey, MyJoystickButtonsEnum?defaultControlJoy, MyJoystickAxesEnum?defaultControlJoyAxis) : this(control, text, controlType) { m_mouseButton = defaultControlMouse.HasValue ? defaultControlMouse.Value : MyMouseButtonsEnum.None; m_keyboardKey = defaultControlKey.HasValue ? defaultControlKey.Value : Keys.None; m_joystickButton = defaultControlJoy.HasValue ? defaultControlJoy.Value : MyJoystickButtonsEnum.None; m_joystickAxis = defaultControlJoyAxis.HasValue ? defaultControlJoyAxis.Value : MyJoystickAxesEnum.None; }
public MyControl(MyEditorControlEnums control, MyTextsWrapperEnum text, MyGuiControlTypeEnum controlType) { m_editorControl = control; m_gameControlType = MyGuiGameControlType.EDITOR; m_text = text; m_controlType = controlType; m_joystickButton = MyJoystickButtonsEnum.None; m_joystickAxis = MyJoystickAxesEnum.None; m_mouseButton = MyMouseButtonsEnum.None; m_keyboardKey = Keys.None; }
public static void NullControl(MyStringId context, MyJoystickAxesEnum axis) { MyStringId key = MyStringId.NullOrEmpty; foreach (var pair in m_bindings[context].Bindings) { if (pair.Value is JoystickAxis && pair.Value.Code == (byte)axis) { key = pair.Key; break; } } if (key != MyStringId.NullOrEmpty) { m_bindings[context][key] = m_nullControl; } }
public MyMichalDebugInputComponent() { Static = this; Axes = new List <MyJoystickAxesEnum>(); AxesCollection = new Dictionary <MyJoystickAxesEnum, float?>(); foreach (var axis in Enum.GetValues(typeof(MyJoystickAxesEnum))) { MyJoystickAxesEnum val = (MyJoystickAxesEnum)axis; AxesCollection[val] = null; Axes.Add(val); } AddShortcut(MyKeys.NumPad7, true, false, false, false, () => "Enable LMB spawning: " + ENABLE_FLORA_SPAWNING, () => { ENABLE_FLORA_SPAWNING = !ENABLE_FLORA_SPAWNING; return(true); }); AddShortcut(MyKeys.NumPad8, true, false, false, false, () => "Select flora to spawn. Selected: " + SELECTED_FLORA, SelectNextFloraToSpawn); AddShortcut(MyKeys.NumPad0, true, false, false, false, () => "Debug draw", DebugDrawFunc); AddShortcut(MyKeys.NumPad9, true, false, false, false, OnRecording, ToggleVoiceChat); if (MyPerGameSettings.Game == GameEnum.SE_GAME) { AddShortcut(MyKeys.NumPad1, true, false, false, false, () => "Remove grids with space balls", RemoveGridsWithSpaceBallsFunc); AddShortcut(MyKeys.NumPad2, true, false, false, false, () => "Throw 50 ores and 50 scrap metals", ThrowFloatingObjectsFunc); } if (MyPerGameSettings.EnableAi) { AddShortcut(MyKeys.NumPad6, true, false, false, false, () => "Next head matrix", NextHeadMatrix); AddShortcut(MyKeys.NumPad5, true, false, false, false, () => "Previous head matrix", PreviousHeadMatrix); AddShortcut(MyKeys.NumPad3, true, false, false, false, OnSelectBotForDebugMsg, () => { OnSelectDebugBot = !OnSelectDebugBot; return(true); }); AddShortcut(MyKeys.NumPad4, true, false, false, false, () => "Remove bot", () => { MyAIComponent.Static.DebugRemoveFirstBot(); return(true); }); AddShortcut(MyKeys.L, true, true, false, false, () => "Add animal bot", SpawnAnimalAroundPlayer); AddShortcut(MyKeys.OemSemicolon, true, true, false, false, () => "Spawn selected bot " + (m_selectBotName != null ? m_selectBotName : "NOT SELECTED"), SpawnBot); AddShortcut(MyKeys.OemMinus, true, true, false, false, () => "Previous bot definition", PreviousBot); AddShortcut(MyKeys.OemPlus, true, true, false, false, () => "Next bot definition", NextBot); AddShortcut(MyKeys.OemQuotes, true, true, false, false, () => "Reload bot definitions", ReloadDefinitions); AddShortcut(MyKeys.OemComma, true, true, false, false, () => "RemoveAllTimbers", RemoveAllTimbers); AddShortcut(MyKeys.N, true, true, false, false, () => "Cast long ray", ChangeAlgo); // AddShortcut(MyKeys.NumPad7, true, false, false, false, () => { return "DEBUG ANIMALS " + (MyDebugDrawSettings.DEBUG_DRAW_ANIMALS ? "TRUE" : "FALSE"); }, () => { MyDebugDrawSettings.DEBUG_DRAW_ANIMALS = !MyDebugDrawSettings.DEBUG_DRAW_ANIMALS; return true; }); } }
string IMyControlNameLookup.GetName(MyJoystickAxesEnum joystickAxis) { switch (joystickAxis) { case MyJoystickAxesEnum.Xpos: return("JX+"); case MyJoystickAxesEnum.Xneg: return("JX-"); case MyJoystickAxesEnum.Ypos: return("JY+"); case MyJoystickAxesEnum.Yneg: return("JY-"); case MyJoystickAxesEnum.Zpos: return("JZ+"); case MyJoystickAxesEnum.Zneg: return("JZ-"); case MyJoystickAxesEnum.RotationXpos: return(MyTexts.GetString(MyCommonTexts.JoystickRotationXpos)); case MyJoystickAxesEnum.RotationXneg: return(MyTexts.GetString(MyCommonTexts.JoystickRotationXneg)); case MyJoystickAxesEnum.RotationYpos: return(MyTexts.GetString(MyCommonTexts.JoystickRotationYpos)); case MyJoystickAxesEnum.RotationYneg: return(MyTexts.GetString(MyCommonTexts.JoystickRotationYneg)); case MyJoystickAxesEnum.RotationZpos: return(MyTexts.GetString(MyCommonTexts.JoystickRotationZpos)); case MyJoystickAxesEnum.RotationZneg: return(MyTexts.GetString(MyCommonTexts.JoystickRotationZneg)); case MyJoystickAxesEnum.Slider1pos: return(MyTexts.GetString(MyCommonTexts.JoystickSlider1pos)); case MyJoystickAxesEnum.Slider1neg: return(MyTexts.GetString(MyCommonTexts.JoystickSlider1neg)); case MyJoystickAxesEnum.Slider2pos: return(MyTexts.GetString(MyCommonTexts.JoystickSlider2pos)); case MyJoystickAxesEnum.Slider2neg: return(MyTexts.GetString(MyCommonTexts.JoystickSlider2neg)); } return(""); }
// Find out how much a specific joystick axis is pressed. // Return a raw number between 0 and 65535. 32768 is the middle value. public float GetJoystickAxisStateRaw(MyJoystickAxesEnum axis) { return ConputeJoystickAxisStateRaw(m_actualJoystickState, axis); }
string ModAPI.IMyInput.GetName(MyJoystickAxesEnum joystickAxis) { return(((IMyInput)this).GetName(joystickAxis)); }
bool ModAPI.IMyInput.IsNewJoystickAxisReleased(MyJoystickAxesEnum axis) { return(((IMyInput)this).IsNewJoystickAxisReleased(axis)); }
public bool IsJoystickAxisSupported(MyJoystickAxesEnum axis) { if (!m_joystickConnected) return false; switch (axis) { case MyJoystickAxesEnum.Xpos: case MyJoystickAxesEnum.Xneg: return m_joystickXAxisSupported; case MyJoystickAxesEnum.Ypos: case MyJoystickAxesEnum.Yneg: return m_joystickYAxisSupported; case MyJoystickAxesEnum.Zpos: case MyJoystickAxesEnum.Zneg: return m_joystickZAxisSupported; case MyJoystickAxesEnum.RotationXpos: case MyJoystickAxesEnum.RotationXneg: return m_joystickRotationXAxisSupported; case MyJoystickAxesEnum.RotationYpos: case MyJoystickAxesEnum.RotationYneg: return m_joystickRotationYAxisSupported; case MyJoystickAxesEnum.RotationZpos: case MyJoystickAxesEnum.RotationZneg: return m_joystickRotationZAxisSupported; case MyJoystickAxesEnum.Slider1pos: case MyJoystickAxesEnum.Slider1neg: return m_joystickSlider1AxisSupported; case MyJoystickAxesEnum.Slider2pos: case MyJoystickAxesEnum.Slider2neg: return m_joystickSlider2AxisSupported; default: return false; } }
public void SetControl(MyJoystickAxesEnum joyAxis) { m_joystickAxis = joyAxis; }
// Check to see if a specific button on the joystick is currently pressed and was not pressed during the last update. bool ModAPI.IMyInput.IsJoystickAxisNewPressed(MyJoystickAxesEnum axis) { return IsJoystickAxisNewPressed(axis); }
float IMyInput.GetJoystickAxisStateForGameplay(MyJoystickAxesEnum axis) { return 0; }
// Find out how much a specific joystick half-axis is pressed. // Return a number between 0 and 1 (taking deadzone, sensitivity and non-linearity into account). public float GetPreviousJoystickAxisStateForGameplay(MyJoystickAxesEnum axis) { return ComputeJoystickAxisStateForGameplay(m_previousJoystickState, axis); }
// Find out how much a specific joystick half-axis is pressed. // Return a number between 0 and 1 (taking deadzone, sensitivity and non-linearity into account). public float GetJoystickAxisStateForGameplay(MyJoystickAxesEnum axis) { return ComputeJoystickAxisStateForGameplay(m_actualJoystickState, axis); }
private float ComputeJoystickAxisStateForGameplay(XB1Interface.XB1Interface.GamepadState padState, MyJoystickAxesEnum axis) { if (IsJoystickConnected() && IsJoystickAxisSupported(axis)) { // Input position scaled to (-1..1). float position = ComputeJoystickAxisState(padState, axis); float distance = (((int)axis) % 2 != 0) ? position : -position; // even -> neg axis if (distance > m_joystickDeadzone) { distance = (distance - m_joystickDeadzone) / (1 - m_joystickDeadzone); // Rescale distance to (0..1) outside the deadzone. return m_joystickSensitivity * (float)Math.Pow(distance, m_joystickExponent); } } return 0.0f; }
private float ComputeJoystickAxisState(XB1Interface.XB1Interface.GamepadState padState, MyJoystickAxesEnum axis) { float value = 0.0f; if (IsJoystickConnected() && IsJoystickAxisSupported(axis)) { switch (axis) { case MyJoystickAxesEnum.RotationXpos: case MyJoystickAxesEnum.RotationXneg: value = padState.rx; break; case MyJoystickAxesEnum.RotationYpos: case MyJoystickAxesEnum.RotationYneg: value = -padState.ry; break; case MyJoystickAxesEnum.Xpos: case MyJoystickAxesEnum.Xneg: value = padState.lx; break; case MyJoystickAxesEnum.Ypos: case MyJoystickAxesEnum.Yneg: value = -padState.ly; break; } } return value; }
public static void AppendName(ref StringBuilder output, MyJoystickAxesEnum joystickAxis) { EnsureExists(ref output); output.Append(MyInput.Static.GetName(joystickAxis)); }
bool IMyInput.IsJoystickAxisValid(MyJoystickAxesEnum axis) { return false; }
float IMyInput.GetJoystickAxisStateForGameplay(MyJoystickAxesEnum axis) { return(0); }
bool IMyInput.IsNewJoystickAxisReleased(MyJoystickAxesEnum axis) { return false; }
bool IMyInput.IsJoystickAxisNewPressed(MyJoystickAxesEnum axis) { return(false); }
// Return true if joystick axis is valid for user controls bool ModAPI.IMyInput.IsJoystickAxisValid(MyJoystickAxesEnum axis) { return IsJoystickAxisValid(axis); }
bool IMyInput.IsNewJoystickAxisReleased(MyJoystickAxesEnum axis) { return(false); }
public bool IsJoystickAxisPressed(MyJoystickAxesEnum axis) { bool isPressed = false; if (m_joystickConnected && axis != MyJoystickAxesEnum.None && m_actualJoystickState != null) { isPressed = GetJoystickAxisStateForGameplay(axis) > MyJoystickConstants.ANALOG_PRESSED_THRESHOLD; } if (!isPressed && axis == MyJoystickAxesEnum.None) { return true; } if (!IsJoystickAxisSupported(axis)) return false; return isPressed; }
bool IMyInput.IsJoystickAxisValid(MyJoystickAxesEnum axis) { return(false); }
// Find out how much a specific joystick half-axis is pressed. // Return a number between 0 and 1 (taking deadzone, sensitivity and non-linearity into account). float ModAPI.IMyInput.GetJoystickAxisStateForGameplay(MyJoystickAxesEnum axis) { return(((IMyInput)this).GetJoystickAxisStateForGameplay(axis)); }
string IMyInput.GetName(MyJoystickAxesEnum joystickAxis) { return(""); }
// Return true if joystick axis is valid for user controls bool ModAPI.IMyInput.IsJoystickAxisValid(MyJoystickAxesEnum axis) { return(((IMyInput)this).IsJoystickAxisValid(axis)); }
// Find out how much a specific joystick half-axis is pressed. // Return a number between 0 and 1 (taking deadzone, sensitivity and non-linearity into account). public float GetPreviousJoystickAxisStateForGameplay(MyJoystickAxesEnum axis) { if (IsJoystickConnected() && IsJoystickAxisSupported(axis)) { // Input position scaled to (-1..1). float position = ((float)GetPreviousJoystickAxisStateRaw(axis) - (float)MyJoystickConstants.CENTER_AXIS) / (float)MyJoystickConstants.CENTER_AXIS; switch (axis) { case MyJoystickAxesEnum.RotationXneg: case MyJoystickAxesEnum.Xneg: case MyJoystickAxesEnum.RotationYneg: case MyJoystickAxesEnum.Yneg: case MyJoystickAxesEnum.RotationZneg: case MyJoystickAxesEnum.Zneg: case MyJoystickAxesEnum.Slider1neg: case MyJoystickAxesEnum.Slider2neg: if (position >= 0) return 0; break; case MyJoystickAxesEnum.RotationXpos: case MyJoystickAxesEnum.Xpos: case MyJoystickAxesEnum.RotationYpos: case MyJoystickAxesEnum.Ypos: case MyJoystickAxesEnum.RotationZpos: case MyJoystickAxesEnum.Zpos: case MyJoystickAxesEnum.Slider1pos: case MyJoystickAxesEnum.Slider2pos: if (position <= 0) return 0; break; default: MyDebug.AssertDebug(false, "Unknown joystick axis!"); break; } float distance = Math.Abs(position); if (distance > m_joystickDeadzone) { distance = (distance - m_joystickDeadzone) / (1 - m_joystickDeadzone); // Rescale distance to (0..1) outside the deadzone. return m_joystickSensitivity * (float)Math.Pow(distance, m_joystickExponent); } } return 0; }
private float ConputeJoystickAxisStateRaw(SharpDX.XInput.State padState, MyJoystickAxesEnum axis) { int value = 0; if (IsJoystickConnected() && IsJoystickAxisSupported(axis)) { switch (axis) { case MyJoystickAxesEnum.RotationXpos: case MyJoystickAxesEnum.RotationXneg: value = padState.Gamepad.RightThumbX; break; case MyJoystickAxesEnum.RotationYpos: case MyJoystickAxesEnum.RotationYneg: value = -padState.Gamepad.RightThumbY; break; /*case MyJoystickAxesEnum.RotationZpos: case MyJoystickAxesEnum.RotationZneg: value = padState.RotationZ; break; */ case MyJoystickAxesEnum.Xpos: case MyJoystickAxesEnum.Xneg: value = padState.Gamepad.LeftThumbX; break; case MyJoystickAxesEnum.Ypos: case MyJoystickAxesEnum.Yneg: value = -padState.Gamepad.LeftThumbY; break; } } return (value + 32768); }
// Check to see if a specific button on the joystick was released. public bool WasJoystickAxisReleased(MyJoystickAxesEnum axis) { bool isPressed = false; //if (m_joystickConnected && axis != MyJoystickAxesEnum.None && m_previousJoystickState != null) if (IsJoystickConnected() && axis != MyJoystickAxesEnum.None) { isPressed = GetPreviousJoystickAxisStateForGameplay(axis) <= MyJoystickConstants.ANALOG_PRESSED_THRESHOLD; } if (!isPressed && axis == MyJoystickAxesEnum.None) { return true; } if (!IsJoystickAxisSupported(axis)) return false; return isPressed; }
public float GetPreviousJoystickAxisStateRaw(MyJoystickAxesEnum axis) { return ConputeJoystickAxisStateRaw(m_previousJoystickState, axis); }
// Return true if joystick axis is valid for user controls public bool IsJoystickAxisValid(MyJoystickAxesEnum axis) { foreach (var item in m_validJoystickAxes) { if (item == axis) return true; } return false; }
// Check to see if a specific button on the joystick is currently pressed and was not pressed during the last update. public bool IsJoystickAxisNewPressed(MyJoystickAxesEnum axis) { bool isNewPressed = false; //if (m_joystickConnected && axis != MyJoystickAxesEnum.None && m_actualJoystickState != null && m_previousJoystickState != null) if( IsJoystickConnected() && axis != MyJoystickAxesEnum.None ) { float newState = GetJoystickAxisStateForGameplay(axis); float oldState = GetPreviousJoystickAxisStateForGameplay(axis); isNewPressed = newState > MyJoystickConstants.ANALOG_PRESSED_THRESHOLD && oldState <= MyJoystickConstants.ANALOG_PRESSED_THRESHOLD; } if (!isNewPressed && axis == MyJoystickAxesEnum.None) { return true; } if (!IsJoystickAxisSupported(axis)) return false; return isNewPressed; }
public JoystickAxis(MyJoystickAxesEnum axis) { Axis = axis; }
public bool IsJoystickAxisSupported(MyJoystickAxesEnum axis) { if (m_joystick.IsConnected == false) { return false; } switch (axis) { case MyJoystickAxesEnum.RotationZpos: case MyJoystickAxesEnum.RotationZneg: case MyJoystickAxesEnum.Zneg: case MyJoystickAxesEnum.Slider1pos: case MyJoystickAxesEnum.Slider1neg: case MyJoystickAxesEnum.Slider2pos: case MyJoystickAxesEnum.Slider2neg: case MyJoystickAxesEnum.None: return false; default: return true; } }
public static void AddControl(MyStringId context, MyStringId stringId, MyJoystickAxesEnum axis) { m_bindings[context][stringId] = new JoystickAxis(axis); }
public string GetName(MyJoystickAxesEnum joystickAxis) { return m_nameLookup.GetName(joystickAxis); }
// Check to see if a specific button on the joystick is currently pressed and was not pressed during the last update. bool ModAPI.IMyInput.IsJoystickAxisNewPressed(MyJoystickAxesEnum axis) { return(IsJoystickAxisNewPressed(axis)); }
string IMyInput.GetName(MyJoystickAxesEnum joystickAxis) { return ""; }
bool IMyInput.IsJoystickAxisNewPressed(MyJoystickAxesEnum axis) { return false; }
// Find out how much a specific joystick half-axis is pressed. // Return a number between 0 and 1 (taking deadzone, sensitivity and non-linearity into account). float ModAPI.IMyInput.GetJoystickAxisStateForGameplay(MyJoystickAxesEnum axis) { return GetJoystickAxisStateForGameplay(axis); }
public static void NullControl(MyStringId context, MyJoystickAxesEnum axis) { MyStringId key = MyStringId.NullOrEmpty; foreach (var pair in m_bindings[context].Bindings) { if (pair.Value is JoystickAxis && pair.Value.Code == (byte)axis) { key = pair.Key; break; } } if (key != MyStringId.NullOrEmpty) m_bindings[context][key] = m_nullControl; }
bool ModAPI.IMyInput.IsNewJoystickAxisReleased(MyJoystickAxesEnum axis) { return IsNewJoystickAxisReleased(axis); }
// Find out how much a specific joystick axis was pressed. // Return a raw number between 0 and 65535. 32768 is the middle value. public float GetPreviousJoystickAxisStateRaw(MyJoystickAxesEnum axis) { int value = 32768; if (m_joystickConnected && axis != MyJoystickAxesEnum.None && m_previousJoystickState != null && IsJoystickAxisSupported(axis)) { switch (axis) { case MyJoystickAxesEnum.RotationXpos: case MyJoystickAxesEnum.RotationXneg: value = m_previousJoystickState.RotationX; break; case MyJoystickAxesEnum.RotationYpos: case MyJoystickAxesEnum.RotationYneg: value = m_previousJoystickState.RotationY; break; case MyJoystickAxesEnum.RotationZpos: case MyJoystickAxesEnum.RotationZneg: value = m_previousJoystickState.RotationZ; break; case MyJoystickAxesEnum.Xpos: case MyJoystickAxesEnum.Xneg: value = m_previousJoystickState.X; break; case MyJoystickAxesEnum.Ypos: case MyJoystickAxesEnum.Yneg: value = m_previousJoystickState.Y; break; case MyJoystickAxesEnum.Zpos: case MyJoystickAxesEnum.Zneg: value = m_previousJoystickState.Z; break; case MyJoystickAxesEnum.Slider1pos: case MyJoystickAxesEnum.Slider1neg: { var array = m_previousJoystickState.Sliders; value = (array.Length < 1) ? 32768 : array[0]; } break; case MyJoystickAxesEnum.Slider2pos: case MyJoystickAxesEnum.Slider2neg: { var array = m_previousJoystickState.Sliders; value = (array.Length < 2) ? 32768 : array[1]; } break; } } return value; }
string ModAPI.IMyInput.GetName(MyJoystickAxesEnum joystickAxis) { return GetName(joystickAxis); }
public MyControl(MyEditorControlEnums control, MyTextsWrapperEnum text, MyGuiControlTypeEnum controlType, MyJoystickAxesEnum defaultControl) : this(control, text, controlType, null, null, null, defaultControl) { }