mirror of
https://github.com/godotengine/godot.git
synced 2024-11-22 20:23:53 +00:00
Project Manager: Added project list scrolling with keyboard
This commit is contained in:
parent
93c3c801db
commit
761193ecd9
@ -31,6 +31,7 @@
|
||||
#include "os/os.h"
|
||||
#include "os/dir_access.h"
|
||||
#include "os/file_access.h"
|
||||
#include "os/keyboard.h"
|
||||
#include "editor_settings.h"
|
||||
#include "scene/gui/separator.h"
|
||||
#include "scene/gui/tool_button.h"
|
||||
@ -491,6 +492,10 @@ void ProjectManager::_notification(int p_what) {
|
||||
if (p_what==NOTIFICATION_ENTER_TREE) {
|
||||
|
||||
get_tree()->set_editor_hint(true);
|
||||
|
||||
} else if (p_what==NOTIFICATION_VISIBILITY_CHANGED) {
|
||||
|
||||
set_process_unhandled_input(is_visible());
|
||||
}
|
||||
}
|
||||
|
||||
@ -576,6 +581,134 @@ void ProjectManager::_panel_input(const InputEvent& p_ev,Node *p_hb) {
|
||||
}
|
||||
}
|
||||
|
||||
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_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);
|
||||
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);
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
break;
|
||||
|
||||
} else if (current==selected_list.back()->key()) {
|
||||
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
} break;
|
||||
default: {
|
||||
scancode_handled = false;
|
||||
} break;
|
||||
}
|
||||
|
||||
if (scancode_handled) {
|
||||
accept_event();
|
||||
|
||||
for(int i=0;i<scroll_childs->get_child_count();i++) {
|
||||
CanvasItem *item = scroll_childs->get_child(i)->cast_to<CanvasItem>();
|
||||
if (item)
|
||||
item->update();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectManager::_favorite_pressed(Node *p_hb) {
|
||||
|
||||
String clicked = p_hb->get_meta("name");
|
||||
@ -964,6 +1097,7 @@ void ProjectManager::_bind_methods() {
|
||||
ObjectTypeDB::bind_method("_load_recent_projects",&ProjectManager::_load_recent_projects);
|
||||
ObjectTypeDB::bind_method("_panel_draw",&ProjectManager::_panel_draw);
|
||||
ObjectTypeDB::bind_method("_panel_input",&ProjectManager::_panel_input);
|
||||
ObjectTypeDB::bind_method("_unhandled_input",&ProjectManager::_unhandled_input);
|
||||
ObjectTypeDB::bind_method("_favorite_pressed",&ProjectManager::_favorite_pressed);
|
||||
ObjectTypeDB::bind_method("_install_project",&ProjectManager::_install_project);
|
||||
|
||||
|
@ -92,6 +92,7 @@ class ProjectManager : public Control {
|
||||
|
||||
void _panel_draw(Node *p_hb);
|
||||
void _panel_input(const InputEvent& p_ev,Node *p_hb);
|
||||
void _unhandled_input(const InputEvent& p_ev);
|
||||
void _favorite_pressed(Node *p_hb);
|
||||
|
||||
protected:
|
||||
|
Loading…
Reference in New Issue
Block a user