1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-28 23:09:46 +00:00

Merge branch 'input_bindings' into 'master'

Fix input bindings handling (#8115)

Closes #8115

See merge request OpenMW/openmw!4332
This commit is contained in:
psi29a 2024-09-05 14:52:54 +00:00
commit 46cbee2f21
3 changed files with 23 additions and 32 deletions

View file

@ -1,5 +1,7 @@
#include "bindingsmanager.hpp" #include "bindingsmanager.hpp"
#include <filesystem>
#include <MyGUI_EditBox.h> #include <MyGUI_EditBox.h>
#include <extern/oics/ICSChannelListener.h> #include <extern/oics/ICSChannelListener.h>
@ -77,12 +79,7 @@ namespace MWInput
// Disallow binding escape key // Disallow binding escape key
if (key == SDL_SCANCODE_ESCAPE) if (key == SDL_SCANCODE_ESCAPE)
{ {
// Unbind if esc pressed // Stop binding if esc pressed
if (mDetectingKeyboard)
clearAllKeyBindings(mInputBinder, control);
else
clearAllControllerBindings(mInputBinder, control);
control->setInitialValue(0.0f);
mInputBinder->cancelDetectingBindingState(); mInputBinder->cancelDetectingBindingState();
MWBase::Environment::get().getWindowManager()->notifyInputActionBound(); MWBase::Environment::get().getWindowManager()->notifyInputActionBound();
return; return;
@ -159,13 +156,6 @@ namespace MWInput
return; return;
clearAllControllerBindings(mInputBinder, control); clearAllControllerBindings(mInputBinder, control);
control->setInitialValue(0.0f); control->setInitialValue(0.0f);
if (button == SDL_CONTROLLER_BUTTON_START)
{
// Disallow rebinding SDL_CONTROLLER_BUTTON_START - it is used to open main and without it is not
// even possible to exit the game (or change the binding back).
mInputBinder->cancelDetectingBindingState();
}
else
ICS::DetectingBindingListener::joystickButtonBindingDetected(ICS, deviceID, control, button, direction); ICS::DetectingBindingListener::joystickButtonBindingDetected(ICS, deviceID, control, button, direction);
MWBase::Environment::get().getWindowManager()->notifyInputActionBound(); MWBase::Environment::get().getWindowManager()->notifyInputActionBound();
} }
@ -190,11 +180,8 @@ namespace MWInput
mListener = std::make_unique<BindingsListener>(mInputBinder.get(), this); mListener = std::make_unique<BindingsListener>(mInputBinder.get(), this);
mInputBinder->setDetectingBindingListener(mListener.get()); mInputBinder->setDetectingBindingListener(mListener.get());
if (!userFileExists)
{
loadKeyDefaults(); loadKeyDefaults();
loadControllerDefaults(); loadControllerDefaults();
}
for (int i = 0; i < A_Last; ++i) for (int i = 0; i < A_Last; ++i)
{ {
@ -209,13 +196,22 @@ namespace MWInput
BindingsManager::~BindingsManager() BindingsManager::~BindingsManager()
{ {
const std::string newFileName = Files::pathToUnicodeString(mUserFile) + ".new";
try try
{ {
mInputBinder->save(Files::pathToUnicodeString(mUserFile)); if (mInputBinder->save(newFileName))
}
catch (std::exception& e)
{ {
Log(Debug::Error) << "Failed to save input bindings: " << e.what(); std::filesystem::rename(Files::pathFromUnicodeString(newFileName), mUserFile);
Log(Debug::Info) << "Saved input bindings: " << mUserFile;
}
else
{
Log(Debug::Error) << "Failed to save input bindings to " << newFileName;
}
}
catch (const std::exception& e)
{
Log(Debug::Error) << "Failed to save input bindings to " << newFileName << ": " << e.what();
} }
} }

View file

@ -357,14 +357,9 @@ namespace ICS
return file.substr(0, file.find_last_of(".")); return file.substr(0, file.find_last_of("."));
} }
bool InputControlSystem::save(std::string fileName) bool InputControlSystem::save(const std::string& fileName)
{ {
if(fileName != "") TiXmlDocument doc(fileName.c_str());
{
mFileName = fileName;
}
TiXmlDocument doc( mFileName.c_str() );
TiXmlDeclaration dec; TiXmlDeclaration dec;
dec.Parse( "<?xml version='1.0' encoding='utf-8'?>", 0, TIXML_ENCODING_UNKNOWN ); dec.Parse( "<?xml version='1.0' encoding='utf-8'?>", 0, TIXML_ENCODING_UNKNOWN );

View file

@ -84,11 +84,11 @@ namespace ICS
// in seconds // in seconds
void update(float timeSinceLastFrame); void update(float timeSinceLastFrame);
inline Channel* getChannel(int i){ return mChannels[i]; }; Channel* getChannel(int i){ return mChannels.at(i); };
float getChannelValue(int i); float getChannelValue(int i);
inline int getChannelCount(){ return (int)mChannels.size(); }; inline int getChannelCount(){ return (int)mChannels.size(); };
inline Control* getControl(int i){ return mControls[i]; }; Control* getControl(int i){ return mControls.at(i); };
float getControlValue(int i); float getControlValue(int i);
inline int getControlCount(){ return (int)mControls.size(); }; inline int getControlCount(){ return (int)mControls.size(); };
inline void addControl(Control* control){ mControls.push_back(control); }; inline void addControl(Control* control){ mControls.push_back(control); };
@ -144,7 +144,7 @@ namespace ICS
void cancelDetectingBindingState(); void cancelDetectingBindingState();
bool detectingBindingState(); bool detectingBindingState();
bool save(std::string fileName = ""); bool save(const std::string& fileName);
void adjustMouseRegion (Uint16 width, Uint16 height); void adjustMouseRegion (Uint16 width, Uint16 height);