mirror of
https://github.com/OpenMW/openmw.git
synced 2025-12-08 23:04:30 +00:00
Add controller support to message boxes
This commit is contained in:
parent
80166cddd0
commit
3b42d02cfc
2 changed files with 53 additions and 0 deletions
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include <components/debug/debuglog.hpp>
|
#include <components/debug/debuglog.hpp>
|
||||||
#include <components/misc/strings/algorithm.hpp>
|
#include <components/misc/strings/algorithm.hpp>
|
||||||
|
#include <components/settings/values.hpp>
|
||||||
|
|
||||||
#include "../mwbase/environment.hpp"
|
#include "../mwbase/environment.hpp"
|
||||||
#include "../mwbase/inputmanager.hpp"
|
#include "../mwbase/inputmanager.hpp"
|
||||||
|
|
@ -259,6 +260,7 @@ namespace MWGui
|
||||||
button->setCaptionWithReplacing(buttonId);
|
button->setCaptionWithReplacing(buttonId);
|
||||||
|
|
||||||
button->eventMouseButtonClick += MyGUI::newDelegate(this, &InteractiveMessageBox::mousePressed);
|
button->eventMouseButtonClick += MyGUI::newDelegate(this, &InteractiveMessageBox::mousePressed);
|
||||||
|
trackFocusEvents(button);
|
||||||
|
|
||||||
mButtons.push_back(button);
|
mButtons.push_back(button);
|
||||||
|
|
||||||
|
|
@ -280,6 +282,12 @@ namespace MWGui
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Settings::gui().mControllerMenus && mButtons.size() > 1)
|
||||||
|
{
|
||||||
|
// If we have more than one button, we need to set the focus to the first one.
|
||||||
|
mButtons[0]->setStateSelected(true);
|
||||||
|
}
|
||||||
|
|
||||||
MyGUI::IntSize mainWidgetSize;
|
MyGUI::IntSize mainWidgetSize;
|
||||||
if (buttonsWidth < textSize.width)
|
if (buttonsWidth < textSize.width)
|
||||||
{
|
{
|
||||||
|
|
@ -431,4 +439,46 @@ namespace MWGui
|
||||||
return mButtonPressed;
|
return mButtonPressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool InteractiveMessageBox::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
|
||||||
|
{
|
||||||
|
if (arg.button == SDL_CONTROLLER_BUTTON_A)
|
||||||
|
{
|
||||||
|
if (mMouseFocus != nullptr)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
buttonActivated(mButtons[mControllerFocus]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (arg.button == SDL_CONTROLLER_BUTTON_B)
|
||||||
|
{
|
||||||
|
if (mButtons.size() == 1)
|
||||||
|
buttonActivated(mButtons[0]);
|
||||||
|
}
|
||||||
|
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT)
|
||||||
|
{
|
||||||
|
if (mButtons.size() > 1)
|
||||||
|
{
|
||||||
|
mButtons[mControllerFocus]->setStateSelected(false);
|
||||||
|
if (mControllerFocus == 0)
|
||||||
|
mControllerFocus = mButtons.size() - 1;
|
||||||
|
else
|
||||||
|
mControllerFocus--;
|
||||||
|
mButtons[mControllerFocus]->setStateSelected(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT)
|
||||||
|
{
|
||||||
|
if (mButtons.size() > 1)
|
||||||
|
{
|
||||||
|
mButtons[mControllerFocus]->setStateSelected(false);
|
||||||
|
if (mControllerFocus == mButtons.size() - 1)
|
||||||
|
mControllerFocus = 0;
|
||||||
|
else
|
||||||
|
mControllerFocus++;
|
||||||
|
mButtons[mControllerFocus]->setStateSelected(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -103,6 +103,8 @@ namespace MWGui
|
||||||
|
|
||||||
bool mMarkedToDelete;
|
bool mMarkedToDelete;
|
||||||
|
|
||||||
|
bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void buttonActivated(MyGUI::Widget* _widget);
|
void buttonActivated(MyGUI::Widget* _widget);
|
||||||
|
|
||||||
|
|
@ -114,6 +116,7 @@ namespace MWGui
|
||||||
int mButtonPressed;
|
int mButtonPressed;
|
||||||
int mDefaultFocus;
|
int mDefaultFocus;
|
||||||
bool mImmediate;
|
bool mImmediate;
|
||||||
|
int mControllerFocus = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue