From d475d09447ded046d32f84946ea57875b680c556 Mon Sep 17 00:00:00 2001 From: scara Date: Wed, 31 Dec 2008 14:20:00 +0000 Subject: [PATCH] Changed key duplicates into warnings git-svn-id: https://scorched3d.svn.sourceforge.net/svnroot/scorched3d/trunk/scorched@133 5b6d9151-9f40-0410-9ac9-943e3bcbbd81 --- CHANGELOG | 3 ++- src/common/common/Keyboard.cpp | 10 ++++++---- src/common/common/KeyboardKey.cpp | 9 +++++---- src/common/common/KeyboardKey.h | 2 +- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index d179d1b..2e6c4ae 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -39,4 +39,5 @@ Added server admin permissions Admin users can now change their own passwords Added server GUI to client to perform simple add/remove player operations. Can be used in offline mode too. Changed effectiveness of some shields after playing review -Changed rollers to be less bouncy \ No newline at end of file +Changed rollers to be less bouncy +Changed key duplicates to be a warning rather than halting the program \ No newline at end of file diff --git a/src/common/common/Keyboard.cpp b/src/common/common/Keyboard.cpp index 5f799e2..a41f5b1 100644 --- a/src/common/common/Keyboard.cpp +++ b/src/common/common/Keyboard.cpp @@ -252,16 +252,18 @@ bool Keyboard::loadKeyFile(bool loadDefaults) itor++) { KeyboardKey::KeyEntry &entry = *itor; - if (key->hasKey(entry.key, entry.state)) + int keyIndex = key->keyIndex(entry.key, entry.state); + if (keyIndex != -1) { const char *keyName = "", *stateName = ""; KeyboardKey::translateKeyNameValue(entry.key, keyName); KeyboardKey::translateKeyStateValue(entry.state, stateName); S3D::dialogMessage("Keyboard", S3D::formatStringBuffer( - "Key \"%s\" and state \"%s\" defined for \"%s\" was also defined for \"%s\"", - keyName, stateName, key->getName(), dupe->getName())); - return false; + "Warning: Key \"%s\" and state \"%s\" defined for \"%s\" was also defined for \"%s\"", + keyName, stateName, key->getName(), dupe->getName())); + + key->removeKey(keyIndex); } } } diff --git a/src/common/common/KeyboardKey.cpp b/src/common/common/KeyboardKey.cpp index a53253f..bae06c7 100644 --- a/src/common/common/KeyboardKey.cpp +++ b/src/common/common/KeyboardKey.cpp @@ -78,18 +78,19 @@ bool KeyboardKey::addKeys(std::list &keyNames, return true; } -bool KeyboardKey::hasKey(unsigned int key, unsigned int state) +int KeyboardKey::keyIndex(unsigned int key, unsigned int state) { + int i=0; std::vector::iterator itor; for (itor = keys_.begin(); itor != keys_.end(); - itor++) + itor++, i++) { KeyEntry &entry = *itor; if (entry.key == key && - entry.state == state) return true; + entry.state == state) return i; } - return false; + return -1; } void KeyboardKey::addKey(unsigned int position, diff --git a/src/common/common/KeyboardKey.h b/src/common/common/KeyboardKey.h index 2bd9190..9ad12c9 100644 --- a/src/common/common/KeyboardKey.h +++ b/src/common/common/KeyboardKey.h @@ -49,7 +49,7 @@ public: void addKey(unsigned int position, unsigned int key, unsigned int state); void removeKey(unsigned int position); - bool hasKey(unsigned int key, unsigned int state); + int keyIndex(unsigned int key, unsigned int state); std::vector &getKeys() { return keys_; } const char *getName() { return name_.c_str(); } -- 2.11.4.GIT