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);
}
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)
{
// 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)
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)
{
// 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
// Remove active ingredients or close the window, starting with right-most slot.
for (size_t i = mIngredients.size() - 1; i >= 0; --i)
{
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)
@ -620,7 +625,6 @@ namespace MWGui
onIncreaseButtonTriggered();
else
mItemView->onControllerButton(arg.button);
}
return true;
}

View File

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