diff --git a/apps/launcher/settingspage.cpp b/apps/launcher/settingspage.cpp
index dfddc45bc5..294c2c09f3 100644
--- a/apps/launcher/settingspage.cpp
+++ b/apps/launcher/settingspage.cpp
@@ -304,6 +304,9 @@ bool Launcher::SettingsPage::loadSettings()
loadSettingBool(Settings::gui().mColorTopicEnable, *changeDialogTopicsCheckBox);
showOwnedComboBox->setCurrentIndex(Settings::game().mShowOwned);
loadSettingBool(Settings::gui().mStretchMenuBackground, *stretchBackgroundCheckBox);
+ connect(controllerMenusCheckBox, &QCheckBox::toggled, this, &SettingsPage::slotControllerMenusToggled);
+ loadSettingBool(Settings::gui().mControllerMenus, *controllerMenusCheckBox);
+ loadSettingBool(Settings::gui().mControllerTooltips, *controllerMenuTooltipsCheckBox);
loadSettingBool(Settings::map().mAllowZooming, *useZoomOnMapCheckBox);
loadSettingBool(Settings::game().mGraphicHerbalism, *graphicHerbalismCheckBox);
scalingSpinBox->setValue(Settings::gui().mScalingFactor);
@@ -497,6 +500,8 @@ void Launcher::SettingsPage::saveSettings()
saveSettingBool(*changeDialogTopicsCheckBox, Settings::gui().mColorTopicEnable);
saveSettingInt(*showOwnedComboBox, Settings::game().mShowOwned);
saveSettingBool(*stretchBackgroundCheckBox, Settings::gui().mStretchMenuBackground);
+ saveSettingBool(*controllerMenusCheckBox, Settings::gui().mControllerMenus);
+ saveSettingBool(*controllerMenuTooltipsCheckBox, Settings::gui().mControllerTooltips);
saveSettingBool(*useZoomOnMapCheckBox, Settings::map().mAllowZooming);
saveSettingBool(*graphicHerbalismCheckBox, Settings::game().mGraphicHerbalism);
Settings::gui().mScalingFactor.set(scalingSpinBox->value());
@@ -555,6 +560,11 @@ void Launcher::SettingsPage::slotAnimSourcesToggled(bool checked)
}
}
+void Launcher::SettingsPage::slotControllerMenusToggled(bool checked)
+{
+ controllerMenuTooltipsCheckBox->setEnabled(checked);
+}
+
void Launcher::SettingsPage::slotPostProcessToggled(bool checked)
{
postprocessTransparentPostpassCheckBox->setEnabled(checked);
diff --git a/apps/launcher/settingspage.hpp b/apps/launcher/settingspage.hpp
index d2bb80d86a..2c6eca477a 100644
--- a/apps/launcher/settingspage.hpp
+++ b/apps/launcher/settingspage.hpp
@@ -34,6 +34,7 @@ namespace Launcher
void slotSkyBlendingToggled(bool checked);
void slotShadowDistLimitToggled(bool checked);
void slotDistantLandToggled(bool checked);
+ void slotControllerMenusToggled(bool checked);
private:
Config::GameSettings& mGameSettings;
diff --git a/apps/launcher/ui/settingspage.ui b/apps/launcher/ui/settingspage.ui
index e792ac2843..aace4b49c7 100644
--- a/apps/launcher/ui/settingspage.ui
+++ b/apps/launcher/ui/settingspage.ui
@@ -1398,6 +1398,29 @@
+ -
+
+
+ <html><head/><body><p>Make it easier to use game menus with a controller.</p></body></html>
+
+
+ Enable Controller Menus
+
+
+
+ -
+
+
+ false
+
+
+ <html><head/><body><p>When using controller menus, make tooltips visible by default.</p></body></html>
+
+
+ Show Controller Tooltips By Default
+
+
+
-
diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt
index e3629d6f27..39fe9c4f7a 100644
--- a/apps/openmw/CMakeLists.txt
+++ b/apps/openmw/CMakeLists.txt
@@ -44,7 +44,7 @@ add_openmw_dir (mwgui
tradeitemmodel companionitemmodel pickpocketitemmodel controllers savegamedialog
recharge mode videowidget backgroundimage itemwidget screenfader debugwindow spellmodel spellview
draganddrop timeadvancer jailscreen itemchargeview keyboardnavigation textcolours statswatcher
- postprocessorhud settings
+ postprocessorhud settings controllerbuttonsoverlay inventorytabsoverlay
)
add_openmw_dir (mwdialogue
diff --git a/apps/openmw/mwbase/inputmanager.hpp b/apps/openmw/mwbase/inputmanager.hpp
index 5ee20476b3..f5adc42340 100644
--- a/apps/openmw/mwbase/inputmanager.hpp
+++ b/apps/openmw/mwbase/inputmanager.hpp
@@ -5,6 +5,7 @@
#include
#include
+#include
#include
#include
@@ -61,6 +62,7 @@ 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;
/// Actions available for binding to keyboard buttons
virtual const std::initializer_list& getActionKeySorting() = 0;
diff --git a/apps/openmw/mwbase/windowmanager.hpp b/apps/openmw/mwbase/windowmanager.hpp
index 8164501b4b..83a714cf05 100644
--- a/apps/openmw/mwbase/windowmanager.hpp
+++ b/apps/openmw/mwbase/windowmanager.hpp
@@ -11,7 +11,9 @@
#include
+#include "../mwgui/hud.hpp"
#include "../mwgui/mode.hpp"
+#include "../mwgui/windowbase.hpp"
#include
@@ -157,7 +159,9 @@ namespace MWBase
virtual MWGui::CountDialog* getCountDialog() = 0;
virtual MWGui::ConfirmationDialog* getConfirmationDialog() = 0;
virtual MWGui::TradeWindow* getTradeWindow() = 0;
+ virtual MWGui::HUD* getHud() = 0;
virtual MWGui::PostProcessorHud* getPostProcessorHud() = 0;
+ virtual std::vector getGuiModeWindows(MWGui::GuiMode mode) = 0;
/// Make the player use an item, while updating GUI state accordingly
virtual void useItem(const MWWorld::Ptr& item, bool force = false) = 0;
@@ -381,6 +385,15 @@ namespace MWBase
/// Same as viewer->getCamera()->getCullMask(), provided for consistency.
virtual uint32_t getCullMask() = 0;
+ /// Return the window that should receive controller events
+ virtual MWGui::WindowBase* getActiveControllerWindow() = 0;
+ /// Cycle to the next window to receive controller events
+ virtual void cycleActiveControllerWindow(bool next) = 0;
+ virtual void setActiveControllerWindow(MWGui::GuiMode mode, int activeIndex) = 0;
+ virtual bool getControllerTooltip() const = 0;
+ virtual void setControllerTooltip(bool enabled) = 0;
+ virtual void updateControllerButtonsOverlay() = 0;
+
// Used in Lua bindings
virtual const std::vector& getGuiModeStack() const = 0;
virtual void setDisabledByLua(std::string_view windowId, bool disabled) = 0;
diff --git a/apps/openmw/mwgui/alchemywindow.cpp b/apps/openmw/mwgui/alchemywindow.cpp
index 5a6245fca0..6cf34702d7 100644
--- a/apps/openmw/mwgui/alchemywindow.cpp
+++ b/apps/openmw/mwgui/alchemywindow.cpp
@@ -6,6 +6,7 @@
#include
#include
#include
+#include
#include
#include
@@ -91,6 +92,15 @@ namespace MWGui
mFilterValue->eventEditTextChange += MyGUI::newDelegate(this, &AlchemyWindow::onFilterEdited);
mFilterType->eventMouseButtonClick += MyGUI::newDelegate(this, &AlchemyWindow::switchFilterType);
+ if (Settings::gui().mControllerMenus)
+ {
+ mControllerButtons.a = "#{sSelect}";
+ mControllerButtons.b = "#{sCancel}";
+ mControllerButtons.x = "#{sCreate}";
+ mControllerButtons.y = "#{sMagicEffects}";
+ mControllerButtons.r3 = "#{sInfo}";
+ }
+
center();
}
@@ -165,7 +175,12 @@ namespace MWGui
std::string_view ingredient = wm->getGameSettingString("sIngredients", "Ingredients");
if (mFilterType->getCaption() == ingredient)
- mCurrentFilter = FilterType::ByName;
+ {
+ if (Settings::gui().mControllerMenus)
+ switchFilterType(mFilterType);
+ else
+ mCurrentFilter = FilterType::ByName;
+ }
else
mCurrentFilter = FilterType::ByEffect;
updateFilters();
@@ -291,6 +306,9 @@ namespace MWGui
initFilter();
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mNameEdit);
+
+ if (Settings::gui().mControllerMenus)
+ mItemView->setActiveControllerWindow(true);
}
void AlchemyWindow::onIngredientSelected(MyGUI::Widget* _sender)
@@ -528,4 +546,80 @@ namespace MWGui
if (currentCount > 1)
mBrewCountEdit->setValue(currentCount - 1);
}
+
+ bool AlchemyWindow::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ MyGUI::Widget* focus = MyGUI::InputManager::getInstance().getKeyFocusWidget();
+ bool isFilterListOpen
+ = focus != nullptr && focus->getParent() != nullptr && focus->getParent()->getParent() == mFilterValue;
+
+ if (isFilterListOpen)
+ {
+ // When the filter list combo box is open, send all inputs to it.
+ if (arg.button == SDL_CONTROLLER_BUTTON_A || arg.button == SDL_CONTROLLER_BUTTON_Y)
+ {
+ // Select the highlighted entry in the combo box and close it.
+ int index = mFilterValue->getIndexSelected();
+ mFilterValue->setIndexSelected(index);
+ onFilterChanged(mFilterValue, index);
+ MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mNameEdit); // Close list
+ MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ {
+ // Close the list without selecting anything
+ mFilterValue->clearIndexSelected();
+ onFilterEdited(mFilterValue);
+ MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mNameEdit); // Close list
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP)
+ MWBase::Environment::get().getWindowManager()->injectKeyPress(MyGUI::KeyCode::ArrowUp, 0, false);
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
+ MWBase::Environment::get().getWindowManager()->injectKeyPress(MyGUI::KeyCode::ArrowDown, 0, false);
+ }
+ else
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ {
+ // Remove active ingredients or close the window
+ if (mIngredients[3]->isUserString("ToolTipType"))
+ onIngredientSelected(mIngredients[3]);
+ else if (mIngredients[2]->isUserString("ToolTipType"))
+ onIngredientSelected(mIngredients[2]);
+ else if (mIngredients[1]->isUserString("ToolTipType"))
+ onIngredientSelected(mIngredients[1]);
+ else if (mIngredients[0]->isUserString("ToolTipType"))
+ onIngredientSelected(mIngredients[0]);
+ else
+ onCancelButtonClicked(mCancelButton);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_X)
+ onCreateButtonClicked(mCreateButton);
+ else if (arg.button == SDL_CONTROLLER_BUTTON_Y && mFilterValue->getItemCount() > 0)
+ {
+ // Magical effects/ingredients filter
+ if (mFilterValue->getIndexSelected() != MyGUI::ITEM_NONE)
+ {
+ // Clear the active filter
+ mFilterValue->clearIndexSelected();
+ onFilterEdited(mFilterValue);
+ }
+ else
+ {
+ // Open the combo box to choose the a filter
+ MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mFilterValue);
+ MWBase::Environment::get().getWindowManager()->injectKeyPress(MyGUI::KeyCode::ArrowDown, 0, false);
+ }
+ MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_LEFTSHOULDER)
+ onDecreaseButtonTriggered();
+ else if (arg.button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER)
+ onIncreaseButtonTriggered();
+ else
+ mItemView->onControllerButton(arg.button);
+ }
+
+ return true;
+ }
}
diff --git a/apps/openmw/mwgui/alchemywindow.hpp b/apps/openmw/mwgui/alchemywindow.hpp
index 82e5c3f583..e79c41b659 100644
--- a/apps/openmw/mwgui/alchemywindow.hpp
+++ b/apps/openmw/mwgui/alchemywindow.hpp
@@ -99,6 +99,8 @@ namespace MWGui
std::vector mApparatus;
std::vector mIngredients;
+
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
};
}
diff --git a/apps/openmw/mwgui/birth.cpp b/apps/openmw/mwgui/birth.cpp
index 3dfdd17627..5a5605aa6e 100644
--- a/apps/openmw/mwgui/birth.cpp
+++ b/apps/openmw/mwgui/birth.cpp
@@ -50,15 +50,20 @@ namespace MWGui
mBirthList->eventListSelectAccept += MyGUI::newDelegate(this, &BirthDialog::onAccept);
mBirthList->eventListChangePosition += MyGUI::newDelegate(this, &BirthDialog::onSelectBirth);
- MyGUI::Button* backButton;
- getWidget(backButton, "BackButton");
- backButton->eventMouseButtonClick += MyGUI::newDelegate(this, &BirthDialog::onBackClicked);
+ getWidget(mBackButton, "BackButton");
+ mBackButton->eventMouseButtonClick += MyGUI::newDelegate(this, &BirthDialog::onBackClicked);
- MyGUI::Button* okButton;
- getWidget(okButton, "OKButton");
- okButton->setCaption(
+ getWidget(mOkButton, "OKButton");
+ mOkButton->setCaption(
MyGUI::UString(MWBase::Environment::get().getWindowManager()->getGameSettingString("sOK", {})));
- okButton->eventMouseButtonClick += MyGUI::newDelegate(this, &BirthDialog::onOkClicked);
+ mOkButton->eventMouseButtonClick += MyGUI::newDelegate(this, &BirthDialog::onOkClicked);
+
+ if (Settings::gui().mControllerMenus)
+ {
+ mControllerButtons.lStick = "#{sMouse}";
+ mControllerButtons.a = "#{sSelect}";
+ mControllerButtons.b = "#{sBack}";
+ }
updateBirths();
updateSpells();
@@ -70,8 +75,17 @@ namespace MWGui
getWidget(okButton, "OKButton");
if (shown)
+ {
okButton->setCaption(
MyGUI::UString(MWBase::Environment::get().getWindowManager()->getGameSettingString("sNext", {})));
+ mControllerButtons.x = "#{sNext}";
+ }
+ else if (Settings::gui().mControllerMenus)
+ {
+ okButton->setCaption(
+ MyGUI::UString(MWBase::Environment::get().getWindowManager()->getGameSettingString("sDone", {})));
+ mControllerButtons.x = "#{sDone}";
+ }
else
okButton->setCaption(
MyGUI::UString(MWBase::Environment::get().getWindowManager()->getGameSettingString("sOK", {})));
@@ -271,4 +285,30 @@ namespace MWGui
mSpellArea->setVisibleVScroll(true);
mSpellArea->setViewOffset(MyGUI::IntPoint(0, 0));
}
+
+ bool BirthDialog::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ {
+ onBackClicked(mBackButton);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_X)
+ {
+ onOkClicked(mOkButton);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP)
+ {
+ MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager();
+ winMgr->setKeyFocusWidget(mBirthList);
+ winMgr->injectKeyPress(MyGUI::KeyCode::ArrowUp, 0, false);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
+ {
+ MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager();
+ winMgr->setKeyFocusWidget(mBirthList);
+ winMgr->injectKeyPress(MyGUI::KeyCode::ArrowDown, 0, false);
+ }
+
+ return true;
+ }
}
diff --git a/apps/openmw/mwgui/birth.hpp b/apps/openmw/mwgui/birth.hpp
index db9e997b6c..b41b1fbb9a 100644
--- a/apps/openmw/mwgui/birth.hpp
+++ b/apps/openmw/mwgui/birth.hpp
@@ -53,8 +53,12 @@ namespace MWGui
MyGUI::ScrollView* mSpellArea;
MyGUI::ImageBox* mBirthImage;
std::vector mSpellItems;
+ MyGUI::Button* mBackButton;
+ MyGUI::Button* mOkButton;
ESM::RefId mCurrentBirthId;
+
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
};
}
#endif
diff --git a/apps/openmw/mwgui/bookpage.cpp b/apps/openmw/mwgui/bookpage.cpp
index 47e85b1f4b..2c58ca3b72 100644
--- a/apps/openmw/mwgui/bookpage.cpp
+++ b/apps/openmw/mwgui/bookpage.cpp
@@ -105,6 +105,18 @@ namespace MWGui
Styles mStyles;
MyGUI::IntRect mRect;
+ void setColour(size_t section, size_t line, size_t run, const MyGUI::Colour& colour) const override
+ {
+ if (section >= mSections.size())
+ return;
+ if (line >= mSections[section].mLines.size())
+ return;
+ if (run >= mSections[section].mLines[line].mRuns.size())
+ return;
+
+ mSections[section].mLines[line].mRuns[run].mStyle->mNormalColour = colour;
+ }
+
virtual ~TypesetBookImpl() {}
Range addContent(const BookTypesetter::Utf8Span& text)
@@ -1288,6 +1300,12 @@ namespace MWGui
void unadviseLinkClicked() override { mPageDisplay->mLinkClicked = std::function(); }
+ void setFocusItem(BookTypesetter::Style* itemStyle) override
+ {
+ mPageDisplay->mFocusItem = (TypesetBookImpl::StyleImpl*)itemStyle;
+ mPageDisplay->dirtyFocusItem();
+ }
+
protected:
void initialiseOverride() override
{
diff --git a/apps/openmw/mwgui/bookpage.hpp b/apps/openmw/mwgui/bookpage.hpp
index d42fb4783f..bb85130b7f 100644
--- a/apps/openmw/mwgui/bookpage.hpp
+++ b/apps/openmw/mwgui/bookpage.hpp
@@ -31,6 +31,9 @@ namespace MWGui
/// text combined prior to pagination.
virtual std::pair getSize() const = 0;
+ /// Used to highlight journal indices
+ virtual void setColour(size_t section, size_t line, size_t run, const MyGUI::Colour& colour) const = 0;
+
virtual ~TypesetBook() = default;
};
@@ -164,6 +167,8 @@ namespace MWGui
/// Register the widget and associated sub-widget with MyGUI. Should be
/// called once near the beginning of the program.
static void registerMyGUIComponents();
+
+ virtual void setFocusItem(BookTypesetter::Style* itemStyle) = 0;
};
}
diff --git a/apps/openmw/mwgui/bookwindow.cpp b/apps/openmw/mwgui/bookwindow.cpp
index ef875a18b9..beba6e5968 100644
--- a/apps/openmw/mwgui/bookwindow.cpp
+++ b/apps/openmw/mwgui/bookwindow.cpp
@@ -66,6 +66,10 @@ namespace MWGui
MyGUI::IntCoord(0, 0, (64 - 7) * scale, mNextPageButton->getSize().height * scale));
}
+ mControllerButtons.l1 = "#{sPrev}";
+ mControllerButtons.r1 = "#{sNext}";
+ mControllerButtons.b = "#{sClose}";
+
center();
}
@@ -218,4 +222,26 @@ namespace MWGui
}
}
+ ControllerButtonStr* BookWindow::getControllerButtons()
+ {
+ mControllerButtons.a = mTakeButton->getVisible() ? "#{sTake}" : "";
+ return &mControllerButtons;
+ }
+
+ bool BookWindow::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_A)
+ {
+ if (mTakeButton->getVisible())
+ onTakeButtonClicked(mTakeButton);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ onCloseButtonClicked(mCloseButton);
+ else if (arg.button == SDL_CONTROLLER_BUTTON_LEFTSHOULDER)
+ prevPage();
+ else if (arg.button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER)
+ nextPage();
+
+ return true;
+ }
}
diff --git a/apps/openmw/mwgui/bookwindow.hpp b/apps/openmw/mwgui/bookwindow.hpp
index 5a3dfdf584..0a1beb7342 100644
--- a/apps/openmw/mwgui/bookwindow.hpp
+++ b/apps/openmw/mwgui/bookwindow.hpp
@@ -18,8 +18,10 @@ namespace MWGui
void setInventoryAllowed(bool allowed);
void onResChange(int, int) override { center(); }
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
std::string_view getWindowIdForLua() const override { return "Book"; }
+ ControllerButtonStr* getControllerButtons() override;
protected:
void onNextPageButtonClicked(MyGUI::Widget* sender);
diff --git a/apps/openmw/mwgui/class.cpp b/apps/openmw/mwgui/class.cpp
index 839f0f5072..450a61b4f8 100644
--- a/apps/openmw/mwgui/class.cpp
+++ b/apps/openmw/mwgui/class.cpp
@@ -18,6 +18,7 @@
#include
#include
#include
+#include
#include
#include "tooltips.hpp"
@@ -46,15 +47,21 @@ namespace MWGui
getWidget(mClassImage, "ClassImage");
getWidget(mClassName, "ClassName");
- MyGUI::Button* backButton;
- getWidget(backButton, "BackButton");
- backButton->setCaptionWithReplacing("#{sMessageQuestionAnswer3}");
- backButton->eventMouseButtonClick += MyGUI::newDelegate(this, &GenerateClassResultDialog::onBackClicked);
+ getWidget(mBackButton, "BackButton");
+ mBackButton->setCaptionWithReplacing("#{sMessageQuestionAnswer3}");
+ mBackButton->eventMouseButtonClick += MyGUI::newDelegate(this, &GenerateClassResultDialog::onBackClicked);
- MyGUI::Button* okButton;
- getWidget(okButton, "OKButton");
- okButton->setCaptionWithReplacing("#{sMessageQuestionAnswer2}");
- okButton->eventMouseButtonClick += MyGUI::newDelegate(this, &GenerateClassResultDialog::onOkClicked);
+ getWidget(mOkButton, "OKButton");
+ mOkButton->setCaptionWithReplacing("#{sMessageQuestionAnswer2}");
+ mOkButton->eventMouseButtonClick += MyGUI::newDelegate(this, &GenerateClassResultDialog::onOkClicked);
+
+ if (Settings::gui().mControllerMenus)
+ {
+ mOkButton->setStateSelected(true);
+ mDisableGamepadCursor = true;
+ mControllerButtons.a = "#{sSelect}";
+ mControllerButtons.b = "#{sBack}";
+ }
center();
}
@@ -71,6 +78,30 @@ namespace MWGui
center();
}
+ bool GenerateClassResultDialog::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_A)
+ {
+ if (mOkButtonFocus)
+ onOkClicked(mOkButton);
+ else
+ onBackClicked(mBackButton);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ {
+ onBackClicked(mBackButton);
+ }
+ else if ((arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT && mOkButtonFocus)
+ || (arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT && !mOkButtonFocus))
+ {
+ mOkButtonFocus = !mOkButtonFocus;
+ mOkButton->setStateSelected(mOkButtonFocus);
+ mBackButton->setStateSelected(!mOkButtonFocus);
+ }
+
+ return true;
+ }
+
// widget controls
void GenerateClassResultDialog::onOkClicked(MyGUI::Widget* _sender)
@@ -110,13 +141,18 @@ namespace MWGui
getWidget(mClassImage, "ClassImage");
- MyGUI::Button* backButton;
- getWidget(backButton, "BackButton");
- backButton->eventMouseButtonClick += MyGUI::newDelegate(this, &PickClassDialog::onBackClicked);
+ getWidget(mBackButton, "BackButton");
+ mBackButton->eventMouseButtonClick += MyGUI::newDelegate(this, &PickClassDialog::onBackClicked);
- MyGUI::Button* okButton;
- getWidget(okButton, "OKButton");
- okButton->eventMouseButtonClick += MyGUI::newDelegate(this, &PickClassDialog::onOkClicked);
+ getWidget(mOkButton, "OKButton");
+ mOkButton->eventMouseButtonClick += MyGUI::newDelegate(this, &PickClassDialog::onOkClicked);
+
+ if (Settings::gui().mControllerMenus)
+ {
+ mControllerButtons.lStick = "#{sMouse}";
+ mControllerButtons.a = "#{sSelect}";
+ mControllerButtons.b = "#{sBack}";
+ }
updateClasses();
updateStats();
@@ -128,8 +164,17 @@ namespace MWGui
getWidget(okButton, "OKButton");
if (shown)
+ {
okButton->setCaption(
MyGUI::UString(MWBase::Environment::get().getWindowManager()->getGameSettingString("sNext", {})));
+ mControllerButtons.x = "#{sNext}";
+ }
+ else if (Settings::gui().mControllerMenus)
+ {
+ okButton->setCaption(
+ MyGUI::UString(MWBase::Environment::get().getWindowManager()->getGameSettingString("sDone", {})));
+ mControllerButtons.x = "#{sDone}";
+ }
else
okButton->setCaption(
MyGUI::UString(MWBase::Environment::get().getWindowManager()->getGameSettingString("sOK", {})));
@@ -278,6 +323,32 @@ namespace MWGui
setClassImage(mClassImage, mCurrentClassId);
}
+ bool PickClassDialog::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ {
+ onBackClicked(mBackButton);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_X)
+ {
+ onOkClicked(mOkButton);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP)
+ {
+ MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager();
+ winMgr->setKeyFocusWidget(mClassList);
+ winMgr->injectKeyPress(MyGUI::KeyCode::ArrowUp, 0, false);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
+ {
+ MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager();
+ winMgr->setKeyFocusWidget(mClassList);
+ winMgr->injectKeyPress(MyGUI::KeyCode::ArrowDown, 0, false);
+ }
+
+ return true;
+ }
+
/* InfoBoxDialog */
void InfoBoxDialog::fitToText(MyGUI::TextBox* widget)
@@ -319,6 +390,9 @@ namespace MWGui
getWidget(mButtonBar, "ButtonBar");
center();
+
+ mDisableGamepadCursor = Settings::gui().mControllerMenus;
+ mControllerButtons.a = "#{sSelect}";
}
void InfoBoxDialog::setText(const std::string& str)
@@ -353,6 +427,13 @@ namespace MWGui
fitToText(button);
button->eventMouseButtonClick += MyGUI::newDelegate(this, &InfoBoxDialog::onButtonClicked);
coord.top += button->getHeight();
+
+ if (Settings::gui().mControllerMenus && buttons.size() > 1 && this->mButtons.empty())
+ {
+ // First button is selected by default
+ button->setStateSelected(true);
+ }
+
this->mButtons.push_back(button);
}
}
@@ -382,6 +463,44 @@ namespace MWGui
}
}
+ bool InfoBoxDialog::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_A)
+ {
+ if (mControllerFocus >= 0 && mControllerFocus < static_cast(mButtons.size()))
+ onButtonClicked(mButtons[mControllerFocus]);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ {
+ if (mButtons.size() == 1)
+ onButtonClicked(mButtons[0]);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP)
+ {
+ if (mButtons.size() <= 1)
+ return true;
+ if (mButtons.size() == 2 && mControllerFocus == 0)
+ return true;
+
+ setControllerFocus(mButtons, mControllerFocus, false);
+ mControllerFocus = wrap(mControllerFocus - 1, mButtons.size());
+ setControllerFocus(mButtons, mControllerFocus, true);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
+ {
+ if (mButtons.size() <= 1)
+ return true;
+ if (mButtons.size() == 2 && mControllerFocus == static_cast(mButtons.size()) - 1)
+ return true;
+
+ setControllerFocus(mButtons, mControllerFocus, false);
+ mControllerFocus = wrap(mControllerFocus + 1, mButtons.size());
+ setControllerFocus(mButtons, mControllerFocus, true);
+ }
+
+ return true;
+ }
+
/* ClassChoiceDialog */
ClassChoiceDialog::ClassChoiceDialog()
@@ -450,14 +569,25 @@ namespace MWGui
MyGUI::Button* descriptionButton;
getWidget(descriptionButton, "DescriptionButton");
descriptionButton->eventMouseButtonClick += MyGUI::newDelegate(this, &CreateClassDialog::onDescriptionClicked);
+ mButtons.push_back(descriptionButton);
MyGUI::Button* backButton;
getWidget(backButton, "BackButton");
backButton->eventMouseButtonClick += MyGUI::newDelegate(this, &CreateClassDialog::onBackClicked);
+ mButtons.push_back(backButton);
MyGUI::Button* okButton;
getWidget(okButton, "OKButton");
okButton->eventMouseButtonClick += MyGUI::newDelegate(this, &CreateClassDialog::onOkClicked);
+ mButtons.push_back(okButton);
+
+ if (Settings::gui().mControllerMenus)
+ {
+ okButton->setStateSelected(true);
+ mControllerButtons.lStick = "#{sMouse}";
+ mControllerButtons.a = "#{sSelect}";
+ mControllerButtons.b = "#{sBack}";
+ }
// Set default skills, attributes
@@ -545,13 +675,56 @@ namespace MWGui
getWidget(okButton, "OKButton");
if (shown)
+ {
okButton->setCaption(
MyGUI::UString(MWBase::Environment::get().getWindowManager()->getGameSettingString("sNext", {})));
+ mControllerButtons.x = "#{sNext}";
+ }
+ else if (Settings::gui().mControllerMenus)
+ {
+ okButton->setCaption(
+ MyGUI::UString(MWBase::Environment::get().getWindowManager()->getGameSettingString("sDone", {})));
+ mControllerButtons.x = "#{sDone}";
+ }
else
okButton->setCaption(
MyGUI::UString(MWBase::Environment::get().getWindowManager()->getGameSettingString("sOK", {})));
}
+ bool CreateClassDialog::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_A)
+ {
+ if (mControllerFocus == 0)
+ onDescriptionClicked(mButtons[0]);
+ else if (mControllerFocus == 1)
+ onBackClicked(mButtons[1]);
+ else
+ onOkClicked(mButtons[2]);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ {
+ onBackClicked(mButtons[1]);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_X)
+ {
+ onOkClicked(mButtons[2]);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT)
+ {
+ setControllerFocus(mButtons, mControllerFocus, false);
+ mControllerFocus = wrap(mControllerFocus - 1, mButtons.size());
+ setControllerFocus(mButtons, mControllerFocus, true);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT)
+ {
+ setControllerFocus(mButtons, mControllerFocus, false);
+ mControllerFocus = wrap(mControllerFocus + 1, mButtons.size());
+ setControllerFocus(mButtons, mControllerFocus, true);
+ }
+ return true;
+ }
+
// widget controls
void CreateClassDialog::onDialogCancel()
@@ -708,6 +881,9 @@ namespace MWGui
MyGUI::Button* cancelButton;
getWidget(cancelButton, "CancelButton");
cancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SelectSpecializationDialog::onCancelClicked);
+
+ mControllerButtons.a = "#{sSelect}";
+ mControllerButtons.b = "#{sCancel}";
}
SelectSpecializationDialog::~SelectSpecializationDialog() {}
@@ -739,6 +915,16 @@ namespace MWGui
return true;
}
+ bool SelectSpecializationDialog::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ {
+ onCancelClicked(nullptr);
+ return true;
+ }
+ return false;
+ }
+
/* SelectAttributeDialog */
SelectAttributeDialog::SelectAttributeDialog()
@@ -760,6 +946,7 @@ namespace MWGui
widget->setAttributeId(attribute.mId);
widget->eventClicked += MyGUI::newDelegate(this, &SelectAttributeDialog::onAttributeClicked);
ToolTips::createAttributeToolTip(widget, attribute.mId);
+ mAttributeButtons.emplace_back(widget);
}
attributes->setVisibleVScroll(false);
@@ -770,6 +957,16 @@ namespace MWGui
MyGUI::Button* cancelButton;
getWidget(cancelButton, "CancelButton");
cancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SelectAttributeDialog::onCancelClicked);
+
+ if (Settings::gui().mControllerMenus)
+ {
+ mControllerFocus = 0;
+ if (mAttributeButtons.size() > 0)
+ mAttributeButtons[0]->setStateSelected(true);
+
+ mControllerButtons.a = "#{sSelect}";
+ mControllerButtons.b = "#{sCancel}";
+ }
}
// widget controls
@@ -791,6 +988,33 @@ namespace MWGui
return true;
}
+ bool SelectAttributeDialog::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_A)
+ {
+ if (mControllerFocus >= 0 && mControllerFocus < static_cast(mAttributeButtons.size()))
+ onAttributeClicked(mAttributeButtons[mControllerFocus]);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ {
+ onCancelClicked(nullptr);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP)
+ {
+ mAttributeButtons[mControllerFocus]->setStateSelected(false);
+ mControllerFocus = wrap(mControllerFocus - 1, mAttributeButtons.size());
+ mAttributeButtons[mControllerFocus]->setStateSelected(true);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
+ {
+ mAttributeButtons[mControllerFocus]->setStateSelected(false);
+ mControllerFocus = wrap(mControllerFocus + 1, mAttributeButtons.size());
+ mAttributeButtons[mControllerFocus]->setStateSelected(true);
+ }
+
+ return true;
+ }
+
/* SelectSkillDialog */
SelectSkillDialog::SelectSkillDialog()
@@ -820,6 +1044,7 @@ namespace MWGui
skillWidget->setSkillId(skill.mId);
skillWidget->eventClicked += MyGUI::newDelegate(this, &SelectSkillDialog::onSkillClicked);
ToolTips::createSkillToolTip(skillWidget, skill.mId);
+ mSkillButtons.emplace_back(skillWidget);
}
for (const auto& [widget, coord] : specializations)
{
@@ -832,6 +1057,16 @@ namespace MWGui
MyGUI::Button* cancelButton;
getWidget(cancelButton, "CancelButton");
cancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SelectSkillDialog::onCancelClicked);
+
+ if (Settings::gui().mControllerMenus)
+ {
+ mControllerFocus = 0;
+ if (mSkillButtons.size() > 0)
+ mSkillButtons[0]->setStateSelected(true);
+
+ mControllerButtons.a = "#{sSelect}";
+ mControllerButtons.b = "#{sCancel}";
+ }
}
SelectSkillDialog::~SelectSkillDialog() {}
@@ -855,6 +1090,51 @@ namespace MWGui
return true;
}
+ bool SelectSkillDialog::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_A)
+ {
+ if (mControllerFocus >= 0 && mControllerFocus < static_cast(mSkillButtons.size()))
+ onSkillClicked(mSkillButtons[mControllerFocus]);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ {
+ onCancelClicked(nullptr);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP)
+ {
+ mSkillButtons[mControllerFocus]->setStateSelected(false);
+ mControllerFocus = wrap(mControllerFocus - 1, mSkillButtons.size());
+ mSkillButtons[mControllerFocus]->setStateSelected(true);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
+ {
+ mSkillButtons[mControllerFocus]->setStateSelected(false);
+ mControllerFocus = wrap(mControllerFocus + 1, mSkillButtons.size());
+ mSkillButtons[mControllerFocus]->setStateSelected(true);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT)
+ {
+ mSkillButtons[mControllerFocus]->setStateSelected(false);
+ if (mControllerFocus < 9)
+ mControllerFocus += 18;
+ else
+ mControllerFocus -= 9;
+ mSkillButtons[mControllerFocus]->setStateSelected(true);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT)
+ {
+ mSkillButtons[mControllerFocus]->setStateSelected(false);
+ if (mControllerFocus >= 18)
+ mControllerFocus -= 18;
+ else
+ mControllerFocus += 9;
+ mSkillButtons[mControllerFocus]->setStateSelected(true);
+ }
+
+ return true;
+ }
+
/* DescriptionDialog */
DescriptionDialog::DescriptionDialog()
@@ -873,6 +1153,8 @@ namespace MWGui
// Make sure the edit box has focus
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mTextEdit);
+
+ mControllerButtons.a = "#{sOk}";
}
DescriptionDialog::~DescriptionDialog() {}
@@ -904,4 +1186,13 @@ namespace MWGui
imageBox->setImageTexture(classImage);
}
+ bool DescriptionDialog::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_A || arg.button == SDL_CONTROLLER_BUTTON_B)
+ {
+ onOkClicked(nullptr);
+ return true;
+ }
+ return false;
+ }
}
diff --git a/apps/openmw/mwgui/class.hpp b/apps/openmw/mwgui/class.hpp
index f89a0c7d88..a4db03d4ab 100644
--- a/apps/openmw/mwgui/class.hpp
+++ b/apps/openmw/mwgui/class.hpp
@@ -42,6 +42,7 @@ namespace MWGui
protected:
void onButtonClicked(MyGUI::Widget* _sender);
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
private:
void fitToText(MyGUI::TextBox* widget);
@@ -50,6 +51,7 @@ namespace MWGui
MyGUI::TextBox* mText;
MyGUI::Widget* mButtonBar;
std::vector mButtons;
+ int mControllerFocus = 0;
};
// Lets the player choose between 3 ways of creating a class
@@ -92,10 +94,14 @@ namespace MWGui
protected:
void onOkClicked(MyGUI::Widget* _sender);
void onBackClicked(MyGUI::Widget* _sender);
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
+ bool mOkButtonFocus = true;
private:
MyGUI::ImageBox* mClassImage;
MyGUI::TextBox* mClassName;
+ MyGUI::Button* mBackButton;
+ MyGUI::Button* mOkButton;
ESM::RefId mCurrentClassId;
};
@@ -140,11 +146,15 @@ namespace MWGui
MyGUI::ImageBox* mClassImage;
MyGUI::ListBox* mClassList;
MyGUI::TextBox* mSpecializationName;
+ MyGUI::Button* mBackButton;
+ MyGUI::Button* mOkButton;
Widgets::MWAttributePtr mFavoriteAttribute[2];
Widgets::MWSkillPtr mMajorSkill[5];
Widgets::MWSkillPtr mMinorSkill[5];
ESM::RefId mCurrentClassId;
+
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
};
class SelectSpecializationDialog : public WindowModal
@@ -173,6 +183,7 @@ namespace MWGui
protected:
void onSpecializationClicked(MyGUI::Widget* _sender);
void onCancelClicked(MyGUI::Widget* _sender);
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
private:
MyGUI::TextBox *mSpecialization0, *mSpecialization1, *mSpecialization2;
@@ -206,6 +217,9 @@ namespace MWGui
protected:
void onAttributeClicked(Widgets::MWAttributePtr _sender);
void onCancelClicked(MyGUI::Widget* _sender);
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
+ int mControllerFocus;
+ std::vector mAttributeButtons;
private:
ESM::RefId mAttributeId;
@@ -237,6 +251,9 @@ namespace MWGui
protected:
void onSkillClicked(Widgets::MWSkillPtr _sender);
void onCancelClicked(MyGUI::Widget* _sender);
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
+ int mControllerFocus;
+ std::vector mSkillButtons;
private:
ESM::RefId mSkillId;
@@ -258,6 +275,7 @@ namespace MWGui
protected:
void onOkClicked(MyGUI::Widget* _sender);
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
private:
MyGUI::EditBox* mTextEdit;
@@ -314,6 +332,7 @@ namespace MWGui
private:
MyGUI::EditBox* mEditName;
MyGUI::TextBox* mSpecializationName;
+ std::vector mButtons;
Widgets::MWAttributePtr mFavoriteAttribute0, mFavoriteAttribute1;
std::array mMajorSkill;
std::array mMinorSkill;
@@ -329,6 +348,9 @@ namespace MWGui
Widgets::MWAttributePtr mAffectedAttribute;
Widgets::MWSkillPtr mAffectedSkill;
+
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
+ int mControllerFocus = 2;
};
}
#endif
diff --git a/apps/openmw/mwgui/companionwindow.cpp b/apps/openmw/mwgui/companionwindow.cpp
index 240198eddc..4a7863b856 100644
--- a/apps/openmw/mwgui/companionwindow.cpp
+++ b/apps/openmw/mwgui/companionwindow.cpp
@@ -6,6 +6,8 @@
#include
#include
+#include
+
#include "../mwbase/environment.hpp"
#include "../mwbase/windowmanager.hpp"
@@ -14,6 +16,7 @@
#include "companionitemmodel.hpp"
#include "countdialog.hpp"
#include "draganddrop.hpp"
+#include "inventorywindow.hpp"
#include "itemview.hpp"
#include "messagebox.hpp"
#include "sortfilteritemmodel.hpp"
@@ -58,6 +61,11 @@ namespace MWGui
mCloseButton->eventMouseButtonClick += MyGUI::newDelegate(this, &CompanionWindow::onCloseButtonClicked);
setCoord(200, 0, 600, 300);
+
+ mControllerButtons.a = "#{sTake}";
+ mControllerButtons.b = "#{sClose}";
+ mControllerButtons.r3 = "#{sInfo}";
+ mControllerButtons.l2 = "#{sInventory}";
}
void CompanionWindow::onItemSelected(int index)
@@ -93,8 +101,13 @@ namespace MWGui
name += MWGui::ToolTips::getSoulString(object.getCellRef());
dialog->openCountDialog(name, "#{sTake}", count);
dialog->eventOkClicked.clear();
- dialog->eventOkClicked += MyGUI::newDelegate(this, &CompanionWindow::dragItem);
+ if (Settings::gui().mControllerMenus)
+ dialog->eventOkClicked += MyGUI::newDelegate(this, &CompanionWindow::takeItem);
+ else
+ dialog->eventOkClicked += MyGUI::newDelegate(this, &CompanionWindow::dragItem);
}
+ else if (Settings::gui().mControllerMenus)
+ takeItem(nullptr, count);
else
dragItem(nullptr, count);
}
@@ -110,6 +123,29 @@ namespace MWGui
mDragAndDrop->startDrag(mSelectedItem, mSortModel, mModel, mItemView, count);
}
+ void CompanionWindow::takeItem(MyGUI::Widget* sender, int count)
+ {
+ if (!mModel)
+ return;
+
+ const ItemStack& item = mModel->getItem(mSelectedItem);
+ if (!mModel->onTakeItem(item.mBase, count))
+ return;
+
+ MWGui::InventoryWindow* inventoryWindow = MWBase::Environment::get().getWindowManager()->getInventoryWindow();
+ ItemModel* playerModel = inventoryWindow->getModel();
+
+ mModel->moveItem(item, count, playerModel);
+
+ inventoryWindow->updateItemView();
+ mItemView->update();
+
+ // play the item's sound
+ MWWorld::Ptr itemBase = item.mBase;
+ const ESM::RefId& sound = itemBase.getClass().getUpSoundId(itemBase);
+ MWBase::Environment::get().getWindowManager()->playSound(sound);
+ }
+
void CompanionWindow::onBackgroundSelected()
{
if (mDragAndDrop->mIsOnDragAndDrop)
@@ -202,4 +238,31 @@ namespace MWGui
mSortModel = nullptr;
}
+ bool CompanionWindow::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_A)
+ {
+ int index = mItemView->getControllerFocus();
+ if (index >= 0 && index < mItemView->getItemCount())
+ onItemSelected(index);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ {
+ onCloseButtonClicked(mCloseButton);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_RIGHTSTICK || arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP
+ || arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN || arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT
+ || arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT)
+ {
+ mItemView->onControllerButton(arg.button);
+ }
+
+ return true;
+ }
+
+ void CompanionWindow::setActiveControllerWindow(bool active)
+ {
+ mItemView->setActiveControllerWindow(active);
+ WindowBase::setActiveControllerWindow(active);
+ }
}
diff --git a/apps/openmw/mwgui/companionwindow.hpp b/apps/openmw/mwgui/companionwindow.hpp
index 97f3a0072e..c0cd87c9d5 100644
--- a/apps/openmw/mwgui/companionwindow.hpp
+++ b/apps/openmw/mwgui/companionwindow.hpp
@@ -1,6 +1,8 @@
#ifndef OPENMW_MWGUI_COMPANIONWINDOW_H
#define OPENMW_MWGUI_COMPANIONWINDOW_H
+#include "companionitemmodel.hpp"
+#include "itemmodel.hpp"
#include "referenceinterface.hpp"
#include "windowbase.hpp"
@@ -32,6 +34,12 @@ namespace MWGui
std::string_view getWindowIdForLua() const override { return "Companion"; }
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
+ void setActiveControllerWindow(bool active) override;
+
+ MWGui::ItemView* getItemView() { return mItemView; }
+ ItemModel* getModel() { return mModel; }
+
private:
ItemView* mItemView;
SortFilterItemModel* mSortModel;
@@ -50,6 +58,7 @@ namespace MWGui
void onNameFilterChanged(MyGUI::EditBox* _sender);
void onBackgroundSelected();
void dragItem(MyGUI::Widget* sender, int count);
+ void takeItem(MyGUI::Widget* sender, int count);
void onMessageBoxButtonClicked(int button);
diff --git a/apps/openmw/mwgui/confirmationdialog.cpp b/apps/openmw/mwgui/confirmationdialog.cpp
index 48b209f17e..f858b9628a 100644
--- a/apps/openmw/mwgui/confirmationdialog.cpp
+++ b/apps/openmw/mwgui/confirmationdialog.cpp
@@ -3,6 +3,8 @@
#include
#include
+#include
+
#include "../mwbase/environment.hpp"
#include "../mwbase/windowmanager.hpp"
@@ -17,6 +19,13 @@ namespace MWGui
mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ConfirmationDialog::onCancelButtonClicked);
mOkButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ConfirmationDialog::onOkButtonClicked);
+
+ if (Settings::gui().mControllerMenus)
+ {
+ mDisableGamepadCursor = true;
+ mControllerButtons.a = "#{sOk}";
+ mControllerButtons.b = "#{sCancel}";
+ }
}
void ConfirmationDialog::askForConfirmation(const std::string& message)
@@ -35,6 +44,13 @@ namespace MWGui
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mOkButton);
+ if (Settings::gui().mControllerMenus)
+ {
+ mOkButtonFocus = true;
+ mOkButton->setStateSelected(true);
+ mCancelButton->setStateSelected(false);
+ }
+
center();
}
@@ -56,4 +72,28 @@ namespace MWGui
eventOkClicked();
}
+
+ bool ConfirmationDialog::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_A)
+ {
+ if (mOkButtonFocus)
+ onOkButtonClicked(mOkButton);
+ else
+ onCancelButtonClicked(mCancelButton);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ {
+ onCancelButtonClicked(mCancelButton);
+ }
+ else if ((arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT && !mOkButtonFocus)
+ || (arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT && mOkButtonFocus))
+ {
+ mOkButtonFocus = !mOkButtonFocus;
+ mOkButton->setStateSelected(mOkButtonFocus);
+ mCancelButton->setStateSelected(!mOkButtonFocus);
+ }
+
+ return true;
+ }
}
diff --git a/apps/openmw/mwgui/confirmationdialog.hpp b/apps/openmw/mwgui/confirmationdialog.hpp
index 1344f2a501..9b26e3a3c9 100644
--- a/apps/openmw/mwgui/confirmationdialog.hpp
+++ b/apps/openmw/mwgui/confirmationdialog.hpp
@@ -27,6 +27,9 @@ namespace MWGui
void onCancelButtonClicked(MyGUI::Widget* _sender);
void onOkButtonClicked(MyGUI::Widget* _sender);
+
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
+ bool mOkButtonFocus = true;
};
}
diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp
index 6ab2c862d4..0be99d38a0 100644
--- a/apps/openmw/mwgui/container.cpp
+++ b/apps/openmw/mwgui/container.cpp
@@ -3,6 +3,8 @@
#include
#include
+#include
+
#include "../mwbase/environment.hpp"
#include "../mwbase/mechanicsmanager.hpp"
#include "../mwbase/scriptmanager.hpp"
@@ -54,6 +56,12 @@ namespace MWGui
mTakeButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerWindow::onTakeAllButtonClicked);
setCoord(200, 0, 600, 300);
+
+ mControllerButtons.a = "#{sTake}";
+ mControllerButtons.b = "#{sClose}";
+ mControllerButtons.x = "#{sTakeAll}";
+ mControllerButtons.r3 = "#{sInfo}";
+ mControllerButtons.l2 = "#{sInventory}";
}
void ContainerWindow::onItemSelected(int index)
@@ -88,8 +96,13 @@ namespace MWGui
name += MWGui::ToolTips::getSoulString(object.getCellRef());
dialog->openCountDialog(name, "#{sTake}", count);
dialog->eventOkClicked.clear();
- dialog->eventOkClicked += MyGUI::newDelegate(this, &ContainerWindow::dragItem);
+ if (Settings::gui().mControllerMenus)
+ dialog->eventOkClicked += MyGUI::newDelegate(this, &ContainerWindow::takeItem);
+ else
+ dialog->eventOkClicked += MyGUI::newDelegate(this, &ContainerWindow::dragItem);
}
+ else if (Settings::gui().mControllerMenus)
+ takeItem(nullptr, count);
else
dragItem(nullptr, count);
}
@@ -105,6 +118,29 @@ namespace MWGui
mDragAndDrop->startDrag(mSelectedItem, mSortModel, mModel, mItemView, count);
}
+ void ContainerWindow::takeItem(MyGUI::Widget* sender, int count)
+ {
+ if (!mModel)
+ return;
+
+ const ItemStack& item = mModel->getItem(mSelectedItem);
+ if (!onTakeItem(item, count))
+ return;
+
+ MWGui::InventoryWindow* inventoryWindow = MWBase::Environment::get().getWindowManager()->getInventoryWindow();
+ ItemModel* playerModel = inventoryWindow->getModel();
+
+ mModel->moveItem(item, count, playerModel);
+
+ inventoryWindow->updateItemView();
+ mItemView->update();
+
+ // play the item's sound
+ MWWorld::Ptr itemBase = item.mBase;
+ const ESM::RefId& sound = itemBase.getClass().getUpSoundId(itemBase);
+ MWBase::Environment::get().getWindowManager()->playSound(sound);
+ }
+
void ContainerWindow::dropItem()
{
if (!mModel)
@@ -320,4 +356,47 @@ namespace MWGui
if (mModel && mModel->usesContainer(ptr))
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Container);
}
+
+ ControllerButtonStr* ContainerWindow::getControllerButtons()
+ {
+ mControllerButtons.r1 = mDisposeCorpseButton->getVisible() ? "#{sDisposeofCorpse}" : "";
+ return &mControllerButtons;
+ }
+
+ bool ContainerWindow::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_A)
+ {
+ int index = mItemView->getControllerFocus();
+ if (index >= 0 && index < mItemView->getItemCount())
+ onItemSelected(index);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ {
+ onCloseButtonClicked(mCloseButton);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_X)
+ {
+ onTakeAllButtonClicked(mTakeButton);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER)
+ {
+ if (mDisposeCorpseButton->getVisible())
+ onDisposeCorpseButtonClicked(mDisposeCorpseButton);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_RIGHTSTICK || arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP
+ || arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN || arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT
+ || arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT)
+ {
+ mItemView->onControllerButton(arg.button);
+ }
+
+ return true;
+ }
+
+ void ContainerWindow::setActiveControllerWindow(bool active)
+ {
+ mItemView->setActiveControllerWindow(active);
+ WindowBase::setActiveControllerWindow(active);
+ }
}
diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp
index 555fa8e1ae..96ee6a6380 100644
--- a/apps/openmw/mwgui/container.hpp
+++ b/apps/openmw/mwgui/container.hpp
@@ -40,6 +40,13 @@ namespace MWGui
std::string_view getWindowIdForLua() const override { return "Container"; }
+ ControllerButtonStr* getControllerButtons() override;
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
+ void setActiveControllerWindow(bool active) override;
+
+ MWGui::ItemView* getItemView() { return mItemView; }
+ ItemModel* getModel() { return mModel; }
+
private:
DragAndDrop* mDragAndDrop;
@@ -55,6 +62,7 @@ namespace MWGui
void onItemSelected(int index);
void onBackgroundSelected();
void dragItem(MyGUI::Widget* sender, int count);
+ void takeItem(MyGUI::Widget* sender, int count);
void dropItem();
void onCloseButtonClicked(MyGUI::Widget* _sender);
void onTakeAllButtonClicked(MyGUI::Widget* _sender);
diff --git a/apps/openmw/mwgui/controllerbuttonsoverlay.cpp b/apps/openmw/mwgui/controllerbuttonsoverlay.cpp
new file mode 100644
index 0000000000..9466f40105
--- /dev/null
+++ b/apps/openmw/mwgui/controllerbuttonsoverlay.cpp
@@ -0,0 +1,106 @@
+#include "controllerbuttonsoverlay.hpp"
+
+#include "../mwbase/environment.hpp"
+#include "../mwbase/windowmanager.hpp"
+
+namespace MWGui
+{
+ ControllerButtonsOverlay::ControllerButtonsOverlay()
+ : WindowBase("openmw_controllerbuttons.layout")
+ {
+ getWidget(mImageA, "BtnAImage");
+ getWidget(mTextA, "BtnAText");
+
+ getWidget(mImageB, "BtnBImage");
+ getWidget(mTextB, "BtnBText");
+
+ getWidget(mImageDpad, "BtnDpadImage");
+ getWidget(mTextDpad, "BtnDpadText");
+
+ getWidget(mImageL1, "BtnL1Image");
+ getWidget(mTextL1, "BtnL1Text");
+
+ getWidget(mImageL2, "BtnL2Image");
+ getWidget(mTextL2, "BtnL2Text");
+
+ getWidget(mImageL3, "BtnL3Image");
+ getWidget(mTextL3, "BtnL3Text");
+
+ getWidget(mImageLStick, "BtnLStickImage");
+ getWidget(mTextLStick, "BtnLStickText");
+
+ getWidget(mImageMenu, "BtnMenuImage");
+ getWidget(mTextMenu, "BtnMenuText");
+
+ getWidget(mImageR1, "BtnR1Image");
+ getWidget(mTextR1, "BtnR1Text");
+
+ getWidget(mImageR2, "BtnR2Image");
+ getWidget(mTextR2, "BtnR2Text");
+
+ getWidget(mImageR3, "BtnR3Image");
+ getWidget(mTextR3, "BtnR3Text");
+
+ getWidget(mImageRStick, "BtnRStickImage");
+ getWidget(mTextRStick, "BtnRStickText");
+
+ getWidget(mImageView, "BtnViewImage");
+ getWidget(mTextView, "BtnViewText");
+
+ getWidget(mImageX, "BtnXImage");
+ getWidget(mTextX, "BtnXText");
+
+ getWidget(mImageY, "BtnYImage");
+ getWidget(mTextY, "BtnYText");
+
+ getWidget(mHBox, "ButtonBox");
+ }
+
+ void ControllerButtonsOverlay::setButtons(ControllerButtonStr* buttons)
+ {
+ int buttonCount = 0;
+ buttonCount += updateButton(mTextA, mImageA, buttons->a);
+ buttonCount += updateButton(mTextB, mImageB, buttons->b);
+ buttonCount += updateButton(mTextDpad, mImageDpad, buttons->dpad);
+ buttonCount += updateButton(mTextL1, mImageL1, buttons->l1);
+ buttonCount += updateButton(mTextL2, mImageL2, buttons->l2);
+ buttonCount += updateButton(mTextL3, mImageL3, buttons->l3);
+ buttonCount += updateButton(mTextLStick, mImageLStick, buttons->lStick);
+ buttonCount += updateButton(mTextMenu, mImageMenu, buttons->menu);
+ buttonCount += updateButton(mTextR1, mImageR1, buttons->r1);
+ buttonCount += updateButton(mTextR2, mImageR2, buttons->r2);
+ buttonCount += updateButton(mTextR3, mImageR3, buttons->r3);
+ buttonCount += updateButton(mTextRStick, mImageRStick, buttons->rStick);
+ buttonCount += updateButton(mTextView, mImageView, buttons->view);
+ buttonCount += updateButton(mTextX, mImageX, buttons->x);
+ buttonCount += updateButton(mTextY, mImageY, buttons->y);
+ mHBox->notifyChildrenSizeChanged();
+
+ setVisible(buttonCount > 0);
+ }
+
+ int ControllerButtonsOverlay::updateButton(
+ MyGUI::TextBox* text, MyGUI::ImageBox* image, const std::string& buttonStr)
+ {
+ if (buttonStr.length() > 0)
+ {
+ image->setVisible(true);
+ image->setUserString("Hidden", "false");
+
+ text->setCaptionWithReplacing(buttonStr);
+ text->setVisible(true);
+ text->setUserString("Hidden", "false");
+ text->setSize(text->getTextSize().width + 16, 48);
+ return 1;
+ }
+ else
+ {
+ image->setVisible(false);
+ image->setUserString("Hidden", "true");
+
+ text->setVisible(false);
+ text->setUserString("Hidden", "true");
+ return 0;
+ }
+ }
+}
diff --git a/apps/openmw/mwgui/controllerbuttonsoverlay.hpp b/apps/openmw/mwgui/controllerbuttonsoverlay.hpp
new file mode 100644
index 0000000000..7008384bee
--- /dev/null
+++ b/apps/openmw/mwgui/controllerbuttonsoverlay.hpp
@@ -0,0 +1,72 @@
+#ifndef MWGUI_CONTROLLERBUTTONSOVERLAY_H
+#define MWGUI_CONTROLLERBUTTONSOVERLAY_H
+
+#include
+#include
+
+#include
+
+#include "windowbase.hpp"
+
+namespace MWGui
+{
+ class ControllerButtonsOverlay : public WindowBase
+ {
+ public:
+ ControllerButtonsOverlay();
+
+ void setButtons(ControllerButtonStr* buttons);
+
+ private:
+ MyGUI::ImageBox* mImageA;
+ MyGUI::TextBox* mTextA;
+
+ MyGUI::ImageBox* mImageB;
+ MyGUI::TextBox* mTextB;
+
+ MyGUI::ImageBox* mImageDpad;
+ MyGUI::TextBox* mTextDpad;
+
+ MyGUI::ImageBox* mImageL1;
+ MyGUI::TextBox* mTextL1;
+
+ MyGUI::ImageBox* mImageL2;
+ MyGUI::TextBox* mTextL2;
+
+ MyGUI::ImageBox* mImageL3;
+ MyGUI::TextBox* mTextL3;
+
+ MyGUI::ImageBox* mImageLStick;
+ MyGUI::TextBox* mTextLStick;
+
+ MyGUI::ImageBox* mImageMenu;
+ MyGUI::TextBox* mTextMenu;
+
+ MyGUI::ImageBox* mImageR1;
+ MyGUI::TextBox* mTextR1;
+
+ MyGUI::ImageBox* mImageR2;
+ MyGUI::TextBox* mTextR2;
+
+ MyGUI::ImageBox* mImageR3;
+ MyGUI::TextBox* mTextR3;
+
+ MyGUI::ImageBox* mImageRStick;
+ MyGUI::TextBox* mTextRStick;
+
+ MyGUI::ImageBox* mImageView;
+ MyGUI::TextBox* mTextView;
+
+ MyGUI::ImageBox* mImageX;
+ MyGUI::TextBox* mTextX;
+
+ MyGUI::ImageBox* mImageY;
+ MyGUI::TextBox* mTextY;
+
+ Gui::HBox* mHBox;
+
+ int updateButton(MyGUI::TextBox* text, MyGUI::ImageBox* image, const std::string& buttonStr);
+ };
+}
+
+#endif
diff --git a/apps/openmw/mwgui/countdialog.cpp b/apps/openmw/mwgui/countdialog.cpp
index 2ca6657a17..816d67921c 100644
--- a/apps/openmw/mwgui/countdialog.cpp
+++ b/apps/openmw/mwgui/countdialog.cpp
@@ -27,6 +27,9 @@ namespace MWGui
mSlider->eventScrollChangePosition += MyGUI::newDelegate(this, &CountDialog::onSliderMoved);
// make sure we read the enter key being pressed to accept multiple items
mItemEdit->eventEditSelectAccept += MyGUI::newDelegate(this, &CountDialog::onEnterKeyPressed);
+
+ mControllerButtons.a = "#{sOk}";
+ mControllerButtons.b = "#{sCancel}";
}
void CountDialog::openCountDialog(const std::string& item, const std::string& message, const int maxCount)
@@ -38,7 +41,7 @@ namespace MWGui
MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize();
mSlider->setScrollRange(maxCount);
- mItemText->setCaption(item);
+ mItemText->setCaptionWithReplacing(item);
int width = std::max(mItemText->getTextSize().width + 160, 320);
setCoord(viewSize.width / 2 - width / 2, viewSize.height / 2 - mMainWidget->getHeight() / 2, width,
@@ -54,6 +57,13 @@ namespace MWGui
mItemEdit->setValue(maxCount);
}
+ void CountDialog::setCount(int count)
+ {
+ count = std::clamp(count, 1, (int)mSlider->getScrollRange());
+ mSlider->setScrollPosition(count - 1);
+ mItemEdit->setValue(count);
+ }
+
void CountDialog::onCancelButtonClicked(MyGUI::Widget* _sender)
{
setVisible(false);
@@ -86,4 +96,22 @@ namespace MWGui
{
mItemEdit->setValue(_position + 1);
}
+
+ bool CountDialog::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_A)
+ onOkButtonClicked(mOkButton);
+ else if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ onCancelButtonClicked(mCancelButton);
+ else if (arg.button == SDL_CONTROLLER_BUTTON_LEFTSHOULDER)
+ setCount(1);
+ else if (arg.button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER)
+ setCount((int)mSlider->getScrollRange());
+ 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;
+ }
}
diff --git a/apps/openmw/mwgui/countdialog.hpp b/apps/openmw/mwgui/countdialog.hpp
index 9cdf231549..b3a1aab3b3 100644
--- a/apps/openmw/mwgui/countdialog.hpp
+++ b/apps/openmw/mwgui/countdialog.hpp
@@ -3,6 +3,8 @@
#include "windowbase.hpp"
+#include
+
namespace Gui
{
class NumericEditBox;
@@ -15,6 +17,7 @@ namespace MWGui
public:
CountDialog();
void openCountDialog(const std::string& item, const std::string& message, const int maxCount);
+ void setCount(int count);
typedef MyGUI::delegates::MultiDelegate EventHandle_WidgetInt;
@@ -24,7 +27,7 @@ namespace MWGui
EventHandle_WidgetInt eventOkClicked;
private:
- MyGUI::ScrollBar* mSlider;
+ Gui::ScrollBar* mSlider;
Gui::NumericEditBox* mItemEdit;
MyGUI::TextBox* mItemText;
MyGUI::TextBox* mLabelText;
@@ -36,6 +39,7 @@ namespace MWGui
void onEditValueChanged(int value);
void onSliderMoved(MyGUI::ScrollBar* _sender, size_t _position);
void onEnterKeyPressed(MyGUI::EditBox* _sender);
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
};
}
diff --git a/apps/openmw/mwgui/dialogue.cpp b/apps/openmw/mwgui/dialogue.cpp
index 6b1e007770..b3f83f3771 100644
--- a/apps/openmw/mwgui/dialogue.cpp
+++ b/apps/openmw/mwgui/dialogue.cpp
@@ -88,6 +88,10 @@ namespace MWGui
mBribe10Button->eventMouseButtonClick += MyGUI::newDelegate(this, &PersuasionDialog::onPersuade);
mBribe100Button->eventMouseButtonClick += MyGUI::newDelegate(this, &PersuasionDialog::onPersuade);
mBribe1000Button->eventMouseButtonClick += MyGUI::newDelegate(this, &PersuasionDialog::onPersuade);
+
+ mDisableGamepadCursor = Settings::gui().mControllerMenus;
+ mControllerButtons.a = "#{sSelect}";
+ mControllerButtons.b = "#{sCancel}";
}
void PersuasionDialog::adjustAction(MyGUI::Widget* action, int& totalHeight)
@@ -144,6 +148,24 @@ namespace MWGui
else
mMainWidget->setSize(mInitialMainWidgetWidth, mMainWidget->getSize().height);
+ if (Settings::gui().mControllerMenus)
+ {
+ mControllerFocus = 0;
+ mButtons.clear();
+ mButtons.push_back(mAdmireButton);
+ mButtons.push_back(mIntimidateButton);
+ mButtons.push_back(mTauntButton);
+ if (mBribe10Button->getEnabled())
+ mButtons.push_back(mBribe10Button);
+ if (mBribe100Button->getEnabled())
+ mButtons.push_back(mBribe100Button);
+ if (mBribe1000Button->getEnabled())
+ mButtons.push_back(mBribe1000Button);
+
+ for (size_t i = 0; i < mButtons.size(); i++)
+ mButtons[i]->setStateSelected(i == 0);
+ }
+
WindowModal::onOpen();
}
@@ -152,6 +174,31 @@ namespace MWGui
return mAdmireButton;
}
+ bool PersuasionDialog::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_A)
+ {
+ onPersuade(mButtons[mControllerFocus]);
+ MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ onCancel(mCancelButton);
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP)
+ {
+ setControllerFocus(mButtons, mControllerFocus, false);
+ mControllerFocus = wrap(mControllerFocus - 1, mButtons.size());
+ setControllerFocus(mButtons, mControllerFocus, true);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
+ {
+ setControllerFocus(mButtons, mControllerFocus, false);
+ mControllerFocus = wrap(mControllerFocus + 1, mButtons.size());
+ setControllerFocus(mButtons, mControllerFocus, true);
+ }
+
+ return true;
+ }
+
// --------------------------------------------------------------------------------------------------
Response::Response(std::string_view text, std::string_view title, bool needMargin)
@@ -335,6 +382,11 @@ namespace MWGui
mMainWidget->castType()->eventWindowChangeCoord
+= MyGUI::newDelegate(this, &DialogueWindow::onWindowResize);
+
+ mControllerScrollWidget = mHistory->getParent();
+ mControllerButtons.a = "#{sAsk}";
+ mControllerButtons.b = "#{sGoodbye}";
+ mControllerButtons.rStick = "#{sScrollup}";
}
void DialogueWindow::onTradeComplete()
@@ -488,6 +540,14 @@ namespace MWGui
updateTopics();
updateTopicsPane(); // force update for new services
+ if (Settings::gui().mControllerMenus && !sameActor)
+ {
+ setControllerFocus(mControllerFocus, false);
+ // Reset focus to very top. Maybe change this to mTopicsList->getItemCount() - mKeywords.size()?
+ mControllerFocus = 0;
+ setControllerFocus(mControllerFocus, true);
+ }
+
updateDisposition();
restock();
}
@@ -543,6 +603,11 @@ namespace MWGui
void DialogueWindow::updateTopicsPane()
{
+ const std::string focusedTopic
+ = Settings::gui().mControllerMenus && mControllerFocus < static_cast(mTopicsList->getItemCount())
+ ? mTopicsList->getItemNameAt(mControllerFocus)
+ : "";
+
mTopicsList->clear();
for (auto& linkPair : mTopicLinks)
mDeleteLater.push_back(std::move(linkPair.second));
@@ -600,10 +665,16 @@ namespace MWGui
mKeywordSearch.seed(topicId, intptr_t(t.get()));
t->eventTopicActivated += MyGUI::newDelegate(this, &DialogueWindow::onTopicActivated);
mTopicLinks[topicId] = std::move(t);
+
+ if (keyword == focusedTopic)
+ mControllerFocus = mTopicsList->getItemCount() - 1;
}
redrawTopicsList();
updateHistory();
+
+ if (Settings::gui().mControllerMenus)
+ setControllerFocus(mControllerFocus, true);
}
void DialogueWindow::updateHistory(bool scrollbar)
@@ -630,6 +701,8 @@ namespace MWGui
// choices
const TextColours& textColours = MWBase::Environment::get().getWindowManager()->getTextColours();
mChoices = MWBase::Environment::get().getDialogueManager()->getChoices();
+ mChoiceStyles.clear();
+ mControllerChoice = -1; // -1 so you must make a choice (and can't accidentally pick the first answer)
for (std::pair& choice : mChoices)
{
auto link = std::make_unique(choice.second);
@@ -641,6 +714,7 @@ namespace MWGui
BookTypesetter::Style* questionStyle = typesetter->createHotStyle(
body, textColours.answer, textColours.answerOver, textColours.answerPressed, interactiveId);
typesetter->write(questionStyle, to_utf8_span(choice.first));
+ mChoiceStyles.push_back(questionStyle);
}
mGoodbye = MWBase::Environment::get().getDialogueManager()->isGoodbye();
@@ -850,4 +924,125 @@ namespace MWGui
&& actor.getRefData().getLocals().getIntVar(actor.getClass().getScript(actor), "companion");
}
+ void DialogueWindow::setControllerFocus(size_t index, bool focused)
+ {
+ // List is mTopicsList + "Goodbye" button below the list.
+ if (index > mTopicsList->getItemCount())
+ return;
+
+ if (index == mTopicsList->getItemCount())
+ {
+ mGoodbyeButton->setStateSelected(focused);
+ }
+ else
+ {
+ const std::string& keyword = mTopicsList->getItemNameAt(mControllerFocus);
+ if (keyword.empty())
+ return;
+
+ MyGUI::Button* button = mTopicsList->getItemWidget(keyword);
+ button->setStateSelected(focused);
+ }
+
+ if (focused)
+ {
+ // Scroll the side bar to keep the active item in view
+ if (index <= 8)
+ mTopicsList->setViewOffset(0);
+ else
+ {
+ int offset = 0;
+ for (int i = 0; i < static_cast(index) - 8; i++)
+ {
+ const std::string& keyword = mTopicsList->getItemNameAt(i);
+ if (keyword.empty())
+ offset += 21;
+ else
+ offset += mTopicsList->getItemWidget(keyword)->getHeight() + 3;
+ }
+ mTopicsList->setViewOffset(-offset);
+ }
+ }
+ }
+
+ bool DialogueWindow::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_A)
+ {
+ if (mChoices.size() > 0)
+ {
+ if (mChoices.size() == 1)
+ onChoiceActivated(mChoices[0].second);
+ else if (mControllerChoice >= 0 && mControllerChoice < static_cast(mChoices.size()))
+ onChoiceActivated(mChoices[mControllerChoice].second);
+ }
+ else if (mControllerFocus == static_cast(mTopicsList->getItemCount()))
+ onGoodbyeActivated();
+ else
+ onSelectListItem(mTopicsList->getItemNameAt(mControllerFocus), mControllerFocus);
+ MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_B && mChoices.empty())
+ {
+ onGoodbyeActivated();
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP)
+ {
+ if (mChoices.size() > 0)
+ {
+ // In-dialogue choice (red text)
+ mControllerChoice = std::clamp(mControllerChoice - 1, 0, static_cast(mChoices.size()) - 1);
+ mHistory->setFocusItem(mChoiceStyles.at(mControllerChoice));
+ }
+ else
+ {
+ // Number of items is mTopicsList.length+1 because of "Goodbye" button.
+ setControllerFocus(mControllerFocus, false);
+ if (mControllerFocus <= 0)
+ mControllerFocus = mTopicsList->getItemCount(); // "Goodbye" button
+ else if (mTopicsList->getItemNameAt(mControllerFocus - 1).empty())
+ mControllerFocus -= 2; // Skip separator
+ else
+ mControllerFocus--;
+ setControllerFocus(mControllerFocus, true);
+ }
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
+ {
+ if (mChoices.size() > 0)
+ {
+ // In-dialogue choice (red text)
+ mControllerChoice = std::clamp(mControllerChoice + 1, 0, static_cast(mChoices.size()) - 1);
+ mHistory->setFocusItem(mChoiceStyles.at(mControllerChoice));
+ }
+ else
+ {
+ // Number of items is mTopicsList.length+1 because of "Goodbye" button.
+ setControllerFocus(mControllerFocus, false);
+ if (mControllerFocus >= static_cast(mTopicsList->getItemCount()))
+ mControllerFocus = 0;
+ else if (mControllerFocus == static_cast(mTopicsList->getItemCount()) - 1)
+ mControllerFocus = mTopicsList->getItemCount(); // "Goodbye" button
+ else if (mTopicsList->getItemNameAt(mControllerFocus + 1).empty())
+ mControllerFocus += 2; // Skip separator
+ else
+ mControllerFocus++;
+ setControllerFocus(mControllerFocus, true);
+ }
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_LEFTSHOULDER && mChoices.size() == 0)
+ {
+ setControllerFocus(mControllerFocus, false);
+ mControllerFocus = std::max(mControllerFocus - 5, 0);
+ setControllerFocus(mControllerFocus, true);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER && mChoices.size() == 0)
+ {
+ setControllerFocus(mControllerFocus, false);
+ mControllerFocus = std::min(mControllerFocus + 5, static_cast(mTopicsList->getItemCount()));
+ setControllerFocus(mControllerFocus, true);
+ }
+
+ return true;
+ }
}
diff --git a/apps/openmw/mwgui/dialogue.hpp b/apps/openmw/mwgui/dialogue.hpp
index 8a8b309401..6f03076e92 100644
--- a/apps/openmw/mwgui/dialogue.hpp
+++ b/apps/openmw/mwgui/dialogue.hpp
@@ -49,6 +49,9 @@ namespace MWGui
MyGUI::Widget* getDefaultKeyFocus() override;
+ protected:
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
+
private:
std::unique_ptr mCallback;
@@ -65,6 +68,9 @@ namespace MWGui
MyGUI::Widget* mActionsBox;
Gui::AutoSizedTextBox* mGoldLabel;
+ std::vector mButtons;
+ int mControllerFocus = 0;
+
void adjustAction(MyGUI::Widget* action, int& totalHeight);
void onCancel(MyGUI::Widget* sender);
@@ -186,6 +192,8 @@ namespace MWGui
void onReferenceUnavailable() override;
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
+
private:
void updateDisposition();
void restock();
@@ -197,6 +205,7 @@ namespace MWGui
std::vector> mHistoryContents;
std::vector> mChoices;
+ std::vector mChoiceStyles;
bool mGoodbye;
std::vector> mLinks;
@@ -220,6 +229,10 @@ namespace MWGui
std::unique_ptr mCallback;
std::unique_ptr mGreetingCallback;
+ void setControllerFocus(size_t index, bool focused);
+ int mControllerFocus = 0;
+ int mControllerChoice = -1;
+
void updateTopicFormat();
};
}
diff --git a/apps/openmw/mwgui/enchantingdialog.cpp b/apps/openmw/mwgui/enchantingdialog.cpp
index af4a3e8ce3..7a1c1532f6 100644
--- a/apps/openmw/mwgui/enchantingdialog.cpp
+++ b/apps/openmw/mwgui/enchantingdialog.cpp
@@ -59,6 +59,12 @@ namespace MWGui
mBuyButton->eventMouseButtonClick += MyGUI::newDelegate(this, &EnchantingDialog::onBuyButtonClicked);
mTypeButton->eventMouseButtonClick += MyGUI::newDelegate(this, &EnchantingDialog::onTypeButtonClicked);
mName->eventEditSelectAccept += MyGUI::newDelegate(this, &EnchantingDialog::onAccept);
+
+ mControllerButtons.a = "#{sSelect}";
+ mControllerButtons.b = "#{sCancel}";
+ mControllerButtons.y = "#{OMWEngine:EnchantType}";
+ mControllerButtons.l1 = "#{sItem}";
+ mControllerButtons.r1 = "#{sSoulGem}";
}
void EnchantingDialog::onOpen()
@@ -152,6 +158,7 @@ namespace MWGui
mEnchanting.setSelfEnchanting(false);
mEnchanting.setEnchanter(ptr);
mBuyButton->setCaptionWithReplacing("#{sBuy}");
+ mControllerButtons.x = "#{sBuy}";
mChanceLayout->setVisible(false);
mPtr = ptr;
setSoulGem(MWWorld::Ptr());
@@ -163,6 +170,7 @@ namespace MWGui
mEnchanting.setSelfEnchanting(true);
mEnchanting.setEnchanter(MWMechanics::getPlayer());
mBuyButton->setCaptionWithReplacing("#{sCreate}");
+ mControllerButtons.x = "#{sCreate}";
mChanceLayout->setVisible(Settings::game().mShowEnchantChance);
mPtr = MWMechanics::getPlayer();
setSoulGem(ptr);
@@ -382,4 +390,22 @@ namespace MWGui
}
}
}
+
+ bool EnchantingDialog::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ onCancelButtonClicked(mCancelButton);
+ else if (arg.button == SDL_CONTROLLER_BUTTON_X)
+ onBuyButtonClicked(mBuyButton);
+ else if (arg.button == SDL_CONTROLLER_BUTTON_Y)
+ onTypeButtonClicked(mTypeButton);
+ else if (arg.button == SDL_CONTROLLER_BUTTON_LEFTSHOULDER)
+ onSelectItem(mItemBox);
+ else if (arg.button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER)
+ onSelectSoul(mSoulBox);
+ else
+ return EffectEditorBase::onControllerButtonEvent(arg);
+
+ return true;
+ }
}
diff --git a/apps/openmw/mwgui/enchantingdialog.hpp b/apps/openmw/mwgui/enchantingdialog.hpp
index 4c720a11fc..3cda350152 100644
--- a/apps/openmw/mwgui/enchantingdialog.hpp
+++ b/apps/openmw/mwgui/enchantingdialog.hpp
@@ -73,6 +73,8 @@ namespace MWGui
MWMechanics::Enchanting mEnchanting;
ESM::EffectList mEffectList;
+
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
};
}
diff --git a/apps/openmw/mwgui/hud.cpp b/apps/openmw/mwgui/hud.cpp
index 0a37c93b4f..a62120fc10 100644
--- a/apps/openmw/mwgui/hud.cpp
+++ b/apps/openmw/mwgui/hud.cpp
@@ -243,6 +243,17 @@ namespace MWGui
mDrowningBar->setVisible(visible);
}
+ void HUD::dropDraggedItem(float mouseX, float mouseY)
+ {
+ if (!mDragAndDrop->mIsOnDragAndDrop)
+ return;
+
+ MWBase::Environment::get().getWorld()->breakInvisibility(MWMechanics::getPlayer());
+
+ WorldItemModel drop(mouseX, mouseY);
+ mDragAndDrop->drop(&drop, nullptr);
+ }
+
void HUD::onWorldClicked(MyGUI::Widget* _sender)
{
if (!MWBase::Environment::get().getWindowManager()->isGuiMode())
@@ -252,15 +263,12 @@ namespace MWGui
if (mDragAndDrop->mIsOnDragAndDrop)
{
// drop item into the gameworld
- MWBase::Environment::get().getWorld()->breakInvisibility(MWMechanics::getPlayer());
-
MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize();
MyGUI::IntPoint cursorPosition = MyGUI::InputManager::getInstance().getMousePosition();
float mouseX = cursorPosition.left / float(viewSize.width);
float mouseY = cursorPosition.top / float(viewSize.height);
- WorldItemModel drop(mouseX, mouseY);
- mDragAndDrop->drop(&drop, nullptr);
+ dropDraggedItem(mouseX, mouseY);
winMgr->changePointer("arrow");
}
diff --git a/apps/openmw/mwgui/hud.hpp b/apps/openmw/mwgui/hud.hpp
index 8dd98628c4..1a1076ff68 100644
--- a/apps/openmw/mwgui/hud.hpp
+++ b/apps/openmw/mwgui/hud.hpp
@@ -61,6 +61,8 @@ namespace MWGui
void clear() override;
+ void dropDraggedItem(float mouseX, float mouseY);
+
private:
MyGUI::ProgressBar *mHealth, *mMagicka, *mStamina, *mEnemyHealth, *mDrowning;
MyGUI::Widget* mHealthFrame;
diff --git a/apps/openmw/mwgui/inventorytabsoverlay.cpp b/apps/openmw/mwgui/inventorytabsoverlay.cpp
new file mode 100644
index 0000000000..35b4d1d87f
--- /dev/null
+++ b/apps/openmw/mwgui/inventorytabsoverlay.cpp
@@ -0,0 +1,51 @@
+#include "inventorytabsoverlay.hpp"
+
+#include "../mwbase/environment.hpp"
+#include "../mwbase/windowmanager.hpp"
+
+namespace MWGui
+{
+ InventoryTabsOverlay::InventoryTabsOverlay()
+ : WindowBase("openmw_inventory_tabs.layout")
+ {
+ MyGUI::Button* tab;
+
+ getWidget(tab, "TabMap");
+ tab->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryTabsOverlay::onTabClicked);
+ mTabs.push_back(tab);
+
+ getWidget(tab, "TabInventory");
+ tab->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryTabsOverlay::onTabClicked);
+ mTabs.push_back(tab);
+
+ getWidget(tab, "TabSpells");
+ tab->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryTabsOverlay::onTabClicked);
+ mTabs.push_back(tab);
+
+ getWidget(tab, "TabStats");
+ tab->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryTabsOverlay::onTabClicked);
+ mTabs.push_back(tab);
+ }
+
+ void InventoryTabsOverlay::onTabClicked(MyGUI::Widget* sender)
+ {
+ if (!MWBase::Environment::get().getWindowManager()->getJournalAllowed())
+ return;
+
+ for (int i = 0; i < static_cast(mTabs.size()); i++)
+ {
+ if (mTabs[i] == sender)
+ {
+ MWBase::Environment::get().getWindowManager()->setActiveControllerWindow(GM_Inventory, i);
+ setTab(i);
+ break;
+ }
+ }
+ }
+
+ void InventoryTabsOverlay::setTab(int index)
+ {
+ for (int i = 0; i < static_cast(mTabs.size()); i++)
+ mTabs[i]->setStateSelected(i == index);
+ }
+}
diff --git a/apps/openmw/mwgui/inventorytabsoverlay.hpp b/apps/openmw/mwgui/inventorytabsoverlay.hpp
new file mode 100644
index 0000000000..5368d9710f
--- /dev/null
+++ b/apps/openmw/mwgui/inventorytabsoverlay.hpp
@@ -0,0 +1,24 @@
+#ifndef MWGUI_INVENTORYTABSSOVERLAY_H
+#define MWGUI_INVENTORYTABSSOVERLAY_H
+
+#include
+
+#include "windowbase.hpp"
+
+namespace MWGui
+{
+ class InventoryTabsOverlay : public WindowBase
+ {
+ public:
+ InventoryTabsOverlay();
+
+ void setTab(int index);
+
+ private:
+ std::vector mTabs;
+
+ void onTabClicked(MyGUI::Widget* sender);
+ };
+}
+
+#endif
diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp
index b4a2024052..a398139df4 100644
--- a/apps/openmw/mwgui/inventorywindow.cpp
+++ b/apps/openmw/mwgui/inventorywindow.cpp
@@ -31,8 +31,11 @@
#include "../mwmechanics/actorutil.hpp"
#include "../mwmechanics/npcstats.hpp"
+#include "companionwindow.hpp"
+#include "container.hpp"
#include "countdialog.hpp"
#include "draganddrop.hpp"
+#include "hud.hpp"
#include "inventoryitemmodel.hpp"
#include "itemview.hpp"
#include "settings.hpp"
@@ -127,6 +130,21 @@ namespace MWGui
setGuiMode(mGuiMode);
+ if (Settings::gui().mControllerMenus)
+ {
+ // Show L1 and R1 buttons next to tabs
+ MyGUI::Widget* image;
+ getWidget(image, "BtnL1Image");
+ image->setVisible(true);
+ image->setUserString("Hidden", "false");
+
+ getWidget(image, "BtnR1Image");
+ image->setVisible(true);
+ image->setUserString("Hidden", "false");
+
+ mControllerButtons.r3 = "#{sInfo}";
+ }
+
adjustPanes();
}
@@ -204,9 +222,13 @@ namespace MWGui
void InventoryWindow::setGuiMode(GuiMode mode)
{
+ if (Settings::gui().mControllerMenus && mGuiMode == mode && isVisible())
+ return;
+
mGuiMode = mode;
const WindowSettingValues settings = getModeSettings(mGuiMode);
- setPinButtonVisible(mode != GM_Container && mode != GM_Companion && mode != GM_Barter);
+ setPinButtonVisible(
+ mode != GM_Container && mode != GM_Companion && mode != GM_Barter && !Settings::gui().mControllerMenus);
const WindowRectSettingValues& rect = settings.mIsMaximized ? settings.mMaximized : settings.mRegular;
@@ -302,7 +324,9 @@ namespace MWGui
}
}
- if (count > 1 && !shift)
+ // Show a dialog to select a count of items, but not when using an item from the inventory
+ // in controller mode. In that case, we skip the dialog and just use one item immediately.
+ if (count > 1 && !shift && !(Settings::gui().mControllerMenus && mGuiMode == MWGui::GM_Inventory))
{
CountDialog* dialog = MWBase::Environment::get().getWindowManager()->getCountDialog();
std::string message = mTrading ? "#{sQuanityMenuMessage01}" : "#{sTake}";
@@ -310,7 +334,10 @@ namespace MWGui
name += MWGui::ToolTips::getSoulString(object.getCellRef());
dialog->openCountDialog(name, message, count);
dialog->eventOkClicked.clear();
- if (mTrading)
+ if (Settings::gui().mControllerMenus
+ && (mGuiMode == MWGui::GM_Companion || mGuiMode == MWGui::GM_Container))
+ dialog->eventOkClicked += MyGUI::newDelegate(this, &InventoryWindow::giveItem);
+ else if (mTrading)
dialog->eventOkClicked += MyGUI::newDelegate(this, &InventoryWindow::sellItem);
else
dialog->eventOkClicked += MyGUI::newDelegate(this, &InventoryWindow::dragItem);
@@ -390,6 +417,32 @@ namespace MWGui
notifyContentChanged();
}
+ void InventoryWindow::giveItem(MyGUI::Widget* sender, int count)
+ {
+ ensureSelectedItemUnequipped(count);
+ mDragAndDrop->startDrag(mSelectedItem, mSortModel, mTradeModel, mItemView, count);
+ notifyContentChanged();
+
+ if (mGuiMode == MWGui::GM_Companion && mDragAndDrop->mIsOnDragAndDrop)
+ {
+ // Drag and drop the item on the companion's window.
+ MWGui::CompanionWindow* companionWindow = (MWGui::CompanionWindow*)MWBase::Environment::get()
+ .getWindowManager()
+ ->getGuiModeWindows(mGuiMode)
+ .at(1);
+ mDragAndDrop->drop(companionWindow->getModel(), companionWindow->getItemView());
+ }
+ else if (mGuiMode == MWGui::GM_Container && mDragAndDrop->mIsOnDragAndDrop)
+ {
+ // Drag and drop the item on the container window.
+ MWGui::ContainerWindow* containerWindow = (MWGui::ContainerWindow*)MWBase::Environment::get()
+ .getWindowManager()
+ ->getGuiModeWindows(mGuiMode)
+ .at(0);
+ mDragAndDrop->drop(containerWindow->getModel(), containerWindow->getItemView());
+ }
+ }
+
void InventoryWindow::updateItemView()
{
MWBase::Environment::get().getWindowManager()->updateSpellWindow();
@@ -866,4 +919,189 @@ namespace MWGui
const MyGUI::IntSize viewport = getPreviewViewportSize();
return osg::Vec2f(normalisedX * float(viewport.width - 1), (1.0 - normalisedY) * float(viewport.height - 1));
}
+
+ ControllerButtonStr* InventoryWindow::getControllerButtons()
+ {
+ switch (mGuiMode)
+ {
+ case MWGui::GM_Companion:
+ mControllerButtons.a = "#{OMWEngine:InventorySelect}";
+ mControllerButtons.b = "#{sClose}";
+ mControllerButtons.x = "";
+ mControllerButtons.y = "";
+ mControllerButtons.r2 = "#{sCompanionShare}";
+ break;
+ case MWGui::GM_Container:
+ mControllerButtons.a = "#{OMWEngine:InventorySelect}";
+ mControllerButtons.b = "#{sClose}";
+ mControllerButtons.x = "#{sTakeAll}";
+ mControllerButtons.y = "";
+ mControllerButtons.r2 = "#{sContainer}";
+ break;
+ case MWGui::GM_Barter:
+ mControllerButtons.a = "#{sSell}";
+ mControllerButtons.b = "#{sCancel}";
+ mControllerButtons.x = "#{sOffer}";
+ mControllerButtons.y = "";
+ mControllerButtons.r2 = "#{sBarter}";
+ break;
+ case MWGui::GM_Inventory:
+ default:
+ mControllerButtons.a = "#{sEquip}";
+ mControllerButtons.b = "#{sBack}";
+ mControllerButtons.x = "#{sDrop}";
+ mControllerButtons.y = "#{sUnequip}";
+ mControllerButtons.r2 = "";
+ break;
+ }
+ return &mControllerButtons;
+ }
+
+ bool InventoryWindow::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ {
+ MWBase::Environment::get().getWindowManager()->exitCurrentGuiMode();
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_A)
+ {
+ mItemView->onControllerButton(SDL_CONTROLLER_BUTTON_A);
+ // The following actions are done here, not in onItemSelectedFromSourceModel, because we
+ // want the mouse to work even in controller mode.
+ if (mGuiMode == MWGui::GM_Inventory && mDragAndDrop->mIsOnDragAndDrop)
+ {
+ // Drag and drop the item on the avatar to activate it.
+ onAvatarClicked(nullptr); // Equip or use
+ // Drop any remaining items back in inventory. This is needed when clicking on a
+ // stack of items; we only want to use the first item.
+ onBackgroundSelected();
+ }
+ else if (mGuiMode == MWGui::GM_Companion && mDragAndDrop->mIsOnDragAndDrop)
+ {
+ // Drag and drop the item on the companion's window.
+ MWGui::CompanionWindow* companionWindow = (MWGui::CompanionWindow*)MWBase::Environment::get()
+ .getWindowManager()
+ ->getGuiModeWindows(mGuiMode)
+ .at(1);
+ mDragAndDrop->drop(companionWindow->getModel(), companionWindow->getItemView());
+ }
+ else if (mGuiMode == MWGui::GM_Container && mDragAndDrop->mIsOnDragAndDrop)
+ {
+ // Drag and drop the item on the container window.
+ MWGui::ContainerWindow* containerWindow = (MWGui::ContainerWindow*)MWBase::Environment::get()
+ .getWindowManager()
+ ->getGuiModeWindows(mGuiMode)
+ .at(0);
+ mDragAndDrop->drop(containerWindow->getModel(), containerWindow->getItemView());
+ }
+ // GM_Barter is handled by onControllerButtonEvent. No other steps are necessary.
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_X)
+ {
+ if (mGuiMode == MWGui::GM_Inventory)
+ {
+ // Drop the item into the gameworld
+ mItemView->onControllerButton(SDL_CONTROLLER_BUTTON_A);
+ if (mDragAndDrop->mIsOnDragAndDrop)
+ MWBase::Environment::get().getWindowManager()->getHud()->dropDraggedItem(0.5f, 0.5f);
+ }
+ else if (mGuiMode == MWGui::GM_Container)
+ {
+ // Take all. Pass the button press to the container window and let it do the
+ // logic of taking all.
+ MWGui::ContainerWindow* containerWindow = (MWGui::ContainerWindow*)MWBase::Environment::get()
+ .getWindowManager()
+ ->getGuiModeWindows(mGuiMode)
+ .at(0);
+ containerWindow->onControllerButtonEvent(arg);
+ }
+ else if (mGuiMode == MWGui::GM_Barter)
+ {
+ // Offer. Pass the button press to the barter window and let it do the logic
+ // of making an offer.
+ MWGui::TradeWindow* tradeWindow = (MWGui::TradeWindow*)MWBase::Environment::get()
+ .getWindowManager()
+ ->getGuiModeWindows(mGuiMode)
+ .at(1);
+ tradeWindow->onControllerButtonEvent(arg);
+ }
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_Y)
+ {
+ if (mGuiMode == MWGui::GM_Inventory)
+ {
+ // Unequip an item.
+ mItemView->onControllerButton(SDL_CONTROLLER_BUTTON_A);
+ onBackgroundSelected(); // Drop on inventory background to unequip
+ }
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_LEFTSHOULDER)
+ {
+ if (mFilterAll->getStateSelected())
+ onFilterChanged(mFilterMisc);
+ else if (mFilterWeapon->getStateSelected())
+ onFilterChanged(mFilterAll);
+ else if (mFilterApparel->getStateSelected())
+ onFilterChanged(mFilterWeapon);
+ else if (mFilterMagic->getStateSelected())
+ onFilterChanged(mFilterApparel);
+ else if (mFilterMisc->getStateSelected())
+ onFilterChanged(mFilterMagic);
+ MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER)
+ {
+ if (mFilterAll->getStateSelected())
+ onFilterChanged(mFilterWeapon);
+ else if (mFilterWeapon->getStateSelected())
+ onFilterChanged(mFilterApparel);
+ else if (mFilterApparel->getStateSelected())
+ onFilterChanged(mFilterMagic);
+ else if (mFilterMagic->getStateSelected())
+ onFilterChanged(mFilterMisc);
+ else if (mFilterMisc->getStateSelected())
+ onFilterChanged(mFilterAll);
+ MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
+ }
+ else
+ {
+ mItemView->onControllerButton(arg.button);
+ }
+
+ return true;
+ }
+
+ void InventoryWindow::setActiveControllerWindow(bool active)
+ {
+ if (!Settings::gui().mControllerMenus)
+ return;
+
+ if (MWBase::Environment::get().getWindowManager()->getMode() == MWGui::GM_Inventory)
+ {
+ // Fill the screen, or limit to a certain size on large screens. Size chosen to
+ // match the size of the stats window.
+ MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize();
+ int width = std::min(viewSize.width, 1600);
+ int height = std::min(viewSize.height - 48 - 48, 750);
+ int x = (viewSize.width - width) / 2;
+ int y = (viewSize.height - height) / 2;
+
+ MyGUI::Window* window = mMainWidget->castType();
+ window->setCoord(x, active ? y : viewSize.height + 1, width, height);
+
+ adjustPanes();
+ updatePreviewSize();
+ }
+
+ // Show L1 and R1 buttons next to tabs
+ MyGUI::Widget* image;
+ getWidget(image, "BtnL1Image");
+ image->setVisible(active);
+
+ getWidget(image, "BtnR1Image");
+ image->setVisible(active);
+
+ mItemView->setActiveControllerWindow(active);
+ WindowBase::setActiveControllerWindow(active);
+ }
}
diff --git a/apps/openmw/mwgui/inventorywindow.hpp b/apps/openmw/mwgui/inventorywindow.hpp
index 9fc77ceec5..a14e0f9477 100644
--- a/apps/openmw/mwgui/inventorywindow.hpp
+++ b/apps/openmw/mwgui/inventorywindow.hpp
@@ -67,8 +67,12 @@ namespace MWGui
std::string_view getWindowIdForLua() const override { return "Inventory"; }
+ ControllerButtonStr* getControllerButtons() override;
+
protected:
void onTitleDoubleClicked() override;
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
+ void setActiveControllerWindow(bool active) override;
private:
DragAndDrop* mDragAndDrop;
@@ -118,6 +122,7 @@ namespace MWGui
void sellItem(MyGUI::Widget* sender, int count);
void dragItem(MyGUI::Widget* sender, int count);
+ void giveItem(MyGUI::Widget* sender, int count);
void onWindowResize(MyGUI::Window* _sender);
void onFilterChanged(MyGUI::Widget* _sender);
diff --git a/apps/openmw/mwgui/itemchargeview.cpp b/apps/openmw/mwgui/itemchargeview.cpp
index 02c3cc182c..31b29122f3 100644
--- a/apps/openmw/mwgui/itemchargeview.cpp
+++ b/apps/openmw/mwgui/itemchargeview.cpp
@@ -1,5 +1,6 @@
#include "itemchargeview.hpp"
+#include
#include
#include
@@ -9,8 +10,11 @@
#include
#include
+#include
#include "../mwbase/environment.hpp"
+#include "../mwbase/inputmanager.hpp"
+#include "../mwbase/windowmanager.hpp"
#include "../mwmechanics/spellutil.hpp"
@@ -19,6 +23,7 @@
#include "itemmodel.hpp"
#include "itemwidget.hpp"
+#include "textcolours.hpp"
namespace MWGui
{
@@ -156,11 +161,20 @@ namespace MWGui
mScrollView->setCanvasSize(
MyGUI::IntSize(mScrollView->getWidth(), std::max(mScrollView->getHeight(), currentY)));
mScrollView->setVisibleVScroll(true);
+
+ if (Settings::gui().mControllerMenus)
+ updateControllerFocus(-1, mControllerFocus);
}
void ItemChargeView::resetScrollbars()
{
mScrollView->setViewOffset(MyGUI::IntPoint(0, 0));
+
+ if (Settings::gui().mControllerMenus)
+ {
+ updateControllerFocus(mControllerFocus, 0);
+ mControllerFocus = 0;
+ }
}
void ItemChargeView::setSize(const MyGUI::IntSize& value)
@@ -224,4 +238,52 @@ namespace MWGui
mScrollView->setViewOffset(
MyGUI::IntPoint(0, static_cast(mScrollView->getViewOffset().top + rel * 0.3f)));
}
+
+ void ItemChargeView::onControllerButton(const unsigned char button)
+ {
+ if (mLines.empty())
+ return;
+
+ int prevFocus = mControllerFocus;
+
+ if (button == SDL_CONTROLLER_BUTTON_A)
+ {
+ // Select the focused item, if any.
+ if (mControllerFocus >= 0 && mControllerFocus < static_cast(mLines.size()))
+ onIconClicked(mLines[mControllerFocus].mIcon);
+ }
+ else if (button == SDL_CONTROLLER_BUTTON_DPAD_UP)
+ mControllerFocus = wrap(mControllerFocus - 1, mLines.size());
+ else if (button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
+ mControllerFocus = wrap(mControllerFocus + 1, mLines.size());
+
+ if (prevFocus != mControllerFocus)
+ updateControllerFocus(prevFocus, mControllerFocus);
+ }
+
+ void ItemChargeView::updateControllerFocus(int prevFocus, int newFocus)
+ {
+ if (mLines.empty())
+ return;
+
+ const TextColours& textColours{ MWBase::Environment::get().getWindowManager()->getTextColours() };
+
+ if (prevFocus >= 0 && prevFocus < static_cast(mLines.size()))
+ {
+ mLines[prevFocus].mText->setTextColour(textColours.normal);
+ mLines[prevFocus].mIcon->setControllerFocus(false);
+ }
+
+ if (newFocus >= 0 && newFocus < static_cast(mLines.size()))
+ {
+ mLines[newFocus].mText->setTextColour(textColours.link);
+ mLines[newFocus].mIcon->setControllerFocus(true);
+
+ // Scroll the list to keep the active item in view
+ if (newFocus <= 3)
+ mScrollView->setViewOffset(MyGUI::IntPoint(0, 0));
+ else
+ mScrollView->setViewOffset(MyGUI::IntPoint(0, -55 * (newFocus - 3)));
+ }
+ }
}
diff --git a/apps/openmw/mwgui/itemchargeview.hpp b/apps/openmw/mwgui/itemchargeview.hpp
index f7617d37eb..73bf9c3de2 100644
--- a/apps/openmw/mwgui/itemchargeview.hpp
+++ b/apps/openmw/mwgui/itemchargeview.hpp
@@ -52,6 +52,8 @@ namespace MWGui
MyGUI::delegates::MultiDelegate eventItemClicked;
+ void onControllerButton(const unsigned char button);
+
private:
struct Line
{
@@ -72,6 +74,9 @@ namespace MWGui
std::unique_ptr mModel;
MyGUI::ScrollView* mScrollView;
DisplayMode mDisplayMode;
+
+ int mControllerFocus;
+ void updateControllerFocus(int prevFocus, int newFocus);
};
}
diff --git a/apps/openmw/mwgui/itemselection.cpp b/apps/openmw/mwgui/itemselection.cpp
index 4fe40ce693..ad2b141d8d 100644
--- a/apps/openmw/mwgui/itemselection.cpp
+++ b/apps/openmw/mwgui/itemselection.cpp
@@ -3,6 +3,8 @@
#include
#include
+#include
+
#include "inventoryitemmodel.hpp"
#include "itemview.hpp"
#include "sortfilteritemmodel.hpp"
@@ -26,6 +28,10 @@ namespace MWGui
cancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ItemSelectionDialog::onCancelButtonClicked);
center();
+
+ mControllerButtons.a = "#{sSelect}";
+ mControllerButtons.b = "#{sCancel}";
+ mControllerButtons.r3 = "#{sInfo}";
}
bool ItemSelectionDialog::exit()
@@ -40,6 +46,8 @@ namespace MWGui
mSortModel = sortModel.get();
mItemView->setModel(std::move(sortModel));
mItemView->resetScrollBars();
+ if (Settings::gui().mControllerMenus)
+ mItemView->setActiveControllerWindow(true);
}
void ItemSelectionDialog::setCategory(int category)
@@ -65,4 +73,13 @@ namespace MWGui
exit();
}
+ bool ItemSelectionDialog::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ onCancelButtonClicked(nullptr);
+ else
+ mItemView->onControllerButton(arg.button);
+
+ return true;
+ }
}
diff --git a/apps/openmw/mwgui/itemselection.hpp b/apps/openmw/mwgui/itemselection.hpp
index fe87d7e38a..83af6d4840 100644
--- a/apps/openmw/mwgui/itemselection.hpp
+++ b/apps/openmw/mwgui/itemselection.hpp
@@ -41,6 +41,7 @@ namespace MWGui
void onSelectedItem(int index);
void onCancelButtonClicked(MyGUI::Widget* sender);
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
};
}
diff --git a/apps/openmw/mwgui/itemview.cpp b/apps/openmw/mwgui/itemview.cpp
index ff05a8b2d6..0afb3d3d76 100644
--- a/apps/openmw/mwgui/itemview.cpp
+++ b/apps/openmw/mwgui/itemview.cpp
@@ -7,6 +7,12 @@
#include
#include
+#include
+
+#include "../mwbase/environment.hpp"
+#include "../mwbase/inputmanager.hpp"
+#include "../mwbase/windowmanager.hpp"
+
#include "itemmodel.hpp"
#include "itemwidget.hpp"
@@ -15,6 +21,7 @@ namespace MWGui
ItemView::ItemView()
: mScrollView(nullptr)
+ , mControllerActiveWindow(false)
{
}
@@ -46,13 +53,16 @@ namespace MWGui
MyGUI::Widget* dragArea = mScrollView->getChildAt(0);
int maxHeight = mScrollView->getHeight();
- int rows = maxHeight / 42;
- rows = std::max(rows, 1);
- bool showScrollbar = int(std::ceil(dragArea->getChildCount() / float(rows))) > mScrollView->getWidth() / 42;
+ mRows = std::max(maxHeight / 42, 1);
+ mItemCount = dragArea->getChildCount();
+ bool showScrollbar = int(std::ceil(mItemCount / float(mRows))) > mScrollView->getWidth() / 42;
if (showScrollbar)
+ {
maxHeight -= 18;
+ mRows = std::max(maxHeight / 42, 1);
+ }
- for (unsigned int i = 0; i < dragArea->getChildCount(); ++i)
+ for (int i = 0; i < mItemCount; ++i)
{
MyGUI::Widget* w = dragArea->getChildAt(i);
@@ -60,7 +70,7 @@ namespace MWGui
y += 42;
- if (y > maxHeight - 42 && i < dragArea->getChildCount() - 1)
+ if (y > maxHeight - 42 && i < mItemCount - 1)
{
x += 42;
y = 0;
@@ -70,6 +80,12 @@ namespace MWGui
MyGUI::IntSize size = MyGUI::IntSize(std::max(mScrollView->getSize().width, x), mScrollView->getSize().height);
+ if (Settings::gui().mControllerMenus)
+ {
+ mControllerFocus = std::clamp(mControllerFocus, 0, mItemCount - 1);
+ updateControllerFocus(-1, mControllerFocus);
+ }
+
// Canvas size must be expressed with VScroll disabled, otherwise MyGUI would expand the scroll area when the
// scrollbar is hidden
mScrollView->setVisibleVScroll(false);
@@ -122,6 +138,11 @@ namespace MWGui
void ItemView::resetScrollBars()
{
mScrollView->setViewOffset(MyGUI::IntPoint(0, 0));
+ if (Settings::gui().mControllerMenus)
+ {
+ updateControllerFocus(mControllerFocus, 0);
+ mControllerFocus = 0;
+ }
}
void ItemView::onSelectedItem(MyGUI::Widget* sender)
@@ -165,4 +186,106 @@ namespace MWGui
MyGUI::FactoryManager::getInstance().registerFactory("Widget");
}
+ void ItemView::setActiveControllerWindow(bool active)
+ {
+ mControllerActiveWindow = active;
+
+ MWBase::Environment::get().getWindowManager()->setControllerTooltip(
+ active && Settings::gui().mControllerTooltips);
+
+ if (active)
+ updateControllerFocus(-1, mControllerFocus);
+ else
+ updateControllerFocus(mControllerFocus, -1);
+ }
+
+ void ItemView::onControllerButton(const unsigned char button)
+ {
+ if (!mItemCount)
+ return;
+
+ int prevFocus = mControllerFocus;
+
+ if (button == SDL_CONTROLLER_BUTTON_A)
+ {
+ // Select the focused item, if any.
+ if (mControllerFocus >= 0 && mControllerFocus < mItemCount)
+ {
+ MyGUI::Widget* dragArea = mScrollView->getChildAt(0);
+ onSelectedItem(dragArea->getChildAt(mControllerFocus));
+ }
+ }
+ else if (button == SDL_CONTROLLER_BUTTON_RIGHTSTICK)
+ {
+ // Toggle info tooltip
+ MWBase::Environment::get().getWindowManager()->setControllerTooltip(
+ !MWBase::Environment::get().getWindowManager()->getControllerTooltip());
+ updateControllerFocus(-1, mControllerFocus);
+ }
+ else if (button == SDL_CONTROLLER_BUTTON_DPAD_UP)
+ {
+ if (mControllerFocus % mRows == 0)
+ mControllerFocus = std::min(mControllerFocus + mRows - 1, mItemCount - 1);
+ else
+ mControllerFocus--;
+ }
+ else if (button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
+ {
+ if (mControllerFocus % mRows == mRows - 1 || mControllerFocus == mItemCount - 1)
+ mControllerFocus -= mControllerFocus % mRows;
+ else
+ mControllerFocus++;
+ }
+ else if (button == SDL_CONTROLLER_BUTTON_DPAD_LEFT && mControllerFocus >= mRows)
+ mControllerFocus -= mRows;
+ else if (button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT)
+ {
+ if (mControllerFocus + mRows < mItemCount)
+ mControllerFocus += mRows;
+ else if (mControllerFocus / mRows != (mItemCount - 1) / mRows)
+ mControllerFocus = mItemCount - 1;
+ }
+
+ if (prevFocus != mControllerFocus)
+ updateControllerFocus(prevFocus, mControllerFocus);
+ else
+ updateControllerFocus(-1, mControllerFocus);
+ }
+
+ void ItemView::updateControllerFocus(int prevFocus, int newFocus)
+ {
+ MWBase::Environment::get().getWindowManager()->setCursorVisible(
+ !MWBase::Environment::get().getWindowManager()->getControllerTooltip());
+
+ if (!mItemCount)
+ return;
+
+ MyGUI::Widget* dragArea = mScrollView->getChildAt(0);
+
+ if (prevFocus >= 0 && prevFocus < mItemCount)
+ {
+ ItemWidget* prev = (ItemWidget*)dragArea->getChildAt(prevFocus);
+ if (prev)
+ prev->setControllerFocus(false);
+ }
+
+ if (mControllerActiveWindow && newFocus >= 0 && newFocus < mItemCount)
+ {
+ ItemWidget* focused = (ItemWidget*)dragArea->getChildAt(newFocus);
+ if (focused)
+ {
+ focused->setControllerFocus(true);
+
+ // Scroll the list to keep the active item in view
+ int column = newFocus / mRows;
+ if (column <= 3)
+ mScrollView->setViewOffset(MyGUI::IntPoint(0, 0));
+ else
+ mScrollView->setViewOffset(MyGUI::IntPoint(-42 * (column - 3), 0));
+
+ if (MWBase::Environment::get().getWindowManager()->getControllerTooltip())
+ MWBase::Environment::get().getInputManager()->warpMouseToWidget(focused);
+ }
+ }
+ }
}
diff --git a/apps/openmw/mwgui/itemview.hpp b/apps/openmw/mwgui/itemview.hpp
index cfbc8a37ac..7915a4dcf1 100644
--- a/apps/openmw/mwgui/itemview.hpp
+++ b/apps/openmw/mwgui/itemview.hpp
@@ -2,6 +2,7 @@
#define MWGUI_ITEMVIEW_H
#include
+#include
#include "itemmodel.hpp"
@@ -31,6 +32,11 @@ namespace MWGui
void resetScrollBars();
+ void setActiveControllerWindow(bool active);
+ int getControllerFocus() { return mControllerFocus; }
+ int getItemCount() { return mItemCount; }
+ void onControllerButton(const unsigned char button);
+
private:
void initialiseOverride() override;
@@ -45,6 +51,12 @@ namespace MWGui
std::unique_ptr mModel;
MyGUI::ScrollView* mScrollView;
+
+ int mItemCount = 0;
+ int mRows;
+ int mControllerFocus = 0;
+ bool mControllerActiveWindow;
+ void updateControllerFocus(int prevFocus, int newFocus);
};
}
diff --git a/apps/openmw/mwgui/itemwidget.cpp b/apps/openmw/mwgui/itemwidget.cpp
index 05fff2d40f..5e47577b27 100644
--- a/apps/openmw/mwgui/itemwidget.cpp
+++ b/apps/openmw/mwgui/itemwidget.cpp
@@ -58,6 +58,7 @@ namespace MWGui
: mItem(nullptr)
, mItemShadow(nullptr)
, mFrame(nullptr)
+ , mControllerBorder(nullptr)
, mText(nullptr)
{
}
@@ -82,10 +83,22 @@ namespace MWGui
assignWidget(mText, "Text");
if (mText)
mText->setNeedMouseFocus(false);
+ if (Settings::gui().mControllerMenus)
+ {
+ assignWidget(mControllerBorder, "ControllerBorder");
+ if (mControllerBorder)
+ mControllerBorder->setNeedMouseFocus(false);
+ }
Base::initialiseOverride();
}
+ void ItemWidget::setControllerFocus(bool focus)
+ {
+ if (mControllerBorder)
+ mControllerBorder->setVisible(focus);
+ }
+
void ItemWidget::setCount(int count)
{
if (!mText)
diff --git a/apps/openmw/mwgui/itemwidget.hpp b/apps/openmw/mwgui/itemwidget.hpp
index 63837ae92f..1191a23342 100644
--- a/apps/openmw/mwgui/itemwidget.hpp
+++ b/apps/openmw/mwgui/itemwidget.hpp
@@ -40,12 +40,15 @@ namespace MWGui
void setIcon(const MWWorld::Ptr& ptr);
void setFrame(const std::string& frame, const MyGUI::IntCoord& coord);
+ void setControllerFocus(bool focus);
+
protected:
void initialiseOverride() override;
MyGUI::ImageBox* mItem;
MyGUI::ImageBox* mItemShadow;
MyGUI::ImageBox* mFrame;
+ MyGUI::ImageBox* mControllerBorder;
MyGUI::TextBox* mText;
std::string mCurrentIcon;
diff --git a/apps/openmw/mwgui/journalbooks.cpp b/apps/openmw/mwgui/journalbooks.cpp
index 86b45b4863..c127508062 100644
--- a/apps/openmw/mwgui/journalbooks.cpp
+++ b/apps/openmw/mwgui/journalbooks.cpp
@@ -169,7 +169,7 @@ namespace MWGui
{
BookTypesetter::Ptr typesetter = createTypesetter();
- BookTypesetter::Style* header = typesetter->createStyle({}, MyGUI::Colour(0.60f, 0.00f, 0.00f));
+ BookTypesetter::Style* header = typesetter->createStyle({}, journalHeaderColour);
BookTypesetter::Style* body = typesetter->createStyle({}, MyGUI::Colour::Black);
typesetter->write(header, to_utf8_span("You have no journal entries!"));
@@ -184,7 +184,7 @@ namespace MWGui
{
BookTypesetter::Ptr typesetter = createTypesetter();
- BookTypesetter::Style* header = typesetter->createStyle({}, MyGUI::Colour(0.60f, 0.00f, 0.00f));
+ BookTypesetter::Style* header = typesetter->createStyle({}, journalHeaderColour);
BookTypesetter::Style* body = typesetter->createStyle({}, MyGUI::Colour::Black);
mModel->visitJournalEntries({}, AddJournalEntry(typesetter, body, header, true));
@@ -196,7 +196,7 @@ namespace MWGui
{
BookTypesetter::Ptr typesetter = createTypesetter();
- BookTypesetter::Style* header = typesetter->createStyle({}, MyGUI::Colour(0.60f, 0.00f, 0.00f));
+ BookTypesetter::Style* header = typesetter->createStyle({}, journalHeaderColour);
BookTypesetter::Style* body = typesetter->createStyle({}, MyGUI::Colour::Black);
mModel->visitTopicName(topicId, AddTopicName(typesetter, header));
@@ -212,7 +212,7 @@ namespace MWGui
{
BookTypesetter::Ptr typesetter = createTypesetter();
- BookTypesetter::Style* header = typesetter->createStyle({}, MyGUI::Colour(0.60f, 0.00f, 0.00f));
+ BookTypesetter::Style* header = typesetter->createStyle({}, journalHeaderColour);
BookTypesetter::Style* body = typesetter->createStyle({}, MyGUI::Colour::Black);
AddQuestName addName(typesetter, header);
diff --git a/apps/openmw/mwgui/journalbooks.hpp b/apps/openmw/mwgui/journalbooks.hpp
index 792edcc070..2549b2ad5b 100644
--- a/apps/openmw/mwgui/journalbooks.hpp
+++ b/apps/openmw/mwgui/journalbooks.hpp
@@ -10,6 +10,8 @@ namespace MWGui
{
MWGui::BookTypesetter::Utf8Span to_utf8_span(std::string_view text);
+ const MyGUI::Colour journalHeaderColour = MyGUI::Colour(0.60f, 0.00f, 0.00f);
+
struct JournalBooks
{
typedef TypesetBook::Ptr Book;
diff --git a/apps/openmw/mwgui/journalwindow.cpp b/apps/openmw/mwgui/journalwindow.cpp
index 574c425d3e..8302f4faea 100644
--- a/apps/openmw/mwgui/journalwindow.cpp
+++ b/apps/openmw/mwgui/journalwindow.cpp
@@ -218,6 +218,10 @@ namespace
}
}
+ mControllerButtons.a = "#{sSelect}";
+ mControllerButtons.x = "#{OMWEngine:JournalQuests}";
+ mControllerButtons.y = "#{sTopics}";
+
mQuestMode = false;
mAllQuests = false;
mOptionsMode = false;
@@ -248,6 +252,9 @@ namespace
}
updateShowingPages();
+ if (Settings::gui().mControllerMenus)
+ setControllerFocusedQuest(0);
+
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(getWidget(CloseBTN));
}
@@ -275,6 +282,8 @@ namespace
updateShowingPages();
updateCloseJournalButton();
+
+ MWBase::Environment::get().getWindowManager()->updateControllerButtonsOverlay();
}
void setOptionsMode()
@@ -307,6 +316,8 @@ namespace
notifyQuests(getWidget(QuestsList));
else
notifyTopics(getWidget(TopicsList));
+
+ MWBase::Environment::get().getWindowManager()->updateControllerButtonsOverlay();
}
void pushBook(Book& book, unsigned int page)
@@ -338,6 +349,7 @@ namespace
{
setVisible(CloseBTN, mStates.size() < 2);
setVisible(JournalBTN, mStates.size() >= 2);
+ MWBase::Environment::get().getWindowManager()->updateControllerButtonsOverlay();
}
void updateShowingPages()
@@ -380,6 +392,8 @@ namespace
setText(PageOneNum, page + 1);
setText(PageTwoNum, page + 2);
+
+ MWBase::Environment::get().getWindowManager()->updateControllerButtonsOverlay();
}
void notifyKeyPress(MyGUI::Widget* sender, MyGUI::KeyCode key, MyGUI::Char character)
@@ -407,6 +421,7 @@ namespace
mTopicsMode = false;
MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("book page"));
+ MWBase::Environment::get().getWindowManager()->updateControllerButtonsOverlay();
}
void notifyTopicSelected(const std::string& topicIdString, int id)
@@ -439,6 +454,7 @@ namespace
mOptionsMode = false;
MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("book page"));
+ MWBase::Environment::get().getWindowManager()->updateControllerButtonsOverlay();
}
void notifyOptions(MyGUI::Widget* _sender)
@@ -459,6 +475,9 @@ namespace
getPage(LeftTopicIndex)->showPage(mTopicIndexBook, 0);
getPage(RightTopicIndex)->showPage(mTopicIndexBook, 1);
}
+
+ if (Settings::gui().mControllerMenus)
+ setIndexControllerFocus(true);
}
void notifyJournal(MyGUI::Widget* _sender)
@@ -467,6 +486,22 @@ namespace
popBook();
MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("book page"));
+ MWBase::Environment::get().getWindowManager()->updateControllerButtonsOverlay();
+ }
+
+ void addControllerButtons(Gui::MWList* _list, size_t _selectedIndex)
+ {
+ mButtons.clear();
+ for (size_t i = 0; i < _list->getItemCount(); i++)
+ {
+ MyGUI::Button* listItem = _list->getItemWidget(_list->getItemNameAt(i));
+ if (listItem)
+ {
+ listItem->setTextColour(
+ mButtons.size() == _selectedIndex ? MWGui::journalHeaderColour : MyGUI::Colour::Black);
+ mButtons.push_back(listItem);
+ }
+ }
}
void notifyIndexLinkClicked(MWGui::TypesetBook::InteractiveId index)
@@ -487,7 +522,14 @@ namespace
list->adjustSize();
+ if (Settings::gui().mControllerMenus)
+ {
+ setControllerFocusedQuest(0);
+ addControllerButtons(list, mSelectedQuest);
+ }
+
MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("book page"));
+ MWBase::Environment::get().getWindowManager()->updateControllerButtonsOverlay();
}
void notifyTopics(MyGUI::Widget* _sender)
@@ -503,6 +545,7 @@ namespace
setVisible(ShowActiveBTN, false);
MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("book page"));
+ MWBase::Environment::get().getWindowManager()->updateControllerButtonsOverlay();
}
struct AddNamesToList
@@ -554,6 +597,12 @@ namespace
list->sort();
list->adjustSize();
+ if (Settings::gui().mControllerMenus)
+ {
+ addControllerButtons(list, mSelectedQuest);
+ setControllerFocusedQuest(MWGui::wrap(mSelectedQuest, mButtons.size()));
+ }
+
if (mAllQuests)
{
SetNamesInactive setInactive(list);
@@ -561,6 +610,7 @@ namespace
}
MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("book page"));
+ MWBase::Environment::get().getWindowManager()->updateControllerButtonsOverlay();
}
void notifyShowAll(MyGUI::Widget* _sender)
@@ -639,6 +689,299 @@ namespace
}
}
}
+
+ MWGui::ControllerButtonStr* getControllerButtons() override
+ {
+ mControllerButtons.b = mOptionsMode || mStates.size() > 1 ? "#{sBack}" : "#{sClose}";
+ mControllerButtons.l1 = mOptionsMode ? "" : "#{sPrev}";
+ mControllerButtons.r1 = mOptionsMode ? "" : "#{sNext}";
+ mControllerButtons.r3 = mOptionsMode && mQuestMode ? "#{OMWEngine:JournalShowAll}" : "";
+ return &mControllerButtons;
+ }
+
+ void setIndexControllerFocus(bool focused)
+ {
+ int col, row;
+ bool isRussian = (mEncoding == ToUTF8::WINDOWS_1251);
+ if (isRussian)
+ {
+ // Cyrillic = 30 (10 + 10 + 10)
+ col = mSelectedIndex / 10;
+ row = mSelectedIndex % 10;
+ }
+ else
+ {
+ // Latin = 26 (13 + 13)
+ col = mSelectedIndex / 13;
+ row = mSelectedIndex % 13;
+ }
+
+ mTopicIndexBook->setColour(col, row, 0, focused ? MWGui::journalHeaderColour : MyGUI::Colour::Black);
+ }
+
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override
+ {
+ bool isRussian = (mEncoding == ToUTF8::WINDOWS_1251);
+
+ if (arg.button == SDL_CONTROLLER_BUTTON_A) // A: Mouse click or Select
+ {
+ if (mOptionsMode && mQuestMode)
+ {
+ // Choose a quest
+ Gui::MWList* list = getWidget(QuestsList);
+ notifyQuestClicked(list->getItemNameAt(mSelectedQuest), 0);
+ }
+ else if (mOptionsMode && mTopicsMode)
+ {
+ // Choose a topic
+ Gui::MWList* list = getWidget(TopicsList);
+ notifyTopicSelected(list->getItemNameAt(mSelectedQuest), 0);
+ }
+ else if (mOptionsMode)
+ {
+ // Choose an index. Cyrillic capital A is a 0xd090 in UTF-8.
+ // Words can not be started with characters 26 or 28.
+ int russianOffset = 0xd090;
+ if (mSelectedIndex >= 26)
+ russianOffset++;
+ if (mSelectedIndex >= 27)
+ russianOffset++; // 27, not 28, because of skipping char 26
+ notifyIndexLinkClicked(isRussian ? mSelectedIndex + russianOffset : mSelectedIndex + 'A');
+ }
+ return true;
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_B) // B: Back
+ {
+ if (mOptionsMode)
+ {
+ // Hide the options overlay
+ notifyCancel(getWidget(CancelBTN));
+ mQuestMode = false;
+ }
+ else if (mStates.size() > 1)
+ {
+ // Pop the current book. If in quest mode, reopen the quest list.
+ notifyJournal(getWidget(JournalBTN));
+ if (mQuestMode)
+ {
+ notifyOptions(getWidget(OptionsBTN));
+ notifyQuests(getWidget(QuestsBTN));
+ }
+ }
+ else
+ {
+ // Close the journal window
+ notifyClose(getWidget(CloseBTN));
+ }
+ return true;
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_X) // X: Quests
+ {
+ if (mOptionsMode && mQuestMode)
+ {
+ // Hide the quest overlay if visible
+ notifyCancel(getWidget(CancelBTN));
+ mQuestMode = false;
+ }
+ else
+ {
+ // Show the quest overlay if viewing a journal entry or the topics
+ if (!mOptionsMode)
+ notifyOptions(getWidget(OptionsBTN));
+ if (!mQuestMode)
+ notifyQuests(getWidget(QuestsBTN));
+ }
+ return true;
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_Y) // Y: Topics
+ {
+ if (mOptionsMode && !mQuestMode)
+ {
+ // Hide the topics overlay if visible
+ notifyCancel(getWidget(CancelBTN));
+ mQuestMode = false;
+ }
+ else
+ {
+ // Show the topics overlay if viewing a journal entry or the quest list
+ if (!mOptionsMode)
+ notifyOptions(getWidget(OptionsBTN));
+ if (mQuestMode)
+ notifyTopics(getWidget(TopicsBTN));
+ }
+ return true;
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_RIGHTSTICK) // R3: Show All/Some
+ {
+ if (mAllQuests)
+ notifyShowActive(getWidget(ShowActiveBTN));
+ else
+ notifyShowAll(getWidget(ShowAllBTN));
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP)
+ {
+ if (mOptionsMode && (mQuestMode || mTopicsMode))
+ {
+ if (mButtons.size() <= 1)
+ return true;
+
+ // Scroll through the list of quests or topics
+ setControllerFocusedQuest(MWGui::wrap(mSelectedQuest - 1, mButtons.size()));
+ }
+ else if (mOptionsMode)
+ {
+ setIndexControllerFocus(false);
+ if (isRussian)
+ {
+ // Cyrillic = 30 (10 + 10 + 10)
+ if (mSelectedIndex == 0)
+ mSelectedIndex = 9;
+ else if (mSelectedIndex == 10)
+ mSelectedIndex = 19;
+ else if (mSelectedIndex == 20)
+ mSelectedIndex = 29;
+ else
+ mSelectedIndex--;
+ }
+ else
+ {
+ // Latin = 26 (13 + 13)
+ if (mSelectedIndex == 0)
+ mSelectedIndex = 12;
+ else if (mSelectedIndex == 13)
+ mSelectedIndex = 25;
+ else
+ mSelectedIndex--;
+ }
+ setIndexControllerFocus(true);
+ setText(PageOneNum, 1); // Redraw the list
+ }
+ return true;
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
+ {
+ if (mOptionsMode && (mQuestMode || mTopicsMode))
+ {
+ if (mButtons.size() <= 1)
+ return true;
+
+ // Scroll through the list of quests or topics
+ setControllerFocusedQuest(MWGui::wrap(mSelectedQuest + 1, mButtons.size()));
+ }
+ else if (mOptionsMode)
+ {
+ setIndexControllerFocus(false);
+ if (isRussian)
+ {
+ // Cyrillic = 30 (10 + 10 + 10)
+ if (mSelectedIndex == 9)
+ mSelectedIndex = 0;
+ else if (mSelectedIndex == 19)
+ mSelectedIndex = 10;
+ else if (mSelectedIndex == 29)
+ mSelectedIndex = 20;
+ else
+ mSelectedIndex++;
+ }
+ else
+ {
+ // Latin = 26 (13 + 13)
+ if (mSelectedIndex == 12)
+ mSelectedIndex = 0;
+ else if (mSelectedIndex == 25)
+ mSelectedIndex = 13;
+ else
+ mSelectedIndex++;
+ }
+ setIndexControllerFocus(true);
+ setText(PageOneNum, 1); // Redraw the list
+ }
+ return true;
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT)
+ {
+ if (!mOptionsMode)
+ notifyPrevPage(getWidget(PrevPageBTN));
+ else if (mOptionsMode && !mQuestMode && !mTopicsMode)
+ {
+ setIndexControllerFocus(false);
+ if (isRussian)
+ {
+ // Cyrillic = 30 (10 + 10 + 10)
+ mSelectedIndex = (mSelectedIndex + 20) % 30;
+ }
+ else
+ {
+ // Latin = 26 (13 + 13)
+ mSelectedIndex = (mSelectedIndex + 13) % 26;
+ }
+ setIndexControllerFocus(true);
+ setText(PageOneNum, 1); // Redraw the list
+ }
+ return true;
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT)
+ {
+ if (!mOptionsMode)
+ notifyNextPage(getWidget(NextPageBTN));
+ else if (mOptionsMode && !mQuestMode && !mTopicsMode)
+ {
+ setIndexControllerFocus(false);
+ if (isRussian)
+ {
+ // Cyrillic = 30 (10 + 10 + 10)
+ mSelectedIndex = (mSelectedIndex + 10) % 30;
+ }
+ else
+ {
+ // Latin = 26 (13 + 13)
+ mSelectedIndex = (mSelectedIndex + 13) % 26;
+ }
+ setIndexControllerFocus(true);
+ setText(PageOneNum, 1); // Redraw the list
+ }
+ return true;
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_LEFTSHOULDER) // LB: Previous Page
+ {
+ if (!mOptionsMode)
+ notifyPrevPage(getWidget(PrevPageBTN));
+ return true;
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER) // RB: Next Page
+ {
+ if (!mOptionsMode)
+ notifyNextPage(getWidget(NextPageBTN));
+ return true;
+ }
+
+ return false;
+ }
+
+ void setControllerFocusedQuest(size_t index)
+ {
+ size_t listSize = mButtons.size();
+ if (mSelectedQuest < listSize)
+ mButtons[mSelectedQuest]->setTextColour(MyGUI::Colour::Black);
+
+ mSelectedQuest = index;
+ if (mSelectedQuest < listSize)
+ {
+ mButtons[mSelectedQuest]->setTextColour(MWGui::journalHeaderColour);
+
+ // Scroll the list to keep the active item in view
+ Gui::MWList* list = getWidget(mQuestMode ? QuestsList : TopicsList);
+ if (mSelectedQuest <= 3)
+ list->setViewOffset(0);
+ else
+ {
+ int offset = 0;
+ for (int i = 0; i < static_cast(mSelectedQuest) - 3; i++)
+ offset += mButtons[i]->getHeight() + 3;
+ list->setViewOffset(-offset);
+ }
+ }
+ }
};
}
diff --git a/apps/openmw/mwgui/journalwindow.hpp b/apps/openmw/mwgui/journalwindow.hpp
index f0f394156c..4a1f686ff1 100644
--- a/apps/openmw/mwgui/journalwindow.hpp
+++ b/apps/openmw/mwgui/journalwindow.hpp
@@ -31,6 +31,12 @@ namespace MWGui
void setVisible(bool newValue) override = 0;
std::string_view getWindowIdForLua() const override { return "Journal"; }
+
+ std::vector mButtons;
+ size_t mSelectedQuest = 0;
+ size_t mSelectedIndex = 0;
+ void setIndexControllerFocus(bool focused);
+ void setControllerFocusedQuest(size_t index);
};
}
diff --git a/apps/openmw/mwgui/levelupdialog.cpp b/apps/openmw/mwgui/levelupdialog.cpp
index 87f2db55a5..b9c90e51e2 100644
--- a/apps/openmw/mwgui/levelupdialog.cpp
+++ b/apps/openmw/mwgui/levelupdialog.cpp
@@ -8,6 +8,7 @@
#include
#include
+#include
#include
#include "../mwbase/environment.hpp"
@@ -72,6 +73,7 @@ namespace MWGui
widgets.mButton->setCaption(attribute.mName);
widgets.mValue = hbox->createWidget("SandText", {}, MyGUI::Align::Default);
mAttributeWidgets.emplace(attribute.mId, widgets);
+ mAttributeButtons.emplace_back(widgets.mButton);
++i;
}
@@ -90,6 +92,15 @@ namespace MWGui
mCoins.push_back(image);
}
+ if (Settings::gui().mControllerMenus)
+ {
+ mDisableGamepadCursor = true;
+ mControllerButtons.a = "#{sSelect}";
+ mControllerButtons.x = "#{sDone}";
+ mOkButton->setCaption(
+ MyGUI::UString(MWBase::Environment::get().getWindowManager()->getGameSettingString("sDone", {})));
+ }
+
center();
}
@@ -217,6 +228,13 @@ namespace MWGui
center();
+ if (Settings::gui().mControllerMenus)
+ {
+ mControllerFocus = 0;
+ for (size_t i = 0; i < mAttributeButtons.size(); i++)
+ setControllerFocus(mAttributeButtons, i, i == 0);
+ }
+
// Play LevelUp Music
MWBase::Environment::get().getSoundManager()->streamMusic(MWSound::triumphMusic, MWSound::MusicType::Normal);
}
@@ -363,4 +381,48 @@ namespace MWGui
return ret;
}
+
+ bool LevelupDialog::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_A)
+ {
+ if (mControllerFocus >= 0 && mControllerFocus < static_cast(mAttributeButtons.size()))
+ onAttributeClicked(mAttributeButtons[mControllerFocus]);
+ MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Item Gold Up"));
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_X)
+ {
+ onOkButtonClicked(mOkButton);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP)
+ {
+ setControllerFocus(mAttributeButtons, mControllerFocus, false);
+ if (mControllerFocus == 0)
+ mControllerFocus = 3;
+ else if (mControllerFocus == 4)
+ mControllerFocus = 7;
+ else
+ mControllerFocus--;
+ setControllerFocus(mAttributeButtons, mControllerFocus, true);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
+ {
+ setControllerFocus(mAttributeButtons, mControllerFocus, false);
+ if (mControllerFocus == 3)
+ mControllerFocus = 0;
+ else if (mControllerFocus == 7)
+ mControllerFocus = 4;
+ else
+ mControllerFocus++;
+ setControllerFocus(mAttributeButtons, mControllerFocus, true);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT || arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT)
+ {
+ setControllerFocus(mAttributeButtons, mControllerFocus, false);
+ mControllerFocus = (mControllerFocus + 4) % mAttributeButtons.size();
+ setControllerFocus(mAttributeButtons, mControllerFocus, true);
+ }
+
+ return true;
+ }
}
diff --git a/apps/openmw/mwgui/levelupdialog.hpp b/apps/openmw/mwgui/levelupdialog.hpp
index 486390679b..8a34a94c8b 100644
--- a/apps/openmw/mwgui/levelupdialog.hpp
+++ b/apps/openmw/mwgui/levelupdialog.hpp
@@ -49,6 +49,10 @@ namespace MWGui
std::string_view getLevelupClassImage(
const int combatIncreases, const int magicIncreases, const int stealthIncreases);
+
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
+ std::vector mAttributeButtons;
+ int mControllerFocus;
};
}
diff --git a/apps/openmw/mwgui/mainmenu.cpp b/apps/openmw/mwgui/mainmenu.cpp
index 1b3619bd9f..d9d5b5c33b 100644
--- a/apps/openmw/mwgui/mainmenu.cpp
+++ b/apps/openmw/mwgui/mainmenu.cpp
@@ -1,6 +1,7 @@
#include "mainmenu.hpp"
#include
+#include
#include
#include
@@ -105,6 +106,7 @@ namespace MWGui
constexpr VFS::Path::NormalizedView menuBackgroundVideo("video/menu_background.bik");
mHasAnimatedMenu = mVFS->exists(menuBackgroundVideo);
+ mDisableGamepadCursor = Settings::gui().mControllerMenus;
updateMenu();
}
@@ -163,9 +165,7 @@ namespace MWGui
const std::string& name = *sender->getUserData();
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 +208,32 @@ namespace MWGui
}
}
+ bool MainMenu::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_A)
+ {
+ MWBase::Environment::get().getWindowManager()->injectKeyPress(MyGUI::KeyCode::Space, 0, false);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_B || arg.button == SDL_CONTROLLER_BUTTON_START)
+ {
+ if (mButtons["return"]->getVisible())
+ onButtonClicked(mButtons["return"]);
+ else
+ MWBase::Environment::get().getWindowManager()->injectKeyPress(MyGUI::KeyCode::Escape, 0, false);
+ }
+ else if (arg.button == 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);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
+ {
+ MWBase::Environment::get().getWindowManager()->injectKeyPress(MyGUI::KeyCode::Tab, 0, false);
+ }
+ return true;
+ }
+
void MainMenu::showBackground(bool show)
{
if (mVideo && !show)
diff --git a/apps/openmw/mwgui/mainmenu.hpp b/apps/openmw/mwgui/mainmenu.hpp
index 06a8c945c1..453a16b5e4 100644
--- a/apps/openmw/mwgui/mainmenu.hpp
+++ b/apps/openmw/mwgui/mainmenu.hpp
@@ -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;
diff --git a/apps/openmw/mwgui/mapwindow.cpp b/apps/openmw/mwgui/mapwindow.cpp
index bf4bd7644c..38cfbc1e58 100644
--- a/apps/openmw/mwgui/mapwindow.cpp
+++ b/apps/openmw/mwgui/mapwindow.cpp
@@ -12,6 +12,7 @@
#include
#include
#include
+#include
#include
#include
@@ -832,6 +833,14 @@ namespace MWGui
mGlobalMap->setVisible(global);
mLocalMap->setVisible(!global);
+
+ if (Settings::gui().mControllerMenus)
+ {
+ mControllerButtons.b = "#{sBack}";
+ mControllerButtons.x = global ? "#{sLocal}" : "#{sWorld}";
+ mControllerButtons.y = "#{sCenter}";
+ mControllerButtons.dpad = Settings::map().mAllowZooming ? "" : "#{sMove}";
+ }
}
void MapWindow::onNoteEditOk()
@@ -1020,7 +1029,20 @@ namespace MWGui
void MapWindow::setVisible(bool visible)
{
WindowBase::setVisible(visible);
- mButton->setVisible(visible && MWBase::Environment::get().getWindowManager()->getMode() != MWGui::GM_None);
+ MWGui::GuiMode mode = MWBase::Environment::get().getWindowManager()->getMode();
+ mButton->setVisible(visible && mode != MWGui::GM_None);
+
+ if (Settings::gui().mControllerMenus && mode == MWGui::GM_None && pinned() && visible)
+ {
+ // Restore the window to pinned size.
+ MyGUI::Window* window = mMainWidget->castType();
+ MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize();
+ const float x = Settings::windows().mMapX * viewSize.width;
+ const float y = Settings::windows().mMapY * viewSize.height;
+ const float w = Settings::windows().mMapW * viewSize.width;
+ const float h = Settings::windows().mMapH * viewSize.height;
+ window->setCoord(x, y, w, h);
+ }
}
void MapWindow::renderGlobalMap()
@@ -1208,6 +1230,8 @@ namespace MWGui
mLocalMap->setVisible(!global);
mButton->setCaptionWithReplacing(global ? "#{sLocal}" : "#{sWorld}");
+ mControllerButtons.x = global ? "#{sLocal}" : "#{sWorld}";
+ MWBase::Environment::get().getWindowManager()->updateControllerButtonsOverlay();
}
void MapWindow::onPinToggled()
@@ -1368,6 +1392,69 @@ namespace MWGui
mGlobalMapRender->asyncWritePng();
}
+ bool MapWindow::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ MWBase::Environment::get().getWindowManager()->exitCurrentGuiMode();
+ else if (arg.button == SDL_CONTROLLER_BUTTON_X)
+ {
+ onWorldButtonClicked(mButton);
+ MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_Y)
+ {
+ centerView();
+ MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP)
+ shiftMap(0, 100);
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
+ shiftMap(0, -100);
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT)
+ shiftMap(100, 0);
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT)
+ shiftMap(-100, 0);
+
+ return true;
+ }
+
+ void MapWindow::shiftMap(int dx, int dy)
+ {
+ if (dx == 0 && dy == 0)
+ return;
+
+ if (!Settings::map().mGlobal)
+ {
+ mNeedDoorMarkersUpdate = true;
+ mLocalMap->setViewOffset(
+ MyGUI::IntPoint(mLocalMap->getViewOffset().left + dx, mLocalMap->getViewOffset().top + dy));
+ }
+ else
+ {
+ mGlobalMap->setViewOffset(
+ MyGUI::IntPoint(mGlobalMap->getViewOffset().left + dx, mGlobalMap->getViewOffset().top + dy));
+ }
+ }
+
+ void MapWindow::setActiveControllerWindow(bool active)
+ {
+ if (MWBase::Environment::get().getWindowManager()->getMode() == MWGui::GM_Inventory)
+ {
+ // Fill the screen, or limit to a certain size on large screens. Size chosen to
+ // show the entire local map without scrolling.
+ MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize();
+ int width = std::min(viewSize.width, 1552);
+ int height = std::min(viewSize.height - 48 - 48, 1572);
+ int x = (viewSize.width - width) / 2;
+ int y = (viewSize.height - height) / 2;
+
+ MyGUI::Window* window = mMainWidget->castType();
+ window->setCoord(x, active ? y : viewSize.height + 1, width, height);
+ }
+
+ WindowBase::setActiveControllerWindow(active);
+ }
+
// -------------------------------------------------------------------
EditNoteDialog::EditNoteDialog()
@@ -1381,6 +1468,12 @@ namespace MWGui
mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &EditNoteDialog::onCancelButtonClicked);
mOkButton->eventMouseButtonClick += MyGUI::newDelegate(this, &EditNoteDialog::onOkButtonClicked);
mDeleteButton->eventMouseButtonClick += MyGUI::newDelegate(this, &EditNoteDialog::onDeleteButtonClicked);
+
+ if (Settings::gui().mControllerMenus)
+ {
+ mControllerButtons.a = "#{sOk}";
+ mControllerButtons.b = "#{sCancel}";
+ }
}
void EditNoteDialog::showDeleteButton(bool show)
@@ -1408,6 +1501,13 @@ namespace MWGui
WindowModal::onOpen();
center();
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mTextEdit);
+
+ if (Settings::gui().mControllerMenus)
+ {
+ mControllerFocus = getDeleteButtonShown() ? 1 : 0;
+ mOkButton->setStateSelected(true);
+ mCancelButton->setStateSelected(false);
+ }
}
void EditNoteDialog::onCancelButtonClicked(MyGUI::Widget* sender)
@@ -1425,6 +1525,78 @@ namespace MWGui
eventDeleteClicked();
}
+ ControllerButtonStr* EditNoteDialog::getControllerButtons()
+ {
+ mControllerButtons.x = getDeleteButtonShown() ? "#{sDelete}" : "";
+ return &mControllerButtons;
+ }
+
+ bool EditNoteDialog::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_A)
+ {
+ if (getDeleteButtonShown())
+ {
+ if (mControllerFocus == 0)
+ onDeleteButtonClicked(mDeleteButton);
+ else if (mControllerFocus == 1)
+ onOkButtonClicked(mOkButton);
+ else
+ onCancelButtonClicked(mCancelButton);
+ }
+ else
+ {
+ if (mControllerFocus == 0)
+ onOkButtonClicked(mOkButton);
+ else
+ onCancelButtonClicked(mCancelButton);
+ }
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ {
+ onCancelButtonClicked(mCancelButton);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_X)
+ {
+ if (getDeleteButtonShown())
+ onDeleteButtonClicked(mDeleteButton);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT)
+ {
+ if (getDeleteButtonShown())
+ {
+ mControllerFocus = wrap(mControllerFocus - 1, 3);
+ mDeleteButton->setStateSelected(mControllerFocus == 0);
+ mOkButton->setStateSelected(mControllerFocus == 1);
+ mCancelButton->setStateSelected(mControllerFocus == 2);
+ }
+ else
+ {
+ mControllerFocus = 0;
+ mOkButton->setStateSelected(mControllerFocus == 0);
+ mCancelButton->setStateSelected(mControllerFocus == 1);
+ }
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT)
+ {
+ if (getDeleteButtonShown())
+ {
+ mControllerFocus = wrap(mControllerFocus + 1, 3);
+ mDeleteButton->setStateSelected(mControllerFocus == 0);
+ mOkButton->setStateSelected(mControllerFocus == 1);
+ mCancelButton->setStateSelected(mControllerFocus == 2);
+ }
+ else
+ {
+ mControllerFocus = 1;
+ mOkButton->setStateSelected(mControllerFocus == 0);
+ mCancelButton->setStateSelected(mControllerFocus == 1);
+ }
+ }
+
+ return true;
+ }
+
bool LocalMapBase::MarkerUserData::isPositionExplored() const
{
if (!mLocalMapRender)
diff --git a/apps/openmw/mwgui/mapwindow.hpp b/apps/openmw/mwgui/mapwindow.hpp
index ed070c5407..8730964094 100644
--- a/apps/openmw/mwgui/mapwindow.hpp
+++ b/apps/openmw/mwgui/mapwindow.hpp
@@ -212,6 +212,8 @@ namespace MWGui
EventHandle_Void eventDeleteClicked;
EventHandle_Void eventOkClicked;
+ ControllerButtonStr* getControllerButtons() override;
+
private:
void onCancelButtonClicked(MyGUI::Widget* sender);
void onOkButtonClicked(MyGUI::Widget* sender);
@@ -221,6 +223,9 @@ namespace MWGui
MyGUI::Button* mOkButton;
MyGUI::Button* mCancelButton;
MyGUI::Button* mDeleteButton;
+
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
+ int mControllerFocus;
};
class MapWindow : public MWGui::WindowPinnableBase, public LocalMapBase, public NoDrop
@@ -265,6 +270,10 @@ namespace MWGui
std::string_view getWindowIdForLua() const override { return "Map"; }
+ protected:
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
+ void setActiveControllerWindow(bool active) override;
+
private:
void onDragStart(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id);
void onMouseDrag(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id);
@@ -283,6 +292,7 @@ namespace MWGui
void setGlobalMapMarkerTooltip(MyGUI::Widget* widget, int x, int y);
float getMarkerSize(size_t agregatedWeight) const;
void resizeGlobalMap();
+ void shiftMap(int dx, int dy);
void worldPosToGlobalMapImageSpace(float x, float z, float& imageX, float& imageY) const;
MyGUI::IntCoord createMarkerCoords(float x, float y, float agregatedWeight) const;
MyGUI::Widget* createMarker(const std::string& name, float x, float y, float agregatedWeight);
diff --git a/apps/openmw/mwgui/merchantrepair.cpp b/apps/openmw/mwgui/merchantrepair.cpp
index 54f9ae4187..425c519175 100644
--- a/apps/openmw/mwgui/merchantrepair.cpp
+++ b/apps/openmw/mwgui/merchantrepair.cpp
@@ -28,6 +28,13 @@ namespace MWGui
getWidget(mGoldLabel, "PlayerGold");
mOkButton->eventMouseButtonClick += MyGUI::newDelegate(this, &MerchantRepair::onOkButtonClick);
+
+ if (Settings::gui().mControllerMenus)
+ {
+ mDisableGamepadCursor = true;
+ mControllerButtons.a = "#{sRepair}";
+ mControllerButtons.b = "#{sCancel}";
+ }
}
void MerchantRepair::setPtr(const MWWorld::Ptr& actor)
@@ -38,6 +45,7 @@ namespace MWGui
while (mList->getChildCount())
MyGUI::Gui::getInstance().destroyWidget(mList->getChildAt(0));
+ mButtons.clear();
const int lineHeight = Settings::gui().mFontSize + 2;
int currentY = 0;
@@ -101,6 +109,15 @@ namespace MWGui
button->eventMouseWheel += MyGUI::newDelegate(this, &MerchantRepair::onMouseWheel);
button->setUserString("ToolTipType", "ItemPtr");
button->eventMouseButtonClick += MyGUI::newDelegate(this, &MerchantRepair::onRepairButtonClick);
+ if (price <= playerGold)
+ mButtons.emplace_back(std::make_pair(button, mButtons.size()));
+ }
+
+ if (Settings::gui().mControllerMenus)
+ {
+ mControllerFocus = 0;
+ if (mButtons.size() > 0)
+ mButtons[0].first->setStateSelected(true);
}
// Canvas size must be expressed with VScroll disabled, otherwise MyGUI would expand the scroll area when the
@@ -157,4 +174,49 @@ namespace MWGui
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_MerchantRepair);
}
+ bool MerchantRepair::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_A)
+ {
+ if (mControllerFocus >= 0 && mControllerFocus < static_cast(mButtons.size()))
+ onRepairButtonClick(mButtons[mControllerFocus].first);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ {
+ onOkButtonClick(mOkButton);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP)
+ {
+ if (mButtons.size() <= 1)
+ return true;
+
+ mButtons[mControllerFocus].first->setStateSelected(false);
+ mControllerFocus = wrap(mControllerFocus - 1, mButtons.size());
+ mButtons[mControllerFocus].first->setStateSelected(true);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
+ {
+ if (mButtons.size() <= 1)
+ return true;
+
+ mButtons[mControllerFocus].first->setStateSelected(false);
+ mControllerFocus = wrap(mControllerFocus + 1, mButtons.size());
+ mButtons[mControllerFocus].first->setStateSelected(true);
+ }
+
+ // Scroll the list to keep the active item in view
+ if (mControllerFocus >= 0 && mControllerFocus < static_cast(mButtons.size()))
+ {
+ int line = mButtons[mControllerFocus].second;
+ if (line <= 5)
+ mList->setViewOffset(MyGUI::IntPoint(0, 0));
+ else
+ {
+ const int lineHeight = Settings::gui().mFontSize + 2;
+ mList->setViewOffset(MyGUI::IntPoint(0, -lineHeight * (line - 5)));
+ }
+ }
+
+ return true;
+ }
}
diff --git a/apps/openmw/mwgui/merchantrepair.hpp b/apps/openmw/mwgui/merchantrepair.hpp
index ffe5b86bdb..e878d34b7d 100644
--- a/apps/openmw/mwgui/merchantrepair.hpp
+++ b/apps/openmw/mwgui/merchantrepair.hpp
@@ -22,13 +22,18 @@ namespace MWGui
MyGUI::ScrollView* mList;
MyGUI::Button* mOkButton;
MyGUI::TextBox* mGoldLabel;
+ /// List of enabled/repairable items and their index in the full list.
+ std::vector> mButtons;
MWWorld::Ptr mActor;
+ int mControllerFocus;
+
protected:
void onMouseWheel(MyGUI::Widget* _sender, int _rel);
void onRepairButtonClick(MyGUI::Widget* sender);
void onOkButtonClick(MyGUI::Widget* sender);
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
};
}
diff --git a/apps/openmw/mwgui/messagebox.cpp b/apps/openmw/mwgui/messagebox.cpp
index 1d6e1511c4..80b2a34a5b 100644
--- a/apps/openmw/mwgui/messagebox.cpp
+++ b/apps/openmw/mwgui/messagebox.cpp
@@ -8,6 +8,7 @@
#include
#include
+#include
#include "../mwbase/environment.hpp"
#include "../mwbase/inputmanager.hpp"
@@ -280,6 +281,22 @@ namespace MWGui
}
}
+ if (Settings::gui().mControllerMenus)
+ {
+ mDisableGamepadCursor = true;
+ mControllerButtons.a = "#{sOk}";
+
+ // If we have more than one button, we need to set the focus to the first one.
+ if (mButtons.size() > 1)
+ {
+ mControllerFocus = 0;
+ if (mDefaultFocus >= 0 && mDefaultFocus < static_cast(mButtons.size()))
+ mControllerFocus = mDefaultFocus;
+ for (int i = 0; i < static_cast(mButtons.size()); ++i)
+ mButtons[i]->setStateSelected(i == mControllerFocus);
+ }
+ }
+
MyGUI::IntSize mainWidgetSize;
if (buttonsWidth < textSize.width)
{
@@ -431,4 +448,41 @@ namespace MWGui
return mButtonPressed;
}
+ bool InteractiveMessageBox::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_A)
+ {
+ mControllerFocus = std::clamp(mControllerFocus, 0, static_cast(mButtons.size()) - 1);
+ buttonActivated(mButtons[mControllerFocus]);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ {
+ if (mButtons.size() == 1)
+ buttonActivated(mButtons[0]);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP || arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT)
+ {
+ if (mButtons.size() <= 1)
+ return true;
+ if (mButtons.size() == 2 && mControllerFocus == 0)
+ return true;
+
+ setControllerFocus(mButtons, mControllerFocus, false);
+ mControllerFocus = wrap(mControllerFocus - 1, mButtons.size());
+ setControllerFocus(mButtons, mControllerFocus, true);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN || arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT)
+ {
+ if (mButtons.size() <= 1)
+ return true;
+ if (mButtons.size() == 2 && mControllerFocus == static_cast(mButtons.size()) - 1)
+ return true;
+
+ setControllerFocus(mButtons, mControllerFocus, false);
+ mControllerFocus = wrap(mControllerFocus + 1, mButtons.size());
+ setControllerFocus(mButtons, mControllerFocus, true);
+ }
+
+ return true;
+ }
}
diff --git a/apps/openmw/mwgui/messagebox.hpp b/apps/openmw/mwgui/messagebox.hpp
index feb717e0ad..e6128ee0d1 100644
--- a/apps/openmw/mwgui/messagebox.hpp
+++ b/apps/openmw/mwgui/messagebox.hpp
@@ -103,6 +103,8 @@ namespace MWGui
bool mMarkedToDelete;
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
+
private:
void buttonActivated(MyGUI::Widget* _widget);
@@ -114,6 +116,7 @@ namespace MWGui
int mButtonPressed;
int mDefaultFocus;
bool mImmediate;
+ int mControllerFocus = 0;
};
}
diff --git a/apps/openmw/mwgui/quickkeysmenu.cpp b/apps/openmw/mwgui/quickkeysmenu.cpp
index c8932c97b6..96045b8e21 100644
--- a/apps/openmw/mwgui/quickkeysmenu.cpp
+++ b/apps/openmw/mwgui/quickkeysmenu.cpp
@@ -58,6 +58,12 @@ namespace MWGui
unassign(&mKey[i]);
}
+
+ if (Settings::gui().mControllerMenus)
+ {
+ mControllerButtons.a = "#{sSelect}";
+ mControllerButtons.b = "#{sOK}";
+ }
}
void QuickKeysMenu::clear()
@@ -109,6 +115,13 @@ namespace MWGui
{
validate(index);
}
+
+ if (Settings::gui().mControllerMenus)
+ {
+ mControllerFocus = 0;
+ for (int i = 0; i < static_cast(mKey.size()); i++)
+ mKey[i].button->setControllerFocus(i == mControllerFocus);
+ }
}
void QuickKeysMenu::onClose()
@@ -456,6 +469,39 @@ namespace MWGui
MWBase::Environment::get().getWindowManager()->updateSpellWindow();
}
+ bool QuickKeysMenu::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_A)
+ onQuickKeyButtonClicked(mKey[mControllerFocus].button);
+ if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ onOkButtonClicked(mOkButton);
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP || arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
+ mControllerFocus = (mControllerFocus + 5) % 10;
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT)
+ {
+ if (mControllerFocus == 0)
+ mControllerFocus = 4;
+ else if (mControllerFocus == 5)
+ mControllerFocus = 9;
+ else
+ mControllerFocus--;
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT)
+ {
+ if (mControllerFocus == 4)
+ mControllerFocus = 0;
+ else if (mControllerFocus == 9)
+ mControllerFocus = 5;
+ else
+ mControllerFocus++;
+ }
+
+ for (int i = 0; i < static_cast(mKey.size()); i++)
+ mKey[i].button->setControllerFocus(i == mControllerFocus);
+
+ return true;
+ }
+
// ---------------------------------------------------------------------------------------------------------
QuickKeysMenuAssign::QuickKeysMenuAssign(QuickKeysMenu* parent)
@@ -491,9 +537,45 @@ namespace MWGui
mCancelButton->setCoord((maxWidth - mCancelButton->getTextSize().width - 24) / 2 + 8, mCancelButton->getTop(),
mCancelButton->getTextSize().width + 24, mCancelButton->getHeight());
+ if (Settings::gui().mControllerMenus)
+ {
+ mDisableGamepadCursor = true;
+ mItemButton->setStateSelected(true);
+ mControllerButtons.a = "#{sSelect}";
+ mControllerButtons.b = "#{sCancel}";
+ }
+
center();
}
+ bool QuickKeysMenuAssign::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_A)
+ {
+ if (mControllerFocus == 0)
+ mParent->onItemButtonClicked(mItemButton);
+ else if (mControllerFocus == 1)
+ mParent->onMagicButtonClicked(mMagicButton);
+ else if (mControllerFocus == 2)
+ mParent->onUnassignButtonClicked(mUnassignButton);
+ else if (mControllerFocus == 3)
+ mParent->onCancelButtonClicked(mCancelButton);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ mParent->onCancelButtonClicked(mCancelButton);
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP)
+ mControllerFocus = wrap(mControllerFocus - 1, 4);
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
+ mControllerFocus = wrap(mControllerFocus + 1, 4);
+
+ mItemButton->setStateSelected(mControllerFocus == 0);
+ mMagicButton->setStateSelected(mControllerFocus == 1);
+ mUnassignButton->setStateSelected(mControllerFocus == 2);
+ mCancelButton->setStateSelected(mControllerFocus == 3);
+
+ return true;
+ }
+
void QuickKeysMenu::write(ESM::ESMWriter& writer)
{
writer.startRecord(ESM::REC_KEYS);
@@ -603,6 +685,12 @@ namespace MWGui
mMagicList->setHighlightSelected(false);
mMagicList->eventSpellClicked += MyGUI::newDelegate(this, &MagicSelectionDialog::onModelIndexSelected);
+ if (Settings::gui().mControllerMenus)
+ {
+ mControllerButtons.a = "#{sSelect}";
+ mControllerButtons.b = "#{sCancel}";
+ }
+
center();
}
@@ -634,4 +722,13 @@ namespace MWGui
mParent->onAssignMagic(spell.mId);
}
+ bool MagicSelectionDialog::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ onCancelButtonClicked(mCancelButton);
+ else
+ mMagicList->onControllerButton(arg.button);
+
+ return true;
+ }
}
diff --git a/apps/openmw/mwgui/quickkeysmenu.hpp b/apps/openmw/mwgui/quickkeysmenu.hpp
index 904029b9a0..228eb926b4 100644
--- a/apps/openmw/mwgui/quickkeysmenu.hpp
+++ b/apps/openmw/mwgui/quickkeysmenu.hpp
@@ -72,6 +72,9 @@ namespace MWGui
// Check if quick key is still valid
inline void validate(int index);
void unassign(keyData* key);
+
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
+ int mControllerFocus;
};
class QuickKeysMenuAssign : public WindowModal
@@ -87,6 +90,9 @@ namespace MWGui
MyGUI::Button* mCancelButton;
QuickKeysMenu* mParent;
+
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
+ int mControllerFocus;
};
class MagicSelectionDialog : public WindowModal
@@ -105,6 +111,9 @@ namespace MWGui
void onCancelButtonClicked(MyGUI::Widget* sender);
void onModelIndexSelected(SpellModel::ModelIndex index);
+
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
+ int mControllerFocus;
};
}
diff --git a/apps/openmw/mwgui/race.cpp b/apps/openmw/mwgui/race.cpp
index 7b445d419f..fdc8725fa0 100644
--- a/apps/openmw/mwgui/race.cpp
+++ b/apps/openmw/mwgui/race.cpp
@@ -23,16 +23,6 @@
namespace
{
- int wrap(int index, int max)
- {
- if (index < 0)
- return max - 1;
- else if (index >= max)
- return 0;
- else
- return index;
- }
-
bool sortRaces(const std::pair& left, const std::pair& right)
{
return left.second.compare(right.second) < 0;
@@ -108,15 +98,23 @@ namespace MWGui
MWBase::Environment::get().getWindowManager()->getGameSettingString("sRaceMenu7", "Specials"));
getWidget(mSpellPowerList, "SpellPowerList");
- MyGUI::Button* backButton;
- getWidget(backButton, "BackButton");
- backButton->eventMouseButtonClick += MyGUI::newDelegate(this, &RaceDialog::onBackClicked);
+ getWidget(mBackButton, "BackButton");
+ mBackButton->eventMouseButtonClick += MyGUI::newDelegate(this, &RaceDialog::onBackClicked);
- MyGUI::Button* okButton;
- getWidget(okButton, "OKButton");
- okButton->setCaption(
+ getWidget(mOkButton, "OKButton");
+ mOkButton->setCaption(
MyGUI::UString(MWBase::Environment::get().getWindowManager()->getGameSettingString("sOK", {})));
- okButton->eventMouseButtonClick += MyGUI::newDelegate(this, &RaceDialog::onOkClicked);
+ mOkButton->eventMouseButtonClick += MyGUI::newDelegate(this, &RaceDialog::onOkClicked);
+
+ if (Settings::gui().mControllerMenus)
+ {
+ mControllerButtons.lStick = "#{sMouse}";
+ mControllerButtons.a = "#{sSelect}";
+ mControllerButtons.b = "#{sBack}";
+ mControllerButtons.y = "#{sSex}";
+ mControllerButtons.l1 = "#{sHair}";
+ mControllerButtons.r1 = "#{sFace}";
+ }
updateRaces();
updateSkills();
@@ -129,8 +127,17 @@ namespace MWGui
getWidget(okButton, "OKButton");
if (shown)
+ {
okButton->setCaption(
MyGUI::UString(MWBase::Environment::get().getWindowManager()->getGameSettingString("sNext", {})));
+ mControllerButtons.x = "#{sNext}";
+ }
+ else if (Settings::gui().mControllerMenus)
+ {
+ okButton->setCaption(
+ MyGUI::UString(MWBase::Environment::get().getWindowManager()->getGameSettingString("sDone", {})));
+ mControllerButtons.x = "#{sDone}";
+ }
else
okButton->setCaption(
MyGUI::UString(MWBase::Environment::get().getWindowManager()->getGameSettingString("sOK", {})));
@@ -462,6 +469,56 @@ namespace MWGui
}
}
+ bool RaceDialog::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ {
+ onBackClicked(mBackButton);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_X)
+ {
+ onOkClicked(mOkButton);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_Y)
+ {
+ onSelectNextGender(nullptr);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_LEFTSHOULDER)
+ {
+ onSelectNextHair(nullptr);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER)
+ {
+ onSelectNextFace(nullptr);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP)
+ {
+ MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager();
+ winMgr->setKeyFocusWidget(mRaceList);
+ winMgr->injectKeyPress(MyGUI::KeyCode::ArrowUp, 0, false);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
+ {
+ MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager();
+ winMgr->setKeyFocusWidget(mRaceList);
+ winMgr->injectKeyPress(MyGUI::KeyCode::ArrowDown, 0, false);
+ }
+
+ return true;
+ }
+
+ bool RaceDialog::onControllerThumbstickEvent(const SDL_ControllerAxisEvent& arg)
+ {
+ if (arg.axis == SDL_CONTROLLER_AXIS_RIGHTX)
+ {
+ if (arg.value < -1000 || arg.value > 1000)
+ onPreviewScroll(nullptr, arg.value < 0 ? 1 : -1);
+ return true;
+ }
+
+ return false;
+ }
+
const ESM::NPC& RaceDialog::getResult() const
{
return mPreview->getPrototype();
diff --git a/apps/openmw/mwgui/race.hpp b/apps/openmw/mwgui/race.hpp
index a6ac0e2813..ead058214c 100644
--- a/apps/openmw/mwgui/race.hpp
+++ b/apps/openmw/mwgui/race.hpp
@@ -3,6 +3,7 @@
#include "windowbase.hpp"
#include
+#include
#include
namespace MWRender
@@ -100,7 +101,9 @@ namespace MWGui
MyGUI::ImageBox* mPreviewImage;
MyGUI::ListBox* mRaceList;
- MyGUI::ScrollBar* mHeadRotate;
+ Gui::ScrollBar* mHeadRotate;
+ MyGUI::Button* mBackButton;
+ MyGUI::Button* mOkButton;
MyGUI::Widget* mSkillList;
std::vector mSkillItems;
@@ -118,6 +121,9 @@ namespace MWGui
std::unique_ptr mPreviewTexture;
bool mPreviewDirty;
+
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
+ bool onControllerThumbstickEvent(const SDL_ControllerAxisEvent& arg) override;
};
}
#endif
diff --git a/apps/openmw/mwgui/recharge.cpp b/apps/openmw/mwgui/recharge.cpp
index 7d57988d97..2dfb47fa23 100644
--- a/apps/openmw/mwgui/recharge.cpp
+++ b/apps/openmw/mwgui/recharge.cpp
@@ -39,6 +39,10 @@ namespace MWGui
mBox->setDisplayMode(ItemChargeView::DisplayMode_EnchantmentCharge);
mGemIcon->eventMouseButtonClick += MyGUI::newDelegate(this, &Recharge::onSelectItem);
+
+ mControllerButtons.a = "#{OMWEngine:RechargeSelect}";
+ mControllerButtons.b = "#{sCancel}";
+ mControllerButtons.y = "#{sSoulGem}";
}
void Recharge::onOpen()
@@ -136,4 +140,18 @@ namespace MWGui
updateView();
}
+ bool Recharge::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if ((arg.button == SDL_CONTROLLER_BUTTON_A && !mGemBox->getVisible()) || arg.button == SDL_CONTROLLER_BUTTON_Y)
+ {
+ onSelectItem(mGemIcon);
+ MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ onCancel(mCancelButton);
+ else
+ mBox->onControllerButton(arg.button);
+
+ return true;
+ }
}
diff --git a/apps/openmw/mwgui/recharge.hpp b/apps/openmw/mwgui/recharge.hpp
index f8a037d2db..c10f96e71e 100644
--- a/apps/openmw/mwgui/recharge.hpp
+++ b/apps/openmw/mwgui/recharge.hpp
@@ -51,6 +51,8 @@ namespace MWGui
void onItemClicked(MyGUI::Widget* sender, const MWWorld::Ptr& item);
void onCancel(MyGUI::Widget* sender);
void onMouseWheel(MyGUI::Widget* _sender, int _rel);
+
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
};
}
diff --git a/apps/openmw/mwgui/repair.cpp b/apps/openmw/mwgui/repair.cpp
index c1602b8407..8962ae2abd 100644
--- a/apps/openmw/mwgui/repair.cpp
+++ b/apps/openmw/mwgui/repair.cpp
@@ -39,6 +39,10 @@ namespace MWGui
mRepairBox->setDisplayMode(ItemChargeView::DisplayMode_Health);
mToolIcon->eventMouseButtonClick += MyGUI::newDelegate(this, &Repair::onSelectItem);
+
+ mControllerButtons.a = "#{sRepair}";
+ mControllerButtons.b = "#{sCancel}";
+ mControllerButtons.y = "#{OMWEngine:RepairTool}";
}
void Repair::onOpen()
@@ -150,4 +154,18 @@ namespace MWGui
updateRepairView();
}
+ bool Repair::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if ((arg.button == SDL_CONTROLLER_BUTTON_A && !mToolBox->getVisible()) || arg.button == SDL_CONTROLLER_BUTTON_Y)
+ {
+ onSelectItem(mToolIcon);
+ MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ onCancel(mCancelButton);
+ else
+ mRepairBox->onControllerButton(arg.button);
+
+ return true;
+ }
}
diff --git a/apps/openmw/mwgui/repair.hpp b/apps/openmw/mwgui/repair.hpp
index 093a10e3fa..986b28b613 100644
--- a/apps/openmw/mwgui/repair.hpp
+++ b/apps/openmw/mwgui/repair.hpp
@@ -50,6 +50,8 @@ namespace MWGui
void onRepairItem(MyGUI::Widget* sender, const MWWorld::Ptr& ptr);
void onCancel(MyGUI::Widget* sender);
+
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
};
}
diff --git a/apps/openmw/mwgui/review.cpp b/apps/openmw/mwgui/review.cpp
index ddce2c5f50..dcaa49b1e2 100644
--- a/apps/openmw/mwgui/review.cpp
+++ b/apps/openmw/mwgui/review.cpp
@@ -46,21 +46,25 @@ namespace MWGui
getWidget(button, "NameButton");
adjustButtonSize(button);
button->eventMouseButtonClick += MyGUI::newDelegate(this, &ReviewDialog::onNameClicked);
+ mButtons.push_back(button);
getWidget(mRaceWidget, "RaceText");
getWidget(button, "RaceButton");
adjustButtonSize(button);
button->eventMouseButtonClick += MyGUI::newDelegate(this, &ReviewDialog::onRaceClicked);
+ mButtons.push_back(button);
getWidget(mClassWidget, "ClassText");
getWidget(button, "ClassButton");
adjustButtonSize(button);
button->eventMouseButtonClick += MyGUI::newDelegate(this, &ReviewDialog::onClassClicked);
+ mButtons.push_back(button);
getWidget(mBirthSignWidget, "SignText");
getWidget(button, "SignButton");
adjustButtonSize(button);
button->eventMouseButtonClick += MyGUI::newDelegate(this, &ReviewDialog::onBirthSignClicked);
+ mButtons.push_back(button);
// Setup dynamic stats
getWidget(mHealth, "Health");
@@ -108,10 +112,22 @@ namespace MWGui
MyGUI::Button* backButton;
getWidget(backButton, "BackButton");
backButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ReviewDialog::onBackClicked);
+ mButtons.push_back(backButton);
MyGUI::Button* okButton;
getWidget(okButton, "OKButton");
okButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ReviewDialog::onOkClicked);
+ mButtons.push_back(okButton);
+
+ if (Settings::gui().mControllerMenus)
+ {
+ setControllerFocus(mButtons, mControllerFocus, true);
+ mControllerButtons.a = "#{sSelect}";
+ mControllerButtons.b = "#{sBack}";
+ mControllerButtons.x = "#{sDone}";
+ okButton->setCaption(
+ MyGUI::UString(MWBase::Environment::get().getWindowManager()->getGameSettingString("sDone", {})));
+ }
}
void ReviewDialog::onOpen()
@@ -522,4 +538,54 @@ namespace MWGui
MyGUI::IntPoint(0, static_cast(mSkillView->getViewOffset().top + _rel * 0.3)));
}
+ bool ReviewDialog::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_A)
+ {
+ switch (mControllerFocus)
+ {
+ case 0:
+ onNameClicked(mButtons[0]);
+ break;
+ case 1:
+ onRaceClicked(mButtons[1]);
+ break;
+ case 2:
+ onClassClicked(mButtons[2]);
+ break;
+ case 3:
+ onBirthSignClicked(mButtons[3]);
+ break;
+ case 4:
+ onBackClicked(mButtons[4]);
+ break;
+ case 5:
+ onOkClicked(mButtons[5]);
+ break;
+ }
+ return true;
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ {
+ onBackClicked(mButtons[4]);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_X)
+ {
+ onOkClicked(mButtons[5]);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP || arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT)
+ {
+ setControllerFocus(mButtons, mControllerFocus, false);
+ mControllerFocus = wrap(mControllerFocus - 1, mButtons.size());
+ setControllerFocus(mButtons, mControllerFocus, true);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN || arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT)
+ {
+ setControllerFocus(mButtons, mControllerFocus, false);
+ mControllerFocus = wrap(mControllerFocus + 1, mButtons.size());
+ setControllerFocus(mButtons, mControllerFocus, true);
+ }
+
+ return true;
+ }
}
diff --git a/apps/openmw/mwgui/review.hpp b/apps/openmw/mwgui/review.hpp
index 7226ad628d..fe53787fe3 100644
--- a/apps/openmw/mwgui/review.hpp
+++ b/apps/openmw/mwgui/review.hpp
@@ -72,6 +72,7 @@ namespace MWGui
void onBirthSignClicked(MyGUI::Widget* _sender);
void onMouseWheel(MyGUI::Widget* _sender, int _rel);
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
private:
void addSkills(const std::vector& skills, const std::string& titleId,
@@ -100,6 +101,10 @@ namespace MWGui
std::vector mSkillWidgets; //< Skills and other information
bool mUpdateSkillArea;
+
+ // 0 = Name, 1 = Race, 2 = Class, 3 = BirthSign, 4 = Back, 5 = OK
+ std::vector mButtons;
+ int mControllerFocus = 5;
};
}
#endif
diff --git a/apps/openmw/mwgui/savegamedialog.cpp b/apps/openmw/mwgui/savegamedialog.cpp
index 4957789ffd..e0b10f6b37 100644
--- a/apps/openmw/mwgui/savegamedialog.cpp
+++ b/apps/openmw/mwgui/savegamedialog.cpp
@@ -17,6 +17,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -28,6 +29,7 @@
#include "../mwbase/world.hpp"
#include "../mwworld/datetimemanager.hpp"
#include "../mwworld/esmstore.hpp"
+#include "../mwworld/timestamp.hpp"
#include "../mwstate/character.hpp"
@@ -64,6 +66,9 @@ namespace MWGui
// To avoid accidental deletions
mDeleteButton->setNeedKeyFocus(false);
+
+ mControllerButtons.a = "#{sSelect}";
+ mControllerButtons.b = "#{sCancel}";
}
void SaveGameDialog::onSlotActivated(MyGUI::ListBox* sender, size_t pos)
@@ -145,6 +150,28 @@ namespace MWGui
WindowModal::onOpen();
mSaveNameEdit->setCaption({});
+ if (Settings::gui().mControllerMenus && mSaving)
+ {
+ // For controller mode, set a default save file name. The format is
+ // "Day 24 - Last Steed 7 p.m."
+ const MWWorld::DateTimeManager& timeManager = *MWBase::Environment::get().getWorld()->getTimeManager();
+ std::string_view month = timeManager.getMonthName();
+ int hour = static_cast(timeManager.getTimeStamp().getHour());
+ bool pm = hour >= 12;
+ if (hour >= 13)
+ hour -= 12;
+ if (hour == 0)
+ hour = 12;
+
+ ESM::EpochTimeStamp currentDate = timeManager.getEpochTimeStamp();
+ std::string daysPassed
+ = Misc::StringUtils::format("#{Calendar:day} %i", timeManager.getTimeStamp().getDay());
+ std::string_view formattedHour(pm ? "#{Calendar:pm}" : "#{Calendar:am}");
+ std::string autoFilename = Misc::StringUtils::format(
+ "%s - %i %s %i %s", daysPassed, currentDate.mDay, month, hour, formattedHour);
+
+ mSaveNameEdit->setCaptionWithReplacing(autoFilename);
+ }
if (mSaving)
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mSaveNameEdit);
else
@@ -159,6 +186,13 @@ namespace MWGui
mSaveList->removeAllItems();
onSlotSelected(mSaveList, MyGUI::ITEM_NONE);
+ if (Settings::gui().mControllerMenus)
+ {
+ mOkButtonFocus = true;
+ mOkButton->setStateSelected(true);
+ mCancelButton->setStateSelected(false);
+ }
+
MWBase::StateManager* mgr = MWBase::Environment::get().getStateManager();
if (mgr->characterBegin() == mgr->characterEnd())
return;
@@ -217,7 +251,7 @@ namespace MWGui
}
mCharacterSelection->setIndexSelected(selectedIndex);
if (selectedIndex == MyGUI::ITEM_NONE)
- mCharacterSelection->setCaptionWithReplacing("#{OMWEngine:SelectCharacter}");
+ mCharacterSelection->setCaptionWithReplacing("#{OMWEngine:SelectCharacter}...");
fillSaveList();
}
@@ -491,4 +525,55 @@ namespace MWGui
mScreenshotTexture = std::make_unique(texture);
mScreenshot->setRenderItemTexture(mScreenshotTexture.get());
}
+
+ ControllerButtonStr* SaveGameDialog::getControllerButtons()
+ {
+ mControllerButtons.y = mSaving ? "" : "#{OMWEngine:SelectCharacter}";
+ return &mControllerButtons;
+ }
+
+ bool SaveGameDialog::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_A)
+ {
+ if (mOkButtonFocus)
+ onOkButtonClicked(mOkButton);
+ else
+ onCancelButtonClicked(mCancelButton);
+ MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ {
+ onCancelButtonClicked(mCancelButton);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_Y)
+ {
+ uint32_t index = mCharacterSelection->getIndexSelected();
+ index = wrap(index + 1, mCharacterSelection->getItemCount());
+ mCharacterSelection->setIndexSelected(index);
+ onCharacterSelected(mCharacterSelection, index);
+ MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP)
+ {
+ MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager();
+ winMgr->setKeyFocusWidget(mSaveList);
+ winMgr->injectKeyPress(MyGUI::KeyCode::ArrowUp, 0, false);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
+ {
+ MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager();
+ winMgr->setKeyFocusWidget(mSaveList);
+ winMgr->injectKeyPress(MyGUI::KeyCode::ArrowDown, 0, false);
+ }
+ else if ((arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT && !mOkButtonFocus)
+ || (arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT && mOkButtonFocus))
+ {
+ mOkButtonFocus = !mOkButtonFocus;
+ mOkButton->setStateSelected(mOkButtonFocus);
+ mCancelButton->setStateSelected(!mOkButtonFocus);
+ }
+
+ return true;
+ }
}
diff --git a/apps/openmw/mwgui/savegamedialog.hpp b/apps/openmw/mwgui/savegamedialog.hpp
index af831f066e..13c4588d3f 100644
--- a/apps/openmw/mwgui/savegamedialog.hpp
+++ b/apps/openmw/mwgui/savegamedialog.hpp
@@ -24,6 +24,8 @@ namespace MWGui
void setLoadOrSave(bool load);
+ ControllerButtonStr* getControllerButtons() override;
+
private:
void confirmDeleteSave();
@@ -67,6 +69,9 @@ namespace MWGui
const MWState::Character* mCurrentCharacter;
const MWState::Slot* mCurrentSlot;
+
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
+ bool mOkButtonFocus = true;
};
}
diff --git a/apps/openmw/mwgui/scrollwindow.cpp b/apps/openmw/mwgui/scrollwindow.cpp
index 0b1658fd84..59fb1f2d20 100644
--- a/apps/openmw/mwgui/scrollwindow.cpp
+++ b/apps/openmw/mwgui/scrollwindow.cpp
@@ -7,6 +7,7 @@
#include
#include "../mwbase/environment.hpp"
+#include "../mwbase/inputmanager.hpp"
#include "../mwbase/windowmanager.hpp"
#include "../mwmechanics/actorutil.hpp"
@@ -38,6 +39,10 @@ namespace MWGui
mCloseButton->eventKeyButtonPressed += MyGUI::newDelegate(this, &ScrollWindow::onKeyButtonPressed);
mTakeButton->eventKeyButtonPressed += MyGUI::newDelegate(this, &ScrollWindow::onKeyButtonPressed);
+ mControllerScrollWidget = mTextView;
+ mControllerButtons.b = "#{sClose}";
+ mControllerButtons.dpad = "#{sScrolldown}";
+
center();
}
@@ -115,4 +120,32 @@ namespace MWGui
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Scroll);
}
+
+ void ScrollWindow::onClose()
+ {
+ if (Settings::gui().mControllerMenus)
+ MWBase::Environment::get().getInputManager()->setGamepadGuiCursorEnabled(true);
+ BookWindowBase::onClose();
+ }
+
+ ControllerButtonStr* ScrollWindow::getControllerButtons()
+ {
+ mControllerButtons.a = mTakeButton->getVisible() ? "#{sTake}" : "";
+ return &mControllerButtons;
+ }
+
+ bool ScrollWindow::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_A)
+ {
+ if (mTakeButton->getVisible())
+ onTakeButtonClicked(mTakeButton);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ onCloseButtonClicked(mCloseButton);
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP || arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
+ return false; // Fall through to keyboard
+
+ return true;
+ }
}
diff --git a/apps/openmw/mwgui/scrollwindow.hpp b/apps/openmw/mwgui/scrollwindow.hpp
index 7daea98894..314925c7a7 100644
--- a/apps/openmw/mwgui/scrollwindow.hpp
+++ b/apps/openmw/mwgui/scrollwindow.hpp
@@ -20,15 +20,19 @@ 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"; }
+ ControllerButtonStr* getControllerButtons() override;
+
protected:
void onCloseButtonClicked(MyGUI::Widget* _sender);
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;
private:
Gui::ImageButton* mCloseButton;
diff --git a/apps/openmw/mwgui/settingswindow.cpp b/apps/openmw/mwgui/settingswindow.cpp
index 02353c5d41..726809c583 100644
--- a/apps/openmw/mwgui/settingswindow.cpp
+++ b/apps/openmw/mwgui/settingswindow.cpp
@@ -459,6 +459,10 @@ namespace MWGui
i++;
}
+
+ mControllerButtons.a = "#{sSelect}";
+ mControllerButtons.b = "#{sOk}";
+ mControllerButtons.lStick = "#{sMouse}";
}
void SettingsWindow::onTabChanged(MyGUI::TabControl* /*_sender*/, size_t /*index*/)
@@ -468,7 +472,7 @@ namespace MWGui
void SettingsWindow::onOkButtonClicked(MyGUI::Widget* _sender)
{
- setVisible(false);
+ MWBase::Environment::get().getWindowManager()->toggleSettingsWindow();
}
void SettingsWindow::onResolutionSelected(MyGUI::ListBox* _sender, size_t index)
@@ -1128,4 +1132,32 @@ namespace MWGui
mResolutionList->setScrollPosition(0);
mControlsBox->setViewOffset(MyGUI::IntPoint(0, 0));
}
+
+ bool SettingsWindow::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ {
+ onOkButtonClicked(mOkButton);
+ return true;
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_LEFTSHOULDER)
+ {
+ uint32_t index = mSettingsTab->getIndexSelected();
+ index = wrap(index - 1, mSettingsTab->getItemCount());
+ mSettingsTab->setIndexSelected(index);
+ MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
+ return true;
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER)
+ {
+ uint32_t index = mSettingsTab->getIndexSelected();
+ index = wrap(index + 1, mSettingsTab->getItemCount());
+ mSettingsTab->setIndexSelected(index);
+ MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
+ return true;
+ }
+
+ return false;
+ }
+
}
diff --git a/apps/openmw/mwgui/settingswindow.hpp b/apps/openmw/mwgui/settingswindow.hpp
index dc4e09f8ac..555468d806 100644
--- a/apps/openmw/mwgui/settingswindow.hpp
+++ b/apps/openmw/mwgui/settingswindow.hpp
@@ -26,6 +26,8 @@ namespace MWGui
void onResChange(int, int) override;
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
+
protected:
MyGUI::TabControl* mSettingsTab;
MyGUI::Button* mOkButton;
diff --git a/apps/openmw/mwgui/spellbuyingwindow.cpp b/apps/openmw/mwgui/spellbuyingwindow.cpp
index 2a67af5498..e43bbfc497 100644
--- a/apps/openmw/mwgui/spellbuyingwindow.cpp
+++ b/apps/openmw/mwgui/spellbuyingwindow.cpp
@@ -9,6 +9,7 @@
#include
#include "../mwbase/environment.hpp"
+#include "../mwbase/inputmanager.hpp"
#include "../mwbase/mechanicsmanager.hpp"
#include "../mwbase/windowmanager.hpp"
@@ -32,6 +33,14 @@ namespace MWGui
getWidget(mSpellsView, "SpellsView");
mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SpellBuyingWindow::onCancelButtonClicked);
+
+ if (Settings::gui().mControllerMenus)
+ {
+ mDisableGamepadCursor = true;
+ mControllerButtons.a = "#{sBuy}";
+ mControllerButtons.b = "#{sCancel}";
+ mControllerButtons.r3 = "#{sInfo}";
+ }
}
bool SpellBuyingWindow::sortSpells(const ESM::Spell* left, const ESM::Spell* right)
@@ -71,6 +80,8 @@ namespace MWGui
toAdd->setUserString("SpellCost", std::to_string(spell.mData.mCost));
toAdd->eventMouseButtonClick += MyGUI::newDelegate(this, &SpellBuyingWindow::onSpellButtonClick);
mSpellsWidgetMap.insert(std::make_pair(toAdd, spell.mId));
+ if (price <= playerGold)
+ mSpellButtons.emplace_back(std::make_pair(toAdd, mSpellsWidgetMap.size()));
}
void SpellBuyingWindow::clearSpells()
@@ -80,6 +91,7 @@ namespace MWGui
while (mSpellsView->getChildCount())
MyGUI::Gui::getInstance().destroyWidget(mSpellsView->getChildAt(0));
mSpellsWidgetMap.clear();
+ mSpellButtons.clear();
}
void SpellBuyingWindow::setPtr(const MWWorld::Ptr& actor)
@@ -130,6 +142,18 @@ namespace MWGui
updateLabels();
+ if (Settings::gui().mControllerMenus)
+ {
+ mControllerFocus = 0;
+ if (mSpellButtons.size() > 0)
+ mSpellButtons[0].first->setStateSelected(true);
+
+ MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager();
+ winMgr->setControllerTooltip(Settings::gui().mControllerTooltips);
+ if (winMgr->getControllerTooltip())
+ MWBase::Environment::get().getInputManager()->warpMouseToWidget(mSpellButtons[0].first);
+ }
+
// Canvas size must be expressed with VScroll disabled, otherwise MyGUI would expand the scroll area when the
// scrollbar is hidden
mSpellsView->setVisibleVScroll(false);
@@ -200,4 +224,60 @@ namespace MWGui
mSpellsView->setViewOffset(
MyGUI::IntPoint(0, static_cast(mSpellsView->getViewOffset().top + _rel * 0.3f)));
}
+
+ bool SpellBuyingWindow::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_A)
+ {
+ if (mControllerFocus >= 0 && mControllerFocus < static_cast(mSpellButtons.size()))
+ onSpellButtonClick(mSpellButtons[mControllerFocus].first);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ {
+ onCancelButtonClicked(mCancelButton);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_RIGHTSTICK)
+ {
+ // Toggle info tooltip
+ MWBase::Environment::get().getWindowManager()->setControllerTooltip(
+ !MWBase::Environment::get().getWindowManager()->getControllerTooltip());
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP)
+ {
+ if (mSpellButtons.size() <= 1)
+ return true;
+
+ mSpellButtons[mControllerFocus].first->setStateSelected(false);
+ mControllerFocus = wrap(mControllerFocus - 1, mSpellButtons.size());
+ mSpellButtons[mControllerFocus].first->setStateSelected(true);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
+ {
+ if (mSpellButtons.size() <= 1)
+ return true;
+
+ mSpellButtons[mControllerFocus].first->setStateSelected(false);
+ mControllerFocus = wrap(mControllerFocus + 1, mSpellButtons.size());
+ mSpellButtons[mControllerFocus].first->setStateSelected(true);
+ }
+
+ if (mControllerFocus >= 0 && mControllerFocus < static_cast(mSpellButtons.size()))
+ {
+ // Scroll the list to keep the active item in view
+ int line = mSpellButtons[mControllerFocus].second;
+ if (line <= 5)
+ mSpellsView->setViewOffset(MyGUI::IntPoint(0, 0));
+ else
+ {
+ const int lineHeight = Settings::gui().mFontSize + 2;
+ mSpellsView->setViewOffset(MyGUI::IntPoint(0, -lineHeight * (line - 5)));
+ }
+
+ // Warp the mouse to the selected spell to show the tooltip
+ if (MWBase::Environment::get().getWindowManager()->getControllerTooltip())
+ MWBase::Environment::get().getInputManager()->warpMouseToWidget(mSpellButtons[mControllerFocus].first);
+ }
+
+ return true;
+ }
}
diff --git a/apps/openmw/mwgui/spellbuyingwindow.hpp b/apps/openmw/mwgui/spellbuyingwindow.hpp
index 257b8a0df9..e67dfde76c 100644
--- a/apps/openmw/mwgui/spellbuyingwindow.hpp
+++ b/apps/openmw/mwgui/spellbuyingwindow.hpp
@@ -39,6 +39,8 @@ namespace MWGui
MyGUI::ScrollView* mSpellsView;
std::map mSpellsWidgetMap;
+ /// List of enabled/purchasable spells and their index in the full list.
+ std::vector> mSpellButtons;
void onCancelButtonClicked(MyGUI::Widget* _sender);
void onSpellButtonClick(MyGUI::Widget* _sender);
@@ -55,6 +57,8 @@ namespace MWGui
private:
static bool sortSpells(const ESM::Spell* left, const ESM::Spell* right);
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
+ int mControllerFocus;
};
}
diff --git a/apps/openmw/mwgui/spellcreationdialog.cpp b/apps/openmw/mwgui/spellcreationdialog.cpp
index d8302df87c..976c2eebd8 100644
--- a/apps/openmw/mwgui/spellcreationdialog.cpp
+++ b/apps/openmw/mwgui/spellcreationdialog.cpp
@@ -7,11 +7,13 @@
#include
#include
+#include
#include
#include
#include "../mwbase/environment.hpp"
+#include "../mwbase/inputmanager.hpp"
#include "../mwbase/mechanicsmanager.hpp"
#include "../mwbase/windowmanager.hpp"
@@ -25,8 +27,8 @@
#include "../mwmechanics/spellutil.hpp"
#include "class.hpp"
+#include "textcolours.hpp"
#include "tooltips.hpp"
-#include "widgets.hpp"
namespace
{
@@ -95,6 +97,13 @@ namespace MWGui
+= MyGUI::newDelegate(this, &EditEffectDialog::onMagnitudeMaxChanged);
mDurationSlider->eventScrollChangePosition += MyGUI::newDelegate(this, &EditEffectDialog::onDurationChanged);
mAreaSlider->eventScrollChangePosition += MyGUI::newDelegate(this, &EditEffectDialog::onAreaChanged);
+
+ if (Settings::gui().mControllerMenus)
+ {
+ mControllerButtons.a = "#{sSelect}";
+ mControllerButtons.b = "#{sCancel}";
+ mControllerButtons.x = "#{sOk}";
+ }
}
void EditEffectDialog::setConstantEffect(bool constant)
@@ -154,6 +163,15 @@ namespace MWGui
mMagnitudeMaxValue->setCaption(to + " 1");
mAreaValue->setCaption("0");
+ if (Settings::gui().mControllerMenus)
+ {
+ mRangeButton->setStateSelected(true);
+ mDeleteButton->setStateSelected(false);
+ mOkButton->setStateSelected(false);
+ mCancelButton->setStateSelected(false);
+ mControllerFocus = 0;
+ }
+
setVisible(true);
}
@@ -187,6 +205,15 @@ namespace MWGui
onDurationChanged(mDurationSlider, effect.mDuration - 1);
eventEffectModified(mEffect);
+ if (Settings::gui().mControllerMenus)
+ {
+ mRangeButton->setStateSelected(true);
+ mDeleteButton->setStateSelected(false);
+ mOkButton->setStateSelected(false);
+ mCancelButton->setStateSelected(false);
+ mControllerFocus = 0;
+ }
+
updateBoxes();
}
@@ -231,6 +258,25 @@ namespace MWGui
mAreaBox->setVisible(true);
// curY += mAreaBox->getSize().height;
}
+
+ if (Settings::gui().mControllerMenus)
+ {
+ mButtons.clear();
+ mButtons.emplace_back(mRangeButton);
+ if (mMagnitudeBox->getVisible())
+ {
+ mButtons.emplace_back(mMagnitudeMinValue);
+ mButtons.emplace_back(mMagnitudeMaxValue);
+ }
+ if (mDurationBox->getVisible())
+ mButtons.emplace_back(mDurationValue);
+ if (mAreaBox->getVisible())
+ mButtons.emplace_back(mAreaValue);
+ if (mDeleteButton->getVisible())
+ mButtons.emplace_back(mDeleteButton);
+ mButtons.emplace_back(mOkButton);
+ mButtons.emplace_back(mCancelButton);
+ }
}
void EditEffectDialog::onRangeButtonClicked(MyGUI::Widget* sender)
@@ -340,6 +386,195 @@ namespace MWGui
eventEffectModified(mEffect);
}
+ bool EditEffectDialog::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ int prevFocus = mControllerFocus;
+ mControllerFocus = std::clamp(mControllerFocus, 0, static_cast(mButtons.size()) - 1);
+ MyGUI::TextBox* button = mButtons[mControllerFocus];
+
+ if (arg.button == SDL_CONTROLLER_BUTTON_A)
+ {
+ if (button == mRangeButton)
+ onRangeButtonClicked(mRangeButton);
+ else if (button == mCancelButton)
+ onCancelButtonClicked(mCancelButton);
+ else if (button == mOkButton)
+ onOkButtonClicked(mOkButton);
+ else if (button == mDeleteButton)
+ onDeleteButtonClicked(mDeleteButton);
+ MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ onCancelButtonClicked(mCancelButton);
+ else if (arg.button == SDL_CONTROLLER_BUTTON_X)
+ {
+ onOkButtonClicked(mOkButton);
+ MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP)
+ {
+ if (mControllerFocus == 0)
+ mControllerFocus = static_cast(mButtons.size()) - 2;
+ else if (button == mCancelButton && mDeleteButton->getVisible())
+ mControllerFocus -= 3;
+ else if (button == mCancelButton || (button == mOkButton && mDeleteButton->getVisible()))
+ mControllerFocus -= 2;
+ else
+ mControllerFocus = std::max(mControllerFocus - 1, 0);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
+ {
+ if (button == mDeleteButton || button == mOkButton || button == mCancelButton)
+ mControllerFocus = 0;
+ else
+ mControllerFocus++;
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_LEFTSHOULDER)
+ {
+ if (button == mMagnitudeMinValue)
+ {
+ mMagnitudeMinSlider->setScrollPosition(0);
+ onMagnitudeMinChanged(nullptr, mMagnitudeMinSlider->getScrollPosition());
+ }
+ else if (button == mMagnitudeMaxValue)
+ {
+ mMagnitudeMaxSlider->setScrollPosition(mMagnitudeMinSlider->getScrollPosition());
+ onMagnitudeMaxChanged(nullptr, mMagnitudeMaxSlider->getScrollPosition());
+ }
+ else if (button == mDurationValue)
+ {
+ mDurationSlider->setScrollPosition(0);
+ onDurationChanged(nullptr, mDurationSlider->getScrollPosition());
+ }
+ else if (button == mAreaValue)
+ {
+ mAreaSlider->setScrollPosition(0);
+ onAreaChanged(nullptr, mAreaSlider->getScrollPosition());
+ }
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER)
+ {
+ if (button == mMagnitudeMinValue)
+ {
+ mMagnitudeMinSlider->setScrollPosition(mMagnitudeMaxSlider->getScrollPosition());
+ onMagnitudeMinChanged(nullptr, mMagnitudeMinSlider->getScrollPosition());
+ }
+ else if (button == mMagnitudeMaxValue)
+ {
+ mMagnitudeMaxSlider->setScrollPosition(mMagnitudeMaxSlider->getScrollRange() - 1);
+ onMagnitudeMaxChanged(nullptr, mMagnitudeMaxSlider->getScrollPosition());
+ }
+ else if (button == mDurationValue)
+ {
+ mDurationSlider->setScrollPosition(mDurationSlider->getScrollRange() - 1);
+ onDurationChanged(nullptr, mDurationSlider->getScrollPosition());
+ }
+ else if (button == mAreaValue)
+ {
+ mAreaSlider->setScrollPosition(mAreaSlider->getScrollRange() - 1);
+ onAreaChanged(nullptr, mAreaSlider->getScrollPosition());
+ }
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT)
+ {
+ if (button == mRangeButton)
+ onRangeButtonClicked(mRangeButton);
+ else if (button == mCancelButton)
+ mControllerFocus--;
+ else if (button == mOkButton && mDeleteButton->getVisible())
+ mControllerFocus--;
+ else if (button == mMagnitudeMinValue)
+ {
+ mMagnitudeMinSlider->setScrollPosition(mMagnitudeMinSlider->getScrollPosition() - 1);
+ onMagnitudeMinChanged(nullptr, mMagnitudeMinSlider->getScrollPosition());
+ }
+ else if (button == mMagnitudeMaxValue)
+ {
+ mMagnitudeMaxSlider->setScrollPosition(
+ std::max(mMagnitudeMaxSlider->getScrollPosition() - 1, mMagnitudeMinSlider->getScrollPosition()));
+ onMagnitudeMaxChanged(nullptr, mMagnitudeMaxSlider->getScrollPosition());
+ }
+ else if (button == mDurationValue)
+ {
+ mDurationSlider->setScrollPosition(mDurationSlider->getScrollPosition() - 1);
+ onDurationChanged(nullptr, mDurationSlider->getScrollPosition());
+ }
+ else if (button == mAreaValue)
+ {
+ mAreaSlider->setScrollPosition(mAreaSlider->getScrollPosition() - 1);
+ onAreaChanged(nullptr, mAreaSlider->getScrollPosition());
+ }
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT)
+ {
+ if (button == mRangeButton)
+ onRangeButtonClicked(mRangeButton);
+ else if (button == mDeleteButton)
+ mControllerFocus++;
+ else if (button == mOkButton)
+ mControllerFocus++;
+ else if (button == mMagnitudeMinValue)
+ {
+ mMagnitudeMinSlider->setScrollPosition(
+ std::min(mMagnitudeMinSlider->getScrollPosition() + 1, mMagnitudeMaxSlider->getScrollPosition()));
+ onMagnitudeMinChanged(nullptr, mMagnitudeMinSlider->getScrollPosition());
+ }
+ else if (button == mMagnitudeMaxValue)
+ {
+ mMagnitudeMaxSlider->setScrollPosition(mMagnitudeMaxSlider->getScrollPosition() + 1);
+ onMagnitudeMaxChanged(nullptr, mMagnitudeMaxSlider->getScrollPosition());
+ }
+ else if (button == mDurationValue)
+ {
+ mDurationSlider->setScrollPosition(mDurationSlider->getScrollPosition() + 1);
+ onDurationChanged(nullptr, mDurationSlider->getScrollPosition());
+ }
+ else if (button == mAreaValue)
+ {
+ mAreaSlider->setScrollPosition(mAreaSlider->getScrollPosition() + 1);
+ onAreaChanged(nullptr, mAreaSlider->getScrollPosition());
+ }
+ }
+
+ if (prevFocus != mControllerFocus)
+ updateControllerFocus(prevFocus, mControllerFocus);
+
+ return true;
+ }
+
+ void EditEffectDialog::updateControllerFocus(int prevFocus, int newFocus)
+ {
+ const TextColours& textColours{ MWBase::Environment::get().getWindowManager()->getTextColours() };
+
+ if (prevFocus >= 0 && prevFocus < static_cast(mButtons.size()))
+ {
+ MyGUI::TextBox* button = mButtons[prevFocus];
+ if (button == mMagnitudeMinValue || button == mMagnitudeMaxValue || button == mDurationValue
+ || button == mAreaValue)
+ {
+ button->setTextColour(textColours.normal);
+ }
+ else
+ {
+ ((MyGUI::Button*)button)->setStateSelected(false);
+ }
+ }
+
+ if (newFocus >= 0 && newFocus < static_cast(mButtons.size()))
+ {
+ MyGUI::TextBox* button = mButtons[newFocus];
+ if (button == mMagnitudeMinValue || button == mMagnitudeMaxValue || button == mDurationValue
+ || button == mAreaValue)
+ {
+ button->setTextColour(textColours.link);
+ }
+ else
+ {
+ ((MyGUI::Button*)button)->setStateSelected(true);
+ }
+ }
+ }
+
// ------------------------------------------------------------------------------------------------
SpellCreationDialog::SpellCreationDialog()
@@ -360,6 +595,14 @@ namespace MWGui
mNameEdit->eventEditSelectAccept += MyGUI::newDelegate(this, &SpellCreationDialog::onAccept);
setWidgets(mAvailableEffectsList, mUsedEffectsView);
+
+ if (Settings::gui().mControllerMenus)
+ {
+ mControllerButtons.a = "#{sSelect}";
+ mControllerButtons.b = "#{sCancel}";
+ mControllerButtons.x = "#{sBuy}";
+ mControllerButtons.r3 = "#{sInfo}";
+ }
}
void SpellCreationDialog::setPtr(const MWWorld::Ptr& actor)
@@ -490,6 +733,22 @@ namespace MWGui
mSuccessChance->setCaption(MyGUI::utility::toString(intChance));
}
+ bool SpellCreationDialog::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ {
+ onCancelButtonClicked(mCancelButton);
+ return true;
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_X)
+ {
+ onBuyButtonClicked(mBuyButton);
+ return true;
+ }
+ else
+ return EffectEditorBase::onControllerButtonEvent(arg);
+ }
+
// ------------------------------------------------------------------------------------------------
EffectEditorBase::EffectEditorBase(Type type)
@@ -561,6 +820,7 @@ namespace MWGui
mAvailableEffectsList->adjustSize();
mAvailableEffectsList->scrollToTop();
+ mAvailableButtons.clear();
for (const short effectId : knownEffects)
{
const std::string& name = MWBase::Environment::get()
@@ -568,13 +828,27 @@ namespace MWGui
->get()
.find(ESM::MagicEffect::indexToGmstString(effectId))
->mValue.getString();
- MyGUI::Widget* w = mAvailableEffectsList->getItemWidget(name);
+ MyGUI::Button* w = mAvailableEffectsList->getItemWidget(name);
+ mAvailableButtons.emplace_back(w);
ToolTips::createMagicEffectToolTip(w, effectId);
}
mEffects.clear();
updateEffectsView();
+
+ if (Settings::gui().mControllerMenus)
+ {
+ mAvailableFocus = 0;
+ mEffectFocus = 0;
+ mRightColumn = false;
+ if (mAvailableButtons.size() > 0)
+ {
+ mAvailableButtons[0]->setStateSelected(true);
+ if (MWBase::Environment::get().getWindowManager()->getControllerTooltip())
+ MWBase::Environment::get().getInputManager()->warpMouseToWidget(mAvailableButtons[0]);
+ }
+ }
}
void EffectEditorBase::setWidgets(Gui::MWList* availableEffectsList, MyGUI::ScrollView* usedEffectsView)
@@ -686,6 +960,7 @@ namespace MWGui
MyGUI::IntSize size(0, 0);
+ mEffectButtons.clear();
int i = 0;
for (const ESM::ENAMstruct& effectInfo : mEffects)
{
@@ -718,6 +993,8 @@ namespace MWGui
size.width = std::max(size.width, effect->getRequestedWidth());
size.height += 24;
++i;
+
+ mEffectButtons.emplace_back(std::pair(effect, button));
}
// Canvas size must be expressed with HScroll disabled, otherwise MyGUI would expand the scroll area when the
@@ -755,4 +1032,100 @@ namespace MWGui
effect.mRange = ESM::RT_Self;
mConstantEffect = constant;
}
+
+ bool EffectEditorBase::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager();
+
+ if (arg.button == SDL_CONTROLLER_BUTTON_A)
+ {
+ if (!mRightColumn && mAvailableFocus >= 0 && mAvailableFocus < static_cast(mAvailableButtons.size()))
+ {
+ onAvailableEffectClicked(mAvailableButtons[mAvailableFocus]);
+ winMgr->playSound(ESM::RefId::stringRefId("Menu Click"));
+ }
+ else if (mRightColumn && mEffectFocus >= 0 && mEffectFocus < static_cast(mEffectButtons.size()))
+ {
+ onEditEffect(mEffectButtons[mEffectFocus].second);
+ winMgr->playSound(ESM::RefId::stringRefId("Menu Click"));
+ }
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_RIGHTSTICK)
+ {
+ // Toggle info tooltip
+ winMgr->setControllerTooltip(!mRightColumn && !winMgr->getControllerTooltip());
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP)
+ {
+ if (mRightColumn && mEffectButtons.size() > 0)
+ {
+ if (mEffectFocus >= 0 && mEffectFocus < static_cast(mEffectButtons.size()))
+ mEffectButtons[mEffectFocus].first->setStateSelected(false);
+ mEffectFocus = wrap(mEffectFocus - 1, mEffectButtons.size());
+ mEffectButtons[mEffectFocus].first->setStateSelected(true);
+ }
+ else if (!mRightColumn && mAvailableButtons.size() > 0)
+ {
+ if (mAvailableFocus >= 0 && mAvailableFocus < static_cast(mAvailableButtons.size()))
+ mAvailableButtons[mAvailableFocus]->setStateSelected(false);
+ mAvailableFocus = wrap(mAvailableFocus - 1, mAvailableButtons.size());
+ mAvailableButtons[mAvailableFocus]->setStateSelected(true);
+ }
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
+ {
+ if (mRightColumn && mEffectButtons.size() > 0)
+ {
+ if (mEffectFocus >= 0 && mEffectFocus < static_cast(mEffectButtons.size()))
+ mEffectButtons[mEffectFocus].first->setStateSelected(false);
+ mEffectFocus = wrap(mEffectFocus + 1, mEffectButtons.size());
+ mEffectButtons[mEffectFocus].first->setStateSelected(true);
+ }
+ else if (!mRightColumn && mAvailableButtons.size() > 0)
+ {
+ if (mAvailableFocus >= 0 && mAvailableFocus < static_cast(mAvailableButtons.size()))
+ mAvailableButtons[mAvailableFocus]->setStateSelected(false);
+ mAvailableFocus = wrap(mAvailableFocus + 1, mAvailableButtons.size());
+ mAvailableButtons[mAvailableFocus]->setStateSelected(true);
+ }
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT && mRightColumn)
+ {
+ mRightColumn = false;
+ if (mEffectFocus >= 0 && mEffectFocus < static_cast(mEffectButtons.size()))
+ mEffectButtons[mEffectFocus].first->setStateSelected(false);
+ if (mAvailableFocus >= 0 && mAvailableFocus < static_cast(mAvailableButtons.size()))
+ mAvailableButtons[mAvailableFocus]->setStateSelected(true);
+
+ winMgr->setControllerTooltip(Settings::gui().mControllerTooltips);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT && !mRightColumn && mEffectButtons.size() > 0)
+ {
+ mRightColumn = true;
+ if (mAvailableFocus >= 0 && mAvailableFocus < static_cast(mAvailableButtons.size()))
+ mAvailableButtons[mAvailableFocus]->setStateSelected(false);
+ if (mEffectFocus >= 0 && mEffectFocus < static_cast(mEffectButtons.size()))
+ mEffectButtons[mEffectFocus].first->setStateSelected(true);
+
+ winMgr->setControllerTooltip(false);
+ }
+
+ // Scroll the list to keep the active item in view
+ if (mAvailableFocus <= 5)
+ mAvailableEffectsList->setViewOffset(0);
+ else
+ {
+ const int lineHeight = Settings::gui().mFontSize + 3;
+ mAvailableEffectsList->setViewOffset(-lineHeight * (mAvailableFocus - 5));
+ }
+
+ if (!mRightColumn && mAvailableFocus >= 0 && mAvailableFocus < static_cast(mAvailableButtons.size()))
+ {
+ // Warp the mouse to the selected spell to show the tooltip
+ if (winMgr->getControllerTooltip())
+ MWBase::Environment::get().getInputManager()->warpMouseToWidget(mAvailableButtons[mAvailableFocus]);
+ }
+
+ return true;
+ }
}
diff --git a/apps/openmw/mwgui/spellcreationdialog.hpp b/apps/openmw/mwgui/spellcreationdialog.hpp
index 6dfe61fc57..2a4f5dcbb3 100644
--- a/apps/openmw/mwgui/spellcreationdialog.hpp
+++ b/apps/openmw/mwgui/spellcreationdialog.hpp
@@ -1,12 +1,15 @@
#ifndef MWGUI_SPELLCREATION_H
#define MWGUI_SPELLCREATION_H
+#include
#include
#include
#include
+#include
#include "referenceinterface.hpp"
+#include "widgets.hpp"
#include "windowbase.hpp"
namespace Gui
@@ -57,10 +60,10 @@ namespace MWGui
MyGUI::TextBox* mDurationValue;
MyGUI::TextBox* mAreaValue;
- MyGUI::ScrollBar* mMagnitudeMinSlider;
- MyGUI::ScrollBar* mMagnitudeMaxSlider;
- MyGUI::ScrollBar* mDurationSlider;
- MyGUI::ScrollBar* mAreaSlider;
+ Gui::ScrollBar* mMagnitudeMinSlider;
+ Gui::ScrollBar* mMagnitudeMaxSlider;
+ Gui::ScrollBar* mDurationSlider;
+ Gui::ScrollBar* mAreaSlider;
MyGUI::TextBox* mAreaText;
@@ -83,13 +86,18 @@ namespace MWGui
void updateBoxes();
- protected:
+ private:
ESM::ENAMstruct mEffect;
ESM::ENAMstruct mOldEffect;
const ESM::MagicEffect* mMagicEffect;
bool mConstantEffect;
+
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
+ void updateControllerFocus(int prevFocus, int newFocus);
+ int mControllerFocus;
+ std::vector mButtons;
};
class EffectEditorBase
@@ -142,8 +150,16 @@ namespace MWGui
virtual void notifyEffectsChanged() {}
+ virtual bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg);
+
private:
Type mType;
+
+ int mAvailableFocus;
+ int mEffectFocus;
+ bool mRightColumn;
+ std::vector mAvailableButtons;
+ std::vector> mEffectButtons;
};
class SpellCreationDialog : public WindowBase, public ReferenceInterface, public EffectEditorBase
@@ -166,6 +182,7 @@ namespace MWGui
void onCancelButtonClicked(MyGUI::Widget* sender);
void onBuyButtonClicked(MyGUI::Widget* sender);
void onAccept(MyGUI::EditBox* sender);
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
void notifyEffectsChanged() override;
diff --git a/apps/openmw/mwgui/spellview.cpp b/apps/openmw/mwgui/spellview.cpp
index 678f6ffe1f..a3eef23092 100644
--- a/apps/openmw/mwgui/spellview.cpp
+++ b/apps/openmw/mwgui/spellview.cpp
@@ -9,6 +9,10 @@
#include
#include
+#include "../mwbase/environment.hpp"
+#include "../mwbase/inputmanager.hpp"
+#include "../mwbase/windowmanager.hpp"
+
#include "tooltips.hpp"
namespace MWGui
@@ -28,6 +32,8 @@ namespace MWGui
: mScrollView(nullptr)
, mShowCostColumn(true)
, mHighlightSelected(true)
+ , mControllerActiveWindow(false)
+ , mControllerFocus(0)
{
}
@@ -88,6 +94,8 @@ namespace MWGui
const int spellHeight = Settings::gui().mFontSize + 2;
mLines.clear();
+ mButtons.clear();
+ mGroupIndices.clear();
while (mScrollView->getChildCount())
MyGUI::Gui::getInstance().destroyWidget(mScrollView->getChildAt(0));
@@ -106,7 +114,9 @@ namespace MWGui
curType = spell.mType;
}
- const std::string skin = spell.mActive ? "SandTextButton" : "SpellTextUnequipped";
+ std::string skin = spell.mActive ? "SandTextButton" : "SpellTextUnequipped";
+ if (Settings::gui().mControllerMenus)
+ skin = spell.mActive ? "SpellTextEquippedController" : "SpellTextUnequippedController";
const std::string captionSuffix = MWGui::ToolTips::getCountString(spell.mCount);
Gui::SharedStateButton* t = mScrollView->createWidget(
@@ -115,6 +125,7 @@ namespace MWGui
t->setCaption(spell.mName + captionSuffix);
t->setTextAlign(MyGUI::Align::Left);
adjustSpellWidget(spell, i, t);
+ mButtons.emplace_back(std::make_pair(t, i));
if (!spell.mCostColumn.empty() && mShowCostColumn)
{
@@ -221,6 +232,12 @@ namespace MWGui
height += lineHeight;
}
+ if (Settings::gui().mControllerMenus)
+ {
+ mControllerFocus = wrap(mControllerFocus, mButtons.size());
+ updateControllerFocus(-1, mControllerFocus);
+ }
+
// Canvas size must be expressed with VScroll disabled, otherwise MyGUI would expand the scroll area when the
// scrollbar is hidden
mScrollView->setVisibleVScroll(false);
@@ -256,6 +273,8 @@ namespace MWGui
}
else
mLines.emplace_back(groupWidget, (MyGUI::Widget*)nullptr, NoSpellIndex);
+
+ mGroupIndices.push_back(mButtons.size());
}
void SpellView::setSize(const MyGUI::IntSize& _value)
@@ -316,4 +335,110 @@ namespace MWGui
{
mScrollView->setViewOffset(MyGUI::IntPoint(0, 0));
}
+
+ void SpellView::setActiveControllerWindow(bool active)
+ {
+ mControllerActiveWindow = active;
+ if (active)
+ update();
+ }
+
+ void SpellView::onControllerButton(const unsigned char button)
+ {
+ if (mButtons.empty())
+ return;
+
+ int prevFocus = mControllerFocus;
+
+ if (button == SDL_CONTROLLER_BUTTON_A)
+ {
+ // Select the focused item, if any.
+ if (mControllerFocus >= 0 && mControllerFocus < static_cast(mButtons.size()))
+ {
+ onSpellSelected(mButtons[mControllerFocus].first);
+ MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
+ }
+ }
+ else if (button == SDL_CONTROLLER_BUTTON_RIGHTSTICK)
+ {
+ // Toggle info tooltip
+ MWBase::Environment::get().getWindowManager()->setControllerTooltip(
+ !MWBase::Environment::get().getWindowManager()->getControllerTooltip());
+ }
+ else if (button == SDL_CONTROLLER_BUTTON_DPAD_UP)
+ mControllerFocus--;
+ else if (button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
+ mControllerFocus++;
+ else if (button == SDL_CONTROLLER_BUTTON_DPAD_LEFT)
+ mControllerFocus = std::max(0, mControllerFocus - 10);
+ else if (button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT)
+ mControllerFocus = std::min(mControllerFocus + 10, static_cast(mButtons.size()) - 1);
+ else if (button == SDL_CONTROLLER_BUTTON_LEFTSHOULDER)
+ {
+ // Jump to first item in previous group
+ int prevGroupIndex = 0;
+ for (int groupIndex : mGroupIndices)
+ {
+ if (groupIndex >= mControllerFocus)
+ break;
+ else
+ prevGroupIndex = groupIndex;
+ }
+ mControllerFocus = prevGroupIndex;
+ }
+ else if (button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER)
+ {
+ // Jump to first item in next group
+ for (int groupIndex : mGroupIndices)
+ {
+ if (groupIndex > mControllerFocus)
+ {
+ mControllerFocus = groupIndex;
+ break;
+ }
+ }
+ }
+
+ mControllerFocus = wrap(mControllerFocus, mButtons.size());
+
+ if (prevFocus != mControllerFocus)
+ updateControllerFocus(prevFocus, mControllerFocus);
+ else
+ updateControllerFocus(-1, mControllerFocus);
+ }
+
+ void SpellView::updateControllerFocus(int prevFocus, int newFocus)
+ {
+ if (mButtons.empty())
+ return;
+
+ if (prevFocus >= 0 && prevFocus < static_cast(mButtons.size()))
+ {
+ Gui::SharedStateButton* prev = mButtons[prevFocus].first;
+ if (prev)
+ prev->onMouseLostFocus(nullptr);
+ }
+
+ if (mControllerActiveWindow && newFocus >= 0 && newFocus < static_cast(mButtons.size()))
+ {
+ Gui::SharedStateButton* focused = mButtons[newFocus].first;
+ if (focused)
+ {
+ focused->onMouseSetFocus(nullptr);
+
+ // Scroll the list to keep the active item in view
+ int line = mButtons[newFocus].second;
+ if (line <= 5)
+ mScrollView->setViewOffset(MyGUI::IntPoint(0, 0));
+ else
+ {
+ const int lineHeight = focused->getHeight();
+ mScrollView->setViewOffset(MyGUI::IntPoint(0, -lineHeight * (line - 5)));
+ }
+
+ if (MWBase::Environment::get().getWindowManager()->getControllerTooltip())
+ MWBase::Environment::get().getInputManager()->warpMouseToWidget(focused);
+ }
+ }
+ }
}
diff --git a/apps/openmw/mwgui/spellview.hpp b/apps/openmw/mwgui/spellview.hpp
index caff43a33e..a2571cd822 100644
--- a/apps/openmw/mwgui/spellview.hpp
+++ b/apps/openmw/mwgui/spellview.hpp
@@ -5,6 +5,9 @@
#include
#include
+#include
+
+#include
#include "spellmodel.hpp"
@@ -54,6 +57,9 @@ namespace MWGui
void resetScrollbars();
+ void setActiveControllerWindow(bool active);
+ void onControllerButton(const unsigned char button);
+
private:
MyGUI::ScrollView* mScrollView;
@@ -89,6 +95,15 @@ namespace MWGui
void addGroup(const std::string& label1, const std::string& label2);
void adjustSpellWidget(const Spell& spell, SpellModel::ModelIndex index, MyGUI::Widget* widget);
+ /// Keep a list of buttons for controller navigation and their index in the full list.
+ std::vector> mButtons;
+ /// Keep a list of group offsets for controller navigation
+ std::vector mGroupIndices;
+
+ bool mControllerActiveWindow;
+ int mControllerFocus;
+ void updateControllerFocus(int prevFocus, int newFocus);
+
void onSpellSelected(MyGUI::Widget* _sender);
void onMouseWheelMoved(MyGUI::Widget* _sender, int _rel);
diff --git a/apps/openmw/mwgui/spellwindow.cpp b/apps/openmw/mwgui/spellwindow.cpp
index 566b7f4ccd..c8d9b2acd9 100644
--- a/apps/openmw/mwgui/spellwindow.cpp
+++ b/apps/openmw/mwgui/spellwindow.cpp
@@ -2,6 +2,8 @@
#include
#include
+#include
+#include
#include
#include
@@ -55,6 +57,14 @@ namespace MWGui
// Adjust the spell filtering widget size because of MyGUI limitations.
int filterWidth = mSpellView->getSize().width - deleteButton->getSize().width - 3;
mFilterEdit->setSize(filterWidth, mFilterEdit->getSize().height);
+
+ if (Settings::gui().mControllerMenus)
+ {
+ setPinButtonVisible(false);
+ mControllerButtons.a = "#{sSelect}";
+ mControllerButtons.b = "#{sBack}";
+ mControllerButtons.r3 = "#{sInfo}";
+ }
}
void SpellWindow::onPinToggled()
@@ -288,4 +298,38 @@ namespace MWGui
onSpellSelected(selectedSpell.mId);
}
}
+
+ bool SpellWindow::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ MWBase::Environment::get().getWindowManager()->exitCurrentGuiMode();
+ else
+ mSpellView->onControllerButton(arg.button);
+
+ return true;
+ }
+
+ void SpellWindow::setActiveControllerWindow(bool active)
+ {
+ if (MWBase::Environment::get().getWindowManager()->getMode() == MWGui::GM_Inventory)
+ {
+ // Fill the screen, or limit to a certain size on large screens. Size chosen to
+ // match the size of the stats window.
+ MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize();
+ int width = std::min(viewSize.width, 600);
+ int height = std::min(viewSize.height - 48 - 48, 750);
+ int x = (viewSize.width - width) / 2;
+ int y = (viewSize.height - height) / 2;
+
+ MyGUI::Window* window = mMainWidget->castType();
+ window->setCoord(x, active ? y : viewSize.height + 1, width, height);
+
+ MWBase::Environment::get().getWindowManager()->setControllerTooltip(
+ active && Settings::gui().mControllerTooltips);
+ }
+
+ mSpellView->setActiveControllerWindow(active);
+
+ WindowBase::setActiveControllerWindow(active);
+ }
}
diff --git a/apps/openmw/mwgui/spellwindow.hpp b/apps/openmw/mwgui/spellwindow.hpp
index e35c5cdc4c..c27ec276a3 100644
--- a/apps/openmw/mwgui/spellwindow.hpp
+++ b/apps/openmw/mwgui/spellwindow.hpp
@@ -41,6 +41,8 @@ namespace MWGui
void onPinToggled() override;
void onTitleDoubleClicked() override;
void onOpen() override;
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
+ void setActiveControllerWindow(bool active) override;
SpellView* mSpellView;
std::unique_ptr mSpellIcons;
diff --git a/apps/openmw/mwgui/statswindow.cpp b/apps/openmw/mwgui/statswindow.cpp
index 69f0b4b449..430101f069 100644
--- a/apps/openmw/mwgui/statswindow.cpp
+++ b/apps/openmw/mwgui/statswindow.cpp
@@ -6,6 +6,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -80,6 +81,14 @@ namespace MWGui
MyGUI::Window* t = mMainWidget->castType();
t->eventWindowChangeCoord += MyGUI::newDelegate(this, &StatsWindow::onWindowResize);
+ if (Settings::gui().mControllerMenus)
+ {
+ setPinButtonVisible(false);
+ mControllerButtons.lStick = "#{sMouse}";
+ mControllerButtons.rStick = "#{sScrolldown}";
+ mControllerButtons.b = "#{sBack}";
+ }
+
onWindowResize(t);
}
@@ -723,4 +732,34 @@ namespace MWGui
else if (!mPinned)
MWBase::Environment::get().getWindowManager()->toggleVisible(GW_Stats);
}
+
+ bool StatsWindow::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ MWBase::Environment::get().getWindowManager()->exitCurrentGuiMode();
+
+ return true;
+ }
+
+ void StatsWindow::setActiveControllerWindow(bool active)
+ {
+ if (MWBase::Environment::get().getWindowManager()->getMode() == MWGui::GM_Inventory)
+ {
+ // Fill the screen, or limit to a certain size on large screens. Size chosen to
+ // show all stats.
+ MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize();
+ int width = std::min(viewSize.width, 600);
+ int height = std::min(viewSize.height - 48 - 48, 750);
+ int x = (viewSize.width - width) / 2;
+ int y = (viewSize.height - height) / 2;
+
+ MyGUI::Window* window = mMainWidget->castType();
+ window->setCoord(x, active ? y : viewSize.height + 1, width, height);
+
+ if (active)
+ onWindowResize(window);
+ }
+
+ WindowBase::setActiveControllerWindow(active);
+ }
}
diff --git a/apps/openmw/mwgui/statswindow.hpp b/apps/openmw/mwgui/statswindow.hpp
index a3fc3157c5..3021873aa8 100644
--- a/apps/openmw/mwgui/statswindow.hpp
+++ b/apps/openmw/mwgui/statswindow.hpp
@@ -47,6 +47,10 @@ namespace MWGui
std::string_view getWindowIdForLua() const override { return "Stats"; }
+ protected:
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
+ void setActiveControllerWindow(bool active) override;
+
private:
void addSkills(const std::vector& skills, const std::string& titleId,
const std::string& titleDefault, MyGUI::IntCoord& coord1, MyGUI::IntCoord& coord2);
diff --git a/apps/openmw/mwgui/textinput.cpp b/apps/openmw/mwgui/textinput.cpp
index 5f47b96f03..7612cf4c67 100644
--- a/apps/openmw/mwgui/textinput.cpp
+++ b/apps/openmw/mwgui/textinput.cpp
@@ -25,6 +25,8 @@ namespace MWGui
// Make sure the edit box has focus
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mTextEdit);
+
+ mControllerButtons.a = "#{sOk}";
}
void TextInputDialog::setNextButtonShow(bool shown)
@@ -83,4 +85,15 @@ namespace MWGui
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/mwgui/textinput.hpp b/apps/openmw/mwgui/textinput.hpp
index c11d40f1a9..ad7896ff27 100644
--- a/apps/openmw/mwgui/textinput.hpp
+++ b/apps/openmw/mwgui/textinput.hpp
@@ -27,6 +27,7 @@ namespace MWGui
protected:
void onOkClicked(MyGUI::Widget* _sender);
void onTextAccepted(MyGUI::EditBox* _sender);
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
private:
MyGUI::EditBox* mTextEdit;
diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp
index 28f0b80010..67c10b980f 100644
--- a/apps/openmw/mwgui/tooltips.cpp
+++ b/apps/openmw/mwgui/tooltips.cpp
@@ -94,7 +94,7 @@ namespace MWGui
if (guiMode)
{
- if (!winMgr->getCursorVisible())
+ if (!winMgr->getCursorVisible() && !winMgr->getControllerTooltip())
return;
const MyGUI::IntPoint& mousePos = MyGUI::InputManager::getInstance().getMousePosition();
diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp
index ba752303d2..c26a7f030a 100644
--- a/apps/openmw/mwgui/tradewindow.cpp
+++ b/apps/openmw/mwgui/tradewindow.cpp
@@ -168,6 +168,25 @@ namespace MWGui
std::numeric_limits::min() + 1); // disallow INT_MIN since abs(INT_MIN) is undefined
setCoord(400, 0, 400, 300);
+
+ if (Settings::gui().mControllerMenus)
+ {
+ // Show L1 and R1 buttons next to tabs
+ MyGUI::Widget* image;
+ getWidget(image, "BtnL1Image");
+ image->setVisible(true);
+ image->setUserString("Hidden", "false");
+
+ getWidget(image, "BtnR1Image");
+ image->setVisible(true);
+ image->setUserString("Hidden", "false");
+
+ mControllerButtons.a = "#{sBuy}";
+ mControllerButtons.b = "#{sCancel}";
+ mControllerButtons.x = "#{sOffer}";
+ mControllerButtons.r3 = "#{sInfo}";
+ mControllerButtons.l2 = "#{sInventory}";
+ }
}
void TradeWindow::setPtr(const MWWorld::Ptr& actor)
@@ -201,6 +220,10 @@ namespace MWGui
onFilterChanged(mFilterAll);
mFilterEdit->setCaption({});
+
+ // Cycle to the buy window if it's not active.
+ if (Settings::gui().mControllerMenus && !mActiveControllerWindow)
+ MWBase::Environment::get().getWindowManager()->cycleActiveControllerWindow(true);
}
void TradeWindow::onFrame(float dt)
@@ -339,6 +362,13 @@ namespace MWGui
}
}
+ void TradeWindow::onOfferSubmitted(MyGUI::Widget* _sender, int offerAmount)
+ {
+ mCurrentBalance = mCurrentBalance < 0 ? -offerAmount : offerAmount;
+ updateLabels();
+ onOfferButtonClicked(mOfferButton);
+ }
+
void TradeWindow::onOfferButtonClicked(MyGUI::Widget* _sender)
{
TradeItemModel* playerItemModel
@@ -643,4 +673,89 @@ namespace MWGui
if (mTradeModel && mTradeModel->usesContainer(ptr))
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Barter);
}
+
+ bool TradeWindow::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_A)
+ {
+ int index = mItemView->getControllerFocus();
+ if (index >= 0 && index < mItemView->getItemCount())
+ onItemSelected(index);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ {
+ onCancelButtonClicked(mCancelButton);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_X)
+ {
+ if (mCurrentBalance == 0)
+ return true;
+ // Show a count dialog to allow for bartering.
+ CountDialog* dialog = MWBase::Environment::get().getWindowManager()->getCountDialog();
+ if (mCurrentBalance < 0)
+ {
+ // Buying from the merchant
+ dialog->openCountDialog("#{sTotalcost}:", "#{sOffer}", -mCurrentMerchantOffer);
+ dialog->setCount(-mCurrentBalance);
+ }
+ else
+ {
+ // Selling to the merchant
+ dialog->openCountDialog("#{sTotalsold}:", "#{sOffer}", getMerchantGold());
+ dialog->setCount(mCurrentBalance);
+ }
+ dialog->eventOkClicked.clear();
+ dialog->eventOkClicked += MyGUI::newDelegate(this, &TradeWindow::onOfferSubmitted);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_LEFTSHOULDER)
+ {
+ if (mFilterAll->getStateSelected())
+ onFilterChanged(mFilterMisc);
+ else if (mFilterWeapon->getStateSelected())
+ onFilterChanged(mFilterAll);
+ else if (mFilterApparel->getStateSelected())
+ onFilterChanged(mFilterWeapon);
+ else if (mFilterMagic->getStateSelected())
+ onFilterChanged(mFilterApparel);
+ else if (mFilterMisc->getStateSelected())
+ onFilterChanged(mFilterMagic);
+ MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER)
+ {
+ if (mFilterAll->getStateSelected())
+ onFilterChanged(mFilterWeapon);
+ else if (mFilterWeapon->getStateSelected())
+ onFilterChanged(mFilterApparel);
+ else if (mFilterApparel->getStateSelected())
+ onFilterChanged(mFilterMagic);
+ else if (mFilterMagic->getStateSelected())
+ onFilterChanged(mFilterMisc);
+ else if (mFilterMisc->getStateSelected())
+ onFilterChanged(mFilterAll);
+ MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_RIGHTSTICK || arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP
+ || arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN || arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT
+ || arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT)
+ {
+ mItemView->onControllerButton(arg.button);
+ }
+
+ return true;
+ }
+
+ void TradeWindow::setActiveControllerWindow(bool active)
+ {
+ // Show L1 and R1 buttons next to tabs
+ MyGUI::Widget* image;
+ getWidget(image, "BtnL1Image");
+ image->setVisible(active);
+
+ getWidget(image, "BtnR1Image");
+ image->setVisible(active);
+
+ mItemView->setActiveControllerWindow(active);
+ WindowBase::setActiveControllerWindow(active);
+ }
}
diff --git a/apps/openmw/mwgui/tradewindow.hpp b/apps/openmw/mwgui/tradewindow.hpp
index 33c39cb269..afd271ed2f 100644
--- a/apps/openmw/mwgui/tradewindow.hpp
+++ b/apps/openmw/mwgui/tradewindow.hpp
@@ -47,6 +47,9 @@ namespace MWGui
std::string_view getWindowIdForLua() const override { return "Trade"; }
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
+ void setActiveControllerWindow(bool active) override;
+
private:
ItemView* mItemView;
SortFilterItemModel* mSortModel;
@@ -102,6 +105,7 @@ namespace MWGui
void onBalanceButtonReleased(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id);
void onBalanceValueChanged(int value);
void onRepeatClick(MyGUI::Widget* widget, MyGUI::ControllerItem* controller);
+ void onOfferSubmitted(MyGUI::Widget* _sender, int offerAmount);
void addRepeatController(MyGUI::Widget* widget);
diff --git a/apps/openmw/mwgui/trainingwindow.cpp b/apps/openmw/mwgui/trainingwindow.cpp
index 890aa0ba68..5b4d355e61 100644
--- a/apps/openmw/mwgui/trainingwindow.cpp
+++ b/apps/openmw/mwgui/trainingwindow.cpp
@@ -37,6 +37,13 @@ namespace MWGui
mTimeAdvancer.eventProgressChanged += MyGUI::newDelegate(this, &TrainingWindow::onTrainingProgressChanged);
mTimeAdvancer.eventFinished += MyGUI::newDelegate(this, &TrainingWindow::onTrainingFinished);
+
+ if (Settings::gui().mControllerMenus)
+ {
+ mDisableGamepadCursor = true;
+ mControllerButtons.a = "#{sBuy}";
+ mControllerButtons.b = "#{sCancel}";
+ }
}
void TrainingWindow::onOpen()
@@ -105,6 +112,7 @@ namespace MWGui
const int lineHeight = Settings::gui().mFontSize + 2;
+ mTrainingButtons.clear();
for (size_t i = 0; i < skills.size(); ++i)
{
const ESM::Skill* skill = skills[i].first;
@@ -128,6 +136,16 @@ namespace MWGui
button->setSize(button->getTextSize().width + 12, button->getSize().height);
ToolTips::createSkillToolTip(button, skill->mId);
+
+ if (price <= playerGold)
+ mTrainingButtons.emplace_back(button);
+ }
+
+ if (Settings::gui().mControllerMenus)
+ {
+ mControllerFocus = 0;
+ if (mTrainingButtons.size() > 0)
+ mTrainingButtons[0]->setStateSelected(true);
}
center();
@@ -229,4 +247,36 @@ namespace MWGui
return !mTimeAdvancer.isRunning();
}
+ bool TrainingWindow::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_A)
+ {
+ if (mControllerFocus >= 0 && mControllerFocus < static_cast(mTrainingButtons.size()))
+ onTrainingSelected(mTrainingButtons[mControllerFocus]);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ {
+ onCancelButtonClicked(mCancelButton);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP)
+ {
+ if (mTrainingButtons.size() <= 1)
+ return true;
+
+ setControllerFocus(mTrainingButtons, mControllerFocus, false);
+ mControllerFocus = wrap(mControllerFocus - 1, mTrainingButtons.size());
+ setControllerFocus(mTrainingButtons, mControllerFocus, true);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
+ {
+ if (mTrainingButtons.size() <= 1)
+ return true;
+
+ setControllerFocus(mTrainingButtons, mControllerFocus, false);
+ mControllerFocus = wrap(mControllerFocus + 1, mTrainingButtons.size());
+ setControllerFocus(mTrainingButtons, mControllerFocus, true);
+ }
+
+ return true;
+ }
}
diff --git a/apps/openmw/mwgui/trainingwindow.hpp b/apps/openmw/mwgui/trainingwindow.hpp
index ee13f24b23..4f866f820e 100644
--- a/apps/openmw/mwgui/trainingwindow.hpp
+++ b/apps/openmw/mwgui/trainingwindow.hpp
@@ -49,9 +49,13 @@ namespace MWGui
MyGUI::Widget* mTrainingOptions;
MyGUI::Button* mCancelButton;
MyGUI::TextBox* mPlayerGold;
+ std::vector mTrainingButtons;
WaitDialogProgressBar mProgressBar;
TimeAdvancer mTimeAdvancer;
+
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
+ int mControllerFocus;
};
}
diff --git a/apps/openmw/mwgui/travelwindow.cpp b/apps/openmw/mwgui/travelwindow.cpp
index e001cf9b43..726e623eb3 100644
--- a/apps/openmw/mwgui/travelwindow.cpp
+++ b/apps/openmw/mwgui/travelwindow.cpp
@@ -37,6 +37,13 @@ namespace MWGui
getWidget(mDestinationsView, "DestinationsView");
mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &TravelWindow::onCancelButtonClicked);
+
+ if (Settings::gui().mControllerMenus)
+ {
+ mDisableGamepadCursor = true;
+ mControllerButtons.a = "#{sTravel}";
+ mControllerButtons.b = "#{sCancel}";
+ }
}
void TravelWindow::addDestination(const ESM::RefId& name, const ESM::Position& pos, bool interior)
@@ -94,6 +101,8 @@ namespace MWGui
toAdd->setUserString("Destination", nameString);
toAdd->setUserData(pos);
toAdd->eventMouseButtonClick += MyGUI::newDelegate(this, &TravelWindow::onTravelButtonClick);
+ if (price <= playerGold)
+ mDestinationButtons.emplace_back(toAdd);
}
void TravelWindow::clearDestinations()
@@ -102,6 +111,7 @@ namespace MWGui
mCurrentY = 0;
while (mDestinationsView->getChildCount())
MyGUI::Gui::getInstance().destroyWidget(mDestinationsView->getChildAt(0));
+ mDestinationButtons.clear();
}
void TravelWindow::setPtr(const MWWorld::Ptr& actor)
@@ -146,6 +156,14 @@ namespace MWGui
}
updateLabels();
+
+ if (Settings::gui().mControllerMenus)
+ {
+ mControllerFocus = 0;
+ if (mDestinationButtons.size() > 0)
+ mDestinationButtons[0]->setStateSelected(true);
+ }
+
// Canvas size must be expressed with VScroll disabled, otherwise MyGUI would expand the scroll area when the
// scrollbar is hidden
mDestinationsView->setVisibleVScroll(false);
@@ -240,4 +258,49 @@ namespace MWGui
mDestinationsView->setViewOffset(
MyGUI::IntPoint(0, static_cast(mDestinationsView->getViewOffset().top + _rel * 0.3f)));
}
+
+ bool TravelWindow::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_A)
+ {
+ if (mControllerFocus >= 0 && mControllerFocus < static_cast(mDestinationButtons.size()))
+ {
+ onTravelButtonClick(mDestinationButtons[mControllerFocus]);
+ MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
+ }
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ {
+ onCancelButtonClicked(mCancelButton);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP)
+ {
+ if (mDestinationButtons.size() <= 1)
+ return true;
+
+ setControllerFocus(mDestinationButtons, mControllerFocus, false);
+ mControllerFocus = wrap(mControllerFocus - 1, mDestinationButtons.size());
+ setControllerFocus(mDestinationButtons, mControllerFocus, true);
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
+ {
+ if (mDestinationButtons.size() <= 1)
+ return true;
+
+ setControllerFocus(mDestinationButtons, mControllerFocus, false);
+ mControllerFocus = wrap(mControllerFocus + 1, mDestinationButtons.size());
+ setControllerFocus(mDestinationButtons, mControllerFocus, true);
+ }
+
+ // Scroll the list to keep the active item in view
+ if (mControllerFocus <= 5)
+ mDestinationsView->setViewOffset(MyGUI::IntPoint(0, 0));
+ else
+ {
+ const int lineHeight = Settings::gui().mFontSize + 2;
+ mDestinationsView->setViewOffset(MyGUI::IntPoint(0, -lineHeight * (mControllerFocus - 5)));
+ }
+
+ return true;
+ }
}
diff --git a/apps/openmw/mwgui/travelwindow.hpp b/apps/openmw/mwgui/travelwindow.hpp
index 630e27518a..79f5f9abc8 100644
--- a/apps/openmw/mwgui/travelwindow.hpp
+++ b/apps/openmw/mwgui/travelwindow.hpp
@@ -25,6 +25,8 @@ namespace MWGui
MyGUI::Button* mCancelButton;
MyGUI::TextBox* mPlayerGold;
+ std::vector mDestinationButtons;
+
MyGUI::ScrollView* mDestinationsView;
void onCancelButtonClicked(MyGUI::Widget* _sender);
@@ -37,6 +39,10 @@ namespace MWGui
void updateLabels();
void onReferenceUnavailable() override;
+
+ private:
+ bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
+ int mControllerFocus;
};
}
diff --git a/apps/openmw/mwgui/waitdialog.cpp b/apps/openmw/mwgui/waitdialog.cpp
index 222a34e53b..f33695a982 100644
--- a/apps/openmw/mwgui/waitdialog.cpp
+++ b/apps/openmw/mwgui/waitdialog.cpp
@@ -80,6 +80,9 @@ namespace MWGui
mTimeAdvancer.eventProgressChanged += MyGUI::newDelegate(this, &WaitDialog::onWaitingProgressChanged);
mTimeAdvancer.eventInterrupted += MyGUI::newDelegate(this, &WaitDialog::onWaitingInterrupted);
mTimeAdvancer.eventFinished += MyGUI::newDelegate(this, &WaitDialog::onWaitingFinished);
+
+ mControllerButtons.b = "#{sCancel}";
+ mDisableGamepadCursor = Settings::gui().mControllerMenus;
}
void WaitDialog::setPtr(const MWWorld::Ptr& ptr)
@@ -326,6 +329,45 @@ namespace MWGui
}
}
+ ControllerButtonStr* WaitDialog::getControllerButtons()
+ {
+ mControllerButtons.a = mSleeping ? "#{sRest}" : "#{sWait}";
+ mControllerButtons.x = mSleeping && mUntilHealedButton->getVisible() ? "#{sUntilHealed}" : "";
+ return &mControllerButtons;
+ }
+
+ bool WaitDialog::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
+ {
+ if (arg.button == SDL_CONTROLLER_BUTTON_A)
+ {
+ onWaitButtonClicked(mWaitButton);
+ MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_B)
+ onCancelButtonClicked(mCancelButton);
+ else if (arg.button == SDL_CONTROLLER_BUTTON_X && mUntilHealedButton->getVisible())
+ {
+ onUntilHealedButtonClicked(mUntilHealedButton);
+ MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
+ }
+ 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);
+ else if (arg.button == SDL_CONTROLLER_BUTTON_LEFTSHOULDER)
+ {
+ mHourSlider->setScrollPosition(0);
+ onHourSliderChangedPosition(mHourSlider, mHourSlider->getScrollPosition());
+ }
+ else if (arg.button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER)
+ {
+ mHourSlider->setScrollPosition(mHourSlider->getScrollRange() - 1);
+ onHourSliderChangedPosition(mHourSlider, mHourSlider->getScrollPosition());
+ }
+
+ return true;
+ }
+
void WaitDialog::stopWaiting()
{
MWBase::Environment::get().getWindowManager()->fadeScreenIn(0.2f);
diff --git a/apps/openmw/mwgui/waitdialog.hpp b/apps/openmw/mwgui/waitdialog.hpp
index 3d66584f54..4a7ccfcd00 100644
--- a/apps/openmw/mwgui/waitdialog.hpp
+++ b/apps/openmw/mwgui/waitdialog.hpp
@@ -4,6 +4,7 @@
#include "timeadvancer.hpp"
#include "windowbase.hpp"
#include
+#include
namespace MWGui
{
@@ -36,6 +37,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();
@@ -45,6 +47,8 @@ namespace MWGui
std::string_view getWindowIdForLua() const override { return "WaitDialog"; }
+ ControllerButtonStr* getControllerButtons() override;
+
protected:
MyGUI::TextBox* mDateTimeText;
MyGUI::TextBox* mRestText;
@@ -52,7 +56,7 @@ namespace MWGui
MyGUI::Button* mUntilHealedButton;
MyGUI::Button* mWaitButton;
MyGUI::Button* mCancelButton;
- MyGUI::ScrollBar* mHourSlider;
+ Gui::ScrollBar* mHourSlider;
TimeAdvancer mTimeAdvancer;
bool mSleeping;
diff --git a/apps/openmw/mwgui/widgets.cpp b/apps/openmw/mwgui/widgets.cpp
index 6cc5bdfdf5..8995f04b92 100644
--- a/apps/openmw/mwgui/widgets.cpp
+++ b/apps/openmw/mwgui/widgets.cpp
@@ -14,6 +14,8 @@
#include
#include
+#include "textcolours.hpp"
+
#include "../mwbase/environment.hpp"
#include "../mwbase/windowmanager.hpp"
@@ -66,6 +68,12 @@ namespace MWGui::Widgets
}
}
+ void MWSkill::setStateSelected(bool selected)
+ {
+ const TextColours& textColours{ MWBase::Environment::get().getWindowManager()->getTextColours() };
+ mSkillNameWidget->setTextColour(selected ? textColours.link : textColours.normal);
+ }
+
void MWSkill::onClicked(MyGUI::Widget* _sender)
{
eventClicked(this);
@@ -150,6 +158,12 @@ namespace MWGui::Widgets
}
}
+ void MWAttribute::setStateSelected(bool selected)
+ {
+ const TextColours& textColours{ MWBase::Environment::get().getWindowManager()->getTextColours() };
+ mAttributeNameWidget->setTextColour(selected ? textColours.link : textColours.normal);
+ }
+
void MWAttribute::initialiseOverride()
{
Base::initialiseOverride();
@@ -231,6 +245,12 @@ namespace MWGui::Widgets
}
}
+ void MWSpell::setStateSelected(bool selected)
+ {
+ const TextColours& textColours{ MWBase::Environment::get().getWindowManager()->getTextColours() };
+ mSpellNameWidget->setTextColour(selected ? textColours.link : textColours.normal);
+ }
+
void MWSpell::initialiseOverride()
{
Base::initialiseOverride();
@@ -461,6 +481,12 @@ namespace MWGui::Widgets
MWSpellEffect::~MWSpellEffect() {}
+ void MWSpellEffect::setStateSelected(bool selected)
+ {
+ const TextColours& textColours{ MWBase::Environment::get().getWindowManager()->getTextColours() };
+ mTextWidget->setTextColour(selected ? textColours.link : textColours.normal);
+ }
+
void MWSpellEffect::initialiseOverride()
{
Base::initialiseOverride();
diff --git a/apps/openmw/mwgui/widgets.hpp b/apps/openmw/mwgui/widgets.hpp
index d562e4e07f..c51846d9df 100644
--- a/apps/openmw/mwgui/widgets.hpp
+++ b/apps/openmw/mwgui/widgets.hpp
@@ -110,6 +110,8 @@ namespace MWGui
*/
EventHandle_SkillVoid eventClicked;
+ void setStateSelected(bool selected);
+
protected:
virtual ~MWSkill();
@@ -149,6 +151,8 @@ namespace MWGui
*/
EventHandle_AttributeVoid eventClicked;
+ void setStateSelected(bool selected);
+
protected:
~MWAttribute() override = default;
@@ -191,6 +195,8 @@ namespace MWGui
const ESM::RefId& getSpellId() const { return mId; }
+ void setStateSelected(bool selected);
+
protected:
virtual ~MWSpell();
@@ -256,6 +262,8 @@ namespace MWGui
int getRequestedWidth() const { return mRequestedWidth; }
+ void setStateSelected(bool selected);
+
protected:
virtual ~MWSpellEffect();
diff --git a/apps/openmw/mwgui/windowbase.cpp b/apps/openmw/mwgui/windowbase.cpp
index f5d90590f8..b607ec50b2 100644
--- a/apps/openmw/mwgui/windowbase.cpp
+++ b/apps/openmw/mwgui/windowbase.cpp
@@ -7,6 +7,7 @@
#include "../mwbase/environment.hpp"
#include "../mwbase/windowmanager.hpp"
+#include