void GeekBind::unbind(const char *keybind) { std::vector<KeyBind>::iterator it; KeyBind b; b.set(keybind); for (it = binds.begin(); it != binds.end(); it++) { if (b.len != it->len) continue; bool eq = true; for (int i = 0; i < b.len; i++) { if (b.mod[i] != it->mod[i]) { eq = false; break; } if (b.c[i] != it->c[i]) { eq = false; break; } } if (eq) { binds.erase(it); break; } } return; }
/* KeyBind::addBind * Adds a new keybind *******************************************************************/ bool KeyBind::addBind(string name, keypress_t key, string desc, string group, bool ignore_shift, int priority) { // Find keybind KeyBind* bind = NULL; for (unsigned a = 0; a < keybinds.size(); a++) { if (keybinds[a].name == name) { bind = &keybinds[a]; break; } } // Add keybind if it doesn't exist if (!bind) { keybinds.push_back(KeyBind(name)); bind = &keybinds.back(); bind->ignore_shift = ignore_shift; } // Set keybind description/group if (!desc.IsEmpty()) { bind->description = desc; bind->group = group; } // Check if the key is already bound to it for (unsigned a = 0; a < bind->keys.size(); a++) { if (bind->keys[a].alt == key.alt && bind->keys[a].ctrl == key.ctrl && bind->keys[a].shift == key.shift && bind->keys[a].key == key.key) { // It is, remove the bind bind->keys.erase(bind->keys.begin() + a); return false; } } // Set priority if (priority >= 0) bind->priority = priority; // Add the keybind bind->addKey(key.key, key.alt, key.ctrl, key.shift); return true; }
std::string GeekBind::getParams(std::string keybind) { std::vector<KeyBind>::iterator it; KeyBind k; k.set(keybind.c_str()); std::string str = k.keyToStr(); for (it = binds.begin(); it != binds.end(); it++) { if (str == it->keyToStr()) return it->params; } return ""; }
/* InputPrefsPanel::applyPreferences * Applies keybind values from the control *******************************************************************/ void InputPrefsPanel::applyPreferences() { // Go through all list items wxTreeListItem item = list_binds->GetFirstItem(); while (item.IsOk()) { // Get bind info BindListItemData* bind = ((BindListItemData*)list_binds->GetItemData(item)); KeyBind* kbind = NULL; if (bind) kbind = bind->bind; // Check if it's a primary key if (kbind) { // Clear the keybind kbind->clear(); // Set primary key if any if (!bind->key.key.IsEmpty()) kbind->addKey(bind->key.key, bind->key.alt, bind->key.ctrl, bind->key.shift); // Add any secondary keys wxTreeListItem child = list_binds->GetFirstChild(item); while (child.IsOk()) { // Add key bind = ((BindListItemData*)list_binds->GetItemData(child)); kbind->addKey(bind->key.key, bind->key.alt, bind->key.ctrl, bind->key.shift); // Next child child = list_binds->GetNextSibling(child); } } // Next item item = list_binds->GetNextItem(item); } // Update sorted keybinds list KeyBind::updateSortedBindsList(); // Update map editor menus theMapEditor->setupMenu(); }
bool GeekBind::bind(const char *keybind, std::string funName, bool arch) { KeyBind k; if (!k.set(keybind)) return false; k.gcFunName = funName; // get first param of params of keybind string::size_type startpos = 0, endpos; if (!k.params.empty()) { if (k.params[0] == '#') startpos = k.params.find_first_not_of('#'); if (startpos != string::npos) endpos = k.params.find_first_of('#', startpos); k.firstParam = string(k.params, startpos, endpos - 1); } k.archive = arch; unbind(keybind); binds.push_back(k); needSort = true; return true; }
GeekBind::BindStatus GeekBind::isBinded(string &key) { KeyBind k; k.set(key.c_str()); return isBinded(k); }