Skip to content

Commit

Permalink
Input assignment bugs solved
Browse files Browse the repository at this point in the history
  • Loading branch information
gerstrong committed Dec 1, 2012
1 parent efcb69e commit b531e42
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 22 deletions.
11 changes: 7 additions & 4 deletions src/common/Menu/CControlsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ mSelectedPlayer(selectedPlayer)
mpMenuDialog->addControl( mpSuperPogoSwitch );
mpMenuDialog->addControl( mpImpPogoSwitch );
mpMenuDialog->addControl( mpAutoGunSwitch );
mpMenuDialog->addControl( new CGUIButton( "Reset Controls",
new ResetInputEvent(mSelectedPlayer-1) ) );
mpMenuDialog->addControl( new CGUIButton( "Reset Controls", new ResetInputEvent(mSelectedPlayer-1) ) );

}

Expand Down Expand Up @@ -150,7 +149,7 @@ void CControlSettingsMovement::init()
for ( ; it != mCommandName.end(); it++ )
{
const std::string buf = it->second;
const std::string buf2 = g_pInput->getEventName( it->first, mSelectedPlayer-1 );
const std::string buf2 = g_pInput->getEventShortName( it->first, mSelectedPlayer-1 );

ReadInputEvent *rie = new ReadInputEvent(mSelectedPlayer, it->first, it->second);
CGUIButton *guiButton = new CGUIButton( buf+buf2, rie );
Expand Down Expand Up @@ -194,6 +193,8 @@ void CControlSettingsMovement::release()
{
if(!mCommandName.empty())
mCommandName.clear();

g_pInput->saveControlconfig();
}


Expand Down Expand Up @@ -223,7 +224,7 @@ void CControlSettingsButtons::init()
for ( ; it != mCommandName.end(); it++ )
{
const std::string buf = it->second;
const std::string buf2 = g_pInput->getEventName( it->first, mSelectedPlayer-1 );
const std::string buf2 = g_pInput->getEventShortName( it->first, mSelectedPlayer-1 );

ReadInputEvent *rie = new ReadInputEvent(mSelectedPlayer, it->first, it->second);
CGUIButton *guiButton = new CGUIButton( buf+buf2, rie );
Expand Down Expand Up @@ -270,5 +271,7 @@ void CControlSettingsButtons::release()
{
if(!mCommandName.empty())
mCommandName.clear();

g_pInput->saveControlconfig();
}

56 changes: 40 additions & 16 deletions src/sdl/input/CInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,39 +284,63 @@ std::string CInput::getNewMappedEvent(int &rPos, unsigned char &rInp)
{
rPos = remapper.mapPosition;
rInp = remapper.mapDevice;
return getEventName(remapper.mapPosition, remapper.mapDevice);
return getEventShortName(remapper.mapPosition, remapper.mapDevice);
}

/**
* \brief This checks what event has been assigned to the chosen command and builds a string calling it
* a standardized way.
* \param command command where you are looking for the event
* \param input number of input chosen. it's normal the number of the player
* \return returns the assigned event as a std::string
*/

std::string CInput::getEventShortName(int command, unsigned char input)
{
std::string buf;
if(InputCommand[input][command].joyeventtype == ETYPE_JOYAXIS)
{
buf = "J" + itoa(InputCommand[input][command].which) + "A" + itoa(InputCommand[input][command].joyaxis);
if(InputCommand[input][command].joyvalue < 0)
buf += "-";
else
buf += "+";
}
else if(InputCommand[input][command].joyeventtype == ETYPE_JOYBUTTON)
{
buf = "J" + itoa(InputCommand[input][command].which) + "B" + itoa(InputCommand[input][command].joybutton);
}
else if(InputCommand[input][command].joyeventtype == ETYPE_JOYHAT)
{
buf = "J" + itoa(InputCommand[input][command].which) + "H" + itoa(InputCommand[input][command].joyhatval);
}
else // In case only keyboard was triggered
{
buf = SDL_GetKeyName(InputCommand[input][command].keysym);
}

return buf;
}

std::string CInput::getEventName(int command, unsigned char input)
{
std::string buf;
if(InputCommand[input][command].joyeventtype == ETYPE_JOYAXIS)
{
buf = "Joy" + itoa(InputCommand[input][command].which) + "-A" + itoa(InputCommand[input][command].joyaxis);
if(InputCommand[input][command].joyvalue < 0)
buf += "-";
else
buf += "+";
buf = "Joy" + itoa(InputCommand[input][command].which) + "-A" + itoa(InputCommand[input][command].joyaxis);
if(InputCommand[input][command].joyvalue < 0)
buf += "-";
else
buf += "+";
}
else if(InputCommand[input][command].joyeventtype == ETYPE_JOYBUTTON)
{
buf = "Joy" + itoa(InputCommand[input][command].which) + "-B" + itoa(InputCommand[input][command].joybutton);
buf = "Joy" + itoa(InputCommand[input][command].which) + "-B" + itoa(InputCommand[input][command].joybutton);
}
else if(InputCommand[input][command].joyeventtype == ETYPE_JOYHAT)
{
buf = "Joy" + itoa(InputCommand[input][command].which) + "-H" + itoa(InputCommand[input][command].joyhatval);
buf = "Joy" + itoa(InputCommand[input][command].which) + "-H" + itoa(InputCommand[input][command].joyhatval);
}
else // In case only keyboard was triggered
{
buf = SDL_GetKeyName(InputCommand[input][command].keysym);
buf = "Key ";
buf += itoa(InputCommand[input][command].keysym);
buf += " (";
buf += SDL_GetKeyName(InputCommand[input][command].keysym);
buf += ")";
}

return buf;
Expand Down
13 changes: 11 additions & 2 deletions src/sdl/input/CInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,17 @@ class CInput : public CSingleton<CInput>
void setAutoGun(const int player, const bool value) { mFullyAutomatic[player] = value; }



std::string getEventName(int position, unsigned char input);
/**
* \brief This checks what event has been assigned to the chosen command and builds a string calling it
* a standardized way.
* \param command command where you are looking for the event
* \param input number of input chosen. it's normal the number of the player
* \return returns the assigned event as a std::string
* \note getEventShortName is the short name version for menu prints
*/
std::string getEventName(int command, unsigned char input);
std::string getEventShortName(int command, unsigned char input);

std::string getNewMappedEvent(int &rPos, unsigned char &rInp);
void readNewEvent();

Expand Down

0 comments on commit b531e42

Please sign in to comment.