Exemplo n.º 1
0
/* 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();
}
Exemplo n.º 2
0
/* 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;
}