Beispiel #1
0
void ProjectManager::_unhandled_input(const InputEvent& p_ev) {

	if (p_ev.type==InputEvent::KEY) {

		const InputEventKey &k = p_ev.key;

		if (!k.pressed)
			return;

		bool scancode_handled = true;

		switch (k.scancode) {

			case KEY_RETURN: {

				_open_project();
			} break;
			case KEY_HOME: {

				for (int i=0; i<scroll_childs->get_child_count(); i++) {

					HBoxContainer *hb = scroll_childs->get_child(i)->cast_to<HBoxContainer>();
					if (hb) {
						selected_list.clear();
						selected_list.insert(hb->get_meta("name"), hb->get_meta("main_scene"));
						scroll->set_v_scroll(0);
						_update_project_buttons();
						break;
					}
				}

			} break;
			case KEY_END: {

				for (int i=scroll_childs->get_child_count()-1; i>=0; i--) {

					HBoxContainer *hb = scroll_childs->get_child(i)->cast_to<HBoxContainer>();
					if (hb) {
						selected_list.clear();
						selected_list.insert(hb->get_meta("name"), hb->get_meta("main_scene"));
						scroll->set_v_scroll(scroll_childs->get_size().y);
						_update_project_buttons();
						break;
					}
				}

			} break;
			case KEY_UP: {

				if (k.mod.shift)
					break;

				if (selected_list.size()) {

					bool found = false;

					for (int i=scroll_childs->get_child_count()-1; i>=0; i--) {

						HBoxContainer *hb = scroll_childs->get_child(i)->cast_to<HBoxContainer>();
						if (!hb) continue;

						String current = hb->get_meta("name");

						if (found) {
							selected_list.clear();
							selected_list.insert(current, hb->get_meta("main_scene"));

							int offset_diff = scroll->get_v_scroll() - hb->get_pos().y;

							if (offset_diff > 0)
								scroll->set_v_scroll(scroll->get_v_scroll() - offset_diff);

							_update_project_buttons();

							break;

						} else if (current==selected_list.back()->key()) {

							found = true;
						}
					}

					break;
				}
				// else fallthrough to key_down
			}
			case KEY_DOWN: {

				if (k.mod.shift)
					break;

				bool found = selected_list.empty();

				for (int i=0; i<scroll_childs->get_child_count(); i++) {

					HBoxContainer *hb = scroll_childs->get_child(i)->cast_to<HBoxContainer>();
					if (!hb) continue;

					String current = hb->get_meta("name");

					if (found) {
						selected_list.clear();
						selected_list.insert(current, hb->get_meta("main_scene"));

						int last_y_visible = scroll->get_v_scroll() + scroll->get_size().y;
						int offset_diff = (hb->get_pos().y + hb->get_size().y) - last_y_visible;

						if (offset_diff > 0)
							scroll->set_v_scroll(scroll->get_v_scroll() + offset_diff);

						_update_project_buttons();

						break;

					} else if (current==selected_list.back()->key()) {

						found = true;
					}
				}

			} break;
			case KEY_F: {
				if (k.mod.command) this->project_filter->search_box->grab_focus();
				else scancode_handled = false;
			} break;
			default: {
				scancode_handled = false;
			} break;
		}

		if (scancode_handled) {
			accept_event();
		}
	}
}