Skip to content

An OpenMW mod that lets you play the whole Elder Scrolls III: Morrowind as a top-down isometric game — with full online co-op or MMO modes.

C++

Controller menus: D-pad left unassigned, a held D-pad repeats, the keyboard on the screen only for words

Alan Saunders5950810c8dc7
diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp
index 83791c3..02575ec 100644
--- a/apps/openmw/mwgui/windowmanagerimp.cpp
+++ b/apps/openmw/mwgui/windowmanagerimp.cpp
@@ -11,6 +11,7 @@
#include <osgViewer/Viewer>
#include <MyGUI_ClipboardManager.h>
+#include <MyGUI_ComboBox.h>
#include <MyGUI_EditBox.h>
#include <MyGUI_FactoryManager.h>
#include <MyGUI_InputManager.h>
@@ -47,6 +48,7 @@
#include <components/vfs/manager.hpp>
+#include <components/widgets/numericeditbox.hpp>
#include <components/widgets/tags.hpp>
#include <components/widgets/widgets.hpp>
@@ -155,6 +157,22 @@ namespace MWGui
return nullptr;
}
}
+
+ // Isowind: whether the keyboard on the screen comes up by itself for a widget given the keyboard focus. Only
+ // for a box to type words into: not for a number (the count of items to take or buy is set with the D-pad), a
+ // drop-down list or text that can't be changed. Y still brings it up for those.
+ bool opensOnScreenKeyboard(MyGUI::Widget* widget)
+ {
+ if (LuaUi::WidgetExtension* luaWidget = dynamic_cast<LuaUi::WidgetExtension*>(widget))
+ return luaWidget->isTextInput();
+ MyGUI::EditBox* edit = widget->castType<MyGUI::EditBox>(false);
+ if (!edit || edit->getEditReadOnly() || edit->getEditStatic()
+ || widget->castType<Gui::NumericEditBox>(false))
+ return false;
+ if (MyGUI::ComboBox* comboBox = widget->castType<MyGUI::ComboBox>(false))
+ return !comboBox->getComboModeDrop();
+ return true;
+ }
}
WindowManager::WindowManager(SDL_Window* window, osgViewer::Viewer* viewer, osg::Group* guiRoot,
@@ -2031,7 +2049,7 @@ namespace MWGui
if (!capturesInput)
mOnScreenKeyboard->close();
else if (Settings::gui().mControllerMenus && isGuiMode() && mOnScreenKeyboard->getTarget() != widget
- && MWBase::Environment::get().getInputManager()->joystickLastUsed())
+ && MWBase::Environment::get().getInputManager()->joystickLastUsed() && opensOnScreenKeyboard(widget))
mOnScreenKeyboard->open();
}
diff --git a/apps/openmw/mwinput/bindingsmanager.cpp b/apps/openmw/mwinput/bindingsmanager.cpp
index 4003ed8..a4c3f3e 100644
--- a/apps/openmw/mwinput/bindingsmanager.cpp
+++ b/apps/openmw/mwinput/bindingsmanager.cpp
@@ -375,7 +375,7 @@ namespace MWInput
defaultButtonBindings[A_QuickKeyNext] = SDL_CONTROLLER_BUTTON_RIGHTSHOULDER;
defaultButtonBindings[A_ZoomIn] = SDL_CONTROLLER_BUTTON_DPAD_UP;
defaultButtonBindings[A_ZoomOut] = SDL_CONTROLLER_BUTTON_DPAD_DOWN;
- defaultButtonBindings[A_QuickKeysMenu] = SDL_CONTROLLER_BUTTON_DPAD_LEFT;
+ // D-pad left is left free for now (the quick keys menu is on F1)
defaultButtonBindings[A_Sneak] = SDL_CONTROLLER_BUTTON_LEFTSTICK;
defaultButtonBindings[A_Rest] = SDL_CONTROLLER_BUTTON_RIGHTSTICK;
defaultButtonBindings[A_Inventory] = SDL_CONTROLLER_BUTTON_BACK;
diff --git a/apps/openmw/mwinput/controllermanager.cpp b/apps/openmw/mwinput/controllermanager.cpp
index 08e1bd6..e9f6a72 100644
--- a/apps/openmw/mwinput/controllermanager.cpp
+++ b/apps/openmw/mwinput/controllermanager.cpp
@@ -17,8 +17,6 @@
#include "../mwbase/statemanager.hpp"
#include "../mwbase/windowmanager.hpp"
#include "../mwgui/windowbase.hpp"
-#include "../mwmp/GUIController.hpp"
-#include "../mwmp/Main.hpp"
#include "actions.hpp"
#include "bindingsmanager.hpp"
@@ -26,6 +24,20 @@
namespace MWInput
{
+ namespace
+ {
+ // Isowind: a D-pad direction held in a menu steps again after this long, then this often (as the left stick
+ // does on the keyboard on the screen). Real time: the game may be paused under a menu.
+ constexpr std::chrono::milliseconds sGuiRepeatDelay(400);
+ constexpr std::chrono::milliseconds sGuiRepeatInterval(100);
+
+ bool isDpadButton(Uint8 button)
+ {
+ return button == SDL_CONTROLLER_BUTTON_DPAD_UP || button == SDL_CONTROLLER_BUTTON_DPAD_DOWN
+ || button == SDL_CONTROLLER_BUTTON_DPAD_LEFT || button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT;
+ }
+ }
+
ControllerManager::ControllerManager(BindingsManager* bindingsManager, MouseManager* mouseManager,
const std::filesystem::path& userControllerBindingsFile, const std::filesystem::path& controllerBindingsFile)
: mBindingsManager(bindingsManager)
@@ -126,10 +138,15 @@ namespace MWInput
MWBase::Environment::get().getInputManager()->resetIdleTime();
}
}
+
+ updateGuiRepeat();
}
void ControllerManager::buttonPressed(int deviceID, const SDL_ControllerButtonEvent& arg)
{
+ // Isowind: another button pressed stops a D-pad direction repeating
+ mGuiRepeatButton = SDL_CONTROLLER_BUTTON_INVALID;
+
if (!Settings::input().mEnableController || mBindingsManager->isDetectingBindingState())
return;
@@ -140,7 +157,10 @@ namespace MWInput
if (MWBase::Environment::get().getWindowManager()->isGuiMode())
{
if (gamepadToGuiControl(arg))
+ {
+ startGuiRepeat(arg);
return;
+ }
if (mGamepadGuiCursorEnabled)
{
@@ -163,13 +183,7 @@ namespace MWInput
}
}
else
- {
- // Isowind multiplayer: D-pad left opens the chat, typed with the keyboard on the screen
- if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT && Settings::gui().mControllerMenus
- && mwmp::Main::isInitialized() && mwmp::Main::get().getGUIController()->openChatWithController())
- return;
mBindingsManager->setPlayerControlsEnabled(true);
- }
// esc, to leave initial movie screen
auto kc = SDLUtil::sdlKeyToMyGUI(SDLK_ESCAPE);
@@ -181,6 +195,9 @@ namespace MWInput
void ControllerManager::buttonReleased(int deviceID, const SDL_ControllerButtonEvent& arg)
{
+ if (arg.button == mGuiRepeatButton)
+ mGuiRepeatButton = SDL_CONTROLLER_BUTTON_INVALID;
+
if (mBindingsManager->isDetectingBindingState())
{
mBindingsManager->controllerButtonReleased(deviceID, arg);
@@ -261,7 +278,7 @@ namespace MWInput
mBindingsManager->controllerRemoved(arg);
}
- bool ControllerManager::gamepadToGuiControl(const SDL_ControllerButtonEvent& arg)
+ bool ControllerManager::gamepadToGuiControl(const SDL_ControllerButtonEvent& arg, bool repeat)
{
MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager();
@@ -364,10 +381,64 @@ namespace MWInput
if (SDL_IsTextInputActive())
return false;
- winMgr->injectKeyPress(key, 0, false);
+ winMgr->injectKeyPress(key, 0, repeat);
return true;
}
+ void ControllerManager::startGuiRepeat(const SDL_ControllerButtonEvent& arg)
+ {
+ if (!isDpadButton(arg.button))
+ return;
+
+ // MyGUI repeats a key it is given until a key is let go (the arrow keys the D-pad stands for, which also set
+ // the count of items to take or buy): the D-pad repeats here instead, at one pace in every menu
+ MyGUI::InputManager::getInstance().injectKeyRelease(MyGUI::KeyCode::None);
+
+ MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager();
+ if (!winMgr->isGuiMode())
+ return;
+ mGuiRepeatButton = arg.button;
+ mGuiRepeatController = arg.which;
+ mGuiRepeatWindow = winMgr->getActiveControllerWindow();
+ mGuiRepeatNext = std::chrono::steady_clock::now() + sGuiRepeatDelay;
+ }
+
+ void ControllerManager::updateGuiRepeat()
+ {
+ if (mGuiRepeatButton == SDL_CONTROLLER_BUTTON_INVALID)
+ return;
+
+ // Over once the direction is let go (its release can be missed), the menu is closed or another window has
+ // the controller (the keyboard on the screen has come up, a message box)
+ MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager();
+ SDL_GameController* controller = SDL_GameControllerFromInstanceID(mGuiRepeatController);
+ if (!controller
+ || !SDL_GameControllerGetButton(controller, static_cast<SDL_GameControllerButton>(mGuiRepeatButton))
+ || !Settings::input().mEnableController || mBindingsManager->isDetectingBindingState()
+ || !winMgr->isGuiMode() || winMgr->getActiveControllerWindow() != mGuiRepeatWindow)
+ {
+ mGuiRepeatButton = SDL_CONTROLLER_BUTTON_INVALID;
+ return;
+ }
+
+ const auto now = std::chrono::steady_clock::now();
+ if (now < mGuiRepeatNext)
+ return;
+ // From now, not from when it was due: a slow frame doesn't bring a burst of steps
+ mGuiRepeatNext = now + sGuiRepeatInterval;
+
+ // To the menu only, not to scripts or the key bindings (D-pad up and down zoom the camera)
+ SDL_ControllerButtonEvent event{};
+ event.type = SDL_CONTROLLERBUTTONDOWN;
+ event.which = mGuiRepeatController;
+ event.button = static_cast<Uint8>(mGuiRepeatButton);
+ event.state = SDL_PRESSED;
+ if (gamepadToGuiControl(event, true))
+ MyGUI::InputManager::getInstance().injectKeyRelease(MyGUI::KeyCode::None);
+ else
+ mGuiRepeatButton = SDL_CONTROLLER_BUTTON_INVALID;
+ }
+
bool ControllerManager::gamepadToGuiControl(const SDL_ControllerAxisEvent& arg)
{
const int triggerPressThreshold = Settings::gui().mControllerTriggerPressThreshold;
diff --git a/apps/openmw/mwinput/controllermanager.hpp b/apps/openmw/mwinput/controllermanager.hpp
index e5c1a93..e46f055 100644
--- a/apps/openmw/mwinput/controllermanager.hpp
+++ b/apps/openmw/mwinput/controllermanager.hpp
@@ -2,12 +2,18 @@
#define MWINPUT_MWCONTROLLERMANAGER_H
#include <array>
+#include <chrono>
#include <filesystem>
#include <string>
#include <components/sdlutil/events.hpp>
#include <components/settings/settings.hpp>
+namespace MWGui
+{
+ class WindowBase;
+}
+
namespace MWInput
{
class BindingsManager;
@@ -53,9 +59,13 @@ namespace MWInput
private:
// Return true if GUI consumes input.
- bool gamepadToGuiControl(const SDL_ControllerButtonEvent& arg);
+ bool gamepadToGuiControl(const SDL_ControllerButtonEvent& arg, bool repeat = false);
bool gamepadToGuiControl(const SDL_ControllerAxisEvent& arg);
+ // Isowind: a D-pad direction held in a menu steps again and again, as a held key does
+ void startGuiRepeat(const SDL_ControllerButtonEvent& arg);
+ void updateGuiRepeat();
+
void enableGyroSensor();
int getControllerType();
@@ -70,6 +80,14 @@ namespace MWInput
bool mGamepadMousePressed;
bool mLeftTriggerGuiPressed;
bool mRightTriggerGuiPressed;
+
+ // Isowind: the D-pad direction held in a menu (controller buttons don't repeat), the controller holding it,
+ // the window it steps in (only compared: a repeat stops if another window takes the controller) and when it
+ // steps next
+ int mGuiRepeatButton = SDL_CONTROLLER_BUTTON_INVALID;
+ SDL_JoystickID mGuiRepeatController = -1;
+ const MWGui::WindowBase* mGuiRepeatWindow = nullptr;
+ std::chrono::steady_clock::time_point mGuiRepeatNext;
};
}
#endif
diff --git a/apps/openmw/mwmp/GUIController.cpp b/apps/openmw/mwmp/GUIController.cpp
index 5ac18d6..1987186 100644
--- a/apps/openmw/mwmp/GUIController.cpp
+++ b/apps/openmw/mwmp/GUIController.cpp
@@ -249,6 +249,7 @@ void mwmp::GUIController::changeChatMode()
mChat->pressedChatMode();
}
+// No controller button opens the chat for now (D-pad left did); it is opened with the keyboard
bool mwmp::GUIController::openChatWithController()
{
MWBase::WindowManager* windowManager = MWBase::Environment::get().getWindowManager();
diff --git a/isowind/README.txt b/isowind/README.txt
index 127559c..7f21ed4 100644
--- a/isowind/README.txt
+++ b/isowind/README.txt
@@ -74,7 +74,7 @@ server\logs. Keep the same game (co-op or MMO) for a world: an MMO world switche
what each player looted, so it's all back.
In multiplayer
-Enter Talk in the chat (D-pad left on a controller, which brings up a keyboard on the screen);
+Enter Talk in the chat (with a keyboard; a controller has no button for it for now);
F2 hides or shows the chat window.
The world never pauses, not even in menus. Saving and loading are off: the server keeps everything.
When you die you wake up at the nearest temple.
@@ -120,7 +120,7 @@ A Jump B Ready weapon
X Use / talk Y Ready magic
Right trigger Attack / cast Left trigger Power attack
Bumpers Previous / next quick key D-pad up / down Zoom (hold to keep going)
-D-pad left Quick keys menu (on a server: the chat)
+D-pad left (nothing for now)
D-pad right Quest log Start Menu
Back Inventory (hold: journal)
Left stick in Sneak Right stick in Rest
diff --git a/isowind/profiles/input_v3.xml b/isowind/profiles/input_v3.xml
index f62a017..23ca47d 100644
--- a/isowind/profiles/input_v3.xml
+++ b/isowind/profiles/input_v3.xml
@@ -171,7 +171,6 @@
</Control>
<Control name="41" autoChangeDirectionOnLimitsAfterStop="false" autoReverseToInitialValue="true" initialValue="0" stepSize="MAX" stepsPerSeconds="MAX">
<KeyBinder key="58" direction="INCREASE" />
- <JoystickButtonBinder button="13" direction="INCREASE" deviceId="1" />
<Channel number="41" direction="DIRECT" percentage="1" />
</Control>
<Control name="42" autoChangeDirectionOnLimitsAfterStop="false" autoReverseToInitialValue="true" initialValue="0" stepSize="MAX" stepsPerSeconds="MAX">