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: a keyboard on the screen, Options by D-pad, the multiplayer chat and dialogs with a controller

Alan Saunders7b1dc9e41044
diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt
index fac1b9b..41f0c8d 100644
--- a/apps/openmw/CMakeLists.txt
+++ b/apps/openmw/CMakeLists.txt
@@ -45,6 +45,7 @@ add_openmw_dir (mwgui
recharge mode videowidget backgroundimage itemwidget screenfader debugwindow spellmodel spellview
draganddrop timeadvancer jailscreen itemchargeview keyboardnavigation textcolours statswatcher
postprocessorhud settings worlditemmodel itemtransfer controllerbuttonsoverlay inventorytabsoverlay
+ onscreenkeyboard
)
add_openmw_dir (mwdialogue
diff --git a/apps/openmw/mwbase/inputmanager.hpp b/apps/openmw/mwbase/inputmanager.hpp
index 400189c..df12ebd 100644
--- a/apps/openmw/mwbase/inputmanager.hpp
+++ b/apps/openmw/mwbase/inputmanager.hpp
@@ -66,7 +66,8 @@ namespace MWBase
virtual float getControllerAxisValue(SDL_GameControllerAxis axis) const = 0; // returns value in range [-1, 1]
virtual int getMouseMoveX() const = 0;
virtual int getMouseMoveY() const = 0;
- virtual void warpMouseToWidget(MyGUI::Widget* widget) = 0;
+ /// Puts the pointer on the widget: across its middle, yFraction of the way down it
+ virtual void warpMouseToWidget(MyGUI::Widget* widget, float yFraction = 0.25f) = 0;
/// Actions available for binding to keyboard buttons
virtual const std::initializer_list<int>& getActionKeySorting() = 0;
diff --git a/apps/openmw/mwbase/windowmanager.hpp b/apps/openmw/mwbase/windowmanager.hpp
index e95e42c..88024b6 100644
--- a/apps/openmw/mwbase/windowmanager.hpp
+++ b/apps/openmw/mwbase/windowmanager.hpp
@@ -431,6 +431,10 @@ namespace MWBase
/// Restore tooltip visibility if user has them enabled but they were hidden by mouse movement
virtual void restoreControllerTooltips() = 0;
virtual void updateControllerButtonsOverlay() = 0;
+ /// Isowind: the keyboard on the screen, for typing with a controller
+ virtual bool isOnScreenKeyboardVisible() const = 0;
+ /// Isowind: brings it up for the text box that has the keyboard focus
+ virtual void openOnScreenKeyboard() = 0;
// Used in Lua bindings
virtual const std::vector<MWGui::GuiMode>& getGuiModeStack() const = 0;
diff --git a/apps/openmw/mwgui/onscreenkeyboard.cpp b/apps/openmw/mwgui/onscreenkeyboard.cpp
new file mode 100644
index 0000000..f423107
--- /dev/null
+++ b/apps/openmw/mwgui/onscreenkeyboard.cpp
@@ -0,0 +1,477 @@
+#include "onscreenkeyboard.hpp"
+
+#include <algorithm>
+#include <climits>
+#include <cmath>
+#include <cstdlib>
+#include <utility>
+
+#include <MyGUI_Button.h>
+#include <MyGUI_EditBox.h>
+#include <MyGUI_Gui.h>
+#include <MyGUI_InputManager.h>
+#include <MyGUI_RenderManager.h>
+#include <MyGUI_UString.h>
+#include <MyGUI_WidgetManager.h>
+
+#include <components/debug/debuglog.hpp>
+#include <components/esm/refid.hpp>
+
+#include "../mwbase/environment.hpp"
+#include "../mwbase/inputmanager.hpp"
+#include "../mwbase/windowmanager.hpp"
+
+namespace MWGui
+{
+ namespace
+ {
+ constexpr int sKeyWidth = 36;
+ constexpr int sKeyHeight = 30;
+ constexpr int sSpacing = 4;
+ constexpr int sMargin = 8;
+ // The button legend along the bottom of the screen (openmw_controllerbuttons.layout)
+ constexpr int sLegendHeight = 48;
+ // The left stick deflected this far picks the next key, and let go to this much releases it
+ constexpr float sStickOn = 0.55f;
+ constexpr float sStickOff = 0.3f;
+ constexpr float sRepeatDelay = 0.4f;
+ constexpr float sRepeatInterval = 0.1f;
+
+ // MyGUI reads # in a caption as the start of a colour code
+ std::string escapeCaption(const std::string& text)
+ {
+ std::string result;
+ for (const char c : text)
+ {
+ if (c == '#')
+ result += '#';
+ result += c;
+ }
+ return result;
+ }
+ }
+
+ OnScreenKeyboard::OnScreenKeyboard()
+ : WindowBase("openmw_onscreen_keyboard.layout")
+ {
+ getWidget(mKeysWidget, "Keys");
+ buildKeys();
+ refreshCaptions();
+
+ mDisableGamepadCursor = true;
+ mControllerButtons.mDpad = "#{Interface:Select}";
+ mControllerButtons.mA = "#{OMWEngine:KeyboardType}";
+ mControllerButtons.mB = "#{OMWEngine:KeyboardBackspace}";
+ mControllerButtons.mX = "#{OMWEngine:KeyboardSpace}";
+ mControllerButtons.mY = "#{OMWEngine:KeyboardShift}";
+ mControllerButtons.mView = "#{Interface:Done}";
+ mControllerButtons.mMenu = "#{Interface:Close}";
+
+ MyGUI::WidgetManager::getInstance().registerUnlinker(this);
+ }
+
+ OnScreenKeyboard::~OnScreenKeyboard()
+ {
+ try
+ {
+ MyGUI::WidgetManager::getInstance().unregisterUnlinker(this);
+ }
+ catch (const MyGUI::Exception& e)
+ {
+ Log(Debug::Error) << "Error in the destructor: " << e.what();
+ }
+ }
+
+ void OnScreenKeyboard::buildKeys()
+ {
+ // What each key types, plain and with shift, laid out like a US keyboard
+ const std::vector<std::vector<std::pair<std::string, std::string>>> rows = {
+ { { "`", "~" }, { "1", "!" }, { "2", "@" }, { "3", "#" }, { "4", "$" }, { "5", "%" }, { "6", "^" },
+ { "7", "&" }, { "8", "*" }, { "9", "(" }, { "0", ")" }, { "-", "_" }, { "=", "+" } },
+ { { "q", "Q" }, { "w", "W" }, { "e", "E" }, { "r", "R" }, { "t", "T" }, { "y", "Y" }, { "u", "U" },
+ { "i", "I" }, { "o", "O" }, { "p", "P" }, { "[", "{" }, { "]", "}" }, { "\\", "|" } },
+ { { "a", "A" }, { "s", "S" }, { "d", "D" }, { "f", "F" }, { "g", "G" }, { "h", "H" }, { "j", "J" },
+ { "k", "K" }, { "l", "L" }, { ";", ":" }, { "'", "\"" } },
+ { { "z", "Z" }, { "x", "X" }, { "c", "C" }, { "v", "V" }, { "b", "B" }, { "n", "N" }, { "m", "M" },
+ { ",", "<" }, { ".", ">" }, { "/", "?" } },
+ };
+ // The bottom row, in key widths
+ const std::vector<std::pair<Special, float>> specials = { { Special::Shift, 2.5f }, { Special::Space, 5.f },
+ { Special::Backspace, 2.5f }, { Special::Done, 2.5f } };
+
+ const auto widthOf = [](float keys) { return static_cast<int>(keys * sKeyWidth + (keys - 1) * sSpacing); };
+ const int rowWidth = widthOf(static_cast<float>(rows.front().size()));
+
+ const auto makeButton = [this](int left, int top, int width) {
+ MyGUI::Button* button = mKeysWidget->createWidget<MyGUI::Button>(
+ "MW_Button", MyGUI::IntCoord(left, top, width, sKeyHeight), MyGUI::Align::Default);
+ // Clicking a key mustn't take the keyboard focus from the text box
+ button->setNeedKeyFocus(false);
+ button->eventMouseButtonClick += MyGUI::newDelegate(this, &OnScreenKeyboard::onKeyClicked);
+ return button;
+ };
+
+ int top = 0;
+ for (const auto& rowKeys : rows)
+ {
+ std::vector<Key> row;
+ int left = (rowWidth - widthOf(static_cast<float>(rowKeys.size()))) / 2;
+ for (const auto& [lower, upper] : rowKeys)
+ {
+ Key key;
+ key.mLower = lower;
+ key.mUpper = upper;
+ key.mButton = makeButton(left, top, sKeyWidth);
+ row.push_back(std::move(key));
+ left += sKeyWidth + sSpacing;
+ }
+ mRows.push_back(std::move(row));
+ top += sKeyHeight + sSpacing;
+ }
+
+ int specialsWidth = -sSpacing;
+ for (const auto& [special, keys] : specials)
+ specialsWidth += widthOf(keys) + sSpacing;
+ std::vector<Key> row;
+ int left = (rowWidth - specialsWidth) / 2;
+ for (const auto& [special, keys] : specials)
+ {
+ Key key;
+ key.mSpecial = special;
+ key.mButton = makeButton(left, top, widthOf(keys));
+ row.push_back(std::move(key));
+ left += widthOf(keys) + sSpacing;
+ }
+ mRows.push_back(std::move(row));
+ const int height = top + sKeyHeight;
+
+ mKeysWidget->setCoord(sMargin, sMargin, rowWidth, height);
+ // The dialog's frame around that
+ const MyGUI::IntCoord client = mMainWidget->getClientCoord();
+ mMainWidget->setSize(rowWidth + 2 * sMargin + mMainWidget->getWidth() - client.width,
+ height + 2 * sMargin + mMainWidget->getHeight() - client.height);
+ }
+
+ void OnScreenKeyboard::refreshCaptions()
+ {
+ for (auto& row : mRows)
+ {
+ for (Key& key : row)
+ {
+ switch (key.mSpecial)
+ {
+ case Special::None:
+ key.mButton->setCaption(escapeCaption(mShift ? key.mUpper : key.mLower));
+ break;
+ case Special::Shift:
+ key.mButton->setCaptionWithReplacing(
+ mShift ? "#{OMWEngine:KeyboardShiftHeld}" : "#{OMWEngine:KeyboardShift}");
+ break;
+ case Special::Space:
+ key.mButton->setCaptionWithReplacing("#{OMWEngine:KeyboardSpace}");
+ break;
+ case Special::Backspace:
+ key.mButton->setCaptionWithReplacing("#{OMWEngine:KeyboardBackspace}");
+ break;
+ case Special::Done:
+ key.mButton->setCaptionWithReplacing("#{Interface:Done}");
+ break;
+ }
+ }
+ }
+ }
+
+ void OnScreenKeyboard::open()
+ {
+ MyGUI::Widget* focus = MyGUI::InputManager::getInstance().getKeyFocusWidget();
+ if (!focus)
+ return;
+ mTarget = focus;
+ mLastTarget = focus;
+ mShift = false;
+ mStickX = 0;
+ mStickY = 0;
+ mStickHeld = 0.f;
+ mStickRepeating = false;
+ refreshCaptions();
+ place();
+ setVisible(true);
+ setFocus(mRow, mColumn);
+ // The left stick picks keys now, not a mouse pointer
+ MWBase::Environment::get().getInputManager()->setGamepadGuiCursorEnabled(false);
+ MWBase::WindowManager* windowManager = MWBase::Environment::get().getWindowManager();
+ windowManager->setCursorActive(false);
+ windowManager->updateControllerButtonsOverlay();
+ }
+
+ void OnScreenKeyboard::close()
+ {
+ mTarget = nullptr;
+ if (!isVisible())
+ return;
+ setVisible(false);
+ MWBase::Environment::get().getWindowManager()->updateControllerButtonsOverlay();
+ }
+
+ void OnScreenKeyboard::place()
+ {
+ const MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize();
+ const MyGUI::IntSize size = mMainWidget->getSize();
+ const int left = std::max(0, (viewSize.width - size.width) / 2);
+ // Along the bottom, above the button legend; at the top instead if that would cover what is typed into
+ int top = viewSize.height - sLegendHeight - sMargin - size.height;
+ if (mTarget)
+ {
+ const MyGUI::IntCoord target = mTarget->getAbsoluteCoord();
+ if (target.bottom() > top && target.top < top + size.height)
+ top = sLegendHeight + sMargin;
+ }
+ mMainWidget->setPosition(left, std::max(0, top));
+ }
+
+ void OnScreenKeyboard::setFocus(int row, int column)
+ {
+ if (mRows.empty())
+ return;
+ if (mRow >= 0 && mRow < static_cast<int>(mRows.size()) && mColumn >= 0
+ && mColumn < static_cast<int>(mRows[mRow].size()))
+ mRows[mRow][mColumn].mButton->setStateSelected(false);
+ mRow = std::clamp(row, 0, static_cast<int>(mRows.size()) - 1);
+ mColumn = std::clamp(column, 0, static_cast<int>(mRows[mRow].size()) - 1);
+ mRows[mRow][mColumn].mButton->setStateSelected(true);
+ }
+
+ void OnScreenKeyboard::moveFocus(int rowDelta, int columnDelta)
+ {
+ if (mRows.empty())
+ return;
+ const int rowCount = static_cast<int>(mRows.size());
+ int row = mRow;
+ int column = mColumn;
+ if (rowDelta != 0)
+ {
+ row = ((row + rowDelta) % rowCount + rowCount) % rowCount;
+ // The key in the same place along the row: the rows differ in their number of keys
+ const MyGUI::Button* current = mRows[mRow][mColumn].mButton;
+ const int centre = current->getLeft() + current->getWidth() / 2;
+ int best = INT_MAX;
+ for (size_t i = 0; i < mRows[row].size(); ++i)
+ {
+ const MyGUI::Button* button = mRows[row][i].mButton;
+ const int distance = std::abs(button->getLeft() + button->getWidth() / 2 - centre);
+ if (distance < best)
+ {
+ best = distance;
+ column = static_cast<int>(i);
+ }
+ }
+ }
+ if (columnDelta != 0)
+ {
+ const int count = static_cast<int>(mRows[row].size());
+ column = ((column + columnDelta) % count + count) % count;
+ }
+ setFocus(row, column);
+ }
+
+ void OnScreenKeyboard::press(const Key& key)
+ {
+ switch (key.mSpecial)
+ {
+ case Special::None:
+ typeText(mShift ? key.mUpper : key.mLower);
+ if (mShift)
+ {
+ mShift = false;
+ refreshCaptions();
+ }
+ break;
+ case Special::Shift:
+ mShift = !mShift;
+ refreshCaptions();
+ break;
+ case Special::Space:
+ typeText(" ");
+ break;
+ case Special::Backspace:
+ sendKey(MyGUI::KeyCode::Backspace);
+ break;
+ case Special::Done:
+ sendKey(MyGUI::KeyCode::Return);
+ break;
+ }
+ MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
+ }
+
+ void OnScreenKeyboard::typeText(const std::string& utf8)
+ {
+ if (!mTarget)
+ return;
+ MyGUI::InputManager& input = MyGUI::InputManager::getInstance();
+ if (input.getKeyFocusWidget() != mTarget)
+ MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mTarget);
+ const MyGUI::UString::utf32string text = MyGUI::UString(utf8).asUTF32();
+ for (const MyGUI::Char character : text)
+ input.injectKeyPress(MyGUI::KeyCode::None, character);
+ }
+
+ void OnScreenKeyboard::sendKey(MyGUI::KeyCode key)
+ {
+ if (!mTarget)
+ return;
+ MWBase::WindowManager* windowManager = MWBase::Environment::get().getWindowManager();
+ if (MyGUI::InputManager::getInstance().getKeyFocusWidget() != mTarget)
+ windowManager->setKeyFocusWidget(mTarget);
+ windowManager->injectKeyPress(key, 0, false);
+ // Or MyGUI would keep repeating it
+ MyGUI::InputManager::getInstance().injectKeyRelease(key);
+ }
+
+ void OnScreenKeyboard::updateStick(float dt)
+ {
+ const MWBase::InputManager* input = MWBase::Environment::get().getInputManager();
+ const auto direction = [](float value, int current) {
+ if (value > sStickOn)
+ return 1;
+ if (value < -sStickOn)
+ return -1;
+ if (std::abs(value) < sStickOff)
+ return 0;
+ return current;
+ };
+ const int x = direction(input->getControllerAxisValue(SDL_CONTROLLER_AXIS_LEFTX), mStickX);
+ const int y = direction(input->getControllerAxisValue(SDL_CONTROLLER_AXIS_LEFTY), mStickY);
+ if (x != mStickX || y != mStickY)
+ {
+ mStickX = x;
+ mStickY = y;
+ mStickHeld = 0.f;
+ mStickRepeating = false;
+ if (x != 0 || y != 0)
+ moveFocus(y, x);
+ return;
+ }
+ if (x == 0 && y == 0)
+ return;
+ mStickHeld += dt;
+ const float wait = mStickRepeating ? sRepeatInterval : sRepeatDelay;
+ if (mStickHeld >= wait)
+ {
+ mStickHeld -= wait;
+ mStickRepeating = true;
+ moveFocus(y, x);
+ }
+ }
+
+ void OnScreenKeyboard::onFrame(float dt)
+ {
+ if (!isVisible())
+ return;
+ // Put away once what it typed into is gone, or no longer being typed into
+ if (!mTarget || !mTarget->getInheritedVisible()
+ || MyGUI::InputManager::getInstance().getKeyFocusWidget() != mTarget)
+ {
+ close();
+ return;
+ }
+ updateStick(dt);
+ }
+
+ void OnScreenKeyboard::onResChange(int /*width*/, int /*height*/)
+ {
+ if (isVisible())
+ place();
+ }
+
+ bool OnScreenKeyboard::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ switch (arg.button)
+ {
+ case SDL_CONTROLLER_BUTTON_A:
+ if (!mRows.empty())
+ press(mRows[mRow][mColumn]);
+ break;
+ case SDL_CONTROLLER_BUTTON_B:
+ {
+ // Backspace; with nothing left to erase, the keyboard goes away
+ MyGUI::EditBox* edit = mTarget ? mTarget->castType<MyGUI::EditBox>(false) : nullptr;
+ if (edit && edit->getOnlyText().empty())
+ close();
+ else
+ sendKey(MyGUI::KeyCode::Backspace);
+ break;
+ }
+ case SDL_CONTROLLER_BUTTON_X:
+ typeText(" ");
+ break;
+ case SDL_CONTROLLER_BUTTON_Y:
+ mShift = !mShift;
+ refreshCaptions();
+ break;
+ case SDL_CONTROLLER_BUTTON_DPAD_UP:
+ moveFocus(-1, 0);
+ break;
+ case SDL_CONTROLLER_BUTTON_DPAD_DOWN:
+ moveFocus(1, 0);
+ break;
+ case SDL_CONTROLLER_BUTTON_DPAD_LEFT:
+ moveFocus(0, -1);
+ break;
+ case SDL_CONTROLLER_BUTTON_DPAD_RIGHT:
+ moveFocus(0, 1);
+ break;
+ case SDL_CONTROLLER_BUTTON_LEFTSHOULDER:
+ sendKey(MyGUI::KeyCode::ArrowLeft);
+ break;
+ case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER:
+ sendKey(MyGUI::KeyCode::ArrowRight);
+ break;
+ case SDL_CONTROLLER_BUTTON_START:
+ sendKey(MyGUI::KeyCode::Return);
+ break;
+ case SDL_CONTROLLER_BUTTON_BACK:
+ close();
+ break;
+ default:
+ break;
+ }
+ // Nothing gets past the keyboard while it is up
+ return true;
+ }
+
+ bool OnScreenKeyboard::onControllerThumbstickEvent(const SDL_ControllerAxisEvent& /*arg*/)
+ {
+ // The sticks are read each frame instead (updateStick): small moves back to rest don't arrive here
+ return true;
+ }
+
+ void OnScreenKeyboard::onKeyClicked(MyGUI::Widget* sender)
+ {
+ // The click took the keyboard focus from the text box, and so put the keyboard away: back to it
+ if (!mTarget && mLastTarget)
+ {
+ MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mLastTarget);
+ open();
+ }
+ for (size_t row = 0; row < mRows.size(); ++row)
+ {
+ for (size_t column = 0; column < mRows[row].size(); ++column)
+ {
+ if (mRows[row][column].mButton == sender)
+ {
+ setFocus(static_cast<int>(row), static_cast<int>(column));
+ press(mRows[row][column]);
+ return;
+ }
+ }
+ }
+ }
+
+ void OnScreenKeyboard::_unlinkWidget(MyGUI::Widget* widget)
+ {
+ if (widget == mTarget)
+ mTarget = nullptr;
+ if (widget == mLastTarget)
+ mLastTarget = nullptr;
+ }
+}
diff --git a/apps/openmw/mwgui/onscreenkeyboard.hpp b/apps/openmw/mwgui/onscreenkeyboard.hpp
new file mode 100644
index 0000000..67989a6
--- /dev/null
+++ b/apps/openmw/mwgui/onscreenkeyboard.hpp
@@ -0,0 +1,91 @@
+#ifndef MWGUI_ONSCREENKEYBOARD_H
+#define MWGUI_ONSCREENKEYBOARD_H
+
+#include <string>
+#include <vector>
+
+#include <MyGUI_IUnlinkWidget.h>
+
+#include "windowbase.hpp"
+
+namespace MyGUI
+{
+ class Button;
+}
+
+namespace MWGui
+{
+ /// Isowind: a keyboard on the screen, for typing with a controller (the multiplayer chat, a character's or
+ /// server's name, a save's name, a spell's). It comes up over the text box that has the keyboard focus and types
+ /// into it as a real keyboard would, so the text box and its window notice nothing.
+ /// D-pad / left stick pick a key A type it
+ /// B backspace X space
+ /// Y shift L1 / R1 move the text cursor
+ /// Start done (Enter) Back put the keyboard away
+ class OnScreenKeyboard : public WindowBase, public MyGUI::IUnlinkWidget
+ {
+ public:
+ OnScreenKeyboard();
+ ~OnScreenKeyboard() override;
+
+ /// Comes up for the widget that has the keyboard focus (nothing if none has)
+ void open();
+ void close();
+
+ /// The widget being typed into
+ MyGUI::Widget* getTarget() const { return mTarget; }
+
+ void onFrame(float dt) override;
+ void onResChange(int width, int height) override;
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
+ bool onControllerThumbstickEvent(const SDL_ControllerAxisEvent& arg) override;
+
+ void _unlinkWidget(MyGUI::Widget* widget) override;
+
+ private:
+ enum class Special
+ {
+ None,
+ Shift,
+ Space,
+ Backspace,
+ Done
+ };
+
+ struct Key
+ {
+ MyGUI::Button* mButton = nullptr;
+ std::string mLower;
+ std::string mUpper;
+ Special mSpecial = Special::None;
+ };
+
+ void buildKeys();
+ void refreshCaptions();
+ void place();
+ void setFocus(int row, int column);
+ void moveFocus(int rowDelta, int columnDelta);
+ void press(const Key& key);
+ void typeText(const std::string& utf8);
+ void sendKey(MyGUI::KeyCode key);
+ void updateStick(float dt);
+ void onKeyClicked(MyGUI::Widget* sender);
+
+ MyGUI::Widget* mTarget = nullptr;
+ // What was typed into last: a mouse click on a key takes the focus from it, and it gets it back
+ MyGUI::Widget* mLastTarget = nullptr;
+ MyGUI::Widget* mKeysWidget = nullptr;
+ std::vector<std::vector<Key>> mRows;
+ int mRow = 1;
+ int mColumn = 0;
+ bool mShift = false;
+
+ // The left stick as a D-pad: the direction it is held in, repeating after a delay
+ int mStickX = 0;
+ int mStickY = 0;
+ float mStickHeld = 0.f;
+ bool mStickRepeating = false;
+ };
+}
+
+#endif
diff --git a/apps/openmw/mwgui/settingswindow.cpp b/apps/openmw/mwgui/settingswindow.cpp
index 7cfdddf..b0b5eb9 100644
--- a/apps/openmw/mwgui/settingswindow.cpp
+++ b/apps/openmw/mwgui/settingswindow.cpp
@@ -1,15 +1,21 @@
#include "settingswindow.hpp"
+#include <algorithm>
#include <array>
#include <unicode/locid.h>
+#include <MyGUI_Button.h>
#include <MyGUI_ComboBox.h>
+#include <MyGUI_EditBox.h>
#include <MyGUI_Gui.h>
+#include <MyGUI_InputManager.h>
#include <MyGUI_LanguageManager.h>
+#include <MyGUI_ListBox.h>
#include <MyGUI_ScrollBar.h>
#include <MyGUI_ScrollView.h>
#include <MyGUI_TabControl.h>
+#include <MyGUI_TabItem.h>
#include <MyGUI_UString.h>
#include <MyGUI_Window.h>
@@ -37,8 +43,8 @@
#include "../mwbase/windowmanager.hpp"
#include "../mwbase/world.hpp"
-#include "../mwmp/Main.hpp"
#include "../mwlua/luamanagerimp.hpp"
+#include "../mwmp/Main.hpp"
#include "confirmationdialog.hpp"
#include "weightedsearch.hpp"
@@ -463,6 +469,9 @@ namespace MWGui
mControllerButtons.mA = "#{Interface:Select}";
mControllerButtons.mB = "#{Interface:OK}";
mControllerButtons.mLStick = "#{Interface:Mouse}";
+ mControllerButtons.mDpad = "#{Interface:Move}";
+ mControllerButtons.mL1 = "#{Interface:Prev}";
+ mControllerButtons.mR1 = "#{Interface:Next}";
}
void SettingsWindow::onTabChanged(MyGUI::TabControl* /*sender*/, size_t /*index*/)
@@ -1072,6 +1081,10 @@ namespace MWGui
difficultyText->getParent()->setVisible(!mwmp::Main::isInitialized());
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mOkButton);
+
+ // Isowind: with a controller the pointer starts on the page's first control
+ if (Settings::gui().mControllerMenus && MWBase::Environment::get().getInputManager()->joystickLastUsed())
+ pointAtFirstControl();
}
void SettingsWindow::onClose()
@@ -1132,6 +1145,7 @@ namespace MWGui
index = wrap(index, mSettingsTab->getItemCount(), -1);
mSettingsTab->setIndexSelected(index);
MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
+ pointAtFirstControl();
return true;
}
else if (arg.button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER)
@@ -1140,10 +1154,292 @@ namespace MWGui
index = wrap(index, mSettingsTab->getItemCount(), 1);
mSettingsTab->setIndexSelected(index);
MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
+ pointAtFirstControl();
+ return true;
+ }
+ // Isowind: the D-pad steps the pointer through the page's controls, A works the one it is on
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP)
+ {
+ stepControl(-1);
+ return true;
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
+ {
+ stepControl(1);
+ return true;
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT)
+ {
+ adjustControl(-1);
+ return true;
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT)
+ {
+ adjustControl(1);
+ return true;
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_A)
+ {
+ selectControl();
return true;
}
return false;
}
+ namespace
+ {
+ bool isInside(const MyGUI::Widget* widget, const MyGUI::Widget* parent)
+ {
+ for (; widget != nullptr; widget = widget->getParent())
+ {
+ if (widget == parent)
+ return true;
+ }
+ return false;
+ }
+
+ void clickAtPointer()
+ {
+ MyGUI::InputManager& input = MyGUI::InputManager::getInstance();
+ const MyGUI::IntPoint mouse = input.getMousePosition();
+ input.injectMousePress(mouse.left, mouse.top, MyGUI::MouseButton::Left);
+ input.injectMouseRelease(mouse.left, mouse.top, MyGUI::MouseButton::Left);
+ }
+ }
+
+ // The controls of the page: buttons (checkboxes among them), sliders, drop-down lists, lists, text boxes and
+ // inner tab bars (the outer tabs are the bumpers'), top to bottom
+ void SettingsWindow::collectControls(MyGUI::Widget* parent, std::vector<MyGUI::Widget*>& controls) const
+ {
+ MyGUI::EnumeratorWidgetPtr children = parent->getEnumerator();
+ while (children.next())
+ {
+ MyGUI::Widget* widget = children.current();
+ if (!widget->getVisible() || !widget->getEnabled())
+ continue;
+ if (MyGUI::TabControl* tabs = widget->castType<MyGUI::TabControl>(false))
+ {
+ if (tabs != mSettingsTab)
+ controls.push_back(tabs);
+ if (tabs->getIndexSelected() != MyGUI::ITEM_NONE)
+ collectControls(tabs->getItemAt(tabs->getIndexSelected()), controls);
+ }
+ else if (widget->castType<MyGUI::ComboBox>(false) || widget->castType<MyGUI::ListBox>(false)
+ || widget->castType<MyGUI::ScrollBar>(false))
+ controls.push_back(widget);
+ else if (MyGUI::EditBox* edit = widget->castType<MyGUI::EditBox>(false))
+ {
+ if (!edit->getEditStatic() && !edit->getEditReadOnly())
+ controls.push_back(widget);
+ }
+ else if (widget->castType<MyGUI::Button>(false))
+ {
+ // The names in the controls list are buttons too; only the bindings beside them do anything
+ if (!isInside(widget, mControlsBox) || widget->getUserData<int>(false) != nullptr)
+ controls.push_back(widget);
+ }
+ else
+ collectControls(widget, controls);
+ }
+ }
+
+ std::vector<MyGUI::Widget*> SettingsWindow::collectControls() const
+ {
+ std::vector<MyGUI::Widget*> controls;
+ collectControls(mMainWidget, controls);
+ std::stable_sort(controls.begin(), controls.end(), [](const MyGUI::Widget* a, const MyGUI::Widget* b) {
+ const MyGUI::IntCoord coordA = a->getAbsoluteCoord();
+ const MyGUI::IntCoord coordB = b->getAbsoluteCoord();
+ return coordA.top != coordB.top ? coordA.top < coordB.top : coordA.left < coordB.left;
+ });
+ return controls;
+ }
+
+ MyGUI::Widget* SettingsWindow::controlUnderPointer(const std::vector<MyGUI::Widget*>& controls) const
+ {
+ for (MyGUI::Widget* widget = MyGUI::InputManager::getInstance().getMouseFocusWidget(); widget != nullptr;
+ widget = widget->getParent())
+ {
+ if (std::find(controls.begin(), controls.end(), widget) != controls.end())
+ return widget;
+ }
+ return nullptr;
+ }
+
+ void SettingsWindow::pointAt(MyGUI::Widget* control)
+ {
+ if (!control)
+ return;
+ // A row of the controls list scrolls into view first
+ if (isInside(control, mControlsBox) && control != mControlsBox)
+ {
+ MyGUI::IntPoint offset = mControlsBox->getViewOffset();
+ const int viewHeight = mControlsBox->getViewCoord().height;
+ const int top = control->getTop() + offset.top;
+ if (top < 0)
+ offset.top = -control->getTop();
+ else if (top + control->getHeight() > viewHeight)
+ offset.top = viewHeight - control->getTop() - control->getHeight();
+ mControlsBox->setViewOffset(offset);
+ }
+ // The middle of the control; an inner tab bar on the tabs themselves along its top, and a list on the row
+ // it has chosen, if that is in view
+ MyGUI::Widget* target = control;
+ float yFraction = 0.5f;
+ if (control->castType<MyGUI::TabControl>(false))
+ yFraction = std::min(0.5f, 12.f / static_cast<float>(std::max(1, control->getHeight())));
+ else if (MyGUI::ListBox* list = control->castType<MyGUI::ListBox>(false))
+ {
+ MyGUI::Widget* row = list->getIndexSelected() != MyGUI::ITEM_NONE
+ ? list->getWidgetByIndex(list->getIndexSelected())
+ : nullptr;
+ if (row && row->getVisible())
+ target = row;
+ else
+ yFraction = std::min(0.5f, 12.f / static_cast<float>(std::max(1, control->getHeight())));
+ }
+ MWBase::InputManager* input = MWBase::Environment::get().getInputManager();
+ input->setGamepadGuiCursorEnabled(true);
+ input->warpMouseToWidget(target, yFraction);
+ // The warp may not come back as a mouse move (Wayland): tell the GUI where the pointer is ourselves
+ const MyGUI::IntCoord coord = target->getAbsoluteCoord();
+ MyGUI::InputManager::getInstance().injectMouseMove(
+ coord.left + coord.width / 2, coord.top + static_cast<int>(coord.height * yFraction), 0);
+ MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager();
+ winMgr->setCursorVisible(true);
+ winMgr->setCursorActive(true);
+ }
+
+ void SettingsWindow::pointAtFirstControl()
+ {
+ const std::vector<MyGUI::Widget*> controls = collectControls();
+ if (!controls.empty())
+ pointAt(controls.front());
+ }
+
+ void SettingsWindow::stepControl(int delta)
+ {
+ const std::vector<MyGUI::Widget*> controls = collectControls();
+ if (controls.empty())
+ return;
+ // From the control the pointer is on, or else from the pointer itself
+ MyGUI::IntPoint from = MyGUI::InputManager::getInstance().getMousePosition();
+ if (const MyGUI::Widget* current = controlUnderPointer(controls))
+ {
+ const MyGUI::IntCoord coord = current->getAbsoluteCoord();
+ from = MyGUI::IntPoint(coord.left + coord.width / 2, coord.top + coord.height / 2);
+ }
+ // The nearest control below (or above): the next row down wins over a nearer one off to the side, so a
+ // column is walked before the next one. None: round to the far end.
+ MyGUI::Widget* best = nullptr;
+ MyGUI::Widget* farthest = nullptr;
+ int bestScore = 0;
+ int farthestY = 0;
+ for (MyGUI::Widget* control : controls)
+ {
+ const MyGUI::IntCoord coord = control->getAbsoluteCoord();
+ const int x = coord.left + coord.width / 2;
+ const int y = coord.top + coord.height / 2;
+ const int dy = (y - from.top) * delta;
+ if (dy > 2)
+ {
+ const int score = dy + std::abs(x - from.left) / 2;
+ if (!best || score < bestScore)
+ {
+ best = control;
+ bestScore = score;
+ }
+ }
+ const int toward = -y * delta;
+ if (!farthest || toward > farthestY)
+ {
+ farthest = control;
+ farthestY = toward;
+ }
+ }
+ pointAt(best ? best : farthest);
+ }
+
+ void SettingsWindow::adjustControl(int delta)
+ {
+ MyGUI::Widget* control = controlUnderPointer(collectControls());
+ if (!control)
+ return;
+ if (MyGUI::ScrollBar* slider = control->castType<MyGUI::ScrollBar>(false))
+ {
+ const int range = static_cast<int>(slider->getScrollRange());
+ if (range <= 0)
+ return;
+ const int step = std::max(1, static_cast<int>(slider->getScrollPage()));
+ const int position = std::clamp(static_cast<int>(slider->getScrollPosition()) + delta * step, 0, range - 1);
+ slider->setScrollPosition(position);
+ onSliderChangePosition(slider, position);
+ }
+ else if (MyGUI::ComboBox* combo = control->castType<MyGUI::ComboBox>(false))
+ {
+ if (combo->getItemCount() == 0)
+ return;
+ const size_t index = wrap(combo->getIndexSelected(), combo->getItemCount(), delta);
+ combo->setIndexSelected(index);
+ combo->eventComboChangePosition(combo, index);
+ }
+ else if (MyGUI::ListBox* list = control->castType<MyGUI::ListBox>(false))
+ {
+ const size_t count = list->getItemCount();
+ if (count == 0)
+ return;
+ size_t index = list->getIndexSelected();
+ if (index == MyGUI::ITEM_NONE)
+ index = 0;
+ else if (delta < 0)
+ index = index == 0 ? 0 : index - 1;
+ else
+ index = std::min(index + 1, count - 1);
+ list->setIndexSelected(index);
+ list->beginToItemAt(index);
+ list->eventListChangePosition(list, index);
+ }
+ else if (MyGUI::TabControl* tabs = control->castType<MyGUI::TabControl>(false))
+ {
+ if (tabs->getItemCount() == 0)
+ return;
+ tabs->setIndexSelected(wrap(tabs->getIndexSelected(), tabs->getItemCount(), delta));
+ pointAt(tabs);
+ }
+ else
+ return;
+ MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager();
+ winMgr->playSound(ESM::RefId::stringRefId("Menu Click"));
+ winMgr->setCursorActive(true);
+ }
+
+ void SettingsWindow::selectControl()
+ {
+ MyGUI::Widget* control = controlUnderPointer(collectControls());
+ MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager();
+ if (control
+ && (control->castType<MyGUI::ComboBox>(false) || control->castType<MyGUI::ScrollBar>(false)
+ || control->castType<MyGUI::TabControl>(false)))
+ {
+ // Stepped through rather than dropped down
+ adjustControl(1);
+ return;
+ }
+ if (!control || control->castType<MyGUI::ListBox>(false))
+ {
+ // A row of a list, or something the page doesn't know (a script's own settings): a click there
+ clickAtPointer();
+ }
+ else if (MyGUI::EditBox* edit = control->castType<MyGUI::EditBox>(false))
+ {
+ // The keyboard on the screen comes up for it
+ winMgr->setKeyFocusWidget(edit);
+ }
+ else if (MyGUI::Button* button = control->castType<MyGUI::Button>(false))
+ button->eventMouseButtonClick(button);
+ winMgr->playSound(ESM::RefId::stringRefId("Menu Click"));
+ winMgr->setCursorActive(true);
+ }
+
}
diff --git a/apps/openmw/mwgui/settingswindow.hpp b/apps/openmw/mwgui/settingswindow.hpp
index 60b3e26..7eefe52 100644
--- a/apps/openmw/mwgui/settingswindow.hpp
+++ b/apps/openmw/mwgui/settingswindow.hpp
@@ -4,6 +4,8 @@
#include <components/files/configurationmanager.hpp>
#include <components/lua_ui/adapter.hpp>
+#include <vector>
+
#include "windowbase.hpp"
namespace MWGui
@@ -123,6 +125,18 @@ namespace MWGui
void computeMinimumWindowSize();
+ /// Isowind: the D-pad steps the pointer through the page's controls, A works the one it is on and left /
+ /// right adjust it; the left stick still moves the pointer freely
+ bool handlesPointerSelect() const override { return true; }
+ std::vector<MyGUI::Widget*> collectControls() const;
+ void collectControls(MyGUI::Widget* parent, std::vector<MyGUI::Widget*>& controls) const;
+ MyGUI::Widget* controlUnderPointer(const std::vector<MyGUI::Widget*>& controls) const;
+ void pointAt(MyGUI::Widget* control);
+ void pointAtFirstControl();
+ void stepControl(int delta);
+ void adjustControl(int delta);
+ void selectControl();
+
private:
void resetScrollbars();
Files::ConfigurationManager& mCfgMgr;
diff --git a/apps/openmw/mwgui/windowbase.hpp b/apps/openmw/mwgui/windowbase.hpp
index 205b3ec..394fc1a 100644
--- a/apps/openmw/mwgui/windowbase.hpp
+++ b/apps/openmw/mwgui/windowbase.hpp
@@ -83,6 +83,8 @@ namespace MWGui
virtual ControllerButtons* getControllerButtons() { return &mControllerButtons; }
MyGUI::Widget* getControllerScrollWidget() { return mControllerScrollWidget; }
bool isGamepadCursorAllowed() { return !mDisableGamepadCursor; }
+ /// Isowind: whether A goes to onControllerButtonEvent even while the pointer is shown (otherwise it is a click)
+ virtual bool handlesPointerSelect() const { return false; }
virtual bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) { return true; }
virtual bool onControllerThumbstickEvent(const SDL_ControllerAxisEvent& arg) { return false; }
virtual void setActiveControllerWindow(bool active);
diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp
index d883075..83791c3 100644
--- a/apps/openmw/mwgui/windowmanagerimp.cpp
+++ b/apps/openmw/mwgui/windowmanagerimp.cpp
@@ -102,6 +102,7 @@
#include "hud.hpp"
#include "maptileskin.hpp"
#include "inventorytabsoverlay.hpp"
+#include "onscreenkeyboard.hpp"
#include "inventorywindow.hpp"
#include "itemchargeview.hpp"
#include "itemtransfer.hpp"
@@ -532,6 +533,11 @@ namespace MWGui
mInventoryTabsOverlay = inventoryTabsOverlay.get();
mWindows.push_back(std::move(inventoryTabsOverlay));
+ // Isowind: a keyboard on the screen for typing with a controller
+ auto onScreenKeyboard = std::make_unique<OnScreenKeyboard>();
+ mOnScreenKeyboard = onScreenKeyboard.get();
+ mWindows.push_back(std::move(onScreenKeyboard));
+
mControllerTooltipEnabled = Settings::gui().mControllerTooltips;
mActiveControllerWindows[GM_Inventory] = 1; // Start on Inventory page
@@ -928,6 +934,10 @@ namespace MWGui
WindowBase* WindowManager::getActiveControllerWindow()
{
+ // Isowind: the keyboard on the screen has the controller while it is up
+ if (mOnScreenKeyboard && mOnScreenKeyboard->isVisible())
+ return mOnScreenKeyboard;
+
if (!mCurrentModals.empty())
return mCurrentModals.back();
@@ -1098,6 +1108,9 @@ namespace MWGui
if (mInventoryTabsOverlay && mInventoryTabsOverlay->isVisible())
mInventoryTabsOverlay->onFrame(frameDuration);
+ if (mOnScreenKeyboard && mOnScreenKeyboard->isVisible())
+ mOnScreenKeyboard->onFrame(frameDuration);
+
if (!gameRunning)
return;
@@ -2011,6 +2024,17 @@ namespace MWGui
capturesInput = widget->castType<MyGUI::EditBox>(false);
}
+ // Isowind: the keyboard on the screen comes up for a text box when a controller is in use, and goes away
+ // with the focus
+ if (mOnScreenKeyboard)
+ {
+ if (!capturesInput)
+ mOnScreenKeyboard->close();
+ else if (Settings::gui().mControllerMenus && isGuiMode() && mOnScreenKeyboard->getTarget() != widget
+ && MWBase::Environment::get().getInputManager()->joystickLastUsed())
+ mOnScreenKeyboard->open();
+ }
+
// The SDL_IsTextInputActive() check helps to avoid duplicate calls in SDL2.
// This may no longer be required when switching to SDL3 where the function
// has also been renamed to SDL_TextInputActive() and returns bool instead
@@ -2024,6 +2048,9 @@ namespace MWGui
SDL_StartTextInput();
else
SDL_StopTextInput();
+
+ // Isowind: the legend offers the keyboard on the screen (Y) while there is something to type into
+ updateControllerButtonsOverlay();
}
void WindowManager::setEnemy(const MWWorld::Ptr& enemy)
@@ -2912,7 +2939,11 @@ namespace MWGui
}
// setButtons will handle setting visibility based on if any buttons are defined.
- mControllerButtonsOverlay->setButtons(topWin->getControllerButtons());
+ ControllerButtons buttons = *topWin->getControllerButtons();
+ // Isowind: Y brings up the keyboard on the screen for a text box being typed into
+ if (buttons.mY.empty() && SDL_IsTextInputActive() && !isOnScreenKeyboardVisible())
+ buttons.mY = "#{OMWEngine:Keyboard}";
+ mControllerButtonsOverlay->setButtons(&buttons);
if (getMode() == GM_Inventory)
{
mInventoryTabsOverlay->setVisible(true);
@@ -2922,6 +2953,17 @@ namespace MWGui
mInventoryTabsOverlay->setVisible(false);
}
+ bool WindowManager::isOnScreenKeyboardVisible() const
+ {
+ return mOnScreenKeyboard && mOnScreenKeyboard->isVisible();
+ }
+
+ void WindowManager::openOnScreenKeyboard()
+ {
+ if (mOnScreenKeyboard && Settings::gui().mControllerMenus)
+ mOnScreenKeyboard->open();
+ }
+
void WindowManager::inventoryUpdated(const MWWorld::Ptr& ptr) const
{
for (const auto& window : mWindows)
diff --git a/apps/openmw/mwgui/windowmanagerimp.hpp b/apps/openmw/mwgui/windowmanagerimp.hpp
index 5507e88..0f6ed17 100644
--- a/apps/openmw/mwgui/windowmanagerimp.hpp
+++ b/apps/openmw/mwgui/windowmanagerimp.hpp
@@ -119,6 +119,7 @@ namespace MWGui
class KeyboardNavigation;
class ItemTransfer;
class ControllerButtonsOverlay;
+ class OnScreenKeyboard;
class InventoryTabsOverlay;
class WindowManager : public MWBase::WindowManager
@@ -412,6 +413,8 @@ namespace MWGui
void setControllerTooltipEnabled(bool enabled) override;
void restoreControllerTooltips() override;
void updateControllerButtonsOverlay() override;
+ bool isOnScreenKeyboardVisible() const override;
+ void openOnScreenKeyboard() override;
// Used in Lua bindings
const std::vector<GuiMode>& getGuiModeStack() const override { return mGuiModes; }
@@ -484,6 +487,8 @@ namespace MWGui
ContainerWindow* mContainerWindow;
ControllerButtonsOverlay* mControllerButtonsOverlay;
InventoryTabsOverlay* mInventoryTabsOverlay;
+ // Isowind: the keyboard on the screen for typing with a controller
+ OnScreenKeyboard* mOnScreenKeyboard = nullptr;
std::vector<std::unique_ptr<WindowBase>> mWindows;
diff --git a/apps/openmw/mwinput/controllermanager.cpp b/apps/openmw/mwinput/controllermanager.cpp
index b73b305..08e1bd6 100644
--- a/apps/openmw/mwinput/controllermanager.cpp
+++ b/apps/openmw/mwinput/controllermanager.cpp
@@ -17,6 +17,8 @@
#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"
@@ -161,7 +163,13 @@ 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);
@@ -259,6 +267,15 @@ namespace MWInput
if (Settings::gui().mControllerMenus)
{
+ // Isowind: Y brings up the keyboard on the screen for a text box being typed into
+ if (arg.button == SDL_CONTROLLER_BUTTON_Y && SDL_IsTextInputActive()
+ && !winMgr->isOnScreenKeyboardVisible())
+ {
+ winMgr->openOnScreenKeyboard();
+ if (winMgr->isOnScreenKeyboardVisible())
+ return true;
+ }
+
// Update cursor state.
bool treatAsMouse = winMgr->getCursorVisible();
winMgr->setCursorActive(false);
@@ -274,7 +291,8 @@ namespace MWInput
mGamepadGuiCursorEnabled = topWin->isGamepadCursorAllowed();
// Fall through to mouse click
- if (mGamepadGuiCursorEnabled && treatAsMouse && arg.button == SDL_CONTROLLER_BUTTON_A)
+ if (mGamepadGuiCursorEnabled && treatAsMouse && arg.button == SDL_CONTROLLER_BUTTON_A
+ && !topWin->handlesPointerSelect())
return false;
// Isowind: in menus with several windows side by side the bumpers switch between them
@@ -373,16 +391,18 @@ namespace MWInput
if (Settings::gui().mControllerMenus)
{
// Left and right triggers toggle through open GUI windows. Isowind: where the bumpers do that (several
- // windows side by side), the triggers instead do what the bumpers do in the active window.
+ // windows side by side), the triggers instead do what the bumpers do in the active window; and not while
+ // the keyboard on the screen is up, they would switch pages under it.
const auto triggerPressed = [&](bool right) {
+ if (winMgr->isOnScreenKeyboardVisible())
+ return;
MWGui::WindowBase* activeWin = winMgr->getActiveControllerWindow();
if (winMgr->controllerCyclesWindows() && activeWin && activeWin->isVisible())
{
SDL_ControllerButtonEvent bumper{};
bumper.type = SDL_CONTROLLERBUTTONDOWN;
bumper.state = SDL_PRESSED;
- bumper.button
- = right ? SDL_CONTROLLER_BUTTON_RIGHTSHOULDER : SDL_CONTROLLER_BUTTON_LEFTSHOULDER;
+ bumper.button = right ? SDL_CONTROLLER_BUTTON_RIGHTSHOULDER : SDL_CONTROLLER_BUTTON_LEFTSHOULDER;
activeWin->onControllerButtonEvent(bumper);
}
else
diff --git a/apps/openmw/mwinput/inputmanagerimp.cpp b/apps/openmw/mwinput/inputmanagerimp.cpp
index fa24130..cf20f8b 100644
--- a/apps/openmw/mwinput/inputmanagerimp.cpp
+++ b/apps/openmw/mwinput/inputmanagerimp.cpp
@@ -189,7 +189,7 @@ namespace MWInput
return mMouseManager->getMouseMoveY();
}
- void InputManager::warpMouseToWidget(MyGUI::Widget* widget)
+ void InputManager::warpMouseToWidget(MyGUI::Widget* widget, float yFraction)
{
// This is currently used to simulate mouse movement when the gamepad UI is used.
// Sometimes this is called in reaction to layout changes.
@@ -209,7 +209,7 @@ namespace MWInput
return;
MWBase::Environment::get().getWindowManager()->setCursorVisible(false);
- mMouseManager->warpMouseToWidget(widget);
+ mMouseManager->warpMouseToWidget(widget, yFraction);
mMouseManager->injectMouseMove(1, 0, 0);
MWBase::Environment::get().getWindowManager()->setCursorActive(true);
}
diff --git a/apps/openmw/mwinput/inputmanagerimp.hpp b/apps/openmw/mwinput/inputmanagerimp.hpp
index 611679a..88b71f2 100644
--- a/apps/openmw/mwinput/inputmanagerimp.hpp
+++ b/apps/openmw/mwinput/inputmanagerimp.hpp
@@ -81,7 +81,7 @@ namespace MWInput
float getControllerAxisValue(SDL_GameControllerAxis axis) const override;
int getMouseMoveX() const override;
int getMouseMoveY() const override;
- void warpMouseToWidget(MyGUI::Widget* widget) override;
+ void warpMouseToWidget(MyGUI::Widget* widget, float yFraction) override;
int getNumActions() override { return A_Last; }
const std::initializer_list<int>& getActionKeySorting() override;
diff --git a/apps/openmw/mwinput/mousemanager.cpp b/apps/openmw/mwinput/mousemanager.cpp
index 1d98488..677b611 100644
--- a/apps/openmw/mwinput/mousemanager.cpp
+++ b/apps/openmw/mwinput/mousemanager.cpp
@@ -288,10 +288,10 @@ namespace MWInput
static_cast<int>(mGuiCursorX * guiUiScale), static_cast<int>(mGuiCursorY * guiUiScale));
}
- void MouseManager::warpMouseToWidget(MyGUI::Widget* widget)
+ void MouseManager::warpMouseToWidget(MyGUI::Widget* widget, float yFraction)
{
float widgetX = widget->getAbsoluteCoord().left + widget->getWidth() / 2.f;
- float widgetY = widget->getAbsoluteCoord().top + widget->getHeight() / 4.f;
+ float widgetY = widget->getAbsoluteCoord().top + widget->getHeight() * yFraction;
if (std::abs(mGuiCursorX - widgetX) > 1 || std::abs(mGuiCursorY - widgetY) > 1)
{
mGuiCursorX = widgetX;
diff --git a/apps/openmw/mwinput/mousemanager.hpp b/apps/openmw/mwinput/mousemanager.hpp
index 323703b..85ae481 100644
--- a/apps/openmw/mwinput/mousemanager.hpp
+++ b/apps/openmw/mwinput/mousemanager.hpp
@@ -32,7 +32,7 @@ namespace MWInput
bool injectMouseButtonRelease(Uint8 button);
void injectMouseMove(float xMove, float yMove, float mouseWheelMove);
void warpMouse();
- void warpMouseToWidget(MyGUI::Widget* widget);
+ void warpMouseToWidget(MyGUI::Widget* widget, float yFraction = 0.25f);
void setMouseLookEnabled(bool enabled) { mMouseLookEnabled = enabled; }
void setGuiCursorEnabled(bool enabled) { mGuiCursorEnabled = enabled; }
diff --git a/apps/openmw/mwlua/uibindings.cpp b/apps/openmw/mwlua/uibindings.cpp
index df16ced..bcf893a 100644
--- a/apps/openmw/mwlua/uibindings.cpp
+++ b/apps/openmw/mwlua/uibindings.cpp
@@ -60,6 +60,7 @@ namespace MWLua
// Isowind multiplayer: the server's text input and list dialogs
{ static_cast<MWGui::GuiMode>(mwmp::GUIController::GM_TES3MP_InputBox), "MultiplayerInput" },
{ static_cast<MWGui::GuiMode>(mwmp::GUIController::GM_TES3MP_ListBox), "MultiplayerList" },
+ { static_cast<MWGui::GuiMode>(mwmp::GUIController::GM_TES3MP_Chat), "MultiplayerChat" },
};
const auto nameToMode = [] {
diff --git a/apps/openmw/mwmp/GUI/GUIChat.cpp b/apps/openmw/mwmp/GUI/GUIChat.cpp
index 33cd56f..ad13d2f 100644
--- a/apps/openmw/mwmp/GUI/GUIChat.cpp
+++ b/apps/openmw/mwmp/GUI/GUIChat.cpp
@@ -191,6 +191,9 @@ namespace mwmp
editState = state;
mCommandLine->setVisible(editState);
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(editState ? mCommandLine : nullptr);
+ // Isowind: opened with a controller, the chat has a GUI mode of its own that ends here
+ if (!editState)
+ Main::get().getGUIController()->chatInputEnded();
}
void GUIChat::pressedSay()
diff --git a/apps/openmw/mwmp/GUI/GUIDialogList.cpp b/apps/openmw/mwmp/GUI/GUIDialogList.cpp
index d0b1596..e1aaf6a 100644
--- a/apps/openmw/mwmp/GUI/GUIDialogList.cpp
+++ b/apps/openmw/mwmp/GUI/GUIDialogList.cpp
@@ -7,6 +7,9 @@
#include <MyGUI_Button.h>
#include <MyGUI_ListBox.h>
+#include <components/esm/refid.hpp>
+#include <components/settings/values.hpp>
+
#include "GUIDialogList.hpp"
#include "../Main.hpp"
#include "../Networking.hpp"
@@ -28,6 +31,38 @@ GUIDialogList::GUIDialogList(const std::string &message, const std::vector<std::
for (size_t i = 0; i < list.size(); i++)
mListBox->addItem(list[i]);
+ // Isowind: with a controller the first entry starts picked, so A always answers with something
+ if (Settings::gui().mControllerMenus)
+ {
+ mDisableGamepadCursor = true;
+ mControllerButtons.mA = "#{Interface:Select}";
+ mControllerButtons.mDpad = "#{Interface:Move}";
+ if (!list.empty())
+ mListBox->setIndexSelected(0);
+ }
+}
+
+bool GUIDialogList::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+{
+ if (arg.button == SDL_CONTROLLER_BUTTON_A)
+ {
+ MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
+ mousePressed(mButton);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP || arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
+ {
+ const size_t count = mListBox->getItemCount();
+ if (count == 0)
+ return true;
+ size_t index = mListBox->getIndexSelected();
+ if (index == MyGUI::ITEM_NONE)
+ index = 0;
+ else
+ index = MWGui::wrap(index, count, arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP ? -1 : 1);
+ mListBox->setIndexSelected(index);
+ mListBox->beginToItemAt(index);
+ }
+ return true;
}
void GUIDialogList::mousePressed(MyGUI::Widget * /*widget*/)
diff --git a/apps/openmw/mwmp/GUI/GUIDialogList.hpp b/apps/openmw/mwmp/GUI/GUIDialogList.hpp
index d9e0262..7652c4b 100644
--- a/apps/openmw/mwmp/GUI/GUIDialogList.hpp
+++ b/apps/openmw/mwmp/GUI/GUIDialogList.hpp
@@ -12,6 +12,8 @@ namespace mwmp
GUIDialogList(const std::string &message, const std::vector<std::string> &list);
void mousePressed(MyGUI::Widget *_widget);
void onFrame(float frameDuration);
+ /// Isowind: the D-pad picks, A answers
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
private:
bool mMarkedToDelete;
MyGUI::EditBox *mMessage;
diff --git a/apps/openmw/mwmp/GUI/TextInputDialog.cpp b/apps/openmw/mwmp/GUI/TextInputDialog.cpp
index 17311e7..32127ad 100644
--- a/apps/openmw/mwmp/GUI/TextInputDialog.cpp
+++ b/apps/openmw/mwmp/GUI/TextInputDialog.cpp
@@ -7,6 +7,8 @@
#include <MyGUI_Button.h>
#include <MyGUI_InputManager.h>
+#include <components/esm/refid.hpp>
+
namespace mwmp
{
TextInputDialog::TextInputDialog()
@@ -24,6 +26,8 @@ namespace mwmp
// Make sure the edit box has focus
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mTextEdit);
+
+ mControllerButtons.mA = "#{Interface:OK}";
}
void TextInputDialog::setNextButtonShow(bool shown)
@@ -91,4 +95,15 @@ namespace mwmp
{
mTextEdit->setCaption(text);
}
+
+ bool TextInputDialog::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_A)
+ {
+ onOkClicked(nullptr);
+ MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
+ return true;
+ }
+ return false;
+ }
}
diff --git a/apps/openmw/mwmp/GUI/TextInputDialog.hpp b/apps/openmw/mwmp/GUI/TextInputDialog.hpp
index 7a3b596..10244dd 100644
--- a/apps/openmw/mwmp/GUI/TextInputDialog.hpp
+++ b/apps/openmw/mwmp/GUI/TextInputDialog.hpp
@@ -32,6 +32,9 @@ namespace mwmp
*/
EventHandle_WindowBase eventDone;
+ /// Isowind: A is OK (the keyboard on the screen comes up with the dialog, or with Y)
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
+
protected:
void onOkClicked(MyGUI::Widget *_sender);
void onTextAccepted(MyGUI::EditBox *_sender);
diff --git a/apps/openmw/mwmp/GUIController.cpp b/apps/openmw/mwmp/GUIController.cpp
index 3b308c2..5ac18d6 100644
--- a/apps/openmw/mwmp/GUIController.cpp
+++ b/apps/openmw/mwmp/GUIController.cpp
@@ -1,5 +1,6 @@
#include <components/openmw-mp/TimedLog.hpp>
#include <components/openmw-mp/Base/BasePlayer.hpp>
+#include <components/settings/values.hpp>
#include <SDL_system.h>
@@ -248,6 +249,37 @@ void mwmp::GUIController::changeChatMode()
mChat->pressedChatMode();
}
+bool mwmp::GUIController::openChatWithController()
+{
+ MWBase::WindowManager* windowManager = MWBase::Environment::get().getWindowManager();
+ if (mChat == nullptr || !Settings::gui().mControllerMenus || windowManager->isGuiMode()
+ || windowManager->isConsoleMode())
+ return false;
+
+ if (mChat->windowState == GUIChat::CHAT_DISABLED)
+ mChat->pressedChatMode();
+
+ // The mode first, so the keyboard on the screen comes up with the chat line (it does only in a menu); the mode
+ // ends with the typing (chatInputEnded), with the keyboard put away, or with B
+ mChatModeOpen = true;
+ mChatKeyboardShown = false;
+ windowManager->pushGuiMode(static_cast<MWGui::GuiMode>(GM_TES3MP_Chat));
+ mChat->pressedSay();
+ return true;
+}
+
+void mwmp::GUIController::chatInputEnded()
+{
+ if (!mChatModeOpen)
+ return;
+ mChatModeOpen = false;
+ mChatKeyboardShown = false;
+ MWBase::WindowManager* windowManager = MWBase::Environment::get().getWindowManager();
+ const MWGui::GuiMode chatMode = static_cast<MWGui::GuiMode>(GM_TES3MP_Chat);
+ if (windowManager->containsMode(chatMode))
+ windowManager->removeGuiMode(chatMode);
+}
+
bool mwmp::GUIController::getChatEditState()
{
return mChat->editState;
@@ -259,6 +291,17 @@ void mwmp::GUIController::update(float dt)
mChat->update(dt);
MWBase::WindowManager* windowManager = MWBase::Environment::get().getWindowManager();
+
+ // Isowind: the chat opened with a controller is over once its mode was left (B), or the keyboard on the
+ // screen was put away
+ if (mChatModeOpen && mChat != nullptr)
+ {
+ if (windowManager->isOnScreenKeyboardVisible())
+ mChatKeyboardShown = true;
+ else if (mChatKeyboardShown || !windowManager->containsMode(static_cast<MWGui::GuiMode>(GM_TES3MP_Chat)))
+ mChat->setEditState(false);
+ }
+
mMenuWasOpen = windowManager->isGuiMode() || windowManager->isConsoleMode();
}
diff --git a/apps/openmw/mwmp/GUIController.hpp b/apps/openmw/mwmp/GUIController.hpp
index 32576a0..4a421d9 100644
--- a/apps/openmw/mwmp/GUIController.hpp
+++ b/apps/openmw/mwmp/GUIController.hpp
@@ -26,8 +26,9 @@ namespace mwmp
{
GM_VR_MetaMenu = MWGui::GM_QuickKeysMenu + 1, // Put this dummy GuiMode here because it's used in VR
GM_TES3MP_InputBox,
- GM_TES3MP_ListBox
-
+ GM_TES3MP_ListBox,
+ // Isowind: the chat opened with a controller (openChatWithController)
+ GM_TES3MP_Chat
};
GUIController();
~GUIController();
@@ -53,6 +54,12 @@ namespace mwmp
void changeChatMode();
+ /// Isowind: a controller opens the chat line, in a GUI mode of its own so that the sticks and buttons work the
+ /// chat (and the keyboard on the screen) and not the character. False if there is no chat to open.
+ bool openChatWithController();
+ /// Isowind: the chat line closed (the message sent, or nothing to send); leaves that mode
+ void chatInputEnded();
+
bool getChatEditState();
void update(float dt);
@@ -76,6 +83,10 @@ namespace mwmp
// Whether a menu was open in the last frame: the Enter that closes a menu (the password box at login, a
// message box) mustn't also start typing in the chat
bool mMenuWasOpen = true;
+ // Isowind: the chat is open in its own GUI mode (openChatWithController), and the keyboard on the screen
+ // has come up for it
+ bool mChatModeOpen = false;
+ bool mChatKeyboardShown = false;
int keyChatMode;
long id;
diff --git a/files/data/CMakeLists.txt b/files/data/CMakeLists.txt
index 464ffc7..098494f 100644
--- a/files/data/CMakeLists.txt
+++ b/files/data/CMakeLists.txt
@@ -197,6 +197,7 @@ set(BUILTIN_DATA_FILES
mygui/openmw_console.skin.xml
mygui/openmw_container_window.layout
mygui/openmw_controllerbuttons.layout
+ mygui/openmw_onscreen_keyboard.layout
mygui/openmw_count_window.layout
mygui/openmw_dialogue_window.layout
mygui/openmw_dialogue_window.skin.xml
diff --git a/files/data/l10n/OMWEngine/en.yaml b/files/data/l10n/OMWEngine/en.yaml
index ad531fe..85a95e0 100644
--- a/files/data/l10n/OMWEngine/en.yaml
+++ b/files/data/l10n/OMWEngine/en.yaml
@@ -235,3 +235,11 @@ JournalShowAll: "Show All"
LoadingSelectCharacter: "Change Character"
RechargeSelect: "Recharge"
RepairTool: "Tool"
+
+# Isowind: the keyboard on the screen
+Keyboard: "Keyboard"
+KeyboardBackspace: "Backspace"
+KeyboardShift: "Shift"
+KeyboardShiftHeld: "SHIFT"
+KeyboardSpace: "Space"
+KeyboardType: "Type"
diff --git a/files/data/mygui/openmw_onscreen_keyboard.layout b/files/data/mygui/openmw_onscreen_keyboard.layout
new file mode 100644
index 0000000..7324c85
--- /dev/null
+++ b/files/data/mygui/openmw_onscreen_keyboard.layout
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- Isowind: the keyboard on the screen for typing with a controller (OnScreenKeyboard builds the keys) -->
+<MyGUI type="Layout">
+ <Widget type="Window" skin="MW_Dialog" layer="Popup" position="0 0 560 196" name="_Main">
+ <Property key="Visible" value="false"/>
+ <Widget type="Widget" skin="" position="8 8 544 180" align="Default" name="Keys"/>
+ </Widget>
+</MyGUI>
diff --git a/files/data/mygui/openmw_settings_window.layout b/files/data/mygui/openmw_settings_window.layout
index 26ffa27..1706c41 100644
--- a/files/data/mygui/openmw_settings_window.layout
+++ b/files/data/mygui/openmw_settings_window.layout
@@ -904,6 +904,16 @@
<Property key="Caption" value="Minimap turns with the view"/>
</Widget>
</Widget>
+ <Widget type="HBox" position="4 216 352 28">
+ <Widget type="AutoSizedButton" skin="MW_Button" position="0 0 24 24" align="Left Top">
+ <UserString key="SettingCategory" value="GUI"/>
+ <UserString key="SettingName" value="controller tooltips"/>
+ <UserString key="SettingType" value="CheckButton"/>
+ </Widget>
+ <Widget type="AutoSizedTextBox" skin="SandText" position="28 4 95 16" align="Left Top">
+ <Property key="Caption" value="Item info in controller menus without pressing the right stick in"/>
+ </Widget>
+ </Widget>
</Widget>
<Widget type="TabItem">
<Property key="Caption" value=" #{OMWEngine:Language} "/>
diff --git a/isowind/profiles/normal/settings.cfg b/isowind/profiles/normal/settings.cfg
index 0ce2dc1..24c6e14 100644
--- a/isowind/profiles/normal/settings.cfg
+++ b/isowind/profiles/normal/settings.cfg
@@ -42,6 +42,9 @@ chain = HBAO,VAIO,godrays,DIVE,wetworld,tonemap,SMAA
# Options > Interface: 'HUD size' scales only the in-game HUD, 'Menu and text size' everything.
scaling factor = 1.0
hud scaling factor = 1.5
+# Item and spell info in the controller's menus without pressing the right stick in ('controller menus' itself
+# is set by isowind.sh / Isowind.exe each time, from whether a controller is plugged in or the --controller flag)
+controller tooltips = true
[Terrain]
# Isowind: nearby objects stay separate, so the top-down camera can fade each one that hides the player
diff --git a/isowind/profiles/pixelart/settings.cfg b/isowind/profiles/pixelart/settings.cfg
index 79b16b3..4076aee 100644
--- a/isowind/profiles/pixelart/settings.cfg
+++ b/isowind/profiles/pixelart/settings.cfg
@@ -56,6 +56,9 @@ chain = HBAO,VAIO,godrays,DIVE,wetworld,tonemap
# Options > Interface: 'HUD size' scales only the in-game HUD, 'Menu and text size' everything.
scaling factor = 1.0
hud scaling factor = 1.5
+# Item and spell info in the controller's menus without pressing the right stick in ('controller menus' itself
+# is set by isowind.sh / Isowind.exe each time, from whether a controller is plugged in or the --controller flag)
+controller tooltips = true
[Terrain]
# Isowind: nearby objects stay separate, so the top-down camera can fade each one that hides the player