1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-11-09 11:26:42 +00:00

Consolidate all gamepad cursor listening in controllermanager

This commit is contained in:
Andrew Lanzone 2025-05-18 01:27:38 -07:00
parent e01291ec4a
commit 33a6189f7a
19 changed files with 76 additions and 155 deletions

View file

@ -282,10 +282,6 @@ namespace MWGui
{ {
if (arg.button == SDL_CONTROLLER_BUTTON_A) if (arg.button == SDL_CONTROLLER_BUTTON_A)
{ {
// Have A button do nothing so mouse controller still works.
if (mUsingGamepadGuiCursor)
return false;
if (mOkButtonFocus) if (mOkButtonFocus)
onOkClicked(mOkButton); onOkClicked(mOkButton);
else else
@ -304,14 +300,12 @@ namespace MWGui
MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager(); MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager();
winMgr->setKeyFocusWidget(mBirthList); winMgr->setKeyFocusWidget(mBirthList);
winMgr->injectKeyPress(MyGUI::KeyCode::ArrowUp, 0, false); winMgr->injectKeyPress(MyGUI::KeyCode::ArrowUp, 0, false);
mUsingGamepadGuiCursor = false;
} }
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN) else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
{ {
MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager(); MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager();
winMgr->setKeyFocusWidget(mBirthList); winMgr->setKeyFocusWidget(mBirthList);
winMgr->injectKeyPress(MyGUI::KeyCode::ArrowDown, 0, false); winMgr->injectKeyPress(MyGUI::KeyCode::ArrowDown, 0, false);
mUsingGamepadGuiCursor = false;
} }
else if ((arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT && mOkButtonFocus) || else if ((arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT && mOkButtonFocus) ||
(arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT && !mOkButtonFocus)) (arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT && !mOkButtonFocus))
@ -319,18 +313,8 @@ namespace MWGui
mOkButtonFocus = !mOkButtonFocus; mOkButtonFocus = !mOkButtonFocus;
mOkButton->setStateSelected(mOkButtonFocus); mOkButton->setStateSelected(mOkButtonFocus);
mBackButton->setStateSelected(!mOkButtonFocus); mBackButton->setStateSelected(!mOkButtonFocus);
mUsingGamepadGuiCursor = false;
} }
return true; 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;
}
} }

View file

@ -59,9 +59,7 @@ namespace MWGui
ESM::RefId mCurrentBirthId; ESM::RefId mCurrentBirthId;
bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override; bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
bool onControllerThumbstickEvent(const SDL_ControllerAxisEvent& arg) override;
bool mOkButtonFocus = true; bool mOkButtonFocus = true;
bool mUsingGamepadGuiCursor = false;
}; };
} }
#endif #endif

View file

@ -58,6 +58,7 @@ namespace MWGui
if (Settings::gui().mControllerMenus) if (Settings::gui().mControllerMenus)
{ {
mOkButton->setStateSelected(true); mOkButton->setStateSelected(true);
mDisableGamepadCursor = true;
trackFocusEvents(mBackButton); trackFocusEvents(mBackButton);
trackFocusEvents(mOkButton); trackFocusEvents(mOkButton);
mControllerButtons.a = "#{sSelect}"; mControllerButtons.a = "#{sSelect}";
@ -323,10 +324,6 @@ namespace MWGui
{ {
if (arg.button == SDL_CONTROLLER_BUTTON_A) if (arg.button == SDL_CONTROLLER_BUTTON_A)
{ {
// Have A button do nothing so mouse controller still works.
if (mUsingGamepadGuiCursor)
return false;
if (mOkButtonFocus) if (mOkButtonFocus)
onOkClicked(mOkButton); onOkClicked(mOkButton);
else else
@ -345,14 +342,12 @@ namespace MWGui
MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager(); MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager();
winMgr->setKeyFocusWidget(mClassList); winMgr->setKeyFocusWidget(mClassList);
winMgr->injectKeyPress(MyGUI::KeyCode::ArrowUp, 0, false); winMgr->injectKeyPress(MyGUI::KeyCode::ArrowUp, 0, false);
mUsingGamepadGuiCursor = false;
} }
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN) else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
{ {
MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager(); MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager();
winMgr->setKeyFocusWidget(mClassList); winMgr->setKeyFocusWidget(mClassList);
winMgr->injectKeyPress(MyGUI::KeyCode::ArrowDown, 0, false); winMgr->injectKeyPress(MyGUI::KeyCode::ArrowDown, 0, false);
mUsingGamepadGuiCursor = false;
} }
else if ((arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT && mOkButtonFocus) || else if ((arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT && mOkButtonFocus) ||
(arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT && !mOkButtonFocus)) (arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT && !mOkButtonFocus))
@ -360,21 +355,11 @@ namespace MWGui
mOkButtonFocus = !mOkButtonFocus; mOkButtonFocus = !mOkButtonFocus;
mOkButton->setStateSelected(mOkButtonFocus); mOkButton->setStateSelected(mOkButtonFocus);
mBackButton->setStateSelected(!mOkButtonFocus); mBackButton->setStateSelected(!mOkButtonFocus);
mUsingGamepadGuiCursor = false;
} }
return true; 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 */ /* InfoBoxDialog */
void InfoBoxDialog::fitToText(MyGUI::TextBox* widget) void InfoBoxDialog::fitToText(MyGUI::TextBox* widget)
@ -417,6 +402,7 @@ namespace MWGui
center(); center();
mDisableGamepadCursor = Settings::gui().mControllerMenus;
mControllerButtons.a = "#{sSelect}"; mControllerButtons.a = "#{sSelect}";
} }
@ -721,10 +707,6 @@ namespace MWGui
{ {
if (arg.button == SDL_CONTROLLER_BUTTON_A) if (arg.button == SDL_CONTROLLER_BUTTON_A)
{ {
// Have A button do nothing so mouse controller still works.
if (mUsingGamepadGuiCursor)
return false;
if (mControllerFocus == 0) if (mControllerFocus == 0)
onDescriptionClicked(mButtons[0]); onDescriptionClicked(mButtons[0]);
else if (mControllerFocus == 1) else if (mControllerFocus == 1)
@ -740,11 +722,6 @@ namespace MWGui
{ {
onOkClicked(mButtons[2]); 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) else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT)
{ {
mButtons[mControllerFocus]->setStateSelected(false); mButtons[mControllerFocus]->setStateSelected(false);
@ -753,7 +730,6 @@ namespace MWGui
else else
mControllerFocus--; mControllerFocus--;
mButtons[mControllerFocus]->setStateSelected(true); mButtons[mControllerFocus]->setStateSelected(true);
mUsingGamepadGuiCursor = false;
} }
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT) else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT)
{ {
@ -763,20 +739,10 @@ namespace MWGui
else else
mControllerFocus++; mControllerFocus++;
mButtons[mControllerFocus]->setStateSelected(true); mButtons[mControllerFocus]->setStateSelected(true);
mUsingGamepadGuiCursor = false;
} }
return true; 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 // widget controls
void CreateClassDialog::onDialogCancel() void CreateClassDialog::onDialogCancel()

View file

@ -155,9 +155,7 @@ namespace MWGui
ESM::RefId mCurrentClassId; ESM::RefId mCurrentClassId;
bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override; bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
bool onControllerThumbstickEvent(const SDL_ControllerAxisEvent& arg) override;
bool mOkButtonFocus = true; bool mOkButtonFocus = true;
bool mUsingGamepadGuiCursor = false;
}; };
class SelectSpecializationDialog : public WindowModal class SelectSpecializationDialog : public WindowModal
@ -349,9 +347,7 @@ namespace MWGui
Widgets::MWSkillPtr mAffectedSkill; Widgets::MWSkillPtr mAffectedSkill;
bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override; bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
bool onControllerThumbstickEvent(const SDL_ControllerAxisEvent& arg) override;
int mControllerFocus = 2; int mControllerFocus = 2;
bool mUsingGamepadGuiCursor = false;
}; };
} }
#endif #endif

View file

@ -22,6 +22,7 @@ namespace MWGui
if (Settings::gui().mControllerMenus) if (Settings::gui().mControllerMenus)
{ {
mDisableGamepadCursor = true;
trackFocusEvents(mOkButton); trackFocusEvents(mOkButton);
trackFocusEvents(mCancelButton); trackFocusEvents(mCancelButton);
mControllerButtons.a = "#{sOk}"; mControllerButtons.a = "#{sOk}";

View file

@ -96,12 +96,12 @@ namespace MWGui
name += MWGui::ToolTips::getSoulString(object.getCellRef()); name += MWGui::ToolTips::getSoulString(object.getCellRef());
dialog->openCountDialog(name, "#{sTake}", count); dialog->openCountDialog(name, "#{sTake}", count);
dialog->eventOkClicked.clear(); dialog->eventOkClicked.clear();
if (Settings::gui().mControllerMenus && !mUsingGamepadGuiCursor) if (Settings::gui().mControllerMenus)
dialog->eventOkClicked += MyGUI::newDelegate(this, &ContainerWindow::takeItem); dialog->eventOkClicked += MyGUI::newDelegate(this, &ContainerWindow::takeItem);
else else
dialog->eventOkClicked += MyGUI::newDelegate(this, &ContainerWindow::dragItem); dialog->eventOkClicked += MyGUI::newDelegate(this, &ContainerWindow::dragItem);
} }
else if (Settings::gui().mControllerMenus && !mUsingGamepadGuiCursor) else if (Settings::gui().mControllerMenus)
takeItem(nullptr, count); takeItem(nullptr, count);
else else
dragItem(nullptr, count); dragItem(nullptr, count);
@ -368,14 +368,9 @@ namespace MWGui
{ {
if (arg.button == SDL_CONTROLLER_BUTTON_A) if (arg.button == SDL_CONTROLLER_BUTTON_A)
{ {
if (mUsingGamepadGuiCursor)
return false;
int index = mItemView->getControllerFocus(); int index = mItemView->getControllerFocus();
if (index >= 0 && index < mItemView->getItemCount()) if (index >= 0 && index < mItemView->getItemCount())
{
onItemSelected(index); onItemSelected(index);
}
} }
else if (arg.button == SDL_CONTROLLER_BUTTON_B) else if (arg.button == SDL_CONTROLLER_BUTTON_B)
{ {
@ -396,21 +391,11 @@ namespace MWGui
arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT) arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT)
{ {
mItemView->onControllerButtonEvent(arg); mItemView->onControllerButtonEvent(arg);
mUsingGamepadGuiCursor = false;
} }
return true; 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) void ContainerWindow::setActiveControllerWindow(bool active)
{ {
mItemView->setActiveControllerWindow(active); mItemView->setActiveControllerWindow(active);

View file

@ -70,8 +70,6 @@ namespace MWGui
void onReferenceUnavailable() override; void onReferenceUnavailable() override;
bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override; bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
bool onControllerThumbstickEvent(const SDL_ControllerAxisEvent& arg) override;
bool mUsingGamepadGuiCursor = false;
}; };
} }
#endif // CONTAINER_H #endif // CONTAINER_H

View file

@ -685,10 +685,6 @@ namespace
{ {
if (arg.button == SDL_CONTROLLER_BUTTON_A) // A: Mouse click or Select if (arg.button == SDL_CONTROLLER_BUTTON_A) // A: Mouse click or Select
{ {
// Fall through to mouse click
if (mUsingGamepadGuiCursor)
return false;
if (mOptionsMode && mQuestMode) if (mOptionsMode && mQuestMode)
{ {
// Choose a quest // Choose a quest
@ -773,7 +769,6 @@ namespace
mSelectedQuest = mButtons.size() - 1; mSelectedQuest = mButtons.size() - 1;
mButtons[mSelectedQuest]->setStateSelected(true); mButtons[mSelectedQuest]->setStateSelected(true);
} }
mUsingGamepadGuiCursor = false;
return true; return true;
} }
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN) else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
@ -787,21 +782,18 @@ namespace
mSelectedQuest = 0; mSelectedQuest = 0;
mButtons[mSelectedQuest]->setStateSelected(true); mButtons[mSelectedQuest]->setStateSelected(true);
} }
mUsingGamepadGuiCursor = false;
return true; return true;
} }
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT) else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT)
{ {
if (!mOptionsMode) if (!mOptionsMode)
notifyPrevPage(getWidget<MyGUI::Widget>(PrevPageBTN)); notifyPrevPage(getWidget<MyGUI::Widget>(PrevPageBTN));
mUsingGamepadGuiCursor = false;
return true; return true;
} }
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT) else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT)
{ {
if (!mOptionsMode) if (!mOptionsMode)
notifyNextPage(getWidget<MyGUI::Widget>(NextPageBTN)); notifyNextPage(getWidget<MyGUI::Widget>(NextPageBTN));
mUsingGamepadGuiCursor = false;
return true; return true;
} }
else if (arg.button == SDL_CONTROLLER_BUTTON_LEFTSHOULDER) // LB: Previous Page else if (arg.button == SDL_CONTROLLER_BUTTON_LEFTSHOULDER) // LB: Previous Page
@ -819,13 +811,6 @@ namespace
return false; 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;
}
}; };
} }

View file

@ -34,7 +34,6 @@ namespace MWGui
std::vector<MyGUI::Button*> mButtons; std::vector<MyGUI::Button*> mButtons;
int mSelectedQuest = 0; int mSelectedQuest = 0;
bool mUsingGamepadGuiCursor = false;
}; };
} }

View file

@ -106,6 +106,7 @@ namespace MWGui
constexpr VFS::Path::NormalizedView menuBackgroundVideo("video/menu_background.bik"); constexpr VFS::Path::NormalizedView menuBackgroundVideo("video/menu_background.bik");
mHasAnimatedMenu = mVFS->exists(menuBackgroundVideo); mHasAnimatedMenu = mVFS->exists(menuBackgroundVideo);
mDisableGamepadCursor = Settings::gui().mControllerMenus;
updateMenu(); updateMenu();
} }

View file

@ -284,6 +284,7 @@ namespace MWGui
if (Settings::gui().mControllerMenus) if (Settings::gui().mControllerMenus)
{ {
mDisableGamepadCursor = true;
mControllerButtons.a = "#{sOk}"; mControllerButtons.a = "#{sOk}";
// If we have more than one button, we need to set the focus to the first one. // If we have more than one button, we need to set the focus to the first one.

View file

@ -475,10 +475,6 @@ namespace MWGui
{ {
if (arg.button == SDL_CONTROLLER_BUTTON_A) if (arg.button == SDL_CONTROLLER_BUTTON_A)
{ {
// Have A button do nothing so mouse controller still works.
if (mUsingGamepadGuiCursor)
return false;
if (mOkButtonFocus) if (mOkButtonFocus)
onOkClicked(mOkButton); onOkClicked(mOkButton);
else else
@ -509,14 +505,12 @@ namespace MWGui
MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager(); MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager();
winMgr->setKeyFocusWidget(mRaceList); winMgr->setKeyFocusWidget(mRaceList);
winMgr->injectKeyPress(MyGUI::KeyCode::ArrowUp, 0, false); winMgr->injectKeyPress(MyGUI::KeyCode::ArrowUp, 0, false);
mUsingGamepadGuiCursor = false;
} }
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN) else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
{ {
MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager(); MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager();
winMgr->setKeyFocusWidget(mRaceList); winMgr->setKeyFocusWidget(mRaceList);
winMgr->injectKeyPress(MyGUI::KeyCode::ArrowDown, 0, false); winMgr->injectKeyPress(MyGUI::KeyCode::ArrowDown, 0, false);
mUsingGamepadGuiCursor = false;
} }
else if ((arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT && mOkButtonFocus) || else if ((arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT && mOkButtonFocus) ||
(arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT && !mOkButtonFocus)) (arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT && !mOkButtonFocus))
@ -524,7 +518,6 @@ namespace MWGui
mOkButtonFocus = !mOkButtonFocus; mOkButtonFocus = !mOkButtonFocus;
mOkButton->setStateSelected(mOkButtonFocus); mOkButton->setStateSelected(mOkButtonFocus);
mBackButton->setStateSelected(!mOkButtonFocus); mBackButton->setStateSelected(!mOkButtonFocus);
mUsingGamepadGuiCursor = false;
} }
return true; return true;
@ -532,11 +525,7 @@ namespace MWGui
bool RaceDialog::onControllerThumbstickEvent(const SDL_ControllerAxisEvent& arg) bool RaceDialog::onControllerThumbstickEvent(const SDL_ControllerAxisEvent& arg)
{ {
if (arg.axis == SDL_CONTROLLER_AXIS_LEFTX || arg.axis == SDL_CONTROLLER_AXIS_LEFTY) if (arg.axis == SDL_CONTROLLER_AXIS_RIGHTX)
{
mUsingGamepadGuiCursor = true;
}
else if (arg.axis == SDL_CONTROLLER_AXIS_RIGHTX)
{ {
if (arg.value < -1000 || arg.value > 1000) if (arg.value < -1000 || arg.value > 1000)
onPreviewScroll(nullptr, arg.value < 0 ? 1 : -1); onPreviewScroll(nullptr, arg.value < 0 ? 1 : -1);

View file

@ -125,7 +125,6 @@ namespace MWGui
bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override; bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
bool onControllerThumbstickEvent(const SDL_ControllerAxisEvent& arg) override; bool onControllerThumbstickEvent(const SDL_ControllerAxisEvent& arg) override;
bool mOkButtonFocus = true; bool mOkButtonFocus = true;
bool mUsingGamepadGuiCursor = false;
}; };
} }
#endif #endif

View file

@ -516,10 +516,6 @@ namespace MWGui
{ {
if (arg.button == SDL_CONTROLLER_BUTTON_A) if (arg.button == SDL_CONTROLLER_BUTTON_A)
{ {
// Have A button do nothing so mouse controller still works.
if (mUsingGamepadGuiCursor)
return false;
if (mOkButtonFocus) if (mOkButtonFocus)
onOkButtonClicked(mOkButton); onOkButtonClicked(mOkButton);
else else
@ -537,21 +533,18 @@ namespace MWGui
else else
index++; index++;
mCharacterSelection->setIndexSelected(index); mCharacterSelection->setIndexSelected(index);
mUsingGamepadGuiCursor = false;
} }
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP) else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP)
{ {
MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager(); MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager();
winMgr->setKeyFocusWidget(mSaveList); winMgr->setKeyFocusWidget(mSaveList);
winMgr->injectKeyPress(MyGUI::KeyCode::ArrowUp, 0, false); winMgr->injectKeyPress(MyGUI::KeyCode::ArrowUp, 0, false);
mUsingGamepadGuiCursor = false;
} }
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN) else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
{ {
MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager(); MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager();
winMgr->setKeyFocusWidget(mSaveList); winMgr->setKeyFocusWidget(mSaveList);
winMgr->injectKeyPress(MyGUI::KeyCode::ArrowDown, 0, false); winMgr->injectKeyPress(MyGUI::KeyCode::ArrowDown, 0, false);
mUsingGamepadGuiCursor = false;
} }
else if ((arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT && !mOkButtonFocus) || else if ((arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT && !mOkButtonFocus) ||
(arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT && mOkButtonFocus)) (arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT && mOkButtonFocus))
@ -559,18 +552,8 @@ namespace MWGui
mOkButtonFocus = !mOkButtonFocus; mOkButtonFocus = !mOkButtonFocus;
mOkButton->setStateSelected(mOkButtonFocus); mOkButton->setStateSelected(mOkButtonFocus);
mCancelButton->setStateSelected(!mOkButtonFocus); mCancelButton->setStateSelected(!mOkButtonFocus);
mUsingGamepadGuiCursor = false;
} }
return true; 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;
}
} }

View file

@ -70,9 +70,7 @@ namespace MWGui
const MWState::Slot* mCurrentSlot; const MWState::Slot* mCurrentSlot;
bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override; bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
bool onControllerThumbstickEvent(const SDL_ControllerAxisEvent& arg) override;
bool mOkButtonFocus = true; bool mOkButtonFocus = true;
bool mUsingGamepadGuiCursor = false;
}; };
} }

View file

@ -88,6 +88,7 @@ namespace MWGui
trackFocusEvents(widget); trackFocusEvents(widget);
mControllerButtons.b = "#{sCancel}"; mControllerButtons.b = "#{sCancel}";
mDisableGamepadCursor = Settings::gui().mControllerMenus;
} }
void WaitDialog::setPtr(const MWWorld::Ptr& ptr) void WaitDialog::setPtr(const MWWorld::Ptr& ptr)

View file

@ -109,25 +109,25 @@ void WindowBase::clampWindowCoordinates(MyGUI::Window* window)
void WindowBase::focusGain(MyGUI::Widget* _new, MyGUI::Widget* _old) void WindowBase::focusGain(MyGUI::Widget* _new, MyGUI::Widget* _old)
{ {
// REMOVEME // REMOVEME
Log(Debug::Verbose) << "WindowBase::focusGain new=" << _new << ", old=" << _old; //Log(Debug::Verbose) << "WindowBase::focusGain new=" << _new << ", old=" << _old;
mMouseFocus = _new; //mMouseFocus = _new;
} }
void WindowBase::focusLoss(MyGUI::Widget* _old, MyGUI::Widget* _new) void WindowBase::focusLoss(MyGUI::Widget* _old, MyGUI::Widget* _new)
{ {
// REMOVEME // REMOVEME
Log(Debug::Verbose) << "WindowBase::focusLoss old=" << _old << ", new=" << _new; //Log(Debug::Verbose) << "WindowBase::focusLoss old=" << _old << ", new=" << _new;
if (mMouseFocus == _old) //if (mMouseFocus == _old)
mMouseFocus = nullptr; // mMouseFocus = nullptr;
} }
void WindowBase::trackFocusEvents(MyGUI::Widget* widget) void WindowBase::trackFocusEvents(MyGUI::Widget* widget)
{ {
if (!Settings::gui().mControllerMenus) // if (!Settings::gui().mControllerMenus)
return; // return;
widget->eventMouseSetFocus += MyGUI::newDelegate(this, &WindowBase::focusGain); // widget->eventMouseSetFocus += MyGUI::newDelegate(this, &WindowBase::focusGain);
widget->eventMouseLostFocus += MyGUI::newDelegate(this, &WindowBase::focusLoss); // widget->eventMouseLostFocus += MyGUI::newDelegate(this, &WindowBase::focusLoss);
} }
WindowModal::WindowModal(const std::string& parLayout) WindowModal::WindowModal(const std::string& parLayout)

View file

@ -74,28 +74,30 @@ namespace MWGui
static void clampWindowCoordinates(MyGUI::Window* window); 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 onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) { return true; };
virtual bool onControllerThumbstickEvent(const SDL_ControllerAxisEvent& 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; } virtual void setActiveControllerWindow(bool active) { mActiveControllerWindow = active; }
protected: protected:
virtual void onTitleDoubleClicked(); virtual void onTitleDoubleClicked();
ControllerButtonStr mControllerButtons; ControllerButtonStr mControllerButtons;
MyGUI::Widget* mMouseFocus = nullptr;
bool mActiveControllerWindow = false; bool mActiveControllerWindow = false;
bool mDisableGamepadCursor = false;
// REMOVEME
void trackFocusEvents(MyGUI::Widget* widget); void trackFocusEvents(MyGUI::Widget* widget);
// REMOVEME
MyGUI::Widget* mMouseFocus = nullptr;
private: private:
void onDoubleClick(MyGUI::Widget* _sender); void onDoubleClick(MyGUI::Widget* _sender);
bool mDisabledByLua = false; bool mDisabledByLua = false;
// REMOVEME
void focusGain(MyGUI::Widget* _new, MyGUI::Widget* _old); void focusGain(MyGUI::Widget* _new, MyGUI::Widget* _old);
void focusLoss(MyGUI::Widget* _old, MyGUI::Widget* _new); void focusLoss(MyGUI::Widget* _old, MyGUI::Widget* _new);
}; };

View file

@ -241,11 +241,26 @@ namespace MWInput
bool ControllerManager::gamepadToGuiControl(const SDL_ControllerButtonEvent& arg) bool ControllerManager::gamepadToGuiControl(const SDL_ControllerButtonEvent& arg)
{ {
MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager();
if (Settings::gui().mControllerMenus) if (Settings::gui().mControllerMenus)
{ {
MWGui::WindowBase* topWin = MWBase::Environment::get().getWindowManager()->getActiveControllerWindow(); // Update cursor state.
if (topWin && topWin->onControllerButtonEvent(arg)) bool treatAsMouse = winMgr->getCursorVisible();
return true; 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. // Presumption of GUI mode will be removed in the future.
@ -273,9 +288,9 @@ namespace MWInput
break; break;
case SDL_CONTROLLER_BUTTON_B: case SDL_CONTROLLER_BUTTON_B:
if (MyGUI::InputManager::getInstance().isModalAny()) if (MyGUI::InputManager::getInstance().isModalAny())
MWBase::Environment::get().getWindowManager()->exitCurrentModal(); winMgr->exitCurrentModal();
else else
MWBase::Environment::get().getWindowManager()->exitCurrentGuiMode(); winMgr->exitCurrentGuiMode();
return true; return true;
case SDL_CONTROLLER_BUTTON_X: case SDL_CONTROLLER_BUTTON_X:
key = MyGUI::KeyCode::Semicolon; key = MyGUI::KeyCode::Semicolon;
@ -285,7 +300,7 @@ namespace MWInput
break; break;
case SDL_CONTROLLER_BUTTON_LEFTSHOULDER: case SDL_CONTROLLER_BUTTON_LEFTSHOULDER:
MyGUI::InputManager::getInstance().injectKeyPress(MyGUI::KeyCode::LeftShift); 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); MyGUI::InputManager::getInstance().injectKeyRelease(MyGUI::KeyCode::LeftShift);
return true; return true;
case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER: case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER:
@ -293,7 +308,7 @@ namespace MWInput
return true; return true;
case SDL_CONTROLLER_BUTTON_LEFTSTICK: case SDL_CONTROLLER_BUTTON_LEFTSTICK:
mGamepadGuiCursorEnabled = !mGamepadGuiCursorEnabled; mGamepadGuiCursorEnabled = !mGamepadGuiCursorEnabled;
MWBase::Environment::get().getWindowManager()->setCursorActive(mGamepadGuiCursorEnabled); winMgr->setCursorActive(mGamepadGuiCursorEnabled);
return true; return true;
default: default:
return false; return false;
@ -303,41 +318,61 @@ namespace MWInput
if (SDL_IsTextInputActive()) if (SDL_IsTextInputActive())
return false; return false;
MWBase::Environment::get().getWindowManager()->injectKeyPress(key, 0, false); winMgr->injectKeyPress(key, 0, false);
return true; return true;
} }
bool ControllerManager::gamepadToGuiControl(const SDL_ControllerAxisEvent& arg) bool ControllerManager::gamepadToGuiControl(const SDL_ControllerAxisEvent& arg)
{ {
MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager();
if (Settings::gui().mControllerMenus) if (Settings::gui().mControllerMenus)
{ {
// Left and right triggers toggle through open GUI windows. // Left and right triggers toggle through open GUI windows.
if (arg.axis == SDL_CONTROLLER_AXIS_TRIGGERRIGHT) if (arg.axis == SDL_CONTROLLER_AXIS_TRIGGERRIGHT)
{ {
if (arg.value == 32767) // Treat like a button. if (arg.value == 32767) // Treat like a button.
MWBase::Environment::get().getWindowManager()->cycleActiveControllerWindow(true); winMgr->cycleActiveControllerWindow(true);
return true; return true;
} }
else if (arg.axis == SDL_CONTROLLER_AXIS_TRIGGERLEFT) else if (arg.axis == SDL_CONTROLLER_AXIS_TRIGGERLEFT)
{ {
if (arg.value == 32767) // Treat like a button. if (arg.value == 32767) // Treat like a button.
MWBase::Environment::get().getWindowManager()->cycleActiveControllerWindow(false); winMgr->cycleActiveControllerWindow(false);
return true; return true;
} }
MWGui::WindowBase* topWin = MWBase::Environment::get().getWindowManager()->getActiveControllerWindow();
if (topWin && topWin->onControllerThumbstickEvent(arg)) MWGui::WindowBase* topWin = winMgr->getActiveControllerWindow();
return true; 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) switch (arg.axis)
{ {
case SDL_CONTROLLER_AXIS_TRIGGERRIGHT: case SDL_CONTROLLER_AXIS_TRIGGERRIGHT:
if (arg.value == 32767) // Treat like a button. 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; break;
case SDL_CONTROLLER_AXIS_TRIGGERLEFT: case SDL_CONTROLLER_AXIS_TRIGGERLEFT:
if (arg.value == 32767) // Treat like a button. 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; break;
case SDL_CONTROLLER_AXIS_LEFTX: case SDL_CONTROLLER_AXIS_LEFTX:
case SDL_CONTROLLER_AXIS_LEFTY: case SDL_CONTROLLER_AXIS_LEFTY: