Commit a3e14b88 authored by Gerhard Stein's avatar Gerhard Stein

Joystick Hat feature added

parent 87accd74
......@@ -108,7 +108,7 @@ void CControlsettings::release()
// Movements Parts of the Control Settings
CControlSettingsMovement::CControlSettingsMovement(const int selectedPlayer) :
CBaseMenu( CRect<float>(0.01f, (1.0f-(MAX_COMMANDS+2)*0.06f)*0.5f, 0.98f,(MAX_COMMANDS+2)*0.06f) ),
CBaseMenu( CRect<float>(0.01f, (1.0f-((MAX_COMMANDS/2.0f)+2)*0.06f)*0.5f, 0.98f,(MAX_COMMANDS/2.0f+2)*0.06f) ),
mSelectedPlayer(selectedPlayer)
{}
......@@ -154,7 +154,7 @@ void CControlSettingsMovement::release()
// Movements Parts of the Control Settings
CControlSettingsButtons::CControlSettingsButtons(const int selectedPlayer) :
CBaseMenu( CRect<float>(0.01f, (1.0f-(MAX_COMMANDS+2)*0.06f)*0.5f, 0.98f,(MAX_COMMANDS+2)*0.06f) ),
CBaseMenu( CRect<float>(0.01f, (1.0f-(MAX_COMMANDS/2.0f+2)*0.06f)*0.5f, 0.98f,(MAX_COMMANDS/2.0f+2)*0.06f) ),
mSelectedPlayer(selectedPlayer)
{}
......
......@@ -74,7 +74,6 @@ void CEndingEp1::ReturnsToShip()
if( m_timepassed<50000 && !g_pInput->getPressedAnyCommand() )
{
// perform a machine typing like dialog.
mpTextbox->processLogic();
}
else
......
......@@ -16,7 +16,8 @@
#include <vector>
#include <SDL.h>
class CEndingEp1 : public CFinale {
class CEndingEp1 : public CFinale
{
public:
CEndingEp1(const SmartPointer<CMap> &pMap, std::vector<CPlayer> &Player, bool &hideobjects, std::vector<CObject*> &Object);
void process();
......
......@@ -27,7 +27,8 @@ IniReader::IniReader(const std::string& filename, KeywordList& keywords) : m_fil
IniReader::~IniReader() {}
bool IniReader::Parse() {
bool IniReader::Parse()
{
FILE* f = OpenGameFile(m_filename, "r");
if(f == NULL)
return false;
......
......@@ -160,23 +160,24 @@ bool CInput::startJoyDriver()
}
else
{
int i=0;
size_t joynum;
joynum = SDL_NumJoysticks();
if(joynum)
const size_t joyNum = SDL_NumJoysticks();
if( joyNum > 0 )
{
g_pLogFile->ftextOut("Detected %i joystick(s).<br>\n", joynum );
SDL_JoystickEventState(SDL_ENABLE);
g_pLogFile->ftextOut("Detected %i joystick(s).<br>\n", joyNum );
g_pLogFile->textOut("The names of the joysticks are:<br>");
for( i=0; i < SDL_NumJoysticks(); i++ )
for( size_t i=0; i < joyNum; i++ )
{
g_pLogFile->ftextOut(" %s<br>", SDL_JoystickName(i));
SDL_JoystickEventState(SDL_ENABLE);
SDL_Joystick *pJoystick = SDL_JoystickOpen(i);
mp_Joysticks.push_back(pJoystick);
for(size_t c=0 ; c<joynum ; c++)
{
SDL_Joystick *p_Joystick = SDL_JoystickOpen(c);
mp_Joysticks.push_back(p_Joystick);
g_pLogFile->ftextOut(" Axes: %i<br>", SDL_JoystickNumAxes(pJoystick));
g_pLogFile->ftextOut(" Buttons: %i <br>", SDL_JoystickNumButtons(pJoystick));
g_pLogFile->ftextOut(" Balls: %i <br>", SDL_JoystickNumBalls(pJoystick));
g_pLogFile->ftextOut(" Hats: %i<br>", SDL_JoystickNumHats(pJoystick));
}
}
else
......@@ -299,6 +300,10 @@ std::string CInput::getEventName(int command, unsigned char input)
{
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);
}
else // In case only keyboard was triggered
{
//buf = "Key ";
......@@ -389,11 +394,13 @@ bool CInput::readNewEvent(Uint8 device, int command)
exit(0);
#endif
break;
case SDL_KEYDOWN:
lokalInput.joyeventtype = ETYPE_KEYBOARD;
lokalInput.keysym = Event.key.keysym.sym;
return true;
break;
case SDL_JOYBUTTONDOWN:
#if defined(CAANOO) || defined(WIZ) || defined(GP2X)
WIZ_EmuKeyboard( Event.jbutton.button, 1 );
......@@ -405,6 +412,7 @@ bool CInput::readNewEvent(Uint8 device, int command)
return true;
#endif
break;
case SDL_JOYAXISMOTION:
lokalInput.joyeventtype = ETYPE_JOYAXIS;
lokalInput.joyaxis = Event.jaxis.axis;
......@@ -412,6 +420,14 @@ bool CInput::readNewEvent(Uint8 device, int command)
lokalInput.joyvalue = (Event.jaxis.value>0) ? 32767 : -32767;
return true;
break;
case SDL_JOYHATMOTION:
lokalInput.joyeventtype = ETYPE_JOYHAT;
lokalInput.joyhatval = Event.jhat.value;
lokalInput.which = Event.jhat.which;
return true;
break;
}
}
return false;
......@@ -462,6 +478,11 @@ void CInput::pollEvents()
case SDL_JOYBUTTONUP:
processJoystickButton(0);
break;
case SDL_JOYHATMOTION:
processJoystickHat();
break;
#ifdef MOUSEWRAPPER
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
......@@ -594,6 +615,24 @@ void CInput::processJoystickAxis(void)
}
}
void CInput::processJoystickHat()
{
for(int j=0 ; j<NUM_INPUTS ; j++)
{
for(int i=0 ; i<MAX_COMMANDS ; i++)
{
// TODO: Check all NUM_INPUTS, if they can be reduced to another variable
if(InputCommand[j][i].joyeventtype == ETYPE_JOYHAT)
{
InputCommand[j][i].active = false;
// Joystick hats are configured for this event !!
if(Event.jhat.value == InputCommand[j][i].joyhatval && Event.jhat.which == InputCommand[j][i].which )
InputCommand[j][i].active = true;
}
}
}
}
/**
* \brief This will tell if any joystick button has been pressed and if they triggered a command by doing so...
*/
......
......@@ -125,7 +125,8 @@ const unsigned int KEYTABLE_SIZE = 160;
#define ETYPE_KEYBOARD 0
#define ETYPE_JOYAXIS 1
#define ETYPE_JOYBUTTON 5
#define ETYPE_JOYBUTTON 2
#define ETYPE_JOYHAT 3
typedef struct stInputCommand
{
......@@ -141,7 +142,8 @@ typedef struct stInputCommand
unsigned short joybutton;
int joyvalue; // in which direction the axis needs to be moved
int joymotion; // in which direction the axis is really moved
}stInputCommand;
int joyhatval; // in which direction the hat is really moved
} stInputCommand;
class CInput : public CSingleton<CInput>
{
......@@ -217,7 +219,8 @@ private:
bool firsttime_immediate_keytable[KEYTABLE_SIZE];
void processKeys(int value);
void processJoystickAxis(void);
void processJoystickAxis();
void processJoystickHat();
void processJoystickButton(int value);
void processMouse();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment