From 3c9897989cf2e4c99e1718355fd70aeb2932cc6d Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Thu, 15 Jun 2006 06:07:45 +0000 Subject: [PATCH] GetDeviceSpecificInputString and DeviceInputToLocalizedString are the same: "a string suitable for display", but just formatted slightly differently. Handle these the same way (so hopefully a way to merge them will become visible). This also fixes the RageInputDevice dependency on RageInput. --- stepmania/src/RageInput.cpp | 17 +++++++ stepmania/src/RageInput.h | 1 + stepmania/src/RageInputDevice.cpp | 44 ------------------- stepmania/src/RageInputDevice.h | 2 - stepmania/src/ScreenEdit.cpp | 5 ++- .../src/arch/InputHandler/InputHandler.cpp | 41 +++++++++++++++++ .../src/arch/InputHandler/InputHandler.h | 1 + 7 files changed, 63 insertions(+), 48 deletions(-) diff --git a/stepmania/src/RageInput.cpp b/stepmania/src/RageInput.cpp index 7e924f16c5..50b8b13671 100644 --- a/stepmania/src/RageInput.cpp +++ b/stepmania/src/RageInput.cpp @@ -97,6 +97,23 @@ RString RageInput::GetDeviceSpecificInputString( const DeviceInput &di ) return di.ToString(); } +RString RageInput::GetLocalizedInputString( const DeviceInput &di ) +{ + FOREACH( InputHandler*, m_pDevices, i ) + { + vector vDevices; + (*i)->GetDevicesAndDescriptions( vDevices ); + + FOREACH_CONST( InputDeviceInfo, vDevices, idi ) + { + if( idi->id == di.device ) + return (*i)->GetLocalizedInputString(di); + } + } + + return Capitalize( DeviceButtonToString(di.button) ); +} + wchar_t RageInput::DeviceInputToChar( DeviceInput di, bool bUseCurrentKeyModifiers ) { FOREACH( InputHandler*, m_pDevices, i ) diff --git a/stepmania/src/RageInput.h b/stepmania/src/RageInput.h index 79df8d1c5d..d24bfb2d3f 100644 --- a/stepmania/src/RageInput.h +++ b/stepmania/src/RageInput.h @@ -21,6 +21,7 @@ public: void WindowReset(); void AddHandler( InputHandler *pHandler ); RString GetDeviceSpecificInputString( const DeviceInput &di ); + RString GetLocalizedInputString( const DeviceInput &di ); wchar_t DeviceInputToChar( DeviceInput di, bool bUseCurrentKeyModifiers ); InputDeviceState GetInputDeviceState( InputDevice id ); RString GetDisplayDevicesString() const; diff --git a/stepmania/src/RageInputDevice.cpp b/stepmania/src/RageInputDevice.cpp index 59d8632286..e30616b7d8 100644 --- a/stepmania/src/RageInputDevice.cpp +++ b/stepmania/src/RageInputDevice.cpp @@ -7,8 +7,6 @@ #include "RageInputDevice.h" #include "RageUtil.h" #include "EnumHelper.h" -#include "LocalizedString.h" -#include "RageInput.h" static map g_mapNamesToString; static map g_mapStringToNames; @@ -150,48 +148,6 @@ RString DeviceButtonToString( DeviceButton key ) return "unknown"; } -static LocalizedString HOME ( "DeviceButton", "Home" ); -static LocalizedString END ( "DeviceButton", "End" ); -static LocalizedString UP ( "DeviceButton", "Up" ); -static LocalizedString DOWN ( "DeviceButton", "Down" ); -static LocalizedString SPACE ( "DeviceButton", "Space" ); -static LocalizedString SHIFT ( "DeviceButton", "Shift" ); -static LocalizedString CTRL ( "DeviceButton", "Ctrl" ); -static LocalizedString ALT ( "DeviceButton", "Alt" ); -static LocalizedString INSERT ( "DeviceButton", "Insert" ); -static LocalizedString DELETE ( "DeviceButton", "Delete" ); -static LocalizedString PGUP ( "DeviceButton", "PgUp" ); -static LocalizedString PGDN ( "DeviceButton", "PgDn" ); -static LocalizedString BACKSLASH ( "DeviceButton", "Backslash" ); - -/* Return the name of the button, as it probably appears on the device itself, such as a keycap; - * eg. "a". */ -RString DeviceInputToLocalizedString( DeviceInput di ) -{ - switch( di.button ) - { - case KEY_HOME: return HOME.GetValue(); - case KEY_END: return END.GetValue(); - case KEY_UP: return UP.GetValue(); - case KEY_DOWN: return DOWN.GetValue(); - case KEY_SPACE: return SPACE.GetValue(); - case KEY_LSHIFT: case KEY_RSHIFT: return SHIFT.GetValue(); - case KEY_LCTRL: case KEY_RCTRL: return CTRL.GetValue(); - case KEY_LALT: case KEY_RALT: return ALT.GetValue(); - case KEY_INSERT: return INSERT.GetValue(); - case KEY_DEL: return DELETE.GetValue(); - case KEY_PGUP: return PGUP.GetValue(); - case KEY_PGDN: return PGDN.GetValue(); - case KEY_BACKSLASH: return BACKSLASH.GetValue(); - default: - wchar_t c = INPUTMAN->DeviceInputToChar(di,false); - if( c ) - return Capitalize( WStringToRString(wstring()+c) ); - - return Capitalize( DeviceButtonToString(di.button) ); - } -} - DeviceButton StringToDeviceButton( const RString& s ) { InitNames(); diff --git a/stepmania/src/RageInputDevice.h b/stepmania/src/RageInputDevice.h index 2e02963b14..5107f6f071 100644 --- a/stepmania/src/RageInputDevice.h +++ b/stepmania/src/RageInputDevice.h @@ -339,8 +339,6 @@ public: bool IsJoystick() const { return ::IsJoystick(device); } }; -RString DeviceInputToLocalizedString( DeviceInput di ); - #endif /* * Copyright (c) 2001-2002 Chris Danford diff --git a/stepmania/src/ScreenEdit.cpp b/stepmania/src/ScreenEdit.cpp index 4760bdb8ee..24fe33ee29 100644 --- a/stepmania/src/ScreenEdit.cpp +++ b/stepmania/src/ScreenEdit.cpp @@ -6,6 +6,7 @@ #include "ScreenSaveSync.h" #include "GameConstantsAndTypes.h" #include "GameManager.h" +#include "RageInput.h" #include "RageLog.h" #include "GameSoundManager.h" #include "GameState.h" @@ -3585,9 +3586,9 @@ static RString GetDeviceButtonsLocalized( const vector &veb, const M DeviceInput diPress = editmap.button[*eb][s]; DeviceInput diHold = editmap.hold[*eb][s]; if( diPress.IsValid() ) - vsPress.push_back( DeviceInputToLocalizedString(diPress) ); + vsPress.push_back( INPUTMAN->GetLocalizedInputString(diPress) ); if( diHold.IsValid() ) - vsHold.push_back( DeviceInputToLocalizedString(diHold) ); + vsHold.push_back( INPUTMAN->GetLocalizedInputString(diHold) ); } } diff --git a/stepmania/src/arch/InputHandler/InputHandler.cpp b/stepmania/src/arch/InputHandler/InputHandler.cpp index 1800d2b7ae..0798f33a55 100644 --- a/stepmania/src/arch/InputHandler/InputHandler.cpp +++ b/stepmania/src/arch/InputHandler/InputHandler.cpp @@ -3,6 +3,7 @@ #include "RageUtil.h" #include "InputHandler.h" #include "RageLog.h" +#include "LocalizedString.h" void InputHandler::UpdateTimer() { @@ -118,6 +119,46 @@ RString InputHandler::GetDeviceSpecificInputString( const DeviceInput &di ) return di.ToString(); } +static LocalizedString HOME ( "DeviceButton", "Home" ); +static LocalizedString END ( "DeviceButton", "End" ); +static LocalizedString UP ( "DeviceButton", "Up" ); +static LocalizedString DOWN ( "DeviceButton", "Down" ); +static LocalizedString SPACE ( "DeviceButton", "Space" ); +static LocalizedString SHIFT ( "DeviceButton", "Shift" ); +static LocalizedString CTRL ( "DeviceButton", "Ctrl" ); +static LocalizedString ALT ( "DeviceButton", "Alt" ); +static LocalizedString INSERT ( "DeviceButton", "Insert" ); +static LocalizedString DELETE ( "DeviceButton", "Delete" ); +static LocalizedString PGUP ( "DeviceButton", "PgUp" ); +static LocalizedString PGDN ( "DeviceButton", "PgDn" ); +static LocalizedString BACKSLASH ( "DeviceButton", "Backslash" ); + +RString InputHandler::GetLocalizedInputString( const DeviceInput &di ) +{ + switch( di.button ) + { + case KEY_HOME: return HOME.GetValue(); + case KEY_END: return END.GetValue(); + case KEY_UP: return UP.GetValue(); + case KEY_DOWN: return DOWN.GetValue(); + case KEY_SPACE: return SPACE.GetValue(); + case KEY_LSHIFT: case KEY_RSHIFT: return SHIFT.GetValue(); + case KEY_LCTRL: case KEY_RCTRL: return CTRL.GetValue(); + case KEY_LALT: case KEY_RALT: return ALT.GetValue(); + case KEY_INSERT: return INSERT.GetValue(); + case KEY_DEL: return DELETE.GetValue(); + case KEY_PGUP: return PGUP.GetValue(); + case KEY_PGDN: return PGDN.GetValue(); + case KEY_BACKSLASH: return BACKSLASH.GetValue(); + default: + wchar_t c = DeviceButtonToChar(di.button,false); + if( c ) + return Capitalize( WStringToRString(wstring()+c) ); + + return Capitalize( DeviceButtonToString(di.button) ); + } +} + /* * (c) 2003-2004 Glenn Maynard * All rights reserved. diff --git a/stepmania/src/arch/InputHandler/InputHandler.h b/stepmania/src/arch/InputHandler/InputHandler.h index 6a1d7f37d5..12be5c5189 100644 --- a/stepmania/src/arch/InputHandler/InputHandler.h +++ b/stepmania/src/arch/InputHandler/InputHandler.h @@ -33,6 +33,7 @@ public: // Override to return a pretty string that's specific to the controller type. virtual RString GetDeviceSpecificInputString( const DeviceInput &di ); + virtual RString GetLocalizedInputString( const DeviceInput &di ); virtual wchar_t DeviceButtonToChar( DeviceButton button, bool bUseCurrentKeyModifiers ); // Override to find out whether the controller is currently plugged in.