mirror of
https://github.com/OpenMW/openmw.git
synced 2025-12-08 14:04:31 +00:00
Hide cursor icon when showing controller tooltips
This commit is contained in:
parent
43b5176367
commit
a6d03717cb
10 changed files with 40 additions and 20 deletions
|
|
@ -390,6 +390,8 @@ namespace MWBase
|
||||||
/// Cycle to the next window to receive controller events
|
/// Cycle to the next window to receive controller events
|
||||||
virtual void cycleActiveControllerWindow(bool next) = 0;
|
virtual void cycleActiveControllerWindow(bool next) = 0;
|
||||||
virtual void setActiveControllerWindow(MWGui::GuiMode mode, int activeIndex) = 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;
|
virtual void updateControllerButtonsOverlay() = 0;
|
||||||
|
|
||||||
// Used in Lua bindings
|
// Used in Lua bindings
|
||||||
|
|
|
||||||
|
|
@ -880,11 +880,6 @@ namespace MWGui
|
||||||
return osg::Vec2f(normalisedX * float(viewport.width - 1), (1.0 - normalisedY) * float(viewport.height - 1));
|
return osg::Vec2f(normalisedX * float(viewport.width - 1), (1.0 - normalisedY) * float(viewport.height - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InventoryWindow::isControllerTooltipVisible()
|
|
||||||
{
|
|
||||||
return mItemView->isControllerTooltipVisible();
|
|
||||||
}
|
|
||||||
|
|
||||||
ControllerButtonStr* InventoryWindow::getControllerButtons()
|
ControllerButtonStr* InventoryWindow::getControllerButtons()
|
||||||
{
|
{
|
||||||
switch (mGuiMode)
|
switch (mGuiMode)
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,6 @@ namespace MWGui
|
||||||
std::string_view getWindowIdForLua() const override { return "Inventory"; }
|
std::string_view getWindowIdForLua() const override { return "Inventory"; }
|
||||||
|
|
||||||
ControllerButtonStr* getControllerButtons() override;
|
ControllerButtonStr* getControllerButtons() override;
|
||||||
bool isControllerTooltipVisible();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void onTitleDoubleClicked() override;
|
void onTitleDoubleClicked() override;
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ namespace MWGui
|
||||||
|
|
||||||
if (Settings::gui().mControllerMenus)
|
if (Settings::gui().mControllerMenus)
|
||||||
{
|
{
|
||||||
mControllerTooltip = false;
|
MWBase::Environment::get().getWindowManager()->setControllerTooltip(false);
|
||||||
mControllerFocus = std::clamp(mControllerFocus, 0, mItemCount - 1);
|
mControllerFocus = std::clamp(mControllerFocus, 0, mItemCount - 1);
|
||||||
updateControllerFocus(-1, mControllerFocus);
|
updateControllerFocus(-1, mControllerFocus);
|
||||||
}
|
}
|
||||||
|
|
@ -190,10 +190,11 @@ namespace MWGui
|
||||||
{
|
{
|
||||||
mControllerActiveWindow = active;
|
mControllerActiveWindow = active;
|
||||||
|
|
||||||
if (mControllerTooltip)
|
MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager();
|
||||||
|
if (winMgr->getControllerTooltip())
|
||||||
{
|
{
|
||||||
MWBase::Environment::get().getWindowManager()->setCursorActive(false);
|
winMgr->setCursorActive(false);
|
||||||
mControllerTooltip = false;
|
winMgr->setControllerTooltip(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (active)
|
if (active)
|
||||||
|
|
@ -221,7 +222,8 @@ namespace MWGui
|
||||||
else if (button == SDL_CONTROLLER_BUTTON_RIGHTSTICK)
|
else if (button == SDL_CONTROLLER_BUTTON_RIGHTSTICK)
|
||||||
{
|
{
|
||||||
// Toggle info tooltip
|
// Toggle info tooltip
|
||||||
mControllerTooltip = !mControllerTooltip;
|
MWBase::Environment::get().getWindowManager()->setControllerTooltip(
|
||||||
|
!MWBase::Environment::get().getWindowManager()->getControllerTooltip());
|
||||||
updateControllerFocus(-1, mControllerFocus);
|
updateControllerFocus(-1, mControllerFocus);
|
||||||
}
|
}
|
||||||
else if (button == SDL_CONTROLLER_BUTTON_DPAD_UP)
|
else if (button == SDL_CONTROLLER_BUTTON_DPAD_UP)
|
||||||
|
|
@ -250,10 +252,15 @@ namespace MWGui
|
||||||
|
|
||||||
if (prevFocus != mControllerFocus)
|
if (prevFocus != mControllerFocus)
|
||||||
updateControllerFocus(prevFocus, mControllerFocus);
|
updateControllerFocus(prevFocus, mControllerFocus);
|
||||||
|
else
|
||||||
|
updateControllerFocus(-1, mControllerFocus);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemView::updateControllerFocus(int prevFocus, int newFocus)
|
void ItemView::updateControllerFocus(int prevFocus, int newFocus)
|
||||||
{
|
{
|
||||||
|
MWBase::Environment::get().getWindowManager()->setCursorVisible(
|
||||||
|
!MWBase::Environment::get().getWindowManager()->getControllerTooltip());
|
||||||
|
|
||||||
if (!mItemCount)
|
if (!mItemCount)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -272,8 +279,6 @@ namespace MWGui
|
||||||
if (focused)
|
if (focused)
|
||||||
{
|
{
|
||||||
focused->setControllerFocus(true);
|
focused->setControllerFocus(true);
|
||||||
if (mControllerTooltip)
|
|
||||||
MWBase::Environment::get().getInputManager()->warpMouseToWidget(focused);
|
|
||||||
|
|
||||||
// Scroll the list to keep the active item in view
|
// Scroll the list to keep the active item in view
|
||||||
int column = newFocus / mRows;
|
int column = newFocus / mRows;
|
||||||
|
|
@ -281,6 +286,9 @@ namespace MWGui
|
||||||
mScrollView->setViewOffset(MyGUI::IntPoint(0, 0));
|
mScrollView->setViewOffset(MyGUI::IntPoint(0, 0));
|
||||||
else
|
else
|
||||||
mScrollView->setViewOffset(MyGUI::IntPoint(-42 * (column - 3), 0));
|
mScrollView->setViewOffset(MyGUI::IntPoint(-42 * (column - 3), 0));
|
||||||
|
|
||||||
|
if (MWBase::Environment::get().getWindowManager()->getControllerTooltip())
|
||||||
|
MWBase::Environment::get().getInputManager()->warpMouseToWidget(focused);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,6 @@ namespace MWGui
|
||||||
void setActiveControllerWindow(bool active);
|
void setActiveControllerWindow(bool active);
|
||||||
int getControllerFocus() { return mControllerFocus; }
|
int getControllerFocus() { return mControllerFocus; }
|
||||||
int getItemCount() { return mItemCount; }
|
int getItemCount() { return mItemCount; }
|
||||||
bool isControllerTooltipVisible() { return mControllerTooltip; }
|
|
||||||
void onControllerButton(const unsigned char button);
|
void onControllerButton(const unsigned char button);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -56,7 +55,6 @@ namespace MWGui
|
||||||
int mItemCount = 0;
|
int mItemCount = 0;
|
||||||
int mRows;
|
int mRows;
|
||||||
int mControllerFocus = 0;
|
int mControllerFocus = 0;
|
||||||
bool mControllerTooltip;
|
|
||||||
bool mControllerActiveWindow;
|
bool mControllerActiveWindow;
|
||||||
void updateControllerFocus(int prevFocus, int newFocus);
|
void updateControllerFocus(int prevFocus, int newFocus);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ namespace MWGui
|
||||||
|
|
||||||
if (guiMode)
|
if (guiMode)
|
||||||
{
|
{
|
||||||
if (!winMgr->getCursorVisible())
|
if (!winMgr->getCursorVisible() && !winMgr->getControllerTooltip())
|
||||||
return;
|
return;
|
||||||
const MyGUI::IntPoint& mousePos = MyGUI::InputManager::getInstance().getMousePosition();
|
const MyGUI::IntPoint& mousePos = MyGUI::InputManager::getInstance().getMousePosition();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -941,6 +941,9 @@ namespace MWGui
|
||||||
|
|
||||||
void WindowManager::setActiveControllerWindow(GuiMode mode, int activeIndex)
|
void WindowManager::setActiveControllerWindow(GuiMode mode, int activeIndex)
|
||||||
{
|
{
|
||||||
|
if (!Settings::gui().mControllerMenus)
|
||||||
|
return;
|
||||||
|
|
||||||
int winCount = mGuiModeStates[mode].mWindows.size();
|
int winCount = mGuiModeStates[mode].mWindows.size();
|
||||||
if (winCount == 0)
|
if (winCount == 0)
|
||||||
return;
|
return;
|
||||||
|
|
@ -2590,6 +2593,14 @@ namespace MWGui
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WindowManager::setControllerTooltip(bool enabled)
|
||||||
|
{
|
||||||
|
if (!Settings::gui().mControllerMenus)
|
||||||
|
return;
|
||||||
|
|
||||||
|
mControllerTooltip = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
void WindowManager::updateControllerButtonsOverlay()
|
void WindowManager::updateControllerButtonsOverlay()
|
||||||
{
|
{
|
||||||
if (!Settings::gui().mControllerMenus || !mControllerButtonsOverlay)
|
if (!Settings::gui().mControllerMenus || !mControllerButtonsOverlay)
|
||||||
|
|
|
||||||
|
|
@ -396,6 +396,8 @@ namespace MWGui
|
||||||
WindowBase* getActiveControllerWindow() override;
|
WindowBase* getActiveControllerWindow() override;
|
||||||
void cycleActiveControllerWindow(bool next) override;
|
void cycleActiveControllerWindow(bool next) override;
|
||||||
void setActiveControllerWindow(GuiMode mode, int activeIndex) override;
|
void setActiveControllerWindow(GuiMode mode, int activeIndex) override;
|
||||||
|
const bool getControllerTooltip() const override { return mControllerTooltip; }
|
||||||
|
void setControllerTooltip(bool enabled) override;
|
||||||
void updateControllerButtonsOverlay() override;
|
void updateControllerButtonsOverlay() override;
|
||||||
|
|
||||||
// Used in Lua bindings
|
// Used in Lua bindings
|
||||||
|
|
@ -508,6 +510,7 @@ namespace MWGui
|
||||||
std::vector<GuiMode> mGuiModes;
|
std::vector<GuiMode> mGuiModes;
|
||||||
// The active window for controller mode for each GUI mode.
|
// The active window for controller mode for each GUI mode.
|
||||||
std::map<GuiMode, int> mActiveControllerWindows;
|
std::map<GuiMode, int> mActiveControllerWindows;
|
||||||
|
bool mControllerTooltip;
|
||||||
|
|
||||||
std::unique_ptr<SDLUtil::SDLCursorManager> mCursorManager;
|
std::unique_ptr<SDLUtil::SDLCursorManager> mCursorManager;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -257,8 +257,7 @@ namespace MWInput
|
||||||
// act like a mouse button; it should act normally.
|
// act like a mouse button; it should act normally.
|
||||||
if (treatAsMouse
|
if (treatAsMouse
|
||||||
&& arg.button == SDL_CONTROLLER_BUTTON_A
|
&& arg.button == SDL_CONTROLLER_BUTTON_A
|
||||||
&& (MWGui::InventoryWindow *)topWin == winMgr->getInventoryWindow()
|
&& winMgr->getControllerTooltip())
|
||||||
&& ((MWGui::InventoryWindow *)topWin)->isControllerTooltipVisible())
|
|
||||||
treatAsMouse = false;
|
treatAsMouse = false;
|
||||||
|
|
||||||
mGamepadGuiCursorEnabled = topWin->isGamepadCursorAllowed();
|
mGamepadGuiCursorEnabled = topWin->isGamepadCursorAllowed();
|
||||||
|
|
@ -363,6 +362,11 @@ namespace MWInput
|
||||||
&& (arg.axis == SDL_CONTROLLER_AXIS_LEFTX || arg.axis == SDL_CONTROLLER_AXIS_LEFTY))
|
&& (arg.axis == SDL_CONTROLLER_AXIS_LEFTX || arg.axis == SDL_CONTROLLER_AXIS_LEFTY))
|
||||||
{
|
{
|
||||||
// Treat the left stick like a cursor, which is the default behavior.
|
// Treat the left stick like a cursor, which is the default behavior.
|
||||||
|
if (winMgr->getControllerTooltip())
|
||||||
|
{
|
||||||
|
winMgr->setControllerTooltip(false);
|
||||||
|
winMgr->setCursorVisible(true);
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -266,8 +266,8 @@ namespace MWInput
|
||||||
|
|
||||||
void MouseManager::warpMouseToWidget(MyGUI::Widget* widget)
|
void MouseManager::warpMouseToWidget(MyGUI::Widget* widget)
|
||||||
{
|
{
|
||||||
float widgetX = widget->getAbsoluteCoord().left + 4;
|
float widgetX = widget->getAbsoluteCoord().left + widget->getWidth() / 2;
|
||||||
float widgetY = widget->getAbsoluteCoord().top + 4;
|
float widgetY = widget->getAbsoluteCoord().top + widget->getHeight() - 30;
|
||||||
if (std::abs(mGuiCursorX - widgetX) > 1 || std::abs(mGuiCursorY - widgetY) > 1)
|
if (std::abs(mGuiCursorX - widgetX) > 1 || std::abs(mGuiCursorY - widgetY) > 1)
|
||||||
{
|
{
|
||||||
mGuiCursorX = widgetX;
|
mGuiCursorX = widgetX;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue