Skip to content

Commit

Permalink
Store translated name of an input axis alongside the internal name.
Browse files Browse the repository at this point in the history
  • Loading branch information
DreamyCecil committed Sep 14, 2024
1 parent 8339580 commit 86351eb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 35 deletions.
31 changes: 12 additions & 19 deletions Sources/Engine/Base/Input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ extern FLOAT inp_bInvertMouse;
extern INDEX inp_bFilterMouse;
extern INDEX inp_bAllowPrescan;

CTString inp_astrAxisTran[EIA_MAX_ALL]; // translated names for axis

#if SE1_PREFER_SDL
// [Cecil] For synchronizing SDL events
static CTCriticalSection inp_csSDLInput;
Expand Down Expand Up @@ -470,19 +468,19 @@ void CInput::SetKeyNames( void)

// -------- Enumerate known axis -------------
// no axis as axis type 0
inp_caiAllAxisInfo[0].cai_strAxisName = "None";
inp_astrAxisTran[ 0] = TRANS("None");
inp_caiAllAxisInfo[0].cai_strNameInt = "None";
inp_caiAllAxisInfo[0].cai_strNameTra = TRANS("None");
// mouse axis occupy types from 1 up to 3
inp_caiAllAxisInfo[1].cai_strAxisName = "mouse X";
inp_astrAxisTran[ 1] = TRANS("mouse X");
inp_caiAllAxisInfo[2].cai_strAxisName = "mouse Y";
inp_astrAxisTran[ 2] = TRANS("mouse Y");
inp_caiAllAxisInfo[3].cai_strAxisName = "mouse Z";
inp_astrAxisTran[ 3] = TRANS("mouse Z");
inp_caiAllAxisInfo[4].cai_strAxisName = "2nd mouse X";
inp_astrAxisTran[ 4] = TRANS("2nd mouse X");
inp_caiAllAxisInfo[5].cai_strAxisName = "2nd mouse Y";
inp_astrAxisTran[ 5] = TRANS("2nd mouse Y");
inp_caiAllAxisInfo[1].cai_strNameInt = "mouse X";
inp_caiAllAxisInfo[1].cai_strNameTra = TRANS("mouse X");
inp_caiAllAxisInfo[2].cai_strNameInt = "mouse Y";
inp_caiAllAxisInfo[2].cai_strNameTra = TRANS("mouse Y");
inp_caiAllAxisInfo[3].cai_strNameInt = "mouse Z";
inp_caiAllAxisInfo[3].cai_strNameTra = TRANS("mouse Z");
inp_caiAllAxisInfo[4].cai_strNameInt = "2nd mouse X";
inp_caiAllAxisInfo[4].cai_strNameTra = TRANS("2nd mouse X");
inp_caiAllAxisInfo[5].cai_strNameInt = "2nd mouse Y";
inp_caiAllAxisInfo[5].cai_strNameTra = TRANS("2nd mouse Y");

// [Cecil] Set joystick names separately
SetJoystickNames();
Expand Down Expand Up @@ -837,8 +835,3 @@ void CInput::ClearInput( void)
inp_caiAllAxisInfo[i].cai_fReading = 0;
}
}

const CTString &CInput::GetAxisTransName( INDEX iAxisNo) const
{
return inp_astrAxisTran[iAxisNo];
}
22 changes: 12 additions & 10 deletions Sources/Engine/Base/Input.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,13 @@ struct MouseSpeedControl
int msc_iSpeed;
};

/*
* One axis descriptive information
*/
struct ControlAxisInfo
{
CTString cai_strAxisName; // name of this axis
FLOAT cai_fReading; // current reading of this axis
BOOL cai_bExisting; // set if the axis exists (for joystick axes)
// Information about a single axis
struct ControlAxisInfo {
CTString cai_strNameInt; // Internal name
CTString cai_strNameTra; // Translated display name

FLOAT cai_fReading; // Current reading of the axis
BOOL cai_bExisting; // Whether a controller has this axis
};

// [Cecil] Individual game controller
Expand Down Expand Up @@ -192,10 +191,13 @@ class ENGINE_API CInput {

// Get name of given axis
inline const CTString &GetAxisName(INDEX iAxisNo) const {
return inp_caiAllAxisInfo[ iAxisNo].cai_strAxisName;
return inp_caiAllAxisInfo[iAxisNo].cai_strNameInt;
};

const CTString &GetAxisTransName(INDEX iAxisNo) const;
// Get translated name of given axis
const CTString &GetAxisTransName(INDEX iAxisNo) const {
return inp_caiAllAxisInfo[iAxisNo].cai_strNameTra;
};

// Get current position of given axis
inline FLOAT GetAxisValue(INDEX iAxisNo) const {
Expand Down
10 changes: 4 additions & 6 deletions Sources/Engine/Base/InputJoystick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
INDEX inp_bForceJoystickPolling = 0;
INDEX inp_ctJoysticksAllowed = MAX_JOYSTICKS;

extern CTString inp_astrAxisTran[EIA_MAX_ALL];

GameController_t::GameController_t() : handle(NULL), iInfoSlot(-1)
{
};
Expand Down Expand Up @@ -243,14 +241,14 @@ void CInput::ShutdownJoysticks(void) {

// Adds axis and buttons for given joystick
void CInput::AddJoystickAbbilities(INDEX iSlot) {
const CTString strJoystickName(0, "C%d ", iSlot + 1);
const CTString strJoystickNameInt(0, "C%d ", iSlot + 1);
const CTString strJoystickNameTra(0, TRANS("C%d "), iSlot + 1);

const INDEX iAxisTotal = EIA_CONTROLLER_OFFSET + iSlot * SDL_CONTROLLER_AXIS_MAX;

#define SET_AXIS_NAMES(_Axis, _Name, _Translated) \
inp_caiAllAxisInfo[iAxisTotal + _Axis].cai_strAxisName = strJoystickName + _Name; \
inp_astrAxisTran [iAxisTotal + _Axis] = strJoystickNameTra + _Translated;
inp_caiAllAxisInfo[iAxisTotal + _Axis].cai_strNameInt = strJoystickNameInt + _Name; \
inp_caiAllAxisInfo[iAxisTotal + _Axis].cai_strNameTra = strJoystickNameTra + _Translated;

// Set default names for all axes
for (INDEX iAxis = 0; iAxis < SDL_CONTROLLER_AXIS_MAX; iAxis++) {
Expand All @@ -268,7 +266,7 @@ void CInput::AddJoystickAbbilities(INDEX iSlot) {
const INDEX iButtonTotal = FIRST_JOYBUTTON + iSlot * SDL_CONTROLLER_BUTTON_MAX;

#define SET_BUTTON_NAMES(_Button, _Name, _Translated) \
inp_strButtonNames [iButtonTotal + _Button] = strJoystickName + _Name; \
inp_strButtonNames [iButtonTotal + _Button] = strJoystickNameInt + _Name; \
inp_strButtonNamesTra[iButtonTotal + _Button] = strJoystickNameTra + _Translated;

// Set default names for all buttons
Expand Down

0 comments on commit 86351eb

Please sign in to comment.