mirror of
https://github.com/OpenMW/openmw.git
synced 2026-01-06 00:13:16 +00:00
Fix spurious button presses causing controller tooltip to wiggle
This commit is contained in:
parent
7b9958247a
commit
5d5d14a5a6
4 changed files with 100 additions and 85 deletions
|
|
@ -206,44 +206,46 @@ namespace MWGui
|
|||
|
||||
int prevFocus = mControllerFocus;
|
||||
|
||||
if (button == SDL_CONTROLLER_BUTTON_A)
|
||||
switch (button)
|
||||
{
|
||||
// Select the focused item, if any.
|
||||
if (mControllerFocus >= 0 && mControllerFocus < mItemCount)
|
||||
{
|
||||
MyGUI::Widget* dragArea = mScrollView->getChildAt(0);
|
||||
onSelectedItem(dragArea->getChildAt(mControllerFocus));
|
||||
}
|
||||
}
|
||||
else if (button == SDL_CONTROLLER_BUTTON_RIGHTSTICK)
|
||||
{
|
||||
// Toggle info tooltip
|
||||
MWBase::Environment::get().getWindowManager()->setControllerTooltip(
|
||||
!MWBase::Environment::get().getWindowManager()->getControllerTooltip());
|
||||
updateControllerFocus(-1, mControllerFocus);
|
||||
}
|
||||
else if (button == SDL_CONTROLLER_BUTTON_DPAD_UP)
|
||||
{
|
||||
if (mControllerFocus % mRows == 0)
|
||||
mControllerFocus = std::min(mControllerFocus + mRows - 1, mItemCount - 1);
|
||||
else
|
||||
mControllerFocus--;
|
||||
}
|
||||
else if (button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
|
||||
{
|
||||
if (mControllerFocus % mRows == mRows - 1 || mControllerFocus == mItemCount - 1)
|
||||
mControllerFocus -= mControllerFocus % mRows;
|
||||
else
|
||||
mControllerFocus++;
|
||||
}
|
||||
else if (button == SDL_CONTROLLER_BUTTON_DPAD_LEFT && mControllerFocus >= mRows)
|
||||
mControllerFocus -= mRows;
|
||||
else if (button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT)
|
||||
{
|
||||
if (mControllerFocus + mRows < mItemCount)
|
||||
mControllerFocus += mRows;
|
||||
else if (mControllerFocus / mRows != (mItemCount - 1) / mRows)
|
||||
mControllerFocus = mItemCount - 1;
|
||||
case SDL_CONTROLLER_BUTTON_A:
|
||||
// Select the focused item, if any.
|
||||
if (mControllerFocus >= 0 && mControllerFocus < mItemCount)
|
||||
{
|
||||
MyGUI::Widget* dragArea = mScrollView->getChildAt(0);
|
||||
onSelectedItem(dragArea->getChildAt(mControllerFocus));
|
||||
}
|
||||
break;
|
||||
case SDL_CONTROLLER_BUTTON_RIGHTSTICK:
|
||||
// Toggle info tooltip
|
||||
MWBase::Environment::get().getWindowManager()->setControllerTooltip(
|
||||
!MWBase::Environment::get().getWindowManager()->getControllerTooltip());
|
||||
updateControllerFocus(-1, mControllerFocus);
|
||||
break;
|
||||
case SDL_CONTROLLER_BUTTON_DPAD_UP:
|
||||
if (mControllerFocus % mRows == 0)
|
||||
mControllerFocus = std::min(mControllerFocus + mRows - 1, mItemCount - 1);
|
||||
else
|
||||
mControllerFocus--;
|
||||
break;
|
||||
case SDL_CONTROLLER_BUTTON_DPAD_DOWN:
|
||||
if (mControllerFocus % mRows == mRows - 1 || mControllerFocus == mItemCount - 1)
|
||||
mControllerFocus -= mControllerFocus % mRows;
|
||||
else
|
||||
mControllerFocus++;
|
||||
break;
|
||||
case SDL_CONTROLLER_BUTTON_DPAD_LEFT:
|
||||
if (mControllerFocus >= mRows)
|
||||
mControllerFocus -= mRows;
|
||||
break;
|
||||
case SDL_CONTROLLER_BUTTON_DPAD_RIGHT:
|
||||
if (mControllerFocus + mRows < mItemCount)
|
||||
mControllerFocus += mRows;
|
||||
else if (mControllerFocus / mRows != (mItemCount - 1) / mRows)
|
||||
mControllerFocus = mItemCount - 1;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
if (prevFocus != mControllerFocus)
|
||||
|
|
|
|||
|
|
@ -263,6 +263,8 @@ namespace MWGui
|
|||
mControllerFocus = wrap(mControllerFocus + 1, mSpellButtons.size());
|
||||
mSpellButtons[mControllerFocus].first->setStateSelected(true);
|
||||
}
|
||||
else
|
||||
return true;
|
||||
|
||||
if (mControllerFocus < mSpellButtons.size())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1109,6 +1109,8 @@ namespace MWGui
|
|||
|
||||
winMgr->setControllerTooltip(false);
|
||||
}
|
||||
else
|
||||
return true;
|
||||
|
||||
// Scroll the list to keep the active item in view
|
||||
if (mAvailableFocus <= 5)
|
||||
|
|
|
|||
|
|
@ -351,58 +351,67 @@ namespace MWGui
|
|||
|
||||
int prevFocus = mControllerFocus;
|
||||
|
||||
if (button == SDL_CONTROLLER_BUTTON_A)
|
||||
switch (button)
|
||||
{
|
||||
// Select the focused item, if any.
|
||||
if (mControllerFocus >= 0 && mControllerFocus < static_cast<int>(mButtons.size()))
|
||||
{
|
||||
onSpellSelected(mButtons[mControllerFocus].first);
|
||||
MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
|
||||
}
|
||||
}
|
||||
else if (button == SDL_CONTROLLER_BUTTON_RIGHTSTICK)
|
||||
{
|
||||
// Toggle info tooltip
|
||||
MWBase::Environment::get().getWindowManager()->setControllerTooltip(
|
||||
!MWBase::Environment::get().getWindowManager()->getControllerTooltip());
|
||||
}
|
||||
else if (button == SDL_CONTROLLER_BUTTON_DPAD_UP)
|
||||
mControllerFocus--;
|
||||
else if (button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
|
||||
mControllerFocus++;
|
||||
else if (button == SDL_CONTROLLER_BUTTON_DPAD_LEFT)
|
||||
mControllerFocus = std::max(0, mControllerFocus - 10);
|
||||
else if (button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT)
|
||||
mControllerFocus = std::min(mControllerFocus + 10, static_cast<int>(mButtons.size()) - 1);
|
||||
else if (button == SDL_CONTROLLER_BUTTON_LEFTSHOULDER)
|
||||
{
|
||||
// Jump to first item in previous group
|
||||
int prevGroupIndex = 0;
|
||||
for (int groupIndex : mGroupIndices)
|
||||
{
|
||||
if (groupIndex >= mControllerFocus)
|
||||
break;
|
||||
else
|
||||
prevGroupIndex = groupIndex;
|
||||
}
|
||||
mControllerFocus = prevGroupIndex;
|
||||
}
|
||||
else if (button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER)
|
||||
{
|
||||
// Jump to first item in next group
|
||||
int newFocus = mControllerFocus;
|
||||
for (int groupIndex : mGroupIndices)
|
||||
{
|
||||
if (groupIndex > mControllerFocus)
|
||||
case SDL_CONTROLLER_BUTTON_A:
|
||||
// Select the focused item, if any.
|
||||
if (mControllerFocus >= 0 && mControllerFocus < static_cast<int>(mButtons.size()))
|
||||
{
|
||||
newFocus = groupIndex;
|
||||
break;
|
||||
onSpellSelected(mButtons[mControllerFocus].first);
|
||||
MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
|
||||
}
|
||||
break;
|
||||
case SDL_CONTROLLER_BUTTON_RIGHTSTICK:
|
||||
// Toggle info tooltip
|
||||
MWBase::Environment::get().getWindowManager()->setControllerTooltip(
|
||||
!MWBase::Environment::get().getWindowManager()->getControllerTooltip());
|
||||
break;
|
||||
case SDL_CONTROLLER_BUTTON_DPAD_UP:
|
||||
mControllerFocus--;
|
||||
break;
|
||||
case SDL_CONTROLLER_BUTTON_DPAD_DOWN:
|
||||
mControllerFocus++;
|
||||
break;
|
||||
case SDL_CONTROLLER_BUTTON_DPAD_LEFT:
|
||||
mControllerFocus = std::max(0, mControllerFocus - 10);
|
||||
break;
|
||||
case SDL_CONTROLLER_BUTTON_DPAD_RIGHT:
|
||||
mControllerFocus = std::min(mControllerFocus + 10, static_cast<int>(mButtons.size()) - 1);
|
||||
break;
|
||||
case SDL_CONTROLLER_BUTTON_LEFTSHOULDER:
|
||||
{
|
||||
// Jump to first item in previous group
|
||||
int prevGroupIndex = 0;
|
||||
for (int groupIndex : mGroupIndices)
|
||||
{
|
||||
if (groupIndex >= mControllerFocus)
|
||||
break;
|
||||
else
|
||||
prevGroupIndex = groupIndex;
|
||||
}
|
||||
mControllerFocus = prevGroupIndex;
|
||||
}
|
||||
// If on last group, jump to bottom of whole list
|
||||
if (newFocus == mControllerFocus)
|
||||
newFocus = mButtons.size() - 1;
|
||||
mControllerFocus = newFocus;
|
||||
break;
|
||||
case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER:
|
||||
{
|
||||
// Jump to first item in next group
|
||||
int newFocus = mControllerFocus;
|
||||
for (int groupIndex : mGroupIndices)
|
||||
{
|
||||
if (groupIndex > mControllerFocus)
|
||||
{
|
||||
newFocus = groupIndex;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// If on last group, jump to bottom of whole list
|
||||
if (newFocus == mControllerFocus)
|
||||
newFocus = mButtons.size() - 1;
|
||||
mControllerFocus = newFocus;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
mControllerFocus = wrap(mControllerFocus, mButtons.size());
|
||||
|
|
|
|||
Loading…
Reference in a new issue