diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/input_map.cpp | 92 | ||||
-rw-r--r-- | core/input_map.h | 3 | ||||
-rw-r--r-- | core/os/os.cpp | 9 | ||||
-rw-r--r-- | core/os/os.h | 1 | ||||
-rw-r--r-- | core/variant_parser.cpp | 39 |
5 files changed, 143 insertions, 1 deletions
diff --git a/core/input_map.cpp b/core/input_map.cpp index 17e98902a1..c266220541 100644 --- a/core/input_map.cpp +++ b/core/input_map.cpp @@ -28,6 +28,7 @@ /*************************************************************************/ #include "input_map.h" #include "globals.h" +#include "os/keyboard.h" InputMap *InputMap::singleton=NULL; @@ -36,6 +37,7 @@ void InputMap::_bind_methods() { ObjectTypeDB::bind_method(_MD("has_action","action"),&InputMap::has_action); ObjectTypeDB::bind_method(_MD("get_action_id","action"),&InputMap::get_action_id); ObjectTypeDB::bind_method(_MD("get_action_from_id","id"),&InputMap::get_action_from_id); + ObjectTypeDB::bind_method(_MD("get_actions"),&InputMap::_get_actions); ObjectTypeDB::bind_method(_MD("add_action","action"),&InputMap::add_action); ObjectTypeDB::bind_method(_MD("erase_action","action"),&InputMap::erase_action); @@ -75,6 +77,35 @@ StringName InputMap::get_action_from_id(int p_id) const { return input_id_map[p_id]; } +Array InputMap::_get_actions() { + + Array ret; + List<StringName> actions = get_actions(); + if(actions.empty()) + return ret; + + for(const List<StringName>::Element *E=actions.front();E;E=E->next()) { + + ret.push_back(E->get()); + } + + return ret; +} + +List<StringName> InputMap::get_actions() const { + + List<StringName> actions = List<StringName>(); + if(input_map.empty()){ + return actions; + } + + for (Map<StringName, Action>::Element *E=input_map.front();E;E=E->next()) { + actions.push_back(E->key()); + } + + return actions; +} + List<InputEvent>::Element *InputMap::_find_event(List<InputEvent> &p_list,const InputEvent& p_event) const { for (List<InputEvent>::Element *E=p_list.front();E;E=E->next()) { @@ -291,6 +322,67 @@ void InputMap::load_from_globals() { } +void InputMap::load_default() { + + InputEvent key; + key.type=InputEvent::KEY; + + add_action("input/ui_accept"); + key.key.scancode=KEY_RETURN; + action_add_event("input/ui_accept",key); + key.key.scancode=KEY_ENTER; + action_add_event("input/ui_accept",key); + key.key.scancode=KEY_SPACE; + action_add_event("input/ui_accept",key); + + add_action("input/ui_select"); + key.key.scancode=KEY_SPACE; + action_add_event("input/ui_select",key); + + add_action("input/ui_cancel"); + key.key.scancode=KEY_ESCAPE; + action_add_event("input/ui_cancel",key); + + add_action("input/ui_focus_next"); + key.key.scancode=KEY_TAB; + action_add_event("input/ui_focus_next",key); + + add_action("input/ui_focus_prev"); + key.key.scancode=KEY_TAB; + key.key.mod.shift=true; + action_add_event("input/ui_focus_prev",key); + key.key.mod.shift=false; + + add_action("input/ui_left"); + key.key.scancode=KEY_LEFT; + action_add_event("input/ui_left",key); + + add_action("input/ui_right"); + key.key.scancode=KEY_RIGHT; + action_add_event("input/ui_right",key); + + add_action("input/ui_up"); + key.key.scancode=KEY_UP; + action_add_event("input/ui_up",key); + + add_action("input/ui_down"); + key.key.scancode=KEY_DOWN; + action_add_event("input/ui_down",key); + + + add_action("input/ui_page_up"); + key.key.scancode=KEY_PAGEUP; + action_add_event("input/ui_page_up",key); + + add_action("input/ui_page_down"); + key.key.scancode=KEY_PAGEDOWN; + action_add_event("input/ui_page_down",key); + +// set("display/orientation", "landscape"); + + +} + InputMap::InputMap() { ERR_FAIL_COND(singleton); diff --git a/core/input_map.h b/core/input_map.h index 5cd1e41922..dc5a911963 100644 --- a/core/input_map.h +++ b/core/input_map.h @@ -47,6 +47,7 @@ class InputMap : public Object { List<InputEvent>::Element *_find_event(List<InputEvent> &p_list,const InputEvent& p_event) const; Array _get_action_list(const StringName& p_action); + Array _get_actions(); protected: @@ -59,6 +60,7 @@ public: bool has_action(const StringName& p_action) const; int get_action_id(const StringName& p_action) const; StringName get_action_from_id(int p_id) const; + List<StringName> get_actions() const; void add_action(const StringName& p_action); void erase_action(const StringName& p_action); @@ -72,6 +74,7 @@ public: void load_from_globals(); + void load_default(); InputMap(); }; diff --git a/core/os/os.cpp b/core/os/os.cpp index 6910b368d3..4daf41e68e 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -306,6 +306,15 @@ String OS::get_system_dir(SystemDir p_dir) const { return "."; } +String OS::get_safe_application_name() const { + String an = Globals::get_singleton()->get("application/name"); + Vector<String> invalid_char = String("\\ / : * ? \" < > |").split(" "); + for (int i=0;i<invalid_char.size();i++) { + an = an.replace(invalid_char[i],"-"); + } + return an; +} + String OS::get_data_dir() const { return "."; diff --git a/core/os/os.h b/core/os/os.h index 76dd235d24..a1047bd48f 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -326,6 +326,7 @@ public: virtual String get_locale() const; + String get_safe_application_name() const; virtual String get_data_dir() const; virtual String get_resource_dir() const; 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: { |