1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2024-11-25 09:44:02 +00:00

Fix ACTION_MENU* input to be sent as intended, broke in a7c2d054a2 iirc

This commit is contained in:
fgenesis 2021-01-12 14:24:30 +01:00
parent 37fa087c2e
commit 4990ae3bf6
8 changed files with 54 additions and 87 deletions

View file

@ -163,40 +163,6 @@ Direction AquariaGuiElement::GetDirection()
{
Direction dir = DIR_NONE;
// This joystick code is already supposed to send ACTION_MENU*.
// Actually some places depend on the actions to be sent,
// So checking this here might work for a few cases,
// but others will break.
// I'll leave this in here for now -- fg
/*Vector p;
for(size_t i = 0; i < core->getNumJoysticks(); ++i)
if(Joystick *j = core->getJoystick(i))
if(j->isEnabled())
{
p = core->getJoystick(i)->position;
if(!p.isLength2DIn(0.4f))
break;
}
if (!p.isLength2DIn(0.4f))
{
if (fabsf(p.x) > fabsf(p.y))
{
if (p.x > 0)
dir = DIR_RIGHT;
else
dir = DIR_LEFT;
}
else
{
if (p.y > 0)
dir = DIR_DOWN;
else
dir = DIR_UP;
}
}
else*/
{
StateObject *obj = dsq->getTopStateObject(); // usually Game...
if (obj)
{
@ -205,7 +171,7 @@ Direction AquariaGuiElement::GetDirection()
else if (obj->isActing(ACTION_MENUUP, -1)) dir = DIR_UP;
else if (obj->isActing(ACTION_MENUDOWN, -1)) dir = DIR_DOWN;
}
}
return dir;
}
@ -380,31 +346,13 @@ bool AquariaSlider::doSliderInput(float dt)
if (!(core->mouse.position - this->position).isLength2DIn(5))
return false;
float inputAmount; // How much to adjust by?
// disabled the jaxis threshold check;
// ACTION_MENU* should be sent automatically when above the threshold -- fg
/*Vector jpos;
for(size_t i = 0; i < core->getNumJoysticks(); ++i)
if(Joystick *j = core->getJoystick(i))
if(j->isEnabled())
{
jpos = core->getJoystick(i)->position;
if(fabsf(jpos.x) > SLIDER_JOY_THRESHOLD)
break;
}*/
float inputAmount = 0; // How much to adjust by?
StateObject *obj = dsq->getTopStateObject();
/*if (jpos.x <= -SLIDER_JOY_THRESHOLD)
inputAmount = -0.1f;
else if (jpos.x >= SLIDER_JOY_THRESHOLD)
inputAmount = +0.1f;
else*/ if (obj && obj->isActing(ACTION_MENULEFT, -1))
if (obj && obj->isActing(ACTION_MENULEFT, -1))
inputAmount = -0.1f;
else if (obj && obj->isActing(ACTION_MENURIGHT, -1))
inputAmount = +0.1f;
else
inputAmount = 0;
if (inputAmount != 0)
{

View file

@ -4500,8 +4500,7 @@ void DSQ::initActionButtons()
clearActionButtons();
std::vector<int> allkeys;
// Don't need joysticks keys for this
for(int i = 0; i < MOUSE_BUTTON_EXTRA_END; ++i)
for(int i = 0; i < INTERNALLY_USED_ACTION_BUTTONS_END; ++i)
allkeys.push_back(i);
// create sentinel

View file

@ -2527,7 +2527,7 @@ void Game::action(int id, int state, int source, InputDevice device)
if(isIgnoreAction((AquariaActions)id))
return;
// forward
// forward menu actions
if(id == ACTION_TOGGLEMENU)
{
themenu->action(id, state, source, device);
@ -2556,16 +2556,6 @@ void Game::action(int id, int state, int source, InputDevice device)
{
if (id == ACTION_TOGGLEGRID && !state) toggleGridRender();
}
// Forward these to Lua scripts (because digital swim movement should be seen as menu movement as well)
if(id == ACTION_SWIMLEFT)
action(ACTION_MENULEFT, state, source, device);
else if(id == ACTION_SWIMRIGHT)
action(ACTION_MENURIGHT, state, source, device);
else if(id == ACTION_SWIMUP)
action(ACTION_MENUUP, state, source, device);
else if(id == ACTION_SWIMDOWN)
action(ACTION_MENUDOWN, state, source, device);
}
void Game::toggleWorldMap()
@ -3251,11 +3241,6 @@ void Game::bindInput()
as.importAction(this, "SwimLeft", ACTION_SWIMLEFT, sourceID);
as.importAction(this, "SwimRight", ACTION_SWIMRIGHT, sourceID);
as.importAction(this, "MenuUp", ACTION_MENUUP, sourceID);
as.importAction(this, "MenuDown", ACTION_MENUDOWN, sourceID);
as.importAction(this, "MenuLeft", ACTION_MENULEFT, sourceID);
as.importAction(this, "MenuRight", ACTION_MENURIGHT, sourceID);
as.importAction(this, "PrevPage", ACTION_PREVPAGE, sourceID);
as.importAction(this, "NextPage", ACTION_NEXTPAGE, sourceID);
as.importAction(this, "CookFood", ACTION_COOKFOOD, sourceID);
@ -3279,6 +3264,18 @@ void Game::bindInput()
as.importAction(this, "Look", ACTION_LOOK, sourceID);
as.importAction(this, "Roll", ACTION_ROLL, sourceID);
// menu movement via ACTION_SWIM* alias
as.importAction(this, "SwimUp", ACTION_MENUUP, sourceID);
as.importAction(this, "SwimDown", ACTION_MENUDOWN, sourceID);
as.importAction(this, "SwimLeft", ACTION_MENULEFT, sourceID);
as.importAction(this, "SwimRight", ACTION_MENURIGHT, sourceID);
// menu movement via analog stick
addAction(ACTION_MENURIGHT, JOY_STICK_RIGHT, sourceID);
addAction(ACTION_MENULEFT, JOY_STICK_LEFT, sourceID);
addAction(ACTION_MENUDOWN, JOY_STICK_DOWN, sourceID);
addAction(ACTION_MENUUP, JOY_STICK_UP, sourceID);
}
if (avatar)

