diff --git a/apps/openmw/mwgui/birth.cpp b/apps/openmw/mwgui/birth.cpp index 53f0f9793b..b047f6dc5f 100644 --- a/apps/openmw/mwgui/birth.cpp +++ b/apps/openmw/mwgui/birth.cpp @@ -282,10 +282,6 @@ namespace MWGui { if (arg.button == SDL_CONTROLLER_BUTTON_A) { - // Have A button do nothing so mouse controller still works. - if (mUsingGamepadGuiCursor) - return false; - if (mOkButtonFocus) onOkClicked(mOkButton); else @@ -304,14 +300,12 @@ namespace MWGui MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager(); winMgr->setKeyFocusWidget(mBirthList); winMgr->injectKeyPress(MyGUI::KeyCode::ArrowUp, 0, false); - mUsingGamepadGuiCursor = false; } else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN) { MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager(); winMgr->setKeyFocusWidget(mBirthList); winMgr->injectKeyPress(MyGUI::KeyCode::ArrowDown, 0, false); - mUsingGamepadGuiCursor = false; } else if ((arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT && mOkButtonFocus) || (arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT && !mOkButtonFocus)) @@ -319,18 +313,8 @@ namespace MWGui mOkButtonFocus = !mOkButtonFocus; mOkButton->setStateSelected(mOkButtonFocus); mBackButton->setStateSelected(!mOkButtonFocus); - mUsingGamepadGuiCursor = false; } return true; } - - bool BirthDialog::onControllerThumbstickEvent(const SDL_ControllerAxisEvent& arg) - { - if (arg.axis == SDL_CONTROLLER_AXIS_LEFTX || arg.axis == SDL_CONTROLLER_AXIS_LEFTY) - { - mUsingGamepadGuiCursor = true; - } - return false; - } } diff --git a/apps/openmw/mwgui/birth.hpp b/apps/openmw/mwgui/birth.hpp index 8a7190b934..09a0b7b1b5 100644 --- a/apps/openmw/mwgui/birth.hpp +++ b/apps/openmw/mwgui/birth.hpp @@ -59,9 +59,7 @@ namespace MWGui ESM::RefId mCurrentBirthId; bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override; - bool onControllerThumbstickEvent(const SDL_ControllerAxisEvent& arg) override; bool mOkButtonFocus = true; - bool mUsingGamepadGuiCursor = false; }; } #endif diff --git a/apps/openmw/mwgui/class.cpp b/apps/openmw/mwgui/class.cpp index 0ac39e4bac..cc44de7b0c 100644 --- a/apps/openmw/mwgui/class.cpp +++ b/apps/openmw/mwgui/class.cpp @@ -58,6 +58,7 @@ namespace MWGui if (Settings::gui().mControllerMenus) { mOkButton->setStateSelected(true); + mDisableGamepadCursor = true; trackFocusEvents(mBackButton); trackFocusEvents(mOkButton); mControllerButtons.a = "#{sSelect}"; @@ -323,10 +324,6 @@ namespace MWGui { if (arg.button == SDL_CONTROLLER_BUTTON_A) { - // Have A button do nothing so mouse controller still works. - if (mUsingGamepadGuiCursor) - return false; - if (mOkButtonFocus) onOkClicked(mOkButton); else @@ -345,14 +342,12 @@ namespace MWGui MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager(); winMgr->setKeyFocusWidget(mClassList); winMgr->injectKeyPress(MyGUI::KeyCode::ArrowUp, 0, false); - mUsingGamepadGuiCursor = false; } else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN) { MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager(); winMgr->setKeyFocusWidget(mClassList); winMgr->injectKeyPress(MyGUI::KeyCode::ArrowDown, 0, false); - mUsingGamepadGuiCursor = false; } else if ((arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT && mOkButtonFocus) || (arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT && !mOkButtonFocus)) @@ -360,21 +355,11 @@ namespace MWGui mOkButtonFocus = !mOkButtonFocus; mOkButton->setStateSelected(mOkButtonFocus); mBackButton->setStateSelected(!mOkButtonFocus); - mUsingGamepadGuiCursor = false; } return true; } - bool PickClassDialog::onControllerThumbstickEvent(const SDL_ControllerAxisEvent& arg) - { - if (arg.axis == SDL_CONTROLLER_AXIS_LEFTX || arg.axis == SDL_CONTROLLER_AXIS_LEFTY) - { - mUsingGamepadGuiCursor = true; - } - return false; - } - /* InfoBoxDialog */ void InfoBoxDialog::fitToText(MyGUI::TextBox* widget) @@ -417,6 +402,7 @@ namespace MWGui center(); + mDisableGamepadCursor = Settings::gui().mControllerMenus; mControllerButtons.a = "#{sSelect}"; } @@ -721,10 +707,6 @@ namespace MWGui { if (arg.button == SDL_CONTROLLER_BUTTON_A) { - // Have A button do nothing so mouse controller still works. - if (mUsingGamepadGuiCursor) - return false; - if (mControllerFocus == 0) onDescriptionClicked(mButtons[0]); else if (mControllerFocus == 1) @@ -740,11 +722,6 @@ namespace MWGui { onOkClicked(mButtons[2]); } - else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP || - arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN) - { - mUsingGamepadGuiCursor = false; - } else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT) { mButtons[mControllerFocus]->setStateSelected(false); @@ -753,7 +730,6 @@ namespace MWGui else mControllerFocus--; mButtons[mControllerFocus]->setStateSelected(true); - mUsingGamepadGuiCursor = false; } else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT) { @@ -763,20 +739,10 @@ namespace MWGui else mControllerFocus++; mButtons[mControllerFocus]->setStateSelected(true); - mUsingGamepadGuiCursor = false; } return true; } - bool CreateClassDialog::onControllerThumbstickEvent(const SDL_ControllerAxisEvent& arg) - { - if (arg.axis == SDL_CONTROLLER_AXIS_LEFTX || arg.axis == SDL_CONTROLLER_AXIS_LEFTY) - { - mUsingGamepadGuiCursor = true; - } - return false; - } - // widget controls void CreateClassDialog::onDialogCancel() diff --git a/apps/openmw/mwgui/class.hpp b/apps/openmw/mwgui/class.hpp index e2566ce6c0..515416973e 100644 --- a/apps/openmw/mwgui/class.hpp +++ b/apps/openmw/mwgui/class.hpp @@ -155,9 +155,7 @@ namespace MWGui ESM::RefId mCurrentClassId; bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override; - bool onControllerThumbstickEvent(const SDL_ControllerAxisEvent& arg) override; bool mOkButtonFocus = true; - bool mUsingGamepadGuiCursor = false; }; class SelectSpecializationDialog : public WindowModal @@ -349,9 +347,7 @@ namespace MWGui Widgets::MWSkillPtr mAffectedSkill; bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override; - bool onControllerThumbstickEvent(const SDL_ControllerAxisEvent& arg) override; int mControllerFocus = 2; - bool mUsingGamepadGuiCursor = false; }; } #endif diff --git a/apps/openmw/mwgui/confirmationdialog.cpp b/apps/openmw/mwgui/confirmationdialog.cpp index 1d8f14176a..6a65b0b3ec 100644 --- a/apps/openmw/mwgui/confirmationdialog.cpp +++ b/apps/openmw/mwgui/confirmationdialog.cpp @@ -22,6 +22,7 @@ namespace MWGui if (Settings::gui().mControllerMenus) { + mDisableGamepadCursor = true; trackFocusEvents(mOkButton); trackFocusEvents(mCancelButton); mControllerButtons.a = "#{sOk}"; diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 615c4801d3..54eb6122c5 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -96,12 +96,12 @@ namespace MWGui name += MWGui::ToolTips::getSoulString(object.getCellRef()); dialog->openCountDialog(name, "#{sTake}", count); dialog->eventOkClicked.clear(); - if (Settings::gui().mControllerMenus && !mUsingGamepadGuiCursor) + if (Settings::gui().mControllerMenus) dialog->eventOkClicked += MyGUI::newDelegate(this, &ContainerWindow::takeItem); else dialog->eventOkClicked += MyGUI::newDelegate(this, &ContainerWindow::dragItem); } - else if (Settings::gui().mControllerMenus && !mUsingGamepadGuiCursor) + else if (Settings::gui().mControllerMenus) takeItem(nullptr, count); else dragItem(nullptr, count); @@ -368,14 +368,9 @@ namespace MWGui { if (arg.button == SDL_CONTROLLER_BUTTON_A) { - if (mUsingGamepadGuiCursor) - return false; - int index = mItemView->getControllerFocus(); if (index >= 0 && index < mItemView->getItemCount()) - { onItemSelected(index); - } } else if (arg.button == SDL_CONTROLLER_BUTTON_B) { @@ -396,21 +391,11 @@ namespace MWGui arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT) { mItemView->onControllerButtonEvent(arg); - mUsingGamepadGuiCursor = false; } return true; } - bool ContainerWindow::onControllerThumbstickEvent(const SDL_ControllerAxisEvent& arg) - { - if (arg.axis == SDL_CONTROLLER_AXIS_LEFTX || arg.axis == SDL_CONTROLLER_AXIS_LEFTY) - { - mUsingGamepadGuiCursor = true; - } - return false; - } - void ContainerWindow::setActiveControllerWindow(bool active) { mItemView->setActiveControllerWindow(active); diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index d2d8c9f4aa..08497e0369 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -70,8 +70,6 @@ namespace MWGui void onReferenceUnavailable() override; bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override; - bool onControllerThumbstickEvent(const SDL_ControllerAxisEvent& arg) override; - bool mUsingGamepadGuiCursor = false; }; } #endif // CONTAINER_H diff --git a/apps/openmw/mwgui/journalwindow.cpp b/apps/openmw/mwgui/journalwindow.cpp index abb1843178..20b7acbd9b 100644 --- a/apps/openmw/mwgui/journalwindow.cpp +++ b/apps/openmw/mwgui/journalwindow.cpp @@ -685,10 +685,6 @@ namespace { if (arg.button == SDL_CONTROLLER_BUTTON_A) // A: Mouse click or Select { - // Fall through to mouse click - if (mUsingGamepadGuiCursor) - return false; - if (mOptionsMode && mQuestMode) { // Choose a quest @@ -773,7 +769,6 @@ namespace mSelectedQuest = mButtons.size() - 1; mButtons[mSelectedQuest]->setStateSelected(true); } - mUsingGamepadGuiCursor = false; return true; } else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN) @@ -787,21 +782,18 @@ namespace mSelectedQuest = 0; mButtons[mSelectedQuest]->setStateSelected(true); } - mUsingGamepadGuiCursor = false; return true; } else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT) { if (!mOptionsMode) notifyPrevPage(getWidget(PrevPageBTN)); - mUsingGamepadGuiCursor = false; return true; } else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT) { if (!mOptionsMode) notifyNextPage(getWidget(NextPageBTN)); - mUsingGamepadGuiCursor = false; return true; } else if (arg.button == SDL_CONTROLLER_BUTTON_LEFTSHOULDER) // LB: Previous Page @@ -819,13 +811,6 @@ namespace return false; } - - bool onControllerThumbstickEvent(const SDL_ControllerAxisEvent& arg) override - { - if (arg.axis == SDL_CONTROLLER_AXIS_LEFTX || arg.axis == SDL_CONTROLLER_AXIS_LEFTY) - mUsingGamepadGuiCursor = true; - return false; - } }; } diff --git a/apps/openmw/mwgui/journalwindow.hpp b/apps/openmw/mwgui/journalwindow.hpp index 5da2038575..45c4100563 100644 --- a/apps/openmw/mwgui/journalwindow.hpp +++ b/apps/openmw/mwgui/journalwindow.hpp @@ -34,7 +34,6 @@ namespace MWGui std::vector mButtons; int mSelectedQuest = 0; - bool mUsingGamepadGuiCursor = false; }; } diff --git a/apps/openmw/mwgui/mainmenu.cpp b/apps/openmw/mwgui/mainmenu.cpp index cfcb63e4d5..286167a61e 100644 --- a/apps/openmw/mwgui/mainmenu.cpp +++ b/apps/openmw/mwgui/mainmenu.cpp @@ -106,6 +106,7 @@ namespace MWGui constexpr VFS::Path::NormalizedView menuBackgroundVideo("video/menu_background.bik"); mHasAnimatedMenu = mVFS->exists(menuBackgroundVideo); + mDisableGamepadCursor = Settings::gui().mControllerMenus; updateMenu(); } diff --git a/apps/openmw/mwgui/messagebox.cpp b/apps/openmw/mwgui/messagebox.cpp index 8c5a968c99..7e372fa215 100644 --- a/apps/openmw/mwgui/messagebox.cpp +++ b/apps/openmw/mwgui/messagebox.cpp @@ -284,6 +284,7 @@ namespace MWGui if (Settings::gui().mControllerMenus) { + mDisableGamepadCursor = true; mControllerButtons.a = "#{sOk}"; // If we have more than one button, we need to set the focus to the first one. diff --git a/apps/openmw/mwgui/race.cpp b/apps/openmw/mwgui/race.cpp index 9b97dfbb53..6aecaa0b88 100644 --- a/apps/openmw/mwgui/race.cpp +++ b/apps/openmw/mwgui/race.cpp @@ -475,10 +475,6 @@ namespace MWGui { if (arg.button == SDL_CONTROLLER_BUTTON_A) { - // Have A button do nothing so mouse controller still works. - if (mUsingGamepadGuiCursor) - return false; - if (mOkButtonFocus) onOkClicked(mOkButton); else @@ -509,14 +505,12 @@ namespace MWGui MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager(); winMgr->setKeyFocusWidget(mRaceList); winMgr->injectKeyPress(MyGUI::KeyCode::ArrowUp, 0, false); - mUsingGamepadGuiCursor = false; } else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN) { MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager(); winMgr->setKeyFocusWidget(mRaceList); winMgr->injectKeyPress(MyGUI::KeyCode::ArrowDown, 0, false); - mUsingGamepadGuiCursor = false; } else if ((arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT && mOkButtonFocus) || (arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT && !mOkButtonFocus)) @@ -524,7 +518,6 @@ namespace MWGui mOkButtonFocus = !mOkButtonFocus; mOkButton->setStateSelected(mOkButtonFocus); mBackButton->setStateSelected(!mOkButtonFocus); - mUsingGamepadGuiCursor = false; } return true; @@ -532,11 +525,7 @@ namespace MWGui bool RaceDialog::onControllerThumbstickEvent(const SDL_ControllerAxisEvent& arg) { - if (arg.axis == SDL_CONTROLLER_AXIS_LEFTX || arg.axis == SDL_CONTROLLER_AXIS_LEFTY) - { - mUsingGamepadGuiCursor = true; - } - else if (arg.axis == SDL_CONTROLLER_AXIS_RIGHTX) + if (arg.axis == SDL_CONTROLLER_AXIS_RIGHTX) { if (arg.value < -1000 || arg.value > 1000) onPreviewScroll(nullptr, arg.value < 0 ? 1 : -1); diff --git a/apps/openmw/mwgui/race.hpp b/apps/openmw/mwgui/race.hpp index c3b322ba8b..3652343308 100644 --- a/apps/openmw/mwgui/race.hpp +++ b/apps/openmw/mwgui/race.hpp @@ -125,7 +125,6 @@ namespace MWGui bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override; bool onControllerThumbstickEvent(const SDL_ControllerAxisEvent& arg) override; bool mOkButtonFocus = true; - bool mUsingGamepadGuiCursor = false; }; } #endif diff --git a/apps/openmw/mwgui/savegamedialog.cpp b/apps/openmw/mwgui/savegamedialog.cpp index 568c12d00d..b07c307d60 100644 --- a/apps/openmw/mwgui/savegamedialog.cpp +++ b/apps/openmw/mwgui/savegamedialog.cpp @@ -516,10 +516,6 @@ namespace MWGui { if (arg.button == SDL_CONTROLLER_BUTTON_A) { - // Have A button do nothing so mouse controller still works. - if (mUsingGamepadGuiCursor) - return false; - if (mOkButtonFocus) onOkButtonClicked(mOkButton); else @@ -537,21 +533,18 @@ namespace MWGui else index++; mCharacterSelection->setIndexSelected(index); - mUsingGamepadGuiCursor = false; } else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP) { MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager(); winMgr->setKeyFocusWidget(mSaveList); winMgr->injectKeyPress(MyGUI::KeyCode::ArrowUp, 0, false); - mUsingGamepadGuiCursor = false; } else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN) { MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager(); winMgr->setKeyFocusWidget(mSaveList); winMgr->injectKeyPress(MyGUI::KeyCode::ArrowDown, 0, false); - mUsingGamepadGuiCursor = false; } else if ((arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT && !mOkButtonFocus) || (arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT && mOkButtonFocus)) @@ -559,18 +552,8 @@ namespace MWGui mOkButtonFocus = !mOkButtonFocus; mOkButton->setStateSelected(mOkButtonFocus); mCancelButton->setStateSelected(!mOkButtonFocus); - mUsingGamepadGuiCursor = false; } return true; } - - bool SaveGameDialog::onControllerThumbstickEvent(const SDL_ControllerAxisEvent& arg) - { - if (arg.axis == SDL_CONTROLLER_AXIS_LEFTX || arg.axis == SDL_CONTROLLER_AXIS_LEFTY) - { - mUsingGamepadGuiCursor = true; - } - return false; - } } diff --git a/apps/openmw/mwgui/savegamedialog.hpp b/apps/openmw/mwgui/savegamedialog.hpp index fbe319aed1..4717279dfb 100644 --- a/apps/openmw/mwgui/savegamedialog.hpp +++ b/apps/openmw/mwgui/savegamedialog.hpp @@ -70,9 +70,7 @@ namespace MWGui const MWState::Slot* mCurrentSlot; bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override; - bool onControllerThumbstickEvent(const SDL_ControllerAxisEvent& arg) override; bool mOkButtonFocus = true; - bool mUsingGamepadGuiCursor = false; }; } diff --git a/apps/openmw/mwgui/waitdialog.cpp b/apps/openmw/mwgui/waitdialog.cpp index fa5cefb238..c57e813767 100644 --- a/apps/openmw/mwgui/waitdialog.cpp +++ b/apps/openmw/mwgui/waitdialog.cpp @@ -88,6 +88,7 @@ namespace MWGui trackFocusEvents(widget); mControllerButtons.b = "#{sCancel}"; + mDisableGamepadCursor = Settings::gui().mControllerMenus; } void WaitDialog::setPtr(const MWWorld::Ptr& ptr) diff --git a/apps/openmw/mwgui/windowbase.cpp b/apps/openmw/mwgui/windowbase.cpp index a3d1b27fb4..d1ce72f067 100644 --- a/apps/openmw/mwgui/windowbase.cpp +++ b/apps/openmw/mwgui/windowbase.cpp @@ -109,25 +109,25 @@ void WindowBase::clampWindowCoordinates(MyGUI::Window* window) void WindowBase::focusGain(MyGUI::Widget* _new, MyGUI::Widget* _old) { // REMOVEME - Log(Debug::Verbose) << "WindowBase::focusGain new=" << _new << ", old=" << _old; - mMouseFocus = _new; + //Log(Debug::Verbose) << "WindowBase::focusGain new=" << _new << ", old=" << _old; + //mMouseFocus = _new; } void WindowBase::focusLoss(MyGUI::Widget* _old, MyGUI::Widget* _new) { // REMOVEME - Log(Debug::Verbose) << "WindowBase::focusLoss old=" << _old << ", new=" << _new; - if (mMouseFocus == _old) - mMouseFocus = nullptr; + //Log(Debug::Verbose) << "WindowBase::focusLoss old=" << _old << ", new=" << _new; + //if (mMouseFocus == _old) + // mMouseFocus = nullptr; } void WindowBase::trackFocusEvents(MyGUI::Widget* widget) { - if (!Settings::gui().mControllerMenus) - return; + // if (!Settings::gui().mControllerMenus) + // return; - widget->eventMouseSetFocus += MyGUI::newDelegate(this, &WindowBase::focusGain); - widget->eventMouseLostFocus += MyGUI::newDelegate(this, &WindowBase::focusLoss); + // widget->eventMouseSetFocus += MyGUI::newDelegate(this, &WindowBase::focusGain); + // widget->eventMouseLostFocus += MyGUI::newDelegate(this, &WindowBase::focusLoss); } WindowModal::WindowModal(const std::string& parLayout) diff --git a/apps/openmw/mwgui/windowbase.hpp b/apps/openmw/mwgui/windowbase.hpp index 2a9d4592d3..25d97d9308 100644 --- a/apps/openmw/mwgui/windowbase.hpp +++ b/apps/openmw/mwgui/windowbase.hpp @@ -74,28 +74,30 @@ namespace MWGui static void clampWindowCoordinates(MyGUI::Window* window); - /// Called by controllermanager to handle controller events + virtual ControllerButtonStr* getControllerButtons() { return &mControllerButtons; } + bool isGamepadCursorAllowed() { return !mDisableGamepadCursor; } virtual bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) { return true; }; virtual bool onControllerThumbstickEvent(const SDL_ControllerAxisEvent& arg) { return true; }; - // REMOVEME - // virtual bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) = 0; - // virtual bool onControllerThumbstickEvent(const SDL_ControllerAxisEvent& arg) = 0; - virtual ControllerButtonStr* getControllerButtons() { return &mControllerButtons; } virtual void setActiveControllerWindow(bool active) { mActiveControllerWindow = active; } protected: virtual void onTitleDoubleClicked(); ControllerButtonStr mControllerButtons; - MyGUI::Widget* mMouseFocus = nullptr; bool mActiveControllerWindow = false; + bool mDisableGamepadCursor = false; + + // REMOVEME void trackFocusEvents(MyGUI::Widget* widget); + // REMOVEME + MyGUI::Widget* mMouseFocus = nullptr; private: void onDoubleClick(MyGUI::Widget* _sender); bool mDisabledByLua = false; + // REMOVEME void focusGain(MyGUI::Widget* _new, MyGUI::Widget* _old); void focusLoss(MyGUI::Widget* _old, MyGUI::Widget* _new); }; diff --git a/apps/openmw/mwinput/controllermanager.cpp b/apps/openmw/mwinput/controllermanager.cpp index f12c9a31ce..d1deef5011 100644 --- a/apps/openmw/mwinput/controllermanager.cpp +++ b/apps/openmw/mwinput/controllermanager.cpp @@ -241,11 +241,26 @@ namespace MWInput bool ControllerManager::gamepadToGuiControl(const SDL_ControllerButtonEvent& arg) { + MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager(); + if (Settings::gui().mControllerMenus) { - MWGui::WindowBase* topWin = MWBase::Environment::get().getWindowManager()->getActiveControllerWindow(); - if (topWin && topWin->onControllerButtonEvent(arg)) - return true; + // Update cursor state. + bool treatAsMouse = winMgr->getCursorVisible(); + winMgr->setCursorActive(false); + + MWGui::WindowBase* topWin = winMgr->getActiveControllerWindow(); + if (topWin) + { + mGamepadGuiCursorEnabled = topWin->isGamepadCursorAllowed(); + + // Fall through to mouse click + if (mGamepadGuiCursorEnabled && treatAsMouse && arg.button == SDL_CONTROLLER_BUTTON_A) + return false; + + if (topWin->onControllerButtonEvent(arg)) + return true; + } } // Presumption of GUI mode will be removed in the future. @@ -273,9 +288,9 @@ namespace MWInput break; case SDL_CONTROLLER_BUTTON_B: if (MyGUI::InputManager::getInstance().isModalAny()) - MWBase::Environment::get().getWindowManager()->exitCurrentModal(); + winMgr->exitCurrentModal(); else - MWBase::Environment::get().getWindowManager()->exitCurrentGuiMode(); + winMgr->exitCurrentGuiMode(); return true; case SDL_CONTROLLER_BUTTON_X: key = MyGUI::KeyCode::Semicolon; @@ -285,7 +300,7 @@ namespace MWInput break; case SDL_CONTROLLER_BUTTON_LEFTSHOULDER: MyGUI::InputManager::getInstance().injectKeyPress(MyGUI::KeyCode::LeftShift); - MWBase::Environment::get().getWindowManager()->injectKeyPress(MyGUI::KeyCode::Tab, 0, false); + winMgr->injectKeyPress(MyGUI::KeyCode::Tab, 0, false); MyGUI::InputManager::getInstance().injectKeyRelease(MyGUI::KeyCode::LeftShift); return true; case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER: @@ -293,7 +308,7 @@ namespace MWInput return true; case SDL_CONTROLLER_BUTTON_LEFTSTICK: mGamepadGuiCursorEnabled = !mGamepadGuiCursorEnabled; - MWBase::Environment::get().getWindowManager()->setCursorActive(mGamepadGuiCursorEnabled); + winMgr->setCursorActive(mGamepadGuiCursorEnabled); return true; default: return false; @@ -303,41 +318,61 @@ namespace MWInput if (SDL_IsTextInputActive()) return false; - MWBase::Environment::get().getWindowManager()->injectKeyPress(key, 0, false); + winMgr->injectKeyPress(key, 0, false); return true; } bool ControllerManager::gamepadToGuiControl(const SDL_ControllerAxisEvent& arg) { + MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager(); + if (Settings::gui().mControllerMenus) { // Left and right triggers toggle through open GUI windows. if (arg.axis == SDL_CONTROLLER_AXIS_TRIGGERRIGHT) { if (arg.value == 32767) // Treat like a button. - MWBase::Environment::get().getWindowManager()->cycleActiveControllerWindow(true); + winMgr->cycleActiveControllerWindow(true); return true; } else if (arg.axis == SDL_CONTROLLER_AXIS_TRIGGERLEFT) { if (arg.value == 32767) // Treat like a button. - MWBase::Environment::get().getWindowManager()->cycleActiveControllerWindow(false); + winMgr->cycleActiveControllerWindow(false); return true; } - MWGui::WindowBase* topWin = MWBase::Environment::get().getWindowManager()->getActiveControllerWindow(); - if (topWin && topWin->onControllerThumbstickEvent(arg)) - return true; + + MWGui::WindowBase* topWin = winMgr->getActiveControllerWindow(); + if (topWin) + { + // Update cursor state + mGamepadGuiCursorEnabled = topWin->isGamepadCursorAllowed(); + if (!mGamepadGuiCursorEnabled) + winMgr->setCursorActive(false); + + if (mGamepadGuiCursorEnabled + && (arg.axis == SDL_CONTROLLER_AXIS_LEFTX || arg.axis == SDL_CONTROLLER_AXIS_LEFTY)) + { + // Treat the left stick like a cursor. Fall through. + return false; + } + else if (topWin->onControllerThumbstickEvent(arg)) + { + // Window handled the event. + return true; + } + } } switch (arg.axis) { case SDL_CONTROLLER_AXIS_TRIGGERRIGHT: if (arg.value == 32767) // Treat like a button. - MWBase::Environment::get().getWindowManager()->injectKeyPress(MyGUI::KeyCode::Minus, 0, false); + winMgr->injectKeyPress(MyGUI::KeyCode::Minus, 0, false); break; case SDL_CONTROLLER_AXIS_TRIGGERLEFT: if (arg.value == 32767) // Treat like a button. - MWBase::Environment::get().getWindowManager()->injectKeyPress(MyGUI::KeyCode::Equals, 0, false); + winMgr->injectKeyPress(MyGUI::KeyCode::Equals, 0, false); break; case SDL_CONTROLLER_AXIS_LEFTX: case SDL_CONTROLLER_AXIS_LEFTY: