Allow keyboard input using Xbox pad
This commit is contained in:
@@ -12,6 +12,10 @@
|
||||
#include "ScreenPrompt.h"
|
||||
#include "NetworkSyncServer.h"
|
||||
|
||||
#if defined(XBOX)
|
||||
#include "archutils/Xbox/VirtualKeyboard.h"
|
||||
#endif
|
||||
|
||||
enum {
|
||||
PO_CONNECTION,
|
||||
PO_SERVER,
|
||||
@@ -111,7 +115,14 @@ void ScreenNetworkOptions::MenuStart( PlayerNumber pn, const InputEventType type
|
||||
{
|
||||
case PO_CONNECTION:
|
||||
if ( !NSMAN->useSMserver )
|
||||
{
|
||||
|
||||
#if defined(XBOX)
|
||||
XBOX_VKB.Reset(VKMODE_IP);
|
||||
#endif
|
||||
|
||||
SCREENMAN->TextEntry( SM_DoneConnecting, "Enter a Network Address\n127.0.0.1 to connect to yourself", PREFSMAN->m_sLastServer );
|
||||
}
|
||||
else {
|
||||
NSMAN->CloseConnection();
|
||||
SCREENMAN->SystemMessage("Disconnected from server.");
|
||||
@@ -123,6 +134,10 @@ void ScreenNetworkOptions::MenuStart( PlayerNumber pn, const InputEventType type
|
||||
{
|
||||
case NO_START_SERVER:
|
||||
if (!NSMAN->isLanServer)
|
||||
#if defined(XBOX)
|
||||
XBOX_VKB.Reset(VKMODE_PROFILE);
|
||||
#endif
|
||||
|
||||
SCREENMAN->TextEntry( SM_ServerNameEnter, "Enter a server name...", "", NULL );
|
||||
break;
|
||||
case NO_STOP_SERVER:
|
||||
|
||||
@@ -9,6 +9,10 @@
|
||||
#include "ScreenTextEntry.h"
|
||||
#include "ScreenPrompt.h"
|
||||
|
||||
#if defined(XBOX)
|
||||
#include "archutils/Xbox/VirtualKeyboard.h"
|
||||
#endif
|
||||
|
||||
|
||||
enum {
|
||||
PO_PLAYER1,
|
||||
@@ -173,6 +177,11 @@ void ScreenProfileOptions::MenuStart( PlayerNumber pn, const InputEventType type
|
||||
switch( GetCurrentRow() )
|
||||
{
|
||||
case PO_CREATE_NEW:
|
||||
|
||||
#if defined(XBOX)
|
||||
XBOX_VKB.Reset(VKMODE_PROFILE); // set the xbox virtual keyboard to profile mode
|
||||
#endif
|
||||
|
||||
SCREENMAN->TextEntry( SM_DoneCreating, "Enter a profile name", "", NULL );
|
||||
break;
|
||||
case PO_DELETE_:
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
#include "FontCharAliases.h"
|
||||
#include "ScreenDimensions.h"
|
||||
|
||||
#if defined(XBOX)
|
||||
#include "archutils/Xbox/VirtualKeyboard.h"
|
||||
#endif
|
||||
|
||||
#define QUESTION_X (CENTER_X)
|
||||
#define QUESTION_Y (CENTER_Y - 60)
|
||||
|
||||
@@ -93,7 +97,31 @@ void ScreenTextEntry::Input( const DeviceInput& DeviceI, const InputEventType ty
|
||||
if( type != IET_FIRST_PRESS )
|
||||
return;
|
||||
|
||||
switch( DeviceI.button )
|
||||
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(!nextChar)
|
||||
{
|
||||
if(!m_sAnswer.empty())
|
||||
m_sAnswer = m_sAnswer.erase( m_sAnswer.size()-1 );
|
||||
}
|
||||
|
||||
m_sAnswer += toAdd;
|
||||
|
||||
UpdateText();
|
||||
return;
|
||||
}
|
||||
|
||||
button = toAdd;
|
||||
#endif
|
||||
|
||||
switch( button )
|
||||
{
|
||||
case KEY_ESC:
|
||||
m_bCancelled = true;
|
||||
@@ -110,6 +138,7 @@ void ScreenTextEntry::Input( const DeviceInput& DeviceI, const InputEventType ty
|
||||
break;
|
||||
default:
|
||||
char c;
|
||||
|
||||
c = DeviceI.ToChar();
|
||||
|
||||
bool bHoldingShift =
|
||||
|
||||
@@ -1315,6 +1315,12 @@ cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\
|
||||
<File
|
||||
RelativePath="archutils\Xbox\GraphicsWindow.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\archutils\Xbox\VirtualKeyboard.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\archutils\Xbox\VirtualKeyboard.h">
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
|
||||
@@ -0,0 +1,365 @@
|
||||
#include "global.h"
|
||||
#include "VirtualKeyboard.h"
|
||||
#include "RageInputDevice.h"
|
||||
|
||||
VirtualKeyboard XBOX_VKB;
|
||||
|
||||
VirtualKeyboard::VirtualKeyboard()
|
||||
{
|
||||
currentMode = VKMODE_PROFILE;
|
||||
currentType = VKTYPE_LOWER;
|
||||
}
|
||||
|
||||
VirtualKeyboard::~VirtualKeyboard()
|
||||
{
|
||||
}
|
||||
|
||||
void VirtualKeyboard::Reset(VirtualKeyboardMode mode)
|
||||
{
|
||||
currentMode = mode;
|
||||
if(currentMode == VKMODE_PROFILE)
|
||||
currentType = VKTYPE_LOWER;
|
||||
else if(currentMode == VKMODE_IP)
|
||||
currentType = VKTYPE_NUMBER;
|
||||
}
|
||||
|
||||
int VirtualKeyboard::Translate(int button, const wstring &cur_string, bool *nextChar)
|
||||
{
|
||||
*nextChar = false;
|
||||
|
||||
if(button == JOY_HAT_LEFT)
|
||||
return KEY_BACK;
|
||||
else if(button == JOY_HAT_RIGHT)
|
||||
{
|
||||
*nextChar = true;
|
||||
if(currentType == VKTYPE_LOWER || currentType == VKTYPE_UPPER)
|
||||
return ' ';
|
||||
else if(currentType == VKTYPE_NUMBER)
|
||||
return '0';
|
||||
else if(currentType == VKTYPE_SYMBOL)
|
||||
return '!';
|
||||
|
||||
return 0;
|
||||
}
|
||||
else if(button == JOY_HAT_UP)
|
||||
{
|
||||
if(currentType == VKTYPE_LOWER)
|
||||
{
|
||||
if(cur_string.empty())
|
||||
{
|
||||
*nextChar = true;
|
||||
return 'a';
|
||||
}
|
||||
else
|
||||
{
|
||||
int c = cur_string[cur_string.size() - 1];
|
||||
|
||||
if(c == ' ')
|
||||
c = 'a';
|
||||
else if(c == 'z')
|
||||
c = ' ';
|
||||
else
|
||||
c++;
|
||||
|
||||
return c;
|
||||
}
|
||||
}
|
||||
else if(currentType == VKTYPE_UPPER)
|
||||
{
|
||||
if(cur_string.empty())
|
||||
{
|
||||
*nextChar = true;
|
||||
return 'A';
|
||||
}
|
||||
else
|
||||
{
|
||||
int c = cur_string[cur_string.size() - 1];
|
||||
|
||||
if(c == ' ')
|
||||
c = 'A';
|
||||
else if(c == 'Z')
|
||||
c = ' ';
|
||||
else
|
||||
c++;
|
||||
|
||||
return c;
|
||||
}
|
||||
}
|
||||
else if(currentType == VKTYPE_NUMBER)
|
||||
{
|
||||
if(cur_string.empty())
|
||||
{
|
||||
*nextChar = true;
|
||||
return '0';
|
||||
}
|
||||
else
|
||||
{
|
||||
int c = cur_string[cur_string.size() - 1];
|
||||
if(c == '9' || c == '.')
|
||||
c = '0';
|
||||
else
|
||||
c++;
|
||||
|
||||
return c;
|
||||
}
|
||||
}
|
||||
else if(currentType == VKTYPE_SYMBOL)
|
||||
{
|
||||
if(cur_string.empty())
|
||||
{
|
||||
*nextChar = true;
|
||||
return '!';
|
||||
}
|
||||
else
|
||||
{
|
||||
int c = cur_string[cur_string.size() - 1];
|
||||
|
||||
if(c == '/')
|
||||
c = ':';
|
||||
else if(c == '@')
|
||||
c = '[';
|
||||
else if(c == '`')
|
||||
c = '{';
|
||||
else if(c == '~')
|
||||
c = '!';
|
||||
else
|
||||
c++;
|
||||
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
else if(button == JOY_HAT_DOWN)
|
||||
{
|
||||
if(currentType == VKTYPE_LOWER)
|
||||
{
|
||||
if(cur_string.empty())
|
||||
{
|
||||
*nextChar = true;
|
||||
return 'z';
|
||||
}
|
||||
else
|
||||
{
|
||||
int c = cur_string[cur_string.size() - 1];
|
||||
|
||||
if(c == ' ')
|
||||
c = 'z';
|
||||
else if(c == 'a')
|
||||
c = ' ';
|
||||
else
|
||||
c--;
|
||||
|
||||
return c;
|
||||
}
|
||||
}
|
||||
else if(currentType == VKTYPE_UPPER)
|
||||
{
|
||||
if(cur_string.empty())
|
||||
{
|
||||
*nextChar = true;
|
||||
return 'Z';
|
||||
}
|
||||
else
|
||||
{
|
||||
int c = cur_string[cur_string.size() - 1];
|
||||
|
||||
if(c == ' ')
|
||||
c = 'Z';
|
||||
else if(c == 'A')
|
||||
c = ' ';
|
||||
else
|
||||
c--;
|
||||
|
||||
return c;
|
||||
}
|
||||
}
|
||||
else if(currentType == VKTYPE_NUMBER)
|
||||
{
|
||||
if(cur_string.empty())
|
||||
{
|
||||
*nextChar = true;
|
||||
return '9';
|
||||
}
|
||||
else
|
||||
{
|
||||
int c = cur_string[cur_string.size() - 1];
|
||||
|
||||
if(c == '0' || c == '.')
|
||||
c = '9';
|
||||
else
|
||||
c--;
|
||||
|
||||
return c;
|
||||
}
|
||||
}
|
||||
else if(currentType == VKTYPE_SYMBOL)
|
||||
{
|
||||
if(cur_string.empty())
|
||||
{
|
||||
*nextChar = true;
|
||||
return '~';
|
||||
}
|
||||
else
|
||||
{
|
||||
int c = cur_string[cur_string.size() - 1];
|
||||
|
||||
if(c == ':')
|
||||
c = '/';
|
||||
else if(c == '[')
|
||||
c = '@';
|
||||
else if(c == '{')
|
||||
c = '`';
|
||||
else if(c == '!')
|
||||
c = '~';
|
||||
else
|
||||
c--;
|
||||
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
else if(button == JOY_AUX_1)
|
||||
return KEY_ENTER;
|
||||
else if(button == JOY_AUX_2)
|
||||
return KEY_ESC;
|
||||
else if(button == JOY_1) // A
|
||||
{
|
||||
if(currentMode != VKMODE_IP && (currentType == VKTYPE_LOWER || currentType == VKTYPE_UPPER))
|
||||
{
|
||||
if(cur_string.empty())
|
||||
*nextChar = true;
|
||||
|
||||
return ' ';
|
||||
}
|
||||
else if(currentMode == VKMODE_IP)
|
||||
{
|
||||
if(!cur_string.empty())
|
||||
return '.';
|
||||
}
|
||||
}
|
||||
else if(button == JOY_4) // Y
|
||||
{
|
||||
if(currentType == VKTYPE_LOWER)
|
||||
{
|
||||
currentType = VKTYPE_UPPER;
|
||||
|
||||
if(cur_string.empty())
|
||||
{
|
||||
*nextChar = true;
|
||||
return 'A';
|
||||
}
|
||||
else
|
||||
{
|
||||
int c = cur_string[cur_string.size() - 1];
|
||||
|
||||
c = toupper(c);
|
||||
return c;
|
||||
}
|
||||
}
|
||||
else if(currentType == VKTYPE_UPPER)
|
||||
{
|
||||
currentType = VKTYPE_NUMBER;
|
||||
|
||||
if(cur_string.empty())
|
||||
*nextChar = true;
|
||||
|
||||
return '0';
|
||||
}
|
||||
else if(currentType == VKTYPE_NUMBER && currentMode != VKMODE_IP)
|
||||
{
|
||||
currentType = VKTYPE_SYMBOL;
|
||||
|
||||
if(cur_string.empty())
|
||||
*nextChar = true;
|
||||
|
||||
return '!';
|
||||
}
|
||||
else if(currentType == VKTYPE_SYMBOL)
|
||||
{
|
||||
currentType = VKTYPE_LOWER;
|
||||
|
||||
if(cur_string.empty())
|
||||
*nextChar = true;
|
||||
|
||||
return 'a';
|
||||
}
|
||||
}
|
||||
else if(button == JOY_2) // B
|
||||
{
|
||||
if(currentType == VKTYPE_UPPER)
|
||||
{
|
||||
currentType = VKTYPE_LOWER;
|
||||
|
||||
if(cur_string.empty())
|
||||
{
|
||||
*nextChar = true;
|
||||
return 'a';
|
||||
}
|
||||
else
|
||||
{
|
||||
int c = cur_string[cur_string.size() - 1];
|
||||
|
||||
c = tolower(c);
|
||||
return c;
|
||||
}
|
||||
}
|
||||
else if(currentType == VKTYPE_SYMBOL)
|
||||
{
|
||||
currentType = VKTYPE_NUMBER;
|
||||
|
||||
if(cur_string.empty())
|
||||
*nextChar = true;
|
||||
|
||||
return '0';
|
||||
}
|
||||
else if(currentType == VKTYPE_LOWER)
|
||||
{
|
||||
currentType = VKTYPE_SYMBOL;
|
||||
|
||||
if(cur_string.empty())
|
||||
*nextChar = true;
|
||||
|
||||
return '!';
|
||||
}
|
||||
else if(currentType == VKTYPE_NUMBER && currentMode != VKMODE_IP)
|
||||
{
|
||||
currentType = VKTYPE_UPPER;
|
||||
|
||||
if(cur_string.empty())
|
||||
*nextChar = true;
|
||||
|
||||
return 'A';
|
||||
}
|
||||
}
|
||||
|
||||
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.
|
||||
*/
|
||||
@@ -0,0 +1,59 @@
|
||||
/* Allows an Xbox user to input profile names or IP addresses using a keypad
|
||||
* Commands are mapped as follows:
|
||||
* D-PAD left - delete
|
||||
* D-PAD right - move cursor right (with space as default character)
|
||||
* D-PAD up/down - next/previous character
|
||||
* Y - change characters to lower-case/upper-case/numbers/symbols
|
||||
* A - make current character a space
|
||||
*/
|
||||
|
||||
#if !defined(VIRTUAL_KEYBOARD_H)
|
||||
#define VIRTUAL_KEYBOARD_H
|
||||
|
||||
#pragma once
|
||||
|
||||
enum VirtualKeyboardMode { VKMODE_PROFILE, VKMODE_IP };
|
||||
enum VirtualKeyboardType { VKTYPE_LOWER, VKTYPE_UPPER, VKTYPE_NUMBER, VKTYPE_SYMBOL };
|
||||
|
||||
class VirtualKeyboard
|
||||
{
|
||||
public:
|
||||
VirtualKeyboard();
|
||||
~VirtualKeyboard();
|
||||
|
||||
void Reset(VirtualKeyboardMode mode);
|
||||
int Translate(int button, const wstring &cur_string, bool *nextChar);
|
||||
|
||||
protected:
|
||||
VirtualKeyboardMode currentMode;
|
||||
VirtualKeyboardType currentType;
|
||||
};
|
||||
|
||||
extern VirtualKeyboard XBOX_VKB;
|
||||
|
||||
#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.
|
||||
*/
|
||||
Reference in New Issue
Block a user