View file

@ -945,11 +945,6 @@ void InGameMenu::bindInput()
as.importAction(this, "FoodLeft", ACTION_FOODLEFT, sourceID);
as.importAction(this, "FoodRight", ACTION_FOODRIGHT, sourceID);
as.importAction(this, "FoodDrop", ACTION_FOODDROP, sourceID);
as.importAction(this, "MenuUp", ACTION_MENUUP, sourceID);
as.importAction(this, "MenuDown", ACTION_MENUDOWN, sourceID);
as.importAction(this, "MenuLeft", ACTION_MENULEFT, sourceID);
as.importAction(this, "MenuRight", ACTION_MENURIGHT, sourceID);
}
}

View file

@ -85,9 +85,10 @@ public:
bool getKeyState(int k, int sourceID);
ActionData *getActionDataByIDAndSource(int actionID, int source);
protected:
std::vector<Event*>createdEvents;
std::vector<Event*> createdEvents;
bool inUpdate;
bool inputEnabled;

View file

@ -160,6 +160,8 @@ void ActionSet::importAction(ActionMapper *mapper, const std::string &name, int
return;
}
}
debugLog("ActionSet::importAction: No such action: " + name);
}
void ActionSet::importAction(ActionMapper *mapper, const std::string &name, Event *event, int state) const
@ -178,6 +180,8 @@ void ActionSet::importAction(ActionMapper *mapper, const std::string &name, Even
return;
}
}
debugLog("ActionSet::importAction: No such action: " + name);
}
ActionInput *ActionSet::addActionInput(const std::string &name)

View file

@ -24,6 +24,12 @@ void ActionButtonStatus::import(const ActionSet& as)
found[inp.data.all[j]] = 1;
}
// HACK: always query these for menu input emulation
found[JOY_STICK_LEFT] = 1;
found[JOY_STICK_RIGHT] = 1;
found[JOY_STICK_UP] = 1;
found[JOY_STICK_DOWN]= 1;
toQuery.clear();
for(int k = 1; k < sizeof(found); ++k) // ignore [0]
if(found[k])
@ -97,6 +103,15 @@ bool ActionButtonStatus::_queryStatus(int k) const
if (k >= JOY_BUTTON_0 && k < JOY_BUTTON_END)
return j->getButton(k - JOY_BUTTON_0);
if(k == JOY_STICK_LEFT)
return j->position.x < -JOY_AXIS_THRESHOLD;
if(k == JOY_STICK_RIGHT)
return j->position.x > JOY_AXIS_THRESHOLD;
if(k == JOY_STICK_UP)
return j->position.y < -JOY_AXIS_THRESHOLD;
if(k == JOY_STICK_DOWN)
return j->position.y > JOY_AXIS_THRESHOLD;
if (k >= JOY_AXIS_0_POS && k < JOY_AXIS_END_POS)
{
float ax = j->getAxisUncalibrated(k - JOY_AXIS_0_POS);

View file

@ -17,7 +17,15 @@ enum ActionButtonType
MOUSE_BUTTON_EXTRA_START,
MOUSE_BUTTON_EXTRA_END = MOUSE_BUTTON_EXTRA_START + mouseExtraButtons,
JOY_BUTTON_0 = MOUSE_BUTTON_EXTRA_END,
// maps to whatever is configured as the primary joystick x/y axes
JOY_STICK_LEFT = MOUSE_BUTTON_EXTRA_END,
JOY_STICK_RIGHT,
JOY_STICK_UP,
JOY_STICK_DOWN,
INTERNALLY_USED_ACTION_BUTTONS_END, // Engine needs anything above this for handling inputs properly
JOY_BUTTON_0 = INTERNALLY_USED_ACTION_BUTTONS_END,
JOY_BUTTON_END = JOY_BUTTON_0 + MAX_JOYSTICK_BTN,
JOY_AXIS_0_POS = JOY_BUTTON_END,