1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-10-24 22:26:37 +00:00

Split onControllerButtonEvent into two; loop through ingredient slots

This commit is contained in:
Andrew Lanzone 2025-07-25 21:46:00 -07:00
parent 6114a01ad4
commit b9ae89e032
2 changed files with 63 additions and 58 deletions

View file

@ -547,15 +547,8 @@ namespace MWGui
mBrewCountEdit->setValue(currentCount - 1); mBrewCountEdit->setValue(currentCount - 1);
} }
bool AlchemyWindow::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) void AlchemyWindow::filterListButtonHandler(const SDL_ControllerButtonEvent& arg)
{ {
MyGUI::Widget* focus = MyGUI::InputManager::getInstance().getKeyFocusWidget();
bool isFilterListOpen
= focus != nullptr && focus->getParent() != nullptr && focus->getParent()->getParent() == mFilterValue;
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) 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 // Select the highlighted entry in the combo box and close it. List is closed by focusing on another
@ -579,20 +572,32 @@ namespace MWGui
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN) else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
MWBase::Environment::get().getWindowManager()->injectKeyPress(MyGUI::KeyCode::ArrowDown, 0, false); MWBase::Environment::get().getWindowManager()->injectKeyPress(MyGUI::KeyCode::ArrowDown, 0, false);
} }
else
bool AlchemyWindow::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
{ {
MyGUI::Widget* focus = MyGUI::InputManager::getInstance().getKeyFocusWidget();
bool isFilterListOpen
= focus != nullptr && focus->getParent() != nullptr && focus->getParent()->getParent() == mFilterValue;
if (isFilterListOpen)
{
// When the filter list combo box is open, send all inputs to it.
filterListButtonHandler(arg);
return true;
}
if (arg.button == SDL_CONTROLLER_BUTTON_B) if (arg.button == SDL_CONTROLLER_BUTTON_B)
{ {
// Remove active ingredients or close the window // Remove active ingredients or close the window, starting with right-most slot.
if (mIngredients[3]->isUserString("ToolTipType")) for (size_t i = mIngredients.size() - 1; i >= 0; --i)
onIngredientSelected(mIngredients[3]); {
else if (mIngredients[2]->isUserString("ToolTipType")) if (mIngredients[i]->isUserString("ToolTipType"))
onIngredientSelected(mIngredients[2]); {
else if (mIngredients[1]->isUserString("ToolTipType")) onIngredientSelected(mIngredients[i]);
onIngredientSelected(mIngredients[1]); return true;
else if (mIngredients[0]->isUserString("ToolTipType")) }
onIngredientSelected(mIngredients[0]); }
else // If the ingredients list is empty, B closes the menu.
onCancelButtonClicked(mCancelButton); onCancelButtonClicked(mCancelButton);
} }
else if (arg.button == SDL_CONTROLLER_BUTTON_X) else if (arg.button == SDL_CONTROLLER_BUTTON_X)
@ -620,7 +625,6 @@ namespace MWGui
onIncreaseButtonTriggered(); onIncreaseButtonTriggered();
else else
mItemView->onControllerButton(arg.button); mItemView->onControllerButton(arg.button);
}
return true; return true;
} }

View file

@ -101,6 +101,7 @@ namespace MWGui
std::vector<ItemWidget*> mIngredients; std::vector<ItemWidget*> mIngredients;
bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override; bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
void filterListButtonHandler(const SDL_ControllerButtonEvent& arg);
}; };
} }