From 7bbfaaa0618ce194a78c01d0ecc392dcaf6dd303 Mon Sep 17 00:00:00 2001 From: Ryan Dortmans Date: Fri, 26 Nov 2004 23:33:07 +0000 Subject: [PATCH] Translate non-keyboard input to keyboard input --- stepmania/src/PrefsManager.cpp | 6 + stepmania/src/PrefsManager.h | 3 + stepmania/src/ScreenNetworkOptions.cpp | 16 +- stepmania/src/ScreenPackages.cpp | 9 +- stepmania/src/ScreenProfileOptions.cpp | 9 +- stepmania/src/ScreenTextEntry.cpp | 37 ++--- stepmania/src/StepMania-net2003.vcproj | 6 + stepmania/src/StepMania.dsp | 8 + stepmania/src/StepMania.vcproj | 6 + stepmania/src/StepManiaXbox.vcproj | 26 +-- stepmania/src/VirtualKeyboard.cpp | 219 +++++++++++++++++++++++++ stepmania/src/VirtualKeyboard.h | 58 +++++++ 12 files changed, 347 insertions(+), 56 deletions(-) create mode 100644 stepmania/src/VirtualKeyboard.cpp create mode 100644 stepmania/src/VirtualKeyboard.h diff --git a/stepmania/src/PrefsManager.cpp b/stepmania/src/PrefsManager.cpp index 818b5424fb..cd0a2a6570 100644 --- a/stepmania/src/PrefsManager.cpp +++ b/stepmania/src/PrefsManager.cpp @@ -324,6 +324,8 @@ void PrefsManager::Init() m_sMemoryCardProfileSubdir = PRODUCT_NAME; m_iProductID = 1; + m_bEnableVirtualKeyboard = true; + #if defined(XBOX) m_bEnableVirtualMemory = true; m_iPageFileSize = 384; @@ -589,6 +591,8 @@ void PrefsManager::ReadPrefsFromFile( CString sIni ) FixSlashesInPlace(m_sAdditionalSongFolders); FixSlashesInPlace(m_sAdditionalFolders); + ini.GetValue( "Options", "EnableVirtualKeyboard", m_bEnableVirtualKeyboard ); + #if defined(XBOX) ini.GetValue( "Options", "EnableVirtualMemory", m_bEnableVirtualMemory ); ini.GetValue( "Options", "PageFileSize", m_iPageFileSize ); @@ -850,6 +854,8 @@ void PrefsManager::SaveGlobalPrefsToDisk() const ini.SetValue( "Options", "AdditionalSongFolders", m_sAdditionalSongFolders); ini.SetValue( "Options", "AdditionalFolders", m_sAdditionalFolders); + ini.SetValue( "Options", "EnableVirtualKeyboard", m_bEnableVirtualKeyboard ); + #if defined(XBOX) ini.SetValue( "Options", "EnableVirtualMemory", m_bEnableVirtualMemory ); ini.SetValue( "Options", "PageFileSize", m_iPageFileSize ); diff --git a/stepmania/src/PrefsManager.h b/stepmania/src/PrefsManager.h index 1182915c7b..891a88c833 100644 --- a/stepmania/src/PrefsManager.h +++ b/stepmania/src/PrefsManager.h @@ -278,6 +278,9 @@ public: /* Game-specific prefs: */ CString m_sDefaultModifiers; + // Virtual keyboard + bool m_bEnableVirtualKeyboard; + #if defined(XBOX) // Virtual memory preferences bool m_bEnableVirtualMemory; diff --git a/stepmania/src/ScreenNetworkOptions.cpp b/stepmania/src/ScreenNetworkOptions.cpp index b6cb511de4..f60d80d2d1 100644 --- a/stepmania/src/ScreenNetworkOptions.cpp +++ b/stepmania/src/ScreenNetworkOptions.cpp @@ -11,10 +11,7 @@ #include "ScreenTextEntry.h" #include "ScreenPrompt.h" #include "NetworkSyncServer.h" - -#if defined(XBOX) -#include "archutils/Xbox/VirtualKeyboard.h" -#endif +#include "VirtualKeyboard.h" enum { PO_CONNECTION, @@ -117,11 +114,7 @@ void ScreenNetworkOptions::MenuStart( PlayerNumber pn, const InputEventType type case PO_CONNECTION: if ( !NSMAN->useSMserver ) { - -#if defined(XBOX) - XBOX_VKB.Reset(VKMODE_IP); -#endif - + VIRTUALKB.Reset(VKMODE_IP); SCREENMAN->TextEntry( SM_DoneConnecting, "Enter a Network Address\n127.0.0.1 to connect to yourself", PREFSMAN->m_sLastServer ); } else { @@ -136,10 +129,7 @@ void ScreenNetworkOptions::MenuStart( PlayerNumber pn, const InputEventType type case NO_START_SERVER: if (!NSMAN->isLanServer) { -#if defined(XBOX) - XBOX_VKB.Reset(VKMODE_PROFILE); -#endif - + VIRTUALKB.Reset(VKMODE_PROFILE); SCREENMAN->TextEntry( SM_ServerNameEnter, "Enter a server name...", "", NULL ); } break; diff --git a/stepmania/src/ScreenPackages.cpp b/stepmania/src/ScreenPackages.cpp index 4a1dc93e6f..1c751a53d4 100644 --- a/stepmania/src/ScreenPackages.cpp +++ b/stepmania/src/ScreenPackages.cpp @@ -11,12 +11,9 @@ #include "RageFile.h" #include "ScreenTextEntry.h" #include "ScreenManager.h" +#include "VirtualKeyboard.h" #include -#if defined(XBOX) -#include "archutils/Xbox/VirtualKeyboard.h" -#endif - #define EXISTINGBG_WIDTH THEME->GetMetricF(m_sName,"PackagesBGWidth") #define WEBBG_WIDTH THEME->GetMetricF(m_sName,"WebBGWidth") #define NUM_PACKAGES_SHOW THEME->GetMetricI(m_sName,"NumPackagesShow") @@ -162,9 +159,7 @@ void ScreenPackages::MenuStart( PlayerNumber pn ) { if ( m_iLinksPos == 0 ) { -#if defined(XBOX) - XBOX_VKB.Reset(VKMODE_PROFILE); // allow all characters -#endif + VIRTUALKB.Reset(VKMODE_PROFILE); // allow all characters SCREENMAN->TextEntry( SM_BackFromURL, "Enter URL:", "http://" ); } else diff --git a/stepmania/src/ScreenProfileOptions.cpp b/stepmania/src/ScreenProfileOptions.cpp index 82c1e78653..d4a9da1193 100644 --- a/stepmania/src/ScreenProfileOptions.cpp +++ b/stepmania/src/ScreenProfileOptions.cpp @@ -8,10 +8,7 @@ #include "ScreenManager.h" #include "ScreenTextEntry.h" #include "ScreenPrompt.h" - -#if defined(XBOX) -#include "archutils/Xbox/VirtualKeyboard.h" -#endif +#include "VirtualKeyboard.h" enum { @@ -179,9 +176,7 @@ void ScreenProfileOptions::MenuStart( PlayerNumber pn, const InputEventType type { case PO_CREATE_NEW: -#if defined(XBOX) - XBOX_VKB.Reset(VKMODE_PROFILE); // set the xbox virtual keyboard to profile mode -#endif + VIRTUALKB.Reset(VKMODE_PROFILE); // set the xbox virtual keyboard to profile mode SCREENMAN->TextEntry( SM_DoneCreating, "Enter a profile name", "", NULL ); break; diff --git a/stepmania/src/ScreenTextEntry.cpp b/stepmania/src/ScreenTextEntry.cpp index a7efb4b332..06234d711b 100644 --- a/stepmania/src/ScreenTextEntry.cpp +++ b/stepmania/src/ScreenTextEntry.cpp @@ -9,10 +9,7 @@ #include "ThemeManager.h" #include "FontCharAliases.h" #include "ScreenDimensions.h" - -#if defined(XBOX) -#include "archutils/Xbox/VirtualKeyboard.h" -#endif +#include "VirtualKeyboard.h" #define QUESTION_X (SCREEN_CENTER_X) #define QUESTION_Y (SCREEN_CENTER_Y - 60) @@ -100,27 +97,29 @@ void ScreenTextEntry::Input( const DeviceInput& DeviceI, const InputEventType ty int button = DeviceI.button; -#if defined(XBOX) - bool nextChar = false; - - int toAdd = XBOX_VKB.Translate(button, m_sAnswer, &nextChar); - - if( toAdd != 0 && toAdd != KEY_BACK && toAdd != KEY_ESC && toAdd != KEY_ENTER ) + if(PREFSMAN->m_bEnableVirtualKeyboard) { - if(!nextChar) + bool nextChar = false; + + int toAdd = VIRTUALKB.Translate(DeviceI, MenuI, m_sAnswer, &nextChar); + + if( toAdd != 0 && toAdd != KEY_BACK && toAdd != KEY_ESC && toAdd != KEY_ENTER ) { - if(!m_sAnswer.empty()) - m_sAnswer = m_sAnswer.erase( m_sAnswer.size()-1 ); + if(!nextChar) + { + if(!m_sAnswer.empty()) + m_sAnswer = m_sAnswer.erase( m_sAnswer.size()-1 ); + } + + m_sAnswer += toAdd; + + UpdateText(); + return; } - m_sAnswer += toAdd; - - UpdateText(); - return; + button = toAdd; } - button = toAdd; -#endif switch( button ) { diff --git a/stepmania/src/StepMania-net2003.vcproj b/stepmania/src/StepMania-net2003.vcproj index 47e88d1604..47c27cca7d 100644 --- a/stepmania/src/StepMania-net2003.vcproj +++ b/stepmania/src/StepMania-net2003.vcproj @@ -2411,6 +2411,12 @@ cl /Zl /nologo /c verstub.cpp /Fo"$(IntDir)"\ + + + + + + + + + RelativePath="ScreenNetRoom.cpp"> + RelativePath="ScreenNetRoom.h"> @@ -525,10 +525,10 @@ cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\ RelativePath="ScreenNetSelectBase.h"> + RelativePath="ScreenNetSelectMusic.cpp"> + RelativePath="ScreenNetSelectMusic.h"> @@ -674,6 +674,12 @@ cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\ + + + + @@ -1339,12 +1345,6 @@ cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\ - - - - @@ -2416,6 +2416,12 @@ cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\ + + + + = 'a' && c <= 'z') + { + c = toupper(c); + return c; + } + else if(c >= 'A' && c <= 'Z') + { + return '0'; + } + else if(c >= '0' && c <= '9' && currentMode != VKMODE_IP) + { + return '!'; + } + else if((c >= '!' && c <= '/') || (c >= ':' && c <= '@') || + (c >= '[' && c <= '`') || (c >= '{' || c <= '~')) + { + return 'a'; + } + } + else if(button == JOY_2) // B + { + // switch to previous character type + if(cur_string.empty()) + return 0; + + int c = cur_string[cur_string.size() - 1]; + + if(c >= 'a' && c <= 'z') + { + return '!'; + } + else if(c >= 'A' && c <= 'Z') + { + return 'a'; + } + else if(c >= '0' && c <= '9' && currentMode != VKMODE_IP) + { + return 'A'; + } + else if((c >= '!' && c <= '/') || (c >= ':' && c <= '@') || + (c >= '[' && c <= '`') || (c >= '{' || c <= '~')) + { + return '0'; + } + } +#endif + return 0; + } +} + +/* + * (c) 2004 Ryan Dortmans + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons to + * whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies of + * the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF + * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS + * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT + * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ \ No newline at end of file diff --git a/stepmania/src/VirtualKeyboard.h b/stepmania/src/VirtualKeyboard.h new file mode 100644 index 0000000000..f52101d32d --- /dev/null +++ b/stepmania/src/VirtualKeyboard.h @@ -0,0 +1,58 @@ +/* Allows a user to input profile names or IP addresses without using a keyboard. + * Commands are mapped as follows: + * left - delete + * right - move cursor right (with space as default character) + * up/down - change right most character to next/previous character + */ + +#if !defined(VIRTUAL_KEYBOARD_H) +#define VIRTUAL_KEYBOARD_H + +#pragma once + +#include "RageInputDevice.h" +#include "MenuInput.h" + +enum VirtualKeyboardMode { VKMODE_PROFILE, VKMODE_IP }; + +class VirtualKeyboard +{ +public: + VirtualKeyboard(); + ~VirtualKeyboard(); + + void Reset(VirtualKeyboardMode mode); + int Translate(const DeviceInput& DeviceI, const MenuInput &MenuI, const wstring &cur_string, bool *nextChar); + +protected: + VirtualKeyboardMode currentMode; +}; + +extern VirtualKeyboard VIRTUALKB; + +#endif + +/* + * (c) 2004 Ryan Dortmans + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons to + * whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies of + * the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF + * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS + * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT + * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */