mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-09-18 17:07:37 -04:00
Add first batch of controller-enabled windows
This commit is contained in:
parent
71aa11404c
commit
a8824b46a8
@ -12,6 +12,7 @@
|
||||
#include <MyGUI_KeyCode.h>
|
||||
|
||||
#include "../mwgui/mode.hpp"
|
||||
#include "../mwgui/windowbase.hpp"
|
||||
|
||||
#include <components/sdlutil/events.hpp>
|
||||
|
||||
@ -381,6 +382,8 @@ namespace MWBase
|
||||
/// Same as viewer->getCamera()->getCullMask(), provided for consistency.
|
||||
virtual uint32_t getCullMask() = 0;
|
||||
|
||||
virtual MWGui::WindowBase* getTopWindow() = 0;
|
||||
|
||||
// Used in Lua bindings
|
||||
virtual const std::vector<MWGui::GuiMode>& getGuiModeStack() const = 0;
|
||||
virtual void setDisabledByLua(std::string_view windowId, bool disabled) = 0;
|
||||
|
@ -17,6 +17,8 @@ namespace MWGui
|
||||
|
||||
mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ConfirmationDialog::onCancelButtonClicked);
|
||||
mOkButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ConfirmationDialog::onOkButtonClicked);
|
||||
|
||||
trackFocusEvents(mCancelButton);
|
||||
}
|
||||
|
||||
void ConfirmationDialog::askForConfirmation(const std::string& message)
|
||||
@ -56,4 +58,19 @@ namespace MWGui
|
||||
|
||||
eventOkClicked();
|
||||
}
|
||||
|
||||
bool ConfirmationDialog::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
|
||||
{
|
||||
if (arg.button == SDL_CONTROLLER_BUTTON_A)
|
||||
{
|
||||
if (mMouseFocus != nullptr)
|
||||
return false;
|
||||
|
||||
onOkButtonClicked(mOkButton);
|
||||
}
|
||||
else if (arg.button == SDL_CONTROLLER_BUTTON_B)
|
||||
onCancelButtonClicked(mCancelButton);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,8 @@ namespace MWGui
|
||||
|
||||
void onCancelButtonClicked(MyGUI::Widget* _sender);
|
||||
void onOkButtonClicked(MyGUI::Widget* _sender);
|
||||
|
||||
bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "mainmenu.hpp"
|
||||
|
||||
#include <MyGUI_Gui.h>
|
||||
#include <MyGUI_InputManager.h>
|
||||
#include <MyGUI_RenderManager.h>
|
||||
#include <MyGUI_TextBox.h>
|
||||
|
||||
@ -163,9 +164,7 @@ namespace MWGui
|
||||
const std::string& name = *sender->getUserData<std::string>();
|
||||
winMgr->playSound(ESM::RefId::stringRefId("Menu Click"));
|
||||
if (name == "return")
|
||||
{
|
||||
winMgr->removeGuiMode(GM_MainMenu);
|
||||
}
|
||||
else if (name == "credits")
|
||||
winMgr->playVideo("mw_credits.bik", true);
|
||||
else if (name == "exitgame")
|
||||
@ -208,6 +207,34 @@ namespace MWGui
|
||||
}
|
||||
}
|
||||
|
||||
bool MainMenu::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
|
||||
{
|
||||
// REMOVEME
|
||||
Log(Debug::Verbose) << "MainMenu::onControllerButtonEvent " << arg.button;
|
||||
|
||||
MyGUI::KeyCode key = MyGUI::KeyCode::None;
|
||||
switch (arg.button)
|
||||
{
|
||||
case SDL_CONTROLLER_BUTTON_DPAD_UP:
|
||||
MyGUI::InputManager::getInstance().injectKeyPress(MyGUI::KeyCode::LeftShift);
|
||||
MWBase::Environment::get().getWindowManager()->injectKeyPress(MyGUI::KeyCode::Tab, 0, false);
|
||||
MyGUI::InputManager::getInstance().injectKeyRelease(MyGUI::KeyCode::LeftShift);
|
||||
return true;
|
||||
case SDL_CONTROLLER_BUTTON_DPAD_DOWN:
|
||||
key = MyGUI::KeyCode::Tab;
|
||||
break;
|
||||
case SDL_CONTROLLER_BUTTON_A:
|
||||
key = MyGUI::KeyCode::Space;
|
||||
break;
|
||||
case SDL_CONTROLLER_BUTTON_B:
|
||||
case SDL_CONTROLLER_BUTTON_START:
|
||||
onButtonClicked(mButtons["return"]);
|
||||
return true;
|
||||
}
|
||||
MWBase::Environment::get().getWindowManager()->injectKeyPress(key, 0, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
void MainMenu::showBackground(bool show)
|
||||
{
|
||||
if (mVideo && !show)
|
||||
|
@ -49,6 +49,7 @@ namespace MWGui
|
||||
MainMenu(int w, int h, const VFS::Manager* vfs, const std::string& versionDescription);
|
||||
|
||||
void onResChange(int w, int h) override;
|
||||
bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
|
||||
|
||||
void setVisible(bool visible) override;
|
||||
|
||||
|
@ -80,6 +80,10 @@ namespace MWGui
|
||||
mTimeAdvancer.eventProgressChanged += MyGUI::newDelegate(this, &WaitDialog::onWaitingProgressChanged);
|
||||
mTimeAdvancer.eventInterrupted += MyGUI::newDelegate(this, &WaitDialog::onWaitingInterrupted);
|
||||
mTimeAdvancer.eventFinished += MyGUI::newDelegate(this, &WaitDialog::onWaitingFinished);
|
||||
|
||||
trackFocusEvents(mUntilHealedButton);
|
||||
trackFocusEvents(mWaitButton);
|
||||
trackFocusEvents(mCancelButton);
|
||||
}
|
||||
|
||||
void WaitDialog::setPtr(const MWWorld::Ptr& ptr)
|
||||
@ -326,6 +330,27 @@ namespace MWGui
|
||||
}
|
||||
}
|
||||
|
||||
bool WaitDialog::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
|
||||
{
|
||||
if (arg.button == SDL_CONTROLLER_BUTTON_A)
|
||||
{
|
||||
if (mMouseFocus != nullptr)
|
||||
return false;
|
||||
|
||||
onWaitButtonClicked(mWaitButton);
|
||||
}
|
||||
else if (arg.button == SDL_CONTROLLER_BUTTON_B)
|
||||
onCancelButtonClicked(mCancelButton);
|
||||
else if (arg.button == SDL_CONTROLLER_BUTTON_X && mUntilHealedButton->getVisible())
|
||||
onUntilHealedButtonClicked(mUntilHealedButton);
|
||||
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT)
|
||||
MWBase::Environment::get().getWindowManager()->injectKeyPress(MyGUI::KeyCode::ArrowDown, 0, false);
|
||||
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT)
|
||||
MWBase::Environment::get().getWindowManager()->injectKeyPress(MyGUI::KeyCode::ArrowUp, 0, false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void WaitDialog::stopWaiting()
|
||||
{
|
||||
MWBase::Environment::get().getWindowManager()->fadeScreenIn(0.2f);
|
||||
|
@ -36,6 +36,7 @@ namespace MWGui
|
||||
void clear() override;
|
||||
|
||||
void onFrame(float dt) override;
|
||||
bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
|
||||
|
||||
bool getSleeping() { return mTimeAdvancer.isRunning() && mSleeping; }
|
||||
void wakeUp();
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwbase/windowmanager.hpp"
|
||||
|
||||
#include <components/settings/values.hpp>
|
||||
#include <components/widgets/imagebutton.hpp>
|
||||
|
||||
#include "draganddrop.hpp"
|
||||
@ -105,6 +106,30 @@ void WindowBase::clampWindowCoordinates(MyGUI::Window* window)
|
||||
window->setPosition(left, top);
|
||||
}
|
||||
|
||||
void WindowBase::focusGain(MyGUI::Widget* _new, MyGUI::Widget* _old)
|
||||
{
|
||||
// REMOVEME
|
||||
Log(Debug::Verbose) << "WindowBase::focusGain new=" << _new << ", old=" << _old;
|
||||
mMouseFocus = _new;
|
||||
}
|
||||
|
||||
void WindowBase::focusLoss(MyGUI::Widget* _old, MyGUI::Widget* _new)
|
||||
{
|
||||
// REMOVEME
|
||||
Log(Debug::Verbose) << "WindowBase::focusLoss old=" << _old << ", new=" << _new;
|
||||
if (mMouseFocus == _old)
|
||||
mMouseFocus = nullptr;
|
||||
}
|
||||
|
||||
void WindowBase::trackFocusEvents(MyGUI::Widget* widget)
|
||||
{
|
||||
if (!Settings::gui().mControllerMenus)
|
||||
return;
|
||||
|
||||
widget->eventMouseSetFocus += MyGUI::newDelegate(this, &WindowBase::focusGain);
|
||||
widget->eventMouseLostFocus += MyGUI::newDelegate(this, &WindowBase::focusLoss);
|
||||
}
|
||||
|
||||
WindowModal::WindowModal(const std::string& parLayout)
|
||||
: WindowBase(parLayout)
|
||||
{
|
||||
|
@ -1,6 +1,8 @@
|
||||
#ifndef MWGUI_WINDOW_BASE_H
|
||||
#define MWGUI_WINDOW_BASE_H
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
#include "layout.hpp"
|
||||
|
||||
namespace MWWorld
|
||||
@ -54,13 +56,26 @@ namespace MWGui
|
||||
|
||||
static void clampWindowCoordinates(MyGUI::Window* window);
|
||||
|
||||
/// Called by controllermanager to handle controller events
|
||||
virtual bool onControllerButtonEvent(const SDL_ControllerButtonEvent& 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;
|
||||
|
||||
protected:
|
||||
virtual void onTitleDoubleClicked();
|
||||
|
||||
MyGUI::Widget* mMouseFocus = nullptr;
|
||||
void trackFocusEvents(MyGUI::Widget* widget);
|
||||
|
||||
private:
|
||||
void onDoubleClick(MyGUI::Widget* _sender);
|
||||
|
||||
bool mDisabledByLua = false;
|
||||
|
||||
void focusGain(MyGUI::Widget* _new, MyGUI::Widget* _old);
|
||||
void focusLoss(MyGUI::Widget* _old, MyGUI::Widget* _new);
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -859,6 +859,40 @@ namespace MWGui
|
||||
mHud->setPlayerPos(x, y, u, v);
|
||||
}
|
||||
|
||||
WindowBase* WindowManager::getTopWindow()
|
||||
{
|
||||
if (!mCurrentModals.empty())
|
||||
return mCurrentModals.back();
|
||||
|
||||
if (isSettingsWindowVisible())
|
||||
return mSettingsWindow;
|
||||
|
||||
if (!mGuiModes.empty())
|
||||
{
|
||||
GuiModeState& state = mGuiModeStates[mGuiModes.back()];
|
||||
// REMOVEME
|
||||
Log(Debug::Error) << "getTopWindow: " << state.mWindows.size() << " windows in state " << mGuiModes.back();
|
||||
// find the topmost window
|
||||
for (WindowBase* window : state.mWindows)
|
||||
if (window->isVisible())
|
||||
return window;
|
||||
else
|
||||
Log(Debug::Error) << "-- Skipping hidden window " << window;
|
||||
}
|
||||
else
|
||||
{
|
||||
// return pinned windows if visible
|
||||
// REMOVEME
|
||||
Log(Debug::Error) << "getTopWindow: " << mGuiModeStates[GM_Inventory].mWindows.size() << " pinned windows";
|
||||
for (WindowBase* window : mGuiModeStates[GM_Inventory].mWindows)
|
||||
if (window->isVisible())
|
||||
return window;
|
||||
else
|
||||
Log(Debug::Error) << "-- Skipping hidden window " << window;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void WindowManager::update(float frameDuration)
|
||||
{
|
||||
handleScheduledMessageBoxes();
|
||||
|
@ -387,6 +387,8 @@ namespace MWGui
|
||||
|
||||
void asyncPrepareSaveMap() override;
|
||||
|
||||
WindowBase* getTopWindow() override;
|
||||
|
||||
// Used in Lua bindings
|
||||
const std::vector<GuiMode>& getGuiModeStack() const override { return mGuiModes; }
|
||||
void setDisabledByLua(std::string_view windowId, bool disabled) override;
|
||||
|
@ -241,6 +241,12 @@ namespace MWInput
|
||||
|
||||
bool ControllerManager::gamepadToGuiControl(const SDL_ControllerButtonEvent& arg)
|
||||
{
|
||||
if (Settings::gui().mControllerMenus)
|
||||
{
|
||||
MWGui::WindowBase* topWin = MWBase::Environment::get().getWindowManager()->getTopWindow();
|
||||
return topWin && topWin->onControllerButtonEvent(arg);
|
||||
}
|
||||
|
||||
// Presumption of GUI mode will be removed in the future.
|
||||
// MyGUI KeyCodes *may* change.
|
||||
MyGUI::KeyCode key = MyGUI::KeyCode::None;
|
||||
@ -302,6 +308,12 @@ namespace MWInput
|
||||
|
||||
bool ControllerManager::gamepadToGuiControl(const SDL_ControllerAxisEvent& arg)
|
||||
{
|
||||
if (Settings::gui().mControllerMenus)
|
||||
{
|
||||
MWGui::WindowBase* topWin = MWBase::Environment::get().getWindowManager()->getTopWindow();
|
||||
return topWin && topWin->onControllerThumbstickEvent(arg);
|
||||
}
|
||||
|
||||
switch (arg.axis)
|
||||
{
|
||||
case SDL_CONTROLLER_AXIS_TRIGGERRIGHT:
|
||||
|
Loading…
x
Reference in New Issue
Block a user