summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/variant_parser.cpp39
-rw-r--r--platform/windows/os_windows.cpp2
-rw-r--r--scene/gui/base_button.cpp36
-rw-r--r--scene/gui/base_button.h7
-rw-r--r--scene/gui/button.cpp1
-rw-r--r--scene/gui/button.h4
-rw-r--r--scene/gui/control.h2
-rw-r--r--scene/gui/input_action.cpp125
-rw-r--r--scene/gui/input_action.h26
-rw-r--r--scene/gui/menu_button.cpp19
-rw-r--r--scene/gui/popup_menu.cpp176
-rw-r--r--scene/gui/popup_menu.h19
-rw-r--r--scene/main/viewport.cpp1
-rw-r--r--scene/register_scene_types.cpp1
-rw-r--r--tools/editor/editor_node.cpp54
-rw-r--r--tools/editor/editor_settings.cpp141
-rw-r--r--tools/editor/editor_settings.h13
-rw-r--r--tools/editor/project_settings.cpp2
-rw-r--r--tools/editor/settings_config_dialog.cpp197
-rw-r--r--tools/editor/settings_config_dialog.h13
20 files changed, 802 insertions, 76 deletions
diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp
index 8bd1fddfad..e2786b8099 100644
--- a/core/variant_parser.cpp
+++ b/core/variant_parser.cpp
@@ -2011,7 +2011,44 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str
} break;
case Variant::INPUT_EVENT: {
- p_store_string_func(p_store_string_ud,"InputEvent()"); //will be added later
+ String str="InputEvent(";
+
+ InputEvent ev=p_variant;
+ switch(ev.type) {
+ case InputEvent::KEY: {
+
+ str+="KEY,"+itos(ev.key.scancode);
+ String mod;
+ if (ev.key.mod.alt)
+ mod+="A";
+ if (ev.key.mod.shift)
+ mod+="S";
+ if (ev.key.mod.control)
+ mod+="C";
+ if (ev.key.mod.meta)
+ mod+="M";
+
+ if (mod!=String())
+ str+=","+mod;
+ } break;
+ case InputEvent::MOUSE_BUTTON: {
+
+ str+="MBUTTON,"+itos(ev.mouse_button.button_index);
+ } break;
+ case InputEvent::JOYSTICK_BUTTON: {
+ str+="JBUTTON,"+itos(ev.joy_button.button_index);
+
+ } break;
+ case InputEvent::JOYSTICK_MOTION: {
+ str+="JAXIS,"+itos(ev.joy_motion.axis)+","+itos(ev.joy_motion.axis_value);
+ } break;
+ default: {}
+ }
+
+ str+=")";
+
+ p_store_string_func(p_store_string_ud,str); //will be added later
+
} break;
case Variant::DICTIONARY: {
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp
index aff48c718c..65ee39f4da 100644
--- a/platform/windows/os_windows.cpp
+++ b/platform/windows/os_windows.cpp
@@ -795,7 +795,7 @@ void OS_Windows::process_key_events() {
k.mod=ke.mod_state;
k.pressed=true;
k.scancode=KeyMappingWindows::get_keysym(ke.wParam);
- k.unicode=ke.wParam;
+ k.unicode=ke.wParam;
if (k.unicode && gr_mem) {
k.mod.alt=false;
k.mod.control=false;
diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp
index 21820d7f10..2200cac5da 100644
--- a/scene/gui/base_button.cpp
+++ b/scene/gui/base_button.cpp
@@ -390,10 +390,43 @@ Control::FocusMode BaseButton::get_enabled_focus_mode() const {
return enabled_focus_mode;
}
+void BaseButton::set_shortcut(const Ref<ShortCut>& p_shortcut) {
+
+ if (shortcut.is_null() == p_shortcut.is_null())
+ return;
+
+ shortcut=p_shortcut;
+ set_process_unhandled_input(shortcut.is_valid());
+}
+
+Ref<ShortCut> BaseButton:: get_shortcut() const {
+ return shortcut;
+}
+
+void BaseButton::_unhandled_input(InputEvent p_event) {
+
+ if (!is_disabled() && is_visible() && shortcut.is_valid() && shortcut->is_shortcut(p_event)) {
+ if (is_toggle_mode()) {
+ set_pressed(!is_pressed());
+ emit_signal("toggled",is_pressed());
+ }
+
+ emit_signal("pressed");
+ }
+}
+
+String BaseButton::get_tooltip(const Point2& p_pos) const {
+
+ String tooltip=Control::get_tooltip(p_pos);
+ if (shortcut.is_valid() && shortcut->is_valid())
+ tooltip+=" ("+shortcut->get_as_text()+")";
+ return tooltip;
+}
void BaseButton::_bind_methods() {
ObjectTypeDB::bind_method(_MD("_input_event"),&BaseButton::_input_event);
+ ObjectTypeDB::bind_method(_MD("_unhandled_input"),&BaseButton::_unhandled_input);
ObjectTypeDB::bind_method(_MD("set_pressed","pressed"),&BaseButton::set_pressed);
ObjectTypeDB::bind_method(_MD("is_pressed"),&BaseButton::is_pressed);
ObjectTypeDB::bind_method(_MD("is_hovered"),&BaseButton::is_hovered);
@@ -406,6 +439,8 @@ void BaseButton::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_draw_mode"),&BaseButton::get_draw_mode);
ObjectTypeDB::bind_method(_MD("set_enabled_focus_mode","mode"),&BaseButton::set_enabled_focus_mode);
ObjectTypeDB::bind_method(_MD("get_enabled_focus_mode"),&BaseButton::get_enabled_focus_mode);
+ ObjectTypeDB::bind_method(_MD("set_shortcut","shortcut"),&BaseButton::set_shortcut);
+ ObjectTypeDB::bind_method(_MD("get_shortcut"),&BaseButton::get_shortcut);
BIND_VMETHOD(MethodInfo("_pressed"));
BIND_VMETHOD(MethodInfo("_toggled",PropertyInfo(Variant::BOOL,"pressed")));
@@ -418,6 +453,7 @@ void BaseButton::_bind_methods() {
ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "is_pressed"), _SCS("set_pressed"), _SCS("is_pressed"));
ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "click_on_press"), _SCS("set_click_on_press"), _SCS("get_click_on_press"));
ADD_PROPERTY( PropertyInfo( Variant::INT,"enabled_focus_mode", PROPERTY_HINT_ENUM, "None,Click,All" ), _SCS("set_enabled_focus_mode"), _SCS("get_enabled_focus_mode") );
+ ADD_PROPERTY( PropertyInfo( Variant::OBJECT, "shortcut",PROPERTY_HINT_RESOURCE_TYPE,"ShortCut"), _SCS("set_shortcut"), _SCS("get_shortcut"));
BIND_CONSTANT( DRAW_NORMAL );
diff --git a/scene/gui/base_button.h b/scene/gui/base_button.h
index 0247fb2f21..0056b00f33 100644
--- a/scene/gui/base_button.h
+++ b/scene/gui/base_button.h
@@ -43,6 +43,7 @@ class BaseButton : public Control {
bool toggle_mode;
FocusMode enabled_focus_mode;
+ Ref<ShortCut> shortcut;
struct Status {
@@ -57,6 +58,7 @@ class BaseButton : public Control {
} status;
+
ButtonGroup *group;
@@ -69,6 +71,7 @@ protected:
virtual void toggled(bool p_pressed);
static void _bind_methods();
virtual void _input_event(InputEvent p_event);
+ virtual void _unhandled_input(InputEvent p_event);
void _notification(int p_what);
public:
@@ -101,6 +104,10 @@ public:
void set_enabled_focus_mode(FocusMode p_mode);
FocusMode get_enabled_focus_mode() const;
+ void set_shortcut(const Ref<ShortCut>& p_shortcut);
+ Ref<ShortCut> get_shortcut() const;
+
+ virtual String get_tooltip(const Point2& p_pos) const;
BaseButton();
~BaseButton();
diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp
index 0f1622a838..579f6e08c9 100644
--- a/scene/gui/button.cpp
+++ b/scene/gui/button.cpp
@@ -213,7 +213,6 @@ Button::TextAlign Button::get_text_align() const {
return align;
}
-
void Button::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_text","text"),&Button::set_text);
diff --git a/scene/gui/button.h b/scene/gui/button.h
index 8a17a164a0..c39237c9af 100644
--- a/scene/gui/button.h
+++ b/scene/gui/button.h
@@ -54,7 +54,6 @@ private:
TextAlign align;
-
protected:
virtual Size2 get_minimum_size() const;
@@ -62,6 +61,8 @@ protected:
static void _bind_methods();
public:
//
+
+
void set_text(const String& p_text);
String get_text() const;
@@ -77,6 +78,7 @@ public:
void set_text_align(TextAlign p_align);
TextAlign get_text_align() const;
+
Button(const String& p_text=String());
~Button();
diff --git a/scene/gui/control.h b/scene/gui/control.h
index f720185c9d..d77ba27f60 100644
--- a/scene/gui/control.h
+++ b/scene/gui/control.h
@@ -35,7 +35,7 @@
#include "scene/2d/canvas_item.h"
#include "math_2d.h"
#include "rid.h"
-
+#include "scene/gui/input_action.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
diff --git a/scene/gui/input_action.cpp b/scene/gui/input_action.cpp
new file mode 100644
index 0000000000..4cf2661e49
--- /dev/null
+++ b/scene/gui/input_action.cpp
@@ -0,0 +1,125 @@
+#include "input_action.h"
+#include "os/keyboard.h"
+
+void ShortCut::set_shortcut(const InputEvent& p_shortcut){
+
+ shortcut=p_shortcut;
+ emit_changed();
+}
+
+InputEvent ShortCut::get_shortcut() const{
+
+ return shortcut;
+}
+
+bool ShortCut::is_shortcut(const InputEvent& p_event) const {
+
+ bool same=false;
+
+
+ switch(p_event.type) {
+
+ case InputEvent::KEY: {
+
+ same=(shortcut.key.scancode==p_event.key.scancode && shortcut.key.mod == p_event.key.mod);
+
+ } break;
+ case InputEvent::JOYSTICK_BUTTON: {
+
+ same=(shortcut.joy_button.button_index==p_event.joy_button.button_index);
+
+ } break;
+ case InputEvent::MOUSE_BUTTON: {
+
+ same=(shortcut.mouse_button.button_index==p_event.mouse_button.button_index);
+
+ } break;
+ case InputEvent::JOYSTICK_MOTION: {
+
+ same=(shortcut.joy_motion.axis==p_event.joy_motion.axis && (shortcut.joy_motion.axis_value < 0) == (p_event.joy_motion.axis_value < 0));
+
+ } break;
+ default: {};
+ }
+
+ return same;
+}
+
+String ShortCut::get_as_text() const {
+
+ switch(shortcut.type) {
+
+ case InputEvent::NONE: {
+
+ return "None";
+ } break;
+ case InputEvent::KEY: {
+
+ String str;
+ if (shortcut.key.mod.shift)
+ str+=TTR("Shift+");
+ if (shortcut.key.mod.alt)
+ str+=TTR("Alt+");
+ if (shortcut.key.mod.control)
+ str+=TTR("Ctrl+");
+ if (shortcut.key.mod.meta)
+ str+=TTR("Meta+");
+
+ str+=keycode_get_string(shortcut.key.scancode).capitalize();
+
+ return str;
+ } break;
+ case InputEvent::JOYSTICK_BUTTON: {
+
+ String str = TTR("Device")+" "+itos(shortcut.device)+", "+TTR("Button")+" "+itos(shortcut.joy_button.button_index);
+ str+=".";
+
+ return str;
+ } break;
+ case InputEvent::MOUSE_BUTTON: {
+
+ String str = TTR("Device")+" "+itos(shortcut.device)+", ";
+ switch (shortcut.mouse_button.button_index) {
+ case BUTTON_LEFT: str+=TTR("Left Button."); break;
+ case BUTTON_RIGHT: str+=TTR("Right Button."); break;
+ case BUTTON_MIDDLE: str+=TTR("Middle Button."); break;
+ case BUTTON_WHEEL_UP: str+=TTR("Wheel Up."); break;
+ case BUTTON_WHEEL_DOWN: str+=TTR("Wheel Down."); break;
+ default: str+=TTR("Button")+" "+itos(shortcut.mouse_button.button_index)+".";
+ }
+
+ return str;
+ } break;
+ case InputEvent::JOYSTICK_MOTION: {
+
+ int ax = shortcut.joy_motion.axis;
+ String str = TTR("Device")+" "+itos(shortcut.device)+", "+TTR("Axis")+" "+itos(ax)+".";
+
+ return str;
+ } break;
+ }
+
+ return "";
+}
+
+bool ShortCut::is_valid() const {
+
+ return shortcut.type!=InputEvent::NONE;
+}
+
+void ShortCut::_bind_methods() {
+
+ ObjectTypeDB::bind_method(_MD("set_shortcut","event"),&ShortCut::set_shortcut);
+ ObjectTypeDB::bind_method(_MD("get_shortcut"),&ShortCut::get_shortcut);
+
+ ObjectTypeDB::bind_method(_MD("is_valid"),&ShortCut::is_valid);
+
+ ObjectTypeDB::bind_method(_MD("is_shortcut","event"),&ShortCut::is_shortcut);
+ ObjectTypeDB::bind_method(_MD("get_as_text"),&ShortCut::get_as_text);
+
+ ADD_PROPERTY(PropertyInfo(Variant::INPUT_EVENT,"shortcut"),_SCS("set_shortcut"),_SCS("get_shortcut"));
+}
+
+ShortCut::ShortCut(){
+
+}
diff --git a/scene/gui/input_action.h b/scene/gui/input_action.h
new file mode 100644
index 0000000000..8e0e1ef0bd
--- /dev/null
+++ b/scene/gui/input_action.h
@@ -0,0 +1,26 @@
+#ifndef INPUTACTION_H
+#define INPUTACTION_H
+
+#include "resource.h"
+
+class ShortCut : public Resource {
+
+ OBJ_TYPE(ShortCut,Resource);
+
+ InputEvent shortcut;
+protected:
+
+ static void _bind_methods();
+public:
+
+ void set_shortcut(const InputEvent& p_shortcut);
+ InputEvent get_shortcut() const;
+ bool is_shortcut(const InputEvent& p_Event) const;
+ bool is_valid() const;
+
+ String get_as_text() const;
+
+ ShortCut();
+};
+
+#endif // INPUTACTION_H
diff --git a/scene/gui/menu_button.cpp b/scene/gui/menu_button.cpp
index 0e39ee8a76..28d67287d5 100644
--- a/scene/gui/menu_button.cpp
+++ b/scene/gui/menu_button.cpp
@@ -32,30 +32,15 @@
void MenuButton::_unhandled_key_input(InputEvent p_event) {
- //check accelerators
- if (p_event.type==InputEvent::KEY && p_event.key.pressed) {
+ if (p_event.is_pressed() && !p_event.is_echo() && (p_event.type==InputEvent::KEY || p_event.type==InputEvent::ACTION || p_event.type==InputEvent::JOYSTICK_BUTTON)) {
if (!get_parent() || !is_visible() || is_disabled())
return;
- uint32_t code=p_event.key.scancode;
- if (code==0)
- code=p_event.key.unicode;
- if (p_event.key.mod.control)
- code|=KEY_MASK_CTRL;
- if (p_event.key.mod.alt)
- code|=KEY_MASK_ALT;
- if (p_event.key.mod.meta)
- code|=KEY_MASK_META;
- if (p_event.key.mod.shift)
- code|=KEY_MASK_SHIFT;
-
-
- int item = popup->activate_item_by_accelerator(code);
+ int item = popup->activate_item_by_event(p_event);
}
-
}
diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp
index 819885809b..4c69584f4a 100644
--- a/scene/gui/popup_menu.cpp
+++ b/scene/gui/popup_menu.cpp
@@ -32,9 +32,16 @@
#include "translation.h"
#include "os/input.h"
-String PopupMenu::_get_accel_text(uint32_t p_accel) const {
+String PopupMenu::_get_accel_text(int p_item) const {
+
+ ERR_FAIL_INDEX_V(p_item,items.size(),String());
+
+ if (items[p_item].shortcut.is_valid())
+ return items[p_item].shortcut->get_as_text();
+ else if (items[p_item].accel)
+ return keycode_get_string(items[p_item].accel);
+ return String();
- return keycode_get_string(p_accel);
/*
String atxt;
if (p_accel&KEY_MASK_SHIFT)
@@ -87,14 +94,15 @@ Size2 PopupMenu::get_minimum_size() const {
size.width+=check_w+hseparation;
}
- size.width+=font->get_string_size(items[i].text).width;
+ String text = items[i].shortcut.is_valid() ? String(tr(items[i].shortcut->get_name())) : items[i].text;
+ size.width+=font->get_string_size(text).width;
if (i>0)
size.height+=vseparation;
- if (items[i].accel) {
+ if (items[i].accel || (items[i].shortcut.is_valid() && items[i].shortcut->is_valid())) {
int accel_w = hseparation*2;
- accel_w+=font->get_string_size(_get_accel_text(items[i].accel)).width;
+ accel_w+=font->get_string_size(_get_accel_text(i)).width;
accel_max_w = MAX( accel_w, accel_max_w );
}
@@ -484,13 +492,15 @@ void PopupMenu::_notification(int p_what) {
}
item_ofs.y+=font->get_ascent();
- if (!items[i].separator)
- font->draw(ci,item_ofs+Point2(0,Math::floor((h-font_h)/2.0)),items[i].text,items[i].disabled?font_color_disabled:(i==mouse_over?font_color_hover:font_color));
+ String text = items[i].shortcut.is_valid() ? String(tr(items[i].shortcut->get_name())) : items[i].text;
+ if (!items[i].separator) {
+ font->draw(ci,item_ofs+Point2(0,Math::floor((h-font_h)/2.0)),text,items[i].disabled?font_color_disabled:(i==mouse_over?font_color_hover:font_color));
+ }
- if (items[i].accel) {
+ if (items[i].accel || (items[i].shortcut.is_valid() && items[i].shortcut->is_valid())) {
//accelerator
- String text = _get_accel_text(items[i].accel);
+ String text = _get_accel_text(i);
item_ofs.x=size.width-style->get_margin(MARGIN_RIGHT)-font->get_string_size(text).width;
font->draw(ci,item_ofs+Point2(0,Math::floor((h-font_h)/2.0)),text,i==mouse_over?font_color_hover:font_color_accel);
@@ -570,6 +580,64 @@ void PopupMenu::add_check_item(const String& p_label,int p_ID,uint32_t p_accel)
update();
}
+
+void PopupMenu::add_icon_shortcut(const Ref<Texture>& p_icon,const Ref<ShortCut>& p_shortcut,int p_ID) {
+
+ ERR_FAIL_COND(p_shortcut.is_null());
+
+ _ref_shortcut(p_shortcut);
+
+ Item item;
+ item.ID=p_ID;
+ item.icon=p_icon;
+ item.shortcut=p_shortcut;
+ items.push_back(item);
+ update();
+
+}
+
+void PopupMenu::add_shortcut(const Ref<ShortCut>& p_shortcut,int p_ID){
+
+ ERR_FAIL_COND(p_shortcut.is_null());
+
+ _ref_shortcut(p_shortcut);
+
+ Item item;
+ item.ID=p_ID;
+ item.shortcut=p_shortcut;
+ items.push_back(item);
+ update();
+
+}
+void PopupMenu::add_icon_check_shortcut(const Ref<Texture>& p_icon,const Ref<ShortCut>& p_shortcut,int p_ID){
+
+ ERR_FAIL_COND(p_shortcut.is_null());
+
+ _ref_shortcut(p_shortcut);
+
+ Item item;
+ item.ID=p_ID;
+ item.shortcut=p_shortcut;
+ item.checkable=true;
+ item.icon=p_icon;
+ items.push_back(item);
+ update();
+}
+
+void PopupMenu::add_check_shortcut(const Ref<ShortCut>& p_shortcut,int p_ID){
+
+ ERR_FAIL_COND(p_shortcut.is_null());
+
+ _ref_shortcut(p_shortcut);
+
+ Item item;
+ item.ID=p_ID;
+ item.shortcut=p_shortcut;
+ item.checkable=true;
+ items.push_back(item);
+ update();
+}
+
void PopupMenu::set_item_text(int p_idx,const String& p_text) {
ERR_FAIL_INDEX(p_idx,items.size());
@@ -701,6 +769,12 @@ String PopupMenu::get_item_tooltip(int p_idx) const {
return items[p_idx].tooltip;
}
+Ref<ShortCut> PopupMenu::get_item_shortcut(int p_idx) const {
+
+ ERR_FAIL_INDEX_V(p_idx,items.size(),"");
+ return items[p_idx].shortcut;
+}
+
void PopupMenu::set_item_as_separator(int p_idx, bool p_separator) {
ERR_FAIL_INDEX(p_idx,items.size());
@@ -730,6 +804,21 @@ void PopupMenu::set_item_tooltip(int p_idx,const String& p_tooltip) {
update();
}
+void PopupMenu::set_item_shortcut(int p_idx, const Ref<ShortCut>& p_shortcut) {
+ ERR_FAIL_INDEX(p_idx,items.size());
+ if (items[p_idx].shortcut.is_valid()) {
+ _unref_shortcut(items[p_idx].shortcut);
+ }
+ items[p_idx].shortcut=p_shortcut;
+
+ if (items[p_idx].shortcut.is_valid()) {
+ _ref_shortcut(items[p_idx].shortcut);
+ }
+
+
+ update();
+}
+
bool PopupMenu::is_item_checkable(int p_idx) const {
ERR_FAIL_INDEX_V(p_idx,items.size(),false);
return items[p_idx].checkable;
@@ -740,14 +829,36 @@ int PopupMenu::get_item_count() const {
return items.size();
}
-bool PopupMenu::activate_item_by_accelerator(uint32_t p_accel) {
+bool PopupMenu::activate_item_by_event(const InputEvent& p_event) {
+
+ uint32_t code=0;
+ if (p_event.type==InputEvent::KEY) {
+ code=p_event.key.scancode;
+ if (code==0)
+ code=p_event.key.unicode;
+ if (p_event.key.mod.control)
+ code|=KEY_MASK_CTRL;
+ if (p_event.key.mod.alt)
+ code|=KEY_MASK_ALT;
+ if (p_event.key.mod.meta)
+ code|=KEY_MASK_META;
+ if (p_event.key.mod.shift)
+ code|=KEY_MASK_SHIFT;
+ }
+
int il=items.size();
for(int i=0;i<il;i++) {
if (is_item_disabled(i))
continue;
- if (items[i].accel==p_accel) {
+
+ if (items[i].shortcut.is_valid() && items[i].shortcut->is_shortcut(p_event)) {
+ activate_item(i);
+ return true;
+ }
+
+ if (code!=0 && items[i].accel==code) {
activate_item(i);
return true;
}
@@ -761,7 +872,7 @@ bool PopupMenu::activate_item_by_accelerator(uint32_t p_accel) {
if(!pm)
continue;
- if(pm->activate_item_by_accelerator(p_accel)) {
+ if(pm->activate_item_by_event(p_event)) {
return true;
}
}
@@ -791,6 +902,12 @@ void PopupMenu::activate_item(int p_item) {
void PopupMenu::remove_item(int p_idx) {
+ ERR_FAIL_INDEX(p_idx,items.size());
+
+ if (items[p_idx].shortcut.is_valid()) {
+ _unref_shortcut(items[p_idx].shortcut);
+ }
+
items.remove(p_idx);
update();
}
@@ -806,6 +923,11 @@ void PopupMenu::add_separator() {
void PopupMenu::clear() {
+ for(int i=0;i<items.size();i++) {
+ if (items[i].shortcut.is_valid()) {
+ _unref_shortcut(items[i].shortcut);
+ }
+ }
items.clear();
mouse_over=-1;
update();
@@ -834,6 +956,27 @@ Array PopupMenu::_get_items() const {
return items;
}
+
+void PopupMenu::_ref_shortcut( Ref<ShortCut> p_sc) {
+
+ if (!shortcut_refcount.has(p_sc)) {
+ shortcut_refcount[p_sc]=1;
+ p_sc->connect("changed",this,"update");
+ } else {
+ shortcut_refcount[p_sc]+=1;
+ }
+}
+
+void PopupMenu::_unref_shortcut(Ref<ShortCut> p_sc) {
+
+ ERR_FAIL_COND(!shortcut_refcount.has(p_sc));
+ shortcut_refcount[p_sc]--;
+ if (shortcut_refcount[p_sc]==0) {
+ p_sc->disconnect("changed",this,"update");
+ shortcut_refcount.erase(p_sc);
+ }
+}
+
void PopupMenu::_set_items(const Array& p_items){
ERR_FAIL_COND(p_items.size() % 10);
@@ -912,12 +1055,20 @@ void PopupMenu::_bind_methods() {
ObjectTypeDB::bind_method(_MD("add_icon_check_item","texture","label","id","accel"),&PopupMenu::add_icon_check_item,DEFVAL(-1),DEFVAL(0));
ObjectTypeDB::bind_method(_MD("add_check_item","label","id","accel"),&PopupMenu::add_check_item,DEFVAL(-1),DEFVAL(0));
ObjectTypeDB::bind_method(_MD("add_submenu_item","label","submenu","id"),&PopupMenu::add_submenu_item,DEFVAL(-1));
+
+ ObjectTypeDB::bind_method(_MD("add_icon_shortcut","texture","shortcut:ShortCut","id"),&PopupMenu::add_icon_shortcut,DEFVAL(-1));
+ ObjectTypeDB::bind_method(_MD("add_shortcut","shortcut:ShortCut","id"),&PopupMenu::add_shortcut,DEFVAL(-1));
+ ObjectTypeDB::bind_method(_MD("add_icon_check_shortcut","texture","shortcut:ShortCut","id"),&PopupMenu::add_icon_check_shortcut,DEFVAL(-1));
+ ObjectTypeDB::bind_method(_MD("add_check_shortcut","shortcut:ShortCut","id"),&PopupMenu::add_check_shortcut,DEFVAL(-1));
+
+
ObjectTypeDB::bind_method(_MD("set_item_text","idx","text"),&PopupMenu::set_item_text);
ObjectTypeDB::bind_method(_MD("set_item_icon","idx","icon"),&PopupMenu::set_item_icon);
ObjectTypeDB::bind_method(_MD("set_item_accelerator","idx","accel"),&PopupMenu::set_item_accelerator);
ObjectTypeDB::bind_method(_MD("set_item_metadata","idx","metadata"),&PopupMenu::set_item_metadata);
ObjectTypeDB::bind_method(_MD("set_item_checked","idx","checked"),&PopupMenu::set_item_checked);
ObjectTypeDB::bind_method(_MD("set_item_disabled","idx","disabled"),&PopupMenu::set_item_disabled);
+ ObjectTypeDB::bind_method(_MD("set_item_shortcut","idx","shortcut:ShortCut"),&PopupMenu::set_item_shortcut);
ObjectTypeDB::bind_method(_MD("set_item_submenu","idx","submenu"),&PopupMenu::set_item_submenu);
ObjectTypeDB::bind_method(_MD("set_item_as_separator","idx","enable"),&PopupMenu::set_item_as_separator);
ObjectTypeDB::bind_method(_MD("set_item_as_checkable","idx","enable"),&PopupMenu::set_item_as_checkable);
@@ -926,6 +1077,7 @@ void PopupMenu::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_item_icon","idx"),&PopupMenu::get_item_icon);
ObjectTypeDB::bind_method(_MD("get_item_metadata","idx"),&PopupMenu::get_item_metadata);
ObjectTypeDB::bind_method(_MD("get_item_accelerator","idx"),&PopupMenu::get_item_accelerator);
+ ObjectTypeDB::bind_method(_MD("get_item_shortcut:ShortCut","idx"),&PopupMenu::get_item_shortcut);
ObjectTypeDB::bind_method(_MD("get_item_submenu","idx"),&PopupMenu::get_item_submenu);
ObjectTypeDB::bind_method(_MD("is_item_separator","idx"),&PopupMenu::is_item_separator);
ObjectTypeDB::bind_method(_MD("is_item_checkable","idx"),&PopupMenu::is_item_checkable);
diff --git a/scene/gui/popup_menu.h b/scene/gui/popup_menu.h
index 0e98765dc4..f35e91d4e4 100644
--- a/scene/gui/popup_menu.h
+++ b/scene/gui/popup_menu.h
@@ -34,6 +34,9 @@
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
+
+
+
class PopupMenu : public Popup {
OBJ_TYPE(PopupMenu, Popup );
@@ -51,6 +54,7 @@ class PopupMenu : public Popup {
String tooltip;
uint32_t accel;
int _ofs_cache;
+ Ref<ShortCut> shortcut;
Item() { checked=false; checkable=false; separator=false; accel=0; disabled=false; _ofs_cache=0; }
};
@@ -62,7 +66,7 @@ class PopupMenu : public Popup {
int mouse_over;
int submenu_over;
Rect2 parent_rect;
- String _get_accel_text(uint32_t p_accel) const;
+ String _get_accel_text(int p_item) const;
int _get_mouse_over(const Point2& p_over) const;
virtual Size2 get_minimum_size() const;
void _input_event(const InputEvent &p_event);
@@ -75,6 +79,10 @@ class PopupMenu : public Popup {
Array _get_items() const;
void _set_items(const Array& p_items);
+ Map< Ref<ShortCut>, int> shortcut_refcount;
+
+ void _ref_shortcut(Ref<ShortCut> p_sc);
+ void _unref_shortcut( Ref<ShortCut> p_sc);
protected:
virtual bool has_point(const Point2& p_point) const;
@@ -90,6 +98,11 @@ public:
void add_check_item(const String& p_label,int p_ID=-1,uint32_t p_accel=0);
void add_submenu_item(const String& p_label,const String& p_submenu, int p_ID=-1);
+ void add_icon_shortcut(const Ref<Texture>& p_icon,const Ref<ShortCut>& p_shortcut,int p_ID=-1);
+ void add_shortcut(const Ref<ShortCut>& p_shortcut,int p_ID=-1);
+ void add_icon_check_shortcut(const Ref<Texture>& p_icon,const Ref<ShortCut>& p_shortcut,int p_ID=-1);
+ void add_check_shortcut(const Ref<ShortCut>& p_shortcut,int p_ID=-1);
+
void set_item_text(int p_idx,const String& p_text);
void set_item_icon(int p_idx,const Ref<Texture>& p_icon);
void set_item_checked(int p_idx,bool p_checked);
@@ -101,6 +114,7 @@ public:
void set_item_as_separator(int p_idx, bool p_separator);
void set_item_as_checkable(int p_idx, bool p_checkable);
void set_item_tooltip(int p_idx,const String& p_tooltip);
+ void set_item_shortcut(int p_idx, const Ref<ShortCut>& p_shortcut);
String get_item_text(int p_idx) const;
Ref<Texture> get_item_icon(int p_idx) const;
@@ -114,10 +128,11 @@ public:
bool is_item_separator(int p_idx) const;
bool is_item_checkable(int p_idx) const;
String get_item_tooltip(int p_idx) const;
+ Ref<ShortCut> get_item_shortcut(int p_idx) const;
int get_item_count() const;
- bool activate_item_by_accelerator(uint32_t p_accel);
+ bool activate_item_by_event(const InputEvent& p_event);
void activate_item(int p_item);
void remove_item(int p_idx);
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 5ce53194a1..313be88526 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -1358,7 +1358,6 @@ void Viewport::_vp_unhandled_input(const InputEvent& p_ev) {
if (disable_input)
return;
-
#ifdef TOOLS_ENABLED
if (get_tree()->is_editor_hint() && get_tree()->get_edited_scene_root()->is_a_parent_of(this)) {
return;
diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp
index 1fd1c77dca..ed38379ca9 100644
--- a/scene/register_scene_types.cpp
+++ b/scene/register_scene_types.cpp
@@ -293,6 +293,7 @@ void register_scene_types() {
OS::get_singleton()->yield(); //may take time to init
+ ObjectTypeDB::register_type<ShortCut>();
ObjectTypeDB::register_type<Control>();
// ObjectTypeDB::register_type<EmptyControl>();
ObjectTypeDB::add_compatibility_type("EmptyControl","Control");
diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp
index 5d0617d8ab..72d5e496d9 100644
--- a/tools/editor/editor_node.cpp
+++ b/tools/editor/editor_node.cpp
@@ -188,10 +188,10 @@ void EditorNode::_unhandled_input(const InputEvent& p_event) {
if (!p_event.key.mod.shift && !p_event.key.mod.command)
_editor_select(EDITOR_SCRIPT);
break;
- case KEY_F5: _menu_option_confirm((p_event.key.mod.control&&p_event.key.mod.shift)?RUN_PLAY_CUSTOM_SCENE:RUN_PLAY,true); break;
+ /* case KEY_F5: _menu_option_confirm((p_event.key.mod.control&&p_event.key.mod.shift)?RUN_PLAY_CUSTOM_SCENE:RUN_PLAY,true); break;
case KEY_F6: _menu_option_confirm(RUN_PLAY_SCENE,true); break;
//case KEY_F7: _menu_option_confirm(RUN_PAUSE,true); break;
- case KEY_F8: _menu_option_confirm(RUN_STOP,true); break;
+ case KEY_F8: _menu_option_confirm(RUN_STOP,true); break;*/
case KEY_F11: {
if (p_event.key.mod.shift) {
if (p_event.key.mod.control) {
@@ -1794,18 +1794,18 @@ void EditorNode::_edit_current() {
PopupMenu *p=object_menu->get_popup();
p->clear();
- p->add_item(TTR("Copy Params"),OBJECT_COPY_PARAMS);
- p->add_item(TTR("Set Params"),OBJECT_PASTE_PARAMS);
+ p->add_shortcut(ED_SHORTCUT("property_editor/copy_params",TTR("Copy Params")),OBJECT_COPY_PARAMS);
+ p->add_shortcut(ED_SHORTCUT("property_editor/paste_params",TTR("Paste Params")),OBJECT_PASTE_PARAMS);
p->add_separator();
- p->add_item(TTR("Paste Resource"),RESOURCE_PASTE);
+ p->add_shortcut(ED_SHORTCUT("property_editor/paste_resource",TTR("Paste Resource")),RESOURCE_PASTE);
if (is_resource) {
- p->add_item(TTR("Copy Resource"),RESOURCE_COPY);
- p->add_item(TTR("Make Built-In"),RESOURCE_UNREF);
+ p->add_shortcut(ED_SHORTCUT("property_editor/copy_resource",TTR("Copy Resource")),RESOURCE_COPY);
+ p->add_shortcut(ED_SHORTCUT("property_editor/unref_resource",TTR("Make Built-In")),RESOURCE_UNREF);
}
p->add_separator();
- p->add_item(TTR("Make Sub-Resources Unique"),OBJECT_UNIQUE_RESOURCES);
+ p->add_shortcut(ED_SHORTCUT("property_editor/make_subresources_unique",TTR("Make Sub-Resources Unique")),OBJECT_UNIQUE_RESOURCES);
p->add_separator();
- p->add_icon_item(gui_base->get_icon("Help","EditorIcons"),"Class Reference",OBJECT_REQUEST_HELP);
+ p->add_icon_shortcut(gui_base->get_icon("Help","EditorIcons"),ED_SHORTCUT("property_editor/open_help",TTR("Open in Help")),OBJECT_REQUEST_HELP);
List<MethodInfo> methods;
current_obj->get_method_list(&methods);
@@ -4700,10 +4700,10 @@ void EditorNode::_update_layouts_menu() {
overridden_default_layout=-1;
editor_layouts->set_size(Vector2());
- editor_layouts->add_item(TTR("Save Layout"), SETTINGS_LAYOUT_SAVE);
- editor_layouts->add_item(TTR("Delete Layout"), SETTINGS_LAYOUT_DELETE);
+ editor_layouts->add_shortcut(ED_SHORTCUT("layout/save",TTR("Save Layout")), SETTINGS_LAYOUT_SAVE);
+ editor_layouts->add_shortcut(ED_SHORTCUT("layout/load",TTR("Load Layout")), SETTINGS_LAYOUT_DELETE);
editor_layouts->add_separator();
- editor_layouts->add_item(TTR("Default"), SETTINGS_LAYOUT_DEFAULT);
+ editor_layouts->add_shortcut(ED_SHORTCUT("property_editor/reset",TTR("Default")), SETTINGS_LAYOUT_DEFAULT);
Ref<ConfigFile> config;
config.instance();
@@ -5588,21 +5588,21 @@ EditorNode::EditorNode() {
file_menu->set_tooltip(TTR("Operations with scene files."));
p=file_menu->get_popup();
- p->add_item(TTR("New Scene"),FILE_NEW_SCENE);
- p->add_item(TTR("New Inherited Scene.."),FILE_NEW_INHERITED_SCENE);
- p->add_item(TTR("Open Scene.."),FILE_OPEN_SCENE,KEY_MASK_CMD+KEY_O);
+ p->add_shortcut(ED_SHORTCUT("editor/new_scene",TTR("New Scene")),FILE_NEW_SCENE);
+ p->add_shortcut(ED_SHORTCUT("editor/new_inherited_scene",TTR("New Inherited Scene..")),FILE_NEW_INHERITED_SCENE);
+ p->add_shortcut(ED_SHORTCUT("editor/open_scene",TTR("Open Scene.."),KEY_MASK_CMD+KEY_O),FILE_OPEN_SCENE);
p->add_separator();
- p->add_item(TTR("Save Scene"),FILE_SAVE_SCENE,KEY_MASK_CMD+KEY_S);
- p->add_item(TTR("Save Scene As.."),FILE_SAVE_AS_SCENE,KEY_MASK_SHIFT+KEY_MASK_CMD+KEY_S);
+ p->add_shortcut(ED_SHORTCUT("editor/save_scene",TTR("Save Scene"),KEY_MASK_CMD+KEY_S),FILE_SAVE_SCENE);
+ p->add_shortcut(ED_SHORTCUT("editor/save_scene_as",TTR("Save Scene As.."),KEY_MASK_SHIFT+KEY_MASK_CMD+KEY_S),FILE_SAVE_AS_SCENE);
p->add_separator();
- p->add_item(TTR("Close Scene"),FILE_CLOSE,KEY_MASK_SHIFT+KEY_MASK_CTRL+KEY_W);
+ p->add_shortcut(ED_SHORTCUT("editor/close_scene",TTR("Close Scene"),KEY_MASK_SHIFT+KEY_MASK_CTRL+KEY_W),FILE_CLOSE);
p->add_separator();
- p->add_item(TTR("Close Goto Prev. Scene"),FILE_OPEN_PREV,KEY_MASK_SHIFT+KEY_MASK_CMD+KEY_P);
+ //p->add_shortcut(ED_SHORTCUT("editor/save_scene",TTR("Close Goto Prev. Scene")),FILE_OPEN_PREV,KEY_MASK_SHIFT+KEY_MASK_CMD+KEY_P);
p->add_submenu_item(TTR("Open Recent"),"RecentScenes",FILE_OPEN_RECENT);
p->add_separator();
- p->add_item(TTR("Quick Open Scene.."),FILE_QUICK_OPEN_SCENE,KEY_MASK_SHIFT+KEY_MASK_CMD+KEY_O);
- p->add_item(TTR("Quick Open Script.."),FILE_QUICK_OPEN_SCRIPT,KEY_MASK_ALT+KEY_MASK_CMD+KEY_O);
- p->add_item(TTR("Quick Search File.."),FILE_QUICK_OPEN_FILE,KEY_MASK_ALT+KEY_MASK_CMD+KEY_P);
+ p->add_shortcut(ED_SHORTCUT("editor/quick_open_scene",TTR("Quick Open Scene.."),KEY_MASK_SHIFT+KEY_MASK_CMD+KEY_O),FILE_QUICK_OPEN_SCENE);
+ p->add_shortcut(ED_SHORTCUT("editor/quick_open_script",TTR("Quick Open Script.."),KEY_MASK_ALT+KEY_MASK_CMD+KEY_O),FILE_QUICK_OPEN_SCRIPT);
+ p->add_shortcut(ED_SHORTCUT("editor/quick_filter_files",TTR("Quick Filter Files.."),KEY_MASK_ALT+KEY_MASK_CMD+KEY_P),FILE_QUICK_OPEN_FILE);
p->add_separator();
PopupMenu *pm_export = memnew(PopupMenu );
@@ -5733,7 +5733,8 @@ EditorNode::EditorNode() {
play_button->set_icon(gui_base->get_icon("MainPlay","EditorIcons"));
play_button->set_focus_mode(Control::FOCUS_NONE);
play_button->connect("pressed", this,"_menu_option",make_binds(RUN_PLAY));
- play_button->set_tooltip(TTR("Play the project (F5)."));
+ play_button->set_tooltip(TTR("Play the project."));
+ play_button->set_shortcut(ED_SHORTCUT("editor/play",TTR("Play"),KEY_F5));
@@ -5746,6 +5747,7 @@ EditorNode::EditorNode() {
pause_button->set_tooltip(TTR("Pause the scene"));
pause_button->set_disabled(true);
play_hb->add_child(pause_button);
+ pause_button->set_shortcut(ED_SHORTCUT("editor/pause_scene",TTR("Pause Scene"),KEY_F7));
stop_button = memnew( ToolButton );
@@ -5754,7 +5756,8 @@ EditorNode::EditorNode() {
stop_button->set_focus_mode(Control::FOCUS_NONE);
stop_button->set_icon(gui_base->get_icon("MainStop","EditorIcons"));
stop_button->connect("pressed", this,"_menu_option",make_binds(RUN_STOP));
- stop_button->set_tooltip(TTR("Stop the scene (F8)."));
+ stop_button->set_tooltip(TTR("Stop the scene."));
+ stop_button->set_shortcut(ED_SHORTCUT("editor/stop",TTR("Stop"),KEY_F8));
run_native = memnew( EditorRunNative);
play_hb->add_child(run_native);
@@ -5774,7 +5777,8 @@ EditorNode::EditorNode() {
play_scene_button->set_focus_mode(Control::FOCUS_NONE);
play_scene_button->set_icon(gui_base->get_icon("PlayScene","EditorIcons"));
play_scene_button->connect("pressed", this,"_menu_option",make_binds(RUN_PLAY_SCENE));
- play_scene_button->set_tooltip(TTR("Play the edited scene (F6)."));
+ play_scene_button->set_tooltip(TTR("Play the edited scene."));
+ play_scene_button->set_shortcut(ED_SHORTCUT("editor/play_scene",TTR("Play Scene"),KEY_F6));
play_custom_scene_button = memnew( ToolButton );
play_hb->add_child(play_custom_scene_button);
diff --git a/tools/editor/editor_settings.cpp b/tools/editor/editor_settings.cpp
index 93b3369aaf..9dd00688c9 100644
--- a/tools/editor/editor_settings.cpp
+++ b/tools/editor/editor_settings.cpp
@@ -45,6 +45,7 @@
#include "io/file_access_memory.h"
#include "io/translation_loader_po.h"
#include "io/compression.h"
+#include "os/keyboard.h"
Ref<EditorSettings> EditorSettings::singleton=NULL;
@@ -57,6 +58,26 @@ EditorSettings *EditorSettings::get_singleton() {
bool EditorSettings::_set(const StringName& p_name, const Variant& p_value) {
_THREAD_SAFE_METHOD_
+
+ if (p_name.operator String()=="shortcuts") {
+
+ Array arr=p_value;
+ ERR_FAIL_COND_V(arr.size() && arr.size()&1,true);
+ print_line("shortcuts: "+Variant(arr).get_construct_string());
+ for(int i=0;i<arr.size();i+=2) {
+
+ String name = arr[i];
+ InputEvent shortcut = arr[i+1];
+
+ Ref<ShortCut> sc;
+ sc.instance();
+ sc->set_shortcut(shortcut);
+ add_shortcut(name,sc);
+ }
+
+ return true;
+ }
+
if (p_value.get_type()==Variant::NIL)
props.erase(p_name);
else {
@@ -74,6 +95,25 @@ bool EditorSettings::_get(const StringName& p_name,Variant &r_ret) const {
_THREAD_SAFE_METHOD_
+ if (p_name.operator String()=="shortcuts") {
+
+ Array arr;
+ for (const Map<String,Ref<ShortCut> >::Element *E=shortcuts.front();E;E=E->next()) {
+
+ Ref<ShortCut> sc=E->get();
+ if (!sc->has_meta("original"))
+ continue; //this came from settings but is not any longer used
+
+ InputEvent original = sc->get_meta("original");
+ if (sc->is_shortcut(original) || (original.type==InputEvent::NONE && sc->get_shortcut().type==InputEvent::NONE))
+ continue; //not changed from default, don't save
+ arr.push_back(E->key());
+ arr.push_back(sc->get_shortcut());
+ }
+ r_ret=arr;
+ return true;
+ }
+
const VariantContainer *v=props.getptr(p_name);
if (!v)
return false;
@@ -126,6 +166,8 @@ void EditorSettings::_get_property_list(List<PropertyInfo> *p_list) const {
p_list->push_back( pi );
}
+
+ p_list->push_back(PropertyInfo(Variant::ARRAY,"shortcuts",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR)); //do not edit
}
bool EditorSettings::has(String p_var) const {
@@ -173,7 +215,7 @@ void EditorSettings::create() {
String config_path;
String config_dir;
- String config_file="editor_settings.xml";
+ //String config_file="editor_settings.xml";
Ref<ConfigFile> extra_config = memnew(ConfigFile);
String exe_path = OS::get_singleton()->get_executable_path().get_base_dir();
@@ -263,17 +305,26 @@ void EditorSettings::create() {
// path at least is validated, so validate config file
- config_file_path = config_path+"/"+config_dir+"/"+config_file;
+ config_file_path = config_path+"/"+config_dir+"/editor_settings.tres";
- if (!dir->file_exists(config_file)) {
- memdelete(dir);
- WARN_PRINT("Config file does not exist, creating.");
- goto fail;
+ String open_path = config_file_path;
+
+ if (!dir->file_exists("editor_settings.tres")) {
+
+ open_path = config_path+"/"+config_dir+"/editor_settings.xml";
+
+ if (!dir->file_exists("editor_settings.xml")) {
+
+ memdelete(dir);
+ WARN_PRINT("Config file does not exist, creating.");
+ goto fail;
+ }
}
memdelete(dir);
- singleton = ResourceLoader::load(config_file_path,"EditorSettings");
+ singleton = ResourceLoader::load(open_path,"EditorSettings");
+
if (singleton.is_null()) {
WARN_PRINT("Could not open config file.");
goto fail;
@@ -865,6 +916,42 @@ bool EditorSettings::_save_text_editor_theme(String p_file) {
return false;
}
+
+void EditorSettings::add_shortcut(const String& p_name, Ref<ShortCut> &p_shortcut) {
+
+ shortcuts[p_name]=p_shortcut;
+}
+
+bool EditorSettings::is_shortcut(const String&p_name, const InputEvent &p_event) const{
+
+ const Map<String,Ref<ShortCut> >::Element *E=shortcuts.find(p_name);
+ if (!E) {
+ ERR_EXPLAIN("Unknown Shortcut: "+p_name);
+ ERR_FAIL_V(false);
+ }
+
+ return E->get()->is_shortcut(p_event);
+
+}
+
+Ref<ShortCut> EditorSettings::get_shortcut(const String&p_name) const{
+
+ const Map<String,Ref<ShortCut> >::Element *E=shortcuts.find(p_name);
+ if (!E)
+ return Ref<ShortCut>();
+
+ return E->get();
+}
+
+void EditorSettings::get_shortcut_list(List<String> *r_shortcuts) {
+
+ for (const Map<String,Ref<ShortCut> >::Element*E=shortcuts.front();E;E=E->next()) {
+
+ r_shortcuts->push_back(E->key());
+ }
+}
+
+
void EditorSettings::_bind_methods() {
ObjectTypeDB::bind_method(_MD("erase","property"),&EditorSettings::erase);
@@ -920,4 +1007,44 @@ EditorSettings::~EditorSettings() {
// singleton=NULL;
}
+Ref<ShortCut> ED_GET_SHORTCUT(const String& p_path) {
+
+ Ref<ShortCut> sc = EditorSettings::get_singleton()->get_shortcut(p_path);
+ if (!sc.is_valid()) {
+ ERR_EXPLAIN("Used ED_GET_SHORTCUT with invalid shortcut: "+p_path);
+ ERR_FAIL_COND_V(!sc.is_valid(),sc);
+ }
+
+ return sc;
+}
+
+Ref<ShortCut> ED_SHORTCUT(const String& p_path,const String& p_name,uint32_t p_keycode) {
+
+ InputEvent ie;
+ if (p_keycode) {
+ ie.type=InputEvent::KEY;
+ ie.key.unicode=p_keycode&KEY_CODE_MASK;
+ ie.key.scancode=p_keycode&KEY_CODE_MASK;
+ ie.key.mod.shift=bool(p_keycode&KEY_MASK_SHIFT);
+ ie.key.mod.alt=bool(p_keycode&KEY_MASK_ALT);
+ ie.key.mod.control=bool(p_keycode&KEY_MASK_CTRL);
+ ie.key.mod.meta=bool(p_keycode&KEY_MASK_META);
+ }
+
+ Ref<ShortCut> sc = EditorSettings::get_singleton()->get_shortcut(p_path);
+ if (sc.is_valid()) {
+
+ sc->set_name(p_name); //keep name (the ones that come from disk have no name)
+ sc->set_meta("original",ie); //to compare against changes
+ return sc;
+ }
+
+ sc.instance();
+ sc->set_name(p_name);
+ sc->set_shortcut(ie);
+ sc->set_meta("original",ie); //to compare against changes
+ EditorSettings::get_singleton()->add_shortcut(p_path,sc);
+
+ return sc;
+}
diff --git a/tools/editor/editor_settings.h b/tools/editor/editor_settings.h
index 879c97c349..60333b5811 100644
--- a/tools/editor/editor_settings.h
+++ b/tools/editor/editor_settings.h
@@ -35,6 +35,8 @@
#include "os/thread_safe.h"
#include "core/io/config_file.h"
#include "translation.h"
+#include "scene/gui/input_action.h"
+
class EditorPlugin;
class EditorSettings : public Resource {
@@ -95,6 +97,8 @@ private:
Vector<Ref<Translation> > translations;
+ Map<String,Ref<ShortCut> > shortcuts;
+
protected:
static void _bind_methods();
@@ -142,6 +146,11 @@ public:
bool save_text_editor_theme();
bool save_text_editor_theme_as(String p_file);
+ void add_shortcut(const String& p_name,Ref<ShortCut>& p_shortcut);
+ bool is_shortcut(const String&p_name,const InputEvent& p_event) const;
+ Ref<ShortCut> get_shortcut(const String&p_name) const;
+ void get_shortcut_list(List<String> *r_shortcuts);
+
EditorSettings();
~EditorSettings();
@@ -152,4 +161,8 @@ public:
#define EDITOR_DEF(m_var,m_val) _EDITOR_DEF(m_var,Variant(m_val))
Variant _EDITOR_DEF( const String& p_var, const Variant& p_default);
+#define ED_IS_SHORTCUT(p_name,p_ev) (EditorSettings::get_singleton()->is_shortcut(p_name,p_ev))
+Ref<ShortCut> ED_SHORTCUT(const String& p_path,const String& p_name,uint32_t p_keycode=0);
+Ref<ShortCut> ED_GET_SHORTCUT(const String& p_path);
+
#endif // EDITOR_SETTINGS_H
diff --git a/tools/editor/project_settings.cpp b/tools/editor/project_settings.cpp
index 1f49f2a9fc..86f1ae6f9f 100644
--- a/tools/editor/project_settings.cpp
+++ b/tools/editor/project_settings.cpp
@@ -330,7 +330,7 @@ void ProjectSettings::_add_item(int p_item){
press_a_key_label->set_text(TTR("Press a Key.."));
last_wait_for_key=InputEvent();
- press_a_key->popup_centered(Size2(250,80));
+ press_a_key->popup_centered(Size2(250,80)*EDSCALE);
press_a_key->grab_focus();
} break;
case InputEvent::MOUSE_BUTTON: {
diff --git a/tools/editor/settings_config_dialog.cpp b/tools/editor/settings_config_dialog.cpp
index 79bcaa4dae..e1a2ea162e 100644
--- a/tools/editor/settings_config_dialog.cpp
+++ b/tools/editor/settings_config_dialog.cpp
@@ -31,6 +31,9 @@
#include "scene/gui/margin_container.h"
#include "globals.h"
#include "editor_file_system.h"
+#include "editor_node.h"
+#include "os/keyboard.h"
+
void EditorSettingsDialog::ok_pressed() {
if (!EditorSettings::get_singleton())
@@ -79,6 +82,7 @@ void EditorSettingsDialog::popup_edit_settings() {
search_box->select_all();
search_box->grab_focus();
+ _update_shortcuts();
popup_centered_ratio(0.7);
}
@@ -101,11 +105,171 @@ void EditorSettingsDialog::_notification(int p_what) {
}
}
+
+void EditorSettingsDialog::_update_shortcuts() {
+
+ shortcuts->clear();
+
+ List<String> slist;
+ EditorSettings::get_singleton()->get_shortcut_list(&slist);
+ TreeItem *root = shortcuts->create_item();
+
+ Map<String,TreeItem*> sections;
+
+ for(List<String>::Element *E=slist.front();E;E=E->next()) {
+
+ Ref<ShortCut> sc = EditorSettings::get_singleton()->get_shortcut(E->get());
+ if (!sc->has_meta("original"))
+ continue;
+
+ InputEvent original = sc->get_meta("original");
+
+ String section_name = E->get().get_slice("/",0);
+
+ TreeItem *section;
+
+ if (sections.has(section_name)) {
+ section=sections[section_name];
+ } else {
+ section = shortcuts->create_item(root);
+ section->set_text(0,section_name.capitalize());
+
+ sections[section_name]=section;
+ section->set_custom_bg_color(0,get_color("prop_subsection","Editor"));
+ section->set_custom_bg_color(1,get_color("prop_subsection","Editor"));
+
+ }
+
+ TreeItem *item = shortcuts->create_item(section);
+
+
+ item->set_text(0,sc->get_name());
+ item->set_text(1,sc->get_as_text());
+ if (!sc->is_shortcut(original) && !(sc->get_shortcut().type==InputEvent::NONE && original.type==InputEvent::NONE)) {
+ item->add_button(1,get_icon("Reload","EditorIcons"),2);
+ }
+ item->add_button(1,get_icon("Edit","EditorIcons"),0);
+ item->add_button(1,get_icon("Close","EditorIcons"),1);
+ item->set_tooltip(0,E->get());
+ item->set_metadata(0,E->get());
+ }
+
+
+
+
+}
+
+void EditorSettingsDialog::_shortcut_button_pressed(Object* p_item,int p_column,int p_idx) {
+
+ TreeItem *ti=p_item->cast_to<TreeItem>();
+ ERR_FAIL_COND(!ti);
+
+ String item = ti->get_metadata(0);
+ Ref<ShortCut> sc = EditorSettings::get_singleton()->get_shortcut(item);
+
+ if (p_idx==0) {
+ press_a_key_label->set_text(TTR("Press a Key.."));
+ last_wait_for_key=InputEvent();
+ press_a_key->popup_centered(Size2(250,80)*EDSCALE);
+ press_a_key->grab_focus();
+ press_a_key->get_ok()->set_focus_mode(FOCUS_NONE);
+ press_a_key->get_cancel()->set_focus_mode(FOCUS_NONE);
+ shortcut_configured=item;
+
+ } else if (p_idx==1) {//erase
+ if (!sc.is_valid())
+ return; //pointless, there is nothing
+
+ UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
+ ur->create_action("Erase Shortcut");
+ ur->add_do_method(sc.ptr(),"set_shortcut",InputEvent());
+ ur->add_undo_method(sc.ptr(),"set_shortcut",sc->get_shortcut());
+ ur->add_do_method(this,"_update_shortcuts");
+ ur->add_undo_method(this,"_update_shortcuts");
+ ur->add_do_method(this,"_settings_changed");
+ ur->add_undo_method(this,"_settings_changed");
+ ur->commit_action();
+ } else if (p_idx==2) {//revert to original
+ if (!sc.is_valid())
+ return; //pointless, there is nothing
+
+ InputEvent original = sc->get_meta("original");
+
+ UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
+ ur->create_action("Restore Shortcut");
+ ur->add_do_method(sc.ptr(),"set_shortcut",original);
+ ur->add_undo_method(sc.ptr(),"set_shortcut",sc->get_shortcut());
+ ur->add_do_method(this,"_update_shortcuts");
+ ur->add_undo_method(this,"_update_shortcuts");
+ ur->add_do_method(this,"_settings_changed");
+ ur->add_undo_method(this,"_settings_changed");
+ ur->commit_action();
+ }
+}
+
+
+void EditorSettingsDialog::_wait_for_key(const InputEvent& p_event) {
+
+
+ if (p_event.type==InputEvent::KEY && p_event.key.pressed && p_event.key.scancode!=0) {
+
+ last_wait_for_key=p_event;
+ String str=keycode_get_string(p_event.key.scancode).capitalize();
+ if (p_event.key.mod.meta)
+ str=TTR("Meta+")+str;
+ if (p_event.key.mod.shift)
+ str=TTR("Shift+")+str;
+ if (p_event.key.mod.alt)
+ str=TTR("Alt+")+str;
+ if (p_event.key.mod.control)
+ str=TTR("Control+")+str;
+
+
+ press_a_key_label->set_text(str);
+ press_a_key->accept_event();
+
+ }
+}
+
+
+
+
+void EditorSettingsDialog::_press_a_key_confirm() {
+
+ if (last_wait_for_key.type!=InputEvent::KEY)
+ return;
+
+ InputEvent ie;
+ ie.type=InputEvent::KEY;
+ ie.key.scancode=last_wait_for_key.key.scancode;
+ ie.key.mod=last_wait_for_key.key.mod;
+
+ Ref<ShortCut> sc = EditorSettings::get_singleton()->get_shortcut(shortcut_configured);
+
+ UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
+ ur->create_action("Change Shortcut '"+shortcut_configured+"'");
+ ur->add_do_method(sc.ptr(),"set_shortcut",ie);
+ ur->add_undo_method(sc.ptr(),"set_shortcut",sc->get_shortcut());
+ ur->add_do_method(this,"_update_shortcuts");
+ ur->add_undo_method(this,"_update_shortcuts");
+ ur->add_do_method(this,"_settings_changed");
+ ur->add_undo_method(this,"_settings_changed");
+ ur->commit_action();
+
+
+
+}
+
void EditorSettingsDialog::_bind_methods() {
ObjectTypeDB::bind_method(_MD("_settings_save"),&EditorSettingsDialog::_settings_save);
ObjectTypeDB::bind_method(_MD("_settings_changed"),&EditorSettingsDialog::_settings_changed);
ObjectTypeDB::bind_method(_MD("_clear_search_box"),&EditorSettingsDialog::_clear_search_box);
+ ObjectTypeDB::bind_method(_MD("_shortcut_button_pressed"),&EditorSettingsDialog::_shortcut_button_pressed);
+ ObjectTypeDB::bind_method(_MD("_update_shortcuts"),&EditorSettingsDialog::_update_shortcuts);
+ ObjectTypeDB::bind_method(_MD("_press_a_key_confirm"),&EditorSettingsDialog::_press_a_key_confirm);
+ ObjectTypeDB::bind_method(_MD("_wait_for_key"),&EditorSettingsDialog::_wait_for_key);
+
}
EditorSettingsDialog::EditorSettingsDialog() {
@@ -145,13 +309,34 @@ EditorSettingsDialog::EditorSettingsDialog() {
vbc = memnew( VBoxContainer );
tabs->add_child(vbc);
- vbc->set_name(TTR("Plugins"));
-
- hbc = memnew( HBoxContainer );
- vbc->add_child(hbc);
- hbc->add_child( memnew( Label(TTR("Plugin List:")+" ") ));
- hbc->add_spacer();
+ vbc->set_name(TTR("Shortcuts"));
+
+ shortcuts = memnew( Tree );
+ vbc->add_margin_child("Shortcut List:",shortcuts,true);
+ shortcuts->set_columns(2);
+ shortcuts->set_hide_root(true);
+ //shortcuts->set_hide_folding(true);
+ shortcuts->set_column_titles_visible(true);
+ shortcuts->set_column_title(0,"Name");
+ shortcuts->set_column_title(1,"Binding");
+ shortcuts->connect("button_pressed",this,"_shortcut_button_pressed");
+
+ press_a_key = memnew( ConfirmationDialog );
+ press_a_key->set_focus_mode(FOCUS_ALL);
+ add_child(press_a_key);
+
+ l = memnew( Label );
+ l->set_text(TTR("Press a Key.."));
+ l->set_area_as_parent_rect();
+ l->set_align(Label::ALIGN_CENTER);
+ l->set_margin(MARGIN_TOP,20);
+ l->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_BEGIN,30);
+ press_a_key_label=l;
+ press_a_key->add_child(l);
+ press_a_key->connect("input_event",this,"_wait_for_key");
+ press_a_key->connect("confirmed",this,"_press_a_key_confirm");
//Button *load = memnew( Button );
+
//load->set_text("Load..");
//hbc->add_child(load);
diff --git a/tools/editor/settings_config_dialog.h b/tools/editor/settings_config_dialog.h
index 5085132108..c930de6a77 100644
--- a/tools/editor/settings_config_dialog.h
+++ b/tools/editor/settings_config_dialog.h
@@ -50,6 +50,13 @@ class EditorSettingsDialog : public AcceptDialog {
Timer *timer;
+ Tree *shortcuts;
+
+ ConfirmationDialog *press_a_key;
+ Label *press_a_key_label;
+ InputEvent last_wait_for_key;
+ String shortcut_configured;
+
virtual void cancel_pressed();
virtual void ok_pressed();
@@ -59,8 +66,14 @@ class EditorSettingsDialog : public AcceptDialog {
void _notification(int p_what);
+ void _press_a_key_confirm();
+ void _wait_for_key(const InputEvent& p_event);
+
void _clear_search_box();
+ void _update_shortcuts();
+ void _shortcut_button_pressed(Object* p_item,int p_column,int p_idx);
+
protected:
static void _bind_methods();