diff --git a/Aquaria/AquariaMenuItem.cpp b/Aquaria/AquariaMenuItem.cpp index f80619c..cc6a770 100644 --- a/Aquaria/AquariaMenuItem.cpp +++ b/Aquaria/AquariaMenuItem.cpp @@ -163,49 +163,15 @@ 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; - } + StateObject *obj = dsq->getTopStateObject(); // usually Game... + if (obj) + { + if (obj->isActing(ACTION_MENULEFT, -1)) dir = DIR_LEFT; + else if (obj->isActing(ACTION_MENURIGHT, -1)) dir = DIR_RIGHT; + else if (obj->isActing(ACTION_MENUUP, -1)) dir = DIR_UP; + else if (obj->isActing(ACTION_MENUDOWN, -1)) dir = DIR_DOWN; + } - 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) - { - if (obj->isActing(ACTION_MENULEFT, -1)) dir = DIR_LEFT; - else if (obj->isActing(ACTION_MENURIGHT, -1)) dir = DIR_RIGHT; - 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) { diff --git a/Aquaria/DSQ.cpp b/Aquaria/DSQ.cpp index ace7e23..7014eaf 100644 --- a/Aquaria/DSQ.cpp +++ b/Aquaria/DSQ.cpp @@ -4500,8 +4500,7 @@ void DSQ::initActionButtons() clearActionButtons(); std::vector 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 diff --git a/Aquaria/Game.cpp b/Aquaria/Game.cpp index 89ab07c..953c504 100644 --- a/Aquaria/Game.cpp +++ b/Aquaria/Game.cpp @@ -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) diff --git a/Aquaria/InGameMenu.cpp b/Aquaria/InGameMenu.cpp index 104ca59..63fc65a 100644 --- a/Aquaria/InGameMenu.cpp +++ b/Aquaria/InGameMenu.cpp @@ -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); } } diff --git a/BBGE/ActionMapper.h b/BBGE/ActionMapper.h index 246d32f..f771db9 100644 --- a/BBGE/ActionMapper.h +++ b/BBGE/ActionMapper.h @@ -85,9 +85,10 @@ public: bool getKeyState(int k, int sourceID); ActionData *getActionDataByIDAndSource(int actionID, int source); + protected: - std::vectorcreatedEvents; + std::vector createdEvents; bool inUpdate; bool inputEnabled; diff --git a/BBGE/ActionSet.cpp b/BBGE/ActionSet.cpp index 2d3a053..27f6a5d 100644 --- a/BBGE/ActionSet.cpp +++ b/BBGE/ActionSet.cpp @@ -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) diff --git a/BBGE/ActionStatus.cpp b/BBGE/ActionStatus.cpp index ec23836..df2ffec 100644 --- a/BBGE/ActionStatus.cpp +++ b/BBGE/ActionStatus.cpp @@ -23,6 +23,12 @@ void ActionButtonStatus::import(const ActionSet& as) if(unsigned(inp.data.all[j]) < ACTION_BUTTON_ENUM_SIZE) 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] @@ -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); diff --git a/BBGE/ActionStatus.h b/BBGE/ActionStatus.h index 6f17fff..76dbb3d 100644 --- a/BBGE/ActionStatus.h +++ b/BBGE/ActionStatus.h @@ -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,