5423: Rename joystick to controller (settings, configs) (fixes #5419) r=Robyt3 a=def-

Also added one Localize

<!-- What is the motivation for the changes of this pull request -->

## Checklist

- [ ] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Dennis Felsing <dennis@felsin9.de>
This commit is contained in:
bors[bot] 2022-06-15 11:39:36 +00:00 committed by GitHub
commit c04aaac64a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 55 additions and 55 deletions

View file

@ -129,7 +129,7 @@ void CInput::UpdateActiveJoystick()
m_pActiveJoystick = nullptr;
for(auto &Joystick : m_vJoysticks)
{
if(str_comp(Joystick.GetGUID(), g_Config.m_InpJoystickGUID) == 0)
if(str_comp(Joystick.GetGUID(), g_Config.m_InpControllerGUID) == 0)
{
m_pActiveJoystick = &Joystick;
return;
@ -148,7 +148,7 @@ void CInput::ConchainJoystickGuidChanged(IConsole::IResult *pResult, void *pUser
float CInput::GetJoystickDeadzone()
{
return g_Config.m_InpJoystickTolerance / 50.0f;
return g_Config.m_InpControllerTolerance / 50.0f;
}
CInput::CJoystick::CJoystick(CInput *pInput, int Index, SDL_Joystick *pDelegate)
@ -185,7 +185,7 @@ void CInput::SelectNextJoystick()
if(Num > 1)
{
m_pActiveJoystick = &m_vJoysticks[(m_pActiveJoystick->GetIndex() + 1) % Num];
str_copy(g_Config.m_InpJoystickGUID, m_pActiveJoystick->GetGUID(), sizeof(g_Config.m_InpJoystickGUID));
str_copy(g_Config.m_InpControllerGUID, m_pActiveJoystick->GetGUID(), sizeof(g_Config.m_InpControllerGUID));
}
}
@ -217,10 +217,10 @@ int CInput::CJoystick::GetHatValue(int Hat)
bool CInput::CJoystick::Relative(float *pX, float *pY)
{
if(!g_Config.m_InpJoystickEnable)
if(!g_Config.m_InpControllerEnable)
return false;
const vec2 RawJoystickPos = vec2(GetAxisValue(g_Config.m_InpJoystickX), GetAxisValue(g_Config.m_InpJoystickY));
const vec2 RawJoystickPos = vec2(GetAxisValue(g_Config.m_InpControllerX), GetAxisValue(g_Config.m_InpControllerY));
const float Len = length(RawJoystickPos);
const float DeadZone = Input()->GetJoystickDeadzone();
if(Len > DeadZone)
@ -235,10 +235,10 @@ bool CInput::CJoystick::Relative(float *pX, float *pY)
bool CInput::CJoystick::Absolute(float *pX, float *pY)
{
if(!Input()->m_MouseFocus || !Input()->m_InputGrabbed || !g_Config.m_InpJoystickEnable)
if(!Input()->m_MouseFocus || !Input()->m_InputGrabbed || !g_Config.m_InpControllerEnable)
return false;
const vec2 RawJoystickPos = vec2(GetAxisValue(g_Config.m_InpJoystickX), GetAxisValue(g_Config.m_InpJoystickY));
const vec2 RawJoystickPos = vec2(GetAxisValue(g_Config.m_InpControllerX), GetAxisValue(g_Config.m_InpControllerY));
const float DeadZone = Input()->GetJoystickDeadzone();
if(dot(RawJoystickPos, RawJoystickPos) > DeadZone * DeadZone)
{
@ -364,7 +364,7 @@ void CInput::UpdateMouseState()
void CInput::UpdateJoystickState()
{
if(!g_Config.m_InpJoystickEnable)
if(!g_Config.m_InpControllerEnable)
return;
IJoystick *pJoystick = GetActiveJoystick();
if(!pJoystick)
@ -390,7 +390,7 @@ void CInput::UpdateJoystickState()
void CInput::HandleJoystickAxisMotionEvent(const SDL_Event &Event)
{
if(!g_Config.m_InpJoystickEnable)
if(!g_Config.m_InpControllerEnable)
return;
CJoystick *pJoystick = GetActiveJoystick();
if(!pJoystick || pJoystick->GetInstanceID() != Event.jaxis.which)
@ -429,7 +429,7 @@ void CInput::HandleJoystickAxisMotionEvent(const SDL_Event &Event)
void CInput::HandleJoystickButtonEvent(const SDL_Event &Event)
{
if(!g_Config.m_InpJoystickEnable)
if(!g_Config.m_InpControllerEnable)
return;
CJoystick *pJoystick = GetActiveJoystick();
if(!pJoystick || pJoystick->GetInstanceID() != Event.jbutton.which)
@ -454,7 +454,7 @@ void CInput::HandleJoystickButtonEvent(const SDL_Event &Event)
void CInput::HandleJoystickHatMotionEvent(const SDL_Event &Event)
{
if(!g_Config.m_InpJoystickEnable)
if(!g_Config.m_InpControllerEnable)
return;
CJoystick *pJoystick = GetActiveJoystick();
if(!pJoystick || pJoystick->GetInstanceID() != Event.jhat.which)

View file

@ -132,13 +132,13 @@ MACRO_CONFIG_INT(InpMouseOld, inp_mouseold, 0, 0, 1, CFGFLAG_SAVE | CFGFLAG_CLIE
MACRO_CONFIG_INT(InpTranslatedKeys, inp_translated_keys, 0, 0, 1, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Translate keys before interpreting them, respects keyboard layouts")
MACRO_CONFIG_INT(InpIgnoredModifiers, inp_ignored_modifiers, 0, 0, 65536, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Ignored keyboard modifier mask")
MACRO_CONFIG_INT(InpJoystickEnable, inp_joystick_enable, 0, 0, 1, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Enable joystick")
MACRO_CONFIG_STR(InpJoystickGUID, inp_joystick_guid, 34, "", CFGFLAG_SAVE | CFGFLAG_CLIENT, "Joystick GUID which uniquely identifies the active joystick")
MACRO_CONFIG_INT(InpJoystickAbsolute, inp_joystick_absolute, 0, 0, 1, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Enable absolute joystick aiming ingame")
MACRO_CONFIG_INT(InpJoystickSens, inp_joystick_sens, 100, 1, 100000, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Ingame joystick sensitivity")
MACRO_CONFIG_INT(InpJoystickX, inp_joystick_x, 0, 0, 12, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Joystick axis that controls X axis of cursor")
MACRO_CONFIG_INT(InpJoystickY, inp_joystick_y, 1, 0, 12, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Joystick axis that controls Y axis of cursor")
MACRO_CONFIG_INT(InpJoystickTolerance, inp_joystick_tolerance, 5, 0, 50, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Joystick axis tolerance to account for jitter")
MACRO_CONFIG_INT(InpControllerEnable, inp_controller_enable, 0, 0, 1, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Enable controller")
MACRO_CONFIG_STR(InpControllerGUID, inp_controller_guid, 34, "", CFGFLAG_SAVE | CFGFLAG_CLIENT, "Controller GUID which uniquely identifies the active controller")
MACRO_CONFIG_INT(InpControllerAbsolute, inp_controller_absolute, 0, 0, 1, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Enable absolute controller aiming ingame")
MACRO_CONFIG_INT(InpControllerSens, inp_controller_sens, 100, 1, 100000, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Ingame controller sensitivity")
MACRO_CONFIG_INT(InpControllerX, inp_controller_x, 0, 0, 12, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Controller axis that controls X axis of cursor")
MACRO_CONFIG_INT(InpControllerY, inp_controller_y, 1, 0, 12, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Controller axis that controls Y axis of cursor")
MACRO_CONFIG_INT(InpControllerTolerance, inp_controller_tolerance, 5, 0, 50, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Controller axis tolerance to account for jitter")
MACRO_CONFIG_INT(ClPort, cl_port, 0, 0, 65535, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Port to use for client connections to server (0 to choose a random port, 1024 or higher to set a manual port, requires a restart)")
MACRO_CONFIG_INT(ClDummyPort, cl_dummy_port, 0, 0, 65535, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Port to use for dummy connections to server (0 to choose a random port, 1024 or higher to set a manual port, requires a restart)")

View file

@ -370,7 +370,7 @@ bool CControls::OnCursorMove(float x, float y, IInput::ECursorType CursorType)
if(m_pClient->m_Snap.m_pGameInfoObj && (m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags & GAMESTATEFLAG_PAUSED))
return false;
if(CursorType == IInput::CURSOR_JOYSTICK && g_Config.m_InpJoystickAbsolute && m_pClient->m_Snap.m_pGameInfoObj && !m_pClient->m_Snap.m_SpecInfo.m_Active)
if(CursorType == IInput::CURSOR_JOYSTICK && g_Config.m_InpControllerAbsolute && m_pClient->m_Snap.m_pGameInfoObj && !m_pClient->m_Snap.m_SpecInfo.m_Active)
{
float AbsX = 0.0f, AbsY = 0.0f;
if(Input()->GetActiveJoystick()->Absolute(&AbsX, &AbsY))
@ -391,7 +391,7 @@ bool CControls::OnCursorMove(float x, float y, IInput::ECursorType CursorType)
Factor = g_Config.m_InpMousesens / 100.0f;
break;
case IInput::CURSOR_JOYSTICK:
Factor = g_Config.m_InpJoystickSens / 100.0f;
Factor = g_Config.m_InpControllerSens / 100.0f;
break;
default:
dbg_msg("assert", "CControls::OnCursorMove CursorType %d", (int)CursorType);

View file

@ -939,7 +939,7 @@ void CMenus::DoSettingsControlsButtons(int Start, int Stop, CUIRect View)
float CMenus::RenderSettingsControlsJoystick(CUIRect View)
{
bool JoystickEnabled = g_Config.m_InpJoystickEnable;
bool JoystickEnabled = g_Config.m_InpControllerEnable;
int NumJoysticks = Input()->NumJoysticks();
int NumOptions = 1; // expandable header
if(JoystickEnabled)
@ -951,7 +951,7 @@ float CMenus::RenderSettingsControlsJoystick(CUIRect View)
if(NumJoysticks > 1)
NumOptions++; // joystick selection
NumOptions += 3; // mode, ui sens, tolerance
if(!g_Config.m_InpJoystickAbsolute)
if(!g_Config.m_InpControllerAbsolute)
NumOptions++; // ingame sens
NumOptions += Input()->GetActiveJoystick()->GetNumAxes() + 1; // axis selection + header
}
@ -967,9 +967,9 @@ float CMenus::RenderSettingsControlsJoystick(CUIRect View)
CUIRect Button;
View.HSplitTop(Spacing, 0, &View);
View.HSplitTop(ButtonHeight, &Button, &View);
if(DoButton_CheckBox(&g_Config.m_InpJoystickEnable, Localize("Enable joystick"), g_Config.m_InpJoystickEnable, &Button))
if(DoButton_CheckBox(&g_Config.m_InpControllerEnable, Localize("Enable controller"), g_Config.m_InpControllerEnable, &Button))
{
g_Config.m_InpJoystickEnable ^= 1;
g_Config.m_InpControllerEnable ^= 1;
}
if(JoystickEnabled)
{
@ -982,33 +982,33 @@ float CMenus::RenderSettingsControlsJoystick(CUIRect View)
View.HSplitTop(ButtonHeight, &Button, &View);
static int s_ButtonJoystickId;
char aBuf[96];
str_format(aBuf, sizeof(aBuf), "Joystick %d: %s", Input()->GetActiveJoystick()->GetIndex(), Input()->GetActiveJoystick()->GetName());
str_format(aBuf, sizeof(aBuf), Localize("Controller %d: %s"), Input()->GetActiveJoystick()->GetIndex(), Input()->GetActiveJoystick()->GetName());
if(DoButton_Menu(&s_ButtonJoystickId, aBuf, 0, &Button))
Input()->SelectNextJoystick();
GameClient()->m_Tooltips.DoToolTip(&s_ButtonJoystickId, &Button, Localize("Click to cycle through all available joysticks."));
GameClient()->m_Tooltips.DoToolTip(&s_ButtonJoystickId, &Button, Localize("Click to cycle through all available controllers."));
}
{
View.HSplitTop(Spacing, 0, &View);
View.HSplitTop(ButtonHeight, &Button, &View);
const char *apLabels[] = {Localize("Relative", "Ingame joystick mode"), Localize("Absolute", "Ingame joystick mode")};
UIEx()->DoScrollbarOptionLabeled(&g_Config.m_InpJoystickAbsolute, &g_Config.m_InpJoystickAbsolute, &Button, Localize("Ingame joystick mode"), apLabels, std::size(apLabels));
const char *apLabels[] = {Localize("Relative", "Ingame controller mode"), Localize("Absolute", "Ingame controller mode")};
UIEx()->DoScrollbarOptionLabeled(&g_Config.m_InpControllerAbsolute, &g_Config.m_InpControllerAbsolute, &Button, Localize("Ingame controller mode"), apLabels, std::size(apLabels));
}
if(!g_Config.m_InpJoystickAbsolute)
if(!g_Config.m_InpControllerAbsolute)
{
View.HSplitTop(Spacing, 0, &View);
View.HSplitTop(ButtonHeight, &Button, &View);
UIEx()->DoScrollbarOption(&g_Config.m_InpJoystickSens, &g_Config.m_InpJoystickSens, &Button, Localize("Ingame joystick sens."), 1, 500, &CUIEx::ms_LogarithmicScrollbarScale, CUIEx::SCROLLBAR_OPTION_NOCLAMPVALUE);
UIEx()->DoScrollbarOption(&g_Config.m_InpControllerSens, &g_Config.m_InpControllerSens, &Button, Localize("Ingame controller sens."), 1, 500, &CUIEx::ms_LogarithmicScrollbarScale, CUIEx::SCROLLBAR_OPTION_NOCLAMPVALUE);
}
View.HSplitTop(Spacing, 0, &View);
View.HSplitTop(ButtonHeight, &Button, &View);
UIEx()->DoScrollbarOption(&g_Config.m_UiJoystickSens, &g_Config.m_UiJoystickSens, &Button, Localize("UI joystick sens."), 1, 500, &CUIEx::ms_LogarithmicScrollbarScale, CUIEx::SCROLLBAR_OPTION_NOCLAMPVALUE);
UIEx()->DoScrollbarOption(&g_Config.m_UiControllerSens, &g_Config.m_UiControllerSens, &Button, Localize("UI controller sens."), 1, 500, &CUIEx::ms_LogarithmicScrollbarScale, CUIEx::SCROLLBAR_OPTION_NOCLAMPVALUE);
View.HSplitTop(Spacing, 0, &View);
View.HSplitTop(ButtonHeight, &Button, &View);
UIEx()->DoScrollbarOption(&g_Config.m_InpJoystickTolerance, &g_Config.m_InpJoystickTolerance, &Button, Localize("Joystick jitter tolerance"), 0, 50);
UIEx()->DoScrollbarOption(&g_Config.m_InpControllerTolerance, &g_Config.m_InpControllerTolerance, &Button, Localize("Controller jitter tolerance"), 0, 50);
View.HSplitTop(Spacing, 0, &View);
RenderTools()->DrawUIRect(&View, ColorRGBA(0.0f, 0.0f, 0.0f, 0.125f), CUI::CORNER_ALL, 5.0f);
@ -1018,7 +1018,7 @@ float CMenus::RenderSettingsControlsJoystick(CUIRect View)
{
View.HSplitTop((View.h - ButtonHeight) / 2.0f, 0, &View);
View.HSplitTop(ButtonHeight, &Button, &View);
UI()->DoLabel(&Button, Localize("No joysticks found. Plug in a joystick and restart the game."), 13.0f, TEXTALIGN_CENTER);
UI()->DoLabel(&Button, Localize("No controller found. Plug in a controller and restart the game."), 13.0f, TEXTALIGN_CENTER);
}
}
@ -1050,7 +1050,7 @@ void CMenus::DoJoystickAxisPicker(CUIRect View)
static int s_aActive[NUM_JOYSTICK_AXES][2];
for(int i = 0; i < minimum<int>(pJoystick->GetNumAxes(), NUM_JOYSTICK_AXES); i++)
{
bool Active = g_Config.m_InpJoystickX == i || g_Config.m_InpJoystickY == i;
bool Active = g_Config.m_InpControllerX == i || g_Config.m_InpControllerY == i;
View.HSplitTop(Spacing, 0, &View);
View.HSplitTop(ButtonHeight, &Row, &View);
@ -1059,7 +1059,7 @@ void CMenus::DoJoystickAxisPicker(CUIRect View)
// Device label
Row.VSplitLeft(DeviceLabelWidth, &Button, &Row);
char aBuf[64];
str_format(aBuf, sizeof(aBuf), Localize("Joystick Axis #%d"), i + 1);
str_format(aBuf, sizeof(aBuf), Localize("Controller Axis #%d"), i + 1);
if(!Active)
TextRender()->TextColor(0.7f, 0.7f, 0.7f, 1.0f);
else
@ -1070,23 +1070,23 @@ void CMenus::DoJoystickAxisPicker(CUIRect View)
Row.VSplitLeft(StatusMargin, 0, &Row);
Row.VSplitLeft(StatusWidth, &Button, &Row);
Button.HMargin((ButtonHeight - 14.0f) / 2.0f, &Button);
DoJoystickBar(&Button, (pJoystick->GetAxisValue(i) + 1.0f) / 2.0f, g_Config.m_InpJoystickTolerance / 50.0f, Active);
DoJoystickBar(&Button, (pJoystick->GetAxisValue(i) + 1.0f) / 2.0f, g_Config.m_InpControllerTolerance / 50.0f, Active);
// Bind to X,Y
Row.VSplitLeft(2 * StatusMargin, 0, &Row);
Row.VSplitLeft(BindWidth, &Button, &Row);
if(DoButton_CheckBox(&s_aActive[i][0], "X", g_Config.m_InpJoystickX == i, &Button))
if(DoButton_CheckBox(&s_aActive[i][0], "X", g_Config.m_InpControllerX == i, &Button))
{
if(g_Config.m_InpJoystickY == i)
g_Config.m_InpJoystickY = g_Config.m_InpJoystickX;
g_Config.m_InpJoystickX = i;
if(g_Config.m_InpControllerY == i)
g_Config.m_InpControllerY = g_Config.m_InpControllerX;
g_Config.m_InpControllerX = i;
}
Row.VSplitLeft(BindWidth, &Button, &Row);
if(DoButton_CheckBox(&s_aActive[i][1], "Y", g_Config.m_InpJoystickY == i, &Button))
if(DoButton_CheckBox(&s_aActive[i][1], "Y", g_Config.m_InpControllerY == i, &Button))
{
if(g_Config.m_InpJoystickX == i)
g_Config.m_InpJoystickX = g_Config.m_InpJoystickY;
g_Config.m_InpJoystickY = i;
if(g_Config.m_InpControllerX == i)
g_Config.m_InpControllerX = g_Config.m_InpControllerY;
g_Config.m_InpControllerY = i;
}
Row.VSplitLeft(StatusMargin, 0, &Row);
}
@ -1188,7 +1188,7 @@ void CMenus::RenderSettingsControls(CUIRect MainView)
RenderTools()->DrawUIRect(&JoystickSettings, ColorRGBA(1, 1, 1, 0.25f), CUI::CORNER_ALL, 10.0f);
JoystickSettings.VMargin(Margin, &JoystickSettings);
TextRender()->Text(0, JoystickSettings.x, JoystickSettings.y + (HeaderHeight - FontSize) / 2.f, FontSize, Localize("Joystick"), -1.0f);
TextRender()->Text(0, JoystickSettings.x, JoystickSettings.y + (HeaderHeight - FontSize) / 2.f, FontSize, Localize("Controller"), -1.0f);
JoystickSettings.HSplitTop(HeaderHeight, 0, &JoystickSettings);
s_JoystickSettingsHeight = RenderSettingsControlsJoystick(JoystickSettings) + HeaderHeight + Margin; // + Margin for another bottom margin
@ -1236,14 +1236,14 @@ void CMenus::RenderSettingsControls(CUIRect MainView)
g_Config.m_InpMousesens = 200;
g_Config.m_UiMousesens = 200;
g_Config.m_InpJoystickEnable = 0;
g_Config.m_InpJoystickGUID[0] = '\0';
g_Config.m_InpJoystickAbsolute = 0;
g_Config.m_InpJoystickSens = 100;
g_Config.m_InpJoystickX = 0;
g_Config.m_InpJoystickY = 1;
g_Config.m_InpJoystickTolerance = 5;
g_Config.m_UiJoystickSens = 100;
g_Config.m_InpControllerEnable = 0;
g_Config.m_InpControllerGUID[0] = '\0';
g_Config.m_InpControllerAbsolute = 0;
g_Config.m_InpControllerSens = 100;
g_Config.m_InpControllerX = 0;
g_Config.m_InpControllerY = 1;
g_Config.m_InpControllerTolerance = 5;
g_Config.m_UiControllerSens = 100;
}
}

View file

@ -173,7 +173,7 @@ void CUI::ConvertMouseMove(float *pX, float *pY, IInput::ECursorType CursorType)
Factor = g_Config.m_UiMousesens / 100.0f;
break;
case IInput::CURSOR_JOYSTICK:
Factor = g_Config.m_UiJoystickSens / 100.0f;
Factor = g_Config.m_UiControllerSens / 100.0f;
break;
default:
dbg_msg("assert", "CUI::ConvertMouseMove CursorType %d", (int)CursorType);

View file

@ -117,7 +117,7 @@ MACRO_CONFIG_INT(UiSettingsPage, ui_settings_page, 0, 0, 9, CFGFLAG_CLIENT | CFG
MACRO_CONFIG_INT(UiToolboxPage, ui_toolbox_page, 0, 0, 2, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Toolbox page")
MACRO_CONFIG_STR(UiServerAddress, ui_server_address, 64, "localhost:8303", CFGFLAG_CLIENT | CFGFLAG_SAVE | CFGFLAG_INSENSITIVE, "Interface server address")
MACRO_CONFIG_INT(UiMousesens, ui_mousesens, 200, 1, 100000, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Mouse sensitivity for menus/editor")
MACRO_CONFIG_INT(UiJoystickSens, ui_joystick_sens, 100, 1, 100000, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Joystick sensitivity for menus/editor")
MACRO_CONFIG_INT(UiControllerSens, ui_controller_sens, 100, 1, 100000, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Controller sensitivity for menus/editor")
MACRO_CONFIG_COL(UiColor, ui_color, 0xE4A046AF, CFGFLAG_CLIENT | CFGFLAG_SAVE | CFGFLAG_COLALPHA, "Interface color") // 160 70 175 228 hasalpha