mirror of
https://github.com/OpenMW/openmw.git
synced 2025-12-12 19:43:12 +00:00
Add basic controller support to scrolls
This commit is contained in:
parent
9a72ecb61c
commit
65bab3858a
2 changed files with 46 additions and 0 deletions
|
|
@ -7,6 +7,7 @@
|
|||
#include <components/widgets/imagebutton.hpp>
|
||||
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwbase/inputmanager.hpp"
|
||||
#include "../mwbase/windowmanager.hpp"
|
||||
|
||||
#include "../mwmechanics/actorutil.hpp"
|
||||
|
|
@ -28,9 +29,11 @@ namespace MWGui
|
|||
|
||||
getWidget(mCloseButton, "CloseButton");
|
||||
mCloseButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ScrollWindow::onCloseButtonClicked);
|
||||
trackFocusEvents(mCloseButton);
|
||||
|
||||
getWidget(mTakeButton, "TakeButton");
|
||||
mTakeButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ScrollWindow::onTakeButtonClicked);
|
||||
trackFocusEvents(mTakeButton);
|
||||
|
||||
adjustButton("CloseButton");
|
||||
adjustButton("TakeButton");
|
||||
|
|
@ -115,4 +118,44 @@ namespace MWGui
|
|||
|
||||
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Scroll);
|
||||
}
|
||||
|
||||
void ScrollWindow::onClose()
|
||||
{
|
||||
if (Settings::gui().mControllerMenus)
|
||||
MWBase::Environment::get().getInputManager()->setGamepadGuiCursorEnabled(true);
|
||||
BookWindowBase::onClose();
|
||||
}
|
||||
|
||||
bool ScrollWindow::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
|
||||
{
|
||||
if (arg.button == SDL_CONTROLLER_BUTTON_A)
|
||||
{
|
||||
if (mMouseFocus != nullptr)
|
||||
return false;
|
||||
|
||||
if (mTakeButton->getVisible())
|
||||
onTakeButtonClicked(mTakeButton);
|
||||
}
|
||||
else if (arg.button == SDL_CONTROLLER_BUTTON_B)
|
||||
onCloseButtonClicked(mCloseButton);
|
||||
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP)
|
||||
onKeyButtonPressed(nullptr, MyGUI::KeyCode::ArrowUp, 0);
|
||||
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
|
||||
onKeyButtonPressed(nullptr, MyGUI::KeyCode::ArrowDown, 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ScrollWindow::onControllerThumbstickEvent(const SDL_ControllerAxisEvent& arg)
|
||||
{
|
||||
if (arg.axis == SDL_CONTROLLER_AXIS_RIGHTY)
|
||||
{
|
||||
MWBase::Environment::get().getInputManager()->setGamepadGuiCursorEnabled(false);
|
||||
|
||||
int scroll = -30.0f * arg.value / 32767;
|
||||
mTextView->setViewOffset(mTextView->getViewOffset() + MyGUI::IntPoint(0, scroll));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ namespace MWGui
|
|||
void setPtr(const MWWorld::Ptr& scroll) override;
|
||||
void setInventoryAllowed(bool allowed);
|
||||
|
||||
void onClose() override;
|
||||
void onResChange(int, int) override { center(); }
|
||||
|
||||
std::string_view getWindowIdForLua() const override { return "Scroll"; }
|
||||
|
|
@ -29,6 +30,8 @@ namespace MWGui
|
|||
void onTakeButtonClicked(MyGUI::Widget* _sender);
|
||||
void setTakeButtonShow(bool show);
|
||||
void onKeyButtonPressed(MyGUI::Widget* sender, MyGUI::KeyCode key, MyGUI::Char character);
|
||||
bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
|
||||
bool onControllerThumbstickEvent(const SDL_ControllerAxisEvent& arg) override;
|
||||
|
||||
private:
|
||||
Gui::ImageButton* mCloseButton;
|
||||
|
|
|
|||
Loading…
Reference in a new issue