2017-02-11 15:11:48 +00:00
|
|
|
/*
|
|
|
|
** joystickmenu.cpp
|
|
|
|
** The joystick configuration menus
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
** Copyright 2010-2017 Christoph Oelckers
|
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
** are met:
|
|
|
|
**
|
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
|
|
** documentation and/or other materials provided with the distribution.
|
|
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
|
|
** derived from this software without specific prior written permission.
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
2017-02-10 23:36:53 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
class OptionMenuSliderJoySensitivity : OptionMenuSliderBase
|
|
|
|
{
|
|
|
|
void Init(String label, double min, double max, double step, int showval)
|
|
|
|
{
|
|
|
|
Super.Init(label, min, max, step, showval);
|
|
|
|
}
|
|
|
|
|
|
|
|
override double GetSliderValue()
|
|
|
|
{
|
|
|
|
return Menu.GetCurrentJoystickConfig().GetSensitivity();
|
|
|
|
}
|
|
|
|
|
|
|
|
override void SetSliderValue(double val)
|
|
|
|
{
|
|
|
|
Menu.GetCurrentJoystickConfig().SetSensitivity(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
class OptionMenuSliderJoyScale : OptionMenuSliderBase
|
|
|
|
{
|
|
|
|
int mAxis;
|
|
|
|
int mNeg;
|
|
|
|
|
|
|
|
void Init(String label, int axis, double min, double max, double step, int showval)
|
|
|
|
{
|
|
|
|
Super.Init(label, min, max, step, showval);
|
|
|
|
mAxis = axis;
|
|
|
|
mNeg = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
override double GetSliderValue()
|
|
|
|
{
|
|
|
|
double d = Menu.GetCurrentJoystickConfig().GetAxisScale(mAxis);
|
|
|
|
mNeg = d < 0? -1:1;
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
override void SetSliderValue(double val)
|
|
|
|
{
|
|
|
|
Menu.GetCurrentJoystickConfig().SetAxisScale(mAxis, val * mNeg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
class OptionMenuSliderJoyDeadZone : OptionMenuSliderBase
|
|
|
|
{
|
|
|
|
int mAxis;
|
|
|
|
int mNeg;
|
|
|
|
|
|
|
|
|
|
|
|
void Init(String label, int axis, double min, double max, double step, int showval)
|
|
|
|
{
|
|
|
|
Super.Init(label, min, max, step, showval);
|
|
|
|
mAxis = axis;
|
|
|
|
mNeg = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
override double GetSliderValue()
|
|
|
|
{
|
|
|
|
double d = Menu.GetCurrentJoystickConfig().GetAxisDeadZone(mAxis);
|
|
|
|
mNeg = d < 0? -1:1;
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
override void SetSliderValue(double val)
|
|
|
|
{
|
|
|
|
Menu.GetCurrentJoystickConfig().SetAxisDeadZone(mAxis, val * mNeg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
class OptionMenuItemJoyMap : OptionMenuItemOptionBase
|
|
|
|
{
|
|
|
|
int mAxis;
|
|
|
|
|
2017-02-11 20:28:48 +00:00
|
|
|
void Init(String label, int axis, Name values, int center)
|
2017-02-10 23:36:53 +00:00
|
|
|
{
|
|
|
|
Super.Init(label, 'none', values, null, center);
|
|
|
|
mAxis = axis;
|
|
|
|
}
|
|
|
|
|
|
|
|
override int GetSelection()
|
|
|
|
{
|
|
|
|
double f = Menu.GetCurrentJoystickConfig().GetAxisMap(mAxis);
|
|
|
|
let opt = OptionValues.GetCount(mValues);
|
|
|
|
if (opt > 0)
|
|
|
|
{
|
|
|
|
// Map from joystick axis to menu selection.
|
|
|
|
for(int i = 0; i < opt; i++)
|
|
|
|
{
|
|
|
|
if (f ~== OptionValues.GetValue(mValues, i))
|
|
|
|
{
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
override void SetSelection(int selection)
|
|
|
|
{
|
|
|
|
let opt = OptionValues.GetCount(mValues);
|
|
|
|
// Map from menu selection to joystick axis.
|
|
|
|
if (opt == 0 || selection >= opt)
|
|
|
|
{
|
|
|
|
selection = JoystickConfig.JOYAXIS_None;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-02-11 15:11:48 +00:00
|
|
|
selection = int(OptionValues.GetValue(mValues, selection));
|
2017-02-10 23:36:53 +00:00
|
|
|
}
|
|
|
|
Menu.GetCurrentJoystickConfig().SetAxisMap(mAxis, selection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
class OptionMenuItemInverter : OptionMenuItemOptionBase
|
|
|
|
{
|
|
|
|
int mAxis;
|
|
|
|
|
|
|
|
|
|
|
|
void Init(String label, int axis, int center)
|
|
|
|
{
|
|
|
|
Super.Init(label, "none", "YesNo", NULL, center);
|
|
|
|
mAxis = axis;
|
|
|
|
}
|
|
|
|
|
|
|
|
override int GetSelection()
|
|
|
|
{
|
|
|
|
float f = Menu.GetCurrentJoystickConfig().GetAxisScale(mAxis);
|
|
|
|
return f > 0? 0:1;
|
|
|
|
}
|
|
|
|
|
|
|
|
override void SetSelection(int Selection)
|
|
|
|
{
|
|
|
|
let f = abs(Menu.GetCurrentJoystickConfig().GetAxisScale(mAxis));
|
|
|
|
if (Selection) f*=-1;
|
|
|
|
Menu.GetCurrentJoystickConfig().SetAxisScale(mAxis, f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
// Executes a CCMD, action is a CCMD name
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
class OptionMenuItemJoyConfigMenu : OptionMenuItemSubmenu
|
|
|
|
{
|
|
|
|
JoystickConfig mJoy;
|
|
|
|
|
|
|
|
void Init(String label = "", JoystickConfig joy = null)
|
|
|
|
{
|
|
|
|
Super.Init(label, "JoystickConfigMenu");
|
|
|
|
mJoy = joy;
|
|
|
|
}
|
|
|
|
|
|
|
|
override bool Activate()
|
|
|
|
{
|
|
|
|
//UpdateJoystickConfigMenu(mJoy);
|
|
|
|
return Super.Activate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|