Skip to content

Commit 85ab6ec

Browse files
committed
ForceEnable->ForceDisable
1 parent 6fc5f05 commit 85ab6ec

File tree

2 files changed

+44
-11
lines changed

2 files changed

+44
-11
lines changed

Source/Managers/UInputMan.cpp

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ int UInputMan::Initialize() {
119119
playerMouseControlled++;
120120
}
121121
}
122-
m_EnableMultiMouseKeyboard = playerMouseControlled > 1 || m_ForceEnableMultiMouseKeyboard;
122+
m_EnableMultiMouseKeyboard = playerMouseControlled > 1 && !m_ForceDisableMultiMouseKeyboard;
123123

124124
m_PlayerScreenMouseBounds = {
125125
0,
@@ -317,15 +317,41 @@ void UInputMan::DisableMouseMoving(bool disable) {
317317
m_PrepareToEnableMouseMoving = true;
318318
}
319319
}
320-
321-
bool UInputMan::IsMultiMouseKeyboardEnabled() const {
320+
bool UInputMan::CheckMultiMouseKeyboardEnabled(std::optional<std::reference_wrapper<const std::vector<int>>> players) {
322321
int playerMouseControlled{0};
323-
for (int player = PlayerOne; player < MaxPlayerCount; player++) {
322+
if (players) {
323+
for (int player: players->get()) {
324+
if (m_ControlScheme[player].GetDevice() == InputDevice::DEVICE_MOUSE_KEYB) {
325+
playerMouseControlled++;
326+
}
327+
}
328+
} else {
329+
for (int player = Players::PlayerOne; player < Players::MaxPlayerCount; player++) {
330+
if (m_ControlScheme[player].GetDevice() == InputDevice::DEVICE_MOUSE_KEYB) {
331+
playerMouseControlled++;
332+
}
333+
}
334+
}
335+
336+
SDL_SetHint(SDL_HINT_WINDOWS_RAW_KEYBOARD, "1");
337+
m_EnableMultiMouseKeyboard = playerMouseControlled > 1 && !m_ForceDisableMultiMouseKeyboard;
338+
return m_EnableMultiMouseKeyboard;
339+
}
340+
341+
bool UInputMan::AllPlayerInputDevicesKnown(const std::vector<int>& humanPlayers) const {
342+
if (!m_EnableMultiMouseKeyboard) {
343+
return true;
344+
}
345+
346+
for (int player: humanPlayers) {
324347
if (m_ControlScheme[player].GetDevice() == InputDevice::DEVICE_MOUSE_KEYB) {
325-
playerMouseControlled++;
348+
DeviceID playerDevice = m_ControlScheme[player].GetDeviceID();
349+
if (playerDevice.mouseKeyboard.mouse == 0 || playerDevice.mouseKeyboard.keyboard == 0) {
350+
return false;
351+
}
326352
}
327353
}
328-
return playerMouseControlled > 1;
354+
return true;
329355
}
330356

331357
Vector UInputMan::GetAbsoluteMousePosition(int whichPlayer) const {
@@ -394,7 +420,7 @@ void UInputMan::SetMousePos(const Vector& newPos, int whichPlayer) {
394420
}
395421

396422
const std::array<bool, MouseButtons::MAX_MOUSE_BUTTONS>& UInputMan::GetMouseState(int whichPlayer) const {
397-
if (whichPlayer == Players::NoPlayer) {
423+
if (whichPlayer == Players::NoPlayer || !m_EnableMultiMouseKeyboard) {
398424
return s_CurrentMouseButtonStates;
399425
}
400426
InputDevice playerInput = m_ControlScheme.at(whichPlayer).GetDevice();
@@ -407,7 +433,7 @@ const std::array<bool, MouseButtons::MAX_MOUSE_BUTTONS>& UInputMan::GetMouseStat
407433
return s_CurrentMouseButtonStates;
408434
}
409435
const std::array<bool, MouseButtons::MAX_MOUSE_BUTTONS>& UInputMan::GetMouseChange(int whichPlayer) const {
410-
if (whichPlayer == Players::NoPlayer) {
436+
if (whichPlayer == Players::NoPlayer || !m_EnableMultiMouseKeyboard) {
411437
return s_ChangedMouseButtonStates;
412438
}
413439
InputDevice playerInput = m_ControlScheme.at(whichPlayer).GetDevice();
@@ -693,7 +719,7 @@ bool UInputMan::GetMouseButtonState(int whichPlayer, int whichButton, InputState
693719
if (whichPlayer != Players::NoPlayer) {
694720
playerDevice = m_ControlScheme.at(whichPlayer).GetDevice();
695721
}
696-
if (mouse == 0 && (whichPlayer == Players::NoPlayer || (playerDevice != InputDevice::DEVICE_MOUSE_KEYB))) {
722+
if (mouse == 0 && (whichPlayer == Players::NoPlayer || !m_EnableMultiMouseKeyboard || (playerDevice != InputDevice::DEVICE_MOUSE_KEYB))) {
697723
switch (whichState) {
698724
case InputState::Held:
699725
return s_CurrentMouseButtonStates[whichButton];

Source/Managers/UInputMan.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <array>
1212
#include <string>
1313
#include <vector>
14+
#include <optional>
15+
#include <functional>
1416

1517
#define g_UInputMan UInputMan::Instance()
1618

@@ -262,7 +264,12 @@ namespace RTE {
262264
/// @param disable Whether to disable mouse positioning or not.
263265
void DisableMouseMoving(bool disable = true);
264266

265-
bool IsMultiMouseKeyboardEnabled() const;
267+
/// @brief Check if multi mouse and keyboard should be enabled.
268+
/// Checks through a list of human players to see if multimouse is required.
269+
/// @param player A list of human players.
270+
bool CheckMultiMouseKeyboardEnabled(std::optional<std::reference_wrapper<const std::vector<int>>> players = std::nullopt);
271+
272+
bool AllPlayerInputDevicesKnown(const std::vector<int>& humanPlayers) const;
266273

267274
/// Get the absolute mouse position in window coordinates.
268275
/// @return The absolute mouse position.
@@ -510,7 +517,7 @@ namespace RTE {
510517

511518
InputDevice m_LastDeviceWhichControlledGUICursor; //!< Indicates which device controlled the cursor last time.
512519

513-
bool m_ForceEnableMultiMouseKeyboard{true}; //!< Whether to force enable muti mouse/keyboard support.
520+
bool m_ForceDisableMultiMouseKeyboard{false}; //!< Whether to force enable muti mouse/keyboard support.
514521
bool m_EnableMultiMouseKeyboard{true}; //!< Allow use of multiple mice and keyboards. (Enables relative mouse mode.)
515522
bool m_PlayerMouseKeyboardKnown{false}; //!< Whether all player devices are known when multiple mouse and/or keyboards are requested.
516523
bool m_DisableKeyboard; //!< Temporarily disable all keyboard input reading.

0 commit comments

Comments
 (0)