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.
This commit is contained in:
Glenn Maynard
2006-06-15 06:07:45 +00:00
parent 7578717a5a
commit 3c9897989c
7 changed files with 63 additions and 48 deletions
+17
View File
@@ -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<InputDeviceInfo> 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 )
+1
View File
@@ -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;
-44
View File
@@ -7,8 +7,6 @@
#include "RageInputDevice.h"
#include "RageUtil.h"
#include "EnumHelper.h"
#include "LocalizedString.h"
#include "RageInput.h"
static map<DeviceButton,RString> g_mapNamesToString;
static map<RString,DeviceButton> 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();
-2
View File
@@ -339,8 +339,6 @@ public:
bool IsJoystick() const { return ::IsJoystick(device); }
};
RString DeviceInputToLocalizedString( DeviceInput di );
#endif
/*
* Copyright (c) 2001-2002 Chris Danford
+3 -2
View File
@@ -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<EditButton> &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) );
}
}
@@ -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.
@@ -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.