mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-07-03 06:24:32 +00:00
Preparations for multiple ActionSets support
This commit is contained in:
parent
95fd453a99
commit
2fd181913e
22 changed files with 481 additions and 304 deletions
|
@ -21,11 +21,71 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
#include "ActionSet.h"
|
||||
#include "Core.h"
|
||||
|
||||
JoystickConfig::JoystickConfig()
|
||||
{
|
||||
s1ax = 0;
|
||||
s1ay = 0;
|
||||
s2ax = 0;
|
||||
s2ay = 0;
|
||||
s1dead = 0.3f;
|
||||
s2dead = 0.3f;
|
||||
}
|
||||
|
||||
ActionSet::ActionSet()
|
||||
{
|
||||
enabled = true;
|
||||
joystickID = 0;
|
||||
}
|
||||
|
||||
void ActionSet::clearActions()
|
||||
{
|
||||
inputSet.clear();
|
||||
}
|
||||
|
||||
int ActionSet::assignJoystickByName()
|
||||
{
|
||||
int idx = _whichJoystickForName();
|
||||
if(idx >= 0)
|
||||
assignJoystickIdx(idx);
|
||||
return idx;
|
||||
}
|
||||
|
||||
void ActionSet::assignJoystickIdx(int idx)
|
||||
{
|
||||
if(idx < 0)
|
||||
{
|
||||
joystickID = -1;
|
||||
joystickName.clear();
|
||||
joystickGUID.clear();
|
||||
}
|
||||
else if(idx < (int)core->getNumJoysticks())
|
||||
{
|
||||
if(Joystick *j = core->getJoystick(idx))
|
||||
{
|
||||
joystickGUID = j->getGUID();
|
||||
joystickName = j->getName();
|
||||
joystickID = idx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int ActionSet::_whichJoystickForName()
|
||||
{
|
||||
if(joystickGUID.length())
|
||||
for(size_t i = 0; i < core->getNumJoysticks(); ++i)
|
||||
if(Joystick *j = core->getJoystick(i))
|
||||
if(j->getGUID()[0] && joystickGUID == j->getGUID())
|
||||
return int(i);
|
||||
|
||||
if(joystickName.length())
|
||||
for(size_t i = 0; i < core->getNumJoysticks(); ++i)
|
||||
if(Joystick *j = core->getJoystick(i))
|
||||
if(joystickName == j->getName())
|
||||
return int(i);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
ActionInput *ActionSet::getActionInputByName(const std::string &name)
|
||||
{
|
||||
for (ActionInputSet::iterator i = inputSet.begin(); i != inputSet.end(); i++)
|
||||
|
@ -40,37 +100,39 @@ ActionInput *ActionSet::getActionInputByName(const std::string &name)
|
|||
|
||||
|
||||
|
||||
void ActionSet::importAction(ActionMapper *mapper, const std::string &name, int actionID)
|
||||
void ActionSet::importAction(ActionMapper *mapper, const std::string &name, int actionID, int sourceID) const
|
||||
{
|
||||
if (!enabled) return;
|
||||
if (!mapper) return;
|
||||
|
||||
for (int i = 0; i < inputSet.size(); i++)
|
||||
{
|
||||
ActionInput *actionInput = &inputSet[i];
|
||||
const ActionInput *actionInput = &inputSet[i];
|
||||
if (actionInput->name == name)
|
||||
{
|
||||
for (int i = 0; i < INP_MSESIZE; i++)
|
||||
if (actionInput->mse[i])
|
||||
mapper->addAction(actionID, actionInput->mse[i]);
|
||||
mapper->addAction(actionID, actionInput->mse[i], sourceID);
|
||||
for (int i = 0; i < INP_KEYSIZE; i++)
|
||||
if (actionInput->key[i])
|
||||
mapper->addAction(actionID, actionInput->key[i]);
|
||||
mapper->addAction(actionID, actionInput->key[i], sourceID);
|
||||
for (int i = 0; i < INP_JOYSIZE; i++)
|
||||
if (actionInput->joy[i])
|
||||
mapper->addAction(actionID, actionInput->joy[i]);
|
||||
mapper->addAction(actionID, actionInput->joy[i], sourceID);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ActionSet::importAction(ActionMapper *mapper, const std::string &name, Event *event, int state)
|
||||
void ActionSet::importAction(ActionMapper *mapper, const std::string &name, Event *event, int state) const
|
||||
{
|
||||
if (!enabled) return;
|
||||
if (!mapper) return;
|
||||
|
||||
for (int i = 0; i < inputSet.size(); i++)
|
||||
{
|
||||
ActionInput *actionInput = &inputSet[i];
|
||||
const ActionInput *actionInput = &inputSet[i];
|
||||
if (actionInput->name == name)
|
||||
{
|
||||
for (int i = 0; i < INP_MSESIZE; i++)
|
||||
|
@ -91,15 +153,13 @@ void ActionSet::importAction(ActionMapper *mapper, const std::string &name, Even
|
|||
ActionInput *ActionSet::addActionInput(const std::string &name)
|
||||
{
|
||||
ActionInput *a = getActionInputByName(name);
|
||||
if (!a)
|
||||
{
|
||||
ActionInput newa;
|
||||
newa.name = name;
|
||||
inputSet.push_back(newa);
|
||||
a = getActionInputByName(name);
|
||||
}
|
||||
if(a)
|
||||
return a;
|
||||
|
||||
return a;
|
||||
ActionInput newa;
|
||||
newa.name = name;
|
||||
inputSet.push_back(newa);
|
||||
return &inputSet.back();
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue