1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-12-07 20:34:31 +00:00

Hide cursor icon when showing controller tooltips

This commit is contained in:
Andrew Lanzone 2025-06-03 00:44:45 -07:00
parent 43b5176367
commit a6d03717cb
10 changed files with 40 additions and 20 deletions

View file

@ -390,6 +390,8 @@ namespace MWBase
/// Cycle to the next window to receive controller events
virtual void cycleActiveControllerWindow(bool next) = 0;
virtual void setActiveControllerWindow(MWGui::GuiMode mode, int activeIndex) = 0;
virtual const bool getControllerTooltip() const = 0;
virtual void setControllerTooltip(bool enabled) = 0;
virtual void updateControllerButtonsOverlay() = 0;
// Used in Lua bindings

View file

@ -880,11 +880,6 @@ namespace MWGui
return osg::Vec2f(normalisedX * float(viewport.width - 1), (1.0 - normalisedY) * float(viewport.height - 1));
}
bool InventoryWindow::isControllerTooltipVisible()
{
return mItemView->isControllerTooltipVisible();
}
ControllerButtonStr* InventoryWindow::getControllerButtons()
{
switch (mGuiMode)

View file

@ -68,7 +68,6 @@ namespace MWGui
std::string_view getWindowIdForLua() const override { return "Inventory"; }
ControllerButtonStr* getControllerButtons() override;
bool isControllerTooltipVisible();
protected:
void onTitleDoubleClicked() override;

View file

@ -81,7 +81,7 @@ namespace MWGui
if (Settings::gui().mControllerMenus)
{
mControllerTooltip = false;
MWBase::Environment::get().getWindowManager()->setControllerTooltip(false);
mControllerFocus = std::clamp(mControllerFocus, 0, mItemCount - 1);
updateControllerFocus(-1, mControllerFocus);
}
@ -190,10 +190,11 @@ namespace MWGui
{
mControllerActiveWindow = active;
if (mControllerTooltip)
MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager();
if (winMgr->getControllerTooltip())
{
MWBase::Environment::get().getWindowManager()->setCursorActive(false);
mControllerTooltip = false;
winMgr->setCursorActive(false);
winMgr->setControllerTooltip(false);
}
if (active)
@ -221,7 +222,8 @@ namespace MWGui
else if (button == SDL_CONTROLLER_BUTTON_RIGHTSTICK)
{
// Toggle info tooltip
mControllerTooltip = !mControllerTooltip;
MWBase::Environment::get().getWindowManager()->setControllerTooltip(
!MWBase::Environment::get().getWindowManager()->getControllerTooltip());
updateControllerFocus(-1, mControllerFocus);
}
else if (button == SDL_CONTROLLER_BUTTON_DPAD_UP)
@ -250,10 +252,15 @@ namespace MWGui
if (prevFocus != mControllerFocus)
updateControllerFocus(prevFocus, mControllerFocus);
else
updateControllerFocus(-1, mControllerFocus);
}
void ItemView::updateControllerFocus(int prevFocus, int newFocus)
{
MWBase::Environment::get().getWindowManager()->setCursorVisible(
!MWBase::Environment::get().getWindowManager()->getControllerTooltip());
if (!mItemCount)
return;
@ -272,8 +279,6 @@ namespace MWGui
if (focused)
{
focused->setControllerFocus(true);
if (mControllerTooltip)
MWBase::Environment::get().getInputManager()->warpMouseToWidget(focused);
// Scroll the list to keep the active item in view
int column = newFocus / mRows;
@ -281,6 +286,9 @@ namespace MWGui
mScrollView->setViewOffset(MyGUI::IntPoint(0, 0));
else
mScrollView->setViewOffset(MyGUI::IntPoint(-42 * (column - 3), 0));
if (MWBase::Environment::get().getWindowManager()->getControllerTooltip())
MWBase::Environment::get().getInputManager()->warpMouseToWidget(focused);
}
}
}

View file

@ -35,7 +35,6 @@ namespace MWGui
void setActiveControllerWindow(bool active);
int getControllerFocus() { return mControllerFocus; }
int getItemCount() { return mItemCount; }
bool isControllerTooltipVisible() { return mControllerTooltip; }
void onControllerButton(const unsigned char button);
private:
@ -56,7 +55,6 @@ namespace MWGui
int mItemCount = 0;
int mRows;
int mControllerFocus = 0;
bool mControllerTooltip;
bool mControllerActiveWindow;
void updateControllerFocus(int prevFocus, int newFocus);
};

View file

@ -94,7 +94,7 @@ namespace MWGui
if (guiMode)
{
if (!winMgr->getCursorVisible())
if (!winMgr->getCursorVisible() && !winMgr->getControllerTooltip())
return;
const MyGUI::IntPoint& mousePos = MyGUI::InputManager::getInstance().getMousePosition();

View file

@ -941,6 +941,9 @@ namespace MWGui
void WindowManager::setActiveControllerWindow(GuiMode mode, int activeIndex)
{
if (!Settings::gui().mControllerMenus)
return;
int winCount = mGuiModeStates[mode].mWindows.size();
if (winCount == 0)
return;
@ -2590,6 +2593,14 @@ namespace MWGui
return res;
}
void WindowManager::setControllerTooltip(bool enabled)
{
if (!Settings::gui().mControllerMenus)
return;
mControllerTooltip = enabled;
}
void WindowManager::updateControllerButtonsOverlay()
{
if (!Settings::gui().mControllerMenus || !mControllerButtonsOverlay)

View file

@ -396,6 +396,8 @@ namespace MWGui
WindowBase* getActiveControllerWindow() override;
void cycleActiveControllerWindow(bool next) override;
void setActiveControllerWindow(GuiMode mode, int activeIndex) override;
const bool getControllerTooltip() const override { return mControllerTooltip; }
void setControllerTooltip(bool enabled) override;
void updateControllerButtonsOverlay() override;
// Used in Lua bindings
@ -508,6 +510,7 @@ namespace MWGui
std::vector<GuiMode> mGuiModes;
// The active window for controller mode for each GUI mode.
std::map<GuiMode, int> mActiveControllerWindows;
bool mControllerTooltip;
std::unique_ptr<SDLUtil::SDLCursorManager> mCursorManager;

View file

@ -257,8 +257,7 @@ namespace MWInput
// act like a mouse button; it should act normally.
if (treatAsMouse
&& arg.button == SDL_CONTROLLER_BUTTON_A
&& (MWGui::InventoryWindow *)topWin == winMgr->getInventoryWindow()
&& ((MWGui::InventoryWindow *)topWin)->isControllerTooltipVisible())
&& winMgr->getControllerTooltip())
treatAsMouse = false;
mGamepadGuiCursorEnabled = topWin->isGamepadCursorAllowed();
@ -363,6 +362,11 @@ namespace MWInput
&& (arg.axis == SDL_CONTROLLER_AXIS_LEFTX || arg.axis == SDL_CONTROLLER_AXIS_LEFTY))
{
// Treat the left stick like a cursor, which is the default behavior.
if (winMgr->getControllerTooltip())
{
winMgr->setControllerTooltip(false);
winMgr->setCursorVisible(true);
}
return false;
}

View file

@ -266,8 +266,8 @@ namespace MWInput
void MouseManager::warpMouseToWidget(MyGUI::Widget* widget)
{
float widgetX = widget->getAbsoluteCoord().left + 4;
float widgetY = widget->getAbsoluteCoord().top + 4;
float widgetX = widget->getAbsoluteCoord().left + widget->getWidth() / 2;
float widgetY = widget->getAbsoluteCoord().top + widget->getHeight() - 30;
if (std::abs(mGuiCursorX - widgetX) > 1 || std::abs(mGuiCursorY - widgetY) > 1)
{
mGuiCursorX = widgetX;