diff --git a/apps/openmw/mwgui/alchemywindow.cpp b/apps/openmw/mwgui/alchemywindow.cpp index 9f493850bf..d0931057cd 100644 --- a/apps/openmw/mwgui/alchemywindow.cpp +++ b/apps/openmw/mwgui/alchemywindow.cpp @@ -547,6 +547,32 @@ namespace MWGui mBrewCountEdit->setValue(currentCount - 1); } + void AlchemyWindow::filterListButtonHandler(const SDL_ControllerButtonEvent& arg) + { + if (arg.button == SDL_CONTROLLER_BUTTON_A || arg.button == SDL_CONTROLLER_BUTTON_Y) + { + // Select the highlighted entry in the combo box and close it. List is closed by focusing on another + // widget. + size_t index = mFilterValue->getIndexSelected(); + mFilterValue->setIndexSelected(index); + onFilterChanged(mFilterValue, index); + MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mNameEdit); + + MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click")); + } + else if (arg.button == SDL_CONTROLLER_BUTTON_B) + { + // Close the list without selecting anything. List is closed by focusing on another widget. + mFilterValue->clearIndexSelected(); + onFilterEdited(mFilterValue); + MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mNameEdit); + } + else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP) + MWBase::Environment::get().getWindowManager()->injectKeyPress(MyGUI::KeyCode::ArrowUp, 0, false); + else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN) + MWBase::Environment::get().getWindowManager()->injectKeyPress(MyGUI::KeyCode::ArrowDown, 0, false); + } + bool AlchemyWindow::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) { MyGUI::Widget* focus = MyGUI::InputManager::getInstance().getKeyFocusWidget(); @@ -556,71 +582,49 @@ namespace MWGui if (isFilterListOpen) { // When the filter list combo box is open, send all inputs to it. - if (arg.button == SDL_CONTROLLER_BUTTON_A || arg.button == SDL_CONTROLLER_BUTTON_Y) - { - // Select the highlighted entry in the combo box and close it. List is closed by focusing on another - // widget. - size_t index = mFilterValue->getIndexSelected(); - mFilterValue->setIndexSelected(index); - onFilterChanged(mFilterValue, index); - MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mNameEdit); + filterListButtonHandler(arg); + return true; + } - MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click")); - } - else if (arg.button == SDL_CONTROLLER_BUTTON_B) + if (arg.button == SDL_CONTROLLER_BUTTON_B) + { + // Remove active ingredients or close the window, starting with right-most slot. + for (size_t i = mIngredients.size() - 1; i >= 0; --i) { - // Close the list without selecting anything. List is closed by focusing on another widget. + if (mIngredients[i]->isUserString("ToolTipType")) + { + onIngredientSelected(mIngredients[i]); + return true; + } + } + // If the ingredients list is empty, B closes the menu. + onCancelButtonClicked(mCancelButton); + } + else if (arg.button == SDL_CONTROLLER_BUTTON_X) + onCreateButtonClicked(mCreateButton); + else if (arg.button == SDL_CONTROLLER_BUTTON_Y && mFilterValue->getItemCount() > 0) + { + // Magical effects/ingredients filter + if (mFilterValue->getIndexSelected() != MyGUI::ITEM_NONE) + { + // Clear the active filter mFilterValue->clearIndexSelected(); onFilterEdited(mFilterValue); - MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mNameEdit); } - else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP) - MWBase::Environment::get().getWindowManager()->injectKeyPress(MyGUI::KeyCode::ArrowUp, 0, false); - else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN) - MWBase::Environment::get().getWindowManager()->injectKeyPress(MyGUI::KeyCode::ArrowDown, 0, false); - } - else - { - if (arg.button == SDL_CONTROLLER_BUTTON_B) - { - // Remove active ingredients or close the window - if (mIngredients[3]->isUserString("ToolTipType")) - onIngredientSelected(mIngredients[3]); - else if (mIngredients[2]->isUserString("ToolTipType")) - onIngredientSelected(mIngredients[2]); - else if (mIngredients[1]->isUserString("ToolTipType")) - onIngredientSelected(mIngredients[1]); - else if (mIngredients[0]->isUserString("ToolTipType")) - onIngredientSelected(mIngredients[0]); - else - onCancelButtonClicked(mCancelButton); - } - else if (arg.button == SDL_CONTROLLER_BUTTON_X) - onCreateButtonClicked(mCreateButton); - else if (arg.button == SDL_CONTROLLER_BUTTON_Y && mFilterValue->getItemCount() > 0) - { - // Magical effects/ingredients filter - if (mFilterValue->getIndexSelected() != MyGUI::ITEM_NONE) - { - // Clear the active filter - mFilterValue->clearIndexSelected(); - onFilterEdited(mFilterValue); - } - else - { - // Open the combo box to choose the a filter - MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mFilterValue); - MWBase::Environment::get().getWindowManager()->injectKeyPress(MyGUI::KeyCode::ArrowDown, 0, false); - } - MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click")); - } - else if (arg.button == SDL_CONTROLLER_BUTTON_LEFTSHOULDER) - onDecreaseButtonTriggered(); - else if (arg.button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER) - onIncreaseButtonTriggered(); else - mItemView->onControllerButton(arg.button); + { + // Open the combo box to choose the a filter + MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mFilterValue); + MWBase::Environment::get().getWindowManager()->injectKeyPress(MyGUI::KeyCode::ArrowDown, 0, false); + } + MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click")); } + else if (arg.button == SDL_CONTROLLER_BUTTON_LEFTSHOULDER) + onDecreaseButtonTriggered(); + else if (arg.button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER) + onIncreaseButtonTriggered(); + else + mItemView->onControllerButton(arg.button); return true; } diff --git a/apps/openmw/mwgui/alchemywindow.hpp b/apps/openmw/mwgui/alchemywindow.hpp index e79c41b659..4c5faa86d4 100644 --- a/apps/openmw/mwgui/alchemywindow.hpp +++ b/apps/openmw/mwgui/alchemywindow.hpp @@ -101,6 +101,7 @@ namespace MWGui std::vector mIngredients; bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override; + void filterListButtonHandler(const SDL_ControllerButtonEvent& arg); }; }