Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualBaneTrapper

Posted 05 November 2012 - 12:36 PM

Hello.
Currently i am trying to find a easy way to make a input name in SFML 2.0

What i am trying to do is something like this
std::string Name;
case sf::Event::KeyPressed: //When key is pressed
			    Name.push_back(EventList.key.code); //Push back the key code
		    break;

The problem in this is that the EventList.key.code is SFML enum that is not "ascii" i think.
So what do i do?

This is the code i am using to add to namestring when a key is pressed, and it works flawlessly
But i want something more efficient!
//objApp.objHeroCreator.NameString is a std::string
case sf::Event::KeyPressed:
switch(EventList.key.code)
			    {
				    case sf::Keyboard::Num1:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('!');
					    else
						    objApp.objHeroCreator.NameString.push_back('1');
					    break;
				    case sf::Keyboard::Num2:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('@');
					    else
						    objApp.objHeroCreator.NameString.push_back('2');
					    break;
				    case sf::Keyboard::Num3:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('#');
					    else
						    objApp.objHeroCreator.NameString.push_back('3');
					    break;
				    case sf::Keyboard::Num4:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('$');
					    else
						    objApp.objHeroCreator.NameString.push_back('4');
					    break;
				    case sf::Keyboard::Num5:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('%');
					    else
						    objApp.objHeroCreator.NameString.push_back('5');
					    break;
				    case sf::Keyboard::Num6:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('^');
					    else
						    objApp.objHeroCreator.NameString.push_back('6');
					    break;
				    case sf::Keyboard::Num7:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('&');
					    else
						    objApp.objHeroCreator.NameString.push_back('7');
					    break;
				    case sf::Keyboard::Num8:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('*');
					    else
						    objApp.objHeroCreator.NameString.push_back('8');
					    break;
				    case sf::Keyboard::Num9:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('(');
					    else
						    objApp.objHeroCreator.NameString.push_back('9');
					    break;
				    case sf::Keyboard::Num0:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back(')');
					    else
						    objApp.objHeroCreator.NameString.push_back('0');
					    break;
				    case sf::Keyboard::Return:
					    sf::Mouse::setPosition(sf::Vector2i(objApp.Screen.getPosition().x + SCREEN_WIDTH /2,
														    objApp.Screen.getPosition().y + SCREEN_HEIGHT /2));
					    break;
				    case sf::Keyboard::Delete:
					    if(objApp.objHeroCreator.NameString.size() > 0)
					    {
						    objApp.objHeroCreator.NameString.erase(objApp.objHeroCreator.NameString.size() - 1);
					    }
					    break;
				    case sf::Keyboard::Back:
					    if(objApp.objHeroCreator.NameString.size() > 0)
					    {
						    objApp.objHeroCreator.NameString.erase(objApp.objHeroCreator.NameString.size() - 1);
					    }
					    break;
				    case sf::Keyboard::Space:
					    if(objApp.objHeroCreator.NameString.size() > 0)
						    objApp.objHeroCreator.NameString.push_back(' ');
					    break;
				    case sf::Keyboard::Q:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('Q');
					    else
						    objApp.objHeroCreator.NameString.push_back('q');
					    break;
				    case sf::Keyboard::W:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('W');
					    else
						    objApp.objHeroCreator.NameString.push_back('w');
					    break;
				    case sf::Keyboard::E:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('E');
					    else
						    objApp.objHeroCreator.NameString.push_back('e');
					    break;
				    case sf::Keyboard::R:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('R');
					    else
						    objApp.objHeroCreator.NameString.push_back('r');
					    break;
				    case sf::Keyboard::T:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('T');
					    else
						    objApp.objHeroCreator.NameString.push_back('t');
					    break;
				    case sf::Keyboard::Y:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('Y');
					    else
						    objApp.objHeroCreator.NameString.push_back('y');
					    break;
				    case sf::Keyboard::U:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('U');
					    else
						    objApp.objHeroCreator.NameString.push_back('u');
					    break;
				    case sf::Keyboard::I:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('I');
					    else
						    objApp.objHeroCreator.NameString.push_back('i');
					    break;
				    case sf::Keyboard:<img src='http://public.gamedev.net//public/style_emoticons/default/ohmy.png' class='bbc_emoticon' alt=':o' />:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('O');
					    else
						    objApp.objHeroCreator.NameString.push_back('o');
					    break;
				    case sf::Keyboard:<img src='http://public.gamedev.net//public/style_emoticons/default/tongue.png' class='bbc_emoticon' alt=':P' />:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('P');
					    else
						    objApp.objHeroCreator.NameString.push_back('p');
					    break;
				    case sf::Keyboard::A:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('A');
					    else
						    objApp.objHeroCreator.NameString.push_back('a');
					    break;
				    case sf::Keyboard::S:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('S');
					    else
						    objApp.objHeroCreator.NameString.push_back('s');
					    break;
				    case sf::Keyboard:<img src='http://public.gamedev.net//public/style_emoticons/default/biggrin.png' class='bbc_emoticon' alt=':D' />:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('D');
					    else
						    objApp.objHeroCreator.NameString.push_back('d');
					    break;
				    case sf::Keyboard::F:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('F');
					    else
						    objApp.objHeroCreator.NameString.push_back('f');
					    break;
				    case sf::Keyboard::G:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('G');
					    else
						    objApp.objHeroCreator.NameString.push_back('g');
					    break;
				    case sf::Keyboard::H:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('H');
					    else
						    objApp.objHeroCreator.NameString.push_back('h');
					    break;
				    case sf::Keyboard::J:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('J');
					    else
						    objApp.objHeroCreator.NameString.push_back('j');
					    break;
				    case sf::Keyboard::K:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('K');
					    else
						    objApp.objHeroCreator.NameString.push_back('k');
					    break;
				    case sf::Keyboard::L:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('L');
					    else
						    objApp.objHeroCreator.NameString.push_back('l');
					    break;
				    case sf::Keyboard::Z:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('Z');
					    else
						    objApp.objHeroCreator.NameString.push_back('z');
					    break;
				    case sf::Keyboard::X:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('X');
					    else
						    objApp.objHeroCreator.NameString.push_back('x');
					    break;
				    case sf::Keyboard::C:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('C');
					    else
						    objApp.objHeroCreator.NameString.push_back('c');
					    break;
				    case sf::Keyboard::V:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('V');
					    else
						    objApp.objHeroCreator.NameString.push_back('V');
					    break;
				    case sf::Keyboard::B:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('B');
					    else
						    objApp.objHeroCreator.NameString.push_back('B');
					    break;
				    case sf::Keyboard::N:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('N');
					    else
						    objApp.objHeroCreator.NameString.push_back('n');
					    break;
				    case sf::Keyboard::M:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('M');
					    else
						    objApp.objHeroCreator.NameString.push_back('m');
					    break;
				    default:
					    break;
			    }

#1BaneTrapper

Posted 05 November 2012 - 12:35 PM

Hello.
Currently i am trying to find a easy way to make a input name in SFML 2.0

What i am trying to do is something like this
std::string Name;
case sf::Event::KeyPressed: //When key is pressed
			    Name.push_back(EventList.key.code); //Push back the key code
		    break;

The problem in this is that the EventList.key.code is SFML enum that is not "ascii" i think.
So what do i do?

This is the code i am using to add to namestring when a key is pressed, and it works flawlessly
//objApp.objHeroCreator.NameString is a std::string
case sf::Event::KeyPressed:
switch(EventList.key.code)
			    {
				    case sf::Keyboard::Num1:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('!');
					    else
						    objApp.objHeroCreator.NameString.push_back('1');
					    break;
				    case sf::Keyboard::Num2:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('@');
					    else
						    objApp.objHeroCreator.NameString.push_back('2');
					    break;
				    case sf::Keyboard::Num3:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('#');
					    else
						    objApp.objHeroCreator.NameString.push_back('3');
					    break;
				    case sf::Keyboard::Num4:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('$');
					    else
						    objApp.objHeroCreator.NameString.push_back('4');
					    break;
				    case sf::Keyboard::Num5:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('%');
					    else
						    objApp.objHeroCreator.NameString.push_back('5');
					    break;
				    case sf::Keyboard::Num6:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('^');
					    else
						    objApp.objHeroCreator.NameString.push_back('6');
					    break;
				    case sf::Keyboard::Num7:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('&');
					    else
						    objApp.objHeroCreator.NameString.push_back('7');
					    break;
				    case sf::Keyboard::Num8:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('*');
					    else
						    objApp.objHeroCreator.NameString.push_back('8');
					    break;
				    case sf::Keyboard::Num9:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('(');
					    else
						    objApp.objHeroCreator.NameString.push_back('9');
					    break;
				    case sf::Keyboard::Num0:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back(')');
					    else
						    objApp.objHeroCreator.NameString.push_back('0');
					    break;
				    case sf::Keyboard::Return:
					    sf::Mouse::setPosition(sf::Vector2i(objApp.Screen.getPosition().x + SCREEN_WIDTH /2,
														    objApp.Screen.getPosition().y + SCREEN_HEIGHT /2));
					    break;
				    case sf::Keyboard::Delete:
					    if(objApp.objHeroCreator.NameString.size() > 0)
					    {
						    objApp.objHeroCreator.NameString.erase(objApp.objHeroCreator.NameString.size() - 1);
					    }
					    break;
				    case sf::Keyboard::Back:
					    if(objApp.objHeroCreator.NameString.size() > 0)
					    {
						    objApp.objHeroCreator.NameString.erase(objApp.objHeroCreator.NameString.size() - 1);
					    }
					    break;
				    case sf::Keyboard::Space:
					    if(objApp.objHeroCreator.NameString.size() > 0)
						    objApp.objHeroCreator.NameString.push_back(' ');
					    break;
				    case sf::Keyboard::Q:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('Q');
					    else
						    objApp.objHeroCreator.NameString.push_back('q');
					    break;
				    case sf::Keyboard::W:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('W');
					    else
						    objApp.objHeroCreator.NameString.push_back('w');
					    break;
				    case sf::Keyboard::E:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('E');
					    else
						    objApp.objHeroCreator.NameString.push_back('e');
					    break;
				    case sf::Keyboard::R:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('R');
					    else
						    objApp.objHeroCreator.NameString.push_back('r');
					    break;
				    case sf::Keyboard::T:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('T');
					    else
						    objApp.objHeroCreator.NameString.push_back('t');
					    break;
				    case sf::Keyboard::Y:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('Y');
					    else
						    objApp.objHeroCreator.NameString.push_back('y');
					    break;
				    case sf::Keyboard::U:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('U');
					    else
						    objApp.objHeroCreator.NameString.push_back('u');
					    break;
				    case sf::Keyboard::I:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('I');
					    else
						    objApp.objHeroCreator.NameString.push_back('i');
					    break;
				    case sf::Keyboard:<img src='http://public.gamedev.net//public/style_emoticons/default/ohmy.png' class='bbc_emoticon' alt=':o' />:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('O');
					    else
						    objApp.objHeroCreator.NameString.push_back('o');
					    break;
				    case sf::Keyboard:<img src='http://public.gamedev.net//public/style_emoticons/default/tongue.png' class='bbc_emoticon' alt=':P' />:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('P');
					    else
						    objApp.objHeroCreator.NameString.push_back('p');
					    break;
				    case sf::Keyboard::A:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('A');
					    else
						    objApp.objHeroCreator.NameString.push_back('a');
					    break;
				    case sf::Keyboard::S:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('S');
					    else
						    objApp.objHeroCreator.NameString.push_back('s');
					    break;
				    case sf::Keyboard:<img src='http://public.gamedev.net//public/style_emoticons/default/biggrin.png' class='bbc_emoticon' alt=':D' />:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('D');
					    else
						    objApp.objHeroCreator.NameString.push_back('d');
					    break;
				    case sf::Keyboard::F:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('F');
					    else
						    objApp.objHeroCreator.NameString.push_back('f');
					    break;
				    case sf::Keyboard::G:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('G');
					    else
						    objApp.objHeroCreator.NameString.push_back('g');
					    break;
				    case sf::Keyboard::H:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('H');
					    else
						    objApp.objHeroCreator.NameString.push_back('h');
					    break;
				    case sf::Keyboard::J:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('J');
					    else
						    objApp.objHeroCreator.NameString.push_back('j');
					    break;
				    case sf::Keyboard::K:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('K');
					    else
						    objApp.objHeroCreator.NameString.push_back('k');
					    break;
				    case sf::Keyboard::L:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('L');
					    else
						    objApp.objHeroCreator.NameString.push_back('l');
					    break;
				    case sf::Keyboard::Z:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('Z');
					    else
						    objApp.objHeroCreator.NameString.push_back('z');
					    break;
				    case sf::Keyboard::X:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('X');
					    else
						    objApp.objHeroCreator.NameString.push_back('x');
					    break;
				    case sf::Keyboard::C:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('C');
					    else
						    objApp.objHeroCreator.NameString.push_back('c');
					    break;
				    case sf::Keyboard::V:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('V');
					    else
						    objApp.objHeroCreator.NameString.push_back('V');
					    break;
				    case sf::Keyboard::B:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('B');
					    else
						    objApp.objHeroCreator.NameString.push_back('B');
					    break;
				    case sf::Keyboard::N:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('N');
					    else
						    objApp.objHeroCreator.NameString.push_back('n');
					    break;
				    case sf::Keyboard::M:
					    if(Shift)
						    objApp.objHeroCreator.NameString.push_back('M');
					    else
						    objApp.objHeroCreator.NameString.push_back('m');
					    break;
				    default:
					    break;
			    }

PARTNERS