mirror of
https://github.com/ZDoom/qzdoom.git
synced 2025-02-01 21:41:12 +00:00
Merged https://github.com/ZDoom/gzdoom/pull/1894 (Individual Joystick Toggles)
This commit is contained in:
parent
0a2fc5651c
commit
b5a95b47c1
10 changed files with 174 additions and 7 deletions
|
@ -120,6 +120,11 @@ bool M_LoadJoystickConfig(IJoystickConfig *joy)
|
|||
{
|
||||
return false;
|
||||
}
|
||||
value = GameConfig->GetValueForKey("Enabled");
|
||||
if (value != NULL)
|
||||
{
|
||||
joy->SetEnabled((bool)atoi(value));
|
||||
}
|
||||
value = GameConfig->GetValueForKey("Sensitivity");
|
||||
if (value != NULL)
|
||||
{
|
||||
|
@ -176,6 +181,10 @@ void M_SaveJoystickConfig(IJoystickConfig *joy)
|
|||
if (GameConfig != NULL && M_SetJoystickConfigSection(joy, true, GameConfig))
|
||||
{
|
||||
GameConfig->ClearCurrentSection();
|
||||
if (!joy->GetEnabled())
|
||||
{
|
||||
GameConfig->SetValueForKey("Enabled", "0");
|
||||
}
|
||||
if (!joy->IsSensitivityDefault())
|
||||
{
|
||||
mysnprintf(value, countof(value), "%g", joy->GetSensitivity());
|
||||
|
|
|
@ -36,6 +36,9 @@ struct NOVTABLE IJoystickConfig
|
|||
virtual void SetAxisMap(int axis, EJoyAxis gameaxis) = 0;
|
||||
virtual void SetAxisScale(int axis, float scale) = 0;
|
||||
|
||||
virtual bool GetEnabled() = 0;
|
||||
virtual void SetEnabled(bool enabled) = 0;
|
||||
|
||||
// Used by the saver to not save properties that are at their defaults.
|
||||
virtual bool IsSensitivityDefault() = 0;
|
||||
virtual bool IsAxisDeadZoneDefault(int axis) = 0;
|
||||
|
|
|
@ -119,6 +119,20 @@ DEFINE_ACTION_FUNCTION(IJoystickConfig, GetNumAxes)
|
|||
ACTION_RETURN_INT(self->GetNumAxes());
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION(IJoystickConfig, GetEnabled)
|
||||
{
|
||||
PARAM_SELF_STRUCT_PROLOGUE(IJoystickConfig);
|
||||
ACTION_RETURN_BOOL(self->GetEnabled());
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION(IJoystickConfig, SetEnabled)
|
||||
{
|
||||
PARAM_SELF_STRUCT_PROLOGUE(IJoystickConfig);
|
||||
PARAM_BOOL(enabled);
|
||||
self->SetEnabled(enabled);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void UpdateJoystickMenu(IJoystickConfig *selected)
|
||||
{
|
||||
|
|
|
@ -104,6 +104,9 @@ public:
|
|||
virtual bool IsAxisMapDefault(int axis);
|
||||
virtual bool IsAxisScaleDefault(int axis);
|
||||
|
||||
virtual bool GetEnabled();
|
||||
virtual void SetEnabled(bool enabled);
|
||||
|
||||
virtual void SetDefaultConfig();
|
||||
virtual FString GetIdentifier();
|
||||
|
||||
|
@ -165,6 +168,7 @@ private:
|
|||
TArray<DigitalButton> m_buttons;
|
||||
TArray<DigitalButton> m_POVs;
|
||||
|
||||
bool m_enabled;
|
||||
bool m_useAxesPolling;
|
||||
|
||||
io_object_t m_notification;
|
||||
|
@ -279,6 +283,7 @@ IOKitJoystick::IOKitJoystick(const io_object_t device)
|
|||
: m_interface(CreateDeviceInterface(device))
|
||||
, m_queue(CreateDeviceQueue(m_interface))
|
||||
, m_sensitivity(DEFAULT_SENSITIVITY)
|
||||
, m_enabled(true)
|
||||
, m_useAxesPolling(true)
|
||||
, m_notification(0)
|
||||
{
|
||||
|
@ -430,6 +435,17 @@ bool IOKitJoystick::IsAxisScaleDefault(int axis)
|
|||
: true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool IOKitJoystick::GetEnabled()
|
||||
{
|
||||
return m_enabled;
|
||||
}
|
||||
void IOKitJoystick::SetEnabled(bool enabled)
|
||||
{
|
||||
m_enabled = enabled;
|
||||
}
|
||||
|
||||
#undef IS_AXIS_VALID
|
||||
|
||||
void IOKitJoystick::SetDefaultConfig()
|
||||
|
@ -547,7 +563,7 @@ void IOKitJoystick::Update()
|
|||
|
||||
if (kIOReturnSuccess == eventResult)
|
||||
{
|
||||
if (use_joystick)
|
||||
if (use_joystick && m_enabled)
|
||||
{
|
||||
ProcessAxis(event) || ProcessButton(event) || ProcessPOV(event);
|
||||
}
|
||||
|
@ -557,7 +573,7 @@ void IOKitJoystick::Update()
|
|||
Printf(TEXTCOLOR_RED "IOHIDQueueInterface::getNextEvent() failed with code 0x%08X\n", eventResult);
|
||||
}
|
||||
|
||||
ProcessAxes();
|
||||
if(m_enabled) ProcessAxes();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
class SDLInputJoystick: public IJoystickConfig
|
||||
{
|
||||
public:
|
||||
SDLInputJoystick(int DeviceIndex) : DeviceIndex(DeviceIndex), Multiplier(1.0f)
|
||||
SDLInputJoystick(int DeviceIndex) : DeviceIndex(DeviceIndex), Multiplier(1.0f) , Enabled(true)
|
||||
{
|
||||
Device = SDL_JoystickOpen(DeviceIndex);
|
||||
if(Device != NULL)
|
||||
|
@ -154,6 +154,17 @@ public:
|
|||
Axes.Push(info);
|
||||
}
|
||||
}
|
||||
|
||||
bool GetEnabled()
|
||||
{
|
||||
return Enabled;
|
||||
}
|
||||
|
||||
void SetEnabled(bool enabled)
|
||||
{
|
||||
Enabled = enabled;
|
||||
}
|
||||
|
||||
FString GetIdentifier()
|
||||
{
|
||||
char id[16];
|
||||
|
@ -248,9 +259,12 @@ protected:
|
|||
SDL_Joystick *Device;
|
||||
|
||||
float Multiplier;
|
||||
bool Enabled;
|
||||
TArray<AxisInfo> Axes;
|
||||
int NumAxes;
|
||||
int NumHats;
|
||||
|
||||
friend class SDLInputJoystickManager;
|
||||
};
|
||||
const EJoyAxis SDLInputJoystick::DefaultAxes[5] = {JOYAXIS_Side, JOYAXIS_Forward, JOYAXIS_Pitch, JOYAXIS_Yaw, JOYAXIS_Up};
|
||||
|
||||
|
@ -291,7 +305,7 @@ public:
|
|||
void ProcessInput() const
|
||||
{
|
||||
for(unsigned int i = 0;i < Joysticks.Size();++i)
|
||||
Joysticks[i]->ProcessInput();
|
||||
if(Joysticks[i]->Enabled) Joysticks[i]->ProcessInput();
|
||||
}
|
||||
protected:
|
||||
TArray<SDLInputJoystick *> Joysticks;
|
||||
|
|
|
@ -180,6 +180,9 @@ public:
|
|||
bool IsAxisMapDefault(int axis);
|
||||
bool IsAxisScaleDefault(int axis);
|
||||
|
||||
bool GetEnabled();
|
||||
void SetEnabled(bool enabled);
|
||||
|
||||
void SetDefaultConfig();
|
||||
FString GetIdentifier();
|
||||
|
||||
|
@ -219,6 +222,8 @@ protected:
|
|||
DIOBJECTDATAFORMAT *Objects;
|
||||
DIDATAFORMAT DataFormat;
|
||||
|
||||
bool Enabled;
|
||||
|
||||
static BOOL CALLBACK EnumObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef);
|
||||
void OrderAxes();
|
||||
bool ReorderAxisPair(const GUID &x, const GUID &y, int pos);
|
||||
|
@ -297,6 +302,7 @@ FDInputJoystick::FDInputJoystick(const GUID *instance, FString &name)
|
|||
Instance = *instance;
|
||||
Name = name;
|
||||
Marked = false;
|
||||
Enabled = true;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
|
@ -410,7 +416,7 @@ void FDInputJoystick::ProcessInput()
|
|||
{
|
||||
hr = Device->Acquire();
|
||||
}
|
||||
if (FAILED(hr))
|
||||
if (FAILED(hr) || !Enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -984,6 +990,28 @@ bool FDInputJoystick::IsAxisScaleDefault(int axis)
|
|||
return true;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// FDInputJoystick :: GetEnabled
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
bool FDInputJoystick::GetEnabled()
|
||||
{
|
||||
return Enabled;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// FDInputJoystick :: SetEnabled
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
void FDInputJoystick::SetEnabled(bool enabled)
|
||||
{
|
||||
Enabled = enabled;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// FDInputJoystick :: IsAxisMapDefault
|
||||
|
|
|
@ -114,6 +114,9 @@ public:
|
|||
bool IsAxisMapDefault(int axis);
|
||||
bool IsAxisScaleDefault(int axis);
|
||||
|
||||
bool GetEnabled();
|
||||
void SetEnabled(bool enabled);
|
||||
|
||||
void SetDefaultConfig();
|
||||
FString GetIdentifier();
|
||||
|
||||
|
@ -153,6 +156,7 @@ protected:
|
|||
bool Connected;
|
||||
bool Marked;
|
||||
bool Active;
|
||||
bool Enabled;
|
||||
|
||||
void Attached();
|
||||
void Detached();
|
||||
|
@ -376,6 +380,7 @@ FRawPS2Controller::FRawPS2Controller(HANDLE handle, EAdapterType type, int seque
|
|||
ControllerNumber = controller;
|
||||
Sequence = sequence;
|
||||
DeviceID = devid;
|
||||
Enabled = true;
|
||||
|
||||
// The EMS USB2 controller provides attachment status. The others do not.
|
||||
Connected = (Descriptors[type].ControllerStatus < 0);
|
||||
|
@ -849,6 +854,28 @@ bool FRawPS2Controller::IsAxisScaleDefault(int axis)
|
|||
return true;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// FRawPS2Controller :: GetEnabled
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
bool FRawPS2Controller::GetEnabled()
|
||||
{
|
||||
return Enabled;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// FRawPS2Controller :: SetEnabled
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
void FRawPS2Controller::SetEnabled(bool enabled)
|
||||
{
|
||||
Enabled = enabled;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// FRawPS2Controller :: IsAxisMapDefault
|
||||
|
@ -972,7 +999,7 @@ bool FRawPS2Manager::ProcessRawInput(RAWINPUT *raw, int code)
|
|||
{
|
||||
if (Devices[i]->Handle == raw->header.hDevice)
|
||||
{
|
||||
if (Devices[i]->ProcessInput(&raw->data.hid, code))
|
||||
if (Devices[i]->Enabled && Devices[i]->ProcessInput(&raw->data.hid, code))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -102,6 +102,9 @@ public:
|
|||
bool IsAxisMapDefault(int axis);
|
||||
bool IsAxisScaleDefault(int axis);
|
||||
|
||||
bool GetEnabled();
|
||||
void SetEnabled(bool enabled);
|
||||
|
||||
void SetDefaultConfig();
|
||||
FString GetIdentifier();
|
||||
|
||||
|
@ -138,6 +141,7 @@ protected:
|
|||
DWORD LastPacketNumber;
|
||||
int LastButtons;
|
||||
bool Connected;
|
||||
bool Enabled;
|
||||
|
||||
void Attached();
|
||||
void Detached();
|
||||
|
@ -221,6 +225,7 @@ FXInputController::FXInputController(int index)
|
|||
{
|
||||
Index = index;
|
||||
Connected = false;
|
||||
Enabled = true;
|
||||
M_LoadJoystickConfig(this);
|
||||
}
|
||||
|
||||
|
@ -269,7 +274,7 @@ void FXInputController::ProcessInput()
|
|||
{
|
||||
Attached();
|
||||
}
|
||||
if (state.dwPacketNumber == LastPacketNumber)
|
||||
if (state.dwPacketNumber == LastPacketNumber || !Enabled)
|
||||
{ // Nothing has changed since last time.
|
||||
return;
|
||||
}
|
||||
|
@ -628,6 +633,28 @@ bool FXInputController::IsAxisScaleDefault(int axis)
|
|||
return true;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// FXInputController :: GetEnabled
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
bool FXInputController::GetEnabled()
|
||||
{
|
||||
return Enabled;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// FXInputController :: SetEnabled
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
void FXInputController::SetEnabled(bool enabled)
|
||||
{
|
||||
Enabled = enabled;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// FXInputController :: IsAxisMapDefault
|
||||
|
|
|
@ -220,6 +220,29 @@ class OptionMenuItemInverter : OptionMenuItemOptionBase
|
|||
//
|
||||
//=============================================================================
|
||||
|
||||
|
||||
class OptionMenuJoyEnable : OptionMenuItemOptionBase
|
||||
{
|
||||
JoystickConfig mJoy;
|
||||
|
||||
OptionMenuJoyEnable Init(String label, JoystickConfig joy)
|
||||
{
|
||||
Super.Init(label,"none","YesNo",null,0);
|
||||
mJoy = joy;
|
||||
return self;
|
||||
}
|
||||
|
||||
override int GetSelection()
|
||||
{
|
||||
return mJoy.GetEnabled() ? 1 : 0;
|
||||
}
|
||||
|
||||
override void SetSelection(int Selection)
|
||||
{
|
||||
mJoy.SetEnabled(Selection);
|
||||
}
|
||||
}
|
||||
|
||||
class OptionMenuItemJoyConfigMenu : OptionMenuItemSubmenu
|
||||
{
|
||||
JoystickConfig mJoy;
|
||||
|
@ -259,6 +282,9 @@ class OptionMenuItemJoyConfigMenu : OptionMenuItemSubmenu
|
|||
it = new("OptionMenuItemStaticText").Init(joy.GetName(), false);
|
||||
it = new("OptionMenuItemStaticText").Init("", false);
|
||||
|
||||
it = new("OptionMenuJoyEnable").Init("$JOYMNU_JOYENABLE", joy);
|
||||
opt.mItems.Push(it);
|
||||
|
||||
it = new("OptionMenuSliderJoySensitivity").Init("$JOYMNU_OVRSENS", 0, 2, 0.1, 3, joy);
|
||||
opt.mItems.Push(it);
|
||||
it = new("OptionMenuItemStaticText").Init(" ", false);
|
||||
|
|
|
@ -84,6 +84,9 @@ struct JoystickConfig native version("2.4")
|
|||
native int GetNumAxes();
|
||||
native String GetAxisName(int axis);
|
||||
|
||||
native bool GetEnabled();
|
||||
native void SetEnabled(bool enabled);
|
||||
|
||||
}
|
||||
|
||||
class Menu : Object native ui version("2.4")
|
||||
|
|
Loading…
Reference in a new issue