mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-07-03 06:24:32 +00:00
Continue implementing support for multiple ActionSets
This commit is contained in:
parent
520239a845
commit
b438064517
12 changed files with 104 additions and 133 deletions
|
@ -720,20 +720,18 @@ void AnimationEditor::update(float dt)
|
||||||
if (core->mouse.buttons.middle)
|
if (core->mouse.buttons.middle)
|
||||||
{
|
{
|
||||||
editSprite->position += core->mouse.change;
|
editSprite->position += core->mouse.change;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (editingStrip)
|
if (editingStrip)
|
||||||
{
|
{
|
||||||
|
if (isActing(ACTION_SWIMLEFT, -1))
|
||||||
if (isActing(ACTION_SWIMLEFT))
|
|
||||||
moveBoneStripPoint(Vector(-dt, 0));
|
moveBoneStripPoint(Vector(-dt, 0));
|
||||||
if (isActing(ACTION_SWIMRIGHT))
|
if (isActing(ACTION_SWIMRIGHT, -1))
|
||||||
moveBoneStripPoint(Vector(dt, 0));
|
moveBoneStripPoint(Vector(dt, 0));
|
||||||
|
|
||||||
if (isActing(ACTION_SWIMUP))
|
if (isActing(ACTION_SWIMUP, -1))
|
||||||
moveBoneStripPoint(Vector(0, -dt));
|
moveBoneStripPoint(Vector(0, -dt));
|
||||||
if (isActing(ACTION_SWIMDOWN))
|
if (isActing(ACTION_SWIMDOWN, -1))
|
||||||
moveBoneStripPoint(Vector(0, dt));
|
moveBoneStripPoint(Vector(0, dt));
|
||||||
}
|
}
|
||||||
int spd = 1;
|
int spd = 1;
|
||||||
|
|
|
@ -151,10 +151,10 @@ void AquariaGuiElement::updateMovement(float dt)
|
||||||
StateObject *obj = dsq->getTopStateObject();
|
StateObject *obj = dsq->getTopStateObject();
|
||||||
if (obj)
|
if (obj)
|
||||||
{
|
{
|
||||||
if (obj->isActing(ACTION_MENULEFT)) dir = DIR_LEFT;
|
if (obj->isActing(ACTION_MENULEFT, -1)) dir = DIR_LEFT;
|
||||||
else if (obj->isActing(ACTION_MENURIGHT)) dir = DIR_RIGHT;
|
else if (obj->isActing(ACTION_MENURIGHT, -1)) dir = DIR_RIGHT;
|
||||||
else if (obj->isActing(ACTION_MENUUP)) dir = DIR_UP;
|
else if (obj->isActing(ACTION_MENUUP, -1)) dir = DIR_UP;
|
||||||
else if (obj->isActing(ACTION_MENUDOWN)) dir = DIR_DOWN;
|
else if (obj->isActing(ACTION_MENUDOWN, -1)) dir = DIR_DOWN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -373,9 +373,9 @@ bool AquariaSlider::doSliderInput(float dt)
|
||||||
inputAmount = -0.1f;
|
inputAmount = -0.1f;
|
||||||
else if (jpos.x >= SLIDER_JOY_THRESHOLD)
|
else if (jpos.x >= SLIDER_JOY_THRESHOLD)
|
||||||
inputAmount = +0.1f;
|
inputAmount = +0.1f;
|
||||||
else if (obj && obj->isActing(ACTION_MENULEFT))
|
else if (obj && obj->isActing(ACTION_MENULEFT, -1))
|
||||||
inputAmount = -0.1f;
|
inputAmount = -0.1f;
|
||||||
else if (obj && obj->isActing(ACTION_MENURIGHT))
|
else if (obj && obj->isActing(ACTION_MENURIGHT, -1))
|
||||||
inputAmount = +0.1f;
|
inputAmount = +0.1f;
|
||||||
else
|
else
|
||||||
inputAmount = 0;
|
inputAmount = 0;
|
||||||
|
|
|
@ -4055,7 +4055,7 @@ void Avatar::startBurst()
|
||||||
{
|
{
|
||||||
if (!riding && canBurst() && (joystickMove || getVectorToCursor().getSquaredLength2D() > sqr(BURST_DISTANCE))
|
if (!riding && canBurst() && (joystickMove || getVectorToCursor().getSquaredLength2D() > sqr(BURST_DISTANCE))
|
||||||
&& getState() != STATE_PUSH && (!skeletalSprite.getCurrentAnimation() || (skeletalSprite.getCurrentAnimation()->name != "spin"))
|
&& getState() != STATE_PUSH && (!skeletalSprite.getCurrentAnimation() || (skeletalSprite.getCurrentAnimation()->name != "spin"))
|
||||||
&& _isUnderWater && !isActing(ACTION_ROLL))
|
&& _isUnderWater && !isActing(ACTION_ROLL, -1))
|
||||||
{
|
{
|
||||||
if (!bursting && burst == 1)
|
if (!bursting && burst == 1)
|
||||||
{
|
{
|
||||||
|
@ -4171,13 +4171,13 @@ void Avatar::startWallBurst(bool useCursor)
|
||||||
Vector Avatar::getKeyDir()
|
Vector Avatar::getKeyDir()
|
||||||
{
|
{
|
||||||
Vector dir;
|
Vector dir;
|
||||||
if (isActing(ACTION_SWIMLEFT))
|
if (isActing(ACTION_SWIMLEFT, -1))
|
||||||
dir += Vector(-1,0);
|
dir += Vector(-1,0);
|
||||||
if (isActing(ACTION_SWIMRIGHT))
|
if (isActing(ACTION_SWIMRIGHT, -1))
|
||||||
dir += Vector(1,0);
|
dir += Vector(1,0);
|
||||||
if (isActing(ACTION_SWIMUP))
|
if (isActing(ACTION_SWIMUP, -1))
|
||||||
dir += Vector(0,-1);
|
dir += Vector(0,-1);
|
||||||
if (isActing(ACTION_SWIMDOWN))
|
if (isActing(ACTION_SWIMDOWN, -1))
|
||||||
dir += Vector(0,1);
|
dir += Vector(0,1);
|
||||||
|
|
||||||
if (dir.x != 0 && dir.y != 0)
|
if (dir.x != 0 && dir.y != 0)
|
||||||
|
@ -4975,13 +4975,13 @@ void Avatar::updateRoll(float dt)
|
||||||
stopRoll();
|
stopRoll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const bool rollact = isActing(ACTION_ROLL, -1);
|
||||||
if (!_isUnderWater && isActing(ACTION_ROLL))
|
if (!_isUnderWater && rollact)
|
||||||
{
|
{
|
||||||
stopRoll();
|
stopRoll();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!core->mouse.buttons.left && dsq->inputMode == INPUT_MOUSE && !isActing(ACTION_ROLL))
|
if (!core->mouse.buttons.left && dsq->inputMode == INPUT_MOUSE && !rollact)
|
||||||
{
|
{
|
||||||
if (rolling)
|
if (rolling)
|
||||||
stopRoll();
|
stopRoll();
|
||||||
|
@ -5022,7 +5022,7 @@ void Avatar::updateRoll(float dt)
|
||||||
stopRoll();
|
stopRoll();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isActing(ACTION_ROLL))
|
if (rollact)
|
||||||
{
|
{
|
||||||
if (_isUnderWater)
|
if (_isUnderWater)
|
||||||
{
|
{
|
||||||
|
@ -5373,7 +5373,7 @@ void Avatar::onUpdate(float dt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dsq->game->isPaused() && isActing(ACTION_LOOK) && !dsq->game->avatar->isSinging() && dsq->game->avatar->isInputEnabled() && !dsq->game->isInGameMenu())
|
if (!dsq->game->isPaused() && isActing(ACTION_LOOK, -1) && !dsq->game->avatar->isSinging() && dsq->game->avatar->isInputEnabled() && !dsq->game->isInGameMenu())
|
||||||
{
|
{
|
||||||
looking = 1;
|
looking = 1;
|
||||||
}
|
}
|
||||||
|
@ -6109,7 +6109,7 @@ void Avatar::onUpdate(float dt)
|
||||||
|
|
||||||
float len = 0;
|
float len = 0;
|
||||||
|
|
||||||
if (dsq->isMiniMapCursorOkay() && !isActing(ACTION_ROLL) &&
|
if (dsq->isMiniMapCursorOkay() && !isActing(ACTION_ROLL, -1) &&
|
||||||
_isUnderWater && !riding && !boneLock.on &&
|
_isUnderWater && !riding && !boneLock.on &&
|
||||||
(movingOn || ((dsq->inputMode == INPUT_JOYSTICK || dsq->inputMode== INPUT_KEYBOARD) || (core->mouse.buttons.left || bursting))))
|
(movingOn || ((dsq->inputMode == INPUT_JOYSTICK || dsq->inputMode== INPUT_KEYBOARD) || (core->mouse.buttons.left || bursting))))
|
||||||
{
|
{
|
||||||
|
@ -6120,7 +6120,7 @@ void Avatar::onUpdate(float dt)
|
||||||
if (dsq->inputMode == INPUT_MOUSE)
|
if (dsq->inputMode == INPUT_MOUSE)
|
||||||
{
|
{
|
||||||
static Vector lastAddVec;
|
static Vector lastAddVec;
|
||||||
if (!isActing(ACTION_PRIMARY) && bursting)
|
if (!isActing(ACTION_PRIMARY, -1) && bursting)
|
||||||
{
|
{
|
||||||
addVec = lastAddVec;
|
addVec = lastAddVec;
|
||||||
}
|
}
|
||||||
|
@ -6162,7 +6162,7 @@ void Avatar::onUpdate(float dt)
|
||||||
// For joystick/keyboard control, don't stop unless
|
// For joystick/keyboard control, don't stop unless
|
||||||
// the Swim (primary action) button is pressed with
|
// the Swim (primary action) button is pressed with
|
||||||
// no movement input. --achurch
|
// no movement input. --achurch
|
||||||
if ((dsq->inputMode == INPUT_MOUSE || isActing(ACTION_PRIMARY))
|
if ((dsq->inputMode == INPUT_MOUSE || isActing(ACTION_PRIMARY, -1))
|
||||||
&& addVec.isLength2DIn(STOP_DISTANCE))
|
&& addVec.isLength2DIn(STOP_DISTANCE))
|
||||||
{
|
{
|
||||||
vel *= 0.9f;
|
vel *= 0.9f;
|
||||||
|
@ -6221,7 +6221,7 @@ void Avatar::onUpdate(float dt)
|
||||||
currentMaxSpeed = vars->maxWallJumpSpeed;
|
currentMaxSpeed = vars->maxWallJumpSpeed;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (isActing(ACTION_SLOW) || isMovingSlow)
|
if (isMovingSlow)
|
||||||
{
|
{
|
||||||
currentMaxSpeed = vars->maxSlowSwimSpeed;
|
currentMaxSpeed = vars->maxSlowSwimSpeed;
|
||||||
}
|
}
|
||||||
|
@ -6250,7 +6250,7 @@ void Avatar::onUpdate(float dt)
|
||||||
// here for roll key?
|
// here for roll key?
|
||||||
// seems like this isn't reached
|
// seems like this isn't reached
|
||||||
//if (isActing("roll"))
|
//if (isActing("roll"))
|
||||||
if (isActing(ACTION_ROLL))
|
if (isActing(ACTION_ROLL, -1))
|
||||||
{
|
{
|
||||||
//debugLog("here");
|
//debugLog("here");
|
||||||
}
|
}
|
||||||
|
|
|
@ -3834,7 +3834,7 @@ void DSQ::onUpdate(float dt)
|
||||||
|
|
||||||
if (dsq->game && watchForQuit && isNested())
|
if (dsq->game && watchForQuit && isNested())
|
||||||
{
|
{
|
||||||
if (dsq->game->isActing(ACTION_ESC))
|
if (dsq->game->isActing(ACTION_ESC, -1))
|
||||||
{
|
{
|
||||||
watchQuitFlag = true;
|
watchQuitFlag = true;
|
||||||
quitNestedMain();
|
quitNestedMain();
|
||||||
|
@ -3921,10 +3921,10 @@ void DSQ::onUpdate(float dt)
|
||||||
}
|
}
|
||||||
if (dsq->game->avatar)
|
if (dsq->game->avatar)
|
||||||
{
|
{
|
||||||
if (dsq->game->avatar->isActing(ACTION_SWIMUP) ||
|
if (dsq->game->avatar->isActing(ACTION_SWIMUP, -1) ||
|
||||||
dsq->game->avatar->isActing(ACTION_SWIMDOWN) ||
|
dsq->game->avatar->isActing(ACTION_SWIMDOWN, -1) ||
|
||||||
dsq->game->avatar->isActing(ACTION_SWIMLEFT) ||
|
dsq->game->avatar->isActing(ACTION_SWIMLEFT, -1) ||
|
||||||
dsq->game->avatar->isActing(ACTION_SWIMRIGHT))
|
dsq->game->avatar->isActing(ACTION_SWIMRIGHT, -1))
|
||||||
{
|
{
|
||||||
dsq->setInputMode(INPUT_KEYBOARD);
|
dsq->setInputMode(INPUT_KEYBOARD);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4520,7 +4520,7 @@ void Game::update(float dt)
|
||||||
if (inHelpScreen)
|
if (inHelpScreen)
|
||||||
{
|
{
|
||||||
const float helpTextScrollSpeed = 400.0f;
|
const float helpTextScrollSpeed = 400.0f;
|
||||||
if (isActing(ACTION_SWIMDOWN))
|
if (isActing(ACTION_SWIMDOWN, -1))
|
||||||
{
|
{
|
||||||
helpText->offset.stop();
|
helpText->offset.stop();
|
||||||
helpText->offset.y -= helpTextScrollSpeed * dt;
|
helpText->offset.y -= helpTextScrollSpeed * dt;
|
||||||
|
@ -4529,7 +4529,7 @@ void Game::update(float dt)
|
||||||
helpText->offset.y = -helpText->getHeight() + core->getVirtualHeight();
|
helpText->offset.y = -helpText->getHeight() + core->getVirtualHeight();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isActing(ACTION_SWIMUP))
|
if (isActing(ACTION_SWIMUP, -1))
|
||||||
{
|
{
|
||||||
helpText->offset.stop();
|
helpText->offset.stop();
|
||||||
helpText->offset.y += helpTextScrollSpeed * dt;
|
helpText->offset.y += helpTextScrollSpeed * dt;
|
||||||
|
|
|
@ -2786,11 +2786,11 @@ void SceneEditor::update(float dt)
|
||||||
{
|
{
|
||||||
case ET_ELEMENTS:
|
case ET_ELEMENTS:
|
||||||
editingEntity = 0;
|
editingEntity = 0;
|
||||||
if (isActing(ACTION_MULTISELECT) || !selectedElements.empty())
|
if (isActing(ACTION_MULTISELECT, -1) || !selectedElements.empty())
|
||||||
{
|
{
|
||||||
editingElement = 0;
|
editingElement = 0;
|
||||||
}
|
}
|
||||||
if (state == ES_SELECTING && !isActing(ACTION_MULTISELECT))
|
if (state == ES_SELECTING && !isActing(ACTION_MULTISELECT, -1))
|
||||||
editingElement = this->getElementAtCursor();
|
editingElement = this->getElementAtCursor();
|
||||||
|
|
||||||
if (editingElement)
|
if (editingElement)
|
||||||
|
@ -2819,13 +2819,13 @@ void SceneEditor::update(float dt)
|
||||||
int camSpeed = 500/zoom.x;
|
int camSpeed = 500/zoom.x;
|
||||||
if (core->getShiftState())
|
if (core->getShiftState())
|
||||||
camSpeed = 5000/zoom.x;
|
camSpeed = 5000/zoom.x;
|
||||||
if (isActing(ACTION_CAMLEFT))
|
if (isActing(ACTION_CAMLEFT, -1))
|
||||||
dsq->cameraPos.x -= dt*camSpeed;
|
dsq->cameraPos.x -= dt*camSpeed;
|
||||||
if (isActing(ACTION_CAMRIGHT))
|
if (isActing(ACTION_CAMRIGHT, -1))
|
||||||
dsq->cameraPos.x += dt*camSpeed;
|
dsq->cameraPos.x += dt*camSpeed;
|
||||||
if (isActing(ACTION_CAMUP))
|
if (isActing(ACTION_CAMUP, -1))
|
||||||
dsq->cameraPos.y -= dt*camSpeed;
|
dsq->cameraPos.y -= dt*camSpeed;
|
||||||
if (isActing(ACTION_CAMDOWN))
|
if (isActing(ACTION_CAMDOWN, -1))
|
||||||
dsq->cameraPos.y += dt*camSpeed;
|
dsq->cameraPos.y += dt*camSpeed;
|
||||||
if (core->mouse.buttons.middle && !core->mouse.change.isZero())
|
if (core->mouse.buttons.middle && !core->mouse.change.isZero())
|
||||||
{
|
{
|
||||||
|
@ -2835,9 +2835,9 @@ void SceneEditor::update(float dt)
|
||||||
|
|
||||||
float spd = 0.5;
|
float spd = 0.5;
|
||||||
const Vector oldZoom = zoom;
|
const Vector oldZoom = zoom;
|
||||||
if (isActing(ACTION_ZOOMOUT))
|
if (isActing(ACTION_ZOOMOUT, -1))
|
||||||
zoom /= (1 + spd*dt);
|
zoom /= (1 + spd*dt);
|
||||||
else if (isActing(ACTION_ZOOMIN))
|
else if (isActing(ACTION_ZOOMIN, -1))
|
||||||
zoom *= (1 + spd*dt);
|
zoom *= (1 + spd*dt);
|
||||||
else if (core->mouse.scrollWheelChange < 0)
|
else if (core->mouse.scrollWheelChange < 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -4962,19 +4962,24 @@ luaFunc(screenFadeGo)
|
||||||
|
|
||||||
luaFunc(isEscapeKey)
|
luaFunc(isEscapeKey)
|
||||||
{
|
{
|
||||||
bool isDown = dsq->game->isActing(ACTION_ESC);
|
int source = lua_tointeger(L, 1) - 1;
|
||||||
|
bool isDown = dsq->game->isActing(ACTION_ESC, source);
|
||||||
luaReturnBool(isDown);
|
luaReturnBool(isDown);
|
||||||
}
|
}
|
||||||
|
|
||||||
luaFunc(isLeftMouse)
|
luaFunc(isLeftMouse)
|
||||||
{
|
{
|
||||||
bool isDown = core->mouse.buttons.left || (dsq->game->avatar && dsq->game->avatar->pollAction(ACTION_PRIMARY));
|
int source = lua_tointeger(L, 1) - 1;
|
||||||
|
bool isDown = (source < 0 && core->mouse.buttons.left)
|
||||||
|
|| (dsq->game->avatar && dsq->game->avatar->pollAction(ACTION_PRIMARY, source));
|
||||||
luaReturnBool(isDown);
|
luaReturnBool(isDown);
|
||||||
}
|
}
|
||||||
|
|
||||||
luaFunc(isRightMouse)
|
luaFunc(isRightMouse)
|
||||||
{
|
{
|
||||||
bool isDown = core->mouse.buttons.right || (dsq->game->avatar && dsq->game->avatar->pollAction(ACTION_SECONDARY));
|
int source = lua_tointeger(L, 1) - 1;
|
||||||
|
bool isDown = (source < 0 && core->mouse.buttons.right)
|
||||||
|
|| (dsq->game->avatar && dsq->game->avatar->pollAction(ACTION_SECONDARY, source));
|
||||||
luaReturnBool(isDown);
|
luaReturnBool(isDown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -992,15 +992,15 @@ void WorldMapRender::onUpdate(float dt)
|
||||||
{
|
{
|
||||||
float scrollSpeed = 2.0f;
|
float scrollSpeed = 2.0f;
|
||||||
float amt = (400*dt)/scale.x;
|
float amt = (400*dt)/scale.x;
|
||||||
if (isActing(ACTION_SWIMLEFT))
|
if (isActing(ACTION_SWIMLEFT, -1))
|
||||||
{
|
{
|
||||||
internalOffset += Vector(amt, 0);
|
internalOffset += Vector(amt, 0);
|
||||||
}
|
}
|
||||||
if (isActing(ACTION_SWIMRIGHT))
|
if (isActing(ACTION_SWIMRIGHT, -1))
|
||||||
{
|
{
|
||||||
internalOffset += Vector(-amt, 0);
|
internalOffset += Vector(-amt, 0);
|
||||||
}
|
}
|
||||||
if (isActing(ACTION_SWIMDOWN))
|
if (isActing(ACTION_SWIMDOWN, -1))
|
||||||
{
|
{
|
||||||
if (core->getShiftState())
|
if (core->getShiftState())
|
||||||
{
|
{
|
||||||
|
@ -1012,7 +1012,7 @@ void WorldMapRender::onUpdate(float dt)
|
||||||
internalOffset += Vector(0, -amt);
|
internalOffset += Vector(0, -amt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isActing(ACTION_SWIMUP))
|
if (isActing(ACTION_SWIMUP, -1))
|
||||||
{
|
{
|
||||||
if (core->getShiftState())
|
if (core->getShiftState())
|
||||||
{
|
{
|
||||||
|
@ -1027,7 +1027,7 @@ void WorldMapRender::onUpdate(float dt)
|
||||||
|
|
||||||
if (core->joystickEnabled)
|
if (core->joystickEnabled)
|
||||||
{
|
{
|
||||||
if (isActing(ACTION_SECONDARY))
|
if (isActing(ACTION_SECONDARY, -1))
|
||||||
{
|
{
|
||||||
Vector jpos;
|
Vector jpos;
|
||||||
for(size_t i = 0; i < core->getNumJoysticks(); ++i)
|
for(size_t i = 0; i < core->getNumJoysticks(); ++i)
|
||||||
|
|
|
@ -31,19 +31,32 @@ ActionMapper::~ActionMapper()
|
||||||
clearCreatedEvents();
|
clearCreatedEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
ActionData *ActionMapper::getActionDataByID(int actionID)
|
ActionData *ActionMapper::getActionDataByIDAndSource(int actionID, int source)
|
||||||
{
|
{
|
||||||
for (ActionDataSet::iterator i = actionData.begin(); i != actionData.end(); i++)
|
for (ActionDataSet::iterator i = actionData.begin(); i != actionData.end(); ++i)
|
||||||
{
|
{
|
||||||
if ((*i).id == actionID)
|
if (i->id == actionID && i->source == source)
|
||||||
return &(*i);
|
return &(*i);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ActionMapper::isActing(int actionID)
|
bool ActionMapper::isActing(int actionID, int source)
|
||||||
{
|
{
|
||||||
ActionData *ad = getActionDataByID(actionID);
|
if(source < 0)
|
||||||
|
{
|
||||||
|
for (ActionDataSet::iterator i = actionData.begin(); i != actionData.end(); ++i)
|
||||||
|
{
|
||||||
|
ActionData& ad = *i;
|
||||||
|
if(ad.id == actionID)
|
||||||
|
for (ButtonList::iterator ii = ad.buttonList.begin(); ii != ad.buttonList.end(); ++ii)
|
||||||
|
if (keyDownMap[*ii])
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ActionData *ad = getActionDataByIDAndSource(actionID, source);
|
||||||
if (ad)
|
if (ad)
|
||||||
{
|
{
|
||||||
ButtonList::iterator i = ad->buttonList.begin();
|
ButtonList::iterator i = ad->buttonList.begin();
|
||||||
|
@ -58,21 +71,15 @@ bool ActionMapper::isActing(int actionID)
|
||||||
|
|
||||||
void ActionMapper::addAction(int actionID, int k, int source)
|
void ActionMapper::addAction(int actionID, int k, int source)
|
||||||
{
|
{
|
||||||
ActionData *ad = getActionDataByID(actionID);
|
ActionData *ad = getActionDataByIDAndSource(actionID, source);
|
||||||
|
|
||||||
if (!ad)
|
if (!ad)
|
||||||
{
|
{
|
||||||
ActionData data;
|
ActionData data;
|
||||||
data.id = actionID;
|
data.id = actionID;
|
||||||
|
data.source = source;
|
||||||
actionData.push_back(data);
|
actionData.push_back(data);
|
||||||
ad = getActionDataByID(actionID);
|
ad = &actionData.back();
|
||||||
if (!ad)
|
|
||||||
{
|
|
||||||
std::ostringstream os;
|
|
||||||
os << "Could not create action for Action ID [" << actionID << "]";
|
|
||||||
errorLog(os.str());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ad)
|
if (ad)
|
||||||
|
@ -83,8 +90,6 @@ void ActionMapper::addAction(int actionID, int k, int source)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ActionMapper::addAction(Event *event, int k, int state)
|
void ActionMapper::addAction(Event *event, int k, int state)
|
||||||
{
|
{
|
||||||
ActionData data;
|
ActionData data;
|
||||||
|
@ -116,8 +121,6 @@ void ActionMapper::clearCreatedEvents()
|
||||||
createdEvents.clear();
|
createdEvents.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ActionMapper::enableInput()
|
void ActionMapper::enableInput()
|
||||||
{
|
{
|
||||||
inputEnabled = true;
|
inputEnabled = true;
|
||||||
|
@ -128,52 +131,27 @@ void ActionMapper::disableInput()
|
||||||
inputEnabled = false;
|
inputEnabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActionMapper::removeAction(int actionID)
|
bool ActionMapper::pollAction(int actionID, int source)
|
||||||
{
|
{
|
||||||
ActionData *ad = getActionDataByID(actionID);
|
if(source < 0)
|
||||||
if (ad)
|
|
||||||
{
|
{
|
||||||
ButtonList::iterator i = ad->buttonList.begin();
|
for (ActionDataSet::iterator i = actionData.begin(); i != actionData.end(); i++)
|
||||||
for (; i != ad->buttonList.end(); i++)
|
if(i->id == actionID && _pollActionData(*i))
|
||||||
{
|
return true;
|
||||||
int k = (*i);
|
return false;
|
||||||
cleared = true; // it's a hack, but it works
|
|
||||||
keyDownMap.erase(k);
|
|
||||||
}
|
|
||||||
for (ActionDataSet::iterator i = actionData.begin(); i != actionData.end();)
|
|
||||||
{
|
|
||||||
if (i->id == actionID)
|
|
||||||
i = actionData.erase(i);
|
|
||||||
else
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ActionData *ad = getActionDataByIDAndSource(actionID, source);
|
||||||
|
return ad && _pollActionData(*ad);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ActionMapper::_pollActionData(const ActionData& ad)
|
||||||
|
|
||||||
bool ActionMapper::pollAction(int actionID)
|
|
||||||
{
|
{
|
||||||
bool down = false;
|
const ButtonList& blist = ad.buttonList;
|
||||||
|
for (ButtonList::const_iterator j = blist.begin(); j != blist.end(); j++)
|
||||||
ActionData *ad = getActionDataByID(actionID);
|
if (getKeyState((*j)))
|
||||||
if (ad)
|
return true;
|
||||||
{
|
return false;
|
||||||
ButtonList *blist = &ad->buttonList;
|
|
||||||
ButtonList::iterator j;
|
|
||||||
j = blist->begin();
|
|
||||||
|
|
||||||
for (; j != blist->end(); j++)
|
|
||||||
{
|
|
||||||
if (getKeyState((*j)))
|
|
||||||
{
|
|
||||||
down = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return down;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ActionMapper::getKeyState(int k)
|
bool ActionMapper::getKeyState(int k)
|
||||||
|
@ -296,18 +274,3 @@ void ActionMapper::clearActions()
|
||||||
keyDownMap.clear();
|
keyDownMap.clear();
|
||||||
actionData.clear();
|
actionData.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActionMapper::removeAllActions()
|
|
||||||
{
|
|
||||||
std::vector <int> deleteList;
|
|
||||||
ActionDataSet::iterator i;
|
|
||||||
for (i = actionData.begin(); i != actionData.end(); i++)
|
|
||||||
{
|
|
||||||
deleteList.push_back(i->id);
|
|
||||||
}
|
|
||||||
for (int c = 0; c < deleteList.size(); c++)
|
|
||||||
{
|
|
||||||
removeAction (deleteList[c]);
|
|
||||||
}
|
|
||||||
actionData.clear();
|
|
||||||
}
|
|
||||||
|
|
|
@ -35,9 +35,9 @@ typedef std::vector<int> ButtonList;
|
||||||
|
|
||||||
struct ActionData
|
struct ActionData
|
||||||
{
|
{
|
||||||
ActionData() { id=-1; state=-1; event=0; }
|
ActionData() { id=-1; state=-1; source = -1; event=0; }
|
||||||
|
|
||||||
int id, state;
|
int id, state, source;
|
||||||
Event *event;
|
Event *event;
|
||||||
ButtonList buttonList;
|
ButtonList buttonList;
|
||||||
};
|
};
|
||||||
|
@ -70,10 +70,7 @@ public:
|
||||||
void addAction(Event *event, int k, int state=-1);
|
void addAction(Event *event, int k, int state=-1);
|
||||||
void addAction(int actionID, int k, int source);
|
void addAction(int actionID, int k, int source);
|
||||||
|
|
||||||
void removeAction(int actionID);
|
bool isActing(int actionID, int source);
|
||||||
void removeAllActions();
|
|
||||||
|
|
||||||
bool isActing(int actionID);
|
|
||||||
virtual void action(int actionID, int state, int source) = 0;
|
virtual void action(int actionID, int state, int source) = 0;
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,7 +80,7 @@ public:
|
||||||
|
|
||||||
// vars
|
// vars
|
||||||
|
|
||||||
typedef std::list<ActionData> ActionDataSet;
|
typedef std::vector<ActionData> ActionDataSet;
|
||||||
ActionDataSet actionData;
|
ActionDataSet actionData;
|
||||||
|
|
||||||
typedef std::map <int, int> KeyDownMap;
|
typedef std::map <int, int> KeyDownMap;
|
||||||
|
@ -97,10 +94,10 @@ public:
|
||||||
Event *addCreatedEvent(Event *event);
|
Event *addCreatedEvent(Event *event);
|
||||||
void clearCreatedEvents();
|
void clearCreatedEvents();
|
||||||
|
|
||||||
bool pollAction(int actionID);
|
bool pollAction(int actionID, int source);
|
||||||
bool getKeyState(int k);
|
bool getKeyState(int k);
|
||||||
|
|
||||||
ActionData *getActionDataByID(int actionID);
|
ActionData *getActionDataByIDAndSource(int actionID, int source);
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
std::vector<Event*>createdEvents;
|
std::vector<Event*>createdEvents;
|
||||||
|
@ -108,6 +105,8 @@ protected:
|
||||||
bool inUpdate;
|
bool inUpdate;
|
||||||
bool inputEnabled;
|
bool inputEnabled;
|
||||||
void onUpdate (float dt);
|
void onUpdate (float dt);
|
||||||
|
private:
|
||||||
|
bool _pollActionData(const ActionData& ad);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -71,6 +71,12 @@ void ActionSet::assignJoystickIdx(int idx)
|
||||||
|
|
||||||
int ActionSet::_whichJoystickForName()
|
int ActionSet::_whichJoystickForName()
|
||||||
{
|
{
|
||||||
|
if(joystickGUID.length() && joystickName.length())
|
||||||
|
for(size_t i = 0; i < core->getNumJoysticks(); ++i)
|
||||||
|
if(Joystick *j = core->getJoystick(i))
|
||||||
|
if(j->getGUID()[0] && joystickGUID == j->getGUID() && joystickName == j->getName())
|
||||||
|
return int(i);
|
||||||
|
|
||||||
if(joystickGUID.length())
|
if(joystickGUID.length())
|
||||||
for(size_t i = 0; i < core->getNumJoysticks(); ++i)
|
for(size_t i = 0; i < core->getNumJoysticks(); ++i)
|
||||||
if(Joystick *j = core->getJoystick(i))
|
if(Joystick *j = core->getJoystick(i))
|
||||||
|
|
|
@ -103,8 +103,8 @@ bool Joystick::init(int stick)
|
||||||
name = n ? n : "<?>";
|
name = n ? n : "<?>";
|
||||||
SDL_JoystickGUID jg = SDL_JoystickGetGUID(sdl_joy);
|
SDL_JoystickGUID jg = SDL_JoystickGetGUID(sdl_joy);
|
||||||
char guidbuf[40];
|
char guidbuf[40];
|
||||||
guid = &guidbuf[0];
|
|
||||||
SDL_JoystickGetGUIDString(jg, &guidbuf[0], sizeof(guidbuf));
|
SDL_JoystickGetGUIDString(jg, &guidbuf[0], sizeof(guidbuf));
|
||||||
|
guid = &guidbuf[0];
|
||||||
debugLog(std::string("Initialized Joystick [") + name + "], GUID [" + guid + "]");
|
debugLog(std::string("Initialized Joystick [") + name + "], GUID [" + guid + "]");
|
||||||
if (sdl_controller)
|
if (sdl_controller)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue