From c7b8787c323701253175d86819a0a12f08f6ab42 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 13 Aug 2012 02:55:22 +0200 Subject: [PATCH] "reset to defaults" button, invert y axis button --- apps/openmw/mwbase/inputmanager.hpp | 1 + apps/openmw/mwgui/settingswindow.cpp | 38 +++++++++++++++++++++-- apps/openmw/mwgui/settingswindow.hpp | 5 +++ apps/openmw/mwinput/inputmanagerimp.cpp | 37 +++++++++++++++++----- apps/openmw/mwinput/inputmanagerimp.hpp | 5 ++- files/mygui/openmw_settings_window.layout | 9 +++++- files/settings-default.cfg | 5 +++ 7 files changed, 88 insertions(+), 12 deletions(-) diff --git a/apps/openmw/mwbase/inputmanager.hpp b/apps/openmw/mwbase/inputmanager.hpp index bf1d8e45f..4c73c72b9 100644 --- a/apps/openmw/mwbase/inputmanager.hpp +++ b/apps/openmw/mwbase/inputmanager.hpp @@ -37,6 +37,7 @@ namespace MWBase virtual std::vector getActionSorting () = 0; virtual int getNumActions() = 0; virtual void enableDetectingBindingMode (int action) = 0; + virtual void resetToDefaultBindings() = 0; }; } diff --git a/apps/openmw/mwgui/settingswindow.cpp b/apps/openmw/mwgui/settingswindow.cpp index 477ffe0e2..5bcec9f70 100644 --- a/apps/openmw/mwgui/settingswindow.cpp +++ b/apps/openmw/mwgui/settingswindow.cpp @@ -116,7 +116,10 @@ namespace MWGui getWidget(mShadowsDebug, "ShadowsDebug"); getWidget(mUnderwaterButton, "UnderwaterButton"); getWidget(mControlsBox, "ControlsBox"); + getWidget(mResetControlsButton, "ResetControlsButton"); + getWidget(mInvertYButton, "InvertYButton"); + mInvertYButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onButtonToggled); mOkButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onOkButtonClicked); mUnderwaterButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onButtonToggled); mShadersButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onShadersToggled); @@ -155,6 +158,9 @@ namespace MWGui mOkButton->setCoord(mMainWidget->getWidth()-16-okSize, mOkButton->getTop(), okSize, mOkButton->getHeight()); + mResetControlsButton->setSize (mResetControlsButton->getTextSize ().width + 24, mResetControlsButton->getHeight()); + mResetControlsButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onResetDefaultBindings); + // fill resolution list Ogre::RenderSystem* rs = Ogre::Root::getSingleton().getRenderSystem(); Ogre::StringVector videoModes = rs->getConfigOptions()["Video Mode"].possibleValues; @@ -220,6 +226,8 @@ namespace MWGui mMiscShadows->setCaptionWithReplacing(Settings::Manager::getBool("misc shadows", "Shadows") ? "#{sOn}" : "#{sOff}"); mShadowsDebug->setCaptionWithReplacing(Settings::Manager::getBool("debug", "Shadows") ? "#{sOn}" : "#{sOff}"); + mInvertYButton->setCaptionWithReplacing(Settings::Manager::getBool("invert y axis", "Input") ? "#{sOn}" : "#{sOff}"); + std::string shaders; if (!Settings::Manager::getBool("shaders", "Objects")) shaders = "off"; @@ -383,6 +391,8 @@ namespace MWGui Settings::Manager::setBool("misc shadows", "Shadows", newState); else if (_sender == mShadowsDebug) Settings::Manager::setBool("debug", "Shadows", newState); + else if (_sender == mInvertYButton) + Settings::Manager::setBool("invert y axis", "Input", newState); apply(); } @@ -521,8 +531,8 @@ namespace MWGui std::vector actions = MWBase::Environment::get().getInputManager()->getActionSorting (); const int h = 18; - const int w = mControlsBox->getWidth() - 34; - int curH = 6; + const int w = mControlsBox->getWidth() - 28; + int curH = 0; for (std::vector::const_iterator it = actions.begin(); it != actions.end(); ++it) { std::string desc = MWBase::Environment::get().getInputManager()->getActionDescription (*it); @@ -539,6 +549,7 @@ namespace MWGui rightText->setTextAlign (MyGUI::Align::Right); rightText->setUserData(*it); // save the action id for callbacks rightText->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onRebindAction); + rightText->eventMouseWheel += MyGUI::newDelegate(this, &SettingsWindow::onInputTabMouseWheel); curH += h; } @@ -558,6 +569,29 @@ namespace MWGui } + void SettingsWindow::onInputTabMouseWheel(MyGUI::Widget* _sender, int _rel) + { + if (mControlsBox->getViewOffset().top + _rel*0.3 > 0) + mControlsBox->setViewOffset(MyGUI::IntPoint(0, 0)); + else + mControlsBox->setViewOffset(MyGUI::IntPoint(0, mControlsBox->getViewOffset().top + _rel*0.3)); + } + + void SettingsWindow::onResetDefaultBindings(MyGUI::Widget* _sender) + { + ConfirmationDialog* dialog = mWindowManager.getConfirmationDialog(); + dialog->open("#{sNotifyMessage66}"); + dialog->eventOkClicked.clear(); + dialog->eventOkClicked += MyGUI::newDelegate(this, &SettingsWindow::onResetDefaultBindingsAccept); + dialog->eventCancelClicked.clear(); + } + + void SettingsWindow::onResetDefaultBindingsAccept() + { + MWBase::Environment::get().getInputManager ()->resetToDefaultBindings (); + updateControlsBox (); + } + void SettingsWindow::open() { updateControlsBox (); diff --git a/apps/openmw/mwgui/settingswindow.hpp b/apps/openmw/mwgui/settingswindow.hpp index 61614da01..aad37826e 100644 --- a/apps/openmw/mwgui/settingswindow.hpp +++ b/apps/openmw/mwgui/settingswindow.hpp @@ -66,6 +66,8 @@ namespace MWGui // controls MyGUI::ScrollView* mControlsBox; + MyGUI::Button* mResetControlsButton; + MyGUI::Button* mInvertYButton; void onOkButtonClicked(MyGUI::Widget* _sender); void onFpsToggled(MyGUI::Widget* _sender); @@ -80,6 +82,9 @@ namespace MWGui void onShadowTextureSize(MyGUI::Widget* _sender); void onRebindAction(MyGUI::Widget* _sender); + void onInputTabMouseWheel(MyGUI::Widget* _sender, int _rel); + void onResetDefaultBindings(MyGUI::Widget* _sender); + void onResetDefaultBindingsAccept (); void apply(); }; diff --git a/apps/openmw/mwinput/inputmanagerimp.cpp b/apps/openmw/mwinput/inputmanagerimp.cpp index 09ed50944..9f757c686 100644 --- a/apps/openmw/mwinput/inputmanagerimp.cpp +++ b/apps/openmw/mwinput/inputmanagerimp.cpp @@ -40,6 +40,7 @@ namespace MWInput , mUserFile(userFile) , mDragDrop(false) , mGuiCursorEnabled(false) + , mInvertY (Settings::Manager::getBool("invert y axis", "Input")) { Ogre::RenderWindow* window = ogre.getWindow (); size_t windowHnd; @@ -280,6 +281,9 @@ namespace MWInput { if (it->first == "Video" && (it->second == "resolution x" || it->second == "resolution y")) changeRes = true; + + if (it->first == "Input" && it->second == "invert y axis") + mInvertY = Settings::Manager::getBool("invert y axis", "Input"); } if (changeRes) @@ -374,7 +378,7 @@ namespace MWInput if (mMouseLookEnabled) { float x = arg.state.X.rel * 0.2; - float y = arg.state.Y.rel * 0.2; + float y = arg.state.Y.rel * 0.2 * (mInvertY ? -1 : 1); MWBase::World *world = MWBase::Environment::get().getWorld(); world->rotateObject(world->getPlayer().getPlayer(), -y, 0.f, x, true); @@ -504,7 +508,7 @@ namespace MWInput return mInputCtrl->getChannel (id)->getValue () == 1; } - void InputManager::loadKeyDefaults () + void InputManager::loadKeyDefaults (bool force) { // using hardcoded key defaults is inevitable, if we want the configuration files to stay valid // across different versions of OpenMW (in the case where another input action is added) @@ -530,16 +534,27 @@ namespace MWInput for (int i = 0; i < A_Last; ++i) { - if (mInputCtrl->getChannel(i)->getControlsCount () == 0) + ICS::Control* control; + bool controlExists = mInputCtrl->getChannel(i)->getControlsCount () != 0; + if (!controlExists) + { + control = new ICS::Control(boost::lexical_cast(i), false, true, 0, ICS::ICS_MAX, ICS::ICS_MAX); + mInputCtrl->addControl(control); + control->attachChannel(mInputCtrl->getChannel(i), ICS::Channel::DIRECT); + } + else + { + control = mInputCtrl->getChannel(i)->getAttachedControls ().front().control; + } + + if (!controlExists || force) { - ICS::Control* control1 = new ICS::Control(boost::lexical_cast(i), false, true, 0, ICS::ICS_MAX, ICS::ICS_MAX); - mInputCtrl->addControl(control1); - control1->attachChannel(mInputCtrl->getChannel(i), ICS::Channel::DIRECT); + clearAllBindings (control); if (defaultKeyBindings.find(i) != defaultKeyBindings.end()) - mInputCtrl->addKeyBinding(control1, static_cast(defaultKeyBindings[i]), ICS::Control::INCREASE); + mInputCtrl->addKeyBinding(control, static_cast(defaultKeyBindings[i]), ICS::Control::INCREASE); else if (defaultMouseButtonBindings.find(i) != defaultMouseButtonBindings.end()) - mInputCtrl->addMouseButtonBinding (control1, defaultMouseButtonBindings[i], ICS::Control::INCREASE); + mInputCtrl->addMouseButtonBinding (control, defaultMouseButtonBindings[i], ICS::Control::INCREASE); } } } @@ -597,6 +612,7 @@ namespace MWInput ret.push_back(A_Crouch); ret.push_back(A_Activate); ret.push_back(A_ToggleWeapon); + ret.push_back(A_ToggleSpell); ret.push_back(A_AutoMove); ret.push_back(A_Jump); ret.push_back(A_Inventory); @@ -681,4 +697,9 @@ namespace MWInput /// \todo add joysticks here once they are added } + void InputManager::resetToDefaultBindings() + { + loadKeyDefaults(true); + } + } diff --git a/apps/openmw/mwinput/inputmanagerimp.hpp b/apps/openmw/mwinput/inputmanagerimp.hpp index d3d4d1385..42c90a73a 100644 --- a/apps/openmw/mwinput/inputmanagerimp.hpp +++ b/apps/openmw/mwinput/inputmanagerimp.hpp @@ -81,6 +81,7 @@ namespace MWInput virtual int getNumActions() { return A_Last; } virtual std::vector getActionSorting (); virtual void enableDetectingBindingMode (int action); + virtual void resetToDefaultBindings(); public: @@ -132,6 +133,8 @@ namespace MWInput bool mDragDrop; + bool mInvertY; + bool mMouseLookEnabled; bool mGuiCursorEnabled; @@ -159,7 +162,7 @@ namespace MWInput bool actionIsActive (int id); - void loadKeyDefaults(); + void loadKeyDefaults(bool force = false); private: enum Actions diff --git a/files/mygui/openmw_settings_window.layout b/files/mygui/openmw_settings_window.layout index ee4855f38..5908c16f9 100644 --- a/files/mygui/openmw_settings_window.layout +++ b/files/mygui/openmw_settings_window.layout @@ -84,9 +84,16 @@ - + + + + + + + + diff --git a/files/settings-default.cfg b/files/settings-default.cfg index a723e307c..fd0c6e7af 100644 --- a/files/settings-default.cfg +++ b/files/settings-default.cfg @@ -144,3 +144,8 @@ sfx volume = 1.0 music volume = 0.4 footsteps volume = 0.6 voice volume = 1.0 + + +[Input] + +invert y axis = false